// Adapted from original script by Arash Ramin (http://www.digitalroom.net)

function setDays(day, month, year)
{
	var m = month.options[month.selectedIndex].value;
	var y = year.options[year.selectedIndex].value;

	// find number of days in current month
	if ((m == 4) || (m == 6) || (m == 9) || (m == 11))
		days = 30;
	else if (m == 2)
	{
		// check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
		if ((Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))))
			days = 29;
		else
			days = 28;
	}
	else
		days = 31;
	
	// if (days in new month > current days) then we must add the extra days
	for (i = day.length; i <= days; i++)
	{
		day.length = days + 1;
		day.options[i].text = i;
		day.options[i].value = i;
	}

	// if (days in new month < current days) then we must delete the extra days
	if (days < day.length)
	{
		if (day.options[day.selectedIndex].value > days)
			day.selectedIndex = days;
		day.length = days + 1;
	}
}

