// JavaScript Validation for Contact Form
//Check the enquiry form is filled in correctly
function CheckForm () { 

	//Initialise variables
	var errorMsg = "";
			 	
	//Check for Title
	myOption = -1;
	for (i=bookform.Title.length-1; i > -1; i--) {
	if (bookform.Title[i].checked) {
	myOption = i; i = -1;
	}
	}
	if (myOption == -1) {
		errorMsg += "\n Select a title";
	}

	
	//Check for Surname
	if (document.bookform.Surname.value == ""){
		errorMsg += "\n Enter your surname(family name)";	
	}	

	//Check for First_Name
	if (document.bookform.First_Name.value == ""){
		errorMsg += "\n Enter your first name";	
	}
	
	//Check for DOB
	if (document.bookform.DOB.value == "dd/mm/yy"){
		errorMsg += "\n Enter your date of birth";	
	}

	//Check for Nationality
	if (document.bookform.Nationality.value == ""){
		errorMsg += "\n Select your nationality";	
	}
	
	//Check for Tel_no
	if (document.bookform.Tel_no.value == ""){
		errorMsg += "\n Enter your daytime phone number";	
	}
	
	//Check for Emergency
	if (document.bookform.Emergency.value == ""){
		errorMsg += "\n Enter your emergency phone number";	
	}

	//Check for an e-mail address and that it is valid
	if ((document.bookform.Email.value == "") || (document.bookform.Email.value.length > 0 && (document.bookform.Email.value.indexOf("@",0) == - 1 || document.bookform.Email.value.indexOf(".",0) == - 1))) { 
		errorMsg += "\n Enter your valid e-mail address";
	}
	
		//Check for Address
	if (document.bookform.Address.value == ""){
		errorMsg += "\n Enter your address";	
	}

	//Check for Passport number
	if (document.bookform.passportNum.value == ""){
		errorMsg += "\n Enter your passport number";	
	}

	//Check for English
	if (document.bookform.English.value == ""){
		errorMsg += "\n Select your level of English";	
	}

	//Check for Course
	if (document.bookform.Course.value == ""){
		errorMsg += "\n Select the course you wish to attend";	
	}
	
	//Check for Start_Date
	if (document.bookform.Start_Date.value == "dd/mm/yy"){
		errorMsg += "\n Enter the course start date";	
	}
	
	//Check for End_Date
	if (document.bookform.End_Date.value == "dd/mm/yy"){
		errorMsg += "\n Enter the course end date";	
	}

	//Check for No_Weeks
	if (document.bookform.No_Weeks.value == ""){
		errorMsg += "\n Enter the total number of weeks";	
	}
	
	//Check for Accom
	if (document.bookform.Accom.value == ""){
		errorMsg += "\n Select the type of accommodation";	
	}
	
	//Check for Transfer
	if (document.bookform.Transfer.value == ""){
		errorMsg += "\n Select the type of transfer";	
	}
	
	//Check for Payment
	if (document.bookform.Payment.value == ""){
		errorMsg += "\n Select payment information";	
	}
	
	//Check for Method
	if (document.bookform.Method.value == ""){
		errorMsg += "\n Select payment method";	
	}
	
	//Check for Read_Terms
	if (!document.bookform.Read_Terms.checked){
		errorMsg += "\n Please confirm you agree to our terms and conditions";	
	}
	

					
	//If there is a problem with the form then display an error
	if (errorMsg != ""){
		msg = "Your booking has not been processed as the form has not been completed as required.\n\n";

		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
