function validateContactForm(){
    // Make quick references to our fields
    var formDOMObj = document.humanauthentication.elements;

// Check each input in the order that it appears in the form!
  if(isEmpty(formDOMObj["first_name"], "Please enter your first name!")){ return false; }
  if(isEmpty(formDOMObj["last_name"], "Please enter your last name!")){ return false; }
  if(!emailValidator(formDOMObj["email"], "Please enter a valid email address!")){ return false; }
  if(isEmpty(formDOMObj["how_may_we_help_you"], "How may we help you?")){ return false; }

  //Everything checks out. Send it.
  return true;

}

function validateApplication(){
    // Make quick references to our fields
    var formDOMObj = document.humanauthentication.elements;

    //Get todays date and format it
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    compareDate = year + '-' + month + '-' + day;
    day += '';
    month += '';
    if ((day.length == 1) && (month.length == 1)) {
        compareDate = year + '-0' + month + '-0' + day;
    }
     else {
         if (month.length == 1) {
             compareDate = year + '-0' + month + '-' + day;
         }
         else {
             if (day.length == 1) {
                 compareDate = year + '-' + month + '-0' + day;
               }
         }
     }

// Check each input in the order that it appears in the form!
  //Everything checks out. Send it.
  if(isEmpty(formDOMObj["date_available"], "Please enter the date you are available to begin work!")){ return false; }
  if(isEmpty(formDOMObj["last_name"], "Please enter your last name!")){ return false; }
  if(isEmpty(formDOMObj["first_name"], "Please enter your first name!")){ return false; }
  if(isEmpty(formDOMObj["area_code"], "Please enter an area code!")){ return false; }
  if(isNumeric(formDOMObj["area_code"], "Please enter a numeric area code!")){ return false; }
  if(isEmpty(formDOMObj["phone_number"], "Please enter your phone number!")){ return false; }
  if(isNumeric(formDOMObj["phone_number"], "Please enter a numeric phone number!")){ return false; }
  if(isEmpty(formDOMObj["address"], "Please enter your address!")){ return false; }
  if(isEmpty(formDOMObj["city"], "Please enter your city!")){ return false; }
  if(isEmpty(formDOMObj["postal_code"], "Please enter your postal code!")){ return false; }
  if(comboCheck(formDOMObj["canada_work_eligible"], "Are You Legally Eligible To Work In Canada?", 3)){ return false; }
  if(comboCheck(formDOMObj["bonding_eligible"], "Are You Eligible For Bonding?", 3)){ return false; }
  if(isEmpty(formDOMObj["qualifications"], "Please enter your qualifications for employment!")){ return false; }
  if(comboCheck(formDOMObj["previously_employed"], "Have you ever been employed by Calgary Italian Bakery before?")){ return false; }
  if(comboCheckYesOption(formDOMObj["previously_employed"])){
    if(isEmpty(formDOMObj["previously_employed_from"],"What date did you first start working for Calgary Italian Bakery",compareDate)){ return false; }
    if(checkDate(formDOMObj["previously_employed_from"],"What date did you first start working for Calgary Italian Bakery",compareDate)){ return false; }
    if(compareDates(formDOMObj["previously_employed_from"],formDOMObj["previously_employed_to"],"What date did you last work for Calgary Italian Bakery")){ return false; }
    if(isEmpty(formDOMObj["previously_employed_position"],"What was your position when you left?")){ return false; }
  }
  if(isEmpty(formDOMObj["referral"], "What source referred you to Calgary Italian Bakery?")){ return false; }
  if(comboCheck(formDOMObj["shift_work"], "Will You Work Shift Work?")){ return false; }
  if(comboCheck(formDOMObj["relocate"], "Are You Willing To Relocate?")){ return false; }
  if(comboCheck(formDOMObj["contact_employer"], "May We Contact Your Present Employer?")){ return false; }
  if(isEmpty(formDOMObj["reference_name_1"], "What is your first reference's name?")){ return false; }
  if(isEmpty(formDOMObj["reference_phone_1"], "What is your first reference's phone number?")){ return false; }
  if(isNumeric(formDOMObj["reference_phone_1"], "Enter a numeric value for your first reference's phone number!")){ return false; }
  if(isEmpty(formDOMObj["reference_occupation_1"], "What is your first reference's occupation?")){ return false; }
  if(isEmpty(formDOMObj["reference_name_2"], "What is your second reference's name?")){ return false; }
  if(isEmpty(formDOMObj["reference_phone_2"], "What is your second reference's phone number?")){ return false; }
  if(isNumeric(formDOMObj["reference_phone_2"], "Enter a numeric value for your second reference's phone number!")){ return false; }
  if(isEmpty(formDOMObj["reference_occupation_2"], "What is your second reference's occupation?")){ return false; }
  if(comboCheck(formDOMObj["declaration_true"], "Do you declare that the information you have provided is true and complete?")){ return false; }
  if(comboCheckYes(formDOMObj["declaration_true"], "You must declare that the information you have provided is true and complete?")){ return false; }
  return true;

}

