﻿Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler)

function posxScroll()
{
    return (window.pageXOffset)?(window.pageXOffset):(document.documentElement)?((document.documentElement.scrollLeft)?document.documentElement.scrollLeft:document.body.scrollLeft):document.body.scrollLeft;
}
function ShowPosyScroll()
{
    return (window.pageYOffset)?(window.pageYOffset):(document.documentElement)?((document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop):document.body.scrollTop;
}
function ShowMask()
{
    if (!document.getElementById("__PanelShowInfoShop"))
    {
        var info = document.createElement("div");
        info.id = "__InfoShowInfoShopAdded";
        info.style.width = "400px";
        info.style.zIndex = "1004";
        
        if(navigator.userAgent.match(/MSIE [123456]/i))
        {
            info.style.position = "absolute";
            info.style.top = ShowPosyScroll() + 30 + "px";
            info.style.left = "39%";
        }
        else
        {
            info.style.position = "fixed";
            info.style.top = "20px";
            info.style.left = "39%";
        }
        
        document.body.appendChild(info);
        
        info.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\">Has añadido un artículo a tu carrito de la compra.<br /><br /><button style=\"font-size:80%\" onclick=\"window.location.href = '" + rootPath + "carrito.aspx';\">Ir al Carrito</button> <button style=\"font-size:80%;margin-left:10px\" onclick=\"RemoveMask()\">Seguir Comprando</button></td><td class=\"mr\"></td></tr><tr><td class=\"bl\"></td><td class=\"bc\"></td><td class=\"br\"></td></tr></table>";
    }
}

function RemoveMask()
{
    var o = document.getElementById("__InfoShowInfoShopAdded");
    if(o) document.body.removeChild(o);
}

function RemovePanelShowActionInfo()
{
    var o = document.getElementById("__PanelShowActionInfo");
    if(o) document.body.removeChild(o);
}

function EndRequestHandler(sender, args)
{
    if (args.get_error() == undefined)
    {
        RemovePanelShowActionInfo();
        var o = sender._postBackSettings.sourceElement.getAttribute("ShowInfoShop");
        if(o && o == "1")
            ShowMask();
        else
            RemoveMask();
    }
}

function BeginRequestHandler(sender, args)
{
    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.width = "300px";
        info.style.backgroundColor = "#FFF";
        info.style.textAlign = "left";
        info.style.border = "2px solid #01384E";
        info.style.padding  = "6px";
        info.style.zIndex = "1003";
        
        if(navigator.userAgent.match(/MSIE [123456]/i))
        {
            info.style.position = "absolute";
            info.style.top = ShowPosyScroll() + 30 + "px";
            info.style.left = "44%";
        }
        else
        {
            info.style.position = "fixed";
            info.style.top = "20px";
            info.style.left = "44%";
        }
        
        panelShowActionInfo.appendChild(info);
        
        var img = document.createElement("img");
        img.src = imgGeneralPath + "loading.gif";
        img.className = "ImgLoading";
        img.style.width = "16px";
        img.style.height = "16px";
        img.alt = "Cargando...";
        img.align = "left";
        info.appendChild(img);
        
        var span = document.createElement("span");
        var message=args.get_postBackElement().getAttribute("ShowInfoMessage");
        if(message)
            span.innerHTML = message;
        else
            span.innerHTML = "Cargando...";
        info.appendChild(span);
    }
}
//--------------------------------------------------
function search()
{
    window.location.href = "/familia.aspx?especial=busqueda&q=" + $get('q').value;
}
function keysearch(e)
{
    if (e.keyCode==13)
    {
        search();
        return false;
    }
    else
        return true;
}

function ShowContacto(asunto)
{
    var table = $get("TableContacto");
    $get(prefixMPC + "_TBAsunto").value=asunto;
    $get(prefixMPC + "_TBNombre").value = "";
    $get(prefixMPC + "_TBEmail").value= "";
    $get(prefixMPC + "_TBComentario").value = "";
    table.style.display="block";
    if(navigator.userAgent.match(/MSIE [123456]/i))
    {
        table.style.position = "absolute";
        table.style.top = ShowPosyScroll() + 200 + "px";
        table.style.left = "25%";
    }
}

function agregar()
{
    var url="http://www.aceroymagia.com";
    var titulo="Acero y Magia  Hacemos REALIDAD tus Peliculas";
    if (document.all) window.external.AddFavorite(url,titulo);
}

function ValidatorDNI( src, arg )
{
    arg.IsValid = !$get(prefixCarrito + "_CBFactura").checked || ValidatorTrim(arg.Value) != "";
}

var paneli=0;
window.alert = function(msg) 
{
    paneli++;
    
    var panel = document.createElement("div");
    panel.id = "p" + paneli;
    panel.style.width = "400px";
    if(navigator.userAgent.match(/MSIE [123456]/i))
    {
        panel.style.position = "absolute";
        panel.style.top = ShowPosyScroll() + 300 + "px";
        panel.style.left = "25%";
    }
    else
    {
        panel.style.position = "fixed";
        panel.style.top = "30%";
        panel.style.left = "25%";
    }
    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(/\r\n/,"<br />") + "<button style=\"display:block;margin-top:5px\" 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.appendChild(panel);
}
function popup(url,width,height)
{
    window.open(url,"","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height);
}
function makeDoubleDelegate(function1, function2)
{
    return function() 
    {
        if (function1) function1();
        if (function2)function2();
    }
}
function ShowWait()
{
    var panelShowActionInfo = document.createElement("div");
     
    var info = document.createElement("IMG");
    info.src = "/images/general/espere.jpg";
    info.alt = "Cargando la página: Por favor espere.";
    info.style.zIndex = "1003";
    panelShowActionInfo.appendChild(info);
    
    if(navigator.userAgent.match(/MSIE [123456]/i))
    {
        info.style.position = "absolute";
        info.style.top = ShowPosyScroll() + 60 + "px";
        info.style.left = "44%";
    }
    else
    {
        info.style.position = "fixed";
        info.style.top = "60px";
        info.style.left = "44%";
    }
    
    document.body.appendChild(panelShowActionInfo);
}