OMB = {}; // global namespace

function typeOf(base, c) // util function for class inheritance
{
    c.prototype = new base();
    c.prototype.constructor = c; // reset
    c.prototype.base = base;
    return c;
}

function debug(s)
{
    OMB.elem('debug').innerHTML += s;
}

//
// STRING FUNCTIONS
//

OMB.trimString = function(s)
{
	return s.replace(/^\s+|\s+$/g,"");
}

OMB.trimStringL = function(s)
{
	return s.replace(/^\s+/,"");
}

OMB.trimStringR = function(s)
{
	return s.replace(/\s+$/,"");
}

OMB.lower   = 'abcdefghijklmnopqrstuvwxyz';
OMB.upper   = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
OMB.numeric = '0123456789';

OMB.isValid = function(s,array) 
{
    if (!s)
        return false;
        
    for (var i=0; i < s.length; i++)
        if (array.indexOf(s.charAt(i),0) == -1) return false;
        
    return true;
}

OMB.isLower            = function(s) { return OMB.isValid(s,OMB.lower); }
OMB.isUpper            = function(s) { return OMB.isValid(s,OMB.upper); }
OMB.isNumeric          = function(s) { return OMB.isValid(s,OMB.numeric); }
OMB.isAlpha            = function(s) { return OMB.isValid(s,OMB.lower+OMB.upper); }
OMB.isAlphaNumeric     = function(s) { return OMB.isValid(s,OMB.lower+OMB.upper+OMB.numeric); }

//
// UTILS
//

OMB.browser = (function()
{
    var agt = navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera")   != -1) return 1; // opera user agent will also contain "msie"
    if (agt.indexOf("msie")    != -1) return 2;
    if (agt.indexOf("firefox") != -1) return 3;
    
    return 0;
})();

OMB.isFirefox = function()
{
    return OMB.browser == 3;
}

OMB.isIE = function()
{
    return OMB.browser == 2;
}

OMB.isOpera = function()
{
    return OMB.browser == 1;
}

OMB.elem = function(i)
{
    return document.getElementById(i);
}

OMB.setCSS = function(e,css)
{
    if (OMB.isIE())
        e.className = css;
    else
        e.setAttribute('class',css);
}

OMB.getCSS = function(e)
{
    if (OMB.isIE())
        return e.className;
    else
        return e.getAttribute('class');
}

if (window.innerWidth)
{
    OMB.winW = function() { return window.innerWidth; }
    OMB.winH = function() { return window.innerHeight; }
    OMB.scrollX = function() { return window.pageXOffset; }
    OMB.scrollY = function() { return window.pageYOffset; }
}
else if (document.documentElement && document.documentElement.clientWidth)
{
    OMB.winW = function() { return document.documentElement.clientWidth; }
    OMB.winH = function() { return document.documentElement.clientHeight; }
    OMB.scrollX = function() { return document.documentElement.scrollLeft; }
    OMB.scrollY = function() { return document.documentElement.scrollTop; }
}
else if (document.body.clientWidth)
{
    OMB.winW = function() { return document.body.clientWidth; }
    OMB.winH = function() { return document.body.clientHeight; }
    OMB.scrollX = function() { return document.body.scrollLeft; }
    OMB.scrollY = function() { return document.body.scrollTop; }
}

if (document.documentElement && document.documentElement.scrollWidth)
{
    OMB.docW = function() { return document.documentElement.scrollWidth; }
    OMB.docH = function() { return document.documentElement.scrollHeight; }
}
else if (document.body.scrollWidth)
{
    OMB.docW = function() { return document.body.scrollWidth; }
    OMB.docH = function() { return document.body.scrollHeight; }
}

OMB.setX = function(e,x)
{
    e.style.left = x + 'px';
}

OMB.setY = function(e,y,bottom)
{
    e.style.top = y + 'px';
}

OMB.setZ = function(e,z)
{
    e.style.zIndex = z;
}

OMB.getX = function(e)
{
    var x=0;
    while(e)
    {
        x += e.offsetLeft;
        e = e.offsetParent;
    }
    return x;
}

OMB.getY = function(e)
{
    var y=0;
    while(e)
    {
        y += e.offsetTop;
        e = e.offsetParent;
    }
    return y;
}

OMB.getW = function(e)
{
    return e.offsetWidth;
}

