﻿//IE FF todo
var MBoxResult =
{    
    NONE:   -1,
    CANCEL: 0,
    ACCEPT: 1,
    OK:     2
}

var MBoxButtons =
{
    ACCEPTCANCEL:   0,
    OK:             1
}

var MBoxIcon =
{
    EXCLAMATION:    0,
    ERROR:          1,
    PROMPT:         2,
    OK:             3
}

var AMBoxes = new Array();

function IMBoxButton(res, mbox)
{    
    AMBoxes[mbox].Result = res;
    AMBoxes[mbox].Hide();
    AMBoxes[mbox].Action(res, $V(AMBoxes[mbox].Id + "text"));
}

function MBox()
{
    this.Win = null;
    this.Id = 0;
    this.Screen = null;
    this.IsModal = false;
    this.Action = null;
    this.Result = MBoxResult.NONE;
}

MBox.prototype =
{
    Create:
        function (id, width, height)
        {
            var html, d = GetPageSize();            
            var box = $C("DIV");
                        
            this.Id = id;
            this.Win = box;
            
            box["id"] = id;
            box["className"] = "Win";
            box["style"]["zIndex"] = 71;
            box["style"]["width"] = width + "px";
            box["style"]["height"] = height + "px";            
            box["style"]["top"] = ((d[1]/2)-(height/2)) + "px";
            box["style"]["left"] = ((d[0]/2)-(width/2)) + "px";            
            
            $Add(box, null);            
            box["style"]["visibility"] = "hidden";
                        
            AMBoxes[this.Id] = this;
        },       
        
    Show:
        function (title, msg, buttons, icon, action, tag)
        {
            var c;        
            var h;

            h = "<table class='WinTitle'>";
            h += "<tr><td><img src='../JFramework/images/16/web.gif' />";
            h += "<span>" + title + "</span></td></tr></table>"; 

            h += "<table style='margin: 10px;'><tr>";

            if (icon == MBoxIcon.EXCLAMATION)
                h += "<td><img src='../JFramework/images/32/warning.gif' /></td>";
            if (icon == MBoxIcon.ERROR)
                h += "<td><img src='../JFramework/images/32/error.gif' /></td>";
            if (icon == MBoxIcon.OK)
                h += "<td><img src='../JFramework/images/32/ok_icon.gif' /></td>";

            h += "<td><span class='Text' style='color: black'>" + msg + "</span></td>"            
            
            if (icon == MBoxIcon.PROMPT)
                h += "<td><input id='" + this.Id + "text' type='text' /></td>";
            
            h += "</tr></table><hr class='WinHR' /><center><table class='WinTable'><tr>";
                    
            if (buttons == MBoxButtons.ACCEPTCANCEL)
            {                    
                h += "<td><input id='" + this.Id + "btnAccept' type='button' value='Aceptar' class='Button' style='width: 100px;' onclick=\"IMBoxButton(MBoxResult.ACCEPT, '" + this.Id + "')\" /></td>";
                h += "<td><input id='" + this.Id + "btnCancel' type='button' value='Cancelar' class='Button' style='width: 100px;' onclick=\"IMBoxButton(MBoxResult.CANCEL, '" + this.Id + "')\" /></td>";                
            }
            if (buttons == MBoxButtons.OK)
                h += "<td><input id='" + this.Id + "btnOK' type='button' value='Ok' class='Button' style='width: 100px;' onclick=\"IMBoxButton(MBoxResult.OK, '"+this.Id+"')\" /></td>";
                    
            h += "</tr></table></center>";
            
            this.Win["innerHTML"] = h;
            this.Win["style"]["visibility"] = "visible";
            
            if (icon == MBoxIcon.PROMPT)
            {
                $(this.Id + "text").value = tag;
                FocusCtrl(this.Id + "text");
            }
            
            this.Action = action;
            this.IsModal = false;         
        },
        
    ShowModal:
        function (title, msg, buttons, icon, action, tag)
        {
            if (this.Screen == null) 
            {
                this.Screen = new ScreenBox();
                this.Screen.Create(this.Id + "sb4mb6", 50, false, false);                
            }
            this.Screen.Show();
            $S(this.Id + "sb4mb6")["zIndex"] = 70;
            this.Show(title, msg, buttons, icon, action, tag);
            
            this.IsModal = true;
        },
        
    Hide:
        function () 
        { 
            this.Win["style"]["visibility"] = "hidden";
            if (this.IsModal == true) this.Screen.Hide();
        }
}

