
var m_uiGenerator = new uiGenerator();
var m_uiUtil = new uiUtil();


function uiUtil() //class
{
    function uiPoint(x, y)
    {
        this.x = x;
        this.y = y;
    }

    this.getAbsolutePosition = function(obj, stopOnAbsolutelyPosParent)
    {
        var d = new uiPoint;
        d.x = 0;
        d.y = 0;

        if (stopOnAbsolutelyPosParent == null)
            stopOnAbsolutelyPosParent = true;

        while (obj != null && (!stopOnAbsolutelyPosParent || obj.style.position != 'absolute') && obj.tagName.toLowerCase() != 'body' && obj.tagName.toLowerCase() != 'html')
        {
            d.x += obj.offsetLeft;
            d.y += obj.offsetTop;
            obj = obj.offsetParent;
        }

        return d;
    }
    
    this.getParentNodeByTagName = function(obj, parentTagName)
    {
        if (obj == null || obj.parentNode == null || obj.tagName == null)
            return null;
        if (obj.tagName.toLowerCase() == parentTagName.toLowerCase())
            return obj;
        return m_uiUtil.getParentNodeByTagName(obj.parentNode, parentTagName);
    }   
    
    this.isChild = function(objParent, objChild)
    {
        while (objChild != null && objChild != objParent)
            objChild = objChild.parentNode;
        
        return (objChild != null);    
    }

    this.setDisplay = function(objOrID, boolCondition)
    {
        if ((typeof(objOrID)).toLowerCase() == 'string')
            objOrID = document.getElementById(objOrID);
            
        if (objOrID == null)
            return;
    
        objOrID.style.display = boolCondition ? '' : 'none';
    }
    
    this.setClassName = function (objOrID, className)
    {
        if ((typeof(objOrID)).toLowerCase() == 'string')
            objOrID = document.getElementById(objOrID);
        if (objOrID == null)
            return;
        
        objOrID.className = className;
    }
    
    this.setStyle = function (objOrID, propertyName, propertyValue)
    {
        if ((typeof(objOrID)).toLowerCase() == 'string')
            objOrID = document.getElementById(objOrID);
        if (objOrID == null)
            return;
        
        if (m_bIsFirefox)
            objOrID.style.setProperty(propertyName, propertyValue, null);
        else
            objOrID.style[propertyName] = propertyValue;
    }

    this.setAttributeValue = function (objOrID, attr, value)
    {
        if ((typeof(objOrID)).toLowerCase() == 'string')
            objOrID = document.getElementById(objOrID);
        if (objOrID == null)
            return;
        
        objOrID.setAttribute(attr, value);
    }
    
    this.getClassIcon = function(ClassID)
    {
        switch (ClassID)
        {
            case (701000000):
                return 'IconArrow2_b.gif';                      //site
            case (702000000):
                return 'IconArrow1_b.gif';                      //search ring
            case (703000000):
                return 'iconscheduleselm.gif';                  //schedule
            case (705000000):
                return 'icons/gif_grey/error.gif';              //incident
            case (706000000):
                return 'icons/gif_grey/calendar_view_day.gif';  //event
            case (711000000):
                return 'icons/gif_grey/cog.gif';                //asset
            case (713000000):
                if (m_PageID == 713030300 && m_bIsPhotoLib)
                    return 'icons/gif_grey/folder_picture.gif'; //photo library
                return 'icons/gif_grey/folder_page.gif';             //library
            case (716000000):
                return 'icons/gif_grey/script.gif';             //lease
            case (723000000):
                return 'icons/gif_grey/money.gif';              //payment
            case (727000000):
                return 'icons/gif/vcard.gif';                   //vendor
            
        }
        return null;
    } 
}


