//================================= CLASS CONSTRUCTOR ========================================
function SysMsgMgr(irmgr,iwinMgr)
{
//MEMBER VARIABLES
//The resource manager ...
 this.rmgr = irmgr;
//The window manager ...
 this.winMgr = iwinMgr;
//The system messages that need to be shown on-screen ...
 this.smsgs = new Array();
//True if there is a message shown ...
 this.msgShown = false;
}

//====================================== STATIC ==============================================
SysMsgMgr.MSGTYPE_DEFAULT = SysMsg.MSGTYPE_INFO;

//====================================== MEMBERS =============================================
SysMsgMgr.prototype.showNextMessage = function()
{
//Checking if we have messages ...
 if (this.smsgs.length == 0)
  return;
//Checking if there isn't another msg on-screen ...
 if (this.msgShown == true)
  return;
//Showing the current message ...
 this.smsgs[0].show();
//The message is now shown ...
 this.msgShown = true;
//Removing the message from list ...
 this.smsgs.splice(0,1);
}

/* apre una finestra modale con 2 pulsanti ok e cancel
   prende come parametri 3 callback da richiamare sulla pressione del pulsante ok ,
   cancel e per la chiusura diretta della finestra */
SysMsgMgr.prototype.getMessageResult = function(imsg,itype,ieClose,callbackOK,callbackCancel)
{
    var
    smsg = null,
    alen = arguments.length;
    vmsg = (alen >= 1)?(imsg):"";
    vtype = (alen >= 2)?(itype):SysMsgMgr.MSGTYPE_DEFAULT;
    veClose = (alen >= 3)?(ieClose):null;

    /* referenzio in questa funzione le callback passate come argomento */
    if( callbackOK )
        this.callbackOK = callbackOK;
    if( callbackCancel )
        this.callbackCancel = callbackCancel;

    //Creating the message ...
    smsg = new SysMsg(this,vmsg,vtype,veClose,true);
    smsg.show();
}

SysMsgMgr.prototype.showMessage = function(imsg,itype,ieClose,typeOkCancel)
{
 var
  smsg = null,
  alen = arguments.length;
  vmsg = (alen >= 1)?(imsg):"";
  vtype = (alen >= 2)?(itype):SysMsgMgr.MSGTYPE_DEFAULT;
  veClose = (alen >= 3)?(ieClose):null;
  veOkCancel = (alen >= 4)?(typeOkCancel):null;

//Creating the message ...
 smsg = new SysMsg(this,vmsg,vtype,ieClose,veOkCancel);
//Adding the newly created message ...
 this.smsgs.push(smsg);
//Showing the next message ...
 this.showNextMessage();
}

SysMsgMgr.prototype.onSysMsgCloseOk = function()
{
    this.callbackOK();
}

SysMsgMgr.prototype.onSysMsgCloseCancel = function()
{
    this.callbackCancel();
}

SysMsgMgr.prototype.onSysMsgClose = function()
{
//Setting that there is now other message shown now!
 this.msgShown = false;
//Showing the next message ...
 this.showNextMessage();
}
