//--------------------------------------------------------------------------------------------
// global variables
//--------------------------------------------------------------------------------------------

	var lastTable = "";

	alertIcon = new Image();
	alertIcon.src = "http://www.nesstaffing.com/public/Images/alert.gif";

	clearIcon = new Image();
	clearIcon.src = "http://www.nesstaffing.com/public/Images/alert.clear.gif";

//--------------------------------------------------------------------------------------------
// function:	SetAlert()
// description:	Sets Alert
//--------------------------------------------------------------------------------------------
	function SetAlert( pTurnOn, pFieldID )
		{
			var iName;
	   
			iName = "i" + pFieldID;
	   
			if( pTurnOn )					
			   {
				  document[iName].src = eval( "alertIcon.src");
			   return 1;
			   }
			else
				  {
				  document[iName].src = eval( "clearIcon.src");
			   return 0;
				  }
		return;
		}
		
		
		
	
	
//--------------------------------------------------------------------------------------------
// function:	AdviceAndValidate()
// description:	Runs all Validations
//--------------------------------------------------------------------------------------------
	function AdviceAndValidate( pField, pFieldID, pType, pMin, pMax, pFormat )
		{
		var wasError=0;
	  
		hideAdvice()

		if( !pField ) return false;
		
		if( (pType != 'DDL') )
			{
				wasError = validateLength( pField, pFieldID, pMin, pMax );				// first check length
			}

			
		switch( pType )
			{
			case 'DDL':									
				if( pFormat == pField[pField.selectedIndex].value ) 
					{
						SetAlert(true, pFieldID);
						return true;
					}
				else
					{
						SetAlert(false, pFieldID);
						return false;
					}
				break;

			case 'OIN':	
											
				if( pField.checked ) 
					{
						SetAlert(false, pFieldID);
						return false;
					}
				else
					{
						SetAlert(true, pFieldID);
						return true;
					}
				break;
							
			case 'DTE':															// if it's a date
				if( validateDate( pField, pFormat ) )
					{
						SetAlert(true, pFieldID);
						return true;
					}
				else
					{
						SetAlert(false, pFieldID);
						return false;
					}
				break;
				
			case 'NUM':
				if( validateNum( pField, pFormat ) )						// if it's a number
					{
						SetAlert(true, pFieldID);
						return true;
					}
				else
					{
						SetAlert(false, pFieldID);
						return false;
					}
				break;
				
			case 'EML':
				if( !validateEmail( pField ) )							// if it's an email address
					{
						SetAlert(true, pFieldID);
						return true;
					}
				else
					{
						SetAlert(false, pFieldID);
						return false;
					}
				break;			
						
			}   	   
		return wasError;
		}
		
	//--------------------------------------------------------------------------------------------
// function:	validateLength()
// description:	validates min/max length of a field
//--------------------------------------------------------------------------------------------	 
	function validateLength( pField, pFieldID, pMin, pMax )
	   {
	   var minOK, maxOK, iName;
	   
	   iName = "i" + pFieldID;
	   
	   minOK = maxOK = true;
	   
	   if( pField.value.length < pMin && pMin != 0 ) minOK=false;				// if length < min and min is not zero, then bad
	   if( pField.value.length > pMax && pMax != 0 ) maxOK=false;				// if length < min and min is not zero, then bad
	  
	   if( !minOK || !maxOK )													// if one of them failed
	      {
			SetAlert(true, pFieldID);
	      return true;
	      }
	   else
		  {
			SetAlert(false, pFieldID);
	      return false;
		  }
	   }


//--------------------------------------------------------------------------------------------
// function:	validateAlpha()
// description:	Validates string to see if it is a number
//--------------------------------------------------------------------------------------------	
	function validateAlpha( pField )
		{
		var err;
		
		for( i=0; i<pField.length; i++ )
			{                                    
			if( pField.charAt(i) == " " )	err=1;
			if( pField.charAt(i) == "-" )	err=1;
			if( pField.charAt(i) == "!" )	err=1;
			if( pField.charAt(i) == "@" )	err=1;
			if( pField.charAt(i) == "." )	err=1;
			if( pField.charAt(i) > "=" )	err=1;
			if( pField.charAt(i) > ")" )	err=1;
			}
		
		if( err==1 )	return 1;
		else			return 0;
		}

