var 	IEBrowser = false;
var 	W3C = false;

if (document.all) {
	IEBrowser = true;
} else if (document.getElementById) {
	W3C = true;   
};

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

var numLimit = 10; //number of jobs allow in job cart
var requiredEEO = false; //do we force candidate to anwser EEO information or not.
var altAddress = true; //we would have alternate address in the form
var requiredResume = true; //we request candidate to enter resume
var serverName = location.protocol + "//" + location.hostname;
var cookieWarning = "Our career site uses cookies to enhance your experience. Your browser settings do not allow cookies.\n\nYou can continue to view job opportunities on this site; however, in order to apply to jobs you must change your browser settings to allow cookies.\n\nYou can typically make this change through Internet Options or Preferences (generally found on the browser's Tools, Edit, View, or File menus), under the Security or Privacy category. Refer to your browser's online help should you need additional information.";

function clearJob(acctID, postSite){

    var oldAcctID = GetCookieValue("AccountID");
    var oldPostSite = GetCookieValue("Site");  
    if(oldAcctID!=acctID || oldPostSite!=postSite){ 
        if(oldAcctID!=acctID && oldAcctID!="0"){
	        SetCookieValue("PROFILE_LDAP_ID", "");
    	    SetCookieValue("ProfileId", ""); 
       	 	SetCookieValue("CANDIDATE_ID", ""); 
       	}    
        SetCookieValue("JobIDs", "");
        SetCookieValue("AccountID", acctID);
        SetCookieValue("Site", postSite);
    }
    if(GetCookieValue("AccountID")=='0'){
		alert(cookieWarning);
    }
}

function clearDestJob(acctID, postSite, cccDest){
    var oldAcctID = GetCookieValue("AccountID");
    var oldPostSite = GetCookieValue("Site");  
    var oldDest = GetCookieValue("CCCDest");      
    if(oldAcctID!=acctID || oldPostSite!=postSite || oldDest != cccDest){ 
        if(oldAcctID!=acctID && oldAcctID!="0"){
	        SetCookieValue("PROFILE_LDAP_ID", "");
    	    SetCookieValue("ProfileId", ""); 
       	 	SetCookieValue("CANDIDATE_ID", ""); 
       	}    
        SetCookieValue("JobIDs", "");
        SetCookieValue("AccountID", acctID);
        SetCookieValue("Site", postSite);
        SetCookieValue("CCCDest", cccDest);        
    }
    if(GetCookieValue("AccountID")=='0'){
		alert(cookieWarning);
    }
}

function selectJob(obj){
    var jobID = obj.value;
    var oldAcctID = GetCookieValue("AccountID");  
    var oldPostSite = GetCookieValue("Site");
    var acctID = document.jobs.ACCT_ID.value;
    var postSite = document.jobs.SITE.value;
    var count = document.jobs.JOB_ID.length;
    if(count>1){
        if(obj.checked)//add job 
        {
            if(oldAcctID!=acctID || oldPostSite!=postSite){ 
                var jobIDs = jobID;
                SetCookieValue("AccountID", acctID);
                SetCookieValue("Site", postSite);
            }else{
                var jobIDs = GetCookieValue("JobIDs");
                if(jobIDs=="0" || jobIDs=="")
                    jobIDs = jobID;
                else if(jobIDs.indexOf(jobID)<0){
                    if(getJobNumber(jobIDs)>=numLimit){
                        window.alert("Please limit your selection to " + numLimit + " jobs.");
                        obj.checked = false;
                        return;
                    }
                    jobIDs = jobIDs + "," + jobID;
                }
            }
            SetCookieValue("JobIDs", jobIDs);  
        }else //remove job
        {
            var jobIDs = GetCookieValue("JobIDs");
            var idx = jobIDs.indexOf(jobID);
            if(idx>0){
                jobIDs = jobIDs.substring(0, idx-1) + jobIDs.substring(idx + jobID.length);
            }else if(idx==0){
                if(jobIDs.length == jobID.length) //only one job
                    jobIDs = "";
                else
                    jobIDs = jobIDs.substring(jobID.length + 1);
            } 
            SetCookieValue("JobIDs", jobIDs);        
        }
    }else{
        if(obj.checked)//add job 
        {
            if(oldAcctID!=acctID || oldPostSite!=postSite){ 
                var jobIDs = jobID;
                SetCookieValue("AccountID", acctID);
                SetCookieValue("Site", postSite);
            }else{
                var jobIDs = GetCookieValue("JobIDs");
                if(jobIDs=="0" || jobIDs=="")
                    jobIDs = jobID;
                else if(jobIDs.indexOf(jobID)<0){
                    if(getJobNumber(jobIDs)>=numLimit){
                        window.alert("Please limit your selection to " + numLimit + " jobs.");
                        obj = false;
                        return;
                    }
                    jobIDs = jobIDs + "," + jobID;
                }
            }
            SetCookieValue("JobIDs", jobIDs);  
        }else //remove job
        {
            var jobIDs = GetCookieValue("JobIDs");
            var idx = jobIDs.indexOf(jobID);
            if(idx>0){
                jobIDs = jobIDs.substring(0, idx-1) + jobIDs.substring(idx + jobID.length);
            }else if(idx==0){
                if(jobIDs.length == jobID.length) //only one job
                    jobIDs = "";
                else
                    jobIDs = jobIDs.substring(jobID.length + 1);
            } 
            SetCookieValue("JobIDs", jobIDs);        
        }
    }
    
}

//remove job from the cart
function removeJob(jobID){
    var jobIDs = GetCookieValue("JobIDs");
    var idx = jobIDs.indexOf(jobID);
    if(idx>0){
        jobIDs = jobIDs.substring(0, idx-1) + jobIDs.substring(idx + jobID.length);
    }else if(idx==0){
        if(jobIDs.length == jobID.length) //only one job
	  {
            jobIDs = "";
	  }
        else{
            jobIDs = jobIDs.substring(jobID.length + 1);
        }
    } 
    SetCookieValue("JobIDs", jobIDs);  
    document.RemoveJob.submit();
}

//see how many jobs is in the cart right now
function getJobNumber(jobIDs){
    var ids = jobIDs.split(',');
    return ids.length;
}

function addJob(acctID, jobID, postSite){
    var oldAcctID = GetCookieValue("AccountID");  
    var oldPostSite = GetCookieValue("Site");
    if(oldAcctID!=acctID || oldPostSite!=postSite){ 
        var jobIDs = jobID;
        SetCookieValue("AccountID", acctID);
        SetCookieValue("Site", postSite);
    }else{
        var jobIDs = GetCookieValue("JobIDs");
        if(jobIDs=="0" || jobIDs=="")
            jobIDs = jobID;
        else if(jobIDs.indexOf(jobID)<0){
            if(getJobNumber(jobIDs)>=numLimit){
                window.alert("Please limit your selection to " + numLimit + " jobs.");
                return false;
            }
            jobIDs = jobIDs + "," + jobID;
        }
    }
    SetCookieValue("JobIDs", jobIDs);
    return true;  
}

//this function would clear all jobs in job cart and just apply to a single job only
function applyJob(acctID, jobID, postSite){
    SetCookieValue("AccountID", acctID);
    SetCookieValue("Site", postSite);
    SetCookieValue("JobIDs", jobID);        
    return true;  
}

