function validateLogin(){
	//<!--- Make sure they entered a number in the ID field, and it is six characters --->
	if (isNaN(trim(document.SalSurv.LoginID.value)) == true){
		alert('Please enter numbers only in the \'Local Government ID from postcard\' field.');
		document.SalSurv.LoginID.focus();
		return false;
	}
	if (trim(document.SalSurv.LoginID.value).length != 6){
		alert('The Imis Number is exactly six digits. Your entry has more or less than 6 digits.');
		document.SalSurv.LoginID.focus();
		return false;
	}
	//<!--- Make sure state is entered --->
	if (trim(document.SalSurv.LoginState.value) == ''){
		alert('Please select the State.');
		document.SalSurv.LoginState.focus();
		return false;
	}
	//<!--- Make sure batchNumber is entered, if DataEntry logged in --->
	if (document.SalSurv.BatchNumber && trim(document.SalSurv.BatchNumber.value) == ''){
		alert('You must enter the Batch Number.');
		document.SalSurv.BatchNumber.focus();
		return false;
	}
	if (document.SalSurv.BatchNumber && isNaN(document.SalSurv.BatchNumber.value) == true){
		alert('The Batch Number must be numerals only.');
		document.SalSurv.BatchNumber.focus();
		return false;
	}
	
	document.SalSurv.submit();
	document.SalSurv.EndButton.value = 'Please Wait';
	return true;
}

function clearPO(){
	if (trim(document.SalSurv.EnteredAddress1.value)!='') {
		document.SalSurv.EnteredAddress1PO.value='';
	}
}

function clearAdd1(){
	if (trim(document.SalSurv.EnteredAddress1PO.value)!='') {
		document.SalSurv.EnteredAddress1.value='';
	}
}

function clearFields(){
	if (document.SalSurv.Vacant.checked==true) {
		document.SalSurv.Prefix.value='';
		document.SalSurv.FirstName.value='';
		document.SalSurv.MiddleName.value='';
		document.SalSurv.LastName.value='';
		document.SalSurv.Suffix.value='';
		document.SalSurv.Gender.value='';
		document.SalSurv.Race.value='';
		document.SalSurv.Hispanic.value='';
	}
}

function checkVacant() {
	if (document.SalSurv.Prefix.value!='' ||
		trim(document.SalSurv.FirstName.value)!='' ||
		trim(document.SalSurv.MiddleName.value)!='' ||
		trim(document.SalSurv.LastName.value)!='' ||
		trim(document.SalSurv.Suffix.value)!='' ||
		document.SalSurv.Gender.value!='' ||
		document.SalSurv.Race.value!='' ||
		document.SalSurv.Hispanic.value!='') {
			document.SalSurv.Vacant.checked=false;
		}
}

function checkIllegalWords(theVal)
{
	//alert(theVal);
	badWords = new Array("vacant","n/a");
	theVal = theVal.toLowerCase();
	var badWordsFound=0;
	var i;
	for (i in badWords)
	{
		if (theVal.indexOf(badWords[i]) > -1)
		{
			badWordsFound=1;
		}
	}
	//additional check for JUST "NA"
	if ( (theVal.length == 2) && (theVal.indexOf("na") > -1) )
	{
		badWordsFound=1;	
	}
	//if we've found something...
	if (badWordsFound == 1)
	{
		alert("Please do not use 'Vacant', 'N/A', etc. to indicate a vacant position - use the checkbox labelled 'This position is vacant or nonexistent in my local government' instead.");
		document.SalSurv.Vacant.checked=true;
		clearFields();
	}
}

function checkPO(){
	//<!--- Make sure P.O. Box entry does not start with any version of 'P.O.Box' --->
	var EnteredPO=trim(document.SalSurv.EnteredAddress1PO.value);
	if (EnteredPO.substring(0,3)=='P.O' ||
		EnteredPO.substring(0,3)=='P. ' ||
		EnteredPO.substring(0,3)=='P O' ||
		EnteredPO.substring(0,3)=='POB' ||
		EnteredPO.substring(0,3)=='p.o' ||
		EnteredPO.substring(0,3)=='p. ' ||
		EnteredPO.substring(0,3)=='p o' ||
		EnteredPO.substring(0,2)=='po' ||
		EnteredPO.substring(0,2)=='PO' ||
		EnteredPO.substring(0,3)=='pob'){
		alert('Please enter the P. O. Box as just the box number,\nwithout the \'P.O. Box...\'');
		document.SalSurv.EnteredAddress1PO.focus();
        return false;
	}
}

