
var bFoundEngineToReplace=false;

// URL Encode / Decode
var Url = {  
  
    // public method for url encoding  
    encode : function (string) {  
        return escape(this._utf8_encode(string));  
    },  
  
    // public method for url decoding  
    decode : function (string) {  
        return this._utf8_decode(unescape(string));  
    },  
  
    // private method for UTF-8 encoding  
    _utf8_encode : function (string) {  
        string = string.replace(/\r\n/g,"\n");  
        var utftext = "";  
  
        for (var n = 0; n < string.length; n++) {  
  
            var c = string.charCodeAt(n);  
  
            if (c < 128) {  
                utftext += String.fromCharCode(c);  
            }  
            else if((c > 127) && (c < 2048)) {  
                utftext += String.fromCharCode((c >> 6) | 192);  
                utftext += String.fromCharCode((c & 63) | 128);  
            }  
            else {  
                utftext += String.fromCharCode((c >> 12) | 224);  
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);  
                utftext += String.fromCharCode((c & 63) | 128);  
            }  
  
        }  
  
        return utftext;  
    },  
  
    // private method for UTF-8 decoding  
    _utf8_decode : function (utftext) {  
        var string = "";  
        var i = 0;  
        var c = c1 = c2 = 0;  
  
        while ( i < utftext.length ) {  
  
            c = utftext.charCodeAt(i);  
  
            if (c < 128) {  
                string += String.fromCharCode(c);  
                i++;  
            }  
            else if((c > 191) && (c < 224)) {  
                c2 = utftext.charCodeAt(i+1);  
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));  
                i += 2;  
            }  
            else {  
                c2 = utftext.charCodeAt(i+1);  
                c3 = utftext.charCodeAt(i+2);  
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));  
                i += 3;  
            }  
  
        }  
  
        return string;  
    }  
  
}  


function ss(w)
{
	window.status=w;
	return true;
}

function cs()
{
	window.status='';
}


function sshref(el) 
{		
	var strUrl	=	el.href;	
	ss(strUrl);
}



function LogClick(strToolbarId,strLogURL,strToolbarOriginalId)
{
	//create an Ajax request to log the clicked url
	var strUrl = "LogClick.aspx?LogType=1&ctid=" + strToolbarId + "&octid=" + strToolbarOriginalId + "&URL=" + escape(strLogURL);
	
	EBAjax.ServerRequest("GET",strUrl,null);
}


function LogADClick(strToolbarId,strLogURL,iADPosition,iSearchTestMode,iAdLocation,strToolbarOriginalId)
{
	//create an Ajax request to log the clicked url
	var strUrl = "LogClick.aspx?LogType=1&ctid=" + strToolbarId + "&octid=" + strToolbarOriginalId + "&URL=" + escape(strLogURL) + "&adpos=" + iADPosition + "&SearchTestMode=" + iSearchTestMode + "&adloc=" + iAdLocation;
	
	EBAjax.ServerRequest("GET",strUrl,null);
}

function LogGeneralClick(strToolbarId,iClickSource,strToolbarOriginalId)
{
	//create an Ajax request to log the clicked url
	var strUrl = "LogClick.aspx?LogType=3&ctid=" + strToolbarId + "&ClickSource=" + iClickSource + "&octid=" + strToolbarOriginalId;
	
	EBAjax.ServerRequest("GET",strUrl,null);
}


function LogSearchEngineClick(strToolbarId,strSearchEngineType,strToolbarOriginalId)
{	
	
	var strSearchTerm = "";
		
	if (window.RegExp && window.encodeURIComponent)
	{
		//get the current search term from the saerch box
		var q	=	document.getElementById('q_top');
		if(q)
		{
		    strSearchTerm	=	q.value;
		}
	}
	
	//create an Ajax request to log the clicked url
	var strUrl = "LogClick.aspx?LogType=2&SearchEngineType="+ strSearchEngineType +"&ctid=" + strToolbarId + "&octid=" + strToolbarOriginalId + "&SearchTerm=" + escape(strSearchTerm);	
	
	EBAjax.ServerRequest("GET",strUrl,null);	
	
	return true;
}

function ServerResponse(xmlDoc){}