//--------------------------------------------------------------------------------------------
// function:	validateNum()
// description:	Validates string to see if it is a number
//--------------------------------------------------------------------------------------------	
	function validateNum( pField, pFormat )
		{
		var err;
		
		for( i=0; i<pField.length; i++ )
			{                                    
			if( pField.charAt(i) < "0" )	err=1;
			if( pField.charAt(i) > "9" )	err=1;
			}
		
		if( err==1 )	return 1;
		else			return 0;
		}

//--------------------------------------------------------------------------------------------
// function:	showAdvice()
// description:	draw the little box on the side of a form
//--------------------------------------------------------------------------------------------	

	function showAdvice( message, title, tableName, displayheight )
		{
		var NS, IE, cell;
 		var s="";		
		
 		NS = (document.layers) ? 1 : 0;
 		IE = (document.all) ? 1: 0;
 		IE = true;
		
		
		if( message.length == 0 ) return;
		
		if( IE )
			cell = eval("document.all." + tableName + ".rows[0].cells['help']");
	
        s="<table width='138' border='1' cellspacing='0' cellpadding='0'><tr><td><table width='90%'>"
        s=s+"<tr><td>" + message
        s=s+"<center><input type='button' name='ok' value='OK' onclick='hideAdvice()'></center>"
		s=s+"</td></tr></table></td></tr></table>"
 
 
 		s="<table width='138' border='1' cellspacing='0' cellpadding='0' >"
	

		s=s+"<table border=0 cellspacing=0 cellpadding=0>"
			s=s+"<tr><td><img src=http://www.nesstaffing.com/public/images/blank.gif height=" + displayheight + " width=1></td></tr>"
		  s=s+"<tr>"
		    s=s+"<td width='3%' height='2'><img src='http://www.nesstaffing.com/public/images/frame.topleft.gif' width=20 height=12></td>"
		    s=s+"<td background='http://www.nesstaffing.com/public/images/frame.top.gif' width='91%' height=2><img src='http://www.nesstaffing.com/public/images/cleardot.gif' width='2' height='2'></td>"
		    s=s+"<td width='6%' height=2><img src='http://www.nesstaffing.com/public/images/frame.topright.gif' width='20' height='12'></td>"
		  s=s+"</tr>"
		  
		  s=s+"<tr height=1 bgcolor='F5F5F5'>"
		    s=s+"<td width='3%' background='http://www.nesstaffing.com/public/images/frame.left.upper.gif'><img src='http://www.nesstaffing.com/public/images/cleardot.gif' width='2' height='2'></td>"
		    s=s+"<td width='91%' bgcolor='F5F5F5' align='center'>"
		    
				//s=s+"<!-- TITLE BEGIN -->"
						s=s+"<font face='verdana' size='1'><b>"
						s=s+ title + "</b></font>"
				//s=s+"<!-- END TITLE -->"
				
			s=s+"</td>"
		    s=s+"<td width='6%' background='http://www.nesstaffing.com/public/images/frame.right.upper.gif'><img src='http://www.nesstaffing.com/public/images/cleardot.gif' width='2' height='2'></td>"
		 s=s+" </tr>"
		  
		  s=s+"<tr>"
		  s=s+"   <td width='3%'><img src='http://www.nesstaffing.com/public/images/frame.mid.left.gif' width='20' height='5'></td>"
		  s=s+"   <td width='91%' background='http://www.nesstaffing.com/public/images/frame.mid.gif'><img src='/common/Form/images/cleardot.gif' width='2' height='2'></td>"
		  s=s+"  <td width='6%'><img src='http://www.nesstaffing.com/public/images/frame.mid.right.gif' width='20' height='5'></td>"
		  s=s+"</tr>"
		  
		 s=s+" <tr>" 
		 s=s+"   <td width='3%' background='http://www.nesstaffing.com/public/images/frame.left.low.gif'><img src='/common/Form/images/cleardot.gif' width='2' height='2'></td>"
		  s=s+"  <td width='91%' bgcolor=#FFFFFF>"
		    
		  s=s+"  <!-- FORM BEGIN -->"
			

				s=s+"<table border=0  cellpadding=0 cellspacing=0 id='groupTable' width='100%'> "   
		
				s=s+"<tr>"
				  s=s+"<td colspan='3'></td>"
				s=s+"</tr>"
					        
					        s=s+"<!-- FIELDS BEGIN -->"
             

		s=s+"<tr><td background=''><table border=0 >"
		s=s+"<tr><td background=''>" + message 
		//s=s+"<center><input type='image' src'http://www.nesstaffing.com/public/images/other.gif' name='ok' value='OK' onclick='hideAdvice()'></center>" 
		s=s+"</td></tr>"
		
			      
				s=s+"</TD></TR></TABLE>"
				s=s+"</TD></TR></TABLE>"

		    s=s+"<td width='6%' background='http://www.nesstaffing.com/public/images/frame.right.lower.gif'><img src='/common/Form/images/cleardot.gif' width=2 height=2></td>"
		 s=s+" </tr>"
		  
		 s=s+" <tr>"
		    s=s+"<td width='3%'><img src='http://www.nesstaffing.com/public/images/frame.bottomleft.gif' width=20 height=20></td>"
		    s=s+"<td width='91%' background='http://www.nesstaffing.com/public/images/frame.bottom.gif'><img src='/common/Form/images/cleardot.gif' width=2 height=2></td>"
		    s=s+"<td width='6%'><img src='http://www.nesstaffing.com/public/images/frame.bottomright.gif' width=20 height=20></td>"
		  s=s+"</tr>"
		  				
		s=s+"</table>"
 
 
		if( IE )
			{
			cell.innerHTML = s;
			}
		else if( NS )
			{
			s= "<form>" + s + "</form>"
			
			//document.layers["adviceLayer"].left = window.screen.availWidth-140;
			//document.layers["adviceLayer"].top = window.screen.availHeight/2-25;
			//document.layers["adviceLayer"].position = "absolute"
			//document.layers["adviceLayer"].visibility = "visible"
			//document.layers["adviceLayer"].document.open()
			//document.layers["adviceLayer"].document.write(s)
			//document.layers["adviceLayer"].document.close()
			}	
			
		lastTable = tableName;
		}