OMB.getH = function(e)
{
    return e.offsetHeight;
}

OMB.resolveUrl = function(s)
{
    var u =  OMB.rootDir;
    if (s && s.length > 0)
    {
        var l = u.charAt(u.length-1) == '/';
        var r = s.charAt(0) == '/';
        
        if (l && r)
        {
            if (s.length > 1)
                u += s.substr(1);
        }
        else if (!l && !r)
            u += '/' + s;
        else
            u += s;
    }
    
    return u;
}

OMB.display = function(e,v)
{
    e.style.display = v ? '' : 'none';
}

OMB.visible = function(e,v)
{
    e.style.visibility = v ? '' : 'hidden';
}

OMB.createAbsDiv = function(html)
{
    var e = document.createElement('div');
    e.innerHTML = html;
    e.style.position = 'absolute';
    document.body.insertBefore(e,document.body.firstChild);
    return e;
}

OMB.createChildDiv = function(parent,html)
{
    var e = document.createElement('div');
    e.innerHTML = html;
    
    parent.appendChild(e);
    return e;
}

//
// EVENTS
//

OMB.addEvent = function(e,name,func)
{
    if (OMB.isIE())
        e.attachEvent('on'+name,func);
    else
        e.addEventListener(name,func,false);
}

OMB.removeEvent = function(e,name,func)
{
    if (OMB.isIE())
        e.detachEvent('on'+name,func);
    else
        e.removeEventListener(name,func,false);
}

OMB.clientX = 0;
OMB.clientY = 0;
OMB.onSampleXY = function(e)
{
    OMB.clientX = e.clientX;
    OMB.clientY = e.clientY;
}

OMB.sampleXY = function(start)
{
    if (start)
        OMB.addEvent(document.body,'mousemove',OMB.onSampleXY);
    else
        OMB.removeEvent(document.body,'mousemove',OMB.onSampleXY);
}

//
// MEMBER INFO
//

OMB.Member = function(user,name)
{
    this.userName = user;
    this.fullName = name;
}

//
// USER MESSAGE
//

OMB.userMessages = {};
OMB.UserMessage = function(id,tbl,img,txt)
{
    this.tbl = tbl;
    this.img = img;
    this.txt = txt;
    OMB.userMessages[id] = this;
}

OMB.showUserMessage = function(id,type,msg)
{
    var o = OMB.userMessages[id];
    if (o)
    {
        var etbl = OMB.elem(o.tbl);
        if (etbl)
        {
            if (msg.length < 1)
                OMB.display(etbl, false);
            else            
            {
                switch (type)
                {
                    case 1: 
                        OMB.setCSS(etbl,"UserInfo");
                        OMB.elem(o.img).src = OMB.resolveUrl('omb/images/icons/info1.gif');
                        break;
                    case 2:
                        OMB.setCSS(etbl,"UserError"); 
                        OMB.elem(o.img).src = OMB.resolveUrl('omb/images/icons/error1.gif');
                        break;
                }
            
                OMB.elem(o.txt).innerHTML = msg;
                OMB.display(etbl, true);
            }
        }
    }
}

//
// AJAX PANEL
//

OMB.mapAjaxPanelToClientObject = {};

OMB.AjaxPanel = function(template,master,content,script,start)
{
    this.template = template;
    this.master = master;    
    this.content = content;
    this.script = script;
    this.start = start;
    this.loading = null;
}

OMB.onAjaxRequestStart = function(s, e) {
    var p = OMB.mapAjaxPanelToClientObject[s.UniqueID];
    if (p) {
        if (p.master) {
            p.footer = OMB.elem('footer');
            if(p.footer)
                p.footer.style.display = "none";

            p.back = document.body.getAttribute('background');
            document.body.setAttribute('background', '');
        }

        var x; var y;
        var econtent = OMB.elem(p.content);
        if (p.template == 1) {
            econtent.style.display = 'none';
            x = OMB.docW() / 2;
            y = OMB.docH() / 2;
        }
        else {
            OMB.setCSS(econtent, 'Opacity40');
            x = OMB.getX(econtent) + OMB.getW(econtent) / 2;
            y = OMB.getY(econtent) + OMB.getH(econtent) / 2;
        }

        p.loading = OMB.createAbsDiv("<img src='" + OMB.resolveUrl('omb/images/loading.gif') + "'/>");
        var w = OMB.getW(p.loading);
        var h = OMB.getH(p.loading);
        x = x - w / 2;
        y = y - h / 2;

        OMB.setX(p.loading, x);
        OMB.setY(p.loading, y);
        OMB.setZ(p.loading, 50000);
    }
}