function GetCookieValue(cookieName) {
    thisCookie = document.cookie.split("; ")
    for (i = 0; i < thisCookie.length; i++) {
        if (cookieName == thisCookie[i].split("=")[0]) {
        	idx = thisCookie[i].indexOf("=");
			if(idx>0)
	       		return thisCookie[i].substring(idx + 1);
			else
				return 0;
        }
    }
    return 0;
}

function SetCookieValue(name, value){
    document.cookie = name + "=" + value + "; path=/";
}

function preSelectJobs(){
    if(document.jobs!=null){
        var oldAcctID = GetCookieValue("AccountID");  
        var oldPostSite = GetCookieValue("Site");
        var acctID = document.jobs.ACCT_ID.value;   
        var postSite = document.jobs.SITE.value;   
        var jobIDs = GetCookieValue("JobIDs");
        if(acctID==oldAcctID && postSite==oldPostSite && jobIDs!=0){
            var jobIDLength = document.jobs.JOB_ID.length;
            
        	if(jobIDLength>1){
	            for(i=0; i<jobIDLength; i++){
    	            jobID = document.jobs.JOB_ID[i].value;
        	        if(jobIDs.indexOf(jobID)>=0)
            	        document.jobs.JOB_ID[i].checked = true;
            	}
            }else{
     	        jobID = document.jobs.JOB_ID.value;
        	    if(jobIDs.indexOf(jobID)>=0){           
            		document.jobs.JOB_ID.checked = true;
            	}
            }
        }
    }
}

//resume converter
function ConvertSpecialChars()
{	
	if(document.forms["response"].UPLOADED==null || document.forms["response"].UPLOADED.value!='true')
	{
		SetCookieValue("UPLOADED", "");
		var strResume = new String(document.forms["response"].RESUME_INPUT.value);
		var strFinalResume = "";

		for (i=0; i<strResume.length; i++) 
		{
			chHandleChar = strResume.charAt(i);

			if (chHandleChar != " ") 
			{
				iHandleChar = strResume.charCodeAt(i);

				switch (iHandleChar) 
				{			
					case 8220: {chHandleChar = "'"; break;}

					// MS Word left double quote
					case 8221: {chHandleChar = "'"; break;}

					// MS Word right single quote
					case 8216: {chHandleChar = "'"; break;}

					// MS Word left single quote
					case 8217: {chHandleChar = "'"; break;}

					// MS Word generic quote
					case 34: {chHandleChar = "'"; break;}

					// MS Word em-dash
					case 8211: {chHandleChar = "-"; break;}

					// MS Word en-dash
					case 8212: {chHandleChar = "-"; break;}

					// MS Word solid square bullet
					case 167: {chHandleChar = "-"; break;}

					// MS Word 3-d arrow bullet
					case 216: {chHandleChar = "-"; break;}

					// MS Word check mark bullet
					case 252: {chHandleChar = "-"; break;}
				}
			}
			strFinalResume = strFinalResume + chHandleChar;	
		}

		document.forms["response"].RESUME.value = strFinalResume;
		document.forms["response"].RESUME_INPUT.value = strFinalResume;
	}else{
		SetCookieValue("UPLOADED", "true");	
		document.forms["response"].RESUME.value = document.forms["response"].RESUME_INPUT.value;	
	}
}
var marker = "<Candidate Resume>";
function AddMarker(){
	//put a marker on top of resume to separate resume and contact information we later add on
	document.forms["response"].RESUME.value = marker + "\n" + document.forms["response"].RESUME.value;
}

function RemoveContactInfo(){
	var strResume = document.forms["response"].RESUME_INPUT.value;
	var index = strResume.indexOf(marker);
	if(index>=0){
		document.forms["response"].RESUME_INPUT.value = strResume.substring(index+marker.length+2, strResume.length);
	}
}

function PreviewResume()
{	
	// convert any special characters and update the resume text on the form
	ConvertSpecialChars();

	// get the resume text to pass into the preview dialog
	var strResume = new String(document.forms["response"].RESUME_INPUT.value);
	// preserve white space formatting
	strResume = replaceMultipleSpaces(strResume);
	// now put it into the hidden variable for the preview dialog		
	document.forms["PreviewFrm"].RESUME.value = strResume;
	var vAcctLogo = document.forms["PreviewFrm"].vLogoGIF.value;
	if ( vAcctLogo != "" && vAcctLogo.indexOf("</img>")<0)
	{	
		var vImg = "<img id='LogoImage' ";
		vImg += "src='" + vAcctLogo + "'></img>";
		document.forms["PreviewFrm"].vLogoGIF.value = vImg;
	}

	var WinObj; //window object
	var WindowURL =	serverName + "/jobcart/PleaseWait.html";
	var WindowName = "PreviewWindow";

	//send the user to the url in the window named 
	WinObj = window.open(WindowURL, WindowName, "height=490,width=850,resizable=yes,scrollbars=yes,titlebar=yes,left=25,top=50");		
	document.forms["PreviewFrm"].submit();
	WinObj.focus();
}

// replace multiple spaces and tabs with non-breaking white space
function replaceMultipleSpaces( vResumeText )
{
	var vText;

	// create a RegEx for the space and replace
	// Note:  This replaces 2 spaces with NBSPs.  The reason for this is to allow
	// line wrapping to occur.  If all single spaces are replaced, there is no line wrapping.
	var reSpace = new RegExp("  ", "g");
	vText = vResumeText.replace(reSpace, "&nbsp;&nbsp;");

	// create a RegEx for the tab and replace
	// Note: this replaces a tab with 8 NBSP.  
	var reTab = new RegExp("	", "g");
	vText = vText.replace(reTab, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");

	// create a RegEx for lf and replace 
	var reLineFeed = new RegExp("\n", "g");
	vText = vText.replace(reLineFeed, "<BR>\r\n");
	
	// create a RegEx for crlf and replace
	var reCRLF = new RegExp("\r\n", "g");
	vText = vText.replace(reCRLF, "<BR>\r\n");

	return vText;
}

// check resume length and if less than 500 warn that this will overlay any existing resume
// Sometimes when a candidate applies multiple times, they put the text 'Resume already on record' 
// in the resume text area.  This text then replaces any valid resume they may have previously submitted.
// This is an attempt to warn them before replacing the resume
function checkResumeLength()
{
	var bReturn = true;
	var strResume = new String(document.forms["response"].RESUME_INPUT.value);

	if ( strResume.length < 500 )
	{
		bReturn = confirm(document.forms["PreviewFrm"].vDlgResumeLength.value);
	}

	return bReturn;
}

var StateNames = new Array();
var StateCodes = new Array();
//change country and repopulate state drop down
function changeCountry(obj, target){
	var countryCode = obj.options[obj.selectedIndex].value;
	
	if(countryCode == "")
		return;

	var sourceURL = serverName + "/jobcart/state_list.cart?country_code="+ countryCode + "&target=" + target;
	
	if (IEBrowser)
	{
		document.frames("hiddenSources").location = sourceURL;
	}else if ( W3C )
	{
		document.getElementsByTagName('iframe')['hiddenSources'].setAttribute("src", sourceURL);
	}
	else
		document.layers["hiddenSources"].src = sourceURL;
}

function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		selectbox.remove(i);
	}
}

