﻿function EndRequestHandler(sender, args) {
    var o = document.getElementById("__PanelShowActionInfo");
    if (o) document.body.removeChild(o);
    if (args.get_error() != undefined && args.get_error().httpStatusCode == '500') {
        var errorName = args.get_error().name;
        var errorMessage = args.get_error().message
        args.set_errorHandled(true);
        alert("<div><strong>No hemos podido atender su solicitud<br />Por favor inténtalo pasados unos instantes.</strong></div><div></div>");
    }
}

function ShowPosyScroll() {
    return (window.pageYOffset) ? (window.pageYOffset) : (document.documentElement) ? ((document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop) : document.body.scrollTop;
}

function BeginRequestHandler() {
    if (!document.getElementById("__PanelShowActionInfo")) {
        var panelShowActionInfo = document.createElement("div");
        panelShowActionInfo.id = "__PanelShowActionInfo";
        document.body.appendChild(panelShowActionInfo);

        var info = document.createElement("div");
        info.id = "__InfoShowInfoShop";
        info.style.zIndex = "1003";
        info.style.left = document.body.offsetWidth / 2 - 192 + "px";

        if (navigator.userAgent.match(/MSIE [123456]/i)) {
            info.style.position = "absolute";
            info.style.top = ShowPosyScroll() + 30 + "px";
        }
        else {
            info.style.position = "fixed";
            info.style.top = "20px";
        }
        panelShowActionInfo.appendChild(info);

        var img = document.createElement("img");
        img.src = Reg_ImgLoading;
        img.className = "ImgLoading";
        img.style.width = "383px";
        img.style.height = "53px";
        img.alt = "Cargando...";
        info.appendChild(img);
    }
}

function showAlert(msg) {
    alert(msg);
}

window.alert = function(msg) {
    var panel = $get("panel_alert");
    if (panel) document.body.removeChild($get("panel_alert"));
    panel = document.createElement("div");
    panel.id = "panel_alert";
    panel.style.width = "400px";
    panel.style.left = "34%";
    if (navigator.userAgent.match(/MSIE [123456]/i)) {
        panel.style.position = "absolute";
        panel.style.top = ShowPosyScroll() + 300 + "px";
    }
    else {
        panel.style.position = "fixed";
        panel.style.top = "30%";
    }
    var regex = new RegExp("\r\n", "g");
    panel.innerHTML = "<table class=\"tableshadow\" align=\"right\"><tr><td class=\"tl\"></td><td class=\"tc\"></td><td class=\"tr\"></td></tr><tr><td class=\"ml\"></td><td class=\"mc\" style=\"padding-right:12px\">" + msg.replace(regex, "<br />") + "<button id=\"button_alert\" style=\"display:block;margin-top:10px\" onclick=\"document.body.removeChild($get('" + panel.id + "'))\">Aceptar</button></td><td class=\"mr\"></td></tr><tr><td class=\"bl\"></td><td class=\"bc\"></td><td class=\"br\"></td></tr></table>";

    document.body.insertBefore(panel, document.body.firstChild);
    $get("button_alert").focus();
}

function SwitchViewDiv(id) {
    var capa = $get(id);
    if (capa) {
        if (capa.style.display == 'none')
            capa.style.display = 'block';
        else
            capa.style.display = 'none';
    }
}