﻿$(document).ready(function() {
    //for page button alignment -brijendra tiwari 25/07/2011
    if ($('#loginDiv_left_Button').length > 0) {
        var lftOffsets = $('#loginDiv_left_Button').offset();
        $('#loginDiv_Right_Button').css('top', lftOffsets.top + 2);
        var _width = $('#loginDiv_Right_Button').prev().width();
        $('#loginDiv_Right_Button').css('width', _width);
        $('#loginDiv_Right_Button').show();
    }
    $('#ctl00_header_ddlRegionCodes').find("table").css("top", "0px");

    var lng = $("#ctl00_header_ddlRegionCodes_HiddenField").val();
    lng = parseInt(lng);
    var _menuCntr = $("#MenuWrap >table:eq(0)").find("tr:eq(0)").children("td").eq(1).children("div").length;
    if (_menuCntr <= 4) { _menuCntr = 3; }
    else { _menuCntr = 4; }

    $("body a").each(function(index) {
        if (
          ($(this).closest('#impContainerPanel').length == 0) &&
          ($(this).closest('#AppDeclarationsDisclaimerers').length == 0) &&
          ($(this).closest('#DeclarationDiv').length == 0) &&
          ($(this).closest('#Clausediv').length == 0) &&
          ($(this).closest('#Fin_PayPromo_Wrap').length == 0) &&
          ($(this).closest('#Lft_Ftr_Lnks').length == 0) &&
          ($(this).closest('#Top_Right').length == 0) &&
          ($(this).closest('#ctl00_prodrightbar_anchorClaim').length == 0) &&
          ($(this).closest('#ctl00_prodrightbar_anchorBrochure').length == 0) &&
          ($(this).closest('#ctl00_menuMSIG_Menu1n' + _menuCntr.toString() + 'Items').length == 0) &&
          ($(this).closest('#ctl00_menuMSIG_Menu1n' + (_menuCntr + 1).toString() + 'Items').length == 0) &&
          ($(this).closest('#ctl00_menu_Menu1n' + _menuCntr.toString() + 'Items').length == 0) &&
          ($(this).closest('#ctl00_menu_Menu1n' + (_menuCntr + 1).toString() + 'Items').length == 0)
        ) {
            if (($(this).attr("href") != null) && ($(this).is(":disabled") == false)) {
                var oldLink = $(this).attr("href");
                if (
                    (oldLink != '') && (oldLink.indexOf('#') < 0) && (oldLink.indexOf("javascript") < 0) && (oldLink.indexOf("mailto") != 0) && (oldLink.indexOf("http") != 0)) {
                    if (lng == 0) {
                        if (oldLink.indexOf('?') > 0) {
                            $(this).attr("href", oldLink + "&lang=en");
                        }
                        else {
                            $(this).attr("href", oldLink + "?lang=en");
                        }
                    }
                    else {
                        if (oldLink.indexOf('?') > 0) {
                            $(this).attr("href", oldLink + "&lang=zh");
                        }
                        else {
                            $(this).attr("href", oldLink + "?lang=zh");
                        }
                    }
                }
            }
        }
    });

    $("input:image.img_tooltip_Style").each(function(index) {
        $(this).bind("click mouseover", function(toolTipClc) {
            var anchorObj = this;
            var objToParent = $(this).parent();
            if ($(objToParent).find("div.tooltip").length == 0) {
                $(objToParent).append("<div class='tooltip'></div>");
                $(objToParent).find("div").text($(this).attr("title"));
                $(this).attr("title", "");

                var anchorOffsets = $(this).offset();
                $(objToParent).find("div").css("top", anchorOffsets.top + $(anchorObj).height() + 5);
                $(objToParent).find("div").css("left", anchorOffsets.left + $(anchorObj).width());
                $(this).bind("mouseout", function(evt) {
                    $(objToParent).find("div").hide();
                });
            }
            else { $(objToParent).find("div.tooltip").show(); }
        });
    });

});

$(window).resize(function() {
    $("div.tooltip").each(function(index) {
        $(this).prev().attr("title", $(this).text());
        $(this).remove();
    });
});

function HideMenu() {
    var url = window.location.href;
    if (document.getElementById("MenuWrap")) {
        var menu = document.getElementById("MenuWrap");
        if (url.indexOf("Product_PaymentGatewayPage.aspx") != -1 || url.indexOf("PaymentSuccess.aspx") != -1 || url.indexOf("PaymentFailure.aspx") != -1 || url.indexOf("PaymentCancel.aspx") != -1) {
            menu.style.display = "none";
        }
        else if (url.indexOf("Error.aspx") != -1) {
            $('#MenuWrap').attr('disabled', 'disabled');
            $('#ctl00_menuMSIG_txtSearch').attr('disabled', 'disabled');
            $('#ctl00_menuMSIG_btnSearch').attr('disabled', 'disabled');
            $('.menu').attr("href", "javascript:void(0)");
            $('.menu').removeAttr("target");
        }
        else {
            menu.style.display = "block";
        }
    }
}
function ClearControls() {
    var url = window.location.href;
    window.location.href = url;
}