//populate the state drop down
function populateStateDropdown(countryCode, target){

	var stateElement = document.response.STATE_CODE_1;
	if(target==2){
		stateElement = document.response.STATE_CODE_2;
	}

	var ver = getInternetExplorerVersion();
	if(ver>=8){

		removeAllOptions(stateElement);

		if(StateNames.length==0){
			addOption(stateElement, "Unavailable", "0");;
		}else{		  
			if(countryCode==40){
				addOption(stateElement, "Please select a province", "");
			}
			else if(countryCode==3 || countryCode==4){
				addOption(stateElement, "Please select a county", "");
			}
			else{
				addOption(stateElement, "Please select a state", "");
			}
	
			for ( i = 0; i < StateNames.length; i++)
			{
				addOption(stateElement, StateNames[i], StateCodes[i]);

			}
		}
	}else{
		for ( i = 0; i < stateElement.length; i++ )
		{
			stateElement.options[0] = null;
		}

		stateElement.length = StateNames.length + 1;

		if(StateNames.length==0){
			stateElement.options[0] = new Option("Unavailable", "0", false, false);
		}else{		  
			if(countryCode==40){
				stateElement.options[0] = new Option("Please select a province", "", false, false);
			}
			else if(countryCode==3 || countryCode==4){
				stateElement.options[0] = new Option("Please select a county", "", false, false);
			}
			else
				stateElement.options[0] = new Option("Please select a state", "", false, false);
	
			for ( i = 0; i < StateNames.length; i++)
			{
				stateElement.options[i+1] = new Option(StateNames[i], StateCodes[i], false, false);
			}
		}

	}

    if(stateCode1>0 && target==1){
		SetInput('STATE_CODE_1', stateCode1);
	}else if(stateCode2>0 && target==2){
		SetInput('STATE_CODE_2', stateCode2);
	}else{
		stateElement.options[0].selected = true;
	}
	if(target==3)
		populateStateDropdown(countryCode, 2);
}

// init the page
function onLoad()
{
    var site = 'I';
    if(document.response.SITE!=null)
    {
       site = document.response.SITE.value;
	}
    if(site=='I' || site=='A')
		ProfilerInfo();	
	initCountry();
}

// Informs user about using profiling
var profilePrompt = "Please note that you are not currently using a profile.  A profile will allow you to store your resume so you can easily apply for future open positions.  To create a profile, click OK; or click Cancel and continue.";
var	profilerRedirect = false;  

function ProfilerInfo()
{
	var frm = document.response;
	var fromCB = false;
	if(location.href.indexOf("jobcart/cb.cart")>0){
		fromCB = true;
		document.cookie = "CB_INFO=TRUE; path=/"; //indicate we have already pop up the information for CareerBuilder 
	}
	
	if (frm.PROFILE_FLG.value == "1" && frm.PROFILE_CAND_ID.value.length == 0)
	{
		if(fromCB){
			profilePrompt = "You have been transferred from CareerBuilder to the company's career site.\n\nYour CareerBuilder personal information and resume have been used to populate the company's form.\n\n" + profilePrompt;
		}
	    if(profilerRedirect)
	    {
	    	var toProfiler = confirm(profilePrompt);
	    	if(toProfiler)
	    		ToProfiler();
	    }else{
			alert("Please note that you are not currently using a profile.  A profile will allow you to store your resume so you can easily apply for future open positions.");
		}
	}else if(fromCB){
		alert("You have been transferred from CareerBuilder to the company's career site.\n\nYour CareerBuilder personal information and resume have been used to populate the company's form.");
	}
	
}

stateCode1 = -1;
stateCode2 = -1;
countryCode1 = -1;
countryCode2 = -1;
//pre select United States for primary address
function initCountry(){
   if(document.response.COUNTRY_CODE_1!=null && document.response.COUNTRY_CODE_1.type=='select-one')
   {
      if(countryCode1<0)
		document.response.COUNTRY_CODE_1.options[1].selected = true;
      else
		SetInput('COUNTRY_CODE_1', countryCode1);

	  changeCountry(document.response.COUNTRY_CODE_1, 1);
   }
}

var SourceNames = new Array();
var SourceIDs = new Array();
//change account source category and repopulate account source drop down
function changeCategory(obj)
{
	var catID = obj.options[obj.selectedIndex].value;
	 initSources(catID);
}

function initSources(catID)
{
    var acctName = document.response.ACCT_NAME.value;
	if(catID == "" || acctName== "")
		return;

	var sourceURL = serverName + "/jobcart/source_list.cart?category_id="+ catID + "&ACCT_NAME=" + acctName;
		
	if (IEBrowser)
	{
		document.frames("hiddenSources").location = sourceURL;
	}else if ( W3C )
	{
		document.getElementsByTagName('iframe')['hiddenSources'].setAttribute("src", sourceURL);
	}
	else
		document.layers["hiddenSources"].src = sourceURL;
}

function initAllSources(catID)
{
    var acctName = document.response.ACCT_NAME.value;
	if(catID == "" || acctName== "")
		return;

	var sourceURL = serverName + "/jobcart/source_list.cart?category_id="+ catID + "&ACCT_NAME=" + acctName + "&all=true";
		
	if (IEBrowser)
	{
		document.frames("hiddenSources1").location = sourceURL;
	}else if ( W3C )
	{
		document.getElementsByTagName('iframe')['hiddenSources1'].setAttribute("src", sourceURL);
	}
	else
		document.layers["hiddenSources1"].src = sourceURL;
}


//populate the account source drop down
function populateSourceDropdown(){
	var sourceElement = document.response.ACCT_SOURCE_ID;
	var ver = getInternetExplorerVersion();
	if(ver>=8){
		removeAllOptions(sourceElement);

		addOption(sourceElement, "Please select a source.", "");
	
		for ( i = 0; i < SourceNames.length; i++)
		{
			addOption(sourceElement, SourceNames[i], SourceIDs[i]);
		}
	}else{
		sourceElement.length = SourceNames.length + 1;

		for ( i = 0; i < sourceElement.length; i++ )
		{
			sourceElement.options[0] = null;
		}

		sourceElement.options[0] = new Option("Please select a source.", "", false, false);
	
		for ( i = 0; i < SourceNames.length; i++)
		{
			sourceElement.options[i+1] = new Option(SourceNames[i], SourceIDs[i], SourceIDs[i], false);
		}
	}
}

var hasSubmit = false; //this prevents a candidate from submitting more than once

function error(elem, text)
{
	if(errorFound) return;

	window.alert(text);
	elem.focus();
	errorFound = true;
}

function CheckSpace(str) //check to see that user does omit the field or enter all white space in it
{
	str = str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');

	if(str.length == 0)
		return true;
	else
		return false;
	
}

//check to make sure the input is number
function CheckNum(str) //check to see that use enter a numerical value
{
	num_number = 0;
	num_dot = 0;
	for(i=0; i<str.length; i++)
	{
		s = str.substring(i,i+1);
		if(s=="0"||s=="1"||s=="2"||s=="3"||s=="4"||s=="5"||s=="6"||s=="7"||s=="8"||s=="9"||s=="."){
			num_number++;
			if(s==".")
				num_dot++;
		}else
			break;
	}
	if(num_dot<=1 && num_dot<str.length && num_number==str.length)
		return false;
	else
		return true;
}

