/*
===========================================================
ad hoc validation functions
requires values to be passed in and returns true or false

first param is the value to be validated
2nd param is whether required or not (true = required)
3rd param is error 'span' id to be displayed or not
===========================================================
*/
function validateEmail(theValue, required, spanID){
  
  var spanExists = false;
  if(document.getElementById(spanID)){
    document.getElementById(spanID).style.display = "none";
    spanExists = true;
  }
  
  PassValidation = true;
  if (theValue == "" && required){
    if (spanExists) {
      document.getElementById(spanID).style.display = "inline";
    }
    PassValidation = false;
  }
  else {
    var eMailRegExp = /^[a-zA-Z]\w*(\.\w+)*(-\w+)*(\.\w+)*@(\w+(-\w+)*\.)+[a-zA-Z]{2,9}$/
    var pass = eMailRegExp.test(theValue);
    if (!pass){
      if (spanExists) {
        document.getElementById(spanID).style.display = "inline";
      }
      PassValidation = false;
    }
  }
  return PassValidation;
}

function validatePhone(theValue, required, spanID){
  
  var spanExists = false;
  if(document.getElementById(spanID)){
    document.getElementById(spanID).style.display = "none";
    spanExists = true;
  }
  
  PassValidation = true;
  if (theValue == "" && required){
    if (spanExists) {
      document.getElementById(spanID).style.display = "inline";
    }
    PassValidation = false;
  }
  else {
    var telephoneRegExp = /^[(]?[+]{0,2}[0-9-.\s\/()]+$/
    var pass = telephoneRegExp.test(theValue);
    if (!pass){
      if (spanExists) {
        document.getElementById(spanID).style.display = "inline";
      }
      PassValidation = false;
    }
  }
  return PassValidation;
}