function FormValidation(frm) {
    var send = true;
    var query = (frm == undefined) ? ".required" : "."+frm+" .required";
    $(query).each(function(key, value) {
        if (trim($(value).val()).length == 0) {
            this.style.border = "1px #9E1111 solid";
            $(this).effect("highlight", {}, 3000);
            send = false;
        }
    });
    return send;
}

function Check(url) {
    if (confirm("האם אתה בטוח שברצונך לבצע פעולה זו?")) {
        window.location = url;
    }
}


function trim(str) {
    if (str != null) {
        var i;
        for (i=0; i<str.length; i++) {
            if (str.charAt(i)!=" ") {
                str=str.substring(i,str.length);
                break;
            }
        }

        for (i=str.length-1; i>=0; i--) {
            if (str.charAt(i)!=" ") {
                str=str.substring(0,i+1);
                break;
            }
        }

        if (str.charAt(0)==" ") {
            return "";
        } else {
            return str;
        }
    }
}

function radioValue(radioNodeList) {
    for (var i = radioNodeList.length - 1; i > -1; i--) {
        if (radioNodeList[i].checked) {
            return radioNodeList[i].value;
        }
    }
    return false;
}

function targetBlank (url) {
    blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

function Search() {
    document.getElementById("q").value = trim(document.getElementById("q").value);
    if (document.getElementById("q").value == "") {
        //document.getElementById("q").style.background = "#CD5C5C";
        document.getElementById("q").style.border = "1px #9E1111 solid";
        $("#q").effect("highlight", {}, 3000);
        document.getElementById("q").focus();
    }
    else {
        window.location = 'search-'+encodeURIComponent(document.getElementById("q").value);
    }
}

function submitSearchOnEnter(variable)
{
    var keyCode;

    //get whatever key was just pressed
    //try to account for different methods of getting
    //event keys depending on implementation
    if(window.event)
    {
        keyCode = window.event.keyCode;
    }
    else if(variable)
    {
        keyCode = variable.which;
    }

    //if the key was the enter key, perform the necessary function
    if(keyCode == 13) //13 = enter key
    {
        //here is where you process the form item or call a function to do that
        Search(); //call search
    }
}


$(document).ready(function(){
    //document.getElementById('q').onkeyup = submitSearchOnEnter;

    $(".imgcat").hover(
        function () {
            elemId = $(this).attr("id");
            num = elemId.split("-");
            if (!$("#td-"+num[1]).hasClass("gray"))
                $("#td-"+num[1]).css("background", "#CCFF01");
        },
        function () {
            elemId = $(this).attr("id");
            num = elemId.split("-");
            if (!$("#td-"+num[1]).hasClass("gray"))
                $("#td-"+num[1]).css("background", "#ffffff");
        }
        );
    $(".imgcat").click(function () {
        elemId = $(this).attr("id");
        num = elemId.split("-");
        for (i=1;i<=4;i++) {
            if ($("#td-"+i).hasClass("gray")) {
                $("#td-"+i).removeClass("gray");
                $("#td-"+i).css("background", "#ffffff");
            }
        }

        if ($("#td-"+num[1]).hasClass("gray")) {
            $("#td-"+num[1]).removeClass("gray");
            $("#td-"+i).css("background", "#ffffff");
        }
        else {
            $("#td-"+num[1]).addClass("gray");
        }

    });

    if ($(".content_side").height() < $(".content_main").height())
        $(".content_side").height($(".content_main").height()+20);

	
});