//check email address, return true if it is valid
function CheckEmailAddress(address)
{
	var isValid = false;
	var idx1 = address.indexOf("@");
	if(idx1>0 && address.indexOf(" ")<0)
	{
		var idx2 = address.indexOf(".", idx1);
		 //make sure we have '.' after '@' and it is not immediate after '@' and
		//it is not the last character of email
		if(idx2>idx1+1 && idx2<address.length - 1)
			isValid = true;
	}
	return isValid;
}

//check agency response fields
function CheckAgency()
{
	errorFound = false;

		if(document.response.ACCT_SOURCE_ID.selectedIndex==0)
			error(document.response.ACCT_SOURCE_ID,"Please select a source.");

		if(CheckSpace(document.response.Agency_Name.value))
			error(document.response.Agency_Name, "Please fill in agency contact name.");
		else if(CheckSpace(document.response.Agency_Phone.value))
			error(document.response.Agency_Phone, "Please fill in agency phone.");
		else if(CheckSpace(document.response.Agency_Email.value))
			error(document.response.Agency_Email, "Please fill in agency e-mail address.");
		else if(!CheckEmailAddress(document.response.Agency_Email.value))
			error(document.response.Agency_Email, "Please fill in a valid e-mail address.");
	
		if(CheckSpace(document.response.FIRST_NAME.value))
			error(document.response.FIRST_NAME, "Please fill in your first name.");
		else if(document.response.MIDDLE_NAME!=null && document.response.MIDDLE_NAME.value.length>1)
			error(document.response.MIDDLE_NAME, "Please limit your middle initial to one character.");			
		else if(CheckSpace(document.response.LAST_NAME.value))		
			error(document.response.LAST_NAME, "Please fill in your last name.");
		else if(CheckSpace(document.response.HOME_PHONE.value))
			error(document.response.HOME_PHONE, "Please fill in your home phone.");
		else if(CheckSpace(document.response.EMAIL.value))
			error(document.response.EMAIL, "Please fill in your e-mail address.");
		else if(!CheckEmailAddress(document.response.EMAIL.value))
			error(document.response.EMAIL, "Please fill in a valid e-mail address.");
		else if(CheckSpace(document.response.PRIMARY_ADDR_1.value))
			error(document.response.PRIMARY_ADDR_1, "Please fill in the street address where you live.");
		else if(CheckSpace(document.response.CITY_1.value))
			error(document.response.CITY_1, "Please fill in the city where you live.");  
		else if(document.response.COUNTRY_CODE_1.selectedIndex==0)
 			error(document.response.COUNTRY_CODE_1, "Please select a country.");
		else if(CheckSpace(document.response.STATE_CODE_1.options[document.response.STATE_CODE_1.selectedIndex].value))
			error(document.response.STATE_CODE_1, "Please select state/province/county where you live.");
		else if(CheckSpace(document.response.ZIP_1.value))
			error(document.response.ZIP_1, "Please fill in your Zip/Postal Code.");
		else if(document.response.ZIP_1.value.length>10)
			error(document.response.ZIP_1, "Please limit your Zip/Postal Code to 10 characters.");
		else if(altAddress && document.response.COUNTRY_CODE_2.selectedIndex>0 && CheckSpace(document.response.STATE_CODE_2.options[document.response.STATE_CODE_2.selectedIndex].value))
			error(document.response.STATE_CODE_2, "Please select state/province/county where you live.");
		else if(document.response.ZIP_2!=null && document.response.ZIP_2.value.length>10)
			error(document.response.ZIP_2, "Please limit your Zip/Postal Code to 10 characters.");				
		else if (!CstmFieldCheck()){
			return false;
		}else if(requiredResume && CheckSpace(document.response.RESUME_INPUT.value))
			error(document.response.RESUME_INPUT, "Please include a copy of your resume.");
		//check additional fields that we put for individual client
		else if(!AdditionalFieldCheck()){
			errorFound = true;
		}  
    
	if(!errorFound) {
		document.response.COUNTRY_1.value=document.response.COUNTRY_CODE_1.options[document.response.COUNTRY_CODE_1.selectedIndex].text;
		document.response.STATE_1.value=document.response.STATE_CODE_1.options[document.response.STATE_CODE_1.selectedIndex].text;
		if(altAddress){
	
			if(document.response.STATE_CODE_2.selectedIndex>0)
				document.response.COUNTRY_2.value=document.response.COUNTRY_CODE_2.options[document.response.COUNTRY_CODE_2.selectedIndex].text;
			if(document.response.COUNTRY_CODE_2.selectedIndex>0)
				document.response.STATE_2.value=document.response.STATE_CODE_2.options[document.response.STATE_CODE_2.selectedIndex].text;			
		}
		if(requiredEEO){
			if(document.response.GENDER_CODE!=null && document.response.GENDER_CODE.selectedIndex<=0){
				error(document.response.GENDER_CODE, "Please select gender/sex.");
			}else if(document.response.RACE_CODE!=null && document.response.RACE_CODE.selectedIndex<=0){
				error(document.response.RACE_CODE, "Please select ethnicity/race.");
			}else if(document.response.DISABLED_FLG!=null && document.response.DISABLED_FLG.selectedIndex<=0){
				error(document.response.DISABLED_FLG, "Please select disabled status.");
			}else if(document.response.VETERAN_STATUS_CODE!=null && document.response.VETERAN_STATUS_CODE.selectedIndex<=0){
				error(document.response.VETERAN_STATUS_CODE, "Please select veteran status.");
			}	
			if(errorFound)
				return false;
		}	
		if(requiredResume && !checkResumeLength())
			return false;
		if(document.response.RESUME_INPUT != null){	
			ConvertSpecialChars();
		}
		if(hasSubmit)
		{
			window.alert("You have already submitted this page. Please wait for a response.");
			return false;
		}else		
		{ 
			hasSubmit = true;
		}
		if(document.response.SUBMIT!=null){
			document.response.SUBMIT.value = "Submitting";			
			document.response.SUBMIT.disabled = true;
		}		
		return true;
	}else{
		return false;
	}
}


