﻿var $objDiv = $('<div></div>').hide();
var $objSfondo = $('<div></div>').hide();

function AX_openMess(messaggio) {
    $objDiv.css({ 'position': 'absolute', 'zIndex': '11', 'background': '#ffffff', 'border': '3px #999 solid' });
    $objSfondo.css({ 'position': 'absolute', 'background': '#000000', 'filter': 'absolute', 'top': '0', 'left': '0', 'width': $(document).width() + 'px', 'height': $(document).height() + 'px', 'zIndex': '10', 'cursor': 'pointer' });

    var strDesc, strChiudi;
    strDesc = "<p style=\"text-align:center;vertical-align:middle;height:100%;padding:5px 20px 15px 20px;\">" + messaggio + "</p>";
    strChiudi = "<div style=\"text-align:right;margin:3px;\"><img src=\"/images/popup/close.gif\" style=\"cursor:pointer;\" onclick=\"AX_closeMess();\" /></div>";

    //objDiv.innerHTML = strTop + strLato + strChiudi + strDesc + strLato + strBottom;
    $objDiv.html(strChiudi + strDesc);

    $('body').append($objSfondo, $objDiv);
    centerDiv($objDiv);
    $objSfondo.fadeTo("slow", 0.5).click(function() { AX_closeMess(); });
    $objDiv.fadeIn("slow");

}

function AX_closeMess() {
    $objSfondo.fadeOut("slow");
    $objDiv.fadeOut("slow");
}

function centerDiv(div) {
    var DIVwidth = $(div).width();
    var DIVheight = $(div).height();
    var SCREENwidth = $(document).width();
    var SCREENheight = $(window).height();
    var SCREENscrolltop = $(window).scrollTop();
    $(div).css({ "position": "absolute", "left": (SCREENwidth - DIVwidth) / 2 + "px", "top": ((SCREENheight - DIVheight) / 2) + SCREENscrolltop + "px" });
}
