
function presence_check(formfield) {
// check for empty fields
	if (formfield.value == "") {
		return false;
	}
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com (.co.uk)");
		formField.focus();
		result = false;
	}
   
  return result;

}


function validateRegistration(theForm) {
	if (presence_check(theForm.customer_first) ==  false) {
		alert ('Please enter your first name, thank you');
		return false;
	}
	if (presence_check(theForm.customer_surname) == false) {
		alert ('Please enter your surname, thank you');
		return false;
	}
	if (presence_check(theForm.booking_people) == false) {
		alert ('Please specify the number of people staying at the house, thank you');
		return false;
	} else if (theForm.booking_people.value > 10) {
		alert ('The maximum capacity is 10 people')
		return false;	
	}
	
	if (theForm.booking_people.value == 0) {
		alert ('Please specify the number of people staying at the house, thank you');
		return false;
	}
	
	if (presence_check(theForm.customer_address1) == false) {
		alert ('Please enter your address');
		return false;
	}
	if (presence_check(theForm.customer_postcode) == false) {
		alert ('Please enter your zip/post code, thank you');
		return false;
	}
	
	if (presence_check(theForm.customer_evecontact) == false) {
		alert ('Please enter your evening contact number, thank you');
		return false;
	}
	
	if ( theForm.customer_email.value != "" ) {
		// check email address is valid
		if (!validEmail(theForm.customer_email, "customer_email", true)) {
			return false;
		}
	}	
	return true;
}


function validatePrice (theform) {
	if (theform.booking_nights.value == "") {
		alert('Please enter the number of nights you would like to stay');
		return false;
	}				
	return true;
} 



function validateTerms (theForm) {
	with(theForm) {
		// check terms and conditions have been agreed
		if (booking_terms.checked) {
			//alert('terms and conditions accepted');
			alert('You will now be forwarded our Moneybookers Gateway. Once your transaction is complete please be patient and wait to be redirected back to dreamofdisney.com.\nThis is automatic. Your booking WILL NOT be confirmed if you exit before returning. Thank you.');
			return true;
		} else {
			alert('Please agree to our terms and conditions if you wish to proceed with your holiday booking, thank you');
			return false;
		}// end if	
	}
}// end function
