/*remove excess white space*/
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

/*check email format, returns true if valid*/
function checkEmail(emailStr)
{
	var emailSyntax = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var matchArray = emailStr.match(emailSyntax);
	if (matchArray == null)
	{
		return false;
	}
	return true;
}

/*check form details*/
function CheckForm() {
	if (trim(document.getElementById('contactname').value) == '') {
		alert('Please enter your name');
		document.getElementById('contactname').focus();
		return false;
	}
	if (!checkEmail(document.getElementById('contactemail').value)) {
		alert('Please enter a valid email address');
		document.getElementById('contactemail').focus();
		return false;
	}
	if (trim(document.getElementById('contactenquiry').value) == '') {
		alert('Please enter your enquiry');
		document.getElementById('contactenquiry').focus();
		return false;
	}
	if (trim(document.getElementById('securityCode').value) == '') {
		alert('Please type in the security code you see in the image');
		document.getElementById('securityCode').focus();
		return false;
	}
	return true;
}