//************************************************************
//
// System Namespace
//
//************************************************************
System = function() { }
System.Imports = function(nameSpace, shortName) {
    eval(shortName + "=nameSpace");
}
System.initialize = function() {
    System.Screen.initialize();
    System.Mouse.initialize();

    for (var i = 0; i < System.Events._loadComplete.length; i++) {
        System.Events._loadComplete[i]();
    }

}
//************************************************************
//
// System.Events Namespace
//
//************************************************************
System.Events = function() { }
System.Events.Add = function(obj, evType, fn) {
    if (evType == 'loadcomplete') {
        System.Events._loadComplete.push(fn)
    }
    else {
        if (obj.addEventListener) {
            obj.addEventListener(evType, fn, false);
            return true;
        }
        else if (obj.attachEvent) {
            var r = obj.attachEvent("on" + evType, fn);
            return r;
        }
        else {
            return false;
        }
    }
}
System.Events._loadComplete = new Array();
System.Events.Add(window, 'load', System.initialize)
//************************************************************
//
// System.Class Namespace
//
//************************************************************
System.Class = function() { }
System.Class.Inherits = function(descendant, parent) {
    var sConstructor = parent.toString();
    var aMatch = sConstructor.match(/\s*function (.*)\(/);
    if (aMatch != null) { descendant.prototype[aMatch[1]] = parent; }
    for (var m in parent.prototype) {
        descendant.prototype[m] = parent.prototype[m];
    }
}

//************************************************************
//
// System.Debugger Namespace
//
//************************************************************
System.Debugger = function() { }
System.Debugger.output = function(str) {
    document.getElementsByTagName("body")[0].appendChild(document.createTextNode(str));
    document.getElementsByTagName("body")[0].appendChild(document.createElement("br"));
}

//************************************************************
//
// System.Screen Namespace
//
//************************************************************
System.Screen = function() { }
System.Screen.initialize = function() {
    if (document.all) { //IE
        System.Screen.width = document.body.clientWidth + document.body.scrollLeft;
        System.Screen.height = document.body.clientHeight + document.body.scrollTop;
    }
    else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        System.Screen.width = window.innerWidth + window.pageXOffset;
        System.Screen.height = window.innerHeight + window.pageYOffset;
    }
}
System.Screen.width = 0;
System.Screen.height = 0;
//System.Events.Add(window, 'load', System.Screen.initialize);

//************************************************************
//
// System.Mouse Namespace
//
//************************************************************
System.Mouse = function() { }
System.Mouse.initialize = function() {
    if (document.all) { // Internet Explorer
        System.Events.Add(document, 'mousemove', System.Mouse.captureMousePosition);
    }
    else if (document.getElementById) { // Netcsape 6
        System.Events.Add(window, 'mousemove', System.Mouse.captureMousePosition);
    }
}
System.Mouse.captureMousePosition = function(e) {
    if (document.all) { //IE
        System.Mouse.x = window.event.x + document.body.scrollLeft;
        System.Mouse.y = window.event.y + document.body.scrollTop;
        System.Mouse.maxX = document.body.clientWidth + document.body.scrollLeft;
        System.Mouse.maxY = document.body.clientHeight + document.body.scrollTop;
    }
    else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        System.Mouse.x = e.pageX;
        System.Mouse.y = e.pageY;
        System.Mouse.maxX = window.innerWidth + window.pageXOffset;
        System.Mouse.maxY = window.innerHeight + window.pageYOffset;
    }
    //window.status = "System.Mouse.x=" + System.Mouse.x + ", System.Mouse.y=" + System.Mouse.y;// + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;
}
System.Mouse.x = 0;
System.Mouse.y = 0;
System.Mouse.maxX = 0;
System.Mouse.maxY = 0;
//System.Events.Add(window, 'load', System.Mouse.initialize);

//************************************************************
//
// AJAX Namespace
//
//************************************************************
AJAX = function() { }
AJAX.GetHTTPRequestObject = function() {
    var xmlHttpRequest;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (exception1) {
        try {
            xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (exception2) {
            xmlhttp = false;
        }
    }
    @else
    xmlhttpRequest = false;
  @end
    @*/

    if (!xmlHttpRequest && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlHttpRequest = new XMLHttpRequest();
        } catch (exception) {
            xmlHttpRequest = false;
        }
    }
    return xmlHttpRequest;
}

//************************************************************
//
// Image Namespace
//
//************************************************************
HTML = function() { }
HTML.Image = function() { }
HTML.Image.MakeTransparent = function(imgObj) {
    HTML.Image.smallTransparentGif = HTML.Image.transparentGif;
    if (navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("msie 7") == -1) {
        //var img = document.getElementById(strImageID);
        if (imgObj) {
            var src = imgObj.getElement().src;
            alert(imgObj.getElement().src);
            imgObj.getElement().style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
            imgObj.getElement().src = HTML.Image.transparentGif;
            imgObj.getElement().attachEvent("onpropertychange", HTML.Image.ImgPropertyChanged);
        }
    }
}
HTML.Image.ImgPropertyChanged = function() {
    if ((window.event.propertyName == "src") && (!HTML.Image.inImgPropertyChanged)) {
        HTML.Image.inImgPropertyChanged = true;
        var el = window.event.srcElement;
        if (el.src != HTML.Image.smallTransparentGif) {
            el.filters.item(0).src = el.src;
            el.src = HTML.Image.smallTransparentGif;
        }
        HTML.Image.inImgPropertyChanged = false;
    }
}
HTML.Image.smallTransparentGif = "";
HTML.Image.transparentGif = "";
HTML.Image.inImgPropertyChanged = false;

//************************************************************
//
// FormSubmission Class
//
//************************************************************
function FormSubmission(formObj) {
    this._formObj = formObj;
    this._onLoad = null;
    this._onLoadComplete = null;
    this._onError = null;
    this._params = "";
    this._divToReplace = null;
    this._request = null;
}
System.Class.Inherits(FormSubmission, BasicObject);
FormSubmission.prototype.submitAjax = function(divObj, onLoad, onLoadComplete, onError) {
    this._divToReplace = divObj;
    this._onLoad = onLoad;
    this._onLoadComplete = onLoadComplete;
    this._onError = onError;

    var doAdd = true;
    for (var i = 0; i < this._formObj.elements.length; i++) {
        doAdd = true;
        if (this._formObj[i].type == "checkbox") {
            if (this._formObj[i].checked == false)
                doAdd = false;
        }

        var mark = "";
        if (doAdd == true) {
            if (this._params.length > 0)
                mark = "&";

            this._params += mark + this._formObj.elements[i].name + "=" + this._formObj.elements[i].value;
        }
    }

    var me = this;
    this._request = new Request(me._formObj.action, me._params, me._onLoad, returnXML, returnXML);
    this._request.loadXML();

    function returnXML() {
        var pn = me._divToReplace.parentNode;
        pn.removeChild(me._divToReplace);
        me.XML2HTML(pn, me._request.xml());
        if (me._onLoadComplete)
            me._onLoadComplete();
    }

}
FormSubmission.prototype.XML2HTML = function(mainObj, xmlObj) {
    var newObj = null;

    if (xmlObj.tagName) {
        newObj = document.createElement(xmlObj.tagName);

        for (var i = 0; i < xmlObj.attributes.length; i++) {
            newObj.setAttribute(xmlObj.attributes[i].nodeName, xmlObj.attributes[i].nodeValue);
        }
        mainObj.appendChild(newObj);
    }

    if (newObj == null)
        newObj = mainObj;

    if (xmlObj.hasChildNodes() == true) {
        for (var i = 0; i < xmlObj.childNodes.length; i++) {
            this.XML2HTML(newObj, xmlObj.childNodes[i]);
        }
    }
    else if (xmlObj.nodeValue) {
        mainObj.appendChild(document.createTextNode(xmlObj.nodeValue));
    }

}

