function checkForm(form) {
	var errorMsg = "";
	var titleReg = "(^(Mr|Mrs|Ms|Miss|Other)\$)";
	var contactMethodReg = "(^(Email|Phone\$))";
	var contactTimeReg = "(^(Morning|Afternoon|Evening\$))";	
	var prefTelReg = "(^(Mobile|Private|Business)\$)";
	var trueFalseReg = "(^(true|false)\$)";
	var yesNoReg = "(^(Yes|No)\$)";
	var thankYouDirReg = "(^(About_Us|Personal_Finance)\$)";

	var otherTitleMandatory = 0;
	var emailMandatory = 0;
	var phoneMandatory = 0;
	var errorCodeMandatory = 0;

errorMsg += isFieldValid(getSelectedOptionValue(form.title),"Your details - Title",1,5,"optionsList",titleReg);
if (getSelectedOptionValue(form.title) == "Other") {
	otherTitleMandatory = 1;
}
errorMsg += isFieldValid(form.other.value,"Your details - Other Title",otherTitleMandatory,15,"text");

errorMsg += isFieldValid(form.firstName.value,"Your details - First name",1,50,"text");
errorMsg += isFieldValid(form.surname.value,"Your details - Surname",1,50,"text");

if (form.nin.value != "") {
	errorMsg += isFieldValid(form.nin.value,"Your details - National ID",8,10,"numOnly");
}

errorMsg += isFieldValid(getSelectedOptionValue(form.contactMethod),"Your details - Preferred contact method",1,5,"optionsList",contactMethodReg);
if (getSelectedOptionValue(form.contactMethod) == "Email") {
	emailMandatory = 1;
}
errorMsg += isFieldValid(getSelectedOptionValue(form.contactTime),"Your details - Preferred contact time",1,9,"optionsList",contactTimeReg);

errorMsg += isFieldValid(form.emailAddress.value,"Your details -  Email address",emailMandatory,80,"email");

if ((getSelectedOptionValue(form.contactMethod) == "Phone") || (form.phone.value.length > 0)) {
	phoneMandatory = 10;
}

errorMsg += isFieldValid(getSelectedOptionValue(form.prefPhone),"Your details - Preferred telephone no.",1,8,"optionsList",prefTelReg);
errorMsg += isFieldValid(form.phone.value,"Your details -  Telephone number",phoneMandatory,14,"num");

errorMsg += isFieldValid(getCheckBoxValue(form.instructions),"Your enquiry - Detailed instructions",0,5,"optionsList",trueFalseReg);
errorMsg += isFieldValid(getCheckBoxValue(form.instructions),"Your enquiry - Problem",0,5,"optionsList",trueFalseReg);
if (eval(form.problem.checked) == true) {
	errorCodeMandatory = 1;
}
	
errorMsg += isFieldValid(form.errorCode.value,"Your enquiry -  Error code",errorCodeMandatory,6,"numOnly");
errorMsg += isFieldValid(form.comments.value,"Your enquiry -  Additional comments",0,1000,"alphaNum");

errorMsg += isFieldValid(form.thankYouPage.value,"Thank You Page",1,6,"num");
errorMsg += isFieldValid(form.thankYouDir.value,"Thank You Directory",1,20,"optionsList",thankYouDirReg);
errorMsg += isFieldValid(form.breadCrumb.value,"Breadcrumb",1,300,"alphaNum");
errorMsg += isFieldValid(form.submitEnquiry.value,"Submit Enquiry",1,3,"optionsList",yesNoReg);

	return errorMsg;
}

function submitForm(form) {
	setThankYouPage(form);
	setBreadCrumb(form);
	var errorMsg = checkForm(form);
	var reEnterMsg = " <p> Please click the 'Close' button and reenter it.</p>";
		
	if (isEmpty(errorMsg)) {
		form.submit();  
	} else {
		popup = window.open("","genericTechEnquiries_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/National/GlobalStyle.css' type='text/css'></head>");
		popup.document.write("<title>Contact us - Internet Banking</title>");
		popup.document.write("<body>");
		popup.document.write("<p><strong>Contact us - Internet Banking</strong></p>");
		popup.document.write(errorMsg);
		popup.document.write(reEnterMsg);
		popup.document.write("<center><form><input type=button value=Close onClick=javascript:window.close();></center></form>");
		popup.document.write("</body>");
		popup.document.write("</html>");
		popup.document.close();
	}
}

// Sets the correct thank you page depending on where the form is located
function setThankYouPage(form) {
	var dirStr = "About_Us";
	var thankYouNum = "85620";
	var strURL = document.URL;

	if (strURL.indexOf("Personal_Finance") > 0) {
		var dirStr = "Personal_Finance";
		var thankYouNum = "86576";
	}

	form.thankYouDir.value = dirStr;
	form.thankYouPage.value = thankYouNum;
}

function setBreadCrumb(form) {
	var breadCrumbStr = "<a href='/About_Us/0,,175,00.html' title='About Us'>About Us</a> &gt; <a href='/About_Us/0,,480,00.html' title='About Us &gt; Contact & Locate Us'>Contact & Locate Us</a> &gt; Internet Banking e-mail enquiry<br />";
	var strURL = document.URL;
	if (strURL.indexOf("0,,1036,00") > 0) {
		breadCrumbStr = "<a href='/About_Us/0,,175,00.html' title='About Us'>About Us</a> &gt; <a href='/About_Us/0,,480,00.html' title='About Us &gt; Contact & Locate Us'>Contact & Locate Us</a> &gt; Internet Banking e-mail enquiry<br />";
	} else if (strURL.indexOf("0,,12677,00") > 0) {
		breadCrumbStr = "<a href='/Personal_Finance/0,,2195,00.html' title='Personal Finance'>Personal Finance</a> &gt; <a href='/Personal_Finance/0,,9173,00.html' title='Personal Finance &gt; Contact us'>Contact us</a> &gt; Internet Banking e-mail enquiry<br />";
	} else if (strURL.indexOf("0,,82850,00") > 0) {
		breadCrumbStr = "<a href='/Personal_Finance/0,,2195,00.html' title='Personal Finance'>Personal Finance</a> &gt; <a href='/Personal_Finance/0,,81203,00.html' title='Personal Finance &gt; Internet Banking'>Internet Banking</a> &gt; <a href='/Personal_Finance/0,,82767,00.html' title='Personal Finance &gt; Internet Banking &gt; Support centre'>Support centre</a> &gt; Contact us<br />";
	} else if (strURL.indexOf("0,,85888,00") > 0) {
		breadCrumbStr = "<a href='/Personal_Finance/0,,2195,00.html' title='Personal Finance'>Personal Finance</a> &gt; <a href='/Personal_Finance/0,,81203,00.html' title='Personal Finance &gt; Internet Banking'>Internet Banking</a> &gt; <a href='/Personal_Finance/0,,85831,00.html' title='Personal Finance &gt; Internet Banking &gt; Need help?'>Need help?</a> &gt; Contact us<br />";
	}

	form.breadCrumb.value = breadCrumbStr;
}