function uiGenerator() //class
{
    var iconPath = 'skins/common/images/icons/gif_buttons_solid/';
    var iconHeight = 16;
    var iconWidth = 16;
    
    this.convertToHTML = function(obj)
    {
        var oContainer = document.createElement("div");
        oContainer.appendChild(obj);        
        return oContainer.innerHTML;    
    }    
    
    this.getAttribute = function(name, value)
    {
        var a = document.createAttribute(name);
        a.value = value;
        return a;
    }
    
    
    this.attachEvent = function(obj, eventName, handler, retVal)
    {
        obj.attachEvent(eventName, this.getFunctionPointer(handler, retVal));
        var xx = document.createAttribute(eventName);
	    xx.value = handler + ";return " + (retVal == null ? false : retVal) + ";";
	    obj.attributes.setNamedItem(xx);
    }
    
    this.getFunctionPointer = function(f, retVal)
    {
        if (retVal == null )
            retVal = false;
        if (typeof(f) == 'function')
            return f;
        else
            return function() {
                eval(f);
                return retVal;
            }
    }
    
    //--------BUTTON---------------BUTTON---------------BUTTON-------
    //      toggle state - null=not a toggle, true=on, false=shoot the hostage
    
    this.getButtonHTML = function(text, id, action, tooltip, icon, style, cssClass, toggleState)
    {        
        return this.convertToHTML(this.getButton(text, id, action, tooltip, icon, style, cssClass, toggleState));
    }

    this.getButton = function(text, id, action, tooltip, icon, style, cssClass, toggleState)
    {
        var btn = new this.Button();
        btn.text = text;
        btn.id = id;
        btn.action = action;
        btn.tooltip = tooltip;
        btn.icon = icon;
        btn.style = style;
        btn.cssClass = cssClass;
        btn.toggleState = toggleState;
        
		return btn.toObject();
    }
    
    
    this.Button = function() //class
    {
        this.text = null
        this.id = null;
        this.action = null;
        this.tooltip = null;
        this.icon = null;
        this.style = null;
        this.cssClass = 'Button';
        this.toggleState = null;
        
        
        this.toObject = function()
        {
            var iconStyle = '';
            if (this.text == null)
            {
                this.text = '';
                iconStyle = 'margin-right:0px;';
            }
            if (this.tooltip == null || this.tooltip == '')
                this.tooltip = this.text.replace(/&#160;/, ' ');
            if (this.cssClass == null || this.cssClass == '')
                this.cssClass = "Button";
            
            oBtn = document.createElement("A");
            oBtn.href = "#";
		    if (this.id != null)
		        oBtn.id = this.id;
		        
		        
		    oBtn.className = this.cssClass;
		    if (this.style != null && this.style != '')
		        oBtn.style.cssText = this.style;
    		if (this.action == null)
    		    this.action = '';
    		
    		if (this.toggleState != null)
    		{
    		    this.action += ';m_uiGenerator.toggleButton();';
    		    m_uiGenerator.toggleButton(oBtn, this.toggleState);
    		}
		    
		    m_uiGenerator.attachEvent(oBtn, 'onclick', this.action);
    		
		    oBtn.title = this.tooltip;		
    		
		    if (this.icon != null && this.icon != '')
                this.text = '<img src="' + iconPath + this.icon + '" height="' + iconHeight + '" width="' + iconWidth + '" style="' + iconStyle + '" />' + this.text;
		    oBtn.icon = iconPath + this.icon;
		    
		    oBtn.innerHTML = this.text;		
    		
		    return oBtn;
        }
    }
    
    this.toggleButton = function(btnObj, forceState)
    {
        if (btnObj == null)
            if (event != null && event.srcElement != null)
            {
                btnObj = event.srcElement;
                while (btnObj != null && btnObj.toggleState == null)
                    btnObj = btnObj.parentNode;
            }
        if (btnObj == null)
            return;
                    
        if (forceState == null)
            forceState = !btnObj.toggleState;
        
        btnObj.toggleState = forceState;
        if (forceState)
        {
            btnObj.style.border = '1px solid #666666';
            btnObj.style.padding = '0px';
        }
        else
        {
            btnObj.style.border = '';
            btnObj.style.padding = '1px';
        }
    }
    
    
    
    //--------TEXTBOX---------------TEXTBOX---------------TEXTBOX-------
    
    this.getTextboxHTML = function(id, value, size, rows, style, cssClass, onchangeJS, maxlength)
    {
        return this.convertToHTML(this.getTextbox(id, value, size, rows, style, cssClass, onchangeJS, maxlength));
    }
    
    this.getTextbox = function(id, value, size, rows, style, cssClass, onchangeJS, maxlength)
    {
        var txtBx = new this.Textbox();
        txtBx.id = id;
        txtBx.value = value;
        txtBx.size = size;
        txtBx.rows = rows;
        txtBx.style = style;
        txtBx.cssClass = cssClass;
        txtBx.onchange = onchangeJS;
        txtBx.maxLength = maxlength;
        
        return txtBx.toObject();
    }
    
    this.Textbox = function() //class
    {
        this.id = null;
        this.value = null;
        this.size = null;
        this.rows = 1; //1 = textbox, >1 = textarea
        this.style = null;
        this.cssClass = null;
        this.onchange = null;
        this.maxLength = null;
        
        this.toObject = function()
        {
            var tb;
            
            if (this.value == null)
                this.value = '';
            
            if (this.rows == null || this.rows == 1)
            {
                tb = document.createElement('input');
                tb.type = 'text';
                tb.setAttribute('value', this.value);
                
                if (this.size != null)
                    tb.size = this.size;
            }
            else
            {
                tb = document.createElement('textarea');
                tb.innerHTML = this.value;
                tb.rows = this.rows;
                tb.cols = this.size;
            }
            tb.id = this.id;
            
            if (this.style != null)
                tb.style.cssText = this.style;
            if (this.cssClass != null)
                tb.className = this.cssClass;
            if (this.onchange != null)
                m_uiGenerator.attachEvent(tb, 'onchange', this.onchange);
            if (this.maxLength != null)
                tb.maxLength = this.maxLength;
                
            return tb;            
        }        
                
    }
    
    //--------span---------------span---------------span-------
    
    this.getSpanHTML = function(id, sHtml, style)
    {
        return this.convertToHTML(this.getSpan(id, sHtml, style));
    }
    
    this.getSpan = function(id, sHtml, style)
    {
        var oSpan = new this.Span();
        oSpan.id = id;
        oSpan.sHtml = sHtml;
        oSpan.style = style;
        
        return oSpan.toObject();
    }
    
    this.Span = function() //class
    {
        this.id = null;
        this.sHtml = null;
        this.style = null;
        
        this.toObject = function()
        {
            var s;
            
            if (this.sHtml == null)
                this.sHtml = '';
            
            s = document.createElement('span');
            s.innerHTML = this.sHtml;
            s.setAttribute('style', this.style);
            s.id = this.id;
            
            
            return s;            
        }        
                
    }
    
    
    //--------HIDDEN---------------HIDDEN---------------HIDDEN-------
    
    this.getHiddenHTML = function(id, value, onchangeJS)
    {
        return this.convertToHTML(this.getHidden(id, value, onchangeJS));
    }
    
    this.getHidden = function(id, value, onchangeJS)
    {
        var oHidden = new this.Hidden();
        oHidden.id = id;
        oHidden.value = value;
        oHidden.onchange = onchangeJS;
        
        return oHidden.toObject();
    }
    
    this.Hidden = function() //class
    {
        this.id = null;
        this.value = null;
        this.onchange = null;
        
        this.toObject = function()
        {
            var h;
            
            if (this.value == null)
                this.value = '';
            
            h = document.createElement('input');
            h.type = 'hidden';
            h.setAttribute('value', this.value);
            h.id = this.id;
            
            if (this.onchange != null)
                m_uiGenerator.attachEvent(h, 'onchange', this.onchange);
          
            return h;            
        }        
                
    }
    
    //--------RADIO---------------RADIO---------------RADIO-------
    this.getRadioHTML = function(id, name, isChecked, style, cssClass, onclickJS)
    {
        return this.convertToHTML(this.getRadio(id, name, isChecked, style, cssClass, onclickJS));
    }
    
    this.getRadio = function(id, name, isChecked, style, cssClass, onclickJS)
    {
        var rb = new this.Radio();
        rb.id = id;
        rb.name = name;
        rb.isChecked = isChecked;
        rb.style = style;
        rb.cssClass = cssClass;
        rb.onclick = onclickJS;
        
        return rb.toObject();
    }
    
    this.Radio = function() //class
    {
        this.id = null;
        this.name = null;
        this.isChecked = false;
        this.style = null;
        this.cssClass = null;
        this.onclick = null;
    
        this.toObject = function()
        {
            var rad;
            
            try
            {
                var html = '<input type="radio" name="' + this.name + '" />';
                rad = document.createElement(html);
            }
            catch (e)
            {
                rad = document.createElement('input');
                rad.attributes.setNamedItem(m_uiGenerator.getAttribute('name', this.name));
                rad.type = 'radio';
            }
            
            rad.id = this.id;
            
                        
            if (this.style != null)
                rad.style.cssText = this.style;
            if (this.cssClass != null)
                rad.className = this.cssClass;
            
            if (this.onclick != null)
                m_uiGenerator.attachEvent(rad, 'onclick', this.onclick, true);
            
            
            if (this.isChecked != null && (this.isChecked == true || this.isChecked == '1'))
            {
                rad.attributes.setNamedItem(m_uiGenerator.getAttribute('checked',1));
                rad.attributes.setNamedItem(m_uiGenerator.getAttribute('orgValue',1));
            }
            
            return rad;            
        }
    }
    
    
    
    
    //--------CHECKBOX---------------CHECKBOX---------------CHECKBOX-------
    
    
    this.getCheckboxHTML = function(id, isChecked, style, cssClass, onclickJS)
    {
        return this.convertToHTML(this.getCheckbox(id, isChecked, style, cssClass, onclickJS));
    }
    
    this.getCheckbox = function(id, isChecked, style, cssClass, onclickJS)
    {
        var cb = new this.Checkbox();
        cb.id = id;
        cb.isChecked = isChecked;
        cb.style = style;
        cb.cssClass = cssClass;
        cb.onclick = onclickJS;
        
        return cb.toObject();
    }
    
    this.Checkbox = function() //class
    {
        this.id = null;
        this.isChecked = false;
        this.style = null;
        this.cssClass = null;
        this.onclick = null;
        
        this.toObject = function()
        {
            var cbox = document.createElement('input');
            cbox.type = 'checkbox';
            cbox.id = this.id;
                        
            if (this.style != null)
                cbox.style.cssText = this.style;
            if (this.cssClass != null)
                cbox.className = this.cssClass;
            
            if (this.onclick != null)
            m_uiGenerator.attachEvent(cbox, 'onclick', this.onclick, true);
            
            
            if (this.isChecked != null && (this.isChecked == true || this.isChecked == '1'))
            {
                cbox.attributes.setNamedItem(m_uiGenerator.getAttribute('checked',1));
                cbox.attributes.setNamedItem(m_uiGenerator.getAttribute('orgValue',1));
            }
            
            return cbox;
        }      
                
    }
    
    //--------LINK---------------LINK---------------LINK-------
    
    this.getLinkHTML = function(text, url, id, style, cssClass, onclickJS)
    {
        return this.convertToHTML(this.getLabel(text, url, id, style, cssClass, onclickJS));
    }
    
    this.getLink = function(text, url, id, style, cssClass, onclickJS)
    {
        var link = new this.Link();
        link.text = text;
        link.url = url;
        link.id = id;
        link.style = style;
        link.cssClass = cssClass;
        link.onclick = onclickJS;
        return link.toObject();
    }
    
    this.Link = function()
    {
        this.text = '';
        this.url = null;
        this.id = null;
        this.style = null;
        this.cssClass = null;
        this.onclick = null;
        
        this.toObject = function()
        {
            var link = document.createElement('a');
            link.innerHTML = this.text;
            if (this.id != null)
                link.id = this.id;
            if (this.url != null)
                link.href = this.url;
            else
                link.href = '#';
                
            if (this.style != null)
                link.style.cssText = this.style;
            if (this.cssClass != null)
                link.className = this.cssClass;
            
            if (this.onclick != null)
            m_uiGenerator.attachEvent(link, 'onclick', this.onclick, (this.url != null));
            
            
            return link;
        }
    }
    
    
    
    //--------LABEL---------------LABEL---------------LABEL-------
    
    this.getLabelHTML = function(text, forID, id, style, cssClass)
    {
        return this.convertToHTML(this.getLabel(text, forID, id, style, cssClass));
    }
    
    this.getLabel = function(text, forID, id, style, cssClass)
    {
        var lbl = new this.Label();
        lbl.text = text;
        lbl.forID = forID;
        lbl.id = id;
        lbl.style = style;
        lbl.cssClass = cssClass;
        return lbl.toObject();
    }
    
    this.Label = function()
    {
        this.text = '';
        this.forID = null;
        this.id = null;
        this.style = null;
        this.cssClass = null;
        
        this.toObject = function()
        {
            var lbl = document.createElement('label');
            lbl.innerHTML = this.text;
            if (this.id != null)
                lbl.id = this.id;
            if (this.forID != null)
                lbl.htmlFor = this.forID;
            if (this.style != null)
                lbl.style.cssText = this.style;
            if (this.cssClass != null)
                lbl.className = this.cssClass;
            
            return lbl;
        }
    }
    
    
    //--------SELECT----------------SELECT----------------SELECT--------    
    
    
    this.getSelectHTML = function(id, aNameValues, selectedValue, rows, style, cssClass, onchangeJS)
    {
        return this.convertToHTML(this.getSelect(id, aNameValues, selectedValue, rows, style, cssClass, onchangeJS));
    }
    
    this.getSelect = function(id, aNameValues, selectedValue, rows, style, cssClass, onchangeJS)
    {
        var dd = new this.Select();
        dd.id = id;
        dd.aNameValues = aNameValues;
        dd.selectedValue = selectedValue;
        dd.rows = rows;
        dd.style = style;
        dd.cssClass = cssClass;
        dd.onchange = onchangeJS;
        
        return dd.toObject();
    }
    
    this.Select = function() //class
    {
        this.id = null;
        this.aNameValues = null;
        this.selectedValue = null;
        this.rows = 1;
        this.style = null;
        this.cssClass = null;
        this.onchange = null;
        
        this.toObject = function()
        {
            var dd = document.createElement('select');
            dd.id = this.id;
                        
            if (this.style != null)
                dd.style.cssText = this.style;
            if (this.cssClass != null)
                dd.className = this.cssClass;
            
            if (this.rows != null && this.rows > 1)
            {
                dd.multiple = true;
                dd.size = this.rows;
            }
            
            if (this.onchange != null)
                m_uiGenerator.attachEvent(dd, 'onchange', this.onchange);
            
            m_uiGenerator.fillSelect(dd, this.aNameValues, this.selectedValue);
                      
            return dd;
        }
        
                
    }
    
    this.fillSelect = function(objSelect, aNameValues, selectedValue)
    {
        var nameValueType = '';
        objSelect.options.length = 0;
        
        if (aNameValues != null && aNameValues.length > 0)
            for (var i = 0; i < aNameValues.length; i++)
            {
                var opt = this.getOption(aNameValues[i], this.getNameValueType(aNameValues[i]));
                if (selectedValue != null && opt.value == selectedValue)
                    opt.setAttribute('selected', 1)
                objSelect.options.add(opt);
            }
    }
    
    this.getOption = function(item, nameValueType)
    {
        switch (nameValueType)
        {
            case 'custom':
                return item.ToOption();
            case 'argument':
                return new Option(item.getName(), item.getValue());
            case 'NameValue':
                return new Option(item.Name, item.Value);
            case 'Option':
                return item; //.cloneNode(true);
                //return new Option(item.innerHTML == '' ? item.text : item.innerHTML, item.value);
            default:
                return new Option('Unknown array type');
        }
    }
    
    this.getNameValueType = function(item)
    {
        if (typeof(item.ToOption) == 'function')
            return 'custom';
        if (typeof(item.getName) == 'function' && typeof(item.getValue) == 'function')
            return 'argument';
        if (typeof(item.Name) == 'string' && typeof(item.Value) == 'string')
            return 'NameValue';
        if (typeof(item.Name) == 'string' && typeof(item.Value) == 'number')
            return 'NameValue';
        if (typeof(item.innerHTML) == 'string' && typeof(item.value) == 'string')
            return 'Option';
    }
    
    this.getOptionTextByValue = function(objSelect, value, defaultText)
    {
        for (var i = 0; i < objSelect.options.length; i++)
            if (objSelect.options[i].value == value)
                return objSelect.options[i].innerHTML;
        return defaultText;
    }
    
    
    //--------AUTOCOMPLETING COMBO-----------AUTOCOMPLETING COMBO-------
    
    
    this.getAutocompleteHTML = function(id, aNameValues, selectedValue, selectedText, autocompleteClassID, autocompleteMethod, autocompleteParameters, allowNew, style, cssClass, onchangeJS)
    {
        return this.convertToHTML(this.getAutocomplete(id, aNameValues, selectedValue, selectedText, autocompleteClassID, autocompleteMethod, autocompleteParameters, allowNew, style, cssClass, onchangeJS));
    }
    
    this.getAutocomplete = function(id, aNameValues, selectedValue, selectedText, autocompleteClassID, autocompleteMethod, autocompleteParameters, allowNew, style, cssClass, onchangeJS)
    {
        var ac = new this.Autocomplete();
        ac.id = id;
        ac.aNameValues = aNameValues;
        ac.selectedValue = selectedValue;
        ac.selectedText = selectedText;
        ac.autocompleteClassID = autocompleteClassID;
        ac.autocompleteMethod = autocompleteMethod;
        ac.autocompleteParameters = autocompleteParameters;
        ac.allowNew = allowNew;
        ac.style = style;
        ac.cssClass = cssClass;
        ac.onchange = onchangeJS;
        
        return ac.toObject();
    }
    
    
    this.Autocomplete = function () //class
    {
        this.id = null;
        this.aNameValues = null;        //initial dropdown values
        this.selectedValue = null; 
        this.selectedText = null;
        
        this.autocompleteClassID = null;
        this.autocompleteMethod = null;     //action number for old-style classes
        this.autocompleteParameters = null; //param array        
                                            // Current autocomplete text will be appended 
                                            // as parameter named 'autocomplete'
                                            // Response is expected as standard arguments xml.
                                      
        this.autocompleteThreshhold = 2; //number of characters before server call
        
        this.allowNew = false; //allow new entries?
        
        this.style = null;
        this.cssClass = null;
        this.onchange = null;
        
        this.toObject = function()
        {
            //returns div
            var acDiv = document.createElement('DIV');
            acDiv.id = this.id;
            
            //var oResponse = sendThroughBroker(LEASE_CLASS_ID, 7, oParameters);		
		    //var bResult = genHandleResponse(oResponse);
            
            if (this.style != null)
                acDiv.style.cssText = this.style;
            if (this.cssClass == null)
                this.cssClass = 'AutoComplete';
            acDiv.className = this.cssClass;
            
            
            var dd = m_uiGenerator.getSelect(this.id + '_dd', null, null, 1, this.style, this.cssClass);
            dd.attachEvent('onclick', m_uiGenerator.getFunctionPointer('m_uiGenerator.AC_show("' + this.id + '")'));
            dd.onclick = 'm_uiGenerator.AC_show("' + this.id + '")';
            
            dd.onmouseout = 'm_uiGenerator.AC_hide("' + this.id + '")';
            
            acDiv.appendChild(dd);
            
            var tb = m_uiGenerator.getTextbox(this.id + '_tb', this.selectedText);
            tb.style.position = 'absolute';
            tb.style.top = '2px';
            tb.style.left = '2px';
            tb.style.border = '0px';
            tb.style.width = (new Number(acDiv.style.width.replace(/px/g,'')) - 20) + 'px';
            tb.style.backgroundColor = 'white';
            
            tb.onclick = 'm_uiGenerator.AC_hide("' + this.id + '")';
            
            acDiv.appendChild(tb);
            
            
            var ld = document.createElement('div');
            ld.id = this.id + '_ld';
            ld.style.position = 'absolute';
            ld.style.display = 'none';
            
            ld.style.top = '20px';
            ld.style.left = '0px';
            
            ld.style.width = (new Number(acDiv.style.width.replace(/px/g,''))) + 'px';
            ld.style.height = '150px';
            
            ld.style.overflowX = 'hidden';
            ld.style.overflowY = 'auto';
            ld.style.border = '1px solid #888888';
            ld.style.background = 'white';
            ld.style.paddingLeft = '2px';
            
            ld.onmouseout = 'm_uiGenerator.AC_hide("' + this.id + '")';
            
            for (var i = 0; i < this.aNameValues.length; i++)
                ld.appendChild(m_uiGenerator.AC_getOption(this.id, this.aNameValues[i], m_uiGenerator.getNameValueType(this.aNameValues[i])));
            
            acDiv.appendChild(ld);
            
            
            return acDiv;        
        }        
    }
    
    this.AC_getOption = function(id, item, nameValueType)
    {  
        var a = document.createElement('a');
        a.href = '#';
        a.onclick = 'm_uiGenerator.AC_setValue("' + id + '");return false;';
        switch (nameValueType)
        {
            case 'argument':
                a.innerHTML = item.getName();
                a.value = item.getValue();
                return a;
            case 'NameValue':
                a.innerHTML = item.Name;
                a.value = item.Value;
                return a;
            case 'Option':
                a.innerHTML = item.innerHTML;
                a.value = item.value;
                return a;
            default:
                a.innerHTML = 'Unknown array type';
                return a;
        }
    }
    
    this.AC_setValue = function (id)
    {
        var a = event.srcElement;
        var ac = document.getElementById(id);
        var tb = document.getElementById(id + '_tb');
        var ld = document.getElementById(id + '_ld'); 
        
        if (a == null || ac == null || tb == null || ld == null)
            return;
        
        ac.selectedValue = a.value;
        ac.selectedText = a.innerHTML;
        tb.value = a.innerHTML;
        ld.style.display = "none";
    }
    
    this.AC_show = function(id)
    {
        var ld = document.getElementById(id + '_ld'); 
        if (ld == null)
            return;
        ld.style.display = "inline"; 
        ld.focus();
    }
    
    this.AC_hide = function(id)
    {
        var ld = document.getElementById(id + '_ld'); 
        if (ld == null)
            return;
            
        var te = event.toElement;
        if (te != null)
            while (te != null)
            {
                if (te.id.slice(0, id.length) == id)
                    return;
                te = te.parentNode;
            }
        
        ld.style.display = "none";
    }    
        
    
    
    //--------SECTION---------------SECTION---------------SECTION-------
    
    
    this.getSectionHTML = function(title, id)
    {
        return this.convertToHTML(this.getSection(title, id));
    }
    
    this.getSection = function(title, id)
    {
        var sec = new this.Section();
        sec.title = title;
        sec.id = id;
        return sec.toObject();
    }

    this.Section = function() //class
    {
        this.id = null;
        this.caption = null;
        this.title = null;
        this.icon = null;
        this.iconID = null;
        this.iconTitle = null;
        
        this.headerContent = null;
        this.ToolbarContentLeft = null;
        this.ToolbarContentRight = null;
        this.content = null;
        
        
        this.toObject = function()
        {
            var div, tbl, tr, td;
            while (this.id == null)
            {
                this.id = Math.round(Math.random() * 1000000);
                if (document.getElementById('DataDiv' + this.id) != null)
                    this.id = null;
            }
            
            if (this.content == null)
                this.content = '';
            
            var sectionDiv = document.createElement('div');
            sectionDiv.id = this.id;
            
            div = document.createElement('div');
            div.className = 'SectionHeaderDiv';
            div.innerHTML = '<img src="skins/common/images/rc/grey_tl.gif"/>';
            sectionDiv.appendChild(div);
            
            div = document.createElement('div');
            div.className = 'roundedC_header';
            
            tbl = document.createElement('table');
            tbl.id = 'DivBar' + this.id;
            tbl.border = 0;
            tbl.width = '100%';
            tbl.cellSpacing = 0;
            tbl.cellPadding = 0;
            tbl.className = 'SectionHeader';
            tbl.title = this.title;
            
            tr = tbl.insertRow(-1);
            tr.id = 'SectionHeader' + this.id;
            tr.sectionID = this.id;
            tr.style.cursor = 'pointer';
            tr.attachEvent('onclick', HandleDataDiv); // = 'HandleDataDiv("' + this.id + '","");';
            
            td = tr.insertCell(-1);
            td.style.letterSpacing = '1px';
            td.style.fontWeight = 'bold';
            td.innerHTML = '<nobr>&#160;<label id="SectionTitle' + this.id + '">' + this.title + "</label></nobr>";
            
            td = tr.insertCell(-1);
            td.style.width = '100%';
            td.style.textAlign = 'right';
            td.innerHTML = '<IMG style="cursor:pointer;" border="0" id="ExpandBarImage' + this.id + '" src="skins/common/images/expand.gif?v=2.0.01" onclick="" title="Expand / Collapse"/>';
            
            div.appendChild(tbl);            
            sectionDiv.appendChild(div);
            
            if (this.ToolbarContentRight != null || this.ToolbarContentLeft != null)
            {
                div = document.createElement('div');
                div.className = 'SectionToolbar';
                if (this.ToolbarContentRight != null)
                    div.innerHTML = '<span style="float:right;">' + this.ToolbarContentRight + '</span>';
                if (this.ToolbarContentLeft != null)
                    div.innerHTML += this.ToolbarContentLeft;
                sectionDiv.appendChild(div);
            }
            
            div = document.createElement('div');
            div.id = 'DataDivContainer' + this.id;
            div.className = 'roundedC_content';
            
            var div2 = document.createElement('div');
            div2.id = 'DataDiv' + this.id;
            div2.style.width = '100%';
            div2.innerHTML = this.content;
            
            div.appendChild(div2);            
            sectionDiv.appendChild(div);
            
            
            div = document.createElement('div');
            div.className = 'SectionFooterDiv';
            div.innerHTML = '<img src="skins/common/images/rc/grey_bl.gif"/>';
            sectionDiv.appendChild(div);
            
            
            return sectionDiv;
        
        }
        
        
    }
    
    this.getSectionToolbarDividerHTML = function()
    {
        return '<span style="height:20px;margin-right:4px;margin-bottom:4px;border-right:2px inset white;">&#160;</span>';
    }
    
    
       
    
    
    this.getRequiredHTML = function(isRequired)
    {
        if (isRequired == null || isRequired)
            return "<font color='red' size='4'>*</font>&#160;";
        return "";
    }
    
    
    this.getTableCellHTML = function(text, id, colSpan, rowSpan, style, cssClass)
    {
        return this.convertToHTML(this.getTableCell(text, id, colSpan, rowSpan, style, cssClass));
    }
    
    this.getTableCell = function(text, id, colSpan, rowSpan, style, cssClass)
    {
        var tc = new this.TableCell();
        tc.text = text;
        tc.id = id;
        tc.colSpan = colSpan;
        tc.rowSpan = rowSpan;
        tc.style = style;
        tc.cssClass = cssClass;
        return tc.toObject();
        
    }
    
    this.TableCell = function()
    {
        this.text = '';
        this.id = null;
        this.colSpan = 1;
        this.rowSpan = 1;
        this.style = null
        this.cssClass = null;
        
        this.toObject = function()
        {
            var td = document.createElement('td');
            td.innerHTML = this.text;
            td.colSpan = (this.colSpan == null ? 1 : this.colSpan);
            td.rowSpan = (this.rowSpan == null ? 1: this.rowSpan);
            if (this.id != null)
                td.id = this.id;
            if (this.style != null)
                td.style.cssText = this.style;
            if (this.cssClass != null)
                td.className = this.cssClass;
                        
            return td;        
        }
    }
    
    
    
    
   
    //--------UPLOAD---------------UPLOAD---------------UPLOAD-------
    
    this.getUploadHTML = function(onFileSelectJS)
    {
         return this.convertToHTML(this.getUpload(onFileSelectJS));
    }
    
    this.getUpload = function(onFileSelectJS)
    {
        var u = new this.Upload();
        u.onFileSelectJS = onFileSelectJS;
        u.eliminateDuplicateFrames();
        return u.toObject();
    } 
    
    this.Upload = function()
    {
        this.onFileSelectJS = '';
        this.id = 'UploadFrame';
        
        this.eliminateDuplicateFrames = function()
        {
            if (document.getElementById('uifc_' + this.id) != null)
                document.getElementById('uifc_' + this.id).removeNode(true);            
        }
        
        this.toObject = function()
        {
            var s = document.createElement('span');
            s.id = 'uifc_' + this.id;
            s.className = 'uploadIFrameContainer';
            
            var ifr = document.createElement('iframe');
            ifr.src = "infrastructures/filesupload/doupload2.aspx?onFileSelectJS=" + this.onFileSelectJS;
            ifr.id = this.id;
            ifr.name = this.id;
            ifr.scrolling = "no";
            ifr.frameBorder = 0;
            ifr.marginHeight = 0;
            ifr.marginWidth = 0;
            ifr.className = 'uploadIFrame';
            
            
            s.appendChild(ifr);
            
                    
            return s;
        
        }
    }
    
    
    
    //--------STYLE EDITOR---------------STYLE EDITOR---------------STYLE EDITOR-------

    //updates style of objToStyle.
    
    this.getStyleEditor = function(objToStyle, onStyleChange)
    {
        var se = new this.StyleEditor(objToStyle, onStyleChange);
        return se.toObject();        
    }    


    this.StyleEditor = function(objToStyle, onStyleChange)
    {
        if (document.aStyleEditors == null)
            document.aStyleEditors = new Array();
        
        this.id = document.aStyleEditors.length;
        document.aStyleEditors.push(this);
        
        this.objToStyle = objToStyle;
        
        if (onStyleChange == null)
            onStyleChange = '';
        this.onStyleChange = m_uiGenerator.getFunctionPointer(onStyleChange);
        
        this.toObject = function()
        {
            var ss = document.createElement('span');
        
            ss.style.position = 'relative';
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleBold' + this.id, 'document.aStyleEditors[' + this.id + '].toggleBold();', 'Bold', 'text_bold.gif', null, 'TinyButton', (objToStyle.style.fontWeight == 'bold')));
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleItalic' + this.id, 'document.aStyleEditors[' + this.id + '].toggleItalic();', 'Italic', 'text_italic.gif', null, 'TinyButton', (objToStyle.style.fontStyle == 'italic')));
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleUnderline' + this.id, 'document.aStyleEditors[' + this.id + '].toggleUnderline();', 'Italic', 'text_underline.gif', null, 'TinyButton', (objToStyle.style.textDecoration == 'underline')));
            ss.appendChild(m_uiGenerator.getLabel('&#160;&#160;&#160;&#160;'));
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleFontLarger' + this.id, 'document.aStyleEditors[' + this.id + '].changeFontSize(1);', 'Increase Font Size', 'font_larger.gif', 'margin-top:-3px', 'TinyButton'));
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleFontSmaller' + this.id, 'document.aStyleEditors[' + this.id + '].changeFontSize(-1);', 'Decrease Font Size', 'font_smaller.gif', 'margin-top:-3px', 'TinyButton'));
            
            ss.appendChild(m_uiGenerator.getLabel('&#160;&#160;&#160;&#160; '));
            
            var btnColor = m_uiGenerator.getButton(null, 'btnStyleColor' + this.id, 'document.aStyleEditors[' + this.id + '].changeFontColor();', 'Font Color', 'font_color2.gif', null, 'TinyButton');
            btnColor.PickedColor = objToStyle.style.color;
            ss.appendChild(btnColor);
            
            var btnBgColor = m_uiGenerator.getButton(null, 'btnStyleBgColor' + this.id, 'document.aStyleEditors[' + this.id + '].changeBackgroundColor();', 'Background Color', 'color_swatch.gif', null, 'TinyButton');
            btnBgColor.PickedColor = objToStyle.style.backgroundColor;
            ss.appendChild(btnBgColor);
            
            ss.appendChild(m_uiGenerator.getLabel('<br/>'));
            
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleTextAlignLeft' + this.id, 'document.aStyleEditors[' + this.id + '].toggleTextAlign("left");', 'Align Left', 'text_align_left.gif', null, 'TinyButton', (objToStyle.style.textAlign == 'left' || objToStyle.style.textAlign == '')));
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleTextAlignCenter' + this.id, 'document.aStyleEditors[' + this.id + '].toggleTextAlign("center");', 'Align Center', 'text_align_center.gif', null, 'TinyButton', (objToStyle.style.textAlign == 'center')));
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleTextAlignRight' + this.id, 'document.aStyleEditors[' + this.id + '].toggleTextAlign("right");', 'Align Right', 'text_align_right.gif', null, 'TinyButton', (objToStyle.style.textAlign == 'right')));
            
            ss.appendChild(m_uiGenerator.getLabel('&#160;&#160;&#160;&#160; '));
            ss.appendChild(m_uiGenerator.getButton(null, 'btnStyleResetStyle' + this.id, 'document.aStyleEditors[' + this.id + '].resetStyle();', 'Reset', 'font_delete.gif', null, 'TinyButton'));
            
            return ss;  
        }
        
                
        
        this.resetStyle = function()
        {
            this.objToStyle.style.cssText = 'font-size:11px; color: #000000; background: #ffffff; text-align: left;';
            
            m_uiGenerator.toggleButton(document.getElementById('btnStyleBold' + this.id), (this.objToStyle.style.fontWeight == 'bold'));
            m_uiGenerator.toggleButton(document.getElementById('btnStyleItalic' + this.id), (this.objToStyle.style.fontStyle == 'italic'));
            m_uiGenerator.toggleButton(document.getElementById('btnStyleUnderline' + this.id), (this.objToStyle.style.textDecoration == 'underline'));    

            m_uiGenerator.toggleButton(document.getElementById('btnStyleTextAlignLeft' + this.id), true);
            this.toggleTextAlign('left');
            
            this.onStyleChange();
        }
        
        this.toggleBold = function()
        {
            this.objToStyle.style.fontWeight = 
                (document.getElementById('btnStyleBold' + this.id).toggleState) ? 'normal' : 'bold';
            this.onStyleChange();
        }

        this.toggleItalic = function()
        {
            this.objToStyle.style.fontStyle = 
                (document.getElementById('btnStyleItalic' + this.id).toggleState) ? 'normal' : 'italic';
            this.onStyleChange();
        }

        this.toggleUnderline = function()
        {
            this.objToStyle.style.textDecoration = 
                (document.getElementById('btnStyleUnderline' + this.id).toggleState) ? 'none' : 'underline';
            this.onStyleChange();
        }

        this.changeFontSize = function(direction)
        {
            var fs = Number(this.objToStyle.style.fontSize.replace(/[^\d]/g,''));
            
            if (isNaN(fs) || fs == 0)
                fs = 11;
            if (fs >= 16)
                direction *= 2;
            
            fs = fs + direction;            
            fs = Math.min(Math.max(fs, 8), 30);            
            
            this.objToStyle.style.fontSize = fs + 'px';
            this.onStyleChange();
        }

        this.changeFontColor = function()
        {
            var btnObj = document.getElementById('btnStyleColor' + this.id);    
            m_uiGenerator.ColorPicker(btnObj, 'document.aStyleEditors[' + this.id + '].changeFontColorCallback();');
        }

        this.changeFontColorCallback = function()
        {
            this.objToStyle.style.color = document.getElementById('btnStyleColor' + this.id).PickedColor;
            this.onStyleChange();
        }

        this.changeBackgroundColor = function()
        {
            var btnObj = document.getElementById('btnStyleBgColor' + this.id);    
            m_uiGenerator.ColorPicker(btnObj, 'document.aStyleEditors[' + this.id + '].changeBackgroundColorCallback();');
        }

        this.changeBackgroundColorCallback = function()
        {
            this.objToStyle.style.backgroundColor = document.getElementById('btnStyleBgColor' + this.id).PickedColor;
            this.onStyleChange();
        }

        this.toggleTextAlign = function(align)
        {
            this.objToStyle.style.textAlign = align;
            
            if (align != 'left')
                m_uiGenerator.toggleButton(document.getElementById('btnStyleTextAlignLeft' + this.id), false);
            if (align != 'center')
                m_uiGenerator.toggleButton(document.getElementById('btnStyleTextAlignCenter' + this.id), false);
            if (align != 'right')
                m_uiGenerator.toggleButton(document.getElementById('btnStyleTextAlignRight' + this.id), false);
            this.onStyleChange();
        }
    }
    
    
    
    
    //--------COLOR PICKER---------------COLOR PICKER---------------COLOR PICKER-------
    
    //stores picked color in btnObj.PickedColor and calls jsOnSelect
    
    this.ColorPicker = function(btnObj, jsOnSelect)
    {
        if (btnObj == null)
            if (event != null && event.srcElement != null)
            {
                btnObj = event.srcElement;
                while (btnObj != null && btnObj.tagName.toLowerCase() != 'a')
                    btnObj = btnObj.parentNode;
            }
        if (btnObj == null)
            return;
        
        if (btnObj.PickedColor == null || btnObj.PickedColor == '')
            btnObj.PickedColor = '#000000';
        
        var aColors = new Array('FF', 'BB', '88', '55', '00');
        var aGrays = new Array('FF', 'CC', 'AA', '88', '66', '33', '00');
        var aPatterns = new Array('FFXXXX', 'XX0000', 
                                  'FFFFXX', 'XXXX00', 
                                  'XXFFXX', '00XX00', 
                                  'XXFFFF', '00XXXX', 
                                  'XXXXFF', '0000XX', 
                                  'FFXXFF', 'XX00XX',
                                  'XXXXXX');
            
        var divColor = document.createElement('div');
        divColor.className = 'ColorPicker';
        divColor.style.top = btnObj.offsetTop + btnObj.offsetHeight - 2;
        divColor.style.left = btnObj.offsetLeft;
        
        var tblColor = document.createElement('table');
        tblColor.cellSpacing = 2;
        var tr, td;

        for (var p = 0; p < aPatterns.length; p++)
        {
            if (p % 2 == 0)
                tr = tblColor.insertRow(-1);
            
            var a = aColors;
            if (aPatterns[p] == 'XXXXXX')
                a = aGrays;
            
            for (var c = p % 2; c < a.length; c++)
            {
                col = aPatterns[p].replace(/XX/g, a[c]);
                
                if ((col != 'FFFFFF' && col != '000000') || aPatterns[p] == 'XXXXXX')
                {
                    td = tr.insertCell(-1);
                    td.title = '#' + col;
                    if (btnObj.PickedColor.toUpperCase().replace(/#/g,'') == col)
                        td.style.background = 'url(skins/common/images/icons/gif/bullet_green.gif) -1px -1px';
                    td.style.backgroundColor = '#' + col;
                    td.innerHTML = '<img src="skins/common/images/blank.gif" width="11" height="11"/>';
                    td.attachEvent('onclick', 
                        function() 
                        {
                            var colCell = event.srcElement;
                            while (colCell.tagName.toLowerCase() != 'td')
                                colCell = colCell.parentNode;
                            btnObj.PickedColor = colCell.style.backgroundColor;
                            divColor.removeNode(true);
                            eval(jsOnSelect);
                        }
                    );
                }
            }            
        }
        
        divColor.appendChild(tblColor);
        
        
        var mouseOutHandler = function()
            {
                var t = event.toElement;
                while (t != null && t != divColor && t != btnObj)
                    t = t.parentNode;
                if (t == null)
                {
                    btnObj.detachEvent('onmouseout', this);
                    divColor.removeNode(true);                    
                } 
            }
        
        divColor.attachEvent('onmouseout', mouseOutHandler);
        btnObj.attachEvent('onmouseout', mouseOutHandler);
        
                
        
        btnObj.parentNode.appendChild(divColor);
        
    }
    
    
    
    this.InfoPopup = null;
    this.InfoTimer = null;
    this.showInfoPopup = function(htmlContent, x, y, w, h, bMouseOut)
    {
        var mouseoutFunction = function() 
            {   
                if (event != null)
                {
                    var to = event.toElement;                
                    while (to != null && to != m_uiGenerator.InfoPopup)
                        to = to.parentNode;
                    
                    if (to == m_uiGenerator.InfoPopup)
                        return;
                }
                
                m_uiGenerator.InfoPopup.style.display = 'none';
                
                try
                {
                    top.resizeFrame();
                }
                catch (e) {}
            };
                
                
                
        if (this.InfoPopup == null)
        {
            this.InfoPopup = document.createElement('div');
            this.InfoPopup.style.position = 'absolute';
            this.InfoPopup.style.padding = "0px";		
		    this.InfoPopup.style.backgroundColor = "lightyellow";
		    this.InfoPopup.style.border = "solid black 1px";		
		    this.InfoPopup.style.fontFamily = "Arial";		
		    this.InfoPopup.style.fontSize = "10px";
		    
		    if(bMouseOut==null) this.InfoPopup.attachEvent('onmouseout', mouseoutFunction);
		    this.InfoPopup.attachEvent('onmouseover', 
		        function() 
		        {
		            window.clearTimeout(m_uiGenerator.InfoTimer);
		        }
		    );
		    
		    document.body.appendChild(this.InfoPopup);	
        }
        
		this.InfoPopup.innerHTML = htmlContent;
    
    
        if (x == null && event != null)
            x = (((event.clientX-100) > 0) ? event.clientX-100 : 10) + document.body.scrollLeft;
        if (y == null && event != null)
            y = event.clientY + 5 + document.body.scrollTop;
        if (w == null)
            w = 400;
        if (h == null)
            h = 250;
            
        if (x + w > document.body.scrollWidth)
            x = document.body.scrollWidth - w;
        
        this.InfoPopup.style.top = y + (!isNaN(Number(h)) ? 'px' : '');
        this.InfoPopup.style.left = x + (!isNaN(Number(h)) ? 'px' : '');
        this.InfoPopup.style.width = w + (!isNaN(Number(h)) ? 'px' : '');
        this.InfoPopup.style.height = h + (!isNaN(Number(h)) ? 'px' : '');
        
        this.InfoPopup.style.display = 'block';
        
        try
        {
            top.resizeFrame();
        }
        catch (e) {}
        
        if (event != null && event.srcElement != null)
            event.srcElement.attachEvent('onmouseout', 
                function()
                {
                    window.clearTimeout(m_uiGenerator.InfoTimer);
                    m_uiGenerator.InfoTimer = window.setTimeout(mouseoutFunction, 100);
                }
            ); 
    }   
        
    
    
    
    
    this.getClassIconFilename = function(classId)
    {        
        return m_uiUtil.getClassIcon(parseInt(classId));
        
    }  
    
    
    
    
    
    
    
    
    

}










//--------Animation--------Animation--------Animation--------Animation--------

var m_animationStack = new Array();
var m_animationTimer = null;

function divAnimation(divObj, shownClass, flipImageObj)
{
    this.obj = divObj;
    this.state = 1;
    this.origHeight = this.obj.offsetHeight;
    this.origWidth = this.obj.offsetWidth;
    this.origOverflowY = this.obj.style.overflowY;
    this.flipImageObj = flipImageObj;
    this.iCounter = 0;
    
    if (this.obj.className == 'Hidden' || this.obj.style.display == 'none')
    {
        this.state = 0;
        this.obj.style.display = 'block';
                
        if (shownClass == null || shownClass == '')
            shownClass = 'roundedC_content';
        this.obj.className = shownClass;
        
        this.origHeight = this.obj.offsetHeight;
        this.origWidth = this.obj.offsetWidth;
        this.obj.style.overflowY = 'hidden';
        this.obj.style.height = '1px';
        this.obj.style.display = 'none';
        
        
    }
    
    //alert('orig height = ' + this.origHeight);
    
}

divAnimation.prototype.slide = function(forceState)
{
    //do not add duplicates
    for (var i = 0; i < m_animationStack.length; i++)
        if (m_animationStack[i].obj.id == this.obj.id)
            return;

    this.obj.style.overflowY = 'hidden';
    this.iCounter = 0;
    
    
    if (forceState != null)
        if (this.state == forceState)
            return;
        else
            this.state = 1 - forceState;
        
    if (this.state == 0)
    {//slide down
        this.targetHeight = this.origHeight;
        this.obj.style.height = '2px';
        this.obj.style.display = 'block';
        this.obj.style.width = '100%';
        //this.obj.style.width = this.origWidth;
    }
    else
    {//slide up
        this.targetHeight = 1;
    }
    this.step = (this.targetHeight - this.obj.offsetHeight) / 10;
    
    m_animationStack.push(this);
    if (m_animationTimer == null)
        m_animationTimer = window.setInterval(DivAnimation_interval, 20);
}

divAnimation.prototype.slideUp = function()
{
    //alert('slide up');
    this.slide(0);
}
divAnimation.prototype.slideDown = function()
{
    //alert('slide down');
    this.slide(1);
}


function DivAnimation_interval()
{
    if (m_animationStack.length == 0)
    {
        //alert('killing interval');
        window.clearInterval(m_animationTimer);
        m_animationTimer = null;
        try
		{
		    if (self != top) 
		        top.resizeFrame();
		}
		catch(e) {}
    }
    
    for (var i = 0; i < m_animationStack.length; i++)
    {
        var anim = m_animationStack[i];
        var done = false;
        var oldHeight = anim.obj.offsetHeight;
        
        var percent = Math.abs((oldHeight - anim.targetHeight) / anim.origHeight);
        var step = anim.step * (1.2 - Math.cos(percent * Math.PI));
        if (Math.abs(step) < 1)
            step = step / Math.abs(step);
                
        var newHeight = oldHeight + step;
        
        //alert('1\nnewHeight = ' + newHeight + '\n\n' + 'offsetHeight = ' + anim.obj.offsetHeight + '\ntargetHeight = ' + anim.targetHeight);
        if (anim.state == 1 && newHeight < 0)
        {
            newHeight = anim.targetHeight;
            done = true;
        }
        else if (anim.state == 0 && newHeight > anim.targetHeight)
        {
            newHeight = anim.targetHeight;
            done = true;
        }    
        anim.obj.style.height = Math.max(0, (isNaN(newHeight) ? 0 : newHeight)) + 'px';
        
        if (anim.state == 1 && oldHeight < anim.obj.offsetHeight)
            done = true;
        
        //alert('2\nnewHeight = ' + newHeight + '\n\n' + 'offsetHeight = ' + anim.obj.offsetHeight + '\ntargetHeight = ' + anim.targetHeight);
        
        anim.iCounter++;
        if (anim.iCounter > 20)
            done = true;
        
        if (done)
        {
            //alert('done');
            anim.obj.style.height = anim.targetHeight;
            anim.state = 1 - anim.state;
            if (anim.state == 1)
            {
                anim.obj.style.overflowY = anim.origOverflowY; 
                if (anim.flipImageObj != null)
                    anim.flipImageObj.src = anim.flipImageObj.src.replace('collapse', 'expand');                
            }
            else
            {
                anim.obj.style.display = 'none';
                if (anim.flipImageObj != null)
                    anim.flipImageObj.src = anim.flipImageObj.src.replace('expand', 'collapse');
            }
            m_animationStack.splice(i,1);
            i--;
        }
    }
    
}


