var nichtalle="Please fill in the required fields. / Bitte alle Felder ausfüllen!";
var novalidemail="Please enter a valid email address. / Bitte eine gültige Email Adresse eintragen!";
var novaliddate="dasParkhotel is closed. The booking will open again in May 2010! / Die Buchung ist ab Mai 2009 wieder geöffnet.";
var dayInMilSec = 86400000;
var bookInAdvance = 0;

function checkForm() {	
	fo = document.buchen;
	valid=true;
	
	valid = validDate( fo.year.value,fo.month.value,fo.day.value );
	
	if ( !valid )
		return valid;
	else{
		valid = allComplete( fo );		
		if ( !valid )
			return valid;
		else			
			return validEmail( fo.email.value );
	}
}

function allComplete() {
	anzahlFelder=5;
	voll="true";
	for(i=0; i < anzahlFelder; i++) {
		if(fo.elements[i].value== "")
			voll=false;
	}
	if(!voll)
		alert(nichtalle);
	
	return voll;
}

function validEmail(field) {
	valid = (field.indexOf(".") > 2) && (field.indexOf("@") > 0);
	if ( !valid )
		alert(novalidemail);
		
	return valid;
}

function validDate(year,month,day) {
	//alert(year+" "+month+" "+day);
	//return false;
	var startday=new Date("July 09, 2010")
	var endday=new Date("September 22, 2010")
	var resday=new Date(year,month-1,day);
	
	var today = new Date();
	var tomorrow = new Date( today.getTime()+(dayInMilSec*bookInAdvance));
	
	//alert( tomorrow.toString() );
	
	/* it's not allowed to book on the same day */
	if ( resday.getTime()<tomorrow.getTime()){
		alert("Für heute werden leider keine Buchungen mehr angenommen. / We don't accept resevervations for today!");
		return false;
	}
	
	var valid = ( resday.getTime()>startday.getTime() )? true : false;
	valid = ( resday.getTime()<endday.getTime() )? valid : false;
	
	if ( !valid )
		alert(novaliddate);
		
	return valid;
}
