function setDay(source, form){
	index = (source.id).indexOf("drp",0);
	control = (source.id).substring(0,index);
	
	// get the control objects
	day = document.getElementById(control+"drp_day");
	dayValue = day.value;
	
	month = document.getElementById(control+"drp_month");
	monthValue = month.value;
	
	year = document.getElementById(control+"drp_year");
	yearValue = year.value;
	
	maxDay = max_day(monthValue, yearValue);
	
	selected = day.selectedIndex; // save the selected index
		
	if (day.length > maxDay)
	{ 
		// remove days if needed and update selected
		for (i = day.length-1 ; i>maxDay ; i--)
		{
			day.options[i] = null;
		}
		//handles selected day
		if (selected >= maxDay)
		{
			day.options[i].selected = true;
		}
		else
		{
			day.options[selected].selected = true;
		}
	}
	else
	{
		// add days if needed and update selected
		for (i = day.length-1;i<=maxDay;i++)
		{
			day.options[i] = new Option(i,i);
		}
		day.options[selected].selected = true;
	}	
}

// function for calculating maximum day in month/year
function max_day(month, year)
{
  var mDay;
  if((month == 4) || (month == 6) || (month == 9) || (month == 11))
  { 
    mDay = 30;
  }
  else if(month == 2)
	{
		//calling leap year function
		if (isLeapYear(year)){
			mDay = 29;
		}else{
			mDay = 28;
		}
	}else{
		mDay = 31;
	}
  return mDay; 
}

// function to check leap year
function isLeapYear(year)
{
  if      (year % 4 != 0)   return false;
  else if (year % 400 == 0) return true;
  else if (year % 100 == 0) return false;
  else                    return true;
}

function checkChange(source, form){
	index = (source.id).indexOf("chk",0);
	control = (source.id).substring(0,index);
	
	// get the control objects
	day = document.getElementById(control+"drp_day");
	month = document.getElementById(control+"drp_month");
	year = document.getElementById(control+"drp_year");
	
	if (source.checked){
		day.disabled = false;
		month.disabled = false;
		year.disabled = false;
	}else{
		day.disabled = true;
		month.disabled = true;
		year.disabled = true;
	}
}