OMB.onAjaxResponseReceived = function(s,e)
{
    var p = OMB.mapAjaxPanelToClientObject[s.UniqueID];
    if (p)
    {
        if (p.master)
        {
            document.body.setAttribute('background', p.back);
            if(p.footer)
                p.footer.style.display='';
        }    
        if (p.loading)
        {
            document.body.removeChild(p.loading);
            p.loading = null;
        }
    }
}

OMB.onAjaxResponseEnd = function(s,e)
{
    var p = OMB.mapAjaxPanelToClientObject[s.UniqueID];
    if (p)
    {
        var estart  = OMB.elem(p.start);
        var escript = OMB.elem(p.script);
        OMB.elem('js').text = escript.value + estart.value;
        escript.value = '';
        estart.value = '';
    }
}

//
// AJAX POP UP
//

OMB.popUps = [];
OMB.popUpResponseCache = {}; 
OMB.mapAjaxPopUpToClientObject = {};

OMB.AjaxPopUp = function(ajax,post,response,wait,content,cache,script,start)
{
    this.ajax = ajax;
    this.post = post;
    this.response = response;
    this.wait = wait;
    this.content = content;
    this.cache = cache;
    this.script = script;
    this.start = start;

    this.ascx = -1;     // int    - popup control UID
    this.args = null;   // string - popup control arguments (separated by '|')
    this.request = 0;
    this.useCache = false;
        
    this.mouseX = 0;
    this.mouseY = 0;
    this.mouseIn = false;
    this.target = null;
    this.transparency = 100;
}

OMB.AjaxPopUp.prototype.hasResponse = function()
{
    var e = OMB.elem(this.response);
    if (e)
    {
        var v = e.value.split('$')[0];
        if (this.request == parseInt(v))
            return true;
    }
    
    return false;
}

OMB.AjaxPopUp.prototype.setTransparency = function(t)
{
    var s = '';
    var co = OMB.elem(this.content)
    var ca = OMB.elem(this.cache)
    var wa = OMB.elem(this.wait)
    if (t < 100)
        s = 'alpha(opacity=' + t + ')';
        
    co.style.filter = s;
    ca.style.filter = s;
    wa.style.filter = s;
    p.transparency = t;      
}

OMB.AjaxPopUp.prototype.display = function(d,x,y)
{
    if (x && y)
    {
        this.mouseX = x;
        this.mouseY = y;
    }

    var co = OMB.elem(this.content);
    var ca = OMB.elem(this.cache);
    var wa = OMB.elem(this.wait);
    
    if (d)
    {
        var e;
        if (this.useCache)
        {
            OMB.display(co, false);
            OMB.display(ca, true);
            OMB.display(wa, false);
            e = ca;        
        }
        else if (this.hasResponse())
        {
            OMB.display(co, true);
            OMB.display(ca, false);
            OMB.display(wa, false);
            e = co;
        }
        else        
        {
            OMB.display(co, false);
            OMB.display(ca, false);
            OMB.display(wa, true);
            e = wa;
        }
        
        OMB.setX(e, this.mouseX);
        OMB.setY(e, this.mouseY - OMB.getH(e));
        return e;
    }
    else
    {
        OMB.display(co, false);
        OMB.display(ca, false);
        OMB.display(wa, false);
    }
}

OMB.onAjaxPopUpRequestStart = function(s,e)
{ 
}

OMB.onAjaxPopUpResponseReceived = function(s,e)
{
}

OMB.onAjaxPopUpResponseEnd = function(s,e)
{
    // NOTE: Timeout is needed to get correct width and height
    // of element when displaying.
    //
    setTimeout('OMB.popUpResponse(\''+ s.UniqueID +'\')', 10);    
}

