

// function that works out the number of days in a
// month given the current year and month
function days_in_month (year, month) 
{
      return 32 - new Date(year, month, 32).getDate();
}

// onChange handle for month and day select boxes
function onMonthYearChange(dayObject,monthObject,yearObject)
{
	onMonthYearChange2(dayObject,monthObject,yearObject);
}
//called by scheduler action page.
function onMonthYearChangeExtra(dayObject,monthObject,yearObject){
	onMonthYearChange2(dayObject,monthObject,yearObject);
}

function onMonthYearChange2(dayObject,monthObject,yearObject)
{

	// get the no of days in the new year/month combination	
	var monthSelected = monthObject;
	var yearSelected  = yearObject;
	monthSelected     = monthSelected-1;

	var days = days_in_month (yearSelected , monthSelected);

	var currentDays = dayObject.length;
	
	if(currentDays == days)
		return;

	if(currentDays < days)
	{
	
		var iSel = dayObject.selectedIndex;
		
		var diff = days - currentDays;
		for(var i=0; i<diff; i++)
		{
			dayObject.options[currentDays + i] = new Option(currentDays+i+1, currentDays+i+1);
		}
		dayObject.options[iSel].selected = true;
		
	}

	if(currentDays > days)
	{
		var iSel = dayObject.selectedIndex;

		dayObject.options.length = 0;
		
		for (var i=0; i<days; i++)
		{
			dayObject.options[dayObject.options.length] = new Option(i+1, i+1);
		}
		
		if (iSel > dayObject.options.length - 1)
		{
			iSel = dayObject.options.length - 1
		}

		dayObject.options[iSel].selected = true;
	}
}
