﻿
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 SelectSubSrchCheck(SrchType,SrchTypeInt)
{
    if (SrchTypeInt == 0){
        document.SF.SubSelectBN_Search.checked=false;
        document.SF.SubSelectSearch.checked=true;
    }
    if (SrchTypeInt == 1){
        document.SF.SubSelectSearch.checked=false;
        document.SF.SubSelectBN_Search.checked=true;
    }  
    if (document.SF.SubSelectSearch.checked == false && document.SF.SubSelectBN_Search.checked == false)
    {
        document.SF.SubSelectSearch.checked=true; 
    }
	document.forms["SF"].elements["SPage"].value = SrchType
}


function SelectRadioSrchList(SrchType,SrchTypeTxt)
{
	//alert(SrchType)
	document.forms["SF"].elements["SPage"].value = SrchType
}

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 DoTagHint(Hint,HintTarget)
{
    document.getElementById("sw1").value=Hint;
    document.getElementById("HintName").style.display= 'none';
	document.getElementById("sw1").focus();
	document.getElementById("sw1").value = document.getElementById("sw1").value;
	document.forms["SF"].elements["SPage"].value = HintTarget
}

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 ;

    }

    /*  SUBSCRIBE */
    function ALL_Subs_clear()
    {
        if (document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].value == ':אימייל') {
            document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].value = ''
        }
        if (document.forms["ALL_Subs_Form"].elements["ALL_Subs_Name"].value == ':שם') {
            document.forms["ALL_Subs_Form"].elements["ALL_Subs_Name"].value = ''
        }           
    
    }
    var ALL_Subs_check_ret = false;
    function ALL_Subs_check() {
        if (document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].value.indexOf('@') == -1) {
            alert('@ כתובת הדואר האלקטרוני חייבת להכיל');
            document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].select();
            document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].focus();
        }
        else {
            if (document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].value.indexOf('.') == -1) {
                alert('כתובת הדואר אלקטרוני צריכה להכיל נקודה');
                document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].select();
                document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].focus();
            }
            else {
                if (document.forms["ALL_Subs_Form"].elements["ALL_Subs_Name"].value.length < 2) {
                    alert('נא הזן שם');
                    document.forms["ALL_Subs_Form"].elements["ALL_Subs_Name"].select();
                    document.forms["ALL_Subs_Form"].elements["ALL_Subs_Name"].focus();
                }
                else {
                    ALL_Subs_check_ret = true;
                }
            }
        }
        return ALL_Subs_check_ret;
    }

    function ALL_Subs_SendAjax(ReqURL, TargetRes) {

        _xmlHttpObj = GetXmlHttpObject();
        ALL_Subs_check();
        //alert(ALL_Subs_check_ret)
        ALL_Subs_Email = document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].value;
        ALL_Subs_Name = document.forms["ALL_Subs_Form"].elements["ALL_Subs_Name"].value;
        ReqURL = ReqURL + '?ALL_Subs_Name=' + ALL_Subs_Name + '&ALL_Subs_Email=' + ALL_Subs_Email
        //alert (ReqURL)

            if (ALL_Subs_check_ret != false) {
                _xmlHttpObj.onreadystatechange = function () {
                    if (_xmlHttpObj.readyState == 4 && _xmlHttpObj.status == 200) {
                        var SendRes = parseInt(_xmlHttpObj.responseText);
                        if (SendRes == 1) {

                            document.getElementById(TargetRes).innerHTML = "הרישום שלך עבר בהצלחה. מייל אישור נשלח אל הכתובת שציינת על מנת להשלים את הבקשה."
                            document.forms["ALL_Subs_Form"].elements["ALL_Subs_Email"].value = "";
                            document.forms["ALL_Subs_Form"].elements["ALL_Subs_Name"].value = "";
                            document.getElementById("ALL_Subs_Main").style.display = "none";
                            document.getElementById(TargetRes).style.display = "block";
                        }
                    }
                }
                _xmlHttpObj.open("POST", ReqURL, true);
                _xmlHttpObj.send();
         }
    }

    function HideTopBoxSub(Chours) {


        if (Chours == null) Chours = 12;
        _xmlHttpObj = GetXmlHttpObject();
        _xmlHttpObj.open("POST", "/ie2/Subscription_Litebox_SetCookie.asp?Chours=" + Chours + "&CKname=Show_Sub_Top", true);
        _xmlHttpObj.send();
        
        if (document.getElementById('ALL_Subs')) {
            document.getElementById('ALL_Subs').style.display = "none";
        }
    }


    function TopBoxSub(showTopBoxSub) {

        if (showTopBoxSub == "1") {
            if (document.getElementById('ALL_Subs')) {
                document.getElementById('ALL_Subs').style.display = "block";
            }
        }
        else {
            if (document.getElementById('ALL_Subs')) {
                document.getElementById('ALL_Subs').style.display = "none";
            }
        }
    }

    function ColorCat(cat1) {
        (cat1.style.background == "#ff7e00") ? (cat1.style.background = "#E7E7E7") : (cat1.style.background = "#ff7e00");
        return
    }

    function FixWinSize() {
        if (document.body.clientWidth > 1100) {

            document.getElementById("LbnrDiv").style.display = 'block';
            document.getElementById("RbnrDiv").style.display = 'block';
            document.getElementById("nanoRepProxyContainer").style.display = 'block';
            
        }
        else {
            document.getElementById("LbnrDiv").style.display = 'none';
            document.getElementById("RbnrDiv").style.display = 'none';
            document.getElementById("nanoRepProxyContainer").style.display = 'none';
        }

        if (document.body.clientHeight < 700) {
            document.getElementById("nanoRepProxyContainer").style.display = 'none';
        }
        return;
    }

    function RegExcheckEmail(inputvalue) {
        var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
        if (!pattern.test(inputvalue)) {
            alert("אימייל לא חוקי");
            return false;
        }
    }
