function loadNotifiche(){

    new Ajax.Request('/smsMaster/notificheWeb.do',
    {
        method:'post',
        parameters: {
            method: 'notifiche'
        },
        onSuccess: function(transport){
            var response = transport.responseText || "no response text";
            var myData = response.evalJSON();

            if(myData.length < 1)
                return;

            $('postit').style.display = 'block';

            //aggiungo drag and drop
            new Draggable('postit',{ scroll: window });

            myData.each(function(notifica) {
                $('notificheWeb').insert({
                    bottom : getHTMLRispostaNotificaWeb(notifica[0],notifica[1],notifica[2],notifica[3])
                    });
            });


        },
        onFailure: function(){ /*alert('Something went wrong...')*/ }
    });

}

function removeNotifica(id){
     new Ajax.Request('/smsMaster/notificheWeb.do',
    {
        method:'post',
        parameters: {
            method: 'eliminaNotifica',
            idnotifica : id
        },
        onSuccess: function(transport){
            var response = transport.responseText || "no response text";
            var myData = response.evalJSON();

            var result = myData.result;
            if(result) {
                $('notificaWeb'+id).hide();
            } else {
                alert('error');
            }


        },
        onFailure: function(){ /*alert('Something went wrong...')*/ }
    });
}



function getHTMLRispostaNotificaWeb(id,chiudi,testo,livello){
    //return '<div id="notificaWeb'+id+'" class="notificaBox notificaLivello'+livello+'"><a href="#" class="removeNotificaBox" onclick="removeNotifica('+id+');return false;">X</a><div class="text">'+testo+'</div></div>';
    var chiudiHTML = '';
    if(chiudi == 'true')
        chiudiHTML = ' <a href="#" class="removeNotificaBox" onclick="removeNotifica('+id+');return false;"> chiudi</a>';
    return '<div id="notificaWeb'+id+'" class="notificaBox notificaLivello'+livello+'"><div class="text"><img src="img/varie/notificaLivello'+livello+'.gif" border="0"> '+testo+chiudiHTML+'</div></div>';
}

document.observe('dom:loaded', function(){
    loadNotifiche();
});