﻿
function GoSearch()
{
	if(document.getElementById("sw1").value.length < 2)
    {
        alert("מילת חיפוש צריכה להיות לפחות באורך של 2 תוים")
        return;
    }
	document.SF.submit();
	return;
}

function openSubSrchList(state)
{
	if (state == true)
	{
		document.getElementById("SubSrchList").style.display == 'block' ? document.getElementById("SubSrchList").style.display = 'none' : document.getElementById("SubSrchList").style.display = 'block'
	}
}

function SelectSubSrchList(SrchType,SrchTypeTxt)
{
	//alert(SrchType)
	document.forms["SF"].elements["SPage"].value = SrchType
	document.getElementById("SubSrchSelected").innerHTML = SrchTypeTxt
	document.getElementById("SubSrchList").style.display = 'none'
}


function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	    //alert (xmlHttp.responseText.length)
	    if (xmlHttp.responseText.length > 0)
	    {
	        document.getElementById("HintName").innerHTML=xmlHttp.responseText;
	        document.getElementById("HintName").style.display= 'block';
	    }
	    else
	    {
	      hideHint()  
	    }
	}
} 

function DoHint(Hint)
{
    document.getElementById("sw1").value=Hint;
    document.getElementById("HintName").style.display= 'none';
	document.getElementById("sw1").focus();
	document.getElementById("sw1").value = document.getElementById("sw1").value;
}

function showHint(str,keyCode)
{
if	(keyCode != 40 && keyCode != 38)
    {
    if (str.length==0)
	{ 
    hideHint()
	return;
	}
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
		{
		//alert ("Your browser does not support AJAX!");
		return;
		} 
	var url="/ie2/GetSearchHintVal.asp?Hint="+escape( str );
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
    }
    else 
    {
        checkKeycode(keyCode);
    }	
}

function hideHint()
{
	document.getElementById("HintName").innerHTML="";
	document.getElementById("HintName").style.display= 'none';
	return;
}



function checkKeycode(keyCode) 
{
    if (keyCode == 40)
    {
    GoDown()
    }
    if (keyCode == 38)
    {
    GoUp()
    }    
}

var CurrInput = 0
var NewOrder = 0
function GoDown()
{
    HitCnt = document.getElementById("HintCounter").value
    if (NewOrder < HitCnt)
        {
        for (Inp=1;Inp<=HitCnt;Inp++)
        {
            document.getElementById("input"+Inp).style.backgroundColor = '#FFF8CF'; 
        }

        NewOrder = CurrInput + 1 ;
        document.getElementById("input"+NewOrder).focus();
        CurrInput = NewOrder;
        //document.getElementById("newordertrace").innerHTML=NewOrder ;
        return;
        }
}

function GoUp()
{
    HitCnt = document.getElementById("HintCounter").value
    if (NewOrder > 1)
    {
        for (Inp=1;Inp<=HitCnt;Inp++)
        {
           document.getElementById("input"+Inp).style.backgroundColor = '#FFF8CF'; 
        }
        NewOrder = CurrInput - 1 ;
        document.getElementById("input"+NewOrder).focus();
        CurrInput = NewOrder;
        //document.getElementById("newordertrace").innerHTML=NewOrder ;
        return;
    } 
        else if(NewOrder==1)
    {
        document.getElementById("sw1").focus();
        document.getElementById("sw1").value = document.getElementById("sw1").value;
        document.getElementById("input1").style.backgroundColor = '#FFF8CF'; 
       // document.getElementById("newordertrace").innerHTML=NewOrder ;
        NewOrder = 0;
        CurrInput = 0;
        return;
    }
}

function GoFocus(NewInput)
{
    HitCnt = document.getElementById("HintCounter").value

        for (Inp=1;Inp<=HitCnt;Inp++)
        {
           document.getElementById("input"+Inp).style.backgroundColor = '#FFF8CF'; 
        }
        NewOrder = NewInput;
        document.getElementById("input"+NewOrder).focus();
        CurrInput = NewOrder;
        //document.getElementById("newordertrace").innerHTML=NewOrder ;
        return ;
 
}