//check response fields
function CheckField()
{
	errorFound = false;

	if(document.response.SOURCE_CATEGORY_ID!=null && document.response.SOURCE_CATEGORY_ID.selectedIndex==0){
		error(document.response.SOURCE_CATEGORY_ID,"Please select a category.");
	}else if(document.response.ACCT_SOURCE_ID!=null && document.response.ACCT_SOURCE_ID.selectedIndex==0)
		error(document.response.ACCT_SOURCE_ID,"Please select a source.");	

	if(document.response.SITE!=null && document.response.SITE.value=='E'){
		if(CheckSpace(document.response.EMP_FIRST_NAME.value))
			error(document.response.EMP_FIRST_NAME, "Please fill in your first name.");
		else if(CheckSpace(document.response.EMP_LAST_NAME.value))
			error(document.response.EMP_LAST_NAME, "Please fill in your last name.");	
		else if(CheckSpace(document.response.FIRST_NAME.value))
			error(document.response.FIRST_NAME, "Please fill in your friend's first name.");
		else if(CheckSpace(document.response.LAST_NAME.value))
			error(document.response.LAST_NAME, "Please fill in your friend's last name.");
		else if(CheckSpace(document.response.HOME_PHONE.value))
			error(document.response.HOME_PHONE, "Please fill in your friend's home phone.");
		else if(CheckSpace(document.response.EMAIL.value))
			error(document.response.EMAIL, "Please fill in your friend's email address.");
		else if(!CheckEmailAddress(document.response.EMAIL.value))
			error(document.response.EMAIL, "Please fill in a valid e-mail address.");
		else if(CheckSpace(document.response.PRIMARY_ADDR_1.value))
			error(document.response.PRIMARY_ADDR_1, "Please fill in your friend's street address.");
		else if(CheckSpace(document.response.CITY_1.value))
			error(document.response.CITY_1, "Please fill in your friend's city.");  
		else if(document.response.COUNTRY_CODE_1.selectedIndex==0)
 			error(document.response.COUNTRY_CODE_1, "Please select your friend's country.");
		else if(CheckSpace(document.response.STATE_CODE_1.options[document.response.STATE_CODE_1.selectedIndex].value))
			error(document.response.STATE_CODE_1, "Please select your friend's state/province/county.");
		else if(CheckSpace(document.response.ZIP_1.value))
			error(document.response.ZIP_1, "Please fill in your friend's Zip/Postal Code.");
		else if(altAddress && document.response.COUNTRY_CODE_2.selectedIndex>0 && CheckSpace(document.response.STATE_CODE_2.options[document.response.STATE_CODE_2.selectedIndex].value))
			error(document.response.STATE_CODE_2, "Please select your friend's state/province/county.");	   
		else if (!CstmFieldCheck()){
			return false;
		}else if(requiredResume && CheckSpace(document.response.RESUME_INPUT.value))
			error(document.response.RESUME_INPUT, "Please include a copy of your friend's resume.");
		//check additional fields that we put for individual client
		else if(!AdditionalFieldCheck()){
			errorFound = true; 
		}
	}else{	
		if(CheckSpace(document.response.FIRST_NAME.value))
			error(document.response.FIRST_NAME, "Please fill in your first name.");
		else if(document.response.MIDDLE_NAME!=null && document.response.MIDDLE_NAME.value.length>1)
			error(document.response.MIDDLE_NAME, "Please limit your middle initial to one character.");			
		else if(CheckSpace(document.response.LAST_NAME.value))		
			error(document.response.LAST_NAME, "Please fill in your last name.");
		else if(CheckSpace(document.response.HOME_PHONE.value))
			error(document.response.HOME_PHONE, "Please fill in your home phone.");
		else if(CheckSpace(document.response.EMAIL.value))
			error(document.response.EMAIL, "Please fill in your e-mail address.");
		else if(!CheckEmailAddress(document.response.EMAIL.value))
			error(document.response.EMAIL, "Please fill in a valid e-mail address.");
		else if(CheckSpace(document.response.PRIMARY_ADDR_1.value))
			error(document.response.PRIMARY_ADDR_1, "Please fill in the street address where you live.");
		else if(CheckSpace(document.response.CITY_1.value))
			error(document.response.CITY_1, "Please fill in the city where you live.");  
		else if(document.response.COUNTRY_CODE_1.selectedIndex==0)
 			error(document.response.COUNTRY_CODE_1, "Please select a country.");
		else if(CheckSpace(document.response.STATE_CODE_1.options[document.response.STATE_CODE_1.selectedIndex].value))
			error(document.response.STATE_CODE_1, "Please select state/province/county where you live.");
		else if(CheckSpace(document.response.ZIP_1.value))
			error(document.response.ZIP_1, "Please fill in your Zip/Postal Code.");
		else if(document.response.ZIP_1.value.length>10)
			error(document.response.ZIP_1, "Please limit your Zip/Postal Code to 10 characters.");
		else if(altAddress && document.response.COUNTRY_CODE_2.selectedIndex>0 && CheckSpace(document.response.STATE_CODE_2.options[document.response.STATE_CODE_2.selectedIndex].value))
			error(document.response.STATE_CODE_2, "Please select state/province/county where you live.");
		else if(document.response.ZIP_2!=null && document.response.ZIP_2.value.length>10)
			error(document.response.ZIP_2, "Please limit your Zip/Postal Code to 10 characters.");				
		else if (!CstmFieldCheck()){
			return false;
		}else if(requiredResume && CheckSpace(document.response.RESUME_INPUT.value))
			error(document.response.RESUME_INPUT, "Please include a copy of your resume.");
		//check additional fields that we put for individual client
		else if(!AdditionalFieldCheck()){
			errorFound = true;
		}  
    }
    
	if(!errorFound) {
		document.response.COUNTRY_1.value=document.response.COUNTRY_CODE_1.options[document.response.COUNTRY_CODE_1.selectedIndex].text;
		document.response.STATE_1.value=document.response.STATE_CODE_1.options[document.response.STATE_CODE_1.selectedIndex].text;
		if(altAddress){
	
			if(document.response.STATE_CODE_2.selectedIndex>0)
				document.response.COUNTRY_2.value=document.response.COUNTRY_CODE_2.options[document.response.COUNTRY_CODE_2.selectedIndex].text;
			if(document.response.COUNTRY_CODE_2.selectedIndex>0)
				document.response.STATE_2.value=document.response.STATE_CODE_2.options[document.response.STATE_CODE_2.selectedIndex].text;			
		}
		if(requiredEEO){
			if(document.response.GENDER_CODE!=null && document.response.GENDER_CODE.selectedIndex<=0){
				error(document.response.GENDER_CODE, "Please select gender/sex.");
			}else if(document.response.RACE_CODE!=null && document.response.RACE_CODE.selectedIndex<=0){
				error(document.response.RACE_CODE, "Please select ethnicity/race.");
			}else if(document.response.DISABLED_FLG!=null && document.response.DISABLED_FLG.selectedIndex<=0){
				error(document.response.DISABLED_FLG, "Please select disabled status.");
			}else if(document.response.VETERAN_STATUS_CODE!=null && document.response.VETERAN_STATUS_CODE.selectedIndex<=0){
				error(document.response.VETERAN_STATUS_CODE, "Please select veteran status.");
			}	
			if(errorFound)
				return false;
		}	
		
		if(!checkEducation()){
			return false;
		}
	
		if(!checkExperience()){
			return false;
		}		
		
		if(requiredResume && !checkResumeLength())
			return false;
		if(document.response.RESUME_INPUT != null){	
			ConvertSpecialChars();
		}
		if(hasSubmit)
		{
			window.alert("You have already submitted this page. Please wait for a response.");
			return false;
		}else		
		{ 
			hasSubmit = true;
		}
		if(document.response.SUBMIT!=null){
			document.response.SUBMIT.value = "Submitting";			
			document.response.SUBMIT.disabled = true;
		}		
		return true;
	}else{
		return false;
	}
}

