
function megaBirthDate_DayChange(ddlDay) {	
	megaBirthDate_setText(ddlDay);
}

function megaBirthDate_YearChange(ddlYear) {
		
	megaBirthDate_setText(ddlYear);
	
	var id = ddlYear.id;	
	id = id.substring(0, id.length - 1);		
	var ddlMonth = document.getElementById(id + "m");
	megaBirthDate_MonthChange(ddlMonth);
	
}

function megaBirthDate_MonthChange(ddlMonth) 
{

	megaBirthDate_setText(ddlMonth);

	var id = ddlMonth.id;
	id = id.substring(0, id.length - 1);
	var ddlDay = document.getElementById(id + "d");
	var ddlYear = document.getElementById(id + "y");
	
	var month = parseInt(ddlMonth.options[ddlMonth.selectedIndex].value);
	var year = parseInt(ddlYear.options[ddlYear.selectedIndex].value);
	var currentDayIndex = ddlDay.selectedIndex;
	
	ddlDay.options.length = 0;
	ddlDay.options[0] = document.createElement("option");
	ddlDay.options[0].text = megaBirthDate_DayLabel;
	ddlDay.options[0].value = "";
	
	var d = new Date();
	d.setDate(1);

	
	if (! isNaN(year)) {
		d.setYear(year);		
	} 
	
	if (! isNaN(month)) {		
		d.setMonth(month - 1);		
	} 
	
	var i = 1;				
		
	while (d.getMonth() == month -1) 
	{			
		ddlDay.options[i] = document.createElement("option");
		ddlDay.options[i].text = d.getDate();
		ddlDay.options[i].value = d.getDate();
		i++;
		d.setDate(i);
	}
	
	ddlDay.selectedIndex = currentDayIndex;
	
	
}


function megaBirthDate_setText(ddl) {
	var id = ddl.id;
	
	id = id.substring(0, id.length - 1);		
	var ddlMonth = document.getElementById(id + "m");
	var ddlYear = document.getElementById(id + "y");
	var ddlDay = document.getElementById(id + "d");
	var txt = document.getElementById(id.substring(0, id.length - 1));
	
	if (ddlDay.selectedIndex < 0) ddlDay.selectedIndex = 0;
	if (ddlMonth.selectedIndex < 0) ddlMonth.selectedIndex = 0;
	if (ddlYear.selectedIndex < 0) ddlYear.selectedIndex = 0;
	
	var month = parseInt(ddlMonth.options[ddlMonth.selectedIndex].value);
	var year = parseInt(ddlYear.options[ddlYear.selectedIndex].value);
	var day = parseInt(ddlDay.options[ddlDay.selectedIndex].value);
	
	var d = new Date();
	
	if (! isNaN(year) &&  ! isNaN(month) && ! isNaN(day)) {		
		d.setYear(year);	
		d.setMonth(month - 1);			
		d.setDate(day);
		txt.value = year + "/" + month + "/" + day;
		
	} else {
		txt.value = "";
	}
	
	try {
		//fire any validator on change...
		var str = txt.onchange + "";
		if (str && str.indexOf("ValidatorOnChange") != -1) {
			var eObj = { target: txt };
			ValidatorOnChange(eObj);
		}
	} catch (error) {}
	

	
}