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;
}

function checkEmail(emailStr) {
var emailSyntax = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var matchArray = emailStr.match(emailSyntax);
if (matchArray == null) {
alert("That 'Email address' is in the wrong format. Please check it to continue.");
return false;
}
return true;
}

function checkForm(theForm){
	if (trim(theForm.q1.value) == ""){
		alert("You must answer question 1.");
		theForm.q1.focus();
		return false;
	}
	if (trim(theForm.q2.value) == ""){
		alert("You must answer question 2.");
		theForm.q2.focus();
		return false;
	}
	if (trim(theForm.q3.value) == ""){
		alert("You must answer question 3.");
		theForm.q3.focus();
		return false;
	}
	else if (trim(theForm.eName.value) == ""){
		alert("You must enter your 'Name' to continue.");
		theForm.eName.focus();
		return false;
	}
	else if (trim(theForm.eAddy.value) == ""){
		alert("You must enter an 'Address' to continue.");
		theForm.eAddy.focus();
		return false;
	}
	else if (trim(theForm.eTitle.value) == ""){
		alert("You must enter your job title to continue.");
		theForm.eTitle.focus();
		return false;
	}
	else if (trim(theForm.eCompany.value) == ""){
		alert("You must enter your company name to continue.");
		theForm.eCompany.focus();
		return false;
	}
	else if (trim(theForm.eEmail.value) == ""){
		alert("You must enter an 'Email address' to continue.");
		theForm.eEmail.focus();
		return false;
	}
	else if (checkEmail(theForm.eEmail.value)==false){
		theForm.eEmail.focus();
		return false;
	}
	else if (trim(theForm.eNo.value) == ""){
		alert("You must enter a 'Telephone number' to continue.");
		theForm.eNo.focus();
		return false;
	}
	return true;
}