﻿var abc = new Array();
abc = getABC();
var DIVpositions;
var somethingChanged = false;
var isHomeSearch = 0;
var cookie_name = "RMSearch";

function writeABC()
{
	var HTML = "";			
			
		HTML += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"FONT\">";
		for( var j = 0; j < abc.length; j ++ )
		{
			HTML += "<tr>";
			for( var i = 0; i < abc[j].length; i ++ )
			{			
				HTML += "<td align=center><a href=\"javascript:getLetter('" + abc[j].substr(i,1) + "')\" style=\"TEXT-TRANSFORM: uppercase\" class=\"FNT_BlackTxt\"><u>" + abc[j].substr(i,1) + "</u></a></td>"
				HTML += "<td> &nbsp; </td>"

				if(j==0 && i == parseInt(abc[j].length/2) -1 )
					HTML += "<td>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr>"
			}
				
			if(j==abc.length-1 )
				HTML += "<td colspan=\"20\"><a href=\"javascript:ClearList()\" style=\"TEXT-TRANSFORM: uppercase\" class=\"FNT_BlackTxt\"> Cancel </a></td>"

			HTML += "</tr>";			
		}			
		HTML += "</table>";

	return HTML;		
}	

function setSearchByCompanyDisplay(IsOnload)
{
	if(getObj('SearchByCompanyTR').style.display == 'none')
	{
		getObj('SearchByCompanyTR').style.display = ''
			if ( typeof( getObj('abcTable') ) != 'undefined' && getObj('abcTable') != null)
				getObj('abcTable').style.display = ''
 	}	
	else
	{
	   getObj('SearchByCompanyTR').style.display = 'none'
		 if ( typeof( getObj('abcTable') ) != 'undefined' && getObj('abcTable') != null)
		 	getObj('abcTable').style.display = 'none'
		 	 if(IsOnload!=1)
				{
			 	  document.theForm.Letter.value=''
				  parent.frames[0].document.hiddenForm.Letter.value=''
				  document.theForm.CompaniesList.length = 0;
				}
   }
}	

function getLetter( letter )
{	
	parent.frames[0].document.hiddenForm.action += '&AffiliateId=' + document.theForm.AffiliateID.value;
	document.theForm.Letter.value = letter;
	parent.frames[0].document.hiddenForm.Letter.value = letter;
	parent.frames[0].document.hiddenForm.submit();
}	

function SetDropDownsValue(objSelect,selectedValue)
{
	for(var i=0; i <= objSelect.length - 1;i++)
		if(objSelect[i].value==selectedValue)
		{
			objSelect.selectedIndex = i
			break;
		}
}			

function setFields()
{
	extractField()
	var UpperLimit = (fields.length) + 1;

	document.theForm.Field.length = UpperLimit;
	for ( i = 1 ; i < UpperLimit ; i++ )	
	{
		document.theForm.Field.options[i].value = fields[i-1][0];
		document.theForm.Field.options[i].text = fields[i-1][1];
	}
}	

function ClearList()
{
	 document.theForm.CompaniesList.length = 0;
	document.theForm.CompaniesList.selectedIndex = -1;
}	

