﻿
var HomePage = {
    PreventSubmiOnEnterClick: function () {
        if (window.event.keyCode == 13) {
            event.returnValue = false;
            event.cancel = true;
        }
    },

    PreloadImages: function (images) {
        if (document.images) {
            var i = 0;
            var imageArray = new Array();
            imageArray = images.split(',');
            var imageObj = new Image();
            for (i = 0; i <= imageArray.length - 1; i++) {
                imageObj.src = this.imagesFolder + images[i];
            }
        }
    },

    Init: function () {
        $(document).ready(function () {
            $(".UpperMenu").find('img').hover(
               function (e) {
                   var bkgr = $(this).attr("src").replace("_off", "_on");
                   $(this).attr("src", bkgr);

               },
               function (e) {
                   var bkgr = $(this).attr("src").replace("_on", "_off");
                   $(this).attr("src", bkgr);

               });

            $('.LoginButton').click(function (e) {
                if (!e) var e = window.event;

                if ($('input:text[name*="UserName"]').val() == '' || $('input:password[name*="Password"]').val() == '') {
                    $('.ErrorMsg').text(HomePage.ErrorMsgLogin);
                    e.preventDefault();
                }
            });

        });

  },


    Redirect: function () {
        if (document.getElementById("redirect").value.length > 0)
            window.location.href = "Public/Search" + document.getElementById("redirect").value + ".aspx";
        else
            alert(msgNoSel);
    },
    //Tooltip
    xstooltip_findPosX: function (obj) {

        var curleft = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curleft += obj.offsetLeft
                obj = obj.offsetParent;
            }
        }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    },

    xstooltip_findPosY: function (obj) {
        var curtop = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    },

    xstooltip_show: function (tooltipId, parentId, posX, posY) {

        it = document.getElementById(tooltipId);

        if ((it.style.top == '' || it.style.top == 0)
        && (it.style.left == '' || it.style.left == 0)) {
            // need to fixate default size (MSIE problem)
            it.style.width = it.offsetWidth + 'px';
            it.style.height = it.offsetHeight + 'px';

            img = document.getElementById(parentId);

            // if tooltip is too wide, shift left to be within parent 
            if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
            // if (posX < 0) posX = 0;

            x = this.xstooltip_findPosX(img) + posX;
            y = this.xstooltip_findPosY(img) + posY;

            it.style.top = y + 'px';
            it.style.left = x + 'px';
        }

        it.style.visibility = 'visible';
    },

    xstooltip_hide: function (id) {
        it = document.getElementById(id);
        it.style.visibility = 'hidden';
    }
    //end of tooltip
}

HomePage.Init();


