var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function check_form(name)
{
	var x = document.forms[0].elements;
	var fnights=document.forms[0].fnights.value;
	var fdep=document.forms[0].fdep1.value;

	if((fnights=="")&&(fdep=="")){
		alert("Please specify where you are departing\n from and how long your trip will be.");
		return false;
	}else if((fnights!="")&&(fdep=="")){
		alert("Please specify where you are departing from.");
		return false;
	}else if((fdep!="")&&(fnights=="")){
		alert("Please specify how long your trip will be.");
		return false;
	}

	
	var dateExists = true;
	var day = parseInt(x[name+"D"].options[x[name+"D"].selectedIndex].value);
	var month = parseInt(x[name+"M"].options[x[name+"M"].selectedIndex].value);
	var year = parseInt(x[name+"Y"].options[x[name+"Y"].selectedIndex].value);

	if (!day || !month || !year)
	{
		alert('Please fill in a complete date');
		return;
	}

	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;

	if (day > monthLength[month-1])
		dateExists = false;

	monthLength[1] = 28;

	//document.forms[0].results.value = 'Date exists? ' + ((dateExists) ? 'Yes' : 'No') + '\n';
	//if (!dateExists) return;

	var now = new Date();
	now = now.getTime(); //NN3

	var dateToCheck = new Date();
	dateToCheck.setYear(year);
	dateToCheck.setMonth(month-1);
	dateToCheck.setDate(day);
	var checkDate = dateToCheck.getTime();

	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);
	if(!futureDate){
		alert("Invalid date - date is in the past!");
		return false;
	}
	else if(!checkDate){
		 alert("Invalid date!");
		return false;
	}
}