function validateLGInfo(){
	//<!--- Make sure Address1 and POBox aren't both filled in --->
	if (trim(document.SalSurv.EnteredAddress1.value) !='' && trim(document.SalSurv.EnteredAddress1PO.value) !='') {
				alert('Please fill out either a Street Address or a P.O. Box, but not both.');
        		return false;
			}
	//<!--- Make sure Address2 and POBox aren't both filled in --->
	if (trim(document.SalSurv.EnteredAddress2.value) !='' && trim(document.SalSurv.EnteredAddress1PO.value) !='') {
				alert('Please fill out either a Street Address or a P.O. Box, but not both. You have entries in both P.O. Box and Street Address (Line 2).');
				document.SalSurv.EnteredAddress2.focus();
        		return false;
			}	
	//<!--- Make sure if Address2 filled out, address 1 filled out as well --->
	if (trim(document.SalSurv.EnteredAddress2.value) !='' && trim(document.SalSurv.EnteredAddress1.value) =='') {
				alert('Please complete the street address. You have entered information in Line 2, but Line 1 is blank.');
				document.SalSurv.EnteredAddress1.focus();
        		return false;
			}	
	//<!--- Require the City  --->
	if (trim(document.SalSurv.EnteredCity.value) =='') {
				alert('Please complete the City.');
				document.SalSurv.EnteredCity.focus();
        		return false;
			}
	//<!--- Require the Zip --->
	if (trim(document.SalSurv.EnteredZip.value) =='') {
				alert('Please complete the Zipcode.');
				document.SalSurv.EnteredZip.focus();
        		return false;
			}
	//<!--- Make sure Zip is all numbers (Allowing 1 dash) --->
	var Chars = "0123456789-";
	var Dash = "-";
	var dashCount=0;
	var trimmedZip=trim(document.SalSurv.EnteredZip.value);
    for (var i = 0; i < trimmedZip.length; i++) {
       if (Chars.indexOf(trimmedZip.charAt(i)) == -1){
	   		alert('The Zip must contain only numbers. (One dash is allowed.)');
			document.SalSurv.EnteredZip.focus();
          	return false;
		}
	   if (Dash.indexOf(trimmedZip.charAt(i)) != -1){
	   		dashCount = dashCount + 1;
		}
	   if (dashCount == 2) {
	   		alert('The Zip must contain only numbers. (One dash is allowed.)');
			document.SalSurv.EnteredZip.focus();
          	return false;
	    }	
    }
	//<!--- Make sure zip is 5 digits or 10 digits with one dash --->
	if (trimmedZip.length!=5 && trimmedZip.length != 10 && trimmedZip.length!=0){
		alert('The Zip must be wither 5 digits or 5 digits, a dash and 4 digits. (Zip or Zip-Plus-4)');
		document.SalSurv.EnteredZip.focus();
          	return false;
	}
	if (trimmedZip.length==10 && dashCount!=1){
		alert('The Zip must be wither 5 digits or 5 digits, a dash and 4 digits. (Zip or Zip-Plus-4)');
		document.SalSurv.EnteredZip.focus();
          	return false;
	}
	//<!--- Make sure if any section of the Phone number is filled out, all sections are --->	
	if ((trim(document.SalSurv.EnteredPhone1.value) !='' || trim(document.SalSurv.EnteredPhone2.value) !='' || trim(document.SalSurv.EnteredPhone3.value) !='') && (trim(document.SalSurv.EnteredPhone1.value) =='' || trim(document.SalSurv.EnteredPhone2.value) =='' || trim(document.SalSurv.EnteredPhone3.value) =='')) {
				alert('Please fully complete the Phone Number.');
				document.SalSurv.EnteredPhone1.focus();
        		return false;
			}	
	//<!--- Make sure first 2 sections of the Phone number are numeric --->	
	if (isNaN(document.SalSurv.EnteredPhone1.value) == true || isNaN(document.SalSurv.EnteredPhone2.value) == true) {
				alert('Please enter only numbers for the Phone Number\'s Area Code and Exchange.');
				document.SalSurv.EnteredPhone1.focus();
        		return false;
			}	
	//<!--- Make sure Area code is 3 digits --->
	if (document.SalSurv.EnteredPhone1.value.length != 0 && document.SalSurv.EnteredPhone1.value.length != 3) {
				alert('The Phone\'s Area Code must be 3 digits.');
				document.SalSurv.EnteredPhone1.focus();
        		return false;
			}
	//<!--- Make sure Exchange is 3 digits --->
	if (document.SalSurv.EnteredPhone2.value.length != 0 && document.SalSurv.EnteredPhone2.value.length != 3) {
				alert('The Phone\'s Exchange must be 3 digits.');
				document.SalSurv.EnteredPhone2.focus();
        		return false;
			}
			
	//<!--- Make sure last part of phone number is at least 4 digits --->
	if (document.SalSurv.EnteredPhone3.value.length != 0 && document.SalSurv.EnteredPhone3.value.length < 4) {
				alert('The Phone\'s last field must be at least 4 digits.');
				document.SalSurv.EnteredPhone3.focus();
        		return false;
			}
	//<!--- Make sure first 4 digits of the last section of the Phone number are numeric --->	
	if (isNaN(document.SalSurv.EnteredPhone3.value.substring(0,4)) == true ) {
				alert('The first 4 digits of the last section of the Phone Number must be numeric.');
        		document.SalSurv.EnteredPhone3.focus();
				return false;
			}	
	//<!--- Make sure if any section of the Fax number is filled out, all sections are --->	
	if ((trim(document.SalSurv.EnteredFax1.value) !='' || trim(document.SalSurv.EnteredFax2.value) !='' || trim(document.SalSurv.EnteredFax3.value) !='') && (trim(document.SalSurv.EnteredFax1.value) =='' || trim(document.SalSurv.EnteredFax2.value) =='' || trim(document.SalSurv.EnteredFax3.value) =='')) {
				alert('Please fully complete the Fax Number.');
				document.SalSurv.EnteredFax1.focus();
        		return false;
			}	
	//<!--- Make sure first 2 sections of the Fax number are numeric --->	
	if (isNaN(document.SalSurv.EnteredFax1.value) == true || isNaN(document.SalSurv.EnteredFax2.value) == true) {
				alert('Please enter only numbers for the Fax Number\'s Area Code and Exchange.');
				document.SalSurv.EnteredFax1.focus();
        		return false;
			}		
	//<!--- Make sure Area code is 3 digits --->
	if (document.SalSurv.EnteredFax1.value.length != 0 && document.SalSurv.EnteredFax1.value.length != 3) {
				alert('The Fax\'s Area Code must be 3 digits.');
				document.SalSurv.EnteredFax1.focus();
        		return false;
			}
	//<!--- Make sure Exchange is 3 digits --->
	if (document.SalSurv.EnteredFax2.value.length != 0 && document.SalSurv.EnteredFax2.value.length != 3) {
				alert('The Fax\'s Exchange must be 3 digits.');
				document.SalSurv.EnteredFax2.focus();
        		return false;
			}
			
	//<!--- Make sure last part of phone number is at least 4 digits --->
	if (document.SalSurv.EnteredFax3.value.length != 0 && document.SalSurv.EnteredFax3.value.length < 4) {
				alert('The Fax\'s last field must be at least 4 digits.');
				document.SalSurv.EnteredFax3.focus();
        		return false;
			}
	//<!--- Make sure first 4 digits of the last section of the Fax number are numeric --->	
	if (isNaN(document.SalSurv.EnteredFax3.value.substring(0,4)) == true ) {
				alert('The first 4 digits of the last section of the Fax Number must be numeric.');
				document.SalSurv.EnteredFax3.focus();
        		return false;
			}	
	//<!--- Make sure HR email is valid --->	
	if (trim(document.SalSurv.EnteredEmail.value).length!=''){
		if (echeck(trim(document.SalSurv.EnteredEmail.value))==false){
		document.SalSurv.EnteredEmail.focus();
		return false;
		}
	}			
	
	document.SalSurv.submit();
	document.SalSurv.EndButton.value = 'Please Wait';
	return true;
}