//loads the language preferences to the 
//radio buttons on the page
function LoadSearchLanguagePreferences(strSearchWebValue,strToolbarLanguageValue,strWhichRadioChecked)
{
	var radioSearchToolbarLanguage	= document.getElementById('RadioSearchToolbarLanguage');
	var radioSearchAllLanguages		= document.getElementById('RadioSearchAllLanguages');
	
	radioSearchToolbarLanguage.value= strToolbarLanguageValue;
	
	radioSearchAllLanguages.value	= strSearchWebValue;
	
	if (strWhichRadioChecked == '1')
	{
		radioSearchAllLanguages.checked = true; 
	}
	else
	{
		radioSearchToolbarLanguage.checked=true;
	}	
}



function ToggleAdvancedSearchTDDisplay(bShow)
{
	var tdAdvancedSearch	= document.getElementById('AdvancedSearchTD');
	
	if (bShow	==	'0')
	{
		tdAdvancedSearch.style.visibility = 'hidden';		
	}
}


function SetSearchLanguagePreferences(strSeletecedLanguage)
{
	var radioSearchToolbarLanguage		= document.getElementById('RadioSearchToolbarLanguage');

	radioSearchToolbarLanguage.value	= strSeletecedLanguage;

	radioSearchToolbarLanguage.checked	= true;
}


function ChangeQueryTerm(el,strBeforeSearchTerm) 
{
	if(typeof strBeforeSearchTerm == "undefined") strBeforeSearchTerm = ""; 
	try
	{
	    if (window.RegExp && window.encodeURIComponent)
	    {
		    var q	=	document.getElementById('q_top');
		    var ue	=	el.href;
		    var qe	=	encodeURIComponent(q.value);
    		
		    if(ue.indexOf("q=")!=-1)//most engines case
		    {
			    var rplcReg=new RegExp("q=[^&$]*");
			    el.href=ue.replace(rplcReg,"q="+strBeforeSearchTerm+qe);
		    }
		    else if(ue.indexOf("KW=")!=-1)//shopping.com case
		    {
			    var rplcReg=new RegExp("KW=[^&$]*");
			    el.href=ue.replace(rplcReg,"KW="+qe);
		    }		
		    else
		    {
				    el.href=ue+"&q="+strBeforeSearchTerm+qe;
		    }
    		
	    }
	}
	catch(ex)
	{}
	return 1;
}

function ArrayToString(arr)
{
	var strResult = "";
	for(var i=0;i<arr.length;strResult+=arr[i]+' ',i++);
	return strResult;
}

function RemoveSearchInSiteKeyword(el)
{
	var obj = document.getElementById('q_top');
	if(obj.value.indexOf('site:') != -1)
	{
		var arrSearchTerms = obj.value.split(' ');
		arrSearchTerms = arrSearchTerms.slice(1);
		obj.value = ArrayToString(arrSearchTerms);
	}
	return ChangeQueryTerm(el);
}


function OpenNewWin(actionType,destinationURL)
{		
	winref = window.open(destinationURL,'navwin',
	'left=20,top=20,width=500,height=500,toolbar=1,resizable=1,location=1,status=1,menubar=1,adressbar=1,scrollbars=1');	
	
	winref.focus();	
}




function SearchWeb()
{
	var searchWebUrlLink	=	document.getElementById('searchWebUrl');
	
	if (searchWebUrlLink != null)
	{	
		location.href= searchWebUrlLink;
	}
}




/*
	Changes the top frame size according
	to it's content
*/
var bSetFrameSize = true;

function SetFrameSize()
{	

	if (bSetFrameSize)
	{
		
		
		var AdditionalEnginesTD			 = document.getElementById ("tdAdditionalEngines");	
		
		if (AdditionalEnginesTD != null)
		{	
			var strAdditionalEnginesTDHeight = AdditionalEnginesTD.clientHeight + 2;
				//alert(strAdditionalEnginesTDHeight)
			var objFramesetParentBody = null;

			try
			{
				objFramesetParentBody = parent.frames['top'].parent.document.body;
			}
			catch(errMain) 
			{
			
			}
			
			
				
			if(objFramesetParentBody)
			{				
				strAddRows = strAdditionalEnginesTDHeight + 'px,*';					
						
				objFramesetParentBody.rows = strAddRows;		
			}
		}	
	}	
}


