// Archivo JScript
var ModalDialog = {};

// Botones
ModalDialog.OK      = 1;
ModalDialog.CANCEL  = 2;
ModalDialog.YES     = 4;
ModalDialog.NO      = 8;
ModalDialog.Panel   = null;
ModalDialog.EmptyFunction = function(){};
ModalDialog.PathImages = null;
ModalDialog.Buttons = { OK_HANDLER    : ModalDialog.EmptyFunction, OK_POSTBACK    : "",
                        CANCEL_HANDLER: ModalDialog.EmptyFunction, CANCEL_POSTBACK: "",
                        YES_HANDLER   : ModalDialog.EmptyFunction, YES_POSTBACK   : "",
                        NO_HANDLER    : ModalDialog.EmptyFunction, NO_POSTBACK    : "" };
ModalDialog.IsReady = false;


ModalDialog.Show = function (title, message, buttons, handlers)
{
    if(!ModalDialog.IsReady)
        ModalDialog.Init();
    // Registrar handlers
    if(handlers != null)
    {
        ModalDialog.Buttons.OK_HANDLER     = (typeof handlers.OK == "function")     ? handlers.OK     : ModalDialog.EmptyFunction;
        ModalDialog.Buttons.CANCEL_HANDLER = (typeof handlers.CANCEL == "function") ? handlers.CANCEL : ModalDialog.EmptyFunction;
        ModalDialog.Buttons.YES_HANDLER    = (typeof handlers.YES == "function")    ? handlers.YES    : ModalDialog.EmptyFunction;
        ModalDialog.Buttons.NO_HANDLER     = (typeof handlers.NO == "function")     ? handlers.NO     : ModalDialog.EmptyFunction;
    }
    // Botones
    var footer = "";
    if(buttons & ModalDialog.OK)
        footer += "<img src='" + ModalDialog.PathImages + "/botones/bt_aceptar.png' onclick='ModalDialog.handlerOk()' class='ModalDialogBoton' />&nbsp;";
    if(buttons & ModalDialog.CANCEL)
        footer += "<img src='" + ModalDialog.PathImages + "/botones/bt_finalizar.png' onclick='ModalDialog.handlerCancel()' class='ModalDialogBoton' />&nbsp;";
    if(buttons & ModalDialog.YES)
        footer += "<img src='" + ModalDialog.PathImages + "/botones/bt_yes.png' onclick='ModalDialog.handlerYes()' class='ModalDialogBoton' />&nbsp;";
    if(buttons & ModalDialog.NO)
        footer += "<img src='" + ModalDialog.PathImages + "/botones/bt_no.png' onclick='ModalDialog.handlerNo()' class='ModalDialogBoton' />&nbsp;";
    // Mostrar
    //$('ModalDialogContainer').style.display='';
    try
    {
        if(panelLoading != null)
            panelLoading.hide();
    }
    catch(ex){}
    ModalDialog.Panel.setHeader(title);
    ModalDialog.Panel.setBody('<center>' + message + '</center>');
    ModalDialog.Panel.setFooter('<center>' + footer + '</center>');
    ModalDialog.Panel.render();
    ModalDialog.Panel.show();
}

ModalDialog.handlerOk = function() { 
    ModalDialog.Buttons.OK_HANDLER();
    eval(ModalDialog.Buttons.OK_POSTBACK);
    ModalDialog.Panel.hide();
    //$('ModalDialogContainer').style.display='none';
}; 

ModalDialog.handlerCancel = function() { 
    ModalDialog.Buttons.CANCEL_HANDLER();
    eval(ModalDialog.Buttons.CANCEL_POSTBACK);
    ModalDialog.Panel.hide(); 
    //$('ModalDialogContainer').style.display='none';
}; 

ModalDialog.handlerYes = function() { 
    ModalDialog.Buttons.YES_HANDLER();
    eval(ModalDialog.Buttons.YES_POSTBACK);
    ModalDialog.Panel.hide(); 
    //$('ModalDialogContainer').style.display='none';
}; 
	 
ModalDialog.handlerNo = function() { 
    ModalDialog.Buttons.NO_HANDLER();
    eval(ModalDialog.Buttons.NO_POSTBACK);
    ModalDialog.Panel.hide(); 
    //$('ModalDialogContainer').style.display='none';
};

ModalDialog.Init = function() {
    if(!ModalDialog.IsReady)
    {
        document.body.className = 'yui-skin-sam';
        $('ModalDialogControl').style.display='';
        ModalDialog.Panel =  new YAHOO.widget.Panel("ModalDialogControl", 
            { width: "468px", fixedcenter: true, close:false, visible: false, draggable: false, zindex:2000, modal: true, constraintoviewport: true } );
        ModalDialog.IsReady = true;
    }
};

YAHOO.util.Event.onDOMReady(ModalDialog.Init);

