function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.first_name,"First Name");
  reason += validateEmpty(theForm.last_name,"Last Name");
  reason += validateEmpty(theForm.address1, "Address");
  reason += validateEmpty(theForm.city, "City");
  reason += validateEmpty(theForm.state, "State");
  reason += validateEmpty(theForm.zip, "Zip Code");
  reason += validateEmpty(theForm.agency, "Agency");
  reason += validateEmpty(theForm.badge_name, "Badge Name");
  reason += validateEmail(theForm.email);
  reason += validateNumber(theForm.night_phone_a, "Phone Number Area Code");
  reason += validateNumber(theForm.night_phone_b, "Phone Number Exchange");
  reason += validateNumber(theForm.night_phone_c, "Phone Number");

      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
  concatforpp();
  
  return true;
}
//-------
function validateEmpty(fld, fldName) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = '#FFFE9D'; 
        error = fldName+" has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}
//--------
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 
//------
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = '#FFFE9D';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFFE9D';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFFE9D';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
//------
function validateNumber(fld, fldname) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = fldname+ " has not be filled in.\n";
        fld.style.background = '#FFFE9D';
    } else if (isNaN(stripped)) {
        error = fldname+ " contains illegal characters.\n";
        fld.style.background = '#FFFE9D';
    } 
    //else if (!(stripped.length == 10)) {
    //   error = "The phone number is the wrong length. Make sure you included an area code.\n";
    //   fld.style.background = '#FFFE9D';
    //} 
    return error;
}


function concatforpp() {
var d="|";
document.getElementById('custom').value = document.getElementById('last_name').value + d + document.getElementById('first_name').value + d + document.getElementById('agency').value + d + document.getElementById('badge_name').value;

return;
}


//=============================================================
function activate( contID, elemTag, thisID ) {
var currElem = document.getElementById(thisID);
currElem.setAttribute('className', 'topmenu hovered');
currElem.setAttribute('class', 'topmenu hovered');
return;
}
//=================================================
 
