function validateForm(){
	// define variables
	var locationCount, i, industryCount=0
	
	locationCount = document.jobsearchAdvanced.selectedLocations.length;
	// check how many locations selected
	for (i=0; i<document.jobsearchAdvanced.selectedLocations.length; i++) {
		document.jobsearchAdvanced.selectedLocations[i].selected = true; 
	}
	
	// check how many industires selected
	for ( i=0; i<document.jobsearchAdvanced.categoryID.length; i++) {
		if(document.jobsearchAdvanced.categoryID[i].selected == true && document.jobsearchAdvanced.categoryID[i].value !=0){
			industryCount++;}
	}
	
	if (locationCount > 5) {
		alert("You can only select a maximum of 5 Locations.");
		return false;
	}
	else if (industryCount > 3) {
		alert("You can only select a maximum of 3 Industries.");
		return false;
	}
	else if (document.jobsearchAdvanced.categoryID[0].selected == true && industryCount >1 ) {
		alert("If you selected No Preference, You should NOT select other industries.");
		return false;
	}
	else
	{
		return true;
	}

}

function MoveOption(objSourceElement, objTargetElement)
{
    var aryTempSourceOptions = new Array();
    var x = 0;
    
    //looping through source element to find selected options
    for (var i = 0; i < objSourceElement.length; i++) {
        if (objSourceElement.options[i].selected) {
            //need to move this option to target element
            var intTargetLen = objTargetElement.length++;
            objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
            objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
        }
        else {
            //storing options that stay to recreate select element
            var objTempValues = new Object();
            objTempValues.text = objSourceElement.options[i].text;
            objTempValues.value = objSourceElement.options[i].value;
            aryTempSourceOptions[x] = objTempValues;
            x++;
        }
    }
    
    //resetting length of source
    objSourceElement.length = aryTempSourceOptions.length;
    //looping through temp array to recreate source select element
    for (var i = 0; i < aryTempSourceOptions.length; i++) {
        objSourceElement.options[i].text = aryTempSourceOptions[i].text;
        objSourceElement.options[i].value = aryTempSourceOptions[i].value;
        objSourceElement.options[i].selected = false;
    }
}
function AddOption(CityState_text, CityState_value, objTargetElement)
{
     var intTargetLen = objTargetElement.length++;
     objTargetElement.options[intTargetLen].text = CityState_text;
     objTargetElement.options[intTargetLen].value = CityState_value;
}
function MoveOptionwithCity(objSourceElement, objCity, objTargetElement)
{
    var aryTempSourceOptions = new Array();
    var x = 0;
    var e;

     var intTargetLen = objTargetElement.length++;
    if(!objSourceElement.options[0].selected) // state is selected
    {
      	for (var j = 0; j < objSourceElement.length; j++) {
       		if (objSourceElement.options[j].selected) {	
       		objTargetElement.options[intTargetLen].text = 'Entire Sate, '+objSourceElement.options[j].value;
       		objTargetElement.options[intTargetLen].value = 'Entire Sate, '+objSourceElement.options[j].value;
       		}
	    }
	}

}
function MoveOptionCountryState(objCountry, objState, objTargetElement)
{
    if(objCountry.options[0].selected){
    	alert("Please select a country");
    	return;
    }
    var aryTempSourceOptions = new Array();
    var x = 0;
    var intTargetLen = objTargetElement.length++;
    if(!objState.options[0].selected) // state is selected so we will copy Country, Entire State, State and remove the state from the combo
    {
      	for (var j = 0; j < objState.length; j++) {
       		if (objState.options[j].selected) {
       			for ( var k=0 ; k < objCountry.length; k++){
       				if (objCountry.options[k].selected) {	
       					if(objCountry.options[k].value=="Canada"){
       						objTargetElement.options[intTargetLen].text = 'Canada, '+objState.options[j].value;
       					}else{	
    						objTargetElement.options[intTargetLen].text = 'Entire State, '+objState.options[j].text;}
    					objTargetElement.options[intTargetLen].value = objCountry.options[k].value+';'+objState.options[j].value+';ALL';	
    				}
       			}
       		}else{
	            //storing options that stay to recreate select element
	            var objTempValues = new Object();
	            objTempValues.text = objState.options[j].text;
	            objTempValues.value = objState.options[j].value;
	            aryTempSourceOptions[x] = objTempValues;
	            x++;
            }
	    }
	    //resetting length of source
	    objState.length = aryTempSourceOptions.length;
	    //looping through temp array to recreate source select element
	    for (var i = 0; i < aryTempSourceOptions.length; i++) {
	        objState.options[i].text = aryTempSourceOptions[i].text;
	        objState.options[i].value = aryTempSourceOptions[i].value;
	        objState.options[i].selected = false;
	    }   
	}else
	{
		// state not selected, so add whole country
		for ( var k=0 ; k < objCountry.length; k++){
			if (objCountry.options[k].selected) {	
				objTargetElement.options[intTargetLen].text = objCountry.options[k].text + ', ALL';
				objTargetElement.options[intTargetLen].value = objCountry.options[k].value + ';ALL;ALL';
				hidetargetboxes();			
			}else{
	            //storing options that stay to recreate select element
	            var objTempValues = new Object();
	            objTempValues.text = objCountry.options[k].text;
	            objTempValues.value = objCountry.options[k].value;
	            aryTempSourceOptions[x] = objTempValues;
	            x++;
	        }
		}
	    //resetting length of source
	    objCountry.length = aryTempSourceOptions.length;
	    //looping through temp array to recreate source select element
	    for (var i = 0; i < aryTempSourceOptions.length; i++) {
	        objCountry.options[i].text = aryTempSourceOptions[i].text;
	        objCountry.options[i].value = aryTempSourceOptions[i].value;
	        objCountry.options[i].selected = false;
	    }   
		
	}

}


