
<!--

/* This script is slightly different from the one shown on this page. It doesn't
return any value, but instead writes the outcome of the check into the textarea. */

var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function checkDate(name)
{
	var dateExists = true;
	var x = document.forms.reservation.elements;
	var day = parseInt(x[name+"_day"].options[x[name+"_day"].selectedIndex].value);
	var month = parseInt(x[name+"_month"].options[x[name+"_month"].selectedIndex].value);
	var year = parseInt(x[name+"_year"].options[x[name+"_year"].selectedIndex].value);

	if (!day || !month || !year)
	{
		alert('Please fill in a complete date');
		return false;
		//exit;
	}

	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==true){
	//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(now == checkDate || now < checkDate){
			// Future
			//alert("<3");
			//document.forms[0].results.value = "<3";
		}else{
			// History
			alert("Date earlier than today is not accepted. Please choose again.");
			//document.forms[0].results.value = "No common sense :(";
			return false;
		}
	}else{
		alert("Invalid date. Please choose again.");
		//document.forms[0].results.value = "Date doesnt exist :("; 
		return false;
	}
	/*document.forms[0].results.value +=
		'In the future? '  + ((futureDate) ? 'Yes' : 'No') + '\n';

	document.forms[0].results.value +=
		'In the past? '  + ((pastDate) ? 'Yes' : 'No');*/

}

// -->