//************************************************************
//
// Request Class
//
//************************************************************
function Request(url, params, onLoad, onComplete, onError) {
    this.BasicObject();
    this.onError = onError;
    this.onComplete = onComplete;
    this.onLoad = onLoad;
    this._url = url;
    this._params = params;
    this._requestObj = AJAX.GetHTTPRequestObject();
    this._html = "";
    this._text = "";
    this._object = "";
    this._xml = null;
    this._iframe = null;
    this._loadType = "";
    this._errorMessage = "";
    var me;
}
System.Class.Inherits(Request, BasicObject);
Request.prototype.url = function(url) {
    if (url)
        this._url = url;
    return this._url;
}
Request.prototype.params = function(params) {
    if (params)
        this._params = params;
    return this._params;
}
Request.prototype.html = function() { return this._html; }
Request.prototype.xml = function() { return this._xml; }
Request.prototype.text = function() { return this._text; }
Request.prototype.object = function() { return this._object; }
Request.prototype.iframe = function() { return this._iframe; }
Request.prototype.errorMessage = function() { return this._errorMessage; }
Request.prototype.__doRequest = function() {
    me = this;
    this._requestObj.open('post', this.url(), true);
    //this._requestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    this._requestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    this._requestObj.setRequestHeader("Content-length", this._params.length);
    this._requestObj.setRequestHeader("Connection", "close");
    this._requestObj.onreadystatechange = this.__loadReturn;
    this._requestObj.send(this._params);
}
Request.prototype.loadHTML = function() { this._loadType = "HTML"; this.__doRequest(); }
Request.prototype.loadXML = function() { this._loadType = "XML"; this.__doRequest(); }
Request.prototype.loadText = function() { this._loadType = "Text"; this.__doRequest(); }
Request.prototype.loadObject = function() { this._loadType = "Object"; this.__doRequest(); }
Request.prototype.loadIFrame = function() { this._loadType = "iFrame"; }
Request.prototype.__loadReturn = function() {
    //      var UNINITIALIZED = 0;
    //      var LOADING = 1;
    //      var LOADED = 2;
    //      var INTERACTIVE = 3;
    //      var COMPLETE = 4;
    switch (me._requestObj.readyState) {
        case 0:
            me._errorMessage = "Not Initialized";
            if (me.onError)
                me.onError();
            break;
        case 4:
            if (me._requestObj.status == 200) {
                var value = null;
                switch (me._loadType) {
                    case "HTML":
                        me._html = me._requestObj.responseText;
                        value = me._html;
                        break;
                    case "XML":
                        if (me._requestObj.responseXML) {
                            me._xml = me._requestObj.responseXML.documentElement;
                            //document.getElementById('taTest').value=me._requestObj.responseText;
                            value = me._xml;
                        }
                        else {

                            me._errorMessage = "There is no XML";
                            if (me.onError)
                                me.onError();
                            return;
                        }
                        break;
                    case "Text":
                        me._text = me._requestObj.responseText;
                        value = me._text;
                        break;
                    case "Object":
                        me._object = me._requestObj.responseText.parseJSON();
                        value = me._object;
                        break;
                }
                if (me.onComplete)
                    me.onComplete(value);
            }
            else {
                if (me.onError)
                    me.onError();
            }
            break;
        default:
            if (me.onLoad)
                me.onLoad();
    }

}

//************************************************************
//
// Styles Namespace
//
//************************************************************
Styles = function() { }

//************************************************************
//
// Styles.UnitType Static Class
//
//************************************************************
Styles.UnitType = function() { }
Styles.UnitType.pixel = "px";
Styles.UnitType.percent = "%";
Styles.UnitType.point = "pt";
Styles.UnitType.GetValueForced = function(str) {
    var units = new Array();
    var rtn = str;

    units.push(Styles.UnitType.pixel);
    units.push(Styles.UnitType.point);
    units.push(Styles.UnitType.percent);

    for (var i = 0; i < units.length; i++)
        rtn = Styles.UnitType.GetValue(rtn, units[i]);

    return parseFloat(rtn);
}
Styles.UnitType.GetValue = function(str, strToRemove) {
    var rtn = str.toString();
    if (rtn.indexOf(strToRemove) > -1)
        rtn = parseFloat(rtn.substring(0, rtn.indexOf(strToRemove)));
    return rtn;
}

//************************************************************
//
// Styles.BorderStyle Static Class
//
//************************************************************
Styles.BorderStyle = function() { }
Styles.BorderStyle.solid = "solid";
Styles.BorderStyle.dashed = "dashed";

//************************************************************
//
// Styles.Overflow Static Class
//
//************************************************************
Styles.Overflow = function() { }
Styles.Overflow.auto = "auto";
Styles.Overflow.hidden = "hidden";

//************************************************************
//
// Styles.Position Static Class
//
//************************************************************
Styles.Position = function() { }
Styles.Position.absolute = "absolute";
Styles.Position.relative = "relative";

//************************************************************
//
// Styles.FontWeight Static Class
//
//************************************************************
Styles.FontWeight = function() { }
Styles.FontWeight.bold = "bold";
Styles.FontWeight.normal = "normal";

//************************************************************
//
// Styles.Align Static Class
//
//************************************************************
Styles.Align = function() { }
Styles.Align.center = "center";
Styles.Align.left = "left";
Styles.Align.right = "right";

//************************************************************
//
// Styles.Cursor Static Class
//
//************************************************************
Styles.Cursor = function() { }
Styles.Cursor.auto = "auto";
Styles.Cursor.crosshair = "crosshair";
Styles.Cursor.pointer = "pointer";
Styles.Cursor.wait = "wait";
Styles.Cursor.text = "text";
Styles.Cursor.help = "help";
Styles.Cursor.move = "move";
Styles.Cursor.nResize = "n-resize";
Styles.Cursor.neResize = "ne-resize";
Styles.Cursor.nwResize = "nw-resize";
Styles.Cursor.eResize = "e-resize";
Styles.Cursor.wResize = "w-resize";
Styles.Cursor.sResize = "s-resize";
Styles.Cursor.swResize = "sw-resize";
Styles.Cursor.seResize = "se-resize";

//function GetStyleDefaultValue(el,styleProp)
//{
//	var x = el;
//	if (x.currentStyle)
//		var y = x.currentStyle[styleProp];
//	else if (window.getComputedStyle)
//		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
//	return y;
//}


//************************************************************
//
// BasicObject Class
//
//************************************************************
function BasicObject() {
    var _obj = null;
    var dateObj = new Date();
    var _id = Math.floor(dateObj.getTime() * (Math.random() * (Math.random() * 1001)));

    this.data = new Array();

    this.setElement = function(o) {
        if (o) {
            _obj = o;
            if (o.id) {
                if (o.id.length > 0)
                    _id = o.id
            }
        }

        _obj.id = _id;
    }
    this.getElement = function() {
        return _obj;
    }
    this.id = function(id) {
        if (id != null) _id = id;
        return _id;
    }
}

//************************************************************
//
// HTMLObject Class
//
//************************************************************
function HTMLObject() {
    this.BasicObject();
    this._onClickFunction = null;
    this._onDoubleClickFunction = null;
    this._onMouseOverFunction = null;
    this._onMouseOutFunction = null;
    this._onMouseDownFunction = null;
    this._onMouseUpFunction = null;
    this._onChangeFunction = null;
    this._onFocusFunction = null;
    this._onBlurFunction = null;

}
System.Class.Inherits(HTMLObject, BasicObject);
HTMLObject.prototype._addEvent = function(e, functionPointer) {
    var thisObj = this;
    if (functionPointer != null && thisObj.getElement() != null)
        System.Events.Add(thisObj.getElement(), e, functionPointer);
}
HTMLObject.prototype.onClick = function(functionPointer) {
    this._onClickFunction = functionPointer;
    this._addEvent('click', functionPointer);
}
HTMLObject.prototype.onDoubleClick = function(functionPointer) {
    this._onDoubleClickFunction = functionPointer;
    this._addEvent('dblclick', functionPointer);
}
HTMLObject.prototype.onMouseOver = function(functionPointer) {
    this._onMouseOverFunction = functionPointer;
    this._addEvent('mouseover', functionPointer);
}
HTMLObject.prototype.onMouseOut = function(functionPointer) {
    this._onMouseOutFunction = functionPointer;
    this._addEvent('mouseout', functionPointer);
}
HTMLObject.prototype.onMouseUp = function(functionPointer) {
    this._onMouseUpFunction = functionPointer;
    this._addEvent('mouseup', functionPointer);
}
HTMLObject.prototype.onMouseDown = function(functionPointer) {
    this._onMouseDownFunction = functionPointer;
    this._addEvent('mousedown', functionPointer);
}
HTMLObject.prototype.onChange = function(functionPointer) {
    this._onChangeFunction = functionPointer;
    this._addEvent('change', functionPointer);
}
HTMLObject.prototype.onFocus = function(functionPointer) {
    this._onFocusFunction = functionPointer;
    this._addEvent('focus', functionPointer);
}
HTMLObject.prototype.onBlur = function(functionPointer) {
    this._onBlurFunction = functionPointer;
    this._addEvent('blur', functionPointer);
}
HTMLObject.prototype.copy = function(fromObject) {
    this.onClick(fromObject._onClickFunction);
    this.onDoubleClick(fromObject._onDoubleClickFunction);
    this.onMouseOver(fromObject._onMouseOverFunction);
    this.onMouseOut(fromObject._onMouseOutFunction);
    this.onMouseDown(fromObject._onMouseDownFunction);
    this.onMouseUp(fromObject._onMouseUpFunction);
    this.onChange(fromObject._onChangeFunction);
    this.onFocus(fromObject._onFocusFunction);
    this.onBlur(fromObject._onBlurFunction);
}

