// Design & Code (c) take2hikes


/* -------------------------------------
/ Function: isEmpty
/ Purpose: Checks for empty fields, if
/          empty function alerts user.
/ Variables: passed field to be checked.
/ -------------------------------------*/
function isEmpty(strfield1, strfield2) {
  
  //change "field1, field2 and field3" to your field names
  strfield1 = document.forms[0].name.value
  strfield2 = document.forms[0].message.value
  
  //name field
  if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
  {
    alert("\"FULL NAME\" is a required field.\nPlease amend and retry.")
    return false;
  }
  
  //message field
  if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
  {
    alert("\"MESSAGE\" is a required field.\nPlease amend and retry.")
    return false;
  }
  return true;
}

/* -------------------------------------
/ Function: isValidEmail
/ Purpose: Checks for valid email, if
/          invalid function alerts user.
/ Variables: passed email to be checked.
/ -------------------------------------*/
function isValidEmail(strEmail){
  validRegExp = /^[a-z0-9_.]+@[a-z0-9.-]+\.(?:[a-z]{2}|com|org|net|gov|mil|biz|info)$/i;  
  strEmail = document.forms[0].email.value;
  
  // search email text for regular exp matches
  if (strEmail.search(validRegExp) == -1)
  {
    alert('A valid e-mail address is required.\nPlease amend and retry');
    return false;
  }
  return true;
}

/* -------------------------------------
/ Function: check
/ Purpose: Calls field check funcitons.
/ Variables: passed form info by onSubmit
/            from html page.
/ -------------------------------------*/
function check(form)
{
  if (isEmpty(form.name))
  {
    if (isValidEmail(form.email))
	 {
      if (isEmpty(form.message))
		{
        return true;
      }
    }
  }
  
  return false;
}