function setSelectedCompaniesDefault()
{

	if(document.theForm.Letter.value!='') 
	{
	   parent.frames[0].document.hiddenForm.Letter.value = document.theForm.Letter.value
	   parent.frames[0].document.hiddenForm.AffiliateID.value = document.theForm.AffiliateID.value	   	   
	}   


	if(typeof(parent.frames[0].document.hiddenForm)!='undefined' && parent.frames[0].document.hiddenForm.Letter.value!='')
	{
	   parent.frames[0].document.hiddenForm.submit();
	  // setSearchByCompanyDisplay()
	}
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function deleteCookies()
{
	eraseCookie("pagerPosition");
	eraseCookie("scrollPos");
}

function setScrollPos()
{
	var scrollPosition;
	if (window.pageYOffset)
		scrollPosition = window.pageYOffset; 
	else if (parent.document.documentElement.scrollTop)
		scrollPosition = parent.document.documentElement.scrollTop; 
	else
		scrollPosition = parent.document.body.scrollTop;
	
	createCookie("scrollPos", scrollPosition, 0);
}

function scrollToPos()
{
	if(readCookie("scrollPos")!= null)
		parent.window.scrollTo(0,Number(readCookie("scrollPos")));
}

function checkValidation( ChunckNumber )
{
	if (typeof(ChunckNumber) != 'undefined') {
		if (ChunckNumber == null || ChunckNumber == 'undefined')
			document.theForm.ChunckNumber.value = 1;
		else 
			document.theForm.ChunckNumber.value = (typeof(ChunckNumber) != 'undefined')?ChunckNumber:1
	}
	else {
		if (typeof(document.theForm.ChunckNumber) != 'undefined')
			document.theForm.ChunckNumber.value = 1
	}

	if(isAdvancedSearch == 1)
		checkValidation_Advanced();
	else
		{
            document.theForm.AdvancedCityId.value =  '';
            checkValidation_Basic();
      }
}

function checkValidation_Advanced()
{
	var obj = document.theForm

	document.theForm.isAdvancedSearch.value = "0";
	document.theForm.FromAdvancedSearch.value = "1";
	document.theForm.target = '_self';
	document.theForm.action = 'c.asp?action=employee.RMSearchResults.init';
	document.theForm.submit();		
}

function checkValidation_Basic()
{
	var obj = document.theForm

	if(isHomeSearch == 0)
	{
//		document.theForm.CompaniesList.value =  '';
		document.theForm.CountryId.value =  '-1';
		document.theForm.JobType.value =  '-1';
		document.theForm.EducationLevelId.value =  '-1';
		document.theForm.ExperienceId.value =  '-1';
		document.theForm.PostedWithin.value =  '-1';
		document.theForm.SalaryMin.value =  '';
		document.theForm.SalaryMax.value =  '';
		document.theForm.ManagerialList.value =  '';
		document.theForm.FieldList.value =  '';
		document.theForm.FreeTextUsing.value =  '';
		document.theForm.IndustryList.value =  '';
		//document.theForm.CompanyId.value =  '';
	}

	var mesAlert = '';
		if(obj.City.selectedIndex != '-1' && typeof(obj.City[obj.City.selectedIndex].IsDefaultCity)!= 'undefined')
			obj.IsDefaultCity.value = obj.City[obj.City.selectedIndex].IsDefaultCity;			
		else
			obj.IsDefaultCity.value = 0;			
			
		obj.keyword.value = ltrim(obj.keyword.value)
		
		if (typeof(obj.CompaniesList) == 'undefined' || obj.CompaniesList == null)
		    var objCompIndex = '-1'
		else {
		    var objCompIndex = obj.CompaniesList.selectedIndex	
		    if (objCompIndex == -1) {
			 document.theForm.Letter.value=''
			 parent.frames[0].document.hiddenForm.Letter.value=''
			 document.theForm.CompaniesList.length = 0;
		    }	
		}
	
		var ObjFreeCity = ''		
		if (typeof(obj.FreeCity) != 'undefined')
			 ObjFreeCity = obj.FreeCity.value
	
		//if (obj.Managerial.value == '-1' && obj.Field.value == '-1' && obj.City.value == '-1' && obj.keyword.value == '' &&  (typeof(obj.Industry)=='undefined' || (typeof(obj.Industry)!='undefined' && obj.Industry.value == '-1')) )
		//	mesAlert+= 'Please select at least one search criteria in order to narrow down the result set'			
		
		if (obj.keyword.value != '' && obj.keyword.length < 2 )
		{
			alert('Please enter at least three characters into the "Keyword" field.')
			return 
		}			
			

		if (ObjFreeCity != '' && ObjFreeCity.length < 2 )
		{
			alert('  Please enter at least two characters into the "Free City Text" field. ')
			return 
		}			
					
		//if(mesAlert != '')
		//{
		//	alert('Please select at least one search criteria in order to narrow down the result set')
		//	return 
		//}
		//else
		//{
			if (getObj('divWait') != null)
			    getObj('divWait').style.display= "block"
			if (getObj('SearchPositionsTable') != null)
			    getObj('SearchPositionsTable').style.height= "0px"			

			if (getObj('TopJobsApp') != null) getObj('TopJobsApp').style.visibility="hidden";			    
			    
			if (typeof(obj.FromAdvancedSearch)!='undefined' && typeof(obj.FromAdvancedSearch)!=null)
				obj.FromAdvancedSearch.value = "0";
		
			if (typeof(obj.Managerial)!='undefined' && obj.Managerial.value == '-1' && typeof(obj.Field)!='undefined' && obj.Field.value == '-1' &&
				obj.City.value == '-1' && obj.keyword.value == '' && ObjFreeCity == '' && typeof(obj.Industry)!='undefined' && obj.Industry.value == '-1')
				obj.FirstSearch.value=1;
			else
				obj.FirstSearch.value=0;
			if(obj.userId.value=='' && DoNotKeepSearchValuesInCookies != 1)
			{
				setCookie("keyword",obj.keyword.value)
				setCookie("Managerial",(typeof(obj.Managerial)!='undefined')? obj.Managerial.value:'')
				setCookie("Field",(typeof(obj.Field)!='undefined')? obj.Field.value:'')
				setCookie("Industry",(typeof(obj.Industry)!='undefined')? obj.Industry.value:'')
				setCookie("City",obj.City.value)
				setCookie("FirstSearch",obj.FirstSearch.value)
				if (obj.IsAdditionalLocations.checked)
					setCookie("IsAdditionalLocations",1)
				else	
					setCookie("IsAdditionalLocations","")
					setCookie("FreeCity",(typeof(obj.FreeCity)!='undefined')? obj.FreeCity.value:'')
				}	
			else
				{
				 deleteCookie("keyword","","")
				 deleteCookie("Managerial","","")
				 deleteCookie("Field","","")
				 deleteCookie("City","","")
				 deleteCookie("FirstSearch","","")
				 deleteCookie("IsAdditionalLocations","","")
				 deleteCookie("FreeCity","","")
				}
	
			obj.submit();
		//}	
}

function getFields()
{
	return;
	if( document.theForm.Managerial.selectedIndex <= 0 )
		{
			document.theForm.Field.length = 1;				
			return;
		}
	parent.frames[0].window.location.href = "c.asp?" + 
		  "action=employee.RMSearch.getField" + 
		  "&param=" +
		  "<RMSearch><field" +
			"managerial=\"" + document.theForm.Managerial.options[document.theForm.Managerial.selectedIndex].value + "\"" +
			"/></RMSearch>";							
	
			document.theForm.Field.selectedIndex = 0;			
}
function extractField()	{ 	var ii,jj	for ( ii = 0 ; ii < fields.length ; ii++ ) 		{			fields[ii].length = fields[ii].length + 1  			fields[ii][4] = '1'			for (  jj = 0 ; jj  < arrCategoryListPos.length ; jj++ ) 
				{					if( fields[ii][0] == arrCategoryListPos[jj] ) 
					{						fields[ii][4] = '0';						break;					}					}	
		}	}function extractCity()
{
			var jj, ii
			for ( ii = 0 ; ii < cities.length ; ii++ ) 
				for (  jj = 0 ; jj < arrCityListPos.length ; jj++ ) {
					cities[ii][2] = 0;
					if( cities[ii][0] == arrCityListPos[jj] ) {
						cities[ii][2] = 1;
						break;
					}	
				}

			for ( ii = 0 ; ii < AffiliateLocations.length ; ii++ ) 
				for (  jj = 0 ; jj  < arrCityListPos.length ; jj++ ) {
					AffiliateLocations[ii][2] = 0;
					if( AffiliateLocations[ii][0] == arrCityListPos[jj]  || AffiliateLocations[ii][3] == 'IsDefaultCity') {
						AffiliateLocations[ii][2] = 1;
						break;
					}	
				}

}
	
function setSelectedCities()
{
	
	var arrCities =new Array();
	var DPobj = document.theForm.City		
	if (CityList != '') DPobj.options[0].selected=false		
	arrCities = CityList.split(',')	
	
	var tmpI = null;
	for (var i=0;i<arrCities.length;i++)
	{
		if( arrCities[i] < 0 )
		{
			tmpI = i;
			break;
		}
	}

	if(tmpI != null)
		arrCities.splice(tmpI, 1)

	

	for (i=0;i<arrCities.length;i++)		
	{ 
	  for (j=0;j<DPobj.length;j++)	
	  {
		if (trim(DPobj.options[j].value) == trim(arrCities[i]))
		{			
			DPobj.options[j].selected=true;			
			break;
		}	
	  }	
    }
if(DPobj.selectedIndex == -1  )
DPobj.selectedIndex = 0;

}		

function getCity()
{
	document.hiddenForm.action = 'c.asp?action=employee.RMSearchResults.getCities&CountryId=' + document.theForm.CountryId.value
	document.hiddenForm.target = parent.frames[0].name
	document.hiddenForm.submit();
}