function SetTopFrameSize()
{

	
	var AdditionalEnginesTD			 = document.frames[0].document.getElementById ("tdAdditionalEngines");	
	
		if (AdditionalEnginesTD != null)
		{	
			var strAdditionalEnginesTDHeight = AdditionalEnginesTD.offsetHeight + 2;
				
			var objFramesetParentBody = null;
			
			try
			{
				objFramesetParentBody = parent.frames['top'].parent.document.body;
			}
			catch(errMain) 
			{
			
			}
				
			if(objFramesetParentBody)
			{				
				strAddRows = strAdditionalEnginesTDHeight + 'px,*';					
						
				objFramesetParentBody.rows = strAddRows;		
			}	
		}	

}



function EscapeFrames(strURL)
{
	try
	{
		parent.frames['top'].parent.document.location.href = strURL;	
	}
	catch(errMain) 
	{
	}
}




function IsFrameExist()
{
	var bRes = false;
	
	var objFramesetParentBody	= null;

	try
	{
		objFramesetParentBody = parent.frames['top'].parent.document.body;
	}
	catch(errMain) 
	{
	}
		
	if (objFramesetParentBody != null)
	{
		bRes = true;
	}
	
	return bRes;
}


function FocusFrameSubmit()
{
	var	q	=	document.getElementById('q_top');

	if (q!=null)
	{
		q.focus();
	}
}




//gets all 'span' html object, exept of ">>" and "<<"
function GetSpans(objDivParent)
{
	var arrSpan	= objDivParent.getElementsByTagName('span');
	var arr		= new Array()
	for(var i=0;i<arrSpan.length;i++)
	{
		if(arrSpan[i].id != 'linkMore' && arrSpan[i].id != 'linkLess')
		{
			arr.push(arrSpan[i]);
		}
	}
	return arr;
}

// sets the initial search engines list display,
// according to the window width.
function initializeEnginesDisplay()
{
	var divMoreOffset	= 21;
	var objDivParent	= document.getElementById('divEnginesParent');
	var strCookieState	= EBCookies.GetCookie('AdditionalMenuState')
	
	var objAnchorSpan	= null;
	var objCurrentSpan	= null;
	var iPrev;
	
	var bodyDir			= document.getElementsByTagName('body')[0].dir;
	var bRtl			= (bodyDir.toLowerCase() == "rtl") ? true : false;
	var isHide			= false;
	var totalWidth = objDivParent.offsetWidth;
	var isFirstTime		= true;
	var objInsertBeforeSpan;
	var prevSpanOffset  = 0;
	var spanOffset		= 0;
	if(bRtl)
	{
		objDivParent.dir = "rtl";
	}
	
	var arrSpan			= GetSpans(objDivParent);

	//run over all the span elements (all engines urls)
	for(var i=0;i<arrSpan.length;i++)
	{								
		objCurrentSpan = arrSpan[i];
		
		//we set them all to 'inline' first		
		objCurrentSpan.style.display  = 'inline';	
		
		//set the right direction
		objCurrentSpan.dir = bodyDir;
		
		//calculate if this engine fits to the container
		spanOffset = objCurrentSpan.offsetWidth;
		totalWidth -= spanOffset;
		
		if(totalWidth < 0)
		{
			isHide = true;
			
			objCurrentSpan.style.display = 'none';
			
			//we save the first element to hide
			if(isFirstTime)
			{
				if(totalWidth + spanOffset - divMoreOffset < 0)
				{
					objInsertBeforeSpan = arrSpan[i-1];
					arrSpan[i-1].style.display = 'none';
				}
				else
				{
					objInsertBeforeSpan = objCurrentSpan;
				}	
				isFirstTime			= false;
			}
		}
		prevSpanOffset = spanOffset;
	}
	
	// get the "more>>" url
	var objDivMore		= document.getElementById('divMore');

	objDivParent.style.height	= "auto";
	objDivParent.style.overflow = "visible";
	if(isHide)
	{
		//insert ">>" before the first element to hide,(will be last one in the row)
		objDivParent.insertBefore(objDivMore,objInsertBeforeSpan);
		
		objDivMore.style.display = 'inline';
			
		bFoundEngineToReplace = true;
	}
	else
	{
		objDivMore.style.display = 'none';
		var strCookieState = EBCookies.GetCookie('AdditionalMenuState')		
		
		bFoundEngineToReplace = false;
	}
		
}