//--------------------------------------------------------------------------------------------
// function:	hideAdvice()
// description:	hide the little box on the side of a form
//--------------------------------------------------------------------------------------------	

	function hideAdvice()
		{
		var NS, IE, cell;
 		var s="";		
		
 		NS = (document.layers) ? 1 : 0;
 		IE = (document.all) ? 1: 0;
 		IE = true;
		
		if( IE )
			{
			if( lastTable != "" )
				{
				cell = eval("document.all." + lastTable + ".rows[0].cells['help']");
				cell.innerText = "";
				}
			lastTable=""
			}
		else if( NS )
			{
			//document.layers["adviceLayer"].visibility = "hidden"
			}
		}

//--------------------------------------------------------------------------------------------
// function:	validateEmail()
// description:	make sure that the person enters a valid email address
//--------------------------------------------------------------------------------------------	


function validateEmail( pField )
{
	if(!validateEmailRegex(pField.value))
	{
		alert("Please enter a valid email address.");
        return(false);
	}
	if(!validateEmailBlacklist(pField.value))
	{
		alert("Please enter a valid email address.");
        return(false);
	}
	if(!validationEmailTypos(pField.value))
	{
		alert("Please enter a valid email address.");
        return(false);
	}
    return(true);
}

//--------------------------------------------------------------------------------------------
// function:	MatchFields()
// description:	open up a new browser window
//--------------------------------------------------------------------------------------------	

	function matchFields(field1, field2, message)
		{
		if( field1.value != field2.value )
			{
				alert(message);
				return false;
			}
			return true;
		}
		
		
//--------------------------------------------------------------------------------------------
// function:	checkURLandEmail()
// description:	checks to see if an email address is entered when the applyURL field is available
//              used on the emp/form/jobpostingform.asp
//--------------------------------------------------------------------------------------------

    function checkURLandEmail(){
      //alert("Checking Email and URL");      
       var email = F.FSendToEmail.value;
       var url = F.FApplyURL.value;     
       
       if (email.length == 0 && url.length ==0){
         alert("Enter an Email Address or URL");
         return false;       
       }        
       if (url.length > 0 && url.indexOf('http://')== -1 && url.indexOf('https://')== -1){
        alert('Invalid Apply URL:  A valid Apply URL should contain "http://"')
        return false;
       }                 
      return true;     
    } 
     
