var startYear = 2009;

function setupDate()
{
	var d = new Date();
	var f = document.forms["avsearch"];
	var s = location.search;
	if (s != "") {
		s = s.substr(1);
		var d = s.split("&");
		for (i in d) {
			x = d[i].split("=");
			if (x[0]=="day") f.day.selectedIndex = x[1]-1;
			if (x[0]=="month") f.month.selectedIndex = x[1]-1;
			if (x[0]=="year") f.year.selectedIndex = x[1]-startYear;
		}
	} else {
		f.day.selectedIndex = d.getDate()-1;
		f.month.selectedIndex = d.getMonth();
		f.year.selectedIndex = d.getFullYear()-startYear;
	}
}

function checkDate(f)
{
	var chk = new Date(optVal(f.year), optVal(f.month)-1, optVal(f.day))
	if ( optVal(f.year)  == chk.getFullYear() &&
	     optVal(f.month) == chk.getMonth()+1  &&
	     optVal(f.day)   == chk.getDate() ) {
	     	 return true;
	} else {
		alert("The date you have selected is not a valid date!");
		f.day.focus();
		return false;
	}
}

function optVal(o)
{
	return o.options[o.selectedIndex].value;
}