//************************************************************
//
// ListObject Class
//
//************************************************************
function ListObject() {
    this.BasicObject();
    this._list = new Array();
    this._owningObject = null;
}
System.Class.Inherits(ListObject, BasicObject);
ListObject.prototype.count = function() {
    return this._list.length;
}
ListObject.prototype.add = function(obj) {
    this._list.push(obj);
    if (obj._index)
        obj._index = this._list.length - 1;

    if (obj._owningObj)
        obj._owningObj = this.owningObject();

    return this._list.length - 1;
}
ListObject.prototype.removeAt = function(index) {
    var temp = new Array();
    for (var i = 0; i < this._list.length; i++) {
        if (i != index)
            temp.push(this._list[i]);
        else
            this._list[i]._owningObj = null;
    }
    this._list = temp;
}
ListObject.prototype.getAt = function(index) {
    if (index > -1 && index < this._list.length)
        return this._list[index];
    else
        return null;
}
ListObject.prototype.clear = function() {
    this._list = new Array();
}
ListObject.prototype.owningObject = function(obj) {
    if (obj)
        this._owningObject = obj;

    return this._owningObject;
}


//************************************************************
//
// HTMLControls Class
//
//************************************************************
function HTMLControls() {
    this.ListObject();
}
System.Class.Inherits(HTMLControls, ListObject);
HTMLControls.prototype._owningControl = function(control) {
    this.owningObject(control);
}

//************************************************************
//
// StyleObject Class
//
//************************************************************
function StyleObject(el) {
    this.element = el;
    this._alpha = 100;
}
StyleObject.prototype.width = function(width, widthUnits) {
    if (isNaN(width) == false) {
        if (width > 0) {
            if (widthUnits)
                this.element.style.width = width.toString() + widthUnits;
            else
                this.element.style.width = width.toString() + Styles.UnitType.pixel;
        }
    }
    return Styles.UnitType.GetValueForced(this.element.style.width);
}
StyleObject.prototype.height = function(height, heightUnits) {
    if (isNaN(height) == false) {
        if (height > 0) {
            if (heightUnits)
                this.element.style.height = height.toString() + heightUnits;
            else
                this.element.style.height = height.toString() + Styles.UnitType.pixel;
        }
    }

    return Styles.UnitType.GetValueForced(this.element.style.height);
}
StyleObject.prototype.borderWidth = function(borderWidth) {
    if (isNaN(borderWidth) == false) {
        if (borderWidth > 0)
            this.element.style.borderWidth = borderWidth.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.borderWidth);
}
StyleObject.prototype.padding = function(padding) {
    if (isNaN(padding) == false) {
        if (padding > 0)
            this.element.style.padding = padding.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.padding);
}
StyleObject.prototype.paddingLeft = function(paddingLeft) {
    if (isNaN(paddingLeft) == false) {
        if (paddingLeft > 0)
            this.element.style.paddingLeft = paddingLeft.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.paddingLeft);
}
StyleObject.prototype.paddingTop = function(paddingTop) {
    if (isNaN(paddingTop) == false) {
        if (paddingTop > 0)
            this.element.style.paddingTop = paddingTop.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.paddingTop);
}
StyleObject.prototype.paddingRight = function(paddingRight) {
    if (isNaN(paddingRight) == false) {
        if (paddingRight > 0)
            this.element.style.paddingRight = paddingRight.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.paddingRight);
}
StyleObject.prototype.paddingBottom = function(paddingBottom) {
    if (isNaN(paddingBottom) == false) {
        if (paddingBottom > 0)
            this.element.style.paddingBottom = paddingBottom.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.paddingBottom);
}
StyleObject.prototype.margin = function(margin) {
    if (isNaN(margin) == false) {
        if (margin > 0)
            this.element.style.margin = margin.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.margin);
}
StyleObject.prototype.marginLeft = function(marginLeft) {
    if (isNaN(marginLeft) == false) {
        if (marginLeft > 0)
            this.element.style.marginLeft = marginLeft.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.marginLeft);
}
StyleObject.prototype.marginRight = function(marginRight) {
    if (isNaN(marginRight) == false) {
        if (marginRight > 0)
            this.element.style.marginRight = marginRight.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.marginRight);
}
StyleObject.prototype.marginTop = function(marginTop) {
    if (isNaN(marginTop) == false) {
        if (marginTop > 0)
            this.element.style.marginTop = marginTop.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.marginTop);
}
StyleObject.prototype.marginBottom = function(marginBottom) {
    if (isNaN(marginBottom) == false) {
        if (marginBottom > 0)
            this.element.style.marginBottom = marginBottom.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.marginBottom);
}
StyleObject.prototype.left = function(leftValue) {
    if (this.element.style.position.length == 0)
        this.element.style.position = "relative";
    if (isNaN(leftValue) == false)
        this.element.style.left = leftValue.toString() + Styles.UnitType.pixel;
    return Styles.UnitType.GetValueForced(this.element.style.left);
}
StyleObject.prototype.top = function(topValue) {
    if (this.element.style.position.length == 0)
        this.element.style.position = "relative";
    if (isNaN(topValue) == false)
        this.element.style.top = topValue.toString() + Styles.UnitType.pixel;
    return Styles.UnitType.GetValueForced(this.element.style.top);
}
StyleObject.prototype.lineHeight = function(lineHeight) {
    if (isNaN(lineHeight) == false) {
        if (lineHeight > 0)
            this.element.style.lineHeight = lineHeight.toString() + Styles.UnitType.pixel;
    }
    return Styles.UnitType.GetValueForced(this.element.style.lineHeight);
}
StyleObject.prototype.fontSize = function(fontSize, fontSizeUnits) {
    if (isNaN(fontSize) == false) {
        if (fontSize > 0) {
            if (fontSizeUnits)
                this.element.style.fontSize = fontSize.toString() + fontSizeUnits;
            else
                this.element.style.fontSize = fontSize.toString() + Styles.UnitType.pixel;
        }
    }
    return Styles.UnitType.GetValueForced(this.element.style.fontSize);
}
StyleObject.prototype.cursor = function(cursor) {
    if (cursor)
        this.element.style.cursor = cursor;
    return this.element.style.cursor;
}
StyleObject.prototype.backgroundColor = function(backgroundColor) {
    if (backgroundColor)
        this.element.style.backgroundColor = backgroundColor;
    return this.element.style.backgroundColor;
}
StyleObject.prototype.backgroundImage = function(backgroundImage) {
    if (backgroundImage)
        this.element.style.backgroundImage = backgroundImage;
    return this.element.style.backgroundImage;
}
StyleObject.prototype.borderColor = function(borderColor) {
    if (borderColor)
        this.element.style.borderColor = borderColor;
    return this.element.style.borderColor;
}
StyleObject.prototype.borderStyle = function(borderStyle) {
    if (borderStyle)
        this.element.style.borderStyle = borderStyle;
    return this.element.style.borderStyle;
}
StyleObject.prototype.position = function(position) {
    if (position)
        this.element.style.position = position;
    return this.element.style.position;
}
StyleObject.prototype.fontFamily = function(fontFamily) {
    if (fontFamily)
        this.element.style.fontFamily = fontFamily;
    return this.element.style.fontFamily;
}
StyleObject.prototype.fontColor = function(fontColor) {
    if (fontColor)
        this.element.style.color = fontColor;
    return this.element.style.color;
}
StyleObject.prototype.fontWeight = function(fontWeight) {
    if (fontWeight)
        this.element.style.fontWeight = fontWeight;
    return this.element.style.fontWeight;
}
StyleObject.prototype.textDecoration = function(textDecoration) {
    if (textDecoration)
        this.element.style.textDecoration = textDecoration;
    return this.element.style.textDecoration;
}
StyleObject.prototype.textAlign = function(textAlign) {
    if (textAlign)
        this.element.style.textAlign = textAlign;
    return this.element.style.textAlign;
}
StyleObject.prototype.overflow = function(overflow) {
    if (overflow)
        this.element.style.overflow = overflow;
    return this.element.style.overflow;
}
StyleObject.prototype.zIndex = function(zIndex) {
    if (zIndex)
        this.element.style.zIndex = zIndex;
    return this.element.style.zIndex;
}
StyleObject.prototype.alpha = function(alpha) {

    if (isNaN(alpha) == false) {
        if (alpha > -1 && alpha <= 100) {
            this.element.style.opacity = alpha / 100;
            this.element.style.MozOpacity = alpha / 100;
            this.element.style.filter = "alpha(opacity=" + alpha + ")";
            this._alpha = alpha;
        }
    }

    return this._alpha;
}
StyleObject.prototype.copy = function(fromObject) {
    this.width(fromObject.width());
    this.height(fromObject.height());
    this.borderWidth(fromObject.borderWidth());
    this.borderStyle(fromObject.borderStyle());
    this.borderColor(fromObject.borderColor());
    this.padding(fromObject.padding());
    this.paddingLeft(fromObject.paddingLeft());
    this.paddingRight(fromObject.paddingRight());
    this.paddingTop(fromObject.paddingTop());
    this.paddingBottom(fromObject.paddingBottom());
    this.margin(fromObject.margin());
    this.marginTop(fromObject.marginTop());
    this.marginBottom(fromObject.marginBottom());
    this.marginLeft(fromObject.marginLeft());
    this.marginRight(fromObject.marginRight());
    this.alpha(fromObject.alpha());
    this.top(fromObject.top());
    this.left(fromObject.left());
    this.fontFamily(fromObject.fontFamily());
    this.fontSize(fromObject.fontSize());
    this.fontColor(fromObject.fontColor());
    this.fontWeight(fromObject.fontWeight());
    this.textDecoration(fromObject.textDecoration());
    this.position(fromObject.position());
    this.backgroundColor(fromObject.backgroundColor());
    this.cursor(fromObject.cursor());
    this.lineHeight(fromObject.lineHeight());
    this.overflow(fromObject.overflow());
    this.zIndex(fromObject.zIndex());
    this.textAlign(fromObject.textAlign());
}