function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 





function testWeb(address){
		//alert(address);
		if (address == 'http:\/\/'){
			window.alert("Please enter a valid web address.");
		}
		else if (address == ''){
			window.alert("Please enter a valid web address.");
		}
		else if (address.substring(0,7) == 'http:\/\/' ){
			remote=window.open(address,'name','width=550,height=250,resizable=yes,scrollbars=no,toolbar=no,status=0');
		}
		else {	
			var add2='http:\/\/' + address;	remote=window.open(add2,'name','width=550,height=250,resizable=yes,scrollbars=no,toolbar=no,status=0');
		}
	}
	
	
	
	
	
//----------------------
function validateContactInfo(){
	//<!--- Make sure First and Last names are entered. --->	
	if (trim(document.SalSurv.ContactFirstName.value) =='') {
		alert('Please enter your First Name.');		
		document.SalSurv.ContactFirstName.focus();
        return false;
	}
	if (trim(document.SalSurv.ContactLastName.value) =='') {
		alert('Please enter your Last Name.');
		document.SalSurv.ContactLastName.focus();
        return false;
	}
	//<!--- Make sure Phone Number entered. --->	
	if (trim(document.SalSurv.ContactPhone1.value) =='') {
		alert('Please enter your Phone Number.');
		document.SalSurv.ContactPhone1.focus();
        return false;
	}
	//<!--- Make sure if any section of the Phone number is filled out, all sections are --->	
	if ((trim(document.SalSurv.ContactPhone1.value) !='' || trim(document.SalSurv.ContactPhone2.value) !='' || trim(document.SalSurv.ContactPhone3.value) !='') && (trim(document.SalSurv.ContactPhone1.value) =='' || trim(document.SalSurv.ContactPhone2.value) =='' || trim(document.SalSurv.ContactPhone3.value) =='')) {
				alert('Please fully complete the Phone Number.');
		document.SalSurv.ContactPhone1.focus();
        		return false;
			}	
	//<!--- Make sure first 2 sections of the Phone number are numeric --->	
	if (isNaN(document.SalSurv.ContactPhone1.value) == true || isNaN(document.SalSurv.ContactPhone2.value) == true) {
				alert('Please enter only numbers for the Phone Number\'s Area Code and Exchange.');
				document.SalSurv.ContactPhone1.focus();
        		return false;
			}	
	//<!--- Make sure Area code is 3 digits --->
	if (document.SalSurv.ContactPhone1.value.length != 0 && document.SalSurv.ContactPhone1.value.length != 3) {
				alert('The Phone\'s Area Code must be 3 digits.');
				document.SalSurv.ContactPhone1.focus();
        		return false;
			}
	//<!--- Make sure Exchange is 3 digits --->
	if (document.SalSurv.ContactPhone2.value.length != 0 && document.SalSurv.ContactPhone2.value.length != 3) {
				alert('The Phone\'s Exchange must be 3 digits.');
				document.SalSurv.ContactPhone2.focus();
        		return false;
			}
			
	//<!--- Make sure last part of phone number is at least 4 digits --->
	if (document.SalSurv.ContactPhone3.value.length != 0 && document.SalSurv.ContactPhone3.value.length < 4) {
				alert('The Phone\'s last field must be at least 4 digits.');				
				document.SalSurv.ContactPhone3.focus();
        		return false;
			}
	//<!--- Make sure first 4 digits of the last section of the Phone number are numeric --->	
	if (isNaN(document.SalSurv.ContactPhone3.value.substring(0,4)) == true ) {
				alert('The first 4 digits of the last section of the Phone Number must be numeric.');
				document.SalSurv.ContactPhone3.focus();
        		return false;
			}	
	//<!--- Make sure contact email is valid --->	
	if (trim(document.SalSurv.ContactEmail.value).length!=''){
		if (echeck(trim(document.SalSurv.ContactEmail.value))==false){		
		document.SalSurv.ContactEmail.focus();
		return false;
		}	}
	
	//<!--- Make sure HR email is valid --->	
	if (trim(document.SalSurv.HRDirectorEmail.value).length!=''){
		if (echeck(trim(document.SalSurv.HRDirectorEmail.value))==false){
		document.SalSurv.HRDirectorEmail.focus();
		return false;
		}
	}	
	
	document.SalSurv.submit();
	document.SalSurv.EndButton.value = 'Please Wait';
	return true;
}