OMB.popUpResponse = function(suid)
{
    var p = OMB.mapAjaxPopUpToClientObject[suid];
    if (p)
    {
        // Content was returned so display it if mouse is still 
        // in target and if not using cache.
        //        
        if (p.mouseIn && !p.useCache) 
            p.display(true);
            
        // Cache this response...
        //
        var r = OMB.elem(p.response).value;
        var h = OMB.elem(p.content).innerHTML;
        var a = r.split('$')[1].split('?');
        
        var ascx = a[0];
        var args = a[1];
        
        var cache = OMB.popUpResponseCache[ascx]; 
        if (!cache)
        {
            cache = {};
            OMB.popUpResponseCache[ascx] = cache;
        }
        
        cache[args] = h;
    }
}

OMB.popUp = function(s,e,i,ascx,args)
{
    var p = OMB.popUps[i];
    if (p)
    {     
        args = args ? args : null;
        if (p.ascx != ascx || p.args != args) // IF NOT SAME ARGS AS LAST
        {
            p.ascx = ascx;
            p.args = args;
        
            // Check if already have cached version of this response...
            //
            var cache = OMB.popUpGetCache(ascx,args);
            if (cache)
            {
                p.useCache = true;
                OMB.elem(p.cache).innerHTML = cache;
            }
            else
            {
                p.useCache = false;
            
                // Server call is made with delay using timeout...
                // This prevents user from creating too many server calls by constantly changing target elements.
                // I.e.) user must stay in target element for 0.500 seconds for server call to be made.
                //
                p.request++;
                setTimeout('OMB.popUpRequest('+ p.request +','+ i +')',500);
            }
        }     
    
        var x = e.clientX + OMB.scrollX();
        var y = e.clientY + OMB.scrollY();

        p.mouseIn = true;
        p.target = s;
        
        p.setTransparency(0);
        p.display(true,x,y);
        OMB.popUpFadeIn(i);
        
        OMB.sampleXY(true);
        setTimeout('OMB.popUpMouseSample('+ i +')',100);
    }
}

OMB.popUpMouseSample = function(i)
{
    var p = OMB.popUps[i];
    if (p)
    {
        var x = OMB.clientX + OMB.scrollX();
        var y = OMB.clientY + OMB.scrollY();
        
        var t = p.target;
        var e = p.display(true);
        var xt = OMB.getX(t);
        var yt = OMB.getY(t);
        var wt = OMB.getW(t);
        var ht = OMB.getH(t);
        var xe = OMB.getX(e);
        var ye = OMB.getY(e);
        var we = OMB.getW(e);
        var he = OMB.getH(e);        
        
        if ((x > xt && x < xt + wt && y > yt && y < yt + ht) || // inside target?
            (x > xe && x < xe + we && y > ye && y < ye + he))   // inside popup element?
        {
            setTimeout('OMB.popUpMouseSample('+ i +')',100);
        }
        else
        {
            p.mouseIn = false;
            OMB.popUpFadeOut(i);
            OMB.sampleXY(false);
        }
    }
}

OMB.popUpGetCache = function(ascx,args)
{
    var cache = OMB.popUpResponseCache[ascx.toString()]; 
    if (cache)
        return cache[args];
        
    return null;
}

OMB.popUpRequest = function(request,i)
{
    var p = OMB.popUps[i];
    if (p)
    {
        if (request == p.request)
            eval(p.ajax + ';').AjaxRequestWithTarget(p.post, p.request + '$' + p.ascx + '?' + p.args);
    }
}

OMB.popUpFadeOut = function(i)
{
    var p = OMB.popUps[i];
    if (p)
    {
        if (!p.mouseIn)
        {            
            if (p.transparency > 0)
            {
                p.setTransparency(p.transparency - 10);
                setTimeout('OMB.popUpFadeOut('+ i +')',20);
            }
            else
                p.display(false);
        }
    }
}

OMB.popUpFadeIn = function(i)
{
    var p = OMB.popUps[i];
    if (p)
    {
        if (p.mouseIn && p.transparency < 100)
        {
            p.setTransparency(p.transparency + 10);
            setTimeout('OMB.popUpFadeIn('+ i +')',20);
        }
    }
}

//
// JS DATA UTILS
//

OMB.objectKeysToHiddenList = function(o,h)
{
    var c = OMB.elem(h);
    c.value='';
    
    var sep=false;
    for (k in o)
    {
        if (sep) c.value+='&';
        c.value += k;
        sep=true;
    }
}

OMB.objectValuesToHiddenList = function(o,h)
{
    var c = OMB.elem(h);
    c.value='';
    
    var sep=false;
    for (k in o)
    {
        if (sep) c.value+='&';
        c.value += o[k];
        sep=true;
    }
}

