var errorLabelList = '';
var errorIDList = '';
var errorDisplayList = '';

function isBlank(inputObj) { 
 for(var x = 0; x < inputObj.value.length; x++) {
  if(inputObj.value.charCodeAt(x) != 32) {
   return false;
  }  
 }
 return true;
}

function isValidEmail(inputObj) {	
	
 if(inputObj.value.indexOf('@') == -1 || inputObj.value.indexOf('.') == -1 || inputObj.value.length < 7) {
  return false;
 }
 return true; 
}

function isNumeric(inputObj) {
 if(isNaN(inputObj.value)) {
  return false;
 }
 else {
  return true;
 }
}

function isRadioSelected(inputObj) { 
 for(x = 0; x < inputObj.length; x++) {
  if(inputObj[x].checked) {	    
   return inputObj[x].value;
  }
 }	  
 return false;
}

function isValidZip(inputObj) {
 if(isNumeric(inputObj) && inputObj.value.length == 5) { 
  return true;
 }
 else {
  return false;
 }
}

function isValidFullZip(inputObj) {}

function isValidPhone(format,inputObj) {
 // format - 0 = (xxx) xxx-xxxx
 // format - 1 = xxx xxx-xxxx
 // format - 2 = xxx.xxx.xxxx
 // format - 3 = xxx-xxxx
 switch(format) {
  case 0: {
   if(inputObj.value.indexOf('(') == -1 || inputObj.value.indexOf(')') == -1 || inputObj.value.indexOf('-') == -1 || inputObj.value.length !=14) {
    return false;
   }
   else {
    return true;
   }
  }
 }
}


