﻿function wopen(url, name, w, h, status, toolbar, menubar, resizable, scrollbars) {
    //menu:1 o 0; resize: 1 o 0; scroll: 1 o 0; 
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;
    // IE5 and other old browsers might allow a window that is
    // partially offscreen or wider than the screen. Fix that.
    // (Newer browsers fix this for us, but let's be thorough.)
    if (wleft < 0) {
        w = screen.width;
        wleft = 0;
    }
    if (wtop < 0) {
        h = screen.height;
        wtop = 0;
    }
    var win = window.open(url,
    name,
    'width=' + w + ',height=' + h +
    ',left=' + wleft + ',top=' + wtop + ',status=' + status + ',toolbar=' + toolbar + ',menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars);
    win.focus();
}
function stopEvent(pE) {
    if (!pE)
        if (window.event)
        pE = window.event;
    else
        return;
    if (pE.cancelBubble != null)
        pE.cancelBubble = true;
    if (pE.stopPropagation)
        pE.stopPropagation();
    if (pE.preventDefault)
        pE.preventDefault();
    if (window.event)
        pE.returnValue = false;
    if (pE.cancel != null)
        pE.cancel = true;
}
//cattura inizio e fine postback asincrono
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function BeginRequestHandler(sender, args) {
    ActivateWaitingDiv(true);
}

function EndRequestHandler(sender, args) {
    ActivateWaitingDiv(false);
}

function ActivateWaitingDiv(activate) {
    var cdiv = $get("coveringDiv");
    var wdiv = $get("waitingDiv");

    if (activate) {
        var bodyWidth = document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
        var bodyHeight = document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight;
        var screenWidth = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
        var screenHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
        var scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
        var scrollLeft = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;

        var maxHeight;
        if (bodyHeight > screenHeight) maxHeight = bodyHeight; else maxHeight = screenHeight;
        //posizionamento covering
        cdiv.style.height = maxHeight + 'px';
        cdiv.style.width = bodyWidth + 'px';

        //posizionamento waiting
        var wtop = scrollTop + Math.floor((screenHeight - 80) / 2);
        wdiv.style.top = wtop + 'px';
        var wleft = scrollLeft + Math.floor((screenWidth - 80) / 2);
        wdiv.style.left = wleft + 'px';

        cdiv.style.display = "block";
        wdiv.style.display = "block";

    }
    else {
        //disattivazione
        cdiv.style.display = "none";
        wdiv.style.display = "none";
    }
}