//call on onload / resize event
function initAdditionalEnginesSettings(strFrom)
{
		
	if(strFrom == 'frame')
	{
		setTimeout("ToggleAdditionalEngines('0','" + strFrom + "');",100);
	}
	else
	{
		var strCookieState = EBCookies.GetCookie('AdditionalMenuState')		
		
		if(strCookieState == '0')
		{	
			ToggleAdditionalEngines('0');
		}
		else if (strCookieState == '1')
		{
		
			//create the engines list
			initializeEnginesDisplay();
			
			//show additional engines
			ToggleAdditionalEngines('1');
		}
		else
		{	
			initializeEnginesDisplay();
		}
		
		SetFrameSize();
	}
	//bSetFrameSize = false;
}

function ChangeChevronState()
{
	
}

function ToggleAdditionalEngines(show,from)
{
		var objDivParent	= document.getElementById('divEnginesParent');
		var objtdMainSearchInterface	= document.getElementById('tdMainSearchInterface');
		var objDivLess		= document.getElementById('divLess');
		var objDivMore		= document.getElementById('divMore');	
		var arrSpan			= GetSpans(objDivParent);
		
		if (show == '1')
		{		
		
			if(objtdMainSearchInterface	!= null)
			{
				objDivParent.style.width = objtdMainSearchInterface.clientWidth - 30;
			}
			
			
			for(var i=0;i<arrSpan.length;i++)
			{
				arrSpan[i].style.display  = 'inline';				
			}
			
			if (objDivMore.style.display != 'none')		
			{
				//replace "more>>" with "Less<<"
				objDivMore.style.display='none';
				
				objDivParent.appendChild(objDivLess);
			}
			
			//if we are on 'show' state, and no engine to replace was found,
			//init again ro remove the '<<' if it was exist
			if(!bFoundEngineToReplace)
			{
			//	initializeEnginesDisplay();
			}
							
			objDivParent.style.height	= "auto";
			objDivParent.style.overflow = "visible";
			//remember the state
			EBCookies.SetCookie('AdditionalMenuState','1');	
		}
		else
		{	
			if(objtdMainSearchInterface	!= null && from != "frame")
			{	
				objDivParent.style.width="345px";
			}
			
			initializeEnginesDisplay();
			
			EBCookies.SetCookie('AdditionalMenuState','0');								
		}
		
		SetFrameSize();
				
}



function DetectToolbarInstallation(strToolbarID)
{
	
	var bIsToolbarInstalled	= true;
	
	try
	{	
		 bIsToolbarInstalled			=	IsToolbarInstalled(strToolbarID);
	}
	catch(err)
	{
	
	}
		
	if (!bIsToolbarInstalled)
	{
		var mBannerDiv	=	document.getElementById('BannerDiv');
		
		if (mBannerDiv != null)
		{
		
			try
			{			
				mBannerDiv.style.display = 'block';
			}
			catch (err){}
		}
	}

}


/*Weather*/

function CelsiusToFahrenheit(dTemperatureCelsius)
{
	// Convert Celsius to Fahrenheit.

	dTemperatureFahrenheit = (dTemperatureCelsius * 9 / 5) + 32;

	return dTemperatureFahrenheit;
}

 

function FahrenheitToCelsius(dTemperatureFahrenheit)
{
	// Convert Fahrenheit to Celsius.
	dTemperatureCelsius = (dTemperatureFahrenheit - 32) * 5 / 9;

	return dTemperatureCelsius;
}



function MilesToKM(iMiles)
{
		return iMiles/ 1.6;
}



function KMToMiles(iKM)
{
		return iKM * 1.6;
}





