function checkForm(form) {
		
	var errorMsg = "";	
	var contactMethodReg = "(home|work|mobile)";
	var titleReg = "(Mr|Mrs|Ms|Miss|Dr|Other)";
	var prefContactTimeReg = "(^(morning|afternoon|evening)\$)";
	var prefContactMethodReg = "(^(email|phone)\$)";
	var otherMin = 0;
	var feedbackReg = "(^(Compliment|Complaint|Suggestion)\$)";

	var contactDayReg = "(^([12][0-9]|3[01]|0?[1-9])\$)";
	var contactMonthReg = "(^(01|02|03|04|05|06|07|08|09|10|11|12)\$)";
	var contactYearReg = "(((19|20)[0-9][0-9])\$)";
	var currentDate = new Date();


	//Validate required fields on form
	errorMsg +=isFieldValid(getSelectedOptionValue(form.title), "Title",1,5,"optionsList",titleReg);
	if (getSelectedOptionValue(form.title)=="Other")
	{
		otherMin = 1;
	}
	errorMsg +=isFieldValid(form.otherTitle.value, "Other title",otherMin,15,"text");
	errorMsg += isFieldValid(form.firstName.value, "First name",1,50, "text");	
	errorMsg += isFieldValid(form.surname.value, "Surname",1,50, "text");
	errorMsg += isFieldValid(getSelectedOptionValue(form.prefContactMethod),"Preferred contact method",1,5,"custom",prefContactMethodReg);
	errorMsg += isFieldValid(getSelectedOptionValue(form.prefContactTime),"Preferred contact time",0,9,"custom",prefContactTimeReg);
	errorMsg += isFieldValid(form.contactDay.value,"Contact day",0,2,"custom",contactDayReg);
	errorMsg += isFieldValid(form.contactMonth.value,"Contact month",0,2,"custom",contactMonthReg);
	errorMsg += isFieldValid(form.contactYear.value,"Contact year",0,4,"custom",contactYearReg);
	var contactDate = new Date(form.contactYear.value,form.contactMonth.value,form.contactDay.value);
	if (form.contactYear.value!= "") {
		if (contactDate < currentDate) 	{
			errorMsg+= "The <strong>Contact date </strong> is in the past.<br /><br />";
		}
	}
	errorMsg += isFieldValid(getSelectedOptionValue(form.prefPhone),"Preferred contact phone",0,6,"custom",contactMethodReg);
	errorMsg += isFieldValid(form.phone.value, "Phone",0,10, "num");
	errorMsg += isFieldValid(form.emailAddress.value, "Email address",1,80, "email");
	errorMsg += isFieldValid(getSelectedOptionValue(form.feedbackType),"Feedback type",9,10,"custom",feedbackReg);
	errorMsg += isFieldValid(form.comments.value, "Comments","0", "2000", "alphaNum");	
	if ((getSelectedOptionValue(form.feedbackType) == "Compliment") || (getSelectedOptionValue(form.feedbackType) == "Suggestion"))
	{
		thankYouPage = "95203";
	} else {
		thankYouPage = "95204";
	}

	return errorMsg;
}

function submitForm(form) {

	var errorMsg = checkForm(form);
	var reEnterMsg = " <p> Please select the 'Close' button below to return to the email form.</p>";
	var formTitle = "Contact Us Form";
	
	if (isEmpty(errorMsg)) {
		form.submit();
   
	} else {

		popup = window.open("","contactFormFinish_win","width=400,height=400,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");

		popup.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><html><head>");
		popup.document.write("<link rel='stylesheet' href='/css/HICAPS/GlobalStyle.css' type='text/css'></head>");
		popup.document.write("<title>");
		popup.document.write("</title>");
		popup.document.write("<body>");
		popup.document.write("<strong>");
		popup.document.write("</strong><br><br>");
		popup.document.write(errorMsg);
		popup.document.write("<br>");
		popup.document.write(reEnterMsg);
		popup.document.write("<center><form><input type=button value=Close onClick='javascript:window.close();opener.focus();'></center></form>");
		popup.document.write("</body>");
		popup.document.write("</html>");
		popup.document.close();
		popup.focus(); // added to give focus to popup window
	}
}
