var DIVpositions;
var somethingChanged = false;
var abc = new Array()
abc = getABC()
var cookie_name = "RMSearch"

function writeABC()
{
		var HTML = "";			
			
			HTML += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"FONT\">";
			HTML += "<tr>";
			for( var j = 0; j < abc.length; j ++ )
			{
				for( var i = 0; i < abc[j].length; i ++ )
				{							
					HTML += "<td ><a href=\"javascript:getLetter('" + abc[j].substr(i,1) + "')\" style=\"TEXT-TRANSFORM: uppercase\" class=\"FNT_LightBlueTxt_Smaller\"><u>" + abc[j].substr(i,1) + "</u></a></td>"
					HTML += "<td> &nbsp; </td>"
					if ((i + 1)%18 == 0)
					   HTML += "<TR/>"
				}				
			}			
			HTML += "<td> &nbsp; </td>"
			HTML += "<td>"
			HTML += "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" class=\"BG_Button_Regular\">"
			
			HTML += "</tr>";
			HTML += "</table>";
			if ( typeof( getObj('abcTable') ) != 'undefined' && getObj('abcTable') != null)
				getObj('abcTable').innerHTML = 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' && typeof(parent.frames[0].document.hiddenForm.Letter) !='undefined' &&  parent.frames[0].document.hiddenForm.Letter.value!='')
	{
	    parent.frames[0].document.hiddenForm.submit();
	}
}

function checkValidation()
{
	var obj = document.theForm
	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 == '' && objCompIndex == '-1' && ObjFreeCity == '')
			mesAlert+= 'Please select at least one search criteria in order to narrow down the result set'		

	
		
		if (obj.keyword.value != '' && obj.keyword.value.length < 3 )
		{
			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";			    
			    
			obj.ChunckNumber.value = 1;
			
			if (typeof(obj.Managerial)!='undefined' && obj.Managerial.value == '-1' && typeof(obj.Field)!='undefined' && obj.Field.value == '-1' &&
				obj.City.value == '-1' && obj.keyword.value == '' && objCompIndex == '-1' && ObjFreeCity == '' && typeof(obj.Industry)!='undefined' && obj.Industry.value == '-1')
				obj.FirstSearch.value=1;
			else
				obj.FirstSearch.value=0;
			//if(obj.userId.value=='')
			//{
				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",getMultipleSelectValues(obj.City));
				setCookie("FirstSearch","0")
				if(obj.IsAdditionalLocations.checked==true || obj.IsAdditionalLocations.checked==1)
				    setCookie("IsAdditionalLocations",true);
				else
				    setCookie("IsAdditionalLocations",false);
			//	}	
			//else
			//	{
			//	 deleteCookie("keyword","","")
			//	 deleteCookie("Managerial","","")
			//	 deleteCookie("Field","","")
			//	 deleteCookie("City","","")
			//	 deleteCookie("FirstSearch","","")
			//	 deleteCookie("IsAdditionalLocations","","")
			//	}
	
			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(',')	
	
	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;
		}	
	  }	
    }
}		
function ClearSearchFields()
{
	var obj = document.theForm

	obj.Field.selectedIndex = 0
	obj.Managerial.selectedIndex = 0
	obj.keyword.value = ''
	if (typeof(obj.FreeCity) !='undefined') obj.FreeCity.value = ''
	var defCity;
	for (i=0; i<AffiliateLocations.length; i++)
	{
		if(AffiliateLocations[i][3]=='IsDefaultCity')
		{
			defCity = AffiliateLocations[i][0];
			break;
		}
	}
	if(defCity == "")
	{
		obj.City.selectedIndex = 0;
	}
	else
	{
		obj.City.value = defCity;
	}
	if (typeof(obj.IsAdditionalLocations) != 'undefined')
	{
	    obj.IsAdditionalLocations.checked = eval(getCookie("IsAdditionalLocationsDefault"));
        setCity();
        setCookie("IsAdditionalLocations",obj.IsAdditionalLocations.checked)
	}
	if (typeof(obj.CompaniesList) !='undefined') obj.CompaniesList.length = 0
	setCookie("keyword",obj.keyword.value)
	setCookie("Managerial",(typeof(obj.Managerial)!='undefined')? obj.Managerial.value:'')
	setCookie("Field",(typeof(obj.Field)!='undefined')? obj.Field.value:'')
	setCookie("City",defCity)
	setCookie("FirstSearch","1")
	setCookie("ChunckNumber",1);
}
