/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 * 
 * isValid() function -- Wrapper function for form validation
 *
 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
function isValid(){
  var torf = false;
  if( isFNameValid() ){
    if( isEmailValid() ){
      torf = true;
    }
  }
  return torf;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 * 
 * isFNameValid() -- Verifys the user enters a value, not left blank
 *
 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
function isFNameValid() {
  var fName = document.getElementById('name');
  if( isEmpty(fName.value) ){
    alert("Name is a required field.");
    fName.focus();
    return false;
  } else {
    return true;
  }
}


/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 * 
 * isEmailValid() function
 *
 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
function isEmailValid(){
  var torf = false;
  var eMail = document.getElementById('email');
  //Did they enter an email address???
  if( eMail.value != "" ){
    //RegExp; Does the email address meet basic format?
    var re = /[a-z0-9]\w{1,}@[a-z0-9-]{3,}\.[a-z]{3}/i
    if( re.test(eMail.value) ){ 
      //RegExp; Does the email end with one of the following extensions?
      re = /com$|net$|edu$|gov$|mil$|org$/i;
      if( re.test(eMail.value) ){
        torf = true;
      }
    }
  }
  //Still False???
  if( !torf ){
    alert("You must supply a valid email address.");
    eMail.focus();
  }
  return torf;
}

function isEmpty(str){
  if((str == null) || (str == "")){
    return true;
  } else {
    return false;
  }
}
