//var http = new ActiveXObject("MSXML2.XMLHTTP");

var http=null;
var v = navigator.userAgent;
           
if (v.indexOf("Firefox") > 0)
    {
    http=new XMLHttpRequest();
    var brow="fireFox";    
    }
else  
    {
    http=new ActiveXObject("Msxml2.XMLHTTP");
    var brow="e";    
    }

//alert(  brow + " " + curTopBase);
var str="";
var strFieldID;
var rowID = 0;
var divLength;
var searchTimeout;
function getStrSearch(strID) {
    //alert(window.event.keyCode);

	if (window.location.href.toLowerCase().indexOf("ordercheckout.aspx") != -1)
		return;
	window.clearTimeout(searchTimeout);
    if (window.event && (window.event.keyCode == 13)) {
        if (window.event.keyCode == 13)
            divIOSearch('none');        
        }
        
    else {
        //alert();
        strFieldID = strID;

        var cityValue = getChrSearch(document.getElementById("SiteHeader1_SiteSearchHeader1_txtFreeText").value);        

        var url = "../mashav/SearchIndex.asp?sn=" + cityValue;
        document.getElementById("roey").value = url;


        if(brow=="e")
            http.open('get',url + '?rand='+ Math.random(),false);	
        else
            http.open('get',url + '?rand='+ Math.random(),true);	
            
	    http.onreadystatechange=handleResponseSearch;	
	    http.send(null);	

        getPositionSearch();
        divIOSearch("block");

		searchTimeout = window.setTimeout("divIOSearch('none')", 8000);
        setAnswerSearch();
    }
}
function mouseOut(obj)
{
	window.clearTimeout(searchTimeout);
	obj.className='strListSearch'
}
function mouseOver(obj)
{
	window.clearTimeout(searchTimeout);
	obj.className='strListSearchSelected';
}
function handleResponseSearch() {
    if (http.readyState == 4) {
        str = http.responseText;        
    }
}

function getChrSearch(pStr){
    var tempStr="";
    for(var i=0; i<=pStr.length-1; i++)
        tempStr=tempStr + pStr.charCodeAt(i) + "@@"
    
    return tempStr;
}

function setStrSearch(pStr, pType, pID) {    

    divIOSearch('none');
    
    document.getElementById(strFieldID).value = pStr;
    
    var url="http://www.21.tv/"
    
    //switch(pType)
      //  {        
        //case "product":
          //  url = url + "p-" + pID + "/" + pStr;
            //break; 
        
        //default:            
          //  url = url + "cn-" + pID + "/" + pStr;
        //}
        
    url = url + pType + "-" + pID + "/" + pStr; 
    //alert(url);
    //location.href=url;
    openWinSearch(url);
    //rowID = strID;
}

function divIOSearch(pStatus) {
    document.getElementById("strListSearch").style.display = pStatus;    
}

function setAnswerSearch() {
    var strArray = new Array();
    strArray = str.split("@");

    if (strArray[0].length > 0)
    {
		while (strArray[0].indexOf("&#gt;") != -1)
			strArray[0] = strArray[0].replace("&gt;", ">");
			
		while (strArray[0].indexOf("&lt;") != -1)
			strArray[0] = strArray[0].replace("&lt;", "<");
			
		while (strArray[0].indexOf("\\\"") != -1)
			strArray[0] = strArray[0].replace("\\\"", "\"");
			
		try{
			document.getElementById("strListSearch").innerHTML = strArray[0];
		}catch(ex){};
		divLength = strArray[1];
    }
    if(0!=0)
    {
        if (window.event && window.event.keyCode != 8) {
            var oTextbox = document.all(strFieldID);
            var oRange = document.all(strFieldID).createTextRange();
            var oLen = oTextbox.value.length;

            document.getElementById(strFieldID).value = document.getElementById("r0").innerHTML;

            oRange.moveStart("character", oLen);
            oRange.moveEnd("character", 0);
            oRange.select();
        }
    }
}

function getPositionSearch() {
    var EHS_box = document.getElementById(strFieldID);
    var curleft = 0;
    var curtop = 0;

    if (EHS_box.offsetParent) {
        do {
            curleft += EHS_box.offsetLeft;
            curtop += EHS_box.offsetTop;
        } while (EHS_box = EHS_box.offsetParent);
    }

    //alert('offsetLeft = ' + curleft + ' offsetTop = ' + curtop);

    /*document.getElementById("strListSearch").style.top = (curtop + 25) + "px";;
    document.getElementById("strListSearch").style.left = curleft + "px";*/
    
    document.getElementById("strListSearch").style.top = (curtop + 21) + 'px';
    document.getElementById("strListSearch").style.left = curleft + 'px';
    document.getElementById("strListSearch").style.zIndex = 101;
    document.getElementById("strListSearch").style.position = 'absolute'; 
}
  

function openWinSearch(pUrl){
    window.location.replace(pUrl);
}
