/*
	Function is used to check if the year is a leap year
*/
function IsLeapYear(theyear) 
{
	if (theyear % 100 == 0) 
	{
    	if (theyear % 400 == 0) 
	  	{ 
	  		return true; 
	  	}
	}
    else 
  	{
    	if ((theyear % 4) == 0) 
	 	{ 
	 		return true; 
	 	}
     }

	return false;
}

/*
	Function is used to check if a series of select boxes used to create a date
	contain a valid date (i.e. not February 30)
*/
function CheckDate(theform,thefield,themessage)
{
	var theday_field_name=thefield+"_day";
	var themonth_field_name=thefield+"_month";
	var theyear_field_name=thefield+"_year";
	var theday=0;
	var themonth=0;
	var theyear=0;
	
	theday=theform[theday_field_name][theform[theday_field_name].selectedIndex].value;
	themonth=theform[themonth_field_name][theform[themonth_field_name].selectedIndex].value;
	theyear=theform[theyear_field_name][theform[theyear_field_name].selectedIndex].value;
	
	if (themonth ==  2) 
	{
		if (theday > 28)
		{
			if (IsLeapYear(theyear))
			{
				if (theday > 29)
				{
					alert("February only has 29 days in a leap year.");
					theform[theday_field_name].focus();
					return false;
				}
			}
			else
			{
				alert("February only has 28 days.");	
				theform[theday_field_name].focus();
				return false;
			}
		}
	}
	if ((themonth == 4) || (themonth == 6) || (themonth == 9) || (themonth == 11))
	{
		if (theday > 30)
		{
			alert("Please pick 30 or less days for the " + themessage + ".");
			theform[theday_field_name].focus();
			return false;
		}
	}

return true;
}

