//works if browsers implement gregorian calendar correctly - they seem to
function daysInMonth(iMonth, iYear)
{
	return 32 - new Date(iYear, iMonth, 32).getDate();
}

function dateSelectChange(id)
{
	var d=document.getElementById("days"+id);
	var m=document.getElementById("months"+id);
	var y=document.getElementById("years"+id);
	
	var dim=daysInMonth(parseInt(m.value)-1,parseInt(y.value));
	var ind=d.selectedIndex;
	while (d.length>0) {
		d.options[0]=null;
	}
	if (ind>=dim)
		ind=0;
	for (var i=0;i<dim;i++) {
		var val=""+(i+1);
		if (parseInt(val)<10)
			val="0"+val;
		d.options[i]=new Option(val,val);
	}
	d.selectedIndex=ind;
	
	var cd=document.getElementById("caldate"+id);
	cd.value=y.value+"-"+m.value+"-"+d.value;
}

function getCalDate(id)
{
	var cd=document.getElementById("caldate"+id);
	var d=document.getElementById("days"+id);
	var m=document.getElementById("months"+id);
	var y=document.getElementById("years"+id);
	
	y.value=cd.value.substring(0,4);
	m.value=cd.value.substring(5,7);
	d.value=cd.value.substring(8,10);
	
	setTimeout("getCalDate('"+id+"')",1000);
}
