
function checkEmail (strng) {
	var error="";
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= "/[\(\)\<\>\,\;\:\\\"\[\]]/";
	if (strng == "") {
		error = "Please enter an Email address.\n";
	}
	else if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid Email address.\n";
    }
    else if (strng.match(illegalChars)){
		//test email for illegal characters
         error = "The Email address contains unprocessable  characters.\n";
     }

	return error;    
}


function checkReference (strng, errorField) {
	var error = "";
	if (strng == "") {
		error = "The " + errorField +" field must be filled in.\n";
	}
	
	return error;
}  



function checkRadio (strng, errorField) {
	var error = "";
	if (!checkIfSelected(strng)) {
		error = "Please check if " + errorField + ".\n";
	}	
	return error;
} 

function checkEmploymentType (strng, strng2) {
	var error = "";
	
	if (!strng.checked && !strng2.checked) {
		error = "Please check employment type (full or part time).\n";
	}
	
	return error;
}  

function checkIfEmptyText (strng, errorField) {
		var error = "";
		var filter = /^[\w\.\-\&\,\:\s\/\@\#\&\)\(\;]+$/;
		
		if (strng == "") {
				error = "Please enter " + errorField + ".\n";
		}
		else if (!filter.test(strng)) {
    	error = "The " + errorField + " contains unprocessable characters. Please omit any special characters.\n";
    } 	
		return error;
}  


// check area code is 3 digits
function checkAreaCode (strng) {
var error = "";
var filter =/[0-9]{3}/;
if (strng == "") {
   error = "Please include your Area Code.\n";
}
else if (!(filter.test(strng))) { 
       error = "Please enter a valid Area Code.\n";
    }
 return error;
}


function checkPhone (strng) {
	var error = "";
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (strng == "") {
	   error = "Please enter a Phone number.\n";
	}


	 else if (isNaN(parseInt(stripped))) {
		   error = "The Phone number contains illegal characters.";
	  
		}
	 else if (!(stripped.length == 7)) {
	error = "Please recheck the Phone number entered. It doesn't match a typical number.\n";
  } 
	return error;
}


function checkZip (strng) {
var error = "";
var zipFilter=/^\d{5}$/;
if (strng == "") {
   error = "Please enter a Zip Code.\n";
}
/*else if (!(zipFilter.test(strng))) { 
       error = "Please enter a valid Zipcode.\n";
    }
 */
 return error;
}

function checkZipExt (strng) {
var error = "";
var zipFilter=/^\d{4}$/;
if (!(strng == "")) {
 if (!(zipFilter.test(strng))) { 
       error = "Please enter a valid Zipcode Extension.\n";
    }}
 return error;
}



function checkStateAbbr (strng) {
	var error = "";
	 var filter = /^[a-zA-Z]{2}$/; 
	if (strng == "") {
	   error = "Please enter a State Abbr.\n";
	}
	else if (!filter.test(strng)) {
		error = "Not able process that state abbreviation.\n";
		} 
	return error;
}  

function checkState (strng) {
	var error = "";
	 var filter = /^[\w\.\-\&\,\s]+$/; 
	if (strng == "") {
	   error = "Please enter a State.\n";
	}
	else if (!filter.test(strng)) {
		error = "Not able process that state abbreviation.\n";
		} 
	return error;
}  



function checkComments (strng) {
var error = "";
var illegalChars= /[\<\>\[\]\%\#\^\*\=]/;
if (illegalChars.test(strng)) { 
       error = "Not able process the comment. Please try again without any special characters. We appreciate your feed back.\n";
    }
 return error;
}


function checkFormEmail(theForm) {
	var why = "";  
  	why += checkEmail(theForm.email.value);
	   if (why != "") {
		   alert(why);
		   return false;
		}
	return true;
}

function checkFormConcessions(theForm) {
	var why = "";  
	why += checkIfEmptyText(theForm.first_name.value, 'First Name');
	why += checkIfEmptyText(theForm.last_name.value, 'Last Name');
	why += checkIfEmptyText(theForm.address_1.value, 'Address');
	why += checkIfEmptyText(theForm.city.value, 'City');
	why += checkIfEmptyText(theForm.state.value, 'State');
	why += checkIfEmptyText(theForm.zip.value, 'Zip');	
	why += checkEmail(theForm.email.value);
	why += checkEmploymentType(theForm.full_time, theForm.part_time);
	why += checkIfEmptyText(theForm.start_date.value, 'Available Start Date');	
	why += checkReference(theForm.name12.value,'First Reference Name');
	why += checkReference(theForm.relation12.value,'First Reference Relation');
	why += checkReference(theForm.phone12.value, 'First Reference Phone');
	why += checkReference(theForm.name22.value, 'Second Reference Name');
	why += checkReference(theForm.relation22.value, 'Second Reference Relation');
	why += checkReference(theForm.phone22.value, 'Second Reference Phone');
	why += checkReference(theForm.name32.value, 'Third Reference Name');
	why += checkReference(theForm.relation32.value, 'Third Reference Relation');
	why += checkReference(theForm.phone32.value, 'Third Reference Phone');
	why += checkRadio(theForm.crime, 'ever pled guilty, no contest, or been convicted of a felony or misdemeanor'); 
		
	   if (why != "") {
		   alert(why);
		   return false;
		}
	return true;
}

function checkFormExpOperator(theForm) {
	var why = "";  
  
	why += checkIfEmptyText(theForm.first_name.value, 'First Name');
	why += checkIfEmptyText(theForm.last_name.value, 'Last Name');
	why += checkIfEmptyText(theForm.address_1.value, 'Address');
	why += checkIfEmptyText(theForm.city.value, 'City');
	why += checkIfEmptyText(theForm.state.value, 'State');
	why += checkIfEmptyText(theForm.zip.value, 'Zip');
	why += checkRadio(theForm.over_18, 'over 18'); 
	why += checkEmail(theForm.email.value);
	why += checkEmploymentType(theForm.full_time, theForm.part_time);
	why += checkIfEmptyText(theForm.start_date.value, 'Available Start Date');	
	why += checkReference(theForm.name12.value,'First Reference Name');
	why += checkReference(theForm.relation12.value,'First Reference Relation');
	why += checkReference(theForm.phone12.value, 'First Reference Phone');
	why += checkReference(theForm.name22.value, 'Second Reference Name');
	why += checkReference(theForm.relation22.value, 'Second Reference Relation');
	why += checkReference(theForm.phone22.value, 'Second Reference Phone');
	why += checkReference(theForm.name32.value, 'Third Reference Name');
	why += checkReference(theForm.relation32.value, 'Third Reference Relation');
	why += checkReference(theForm.phone32.value, 'Third Reference Phone');
	why += checkRadio(theForm.crime, 'ever pled guilty, no contest, or been convicted of a felony or misdemeanor'); 
			
	   if (why != "") {
		   alert(why);
		   return false;
		}
	return true;
}


function checkFormFoodServiceSupervisor(theForm) {
	var why = "";  
  
	why += checkIfEmptyText(theForm.first_name.value, 'First Name');
	why += checkIfEmptyText(theForm.last_name.value, 'Last Name');
	why += checkIfEmptyText(theForm.address_1.value, 'Address');
	why += checkIfEmptyText(theForm.city.value, 'City');
	why += checkIfEmptyText(theForm.state.value, 'State');
	why += checkIfEmptyText(theForm.zip.value, 'Zip');	
	why += checkEmail(theForm.email.value);
	why += checkEmploymentType(theForm.full_time, theForm.part_time);
	why += checkIfEmptyText(theForm.start_date.value, 'Available Start Date');
	why += checkRadio(theForm.available_all_summer, 'available all summer'); 
	why += checkReference(theForm.name12.value,'First Reference Name');
	why += checkReference(theForm.relation12.value,'First Reference Relation');
	why += checkReference(theForm.phone12.value, 'First Reference Phone');
	why += checkReference(theForm.name22.value, 'Second Reference Name');
	why += checkReference(theForm.relation22.value, 'Second Reference Relation');
	why += checkReference(theForm.phone22.value, 'Second Reference Phone');
	why += checkReference(theForm.name32.value, 'Third Reference Name');
	why += checkReference(theForm.relation32.value, 'Third Reference Relation');
	why += checkReference(theForm.phone32.value, 'Third Reference Phone');
	why += checkRadio(theForm.crime, 'ever pled guilty, no contest, or been convicted of a felony or misdemeanor'); 
   
	   if (why != "") {
		   alert(why);
		   return false;
		}
	return true;
}


function checkFormGiftCashier(theForm) {
	var why = "";  
  
	why += checkIfEmptyText(theForm.first_name.value, 'First Name');
	why += checkIfEmptyText(theForm.last_name.value, 'Last Name');
	why += checkIfEmptyText(theForm.address_1.value, 'Address');
	why += checkIfEmptyText(theForm.city.value, 'City');
	why += checkIfEmptyText(theForm.state.value, 'State');
	why += checkIfEmptyText(theForm.zip.value, 'Zip');
	why += checkRadio(theForm.over_18, 'over 18'); 
	why += checkEmail(theForm.email.value);
	why += checkEmploymentType(theForm.full_time, theForm.part_time);
	why += checkIfEmptyText(theForm.start_date.value, 'Available Start Date');
	why += checkReference(theForm.name12.value,'First Reference Name');
	why += checkReference(theForm.relation12.value,'First Reference Relation');
	why += checkReference(theForm.phone12.value, 'First Reference Phone');
	why += checkReference(theForm.name22.value, 'Second Reference Name');
	why += checkReference(theForm.relation22.value, 'Second Reference Relation');
	why += checkReference(theForm.phone22.value, 'Second Reference Phone');
	why += checkReference(theForm.name32.value, 'Third Reference Name');
	why += checkReference(theForm.relation32.value, 'Third Reference Relation');
	why += checkReference(theForm.phone32.value, 'Third Reference Phone');
	why += checkRadio(theForm.crime, 'ever pled guilty, no contest, or been convicted of a felony or misdemeanor'); 
   
	   if (why != "") {
		   alert(why);
		   return false;
		}
	return true;
}


function checkGPF(theForm) {
	var why = "";  
  
	why += checkIfEmptyText(theForm.first_name.value, 'First Name');
	why += checkIfEmptyText(theForm.last_name.value, 'Last Name');
	why += checkIfEmptyText(theForm.address_1.value, 'Address');
	why += checkIfEmptyText(theForm.city.value, 'City');
	why += checkIfEmptyText(theForm.state.value, 'State');
	why += checkIfEmptyText(theForm.zip.value, 'Zip');
	why += checkIfEmptyText(theForm.phonehome.value, 'Home Phone');
	why += checkEmail(theForm.email.value);
	why += checkReference(theForm.name12.value,'First Reference Name');
	why += checkReference(theForm.relation12.value,'First Reference Relation');
	why += checkReference(theForm.phone12.value, 'First Reference Phone');
	why += checkReference(theForm.name22.value, 'Second Reference Name');
	why += checkReference(theForm.relation22.value, 'Second Reference Relation');
	why += checkReference(theForm.phone22.value, 'Second Reference Phone');
	why += checkReference(theForm.name32.value, 'Third Reference Name');
	why += checkReference(theForm.relation32.value, 'Third Reference Relation');
	why += checkReference(theForm.phone32.value, 'Third Reference Phone');
	why += checkRadio(theForm.crime, 'ever pled guilty, no contest, or been convicted of a felony or misdemeanor'); 
   
	   if (why != "") {
		   alert(why);
		   return false;
		}
	return true;
}
function checkIfSelected(strn) {

	chosen = ""
	len = strn.length

	for (i = 0; i <len; i++) {
		if (strn[i].checked) {
		chosen = strn[i].value
		}
	}

	if (chosen == "") {
		return false;
	}
	else {
		return true;
	}

}