OMB.objectToHiddenMap = function(o,h)
{
    var c = OMB.elem(h);
    c.value='';
    
    var sep=false;
    for (k in o)
    {
        if (sep) c.value+='&';
        c.value += k + '=' + o[k];
        sep=true;
    }
}

//
// LIST CONTROL UTILS
//

OMB.getSelectedValue = function(lc)
{
    if (lc.selectedIndex > -1)
        return lc.options[lc.selectedIndex].value;
        
    return '';        
}

OMB.insertOption = function(lc,opt,index)
{
    if (index < 0) return;
    
    var opts = lc.options;
    var last = opts.length;
    if (index > last) 
        index = last;
                
    opts.length = last + 1;
    for (var i=opts.length-1; i > index; i--)
    {
        var copy = opts[i-1];
        opts[i] = new Option(copy.text,copy.value);
    }
        
    opts[index] = opt;        
}

OMB.addOption = function(lc,opt,sort)
{
    var opts = lc.options;
    if (sort)
    {
        for (var i=0; i < opts.length; i++)
        {
            if (opts[i].text > opt.text)
                break;
        }
        
        OMB.insertOption(lc,opt,i);
    }
    else
    {
        var last = opts.length;
        opts.length = last + 1;
        opts[last] = opt;
    }
}

OMB.addOptions = function(lc,opts,sort)
{
    for (var i=0; i < opts.length; i++)
        OMB.addOption(lc,opts[i],sort);
}

OMB.removeOptions = function(lc)
{
    lc.options.length = 0;
}

OMB.removeSelectedOptions = function(lc)
{
    var opts = lc.options;
    for (var i=opts.length-1; i >= 0; i--)
    {
        var opt = opts[i];
        if (opt.selected) opts[i] = null;
    }
}

OMB.copyOptions = function(lc)
{
    var j = 0;
    var opts = [];
    
    for (var i=0; i < lc.options.length; i++)
    {
        var opt = lc.options[i];
        opts[j++] = new Option(opt.text,opt.value);
    }
    
    return opts;
}

OMB.copySelectedOptions = function(lc)
{
    var j = 0;
    var opts = [];
    
    for (var i=0; i < lc.options.length; i++)
    {
        var opt = lc.options[i];
        if (opt.selected) opts[j++] = new Option(opt.text,opt.value);
    }
    
    return opts;
}

OMB.moveOptions = function(src,dest)
{
    OMB.addOptions(dest,OMB.copyOptions(src));
    OMB.removeOptions(src);
}

OMB.moveSelectedOptions = function(src,dest)
{
    OMB.addOptions(dest,OMB.copySelectedOptions(src));
    OMB.removeSelectedOptions(src);
}

//
// LIST BOX EX UTILS
//

OMB.synchListBoxChanges = function(lc,txt,val,sel)
{
    txt.value = '';
    val.value = '';
    sel.value = '';

    for (var i=0; i < lc.options.length; i++)
    {
        if (i > 0)
        {
            txt.value += '|';
            val.value += '|';
            sel.value += '|';
        }
    
        var opt = lc.options[i];
        txt.value += opt.text;
        val.value += opt.value;
        sel.value += opt.selected ? '1' : '0';
    }
}

OMB.insertOptionEx = function(lc,opt,index,txt,val,sel)
{
    OMB.insertOption(lc,opt,index);
    OMB.synchListBoxChanges(lc,txt,val,sel);
}

OMB.addOptionEx = function(lc,opt,sort,txt,val,sel)
{
    OMB.addOption(lc,opt,sort);
    OMB.synchListBoxChanges(lc,txt,val,sel);
}

OMB.addOptionsEx = function(lc,opts,sort,txt,val,sel)
{
    OMB.addOptions(lc,opts,sort);
    OMB.synchListBoxChanges(lc,txt,val,sel);
}

OMB.removeOptionsEx = function(lc,txt,val,sel)
{
    OMB.removeOptions(lc);
    OMB.synchListBoxChanges(lc,txt,val,sel);
}

OMB.removeSelectedOptionsEx = function(lc,txt,val,sel)
{
    OMB.removeSelectedOptions(lc);
    OMB.synchListBoxChanges(lc,txt,val,sel);
}

