﻿
//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'
        }
    });
}



function modalAttendere(testo) {

    $.blockUI({
        message: "<div class='div-loading'><div>" + testo + "</div></div>",
        fadeIn: 700,
        fadeOut: 700,
        timeout: 0,
        showOverlay: true,
        centerY: true,
        centerX: true,
        css: {
            width: '370px',
            'border': '1px solid #E2001A'
        }
    });



}


//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);
}

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;
}



$('#div_news0').css('top', 5 + 'px');
$('#div_news1').css('top', 27 + 'px');

$('#div_news0').css('top', 5 + 'px');
$('#div_news1').css('top', 27 + 'px');

function scorriNews() {

    if (parseInt(count + 0) == 2) {
        count = 0
    }

    $('#div_news' + parseInt(count)).css('top', 5 + 'px');
    if (parseInt(count + 1) == 2) {
        count = 0
    }

    $('#div_news' + parseInt(count)).css('top', 27 + 'px');



    setTimeout('scorriNews()', 3000);
}

function contaCaratteri(TextBoxID, MaxCharacter, SpanCharacterCounterID, TitoloErrore, TestoErrore) {
    var TextBox = $("#" + TextBoxID);
    var span = $("#" + SpanCharacterCounterID);

    var testo = TextBox.val();

    if (MaxCharacter - testo.length < 0) {
        TextBox.val(testo.substring(0, MaxCharacter));
        span.html(MaxCharacter);
        modalError(TitoloErrore, TestoErrore);
    } else {
        span.html(testo.length);
    }
} 

