$(document).ready(function(){
	onFinPage();
});


var SearchDataCategoriesSelector = true;
ShowSideBnr = (screen.width == "800")? false:true;

function onFinPage()
{

	if(ShowSideBnr)
	{
		if(parseInt(screen.width) <= 1152)
			AbsoluteCenter(document.getElementById('_DivMain'), 800, 180);			 		 
		else
			AbsoluteCenter(document.getElementById('_DivMain'), 748, 202);
			
		document.getElementById('Bnr').style.display = "block";
	}
	else
		AbsoluteCenter(document.getElementById('_DivMain'), 788,0);
		

	// Show User Email From Cookie
	setEmailInSignIn();
	
	// Set cookie for Side Logo and Side Logo Link
	setCookie("LogoSideCookie","/Partners/Images/989/fileLogoSide_989.jpg|/%D7%A2%D7%91%D7%95%D7%93%D7%94_%D7%91%D7%97%D7%95%22%D7%9C", "/");
	
	//If came from Campaign/Hul/HulLandingPage.aspx (user filled lid form) >> tell google analytics
	if(RequestQueryString('CampHul') == '1')
	{
		var IframeGoal = document.createElement('iframe');
		IframeGoal.src = '/Campaigns/Hul/HulLandingPageGoal.aspx';
		IframeGoal.width = '0';
		IframeGoal.height = '0';
		IframeGoal.frameBorder = "0";
		$('#tdCredit').append(IframeGoal);
	}
}

 
function AbsoluteCenter(obj, objWidth, bnrWidth)
{	
	var leftPos = 0;
	var curWidth = parseInt(screen.width);
	 
	leftPos = ((curWidth- objWidth)/2);
	 
	if(bnrWidth >= leftPos && curWidth != 800)
		leftPos = bnrWidth + 50;
			
	 
	obj.style.marginLeft = leftPos+"px";
	obj.style.display = "block";
	 
}

var CatPIDHul = '1498';

function CreateCategoriesHulSearchEngine()
{
	var checkbox;
	var txt;
	var divParentCategory;
	var divChildernCategory;

	//Create categories for Hul Search Engine
	for(k=0;k<CatIDs.length;k++)
		if(CatPIDs[k] == CatPIDHul && CatPIDHul != CatIDs[k] )
		{
			//Create checkbox element
			checkbox = document.createElement('input'); 
			checkbox.type = "checkbox";
			checkbox.setAttribute('id','chkCategory' );
			checkbox.setAttribute('value',CatIDs[k]);
			
			//Create child div element
			divChildernCategory =  document.createElement("div");
			divChildernCategory.setAttribute('id','divChildernCategory' + CatIDs[k]);
			
			//Create text with city name
			txt = document.createTextNode(CatNames[k]);
			
			divChildernCategory.appendChild(checkbox);
			divChildernCategory.appendChild(txt);
			
			document.getElementById("divPositions").appendChild(divChildernCategory);
			
		}
		
}

function CreateCitiesHulSearchEngine()
{
	var checkbox;
	var txt;
	var divParentCity;
	var divChildernCity;
    var HulArrayPosition; //Row in matrix array
    
    //Check on wich position in array RegionId(5) of Hul exist
	for(i=0;i<regionsID.length;i++)
  	{
  		if(regionsID[i]=='5')
  		{
  			HulArrayPosition = i;
  			break;
  		}	
  	}
  	 
		//Create cities(countries) for Hul Search Engine
		for(m=0;m<cities[HulArrayPosition].length;m++)
		{
			//Create checkbox element
			checkbox = document.createElement('input'); 
			checkbox.type = "checkbox";
			checkbox.setAttribute('id','chkCity');
			checkbox.setAttribute('value',citiesID[HulArrayPosition][m]);
			
			//Create child div element
			divChildernCity =  document.createElement("div");
			divChildernCity.setAttribute('id','divChildernCity' + citiesID[HulArrayPosition][m]);
			
			//Create text with city name
			txt = document.createTextNode(cities[HulArrayPosition][m]);
			
			divChildernCity.appendChild(checkbox);
			divChildernCity.appendChild(txt);
			
			document.getElementById("divCities").appendChild(divChildernCity);
		}
}

function GetSearchResultsHul()
{
	//Build Url
	var pageurl = "/SearchResultsGuest.aspx?page=1";
	var isPosition = $('#divPositions input[@type="checkbox"][@checked]').length;
	var isCities = $('#divCities input[@type="checkbox"][@checked]').length;
	var freeTxt = trim($('input:text[@id$="SearchBox"]').val());

	if(freeTxt.length > 0)
	{
		//Check positions and regions that were choosen
		if( isPosition == '0' && isCities == '0') 
			//If checkboxs wasn't choosen get all jobs for Hul
			pageurl += '&position=' + CatPIDHul + '&region=&type=&freetxt=' + freeTxt;
		else
			//Create link from params
			pageurl += CreateLink() + '&freetxt=' + freeTxt;
	}
	else
	{
		//Check positions and regions that were choosen
		if( isPosition == '0' && isCities == '0') 
			//If checkboxs wasn't choosen get all jobs for Hul
			pageurl += '&position=' + CatPIDHul + '&region=&type=';
		else
			//Create link from params
			pageurl += CreateLink();
	}
	
	document.location.href = pageurl;
}

//Create url for SearchResultGuest
function CreateLink()
{
	var position = '';
	var city = '';
	var url;

	
	//Create position -> ( Categories ) string
	$('#divPositions input[@type="checkbox"][@checked]').each(
			function()
			{
				//Create positions string IDs
				position += this.value + ',';
			}
	);
	
	//Create cities ->( Countries ) string
	$('#divCities input[@type="checkbox"][@checked]').each(
			function()
			{
				//Create positions string IDs
				city += this.value + ',';
			}
	);
	
	//Remove last  seperator
	if(position != '')
		position = position.substring(0, position.length - 1);
	else
		position = CatPIDHul;	
		
	if(city != '')
	{
		city = city.substring(0, city.length - 1);	
		url = '&position=' + position + '&region=&type=&city=' + city;
	}
	else
		url = '&position=' + position + '&region=&type=';
		
	return 	url;
	
}
//Set Email in to textbox
function setEmailInSignIn()
{
	
	var Email =  getCookie("AllJobsUserEmail");
	
	if(Email == "" || Email == null)
		return;
		
	$('#txtEmailSignIn').val(Email);
	$('#txtEmailSign').hide();
	$('#txtEmailSignIn').show();
	$('#txtPasswordSign').focus();
}

//Get Email from cookie

function getCookie(name)
{
var prefix = name + '=';var begin = document.cookie.indexOf('; ' + prefix);if (begin == -1){begin = document.cookie.indexOf(prefix);if (begin != 0) return null;}else begin += 2;var end = document.cookie.indexOf(';', begin);if (end == -1)end = document.cookie.length;return unescape(document.cookie.substring(begin + prefix.length, end));}

function setCookie(name, value, path, expires , domain, secure) {
	var curCookie = name + '=' + escape(value) +
		((expires) ? '; expires=' + expires.toGMTString() : '') +
		((path) ? '; path=' + path : '') +
		((domain) ? '; domain=' + domain : '') +
		((secure) ? '; secure' : '');
	 
	document.cookie = curCookie;
}


 
