var Globals__loaded = false;

function AddNamespace(ns)
    {
    var nsParts = ns.split(".");
    var root = window;

    for (var i = 0; i < nsParts.length; i++)
        {
        if (typeof(root[nsParts[i]]) == "undefined")
            {
            root[nsParts[i]] = new Object();
            }
        root = root[nsParts[i]];
        }
    };
AddNamespace("DSS.Web");

DSS.Web.Debug = function(f9)
    {
    if (f9)
        {
        debugger;
        }
    };
    
DSS.Web.StopEventBubble = function(e)
    {
    if (!e)
        {
        var e = window.event;
        }
    e.cancelBubble = true;
    if (e.stopPropogation)
        {
        e.stopPropogation();
        }
    };
    
DSS.Web.FindElement = function(id, quiet)
    {
    var elt = document.getElementById(id);
    if (elt == null)
        {
        if (quiet != null && !quiet)
            {
            alert("No Element found [ID = " + id + "]");
            }
        }
    return elt;
    };
    
DSS.Web.FormatDate = function(val, format)
    {
    if (typeof(val) == "undefined" || val == null)
        {
        return null;
        }
        
    var ret = "";
    for (i = 0; i < format.length; i++)
        {
        var c = format.charAt(i);
        switch (c)
            {
            case "M":
                ret += (val.getMonth() + 1);
                break;
            case "Y":
                ret += val.getFullYear();
                break;
            case "D":
                ret += val.getDate();
                break;
            default:
                ret += c
                break;
            }
        }
    return ret;
    };
    
DSS.Web.FreeMem = function(node)
    {
    if (typeof(node) == "undefined" || node == null)
        {
        return;
        }
    for (var i = 0; i < node.childNodes; i++)
        {
        FreeMem(node.childNodes[i]);
        }
    if (node.parentNode)
        {
        node.parentNode.removeChild(node);
        }
    node = null;
    node = undefined;
    };
    
DSS.Web.GetStyleValue = function(elt, property)
    {
    if (elt.style[property] != "")
        {
        DSS.Web.Trace("Get style from style property " + property + ": " + elt.style[property]);
        return elt.style[property];
        }
    else if (elt.currentStyle)
        {
        DSS.Web.Trace("Get computed style IE " + property + ": " + elt.currentStyle[property]);
        return elt.currentStyle[property];
        }
    else if (document.defaultView.getComputedStyle)
        {
        var converted = "";
        for (var i = 0, len = property.length; i < len; ++i)
            {
            if (property.charAt(i) == property.charAt(i).toUpperCase())
                {
                converted = converted + "-" + property.charAt(i).toLowerCase();
                }
            else
                {
                converted = converted + property.charAt(i);
                }
            }
            
        var compStyle = document.defaultView.getComputedStyle(elt, null);
        DSS.Web.Trace("Get computed style W3C " + converted + ": " + compStyle.getPropertyValue(converted));
        return compStyle.getPropertyValue(converted);
        }
    return "";
    };
    
DSS.Web.CenterElement = function(elt)
    {
    var width = 0;
    var height = 0;
    if (new DSS.Web.Toolkit().GetBrowser() == "IE")
        {
        width = document.body.offsetWidth;
        height = document.body.offsetHeight;
        }
    else
        {
        width = window.innerWidth;
        height = window.innerHeight;
        }
        
    var origWidth = 0;
    var origHeight = 0;
    if (isNaN(parseInt(elt.style.width)))
        {
        if (isNaN(parseInt(DSS.Web.GetStyleValue(elt, "width", "width"))))
            {
            DSS.Web.Trace("Cannot calculate width - Element not centered");
            return;
            }
        else
            {
            origWidth = parseInt(DSS.Web.GetStyleValue(elt, "width", "width"));
            }
        }
    else
        {
        origWidth = parseInt(elt.style.width);
        }
        
    if (isNaN(parseInt(elt.style.height)))
        {
        if (isNaN(parseInt(DSS.Web.GetStyleValue(elt, "height", "height"))))
            {
            DSS.Web.Trace("Cannot calculate height - Element not centered");
            return;
            }
        else
            {
            origHeight = parseInt(DSS.Web.GetStyleValue(elt, "height", "height"));
            }
        }
    else
        {
        origHeight = parseInt(elt.stlye.height);
        }
        
    DSS.Web.Trace("Window: [width = " + width + ", height = " + height + "]");
    DSS.Web.Trace("Element: [width = " + origWidth + ", height = " + origHeight + "]");
    
    var newLeft = 0;
    var newTop = 0;
    if (width > origWidth)
        {
        newLeft = Math.floor((width - origWidth) / 2);
        }
    if (height > origHeight)
        {
        newTop = Math.floor((height - origHeight) / 5);
        }
        
    elt.style.left = newLeft + "px";
    elt.style.top = newTop + "px";
    };
    
if (Array.prototype.push == null)   
    {
    Array.prototype.push = function()
        {
        for (var i = 0; i < arguments.length; i++)
            {
            this[this.length] = arguments[i];
            }
        return this.length;
        };
    }
    
var EventCache = function()
    {
    var listEvents = [];
    
    return {
        listEvents: listEvents,
        add: function(node, eventName, handler, capture)
            {
            listEvents.push(arguments);
            },
        remove: function(node, eventName, handler, capture)
            {
            if (capture == null)
                {
                arguments[3] = false;
                }
                
            for (var i = 0; i < listEvents.length; i++)
                {
                found = true;
                for (var j = 0; j < listEvents[i].length; j++)
                    {
                    if (listEvents[i][j] != arguments[j])
                        {
                        found = false;
                        break;
                        }
                    }
                if (found)
                    {
                    listEvents.splice(i, 1);
                    }
                }
            },
        flush: function()
            {
            var i, items;
            for (i = listEvents.length - 1; i >= 0; i = i - 1)
                {
                try
                    {
                    item = listEvents[i];
                    
                    if (item[0].removeEventListener)
                        {
                        item[0].removeEventListener(item[1], item[2], item[3]);
                        }
                        
                    if (item[1].substring(0, 2) != "on")
                        {
                        item[1] = "on" + item[1];
                        }
                        
                    if (item[0].detachEvent)
                        {
                        item[0].detachEvent(item[1], item[2]);
                        }
                        
                    item[0][item[1]] = null;
                    }
                catch (e) { }
                }
            }
        };
    }();
    
DSS.Web.MemoryCleanUp = function()
    {
    EventCache.flush();
    };
window.onunload = DSS.Web.MemoryCleanUp;
    
DSS.Web.Trace = function(message)
    {
    if (typeof(DSS.Web.Diagnostics) == "object")
        {
        if (typeof(DSS.Web.Diagnostics.Tracer) == "object" && DSS.Web.Diagnostics.Tracer)
            {
            DSS.Web.Diagnostics.Tracer.Trace(message);
            }
        }
    };
    
Globals__loaded = true;