

function checkForm(form) {
		
	var errorMsg = "";	

	var stateReg = "(ACT|NSW|NT|QLD|SA|TAS|VIC|WA|)";
	var contactMethodReg = "(home|work|mobile)";
	var titleReg = "(Mr|Mrs|Ms|Miss|Dr)";
	var specialityReg = "(^(Acupuncturist|Advanced Dental Technician|Chiropractor|Clinical Psychologist|Dental Prosthetist|Dietitian|Dispensing Optometrist|Endodontist|General Dentist|Myotherapist|Naturopath|Occupational Therapist|Optical Dispenser|Osteopath|Paediatric Dentist|Periodontist|Physiotherapist|Podiatrist|Prosthodontist|Psychologist|Remedial Massage Therapist|Speech Pathologist|Other)\$)";
	var prefContactTimeReg = "(^(morning|afternoon|evening)\$)";
	var prefContactMethodReg = "(^(email|phone|mail)\$)";
	var prefContactDayReg = "(^(monday|tuesday|wednesday|thursday|friday)\$)";
	var yesNoReg = "(^(yes|no)\$)";

	//Validate required fields on form
	errorMsg +=isFieldValid(getSelectedOptionValue(form.title), "Title",1,5,"optionsList",titleReg);	
	errorMsg += isFieldValid(form.firstName.value, "First name",1,50, "text");	
	errorMsg += isFieldValid(form.surname.value, "Surname",1,50, "text");			
	errorMsg += isFieldValid(form.busName.value, "Business Name",1, 50, "alphaNum");
	errorMsg += isFieldValid(form.address.value, "Address",1,50, "alphaNum");
	errorMsg += isFieldValid(form.suburb.value, "Suburb",1,50, "text");
	errorMsg += isFieldValid(getSelectedOptionValue(form.state), "State",2,3, "optionsList",stateReg);
	errorMsg += isFieldValid(form.postcode.value, "Post code",4,4,"num");
	errorMsg += isFieldValid(form.speciality1.value, "Speciality",1,26,"optionsList",specialityReg);
	errorMsg += isFieldValid(getSelectedOptionValue(form.prefPhone),"Preferred contact phone",1,6,"custom",contactMethodReg);
	errorMsg += isFieldValid(form.phone.value, "Phone",10,10, "num");
	errorMsg += isFieldValid(form.emailAddress.value, "Email address",0,80, "email");
	errorMsg += isFieldValid(getSelectedOptionValue(form.prefContactTime),"Preferred contact time",0,9,"custom",prefContactTimeReg);
	errorMsg += isFieldValid(getSelectedOptionValue(form.prefContactMethod),"Preferred contact method",0,5,"custom",prefContactMethodReg);
	errorMsg += isFieldValid(getSelectedOptionValue(form.prefContactDay),"Preferred contact day",0,9,"custom",prefContactDayReg);
	errorMsg += isFieldValid(getRadioButtonValue(form.termUpgrade),"Need terminal upgraded",1,3,"optionsList",yesNoReg);	
	errorMsg += isFieldValid(getRadioButtonValue(form.hicapsTermup),"HICAPS/Medicare Easyclaim Terminal",1,3,"optionsList",yesNoReg);
	errorMsg += isFieldValid(form.addComments.value, "Additional Comments","0", "500", "alphaNum");	

	if ((getRadioButtonValue(form.termUpgrade) == "yes") && (getRadioButtonValue(form.hicapsTermup) == "yes"))
	{
		errorMsg += "You have indicated <strong>you have</strong> and <strong>do not have HICAPS</strong>, these should be mutually exclusive of one another.<br /><br />"
	}

	if ((getRadioButtonValue(form.termUpgrade) == "no") && (getRadioButtonValue(form.hicapsTermup) == "no"))
	{
		errorMsg += "You have not indicated <strong>you have</strong> and <strong>do not have HICAPS</strong>, these should be mutually exclusive of one another.<br /><br />"
	}
	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)) {
//		globalWindowOpen('','medicareClaim_win',350,300,1,0,0,1,0,0,0,300,300);
		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
	}
}
