function CheckEmail(email) {
	AtPos = email.indexOf("@");
	StopPos = email.lastIndexOf(".");
	Space = email.indexOf(" ");
		
	if (email == "") 
		return false;
		
	if (AtPos == -1 || StopPos == -1 || Space != -1) 
		return false;
		
	if (StopPos == email.length - 1)
		return false;
		
	if (StopPos < AtPos) 
		return false;
		
	if (StopPos - AtPos == 1) 
		return false;
		
	return true;
}

function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}
  
function FormValidator(theForm)
{
  if (TrimString(theForm.subject.value) == "")
  {
    alert("Please enter a subject for your email.");
  	return false;
  }
  
  if (!CheckEmail(TrimString(theForm.email.value)))
  {
    alert("Please enter a valid email address.");
  	return false;
  }
  
  if (TrimString(theForm.message.value) == "")
  {
    alert("Please enter a message for your email.");
  	return false;
  }
  
  return (true);
}