function RemoveMoveOption(objSourceElement, objCountry, objState)
{
    var aryTempSourceOptions = new Array();
    var x = 0;
    // add option to the coutry/state combo
    var selem="";
    var selemtext="";
    var selemarr;
    var selemtextarr;
    
    
    //looping through source element to find selected options
    for (var i = 0; i < objSourceElement.length; i++) {
        if (objSourceElement.options[i].selected==false)  {
            //storing options that stay to recreate select element
            var objTempValues = new Object();
            objTempValues.text = objSourceElement.options[i].text;
            objTempValues.value = objSourceElement.options[i].value;
            aryTempSourceOptions[x] = objTempValues;
            x++;
        }else{
        	// have the selected element; get the value
        	selem = objSourceElement.options[i].value;
        	selemarr=selem.split(";");
        	selemtext = objSourceElement.options[i].text;
        	selemtextarr=selemtext.split(",");
        	if (selemarr[1]=="ALL"){
    			var intTargetLen = objCountry.length++;
    			objCountry.options[intTargetLen].text = selemarr[0];
    			objCountry.options[intTargetLen].value = selemarr[0];
				sortCountries(objCountry);
        	}else if(selemarr[2]=="ALL") {
    			var intTargetLen = objState.length++;
    			objState.options[intTargetLen].value = selemarr[1];
    			objState.options[intTargetLen].text = trim(selemtextarr[1]);
				sortStates(objState);
        	}
        }
        
    }
    
    //resetting length of source
    objSourceElement.length = aryTempSourceOptions.length;
    //looping through temp array to recreate source select element
    for (var i = 0; i < aryTempSourceOptions.length; i++) {
        objSourceElement.options[i].text = aryTempSourceOptions[i].text;
        objSourceElement.options[i].value = aryTempSourceOptions[i].value;
        objSourceElement.options[i].selected = false;
    }
}