OMB.moveOptionsEx = function(src,dest,stxt,sval,ssel,dtxt,dval,dsel)
{
    var opts = OMB.copyOptions(src);
    OMB.display(src,false);    
    OMB.removeOptionsEx(src,stxt,sval,ssel);
    
    OMB.addOptionsEx(dest,opts,true,dtxt,dval,dsel)
    
    if (dest.options.length > 0)
    {
        dest.size = dest.options.length;
        OMB.display(dest,true);
    }
}

OMB.moveSelectedOptionsEx = function(src,dest,stxt,sval,ssel,dtxt,dval,dsel)
{
    var opts = OMB.copySelectedOptions(src);
    OMB.removeSelectedOptionsEx(src,stxt,sval,ssel);

    if (src.options.length > 0)
        src.size = src.options.length;
    else
        OMB.display(src,false);
    
    OMB.addOptionsEx(dest,opts,true,dtxt,dval,dsel)
    
    if (dest.options.length > 0)
    {
        dest.size = dest.options.length;
        OMB.display(dest,true);
    }
}

//
// DATA GRID FUNCTIONS
//

OMB.gridState = {};
OMB.gridBeforeAddRow = function(id)
{
    delete OMB.gridState[id];

    var g = window[id];    
    if (!g || !g.MasterTableView)
        return;
        
    var tbl = g.MasterTableView.Control;
    var state = {};
    
    for (var i = 1; i < tbl.rows.length; i++)
    {
        var tr = tbl.rows[i];
        for (var j = 0; j < tr.cells.length; j++)
        {
            var div = tr.cells[j].childNodes[0];
            for (var k = 0; k < div.childNodes.length; k++)
            {
                var e = div.childNodes[k];
                var key = i.toString() + '|' + j.toString() + '|' + k.toString();
                
                if (e.tagName == 'INPUT')
                {
                    if (e.type == 'text')
                        state[key] = e.value;
                    else if (e.type == 'checkbox')
                        state[key] = e.checked;
                }
                else if (e.tagName == 'SELECT')
                    state[key] = e.selectedIndex;
            }
        }
    }

    OMB.gridState[id] = state;
}

OMB.gridAfterAddRow = function(id)
{
    var g = window[id];    
    if (!g || !g.MasterTableView)
        return;
        
    var tbl = g.MasterTableView.Control;

    var state = OMB.gridState[id];
    if (!state)
        return;
        
    for (var key in state)
    {
        var value = state[key];
        var a = key.split('|');
        var i = parseInt(a[0]);
        var j = parseInt(a[1]);
        var k = parseInt(a[2]);
        var e = tbl.rows[i].cells[j].childNodes[0].childNodes[k];
        
        if (e.tagName == 'INPUT')
        {
            if (e.type == 'text')
                e.value = value;
            else if (e.type == 'checkbox')
                e.checked = value;
        }
        else if (e.tagName == 'SELECT')
            e.selectedIndex = value;        
    }
}

//
// GRID DDL CELL EVENTS
//

OMB.mapDdlToCurrentCell = {};
OMB.DdlCell = function(s,e,t,d,b,c,v,p)
{
    this.td  = s;
    this.tbl = t;
    this.ddl = d;
    this.btn = b;
    this.clr = c;
    this.val = v;
    this.pnl = p;
}

OMB.onDdlCellFocusIn = function(s,e,t,d,b,c,v,p)
{
    OMB.mapDdlToCurrentCell[d] = new OMB.DdlCell(s,e,t,d,b,c,v,p);
    setTimeout('OMB.showGridCellDdl(\''+ d +'\')', 150);   
}

OMB.onGridDdlChange = function(d)
{
    var cel = OMB.mapDdlToCurrentCell[d];
    if (cel)
    {
        var ddl = OMB.elem(cel.ddl);
        var val = OMB.elem(cel.val);
        var pnl = OMB.elem(cel.pnl);

        var text = '';
        val.value = '';
                        
        var sep = false;
        for (var i=0; i < ddl.options.length; i++)
        {
            var opt = ddl.options[i]
            if (opt.selected)
            {
                if (sep)
                {
                    text += ', ';
                    val.value += ',';
                }
               
                text += opt.text;
                val.value += opt.value;
                sep = true;
            }
        }
        
        pnl.innerHTML = '<nobr>' + text + '</nobr>';
        OMB.hideGridCellDdl(d);
    }
}
    