function validateApplication() {
   var errArray;

	 // Clear Errors
   if (errorLabelList != '') {
   	  errArray = errorIDList.split(',');
   	   for (i=0; i < errArray.length; i++) {
   	 	 document.getElementById(errArray[i]).style.border = '1px solid #000000';
   	   }   	
   	   document.getElementById('errorMessages').innerHTML = '';
   	   document.getElementById('errorMessages').style.display = 'none';
   	 
       errorIDList = '';
       errorLabelList = '';
   	   errorDisplayList = '';
   }	
   
   if (isBlank(document.getElementById('lastName'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'lastName';
   	   errorLabelList = errorLabelList + 'lastNameLabel';
   	   errorDisplayList = errorDisplayList + 'Last name is a required field.';   	 	
   }  

   if (isBlank(document.getElementById('firstName'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'firstName';
   	   errorLabelList = errorLabelList + 'firstNameLabel';
   	   errorDisplayList = errorDisplayList + 'First name is a required field.';   	 	
   }  

   if (isBlank(document.getElementById('middleName'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'middleName';
   	   errorLabelList = errorLabelList + 'middleNameLabel';
   	   errorDisplayList = errorDisplayList + 'Middle name is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('street'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'street';
   	   errorLabelList = errorLabelList + 'streetLabel';
   	   errorDisplayList = errorDisplayList + 'Your current mailing address\'s street is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('cityStateZip'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'cityStateZip';
   	   errorLabelList = errorLabelList + 'cityStateZipLabel';
   	   errorDisplayList = errorDisplayList + 'Your current mailing address\'s city state and zip is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('PMAstreet'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'PMAstreet';
   	   errorLabelList = errorLabelList + 'PMAstreetLabel';
   	   errorDisplayList = errorDisplayList + 'Your permanent mailing address\'s street is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('PMAcityStateZip'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'PMAcityStateZip';
   	   errorLabelList = errorLabelList + 'PMAcityStateZipLabel';
   	   errorDisplayList = errorDisplayList + 'Your permanent mailing address\'s city state and zip is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('SSN'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'SSN';
   	   errorLabelList = errorLabelList + 'SSNLabel';
   	   errorDisplayList = errorDisplayList + 'Your social security number is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('homePhone'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'homePhone';
   	   errorLabelList = errorLabelList + 'homePhoneLabel';
   	   errorDisplayList = errorDisplayList + 'Your home phone number is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('position'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'position';
   	   errorLabelList = errorLabelList + 'positionLabel';
   	   errorDisplayList = errorDisplayList + 'The position you are applying for is a required field.';   	 	
   }  

   if (isBlank(document.getElementById('dateAvailable'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'dateAvailable';
   	   errorLabelList = errorLabelList + 'dateAvailableLabel';
   	   errorDisplayList = errorDisplayList + 'The date you are available for is a required field.';   	 	
   }  
   
   if ( isBlank(document.getElementById('employeeReferral')) && document.getElementById('sourceReferral').value == 'employeeReferral') {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'employeeReferral';
   	   errorLabelList = errorLabelList + 'employeeReferralLabel';
   	   errorDisplayList = errorDisplayList + 'The employee referral is a required field.';   	 	
   }  
   
   if ( isBlank(document.getElementById('otherReferral')) && document.getElementById('sourceReferral').value == 'other') {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'otherReferral';
   	   errorLabelList = errorLabelList + 'otherReferral';
   	   errorDisplayList = errorDisplayList + 'The other referral is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('E1employer'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1employer';
   	   errorLabelList = errorLabelList + 'E1employerLabel';
   	   errorDisplayList = errorDisplayList + 'Your present employer name is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('E1businessType'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1businessType';
   	   errorLabelList = errorLabelList + 'E1businessTypeLabel';
   	   errorDisplayList = errorDisplayList + 'Your present employer\'s business type is a required field.';   	 	
   } 
   
   if (isBlank(document.getElementById('E1phone'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1phone';
   	   errorLabelList = errorLabelList + 'E1phoneLabel';
   	   errorDisplayList = errorDisplayList + 'Your present employer\'s phone number is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1managersName'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1managersName';
   	   errorLabelList = errorLabelList + 'E1managersNameLabel';
   	   errorDisplayList = errorDisplayList + 'Your present employer\'s manager\'s name is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1street'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1street';
   	   errorLabelList = errorLabelList + 'E1streetLabel';
   	   errorDisplayList = errorDisplayList + 'Your present employer\'s street address is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1cityStateZip'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1cityStateZip';
   	   errorLabelList = errorLabelList + 'E1cityStateZipLabel';
   	   errorDisplayList = errorDisplayList + 'Your present employer\'s city state and zip is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1currentSalary'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1currentSalary';
   	   errorLabelList = errorLabelList + 'E1currentSalaryLabel';
   	   errorDisplayList = errorDisplayList + 'Your present current salary is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1jobTitle'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1jobTitle';
   	   errorLabelList = errorLabelList + 'E1jobTitleLabel';
   	   errorDisplayList = errorDisplayList + 'Your present job title is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1datesEmployed'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1datesEmployed';
   	   errorLabelList = errorLabelList + 'E1datesEmployedLabel';
   	   errorDisplayList = errorDisplayList + 'Your present dates employed is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1lastIncrease'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1lastIncrease';
   	   errorLabelList = errorLabelList + 'E1lastIncreaseLabel';
   	   errorDisplayList = errorDisplayList + 'Your last increase is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1natureDuties'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1natureDuties';
   	   errorLabelList = errorLabelList + 'E1natureDutiesLabel';
   	   errorDisplayList = errorDisplayList + 'The nature of your duties is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1reasonLeaving'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1reasonLeaving';
   	   errorLabelList = errorLabelList + 'E1reasonLeavingLabel';
   	   errorDisplayList = errorDisplayList + 'The reason of your leaving is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('E1annualEarnings'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'E1annualEarnings';
   	   errorLabelList = errorLabelList + 'E1annualEarningsLabel';
   	   errorDisplayList = errorDisplayList + 'Your annual earnings is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('highSchoolName'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'highSchoolName';
   	   errorLabelList = errorLabelList + 'highSchoolNameLabel';
   	   errorDisplayList = errorDisplayList + 'Your high school\'s name is a required field.';   	 	
   }
   
   if (isBlank(document.getElementById('HSaddress'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'HSaddress';
   	   errorLabelList = errorLabelList + 'HSaddressLabel';
   	   errorDisplayList = errorDisplayList + 'Your high school\'s address is a required field.';   	 	
   }
   
   if (!document.getElementById('agreeYes').checked) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'agreeYes';
   	   errorLabelList = errorLabelList + 'agreeYesLabel';
   	   errorDisplayList = errorDisplayList + 'You must agree to our Authorization and Acknowledgment statement.';   	 	
   }  
   
   if (errorIDList != '') {
   	var errDisplay = '<strong>The following errors have occurred:</strong><ul>';
   	
   	errIDArray = errorIDList.split(',');
   	errLabelArray = errorLabelList.split(',');
   	errDisplayArray = errorDisplayList.split(',');

   	for (i=0; i < errLabelArray.length; i++) {   		
   		document.getElementById(errIDArray[i]).style.border='1px solid #FF0000';	 
   		errDisplay = errDisplay + '<li>' + errDisplayArray[i] + '</li>';
   	}   	
   	errDisplay = errDisplay + '</ul>';
   	
   	document.getElementById('errorMessages').innerHTML = errDisplay;
   	document.getElementById('errorMessages').style.display = 'block';
   	document.getElementById(errIDArray[0]).focus();
   	return;
   }
   else  {
     document.getElementById('application').submit();   	    
   }

}