//************************************************************
//
// Animation Class
//
//************************************************************
function Animation(obj) {
    this.BasicObject();
    this._obj = obj;
    this.widthDiff = 0;
    this.heightDiff = 0;
    this.sizeInterval = null;
    this.leftDiff = 0;
    this.topDiff = 0;
    this.positionInterval = null;
    this.alphaDiff = 0;
    this.alphaInterval = null;
    this.propertyDiff = 0;
    this.propertyName = "";
    this.propertyInterval = null;
    this._animationEase = 8;
}
System.Class.Inherits(Animation, BasicObject);
Animation.prototype.getControl = function() {
    return this._obj;
}
Animation.prototype.animationEase = function(animationEase) {
    if (animationEase)
        this._animationEase = animationEase;
    return this._animationEase;
}
Animation.prototype.property = function(property, newValue, complete) {
    var me = this;
    clearInterval(this.propertyInterval);
    this.propertyName = property;
    eval("this.propertyDiff = newValue - this._obj.style." + property + "()");

    this.__animateProperty = function() {
        eval("me._obj.style." + me.propertyName + "(me._obj.style." + me.propertyName + "()+(me.propertyDiff/me.animationEase()))");
        me.propertyDiff -= (me.propertyDiff / me.animationEase());

        if (Math.abs(me.propertyDiff) < 2) {
            eval("me._obj.style." + me.propertyName + "(me._obj.style." + me.propertyName + "()+me.propertyDiff)");
            clearInterval(me.propertyInterval);
            if (complete)
                complete();
        }
    }
    this.propertyInterval = setInterval(this.__animateProperty, 25);
}
Animation.prototype.size = function(widthValue, heightValue, absolute, complete) {
    var me = this;
    clearInterval(this.sizeInterval);
    if (absolute == false) {
        this.widthDiff = widthValue;
        this.heightDiff = heightValue;
    }
    else {
        this.widthDiff = widthValue - me._obj.style.width();
        this.heightDiff = heightValue - me._obj.style.height();
    }

    this.__animateSize = function() {
        me._obj.style.width(me._obj.style.width() + (me.widthDiff / me.animationEase()));
        me._obj.style.height(me._obj.style.height() + (me.heightDiff / me.animationEase()));

        me.widthDiff -= (me.widthDiff / me.animationEase());
        me.heightDiff -= (me.heightDiff / me.animationEase());

        if (Math.abs(me.widthDiff) < 2 && Math.abs(me.heightDiff) < 2) {
            me._obj.style.width(me._obj.style.width() + me.widthDiff);
            me._obj.style.height(me._obj.style.height() + me.heightDiff);
            clearInterval(me.sizeInterval);
            if (complete)
                complete();
        }
    }
    this.sizeInterval = setInterval(this.__animateSize, 25);
}
Animation.prototype.position = function(x, y, absolute, complete) {
    var me = this;
    clearInterval(this.positionInterval);
    if (absolute == false) {
        this.leftDiff = x;
        this.topDiff = y;
    }
    else {
        this.leftDiff = x - me._obj.style.left();
        this.topDiff = y - me._obj.style.top();
    }

    this.__animatePosition = function() {
        //totalCounter++;
        //System.Debugger.output(totalCounter);
        me._obj.style.left(me._obj.style.left() + (me.leftDiff / me.animationEase()));
        me._obj.style.top(me._obj.style.top() + (me.topDiff / me.animationEase()));

        me.leftDiff -= (me.leftDiff / me.animationEase());
        me.topDiff -= (me.topDiff / me.animationEase());

        if (Math.abs(me.leftDiff) < 2 && Math.abs(me.topDiff) < 2) {
            me._obj.style.left(me._obj.style.left() + me.leftDiff);
            me._obj.style.top(me._obj.style.top() + me.topDiff);
            clearInterval(me.positionInterval);
            if (complete)
                complete();
        }
    }

    this.positionInterval = setInterval(this.__animatePosition, 25);
}
Animation.prototype.alpha = function(alphaTarget, complete) {
    var me = this;
    clearInterval(this.alphaInterval);
    this.alphaDiff = alphaTarget - this._obj.style.alpha();

    this.__animateAlpha = function() {
        me._obj.style.alpha(me._obj.style.alpha() + (me.alphaDiff / me.animationEase()));
        me.alphaDiff -= (me.alphaDiff / me.animationEase());

        if (Math.abs(me.alphaDiff) < 2) {
            me._obj.style.alpha(me._obj.style.alpha() + me.alphaDiff);
            clearInterval(me.alphaInterval);
            if (complete)
                complete();
        }
    }
    this.alphaInterval = setInterval(this.__animateAlpha, 25);
}

//************************************************************
//
// HMTLControl Class
//
//************************************************************
function HTMLControl(type, existingId) {
    this.HTMLObject();
    if (existingId)
        this.setElement(document.getElementById(existingId));
    else
        this.setElement(document.createElement(type));
    this.owningControl = null;
    this.style = new StyleObject(this.getElement());
    this._isDraggable = false;

    var _obj = this;
    this.onMouseDown(function() { _obj.startMove(_obj); });
}
System.Class.Inherits(HTMLControl, HTMLObject);
HTMLControl.prototype.visible = function(v) {
    if (v === true) {
        this.getElement().style.display = "block";
    }
    else if (v === false) {
        this.getElement().style.display = "none";
    }

    if (this.getElement().style.display == "block")
        return true;
    else if (this.getElement().style.display == "none")
        return false;
    else
        return true;

}
HTMLControl.prototype.renderControls = function() {
    return this.getElement();
}
HTMLControl.prototype.remove = function() {
    try {
        this.getElement().parentNode.removeChild(this.getElement());
    }
    catch (e) {//alert(e);
    }
}
HTMLControl.prototype.isDraggable = function(isDraggable) {
    if (isDraggable != null)
        this._isDraggable = isDraggable;
    return false; //this._isDraggable;
}
HTMLControl.prototype.startMove = function(me) {
    var me = this;
    var moveInterval = null;
    var lastX = System.Mouse.x;
    var lastY = System.Mouse.y;
    if (me.isDraggable() == true) {

        this.getMousePosition = function() {
            xDiff = System.Mouse.x - lastX;
            yDiff = System.Mouse.y - lastY;

            //System.Debugger.output("xDiff: "+xDiff+" yDiff: "+yDiff);
            //System.Debugger.output("xDiff: "+xDiff+" yDiff: "+yDiff);

            me.style.left(me.style.left() + xDiff);
            me.style.top(me.style.top() + yDiff);

            lastX += xDiff;
            lastY += yDiff;
        }
        this.endMove = function() {
            clearInterval(moveInterval);
        }
        this.onMouseUp(me.endMove);
        moveInterval = setInterval(me.getMousePosition, 25);
    }
}