function sortCountries(objCountry){
	var tempSort = new Array();
	
	for(i=1; i< objCountry.length; i++){
		tempSort[i-1] = new Array();
		if (objCountry.options[i].text=="United States")
		{
			tempSort[i-1][0] = "1";
			tempSort[i-1][1] = "1";
		}else if (objCountry.options[i].text=="Canada")
		{
			tempSort[i-1][0] = "2";
			tempSort[i-1][1] = "2";
		}
		else if (objCountry.options[i].text=="(Not on the list)")
		{
			tempSort[i-1][0] = "zzz";
			tempSort[i-1][1] = "zzz";
		}else
		{	
			tempSort[i-1][0] = objCountry.options[i].text;
			tempSort[i-1][1] = objCountry.options[i].value;
		}
	}
	objCountry.selectedIndex = 0;
	var selectedValue = objCountry.options[objCountry.selectedIndex].value;
	tempSort.sort();
	for(i=1; i<objCountry.length; i++){
		objCountry.options[i].text = tempSort[i-1][0];
		objCountry.options[i].value = tempSort[i-1][1];
	}
	objCountry.selectedIndex = 0;
	
	// redo Us, Canada, not in the list
	for(i=1; i<objCountry.length; i++){
		if (objCountry.options[i].text=="1")
		{
			objCountry.options[i].text="United States";
			objCountry.options[i].value="United States";
		}else if (objCountry.options[i].text=="2")
		{
			objCountry.options[i].text="Canada";
			objCountry.options[i].value="Canada";
		}else if (objCountry.options[i].text=="zzz")
		{
			objCountry.options[i].text="(Not on the list)";
			objCountry.options[i].value="Other";
		}
	}
} 

function sortStates(objState){
	var tempSort = new Array();
	for(i=1; i<objState.length; i++){
		tempSort[i-1] = new Array();
		tempSort[i-1][0] = objState.options[i].text;
		tempSort[i-1][1] = objState.options[i].value;
	}
	objState.selectedIndex = 0;
	var selectedValue = objState.options[objState.selectedIndex].value;
	tempSort.sort();
	for(i=1; i<objState.length; i++){
		objState.options[i].text = tempSort[i-1][0];
		objState.options[i].value = tempSort[i-1][1];
	}
	objState.selectedIndex = 0;
}



    function getcityforstate(statename)
    {
		document.jobsearchAdvanced.ecity.value="";
      	//lookupcity(statename);
      	lookupcbsa(statename);
    }
    function getcityforstatefiltered(thediv,statename, cityfilter, target, formname)
    {
      lookupcityfiltered(thediv,statename, cityfilter, target, formname);
    }
    function getcityforzip(zipcode)
    {
      lookupcitystate(zipcode);
    }

var cX = 0; var cY = 0; var rX = 0; var rY = 0;

function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+1) + "px";
d.style.top = (cY+1) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
//AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}

function SelectHideContent(d,CityState, objTargetElement) {
var selemarr;
var city="";
var state="";
var staten="";
if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
	if(objTargetElement=="primary")
	{
       	selemarr=CityState.split(",");
       	city=selemarr[0];
       	state=selemarr[1];
       	staten=selemarr[2];
		document.getElementById(objTargetElement).value=city+','+state;
		document.getElementById("primarychange").value=1;
		document.getElementById("prLocation").value=state+';'+city;
	} else
	{
       	selemarr=CityState.split(",");
       	city=selemarr[0];
       	state=selemarr[1];
       	staten=selemarr[2];
		AddOption(city+', '+state,'United States;'+state+';'+city , objTargetElement); 
		document.getElementById("ecity").value="type city name";
	}
}

// function w/ new data input: formname
function getcityforstatefiltered2(thediv,statename, cityfilter, target, formname)
{
  lookupcityfiltered2(thediv,statename, cityfilter, target, formname);
}

//-------------------------------------------------------
//new function for zipcode box in resume search result 
function getZipcodeCityInResult(thediv, qryfilter, strInPg)
    {
      lookupZipcodeCityInResult(thediv, qryfilter, strInPg);
    }
	
function SelectHideListInBox(d,CityState,str) {
	
		var selemarr;
		var zipcode="";
		var city="";
		var state="";
		if(d.length < 1) { return; }
		document.getElementById(d).style.display = "none";
       	selemarr=CityState.split(",");
		zipcode= selemarr[0];
       	city=selemarr[1];
       	state=selemarr[2];
		if (str == "zc")
		{
			document.getElementById("zipcodecity").value = zipcode+' '+city+', '+state;
			//document.getElementById("zipcodecityInH").value = zipcode+' '+city+', '+state;;
		}
		else if (str == "cl")
		{
			document.getElementById("zipcodecity").value = city+', '+state;;
			//document.getElementById("zipcodecityInH").value = city+', '+state;;
		}
	}
	
	
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

	