function ChangeWeatherUnits(strChangeToUnits)
{
	var tblweather	 = document.getElementById('tblWeather');
	
	var spnArr		= tblweather.getElementsByTagName('span');
	
	var spnObj		= null;
	
	var iResult		= 0;
	
	var iUnitsValue = 0;
	
	var fResult		= 0;
	
	var fUnitsValue = 0;	
	
	
	//run over all span objects to identify
	
	if (strChangeToUnits	==	'c')
	{
		//change all span values
		for(i=0;i<spnArr.length;i++)
		{
			spnObj = spnArr[i];
			
				if (spnObj.innerHTML != 'N/A')
				{
					if (spnObj.getAttribute('name') == 'spnWeatherUnitValue')
					{
						iUnitsValue	=	parseInt(spnObj.innerHTML);
										
						iResult		=	FahrenheitToCelsius(iUnitsValue);
				
						iResult = Math.round(iResult)
						
						spnObj.innerHTML = iResult;
					}
					else if (spnObj.getAttribute('name') == 'spnWeatherUnitSign')
					{
						spnObj.innerHTML = '&#186 C';
					}
					else if (spnObj.getAttribute('name') == 'spnChangeWeatherUnits')
					{
						spnObj.innerHTML = "<A id=\"hrefChangeWeatherUnits\" class=\"AdditionalEnginesSearch\"   href=\"javascript:ChangeWeatherUnits('f')\"><span style=\"letter-spacing:-0.3mm\" >&#186 F</span></A>";
					}
					else if (spnObj.getAttribute('name') == 'spnWindSpeedUnits')
					{
						iUnitsValue			= parseInt(spnObj.innerHTML);
		
						iResult				= KMToMiles(iUnitsValue);
						
						iResult				= Math.round(iResult)
		
						spnObj.innerHTML	=  iResult;										
					}
					else if (spnObj.getAttribute('name') == 'spnWindSpeedUnitsSign')
					{
						spnObj.innerHTML = 'kmh';								
					}	
					else if (spnObj.getAttribute('name') == 'spnVisibilityUnitsValue')
					{				

						fUnitsValue			= parseFloat(spnObj.innerHTML);
						
						fResult				= KMToMiles(fUnitsValue);
						
						spnObj.innerHTML	= EBUtilities.FormatNumber(fResult,2,true,false,false);								
					}	
					else if (spnObj.getAttribute('name') == 'spnVisibilityUnitsSign')
					{
						spnObj.innerHTML = 'kilometers';								
					}						
				}
		}	
					
	} 
	else if (strChangeToUnits	==	'f')		
	{
		//change all span values
		for(i=0;i<spnArr.length;i++)
		{
			spnObj = spnArr[i];
			
			if (spnObj.innerHTML != 'N/A')
			{										
				if (spnObj.getAttribute('name') == 'spnWeatherUnitValue')
				{
					iUnitsValue	=	parseInt(spnObj.innerHTML);
									
					iResult		=	CelsiusToFahrenheit(iUnitsValue);
			
					iResult = Math.round(iResult)
					
					spnObj.innerHTML = iResult;
				}
				else if (spnObj.getAttribute('name') == 'spnWeatherUnitSign')
				{
					spnObj.innerHTML = '&#186 F';
				}				
				else if (spnObj.getAttribute('name') == 'spnChangeWeatherUnits')
				{
					spnObj.innerHTML = "<A id=\"hrefChangeWeatherUnits\" class=\"AdditionalEnginesSearch\"  href=\"javascript:ChangeWeatherUnits('c')\"><span style=\"letter-spacing:-0.3mm\" >&#186 C</span></A>";
				}
				else if (spnObj.getAttribute('name') == 'spnWindSpeedUnits')
				{
					iUnitsValue			= parseInt(spnObj.innerHTML);
	
					iResult				= MilesToKM(iUnitsValue);
					
					iResult				= Math.round(iResult)
	
					spnObj.innerHTML	= iResult;								
				}
				else if (spnObj.getAttribute('name') == 'spnWindSpeedUnitsSign')
				{
					spnObj.innerHTML = 'mph';								
				}	
				else if (spnObj.getAttribute('name') == 'spnVisibilityUnitsValue')
				{								
					fUnitsValue			= parseFloat(spnObj.innerHTML);
	
					fResult				= MilesToKM(fUnitsValue);
					
					spnObj.innerHTML	= EBUtilities.FormatNumber(fResult,2,true,false,false);							
				}	
				else if (spnObj.getAttribute('name') == 'spnVisibilityUnitsSign')
				{
					spnObj.innerHTML = 'miles';								
				}							
			}
		}			
	}		

}