//************************************************************
//
// HTMLContainerControl Class
//
//************************************************************
function HTMLContainerControl(type, existingId) {
    this.HTMLControl(type, existingId);
    this.controls = new HTMLControls();
}
System.Class.Inherits(HTMLContainerControl, HTMLControl);
HTMLContainerControl.prototype.renderControls = function() {
    HTMLControl.prototype.renderControls.apply(this);

    var count = this.controls.count();
    for (var i = 0; i < count; i++) {
        if (this.controls.getAt(i).getElement) {
            if (this.controls.getAt(i).renderControls) {
                this.getElement().appendChild(this.controls.getAt(i).renderControls());
            }
            else
                this.getElement().appendChild(this.controls.getAt(i).getElement());
        }
        else
            this.getElement().appendChild(this.controls.getAt(i));
    }
    return this.getElement();
}
HTMLContainerControl.prototype.innerHTML = function(innerHTML) {
    if (innerHTML)
        this.getElement().innerHTML = innerHTML

    return this.getElement().innerHTML;
}

//************************************************************
//
// HTMLTable Class
//
//************************************************************
function HTMLTable() {
    this.HTMLContainerControl("table");
    this._cellPadding = 0;
    this._cellSpacing = 0;
    this.rows = new HTMLTableRows();
    this.rows._owningTable(this);
}
System.Class.Inherits(HTMLTable, HTMLContainerControl);
HTMLTable.prototype.renderControls = function() {
    HTMLContainerControl.prototype.renderControls.apply(this);

    this.getElement().cellPadding = this.cellPadding;
    this.getElement().cellSpacing = this.cellSpacing;

    var tbody = document.createElement("tbody");
    this.getElement().appendChild(tbody);

    var count = this.rows.count();
    for (var i = 0; i < count; i++) {
        tbody.appendChild(this.rows.getAt(i).renderControls());
    }
    return this.getElement();
}
HTMLTable.prototype.cellPadding = function(cellPadding) {
    if (cellPadding)
        this._cellPadding = cellPadding;
    return this._cellPadding;
}
HTMLTable.prototype.cellSpacing = function(cellSpacing) {
    if (cellSpacing)
        this._cellSpacing = cellSpacing;
    return this._cellSpacing;
}

//************************************************************
//
// HTMLTableRows Class
//
//************************************************************
function HTMLTableRows() {
    this.ListObject();
}
System.Class.Inherits(HTMLTableRows, ListObject);
HTMLTableRows.prototype._owningTable = function(table) {
    this.owningObject(table);
}

//************************************************************
//
// HTMLTableRow Class
//
//************************************************************
function HTMLTableRow() {
    this.HTMLContainerControl("tr");
    this.cells = new HTMLTableCells();
    this.cells._owningRow(this);
    this._index = -1;
    this._owningObj = null;
}
System.Class.Inherits(HTMLTableRow, HTMLContainerControl);
HTMLTableRow.prototype.renderControls = function() {
    HTMLContainerControl.prototype.renderControls.apply(this);

    var count = this.cells.count();
    for (var i = 0; i < count; i++) {
        this.getElement().appendChild(this.cells.getAt(i).renderControls());
    }
    return this.getElement();
}

//************************************************************
//
// HMTLTableCells Class
//
//************************************************************
function HTMLTableCells() {
    this.ListObject();
}
System.Class.Inherits(HTMLTableCells, ListObject);
HTMLTableCells.prototype._owningRow = function(row) {
    this.owningObject(row);
}

//************************************************************
//
// HTMLTableCell Class
//
//************************************************************
function HTMLTableCell() {
    this.HTMLContainerControl("td");
    this._index = -1;
    this._owningObj = null;
}
System.Class.Inherits(HTMLTableCell, HTMLContainerControl);
HTMLTableCell.prototype.owningRow = function() {
    return this._owningObj;
}

//************************************************************
//
// HTMLInputControl Class
//
//************************************************************
function HTMLInputControl() {
    //this.HTMLControl("input");
    this.labelControl = null;
    this.name = '_' + this.id;
}
System.Class.Inherits(HTMLInputControl, HTMLControl);
HTMLInputControl.prototype.renderControls = function() {
    HTMLControl.prototype.renderControls.apply(this);
    this.getElement().name = this.name;
}
HTMLInputControl.prototype.enabled = function(enabled) {
    if (enabled != null) {
        if (enabled == false)
            this.getElement().disabled = true;
        else
            this.getElement().disabled = false;
    }
    if (this.getElement().disabled == false)
        return true;
    else
        return false;
}

//************************************************************
//
// Textbox Class
//
//************************************************************
function HTMLTextbox() {
    this.HTMLControl("input");
    this.HTMLInputControl();
    this.getElement().type = "text";
    this.columns = -1;
    this.maxLength = -1
}
System.Class.Inherits(HTMLTextbox, HTMLInputControl);
HTMLTextbox.prototype.text = function(str) {
    if (str)
        this.getElement().value = str;

    return this.getElement().value;
}
HTMLTextbox.prototype.renderControls = function() {
    HTMLInputControl.prototype.renderControls.apply(this);

    if (this.columns > -1)
        this.getElement().size = this.columns;
    if (this.maxLength > -1)
        this.getElement().maxLength = this.maxLength;

    return this.getElement();
}


//************************************************************
//
// Textarea Class
//
//************************************************************
function HTMLTextarea() {
    this.HTMLControl("textarea");
    this.HTMLInputControl();
    this.columns = -1;
    this.rows = 1;
}
System.Class.Inherits(HTMLTextarea, HTMLInputControl);
HTMLTextarea.prototype.text = function(text) {
    if (text != null)
        this.getElement().value = text;

    return this.getElement().value;
}
HTMLTextarea.prototype.renderControls = function() {
    HTMLInputControl.prototype.renderControls.apply(this);

    if (this.columns > -1)
        this.getElement().cols = this.columns;
    if (this.rows > -1)
        this.getElement().rows = this.rows;

    return this.getElement();
}

//************************************************************
//
//  Class
//
//************************************************************
function HTMLImage(existingId) {
    this.HTMLControl("img", existingId);
    this._onLoadComplete = null;
    this._completeInterval = null;
    this._div = null;
}
System.Class.Inherits(HTMLImage, HTMLControl);
HTMLImage.prototype.onLoadComplete = function(fn) {
    if (fn)
        this._onLoadComplete = fn;
}

HTMLImage.prototype.url = function(url) {
    var me = this;
    if (url) {
        this.getElement().src = url;
    }

    this.checkIfLoaded = function() {
        if (me.isLoaded() == true) {
            clearInterval(me._completeInterval);
            if (me._onLoadComplete)
                me._onLoadComplete();
        }
    }
    this._completeInterval = setInterval(this.checkIfLoaded, 100);


    return this.getElement().src;
}
HTMLImage.prototype.makeTransparent = function() {
    var div = new HTMLContainerControl("div");
    div.getElement().style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.url().toString() + "',sizingMethod='scale')";
    var parentNode = this.getElement().parentNode;
    //div.style.copy(this.style);
    div.style.width(this.getElement().width);
    div.style.height(this.getElement().height);
    parentNode.removeChild(this.getElement());
    parentNode.appendChild(div.getElement());
}
HTMLImage.prototype.alt = function(alt) {
    if (alt)
        this.getElement().alt = alt;

    return this.getElement().alt;
}
HTMLImage.prototype.width = function(width) {
    if (width)
        this.getElement().width = width;

    return this.getElement().width;
}
HTMLImage.prototype.height = function(height) {
    if (height)
        this.getElement().height = height;

    return this.getElement().height;
}
HTMLImage.prototype.isLoaded = function() {
    return this.getElement().complete;
}

//************************************************************
//
// HTMLCheckbox Class
//
//************************************************************
function HTMLCheckbox() {
    this.HTMLControl("input");
    this.HTMLInputControl();
    this.getElement().type = "checkbox";
}
System.Class.Inherits(HTMLCheckbox, HTMLInputControl);
HTMLCheckbox.prototype.checked = function(checked) {
    if (checked != null)
        this.getElement().checked = checked;

    return this.getElement().checked;
}

//************************************************************
//
// HTMLButton Class
//
//************************************************************
function HTMLButton() {
    this.HTMLControl("input");
    this.getElement().type = "button";
}
System.Class.Inherits(HTMLButton, HTMLControl);
HTMLButton.prototype.text = function(text) {
    if (text != null)
        this.getElement().value = text;

    return this.getElement().value;
}

//************************************************************
//
// HTMLSelect Class
//
//************************************************************
function HTMLSelect() {
    this.HTMLControl("select");
}
System.Class.Inherits(HTMLSelect, HTMLControl);
HTMLSelect.prototype.rows = function(rows) {
    if (rows)
        this.getElement().size = rows;
    return this.getElement().size;
}
HTMLSelect.prototype.selectMultiple = function(selectMultiple) {
    if (selectMultiple)
        this.getElement().multiple = selectMultiple;
    return this.getElement().multiple
}


