﻿
//funzione il popup di avviso
function modal(testo) {

    $.blockUI({
        message: "<div class='div-modal'><div>" + testo + "</div></div>",
        fadeIn: 700,
        fadeOut: 700,
        timeout: 3000,
        showOverlay: false,
        centerY: true,
        centerX: true,
             css: {
            width: '370px',
            left: '50%',
            'margin-left': '-185px'
        }
    });
}


//funzione per il popup modal di errore
function modalError(titolo, testo) {

    $.blockUI({
        message: "<div class='div-modal-error'>" +
                        "<div class='div-modal-error-title'>" + titolo + "</div>" +
                        "<div class='div-modal-error-body'>" + testo + "</div>" +
                        "<div class='div-modal-error-button'><span id='span_chiudi_modal_error'>Chiudi</span></div>" +
                    "</div>",
        centerY: true,
        centerX: true,
              css: {
            width: '370px',
            cursor: 'default',
            left: '50%',
            'margin-left': '-185px'
        }
    });

    $('#span_chiudi_modal_error').click($.unblockUI);
}


//funzione per capire se l'utente ha premuto OK o Annulla nei confirm di Telerik
//se l'utente ha clickato OK fa postbak altrimenti no
window.blockConfirm = function(text, mozEvent, oWidth, oHeight, callerObj, oTitle) {
    var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually
    //Cancel the event
    ev.cancelBubble = true;
    ev.returnValue = false;
    if (ev.stopPropagation) ev.stopPropagation();
    if (ev.preventDefault) ev.preventDefault();

    //Determine who is the caller
    var callerObj = ev.srcElement ? ev.srcElement : ev.target;

    //Call the original radconfirm and pass it all necessary parameters
    if (callerObj) {
        //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.
        var callBackFn = function(arg) {
            if (arg) {
                callerObj["onclick"] = "";
                if (callerObj.click) {
                    callerObj.click(); //Works fine every time in IE, but does not work for links in Moz
                } else if (callerObj.tagName == "A") {
                    //We assume it is a link button! 
                    try {
                        eval(callerObj.href)
                    }
                    catch (e) { }
                } else if (callerObj.parentNode.click) {
                    callerObj.parentNode.click();
                } else if (callerObj.parentNode.tagName == "A") {
                    try {
                        eval(callerObj.parentNode.href)
                    }
                    catch (e) { }
                }
            }
        }

        radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);

    }
    return false;
}
function hideLeanModal() {
    $("#lean_overlay").fadeOut(200);
    $("#loginModal").hide();
    return false;
}



