var monthDays = [ 31,28,31,30,31,30,31,31,30,31,30,31 ]
function rebuild(yearId,monthId,dayId){
    var dayObj = document.getElementById(dayId);
    var monthObj = document.getElementById(monthId);    
    var yearObj = document.getElementById(yearId);
	
	var countDays = monthDays[parseInt(monthObj.value) - 1];
	if ( parseInt(yearObj.value) % 4 == 0 && parseInt(monthObj.value) == 2){
		countDays = 29;
	}
    var dayObj2 = dayObj.cloneNode(false);
    var dayObjParent = dayObj.parentNode; 
	for ( i = 1; i <= countDays; i ++ ){
		var nod = document.createElement('option');
		nod.setAttribute('value', i);
		var txt = document.createTextNode(i);
		nod.appendChild(txt);			
		dayObj2.appendChild(nod);
	}
    dayObjParent.replaceChild(dayObj2,dayObj);
}
window.onload = function(){
    document.getElementById('in_month').onchange = function(){ rebuild('in_year','in_month','in_date'); }
    document.getElementById('in_year').onchange = function(){ rebuild('in_year','in_month','in_date'); }
    document.getElementById('out_month').onchange = function(){ rebuild('out_year','out_month','out_date'); }
    document.getElementById('out_year').onchange = function(){ rebuild('out_year','out_month','out_date'); }
    rebuild('out_year','out_month','out_date');
    rebuild('out_year','out_month','out_date');
}
