<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->

function submitFrmContact() {
			MM_validateForm('firstName','','R', 'surname','','R', 'email','','RisEmail', 'phone','','RisNum'); 
			return document.MM_returnValue;
}

function submitFrmSubscribe() {
		if (document.contactus.moreInfo.checked&&!document.contactus.consent.checked) { 
			alert('You must provide consent to subscribe to the newsletter.'); 
			return false; 
		} 
		else { 
			MM_validateForm('firstName','','R', 'surname','','R', 'email','','RisEmail', 'phone','','isNum'); 
			return document.MM_returnValue;
		}
}
function isValidated(frmName) {
	function isEmail() { var a = isEmail.arguments[0]; return /(\w+)@(\w+)[.](\w+)/.test(a); }
	function isEmpty() { var a = isEmpty.arguments[0];	return ((a==null) || (a.length==0) || /^\a+$/.test(a)); }
	function isPaddedNumber() { var a = isPaddedNumber.arguments[0]; return (a.search(/[^ \d]/) == -1); }
	function isPhoneNumber() { var a = isPhoneNumber.arguments[0]; return (a.search(/[^ \d\+\(\)-\.]/) == -1); }

	var frm = eval("document."+frmName);
	var REValidEmail = /(^.+@[^\.].*\.[a-z]{2,}$)/;
	var REValidPhone = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,4}\)?))(-| )?(\d{3,4})(-| )?(\d{3,4})(( x| ext)\d{1,5}){0,1}$/;
	switch (frm.name.toLowerCase()) {
		case 'contactus':
			if (isEmpty(frm.firstName.value)) { 
				alert('Please specify your First Name');
				return false;
			}
			else if (isEmpty(frm.surname.value)) { 
				alert('Please specify your Surname');
				return false;
			}
			else if (!isEmpty(frm.phone.value)) {
				if (!isPhoneNumber(frm.phone.value)) {
					alert('Please specify a valid Phone number');
					return false;
				}
			}
			else if (isEmpty(frm.email.value)) {
				alert('Please specify an Email address');
				return false;
			}
			else if (!isEmpty(frm.email.value) && !isEmail(frm.email.value)) {
				alert('Please specify a valid Email address');
				return false;
			}
			break;
		case 'subscribe':
			if (!frm.consent.checked) { 
				alert('You must provide consent to subscribe to the newsletter.'); 
				return false; 
			} 
			else if (isEmpty(frm.firstName.value)) { 
				alert('Please specify your First Name');
				return false;
			}
			else if (isEmpty(frm.surname.value)) { 
				alert('Please specify your Surname');
				return false;
			}
			else if (!isEmpty(frm.phone.value)) {
				if (!isPhoneNumber(frm.phone.value)) {
					alert('Please specify a valid Phone number');
					return false;
				}
			}
			else if (isEmpty(frm.email.value)) {
				alert('Please specify an Email address');
				return false;
			}
			else if (!isEmpty(frm.email.value) && !isEmail(frm.email.value)) {
				alert('Please specify a valid Email address');
				return false;
			}
			break;
		case 'enquiry':
			if (frm.firstName.value.length==0) {
				alert("'First Name' must be specified in order to submit your enquiry.");
				frm.firstName.focus();
				return false;
			}
			if (frm.surname.value.length==0) {
				alert("'Surname' must be specified in order to submit your enquiry.");
				frm.surname.focus();
				return false;
			}
			if (frm.phone.value.length==0) {
				alert("'Telephone' must be specified in order to submit your enquiry.");
				frm.phone.focus();
				return false;
			}
			else if (!REValidPhone.test(frm.phone.value)) {
				alert('Please specify a valid Phone number, including area code.');
				frm.phone.focus();
				return false;
			}
			if (frm.email.value.length==0) {
				alert("'Email' must be specified in order to submit your enquiry.");
				frm.email.focus();
				return false;
			}
			else if (!REValidEmail.test(frm.email.value)) {
				alert("A valid Email must be entered in order to submit your enquiry.");
				frm.email.focus();
				return false;	
			}
			if (frm.enquiryType.selectedIndex==0) {
				alert("'Location Preference' must be specified in order to submit your enquiry.");
				frm.enquiryType.focus();
				return false;
			}
/*
			if (!frm.interest[0].checked&&!frm.interest[1].checked&&!frm.interest[2].checked) {
				alert("'Enquiry Type' must be specified in order to submit your enquiry.");
				return false;
			}*/
			/*
			if (frm.timeframe.selectedIndex==0) {
				alert("'Timeframe' must be specified in order to submit your enquiry.");
				frm.timeframe.focus();
				return false;
			}//*/
/*			if (frm.officeSize.selectedIndex==0) {
				alert("'Preferred Office Size' must be specified in order to submit your enquiry.");
				frm.officeSize.focus();
				return false;
			}
			if (frm.accommodate.selectedIndex==0) {
				alert("'Employees to Accommodate' must be specified in order to submit your enquiry.");
				frm.accommodate.focus();
				return false;
			}
			if (frm.heardAbout.selectedIndex==0) {
				alert("'How did you first hear about HQ NewQuay?' must be specified in order to submit your enquiry.");
				frm.heardAbout.focus();
				return false;
			}*/
			/*consentNoKeep
			if (frm.consentHQNQ.checked!=true) {
				alert("You must provide your consent to receive information about HQ NewQuay and other commercial properties in order to submit your enquiry.");
				frm.consentHQNQ.focus();
				return false;
			}
			if (frm.consentMAB.checked!=true) {
				alert("You must provide your consent to receive information about MAB Corporation in order to submit your enquiry.");
				frm.consentMAB.focus();
				return false;
			}
			*/
			
			if ((frm.consentHQNQ.checked!=true) && (frm.consentMAB.checked!=true) && (frm.consentNoKeep.checked!=true))
			{
				alert("You must let us know whether you would like to receive further information from MAB / New Quay.");
				frm.consentMAB.focus();
				return false;
			}
			
			break;
	}
	return true;
} //*/
