function setDaySelect(daySelect,sourceMonth,sourceYear)
{
	var ssel=$F(sourceMonth);
	var month=$F(sourceMonth);
	if(month==0)
		return;
	var syear=$F(sourceYear);
	var isLeap=((syear%4)==0);
	var dsel=$(daySelect);
	var sday=parseInt($F(daySelect));
	var days=0;
	switch(parseInt(month))
	{
		case 1:case 3:case 5:case 7:case 8:case 10:case 12:
			days=31;
			break;
		case 2:
				days=(isLeap?29:28);
				break;
		case 4:case 6:case 9:case 11:
			days=30;
			break;
		case 0:
			days=31;
			break;
	}
	clearSelect(dsel);
	var endi=$(sourceMonth).options.length;
	dsel.options[0]=new Option("DD",0);
	for(var i=1;i<days+1;i++)
		dsel.options[i]=new Option((i>9?i:"0"+i),i);
	if(sday!=null && sday<dsel.options.length)
		dsel.options[parseInt(sday)].selected=true;
	else
		dsel.options[0].selected=true;
}

function the_day(Y, M, D)
{
	daynames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	theDate = new Date(Y, M, D);
	temp = theDate.getDay();
	return daynames[temp];
}
/* isDateValid() takes a date of the form theYear, theMonth, theDay and ensures it is not in the past, is actaully valid (i.e 30th Feb), and compensates for leap years.
* dateType is a string that names the date (i.e. Date of Birth)
* returns a message explaining why theDate is invalid if invalid, and true if valid.
*/
function isDateValid(theYear, theMonth, theDay, dateType, checkPast)
{
	//get today's date to vaildate id/concession/connection/etc dates
	var dateVar = new Date();	//todays date
	var todayYear = dateVar.getFullYear();
	var todayMonth = dateVar.getMonth()+1;
	var todayDay = dateVar.getDate();
	theYear=((isNaN(parseInt(theYear)))?0:parseInt(theYear));
	theMonth=((isNaN(parseInt(theMonth)))?0:parseInt(theMonth));
	theDay=((isNaN(parseInt(theDay)))?0:parseInt(theDay));

	var notValid = '';
	var leapYear = theYear%4;	//leap year will be 0, any other value is not a leap year
	var tmpToday = '';
	
	if((theMonth > 0 && theMonth < 10))
		theMonth = '0'+theMonth;
	
	if((theDay > 0 && theDay < 10))
		theDay = '0'+theDay;
	
	var theDate = theYear+''+theMonth+''+theDay;
	
	if(todayMonth < 10 || todayMonth.length == 1)
		todayMonth = '0'+todayMonth;
	
	if(todayDay < 10 || todayDay.length == 1)
		todayDay = '0'+todayDay;
	
	tmpToday = todayYear+''+todayMonth+''+todayDay;

	if(theDate.length != 8)
		return 'The '+dateType+' you have entered is not valid.';
	
	switch(theMonth)
	{
		case '02':
			if(theDay > 29)
				return 'The '+dateType+' you have entered is not valid. Feburary never has more than 29 days.';
			if(theDay == 29 && leapYear != 0)
				return 'The '+dateType+' you have entered is not valid. Feburary only has 29 days in a leap year.';
		break;
		case '04': case '06': case '09': case '11':
			if(theDay > 30)
				return 'The '+dateType+' you have entered is not valid. Month should have less than 31 days.';
		break;
	}

	if(checkPast && theDate < tmpToday)
		return 'The '+dateType+' you have entered is in the past.';

	return true;
}
function clearSelect(objSelect)
{
	for (var i = (objSelect.options.length-1); i >= 0; i--)
  	objSelect.options[i]=null;
}