//---------------------- VALIDATE GCode Page
var askOnceForFullName='y';
function validateGCodePage(){
	if (document.SalSurv.Vacant.checked==false && trim(document.SalSurv.FirstName.value)=='' ){
		alert('Please enter the Position Holder\'s First Name.');
		document.SalSurv.FirstName.focus()
		return false;
	} 
	if (document.SalSurv.Vacant.checked==false && trim(document.SalSurv.LastName.value)==''){
		alert('Please enter the Position Holder\'s Last Name.');
		document.SalSurv.LastName.focus()
		return false;
	}	
		 
	if (askOnceForFullName=='y' && document.SalSurv.Vacant.checked==false && trim(document.SalSurv.Prefix.value)==''){
		alert('Please consider completing the Position Holder\'s complete name, including Prefix, in order to list it accurately in the Municipal Yearbook.');
		askOnceForFullName='n';
		document.SalSurv.Prefix.focus()
		return false;
	}	
	 
	
	document.SalSurv.submit();	
	document.SalSurv.EndButton1.value = 'Please Wait';
	document.SalSurv.EndButton2.value = '               Please Wait              ';
	return true;
}

function validateReviewGCodePage() {
	if (document.SalSurv.Holder.length==2 && document.SalSurv.Holder[0].checked==false && document.SalSurv.Holder[1].checked==false) {
		alert('Please indicate whether this is a new position holder or you are correcting the existing position holder\'s information.');
		return false;
	}
	document.SalSurv.submit();
	document.SalSurv.EndButton1.value = 'Please Wait ';
	document.SalSurv.EndButton2.value = '             Please Wait             ';
	return true;
}