var globalWeatherInitaialInfo = null;

var globalChangeUnitsContent = null;

function toggleWeatherTableContent(iType)
{

	var spnToggleWeatherContent =  document.getElementById("spnToggleWeatherContent");
	
	var hrefChangeUnits			=  	document.getElementById("hrefChangeWeatherUnits");
	
	var spnForcastTitle				=	document.getElementById("spnForcastTitle");
	
	var spnWeatehrTitleChangeUnits	=	document.getElementById("spnWeatehrTitleChangeUnits");
			
	if (iType==1)//show additional locations
	{
			
		var strAdditionalCitiesHTML	=	strASPXAlternativeCitiesHTML;
		
		var divWeather				=	document.getElementById("divWeatherContentInfo");
			
		
		if (globalWeatherInitaialInfo	==	null)
		{
			if (divWeatherContentInfo)
			{
				globalWeatherInitaialInfo	=	divWeatherContentInfo.innerHTML;
			}
		}
		
		if (globalChangeUnitsContent	==	null)
		{
			if (hrefChangeUnits)
			{
				globalChangeUnitsContent	=  hrefChangeUnits.href;	
			}
		}		
		
		divWeather.innerHTML				=	strAdditionalCitiesHTML;	
		
		spnToggleWeatherContent.innerHTML	= '<a class=\"AdvancedSearchLinkCaption\"   href=\"javascript:toggleWeatherTableContent(0);\">Back to forecast</a>';	
				
		if (hrefChangeUnits != null)
		{
			disableAnchor(hrefChangeUnits,true);
		}
		
		spnForcastTitle.style.display='none';
		
		if (spnWeatehrTitleChangeUnits)
		{
			spnWeatehrTitleChangeUnits.style.display='none';
		}
	
	}
	else // show the weather table
	{
		
		spnToggleWeatherContent.innerHTML	= '<a class=\"AdvancedSearchLinkCaption\"  href=\"javascript:toggleWeatherTableContent(1);\">More matching locations...</a>';	
		
		var divWeather						=	document.getElementById("divWeatherContentInfo");	
			
		divWeather.innerHTML				=	globalWeatherInitaialInfo;
		
		if (hrefChangeUnits != null)
		{
			disableAnchor(hrefChangeUnits,false);			
		}
		
		spnForcastTitle.style.display='inline';
		
		if (spnWeatehrTitleChangeUnits)
		{
			spnWeatehrTitleChangeUnits.style.display='inline';
		}
	}
		
}


function disableAnchor(obj, disable){

  if(disable)
  {
    var href = obj.getAttribute("href");
    
    if(href && href != "" && href != null)
    {
       obj.setAttribute('href_bak', href);
    }
   
    obj.removeAttribute('href');
   
    obj.style.color="gray";
    obj.style.fontSize	='12px';
    
  }
  else
  {
      
    obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);
    
    obj.style.color="#0000CC";
  }
}

function CheckHP(strHPText,strHPURL,strToolbarId,strToolbarOriginalId)
{
	//for IE
	if (navigator.userAgent.indexOf("MSIE") != -1)
	{
		if(!hp.isHomePage(strHPURL)) 
		{
			document.write("<a class=\"AdditionalEnginesSearch\" href=\"#\" onclick=\"style.behavior='url(#default#homepage)';setHomePage('" +strHPURL +"');return LogGeneralClick('" + strToolbarId + "','3','" + strToolbarOriginalId + "');\">"+strHPText+"</a>");
		}
	}
}



