/***************************************************************
 * Licensed Materials - Property of IBM
 * IBM Tivoli Usage and Accounting Manager
 * 5724-O33, 5765-UAV, 5765-UA7, 44E7863
 * © Copyright IBM Corp. 2005, 2007
 *
 * The source code for this program is not published or otherwise
 * divested of its trade secrets, irrespective of what has been
 * deposited with the U.S. Copyright Office.
 ****************************************************************
 */
 
var _inPrototype=false;

/////////////////////////
// _mExtend
////////////////////////
function _mExtend(fConstr,fSuperConstr,sName)
{
	_inPrototype=true;
	var p=fConstr.prototype=new fSuperConstr;
	if(sName){p._className=sName;}
	p.constructor=fConstr;
	_inPrototype=false;
	return p;
};

Object.isEmpty = function (o)
{
    for (var _ in o)return false; return true; };

Object.getKeys = function (o)
{
    var r = [];
    for (var i in o)
    {
        r.push(i);
    }
    return r};

Object.getValues = function (o)
{
    var r = [];
    for (var i in o)
    {
        r.push(o[i]);
    }
    return r;
};

if (!Array.prototype.indexOf)
{
    Array.prototype.indexOf = function (obj, fromIndex)
    {
        if (fromIndex == null)
        {
            fromIndex = 0;
        }
        else if (fromIndex < 0)
        {
            fromIndex = Math.max(0, this.length + fromIndex);
        }
        for (var i = fromIndex; i < this.length; i++)
        {
            if (this[i] === obj)return i;
        }
        return - 1;
    };
}
if (!Array.prototype.lastIndexOf)
{
    Array.prototype.lastIndexOf = function (obj, fromIndex)
    {
        if (fromIndex == null)
        {
            fromIndex = this.length - 1;
        }
        else if (fromIndex < 0)
        {
            fromIndex = Math.max(0, this.length + fromIndex);
        }
        for (var i = fromIndex; i >= 0; i--)
        {
            if (this[i] === obj)return i;
        }
        return - 1;
    };
}
Array.prototype.contains = function (o)
{
    return this.indexOf(o) !=  - 1;
};

Array.prototype.copy = function (o)
{
    return this.concat();
};

Array.prototype.insertAt = function (o, i)
{
    this.splice(i, 0, o);
};

Array.prototype.insertBefore = function (o, o2)
{
    var i = this.indexOf(o2);
    if (i ==  - 1)this.push(o);
    else this.splice(i, 0, o);
};

Array.prototype.removeAt = function (i)
{
    this.splice(i, 1);
};

Array.prototype.remove = function (o)
{
    var i = this.indexOf(o);
    if (i !=  - 1)this.splice(i, 1);
};

if (!Array.prototype.forEach)
{
    Array.prototype.forEach = function (f, obj)
    {
        var l = this.length;
        for (var i = 0; i < l; i++)
        {
            f.call(obj, this[i], i, this);
        }
    };
}
if (!Array.prototype.filter)
{
    Array.prototype.filter = function (f, obj)
    {
        var l = this.length;
        var res = [];
        for (var i = 0; i < l; i++)
        {
            if (f.call(obj, this[i], i, this))
            {
                res.push(this[i]);
            }
        }
        return res;
    };
}
if (!Array.prototype.map)
{
    Array.prototype.map = function (f, obj)
    {
        var l = this.length;
        var res = [];
        for (var i = 0; i < l; i++)
        {
            res.push(f.call(obj, this[i], i, this));
        }
        return res;
    };
}
if (!Array.prototype.some)
{
    Array.prototype.some = function (f, obj)
    {
        var l = this.length;
        for (var i = 0; i < l; i++)
        {
            if (f.call(obj, this[i], i, this))
            {
                return true;
            }
        }
        return false;
    };
}
if (!Array.prototype.every)
{
    Array.prototype.every = function (f, obj)
    {
        var l = this.length;
        for (var i = 0; i < l; i++)
        {
            if (!f.call(obj, this[i], i, this))
            {
                return false;
            }
        }
        return true;
    };
}
String.prototype.trim = function ()
{
    return this.replace(/(^\s+)|\s+$/g, "");
};

String.prototype.capitalize = function ()
{
    return this.charAt(0).toUpperCase() + this.substr(1);
};
String.prototype.startsWith = function (s)
{
    return this.substring(0, s.length) == s;
};
String.prototype.endsWith = function (s)
{
    return this.substring(this.length - s.length, this.length) == s;
};
String.EMPTY = "";
String.BOOLEAN_TRUE = "true";
String.BOOLEAN_FALSE = "false";
Function.READ = 1;
Function.WRITE = 2;
Function.READ_WRITE = 3;
Function.EMPTY = function (){};
Function.prototype.addProperty = function (sName, nReadWrite)
{
    var p = this.prototype;
    nReadWrite = nReadWrite || Function.READ_WRITE;
    var capitalized = sName.capitalize();
    sName = "_" + sName;
    if (nReadWrite & Function.READ)
    {
        p["get" + capitalized] = function ()
        {
            return this[sName];
        };
    }
    if (nReadWrite & Function.WRITE)
    {
        p["set" + capitalized] = function (v)
        {
            this[sName] = v;
        };
    }
};


//////////////////
// CimsObject
//////////////////
function CimsObject()
{
}
_p = _mExtend(CimsObject, Object, "CimsObject");
_p._disposed = false;
_p._id = null;
CimsObject.TYPE_FUNCTION = "function";
CimsObject.TYPE_OBJECT = "object";
CimsObject.TYPE_STRING = "string";
CimsObject._hashCodeCounter = 1;
CimsObject.toHashCode = function (o)
{
    //if (o._hashCode != null)return o._hashCode;
    //return o._hashCode = CimsObject._hashCodePrefix + Math.round(Math.random() * 1000) + CimsObject._hashCodePrefix + CimsObject._hashCodeCounter++;
    if (o.hasOwnProperty("_hashCode")) return o._hashCode;
    return o._hashCode = "_" + (CimsObject._hashCodeCounter++).toString(32);    
};

CimsObject.prototype.getDisposed = function ()
{
    return this._disposed;
};

CimsObject.prototype.getId = function ()
{
    return this._id;
};

CimsObject.prototype.setId = function (v)
{
    this._id = v;
};

CimsObject.prototype.getUserData = function ()
{
    return this._userData;
};

CimsObject.prototype.setUserData = function (v)
{
    this._userData = v;
};

_p.toHashCode = function ()
{
    return CimsObject.toHashCode(this);
};

_p.dispose = function ()
{
    this._disposed = true;
    delete this._userData;
    delete this._id;
    this.dispose = Function.EMPTY;    
};
_p.disposeFields = function (fieldNames)
{    
    var fields = fieldNames instanceof Array ? fieldNames : arguments;    
    var n, o, p;    
    for (var i = 0; i < fields.length; i++)    
    {        
        n = fields[i];        
        if (this.hasOwnProperty(n))        
        {            
            o = this[n];
            if (o != null)
            {
                if (typeof o.dispose == CimsObject.TYPE_FUNCTION)
                {
                    o.dispose();
                }
                else if (o instanceof Array)
                {
                    for (var j = 0; j < o.length; j++)
                    {
                        p = o[j];
                        if (p && typeof p.dispose == CimsObject.TYPE_FUNCTION)
                        {
                            p.dispose();
                        }
                    }
                }
            }
            delete this[n];
        }
    }
};
_p.toString = function ()
{
    if (this._className)return "[object " + this._className + "]";
    return "[object Object]";
};

_p.getProperty = function (sPropertyName)
{
    var getterName = "get" + sPropertyName.capitalize();
    if (typeof this[getterName] == "function")return this[getterName]();
    throw new Error("No such property, " + sPropertyName);
};

_p.setProperty = function (sPropertyName, oValue)
{
    var setterName = "set" + sPropertyName.capitalize();
    if (typeof this[setterName] == "function")this[setterName](oValue);
    else throw new Error("No such property, " + sPropertyName);
};

_p.setProperties = function (oProperties)
{
    for (var p in oProperties)
    {
        this.setProperty(p, oProperties[p]);
    }
};

_p.setAttribute = function (sName, sValue, oParser)
{
    var v, vv;
    if (sValue == "true")v = true;
    else if (sValue == "false")v = false;
    else if ((vv = parseFloat(sValue)) == sValue)v = vv;
    else v = sValue;
    this.setProperty(sName, v);
};

_p.getAttribute = function (sName)
{
    return String(this.getProperty(sName));
};

_p.addXmlNode = function (oNode, oParser)
{
    if (oNode.nodeType == 1)oParser.fromNode(oNode);
};

if (typeof CimsObject == "undefined")
	CimsObject = new Function();

//////////////////
// CimsBrowserCheck
//////////////////
function CimsBrowserCheck()
{
    if (_inPrototype)return;
    if (CimsBrowserCheck._singleton)return CimsBrowserCheck._singleton;
    var ua = navigator.userAgent;
    this._ie = /msie/i.test(ua);
    this._moz = navigator.product == "Gecko";
    this._platform = navigator.platform;
    if (this._moz)
    {
        /rv\:([^\);]+)(\)|;)/.test(ua);
        this._version = RegExp.$1;
        this._ie55 = false;
        this._ie6 = false;
        this._hta = false;
    }
    else 
    {
        /MSIE\s+([^\);]+)(\)|;)/.test(ua);
        this._version = RegExp.$1;
        this._ie55 = /msie 5\.5/i.test(ua);
        this._ie6 = /msie 6/i.test(ua);
        this._hta =!window.external;
    }
    CimsBrowserCheck._singleton = this;
}
_p = _mExtend(CimsBrowserCheck, CimsObject, "CimsBrowserCheck");
_p.getIe = function ()
{
    return this._ie;
};

_p.getIe55 = function ()
{
    return this._ie55;
};

_p.getIe6 = function ()
{
    return this._ie6;
};

_p.getMoz = function ()
{
    return this._moz;
};

_p.getVersion = function ()
{
    return this._version;
};

_p.getPlatform = function ()
{
    return this._platform;
};

_p.getHta = function ()
{
    return this._hta;
};

(function ()
{
    var bc = new CimsBrowserCheck;
    CimsBrowserCheck.ie = bc.getIe();
    CimsBrowserCheck.ie55 = bc.getIe55();
    CimsBrowserCheck.ie6 = bc.getIe6();
    CimsBrowserCheck.moz = bc.getMoz();
    CimsBrowserCheck.version = bc.getVersion();
    CimsBrowserCheck.versionNumber = parseFloat(bc.getVersion());
    CimsBrowserCheck.platform = bc.getPlatform();
    CimsBrowserCheck.hta = bc.getHta();
    bc = null;
}
)();

if (CimsBrowserCheck.moz)
{
	HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var df = r.createContextualFragment(sHTML);
		this.parentNode.replaceChild(df, this);

		return sHTML;
	});    

	HTMLElement.prototype.__defineGetter__("outerHTML", function () {
		var attr, attrs = this.attributes;
		var str = "<" + this.tagName;
		for (var i = 0; i < attrs.length; i++) {
			attr = attrs[i];
			if (attr.specified)
				str += " " + attr.name + '="' + attr.value + '"';
		}
		if (!this.canHaveChildren)
			return str + ">";

		return str + ">" + this.innerHTML + "</" + this.tagName + ">";
	});
	
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        switch (this.tagName) {
            case "AREA":
            case "BASE":
            case "BASEFONT":
            case "COL":
            case "FRAME":
            case "HR":
            case "IMG":
            case "BR":
            case "INPUT":
            case "ISINDEX":
            case "LINK":
            case "META":
            case "PARAM":
                return false;
        }
        return true;
    });	
}

//////////////////
// CimsUri
//////////////////
function CimsUri(sBase, sRel)
{
    if (_inPrototype) return;
    this._params = {};
    if (sBase)
    {
        this.setHref(sBase);
        if (sRel)
			this._setRelative(sRel);
	}
}
_p = _mExtend(CimsUri, CimsObject, "CimsUri");
_p._scheme = "";
_p._userInfo = "";
_p._port = "";
_p._host = "";
_p._path = "";
_p._dirPath = "";
_p._fragment = "";
_p._query = "";
_p._hrefCache = null;
_p._generic = true;
CimsUri.prototype.getScheme = function ()
{
    return this._scheme;
};

CimsUri.prototype.getPath = function ()
{
    return this._path;
};

CimsUri.prototype.getDirPath = function ()
{
    return this._dirPath;
};

CimsUri.prototype.getHost = function ()
{
    return this._host;
};

CimsUri.prototype.getPort = function ()
{
    return this._port;
};

CimsUri.prototype.getFragment = function ()
{
    return this._fragment;
};

CimsUri.prototype.getUserInfo = function ()
{
    return this._userInfo;
};