function noAlpha(e,fieldin,fieldout,amount)
{
  var formDOMObj = document.registration75.elements;
  var keynum;
  var keychar;
  var numcheck;
  if(window.event) // IE
  {
    keynum = e.keyCode;
  }
  else if(e.which) // Netscape/Firefox/Opera
  {
    keynum = e.which;
  }
  if (keynum == 9) {
    formDOMObj["totalregistration"].value = (formDOMObj["adultamount"].value * 1) + (formDOMObj["satchildamount"].value * 1) + (formDOMObj["satchildlunchamount"].value * 1) + (formDOMObj["satchildbbqamount"].value * 1) + (formDOMObj["sunchildamount"].value * 1);
    return true;
  }
  keychar = String.fromCharCode(keynum);
  numcheck = /\d/;
  if (numcheck.test(keychar) == false) {
    return false;
  }
  if(fieldin.name == "numadults" && keychar == "0") {keychar = 1;}
  fieldin.value = keychar;
  fieldout.value=keychar*amount;
  formDOMObj["totalregistration"].value = (formDOMObj["adultamount"].value * 1) + (formDOMObj["satchildamount"].value * 1) + (formDOMObj["satchildlunchamount"].value * 1) + (formDOMObj["satchildbbqamount"].value * 1) + (formDOMObj["sunchildamount"].value * 1);
  return true;
}



function isCheckedLenDependency(elem1, elem2, helperMsg){
  if(elem1.checked){
    if(elem2.value.length == 0){
      alert(helperMsg);
          elem2.focus(); // set the focus to this input
          return true;
      }
  }
    return false;
}


function isCheckedNumDependency(elem1, elem2, helperMsg){
  if(elem1.checked){
    if(elem2.value == 0){
      alert(helperMsg);
          elem2.focus(); // set the focus to this input
          return true;
      }
  }
    return false;
}

function isEmpty(elem, helperMsg){
    var theElem;
    theElem = elem.value.replace(" ", "");
    if(theElem.length == 0){
        alert(helperMsg);
        elem.focus(); // set the focus to this input
        return true;
    }
    return false;
}

function isEmptyFiller(elem1, elem2){
    if(elem2.value.length == 0){
    elem2.value = elem1.value;
        return true;
    }
    return false;
}

function isNumeric(elem, helperMsg){
    var numericExpression = /^[0-9-]+$/;
    if(elem.value.match(numericExpression)){
        return false;
    }else{
        alert(helperMsg);
        elem.focus();
        return true;
    }
}

function comboCheck(elem, helperMsg){
    if(elem.options[elem.selectedIndex].value != 3){
        return false;
    }else{
        alert(helperMsg);
        elem.focus();
        return true;
    }
}

function checkDate(elem, helperMsg, compareDate){
    theDate = elem.value + '';
    compareDate += '';
    if(theDate != compareDate){
        return false;
    }else{
        alert(helperMsg);
        elem.focus();
        return true;
    }
}

function compareDates(elemFrom, elemTo, helperMsg){
    if(elemFrom.value < elemTo.value){
        return false;
    }else{
        alert(helperMsg);
        elemTo.focus();
        return true;
    }
}

function comboCheckYesOption(elem){
    if(elem.value == 1){
        return true;
    }else{
        return false;
    }
}


function comboCheckYes(elem, helperMsg){
    if(elem.value == 1){
        return false;
    }else{
        alert(helperMsg);
        elem.focus();
        return true;
    }
}

function isAlphabet(elem, helperMsg){
    var alphaExp = /^[\sa-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function isAlphanumeric(elem, helperMsg){
    var alphaExp = /^[0-9a-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function lengthRestriction(elem, min, max){
    var uInput = elem.value;
    if(uInput.length >= min && uInput.length <= max){
        return true;
    }else{
        alert("Please enter between " +min+ " and " +max+ " characters");
        elem.focus();
        return false;
    }
}

function madeSelection(elem, helperMsg){
    if(elem.value == "Please Choose"){
        alert(helperMsg);
        elem.focus();
        return false;
    }else{
        return true;
    }
}

function emailValidator(elem, helperMsg){
    var emailExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(elem.value.match(emailExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