function MoreSponsoredLink(dontSubmit)
{
	if(!document.getElementById('txtSponsoredOnly'))
	{
	    var arrForms = document.getElementsByTagName('form');
	    var objHidden = document.createElement('input');
	    objHidden.setAttribute('type','hidden');
	    objHidden.setAttribute('name','SponsoredOnly');
	    objHidden.setAttribute('value','true');
	    objHidden.setAttribute('id','txtSponsoredOnly');
	    arrForms[0].appendChild(objHidden);
    	
	    var objHidden2 = document.createElement('input');
	    objHidden2.setAttribute('type','hidden');
	    objHidden2.setAttribute('name','SponsoredOnly');
	    objHidden2.setAttribute('value','true');
	    objHidden.setAttribute('id','txtSponsoredOnly2');
	    arrForms[1].appendChild(objHidden2);
	}
	
	if(!dontSubmit)
		arrForms[0].submit();
}

function CheckSubmit(event,index)
{
	var arr = document.getElementsByName("btnSearchInSponsored");
	if(arr.length != 0)
	{
		if(event.keyCode == 13)
		{
			var arr2 = document.getElementsByName("SponsoredOnly")
			if(arr2.length == 0)
			{
				var arrForms = document.getElementsByTagName('form');
				var objHidden = document.createElement('input');
				objHidden.setAttribute('type','hidden');
				objHidden.setAttribute('name','SponsoredOnly');
				objHidden.setAttribute('value','1');
				arrForms[index].appendChild(objHidden);
				return true;
			}
		}
	}
}

function GoToUrl(event,obj,url)
{
	//IE
	if(window.ActiveXObject)
	{
		//clicked on <td>, not <a>
		if(event.srcElement.name == "td")
		{
			window.open(url,'_self');
		}
	}
	//all others
	else
	{
		if(event.target == obj)
		{
			window.open(url,'_self');
		}
	}
}

function ChangeInterfaceLang(strGID)
{
	var strUrl = window.location.href;
	var iStart, iEnd, strReplace;
	if(strUrl.indexOf("?") == -1)
	{
		strUrl += "?";
	}
	if(strUrl.toLowerCase().indexOf("gid=") == -1)
	{
		strUrl += "&gid=" + strGID;
	}
	else
	{
		iStart = strUrl.toLowerCase().indexOf("gid=") + 4;
		iEnd = strUrl.toLowerCase().indexOf("&",iStart)
		if(iEnd == -1)
		{
			iEnd = strUrl.length;
		}
		var strReplace = strUrl.substr(iStart,iEnd - iStart);
		strUrl = strUrl.replace(strReplace,strGID)
	}
	
	if(strUrl.toLowerCase().indexOf("hl=") != -1)
	{
		iStart = strUrl.toLowerCase().indexOf("hl=");
		if(iStart != -1)
		{
			iEnd = strUrl.toLowerCase().indexOf("&",iStart)
			if(iEnd == -1)
			{
				iEnd = strUrl.length;
			}
			strReplace = strUrl.substr(iStart,iEnd - iStart);
			strUrl = strUrl.replace(strReplace,"")
		}
	}
	
	if(strUrl.toLowerCase().indexOf("gl=") != -1)
	{
		iStart = strUrl.toLowerCase().indexOf("gl=");
		if(iStart != -1)
		{
			iEnd = strUrl.toLowerCase().indexOf("&",iStart)
			if(iEnd == -1)
			{
				iEnd = strUrl.length;
			}
			strReplace = strUrl.substr(iStart,iEnd - iStart);
			strUrl = strUrl.replace(strReplace,"")
		}
	}
	
	if(strUrl.toLowerCase().indexOf("meta=") != -1)
	{
		iStart = strUrl.toLowerCase().indexOf("meta=");
		if(iStart != -1)
		{
			iEnd = strUrl.toLowerCase().indexOf("&",iStart)
			if(iEnd == -1)
			{
				iEnd = strUrl.length;
			}
			strReplace = strUrl.substr(iStart,iEnd - iStart);
			strUrl = strUrl.replace(strReplace,"")
		}
	}
	
	if(strUrl.toLowerCase().indexOf("gil=") != -1)
	{
		iStart = strUrl.toLowerCase().indexOf("gil=");
		if(iStart != -1)
		{
			iEnd = strUrl.toLowerCase().indexOf("&",iStart)
			if(iEnd == -1)
			{
				iEnd = strUrl.length;
			}
			strReplace = strUrl.substr(iStart,iEnd - iStart);
			strUrl = strUrl.replace(strReplace,"gil=")
		}
	}
	else
	{
		strUrl += "&gil=";
	}

	strUrl = strUrl.replace(/&&&/g,"&");
	strUrl = strUrl.replace(/&&/g,"&");
	window.location.href = strUrl;
}