//--------------------------------------------------------------------------------------------
// function:	disableSubmit()
// description:	Disables the submit button of a form.  Used on page /js/form/signupform.asp              
//--------------------------------------------------------------------------------------------  
    function disableSubmit(F) {
		F.submitbutton.value = '   Processing...   ';
		F.submitbutton.disabled = true;
		return true;
}


    function checkEmail(F){
      var toReturn;
      toReturn = true;
      var email = F.FEAdd.value ;
      if (email.length == 0){
        toReturn = true;
      }
      else{        
        if (email.indexOf("@") < 0){
            alert("Email must have an '@'");
            toReturn = false;
        }
        if (email.indexOf(".") < 0){
            alert("Email must have an a '.'");
            toReturn = false;      
        }
      }
      return toReturn;
    }

//--------------------------------------------------------------------------------------------
// function:	validateBoolean()
// description:	Used to do front end validation on the keyword field when boolean search is chosen
//--------------------------------------------------------------------------------------------

function validateBoolean()
{
  var keywords = document.F.FKeywords.value;
  var searchType = document.F.FSearchType.value;
  
  var numQuotes = 0;
  var openParens = 0;
  var closedParens = 0;
  
  var goodQuotes = false;
  var goodParens = false;
  
  //if there are keywords entered and searchtype is boolean
  if (keywords)
  {
    if (searchType == 5 || searchType == "BOOLEAN")
    {
      //replace all single quotes with double quote
      keywords = keywords.replace(/'/g,"\"");
      
      //check for odd number of double quotes - error
      numQuotes = keywords.replaceAll('[^"]','').length;
      if ((numQuotes % 2) != 0)
      {
        alert('A boolean keyword search must contain an even number of quotes.');
        return false;
      }
      else 
      {
        //check for unmatched parens - error
        openParens = keywords.replaceAll('[^(]','').length;
        closedParens = keywords.replaceAll('[^)]','').length;
        if (openParens != closedParens)
        {
          alert('A boolean keyword search must contain an equal number of open and closed parenthesis.');
          return false;
        }
        else
        {
          document.F.FKeywords.value = keywords;
          return true;
        }
      }
    } else {return true;}
  } else {return true;}
}

//--------------------------------------------------------------------------------------------
// function:	validateAll()
// description:	Used to do front end validation on the keyword no " or ' when is not necesary 
//--------------------------------------------------------------------------------------------

function validateAll()
{
  var keywords = document.F.FKeywords.value;
  var searchType = document.F.FSearchType.value;
  //if there are keywords entered and searchtype is boolean
  if (keywords)
  {
    if ((searchType == 2 || searchType == "ALL") || (searchType == 3 || searchType == "ANY")||(searchType == 6 || searchType == "TITLE-ANY")||(searchType == 0 || searchType == "ANY")||(searchType == 1 || searchType == "FREE"))
    {//replace all sdouble quotes with nothing
    keywords = keywords.replace(/['"]/g,''); 
    document.F.FKeywords.value = keywords; 
     return true; 
     }
     else 
     {return false;}
   
  }
}

//Function used in counting above
String.prototype.replaceAll=function(s1, s2)
{
  return this.replace(new RegExp(s1,"g"), s2);
}

//--------------------------------------------------------------------------------------------
// function:	containsDigit(str)
// description:	returns true if the string passed contains a digit 
//--------------------------------------------------------------------------------------------
function containsDigit(str)
{
  var regex = /\d/g;
  return regex.test(str);
}

function validateEmailRegex(email)
{
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email))
        return true;
    else
        return false;
}

function validateEmailBlacklist(email)
{
    if( email.indexOf("@hotjobs") >= 0 ){return(false);}
	if( email.indexOf("@monster") >= 0 ){return(false);}
	if( email.indexOf("blacklist@") >= 0 ){return(false);}
	if( email.indexOf("bulkmail@") >= 0 ){return(false);}
	if( email.indexOf("devnull@") >= 0 ){return(false);}
	if( email.indexOf("kill@") >= 0 ){return(false);}
	if( email.indexOf("mailer-daemon@") >= 0 ){return(false);}
	
    return true;	
}

function validationEmailTypos(email)
{
/*
    'var filter = /^([@a0l.com])+([@ahoo\.com])+([@ayahoo\.com])+([@ayhoo\.com])+([@cocast\.net])+([@cocmast\.net])+([comast\.net])+([comcas\.net])+([comcst\.net])+([concast\.net])+([gamil\.com])+([gmai\.com])+([gmailcom])+([gmaill\.com])+([gmal\.com])+([homail\.com])+([homtail\.com])+([hotamil\.com])+([hotmal\.com])+([hotmial\.com])+([hotmil\.com])+([yaahoo\.com])+([yah00\.com])+([yahaoo\.com])+([yahho\.com])+([yaho\.com])+([yahool\.com])+([yahooo\.com])+([yahpp\.com])+([yaoo\.com])+([yayoo\.com])+([yhaoo\.com])+([yhoo\.com])+([yohoo\.com])+([yshoo\.com])+$;
    'var filter = /com/;
    'Dim index = -1
    
    'if(inStr(email, "@a0l.com") > -1) then
    'if (filter.test(email))
    '    return true;
    'else
    '    return false;
  */  
    if( email.indexOf("@a0l.com") >= 0 ){return(false);}
    if( email.indexOf("@ahoo.com") >= 0 ){return(false);}
    if( email.indexOf("@ayahoo.com") >= 0 ){return(false);}
    if( email.indexOf("@ayhoo.com") >= 0 ){return(false);}
    if( email.indexOf("@cocast.net") >= 0 ){return(false);}
    if( email.indexOf("@cocmast.net") >= 0 ){return(false);}
    if( email.indexOf("comast.net") >= 0 ){return(false);}
    if( email.indexOf("comcas.net") >= 0 ){return(false);}
    if( email.indexOf("comcst.net") >= 0 ){return(false);}
    if( email.indexOf("concast.net") >= 0 ){return(false);}
    if( email.indexOf("gamil.com") >= 0 ){return(false);}
    if( email.indexOf("gmai.com") >= 0 ){return(false);}
    if( email.indexOf("gmaill.com") >= 0 ){return(false);}
    if( email.indexOf("gmal.com") >= 0 ){return(false);}
    if( email.indexOf("homail.com") >= 0 ){return(false);}
    if( email.indexOf("homtail.com") >= 0 ){return(false);}
    if( email.indexOf("hotamil.com") >= 0 ){return(false);}
    if( email.indexOf("hotmal.com") >= 0 ){return(false);}
    if( email.indexOf("hotmial.com") >= 0 ){return(false);}
    if( email.indexOf("hotmil.com") >= 0 ){return(false);}
    if( email.indexOf("@otmail.com") >= 0 ){return(false);} // hotmail.com includes "otmail.com", changed to @otmail.com after 10 calls regarding this issue
    if( email.indexOf("yaahoo.com") >= 0 ){return(false);}
    if( email.indexOf("yah00.com") >= 0 ){return(false);}
    if( email.indexOf("yahaoo.com") >= 0 ){return(false);}
    if( email.indexOf("yahho.com") >= 0 ){return(false);}
    if( email.indexOf("yaho.com") >= 0 ){return(false);}
    if( email.indexOf("yahool.com") >= 0 ){return(false);}
    if( email.indexOf("yahooo.com") >= 0 ){return(false);}
    if( email.indexOf("yahpp.com") >= 0 ){return(false);}
    if( email.indexOf("yaoo.com") >= 0 ){return(false);}
    if( email.indexOf("yayoo.com") >= 0 ){return(false);}
    if( email.indexOf("yhaoo.com") >= 0 ){return(false);}
    if( email.indexOf("yhoo.com") >= 0 ){return(false);}
    if( email.indexOf("yohoo.com") >= 0 ){return(false);}
    if( email.indexOf("yshoo.com") >= 0 ){return(false);}
    if( email.indexOf(".cmo") >= 0 ){return(false);}
	if( email.indexOf(".hotmial") >= 0 ){return(false);}
	if( email.indexOf(".htomail") >= 0 ){return(false);}
	if( email.indexOf(".yhoo") >= 0 ){return(false);}
	if( email.indexOf(".hotmial") >= 0 ){return(false);}
    if( email.indexOf(".ogr") >= 0 ){return(false);}
	if( email.indexOf(".eud") >= 0 ){return(false);}
	if( email.indexOf(".rog") >= 0 ){return(false);}
	if( email.indexOf(".deu") >= 0 ){return(false);}
	if( email.indexOf(".nte") >= 0 ){return(false);}
	if( email.indexOf(".txt") >= 0 ){return(false);}

    return true;	
}
