// Main Funtion

function checkWholeForm(form1) {
    var why = "";

// ==========================================================
// Below is the editable area - remove the // to enable validateion
// This script was written by Duffy System Solutions
// Support Contact - bduffy@4duffy.com
// It is not recommended to have too many field validate
// ==========================================================

// ------------------------  PAGE 1  ------------------------
//Position requesting

    why += isEmpty(document.form1.P1POSITION.value);

//Personal info

    why += checkPhone(document.form1.P1HomePhone.value);
    why += checkFullName(document.form1.P1Name.value);
//    why += P1SSN(document.form1.P1SSN.value);
    why += P1ADDR1(document.form1.P1ADDR1.value);
    why += P1City(document.form1.P1City.value);
    why += P1State(document.form1.P1State.value);
    why += P1Zip(document.form1.P1Zip.value);

//EMERGENCY INFORMATION

//    why += isEmpty(document.form1.P1EmerName.value);
//    why += isEmpty(document.form1.P1EmerRelation.value);
    why += EmerContactAddr(document.form1.P1EmerAddr.value);
//    why += isEmpty(document.form1.P1EmerPhone.value);

//OTHER EMPLOYMENT INFORMATION

//    why += isEmpty(document.form1.P1PosAdv.value);
//    why += isEmpty(document.form1.P1RelWork.value);
//    why += isEmpty(document.form1.P1ConvCrime.value);
    why += Convictedexplain(document.form1.P1ConvExplain.value);
//    why += isEmpty(document.form1.P1PrisonRec.value);
//    why += isEmpty(document.form1.P1Probation.value);
//    why += isEmpty(document.form1.P1ProbOffName.value);
//    why += isEmpty(document.form1.P1TakeDrugs.value);
    why += Certificates(document.form1.P1CERT1.value);
    why += Certificates(document.form1.P1CERT2.value);

// ------------------------  PAGE 2  ------------------------
//EDUCATION INFORMATION

//    why += isEmpty(document.form1.P2HighSchool.value);
//    why += isEmpty(document.form1.P2HSGrad.value);
//    why += isEmpty(document.form1.P2HSGLC.value);
//    why += isEmpty(document.form1.P2HSMajSub.value);
//    why += isEmpty(document.form1.P2HSGPA.value);
//    why += isEmpty(document.form1.P2Collage.value);
//    why += isEmpty(document.form1.P2ColDegree.value);
//    why += isEmpty(document.form1.P2ColMajSub.value);
//    why += isEmpty(document.form1.P2ColGPA.value);
//    why += isEmpty(document.form1.P2Vocational.value);
//    why += isEmpty(document.form1.P2VocComplete.value);
//    why += isEmpty(document.form1.P2VocYears.value);
//    why += isEmpty(document.form1.P2VocMajSub.value);
//    why += isEmpty(document.form1.P2VocOther.value);
//    why += isEmpty(document.form1.P2VocDegree.value);
//    why += isEmpty(document.form1.P24ThisPos.value);
//    why += isEmpty(document.form1.P2Uscore1.value);
//    why += isEmpty(document.form1.P2Uscore2.value);

//WORK EXPERIENCE

//    why += isEmpty(document.form1.P2LastEmploy.value);
//    why += isEmpty(document.form1.P2LEAddr.value);
//    why += isEmpty(document.form1.P2LEStartDate.value);
//    why += isEmpty(document.form1.P2LELeaveDate.value);
//    why += isEmpty(document.form1.P2LEStartPay.value);
//    why += isEmpty(document.form1.P2LEFinalPay.value);
//    why += isEmpty(document.form1.P2LER4Leave.value);
//    why += isEmpty(document.form1.P2LEJTitle.value);
//    why += isEmpty(document.form1.P2LENOfSup.value);
//    why += isEmpty(document.form1.P2NextEmploy.value);
//    why += isEmpty(document.form1.P2NEAddr.value);
//    why += isEmpty(document.form1.P2NEStartDate.value);
//    why += isEmpty(document.form1.P2NELeaveDate.value);
//    why += isEmpty(document.form1.P2NEStartPay.value);
//    why += isEmpty(document.form1.P2NEFinalPay.value);
//    why += isEmpty(document.form1.P2NER4Leave.value);
//    why += isEmpty(document.form1.P2NEJTitle.value);
//    why += isEmpty(document.form1.P2NENOfSup.value);

// ------------------------  PAGE 3  ------------------------

//    why += isEmpty(document.form1.P3NextEmploy2.value);
//    why += isEmpty(document.form1.P3NE2Addr.value);
//    why += isEmpty(document.form1.P3NE2StartDate.value);
//    why += isEmpty(document.form1.P3NE2LeaveDate.value);
//    why += isEmpty(document.form1.P3NE2StartPay.value);
//    why += isEmpty(document.form1.P3NE2FinalPay.value);
//    why += isEmpty(document.form1.P3NE2R4Leave.value);
//    why += isEmpty(document.form1.P3NE2JTitle.value);
//    why += isEmpty(document.form1.P3NE2NOfSup.value);

// ------------------------  PAGE 4  ------------------------
//INFORMATION AUTHORIZATION AND CONDUCT AGREEMENT

//    why += isEmpty(document.form1.P4BGCheck.value);

// ------------------------  PAGE 5  ------------------------
//Sheet Metal Workers Union Local 19

//    why += isEmpty(document.form1.IsLocal19.value);

// ------------------------  PAGE 6  ------------------------
//OSEPH OAT CORPORATION AGREEMENT

//    why += isEmpty(document.form1.P6PETFTextField2.value);
//    why += isEmpty(document.form1.P6PESign.value);
//    why += isEmpty(document.form1.P6PESignDate.value);

// ------------------------  PAGE 7  ------------------------
//SUPPLEMENT TO APPLICATION FOR FITTERS AND WELDERS

//    why += isEmpty(document.form1.P7TextField3.value);
//    why += isEmpty(document.form1.P7TextField4.value);
//    why += isEmpty(document.form1.P7TextField5.value);
//    why += isEmpty(document.form1.P7TextField6.value);
//    why += isEmpty(document.form1.P7TextField7.value);
//    why += isEmpty(document.form1.P7TextField8.value);
//    why += isEmpty(document.form1.P7TextField9.value);


// ==========================================================
// ============ DO NOT EDIT BELOW THIS LINE =================
// ==========================================================

// Page Random Number Validator
    why += RandomNumVarify();

    if (why != "") {
       alert(why);
       return false;
    }

// ==========================================================
// ===== You may edit or comment out the message below ======
// ==========================================================

   alert("Please wait while your your application is being processed");
return true;
}





// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}



// FullName - 4-10 chars, uc, lc, and underscore only.

function checkFullName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your Name.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 50)) {
       error = "The name field is the wrong length. Please use Bettween 4 and 50 characters.\n";
    }
//    else if (illegalChars.test(strng)) {
//    error = "The username contains illegal characters.\n";
//    } 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "A mandatory text area has not been filled in.\n"
  }
return error;	  
}


// Page Random Number Validator
//     why += RandomNumVarify(document.form1.PageVerifiedval.value);

function RandomNumVarify(strng) {
var error = "";
  if (document.form1.PageVerifiedval.value != document.form1.fullrandomval.value) {
     error = "Please type in the correct number listed at the bottom of the page.\n"
  }
return error;	  
}

// Emergency Contact Address

function EmerContactAddr(strng) {
var error = "";
  if (strng.length > 56) {
     error = "Too Many Charachters in Emergency Contact Address.  Use less then 56 Characters.\n"
  }
return error;	  
}

// Convicted explain

function Convictedexplain(strng) {
var error = "";
  if (strng.length > 81) {
     error = "Too Many Charachters in Conviction Explanation.  Use less then 81 Characters.\n"
  }
return error;	  
}

// Certificates

function Certificates(strng) {
var error = "";
  if (strng.length > 110) {
     error = "Too Many Charachters in Certificates.  Use less then 110 Characters.\n"
  }
return error;	  
}

// P1SSN

function P1SSN(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Your SNN has not been filled in.\n"
  }
return error;	  
}

// P1ADDR1

function P1ADDR1(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Your Address has not been filled in.\n"
  }
return error;	  
}

// P1City

function P1City(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Your City has not been filled in.\n"
  }
return error;	  
}

// P1State

function P1State(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Your State has not been filled in.\n"
  }
return error;	  
}

// P1Zip

function P1Zip(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Your Zip has not been filled in.\n"
  }
return error;	  
}