//check response fields
function CheckPrescreenField()
{
	errorFound= false;	

	if(document.prescreen.YN_CAN_ANSWER1!=null)
	{
		if(!document.prescreen.YN_CAN_ANSWER1[0].checked && !document.prescreen.YN_CAN_ANSWER1[1].checked)
			error(document.prescreen.YN_CAN_ANSWER1[0], "Please answer each prescreening question.");
	}

	if(document.prescreen.YN_CAN_ANSWER2!=null)
	{
		if(!document.prescreen.YN_CAN_ANSWER2[0].checked && !document.prescreen.YN_CAN_ANSWER2[1].checked)
			error(document.prescreen.YN_CAN_ANSWER2[0], "Please answer each prescreening question.");
	}

	if(document.prescreen.YN_CAN_ANSWER3!=null)
	{
		if(!document.prescreen.YN_CAN_ANSWER3[0].checked && !document.prescreen.YN_CAN_ANSWER3[1].checked)
			error(document.prescreen.YN_CAN_ANSWER3[0], "Please answer each prescreening question.");
	}

	if(document.prescreen.YN_CAN_ANSWER4!=null)
	{
		if(!document.prescreen.YN_CAN_ANSWER4[0].checked && !document.prescreen.YN_CAN_ANSWER4[1].checked)
			error(document.prescreen.YN_CAN_ANSWER4[0], "Please answer each prescreening question.");
	}

	if(document.prescreen.YN_CAN_ANSWER5!=null)
	{
		if(!document.prescreen.YN_CAN_ANSWER5[0].checked && !document.prescreen.YN_CAN_ANSWER5[1].checked)
			error(document.prescreen.YN_CAN_ANSWER5[0], "Please answer each prescreening question.");
	}

	if(document.prescreen.SKILL1!=null)
	{
		if(!document.prescreen.SKILL1[0].checked && !document.prescreen.SKILL1[1].checked)
			error(document.prescreen.SKILL1[0], "Please designate experience in each skill.");
	}

	if(document.prescreen.SKILL2!=null)
	{
		if(!document.prescreen.SKILL2[0].checked && !document.prescreen.SKILL2[1].checked)
			error(document.prescreen.SKILL2[0], "Please designate experience in each skill.");
	}

	if(document.prescreen.SKILL3!=null)
	{
		if(!document.prescreen.SKILL3[0].checked && !document.prescreen.SKILL3[1].checked)
			error(document.prescreen.SKILL3[0], "Please designate experience in each skill.");
	}

	if(document.prescreen.SKILL4!=null)
	{
		if(!document.prescreen.SKILL4[0].checked && !document.prescreen.SKILL4[1].checked)
			error(document.prescreen.SKILL4[0], "Please designate experience in each skill.");
	}

	if(document.prescreen.SKILL5!=null)
	{
		if(!document.prescreen.SKILL5[0].checked && !document.prescreen.SKILL5[1].checked)
			error(document.prescreen.SKILL5[0], "Please designate experience in each skill.");
	}

	if(document.prescreen.WORK_AUTH!=null)
	{
		if(!document.prescreen.WORK_AUTH[0].checked && !document.prescreen.WORK_AUTH[1].checked)
			error(document.prescreen.WORK_AUTH[0], "Please designate work authorization.");
	}

	if(document.prescreen.NOTSEARCH_FIRM!=null)
	{
		if(!document.prescreen.NOTSEARCH_FIRM[0].checked && !document.prescreen.NOTSEARCH_FIRM[1].checked)
			error(document.prescreen.NOTSEARCH_FIRM[0], "Please designate if you are working in conjunction with a search firm.");
	}

	if(document.prescreen.BACHELOR!=null)
	{
		if(!document.prescreen.BACHELOR[0].checked && !document.prescreen.BACHELOR[1].checked)
			error(document.prescreen.BACHELOR[0], "Please designate if you have a bachelor's degree.");
		if(document.prescreen.BACHELOR_AREA!=null)
		{
			if(document.prescreen.BACHELOR[0].checked && document.prescreen.BACHELOR_AREA.selectedIndex==0)
			{
				error(document.prescreen.BACHELOR_AREA,"Please select bachelor's degree major.");
			}
		}
	}

	if(document.prescreen.MASTER!=null)
	{
		if(!document.prescreen.MASTER[0].checked && !document.prescreen.MASTER[1].checked)
			error(document.prescreen.MASTER[0], "Please designate if you have a master's degree.");

		if(document.prescreen.MASTER_AREA!=null)
		{
			if(document.prescreen.MASTER[0].checked && document.prescreen.MASTER_AREA.selectedIndex==0)
			{
				error(document.prescreen.MASTER_AREA,"Please select master's degree major.");
			}
		}
	}

	if(document.prescreen.RELOCATION!=null)
	{
		if(!document.prescreen.RELOCATION[0].checked && !document.prescreen.RELOCATION[1].checked)
			error(document.prescreen.RELOCATION[0], "Please respond if you are willing to relocate yourself to the designated city.");
	}

	if(document.prescreen.CURRENT_SALARY!=null)
	{
		if(CheckSpace(document.prescreen.CURRENT_SALARY.value))
			error(document.prescreen.CURRENT_SALARY, "Please fill in salary requirements.");
		if(CheckNum(document.prescreen.CURRENT_SALARY.value))
			error(document.prescreen.CURRENT_SALARY, "For salary field, please use numerical value only. DO NOT use special characters such as \ndollar signs ($), pound signs (&pound;), dashes (-), or commas (,).");
	}

	return !errorFound;
}

//skip prescreenlds
function SkipPrescreenJob()
{
	document.prescreen.SKIP.value = "TRUE";
	document.prescreen.submit();
}

function SetJobStatus(jobID, status){
      document.cookie = "JS" + jobID + "=" + status + "; path=/";
}

var upLevel = false;
var ns4 = false;
var ie4 = false;
if(document.getElementById) {
	upLevel = true;
}else if(document.layers) {
	ns4 = true;
}else if(document.all) {
	ie4 = true;
}

function showObject(obj) {
	if (ns4) 
		obj.visibility = "show";
	else if (ie4 || upLevel) 
		obj.style.visibility = "visible";
}

function hideObject(obj) {
	if (ns4) {
		obj.visibility = "hide";
	}
	if (ie4 || upLevel) {
		obj.style.visibility = "hidden";
	}
}

function SetInput(inputName, inputValue)
{
  var elem = document.response.elements[inputName];

  if(elem!=null)
  {
    if(elem.type == 'text' || elem.type=='textarea'){
        elem.value = inputValue;
    }
    else if(elem.type == 'select-one')
    {
    	var selectedIndex = -1;
        for(i=0; i<elem.options.length; i++)
        {
            if(elem.options[i].value == inputValue)
				selectedIndex = i;
        }
        if(selectedIndex>=0)
        	elem.options[selectedIndex].selected = true;
    }else if(elem.type == 'select-multiple')
    {
        for(i=0; i<elem.options.length; i++)
        {
            if(elem.options[i].value!='' && (inputValue.indexOf(elem.options[i].value) == 0 ||  inputValue.indexOf("," + elem.options[i].value) >= 0))
                elem.options[i].selected = true;
		else
                elem.options[i].selected = false;
        }
    }else if(elem.type == 'checkbox')
    {
        if(elem.value == inputValue)
            elem.checked = true;
    }else if(elem.type == 'radio')
    {
        if(elem.value == inputValue)    
	        elem.checked = true;
    }else if(elem.length>1 && elem[0].type == 'radio')
    {
         for(i=0; i<elem.length; i++)
        {
            if(elem[i].value == inputValue)
                elem[i].checked = true ;
			else
                elem[i].checked = false ;
        }       
    }
  }
}

