var date = [];
date[1] = 31;
date[2] = [];
date[2][0] = 29;
date[2][1] = 28;
date[3] = 31;
date[4] = 30;
date[5] = 31;
date[6] = 30;
date[7] = 31;
date[8] = 31;
date[9] = 30;
date[10] = 31;
date[11] = 30;
date[12] = 31;

function setMonth(year, month) {
	var str = '<select name="birthmonth" onchange="setDate(' + year + ', this.value)">';
	for(i = 1;i <= 12;i++) {
		if(month && month == i) {
			str += '<option value="' + i + '" selected>' + i + '</option>';
		} else {
			str += '<option value="' + i + '">' + i + '</option>';
		}
	}
	str += '</select>';
	document.getElementById('month').innerHTML = str;
	document.getElementById('month').style.display = '';
	document.getElementById('date').innerHTML = '<select name="birthdate"><option value="1">1</option></select>';
	document.getElementById('date').style.display = '';
}

function setDate(year, month, day) {
	var days = 0;
	if(year % 4 == 0 && month == 2) {
		days = date[month][0];
	} else if (month == 2) {
		days = date[month][1];
	} else {
		days = date[month];
	}
	var str = '<select name="birthdate">';
	for(i = 1;i <= days;i++) {
		if(day && day == i) {
			str += '<option value="' + i + '" selected>' + i + '</option>';
		} else {
			str += '<option value="' + i + '">' + i + '</option>';
		}
	}
	str += '</select>';
	document.getElementById('date').innerHTML = str;
	document.getElementById('date').style.display = '';
}