//************************************************************
//
// RoundedPanel Class
//
//************************************************************
function RoundedPanel(width, height, backgroundColor, borderColor) {
    this.BasicObject();
    this._width = width;
    this._height = height;
    this._backgroundColor = backgroundColor;
    this._borderColor = borderColor;
    this._outerDiv = new HTMLContainerControl("div");
}
System.Class.Inherits(RoundedPanel, BasicObject);
RoundedPanel.prototype.width = function(width) {
    if (isNaN(width) == false) {
        if (width > 0)
            this._width = width;
    }
    return this._width;
}
RoundedPanel.prototype.visible = function(visible) {
    if (visible != null)
        this._outerDiv.visible(visible);
    return this._outerDiv.visible();
}
RoundedPanel.prototype.height = function(height) {
    if (isNaN(height) == false) {
        if (height > 0)
            this._height = height;
    }
    return this._height;
}
RoundedPanel.prototype.borderColor = function(borderColor) {
    if (borderColor != null)
        this._borderColor = borderColor;
    return this._borderColor;
}
RoundedPanel.prototype.backgroundColor = function(backgroundColor) {
    if (backgroundColor != null)
        this._backgroundColor = backgroundColor;
    return this._backgroundColor;
}
RoundedPanel.prototype.renderControls = function() {
    var pdiv2 = new HTMLContainerControl("div");
    var pdiv3 = new HTMLContainerControl("div");
    var leftBar = new HTMLContainerControl("div");
    var leftBar2 = new HTMLContainerControl("div");
    var rightBar = new HTMLContainerControl("div");
    var rightBar2 = new HTMLContainerControl("div");
    var topBar = new HTMLContainerControl("div");
    var topBar2 = new HTMLContainerControl("div");
    var bottomBar = new HTMLContainerControl("div");
    var bottomBar2 = new HTMLContainerControl("div");
    var rcs = new RoundedCorners(this.borderColor(), this.backgroundColor());

    this._outerDiv.controls.add(pdiv2);
    this._outerDiv.style.position(Styles.Position.relative);
    this._outerDiv.style.width(this.width());
    this._outerDiv.style.height(this.height());

    pdiv2.style.position(Styles.Position.absolute);
    pdiv2.style.width(this.width());
    pdiv2.style.height(this.height());

    pdiv3.style.position(Styles.Position.absolute);
    pdiv3.style.width(this.width() - 20);
    pdiv3.style.height(this.height() - 20);
    pdiv3.style.top(10);
    pdiv3.style.left(10);
    pdiv3.style.backgroundColor(this.backgroundColor());

    rcs.topLeft.style.position(Styles.Position.absolute);
    rcs.topRight.style.position(Styles.Position.absolute);
    rcs.bottomLeft.style.position(Styles.Position.absolute);
    rcs.bottomRight.style.position(Styles.Position.absolute);

    leftBar.style.width(1);
    leftBar.style.height(this.height() - 20);
    leftBar.style.top(10);
    leftBar.style.left(0);
    leftBar.style.backgroundColor(this.borderColor());
    leftBar.style.position(Styles.Position.absolute);
    leftBar2.style.width(9);
    leftBar2.style.height(this.height() - 20);
    leftBar2.style.top(10);
    leftBar2.style.left(1);
    leftBar2.style.backgroundColor(this.backgroundColor());
    leftBar2.style.position(Styles.Position.absolute);

    rightBar.style.width(1);
    rightBar.style.height(this.height() - 20);
    rightBar.style.top(10);
    rightBar.style.left(this.width() - 1);
    rightBar.style.backgroundColor(this.borderColor());
    rightBar.style.position(Styles.Position.absolute);
    rightBar2.style.width(9);
    rightBar2.style.height(this.height() - 20);
    rightBar2.style.top(10);
    rightBar2.style.left(this.width() - 10);
    rightBar2.style.backgroundColor(this.backgroundColor());
    rightBar2.style.position(Styles.Position.absolute);

    topBar.style.width(this.width() - 20);
    topBar.style.height(1);
    topBar.style.top(0);
    topBar.style.left(10);
    topBar.style.backgroundColor(this.borderColor());
    topBar.style.position(Styles.Position.absolute);
    topBar2.style.width(this.width() - 20);
    topBar2.style.height(9);
    topBar2.style.top(1);
    topBar2.style.left(10);
    topBar2.style.backgroundColor(this.backgroundColor());
    topBar2.style.position(Styles.Position.absolute);

    bottomBar.style.width(this.width() - 20);
    bottomBar.style.height(1);
    bottomBar.style.top(this.height() - 1);
    bottomBar.style.left(10);
    bottomBar.style.backgroundColor(this.borderColor());
    bottomBar.style.position(Styles.Position.absolute);
    bottomBar2.style.width(this.width() - 20);
    bottomBar2.style.height(9);
    bottomBar2.style.top(this.height() - 10);
    bottomBar2.style.left(10);
    bottomBar2.style.backgroundColor(this.backgroundColor());
    bottomBar2.style.position(Styles.Position.absolute);

    pdiv2.controls.add(rcs.topLeft.renderControls());
    pdiv2.controls.add(rcs.topRight.renderControls());
    pdiv2.controls.add(rcs.bottomLeft.renderControls());
    pdiv2.controls.add(rcs.bottomRight.renderControls());
    pdiv2.controls.add(leftBar.renderControls());
    pdiv2.controls.add(leftBar2.renderControls());
    pdiv2.controls.add(rightBar.renderControls());
    pdiv2.controls.add(rightBar2.renderControls());
    pdiv2.controls.add(topBar.renderControls());
    pdiv2.controls.add(topBar2.renderControls());
    pdiv2.controls.add(bottomBar.renderControls());
    pdiv2.controls.add(bottomBar2.renderControls());
    pdiv2.controls.add(pdiv3.renderControls());

    rcs.topLeft.style.left(0);
    rcs.topLeft.style.top(0);
    rcs.topRight.style.left(390);
    rcs.topRight.style.top(0);
    rcs.bottomLeft.style.left(0);
    rcs.bottomLeft.style.top(390);
    rcs.bottomRight.style.left(390);
    rcs.bottomRight.style.top(390);

    return this._outerDiv.renderControls();
}