CimsUri.regExps = {
	scheme   :/^([^:]+)\:.+$/, 
	user     :/^([^@\/]+)@.+$/, 
	host     :/^([^:\/\?\#]+).*$/, 
	port     :/^:(\d+)/, 
	path     :/^([^\?#]*)/, 
	dirPath  :/^(.*\/)[^\/]*$/, 
	fragment :/^[^#]*#(.*)$/, 
	absUri   :/^\w(\w|\d|\+|\-|\.)*:/i
};

_p.toString = function ()
{
    return this.getHref();
};

_p.setHref = function (s)
{
    this._hrefCache = null;
    s = String(s);
    this._scheme = "";
    this._userInfo = "";
    this._host = "";
    this._port = null;
    this._path = "";
    this._dirPath = "";
    this._query = "";
    this._fragment = "";
    this._params = {};
    var err = new Error("Not a well formatted URI");
    var ok = CimsUri.regExps.scheme.test(s);
    if (!ok)throw err;
    this._scheme = RegExp.$1;
    this._generic = s.substr(this._scheme.length, 3) == "://";
    if (this._generic)s = s.substring(this._scheme.length + 3);
    else s = s.substring(this._scheme.length + 1);
    if (this._generic || this._scheme == "mailto" || this._scheme == "news")
    {
        ok = CimsUri.regExps.user.test(s);
        if (ok)
        {
            this._userInfo = RegExp.$1;
            s = s.substring(this._userInfo.length + 1);
        }
        if (this._scheme != "file" || s.charAt(0) != "/")
        {
            ok = CimsUri.regExps.host.test(s);
            if (!ok)throw err;
            this._host = RegExp.$1;
            s = s.substring(this._host.length);
        }
        ok = CimsUri.regExps.port.test(s);
        if (ok)
        {
            this._port = Number(RegExp.$1);
            s = s.substring(RegExp.$1.length + 1);
        }
    }
    this._parsePathAndRest(s);
};

_p._parsePathAndRest = function (s)
{
    var err = new Error("Not a well formatted URI");
    var i;
    var ok = CimsUri.regExps.path.test(s);
    if (!ok)throw err;
    this._path = RegExp.$1;
    s = s.substring(this._path.length);
    if (this._path == "" && (this._scheme == "file" || this._scheme == "http" || this._scheme == "https" || this._scheme == "ftp"))
    {
        this._path = "/";
    }
    var segments = this._path.split("/");
    var sb = [];
    var j = 0;
    for (i = 0; i < segments.length; i++)
    {
        if (segments[i] == ".")continue;
        if (segments[i] == "..")
        {
            j--;
            delete sb[j];
            sb.length = j;
            continue;
        }
        sb[j++] = segments[i];
    }
    this._path = sb.join("/");
    if (this._path.length > 0)
    {
        ok = CimsUri.regExps.dirPath.test(this._path);
        if (!ok)throw err;
        this._dirPath = RegExp.$1;
    }
    ok = CimsUri.regExps.fragment.test(s);
    if (ok)
    {
        this._fragment = RegExp.$1;
        s = s.substring(0, s.length - this._fragment.length - 1);
        this._fragment = "#" + this._fragment.replace("#", "%23");
    }
    this._query = s;
    s = s.substring(1);
    if (this._query != "")
    {
        var pairs = s.split(/\;|\&/);
        var parts, name, value;
        for (i = 0; i < pairs.length; i++)
        {
            parts = pairs[i].split("=");
            try { name = decodeURIComponent(parts[0]); }
            catch (e) { name = parts[0]; }
            if (parts.length == 2)
            {
                try { value = decodeURIComponent(parts[1]); }
                catch (e) { value = parts[1]; }            
            }
            else
            {
                value = null;
            }
            if (name in this._params)
                this._params[name].push(value);
            else 
                this._params[name] = [value];
        }
    }
};

_p._setRelative = function (s)
{
    this._hrefCache = null;
    s = String(s);
    var isAbsolute = CimsUri.regExps.absUri.test(s);
    if (isAbsolute)
    {
        this.setHref(s);
        return;
    }
    var dirPath = this._dirPath;
    this._path = "";
    this._dirPath = "";
    this._query = "";
    this._fragment = "";
    this._params = {};
    if (s.charAt(0) == "/")
        this._parsePathAndRest(s)
    else 
        this._parsePathAndRest(dirPath + s);
};

_p.getHref = function ()
{
    if (this._hrefCache != null)return this._hrefCache;
    var s = this._scheme + (this._generic ? "://" : ":") + this._userInfo + (this._userInfo == "" ? "" : "@") + this._host + (this._port != null ? ":" + this._port : "") + this._path;
    return this._hrefCache = s + this.getQuery() + this._fragment;
};

_p.getParam = function (sName)
{
    if (sName in this._params)return this._params[sName][this._params[sName].length - 1];
    return undefined;
};

_p.setParam = function (sName, sValue)
{
    this._hrefCache = null;
    return this._params[sName] = [String(sValue)];
};

_p.removeParam = function (sName)
{
    this._hrefCache = null;
    delete this._params[sName];
};

_p.hasParam = function (sName)
{
    return sName in this._params;
};

_p.getParams = function (sName)
{
    if (sName in this._params)return this._params[sName].concat();
    return[];
};

_p.addParam = function (sName, sValue)
{
    this._hrefCache = null;
    var v = sValue == null ? null : String(sValue);
    if (sName in this._params)this._params[sName].push(v);
    else this._params[sName] = [v];
};

_p.getQuery = function ()
{
    var sb = [];
    var sb2, sb3, v;
    for (var name in this._params)
    {
        sb2 = [];
        for (var i = 0; i < this._params[name].length; i++)
        {
            sb3 = [];
            v = this._params[name][i];
            if (v == null)
                sb2.push(encodeURIComponent(name));
            else 
            {
                sb3.push(encodeURIComponent(name), "=", encodeURIComponent(v));
                sb2.push(sb3.join(""));
            }
        }
        sb.push(sb2.join("&"));
    }
    return sb.length > 0 ? "?" + sb.join("&") : "";
};

//////////////////
// CimsEvent
//////////////////
function CimsEvent(sType)
{
    if (_inPrototype)return;
    CimsObject.call(this);
    this._type = sType;
}
_p = _mExtend(CimsEvent, CimsObject, "CimsEvent");
_p._bubbles = false;
_p._propagationStopped = true;
_p._defaultPrevented = false;
CimsEvent.prototype.getType = function ()
{
    return this._type;
};

CimsEvent.prototype.getTarget = function ()
{
    return this._target;
};

CimsEvent.prototype.getCurrentTarget = function ()
{
    return this._currentTarget;
};

CimsEvent.prototype.getBubbles = function ()
{
    return this._bubbles;
};

_p.stopPropagation = function ()
{
    this._propagationStopped = true;
};

CimsEvent.prototype.getPropagationStopped = function ()
{
    return this._propagationStopped;
};

_p.preventDefault = function ()
{
    this._defaultPrevented = true;
};

CimsEvent.prototype.getDefaultPrevented = function ()
{
    return this._defaultPrevented;
};

_p.dispose = function ()
{
    CimsObject.prototype.dispose.call(this);
    delete this._target;
    delete this._currentTarget;
    delete this._bubbles;
    delete this._propagationStopped;
    delete this._defaultPrevented;    
};

_p.getDefaultPrevented = function ()
{
    return this._defaultPrevented;
};


//////////////////
// CimsMouseEvent
//////////////////
function CimsMouseEvent(){};

//////////////////
// CimsKeyboardEvent
//////////////////
function CimsKeyboardEvent(){};

//////////////////
// CimsEventTarget
//////////////////
function CimsEventTarget()
{
    if (_inPrototype)return;
    CimsObject.call(this);
    this._listeners = {};
    this._listenersCount = 0;
}
_p = _mExtend(CimsEventTarget, CimsObject, "CimsEventTarget");
_p.addEventListener = function (sType, fHandler, oObject)
{
    if (typeof fHandler != "function")
        throw new Error(this + " addEventListener: " + fHandler + " is not a function");
    if (oObject && typeof oObject != CimsObject.TYPE_OBJECT)
        throw new Error(this + " addEventListener: " + oObject + " is not an object");
    var ls = this._listeners[sType];
    if (!ls)
        ls = this._listeners[sType] = {};
    var key = CimsObject.toHashCode(fHandler) + (oObject ? CimsObject.toHashCode(oObject) : String.EMPTY);
    if (!(key in ls))
    {
        this._listenersCount++;
    }
    ls[key] = {handler : fHandler, object : oObject || this};
};

_p.removeEventListener = function (sType, fHandler, oObject)
{
    if (this._disposed ||!(sType in this._listeners))return;
    var key = CimsObject.toHashCode(fHandler) + (oObject ? CimsObject.toHashCode(oObject) : String.EMPTY);
    if (key in this._listeners[sType])
    {
        --this._listenersCount;
    }
    delete this._listeners[sType][key];
    if (Object.isEmpty(this._listeners[sType]))
    {
        delete this._listeners[sType];
    }
};

_p.dispatchEvent = function (oEvent)
{
    if (this._disposed)return;
    oEvent._target = this;
    this._dispatchEvent(oEvent);
    return!oEvent._defaultPrevented;
};

_p._dispatchEvent = function (oEvent)
{
    oEvent._currentTarget = this;
    if (!(oEvent instanceof CimsMouseEvent) &&!(oEvent instanceof CimsKeyboardEvent) || this.getIsEnabled())
    {
        var fs = this._listeners[oEvent.getType()];
        if (fs)
        {
            var f, o;
            for (var hc in fs)
            {
                f = fs[hc].handler;
                if (typeof f == "function")
                {
                    o = fs[hc].object;
                    if (typeof o == "object")
                    {
                        f.call(o, oEvent);
                    }
                    else 
                    {
                        f.call(this, oEvent);
                    }
                }
            }
        }
    }
    if (oEvent._bubbles &&!oEvent._propagationStopped && this._parent &&!this._parent._disposed)
    {
        this._parent._dispatchEvent(oEvent);
    }
};

_p.setAttribute=function(sName,sValue,oParser)
{
	if(sName.substring(0,2)=="on")
	{
		var type=sName.substring(2);
		this.addEventListener(type,new Function("event",sValue),oParser);
	}
	else 
		CimsObject.prototype.setAttribute.call(this,sName,sValue,oParser);
};
_p.dispose=function()
{
	if(this._disposed)return;
	CimsObject.prototype.dispose.call(this);
    for (var t in this._listeners)
        delete this._listeners[t];
    delete this._listeners; 
    delete this._listenersCount; 
};

//////////////////
// XmlHttp
//////////////////
function CimsXmlHttp()
{
    if (_inPrototype)return;
    if (window.XMLHttpRequest)return new XMLHttpRequest();
    else if (window.ActiveXObject)return new ActiveXObject(CimsXmlHttp._activeXName);
    throw new Error("Your browser does not support XML HTTP Requests");
}
CimsXmlHttp.prototype = new Object;
CimsXmlHttp.create = function ()
{
    return new CimsXmlHttp();
};

//////////////////
// CimsXmlDocument
//////////////////
function CimsXmlDocument()
{
    if (_inPrototype)return;
    if (document.implementation && document.implementation.createDocument)
    {
        var doc = document.implementation.createDocument("", "", null);
        doc.addEventListener("load", function (e) { this.readyState = 4; }, false);
        doc.readyState = 4;
        return doc;
    }
    else if (window.ActiveXObject)
        return new ActiveXObject(CimsXmlDocument._activeXName);
    throw new Error("Your browser does not support creating DOM documents at runtime");
}
CimsXmlDocument.prototype = new Object();
CimsXmlDocument.create = function ()
{
    return new CimsXmlDocument();
};

CimsXmlDocument._biGetActiveXName = CimsXmlHttp._biGetActiveXName = function (sType)
{
    var servers = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
    var o;
    for (var i = 0; i < servers.length; i++)
    {
        try
        {
            o = new ActiveXObject(servers[i] + "." + sType);
            return servers[i] + "." + sType;
        }
        catch (ex){};
    }
    throw new Error("Could not find an installed XML parser");
};

if (window.ActiveXObject)
{
    CimsXmlDocument._activeXName = CimsXmlDocument._biGetActiveXName("DomDocument");
    CimsXmlHttp._activeXName = CimsXmlHttp._biGetActiveXName("XmlHttp");
}

if (typeof ActiveXObject == "undefined" && typeof XMLHttpRequest != "undefined")
{
    (function ()
    {
        var _xmlDocPrototype = XMLDocument.prototype;
        _xmlDocPrototype.__proto__ = {__proto__ : _xmlDocPrototype.__proto__};
        
        var _p = _xmlDocPrototype.__proto__;
        _p.createNode = function (aType, aName, aNamespace)
        {
            switch (aType)
            {
                case 1:
                    if (aNamespace && aNamespace != "")return this.createElementNS(aNamespace, aName);
                    else return this.createElement(aName);
                case 2:
                    if (aNamespace && aNamespace != "")return this.createAttributeNS(aNamespace, aName);
                    else return this.createAttribute(aName);
                case 3:
                    default : return this.createTextNode("");
            }
        };
        
        _p.__realLoad = _xmlDocPrototype.load;
        _p.load = function (sUri)
        {
            this.readyState = 0;
            this.__realLoad(sUri);
        };
        
        _p.loadXML = function (s)
        {
            var doc2 = (new DOMParser).parseFromString(s, "text/xml");
            while (this.hasChildNodes())this.removeChild(this.lastChild);
            var cs = doc2.childNodes;
            var l = cs.length;
            for (var i = 0; i < l; i++)this.appendChild(this.importNode(cs[i], true)); 
        };
        
        _p.setProperty = function (sName, sValue)
        {
            if (sName == "SelectionNamespaces")
            {
                this._selectionNamespaces = {};
                var parts = sValue.split(/\s+/);
                var re = /^xmlns\:([^=]+)\=((\"([^\"]*)\")|(\'([^\']*)\'))$/;
                for (var i = 0; i < parts.length; i++)
                {
                    re.test(parts[i]);
                    this._selectionNamespaces[RegExp.$1] = RegExp.$4 || RegExp.$6;
                }
            }
        };
        
        _p.__defineSetter__("onreadystatechange", function (f)
        {
            if (this._onreadystatechange)this.removeEventListener("load", this._onreadystatechange, false);
            this._onreadystatechange = f;
            if (f)this.addEventListener("load", f, false);
            return f;
        });
        
        _p.__defineGetter__("onreadystatechange", function ()
        {
            return this._onreadystatechange;
        });
        
        CimsXmlDocument._mozHasParseError = function (oDoc)
        {
            return!oDoc.documentElement || oDoc.documentElement.localName == "parsererror" && oDoc.documentElement.getAttribute("xmlns") == "http://www.mozilla.org/newlayout/xml/parsererror.xml";
        };
        
        _p.__defineGetter__("parseError", function ()
        {
            var hasError = CimsXmlDocument._mozHasParseError(this);
            var res = 
            {
                errorCode : 0, filepos : 0, line : 0, linepos : 0, reason : "", srcText : "", url : ""}
            ;
            if (hasError)
            {
                res.errorCode =  - 1;
                try
                {
                    res.srcText = this.getElementsByTagName("sourcetext")[0].firstChild.data;
                    res.srcText = res.srcText.replace(/\n\-\^$/, "");
                }
                catch (ex)
                {
                    res.srcText = "";
                }
                try
                {
                    var s = this.documentElement.firstChild.data;
                    var re = /XML Parsing Error\:(.+)\nLocation\:(.+)\nLine Number(\d+)\,Column(\d+)/;
                    var a = re.exec(s);
                    res.reason = a[1];
                    res.url = a[2];
                    res.line = a[3];
                    res.linepos = a[4];
                }
                catch (ex)
                {
                    res.reason = "Unknown";
                }
            }
            return res;
        });
        
        var _nodePrototype = Node.prototype;
        _nodePrototype.__proto__ = {__proto__ : _nodePrototype.__proto__};
        _p = _nodePrototype.__proto__;
        _p.__defineGetter__("xml", function ()
        {
            return (new XMLSerializer).serializeToString(this);
        });
        
        _p.__defineGetter__("baseName", function ()
        {
            var lParts = this.nodeName.split(":");
            return lParts[lParts.length - 1];
        });
        
        _p.__defineGetter__("text", function ()
        {
            var cs = this.childNodes;
            var l = cs.length;
            var sb = new Array(l);
            for (var i = 0; i < l; i++)
				sb[i] = cs[i].text; return sb.join(""); }
        );
        
        _p.selectNodes = function (sExpr)
        {
            var doc = this.nodeType == 9 ? this : this.ownerDocument;
            var nsRes = doc.createNSResolver(this.nodeType == 9 ? this.documentElement : this);
            var nsRes2;
            if (doc._selectionNamespaces)
            {
                nsRes2 = function (s)
                {
                    if (s in doc._selectionNamespaces)return doc._selectionNamespaces[s];
                    return nsRes.lookupNamespaceURI(s);
                };
            }
            else nsRes2 = nsRes;
            var xpRes = doc.evaluate(sExpr, this, nsRes2, 5, null);
            var res = [];
            var item;
            while ((item = xpRes.iterateNext()))
				res.push(item);
            return res;
        };
        
        _p.selectSingleNode = function (sExpr)
        {
            var doc = this.nodeType == 9 ? this : this.ownerDocument;
            var nsRes = doc.createNSResolver(this.nodeType == 9 ? this.documentElement : this);
            var nsRes2;
            if (doc._selectionNamespaces)
            {
                nsRes2 = function (s)
                {
                    if (s in doc._selectionNamespaces)return doc._selectionNamespaces[s];
                    return nsRes.lookupNamespaceURI(s);
                };
            }
            else nsRes2 = nsRes;
            var xpRes = doc.evaluate(sExpr, this, nsRes2, 9, null);
            return xpRes.singleNodeValue;
        };
        
        _p.transformNode = function (oXsltNode)
        {
            var doc = this.nodeType == 9 ? this : this.ownerDocument;
            var processor = new XSLTProcessor();
            processor.importStylesheet(oXsltNode);
            var df = processor.transformToFragment(this, doc);
            return df.xml;
        };
        
        _p.transformNodeToObject = function (oXsltNode, oOutputDocument)
        {
            var doc = this.nodeType == 9 ? this : this.ownerDocument;
            var outDoc = oOutputDocument.nodeType == 9 ? oOutputDocument : oOutputDocument.ownerDocument;
            var processor = new XSLTProcessor();
            processor.importStylesheet(oXsltNode);
            var df = processor.transformToFragment(this, doc);
            while (oOutputDocument.hasChildNodes())oOutputDocument.removeChild(oOutputDocument.lastChild);
            var cs = df.childNodes;
            var l = cs.length;
            for (var i = 0; i < l; i++)
				oOutputDocument.appendChild(outDoc.importNode(cs[i], true)); 
        };
        
        var _attrPrototype = Attr.prototype;
        _attrPrototype.__proto__ = {__proto__ : _attrPrototype.__proto__};
        _p = _attrPrototype.__proto__;
        _p.__defineGetter__("xml", function ()
        {
            var nv = (new XMLSerializer).serializeToString(this);
            return this.nodeName + "=\"" + nv.replace(/\"/g, "&quot;") + "\"";
        });
        
        var _textPrototype = Text.prototype;
        _textPrototype.__proto__ = {__proto__ : _textPrototype.__proto__};
        _p = _textPrototype.__proto__;
        _p.__defineGetter__("text", function ()
        {
            return this.nodeValue;
        });
    }
    )();
}


//////////////////
// CimsLauncher
//////////////////
function CimsLauncher(sRootPath)
{
    if (_inPrototype)return;
    if (sRootPath)this.setRootPath(sRootPath);
    this._arguments = [];
}
_p = _mExtend(CimsLauncher, Object, "CimsLauncher");
_p._reuseWindow = true;
_p._newWindow = true;
_p._errorMessage = "";
_p._accessibilityMode = false;
_p._focusOnLoad = true;
CimsLauncher.MISSING_ADF_ARGUMENT = "Missing ADF argument";
CimsLauncher.ADF_ARGUMENT_PARSE_ERROR = "The ADF argument cannot be parsed";
CimsLauncher.IE_ERROR_PLATFORM = "Internet Explorer for Windows is required";
CimsLauncher.IE_ERROR_VERSION = "Internet Explorer 5.5 or later is required";
CimsLauncher.GECKO_ERROR_VERSION = "Mozilla (Gecko) 1.4 or later is required";
CimsLauncher.NOT_SUPPORTED_ERROR = "Internet Explorer 5.5+ or Mozilla 1.4+ required";
CimsLauncher.FILE_NOT_FOUND = "File not found";
CimsLauncher.POPUP_BLOCKER_QUESTION = "Failed to open window. Are you using a popup blocker?";
_p.getReuseWindow = function ()
{
    return this._reuseWindow;
};

_p.setReuseWindow = function (b)
{
    this._reuseWindow = b;
};

_p.getNewWindow = function ()
{
    return this._newWindow;
};

_p.setNewWindow = function (b)
{
    this._newWindow = b;
};

_p.getWindow = function ()
{
    return this._window || null;
};

_p.getRootPath = function ()
{
    return this._rootPath;
};

_p.setRootPath = function (s)
{
    s = String(s);
    if (s.charAt(s.length - 1) != "/")s += "/";
    this._rootPath = s;
};

_p.getAdfPath = function ()
{
    return this._adfPath;
};

_p.setAdfPath = function (s)
{
    if (s == null || s == "")
    {
        this._errorMessage = CimsLauncher.MISSING_ADF_ARGUMENT;
        return;
    }
    s = String(s);
    var re = /([^\/]+\/)?(\w+)(\.[^\/]*)?$/;
    if (re.test(s))
    {
        this._adfName = RegExp.$2;
        this._adfPath = s;
    }
    else 
    {
        this._errorMessage = CimsLauncher.ADF_ARGUMENT_PARSE_ERROR;
    }
};

_p.getAdfName = function ()
{
    return this._adfName;
};

_p.setAdfName = function (s)
{
    this._adfName = s;
};

_p.getArguments = function ()
{
    return this._arguments;
};

_p.setArguments = function (a)
{
    this._arguments = [];
    for (var i = 0; i < a.length; i++)
        this._arguments.push(String(a[i])); 
};

_p.getTarget = function ()
{
    return this._target;
};

_p.setTarget = function (s)
{
    this._target = s;
};

_p.getFocusOnLoad = function ()
{
    return this._focusOnLoad;
};

_p.setFocusOnLoad = function (b)
{
    this._focusOnLoad = b;
};

_p.getSupported = function ()
{
    var br = new CimsBrowserCheck;
    var p, v;
    if (br.getIe())
    {
        p = String(br.getPlatform()).toLowerCase();
        if (p != "win32" && p != "win64")
        {
            this._errorMessage = CimsLauncher.IE_ERROR_PLATFORM;
            return false;
        }
        v = br.getVersion();
        if (v < "5.5")
        {
            this._errorMessage = CimsLauncher.IE_ERROR_VERSION;
            return false;
        }
        return true;
    }
    else if (br.getMoz())
    {
        v = br.getVersion();
        if (v < "1.4")
        {
            this._errorMessage = CimsLauncher.GECKO_ERROR_VERSION;
            return false;
        }
        return true;
    }
    this._errorMessage = CimsLauncher.NOT_SUPPORTED_ERROR;
    return false;
};

_p.getErrorMessage = function ()
{
    return this._errorMessage;
};

_p.getHasError = function ()
{
    return this._errorMessage != "";
};

CimsLauncher.prototype.launch = function (sAdfPath, oArgs)
{
    var left, right, top, bottom, width, height, centered, resizable, fullScreen;
    var adfPath, adfName, args;
    if (!this.getSupported())return false;
    if (sAdfPath)this.setAdfPath(sAdfPath);
    if (this.getHasError())return false;
    var bUseCurrentWindow =!this.getNewWindow();
    var sRootPath = this.getRootPath();
    var sAdfRelPath = this.getAdfPath();
    if (arguments.length > 1)
    {
        args = [];
        for (var i = 1; i < arguments.length; i++)
			args.push(arguments[i]); 
	    this.setArguments(args); 
    }
    adfName = this.getAdfName();
    args = this.getArguments();
    if (/(^http\:)|(^https\:)|(^file\:)|(^\/)/.test(sAdfRelPath))
    {
        adfPath = sAdfRelPath;
    }
    else 
    {
        var curPath = document.location.href;
        var slashIndex = curPath.lastIndexOf("/");
        curPath = curPath.substring(0, slashIndex);
        adfPath = curPath + "/" + sAdfRelPath;
    }
    var uri = sRootPath + "main.html?Adf=" + encodeURIComponent(adfPath) + ";AdfName=" + adfName + ";Params=" + args.length;
    for (i = 0; i < args.length; i++)
    {
        uri += ";Param" + i + "=" + encodeURIComponent(args[i]);
    }
    var xmlHttp = new CimsXmlHttp;
    xmlHttp.open("GET", adfPath, false);
    try
    {
        xmlHttp.send(null);
    }
    catch (ex)
    {
        this._errorMessage = CimsLauncher.FILE_NOT_FOUND;
        return false;
    }
    var fs = /^file\:/.test(adfPath);
    if (fs)
    {
        var s = String(xmlHttp.responseText).replace(/<\?xml[^\?]*\?>/, "");
        xmlHttp.responseXML.loadXML(s);
    }
    else if (xmlHttp.status != 200)
    {
        this._errorMessage = xmlHttp.status + ": " + xmlHttp.statusText;
        return false;
    }
    if (xmlHttp.responseXML.parseError.errorCode != 0)
    {
        this._errorMessage = xmlHttp.responseXML.parseError.reason;
        return false;
    }
    var doc = xmlHttp.responseXML;
    var n = doc.selectSingleNode("/application/window | /Application/Window");
    left = CimsLauncher._getAttr(n, "left", "", "x");
    right = CimsLauncher._getAttr(n, "right", "", "x");
    top = CimsLauncher._getAttr(n, "top", "", "y");
    bottom = CimsLauncher._getAttr(n, "bottom", "", "y");
    width = CimsLauncher._getAttr(n, "width", "", "x");
    height = CimsLauncher._getAttr(n, "height", "", "y");
    centered = CimsLauncher._getAttr(n, "centered", "false") == "true";
    resizable = CimsLauncher._getAttr(n, "resizable", "true") != "false";
    fullScreen = CimsLauncher._getAttr(n, "fullScreen", "false") == "true";
    var sw = screen.width;
    var sh = screen.height;
    if (right != "" && width != "")left = sw - width - right;
    else if (left != "" && right != "")width = sw - left - right;
    if (bottom != "" && height != "")top = sh - height - bottom;
    else if (top != "" && bottom != "")height = sh - top - bottom;
    if (left == "" && right == "" && centered)left = (sw - width)/2;
    if(top==""&&bottom==""&&centered)top=(sh-height)/2;
    n = doc.selectSingleNode("/application/@focusOnLoad | /Application/@focusOnLoad");
    if (n)this._focusOnLoad = n.text != "false";
    if (!bUseCurrentWindow)
    {
        var windowName = this.getReuseWindow() ? this._target || adfName : "";        
        var w = window.open(CimsBrowserCheck.moz ? sRootPath + "blank.html" : uri, windowName, "menubar=0,location=0,status=0,toolbar=0,scrollbars=1" + (left ? ",left=" + left : "") + (top ? ",top=" + top : "") + (width ? ",width=" + (width - 8) : "") + (height ? ",height=" + (height - 32) : "") + (fullScreen ? ",fullscreen=1" : "") + (resizable ? ",resizable=1" : ""), false);               
        if (!w)
        {
            this._errorMessage = CimsLauncher.POPUP_BLOCKER_QUESTION;
            return false;
        }
        if (this._focusOnLoad)w.focus();
        this._window = w;
        if (CimsBrowserCheck.moz)
            setTimeout(function () { w.document.location.href = uri; });        
    }
    else 
    {
        document.location.href = uri;
        if (this._focusOnLoad)window.focus();
        this._window = window;
    }
    return true;
};

CimsLauncher._toPixel = function (s, sAxis)
{
    if (String(s).indexOf("%") !=  - 1)
    {
        var n = Number(s.replace(/\%/g, ""));
        return n / 100 * (sAxis == "x" ? screen.availWidth : screen.availHeight);
    }
    return s;
};

CimsLauncher._getAttr = function (el, name, def, tp)
{
    var res;
    if (!el ||!el.getAttribute(name))res = def;
    else res = el.getAttribute(name);
    if (tp)return CimsLauncher._toPixel(res, tp);
    return res;
};



//////////////////
// CimsExec
//////////////////
function CimsExec(sRootPath, sAdfRelPath, bUseCurrentWindow)
{
    var args = [sAdfRelPath];
    for (var i = 3; i < arguments.length; i++)
		args.push(arguments[i]); 
	var l = new CimsLauncher(sRootPath); 
	l.setAdfPath(sAdfRelPath); 
	l.setNewWindow(!bUseCurrentWindow); 
	var ok = l.launch.apply(l, args); 
	if (!ok)
		alert(l.getErrorMessage());
	return ok; 
};


//////////////////
// CimsTextLoader
//////////////////
function CimsTextLoader()
{
    if (_inPrototype)return;
    CimsEventTarget.call(this);
    this._xmlHttp = new CimsXmlHttp();
    var oThis = this;
    this.__onreadystatechange = function () { oThis._onreadystatechange(); };
}
_p = _mExtend(CimsTextLoader, CimsEventTarget, "CimsTextLoader");
_p._method = "GET";
_p._async = false;
_p._uri = null;
_p._user = "";
_p._password = "";
_p._loadCount = 0;
CimsTextLoader.load = function (oUri)
{
    var tl = new CimsTextLoader;
    tl.load(oUri);
    var s = tl.getText();
    tl.dispose();
    return s;
};

CimsTextLoader.prototype.getMethod = function ()
{
    return this._method;
};

CimsTextLoader.prototype.setMethod = function (v)
{
    this._method = v;
};

CimsTextLoader.prototype.getUri = function ()
{
    return this._uri;
};

CimsTextLoader.prototype.getAsync = function ()
{
    return this._async;
};

CimsTextLoader.prototype.setAsync = function (v)
{
    this._async = v;
};

CimsTextLoader.prototype.getUser = function ()
{
    return this._user;
};

CimsTextLoader.prototype.setUser = function (v)
{
    this._user = v;
};

CimsTextLoader.prototype.getPassword = function ()
{
    return this._password;
};

CimsTextLoader.prototype.setPassword = function (v)
{
    this._password = v;
};

_p.setUri = function (oUri)
{
    if (oUri instanceof CimsUri)this._uri = oUri;
    else this._uri = new CimsUri(application.getAdfPath(), oUri);
};

_p.load = function (oUri)
{
    this.open("GET", oUri || this._uri, this._async);
    this.send();
};

_p.post = function (oUri, oXmlDocument)
{
    this.open("POST", oUri || this._uri, this._async);
    this.send(oXmlDocument);
};

_p.open = function (sMethod, oUri, bAsync, sUser, sPassword)
{
    this._method = sMethod;
    this.setUri(oUri);
    this._async = bAsync != null ? bAsync : true;
    this._user = sUser;
    this._password = sPassword;
    this._xmlHttp.abort();
    this._xmlHttp.onreadystatechange = this.__onreadystatechange;
    this._xmlHttp.open(this._method, String(this._uri), this._async, this._user, this._password);
};

_p.send = function (oObject)
{
    this._loadCount = 0;
    this._xmlHttp.setRequestHeader("Accept-Encoding", "gzip, deflate");
    this._xmlHttp.send(oObject);
    if (!this._async && CimsBrowserCheck.moz)         
        this._onload();    
};

_p.abort = function ()
{
    this._xmlHttp.abort();
};

_p.getLoaded = function ()
{
    return this._xmlHttp.readyState == 4;
};

_p.getLoading = function ()
{
    return this._xmlHttp.readyState > 0 && this._xmlHttp.readyState < 4;
};

_p.getText = function ()
{
    return String(this._xmlHttp.responseText);
};

_p.getXmlHttp = function ()
{
    return this._xmlHttp;
};

_p.getError = function ()
{   
    if (!this.getLoaded())return false;
    var s = this.getUri().getScheme();
    if (s == "http" || s == "https")
    {
        return this._xmlHttp.status != 200;
    }    
    return this._xmlHttp.status != 0;    
};

_p.dispose = function ()
{
    if (this._disposed)return;
    CimsEventTarget.prototype.dispose.call(this);
    try
    {
        delete this.__onreadystatechange;
        delete this._xmlHttp.onreadystatechange;
        delete this._xmlHttp;
    }
    catch (e) { }
    this.disposeFields("_uri");  
};

_p._onreadystatechange = function ()
{
    if (this._xmlHttp && this._xmlHttp.readyState == 4)
    {
        if (this._loadCount == 0)
        {
            this._loadCount++;
            this._onload();
            application.flushLayoutQueue();
        }
    }
};

_p._onload = function ()
{    
    this.dispatchEvent(new CimsEvent("load"));
};


//////////////////
// CimsXmlLoader
//////////////////
function CimsXmlLoader()
{
    if (_inPrototype)return;
    CimsTextLoader.call(this);
    this.addEventListener("load", CimsXmlLoader._onLoad);
}
_p = _mExtend(CimsXmlLoader, CimsTextLoader, "CimsXmlLoader");
_p._disposed = false;
CimsXmlLoader.load = function (oUri)
{
    var xl = new CimsXmlLoader();
    xl.load(oUri);
    var doc = xl.getDocument();
    xl.dispose();
    return doc;
};

_p.getDocument = function ()
{
    return this.getXmlHttp().responseXML;
};

_p.getError = function ()
{
    return CimsTextLoader.prototype.getError.call(this) || this.getDocument().parseError.errorCode != 0;
};

CimsXmlLoader._onLoad = function (e)
{
    var xl = e.getTarget();
    if (CimsBrowserCheck.ie && xl.getUri().getScheme() == "file" &&!xl.getError())
    {
        var s = xl.getText();
        s = s.replace(/<\?xml[^\?]*\?>/, "");
        var d = xl.getXmlHttp().responseXML;
        d.loadXML(s);
    }
};



//////////////////
// CimsScriptLoaderQueue
//////////////////
function CimsScriptLoaderQueue()
{
    if (_inPrototype)return;
    CimsEventTarget.call(this);
    this._items = [];
    this._uris = {};
};

_p = _mExtend(CimsScriptLoaderQueue, CimsEventTarget, "CimsScriptLoaderQueue");
_p._async = true;
CimsScriptLoaderQueue.prototype.getAsync = function ()
{
    return this._async;
};

CimsScriptLoaderQueue.prototype.setAsync = function (v)
{
    this._async = v;
};

_p._allExecuted = true;
_p.add = function (oUri)
{
    var sUri = String(oUri);
    if (sUri in this._uris)return;
    this._allExecuted = false;
    var tl = new CimsTextLoader();
    tl.setUri(oUri);
    tl.addEventListener("load", this._onProgress, this);
    this._uris[sUri] = true;
    this._items.push(
    {
        src : oUri, textLoader : tl}
    );
};

_p.addInline = function (sText)
{
    this._allExecuted = false;
    this._items.push(
    {
        text : sText}
    );
};

_p.load = function ()
{
    if (this._getAllLoaded())this._onAllLoaded();
    else 
    {
        for (var i = 0; i < this._items.length; i++)
        {
            if (this._items[i].textLoader)
            {
                this._items[i].textLoader.setAsync(this._async);
                this._items[i].textLoader.load();
            }
        }
        if (this._getAllLoaded())this._onAllLoaded();
    }
};

_p.abort = function ()
{
    for (var i = 0; i < this._items.length; i++)
    {
        if (this._items[i].textLoader)
            this._items[i].textLoader.abort();
    }
};

_p.getLoaded = function ()
{
    if (this._allExecuted)return true;
    return this._allExecuted && this._getAllLoaded()};

_p._getAllLoaded = function ()
{
    var items = this._items;
    var tl;
    for (var i = 0; i < items.length; i++)
    {
        tl = items[i].textLoader;
        if (tl &&!tl.getLoaded())return false;
    }
    return true;
};

_p.getLoadedCount = function ()
{
    if (this.getLoaded())return this.getScriptCount();
    var n = 0;
    var items = this._items;
    var tl;
    for (var i = 0; i < items.length; i++)
    {
        tl = items[i].textLoader;
        if (!tl || tl.getLoaded())n++}
    return n;
};

_p.getScriptCount = function ()
{
    return this._items.length;
};

_p._onProgress = function (e)
{
    if (e.getTarget().getError())
    {
        throw new Error("Error loading file \"" + e.getTarget().getUri() + "\"");
    }
    if (this._getAllLoaded())this._onAllLoaded();
    else this.dispatchEvent(new CimsEvent("progress"));
};

_p._onAllLoaded = function ()
{
    if (this._allExecuted || this._errorLoading)return;
    this.dispatchEvent(new CimsEvent("progress"));
    var items = this._items;
    for (var i = 0; i < items.length; i++)
    {
        if (items[i].textLoader)
        {
            try
            {
                this.execScript(items[i].textLoader.getText());
            }
            catch (ex)
            {
                this._errorLoading = true;
                ex.uri = items[i].textLoader.getUri();
                throw ex;
            }
        }
        else
        {
            try
            {
                this.execScript(items[i].text);
            }
            catch (ex)
            {
                this._errorLoading = true;
                ex.text = items[i].text;
                throw ex;
            }
        }
    }
    this._allExecuted = true;
    this.dispatchEvent(new CimsEvent("load"));
    this._uris = {};
};

_p.dispose = function ()
{
    if (this._disposed)return;
    CimsEventTarget.prototype.dispose.call(this);
    if (this._items)
    {
        for (var i = 0; i < this._items.length; i++)
        {
            if (this._items[i].textLoader)this._items[i].textLoader.dispose();
            this._items[i].textLoader = null;
            this._items[i].text = null;
            this._items[i].src = null;
            this._items[i] = null;
        }
        delete this._items;
    }
};

_p.execScript = function (s)
{
    if (!s || s.length == 0)return;
    if (window.execScript)
    {
        window.execScript(s);
    }
    else
    {
        window.eval(s);
    }
};




//////////////////
// CimsXmlResourceParser
//////////////////
function CimsXmlResourceParser()
{
    if (_inPrototype)return;
    CimsXmlLoader.call(this);
    this._componentsById = 
    {
    }
    ;
}
_p = _mExtend(CimsXmlResourceParser, CimsXmlLoader, "CimsXmlResourceParser");
_p._disposed = false;
_p._autoNameMapping = false;
CimsXmlResourceParser.prototype.getAutoNameMapping = function ()
{
    return this._autoNameMapping;
};

CimsXmlResourceParser.prototype.setAutoNameMapping = function (v)
{
    this._autoNameMapping = v;
};

_p._rootNode = null;
CimsXmlResourceParser.getClassFromUri = function (oUri)
{
    return CimsXmlResourceParser.getClassFromDocument(CimsXmlLoader.load(oUri));
};

CimsXmlResourceParser.getClassFromDocument = function (oDoc)
{
    return CimsXmlResourceParser.getClassFromNode(oDoc.documentElement);
};



CimsXmlResourceParser.getClassFromNode = function (oNode)
{
    if (oNode == null || oNode.nodeType != 1)return null;
    var tagName = oNode.localName || oNode.baseName;
    
    var constr = window["Cims" + tagName] || window[tagName];
    if (typeof constr == "function")
    {
        var p = new constr;
        var newConstr = function ()
        {
            if (_inPrototype)return;
            constr.apply(this, arguments);
            this._xmlResourceParser = new CimsXmlResourceParser;
            this._xmlResourceParser.setRootNode(oNode);
            this._xmlResourceParser.processAttributes(this, oNode);
            this._xmlResourceParser.processChildNodes(this, oNode);
            if (typeof p.initialize == "function")
                p.initialize.apply(this, arguments);
        };
        
        newConstr.prototype = p;
        p.dispose();
        p._disposed = false;
        p.dispose = function ()
        {
            if (this.getDisposed())return;
            constr.prototype.dispose.call(this);
            this._xmlResourceParser.dispose();
            delete this._xmlResourceParser;
        };
        
        p.getComponentById = function (sId)
        {
            return this._xmlResourceParser.getComponentById(sId);
        };
        
        p.getXmlResourceParser = function ()
        {
            return this._xmlResourceParser;
        };
        
        p.initialize = p.initialize || function ()
        {
        };
        
        application.addEventListener("dispose", function ()
        {
            newConstr = null;
            oNode = null;
        });
        
        return newConstr;
    }
    throw new Error("CimsXmlResourceParser getClassFromNode. Cannot create object from \"" + oNode.tagName + "\"");
};

CimsXmlResourceParser.prototype.setRootNode = function (v)
{
    this._rootNode = v;
};

_p.getRootNode = function ()
{
    if (this._rootNode)return this._rootNode;
    else 
    {
        if (this.getLoaded())return this.getDocument();
        return null;
    }
};

_p.fromNode = function (oNode)
{
    if (oNode == null || oNode.nodeType != 1)return null;
    var id = oNode.getAttribute("id");
    var c;
    if (id && (c = this._componentsById[id]))
    {
        if (c.getDisposed())
        {
            this._removeObject(c);
        }
        else 
        {
            return c;
        }
    }
    var tagName = oNode.localName || oNode.baseName;
    var o;
    var constr = window["Cims" + tagName] || window[tagName];
    if (typeof constr == "function")
    {
        o = new constr;
        this.processAttributes(o, oNode);
        this.processChildNodes(o, oNode);
        return o;
    }
    throw new Error("CimsXmlResourceParser fromNode. Cannot create object from \"" + oNode.tagName + "\"");
};

_p._removeObject = function (o)
{
    var id = o.getId();
    delete this._componentsById[id];
    if (this._autoNameMapping)
    {
        try
        {
            delete window[id];
        }
        catch (ex)
        {
            window[id] = null;
        }
    }
};

_p._addObject = function (o, id)
{
    this._componentsById[id] = o;
    if (this._autoNameMapping)
    {
        if (id in window && window[id] != o)throw new Error("Naming conflict. \"" + id + "\" is already in use or reserved.");
        window[id] = o;
    }
    var orgDispose = o.dispose;
    var oResParser = this;
    o.dispose = function ()
    {
        oResParser._removeObject(this);
        orgDispose.call(this);
        o.dispose = orgDispose;
        orgDispose = null;
        oResParser = null;
    }
    ;
};

_p.processAttributes = function (o, oNode)
{
    var attrs = oNode.attributes;
    var l = attrs.length;
    var name, value, parts, className, setterName, constr;
    for (var i = 0; i < l; i++)
    {
        name = attrs[i].nodeName;
        value = attrs[i].nodeValue;
        if (name == "xmlns" || name.substr(0, 4) == "xml:" || name.substr(0, 6) == "xmlns:")continue;
        if (name.indexOf(".") > 0)
        {
            parts = name.split(".");
            className = parts[0];
            setterName = "set" + parts[1].capitalize();
            constr = window["Cims" + className] || window[className];
            if (typeof constr == "function")
            {
                if (typeof constr[setterName] == "function")
                {
                    constr[setterName](o, value);
                }
                else throw new Error("No such attached property \"" + name + "\"");
            }
            else throw new Error("No such class: \"" + className + "\"");
        }
        else o.setAttribute(name, value, this);
        if (name == "id")this._addObject(o, value);
    }
};

_p.processChildNodes = function (obj, oNode)
{
    var tagName = oNode.localName || oNode.baseName;
    var re = new RegExp("^" + tagName + "\\.(.+)$");
    var cs = oNode.childNodes;
    var l = cs.length;
    var s;
    var emptyRe = /^\s*$/;
    for (var i = 0; i < l; i++)
    {
        if (re.test(cs[i].localName || cs[i].baseName))
        {
            var propertyName = RegExp.$1;
            var cs2 = cs[i].childNodes;
            var l2 = cs2.length;
            for (var j = 0; j < l2; j++)
            {
                if (cs2[j].nodeType == 3)
                {
                    s = cs2[j].data;
                    if (emptyRe.test(s))continue;
                    obj.setAttribute(propertyName, s, this);
                    break;
                }
                else if (cs2[j].nodeType == 1)
                {
                    obj.setProperty(propertyName, this.fromNode(cs2[j]));
                    break;
                }
            }
        }
        else obj.addXmlNode(cs[i], this);
    }
};

_p.getComponentById = function (sId)
{
    var o = this._componentsById[sId];
    if (o)
    {
        if (o.getDisposed())this._removeObject(o);
        else return o;
    }
    if (this.getLoaded())
    {
        var rn = this.getRootNode();
        var n = rn.selectSingleNode("//*[@id='" + sId + "']");
        if (!n)return null;
        o = this.fromNode(n);
        if (o)return o;
    }
    return null;
};

_p.getLoaded = function ()
{
    return this._rootNode != null || CimsXmlLoader.prototype.getLoaded.call(this);
};

_p.dispose = function ()
{
    if (this.getDisposed())return;
    CimsXmlLoader.prototype.dispose.call(this);
    for (var id in this._componentsById)
    {
        this._removeObject(this._componentsById[id]);
    }
    this._rootNode = null;
};




//////////////////
// CimsResourceLoader
//////////////////
function CimsResourceLoader()
{
    if (_inPrototype)return;
    CimsEventTarget.call(this);
    this._resources = [];
    this._resourcesById = [];
    this._duplicateScripts = {};
}
_p = _mExtend(CimsResourceLoader, CimsEventTarget, "CimsResourceLoader");
_p._lastLoaded =  - 1;
_p._lastStarted =  - 1;
_p._count = 0;
_p._loaded = false;
_p._autoNameMapping = false;
CimsResourceLoader.prototype.getAutoNameMapping = function ()
{
    return this._autoNameMapping;
};

_p.setAutoNameMapping = function (b)
{
    this._autoNameMapping = b;
    if (this._xmlResourceParser)
		this._xmlResourceParser.setAutoNameMapping(b);
};

_p.getResourceById = function (sId)
{
    if (sId in this._resourcesById)return this._resourcesById[sId].object;
    return null;
};

_p.addResource = function (sType, oData, sId)
{
    var lastRes = this._resources[this._resources.length - 1];
    if ((sType == "script" || sType == "inlinescript") &&!(lastRes instanceof CimsScriptLoaderQueue))
    {
        lastRes = new CimsScriptLoaderQueue;
        lastRes.addEventListener("load", this.load, this);
        lastRes.addEventListener("progress", this._onprogress, this);
        lastRes.addEventListener("error", this._onerror, this);
        this._resources.push(lastRes);
    }
    if (sType == "script")
    {
        if (!(oData in this._duplicateScripts))
        {
            lastRes.add(oData);
            this._duplicateScripts[oData] = true;
            this._count++;
        }
    }
    else if (sType == "inlinescript")
    {
        lastRes.addInline(oData);
        this._count++;
    }
    else 
    {
        var item = {name : sType, node : oData, id : sId};
        this._resources.push(item);
        if (sId)this._resourcesById[sId] = item;
        this._count++;
    }
};

_p._createGeneralObject = function (oItem)
{
    var node = oItem.node;
    if (!this._xmlResourceParser)
    {
        this._xmlResourceParser = new CimsXmlResourceParser;
        this._xmlResourceParser.setRootNode(node.parentNode);
        this._xmlResourceParser.setAutoNameMapping(this._autoNameMapping);
    }
    var o = this._xmlResourceParser.fromNode(node);
    oItem.object = o;
    oItem.node = null;
    if (o instanceof CimsEventTarget)
    {
        o.addEventListener("load", this.load, this);
        o.addEventListener("error", this._onerror, this);
    }
    if (typeof o.load == "function")
		o.load();
};

_p.load = function ()
{
    if (this._loaded)return;
    var allLoaded = true;
    if (this._lastStarted ==  - 1)
    {
        allLoaded = false;
        this._lastStarted = 0;
        this._startLoad(this._resources[0]);
    }
    else 
    {
        for (var i = this._lastStarted; i < this._resources.length; i++)
        {
            var obj = this._resources[i];
            if (this._isLoaded(obj))
            {
                this._lastLoaded = i;
                this._removeListeners(obj);
                this._onprogress();
                continue;
            }
            else 
            {
                if (i == this._lastStarted)
                {
                    allLoaded = false;
                    break;
                }
                this._lastStarted = i;
                this._startLoad(obj);
                if (!this._isLoaded(obj))
                {
                    allLoaded = false;
                    break;
                }
                else 
                {
                    this._lastLoaded = i;
                    this._removeListeners(obj);
                    this._onprogress();
                }
            }
        }
    }
    if (allLoaded)this._onAllLoaded();
};

_p._startLoad = function (obj)
{
    if (obj instanceof CimsScriptLoaderQueue)obj.load();
    else this._createGeneralObject(obj);
};

_p._isLoaded = function (obj)
{
    if (obj instanceof CimsScriptLoaderQueue)return obj.getLoaded();
    else if (obj.object == null)return false;
    else if (typeof obj.object.getLoaded == "function")return obj.object.getLoaded();
    else return true;
};

_p._removeListeners = function (obj)
{
    if (obj instanceof CimsScriptLoaderQueue)
    {
        obj.removeEventListener("load", this.load, this);
        obj.removeEventListener("progress", this._onprogress, this);
        obj.removeEventListener("error", this._onerror, this);
    }
    else if (obj.object != null && obj.object instanceof CimsEventTarget)
    {
        obj.object.removeEventListener("load", this.load, this);
        obj.object.removeEventListener("error", this._onerror, this);
    }
};

_p.abort = function ()
{
    var items = this._resources;
    var l = items.length;
    for (var i = 0; i < l; i++)
    {
        if (items[i]instanceof CimsScriptLoaderQueue)
			items[i].abort();
		else if (items[i].object && typeof items[i].object.abort == "function")
			items[i].object.abort();
    }
};

_p.getLoaded = function ()
{
    return this._lastLoaded == this._resources.length - 1;
};

_p.getLoadedCount = function ()
{
    var n = 0;
    var items = this._resources;
    var l = items.length;
    for (var i = 0; i < l; i++)
    {
        if (items[i]instanceof CimsScriptLoaderQueue)
			n += items[i].getLoadedCount();
        else if (this._isLoaded(items[i]))
			n++;
    }
    return n;
};

CimsResourceLoader.prototype.getCount = function ()
{
    return this._count;
};

_p.dispose = function ()
{
    if (this._disposed)return;
    CimsEventTarget.prototype.dispose.call(this);
    var item;
    for (var i = this._resources.length - 1; i >= 0; i--)
    {
        item = this._resources[i];
        if (item instanceof CimsScriptLoaderQueue)
			item.dispose();
        else if (item.object && typeof item.object.dispose == "function")
			item.object.dispose();
        item.object = null;
        item.uri = null;
        item.constr = null;
    }
    this._resources = null;
    this._resourcesId = null;
};

_p._onprogress = function ()
{
    if (this._loaded)return;
    this.dispatchEvent(new CimsEvent("progress"));
};

_p._onerror = function (e)
{
    var t = e.getTarget();
    throw new Error("Error loading " + t + "\nURI: " + t.getUri());
};

_p._onAllLoaded = function ()
{
    if (this._loaded)return;
    this._loaded = true;
    this._onprogress();
    this.dispatchEvent(new CimsEvent("load"));
    this._duplicateScripts = {};
};




//////////////////
// CimsStringBundle
//////////////////
function CimsStringBundle()
{
    if (_inPrototype)return;
    CimsEventTarget.call(this);
    this._bundles = {};
    this._language = this._lastUserLang = this.getUserLanguage();
    this._majorLanguage = this.getMajorLanguage();
}
_p = _mExtend(CimsStringBundle, CimsEventTarget, "CimsStringBundle");
CimsStringBundle.formatString = function (sPattern, args)
{
    var _args = arguments;
    return sPattern.replace(/\%(\d+)/g, function (s, n)
    {
        return _args[n];
    });
};

_p.setLanguage = function (s)
{
    if (s != this._language)
    {
        this._language = s;
        this._majorLanguage = null;
        this.dispatchEvent(new CimsEvent("change"));
    }
};

_p.getLanguage = function ()
{
    return this._language;
}
_p.getLanguages = function ()
{
    var res = [];
    for (var s in this._bundles)
		res.push(s); 
    return res; 
};

_p.getStringKeys = function (sLanguage)
{
    var b = this.getBundleForLanguage(sLanguage);
    var res = [];
    for (var key in b)
		res.push(key); 
	return res; 
};

_p.getMajorLanguage = function ()
{
    if (this._majorLanguage != null)
		return this._majorLanguage;
    return this._majorLanguage = this._language.split("-")[0];
};

_p.getString = function (sStringId, sLanguage)
{
    return this._getString(sLanguage, sStringId);
};

_p.getFormattedString = function (sStringId, args)
{
    var _args = [];
    _args[0] = this._getString(null, sStringId);
    for (var i = 1; i < arguments.length; i++)
		_args[i] = arguments[i]; 
	return CimsStringBundle.formatString.apply(CimsStringBundle, _args); 
};

_p.addBundle = function (sLanguage, oStringMap)
{
    this._bundles[sLanguage] = oStringMap;
    if (sLanguage == this._language)
		this.dispatchEvent(new CimsEvent("change"));
};

_p.appendBundle = function (sLanguage, oStringMap)
{
    if (sLanguage in this._bundles)
    {
        var o = this._bundles[sLanguage];
        for (var key in oStringMap)
			o[key] = oStringMap[key]; 
	}
    else 
		this._bundles[sLanguage] = oStringMap;
};

_p.removeBundle = function (sLanguage)
{
    delete this._bundles[sLanguage];
};

_p.getUserLanguage = function ()
{
    return navigator.userLanguage || navigator.language;
};

_p.getBundleForLanguage = function (sLanguage)
{
    if (sLanguage)
    {
        if (sLanguage in this._bundles)return this._bundles[sLanguage];
        var p0 = sLanguage.split("-")[0];
        if (p0 in this._bundles)return this._bundles[p0];
    }
    if (this.getLanguage()in this._bundles)return this._bundles[this.getLanguage()];
    if (this.getMajorLanguage()in this._bundles)return this._bundles[this.getMajorLanguage()];
    if ("en"in this._bundles)return this._bundles.en;
    return {};
};

_p._getString = function (sLang, sKey)
{
    var bs = this._bundles;
    if (sLang)
    {
        if (sLang in bs && sKey in bs[sLang])return bs[sLang][sKey];
        var p0 = sLang.split("-")[0];
        if (p0 in bs && sKey in bs[p0])return bs[p0][sKey];
    }
    var l;
    if ((l = this.getLanguage())in bs && sKey in bs[l])return bs[l][sKey];
    if ((l = this.getMajorLanguage())in bs && sKey in bs)return bs[l][sKey];
    if ("en"in bs && sKey in bs.en)return bs.en[sKey];
    return null;
};

_p.getBundles = function ()
{
    var res = [];
    for (var s in this._bundles)
        res.push(this._bundles[s]); 
    return res; 
};

_p.dispose = function ()
{
    if (this.getDisposed())return;
    this._bundles = null;
    CimsEventTarget.prototype.dispose.call(this);
};

CimsStringBundle._stringBundleMacro = function (p, fOnChange)
{
    if (fOnChange)
    {
        p.setStringBundle = function (sb)
        {
            if (this._stringBundle != sb)
            {
                if (sb &&!this._stringBundle)application.getStringBundle().removeEventListener("change", fOnChange, this);
                if (this._stringBundle)this._stringBundle.removeEventListener("change", fOnChange, this);
                this._stringBundle = sb;
                if (this._stringBundle)this._stringBundle.addEventListener("change", fOnChange, this);
                fOnChange.call(this);
            }
        };
    }
    else 
    {
        p.setStringBundle = function (sb)
        {
            this._stringBundle = sb;
        };
    }
    p._getString = function (s)
    {
        var sb = this._stringBundle || application.getStringBundle();
        return sb.getFormattedString.apply(sb, arguments);
    };
};

//////////////////
// LoadingStatus
//////////////////
function LoadingStatus()
{
	this._element=document.createElement("DIV");
	this._element.className="bi-loading-status";
	this._htmlElement=document.createElement("DIV");
	this._htmlElement.className="bi-loading-status-html";
	this._element.appendChild(this._htmlElement);
	this._textElement=document.createElement("DIV");
	this._textElement.className="bi-loading-status-text";
	this._element.appendChild(this._textElement);
	this._pbElement=document.createElement("DIV");
	this._pbElement.className="bi-loading-status-progress-bar";
	this._element.appendChild(this._pbElement);
	this._fillElement=document.createElement("DIV");
	this._pbElement.appendChild(this._fillElement);
	document.body.appendChild(this._element);
	var oThis=this;
	this._onresize=function(){oThis.fixSize();};
	if(CimsBrowserCheck.ie)
		window.attachEvent("onresize",this._onresize);
	else 
		window.addEventListener("resize",this._onresize,false);
	this.fixSize();
	this.setHtmlText(LoadingStatus._defaultHtml);
}
_p=LoadingStatus.prototype;
_p.dispose=function(nValue)
{
	if(this._disposed)return;
	if(CimsBrowserCheck.ie)
		window.detachEvent("onresize",this._onresize);
	else 
		window.removeEventListener("resize",this._onresize,false);
	
	this._element.style.filter="none";
	if(document.body&&!(application&&application._disposed))
		document.body.removeChild(this._element);
	this._element=this._htmlElement=this._pbElement=this._textElement=this._fillElement=this._onresize=null;
	this._disposed=true;
};
_p.setValue=function(nValue)
{
	this._fillElement.style.width=(nValue==null?"10":nValue)+"%";
};
_p.setText=function(s)
{
	while(this._textElement.hasChildNodes())
		this._textElement.removeChild(this._textElement.lastChild);
	this._textElement.appendChild(document.createTextNode(s));
};
_p.fixSize=function()
{
	this._element.style.left=Math.max(0,(document.body.clientWidth-this._element.offsetWidth)/2)+"px";
	this._element.style.top=Math.max(0,(document.body.clientHeight-this._element.offsetHeight)/2)+"px";
};
_p.setHtmlText=function(sHtml,sStyle)
{
	if(typeof application!="undefined")
	{
		sHtml=sHtml.replace("%VERSION%",application.getVersion());
	}
	this._htmlElement.innerHTML=sHtml;
	if(sStyle)
		this._htmlElement.style.cssText=sStyle;
};
_p.setStyle=function(sStyle)
{
	if(!/visibility/i.test(sStyle)&&this._element.style.visibility!="")
	{
		sStyle="visibility:"+this._element.style.visibility+";"+sStyle;
	}
	this._element.style.cssText=sStyle;
	this.fixSize();
};
_p.setStatusTextStyle=function(sStyle)
{
	if(sStyle)
		this._textElement.style.cssText=sStyle;
};
_p.setProgressBarStyle=function(sStyle)
{
	if(sStyle)
		this._pbElement.style.cssText=sStyle;
};
_p.setVisible=function(b)
{
	this._element.style.visibility=b?"visible":"hidden";
};
LoadingStatus._defaultHtml='<div style="position:absolute;top: 5px;left:10px;width:280px;"><h1 style="font-size:220%;margin:0;">CIMS Web Application</h1>'+'<p style="font-size:80%;margin:5px 0;">CIMS Lab, Inc. All rights reserved.</p></div>'+'<div style="position:absolute;bottom:5px;right:10px">&#x00A9; 2005 CIMS Lab, Inc.</div>';

//////////////////
// CimsSet
//////////////////
function CimsSet()
{
    if (_inPrototype)return;
    this._items = {};
}
_p = _mExtend(CimsSet, CimsObject, "CimsSet");
_p.add = function (o)
{
    this._items[CimsObject.toHashCode(o)] = o;
};

_p.remove = function (o)
{
    delete this._items[CimsObject.toHashCode(o)];
};

_p.contains = function (o)
{
    return CimsObject.toHashCode(o)in this._items;
};

_p.clear = function ()
{
    this._items = {};
};

_p.toArray = function ()
{
    var res = [];
    for (var hc in this._items)
    {
        res.push(this._items[hc]);
    }
    return res;
};

_p.dispose = function ()
{
    if (this._disposed)return;
    CimsObject.prototype.dispose.call(this);
    this._items = null;
};


//////////////////
// CimsThemeManager
//////////////////
function CimsThemeManager()
{
    if (_inPrototype)return;
    if (CimsThemeManager._singleton)return CimsThemeManager._singleton;
    CimsEventTarget.call(this);
    this._allSet = new CimsSet;
    this._hoverSet = new CimsSet;
    this._activeSet = new CimsSet;
    this._stateHash = {};
    this._themes = {};
    return CimsThemeManager._singleton = this;
}
_p = _mExtend(CimsThemeManager, CimsEventTarget, "CimsThemeManager");
_p.setClassAppearance = function (fClass, sName, bManual)
{
    this.setAppearance(fClass.prototype, sName, bManual);
};

_p.setAppearance = function (oComp, sName, bManual)
{
    var t = this.getDefaultTheme();
    oComp._themeAppearance = sName;
    if (bManual != null)oComp._themeManualInteractivity = Boolean(bManual);
};

_p.addAppearanceListeners = function (oComp)
{
    var app = oComp.getAppearance();
    var states = this.getAppearanceStates(app);
    this._addAppearanceListeners(oComp, states)}
_p._addAppearanceListeners = function (oComp, oStates)
{
    if (Object.isEmpty(oStates) || oComp._themeManualInteractivity)return;
    var win = application.getWindow();
    if (!win)return;
    var hash = oStates;
    if ("hover"in hash)
    {
        oComp.addEventListener("mouseover", this._handleMouseOver, this);
        oComp.addEventListener("mouseout", this._handleMouseOut, this);
    }
    if ("active"in hash)
    {
        oComp.addEventListener("mousedown", this._handleMouseDown, this);
    }
    if ("focus"in hash)
    {
        oComp.addEventListener("focusin", this._handleFocusIn, this);
        oComp.addEventListener("focusout", this._handleFocusOut, this);
    }
    if ("checked"in hash)
    {
        oComp.addEventListener("change", this._handleChange, this);
    }
    if ("disabled"in hash)
    {
        oComp.addEventListener("enabledchanged", this._handleEnabledChanged, this);
    }
};

_p.removeAppearanceListeners = function (oComp)
{
    var app = oComp.getAppearance();
    var states = this.getAppearanceStates(app);
    this._removeAppearanceListeners(oComp, states)}
_p._removeAppearanceListeners = function (oComp, oStates)
{
    if (Object.isEmpty(oStates) || oComp._themeManualInteractivity)return;
    var win = application.getWindow();
    if (!win)return;
    var hash = oStates;
    if ("hover"in hash)
    {
        oComp.removeEventListener("mouseover", this._handleMouseOver, this);
        oComp.removeEventListener("mouseout", this._handleMouseOut, this);
    }
    if ("active"in hash)
    {
        oComp.removeEventListener("mousedown", this._handleMouseDown, this);
        if (this._addedMouseUpListeners)
        {
            win.removeEventListener("mouseup", this._handleMouseUp, this);
            this._addedMouseUpListeners = false;
        }
    }
    if ("focus"in hash)
    {
        oComp.removeEventListener("focusin", this._handleFocusIn, this);
        oComp.removeEventListener("focusout", this._handleFocusOut, this);
    }
    if ("checked"in hash)
    {
        oComp.removeEventListener("change", this._handleChange, this);
    }
    if ("disabled"in hash)
    {
        oComp.removeEventListener("enabledchanged", this._handleEnabledChanged, this);
    }
};

_p.addAppearance = function (oComp)
{
    this.applyAppearance(oComp);
    this.addAppearanceListeners(oComp);
    var app = oComp.getAppearance();
    var states = this.getAppearanceStates(app);
    if (Object.isEmpty(states))return;
    var hash = states;
    var changed = false;
    if ("focus"in hash && (oComp.getFocused() || oComp.getContainsFocus()))
    {
        this.addState(oComp, "focus");
        changed = true;
    }
    if ("selected"in hash && oComp.getSelected())
    {
        this.addState(oComp, "selected");
        changed = true;
    }
    if ("checked"in hash && oComp.getChecked && oComp.getChecked())
    {
        this.addState(oComp, "checked");
        changed = true;
    }
    if ("disabled"in hash &&!oComp.getEnabled())
    {
        this.addState(oComp, "disabled");
        changed = true;
    }
    if (changed)this.applyAppearance(oComp);
};

_p.getAppearanceStates = function (sName)
{
    var t = this.getDefaultTheme();
    return t.getAppearanceStates(sName);
};

_p.getThemeStates = function (oComp)
{
    return oComp._themeStates;
};

_p.getCurrentState = function (oComp)
{
    return this._stateHash[oComp.toHashCode()];
};

_p.getHasInteractiveTheme = function (oComp)
{
    return Object.isEmpty(oComp._themeStates);
};

_p.getAppearanceTag = function (oComp)
{
    var app = oComp.getAppearance();
    var state = this._stateHash[oComp.toHashCode()];
    if (app)return this._getAppearanceTag(app, state);
    return "";
};

_p._getAppearanceTag = function (sName, oStates)
{
    var s = " " + sName;
    for (var pseudo in oStates)s += " " + sName + "-" + pseudo; return s; };

_p.applyAppearance = function (oComp)
{
    oComp.setHtmlProperty("className", oComp._cssClassName + this.getAppearanceTag(oComp));
};

_p.addState = function (oComp, sPseudo)
{
    var hc = oComp.toHashCode();
    if (!(hc in this._stateHash))this._stateHash[hc] = 
    {
    }
    ;
    this._stateHash[hc][sPseudo] = true;
};

_p.removeState = function (oComp, sPseudo)
{
    var hc = oComp.toHashCode();
    if (hc in this._stateHash)delete this._stateHash[hc][sPseudo];
};

_p.setStateValue = function (oComp, sPseudo, bAdd)
{
    if (bAdd)this.addState(oComp, sPseudo);
    else this.removeState(oComp, sPseudo);
};

_p.addTheme = function (oTheme)
{
    var n = oTheme.getName();
    if (!(n in this._themes))
    {
        this._themes[n] = oTheme;
        oTheme._create();
        if (oTheme.getName() == this._defaultThemeName)
        {
            this._defaultThemeName = "";
            this.setDefaultTheme(oTheme);
        }
    }
    else if (this._themes[n] != oTheme)
    {
        throw new Error("Cannot add another theme with the same name: " + n);
    }
};

_p.removeTheme = function (oTheme)
{
    if (oTheme.getDefault())oTheme.setDefault(false);
    delete this._themes[oTheme.getName()];
}
_p.getThemes = function ()
{
    var res = [];
    for (var n in this._themes)res.push(this._themes[n]); return res; };

_p.getDefaultTheme = function ()
{
    if (this._defaultTheme)return this._defaultTheme;
    return this._defaultTheme = this._themes[this._defaultThemeName];
};

_p.setDefaultTheme = function (oTheme)
{
    if (oTheme != this._defaultTheme)
    {
        this._setDefaultThemeByName(oTheme.getName());
        this.dispatchEvent(new CimsEvent("themechanged"));
    }
};

_p._setDefaultThemeByName = function (sName)
{
    if (this._defaultThemeName != sName)
    {
        this._defaultThemeName = sName;
        if (sName in this._themes)
        {
            var t = this._themes[sName];
            this._defaultTheme = t;
            for (var n in this._themes)this._themes[n].setDefault(t == this._themes[n]); if (window.CimsComponent && CimsComponent.invalidateAll)CimsComponent.invalidateAll(); if (window.CimsMenu && CimsMenu.invalidateAll)CimsMenu.invalidateAll(); }
    }
};

_p.addCssRule = function (sSelector, sStyle)
{
    if (!sSelector ||!sStyle)
    {
        return;
    }
    if (!this._sharedStyleSheet)
    {
        this._sharedStyleSheet = CimsThemeManager._createStyleElement();
        this._sharedStyleSheet.id = "bi-theme-shared-style-sheet";
    }
    var ss;
    if (CimsBrowserCheck.ie)
    {
        ss = document.styleSheets["bi-theme-shared-style-sheet"];
        ss.addRule(sSelector, sStyle);
    }
    else 
    {
        ss = this._sharedStyleSheet.sheet;
        ss.insertRule(sSelector + "{" + sStyle + "}", ss.cssRules.length);
    }
};

_p.removeCssRule = function (sSelector)
{
    if (sSelector == null ||!this._sharedStyleSheet)
    {
        return;
    }
    var ss, rules, l, i;
    if (CimsBrowserCheck.ie)
    {
        ss = document.styleSheets["bi-theme-shared-style-sheet"];
        rules = ss.rules;
        l = rules.length;
        for (i = rules.length - 1; i >= 0; i--)
        {
            if (rules[i].selectorText == sSelector)
            {
                ss.removeRule(i);
            }
        }
    }
    else
    {
        ss = this._sharedStyleSheet.sheet;
        rules = ss.cssRules;
        l = rules.length;
        for (i = rules.length - 1; i >= 0; i--)
        {
            if (rules[i].selectorText == sSelector)
            {
                ss.deleteRule(i);
            }
        }
    }
};

CimsThemeManager._createStyleElement = function (sCssText, sClassName)
{
    var el;
    if (CimsBrowserCheck.ie)
    {
        var ss = document.createStyleSheet();
        if (sCssText)ss.cssText = sCssText;
        el = ss.owningElement;
    }
    else 
    {
        el = document.createElement("STYLE");
        el.type = "text/css";
        el.appendChild(document.createTextNode(sCssText));
        var h = document.getElementsByTagName("HEAD")[0];
        h.appendChild(el);
    }
    if (sClassName)el.className = sClassName;
    return el;
};

CimsThemeManager._createLinkElement = function (sName, oUri, sClassName)
{
    var uri = String(oUri);
    var el = document.createElement("link");
    el.type = "text/css";
    el.rel = "stylesheet";
    el.href = uri;
    var h = document.getElementsByTagName("HEAD")[0];
    h.appendChild(el);
    el.className = sClassName || "bi-theme-link";
    el.title = sName;
    el.disabled = false;
    return el;
};

_p._handleMouseDown = function (e)
{
    var c = e.getCurrentTarget();
    this._activeSet.add(c);
    this.addState(c, "active");
    this.applyAppearance(c);
};

_p._handleMouseUp = function (e)
{
    var changed = new CimsSet();
    var active = this._activeSet.toArray();
    var c, i;
    for (i = 0; i < active.length; i++)
    {
        c = active[i];
        changed.add(c);
        this.removeState(c, "active");
    }
    this._activeSet.clear();
    var changed2 = changed.toArray();
    for (i = 0; i < changed2.length; i++)
    {
        if (!changed2[i]._disposed)
        {
            this.applyAppearance(changed2[i]);
        }
    }
    changed.dispose();
};

_p._handleMouseOver = function (e)
{
    var c = e.getCurrentTarget();
    this._hoverSet.add(c);
    this.addState(c, "hover");
    if (this._activeSet.contains(c))
    {
        this.addState(c, "active");
    }
    this.applyAppearance(c);
};

_p._handleMouseOut = function (e)
{
    var c = e.getCurrentTarget();
    this._hoverSet.remove(c);
    this.removeState(c, "active");
    this.removeState(c, "hover");
    this.applyAppearance(c);
};

_p._handleFocusIn = function (e)
{
    var c = e.getCurrentTarget();
    this.addState(c, "focus");
    this.applyAppearance(c);
};

_p._handleFocusOut = function (e)
{
    var c = e.getCurrentTarget();
    this.removeState(c, "focus");
    this.applyAppearance(c);
};

_p._handleChange = function (e)
{
    var c = e.getCurrentTarget();
    if (c.getChecked && c.getChecked())this.addState(c, "checked");
    else this.removeState(c, "checked");
    this.applyAppearance(c);
};

_p._handleEnabledChanged = function (e)
{
    var c = e.getCurrentTarget();
    if (c.getEnabled())this.removeState(c, "disabled");
    else this.addState(c, "disabled");
    this.applyAppearance(c);
};

_p.dispose = function ()
{
    if (this.getDisposed())return;
    CimsObject.prototype.dispose.call(this);
    this._sharedStyleSheet = null;
};




//////////////////
// CimsTheme
//////////////////
function CimsTheme(sName)
{
    if (_inPrototype)return;
    CimsObject.call(this);
    this._appearances = {};
    this._appearanceProperties = {};
    if (sName)this._name = sName;
}
_p = _mExtend(CimsTheme, CimsObject, "CimsTheme");
_p._name = "";
_p._default = false;
CimsTheme.prototype.getName = function ()
{
    return this._name;
};

CimsTheme.prototype.getDefault = function ()
{
    return this._default;
};

_p.setDefault = function (b)
{
    if (b != this._default)
    {
        this._default = b;
        if (this._created)
        {
            if (CimsBrowserCheck.ie)
            {
                this._menuStyleEl.disabled =!b;
                if (b && window.Menu && window.Menu.prototype)
                {
                    Menu.prototype.cssText = this.getMenuCss();
                }
            }
            this._linkEl.disabled =!b;
        }
        if (b)application.getThemeManager().setDefaultTheme(this);
    }
    this._default = b;
    if (this._created)this._linkEl.disabled =!b;
};

_p.addAppearance = function (sAppearanceName, oStates)
{
    var hash = {};
    for (var i = 0; i < oStates.length; i++)
        hash[oStates[i]] = true; 
    this._appearances[sAppearanceName] = hash; 
};

_p.removeAppearance = function (sAppearanceName)
{
    delete this._appearances[sAppearanceName];
};

_p.getAppearanceStates = function (sName)
{
    return this._appearances[sName] || {};
};

_p.getAppearanceProperty = function (sName, sPropertyName)
{
    if (sName in this._appearanceProperties)return this._appearanceProperties[sName][sPropertyName];
    return null;
};

_p.setAppearanceProperty = function (sName, sPropertyName, oValue)
{
    if (!(sName in this._appearanceProperties))
		this._appearanceProperties[sName] = {};
    this._appearanceProperties[sName][sPropertyName] = oValue;
};

_p._create = function ()
{
    if (this._created)return;
    this._linkEl = application.getAdf()._findLinkElement(this.getName());
    if (this._linkEl)
    {
        this._linkEl.disabled =!this.getDefault();
    }
    if (CimsBrowserCheck.ie)
    {
        this._menuStyleEl = CimsThemeManager._createStyleElement(this.getMenuCss());
        this._menuStyleEl.disabled =!this.getDefault();
    }
    this._created = true;
};

_p.dispose = function ()
{
    if (this.getDisposed())return;
    CimsObject.prototype.dispose.call(this);
    if (this._linkEl)
    {
        this._linkEl.disabled = true;
        this._linkEl.onload = null;
    }
    this._linkEl = null;
    if (this._menuStyleEl)this._menuStyleEl.disabled = true;
    this._menuStyleEl = null;
};

CimsTheme.prototype.getMenuCss = function ()
{
    return this._menuCss;
};

CimsTheme.prototype.setMenuCss = function (v)
{
    this._menuCss = v;
};



//////////////////
// CimsAdf
//////////////////
function CimsAdf()
{
    if (_inPrototype)return;
    CimsXmlLoader.call(this);
    this._async = true;
    this._caption = "";
    this._scripts = [];
    this._linkEls = {};
    this._xmlResourceParser = new CimsXmlResourceParser;
}
_p = _mExtend(CimsAdf, CimsXmlLoader, "CimsAdf");
_p._disposed = false;
CimsAdf.prototype.getCaption = function ()
{
    return this._caption;
};
CimsAdf.prototype.setCaption = function (v)
{
    this._caption = v;
};
CimsAdf.prototype.getXmlResourceParser = function ()
{
    return this._xmlResourceParser;
};
_p.setAutoNameMapping = function (b)
{
    if (this._autoNameMapping != b)
    {
        this._autoNameMapping = b;
        if (this._xmlResourceParser)this._xmlResourceParser.setAutoNameMapping(b);
        var rl = application.getResourceLoader();
        if (rl)rl.setAutoNameMapping(b);
        application.setAutoNameMapping(b);
    }
};
_p.getAutoNameMapping = function ()
{
    return application.getAutoNameMapping();
};
_p._interpret = function ()
{
    var doc = this.getDocument();
    var node = doc.selectSingleNode("/application/window/@caption | /Application/Window/@caption");
    if (node)
    {
        this._caption = String(node.text);
        document.title = this._caption;
    }
    var appEl = doc.documentElement;
    this._xmlResourceParser.processAttributes(application, appEl);
    application._themeManager = new CimsThemeManager();
    this._insertThemeCss();
    this._createSplashScreen();
};
_p._addResources = function ()
{
    var doc = this.getDocument();
    var rl = application.getResourceLoader();
    rl.setAutoNameMapping(this._autoNameMapping);
    var n = doc.selectSingleNode("/application/resources | /Application/Resources");
    if (n)
    {
        var nl = n.childNodes;
        var l = nl.length;
        var uri;
        var systemRootPath = application.getPath();
        for (var i = 0; i < l; i++)
        {
            if (nl[i].nodeType != 1)continue;
            uri = nl[i].getAttribute("uri") || nl[i].getAttribute("src");
            switch (nl[i].tagName)
                {
                case "package":
                case "Package":
                    if (uri)
						rl.addResource("script", new CimsUri(systemRootPath, uri));
                    else if (nl[i].getAttribute("name"))
                    {
                        var uris = application.getPackage(nl[i].getAttribute("name"));
                        for (var j = 0; j < uris.length; j++)
							rl.addResource("script", new CimsUri(systemRootPath, uris[j])); 
					}
                    break;
                case "script":
                case "Script":
                {
                    if (uri)
						rl.addResource("script", uri);
                    else if (nl[i].text != "")
                    {
                        rl.addResource("inlinescript", nl[i].text);
                    }
                    break;
                }
				default : 
					rl.addResource(nl[i].tagName, nl[i], nl[i].getAttribute("id"));
					break;						
            }
        }
    }
};
_p._createSplashScreen=function()
{
	var doc=this.getDocument();
	var splashEl=doc.selectSingleNode("/application/splashscreen | /Application/SplashScreen");
	if(splashEl)
	{
		var status = application._loadStatus;
		var style = splashEl.getAttribute("style");
		if (style) status.setStyle(style);
		var htmlEl = splashEl.selectSingleNode("Html | html | HTML");
		if (htmlEl) status.setHtmlText(htmlEl.xml, htmlEl.getAttribute("style"));			
		style = splashEl.selectSingleNode("StatusText/@style");
		if (style) status.setStatusTextStyle(style.value);
		style = splashEl.selectSingleNode("ProgressBar/@style");
		if (style) status.setProgressBarStyle(style.value);		
	}
	application._loadStatus.setVisible(true);
};
_p.parseXmlResources=function()
{
	this._xmlResourceParser.setAutoNameMapping(this._autoNameMapping);
	var doc=this.getDocument();
	var windowEl=doc.selectSingleNode("/application/window | /Application/Window");
	if(!windowEl)
		return;
	this._xmlResourceParser.setRootNode(windowEl);
	var win=application.getWindow();
	var adfAttrs=["left","right","top","bottom","width","height","centered","resizable","fullScreen"];
	var temp={};
	for(var i=0;i<adfAttrs.length;i++)
	{
		if(windowEl.getAttributeNode(adfAttrs[i])!=null)
		{
			temp[adfAttrs[i]]=windowEl.getAttribute(adfAttrs[i]);
			windowEl.removeAttribute(adfAttrs[i]);
		}
	}
	this._xmlResourceParser.processAttributes(win,windowEl);
	this._xmlResourceParser.processChildNodes(win,windowEl);
	for(var attr in temp)
	{
		windowEl.setAttribute(attr,temp[attr]);
		temp[attr]=null;
	}
};
_p._insertThemeCss=function()
{
	this._loadTheme("Default",true,new CimsUri(application.getPath(),"themes/Default/theme.css"),new CimsUri(application.getPath(),"themes/Default/theme.js"));
	var doc=this.getDocument();
	var themes=doc.selectNodes("/application/theme | /Application/Theme");
	for(var i=0;i<themes.length;i++)
	{
		this._loadTheme(themes[i].getAttribute("name"),themes[i].getAttribute("default")=="true",themes[i].getAttribute("cssUri"),themes[i].getAttribute("jsUri"));
	}
};
_p._loadTheme=function(sName,bDefault,sCssUri,sJsUri)
{
	var rl=application.getResourceLoader();
	if(!sCssUri)
		sCssUri=new CimsUri(application.getPath(),"themes/"+sName+"/theme.css");
	else 
		sCssUri=new CimsUri(application.getAdfPath(),sCssUri);
	if(!sJsUri)
		sJsUri=new CimsUri(application.getPath(),"themes/"+sName+"/theme.js");
	else 
		sJsUri=new CimsUri(application.getAdfPath(),sJsUri);
	var linkEl=CimsThemeManager._createLinkElement(sName,sCssUri);
	linkEl.disabled=!bDefault;
	this._linkEls[sName]=linkEl;
	rl.addResource("script",sJsUri);
	if(bDefault)
		application.getThemeManager()._setDefaultThemeByName(sName);
};
_p._findLinkElement=function(sName)
{
	return this._linkEls[sName];
};
_p.dispose=function()
{
	if(this._disposed)return;
	CimsXmlLoader.prototype.dispose.call(this);
	for(var n in this._linkEls)
		delete this._linkEls[n];
    this.disposeFields("_linkEls", "_scripts", "_xmlResourceParser");
};

//////////////////
// CimsApplication
//////////////////
function CimsApplication()
{
	if(_inPrototype)return;
	if(typeof application=="object")
		return application;
	application=this;
	CimsEventTarget.call(this);
	this._progressStatus="";
	this._adf=new CimsAdf();
}
var application;
_p=_mExtend(CimsApplication,CimsEventTarget,"CimsApplication");
_p._version="1.1";
CimsApplication.prototype.getVersion=function()
{
	return this._version;
};
_p.start=function(sRootPath,sAdfPath,oArgs)
{
	this.addEventListener("progressstatus",this._onprogressstatus);
	this._loadStatus=new LoadingStatus();
	this._loadStatus.setValue(2);
	if(arguments.length!=0)
	this._buildArgumentsMapFromArguments(arguments);
	this._loadAdf();
	if(CimsBrowserCheck.ie)
		window.attachEvent("onunload",this._onunload);
	else 
		window.addEventListener("unload",this._onunload,false);
};
_p._findRootPath = function ()
{
    var els = document.getElementsByTagName("script");
    var l = els.length;
    var p, src;
    var re = /(^|\/)js\/application\.js$/;
    for (var i = 0; i < l; i++)
    {
        src = els[i].src;
        if (re.test(src))
        {
            p = RegExp.leftContext;
            if (p.charAt(p.length - 1) != "/")
            {
                p = p + "/";
            }
            return new CimsUri(this._uri, p);
        }
    }
    return null;
};
_p._onunload = function ()
{
    application.dispose();
};

_p._uri = new CimsUri(window.location.href);
_p._uriParams = new CimsUri(window.location.href);
_p._systemRootPath = new CimsUri(window.location.href, "./");
_p.getPath = function ()
{
    return this._systemRootPath;
};

_p.getAdfPath = function ()
{
    if (this._adfPath)return this._adfPath;
    var p = this._uriParams.getParam("Adf");
    return this._adfPath = new CimsUri(p, "./");
};

CimsApplication.prototype.getProgressStatus = function ()
{
    return this._progressStatus;
};

CimsApplication.prototype.setProgressStatus = function (v)
{
    this._progressStatus = v;
};

CimsApplication.prototype.getWindow = function ()
{
    return this._window;
};

CimsApplication.prototype.getAdf = function ()
{
    return this._adf;
};

CimsApplication.prototype.getUri = function ()
{
    return this._uri;
};

_p._accessibilityMode = false;
CimsApplication.prototype.getAccessibilityMode = function ()
{
    return this._accessibilityMode;
};

CimsApplication.prototype.setAccessibilityMode = function (v)
{
    this._accessibilityMode = v;
};

_p._autoNameMapping = false;
CimsApplication.prototype.getAutoNameMapping = function ()
{
    return this._autoNameMapping;
};

_p.setAutoNameMapping = function (b)
{
    if (this._autoNameMapping != b)
    {
        this._autoNameMapping = b;
        this._adf.setAutoNameMapping(b);
    }
};

_p._focusOnLoad = true;
_p.getFocusOnLoad = function ()
{
    return this._focusOnLoad;
};

_p.setFocusOnLoad = function (b)
{
    this._focusOnLoad = b;
};

_p._buildArgumentsMapFromArguments = function (oArguments)
{
    var adfName = "";
    var adfPath;
    var a0 = oArguments[0];
    if (a0.charAt(a0.length - 1) != "/")a0 += "/";
    this._systemRootPath = String(new CimsUri(this._uri, a0));
    var re = /([^\/]+\/)?(\w+)(\.[^\/]*)?$/;
    var ok = re.test(oArguments[1]);
    if (ok)adfName = RegExp.$2;
    else this._reportError(this._getString("ApplicationIncorrectAdfArgument"));
    adfPath = String(new CimsUri(this._uri, oArguments[1]));
    var uri = this._uriParams;
    uri.setParam("AdfName", adfName);
    uri.setParam("Adf", adfPath);
    uri.setParam("Params", oArguments.length - 1);
    for (var i = 2; i < oArguments.length; i++)
    {
        uri.setParam("Param" + (i - 2), oArguments[i]);
    }
};

_p._loadAdf=function()
{
	this._progressStatus=this._getString("ApplicationLoadingAdf");
	this.dispatchEvent(new CimsEvent("progressstatus"));
	this._resourceLoader=new CimsResourceLoader;
	this._adf.addEventListener("load",this._onAdfLoaded,this);
	var adf=this._uriParams.getParam("Adf");
	if(adf!=null)
		this._adf.load(adf);
	else 
		this._reportError(this._getString("ApplicationNoAdf"));
};
_p._onAdfLoaded=function()
{
	this._progressStatus=this._getString("ApplicationAdfLoaded");
	this.dispatchEvent(new CimsEvent("progressstatus"));
	if(this._adf.getError())
	{
		this._reportError(this._getString("ApplicationAdfLoadError"),this._getString("ApplicationAdfLoadErrorDetails",this._uriParams.getParam("Adf"),this._adf.getXmlHttp().status,this._adf.getXmlHttp().statusText));
	}
	else
	{
		this._adf._interpret();
		if(CimsBrowserCheck.ie)
			window.setTimeout("application._loadResources()",1);
		else 
			application._loadResources();
	}
};
_p.getResourceLoader = function ()
{
    return this._resourceLoader;
};

_p.getResourceById = function (sId)
{
    if (this._resourceLoader == null)return null;
    return this._resourceLoader.getResourceById(sId);
};

_p.getComponentById = function (sId)
{
    if (this._adf && this._adf.getXmlResourceParser())return this._adf.getXmlResourceParser().getComponentById(sId);
    return null;
};

_p._loadResources = function ()
{
    var systemRootPath = this.getPath();
    var files;
    for (var i = 0; i < this._defaultPackages.length; i++)
    {
        files = this.getPackage(this._defaultPackages[i]);
        for (var j = 0; j < files.length; j++)
        {
            this._resourceLoader.addResource("script", new CimsUri(systemRootPath, files[j]));
        }
    }
    this._adf._addResources();
    this._resourceLoader.addEventListener("progress", this._onprogressstatus, this);
    this._resourceLoader.addEventListener("load", this._onResourcesLoaded, this);
    this._progressStatus = "Loading Resources";
    this._resourceLoader.load();
};

_p._onprogressstatus = function (e)
{
    if (!this._resourceLoader || this._resourceLoader.getCount() == 0)this._loadStatus.setValue(5);
    else
    {
        this._loadStatus.setValue(Math.max(5, Math.min(95, this._resourceLoader.getLoadedCount()/this._resourceLoader.getCount()*100)));
        this._progressStatus=this._getString("ApplicationLoadingResources",this._resourceLoader.getLoadedCount(),this._resourceLoader.getCount());
    }
	this._loadStatus.setText(this.getProgressStatus());
};

_p._onResourcesLoaded = function (e)
{
    this._useTimersWorkAround = CimsBrowserCheck.moz && CimsBrowserCheck.version < "1.7";
    this._loadStatus.setText(this._getString("ApplicationLoadingCompleted"));
    this._loadStatus.setValue(100);
    this._window = new CimsApplicationWindow();
    this._window._create();
    if (this._useTimersWorkAround)
    {
        window.setTimeout("application._onResourcesLoaded2()", 1);
    }
    else this._onResourcesLoaded2();
};

_p._onResourcesLoaded2 = function ()
{
    this._adf.parseXmlResources();
    this.dispatchEvent(new CimsEvent("resourcesready"));
    if (this._useTimersWorkAround)
    {
        window.setTimeout("application._onResourcesLoaded3()", 1);
    }
    else this._onResourcesLoaded3();
};

_p._onResourcesLoaded3 = function ()
{
    this.flushLayoutQueue();
    if (application._loadStatus)
    {
        application._loadStatus.dispose();
        delete application._loadStatus;
    }
    if (this._focusOnLoad)
    {
        try {window.focus();}
        catch(ex){}
    }
    if (this._useTimersWorkAround)
    {
        window.setTimeout("application._onResourcesLoaded4", 1);
    }
    else 
    {
        application._onResourcesLoaded4();
    }
};


_p._onResourcesLoaded4=function()
{
    var appClassName=this._uriParams.getParam("AdfName");
    var uri=this._uriParams;
    var argc=Number(uri.getParam("Params"));
    var argv=new Array(argc);
    for(var i=0;i<argc;i++)
        argv[i]=uri.getParam("Param"+i);
    if(window[appClassName]&&typeof window[appClassName].main=="function")
    {
        window[appClassName].main.apply(window[appClassName],argv);
        this.flushLayoutQueue();
    }
    appClassName=null;
    argv=null;
    this.dispatchEvent(new CimsEvent("load"));
    this.flushLayoutQueue();
};

_p._reportError = function (s, s2)
{
    if (this._loadStatus)this._loadStatus.setText(s);
    throw new Error(s2 || s);
};

_p.dispose = function ()
{
    this.dispatchEvent(new CimsEvent("dispose"));
    if (this._disposed)return;
    CimsEventTarget.prototype.dispose.call(this);
    if (CimsBrowserCheck.ie)window.detachEvent("onunload", this._onunload);
    else window.removeEventListener("unload", this._onunload, false);
    if (this._window)this._window.dispose();
    this._window = null;
    if (this._loadStatus)this._loadStatus.dispose();
    this._loadStatus = null;
    if (this._resourceLoader)this._resourceLoader.dispose();
    this._resourceLoader = null;
    this._adf.dispose();
    this._adf = null;
};

_p.setAttribute = function (sName, sValue, oParser)
{
    switch (sName)
        {
        case "defaultPackages":
            this.setProperty(sName, sValue.split(/\s*,\s*/));
            break;
            default : CimsEventTarget.prototype.setAttribute.apply(this, arguments);
    }
};

_p.flushLayoutQueue = function ()
{
    if (typeof CimsComponent == "function")
    {
        CimsComponent.flushLayoutQueue();
    }
};

_p.getThemeManager = function ()
{
    if (!this._themeManager)
    {
        this._themeManager = new CimsThemeManager();
    }
    return this._themeManager;
};

_p.getTheme = function ()
{
    return this._themeManager.getDefaultTheme();
};

_p._defaultPackages = ["Core", "Gui", "WebService", "Grid", "TreeView"];
_p.getPackage = function (sName)
{
    if (sName in this._packages)return this._packages[sName];
    return[];
};

_p.getPackages = function ()
{
    var res = [];
    for (n in this._packages)res.push(n); return res; };

_p.addPackage = function (sName, oFiles)
{
    this._packages[sName] = oFiles;
};

CimsApplication.prototype.getDefaultPackages = function ()
{
    return this._defaultPackages;
};

CimsApplication.prototype.setDefaultPackages = function (v)
{
    this._defaultPackages = v;
};

CimsApplication.prototype.getStringBundle = function ()
{
    return this._stringBundle;
};

CimsApplication.prototype.setStringBundle = function (v)
{
    this._stringBundle = v;
};

_p._getString = function (s)
{
    var o = this._stringBundle;
    return o.getFormattedString.apply(o, arguments);
};

_p._stringBundle = new CimsStringBundle();
_p._stringBundle.addBundle("en", {
    ApplicationIncorrectAdfArgument : "The ADF argument is incorrect", 
    ApplicationLoadingAdf : "Loading Application Description File", 
    ApplicationNoAdf : "No ADF specified", 
    ApplicationAdfLoaded : "Application Description File Loaded", 
    ApplicationAdfLoadError : "Error loading ADF", 
    ApplicationAdfLoadErrorDetails : "Error loading ADF\nURI: %1\nStatus: %2, %3", 
    ApplicationLoadingResources : "Loading resources (%1/%2)", 
    ApplicationLoadingCompleted : "Loading completed"
    }
);


application=new CimsApplication();
application._packages_ie={"Core":["js/core.js"],"Gui":["js/gui1.js","js/gui2.ie.js","js/gui3.js"],"Grid":["js/grids.js"],"TreeView":["js/treeview.js"],"WebService":["js/webservice.js"],"OlapGrid":["js/olapgrid.js"]};
application._packages_moz={"Core":["js/core.js"],"Gui":["js/gui1.js","js/gui2.moz.js","js/gui3.js"],"Grid":["js/grids.js"],"TreeView":["js/treeview.js"],"WebService":["js/webservice.js"],"OlapGrid":["js/olapgrid.js"]};
application._packages=CimsBrowserCheck.ie?application._packages_ie:application._packages_moz;


