var SearchDataCategoriesSelector = true; //for SearchDataHitech.js
var AJ_MainSearchNewNew = true;

function InitAllSearchEngineJS()
{

    var head = document.getElementsByTagName("head")[0];
    var script = document.createElement('script');
	var link = document.createElement('link');

    //Include for CSS file
    link.type = 'text/css';
    link.href = CSS;
    link.rel = 'stylesheet';
    head.appendChild(link);

    //Call SearchEngine JSs -> Categories,Types,Regions
	CreateParentCategories();
	//Create EngineRegions
	SetSearchEngineRegions();


}

function GetSearchResults()
{	
		var positionParent = GetSearchResultsCategories();
				
		//Build Url to SearchResultGuest
		var pageurl = "/SearchResultsGuest.aspx?page=1";
	
		var freeTxt = trim($('input:text[@id$="SearchBox"]').val());
		if(freeTxt.length > 0)
		{
			if(positionParent == "-1")
				pageurl += CheckCategoryFreeTxtSearch(freeTxt);
			else
				pageurl += '&position=' + GetSearchResultsCategories() + '&region=' + GetSearchResultsRegions() + '&type='+ citiesIDs + '&freetxt=' + escape(freeTxt);	
		}
		else if(positionParent == "-1")
				pageurl += '&position=&region=' + GetSearchResultsRegions() + '&type='+ citiesIDs;	
			 else	//If parent Relocation Category
					if(ChoosenParentID == '15')
						pageurl += '&position=' + GetSearchResultsCategories() + '&region=' + GetSearchResultsRegions() + '&type=9'+ citiesIDs;
					else
						pageurl += '&position=' + GetSearchResultsCategories() + '&region=' + GetSearchResultsRegions() + '&type='+ citiesIDs;
	
		parent.location = pageurl;
		return true;
		 
	
}
//Go to SearchResultGuest By parent categoryID link
function GetSearchResultsByPCategoryID(CategoryID)
{	
	var positionParent = CategoryID;
	var categoriesIDs = '';

	//Get all children of this CategoryID
	for(i=0;i<CatIDs.length;i++)
	{
		if(CatPIDs[i] == positionParent && CatPIDs[i] != CatIDs[i])
			categoriesIDs += CatIDs[i] + ',';
	}
	//Erase last seperator
	categoriesIDs =   categoriesIDs.substring(0, categoriesIDs.length - 1);
	
	//Build Url to SearchResultGuest
	var pageurl = '/SearchResultsGuest.aspx?page=1';
	pageurl += '&position=' + categoriesIDs + '&region=&type=';
	parent.location = pageurl;
}

//Get free text
function CheckCategoryFreeTxtSearch(freeTxt)
{
	var url = "";
	for(i=0;i<CatNames.length;i++)
	{
		if(CatNames[i].toLowerCase() == freeTxt.toLowerCase()) 
		{
			url = '&position=' + CatIDs[i] + '&region=' +  GetSearchResultsRegions() + '&type='+ citiesIDs;
			return url;
		}
	}	
	//This category doesn't exists
	url = '&position=&region=' +  GetSearchResultsRegions() + '&type='+ citiesIDs + '&freetxt=' + escape(freeTxt);
	return url;
}

//Effect Focus On Seaech Free textbox
function FocusOnInput(ObjUp,ObjDown,Flag,Content)
{
	ObjUp =($('input:text[@id$="'+ObjUp+'"]').get(0));
	ObjDown = ($('input:text[@id$="'+ObjDown+'"]').get(0));
	
	if(Flag == 1)//Focus
	{
		if(ObjUp.style.display = "block")
			{
				ObjUp.style.display = "none";
				ObjDown.style.display = "block";
				ObjDown.select();
			}
	}
	else //Out Of Focus
		if(ObjDown.value == '')
			{
				ObjUp.style.display = "block";
				ObjDown.style.display = "none";
			}
}