//************************************************************
//
// RoundedCorner Class
//
//************************************************************
function RoundedCorners(borderColor, backgroundColor) {
    this.BasicObject();
    this.topLeft = new HTMLContainerControl("div");
    this.topRight = new HTMLContainerControl("div");
    this.bottomLeft = new HTMLContainerControl("div");
    this.bottomRight = new HTMLContainerControl("div");

    this.borderColor = borderColor;
    this.backgroundColor = backgroundColor;

    this.initialize();
}
System.Class.Inherits(RoundedCorners, BasicObject);
RoundedCorners.prototype.initialize = function() {
    this.__topLeft();
    this.__topRight();
    this.__bottomLeft();
    this.__bottomRight();
}
RoundedCorners.prototype.__createPixel = function(x, y, color) {
    var pixelDiv = new HTMLContainerControl("div");
    pixelDiv.style.width(1);
    pixelDiv.style.height(1);
    pixelDiv.style.left(x);
    pixelDiv.style.top(y);
    pixelDiv.style.position(Styles.Position.absolute);
    pixelDiv.style.backgroundColor(color);

    return pixelDiv;
}
RoundedCorners.prototype.__topLeft = function() {
    this.topLeft.controls.clear();

    for (var i = 5; i < 10; i++) {
        this.topLeft.controls.add(this.__createPixel(i, 0, this.borderColor));
        this.topLeft.controls.add(this.__createPixel(0, i, this.borderColor));
        for (var j = 1; j < 10; j++) {
            this.topLeft.controls.add(this.__createPixel(j, i, this.backgroundColor));
            this.topLeft.controls.add(this.__createPixel(i, j, this.backgroundColor));
        }
    }
    for (var i = 3; i < 6; i++) {
        this.topLeft.controls.add(this.__createPixel(i, 1, this.borderColor));
        this.topLeft.controls.add(this.__createPixel(1, i, this.borderColor));
        for (var j = 2; j < 10; j++) {
            this.topLeft.controls.add(this.__createPixel(j, i, this.backgroundColor));
            this.topLeft.controls.add(this.__createPixel(i, j, this.backgroundColor));
        }
    }

    this.topLeft.controls.add(this.__createPixel(3, 2, this.borderColor));
    this.topLeft.controls.add(this.__createPixel(2, 2, this.borderColor));
    this.topLeft.controls.add(this.__createPixel(2, 3, this.borderColor));
}
RoundedCorners.prototype.__topRight = function() {
    this.topRight.controls.clear();

    for (var i = 0; i < 5; i++) {
        this.topRight.controls.add(this.__createPixel(i, 0, this.borderColor));
        this.topRight.controls.add(this.__createPixel(9, i + 5, this.borderColor));
        for (var j = 0; j < 9; j++)
            this.topRight.controls.add(this.__createPixel(j, i + 5, this.backgroundColor));
        for (var j = 1; j < 10; j++)
            this.topRight.controls.add(this.__createPixel(i, j, this.backgroundColor));
    }
    for (var i = 3; i < 6; i++) {
        this.topRight.controls.add(this.__createPixel(i + 1, 1, this.borderColor));
        this.topRight.controls.add(this.__createPixel(8, i, this.borderColor));
        for (var j = 0; j < 8; j++)
            this.topRight.controls.add(this.__createPixel(j, i, this.backgroundColor));
        for (var j = 2; j < 10; j++)
            this.topRight.controls.add(this.__createPixel(i, j, this.backgroundColor));
    }
    this.topRight.controls.add(this.__createPixel(6, 2, this.borderColor));
    this.topRight.controls.add(this.__createPixel(7, 2, this.borderColor));
    this.topRight.controls.add(this.__createPixel(7, 3, this.borderColor));
}
RoundedCorners.prototype.__bottomLeft = function() {
    this.bottomLeft.controls.clear();

    for (var i = 0; i < 5; i++) {
        this.bottomLeft.controls.add(this.__createPixel(0, i, this.borderColor));
        this.bottomLeft.controls.add(this.__createPixel(i + 5, 9, this.borderColor));
        for (var j = 0; j < 9; j++)
            this.bottomLeft.controls.add(this.__createPixel(i + 5, j, this.backgroundColor));
        for (var j = 1; j < 10; j++)
            this.bottomLeft.controls.add(this.__createPixel(j, i, this.backgroundColor));
    }
    for (var i = 3; i < 6; i++) {
        this.bottomLeft.controls.add(this.__createPixel(1, i + 1, this.borderColor));
        this.bottomLeft.controls.add(this.__createPixel(i, 8, this.borderColor));
        for (var j = 0; j < 8; j++)
            this.bottomLeft.controls.add(this.__createPixel(i, j, this.backgroundColor));
        for (var j = 2; j < 10; j++)
            this.bottomLeft.controls.add(this.__createPixel(j, i, this.backgroundColor));
    }

    this.bottomLeft.controls.add(this.__createPixel(2, 6, this.borderColor));
    this.bottomLeft.controls.add(this.__createPixel(2, 7, this.borderColor));
    this.bottomLeft.controls.add(this.__createPixel(3, 7, this.borderColor));
}
RoundedCorners.prototype.__bottomRight = function() {

    this.bottomRight.controls.clear();
    for (var i = 0; i < 5; i++) {
        this.bottomRight.controls.add(this.__createPixel(i, 9, this.borderColor));
        this.bottomRight.controls.add(this.__createPixel(9, i, this.borderColor));
        for (var j = 0; j < 9; j++) {
            this.bottomRight.controls.add(this.__createPixel(j, i, this.backgroundColor));
            this.bottomRight.controls.add(this.__createPixel(i, j, this.backgroundColor));
        }
    }
    for (var i = 4; i < 7; i++) {
        this.bottomRight.controls.add(this.__createPixel(i, 8, this.borderColor));
        this.bottomRight.controls.add(this.__createPixel(8, i, this.borderColor));
        for (var j = 0; j < 8; j++) {
            this.bottomRight.controls.add(this.__createPixel(j, i, this.backgroundColor));
            this.bottomRight.controls.add(this.__createPixel(i, j, this.backgroundColor));
        }
    }
    this.bottomRight.controls.add(this.__createPixel(7, 6, this.borderColor));
    this.bottomRight.controls.add(this.__createPixel(7, 7, this.borderColor));
    this.bottomRight.controls.add(this.__createPixel(6, 7, this.borderColor));
}


//************************************************************
//
// TabControl Class
//
//************************************************************
function TabControl(width, height) {
    this.BasicObject();
    this.tabs = new ListObject();
    this._showLabels = false;
    this._labelWidth = 50;
    this._labelHeight = 14;
    this._outerDiv = new HTMLContainerControl("div")
    this._innerDiv = new HTMLContainerControl("div");

    this._outerDiv.style.width(750);
    this._outerDiv.style.width(450);
    if (width)
        this._outerDiv.style.width(width);
    if (height)
        this._outerDiv.style.height(height);

    this._outerDiv.controls.add(this._innerDiv);
    this._innerDiv.style.position(Styles.Position.absolute);
    this._innerDiv.style.borderWidth(1);
    this._innerDiv.style.borderStyle(Styles.BorderStyle.solid);
}
System.Class.Inherits(TabControl, BasicObject);
TabControl.prototype.renderControls = function() {
    if (this.showLabels() == false) {
        this._innerDiv.style.width(this._outerDiv.style.width())
        this._innerDiv.style.height(this._outerDiv.style.height())
    }

    var count = this.tabs.count();
    for (var i = 0; i < count; i++)
        this._innerDiv.controls.add(this.tabs.getAt(i));

    if (count > 0)
        this.showTab(0);

    return this._outerDiv.renderControls();
}
TabControl.prototype.width = function(width) {
    if (width)
        this._width = width;
    return this._width;
}
TabControl.prototype.height = function(height) {
    if (height)
        this._height = height;
    return this._height;
}
TabControl.prototype.labelWidth = function(labelWidth) {
    if (labelWidth)
        this._labelWidth = labelWidth;
    return this._labelWidth;
}
TabControl.prototype.labelHeight = function(labelHeight) {
    if (labelHeight)
        this._labelHeight = labelHeight;
    return this._labelHeight;
}
TabControl.prototype.showLabels = function(showLabels) {
    if (showLabels)
        this._showLabels = showLabels;
    return this._showLabels;
}
TabControl.prototype.x = function(x) {
    if (x)
        this._outerDiv.style.left(x);
    return this._outerDiv.style.left();
}
TabControl.prototype.y = function(y) {
    if (y)
        this._outerDiv.style.left(y);
    return this._outerDiv.style.top();
}
TabControl.prototype.borderColor = function(borderColor) {
    if (borderColor)
        this._innerDiv.style.borderColor(borderColor);
    return this._innerDiv.style.borderColor();
}
TabControl.prototype.showTab = function(index) {
    var count = this.tabs.count();
    for (var i = 0; i < count; i++)
        this.tabs.getAt(i).visible(false);

    this.tabs.getAt(index).visible(true);
}

//************************************************************
//
// Tab Class
//
//************************************************************
function Tab() {
    this.HTMLContainerControl("div");
    this._index = -1;
    this._label = "";
    this.style.position(Styles.Position.absolute);
}
System.Class.Inherits(Tab, HTMLContainerControl);
Tab.prototype.index = function() {
    return this._index;
}
Tab.prototype.label = function(label) {
    if (label)
        this._label = label;

    return this._label;
}


//************************************************************
//
// Image Viewer
//
//************************************************************
function ImageViewer() {
    this._index = -1;
    this.images = new ListObject();
    this._div = new HTMLContainerControl("div");
}
System.Class.Inherits(ImageViewer, BasicObject);
ImageViewer.prototype.visible = function(visible) {
    this._div.visible(visible)
}
ImageViewer.prototype.show = function(index) {
    for (var i = 0; i < this.images.count(); i++) {
        this.images.getAt(i).visible(false);
    }
    if (index > -1 && index < this.images.count()) {
        var me = this;
        var anim = new Animation(me.images.getAt(index));
        if (this.images.getAt(index).isLoaded() == false)
            this.images.getAt(index).onLoadComplete(function() { var left = (me._div.style.width() - me.images.getAt(index).width()) / 2; var top = (me._div.style.height() - me.images.getAt(index).height()) / 2; me.images.getAt(index).style.left(left); me.images.getAt(index).style.top(top); me.images.getAt(index).style.alpha(0); me.images.getAt(index).visible(true); anim.alpha(100); });
        else {
            var left = (this._div.style.width() - this.images.getAt(index).width()) / 2;
            var top = (this._div.style.height() - this.images.getAt(index).height()) / 2;
            this.images.getAt(index).style.left(left);
            this.images.getAt(index).style.top(top);
            this.images.getAt(index).style.alpha(0);
            this.images.getAt(index).visible(true);
            var anim = new Animation(this.images.getAt(index));
            anim.alpha(100);
        }
        this._index = index;
    }
}
ImageViewer.prototype.next = function() {
    if (this._index < this.images.count() - 1)
        this.show(this._index + 1);
}
ImageViewer.prototype.previous = function() {
    if (this._index > 0)
        this.show(this._index - 1);
}
ImageViewer.prototype.position = function(x, y) {
    this._div.style.left(x);
    this._div.style.top(y);
}
ImageViewer.prototype.dimensions = function(w, h) {
    this._div.style.width(w);
    this._div.style.height(h);
}
ImageViewer.prototype.index = function() {
    return this._index;
}
ImageViewer.prototype.remove = function() {
    return this._div.remove();
}
ImageViewer.prototype.renderControls = function() {
    this._div.style.textAlign(Styles.Align.center);
    this._div.style.position(Styles.Position.absolute);

    for (var i = 0; i < this.images.count(); i++) {
        this.images.getAt(i).style.position(Styles.Position.absolute);
        this.images.getAt(i).style.top(0);
        this._div.controls.add(this.images.getAt(i));
    }

    this.show(0);

    return this._div.renderControls();
}

