function checkForm(form) {
	
	var errorMsg = "";
	var cityReg = "(^(Hong Kong|Singapore|Japan|China|India|Other)\$)";
	var contactFormReg = "(^(Hong Kong|Singapore|Japan|China|India|nabCapital)\$)";
	var yesNoReg = "(^(Yes|No\$))";
	var phoneMandatory = 1;

errorMsg += isFieldValid(form.contactForm.value,"Contact Form",0,20,"optionsList",contactFormReg);

if (form.contactForm.value == "Japan") {
	phoneMandatory = 0;
}

errorMsg += isFieldValid(form.givenName.value,"Given Name",1,50,"text");
errorMsg += isFieldValid(form.surname.value,"Surname",1,50,"text");
errorMsg += isFieldValid(form.emailAddress.value,"Your email address",1,50,"email");
errorMsg += isFieldValid(form.countryCode.value,"Phone Country code",phoneMandatory,3,"num");
errorMsg += isFieldValid(form.phone.value,"Phone Number",phoneMandatory,10,"num");
errorMsg += isFieldValid(form.city.value,"City",1,20,"optionsList",cityReg);
errorMsg += isFieldValid(form.request.value,"Your enquiry",1,1000,"alphaNum");
errorMsg += isFieldValid(form.meeting.value,"Arrange a meeting",1,3,"optionsList",yesNoReg);

	return errorMsg;
}

function submitForm(form) {
	setContactForm(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("","enquiry_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/NABAsia/ContentStyle.css' type='text/css'></head>");
		popup.document.write("<title>E-mail enquiry</title>");
		popup.document.write("<body><div class='validationMsg'>");
		
		popup.document.write("<strong>E-mail enquiry</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();></center></form>");
		popup.document.write("</div></body>");
		popup.document.write("</html>");
		popup.document.close();
	}
}

function setContactForm(form) {
	var contactForm = "";
	var strURL = document.URL;

	if (strURL.indexOf("87679") > 0) {
		var contactForm = "Hong Kong";
	} else if (strURL.indexOf("87680") > 0) {
		var contactForm = "Singapore";
	} else if (strURL.indexOf("87681") > 0) {
		var contactForm = "Japan";
	} else if (strURL.indexOf("87682") > 0) {
		var contactForm = "China";
	} else if (strURL.indexOf("87683") > 0) {
		var contactForm = "India";
	} else if (strURL.indexOf("87684") > 0) {
		var contactForm = "nabCapital";
	}

	form.contactForm.value = contactForm;
}
