//	validation.js
//	Copyright 2004
//	author Steffan Packer


function isAnEmail(email){
	re = /^[a-z0-9\-_\.]+@{1}[a-z0-9-_]+\.{0,1}[a-z0-9-_]+\.{1}[a-z]{2,3}$/i;
	email = email.replace(/\s/g, '');//strip all white space from email address
	if(re.test(email)){
		return email;
	}else{
		return false;
	}
} 
function isOnlyNumbers(testStr){
	re = /^[0-9]+$/i;
	if(re.test(testStr)){
		return true;
	}else{
		return false;
	}
}
//if second parameter is true this method will allow white space in the string
function isOnlyLetters(testStr, space){
	if(space){
		re = /^[a-z\s]+$/i;
	}else{
		re = /^[a-z]+$/i;
	}
	if(re.test(testStr)){
		return true;
	}else{
		return false;
	}
}
function validateForm(){
	var errorMsg = "";
	if(document.bookingForm.name.value.length<1){
		errorMsg+="You must enter a valid name.\r\n";
	}else if(!isOnlyLetters(document.bookingForm.name.value, true)){
		errorMsg+="You can only have letters in your name!\r\n";
	}
	if(document.bookingForm.email.value.length<1){
		errorMsg+="You must enter a valid email address.\r\n";
	}else if(!isAnEmail(document.bookingForm.email.value)){
		errorMsg+="The email address you entered is not valid.\r\n";
	}
	if(document.bookingForm.roomType.value=="null"){
		errorMsg+="Please select a room type\r\n";
	}
	if(document.bookingForm.numPeople.value=="null"){
		errorMsg+="Please select how many people in your party\r\n";
	}
	var arrivalDate = document.bookingForm.arrivalDay.value+"/"
			+document.bookingForm.arrivalMonth.value+"/"
			+document.bookingForm.arrivalYear.value;
	if(arrivalDate.indexOf("null")>-1){
		errorMsg+="Please select an arrival date\r\n";
	}
	var depDate = document.bookingForm.depDay.value+"/"
			+document.bookingForm.depMonth.value+"/"
			+document.bookingForm.depYear.value;
	if(depDate.indexOf("null")>-1){
		errorMsg+="Please select an departure date\r\n";
	}
	//if any errors occur display message otherwise submit form
	if(errorMsg.length>0){
		alert(errorMsg);
	}else{
		//alert("all ok!");
		document.bookingForm.submit();
	}
}