//************************************************************
//
// Page Namespace
//
//************************************************************
Page = function() { }
Page.Disable = function(backgroundColor, doAnimation) {
    var div = new HTMLContainerControl("div");
    var windowWidth = 0;
    var windowHeight = 0;

    if (window.innerWidth == null) {
        //System.Debugger.output(document.documentElement.clientWidth);
        //System.Debugger.output(document.getElementsByTagName('body').item(0).scrollWidth);
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }
    else {
        windowWidth = window.innerWidth;
        windowHeight = window.innerHeight;
    }

    if (windowWidth > document.getElementsByTagName('body').item(0).scrollWidth + 16)
        div.style.width(windowWidth);
    else
        div.style.width(document.getElementsByTagName('body').item(0).scrollWidth + 16);

    if (windowHeight > document.getElementsByTagName('body').item(0).scrollHeight + 16)
        div.style.height(windowHeight);
    else
        div.style.height(document.getElementsByTagName('body').item(0).scrollHeight + 16);

    div.style.position(Styles.Position.absolute);
    div.style.top(0);
    div.style.left(0);
    div.style.backgroundColor(backgroundColor);
    if (doAnimation == true) {
        div.style.alpha(1);
        div.animateAlpha(100);
    }
    document.getElementsByTagName("body")[0].appendChild(div.renderControls());
}


//************************************************************
//
// function InitPage
//
//************************************************************

function InitPage() {
    var table;
    var cellIndex;
    var rowIndex;

    table = new HTMLTable();
    table.cellPadding = 3;
    table.cellSpacing = 1;
    table.style.backgroundColor("rgb(200,200,200)");
    table.style.borderWidth(1);
    table.style.borderColor("#000000");
    table.style.borderStyle(Styles.BorderStyle.solid);
    //table.style.position(Styles.Position.relative);
    table.style.top(0);
    table.style.left(0);

    rowIndex = table.rows.add(new HTMLTableRow());
    cellIndex = table.rows.getAt(rowIndex).cells.add(new HTMLTableCell());
    table.rows.getAt(rowIndex).cells.getAt(cellIndex).controls.add(document.createTextNode("Here"));
    cellIndex = table.rows.getAt(rowIndex).cells.add(new HTMLTableCell());
    table.rows.getAt(rowIndex).cells.getAt(cellIndex).controls.add(document.createTextNode("Here Again"));

    rowIndex = table.rows.add(new HTMLTableRow());
    cellIndex = table.rows.getAt(rowIndex).cells.add(new HTMLTableCell());
    table.rows.getAt(rowIndex).cells.getAt(cellIndex).controls.add(document.createTextNode("Here 2"));
    cellIndex = table.rows.getAt(rowIndex).cells.add(new HTMLTableCell());
    table.rows.getAt(rowIndex).cells.getAt(cellIndex).controls.add(document.createTextNode("Here 2 Again"));

    var textbox = new Textarea();
    textbox.text("here it is");
    textbox.rows = 4;
    textbox.cols = 15;
    textbox.style.borderWidth(4);
    textbox.style.borderColor("#999999");
    textbox.style.borderStyle(Styles.BorderStyle.solid);
    textbox.onMouseOver(function() { textbox.style.borderWidth(4); });
    textbox.onMouseOut(function() { textbox.style.borderWidth(1); });
    table.rows.getAt(rowIndex).cells.getAt(cellIndex).controls.add(textbox);

    var div = new HTMLContainerControl("div");
    div.style.width(400);
    div.style.height(50);
    div.style.position(Styles.Position.absolute);
    div.style.top(100);
    div.style.left(400);
    div.style.backgroundColor("#999999");
    div.style.alpha(100);
    div.style.fontSize(25);
    div.style.borderWidth(1);
    div.style.borderStyle(Styles.BorderStyle.solid);
    div.style.borderColor("#000000");
    div.style.cursor(Styles.Cursor.pointer);
    div.style.overflow(Styles.Overflow.hidden);
    var divAnim1 = new Animation(div);
    divAnim1.animationEase(3);
    //div.onMouseOver(function(){divAnim1.property("borderWidth", 35);})
    //div.onMouseOut(function(){divAnim1.property("borderWidth", 1);})
    //div.onClick(function(){textbox.visible(false);})
    //div.onDoubleClick(function(){textbox.visible(true);})
    div.controls.add(document.createTextNode("test"));

    textbox.onFocus(function() { div.style.borderWidth(0); })
    textbox.onFocus(function() { div.animateAlpha(0); })
    textbox.onFocus(function() { div.animateSize(-400, -50, false); })
    textbox.onFocus(function() { div.animatePosition(100, 25, false); })
    textbox.onFocus(function() { div.animateProperty("fontSize", 0); })

    textbox.onBlur(function() { div.style.borderWidth(1); })
    textbox.onBlur(function() { div.animateAlpha(100); })
    textbox.onBlur(function() { div.animateSize(400, 50, false); })
    textbox.onBlur(function() { div.animatePosition(-100, -25, false); })
    textbox.onBlur(function() { div.animateProperty("fontSize", 25); })


    var image = new HTMLImage();
    var imgAnim = new Animation(image);
    image.url("http://www.sacredintent.com/dev/v4/images/menuHome.gif");
    image.style.borderColor("#999999");
    image.style.borderStyle(Styles.BorderStyle.solid);
    image.style.borderWidth(1);
    image.style.alpha(25);
    image.style.position(Styles.Position.absolute);
    image.style.top(300);
    image.style.left(300);
    image.onMouseOver(function() { imgAnim.alpha(100); })
    image.onMouseOut(function() { imgAnim.alpha(25); })

    var checkbox = new HTMLCheckbox();
    checkbox.onMouseOver(function() { checkbox.checked(true); })
    checkbox.onMouseOut(function() { checkbox.checked(false); })

    var rp = new RoundedPanel(400, 400, "#DDDDDD", "#999999")

    var button = new HTMLButton();
    button.text("Click Here to Disable Page");
    button.onClick(function() { Page.Disable("#FFFFFF", true); });

    tab1 = new TabControl(800, 600);
    tab1.showLabels(false);
    tab1.borderColor("#999999");

    tab1.tabs.add(new Tab());
    tab1.tabs.add(new Tab());
    tab1.tabs.add(new Tab());

    tab1.tabs.getAt(0).controls.add(document.createTextNode("This is a test"));
    tab1.tabs.getAt(1).controls.add(document.createTextNode("This is a test 2"));
    //tab1.tabs.getAt(1);

    var btn1 = new HTMLButton();
    var btn2 = new HTMLButton();

    btn1.text("Tab1");
    btn2.text("Tab2");

    btn1.onClick(function() { tab1.showTab(0); });
    btn2.onClick(AddTabContent);

    var divPage = document.getElementById('divPage');
    divPage.appendChild(table.renderControls());
    divPage.appendChild(div.renderControls());
    divPage.appendChild(image.getElement());
    divPage.appendChild(checkbox.getElement());
    divPage.appendChild(rp.renderControls());
    divPage.appendChild(button.getElement());
    divPage.appendChild(btn1.getElement());
    divPage.appendChild(btn2.getElement());
    //divPage.appendChild(tab1.renderControls());
    tab1.showTab(0);
    //div.isDraggable(true);

    table.visible(false);
    //div.visible(false);
    image.visible(false);
    rp.visible(false);


    //System.Debugger.output(rp.toJSONString());
    //var testObj = rp.toJSONString().parseJSON();
    //System.Debugger.output(testObj.toJSONString()); 
}

function AddTabContent() {
    reqObj = new Request("test.html", TabLoad, TabComplete, TabError);
    reqObj.loadHTML();
}
function TabLoad() {
    System.Debugger.output("Loading");
}
function TabComplete() {
    System.Debugger.output("Completed");
    tab1.showTab(1);
    System.Debugger.output("HTML: " + reqObj.html());
    tab1.tabs.getAt(1).innerHTML(reqObj.html());
}
function TabError() {
    System.Debugger.output("Error");
}