OMB.onGridDdlClear = function(d)
{
    var cel = OMB.mapDdlToCurrentCell[d];
    if (cel)
    {
        var ddl = OMB.elem(cel.ddl);
        var val = OMB.elem(cel.val);
        var pnl = OMB.elem(cel.pnl);

        for (var i=0; i < ddl.options.length; i++)
            ddl.options[i].selected = false;
        
        val.value = '';
        pnl.innerHTML = '';
        OMB.hideGridCellDdl(d);
    }
}
    
OMB.onGridDdlFocusOut = function(s,e)
{
    var cel = OMB.mapDdlToCurrentCell[s.id];
    if (cel)
    {
        if (e.toElement != cel.td && e.toElement != OMB.elem(cel.btn) && e.toElement != OMB.elem(cel.clr))
            OMB.hideGridCellDdl(s.id);
    }
}    
    
OMB.showGridCellDdl = function(d)
{    
    var cel = OMB.mapDdlToCurrentCell[d];
    if (cel)
    {
        var td  = cel.td;
        var tbl = OMB.elem(cel.tbl);
        var ddl = OMB.elem(cel.ddl);
        var val = OMB.elem(cel.val);
        var pnl = OMB.elem(cel.pnl);
        
        var v = val.value.split(',');
        for (var i=0; i < ddl.options.length; i++)
        {
            var opt = ddl.options[i]
            opt.selected = false;
            
            for (var j=0; j < v.length; j++)
            {
                if (v[j] == opt.value)
                {
                    opt.selected = true;
                    break;
                }
            }
        }        
        
        OMB.setX(tbl, OMB.getX(td) + 5);
        OMB.setY(tbl, OMB.getY(td) + 5);
        ddl.size = ddl.options.length;
        if (ddl.size > 12)
            ddl.size = 12;
            
        OMB.visible(pnl, false);
        OMB.display(tbl, true);
        ddl.focus();
    }
}    
    
OMB.hideGridCellDdl = function(d)
{       
    var cel = OMB.mapDdlToCurrentCell[d];
    if (cel)
    {
        var tbl = OMB.elem(cel.tbl);
        var pnl = OMB.elem(cel.pnl);    
    
        OMB.display(tbl, false);
        OMB.visible(pnl, true);        
        delete OMB.mapDdlToCurrentCell[d];
    }
}

//
// GRID TBX CELL EVENTS
//

OMB.mapTbxToCell = {};
OMB.TbxCell = function(s,e,t,p)
{
    this.td  = s;
    this.tbx = t;
    this.pnl = p;
}

OMB.onTbxCellFocusIn = function(s,e,t,p)
{
    OMB.mapTbxToCell[t] = new OMB.TbxCell(s,e,t,p);
    setTimeout('OMB.showGridCellTbx(\''+ t +'\')', 50);   
}

OMB.onGridTbxChange = function(s,e)
{
    var cel = OMB.mapTbxToCell[s.id];
    if (cel)
    {
        OMB.elem(cel.pnl).innerHTML = '<nobr>' + s.value + '</nobr>';
        OMB.hideGridCellTbx(s.id);
    }
}

OMB.onGridTbxFocusOut = function(s,e)
{
    var cel = OMB.mapTbxToCell[s.id];
    if (cel)
    {
        if (e.toElement != cel.td)
            OMB.hideGridCellTbx(s.id);
    }
}

OMB.showGridCellTbx = function(t)
{    
    var cel = OMB.mapTbxToCell[t];
    if (cel)
    {
        var tbx = OMB.elem(cel.tbx);
        var pnl = OMB.elem(cel.pnl);
        
        OMB.display(pnl, false);
        OMB.setCSS(cel.td, 'TbxCellPad');
        OMB.display(tbx, true);
        tbx.focus();
        tbx.select();
    }
}

OMB.hideGridCellTbx = function(t)
{ 
    var cel = OMB.mapTbxToCell[t];
    if (cel)
    {
        var tbx = OMB.elem(cel.tbx);
        var pnl = OMB.elem(cel.pnl);
        
        OMB.display(tbx, false);
        OMB.setCSS(cel.td, '');
        OMB.display(pnl, true);      
        delete OMB.mapTbxToCell[t];
    }
}
