String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/,""); };

function validateForm(valForm){
  if(valForm.firstname.value.trim() == ""){
    alert("First Name is a required field.");
    return false;
  }

  if(valForm.lastname.value.trim() == ""){
    alert("Last Name is a required field.");
    return false;
  }

  if(valForm.emailaddress.value.trim() != "" && !(/^([a-zA-Z])+([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(valForm.emailaddress.value.trim()))){
    alert("If you are choosing to enter an email address, please enter a valid address.  If not, please leave the Email Address field empty");
    return false;
  }
  return true;
}