uploadOpen=0;
function openUploadWindow()
{
  if(uploadOpen==1 && !uploadWindow.closed)
  {
    uploadWindow.focus();
    uploadWindow.location = serverName + '/jobcart/UploadResume.html';
  }
  else
  {
    uploadWindow=window.open(serverName + '/jobcart/UploadResume.html', 'uploadwin','resizable=1,scrollbars=yes,width=400,height=300');
    uploadOpen=1;
  }
}

function LogOut(destUrl)
{
	var expiration = new Date();
	//Clear the profile id to complete logout
	document.cookie = "ProfileId=; expires=" + expiration.toGMTString() + "; path=/";
	// goto destination (i.e. Job Search page)
	window.location = destUrl;
}

var cstmFieldNum = 0;
var cstmFieldID = new Array();
var cstmFieldName = new Array();

//check custom required custom fields
function CstmFieldCheck(){
    for(i=0; i<cstmFieldNum; i++){
       var elem = document.response[cstmFieldID[i]];
       if(elem.type!=null){
         if(elem.type == 'text' && CheckSpace(elem.value)){
	        error(elem, cstmFieldName[i]);
	     }
	     else if(elem.type == 'checkbox' && !elem.checked)
   	        error(elem, cstmFieldName[i]);
	     else if(elem.type == 'select-one' && elem.selectedIndex==0){  
   	        error(elem, cstmFieldName[i]);
   	     }
 	     
   	   }
	   else if(elem[0].type == 'radio'){
	      var radioSelected = false;
	      for(j=0; j<elem.length; j++){
	          if(elem[j].checked)
	          {
	              radioSelected = true;
	          }
	      }
	      if(!radioSelected)
	   	      error(elem[0], cstmFieldName[i]);
   	   }
   	   if(errorFound)
   	       break;
    }
	return !errorFound;
}

//check required fields for ERP submit form
function CheckERPField()
{
   errorFound = false;

   var numRef = 0;
   if(CheckSpace(document.referral.EMP_FIRST_NAME.value))
      error(document.referral.EMP_FIRST_NAME,"Please fill in your first name.");
   else if(CheckSpace(document.referral.EMP_LAST_NAME.value))
      error(document.referral.EMP_LAST_NAME,"Please fill in your last name.");
   else if(CheckSpace(document.referral.EMP_EMAIL.value))
      error(document.referral.EMP_EMAIL,"Please fill in your e-mail address.");
   else if(!CheckEmailAddress(document.referral.EMP_EMAIL.value))
	  error(document.referral.EMP_EMAIL, "Please fill in a valid e-mail address.");	
	  
   if(!CheckSpace(document.referral.NAME1.value))
   {
      numRef += 1;
      if(CheckSpace(document.referral.EMAIL1.value) || !CheckEmailAddress(document.referral.EMAIL1.value))
      	error(document.referral.EMAIL1,"Please fill in an valid e-mail address for this referral.");
   }
   
   if(!CheckSpace(document.referral.NAME2.value))
   {
      numRef += 1;
      if(CheckSpace(document.referral.EMAIL2.value) || !CheckEmailAddress(document.referral.EMAIL2.value))
      	error(document.referral.EMAIL2,"Please fill in an valid e-mail address for this referral.");
   }
   
   if(!CheckSpace(document.referral.NAME3.value))
   {
      numRef += 1;
      if(CheckSpace(document.referral.EMAIL3.value) || !CheckEmailAddress(document.referral.EMAIL3.value))
      	error(document.referral.EMAIL3,"Please fill in an valid e-mail address for this referral.");
   }
   
   if(!CheckSpace(document.referral.NAME4.value))
   {
      numRef += 1;
      if(CheckSpace(document.referral.EMAIL4.value) || !CheckEmailAddress(document.referral.EMAIL4.value))
      	error(document.referral.EMAIL4,"Please fill in an valid e-mail address for this referral.");
   }

   if(!CheckSpace(document.referral.NAME5.value))
   {
      numRef += 1;
      if(CheckSpace(document.referral.EMAIL5.value) || !CheckEmailAddress(document.referral.EMAIL5.value))
      	error(document.referral.EMAIL5,"Please fill in an valid e-mail address for this referral.");
   }
   
   if(numRef==0)
       error(document.referral.NAME1,"Please fill in at least one referral name");
   
   return !errorFound;
}

function SetERPCode()
{
	var erpCode = "";
	argstr = top.location.href;
	idx = argstr.indexOf("ERP_CODE=");
	if(idx>0){
		erpCode = argstr.substring(idx + 9, argstr.length);	
	    document.cookie = "ERP_CODE=" + erpCode + "; path=/";    		
	}
}

function SetSearchPage(searchPage)
{
	document.cookie = "SEARCH_PAGE=" + searchPage + "; path=/";    		
}

function ResetForm(){
	if(document.response.PROFILE_RESUME_UPLOADED==null || document.response.PROFILE_RESUME_UPLOADED.value != 'true'){
	    document.response.reset();			
	    document.response.UPLOADED.value = "";
 		if(document.getElementById) {
			ChangeDisplay(document.getElementById("resume_text_area"), "block");
			ChangeDisplay(document.getElementById("resume_paste_message"), "block");
			ChangeDisplay(document.getElementById("resume_uploaded_message"), "none");
		}else if(document.layers) {
			ChangeDisplay(document.resume_text_area, "block");
			ChangeDisplay(document.resume_paste_message, "block");
			ChangeDisplay(document.resume_uploaded_message, "none");
		}else if(document.all) {
			ChangeDisplay(document.all.resume_text_area, "block");
			ChangeDisplay(document.all.resume_paste_message, "block");
			ChangeDisplay(document.all.resume_uploaded_message, "none");
		}
		if(document.response.previewResume!=null)
			document.response.previewResume.disabled=false;
	}else{
	    document.response.reset();		
		disableResumePreview();
		initCountry();
	}
	
	if(document.response.ACCT_SOURCE_ID != null && document.response.ACCT_SOURCE_ID.type == 'select-one'){
		document.response.ACCT_SOURCE_ID.length = 1;
		document.response.ACCT_SOURCE_ID.options[0] = new Option("Please select a source.", "", false, false);
	}	
}

function ChangeDisplay(obj, str){
	if(obj!=null){
		obj.style.display = str;
	}
}

function ProcessAssessments(vendorUrls)
{
	var ArrURLs = new Array();
	var CurrentURL = new String();
	var CookieURLs = new String();
					
	ArrURLs = vendorUrls.split("||");
	CurrentURL = ArrURLs.shift();
					
	for (i=0;i<ArrURLs.length;i++)
	{
		if (i != 0)
			CookieURLs += "||";
					
		CookieURLs += ArrURLs[i];						
	}

	var Today = new Date();
	var Expire = new Date();					
					
	if (CookieURLs != "")
	{
		Expire.setTime(Today.getTime() + 3600000*24*1);
		document.cookie = "WHVendor="+escape(CookieURLs)+";expires="+Expire.toGMTString();						
	}
	else
		document.cookie = "WHVendor=;expires="+Today.toGMTString();
					
	if (CurrentURL != "")
	{
		window.location.href = CurrentURL;
		return;
	}
}

