$(function() {

	if (document.getElementById("photo-gallery"))
	{
		var url = '';
		
		$('#photo-gallery div p').each(function(n) {
			
			if (n == 0)
				$(this).hide();
			else if (n == 1) // picture
				url = $(this).find('a').attr('href');
			else if (n == 2) // description
				$(this).html( '<a href="' + url + '" target="_blank">' + $(this).html() + '</a>');
		});
	}
});


function isValidDate(ctrlDate)
{
	var d = new Date();
	var nCurrent_Year = d.getFullYear();
	if (ctrlDate.value == '') return true;
	d.setTime(Date.parse(ctrlDate.value));
	if (isNaN(d) || d.getFullYear() < 1900 || d.getFullYear() > (nCurrent_Year+5))
	{
		alert("Date format should be 'MM/DD/YYYY'.");
		ctrlDate.value = '';
		ctrlDate.focus();
		return false;
	}
	else
	{
		ctrlDate.value = formatShortDate(d);
		return true;
	}
}

function formatShortDate(d)
{
  var cDate  = '';
  var nDays  = d.getDate();
  var nMonth = d.getMonth()+1;
  var nYear  = d.getFullYear();
  if (nYear < 1940) nYear += 100;

  cDate += ((nMonth < 10) ? '0' : '') + nMonth + '/' + ((nDays < 10) ? '0' : '') + nDays + '/' + nYear;

  return cDate;
}