//---------------------- VALIDATE GCode Page
var askOnceForFullName='y';
function validateNewGCode3(){
	if (trim(document.SalSurv.FirstName.value)=='' ){
		alert('Please enter the Position Holder\'s First Name.');
		document.SalSurv.FirstName.focus()
		return false;
	} 
	if (trim(document.SalSurv.LastName.value)==''){
		alert('Please enter the Position Holder\'s Last Name.');
		document.SalSurv.LastName.focus()
		return false;
	}	
		 
	if (askOnceForFullName=='y' && trim(document.SalSurv.Prefix.value)==''){
		alert('Please consider completing the Position Holder\'s complete name, including Prefix, in order to list it accurately in the Municipal Yearbook.');
		askOnceForFullName='n';
		document.SalSurv.Prefix.focus()
		return false;
	}	 
	
	document.SalSurv.submit();	
	document.SalSurv.EndButton1.value = 'Please Wait';
	document.SalSurv.EndButton2.value = '               Please Wait              ';
	return true;
}

function validateReviewNewGC3() {
	document.SalSurv.submit();
	document.SalSurv.EndButton1.value = 'Please Wait ';
	document.SalSurv.EndButton2.value = '             Please Wait             ';
	return true;
}


function validateReviewEditGC3() {
	if (document.SalSurv.Holder.length==2 && document.SalSurv.Holder[0].checked==false && document.SalSurv.Holder[1].checked==false) {
		alert('Please indicate whether this is a new position holder or you are correcting the existing position holder\'s information.');
		return false;
	}
	if (document.SalSurv.Holder[0].checked==true) {
		document.SalSurv.SurveyStep.value = 'SaveNewGC3';
	}
	document.SalSurv.submit();
	document.SalSurv.EndButton1.value = 'Please Wait ';
	document.SalSurv.EndButton2.value = '             Please Wait             ';
	return true;
}
//---------------------- VALIDATE GCode3/Salary Page for Assistant Chief Administrative Officers

function validateGCodePage3(){
	if (document.SalSurv.Vacant.checked==true && document.SalSurv.AlreadyVacant.value=='N') {
		if (confirm('Are you sure you want to mark this position as vacant? This will delete all the existing position holders listed here.')==false) {
			return false;
		}
	}
	document.SalSurv.submit();
	document.SalSurv.EndButton.value = 'Please Wait';
	return true;
}



//<!--- Duplicate name matching form --->
var DupeTypeChecked='N';
function validateGCode2(){
	for (var i=0;i<document.SalSurv.DupeType.length;i++) {
        if (document.SalSurv.DupeType[i].checked == true){
				DupeTypeChecked='Y';
			}
    }
	if (DupeTypeChecked=='N'){
		alert('You must select one of the options before proceeding.');
		return false;
	}
	
	
	document.SalSurv.submit();
	document.SalSurv.EndButton.value = 'Please Wait';
	return true;
}


//##########################

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert('Invalid E-mail address:' + str);
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert('Invalid E-mail address:' + str);
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert('Invalid E-mail address:' + str);
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert('Invalid E-mail address:' + str);
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert('Invalid E-mail address:' + str);
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert('Invalid E-mail address:' + str);
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert('Invalid E-mail address:' + str);
		    return false;
		 }
		 
		 var Chars = "0123456789-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.@";
		 for (var i = 0; i < str.length; i++) {
       		if (Chars.indexOf(str.charAt(i)) == -1){
	   		alert('Invalid E-mail address:' + str + '. The address contains invalid characters.');
          	return false;
			}   
		}
 		 return true;		
	}
	