function SetBoardID()
{
	var boardID = GetCookieValue("BOARD_ID");
	if(boardID.length>0 && boardID!="111111" && boardID!="222222"){
		document.Apply.BOARD_ID.value = boardID;
	}
	
	var Today = new Date();	
	document.cookie = "BOARD_ID=;expires="+Today.toGMTString();
}


function ValidatePrescreenTemplate()
{
	var Valid = ValidateRenderedFields();
	
	return Valid;
}

function ApplyComplet(){
	var monsterCompletURL = GetCookieValue("MONSTER_APPLY_COMPLET_URL");
	//send monster signal that apply complet
	if(monsterCompletURL!=null &&  monsterCompletURL.length>10){
		if (IEBrowser)
		{
			document.frames("monsterSource").location = monsterCompletURL;
		}else if ( W3C )
		{
			document.getElementsByTagName('iframe')['monsterSource'].setAttribute("src", monsterCompletURL);
		}
		else{
			document.layers["monsterSource"].src = monsterCompletURL;	
		}
		SetCookieValue("MONSTER_APPLY_COMPLET_URL", "");
	}
}

function disableResumePreview(){
    document.response.UPLOADED.value = "true";
    document.response.PROFILE_RESUME_UPLOADED.value = "true";
    var resumeText;
    var pastMessage;
    var uploadMessage;
 	if(document.getElementById) {
		resumeText = document.getElementById("resume_text_area");
		pastMessage = document.getElementById("resume_paste_message");
		uploadMessage = document.getElementById("resume_uploaded_message");
	}else if(document.layers) {
		resumeText = document.resume_text_area;
		pastMessage = document.resume_paste_message;
		uploadMessage = document.resume_uploaded_message;
	}else if(document.all) {
		resumeText = document.all.resume_text_area;
		pastMessage = document.all.resume_paste_message;
		uploadMessage = document.all.resume_uploaded_message;
	} 
	if(resumeText!=null)
		resumeText.style.display="none";
	if(pastMessage!=null)
		pastMessage.style.display="none";
	if(uploadMessage!=null){
		uploadMessage.style.display="block";	
	}		
	document.response.previewResume.disabled=true;
}

//resume parsing
var rpInputNames = new Array();
var rpInputValues = new Array();

function resumeParsing(){
	var countryChange = false;
	var changeFromInput = false;

	for(i=0; i<rpInputNames.length; i++){
		inputName = rpInputNames[i];
		inputValue = rpInputValues[i];
		var element = document.response[inputName];
		
		if(element!=null && inputValue.length>0)
		{
			inputValue = inputValue.replace("&amp;", "&");
			if(element.value.length>0 && element.value != inputValue)
			{
				changeFromInput = true;
				break;
			}
		}
	}
	
	var replace = true;
	if(changeFromInput){
		replace = confirm("Some of data we extracted from your resume is different from the data you have typed in.\nDo you want to overwrite your typed in data with the data we extracted from your resume?");	
	}
	
	if(replace){
	
		for(i=0; i<rpInputNames.length; i++){
			inputName = rpInputNames[i];
			inputValue = rpInputValues[i];
			var element = document.response[inputName];
		
			if(element!=null && inputValue.length>0)
			{
				inputValue = inputValue.replace("&amp;", "&");

				if(inputName=='COUNTRY_CODE_1'){
					countryChange = true;
					countryCode1 = inputValue;
				}else if(inputName=='STATE_CODE_1')
				{
					stateCode1 = inputValue;
				}else
				{
					element.value = inputValue;
				}
			}
		}	
	}
	
	if(countryChange){
		initCountry();
	}else{
		SetInput('STATE_CODE_1', stateCode1);
	}
}

function EnableExtractButton(){
	if(document.response.extractResume != null){
		document.response.extractResume.disabled=false;
	}
}

function ExtractResume(){
	count = CountWord(document.forms["response"].RESUME_INPUT.value);
	if(count<52){
		alert("You resume has only " + count + " words. Please enter a resume that has more than 51 words.");
		return false;
	}

	document.forms["ExtractFrm"].RESUME.value = document.forms["response"].RESUME_INPUT.value;
	var WinObj; //window object
	var WindowURL =	serverName + "/jobcart/PleaseWait.html";
	var WindowName = "PreviewWindow";	
	var WinObj = window.open(WindowURL, WindowName, "height=490,width=850,resizable=yes,scrollbars=yes,titlebar=yes,left=250,top=50");		
	document.forms["ExtractFrm"].submit();
	WinObj.focus();
}

function CountWord(text){
	var count = 0;
	a = text.replace(/\s/g,' ');
	a = a.split(' ');
	for (z=0; z<a.length; z++) 
	{
		if (a[z].match("^[a-zA-Z]+")) 
		{
			count++;
		}
	}
	return count;
} 

function isInt(myNum) {
    // get the modulus: if it's 0, then it's an integer
    var myMod = myNum % 1;
    if (myMod == 0) {
       return true;
    } else {
       return false;
    }
}


//check education fields to see that the GPA and year are correct
function checkEducation(){
	if(document.response['SHOW_EDU_FLAG'] != null && document.response['SHOW_EDU_FLAG'].value==1){
		for(j=1; j<4 && !errorFound; j++){
		
			var element = document.response['END_YEAR_' + j];
			if(element.value.length>0 && (CheckNum(element.value) || !isInt(element.value))){
				error(element, "Please enter a valid year.");		
			}else{
				element = document.response['GPA_' + j];
				if(element.value.length>0 && CheckNum(element.value)){
					error(element, "Please enter a valid GPA number.");		
				}				
			}
		}
		return !errorFound;		
	}else{
		return true;
	}	
}

//check experience fields to see that the GPA and year are correct
function checkExperience(){

	if(document.response['SHOW_EXP_FLAG'] != null && document.response['SHOW_EXP_FLAG'].value==1){

		for(j=1; j<4 && !errorFound; j++){
			
 			var element = document.response['EXP_START_YEAR_' + j];
 			var	element1 = document.response['EXP_END_YEAR_' + j];
			
			if(element.value.length>0 && (CheckNum(element.value) || !isInt(element.value))){
				error(element, "Please enter a valid year.");		
			}else{
				if(element1.value.length>0 && (CheckNum(element1.value) || !isInt(element1.value))){
					error(element1, "Please enter a valid year.");		
				}
			}

			if ( element.value.length>0 && element1.value.length>0 && element1.value < element.value ) 
			{
				error(element1, "End year can not be earlier than start year.");
			}
				
		}
		return !errorFound;
	}else{
		return true;
	}
}


function CleanApplyCookies(){
	var expiration = new Date();
      document.cookie = "WORK_AUTH=; expires=" + expiration.toGMTString() + "; path=/";
      document.cookie = "NOTSEARCH_FIRM=; expires=" + expiration.toGMTString() + "; path=/";
      document.cookie = "CURRENT_SALARY=; expires=" + expiration.toGMTString() + "; path=/";
      document.cookie = "BACHELOR=; expires=" + expiration.toGMTString() + "; path=/";
      document.cookie = "MASTER=; expires=" + expiration.toGMTString() + "; path=/";
}

function PageLoad(){
	//do nothing, need to overwrite for individual page if we need to do something
}