function drawDateBoxes(name, day, month, year, yearhint){
	
	var str = "<select name=\"" + name + "day\" id=\"" + name + "day\" onchange=\"validateDate('" + name + "');\">";
	str += "<option value=\"0\"> </option>";
	for(i = 0; i < 31; i++){
		var d = i+1;
		str += "<option value=\"" + d + "\"";
		if(day == d){
			str += " selected=\"selected\"";
		}
		str += ">" + d + "</option>";
	}
	
	str += "</select>&nbsp;/&nbsp;";
	
	str += "<select name=\"" + name + "month\" id=\"" + name + "month\" onchange=\"validateDate('" + name + "');\">";
	str += "<option value=\"0\"> </option>";
	for(i = 0; i < 12; i++){
		var m = i+1;
		str += "<option value=\"" + i + "\"";
		if(month == i){
			str += " selected=\"selected\"";
		}
		str += ">" + m + "</option>";
	}
		
	str += "</select>&nbsp;/&nbsp;";
	str += "<input type=\"text\" maxlength=\"4\" ";
	if(year != null && !isNaN(year)){
		str += "value=\"" + year + "\" ";
	}
	str += "style=\"width: 35px;text-align: left;\" name=\"" + name + "year\" id=\"" + name + "year\" onchange=\"checkYearInput(this);validateDate('" + name + "');\"" ;
	
	if( yearhint != null && yearhint != "" )
		str += " onfocus=\"setHint('"+yearhint+"');\" onblur=\"setHint('');\"" ;
	
	str += ">";
	
	document.write(str);

}

function validateDate(name){
	var day = document.getElementById(name+'day');
	var month = document.getElementById(name+'month');
	var year = document.getElementById(name+'year');
		
	if((day[day.selectedIndex].value == "31" && month[month.selectedIndex].value == "4") ||
		(day[day.selectedIndex].value == "31" && month[month.selectedIndex].value == "6") ||
		(day[day.selectedIndex].value == "31" && month[month.selectedIndex].value == "9") ||
		(day[day.selectedIndex].value == "31" && month[month.selectedIndex].value == "11")){
		
		day.selectedIndex = 30;
	}

	if(parseInt(day[day.selectedIndex].value) > 28 && parseInt(year.value) % 4 == 0 && month[month.selectedIndex].value == "2"){
		if(parseInt(year.value) % 4 == 0){
			day.selectedIndex = 29;
		}
		if(parseInt(year.value) % 100 == 0){
			day.selectedIndex = 28;
		}
		if(parseInt(year.value) % 400 == 0){
			day.selectedIndex = 29;
		}
	}
	if(parseInt(day[day.selectedIndex].value) > 28 && parseInt(year.value) % 4 != 0 && month[month.selectedIndex].value == "2"){
		day.selectedIndex = 28;
	}
}

function checkYearInput(year){
	
	if((!year.value.match("^[0-9]{4}$") || parseInt(year.value) > 2039 || parseInt(year.value) < 1902) &&
	!year.value.match("")){
		year.blur();
		alert("Please enter a valid four digit year between 1902 and 2039");
		year.focus();
		year.select();
	}
}
