//--------------------------------------------------------------------------------------------
// global variables
//--------------------------------------------------------------------------------------------

	var lastTable = "";

	alertIcon = new Image();
	alertIcon.src = "http://voiceapplied.com/public/images/main/alert.gif";

	clearIcon = new Image();
	clearIcon.src = "http://voiceapplied.com/public/images/main/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://voiceapplied.com/public/images/mainimages/blank.gif height=" + displayheight + " width=1></td></tr>"
		  s=s+"<tr>"
		    s=s+"<td width='3%' height='2'><img src='http://voiceapplied.com/public/images/main/frame_topleft.gif' width=20 height=12></td>"
		    s=s+"<td background='http://voiceapplied.com/public/images/main/frame_top.gif' width='91%' height=2><img src='http://voiceapplied.com/public/images/main/cleardot.gif' width='2' height='2'></td>"
		    s=s+"<td width='6%' height=2><img src='http://voiceapplied.com/public/images/main/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://voiceapplied.com/public/images/main/frame_left_upper.gif'><img src='http://voiceapplied.com/public/images/main/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://voiceapplied.com/public/images/main/frame_right_upper.gif'><img src='http://voiceapplied.com/public/images/main/cleardot.gif' width='2' height='2'></td>"
		 s=s+" </tr>"
		  
		  s=s+"<tr>"
		  s=s+"   <td width='3%'><img src='http://voiceapplied.com/public/images/main/frame_mid_left.gif' width='20' height='5'></td>"
		  s=s+"   <td width='91%' background='http://voiceapplied.com/public/images/main/frame_mid.gif'><img src='http://voiceapplied.com/public/images/main/cleardot.gif' width='2' height='2'></td>"
		  s=s+"  <td width='6%'><img src='http://voiceapplied.com/public/images/main/frame_mid_right.gif' width='20' height='5'></td>"
		  s=s+"</tr>"
		  
		 s=s+" <tr>" 
		 s=s+"   <td width='3%' background='http://voiceapplied.com/public/images/main/frame_left_low.gif'><img src='http://voiceapplied.com/public/images/main/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://voiceapplied.com/public/images/main/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://voiceapplied.com/public/images/main/frame_right_lower.gif'><img src='http://voiceapplied.com/public/images/main/cleardot.gif' width=2 height=2></td>"
		 s=s+" </tr>"
		  
		 s=s+" <tr>"
		    s=s+"<td width='3%'><img src='http://voiceapplied.com/public/images/main/frame_bottomleft.gif' width=20 height=20></td>"
		    s=s+"<td width='91%' background='http://voiceapplied.com/public/images/main/frame_bottom.gif'><img src='http://voiceapplied.com/public/images/main/cleardot.gif' width=2 height=2></td>"
		    s=s+"<td width='6%'><img src='http://voiceapplied.com/public/images/main/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 )
		
	{
	
	var FieldValue = pField.value.toLowerCase();
	
	if (pField.value == "")
		{
		alert("Please enter your email address in the \"Email Address\" field.");
		return (false);
		}
		
	if( pField.value.indexOf("@") == -1 )
		{
		alert("Please enter a valid email address.  A valid email address contains an @ symbol and a '.'.");
		return (false);
		}
					
	if( pField.value.indexOf(".") == -1 )
		{
		alert("Please enter a valid email address.  A valid email address contains a '.'.");
		return (false);
		}
		
			if( pField.value.indexOf(".") == 0 )
		{
		alert("Please enter a valid email address.  A valid email address  can not contain a '.' as a first character.");
		return (false);
		}
		if( pField.value.indexOf("..") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address can not contain a '..'.");
		return (false);
		}
	
	if( pField.value.indexOf(" ") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain any spaces.");
		return (false);
		}
	
	if( pField.value.indexOf("/") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '/'.");
		return (false);
		}
			if( pField.value.indexOf("\\") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '\\'.");
		return (false);
		}
	
	if( pField.value.indexOf(";") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a ';'.");
		return (false);
		}
			
	if( pField.value.indexOf(",") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a ','.");
		return (false);
		}
		
	if( pField.value.indexOf("!") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '!'.");
		return (false);
		}
	if( pField.value.indexOf(".cmo") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '.cmo'.");
		return (false);
		}
	if( pField.value.indexOf(".com.") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '.com.'.");
		return (false);
		}
		if( pField.value.indexOf(".con") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.con'.");
		return (false);
		}
				if( pField.value.indexOf(".hotmial") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.hotmial'.");
		return (false);
		}
				if( pField.value.indexOf(".htomail") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.htomail'.");
		return (false);
		}
				if( pField.value.indexOf(".yhoo") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.yhoo'.");
		return (false);
		}
				if( pField.value.indexOf(".hotmial") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.hotmial'.");
		return (false);
		}
	if( pField.value.indexOf(".ogr") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '.ogr'.");
		return (false);
		}
				if( pField.value.indexOf(".eud") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.eud'.");
		return (false);
		}
				if( pField.value.indexOf(".rog") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.rog'.");
		return (false);
		}
				if( pField.value.indexOf(".deu") >= 0 )
		{
		alert("Please enter a valid email address.  There is an error on '.deu'.");
		return (false);
		}
		if( pField.value.indexOf(".nte") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '.nte'.");
		return (false);
		}
		if( pField.value.indexOf(".txt") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '.txt'.");
		return (false);
		}
				if( pField.value.indexOf("@hotjobs") >= 0 )
		{
		alert("Please enter a valid email address.");
		return (false);
		}
			if( pField.value.indexOf("@monster") >= 0 )
		{
		alert("Please enter a valid email address.");
		return (false);
		}
			if( pField.value.indexOf("blacklist@") >= 0 )
		{
		alert("Please enter a valid email address.");
		return (false);
		}
		if( pField.value.indexOf("bulkmail@") >= 0 )
		{
		alert("Please enter a valid email address.");
		return (false);
		}
		if( pField.value.indexOf("devnull@") >= 0 )
		{
		alert("Please enter a valid email address.");
		return (false);
		}
		if( pField.value.indexOf("kill@") >= 0 )
		{
		alert("Please enter a valid email address.");
		return (false);
		}
		if( pField.value.indexOf("mailer-daemon@") >= 0 )
		{
		alert("Please enter a valid email address.");
		return (false);
		}
	if( pField.value.indexOf("#") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '#'.");
		return (false);
		}
		
	if( pField.value.indexOf("~") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '~'.");
		return (false);
		}
		
	if( pField.value.indexOf("$") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '$'.");
		return (false);
		}
		
	if( pField.value.indexOf("%") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '%'.");
		return (false);
		}
		
	if( pField.value.indexOf("www.") > 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a 'www.'.");
		return (false);
		}
		
		if( pField.value.indexOf("www@") > 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a 'www@'.");
		return (false);
		}
		
	if( pField.value.indexOf("?") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '?'.");
		return (false);
		}
		
	if( pField.value.indexOf("]") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a ']'.");
		return (false);
		}
		
	if( pField.value.indexOf("{") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '{'.");
		return (false);
		}
		
	if( pField.value.indexOf("}") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '}'.");
		return (false);
		}
		
	if( pField.value.indexOf("^") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '^'.");
		return (false);
		}
		
	if( pField.value.indexOf("*") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '*'.");
		return (false);
		}
		
	if( pField.value.indexOf("<") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '<'.");
		return (false);
		}
		
	if( pField.value.indexOf(">") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '>'.");
		return (false);
		}
		
	if( pField.value.indexOf(":") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a ':'.");
		return (false);
		}
	if( pField.value.indexOf("(") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '('.");
		return (false);
		}
		
	if( pField.value.indexOf(")") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a ')'.");
		return (false);
		}
		
	if( pField.value.indexOf("=") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '='.");
		return (false);
		}
		
	if( pField.value.indexOf("+") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '+'.");
		return (false);
		}
		
	if( pField.value.indexOf("[") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '['.");
		return (false);
		}
		if( pField.value.indexOf("&") >= 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '&'.");
		return (false);
		}
		
	if( pField.value.indexOf("@.") > 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '@.'.");
		return (false);
		}
	
	if( pField.value.indexOf(".@") > 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '.@'.");
		return (false);
		}
	
	if( pField.value.indexOf("@@") > 0 )
		{
		alert("Please enter a valid email address.  A valid email address cannot contain a '@@'.");
		return (false);
		}
	
	if( FieldValue.indexOf("http://www.") == 0 )
		{
		alert("Please enter a valid email address.  A valid email address does not start with 'www.'.");
		return (false);
		}
		if( FieldValue.indexOf("@") == 0 )
		{
		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 = J67180584.FSendToEmail.value;
       var url = J67180584.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(J67180584) {
		J67180584.submitbutton.value = '   Processing...   ';
		J67180584.submitbutton.disabled = true;
		return true;
}


    function checkEmail(J67180584){
      var toReturn;
      toReturn = true;
      var email = J67180584.FEmailAddress.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.J67180584.FKeywords.value;
  var searchType = document.J67180584.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.J67180584.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.J67180584.FKeywords.value;
  var searchType = document.J67180584.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);
}