function ClearSearchHistory()
{
	EBCookies.SetCookie('SearchHistory','');
	document.getElementById("divHistoryContant").style.display = 'none';
}

function EnableSearchHistory()
{
	EBCookies.SetCookie('SearchHistory_Show','true');
	document.getElementById("divHistory_Enable").style.display = 'none';
	var objHistory = document.getElementById("divHistory");
	if(HistoryHeight != 0)
	{
		objHistory.style.width = HistoryWidth;
		objHistory.style.height = HistoryHeight;
	}
	
	objHistory.style.display = '';
}

var HistoryWidth = 0;
var HistoryHeight = 0;
function RemoveSearchHistory()
{
	EBCookies.SetCookie('SearchHistory','');
	EBCookies.SetCookie('SearchHistory_Show','false');
	var obj = document.getElementById("divHistory");
	HistoryWidth = obj.offsetWidth;
	HistoryHeight = obj.offsetHeight;
	obj.style.overflow = "hidden";
	setTimeout("CloseHistory("+HistoryWidth+","+HistoryHeight+")",10);
}

function CloseHistory(width,height)
{
	ClearSearchHistory();
	width = parseInt(width);
	height = parseInt(height);
	height -= 10;
	if(width < 0 || height < 0)
	{
		document.getElementById("divHistory").style.display = "none";
		document.getElementById("divHistory_Enable").style.display = "";
		document.getElementById("divHistoryContant").style.display = 'none';
	}
	else
	{
		document.getElementById("divHistory").style.height = height + 'px';
		setTimeout("CloseHistory("+width+","+height+")",8);
	}
}

function OpenSelectLanguagesDiv(objLink)
{
	
	var leftX	= EBUtilities.FindPosX(objLink);
	var topY	= EBUtilities.FindPosY(objLink);
	
	var objDiv	= document.getElementById('divSelectLanguages');
	var oBody = document.getElementsByTagName('body')[0];
	
	var bodyDir	= oBody.dir;
	
	objDiv.style.display = '';
	objDiv.style.top = topY;
	
	if(bodyDir.toLowerCase() == "ltr")
	{
		leftX -= objDiv.offsetWidth;
	}
	
	objDiv.style.left = leftX;
	objDiv.style.zIndex = 100;
	
	var shadowDiv = document.getElementById("divSelectLanguagesShadow");
	if(!shadowDiv)
	{
		shadowDiv = document.createElement("div");
		shadowDiv.id = "divSelectLanguagesShadow";
		shadowDiv.style.backgroundColor = "#8E8E8E";
		shadowDiv.style.border = "solid 1px #D4D4D4"
		shadowDiv.style.width = objDiv.offsetWidth;
		shadowDiv.style.height = objDiv.offsetHeight;
		shadowDiv.style.position = "absolute";
		shadowDiv.style.zIndex = 99;
		objDiv.parentNode.appendChild(shadowDiv);
	}
	else
	{
		shadowDiv.style.display = '';
	}
	
	shadowDiv.style.top = topY + 5;
	shadowDiv.style.left = leftX + 5;
}

function CloseSelectLanguagesDiv()
{
	document.getElementById("divSelectLanguages").style.display = 'none';
	document.getElementById("divSelectLanguagesShadow").style.display = 'none';
}

function DeleteHistoryEntry(obj)
{
	var objSpan = obj.parentNode;
	var objParent = objSpan.parentNode;
	var strEntryText = objSpan.getElementsByTagName("a")[0].innerHTML;
	objParent.removeChild(objSpan);
	var strHistory = EBCookies.GetCookie('SearchHistory');
	var arrHistory = strHistory.split("~");
	for(var i=0;i<arrHistory.length;i++)
	{
		if(Url.decode(arrHistory[i]).replace(/\+/g," ") == strEntryText)
		{
			arrHistory.splice(i,1);
		}
	}
	
	strHistory = arrHistory.join("~");
	EBCookies.SetCookie('SearchHistory',strHistory);
}
	