//v.2.0 build 81009

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
dhtmlxAjax={
    get:function(url,callback){
        var t=new dtmlXMLLoaderObject(true);
        t.async=(arguments.length<3);
        t.waitCall=callback;
        t.loadXML(url)
        return t;
    },
    post:function(url,post,callback){
        var t=new dtmlXMLLoaderObject(true);
        t.async=(arguments.length<4);
        t.waitCall=callback;
        t.loadXML(url,true,post)
        return t;
    },
    getSync:function(url){
        return this.get(url,null,true)
    },
    postSync:function(url,post){
        return this.post(url,post,null,true);
    }
}

/**
  *     @desc: xmlLoader object
  *     @type: private
  *     @param: funcObject - xml parser function
  *     @param: object - jsControl object
  *     @param: async - sync/async mode (async by default)
  *     @param: rSeed - enable/disable random seed ( prevent IE caching)
  *     @topic: 0
  */
function dtmlXMLLoaderObject(funcObject, dhtmlObject, async, rSeed){
    this.xmlDoc="";

    if (typeof (async) != "undefined")
        this.async=async;
    else
        this.async=true;

    this.onloadAction=funcObject||null;
    this.mainObject=dhtmlObject||null;
    this.waitCall=null;
    this.rSeed=rSeed||false;
    return this;
};
/**
  *     @desc: xml loading handler
  *     @type: private
  *     @param: dtmlObject - xmlLoader object
  *     @topic: 0
  */
dtmlXMLLoaderObject.prototype.waitLoadFunction=function(dhtmlObject){
    var once = true;
    this.check=function (){
        if ((dhtmlObject)&&(dhtmlObject.onloadAction != null)){
            if ((!dhtmlObject.xmlDoc.readyState)||(dhtmlObject.xmlDoc.readyState == 4)){
                if (!once)
                    return;

                once=false; //IE 5 fix
                if (typeof dhtmlObject.onloadAction == "function")
                    dhtmlObject.onloadAction(dhtmlObject.mainObject, null, null, null, dhtmlObject);

                if (dhtmlObject.waitCall){
                    dhtmlObject.waitCall.call(this,dhtmlObject);
                    dhtmlObject.waitCall=null;
                }
            }
        }
    };
    return this.check;
};

/**
  *     @desc: return XML top node
  *     @param: tagName - top XML node tag name (not used in IE, required for Safari and Mozilla)
  *     @type: private
  *     @returns: top XML node
  *     @topic: 0
  */
dtmlXMLLoaderObject.prototype.getXMLTopNode=function(tagName, oldObj){
    if (this.xmlDoc.responseXML){
        var temp = this.xmlDoc.responseXML.getElementsByTagName(tagName);
        if(temp.length==0 && tagName.indexOf(":")!=-1)
            var temp = this.xmlDoc.responseXML.getElementsByTagName((tagName.split(":"))[1]);
        var z = temp[0];
    } else
        var z = this.xmlDoc.documentElement;

    if (z){
        this._retry=false;
        return z;
    }

    if ((_isIE)&&(!this._retry)){
        //fall back to MS.XMLDOM
        var xmlString = this.xmlDoc.responseText;
        var oldObj = this.xmlDoc;
        this._retry=true;
        this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        this.xmlDoc.async=false;
        this.xmlDoc["loadXM"+"L"](xmlString);

        return this.getXMLTopNode(tagName, oldObj);
    }
    dhtmlxError.throwError("LoadXML", "Incorrect XML", [
        (oldObj||this.xmlDoc),
        this.mainObject
    ]);

    return document.createElement("DIV");
};

/**
  *     @desc: load XML from string
  *     @type: private
  *     @param: xmlString - xml string
  *     @topic: 0
  */
dtmlXMLLoaderObject.prototype.loadXMLString=function(xmlString){
    {
        try{
            var parser = new DOMParser();
            this.xmlDoc=parser.parseFromString(xmlString, "text/xml");
        }
        catch (e){
            this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            this.xmlDoc.async=this.async;
            this.xmlDoc["loadXM"+"L"](xmlString);
        }
    }

    this.onloadAction(this.mainObject, null, null, null, this);

    if (this.waitCall){
        this.waitCall();
        this.waitCall=null;
    }
}
/**
  *     @desc: load XML
  *     @type: private
  *     @param: filePath - xml file path
  *     @param: postMode - send POST request
  *     @param: postVars - list of vars for post request
  *     @topic: 0
  */
dtmlXMLLoaderObject.prototype.loadXML=function(filePath, postMode, postVars, rpc){
    if (this.rSeed)
        filePath+=((filePath.indexOf("?") != -1) ? "&" : "?")+"a_dhx_rSeed="+(new Date()).valueOf();
    this.filePath=filePath;

    if ((!_isIE)&&(window.XMLHttpRequest))
        this.xmlDoc=new XMLHttpRequest();
    else {
        if (document.implementation&&document.implementation.createDocument){
            this.xmlDoc=document.implementation.createDocument("", "", null);
            this.xmlDoc.onload=new this.waitLoadFunction(this);
            this.xmlDoc.load(filePath);
            return;
        } else
            this.xmlDoc=new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (this.async)
        this.xmlDoc.onreadystatechange=new this.waitLoadFunction(this);
    this.xmlDoc.open(postMode ? "POST" : "GET", filePath, this.async);

    if (rpc){
        this.xmlDoc.setRequestHeader("User-Agent", "dhtmlxRPC v0.1 ("+navigator.userAgent+")");
        this.xmlDoc.setRequestHeader("Content-type", "text/xml");
    }

    else if (postMode)
        this.xmlDoc.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

    this.xmlDoc.setRequestHeader("X-Requested-With","XMLHttpRequest");
    this.xmlDoc.send(null||postVars);

    if (!this.async)
        (new this.waitLoadFunction(this))();
};
/**
  *     @desc: destructor, cleans used memory
  *     @type: private
  *     @topic: 0
  */
dtmlXMLLoaderObject.prototype.destructor=function(){
    this.onloadAction=null;
    this.mainObject=null;
    this.xmlDoc=null;
    return null;
}

dtmlXMLLoaderObject.prototype.xmlNodeToJSON = function(node){
        var t={};
        for (var i=0; i<node.attributes.length; i++)
            t[node.attributes[i].name]=node.attributes[i].value;
        t["_tagvalue"]=node.firstChild?node.firstChild.nodeValue:"";
        for (var i=0; i<node.childNodes.length; i++){
            var name=node.childNodes[i].tagName;
            if (name){
                if (!t[name]) t[name]=[];
                t[name].push(this.xmlNodeToJSON(node.childNodes[i]));
            }
        }
        return t;
    }

/**
  *     @desc: Call wrapper
  *     @type: private
  *     @param: funcObject - action handler
  *     @param: dhtmlObject - user data
  *     @returns: function handler
  *     @topic: 0
  */
function callerFunction(funcObject, dhtmlObject){
    this.handler=function(e){
        if (!e)
            e=window.event;
        funcObject(e, dhtmlObject);
        return true;
    };
    return this.handler;
};

/**
  *     @desc: Calculate absolute position of html object
  *     @type: private
  *     @param: htmlObject - html object
  *     @topic: 0
  */
function getAbsoluteLeft(htmlObject){
    var xPos = htmlObject.offsetLeft;
    var temp = htmlObject.offsetParent;

    while (temp != null){
        xPos+=temp.offsetLeft;
        temp=temp.offsetParent;
    }
    return xPos;
}
/**
  *     @desc: Calculate absolute position of html object
  *     @type: private
  *     @param: htmlObject - html object
  *     @topic: 0
  */
function getAbsoluteTop(htmlObject){
    var yPos = htmlObject.offsetTop;
    var temp = htmlObject.offsetParent;

    while (temp != null){
        yPos+=temp.offsetTop;
        temp=temp.offsetParent;
    }
    return yPos;
}


/**
*     @desc: Convert string to it boolean representation
*     @type: private
*     @param: inputString - string for covertion
*     @topic: 0
*/
function convertStringToBoolean(inputString){
    if (typeof (inputString) == "string")
        inputString=inputString.toLowerCase();

    switch (inputString){
        case "1":
        case "true":
        case "yes":
        case "y":
        case 1:
        case true:
            return true;
            break;

        default: return false;
    }
}

/**
*     @desc: find out what symbol to use as url param delimiters in further params
*     @type: private
*     @param: str - current url string
*     @topic: 0
*/
function getUrlSymbol(str){
    if (str.indexOf("?") != -1)
        return "&"
    else
        return "?"
}

function dhtmlDragAndDropObject(){
    if (window.dhtmlDragAndDrop)
        return window.dhtmlDragAndDrop;

    this.lastLanding=0;
    this.dragNode=0;
    this.dragStartNode=0;
    this.dragStartObject=0;
    this.tempDOMU=null;
    this.tempDOMM=null;
    this.waitDrag=0;
    window.dhtmlDragAndDrop=this;

    return this;
};

dhtmlDragAndDropObject.prototype.removeDraggableItem=function(htmlNode){
    htmlNode.onmousedown=null;
    htmlNode.dragStarter=null;
    htmlNode.dragLanding=null;
}
dhtmlDragAndDropObject.prototype.addDraggableItem=function(htmlNode, dhtmlObject){
    htmlNode.onmousedown=this.preCreateDragCopy;
    htmlNode.dragStarter=dhtmlObject;
    this.addDragLanding(htmlNode, dhtmlObject);
}
dhtmlDragAndDropObject.prototype.addDragLanding=function(htmlNode, dhtmlObject){
    htmlNode.dragLanding=dhtmlObject;
}
dhtmlDragAndDropObject.prototype.preCreateDragCopy=function(e){
    if (e&&(e||event).button == 2)
        return;

    if (window.dhtmlDragAndDrop.waitDrag){
        window.dhtmlDragAndDrop.waitDrag=0;
        document.body.onmouseup=window.dhtmlDragAndDrop.tempDOMU;
        document.body.onmousemove=window.dhtmlDragAndDrop.tempDOMM;
        return false;
    }

    window.dhtmlDragAndDrop.waitDrag=1;
    window.dhtmlDragAndDrop.tempDOMU=document.body.onmouseup;
    window.dhtmlDragAndDrop.tempDOMM=document.body.onmousemove;
    window.dhtmlDragAndDrop.dragStartNode=this;
    window.dhtmlDragAndDrop.dragStartObject=this.dragStarter;
    document.body.onmouseup=window.dhtmlDragAndDrop.preCreateDragCopy;
    document.body.onmousemove=window.dhtmlDragAndDrop.callDrag;

    if ((e)&&(e.preventDefault)){
        e.preventDefault();
        return false;
    }
    return false;
};
dhtmlDragAndDropObject.prototype.callDrag=function(e){
    if (!e)
        e=window.event;
    dragger=window.dhtmlDragAndDrop;

    if ((e.button == 0)&&(_isIE))
        return dragger.stopDrag();

    if (!dragger.dragNode&&dragger.waitDrag){
        dragger.dragNode=dragger.dragStartObject._createDragNode(dragger.dragStartNode, e);

        if (!dragger.dragNode)
            return dragger.stopDrag();

        dragger.gldragNode=dragger.dragNode;
        document.body.appendChild(dragger.dragNode);
        document.body.onmouseup=dragger.stopDrag;
        dragger.waitDrag=0;
        dragger.dragNode.pWindow=window;
        dragger.initFrameRoute();
    }

    if (dragger.dragNode.parentNode != window.document.body){
        var grd = dragger.gldragNode;

        if (dragger.gldragNode.old)
            grd=dragger.gldragNode.old;

        //if (!document.all) dragger.calculateFramePosition();
        grd.parentNode.removeChild(grd);
        var oldBody = dragger.dragNode.pWindow;

        //      var oldp=dragger.dragNode.parentObject;
        if (_isIE){
            var div = document.createElement("Div");
            div.innerHTML=dragger.dragNode.outerHTML;
            dragger.dragNode=div.childNodes[0];
        } else
            dragger.dragNode=dragger.dragNode.cloneNode(true);

        dragger.dragNode.pWindow=window;
        //      dragger.dragNode.parentObject=oldp;

        dragger.gldragNode.old=dragger.dragNode;
        document.body.appendChild(dragger.dragNode);
        oldBody.dhtmlDragAndDrop.dragNode=dragger.dragNode;
    }

    dragger.dragNode.style.left=e.clientX+15+(dragger.fx
        ? dragger.fx*(-1)
        : 0)
        +(document.body.scrollLeft||document.documentElement.scrollLeft)+"px";
    dragger.dragNode.style.top=e.clientY+3+(dragger.fy
        ? dragger.fy*(-1)
        : 0)
        +(document.body.scrollTop||document.documentElement.scrollTop)+"px";

    if (!e.srcElement)
        var z = e.target;
    else
        z=e.srcElement;
    dragger.checkLanding(z, e);
}

dhtmlDragAndDropObject.prototype.calculateFramePosition=function(n){
    //this.fx = 0, this.fy = 0;
    if (window.name){
        var el = parent.frames[window.name].frameElement.offsetParent;
        var fx = 0;
        var fy = 0;

        while (el){
            fx+=el.offsetLeft;
            fy+=el.offsetTop;
            el=el.offsetParent;
        }

        if ((parent.dhtmlDragAndDrop)){
            var ls = parent.dhtmlDragAndDrop.calculateFramePosition(1);
            fx+=ls.split('_')[0]*1;
            fy+=ls.split('_')[1]*1;
        }

        if (n)
            return fx+"_"+fy;
        else
            this.fx=fx;
        this.fy=fy;
    }
    return "0_0";
}
dhtmlDragAndDropObject.prototype.checkLanding=function(htmlObject, e){
    if ((htmlObject)&&(htmlObject.dragLanding)){
        if (this.lastLanding)
            this.lastLanding.dragLanding._dragOut(this.lastLanding);
        this.lastLanding=htmlObject;
        this.lastLanding=this.lastLanding.dragLanding._dragIn(this.lastLanding, this.dragStartNode, e.clientX,
            e.clientY, e);
        this.lastLanding_scr=(_isIE ? e.srcElement : e.target);
    } else {
        if ((htmlObject)&&(htmlObject.tagName != "BODY"))
            this.checkLanding(htmlObject.parentNode, e);
        else {
            if (this.lastLanding)
                this.lastLanding.dragLanding._dragOut(this.lastLanding, e.clientX, e.clientY, e);
            this.lastLanding=0;

            if (this._onNotFound)
                this._onNotFound();
        }
    }
}
dhtmlDragAndDropObject.prototype.stopDrag=function(e, mode){
    dragger=window.dhtmlDragAndDrop;

    if (!mode){
        dragger.stopFrameRoute();
        var temp = dragger.lastLanding;
        dragger.lastLanding=null;

        if (temp)
            temp.dragLanding._drag(dragger.dragStartNode, dragger.dragStartObject, temp, (_isIE
                ? event.srcElement
                : e.target));
    }
    dragger.lastLanding=null;

    if ((dragger.dragNode)&&(dragger.dragNode.parentNode == document.body))
        dragger.dragNode.parentNode.removeChild(dragger.dragNode);
    dragger.dragNode=0;
    dragger.gldragNode=0;
    dragger.fx=0;
    dragger.fy=0;
    dragger.dragStartNode=0;
    dragger.dragStartObject=0;
    document.body.onmouseup=dragger.tempDOMU;
    document.body.onmousemove=dragger.tempDOMM;
    dragger.tempDOMU=null;
    dragger.tempDOMM=null;
    dragger.waitDrag=0;
}

dhtmlDragAndDropObject.prototype.stopFrameRoute=function(win){
    if (win)
        window.dhtmlDragAndDrop.stopDrag(1, 1);

    for (var i = 0; i < window.frames.length; i++)
        if ((window.frames[i] != win)&&(window.frames[i].dhtmlDragAndDrop))
            window.frames[i].dhtmlDragAndDrop.stopFrameRoute(window);

    if ((parent.dhtmlDragAndDrop)&&(parent != window)&&(parent != win))
        parent.dhtmlDragAndDrop.stopFrameRoute(window);
}
dhtmlDragAndDropObject.prototype.initFrameRoute=function(win, mode){
    if (win){
        window.dhtmlDragAndDrop.preCreateDragCopy();
        window.dhtmlDragAndDrop.dragStartNode=win.dhtmlDragAndDrop.dragStartNode;
        window.dhtmlDragAndDrop.dragStartObject=win.dhtmlDragAndDrop.dragStartObject;
        window.dhtmlDragAndDrop.dragNode=win.dhtmlDragAndDrop.dragNode;
        window.dhtmlDragAndDrop.gldragNode=win.dhtmlDragAndDrop.dragNode;
        window.document.body.onmouseup=window.dhtmlDragAndDrop.stopDrag;
        window.waitDrag=0;

        if (((!_isIE)&&(mode))&&((!_isFF)||(_FFrv < 1.8)))
            window.dhtmlDragAndDrop.calculateFramePosition();
    }

    if ((parent.dhtmlDragAndDrop)&&(parent != window)&&(parent != win))
        parent.dhtmlDragAndDrop.initFrameRoute(window);

    for (var i = 0; i < window.frames.length; i++)
        if ((window.frames[i] != win)&&(window.frames[i].dhtmlDragAndDrop))
            window.frames[i].dhtmlDragAndDrop.initFrameRoute(window, ((!win||mode) ? 1 : 0));
}

var _isFF = false;
var _isIE = false;
var _isOpera = false;
var _isKHTML = false;
var _isMacOS = false;

if (navigator.userAgent.indexOf('Macintosh') != -1)
    _isMacOS=true;

if ((navigator.userAgent.indexOf('Safari') != -1)||(navigator.userAgent.indexOf('Konqueror') != -1)){
    var _KHTMLrv = parseFloat(navigator.userAgent.substr(navigator.userAgent.indexOf('Safari')+7, 5));

    if (_KHTMLrv > 525){ //mimic FF behavior for Safari 3.1+
        _isFF=true;
        var _FFrv = 1.9;
    } else
        _isKHTML=true;
} else if (navigator.userAgent.indexOf('Opera') != -1){
    _isOpera=true;
    _OperaRv=parseFloat(navigator.userAgent.substr(navigator.userAgent.indexOf('Opera')+6, 3));
}

else if (navigator.appName.indexOf("Microsoft") != -1)
    _isIE=true;

else {
    _isFF=true;
    var _FFrv = parseFloat(navigator.userAgent.split("rv:")[1])
}

//deprecated, use global constant instead
//determines if current browser is IE
function isIE(){
    if (navigator.appName.indexOf("Microsoft") != -1)
        if (navigator.userAgent.indexOf('Opera') == -1)
            return true;
    return false;
}

//multibrowser Xpath processor
dtmlXMLLoaderObject.prototype.doXPath=function(xpathExp, docObj, namespace, result_type){
    if ((_isKHTML))
        return this.doXPathOpera(xpathExp, docObj);

    if (_isIE){ //IE
        if (!docObj)
            if (!this.xmlDoc.nodeName)
                docObj=this.xmlDoc.responseXML
            else
                docObj=this.xmlDoc;

        if (!docObj)
            dhtmlxError.throwError("LoadXML", "Incorrect XML", [
                (docObj||this.xmlDoc),
                this.mainObject
            ]);

        if (namespace != null)
            docObj.setProperty("SelectionNamespaces", "xmlns:xsl='"+namespace+"'"); //

        if (result_type == 'single'){
            return docObj.selectSingleNode(xpathExp);
        }
        else {
            return docObj.selectNodes(xpathExp)||new Array(0);
        }
    } else { //Mozilla
        var nodeObj = docObj;

        if (!docObj){
            if (!this.xmlDoc.nodeName){
                docObj=this.xmlDoc.responseXML
            }
            else {
                docObj=this.xmlDoc;
            }
        }

        if (!docObj)
            dhtmlxError.throwError("LoadXML", "Incorrect XML", [
                (docObj||this.xmlDoc),
                this.mainObject
            ]);

        if (docObj.nodeName.indexOf("document") != -1){
            nodeObj=docObj;
        }
        else {
            nodeObj=docObj;
            docObj=docObj.ownerDocument;
        }
        var retType = XPathResult.ANY_TYPE;

        if (result_type == 'single')
            retType=XPathResult.FIRST_ORDERED_NODE_TYPE
        var rowsCol = new Array();
        var col = docObj.evaluate(xpathExp, nodeObj, function(pref){
            return namespace
        }, retType, null);

        if (retType == XPathResult.FIRST_ORDERED_NODE_TYPE){
            return col.singleNodeValue;
        }
        var thisColMemb = col.iterateNext();

        while (thisColMemb){
            rowsCol[rowsCol.length]=thisColMemb;
            thisColMemb=col.iterateNext();
        }
        return rowsCol;
    }
}

function _dhtmlxError(type, name, params){
    if (!this.catches)
        this.catches=new Array();

    return this;
}

_dhtmlxError.prototype.catchError=function(type, func_name){
    this.catches[type]=func_name;
}
_dhtmlxError.prototype.throwError=function(type, name, params){
    if (this.catches[type])
        return this.catches[type](type, name, params);

    if (this.catches["ALL"])
        return this.catches["ALL"](type, name, params);

    alert("Error type: "+arguments[0]+"\nDescription: "+arguments[1]);
    return null;
}

window.dhtmlxError=new _dhtmlxError();


//opera fake, while 9.0 not released
//multibrowser Xpath processor
dtmlXMLLoaderObject.prototype.doXPathOpera=function(xpathExp, docObj){
    //this is fake for Opera
    var z = xpathExp.replace(/[\/]+/gi, "/").split('/');
    var obj = null;
    var i = 1;

    if (!z.length)
        return [];

    if (z[0] == ".")
        obj=[docObj]; else if (z[0] == ""){
        obj=(this.xmlDoc.responseXML||this.xmlDoc).getElementsByTagName(z[i].replace(/\[[^\]]*\]/g, ""));
        i++;
    } else
        return [];

    for (i; i < z.length; i++)obj=this._getAllNamedChilds(obj, z[i]);

    if (z[i-1].indexOf("[") != -1)
        obj=this._filterXPath(obj, z[i-1]);
    return obj;
}

dtmlXMLLoaderObject.prototype._filterXPath=function(a, b){
    var c = new Array();
    var b = b.replace(/[^\[]*\[\@/g, "").replace(/[\[\]\@]*/g, "");

    for (var i = 0; i < a.length; i++)
        if (a[i].getAttribute(b))
            c[c.length]=a[i];

    return c;
}
dtmlXMLLoaderObject.prototype._getAllNamedChilds=function(a, b){
    var c = new Array();

    if (_isKHTML)
        b=b.toUpperCase();

    for (var i = 0; i < a.length; i++)for (var j = 0; j < a[i].childNodes.length; j++){
        if (_isKHTML){
            if (a[i].childNodes[j].tagName&&a[i].childNodes[j].tagName.toUpperCase() == b)
                c[c.length]=a[i].childNodes[j];
        }

        else if (a[i].childNodes[j].tagName == b)
            c[c.length]=a[i].childNodes[j];
    }

    return c;
}

function dhtmlXHeir(a, b){
    for (var c in b)
        if (typeof (b[c]) == "function")
            a[c]=b[c];
    return a;
}

function dhtmlxEvent(el, event, handler){
    if (el.addEventListener)
        el.addEventListener(event, handler, false);

    else if (el.attachEvent)
        el.attachEvent("on"+event, handler);
}

//============= XSL Extension ===================================

dtmlXMLLoaderObject.prototype.xslDoc=null;
dtmlXMLLoaderObject.prototype.setXSLParamValue=function(paramName, paramValue, xslDoc){
    if (!xslDoc)
        xslDoc=this.xslDoc

    if (xslDoc.responseXML)
        xslDoc=xslDoc.responseXML;
    var item =
        this.doXPath("/xsl:stylesheet/xsl:variable[@name='"+paramName+"']", xslDoc,
            "http:/\/www.w3.org/1999/XSL/Transform", "single");

    if (item != null)
        item.firstChild.nodeValue=paramValue
}
dtmlXMLLoaderObject.prototype.doXSLTransToObject=function(xslDoc, xmlDoc){
    if (!xslDoc)
        xslDoc=this.xslDoc;

    if (xslDoc.responseXML)
        xslDoc=xslDoc.responseXML

    if (!xmlDoc)
        xmlDoc=this.xmlDoc;

    if (xmlDoc.responseXML)
        xmlDoc=xmlDoc.responseXML

    //MOzilla
    if (!isIE()){
        if (!this.XSLProcessor){
            this.XSLProcessor=new XSLTProcessor();
            this.XSLProcessor.importStylesheet(xslDoc);
        }
        var result = this.XSLProcessor.transformToDocument(xmlDoc);
    } else {
        var result = new ActiveXObject("Msxml2.DOMDocument.3.0");
        xmlDoc.transformNodeToObject(xslDoc, result);
    }
    return result;
}

dtmlXMLLoaderObject.prototype.doXSLTransToString=function(xslDoc, xmlDoc){
    return this.doSerialization(this.doXSLTransToObject(xslDoc, xmlDoc));
}

dtmlXMLLoaderObject.prototype.doSerialization=function(xmlDoc){
    if (!xmlDoc)
            xmlDoc=this.xmlDoc;
    if (xmlDoc.responseXML)
            xmlDoc=xmlDoc.responseXML
    if (!isIE()){
        var xmlSerializer = new XMLSerializer();
        return xmlSerializer.serializeToString(xmlDoc);
    } else
        return xmlDoc.xml;
}

//(c)dhtmlx ltd. www.dhtmlx.com
//v.2.0 build 81107

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/**
*   @desc: constructor, creates dhtmlxlayout panel
*   @pseudonym: td
*   @type: public
*/
function dhtmlXLayoutPanel() {

}

/**
*   @desc: constructor, creats a new dhtmlXLayout object
*   @param: base - object/object id, document.body or dhtmlxWindow - the layout will be attached to it
*   @param: view - layout's pattern
*   @param: skin - skin
*   @type: public
*/
function dhtmlXLayoutObject(base, view, skin) {

    // 1. object/objectId - window without borders
    // 2. document.body - fullscreened window
    // 3. window object - simple attach

    var that = this;

    this.skin = (skin!=null?skin:"dhx_blue");

    if (typeof(base) == "string") { base = document.getElementById(base); }

    if (!base._skipChecksOnStartUp) {
        // check if layout cell
        if (base._isLayoutCell == true) {
            this._updateDimensions = true;
            base = base.window;
        }
        // check if window
        if (base._isWindow == true) {
            var layout = base.attachLayout(view, this.skin);
            if (this._updateDimensions == true) { layout._dimension = new Array(0, 0); }
            return layout;
        } else if (base == document.body) {
            document.body.style.overflow = "hidden";
            this.parentDhxWins = new dhtmlXWindows();
            this.parentDhxWins.setSkin(this.skin);
            this.parentDhxWindow = this.parentDhxWins.createWindow("parentDhxWins", 10, 10, 800, 600);
            this.parentDhxWindow.setToFullScreen(true);
            var layout = this.parentDhxWindow.attachLayout(view, this.skin);
            return layout;
        } else if (typeof(base) == "object") {
            this.parentDhxWins = new dhtmlXWindows();
            this.parentDhxWins.setSkin(this.skin);
            this.parentDhxWins.enableAutoViewport(false);
            this.parentDhxWins.setViewport(0, 0, base.offsetWidth, base.offsetHeight, base);
            this.parentDhxWindow = this.parentDhxWins.createWindow("parentDhxWins", 0, 0, base.offsetWidth, base.offsetHeight);
            this.parentDhxWindow.denyMove();
            this.parentDhxWindow.denyResize();
            this.parentDhxWindow.denyPark();
            this.parentDhxWindow.button("close").disable();
            this.parentDhxWins._attachWindowContentTo(this.parentDhxWindow, base);
            var globalParent = this;
            // this.parentDhxWindow.setToFullScreen(true);
            this.layout = this.parentDhxWindow.attachLayout(view, this.skin);
            this.layout.globalParent = globalParent;
            return this.layout;
        }
    }

    if (_isOpera) {
        this._opera950FixBorder = "#FFFFFF 0px solid";
        switch (this.skin) {
            case "dhx_black":
                this._opera950FixBorder = "#333333 1px solid";
                break;
            case "dhx_blue":
                this._opera950FixBorder = "#D3E2E5 1px solid";
                break;
        }
    }

    this.items = new Array();
    /**
    *   @desc: returns cell's object by cell's id
    *   @param: id - cell's id
    *   @type: public
    */
    this.cells = function(id) {
        if (this.polyObj[id] != null) { return this.polyObj[id]; }
        return null;
    }
    /**
    *   @desc: returns cell's id by index
    *   @param: ind - cell's index
    *   @type: public
    */
    this.getIdByIndex = function(ind) {
        if (ind < 0) return null;
        if (ind >= this.items.length) return null;
        // return this.items[ind]._link;
        return this.items[ind]._idd;
    }
    /**
    *   @desc: returns cell's index by id
    *   @param: id - cell's id
    *   @type: public
    */
    this.getIndexById = function(id) {
        if (this.cells(id) != null) return this.cells(id).getIndex();
        return null;
    }

    this.base = base; // (typeof(base)=="object"?base:document.getElementById(base));

    this.imagePath = "codebase/imgs/";
    /**
    *   @desc: set path to images
    *   @param: path - path on hard disk
    *   @type: public
    */
    this.setImagePath = function(path) {
        this.imagePath = path;
    }

    // if (parentWindow != null) { this._parentWindow = parentWindow; }

    this.polyObj = {};
    this.sepHor = new Array();
    this.sepVer = new Array();

    this._layoutView = (view!=null?String(view).toUpperCase():"3E");

    this._minWidth = 40;
    this._minHeight = 40;
    //
    this._CPanelBtnsWidth = 32;
    //
    // this._collapsedW = 7;//20;
    // this._collapsedH = (_isFF?7:8);//(_isFF?20:22);

    this.skinParams = { "standard"      : {"hor_sep_height": 6, "cpanel_height": 31, "cpanel_collapsed_width": 20, "cpanel_collapsed_height": (_isFF?20:22)},
                "glassy_blue"   : {"hor_sep_height": 4, "cpanel_height": 23, "cpanel_collapsed_width":  7, "cpanel_collapsed_height": (_isFF?7:8)},
                "glassy_caramel"    : {"hor_sep_height": 4, "cpanel_height": 23, "cpanel_collapsed_width":  7, "cpanel_collapsed_height": (_isFF?7:8)},
                "glassy_greenapple" : {"hor_sep_height": 4, "cpanel_height": 23, "cpanel_collapsed_width":  7, "cpanel_collapsed_height": (_isFF?7:8)},
                "glassy_rainy"  : {"hor_sep_height": 4, "cpanel_height": 23, "cpanel_collapsed_width":  7, "cpanel_collapsed_height": (_isFF?7:8)},
                "glassy_raspberries": {"hor_sep_height": 4, "cpanel_height": 23, "cpanel_collapsed_width":  7, "cpanel_collapsed_height": (_isFF?7:8)},
                "glassy_yellow" : {"hor_sep_height": 4, "cpanel_height": 23, "cpanel_collapsed_width":  7, "cpanel_collapsed_height": (_isFF?7:8)},
                "dhx_black"     : {"hor_sep_height": 5, "cpanel_height": (_isOpera?34:34), "cpanel_collapsed_width":  18, "cpanel_collapsed_height": 18},
                "dhx_blue"      : {"hor_sep_height": 5, "cpanel_height": (_isOpera?34:34), "cpanel_collapsed_width":  18, "cpanel_collapsed_height": 18}
    };
    // ff - 34,18
    // ie - 34,18
    // safari - 34,18
    // opera ?
    this._CPanelHeight = this.skinParams[this.skin]["cpanel_height"];
    this._collapsedW = this.skinParams[this.skin]["cpanel_collapsed_width"];
    this._collapsedH = this.skinParams[this.skin]["cpanel_collapsed_height"];
    //
    this.tpl = document.createElement("TABLE");
    this.tpl.className = "dhtmlxLayoutPolyContainer_"+this.skin;
    this.tpl.cellSpacing = 0;
    this.tpl.cellPadding = 0;
    var bd = document.createElement("TBODY");
    this.tpl.appendChild(bd);
    this.tpl.border = 0;
    //
    this.tplSizes = {};
    this.tplData = {
            "1C": '<layout><autosize hor="a" ver="a" rows="1" cols="1"/><row><cell obj="a" resize="ver" neighbors="a"/></row></layout>',
            "2E": '<layout><autosize hor="a;b" ver="b" rows="2" cols="1"/><row><cell obj="a" a_height="*" resize="ver" neighbors="a;b"/></row><row sep="true"><cell sep="hor" top="a" bottom="b" dblclick="a"/></row><row><cell obj="b" b_height="*" resize="ver" neighbors="a;b"/></row></layout>',
            "2U": '<layout><autosize hor="b" ver="a;b" rows="1" cols="2"/><row><cell obj="a" a_width="*" resize="hor" neighbors="a;b"/><cell sep="ver" left="a" right="b"/><cell obj="b" b_width="*" resize="hor" neighbors="a;b"/></row></layout>',
            "3E": '<layout><autosize hor="a;b;c" ver="c" rows="3" cols="1"/><row><cell obj="a" a_height="*" resize="ver" neighbors="a;b;c"/></row><row sep="yes"><cell sep="hor" top="a" bottom="b;c" dblclick="a"/></row><row><cell obj="b" b_height="*" resize="ver" neighbors="a;b;c"/></row><row sep="yes"><cell sep="hor" top="a;b" bottom="c" dblclick="b"/></row><row><cell obj="c" c_height="*" resize="ver" neighbors="a;b;c"/></row></layout>',
            "3J": '<layout><autosize hor="b" ver="b;c" rows="2" cols="2"/><row><cell obj="a" a_width="*" a_height="*" resize="ver" neighbors="a;c"/><cell sep="ver" left="a,c" right="b" dblclick="b" rowspan="3"/><cell obj="b" b_width="*" resize="hor" neighbors="a,c;b" rowspan="3"/></row><row sep="yes"><cell sep="hor" top="a" bottom="c" dblclick="a"/></row><row><cell obj="c" c_width="*" c_height="*" resize="ver" neighbors="a;c"/></row></layout>',
            "3L": '<layout><autosize hor="b;c" ver="a;c" rows="2" cols="2"/><row><cell obj="a" a_width="*" resize="hor" neighbors="a;b,c" rowspan="3"/><cell sep="ver" left="a" right="b,c" dblclick="a" rowspan="3"/><cell obj="b" b_width="*" b_height="*" resize="ver" neighbors="b;c"/></row><row sep="true"><cell sep="hor" top="b" dblclick="b" bottom="c"/></row><row><cell obj="c" c_width="*" c_height="*" resize="ver" neighbors="b;c"/></row></layout>',
            "3T": '<layout><autosize hor="a;c" ver="b;c" rows="2" cols="2"/><row><cell obj="a" a_height="*" resize="ver" neighbors="a;b,c" colspan="3"/></row><row sep="true"><cell sep="hor" top="a" bottom="b,c" dblclick="a" colspan="3"/></row><row><cell obj="b" b_width="*" b_height="*" resize="hor" neighbors="b;c"/><cell sep="ver" left="b" right="c" dblclick="b"/><cell obj="c" c_width="*" c_height="*" resize="hor" neighbors="b;c"/></row></layout>',
            "3U": '<layout><autosize hor="b;c" ver="c" rows="2" cols="2"/><row><cell obj="a" a_width="*" a_height="*" resize="hor" neighbors="a;b"/><cell sep="ver" left="a" right="b" dblclick="a"/><cell obj="b" b_width="*" b_height="*" resize="hor" neighbors="a;b"/></row><row sep="true"><cell sep="hor" top="a,b" bottom="c" dblclick="c" colspan="3"/></row><row><cell obj="c" c_height="*" resize="ver" neighbors="a,b;c" colspan="3"/></row></layout>',
            "3W": '<layout><autosize hor="c" ver="a;b;c" rows="1" cols="3"/><row><cell obj="a" a_width="*" resize="hor" neighbors="a;b;c"/><cell sep="ver" left="a" right="b;c" dblclick="a"/><cell obj="b" b_width="*" resize="hor" neighbors="a;b;c"/><cell sep="ver" left="a;b" right="c" dblclick="b"/><cell obj="c" c_width="*" resize="hor" neighbors="a;b;c"/></row></layout>',
            "4H": '<layout><autosize hor="d" ver="a;c;d" rows="2" cols="3"/><row><cell obj="a" a_width="*" resize="hor" neighbors="a;b,c;d" rowspan="3"/><cell sep="ver" left="a" right="b,c;d" dblclick="a" rowspan="3"/><cell obj="b" b_width="*" b_height="*" resize="ver" neighbors="b;c"/><cell sep="ver" left="a;b,c" right="d" dblclick="d" rowspan="3"/><cell obj="d" d_width="*" resize="hor" neighbors="a;b,c;d" rowspan="3"/></row><row sep="true"><cell sep="hor" top="b" dblclick="b" bottom="c"/></row><row><cell obj="c" c_width="*" c_height="*" resize="ver" neighbors="b;c"/></row></layout>',
            "4I": '<layout><autosize hor="a;c;d" ver="d" rows="3" cols="2"/><row><cell obj="a" a_height="*" resize="ver" neighbors="a;b,c;d" colspan="4"/></row><row sep="true"><cell sep="hor" top="a" bottom="b,c;d" dblclick="a" colspan="4"/></row><row><cell obj="b" b_width="*" b_height="*" resize="hor" neighbors="b;c"/><cell sep="ver" left="b" dblclick="b" right="c"/><cell obj="c" c_width="*" c_height="*" resize="hor" neighbors="b;c"/></row><row sep="true"><cell sep="hor" top="a;b,c" bottom="d" dblclick="d" colspan="4"/></row><row><cell obj="d" d_height="*" resize="ver" neighbors="a;b,c;d" colspan="4"/></row></layout>',
            "4T": '<layout><autosize hor="a;d" ver="b;c;d" rows="2" cols="3"/><row><cell obj="a" a_height="*" resize="ver" neighbors="a;b,c,d" colspan="5"/></row><row sep="true"><cell sep="hor" top="a" bottom="b,c,d" dblclick="a" colspan="5"/></row><row><cell obj="b" b_width="*" b_height="*" resize="hor" neighbors="b;c;d"/><cell sep="ver" left="b" right="c;d" dblclick="b"/><cell obj="c" c_width="*" c_height="*" resize="hor" neighbors="b;c;d"/><cell sep="ver" left="b;c" right="d" dblclick="c"/><cell obj="d" d_width="*" d_height="*" resize="hor" neighbors="b;c;d"/></row></layout>',
            "4U": '<layout><autosize hor="c;d" ver="d" rows="2" cols="3"/><row><cell obj="a" a_width="*" a_height="*" resize="hor" neighbors="a;b;c"/><cell sep="ver" left="a" right="b;c" dblclick="a"/><cell obj="b" c_width="*" b_height="*" resize="hor" neighbors="a;b;c"/><cell sep="ver" left="a;b" right="c" dblclick="b"/><cell obj="c" c_width="*" c_height="*" resize="hor" neighbors="a;b;c"/></row><row sep="true"><cell sep="hor" top="a,b,c" bottom="d" dblclick="d" colspan="5"/></row><row><cell obj="d" d_height="*" resize="ver" neighbors="a,b,c;d" colspan="5"/></row></layout>',
            "5H": '<layout><autosize hor="b;c;d" ver="a;c;e" rows="3" cols="3"/><row><cell obj="a" a_width="*" resize="hor" neighbors="a;b,c,d" rowspan="5"/><cell sep="ver" left="a" right="b,c,d;e" dblclick="a" rowspan="5"/><cell obj="b" b_width="*" b_height="*" resize="ver" neighbors="b;c;d"/><cell sep="ver" left="a;b,c,d" right="e" dblclick="e" rowspan="5"/><cell obj="e" e_width="*" resize="hor" neighbors="b,c,d;e" rowspan="5"/></row><row sep="true"><cell sep="hor" top="b" dblclick="b" bottom="c;d"/></row><row><cell obj="c" c_width="*" c_height="*" resize="ver" neighbors="b;c;d"/></row><row sep="true"><cell sep="hor" top="b;c" dblclick="c" bottom="d"/></row><row><cell obj="d" d_width="*" d_height="*" resize="ver" neighbors="b;c;d"/></row></layout>',
            "5I": '<layout><autosize hor="a;d;e" ver="e" rows="3" cols="3"/><row><cell obj="a" a_height="*" resize="ver" neighbors="a;b,c,d;e" colspan="5"/></row><row sep="match"><cell sep="hor" top="a" bottom="b,c,d;e" dblclick="a" colspan="5"/></row><row><cell obj="b" b_width="*" b_height="*" resize="hor" neighbors="b;c;d"/><cell sep="ver" left="b" right="c;d" dblclick="b"/><cell obj="c" c_width="*" c_height="*" resize="hor" neighbors="b;c;d"/><cell sep="ver" left="b;c" right="d" dblclick="c"/><cell obj="d" d_width="*" d_height="*" resize="hor" neighbors="b;c;d"/></row><row sep="match"><cell sep="hor" top="a;b,c,d" bottom="e" dblclick="e" colspan="5"/></row><row><cell obj="e" e_height="*" resize="ver" neighbors="a;b,c,d;e" colspan="5"/></row></layout>',
            "6I": '<layout><autosize hor="a;e;f" ver="f" rows="3" cols="4"/><row><cell obj="a" a_height="*" resize="ver" neighbors="a;b,c,d,e;f" colspan="7"/></row><row sep="true"><cell sep="hor" top="a" bottom="b,c,d,e;f" dblclick="a" colspan="7"/></row><row><cell obj="b" b_width="*" b_height="*" resize="hor" neighbors="b;c;d;e"/><cell sep="ver" left="b" right="c;d;e" dblclick="b"/><cell obj="c" c_width="*" c_height="*" resize="hor" neighbors="b;c;d;e"/><cell sep="ver" left="b;c" right="d;e" dblclick="c"/><cell obj="d" d_width="*" d_height="*" resize="hor" neighbors="b;c;d;e"/><cell sep="ver" left="b;c;d" right="e" dblclick="d"/><cell obj="e" e_width="*" e_height="*" resize="hor" neighbors="b;c;d;e"/></row><row sep="true"><cell sep="hor" top="a;b,c,d,e" bottom="f" dblclick="f" colspan="7"/></row><row><cell obj="f" f_height="*" resize="ver" neighbors="a;b,c,d,e;f" colspan="7"/></row></layout>'
    };
    this._effects = { "collapse": false, "resize": false, "highlight": true };

    this.sizer = document.createElement("DIV");
    this.sizer.className = "dhxLayout_Sizer_"+this.skin;
    this.sizer.style.display = "none";
    document.body.appendChild(this.sizer);

    this._attachSizer = function(obj) {
        that.sizer.style.left = getAbsoluteLeft(obj)+"px";
        that.sizer.style.top = getAbsoluteTop(obj)+"px";
        that.sizer.style.width = obj.offsetWidth+"px";
        that.sizer.style.height = obj.offsetHeight+"px";
        that.sizer.style.display = "";
        that.sizer.className = "dhxLayout_Sizer_"+that.skin;
        if (obj._dir != null) { that.sizer.className += " "+(obj._dir=="hor"?"dhxCursorNResize":"dhxCursorWResize"); }
    }

    /**
    *   @desc: returns array with available layout patterns
    *   @type: public
    */
    this.listViews = function() {
        var views = new Array();
        for (var a in this.tplData) { views[views.length] = a; }
        return views;
    }
    this._init = function() {
        this.obj = document.createElement("DIV");
        this.obj.className = "dhtmlxLayoutObject";
        this.base.appendChild(this.obj);
        this.obj.appendChild(this.tpl);
        this.w = this.obj.offsetWidth;
        this.h = this.obj.offsetHeight;
        this.dhxWins = new dhtmlXWindows();
        this.dhxWins.setSkin(this.skin);
        // this.dhxWins.enableAutoViewport(false);
        // this.dhxWins.setViewport(0, 0, 800, 600, this.base);
        // this.dhxWins.setImagePath("../dhtmlxWindows/codebase/imgs/");
        this.dhxWins.setImagePath(this.imagePath);
        this.dhxWins.attachEvent("onTextChange", that._changeCPanelText);
        this.dhxWins.dhxLayout = this;
        //
        this._xmlLoader.loadXMLString(this.tplData[this._layoutView]!=null?this.tplData[this._layoutView]:this.tplData["3E"]);
    }

    this._autoHor = new Array();
    this._autoVer = new Array();
    // minimal dimension for parent window
    this._dimension = new Array(320, 200);
    this._rowsRatio = 100;
    this._colsRatio = 100;
    /*
    this._doOnLoad = function(){}
    this.loadXML = function(xmlFile, onLoadFunction) {
        if (onLoadFunction != null) { this._doOnLoad = function() { onLoadFunction(); } }
        this._xmlLoader.loadXML(xmlFile);
    }
    */

    this._xmlParser = function() {
        var usedRows = 0;
        var totalHeight = "none";
        var usedHeight = 0;
        var sepHeight = that.skinParams[that.skin]["hor_sep_height"];
        if (that.base.style.height != null) { totalHeight = parseInt(that.base.style.height); }
        if (isNaN(totalHeight)) { totalHeight = that.base.offsetHeight; }
        if (isNaN(totalHeight)) { alert("init error, incorrect height of parent object, aborted"); return; }
        var root = this.getXMLTopNode("layout");
        for (var q=0; q<root.childNodes.length; q++) {
            if (root.childNodes[q].tagName == "row") {
                var row = root.childNodes[q];
                var tr = document.createElement("TR");
                var rowHeight = "";
                if (row.getAttribute("sep") != null) {
                    tr.style.height = sepHeight+"px";
                    usedHeight += sepHeight;
                    //usedRows++;
                } else {
                    if (usedRows < that._totalRows - 1) {
                        rowHeight = Math.round((totalHeight - (that._totalRows-1)*sepHeight)/that._totalRows);
                    } else {
                        rowHeight = totalHeight - usedHeight;
                    }
                    // tr.style.height = rowHeight+"px";
                    usedHeight += rowHeight;
                    usedRows++;
                }
                //alert(rowHeight)
                // tr._collapse = new Array();
                that.tpl.childNodes[0].appendChild(tr);
                for (var w=0; w<row.childNodes.length; w++) {
                    if (row.childNodes[w].tagName == "cell") {
                        var cell = row.childNodes[w];
                        var td = document.createElement("TD");
                        td._dir = "null";

                        if (cell.getAttribute("obj") != null) {
                            var obj = cell.getAttribute("obj");
                            td.style.height = rowHeight;
                            //var item = Number(obj.replace("p",""))-1;
                            //that.items[item] = td;

                            //td._id = obj;
                            //td._ind = item;

                            td.className = "dhtmlxLayoutSinglePoly";
                            td.innerHTML = "";//"<div class='dhtmlxPolyInnerContainer'>&nbsp;</div>";
                            td._minW = (cell.getAttribute("minWidth") != null ? Number(cell.getAttribute("minWidth")):that._minWidth);
                            td._minH = (cell.getAttribute("minHeight") != null ? Number(cell.getAttribute("minHeight")):that._minHeight);
                            td._initCPanel = (cell.getAttribute("cpanel") != null ? (cell.getAttribute("cpanel")=="false"?false:true):true);
                            td._resize = cell.getAttribute("resize");
                            if (cell.getAttribute("width") != null) { td.style.width = cell.getAttribute("width"); }
                            if (cell.getAttribute("height") != null) { td.style.height = cell.getAttribute("height"); }
                            // td._initW = (cell.getAttribute("width")!=null?cell.getAttribute("width"):"*");
                            // td._initH = (cell.getAttribute("height")!=null?cell.getAttribute("height"):"*");
                            var rd = String(cell.getAttribute("neighbors")).split(";");
                            for (var e=0; e<rd.length; e++) { var p = String(rd[e]).split(","); if (p.length > 1) { rd[e] = p; } }
                            td._rowData = rd;
                            that.polyObj[obj] = td;
                        }
                        if (cell.getAttribute("sep") != null) {
                            var sep = cell.getAttribute("sep");
                            if (sep == "hor") {
                                td.className = "dhtmlxLayoutPolySplitterHor";
                                td._dir = "hor";
                                // top side
                                var top = cell.getAttribute("top").split(";");
                                for (var e=0; e<top.length; e++) { var p = String(top[e]).split(","); if (p.length > 1) { top[e] = p; } }
                                td._top = top;
                                // bottom side
                                var bottom = cell.getAttribute("bottom").split(";");
                                for (var e=0; e<bottom.length; e++) { var p = String(bottom[e]).split(","); if (p.length > 1) { bottom[e] = p; } }
                                td._bottom = bottom;
                                that.sepHor[that.sepHor.length] = td;
                            } else {
                                td.className = "dhtmlxLayoutPolySplitterVer";
                                td._dir = "ver";
                                // left side
                                var left = cell.getAttribute("left").split(";");
                                for (var e=0; e<left.length; e++) { var p = String(left[e]).split(","); if (p.length > 1) { left[e] = p; } }
                                td._left = left;
                                // right side
                                var right = cell.getAttribute("right").split(";");
                                for (var e=0; e<right.length; e++) { var p = String(right[e]).split(","); if (p.length > 1) { right[e] = p; } }
                                td._right = right;
                                that.sepVer[that.sepVer.length] = td;
                            }
                            td._dblClick = cell.getAttribute("dblclick");
                            td._isSep = true;
                            td.innerHTML = "&nbsp;";
                        }
                        if (cell.getAttribute("colspan") != null) { td.colSpan = cell.getAttribute("colspan"); }
                        if (cell.getAttribute("rowspan") != null) { td.rowSpan = cell.getAttribute("rowspan"); }
                        tr.appendChild(td);
                    }
                }
            }
            // autosize data
            if (root.childNodes[q].tagName == "autosize") {
                that._autoHor = (root.childNodes[q].getAttribute("hor")).split(";");
                that._autoVer = (root.childNodes[q].getAttribute("ver")).split(";");
                that._totalCols = root.childNodes[q].getAttribute("cols");
                that._totalRows = root.childNodes[q].getAttribute("rows");
                that._dimension[0] = that._totalCols * that._colsRatio;
                that._dimension[1] = that._totalRows * that._rowsRatio;
            }
        }
        if (that._parentWindow != null) {
            that._parentWindow.setMinDimension(that._dimension[0], that._dimension[1]);
        }
        that._buildSurface();
        // that._doOnLoad();
    }
    this._xmlLoader = new dtmlXMLLoaderObject(this._xmlParser, window);
    this._availAutoSize = { "1C_hor": new Array("a"),
                "1C_ver": new Array("a"),
                "2E_hor": new Array("a;b"),
                "2E_ver": new Array("a", "b"),
                "2U_hor": new Array("a", "b"),
                "2U_ver": new Array("a;b"),
                "3E_hor": new Array("a;b;c"),
                "3E_ver": new Array("a", "b", "c"),
                "3J_hor": new Array("a;c", "b"),
                "3J_ver": new Array("a;b", "c;b"),
                "3L_hor": new Array("a", "b;c"),
                "3L_ver": new Array("a;b", "a;c"),
                "3T_hor": new Array("a;b", "a;c"),
                "3T_ver": new Array("a", "b;c"),
                "3U_hor": new Array("a;c", "b;c"),
                "3U_ver": new Array("a;b", "c"),
                "3W_hor": new Array("a", "b", "c"),
                "3W_ver": new Array("a;b;c"),
                "4H_hor": new Array("a", "b;c", "d"),
                "4H_ver": new Array("a;b;d", "a;c;d"),
                "4I_hor": new Array("a;b;d", "a;c;d"),
                "4I_ver": new Array("a", "b;c", "d"),
                "4T_hor": new Array("a;b", "a;c", "a;d"),
                "4T_ver": new Array("a", "b;c;d"),
                "4U_hor": new Array("a;d", "b;d", "c;d"),
                "4U_ver": new Array("a;b;c", "d"),
                "5H_hor": new Array("a", "b;c;d", "e"),
                "5H_ver": new Array("a;b;e", "a;c;e", "a;d;e"),
                "5I_hor": new Array("a;b;e", "a;c;e", "a;d;e"),
                "5I_ver": new Array("a", "b;c;d", "e"),
                "6I_hor": new Array("a;b;f", "a;c;f", "a;d;f", "a;e;f"),
                "6I_ver": new Array("a", "b;c;d;e", "f")
    };
    /**
    *   @desc: returns array with available autosize settings
    *   @type: public
    */
    this.listAutoSizes = function() {
        var hor = this._availAutoSize[this._layoutView+"_hor"];
        var ver = this._availAutoSize[this._layoutView+"_ver"];
        var currentHor = (this._autoHor).join(";");
        var currentVer = (this._autoVer).join(";");
        return new Array(currentHor, currentVer, hor, ver);
    }
    /**
    *   @desc: sets autosize for the layout
    *   @param: hor - cells that will be autosized horizontally
    *   @param: ver - cells that will be autosized vertically
    *   @type: public
    */
    this.setAutoSize = function(hor, ver) {
        if (hor != null) {
            var allow = false;
            var data = this._availAutoSize[this._layoutView+"_hor"];
            for (var q=0; q<data.length; q++) { allow = allow || (data[q] == hor); }
            if (allow == true) { this._autoHor = hor.split(";"); }
        }
        if (ver != null) {
            var allow = false;
            var data = this._availAutoSize[this._layoutView+"_ver"];
            for (var q=0; q<data.length; q++) { allow = allow || (data[q] == ver); }
            if (allow == true) { this._autoVer = ver.split(";"); }
        }
    }

    this._buildSurface = function() {

        for (var r=0; r<this.tpl.childNodes[0].childNodes.length; r++) {
            var tr = this.tpl.childNodes[0].childNodes[r];
            for (var c=0; c<tr.childNodes.length; c++) {
                var td = tr.childNodes[c];
                var that = this;
                if (!td._isSep) {
                    td._isLayoutCell = true;
                    /**
                    *   @desc: returns cell's id
                    *   @type: public
                    */
                    td.getId = function() {
                        return this._idd;
                    }
                    /**
                    *   @desc: returns cell's index
                    *   @type: public
                    */
                    td.getIndex = function() {
                        return this._ind;
                    }
                    /**
                    *   @desc: shows a header
                    *   @type: public
                    */
                    td.showHeader = function() {
                        that.showPanel(this._idd);
                    }
                    /**
                    *   @desc: hides a header
                    *   @type: public
                    */
                    td.hideHeader = function() {
                        that.hidePanel(this._idd);
                    }
                    /**
                    *   @desc: returns true if a header is visible
                    *   @type: public
                    */
                    td.isHeaderVisible = function() {
                        return that.isPanelVisible(this._idd);
                    }
                    /**
                    *   @desc: set header's text
                    *   @param: text - new header's text
                    *   @type: public
                    */
                    td.setText = function(text) {
                        that.setText(this._idd, text);
                    }
                    /**
                    *   @desc: expands a cell
                    *   @type: public
                    */
                    td.expand = function() {
                        if (!that._isCollapsed(this._idd)) { return; }
                        that._expand(this._idd, "hide");
                    }
                    /**
                    *   @desc: collapses a cell
                    *   @type: public
                    */
                    td.collapse = function() {
                        if (that._isCollapsed(this._idd)) { return; }
                        that._collapse(this._idd, "hide");
                    }
                    /**
                    *   @desc: return true if a cell is collapsed
                    *   @type: public
                    */
                    td.isCollapsed = function() {
                        return that._isCollapsed(this._idd);
                    }
                    /**
                    *   @desc: docks a cell from a window
                    *   @type: public
                    */
                    td.dock = function() {
                        if (!that._isCollapsed(this._idd)) { return; }
                        that._expand(this._idd, "dock");
                        that.dockWindow(this._idd, this._wId);
                    }
                    /**
                    *   @desc: undocks a cell to a window
                    *   @type: public
                    */
                    td.undock = function() {
                        if (that._isCollapsed(this._idd)) { return; }
                        that.unDockWindow(this._wId);
                        that._collapse(this._idd, "dock");
                    }
                    /**
                    *   @desc: sets cell's width
                    *   @param: width
                    *   @type: public
                    */
                    td.setWidth = function(width) {
                        if (!Number(width)) { return; }
                        that._setWidth(this._idd, width);
                    }
                    /**
                    *   @desc: returns cell's width
                    *   @type: public
                    */
                    td.getWidth = function() {
                        return parseInt(this.style.width);
                    }
                    /**
                    *   @desc: sets cell's height
                    *   @param: height
                    *   @type: public
                    */
                    td.setHeight = function(height) {
                        if (!Number(height)) { return; }
                        that._setHeight(this._idd, height);
                    }
                    /**
                    *   @desc: returns cell's height
                    *   @type: public
                    */
                    td.getHeight = function() {
                        return parseInt(this.style.height);
                    }
                    /**
                    *   @desc: fixes cell's size (block resize)
                    *   @param: width - true/false
                    *   @param: height - true/false
                    *   @type: public
                    */
                    td.fixSize = function(width, height) {
                        that._fixSize(this._idd, width, height);
                    }
                    /**
                    *   @desc: attaches a dhtmlxGrid to a cell
                    *   @type: public
                    */
                    td.attachGrid = function() {
                        this._grid = this.window.attachGrid();
                        return this._grid;
                    }
                    /**
                    *   @desc: attaches a dhtmlxTree to a cell
                    *   @param: root - not mandatory, tree super root, see dhtmlxTree documentation for details
                    *   @type: public
                    */
                    td.attachTree = function(root) {
                        this._tree = this.window.attachTree(root);
                        return this._tree;
                    }
                    /**
                    *   @desc: attaches a dhtmlxTabbar to a cell
                    *   @type: public
                    */
                    td.attachTabbar = function() {
                        this._tabbar = this.window.attachTabbar();
                        return this._tabbar;
                    }
                    /**
                    *   @desc: attaches a dhtmlxAccordion to a cell
                    *   @type: public
                    */
                    td.attachAccordion = function() {
                        this._accordion = this.window.attachAccordion();
                        return this._accordion;
                    }
                    /**
                    *   @desc: attaches a dhtmlxFolders to a cell
                    *   @type: public
                    */
                    td.attachFolders = function() {
                        this._folders = this.window.attachFolders();
                        return this._folders;
                    }
                    /**
                    *   @desc: attaches a status bar to a cell
                    *   @type: public
                    */
                    td.attachStatusBar = function() {
                        this._status = this.window.attachStatusBar();
                        return this._status;
                    }
                    /**
                    *   @desc: attaches a dhtmlxMenu to a cell
                    *   @type: public
                    */
                    td.attachMenu = function() {
                        this._menu = this.window.attachMenu();
                        return this._menu;
                    }
                    /**
                    *   @desc: attaches a dhtmlxToolbar to a cell
                    *   @type: public
                    */
                    td.attachToolbar = function() {
                        this._toolbar = this.window.attachToolbar();
                        return this._toolbar;
                    }
                    /**
                    *   @desc: attaches a dhtmlxEditor to a cell
                    *   @type: public
                    */
                    td.attachEditor = function() {
                        this._editor = this.window.attachEditor();
                        return this._editor;
                    }
                    /**
                    *   @desc: attaches an object to a cell
                    *   @param: obj - object/object id
                    *   @type: public
                    */
                    td.attachObject = function(obj) {
                        this._obj = this.window.attachObject(obj);
                    }
                    /**
                    *   @desc: attaches an url into a cell
                    *   @param: url
                    *   @type: public
                    */
                    td.attachURL = function(url) {
                        this._url = this.window.attachURL(url);
                        this._frame = this.window._frame;
                    }
                }
                //
                if (td._dir == "ver") {
                    td.onselectstart = function(e) { e = e||event; e.returnValue = false; }
                    td.onmousedown = function(e) {
                        var p = that._findDockCellsVer(this);
                        that._resAreaData = new Array();
                        if (p[0] != null && p[1] != null) {
                            if (String(document.body.className).search("dhxCursorWResize") == -1) { document.body.className += " dhxCursorWResize";
                            }
                            e = e||event;
                            that._resObj = this;
                            that._anyExpL = p[0];
                            that._anyExpR = p[1];
                            that._collectResAreaData(p);
                            // not needed
                            // that._resXScrollLeft = that._countScrollLeft(e.target||e.srcElement);
                            that._resX = e.clientX;// + that._resXScrollLeft;
                            // sizmple resize
                            if (that._effects["resize"] == false) {
                                that._attachSizer(this);
                                that.sizer._leftXStart = parseInt(that.sizer.style.left);
                                // getting neares objects
                                var objLeft = that.polyObj[that._anyExpL[0]];
                                that._resXMaxWidthLeft = parseInt(objLeft.style.width)-that._minWidth;
                                var objRight = that.polyObj[that._anyExpR[0]];
                                that._resXMaxWidthRight = parseInt(objRight.style.width)-that._minWidth;
                                // checking alternative min width in attached layout case
                                if (that._alterSizes.length > 0) {
                                    for (var q=0; q<that._alterSizes.length; q++) {
                                        for (var w=0; w<that._anyExpL.length; w++) {
                                            if (that._alterSizes[q][0] == that._anyExpL[w]) {
                                                var newVal = that._resXMaxWidthLeft = parseInt(objLeft.style.width)-that._alterSizes[q][1];
                                                if (newVal < that._resXMaxWidthLeft) { that._resXMaxWidthLeft = newVal; }
                                            }
                                        }
                                        for (var w=0; w<that._anyExpR.length; w++) {
                                            if (that._alterSizes[q][0] == that._anyExpR[w]) {
                                                newVal = parseInt(objRight.style.width)-that._alterSizes[q][1];
                                                if (newVal < that._resXMaxWidthRight) { that._resXMaxWidthRight = newVal; }
                                            }
                                        }
                                    }
                                }
                                that._resXStart = that._resX;
                            }
                            //
                            that._resFunc = that._resizeVer;
                            that._showCovers();
                        }
                    }
                    td.onmouseup = function() {
                        if (that._effects["resize"] == true) {
                            that._resizeStop();
                            that._anyExpL = null;
                            that._anyExpR = null;
                        }
                    }
                }
                if (td._dir == "hor") {
                    td.onselectstart = function(e) { e = e||event; e.returnValue = false; }
                    td.onmousedown = function(e) {
                        var p = that._findDockCellsHor(this);
                        that._resAreaData = new Array();
                        if (p[0] != null && p[1] != null) {
                            if (String(document.body.className).search("dhxCursorNResize") == -1) { document.body.className += " dhxCursorNResize";
                            }
                            e = e||event;
                            that._resObj = this;
                            that._anyExpT = p[0];
                            that._anyExpB = p[1];
                            that._collectResAreaData(p);
                            // not needed + that._countScrollTop() not needed too
                            // that._resYScrollTop = that._countScrollTop(e.target||e.srcElement);
                            that._resY = e.clientY;// + that._resYScrollTop;
                            // sizmple resize
                            if (that._effects["resize"] == false) {
                                that._attachSizer(this);
                                that.sizer._topYStart = parseInt(that.sizer.style.top);
                                // getting neares objects
                                var objTop = that.polyObj[that._anyExpT[0]];
                                that._resYMaxHeightTop = parseInt(objTop.style.height)-that._minHeight;
                                var objBottom = that.polyObj[that._anyExpB[0]];
                                that._resYMaxHeightBottom = parseInt(objBottom.style.height)-that._minHeight;
                                // checking alternative min height in attached layout case
                                if (that._alterSizes.length > 0) {
                                    for (var q=0; q<that._alterSizes.length; q++) {
                                        for (var w=0; w<that._anyExpT.length; w++) {
                                            if (that._alterSizes[q][0] == that._anyExpT[w]) {
                                                var newVal =
                                                parseInt(objTop.style.height)-that._alterSizes[q][2]-(objTop.childNodes[0].style.display!="none"?that.skinParams[that.skin]["cpanel_height"]:0);
                                                if (newVal < that._resYMaxHeightTop) { that._resYMaxHeightTop = newVal; }
                                            }
                                        }
                                        for (var w=0; w<that._anyExpB.length; w++) {
                                                if (that._alterSizes[q][0] == that._anyExpB[w]) {
                                                    var newVal =
                                                    parseInt(objBottom.style.height)-that._alterSizes[q][2]-(objBottom.childNodes[0].style.display!=
                                                    "none"?that.skinParams[that.skin]["cpanel_height"]:0);
                                                    if (newVal < that._resYMaxHeightBottom) { that._resYMaxHeightBottom = newVal; }
                                                }
                                        }
                                    }
                                }
                                that._resYStart = that._resY;
                            }
                            //
                            that._resFunc = that._resizeHor;
                            that._showCovers();
                        }
                    }
                    td.onmouseup = function() {
                        if (that._effects["resize"] == true) {
                            that._resizeStop();
                            that._anyExpT = null;
                            that._anyExpB = null;
                        }
                    }
                }
                td.ondblclick = function() {
                    //
                    if (this._dblClick == null) { return; }
                    if (that.polyObj[this._dblClick] == null) { return; }
                    // show/hide
                    var obj = that.polyObj[this._dblClick];
                    if (obj.childNodes[0].style.display == "none") { return; }
                    if (obj._collapsed == true) {
                        //
                        that._doExpand(obj._resize, this._dblClick, obj._rowData, "hide");
                    } else {
                        // save dimension
                        obj._savedW = parseInt(obj.style.width);
                        obj._savedH = parseInt(obj.style.height);
                        //
                        that._doCollapse(obj._resize, this._dblClick, obj._rowData, "hide");
                    }
                }
            }
        }

        //return;

        //var symboLink = String("a").charCodeAt(0);

        var p = {};
        for (var a in this.polyObj) {
            var w = this.polyObj[a].offsetWidth;
            var h = this.polyObj[a].offsetHeight;
            p[a] = new Array(w,h);
        }
        var q = 1;
        for (var a in p) {
            //alert(a+" "+p[a][0]+" "+p[a][1]);
            this.polyObj[a].style.width = p[a][0]-2+"px";
            this.polyObj[a].style.height = p[a][1]-2+"px";
            this.polyObj[a]._collapsed = false;
            this.polyObj[a]._idd = a;
            this.polyObj[a]._ind = this.items.length;
            this.items[this.items.length] = this.polyObj[a];
            //
            var bar = document.createElement("DIV");
            bar._dockCell = a;
            bar._resize = this.polyObj[a]._resize;
            bar.className = "dhtmlxPolyInfoBar";
            bar.innerHTML = "<div class='dhtmlxInfoBarLabel'>&nbsp;</div>"+
                    "<div class='dhtmlxInfoBarButtonsFake'>&nbsp;</div>"+
                    "<div class='dhtmlxInfoButtonDock' title='Dock'></div>"+
                    "<div class='dhtmlxInfoButtonUnDock' style='display: none;' title='UnDock'></div>"+
                    "<div class='dhtmlxInfoButtonShowHide_"+bar._resize+"' title='Collapse'></div>";
            if (this.polyObj[a]._initCPanel == true) {
                bar._h = this._CPanelHeight;
                bar.style.display = "";
            } else {
                bar._h = 0;
                bar.style.display = "none";
            }

            this.polyObj[a].appendChild(bar);
            //

            for (var r=0; r<bar.childNodes.length; r++) {
                bar.childNodes[r].onselectstart = function(e) { e = e||event; e.returnValue = false; }
            }

            //
            var wId = "w"+a;//String(q++);
            var win = this.dhxWins.createWindow(wId, 10, 10, p[a][0], p[a][1]);
            win.hide();
            win._tmpRowData = this.polyObj[a]._rowData;
            win._tmpReszie = bar._resize;
            win._dockCell = a;
            //win.setText("dhtmlxWindow "+a);
            win.setText(a);
            //var symboLinkStr = String.fromCharCode(symboLink);
            //win.setText(symboLinkStr);
            //this.polyObj[a]._link = symboLinkStr;
            //this.cells[symboLinkStr] = this.items[symboLink-String("a").charCodeAt(0)];
            //symboLink++;
            win.button("close").hide();
            win.addUserButton("dock", 99, "Dock", "dock");
            win.button("dock").attachEvent("onClick", function(win) {
                that._doExpand(win._tmpReszie, win._dockCell, win._tmpRowData, "dock");
            });

            this.polyObj[a]._wId = wId;
            this.polyObj[a].window = win;
            bar._win = wId;

            // bar.childNodes[2].style.display = "none";
            bar.childNodes[2].onclick = function() { // dock & show
                that._expand(this.parentNode._dockCell, "dock");
            }
            bar.childNodes[3].onclick = function() { // undock & hide
                that.unDockWindow(this.parentNode._win);
                that._collapse(this.parentNode._dockCell, "dock");
            }
            bar.childNodes[4].onclick = function() { // show/hide
                var pId = this.parentNode._dockCell;
                if (that._isCollapsed(pId)) { that._expand(pId, "hide"); } else { that._collapse(pId, "hide"); }
            }

            this.dockWindow(a, wId);
        }
        this._fixIcons();
    }

    this._resX = null;
    this._resY = null;
    this._resObj = null;
    this._resFunc = null;
    //
    // optimized resize
    this._anyExpL = null;
    this._anyExpR = null;
    this._anyExpT = null;
    this._anyExpB = null;
    //
    this._expand = function(pId, mode) {
        this._doExpand(this.polyObj[pId]._resize, pId, this.polyObj[pId]._rowData, mode);
    }
    this._collapse = function(pId, mode) {
        if (this._isCollapsed(pId)) { return; }
        // save dimension
        this.polyObj[pId]._savedW = parseInt(this.polyObj[pId].style.width);
        this.polyObj[pId]._savedH = parseInt(this.polyObj[pId].style.height);
        // collapsing
        this._doCollapse(this.polyObj[pId]._resize, pId, this.polyObj[pId]._rowData, mode);
    }
    this._isCollapsed = function(pId) {
        return this.polyObj[pId]._collapsed;
    }
    // used to get alternative width/height for resising cell (in case of attached layout)
    this._checkAlterMinSize = function(data) {
        this._alterSizes = new Array();
        for (var q=0; q<data.length; q++) {
            for (var w=0; w<data[q].length; w++) {
                var win = this.polyObj[data[q][w]].window;
                if (win.layout != null) {
                    var dims = win.layout._defineWindowMinDimension(win, true);
                    dims[0] = data[q][w];
                    this._alterSizes[this._alterSizes.length] = dims;
                }
            }
        }
    }
    //
    this._findDockCellsVer = function(resObj) {
        var res = new Array(null, null);
        if (resObj == null) { return res; }
        // find nearest expanded on the left side
        var anyExpL = null;
        for (var q=resObj._left.length-1; q>=0; q--) {
            if (anyExpL == null) {
                if (typeof(resObj._left[q]) == "object") {
                    var isBlocked = false;
                    for (var w=0; w<resObj._left[q].length; w++) { isBlocked = isBlocked ||
                    (this.polyObj[resObj._left[q][w]]._isBlockedWidth||false); }
                    if (!isBlocked) { anyExpL = resObj._left[q]; }
                } else if(this.polyObj[resObj._left[q]]._collapsed == false) {
                    if (!this.polyObj[resObj._left[q]]._isBlockedWidth) { anyExpL = resObj._left[q]; }
                }
            }
        }
        // find nearest expanded on the right side
        var anyExpR = null;
        for (var q=0; q<resObj._right.length; q++) {
            if (anyExpR == null) {
                if (typeof(resObj._right[q]) == "object") {
                    var isBlocked = false;
                    for (var w=0; w<resObj._right[q].length; w++) { isBlocked = isBlocked ||
                    (this.polyObj[resObj._right[q][w]]._isBlockedWidth||false); }
                    if (!isBlocked) { anyExpR = resObj._right[q]; }
                } else if(this.polyObj[resObj._right[q]]._collapsed == false) {
                    if (!this.polyObj[resObj._right[q]]._isBlockedWidth) { anyExpR = resObj._right[q]; }
                }
            }
        }
        // nothing to resize
        if (anyExpL == null || anyExpR == null) { return res; }
        // convert to array if needed
        if (typeof(anyExpL) == "string") { anyExpL = new Array(anyExpL); }
        if (typeof(anyExpR) == "string") { anyExpR = new Array(anyExpR); }
        //
        res[0] = anyExpL;
        res[1] = anyExpR;
        // checking alter size in case of attached layout
        this._checkAlterMinSize(res);
        this._minWLAlter = 0;
        this._minWRAlter = 0;
        if (this._alterSizes.length > 0 && this._effects["resize"] == true) {
            var objL = new Array();
            var objR = new Array();
            for (var q=0; q<anyExpL.length; q++) { objL[q] = this.polyObj[anyExpL[q]]; }
            for (var q=0; q<anyExpR.length; q++) { objR[q] = this.polyObj[anyExpR[q]]; }
            for (var q=0; q<objL.length; q++) { for (var w=0; w<this._alterSizes.length; w++) { if (this._alterSizes[w][0] == objL[q]._idd &&
            this._minWLAlter < this._alterSizes[w][1]) { this._minWLAlter = this._alterSizes[w][1]; } } }
            for (var q=0; q<objR.length; q++) { for (var w=0; w<this._alterSizes.length; w++) { if (this._alterSizes[w][0] == objR[q]._idd &&
            this._maxWRAlter < this._alterSizes[w][1]) { this._minWRAlter = this._alterSizes[w][1]; } } }
        }
        return res;
    }
    //
    this._findDockCellsHor = function(resObj) {
        var res = new Array(null, null);
        if (resObj == null) { return res; }
        // find nearest expanded on the top side
        var anyExpT = null;
        for (var q=resObj._top.length-1; q>=0; q--) {
            if (anyExpT == null) {
                if (typeof(resObj._top[q]) == "object") {
                    var isBlocked = false;
                    for (var w=0; w<resObj._top[q].length; w++) { isBlocked = isBlocked ||
                    (this.polyObj[resObj._top[q][w]]._isBlockedHeight||false); }
                    if (!isBlocked) { anyExpT = resObj._top[q]; }
                } else if(this.polyObj[resObj._top[q]]._collapsed == false) {
                    if (!this.polyObj[resObj._top[q]]._isBlockedHeight) { anyExpT = resObj._top[q]; }
                }
            }
        }
        // find nearest expanded on the bottom side
        var anyExpB = null;
        for (var q=0; q<resObj._bottom.length; q++) {
            if (anyExpB == null) {
                if (typeof(resObj._bottom[q]) == "object") {
                    var isBlocked = false;
                    for (var w=0; w<resObj._bottom[q].length; w++) { isBlocked = isBlocked ||
                    (this.polyObj[resObj._bottom[q][w]]._isBlockedHeight||false); }
                    if (!isBlocked) { anyExpB = resObj._bottom[q]; }
                } else if(this.polyObj[resObj._bottom[q]]._collapsed == false) {
                    if (!this.polyObj[resObj._bottom[q]]._isBlockedHeight) { anyExpB = resObj._bottom[q]; }
                }
            }
        }
        // nothing to resize
        if (anyExpT == null || anyExpB == null) { return res; }
        // convert to array if needed
        if (typeof(anyExpT) == "string") { anyExpT = new Array(anyExpT); }
        if (typeof(anyExpB) == "string") { anyExpB = new Array(anyExpB); }
        //
        res[0] = anyExpT;
        res[1] = anyExpB;
        // checking alter size in case of attached layout
        this._checkAlterMinSize(res);
        this._minHTAlter = 0;
        this._minHBAlter = 0;
        if (this._alterSizes.length > 0 && this._effects["resize"] == true) {
            var objT = new Array();
            var objB = new Array();
            for (var q=0; q<anyExpT.length; q++) { objT[q] = this.polyObj[anyExpT[q]]; }
            for (var q=0; q<anyExpB.length; q++) { objB[q] = this.polyObj[anyExpB[q]]; }
            for (var q=0; q<objT.length; q++) { for (var w=0; w<this._alterSizes.length; w++) { if (this._alterSizes[w][0] == objT[q]._idd &&
            this._minHTAlter < this._alterSizes[w][2]) { this._minHTAlter = this._alterSizes[w][2]; } } }
            for (var q=0; q<objB.length; q++) { for (var w=0; w<this._alterSizes.length; w++) { if (this._alterSizes[w][0] == objB[q]._idd &&
            this._minHBAlter < this._alterSizes[w][2]) { this._minHBAlter = this._alterSizes[w][2]; } } }
        }
        //
        return res;
    }
    //
    this._resizeVer = function(e) {
        if (this._resObj == null || this._anyExpL == null || this._anyExpR == null) { return; }
        // simple resize
        if (this._effects["resize"] == false) {
            this._resX = e.clientX;
            var offsetX = e.clientX - this._resXStart;
            if (-offsetX > this._resXMaxWidthLeft && offsetX < 0) { offsetX = -this._resXMaxWidthLeft; this._resX = offsetX+this._resXStart; }
            if (offsetX > this._resXMaxWidthRight && offsetX > 0) { offsetX = this._resXMaxWidthRight; this._resX = offsetX+this._resXStart; }
            this.sizer.style.left = this.sizer._leftXStart+offsetX+"px";
            return;
        }
        // console.log(this._resObj._leftXStart);
        //
        var anyExpL = this._anyExpL;
        var anyExpR = this._anyExpR;
        // resize items
        var newX = e.clientX;
        var offsetX = e.clientX - that._resX;
        //
        var objL = new Array();
        var objR = new Array();
        for (var q=0; q<anyExpL.length; q++) { objL[q] = this.polyObj[anyExpL[q]]; }
        for (var q=0; q<anyExpR.length; q++) { objR[q] = this.polyObj[anyExpR[q]]; }
        //
        var wL = parseInt(objL[0].style.width);
        var wR = parseInt(objR[0].style.width);
        //
        if (offsetX < 0) {
            var newWL = wL + offsetX;
            if (newWL > objL[0]._minW && newWL > this._minWLAlter) {
                var newWR = wR + wL - newWL;
                for (var q=0; q<objL.length; q++) {
                    objL[q].style.width = newWL + "px";
                    objL[q].childNodes[1].style.width = newWL + "px";
                }
                for (var q=0; q<objR.length; q++) {
                    objR[q].style.width = newWR + "px";
                    objR[q].childNodes[1].style.width = newWR + "px";
                }
                this._resX = newX;
            }
        } else if (offsetX > 0) {
            var newWR = wR - offsetX;
            if (newWR > objR[0]._minW && newWR > this._minWRAlter) {
                var newWL = wL + wR - newWR;
                for (var q=0; q<objL.length; q++) {
                    objL[q].style.width = newWL + "px";
                    objL[q].childNodes[1].style.width = newWL + "px";
                }
                for (var q=0; q<objR.length; q++) {
                    objR[q].style.width = newWR + "px";
                    objR[q].childNodes[1].style.width = newWR + "px";
                }
                this._resX = newX;
            }
        }
    }
    this._resizeHor = function(e) {
        if (this._resObj == null || this._anyExpT == null || this._anyExpB == null) { return; }
        // simple resize
        if (this._effects["resize"] == false) {
            this._resY = e.clientY;
            var offsetY = e.clientY - this._resYStart;
            if (-offsetY > this._resYMaxHeightTop && offsetY < 0) { offsetY = -this._resYMaxHeightTop; this._resY = offsetY + this._resYStart; }
            if (offsetY > this._resYMaxHeightBottom && offsetY > 0) { offsetY = this._resYMaxHeightBottom; this._resY = offsetY + this._resYStart; }
            this.sizer.style.top = this.sizer._topYStart+offsetY+"px";
            return;
        }
        //
        var anyExpT = this._anyExpT;
        var anyExpB = this._anyExpB;
        // resize items
        var newY = e.clientY;
        var offsetY = e.clientY - that._resY;
        //
        var objT = new Array();
        var objB = new Array();
        for (var q=0; q<anyExpT.length; q++) { objT[q] = this.polyObj[anyExpT[q]]; }
        for (var q=0; q<anyExpB.length; q++) { objB[q] = this.polyObj[anyExpB[q]]; }
        //
        var hT = parseInt(objT[0].style.height);
        var hB = parseInt(objB[0].style.height);
        //
        if (offsetY < 0) {
            var newHT = hT + offsetY;
            if (newHT > objT[0]._minH + this._minHTAlter) {
                var newHB = hB + hT - newHT;
                for (var q=0; q<objT.length; q++) {
                    objT[q].style.height = newHT + "px";
                    objT[q].childNodes[1].style.height = newHT - objT[q].childNodes[0]._h + "px";
                }
                for (var q=0; q<objB.length; q++) {
                    objB[q].style.height = newHB + "px";
                    objB[q].childNodes[1].style.height = newHB - objB[q].childNodes[0]._h + "px";
                }
                this._resY = newY;
            }
        } else if (offsetY > 0) {
            var newHB = hB - offsetY;
            // console.log(newHB, objB[0]._minH, this._minHBAlter)
            if (newHB > objB[0]._minH + this._minHBAlter) {
                var newHT = hT + hB - newHB;
                for (var q=0; q<objT.length; q++) {
                    objT[q].style.height = newHT + "px";
                    objT[q].childNodes[1].style.height = newHT - objT[q].childNodes[0]._h + "px";
                }
                for (var q=0; q<objB.length; q++) {
                    objB[q].style.height = newHB + "px";
                    objB[q].childNodes[1].style.height = newHB - objB[q].childNodes[0]._h + "px";
                }
                this._resY = newY;
            }
        }
    }

    this._resizeStop = function() {
        document.body.className = String(document.body.className).replace(/dhxCursorWResize/g,"").replace(/dhxCursorNResize/g,"");
        if (this._resObj == null) { return; }
        // simple resize
        if (this._effects["resize"] == false) {
            this.sizer.style.display = "none";
            if (this._resObj._dir == "hor") {
                var objTop = (typeof(this._anyExpT[0])=="object"?this._anyExpT[0][0]:this._anyExpT[0]);
                var offsetY = this._resY-this._resYStart;
                var newH = parseInt(this.polyObj[objTop].style.height)+offsetY;
                this._setHeight(objTop, newH);
            } else {
                var objLeft = (typeof(this._anyExpL[0])=="object"?this._anyExpL[0][0]:this._anyExpL[0]);
                var offsetX = this._resX-this._resXStart;
                var newW = parseInt(this.polyObj[objLeft].style.width)+offsetX;
                this._setWidth(objLeft, newW);
            }
            // fix inner content
            if (typeof(this._anyExpT) == "object" && this._anyExpT != null) { this._fixInnerContentFromArray(this._anyExpT); this._anyExpT = null; }
            if (typeof(this._anyExpB) == "object" && this._anyExpB != null) { this._fixInnerContentFromArray(this._anyExpB); this._anyExpB = null; }
            if (typeof(this._anyExpL) == "object" && this._anyExpL != null) { this._fixInnerContentFromArray(this._anyExpL); this._anyExpL = null; }
            if (typeof(this._anyExpR) == "object" && this._anyExpR != null) { this._fixInnerContentFromArray(this._anyExpR); this._anyExpR = null; }
            // clear data
            this._resObj = null;
            this._resFunc = null;
            this._hideCovers();
            //
            this.callEvent("onPanelResizeFinish", []);
            //
            // fix for opera with vertical resize
            this._fixCellsContentOpera950();
            //
            return;
        }
        // resize effect
        var poly = new Array();
        if (this._resObj._left != null) { for (var q=0; q<this._resObj._left.length; q++) { poly[poly.length] = this._resObj._left[q]; } }
        if (this._resObj._right != null) { for (var q=0; q<this._resObj._right.length; q++) { poly[poly.length] = this._resObj._right[q]; } }
        if (this._resObj._top != null) { for (var q=0; q<this._resObj._top.length; q++) { poly[poly.length] = this._resObj._top[q]; } }
        if (this._resObj._bottom != null) { for (var q=0; q<this._resObj._bottom.length; q++) { poly[poly.length] = this._resObj._bottom[q]; } }
        this._resFunc = null;
        this._resObj = null;
        this._hideCovers();
        // sizes in grid and tabbar
        var wId = new Array();
        for (var q=0; q<poly.length; q++) {
            if (typeof(poly[q]) == "object") {
                for (var w=0; w<poly[q].length; w++) { wId[wId.length] = this.polyObj[poly[q][w]]._win; }
            } else {
                wId[wId.length] = this.polyObj[poly[q]]._win;
            }
        }
        for (var q=0; q<wId.length; q++) { if (this.dhxWins.window(wId[q]) != null) { this._updateComponentsView(this.dhxWins.window(wId[q])); } }
        //
        this.callEvent("onPanelResizeFinish", []);
    }
    this._showCovers = function() {
        for (var a in this.polyObj) {
            if (this.polyObj[a].childNodes[1] != null) {
                if (this.polyObj[a].childNodes[1].childNodes[this.polyObj[a].childNodes[1].childNodes.length-1] != null) {
                    var cover = this.polyObj[a].childNodes[1].childNodes[this.polyObj[a].childNodes[1].childNodes.length-1];
                    cover.className = (this._effects["highlight"]&&this._isResizable(a)?"dhxLayout_Cover_"+this.skin:"dhx_content_cover_blocker");
                    cover.style.display = "";
                }
            }
        }
    }
    this._hideCovers = function() {
        for (var a in this.polyObj) {
            if (this.polyObj[a].childNodes[1] != null) {
                if (this.polyObj[a].childNodes[1].childNodes[this.polyObj[a].childNodes[1].childNodes.length-1] != null) {
                    var cover = this.polyObj[a].childNodes[1].childNodes[this.polyObj[a].childNodes[1].childNodes.length-1];
                    cover.style.display = "none";
                }
            }
        }
    }
    this._isResizable = function(pId) {
        var need = false;
        for (var q=0; q<this._resAreaData.length; q++) { need = need || (this._resAreaData[q] == pId); }
        return need;
    }
    this._collectResAreaData = function(obj) {
        for (var q=0; q<obj.length; q++) {
            if (typeof(obj[q]) == "string") {
                this._resAreaData[this._resAreaData.length] = obj[q];
            } else if (typeof(obj[q]) == "object") {
                this._collectResAreaData(obj[q]);
            }
        }
    }
    if (_isIE) {
        document.body.attachEvent("onselectstart", function(){ e = event; if (that._resObj != null) { e.returnValue = false; } });
        document.body.attachEvent("onmousemove", function(e){ e = e||event; if (that._resObj != null && that._resFunc != null) { that._resFunc(e); }
        }, false);
        document.body.attachEvent("onmouseup", function(){ that._resizeStop(); });
    } else {
        document.body.addEventListener("mousemove", function(e){ e = e||event; if (that._resObj != null && that._resFunc != null) {
        that._resFunc(e); } }, false);
        document.body.addEventListener("mouseup", function(){ that._resizeStop(); }, false);
    }
    this._fixCellsContentOpera950 = function() {
        if (_isOpera) {
            this.forEachItem(function(item){
                var cell = item.childNodes[1].childNodes[2];
                var brd = that._opera950FixBorder;
                cell.style.border = "#FFFFFF 0px dashed";
                window.setTimeout(function(){cell.style.border=brd;}, 1);
            });
        }
    }
    this._doExpand = function(dir, pId, rowData, mode) { // dir=hor|ver
        // console.log("expand", mode)
        if (rowData.length <= 1) { return; }
        var ind = -1;
        for (var q=0; q<rowData.length; q++) { if (rowData[q] == pId) { ind = q; } }
        if (ind == -1) { return; }
        // go to the right/bottom
        var anyExp = null;
        for (var q=ind+1; q<rowData.length; q++) {
            if (anyExp == null) {
                if (typeof(rowData[q]) == "string") { if (this.polyObj[rowData[q]]._collapsed == false) { anyExp = rowData[q]; } } else { anyExp =
                rowData[q]; }
            }
        }
        // go to the left/top
        if (anyExp == null) {
            for (var q=ind-1; q>=0; q--) {
                if (anyExp == null) {
                    if (typeof(rowData[q]) == "string") { if (this.polyObj[rowData[q]]._collapsed == false) { anyExp = rowData[q]; } } else { anyExp
                    = rowData[q]; }
                }
            }
        }
        if (anyExp == null) { return; }
        //
        if (typeof(anyExp) != "object") { anyExp = new Array(anyExp); }
        if (dir == "hor") {

            var availSpace = parseInt(this.polyObj[anyExp[0]].style.width) - this._minWidth;
            var maxSize = this.polyObj[pId]._savedW;
            if (maxSize > availSpace) { maxSize = availSpace; }
            if (maxSize < this._minWidth) { return; }
            var step = Math.round(maxSize/3);

            // var maxSize = Math.round(parseInt(this.polyObj[anyExp[0]].style.width)/2);
            // var step = Math.round(this.polyObj[anyExp[0]].offsetWidth/24);
        } else {

            var availSpace = parseInt(this.polyObj[anyExp[0]].style.height) - this._minHeight;
            var maxSize = this.polyObj[pId]._savedH;
            if (maxSize > availSpace) { maxSize = availSpace; }
            if (maxSize < this._minHeight) { return; }
            var step = Math.round(maxSize/3);

            // var maxSize = Math.round(parseInt(this.polyObj[anyExp[0]].style.height)/2);
            // var step = Math.round(this.polyObj[anyExp[0]].offsetHeight/16);
        }

        // do expanding
        this.polyObj[pId].childNodes[1].style.display = "";
        this.polyObj[pId].childNodes[0].className = "dhtmlxPolyInfoBar";
        // icons
        this.polyObj[pId].childNodes[0].childNodes[1].style.display = "";
        this.polyObj[pId].childNodes[0].childNodes[2].style.display = "";
        //this.polyObj[pId].childNodes[0].childNodes[3].style.display = "";
        this.polyObj[pId].childNodes[0].childNodes[4].style.display = "";


        //
        var obj2 = new Array();
        for (var q=0; q<anyExp.length; q++) { obj2[q] = this.polyObj[anyExp[q]]; }
        //
        // tabbar special mode
        if (this.polyObj[pId].className == "dhtmlxLayoutSinglePolyTabbarCollapsed") {
            this.polyObj[pId].className = "dhtmlxLayoutSinglePolyTabbar";
        }
        // console.log(dir, maxSize, this.polyObj[pId]._savedW, this.polyObj[pId]._savedH)
        this._expandEffect(this.polyObj[pId], obj2, maxSize, mode, (this._effects["collapse"]==true?step:1000000), dir);
        //
    }
    this._doCollapse = function(dir, pId, rowData, mode) { // dir=hor|ver
        // console.log("collapse", mode)
        if (rowData.length <= 1) { return; }
        var ind = -1;
        for (var q=0; q<rowData.length; q++) { if (rowData[q] == pId) { ind = q; } }
        if (ind == -1) { return; }
        // go to the right
        var anyExp = null;
        for (var q=ind+1; q<rowData.length; q++) {
            if (anyExp == null) {
                if (typeof(rowData[q]) == "string") { if (this.polyObj[rowData[q]]._collapsed == false) { anyExp = rowData[q]; } } else { anyExp =
                rowData[q]; }
            }
        }
        // go to the left
        if (anyExp == null) {
            for (var q=ind-1; q>=0; q--) {
                if (anyExp == null) {
                    if (typeof(rowData[q]) == "string") { if (this.polyObj[rowData[q]]._collapsed == false) { anyExp = rowData[q]; } } else { anyExp
                    = rowData[q]; }
                }
            }
        }
        if (anyExp == null) {
            if (rowData[ind+1] != null) { anyExp = rowData[ind+1]; }
        }
        // check first collapsed on the left for expanding
        if (anyExp == null) {
            if (ind-1 >= 0) {
                if (rowData[ind-1] != null) { anyExp = rowData[ind-1]; }
            }
        }
        // do collapsing
        if (anyExp != null) {

            if (typeof(anyExp) != "object") {

                if (this.polyObj[anyExp]._collapsed == true) {
                    this.polyObj[anyExp].childNodes[1].style.display = "";
                    this.polyObj[anyExp]._collapsed = false;
                    this.polyObj[anyExp].childNodes[0].className = "dhtmlxPolyInfoBar";
                    this.polyObj[anyExp].childNodes[0].childNodes[1].style.display = "";
                    this.polyObj[anyExp].childNodes[0].childNodes[4].title = "Collapse";
                    this.polyObj[anyExp].childNodes[0].childNodes[2].style.display = "";
                    this.polyObj[anyExp].childNodes[0].childNodes[3].style.display = "none";
                    this.polyObj[anyExp].childNodes[0].childNodes[4].style.display = "";
                    //
                    // undock expanding window
                    var wId = this.polyObj[anyExp].childNodes[0]._win;
                    var win = this.dhxWins.window(wId);
                    if (!win._isDocked) { this.dockWindow(anyExp, wId); }
                    //
                    // console.log("need to undock "+this.polyObj[anyExp].childNodes[0]._win)
                    //
                    // tabbar special mode
                    if (this.polyObj[anyExp].className == "dhtmlxLayoutSinglePolyTabbarCollapsed") {
                        this.polyObj[anyExp].className = "dhtmlxLayoutSinglePolyTabbar";
                    }
                    // opera 9.50 height fix
                    this._fixCellsContentOpera950();
                    // show/hide splitter images
                    this._fixSplitters();
                    // check icons
                    this._fixIcons();
                    // event
                    this.callEvent("onExpand", [anyExp]);
                }

                anyExp = new Array(anyExp);
            }
            var obj2 = new Array();
            for (var q=0; q<anyExp.length; q++) { obj2[q] = this.polyObj[anyExp[q]]; }
            //
            if (dir == "hor") {
                var step = Math.round(Math.max(this.polyObj[pId].offsetWidth, this.polyObj[anyExp[0]].offsetWidth)/3);
            } else {
                var step = Math.round(Math.max(this.polyObj[pId].offsetHeight, this.polyObj[anyExp[0]].offsetHeight)/3);
            }

            this.polyObj[pId].childNodes[1].style.display = "none";
            //
            this._collapseEffect(this.polyObj[pId], obj2, mode, (this._effects["collapse"]==true?step:1000000), dir);
        }
    }

    /**
    *   @desc: sets effect
    *   @param: efName - effect's name
    *   @param: efValue - true/false
    *   @type: public
    */
    this.setEffect = function(efName, efValue) {
        if (this._effects[efName] != null && typeof(efValue) == "boolean") {
            this._effects[efName] = efValue;
        }
    }
    /**
    *   @desc: returns true if the effect is enabled
    *   @param: efName - effect name
    *   @param: efValue - true/false
    *   @type: public
    */
    this.getEffect = function(efName) {
        if (this._effects[efName] != null) { return this._effects[efName]; }
        return null;
    }

    this._expandEffect = function(obj, obj2, maxSize, mode, step, dir) {
        //
        if (dir == "hor") {
            var s = parseInt(obj.style.width);
            var s2 = parseInt(obj2[0].style.width);
        } else {
            var s = parseInt(obj.style.height);
            var s2 = parseInt(obj2[0].style.height);
        }
        var newS = s + step;
        if (newS > maxSize) { newS = maxSize; }
        //
        if (dir == "hor") {
            obj.style.width = newS+"px";
            obj.childNodes[1].style.width = newS+"px";
        } else {
            obj.style.height = newS+"px";
            obj.childNodes[1].style.height = newS-obj.childNodes[0]._h+"px";
        }
        //
        for (var q=0; q<obj2.length; q++) {
            if (dir == "hor") {
                obj2[q].style.width = s2+s-newS+"px";
                obj2[q].childNodes[1].style.width = s2+s-newS+"px";
            } else {
                obj2[q].style.height = s2+s-newS+"px";
                obj2[q].childNodes[1].style.height = s2+s-newS-obj2[q].childNodes[0]._h+"px";
            }
        }
        //
        if (newS != maxSize) {
            window.setTimeout(function(){that._expandEffect(obj, obj2, maxSize, mode, step, dir);}, 4);
        } else {
            obj._collapsed = false;
            // dock expanding window
            var wId = obj.childNodes[0]._win;
            var win = this.dhxWins.window(wId);
            if (!win._isDocked) { this.dockWindow(obj._idd, wId); }
            //
            // sizing grid/tabbar
            for (var q=0; q<obj2.length; q++) { if (obj2[q]._win != null) { this._updateComponentsView(this.dhxWins.window(obj2[q]._win)); } }
            this._updateComponentsView(this.dhxWins.window(wId));
            this.polyObj[obj._idd].childNodes[0].childNodes[4].title = "Collapse";
            //
            // opera 9.50 height fix
            this._fixCellsContentOpera950();
            // show/hide splitter images
            this._fixSplitters();
            // check icons
            this._fixIcons();
            // event
            this.callEvent("onExpand", [obj._idd]);
        }
    }
    this._collapseEffect = function(obj, obj2, mode, step, dir) {
        //
        if (dir == "hor") {
            var s = parseInt(obj.style.width);
            var s2 = parseInt(obj2[0].style.width);
        } else {
            var s = parseInt(obj.style.height);
            var s2 = parseInt(obj2[0].style.height);
        }
        var newS = s - step;
        if (dir == "hor") {
            if (newS < this._collapsedW) { newS = this._collapsedW; }
            obj.style.width = newS+"px";
            //obj.childNodes[1].style.width = newS+"px";
        } else {
            if (newS < this._collapsedH) { newS = this._collapsedH; }
            obj.style.height = newS+"px";
            var p = newS-obj.childNodes[0]._h;
            if (p < 0) { p = 0; }
            //obj.childNodes[1].style.height = p+"px";
        }

        //

        for (var q=0; q<obj2.length; q++) {
            if (dir == "hor") {
                obj2[q].style.width = s2+(s-newS)+"px";
                // obj2[q].childNodes[1].style.width = s2+(s-newS)+"px";
            } else {
                obj2[q].style.height = s2+(s-newS)+"px";
                // obj2[q].childNodes[1].style.height = s2+(s-newS)-obj2[q].childNodes[0]._h+"px";
            }
        }

        //
        if ((newS > this._collapsedW && dir == "hor") || (newS > this._collapsedH && dir == "ver")) {
            window.setTimeout(function(){that._collapseEffect(obj, obj2, mode, step, dir);}, 4);
        } else {
            for (var q=0; q<obj2.length; q++) {
                if (dir == "hor") {
                    // obj2[q].style.width = s2+(s-newS)+"px";
                    obj2[q].childNodes[1].style.width = s2+(s-newS)+"px";
                } else {
                    // obj2[q].style.height = s2+(s-newS)+"px";
                    obj2[q].childNodes[1].style.height = s2+(s-newS)-obj2[q].childNodes[0]._h+"px";
                }
            }
            // finish collapsing
            obj._collapsed = true;
            // obj.childNodes[1].style.display = "none";
            if (dir == "hor") {
                obj.childNodes[0].className = "dhtmlxPolyInfoBarCollapsedVer";
            } else {
                obj.childNodes[0].className = "dhtmlxPolyInfoBarCollapsedHor";
            }
            // sizing components
            for (var q=0; q<obj2.length; q++) { if (obj2[q]._win != null) { this._updateComponentsView(this.dhxWins.window(obj2[q]._win)); } }
            // icons
            if (mode == "hide") {
                obj.childNodes[0].childNodes[1].style.display = "";
                obj.childNodes[0].childNodes[2].style.display = "none";
                obj.childNodes[0].childNodes[3].style.display = "none";
                obj.childNodes[0].childNodes[4].style.display = "";
            } else {
                obj.childNodes[0].childNodes[1].style.display = "";
                obj.childNodes[0].childNodes[2].style.display = "";
                obj.childNodes[0].childNodes[3].style.display = "none";
                obj.childNodes[0].childNodes[4].style.display = "none";
            }
            // tabbar special mode
            if (obj.className == "dhtmlxLayoutSinglePolyTabbar") {
                obj.className = "dhtmlxLayoutSinglePolyTabbarCollapsed";
            }
            this.polyObj[obj._idd].childNodes[0].childNodes[4].title = "Expand";
            // fix content height in opera 9.50
            this._fixCellsContentOpera950();
            // show/hide splitter images
            this._fixSplitters();
            // check icons
            this._fixIcons();
            // events
            this.callEvent("onCollapse", [obj._idd]);
        }
    }

    this._setWidth = function(pId, width) {
        if (this.polyObj[pId] == null) { return; }
        if (!Number(width)) { return; }
        var sep = null;
        //
        for (var q=0; q<this.sepVer.length; q++) {
            var p = this.sepVer[q]._left;
            if (p[p.length-1] == pId) {
                sep = new Array(this.sepVer[q], "left");
            } else if (typeof(p[p.length-1]) == "object") {
                var k = p[p.length-1];
                for (var e=0; e<k.length; e++) { if (k[e] == pId) { sep = new Array(this.sepVer[q], "left"); } }
            }
            //
            var p = this.sepVer[q]._right;
            if (p[0] == pId) {
                sep = new Array(this.sepVer[q], "right");
            } else if (typeof(p[0]) == "object") {
                var k = p[0];
                for (var e=0; e<k.length; e++) { if (k[e] == pId) { sep = new Array(this.sepVer[q], "right"); } }
            }
        }
        if (sep != null) {
            // allow resizing
            var set = this._findDockCellsVer(sep[0]);
            var anyExpL = set[0];
            var anyExpR = set[1];
            if (anyExpL == null || anyExpR == null) { return; }
            var sumSize = parseInt(this.polyObj[anyExpL[0]].style.width) + parseInt(this.polyObj[anyExpR[0]].style.width);
            if (width < this._minWidth) { width = this._minWidth; } else if (width > sumSize - this._minWidth) { width = sumSize - this._minWidth; }
            var width2 = sumSize - width;
            //
            for (var q=0; q<anyExpL.length; q++) {
                this.polyObj[anyExpL[q]].style.width = (sep[1]=="left"?width:width2)+"px";
                this.polyObj[anyExpL[q]].childNodes[1].style.width = (sep[1]=="left"?width:width2)+"px";
                this._updateComponentsView(this.polyObj[anyExpL[q]].window);
            }
            for (var q=0; q<anyExpR.length; q++) {
                this.polyObj[anyExpR[q]].style.width = (sep[1]=="right"?width:width2)+"px";
                this.polyObj[anyExpR[q]].childNodes[1].style.width = (sep[1]=="right"?width:width2)+"px";
                this._updateComponentsView(this.polyObj[anyExpR[q]].window);
            }
        }
    }
    this._setHeight = function(pId, height) {
        if (this.polyObj[pId] == null) { return; }
        if (!Number(height)) { return; }
        var sep = null;
        //
        for (var q=0; q<this.sepHor.length; q++) {
            var p = this.sepHor[q]._top;
            if (p[p.length-1] == pId) {
                sep = new Array(this.sepHor[q], "top");
            } else if (typeof(p[p.length-1]) == "object") {
                var k = p[p.length-1];
                for (var e=0; e<k.length; e++) { if (k[e] == pId) { sep = new Array(this.sepHor[q], "top"); } }
            }
            //
            var p = this.sepHor[q]._bottom;
            if (p[0] == pId) {
                sep = new Array(this.sepHor[q], "bottom");
            } else if (typeof(p[0]) == "object") {
                var k = p[0];
                for (var e=0; e<k.length; e++) { if (k[e] == pId) { sep = new Array(this.sepHor[q], "bottom"); } }
            }
        }
        if (sep != null) {
            // allow resizing
            var set = this._findDockCellsHor(sep[0]);
            var anyExpT = set[0];
            var anyExpB = set[1];
            if (anyExpT == null || anyExpB == null) { return; }
            var sumSize = parseInt(this.polyObj[anyExpT[0]].style.height) + parseInt(this.polyObj[anyExpB[0]].style.height);
            if (height < this._minHeight) { height = this._minHeight; } else if (height > sumSize - this._minHeight) { height = sumSize -
            this._minHeight; }
            var height2 = sumSize - height;
            //
            for (var q=0; q<anyExpT.length; q++) {
                this.polyObj[anyExpT[q]].style.height = (sep[1]=="top"?height:height2)+"px";
                this.polyObj[anyExpT[q]].childNodes[1].style.height = (sep[1]=="top"?height:height2)-this.polyObj[anyExpT[q]].childNodes[0]._h+"px";
                this._updateComponentsView(this.polyObj[anyExpT[q]].window);
            }
            for (var q=0; q<anyExpB.length; q++) {
                this.polyObj[anyExpB[q]].style.height = (sep[1]=="bottom"?height:height2)+"px";
                this.polyObj[anyExpB[q]].childNodes[1].style.height =
                (sep[1]=="bottom"?height:height2)-this.polyObj[anyExpB[q]].childNodes[0]._h+"px";
                this._updateComponentsView(this.polyObj[anyExpB[q]].window);
            }
        }
    }
    this._fixInnerContentFromArray = function(obj) {
        for (var q=0; q<obj.length; q++) { if (typeof(obj[q])=="object") { this._fixInnerContentFromArray(obj[q]); } else {
        this._updateComponentsView(this.polyObj[obj[q]].window); } }
    }
    this._fixInnerContent = function(pId) {
        this._updateComponentsView(this.polyObj[pId].window);
    }
    this._updateComponentsView = function(win) {
        if (win.grid != null) { win.grid.setSizes(); win.grid.setSizes(); }
        if (win.tabbar) { win.tabbar.adjustOuterSize(); }
        if (win.accordion != null) { win.accordion.setSizes(); }
        if (win.layout != null) { win.layout.setSizes(win); }
        if (win.folders != null) { win.folders.setSizes(); }
        if (win.editor != null) { if (_isOpera) { window.setTimeout(function(){win.editor.adjustSize();},10); } else { win.editor.adjustSize(); } }
    }
    this.dockWindow = function(pId, wId) {
        if (this.polyObj[pId] == null) { return; }
        if (this.polyObj[pId]._win != null) { return; }
        if (this.dhxWins.window(wId) == null) { return; }
        // docking
        var win = this.dhxWins.window(wId);
        // editor fix
        if (win.editor != null) { var winEditorStoredData = win.editor.getContent(); }
        //
        win._isDocked = true;
        win._dockCell = pId;
        while (this.polyObj[pId].childNodes.length > 1) { this.polyObj[pId].removeChild(this.polyObj[pId].childNodes[1]); }
        var data = win._content;
        data.parentNode.removeChild(data);
        win.hide();
        // var bar = this.polyObj[pId].childNodes[0];
        // console.log(bar)
        data.style.width = this.polyObj[pId].style.width;
        var p = parseInt(this.polyObj[pId].style.height) - this.polyObj[pId].childNodes[0]._h;
        if (p < 0) { p = 0; }
        data.style.height = p + "px";
        this.polyObj[pId].appendChild(data);
        this.polyObj[pId]._win = wId;
        this._updateComponentsView(this.dhxWins.window(wId));
        // editor fix
        if (win.editor != null && winEditorStoredData != null) {
            var iconsPath = win.editor.iconsPath;
            win.editor = win.attachEditor();
            win.editor.setIconsPath(iconsPath);
            win.editor.init();
            win.editor.setContent(winEditorStoredData);
        }
        // ie small fixes
        if (_isIE && this.dhxWins.window(wId)._IEFixMTS == true) {
            var obj = this.dhxWins.window(wId)._content.childNodes[2];
            var pad = obj.style.paddingBottom;
            obj.style.paddingBottom = "0px";
            window.setTimeout(function(){obj.style.paddingBottom=pad;},1);
        }
        // events
        this.callEvent("onDock", [pId]);
    }
    this.unDockWindow = function(wId) {
        var p = null;
        var win = null;
        for (var a in this.polyObj) {
            if (this.polyObj[a]._win == wId) {
                p = a;
                win = this.dhxWins.window(wId);
            }
        }
        if (p != null && win != null) {
            // editor fix
            if (win.editor != null) { var winEditorStoredData = win.editor.getContent(); }
            //
            var data = win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1];
            var base = this.polyObj[p].childNodes[1];
            //
            this.polyObj[p].removeChild(base);
            var fake = document.createElement("DIV");
            fake.style.position = "relative";
            fake.innerHTML = "&nbsp;";
            this.polyObj[p].appendChild(fake);
            this.polyObj[p]._win = null;
            //
            data.appendChild(base);
            win._isDocked = false;
            if (win._isParked) {
                base.style.height = "0px";
            } else {
                win.setDimension(400, 300);
            }
            win.show();
            win.bringToTop();
            win.center();
            this._updateComponentsView(this.dhxWins.window(wId));
            // editor fix
            if (win.editor != null && winEditorStoredData != null) {
                var iconsPath = win.editor.iconsPath;
                win.editor = win.attachEditor();
                win.editor.setIconsPath(iconsPath);
                win.editor.init();
                win.editor.setContent(winEditorStoredData);
            }
            // ie small fixes
            if (_isIE && this.dhxWins.window(wId)._IEFixMTS == true) {
                var obj = this.dhxWins.window(wId)._content.childNodes[2];
                var pad = obj.style.paddingBottom;
                obj.style.paddingBottom = "0px";
                window.setTimeout(function(){obj.style.paddingBottom=pad;},1);
            }
            // events
            this.callEvent("onUnDock", [p]);
        }
    }
    this.isPanelVisible = function(pId) {
        if (this.polyObj[pId] == null) { return; }
        if (this.polyObj[pId]._collapsed == true) { return; }
        var bar = this.polyObj[pId].childNodes[0];
        var isVisible = (bar.style.display!="none");
        return isVisible;
    }
    this.showPanel = function(pId) {
        if (this.polyObj[pId] == null) { return; }
        if (this.polyObj[pId]._collapsed == true) { return; }
        var bar = this.polyObj[pId].childNodes[0];
        if (bar._tabbarMode == -2) {
            this.dhxWins.window(bar._win).tabbar._tabZone.style.display='';
            this.dhxWins.window(bar._win).tabbar.adjustOuterSize();
            return bar._tabbarMode = -1;
        }
        if (bar._tabbarMode == -1) return;
        bar._h = this._CPanelHeight;
        this.polyObj[pId].childNodes[1].style.height = parseInt(this.polyObj[pId].style.height) - bar._h + "px";
        bar.style.display = "";
        if (_isOpera) { this._fixCellsContentOpera950(); }
    }
    this.hidePanel = function(pId) {
        if (this.polyObj[pId] == null) { return; }
        if (this.polyObj[pId]._collapsed == true) { return; }
        var bar = this.polyObj[pId].childNodes[0];
        if (typeof bar._tabbarMode == "undefined") {
            bar.style.display = "none";
        } else {
            if (bar._tabbarMode===true) {
                this.polyObj[pId].childNodes[1].style.position = "absolute";
                bar._tabbarMode = -1;
            } else if (bar._tabbarMode == -1) {
                this.dhxWins.window(bar._win).tabbar._tabZone.style.display='none'
                this.dhxWins.window(bar._win).tabbar.adjustOuterSize();
                bar._tabbarMode = -2;
            }
        }
        bar._h = 0;
        var h = parseInt(this.polyObj[pId].style.height);
        this.polyObj[pId].childNodes[1].style.height = h+"px";
        if (_isOpera) { this._fixCellsContentOpera950(); }
    }
    this.setText = function(pId, text) {
        // this._changeCPanelText(pId, text);
        this.dhxWins.window("w"+pId).setText(text);
    }
    this._changeCPanelText = function(pId, text) {
        var layout = that;
        if (layout.polyObj[pId] == null) { return; }
        layout.polyObj[pId].childNodes[0].childNodes[0].innerHTML = text;
    }
    /**
    *   @desc: iterator, calls a user-defined function n-times
    *   @param: handler - user-defined function, passed cell's object as an argument
    *   @type: public
    */
    this.forEachItem = function(handler) {
        for (var q=0; q<this.items.length; q++) {
            handler(this.items[q]);//, this.items[q]._idd, this.items[q]._ind);
        }
    }
    this._fixPositionInWin = function(w, h) {
        this.base.style.width = w+"px";
        this.base.style.height = h+"px";
    }
    /**
    *   @desc: attaches a dhtmlxMenu to the whole container
    *   @type: public
    */
    this.attachMenu = function() {
        this._menu = this._parentWindow.attachMenu();
        return this._menu;
    }
    /**
    *   @desc: attaches a dhtmlxToolbar to the whole container
    *   @type: public
    */
    this.attachToolbar = function() {
        this._toolbar = this._parentWindow.attachToolbar();
        return this._toolbar;
    }
    /**
    *   @desc: attaches a status bar to the whole container
    *   @type: public
    */
    this.attachStatusBar = function() {
        this._status = this._parentWindow.attachStatusBar();
        return this._status;
    }
    // static sizes
    this._fixSize = function(pId, width, height) {
        if (this.polyObj[pId] == null) { return; }
        this.polyObj[pId]._isBlockedWidth = width;
        this.polyObj[pId]._isBlockedHeight = height;
        this._fixSplitters();
    }
    this._fixSplitters = function() {
        // vertical splitters
        // console.log(this.sepVer)
        for (var q=0; q<this.sepVer.length; q++) {
            var data = this._findDockCellsVer(this.sepVer[q]);
            // console.log(data)
            if (data[0] == null || data[1] == null) {
                if (this.sepVer[q].className != "dhtmlxLayoutPolySplitterVerInactive") { this.sepVer[q].className =
                "dhtmlxLayoutPolySplitterVerInactive"; }
            } else {
                if (this.sepVer[q].className != "dhtmlxLayoutPolySplitterVer") { this.sepVer[q].className = "dhtmlxLayoutPolySplitterVer"; }
            }
        }
        // horizontal splitters
        for (var q=0; q<this.sepHor.length; q++) {
            var data = this._findDockCellsHor(this.sepHor[q]);
            if (data[0] == null || data[1] == null) {
                if (this.sepHor[q].className != "dhtmlxLayoutPolySplitterHorInactive") { this.sepHor[q].className =
                "dhtmlxLayoutPolySplitterHorInactive"; }
            } else {
                if (this.sepHor[q].className != "dhtmlxLayoutPolySplitterHor") { this.sepHor[q].className = "dhtmlxLayoutPolySplitterHor"; }
            }
        }
    }
    this._fixIcons = function() {
        for (var a in this.polyObj) {
            // 1. get cell index in _rowData
            var data = this.polyObj[a]._rowData;
            var cps = this.polyObj[a]._collapsed;
            var idx = -1;
            for (var q=0; q<data.length; q++) {
                if (typeof(data[q]) == "object") {
                    // nothing there?
                } else {
                    if (data[q] == a) { idx = q; }
                }
            }
            // 2. search first expanded item next to the right, then to the left of the collapsed cell
            var newIcon = null;
            if (idx != -1) {
                // to the right
                for (var q=idx+1; q<data.length; q++) {
                    if (typeof(data[q]) == "object") {
                        newIcon = (this.polyObj[a]._resize=="ver"?(cps?"b":"t"):(cps?"r":"l"));
                    } else if (this.polyObj[data[q]]._collapsed == false) {
                        newIcon = (this.polyObj[a]._resize=="ver"?(cps?"b":"t"):(cps?"r":"l"));
                    }
                }
                if (newIcon == null && idx >= 1) {
                    // to the left
                    for (var q=idx-1; q>=0; q--) {
                        if (typeof(data[q]) == "object") {
                            newIcon = (this.polyObj[a]._resize=="ver"?(cps?"t":"b"):(cps?"l":"r"));
                        } else if (this.polyObj[data[q]]._collapsed == false) {
                            newIcon = (this.polyObj[a]._resize=="ver"?(cps?"t":"b"):(cps?"l":"r"));
                        }
                    }
                }
            }
            // 3. update icon
            if (newIcon != null) {
                var dir = this.polyObj[a]._resize;
                this.polyObj[a].childNodes[0].childNodes[4].className = "dhtmlxInfoButtonShowHide_"+dir+"dhxLayoutButton_"+this.skin+"_"+dir+(this.polyObj[a]._collapsed?"2":"1")+newIcon;
            }
        }
    }

    /* RESIZE IN WINDOWS */
    this._defineWindowMinDimension = function(win, inLayout) {
        if (inLayout == true) {
            var dim = new Array();
            dim[0] = parseInt(win._content.style.width);
            dim[1] = parseInt(win._content.style.height);
        } else {
            var dim = win.getDimension();
            if (dim[0] == "100%") { dim[0] = win.offsetWidth; }
            if (dim[1] == "100%") { dim[1] = win.offsetHeight; }
        }
        // getting cells which will touched by resize
        var hor = that._getNearestParents("hor");
        var ver = that._getNearestParents("ver");
        //
        if (!inLayout) {
            // window-based init, checking cells if any layout attached
            var resH = new Array();
            var resV = new Array();
            for (var a in hor) { resH[resH.length] = a; }
            for (var a in ver) { resV[resV.length] = a; }
            that._checkAlterMinSize(new Array(resH, resV));
            // calculating new avail width/height
            var hor2 = {};
            var ver2 = {};
            for (var q=0; q<that._alterSizes.length; q++) {
                var a = that._alterSizes[q][0];
                var w = that._alterSizes[q][1];
                var h = that._alterSizes[q][2];
                if (hor2[a] == null) { hor2[a] = w; } else { if (w > hor2[a]) { hor2[a] = w; } }
                if (ver2[a] == null) { ver2[a] = h; } else { if (h > ver2[a]) { ver2[a] = h; } }
            }
            for (var a in hor) { if (hor2[a] != null) { hor[a] = hor[a]-hor2[a]+that._minWidth; } }
            for (var a in ver) { if (ver2[a] != null) { ver[a] =
            ver[a]-ver2[a]+that._minHeight-(that.polyObj[a].childNodes[0].style.display!="none"?that.skinParams[that.skin]["cpanel_height"]:0); } }
        }
        // 1. detect available minimal width
        var minWidth = 65536;
        for (var a in hor) { if (hor[a] < minWidth) { minWidth = hor[a]; } }
        // console.log(minWidth)
        minWidth = minWidth - that._minWidth;
        minWidth = dim[0] - minWidth;
        if (minWidth < that._dimension[0]) { minWidth = that._dimension[0]; }
        // 2. detect available minimal height
        var minHeight = 65536;
        for (var a in ver) { if (ver[a] < minHeight) { minHeight = ver[a]; } }
        minHeight = minHeight - that._minHeight;
        minHeight = dim[1] - minHeight;
        if (minHeight < that._dimension[1]) { minHeight = that._dimension[1]; }
        // 3. set min dimension to window
        if (inLayout == true) {
            return new Array("", minWidth, minHeight);
        } else {
            win.setMinDimension(minWidth, minHeight);
        }
    }
    this._getNearestParents = function(resize) {
        var data = (resize=="hor"?this._autoHor:this._autoVer);
        var pool = {};
        for (var q=0; q<data.length; q++) {
            var id = data[q];
            if (this.polyObj[id]._collapsed == true && this.polyObj[id]._resize == resize) {
                // search neares parents for object
                var rowData = this.polyObj[id]._rowData;
                var e = -1;
                for (var w=0; w<rowData.length; w++) { if (typeof(rowData[w]) == "object") { e = w; } else { if (rowData[w] == id) e = w; } }
                var r = e;
                id = null;
                if (e > 0) { for (var w=e-1; w>=0; w--) { if (typeof(rowData[w]) == "object") { id = rowData[w]; } else { if
                (this.polyObj[rowData[w]]._collapsed == false && id == null) { id = rowData[w]; } } } }
                if (id == null) { for (var w=r; w<rowData.length; w++) { if (typeof(rowData[w]) == "object") { id = rowData[w]; } else { if
                (this.polyObj[rowData[w]]._collapsed == false && id == null) { id = rowData[w]; } } } }
            }
            if (id != null) {
                if (typeof(id) == "string") { id = new Array(id); }
                for (var w=0; w<id.length; w++) {
                    pool[id[w]] = parseInt(resize=="hor"?this.polyObj[id[w]].style.width:this.polyObj[id[w]].style.height);
                }
            }
        }

        // console.log(resize, pool)

        return pool;
    }

    this.adjustOuterSize = function() {
        // not implemented yet
    }

    /**
    *   @desc: sets outer size for the container in case of a window-based initialization
    *   @param: winObj - dhtmlxWindow object (layout's parent)
    *   @type: public
    */
    this.setSizes = function(winObj) {
        // console.log(1)
        var bw = parseInt(this.base.style.width);
        var bh = parseInt(this.base.style.height);
        //
        // var ww = parseInt(winObj._content.style.width);
        // var wh = parseInt(winObj._content.style.height);

        // var ww = winObj._content.offsetWidth-(_isIE&&winObj._isFullScreened?4:0);
        // var wh = winObj._content.childNodes[2].offsetHeight-(_isIE&&winObj._isFullScreened?4:0);
        var ww = winObj._content.offsetWidth;
        var wh = winObj._content.childNodes[2].offsetHeight;
        //
        if (_isIE) {
            if (winObj.sb != null) { wh = wh-winObj._sbH; }
            if (winObj.menu != null) { wh = wh-winObj._menuH; }
            if (winObj.toolbar != null) { wh = wh-winObj._toolbarH; }
        }
        //
        var ax = ww-bw;
        var ay = wh-bh;
        //
        var hor = this._getNearestParents("hor");
        var ver = this._getNearestParents("ver");
        var both = {};
        //
        for (var a in hor) {
            both[a] = a;
            this.polyObj[a].style.width = hor[a]+ax+"px";
            this.polyObj[a].childNodes[1].style.width = hor[a]+ax+"px";
        }
        for (var a in ver) {
            both[a] = a;
            this.polyObj[a].style.height = ver[a]+ay+"px";
            this.polyObj[a].childNodes[1].style.height = ver[a]-this.polyObj[a].childNodes[0]._h+ay+"px";
        }
        // main
        this.base.style.width = ww+"px";
        this.base.style.height = wh+"px";
        // inner content fixes
        for (var a in both) { this._updateComponentsView(this.dhxWins.window(this.polyObj[a]._win)); }
        //
        this.callEvent("onResizeFinish", []);
    }

    this._cleatTDActions = function(obj) {
        obj._dir = null;
        obj._top = null;
        obj._bottom = null;
        obj._left = null;
        obj._right = null;
        obj._dblClick = null;
        obj._minW = null;
        obj._minH = null;
        obj._initCPanel = null;
        obj._resize = null;
        obj._rowData = null;
        obj.onselectstart = null;
        obj.onmousedown = null;
        obj.onmouseup = null;
        obj.onmousemove = null;
        obj.onclick = null;
        obj.ondblclick = null;
    }

    this.clearAll = function() {
        // closing object
        for (var a in this.polyObj) {
            // if (this.dhxWins.window(this.polyObj[a]._win) != null) { this.dhxWins.window(this.polyObj[a]._win).close(); }
            var bar = this.polyObj[a].childNodes[0];
            while (bar.childNodes.length > 0) {
                this._cleatTDActions(bar.childNodes[0]);
                bar.removeChild(bar.childNodes[0]);
            }
            bar = null;
            while (this.polyObj[a].childNodes.length > 0) {
                this.polyObj[a].removeChild(this.polyObj[a].childNodes[0]);
            }
            delete this.polyObj[a];
        }
        // destroy table
        while (this.tpl.childNodes[0].childNodes.length > 0) {
            var tr = this.tpl.childNodes[0].childNodes[0];
            while (tr.childNodes.length > 0) {
                this._cleatTDActions(tr.childNodes[0]);
                tr.removeChild(tr.childNodes[0]);
            }
            this.tpl.childNodes[0].removeChild(tr);
            tr = null;
        }
    }

    this.dhx_Event();
    this.dhxLayout_destructor();
    this._init();
}
dhtmlXLayoutObject.prototype.dhx_Event = function() {
    this.dhx_SeverCatcherPath="";
    /**
    *   @desc: attaches an event handler to a dhtmlxLayout
    *   @param: original - event's original name
    *   @param: catcher - event handler
    *   @param: CallObj - object that will call the event
    *   @type: public
    */
    this.attachEvent = function(original, catcher, CallObj) {
        original = original.toLowerCase();
        CallObj = CallObj||this;
        original = 'ev_'+original;
        if ((!this[original]) || (!this[original].addEvent)) {
            var z = new this.eventCatcher(CallObj);
            z.addEvent(this[original]);
            this[original] = z;
        }
        return (original + ':' + this[original].addEvent(catcher)); //return ID (event name & event ID)
    }
    this.callEvent = function(name,arg0) {
        name = name.toLowerCase();
        if (this["ev_"+name]) { return this["ev_"+name].apply(this,arg0); }
        return true;
    }
    /**
    *   @desc: returns true if the event exists
    *   @param: name - event's name
    *   @type: public
    */
    this.checkEvent = function(name) {
        name = name.toLowerCase();
        if (this["ev_"+name]) { return true; }
        return false;
    }
    this.eventCatcher = function(obj) {
        var dhx_catch = new Array();
        var m_obj = obj;
        var z = function() {
            if (dhx_catch) var res = true;
            for (var i=0; i<dhx_catch.length; i++) { if (dhx_catch[i] != null) { var zr = dhx_catch[i].apply(m_obj, arguments); res = res && zr; } }
            return res;
        }
        z.addEvent = function(ev) {
            if (typeof(ev) != "function") ev = eval(ev);
            if (ev) return dhx_catch.push( ev ) - 1;
            return false;
                }
        z.removeEvent = function(id) { dhx_catch[id] = null; }
        return z;
    }
    /**
    *   @desc: removes an event handler
    *   @param: id - event id
    *   @type: public
    */
    this.detachEvent = function(id) {
        if (id != false) {
            var list = id.split(':'); //get EventName and ID
            this[list[0]].removeEvent(list[1]); //remove event
        }
    }
};
dhtmlXLayoutObject.prototype.dhxLayout_destructor = function() {
    this.destructor = function() {
        // single variables
        var vars = new Array("_CPanelBtnsWidth", "_CPanelHeight", "_resFunc", "_resObj", "_resX", "_resY", "_totalCols", "_totalRows", "_autoHor",
        "_autoVer",
                     "_anyExpB", "_anyExpL", "_anyExpR", "_anyExpT", "_layoutView", "_minHeight", "_minWidth", "_availAutoSize", "_dimension",
                     "_effects",
                     "_collapsedH", "_collapsedW", "_colsRatio", "_rowsRatio", "h", "w", "skin", "imagePath");
        for (var q=0; q<vars.length; q++) { delete this[vars[q]]; }
        vars = null;
        // separators
        var seps = new Array("sepHor", "sepVer");
        var vars = new Array("_bottom", "_top", "_left", "_right", "_dblClick", "_dir", "_isLayoutCell", "_isSep");
        var funcs = new Array("ondblclick", "onmousedown", "onmouseup", "onselectstart");
        for (var w=0; w<seps.length; w++) {
            for (var a in this[seps[w]]) {
                var sep = this[seps[w]][a];
                sep.className = null;
                for (var q=0; q<vars.length; q++) { delete sep[vars[q]]; }
                for (var q=0; q<funcs.length; q++) { sep[funcs[q]] = null; delete sep[funcs[q]]; }
                sep = null;
            }
            delete this[seps[w]];
        }
        vars = null;
        funcs = null;
        seps = null;
        // objects
    }

}
//v.2.0 build 81107

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/**
*   @desc: constructor, creates a single window under dhtmlxWindows system
*   @pseudonym: win
*   @type: public
*/
function dhtmlXWindowsSngl(){
 
}
/**
*   @desc: constructor, creates a button for a window under dhtmlxWindows system
*   @pseudonym: btn
*   @type: public
*/
function dhtmlXWindowsBtn(){

}

/**
*   @desc: constructor, creates a new dhtmlxWindows object
*   @type: public
*/
function dhtmlXWindows() {

    var that = this;
    // image manipulation
    this.pathPrefix = "dhxwins_";
    this.imagePath = "codebase/imgs/";
    /**
    *   @desc: sets path to the directory where used images are located
    *   @param: path - url to the directory where images are located
    *   @type: public
    */
    this.setImagePath = function(path) {
        this.imagePath = path;
    }

    // skins
    this.skin = "dhx_blue";
    this.skinParams = { // standard
                "standard"      : { "header_height": 32, "border_left_width": 6, "border_right_width": 7, "border_bottom_height": 6 },
                // aqua
                "aqua_dark"     : { "header_height": 31, "border_left_width": 3, "border_right_width": 3, "border_bottom_height": 3 },
                "aqua_orange"   : { "header_height": 31, "border_left_width": 3, "border_right_width": 3, "border_bottom_height": 3 },
                "aqua_sky"      : { "header_height": 31, "border_left_width": 3, "border_right_width": 3, "border_bottom_height": 3 },
                // clear
                "clear_blue"    : { "header_height": 32, "border_left_width": 6, "border_right_width": 6, "border_bottom_height": 6 },
                "clear_green"   : { "header_height": 32, "border_left_width": 6, "border_right_width": 6, "border_bottom_height": 6 },
                "clear_silver"  : { "header_height": 32, "border_left_width": 6, "border_right_width": 6, "border_bottom_height": 6 },
                // glassy
                "glassy_blue"   : { "header_height": 26, "border_left_width": 4, "border_right_width": 4, "border_bottom_height": 4 },
                "glassy_blue_light" : { "header_height": 26, "border_left_width": 3, "border_right_width": 3, "border_bottom_height": 3 },
                "glassy_caramel"    : { "header_height": 26, "border_left_width": 4, "border_right_width": 4, "border_bottom_height": 4 },
                "glassy_greenapple" : { "header_height": 26, "border_left_width": 4, "border_right_width": 4, "border_bottom_height": 4 },
                "glassy_rainy"  : { "header_height": 26, "border_left_width": 4, "border_right_width": 4, "border_bottom_height": 4 },
                "glassy_raspberries": { "header_height": 26, "border_left_width": 4, "border_right_width": 4, "border_bottom_height": 4 },
                "glassy_yellow" : { "header_height": 26, "border_left_width": 4, "border_right_width": 4, "border_bottom_height": 4 },
                // modern
                "modern_black"  : { "header_height": 39, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
                "modern_blue"   : { "header_height": 39, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
                "modern_red"    : { "header_height": 39, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
                // web
                "web"       : { "header_height": 21, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
                // vista
                "vista_blue"    : { "header_height": 28, "border_left_width": 8, "border_right_width": 8, "border_bottom_height": 8 },
                // dhx
                "dhx_black"     : { "header_height": 21, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
                "dhx_blue"      : { "header_height": 21, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 }
    };
    /**
    *   @desc: changes window's skin
    *   @param: skin - skin's name
    *   @type: public
    */
    this.setSkin = function(skin) {
        this.skin = skin;
        this._redrawSkin();
    }
    this._redrawSkin = function() {

        for (var a in this.wins) {
            var win = this.wins[a];
            var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
            //
            win.childNodes[0].className = "dhtmlx_wins_"+this.skin;
            // icon
            win.childNodes[1].className = "dhtmlx_wins_icon_"+this.skin;
            this._restoreWindowIcons(win);
            // title
            win.childNodes[2].className = "dhtmlx_wins_title_"+this.skin;
            // butons
            win.childNodes[3].className = "dhtmlx_wins_buttons_"+this.skin;
            this._redrawWindow(win);
        }
        // this._restoreWindowIcons(this.getTopmostWindow());
    }

    // return true if window with specified id is exists
    /**
    *   @desc: returns true if the window with specified id exists
    *   @param: id
    *   @type: public
    */
    this.isWindow = function(id) {
        var t = (this.wins[id] != null);
        return t;
    }
//#wind_uber:09062008{}
    // return array of handlers finded by text
    /**
    *   @desc: returns array of window handlers found by header text
    *   @param: id
    *   @type: public
    */
    this.findByText = function(text) {
        var wins = new Array();
        for (var a in this.wins) {
            if (this.wins[a].getText().search(text, "gi") >= 0) {
                wins[wins.lentgh] = this.wins[a];
            }
        }
        return wins;
    }
//#}
    // return handler by id
    /**
    *   @desc: returns the window handler (dhtmlXWindowSngl object) found by id
    *   @param: id
    *   @type: public
    */
    this.window = function(id) {
        var win = null;
        if (this.wins[id] != null) { win = this.wins[id]; }
        return win;
    }
//#wind_uber:09062008{
    // iterator
    /**
    *   @desc: iterator - goes through all windows and calls a user handler
    *   @param: hander (user function)
    *   @type: public
    */
    this.forEachWindow = function(handler) {
        for (var a in this.wins) {
            handler(this.wins[a]);
        }
    }

    // return bottommost focused window handler
    /**
    *   @desc: returns the bottommost window
    *   @type: public
    */
    this.getBottommostWindow = function() {
        var bottommost = this.getTopmostWindow();
        for (var a in this.wins) {
            if (this.wins[a].zi < bottommost.zi) {
                bottommost = this.wins[a];
            }
        }
        return (bottommost.zi != 0 ? bottommost : null);
    }
//#}

    // return topmost focused window handler
    /**
    *   @desc: returns the topmost window
    *   @type: public
    */
    this.getTopmostWindow = function(visibleOnly) {
        var topmost = {"zi": 0};
        for (var a in this.wins) {

            if (this.wins[a].zi > topmost.zi) {
                if (visibleOnly == true && !this._isWindowHidden(this.wins[a])) {
                    topmost = this.wins[a];
                }
                if (visibleOnly != true) {
                    topmost = this.wins[a];
                }
            }
        }
        return (topmost.zi != 0 ? topmost : null);
    }

    // windows storage
    this.wins = {};

    // viewport
    this.autoViewport = true;
    this._createViewport = function() {
        this.vp = document.body;
        // modal cover
        this.modalCoverI = document.createElement("IFRAME");
        this.modalCoverI.frameBorder = "0";
        this.modalCoverI.className = "dhx_modal_cover_ifr";
        this.modalCoverI.style.display = "none";
        this.modalCoverI.style.zIndex = 0;
        this.vp.appendChild(this.modalCoverI);
        this.modalCoverD = document.createElement("DIV");
        this.modalCoverD.className = "dhx_modal_cover_dv";
        this.modalCoverD.style.display = "none";
        this.modalCoverD.style.zIndex = 0;
        this.vp.appendChild(this.modalCoverD);
        // vp move/resize cover
        this._vpcover = document.createElement("DIV");
        this._vpcover.className = "dhx_content_vp_cover";
        this._vpcover.style.display = "none";
        this.vp.appendChild(this._vpcover);
        // resize/move carcass
        this._carcass = document.createElement("DIV");
        this._carcass.className = "dhx_carcass_resmove";
        this._carcass.style.display = "none";
        if (_isIE) {
            this._carcass.innerHTML = "<iframe border=0 frameborder=0 style='filter: alpha(opacity=0); width: 100%; height:100%; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;'></iframe><div style='position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;'></div>";
        }
        this._carcass.onselectstart = function(e) {
            e = e||event;
            e.returnValue = false;
        }
        this.vp.appendChild(this._carcass);
    }
    this._autoResizeViewport = function() {
        for (var a in this.wins) {
            if (this.wins[a]._isFullScreened) {
                this.wins[a]._content.style.width = document.body.offsetWidth-(_isIE?4:0)+"px";
                // doctype fix
                if (document.body.offsetHeight == 0) {
                    if (window.innerHeight) {
                        this.wins[a]._content.style.height = window.innerHeight+"px";
                    } else {
                        this.wins[a]._content.style.height = document.body.scrollHeight+"px";
                    }
                } else {
                    this.wins[a]._content.style.height = document.body.offsetHeight-(_isIE?4:0)+"px";
                }
                // this.wins[a]._content.style.height = document.body.offsetHeight-(_isIE?4:0)+"px";
                if (this.wins[a].layout != null && _isOpera) { this.wins[a].layout._fixCellsContentOpera950(); }
                this._fixInnerObjs(this.wins[a]);
            }
            if (this.wins[a]._isMaximized && this.wins[a].style.display != "none") {
                this._restoreWindow(this.wins[a]);
                this._maximizeWindow(this.wins[a]);
            }
        }

        if (this.vp == document.body) { return; }
        if (this.autoViewport == false) { return; }
        this.vp.style.width = (_isIE ? document.body.offsetWidth - 4 : window.innerWidth) + "px";
        this.vp.style.height = (_isIE ? document.body.offsetHeight - 4 : window.innerHeight) + "px";
        //
        // check windows out of viewports edge
        for (var a in this.wins) {
            var win = this.wins[a];
            var overX = false;
            var overY = false;
            if (win.x > this.vp.offsetWidth - 10) {
                win.x = this.vp.offsetWidth - 10;
                overX = true;
            }
            var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
            if (win.y + skinParams["header_height"] > this.vp.offsetHeight) {
                win.y = this.vp.offsetHeight - skinParams["header_height"];
                overY = true;
            }
            if (overX || overY) {
                this._redrawWindow(win);
            }
        }
    }
    /**
    *   @desc: if true - allows an object to adjust the viewport automatically to document.body
    *   @param: state - true|false
    *   @type: public
    */
    this.enableAutoViewport = function(state) {

        if (this.vp != document.body) { return; }
        this.autoViewport = state;
        if (state == false) {
            this.vp = document.createElement("DIV");
            this.vp.className = "dhtmlx_winviewport";
            this.vp.style.left = "0px";
            this.vp.style.top = "0px";
            document.body.appendChild(this.vp);
            this.vp.ax = 0;
            this.vp.ay = 0;
            this._autoResizeViewport();
            this.vp.appendChild(this.modalCoverI);
            this.vp.appendChild(this.modalCoverD);
            this.vp.appendChild(this._carcass);
        }
    }
    /**
    *   @desc: attaches a vp to an existing object on page (renders an object as a viewport)
    *   @param: objId - object id
    *   @type: public
    */
    this.attachViewportTo = function(objId) {
        if (this.autoViewport == false) {
            if (this.vp != document.body) { this.vp.parentNode.removeChild(this.vp); }
            this.vp = document.getElementById(objId);
            this.vp.style.position = "relative";
            this.vp.style.overflow = "hidden";
            this.vp.ax = 0;
            this.vp.ay = 0;
            this.vp.appendChild(this.modalCoverI);
            this.vp.appendChild(this.modalCoverD);
            this.vp.appendChild(this._carcass);
        }
    }
    /**
    *   @desc: sets user-defined viewport if enableAutoViewport(false)
    *   @param: x - top-left viewport corner's X-coordinate
    *   @param: y - top-left viewport corner's Y-coordinate
    *   @param: width - viewport's width
    *   @param: height - viewport's height
    *   @type: public
    */
    this.setViewport = function(x, y, width, height, parentObj) {
        if (this.autoViewport == false) {
            this.vp.style.left = x + "px";
            this.vp.style.top = y + "px";
            this.vp.style.width = width + "px";
            this.vp.style.height = height + "px";
            // attach to parent
            if (parentObj != null) { parentObj.appendChild(this.vp); }
            this.vp.ax = getAbsoluteLeft(this.vp);
            this.vp.ay = getAbsoluteTop(this.vp);
        }
    }
    // effects
    this._effects = {"move" : false, "resize" : false};
    /**
    *   @desc: sets a visual effect
    *   @param: efName - effect's name
    *   @param: efValue - true/false to enable/disable
    *   @type: public
    */
    this.setEffect = function(efName, efValue) {
        if ((this._effects[efName] != null) && (typeof(efValue) == "boolean")) {
            this._effects[efName] = efValue;
        }
    }
    /**
    *   @desc: returns true if the effect is enabled
    *   @param: efName - effect's name
    *   @type: public
    */
    this.getEffect = function(efName) {
        return this._effects[efName];
    }
    // windows
    /**
    *   @desc: creates a new window and returns its handler
    *   @param: id - window's id
    *   @param: x - top-left window corner's X-coordinate
    *   @param: y - top-left window corner's Y-coordinate
    *   @param: width - window's width
    *   @param: height - window's height
    *   @type: public
    */
    this.createWindow = function(id, x, y, width, height) {
        var win = document.createElement("DIV");
        win.className = "dhtmlx_window_inactive";
        // move all available windows up
        for (var a in this.wins) {
            this.wins[a].zi += this.zIndexStep;
            this.wins[a].style.zIndex = this.wins[a].zi;
        }
        // bottom, bring on top will at the end of createWindow function
        win.zi = this.zIndexStep;// this._getTopZIndex(true) + this.zIndexStep;
        win.style.zIndex = win.zi;
        //
        win.active = false;
        //
        win._isWindow = true;

        win.isWindow = true;
        //
        // win.that = this;
        //
        win.w = width;
        win.h = height;
        win.x = x;
        win.y = y;
        this._fixWindowPositionInViewport(win);
        //
        win.style.width = win.w + "px";
        win.style.height = win.h + "px";
        win.style.left = win.x + "px";
        win.style.top = win.y + "px";
        win._isModal = false;
        // resize params
        win._allowResize = true;
        win.maxW = "auto"; // occupy all viewport on click or
        win.maxH = "auto";
        win.minW = 200;
        win.minH = 140;
        win.iconsPresent = true;
        win.icons = new Array(this.imagePath+this.pathPrefix+this.skin+"/active/icon_normal.gif",
        this.imagePath+this.pathPrefix+this.skin+"/inactive/icon_normal.gif");
        //
        win._allowMove = true;
        win._allowMoveGlobal = true;
        win._allowResizeGlobal = true;
        //
        win._keepInViewport = false;
        //
        var skin = this.skinParams[this.skin];
        win.idd = id;
        win._midd = "dhxWMNObj_"+this._genStr(12);
        win._tidd = "dhxWTBObj_"+this._genStr(12);
        win._sidd = "dhxSTBObj_"+this._genStr(12);
        //
        win.innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='100%' height='"+win.h+"' class='dhtmlx_wins_"+this.skin+"'>"+
                    // head
                    "<tr><td class='dhtmlx_wins_td_header_full' clearonselect='yes'>"+
                        "<table border='0' cellspacing='0' cellpadding='0' width='100%' class='dhtmlx_wins_header' clearonselect='yes'>"+
                            "<tr>"+
                                "<td class='dhtmlx_wins_td_header_left' clearonselect='yes'>&nbsp;</td>"+
                                "<td class='dhtmlx_wins_td_header_middle' clearonselect='yes'>&nbsp;</td>"+
                                "<td class='dhtmlx_wins_td_header_right' clearonselect='yes'>&nbsp;</td>"+
                            "</tr>"+
                        "</table>"+
                        (_isIE?"<iframe frameborder='0' class='dhx_ie6_wincover_forsel' onload='this.contentWindow.document.body.style.overflow=\"hidden\";'></iframe>":"")+
                    "</td></tr>"+
                    // body
                    "<tr><td class='dhtmlx_wins_td_body_full' height='"+(win.h-skin["header_height"])+"'>"+
                        "<table border='0' cellspacing='0' cellpadding='0' width='100%' height='"+(win.h-skin["header_height"])+"' class='dhtmlx_wins_body'>"+
                            // window middle row
                            "<tr>"+
                                "<td class='dhtmlx_wins_body_border_middle_left' clearonselect='yes'>&nbsp;</td>"+
                                "<td class='dhtmlx_wins_body_content' align='left' valign='top'>"+
                                    "<div class='dhtmlx_wins_body_content' style='width: "+(win.w-skin["border_left_width"]-skin["border_right_width"])+"px; height:"+(win.h-skin["header_height"]-skin["border_bottom_height"])+"px;'>"+
                                        "<div id='"+win._midd+"' class='dhtmlxMenuInWin' style='height: 0px; display: none; position: relative;'></div>"+
                                        "<div id='"+win._tidd+"' class='dhtmlxToolbarInWin' style='height: 0px; display: none; position: relative;'></div>"+
                                        "<div class='dhtmlxWindowMainContent' style='position: absolute; overflow: hidden; width=100%; top: 0px; bottom: 0px; height=100%; left: 0px; right: 0px;'></div>"+
                                        "<div id='"+win._sidd+"' style='height: 0px; display: none;'></div>"+
                                        "<div class='dhx_content_cover_blocker' style='display: none;'></div>"+
                                    "</div>"+
                                "</td>"+
                                "<td class='dhtmlx_wins_body_border_middle_right' clearonselect='yes'>&nbsp;</td>"+
                            "</tr>"+
                            // window bottom row
                            "<tr clearonselect='yes'>"+
                                "<td class='dhtmlx_wins_body_border_bottom_left' clearonselect='yes'>&nbsp;</td>"+
                                "<td class='dhtmlx_wins_body_border_bottom_middle' clearonselect='yes'>&nbsp;</td>"+
                                "<td class='dhtmlx_wins_body_border_bottom_right' clearonselect='yes'>&nbsp;</td>"+
                            "</tr>"+
                        "</table>"+
                        (_isIE?"<iframe frameborder='0' style='top:"+skin["header_height"]+"px;' class='dhx_ie6_wincover_forsel' onload='this.contentWindow.document.body.style.overflow=\"hidden\";'></iframe>":"")+
                    "</td></tr>"+
                "</table>"+
                // window icon
                "<img clearonselect='yes' class='dhtmlx_wins_icon_"+this.skin+"' src='"+win.icons[0]+"'>"+
                // window title
                "<div clearonselect='yes' class='dhtmlx_wins_title_"+this.skin+"'>dhtmlxWindow</div>"+
                // buttons
                "<div class='dhtmlx_wins_buttons_"+this.skin+"'>"+
                    "<table border='0' cellspacing='0' cellpadding='0'><tr></tr></table>"+
                "</div>"+
                // progress
                "<div clearonselect='yes' class='dhtmlx_wins_progress_"+this.skin+"'></div>"+
                "";
        this.vp.appendChild(win);
        //
        win._content =
        win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
        this._diableOnSelectInWin(win, true);
        //
        this.wins[id] = win;
        //
        win.dhx_Event = this.dhx_Event;
        win.dhx_Event();
        //
        this._makeActive(win, true);
        // moving
        var hdr = win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0]; // table class='header'
        // hdr.that = this;
        // hdr.win = win;
        hdr.onmousedown = function(e) {
            if (!win._allowMove || !win._allowMoveGlobal) { return; }
            e = e || event;
            // save last coords to determine moveFinish event
            win.oldMoveX = win.x;
            win.oldMoveY = win.y;
            //
            win.moveOffsetX = win.x - e.clientX;
            win.moveOffsetY = win.y - e.clientY;
            that.movingWin = win;
            // carcass
            if (that._effects["move"] == false) {
                that._carcass.x = that.movingWin.x;
                that._carcass.y = that.movingWin.y;
                that._carcass.w = parseInt(that.movingWin.style.width)+(_isIE?0:-2);
                that._carcass.h = parseInt(that.movingWin.style.height)+(_isIE?0:-2);
                that._carcass.style.left = that._carcass.x+"px";
                that._carcass.style.top = that._carcass.y+"px";
                that._carcass.style.width = that._carcass.w+"px";
                that._carcass.style.height = that._carcass.h+"px";
                // that._carcass.style.zIndex = that.movingWin.style.zIndex+1;
                that._carcass.style.zIndex = that.movingWin.style.zIndex+that._getTopZIndex()+10;

                that._carcass.style.cursor = "move";
                that._carcass._keepInViewport = win._keepInViewport;
                // that._carcass.style.display = "";
            }
            that._blockSwitcher("none");
            // cursor
            that.movingWin.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].style.cur
            sor = "move";
            that.movingWin.childNodes[2].style.cursor = "move";
            // vpcover
            that._vpcover.style.zIndex = that.movingWin.style.zIndex-1;
            that._vpcover.style.display = "";
            // disabling select for opera
            if (_isOpera) {
                e.returnValue = false;
                e.cancelBubble = true;
            }
        }

        hdr.ondblclick = function() {
            // maximize/minimize
            if (win._allowResizeGlobal && !win._isParked) {
                if (win._isMaximized == true) {
                    that._restoreWindow(win);
                } else {
                    that._maximizeWindow(win);
                }
            }
            // parkup/parkup
            /*
            if (win._isParkedAllowed && win.button("park").isEnabled()) {
                that._parkWindow(win);
            }
            */
        }

        var h_title = win.childNodes[2];
        h_title.onmousedown = hdr.onmousedown;
        h_title.ondblclick = hdr.ondblclick;

        // set text
        /**
        *   @desc: sets window's header text
        *   @param: text
        *   @type: public
        */
        win.setText = function(text) {
            this.childNodes[2].innerHTML = text;
            that.callEvent("onTextChange", [this._dockCell, text]);
        }
        // get text
        /**
        *   @desc: returns window's header text
        *   @type: public
        */
        win.getText = function() {
            return this.childNodes[2].innerHTML;
        }
        // het id by handler
        /**
        *   @desc: returns window's id
        *   @type: public
        */
        win.getId = function() {
            return this.idd;
        }
        // show
        /**
        *   @desc: shows a window
        *   @type: public
        */
        win.show = function() {
            that._showWindow(this);
        }
        // hide
        /**
        *   @desc: hides a window
        *   @type: public
        */
        win.hide = function() {
            that._hideWindow(this);
        }
        // minimize
        /**
        *   @desc: minimizes a window
        *   @type: public
        */
        win.minimize = function() {
            that._restoreWindow(this);
        }
        // maximize
        /**
        *   @desc: maximizes a window
        *   @type: public
        */
        win.maximize = function() {
            that._maximizeWindow(this);
        }
        // close
        /**
        *   @desc: closes a window
        *   @type: public
        */
        win.close = function() {
            that._closeWindow(this);
        }
        // park
        /**
        *   @desc: parks a window (next action is based on window's current state)
        *   @type: public
        */
        win.park = function() {
            if (this._isParkedAllowed) {
                that._parkWindow(this);
            }
        }
        // stick/unstick
        /**
        *   @desc: sticks a window
        *   @type: public
        */
        win.stick = function() {
            that._stickWindow(this);
        }
        /**
        *   @desc: unsticks a window
        *   @type: public
        */
        win.unstick = function() {
            that._unstickWindow(this);
        }
        /**
        *   @desc: returns true if the window is sticked
        *   @type: public
        */
        win.isSticked = function() {
            return this._isSticked;
        }
        // set icon
        /**
        *   @desc: sets window's header icon
        *   @param: iconEnabled - url to the icon for the enabled state
        *   @param: iconDisabled - url to the icon for the disabled state
        *   @type: public
        */
        win.setIcon = function(iconEnabled, iconDisabled) {
            that._setWindowIcon(win, iconEnabled, iconDisabled);
        }
        // return array(iconEnabled, iconDisabled) icons for window
        /**
        *   @desc: returns current window's header icon
        *   @param: text
        *   @type: public
        */
        win.getIcon = function() {
            return that._getWindowIcon(this);
        }
        // clear icon
        /**
        *   @desc: clears window's header icon
        *   @type: public
        */
        win.clearIcon = function() {
            that._clearWindowIcons(this);
        }
        // restore default window icon according the loaded skin
        /**
        *   @desc: restores default window's header icon (based on skin)
        *   @type: public
        */
        win.restoreIcon = function() {
            that._restoreWindowIcons(this);
        }
        //
        /**
        *   @desc: keeps a window within the viewport
        *   @param: state - if true - window is not allowed to be placed outside the viewport
                    if false - window is not allowed to be placed outside the viewport leaving only a small part of its header within the viewport
        *   @type: public
        */
        win.keepInViewport = function(state) {
            this._keepInViewport = state;
        }
        // ask window be/not be modal
        /**
        *   @desc: makes a window modal/modeless
        *   @param: state - true|false
        *   @type: public
        */
        win.setModal = function(state) {
            if (state == true) {
                if (that.modalWin != null || that.modalWin == this) { return; }
                that._setWindowModal(this, true);
            } else {
                if (that.modalWin != this) { return; }
                that._setWindowModal(this, false);
            }
        }
        // return true if window is modal
        /**
        *   @desc: returns true if the window is modal
        *   @type: public
        */
        win.isModal = function() {
            return this._isModal;
        }
        // return true if window is hidden
        /**
        *   @desc: returns true if the window is hidden
        *   @type: public
        */
        win.isHidden = function() {
            return that._isWindowHidden(this);
        }
        // return true if window is maximized
        /**
        *   @desc: returns true if the window is maximized
        *   @type: public
        */
        win.isMaximized = function() {
            return this._isMaximized;
        }
        // return true if window is parkded
        /**
        *   @desc: returns true if the window is parked
        *   @type: public
        */
        win.isParked = function() {
            return this._isParked;
        }
        // allow/deny park
        /**
        *   @desc: allows a window to be parked
        *   @type: public
        */
        win.allowPark = function() {
            that._allowParking(this);
        }
        /**
        *   @desc: denies a window from parking
        *   @type: public
        */
        win.denyPark = function() {
            that._denyParking(this);
        }
        /**
        *   @desc: returns true if the window is parkable
        *   @type: public
        */
        win.isParkable = function() {
            return this._isParkedAllowed;
        }
        // allow/deny for allow window to be resized
        /**
        *   @desc: allows a window to be resized
        *   @type: public
        */
        win.allowResize = function() {
            that._allowReszieGlob(this);
        }
        /**
        *   @desc: denies a window from resizing
        *   @type: public
        */
        win.denyResize = function() {
            that._denyResize(this);
        }
        // return true if window resizeable
        /**
        *   @desc: returns true if the window is resizable
        *   @type: public
        */
        win.isResizable = function() {
            return this._allowResizeGlobal;
        }
        // move
        /**
        *   @desc: allows a window to be moved
        *   @type: public
        */
        win.allowMove = function() {
            if (!this._isMaximized) { this._allowMove = true; }
            this._allowMoveGlobal = true;
        }
        /**
        *   @desc: denies a window from moving
        *   @type: public
        */
        win.denyMove = function() {
            this._allowMoveGlobal = false;
        }
        /**
        *   @desc: returns true if the window is movable
        *   @type: public
        */
        win.isMovable = function() {
            return this._allowMoveGlobal;
        }
        // bring window to top and set focus
        /**
        *   @desc: brings/sends a window on top (z-positioning)
        *   @type: public
        */
        win.bringToTop = function() {
            that._bringOnTop(this);
            that._makeActive(this);
        }
        // bring window to bottom and set focus
        /**
        *   @desc: brings/sends a window to bottom (z-positioning)
        *   @type: public
        */
        win.bringToBottom = function() {
            that._bringOnBottom(this);
        }
        // return true if window is on top
        /**
        *   @desc: returns true if the window is on top
        *   @type: public
        */
        win.isOnTop = function() {
            return that._isWindowOnTop(this);
        }
        // return true if window if on bottom
        /**
        *   @desc: returns true if the window is on bottom
        *   @type: public
        */
        win.isOnBottom = function() {
            return that._isWindowOnBottom(this);
        }
        // set new position for window, if it will outlay the viewport it was moved into it visible area
        /**
        *   @desc: sets window's position (moves a window to the point set by user)
        *   @param: x - x coordinate
        *   @param: y - y coordinate
        *   @type: public
        */
        win.setPosition = function(x, y) {
            this.x = x;
            this.y = y;
            that._fixWindowPositionInViewport(this);
            // fixing mozilla artefakts
            if (_isFF) {
                this.h++;
                that._redrawWindow(this);
                this.h--;
            }
            that._redrawWindow(this);
        }
        // return array(x, y) with position of window
        /**
        *   @desc: returns current window's position
        *   @type: public
        */
        win.getPosition = function() {
            return new Array(this.x, this.y);
        }
        // set new dimension for window, if it will outlay the viewport it was moved into it visible area
        /**
        *   @desc: sets window's dimension
        *   @param: width
        *   @param: height
        *   @type: public
        */
        win.setDimension = function(width, height) {
            if (width != null) { this.w = width; }
            if (height != null) { this.h = height; }
            that._fixWindowDimensionInViewport(this);
            that._fixWindowPositionInViewport(this);
            that._redrawWindow(this);
        }
        // return array(width, height) with current dimension of window
        /**
        *   @desc: returns current window's dimension
        *   @type: public
        */
        win.getDimension = function() {
            return new Array(this.w, this.h);
        }
        // set max dimension for window
        /**
        *   @desc: sets max window's dimension
        *   @param: maxWidth
        *   @param: maxHeight
        *   @type: public
        */
        win.setMaxDimension = function(maxWidth, maxHeight) {
            this.minW = "auto"; // maxWidth;
            this.minH = "auto"; // maxHeight;
            that._redrawWindow(this);
        }
        // return array(maxWidth, maxheight) with max dimension for window
        /**
        *   @desc: returns current max window's dimension
        *   @type: public
        */
        win.getMaxDimension = function() {
            return new Array(this.maxW, this.maxH);
        }
        // set min dimensuion for window
        /**
        *   @desc: sets min window's dimension
        *   @param: minWidth
        *   @param: minHeight
        *   @type: public
        */
        win.setMinDimension = function(minWidth, minHeight) {
            if (minWidth != null) { this.minW = minWidth; }
            if (minHeight != null) { this.minH = minHeight; }
            that._fixWindowDimensionInViewport(this);
            that._redrawWindow(this);
        }
        // return array(minWidth, minHeight) with min dimension for window
        /**
        *   @desc: returns current min window's dimension
        *   @type: public
        */
        win.getMinDimension = function() {
            return new Array(this.minW, this.minH);
        }
//#wind_buttons:09062008{
        // add user button
        /**
        *   @desc: adds a user button
        *   @param: id - button's id
        *   @param: pos - button's position
        *   @param: title - button's tooltip
        *   @param: label - button's name (according to css)
        *   @type: public
        */
        win.addUserButton = function(id, pos, title, label) {
            var userBtn = that._addUserButton(this, id, pos, title, label);
            return userBtn;
        }
        // remove user button
        /**
        *   @desc: removes a user button
        *   @param: id - button's id
        *   @type: public
        */
        win.removeUserButton = function(id) {
            if (!((id == "minmax1") || (id == "minmax2") || (id == "park") || (id == "close") || (id == "stick") || (id == "unstick") || (id == "help"))) {
                var btn = this.button(id);
                // if (btn != null) { that._removeUserButton(win, id, btn); }
                if (btn != null) { that._removeUserButton(this, id, btn); }
            }
        }
//#}
        /**
        *   @desc: shows a progress indicator
        *   @type: public
        */
        win.progressOn = function() {
            that._switchProgress(this, true);
        }
        /**
        *   @desc: hides a progress indicator
        *   @type: public
        */
        win.progressOff = function() {
            that._switchProgress(this, false);
        }
        /**
        *   @desc: attaches a status bar to a window
        *   @type: private
        */
        win.attachStatusBar = function() {
            return that._attachStatusBar(this);
        }
        /**
        *   @desc: attaches a dhtmlxMenu to a window
        *   @type: private
        */
        win.attachMenu = function() {
            return that._attachWebMenu(this);
        }
        /**
        *   @desc: attaches a dhtmlxToolbar to a window
        *   @type: private
        */
        win.attachToolbar = function() {
            return that._attachWebToolbar(this);
        }
//#wind_comps:09062008{
        /**
        *   @desc: attaches a dhtmlxGrid to a window
        *   @type: public
        */
        win.attachGrid = function() {
            var obj = document.createElement("DIV");
            obj.id = "dhxGridObj_"+that._genStr(12);
            obj.style.width = "100%";
            obj.style.height = "100%";
            document.body.appendChild(obj);
            this.attachObject(obj.id);
            this.grid = new dhtmlXGridObject(obj.id);
            this.grid.setSkin(that.skin);
            this.grid.entBox.style.border="0px solid white";
            this.grid._sizeFix=0;
            return this.grid;
        }
        /**
        *   @desc: attaches a dhtmlxTree to a window
        *   @param: rootId - not mandatory, tree super root, see dhtmlxTree documentation for details
        *   @type: public
        */
        win.attachTree = function(rootId) {
            var obj = document.createElement("DIV");
            obj.id = "dhxTreeObj_"+that._genStr(12);
            obj.style.width = "100%";
            obj.style.height = "100%";
            document.body.appendChild(obj);
            this.attachObject(obj.id);
            this.tree = new dhtmlXTreeObject(obj.id, "100%", "100%", (rootId||0));
            this.tree.setSkin(that.skin);
            // this.tree.allTree.style.paddingTop = "2px";
            this.tree.allTree.childNodes[0].style.marginTop = "2px";
            this.tree.allTree.childNodes[0].style.marginBottom = "2px";
            return this.tree;
        }
        /**
        *   @desc: attaches a dhtmlxTabbar to a window
        *   @type: public
        */
        win.attachTabbar = function() {
            var obj = document.createElement("DIV");
            obj.id = "dhxTabbarObj_"+that._genStr(12);
            obj.style.width = "100%";
            obj.style.height = "100%";
            obj.style.overflow = "hidden";
            document.body.appendChild(obj);
            this.attachObject(obj.id);
            // manage dockcell if exists
            if (this._dockCell != null && that.dhxLayout != null) {
                var dockCell = that.dhxLayout.polyObj[this._dockCell];
                if (dockCell != null) {
                    dockCell.childNodes[0]._tabbarMode = true;
                    that.dhxLayout.hidePanel(this._dockCell);
                    dockCell.className = "dhtmlxLayoutSinglePolyTabbar";
                    // dockCell.childNodes[0]._h = -2;
                    // dockCell.childNodes[1].style.height = parseInt(dockCell.childNodes[1].style.height) - dockCell.childNodes[0]._h + "px";
                    // dockCell.className = "dhtmlxLayoutSinglePolyTabbar";
                    // fix panel
                    // that.dhxLayout._panelForTabs(this._dockCell);
                }
            }
            //
            this.tabbar = new dhtmlXTabBar(obj.id, "top",26);
            this.tabbar._linePos=-4;
            if ((_isIE)&&(document.compatMode == "BackCompat")){
                this.tabbar._lineAHeight=this.tabbar._lineA.style.height="6px";
                this.tabbar._bFix=5;
            } else{
                this.tabbar._lineAHeight=this.tabbar._lineA.style.height="4px";
                this.tabbar._bFix=4;
            }
            this.tabbar.setSkin(that.skin);
            this.tabbar._conZone.style.borderWidth="0px";
            this.tabbar._EARS = true;
            this.tabbar.setMargin(-1)
            this.tabbar.setOffset(0)
            this.tabbar.adjustOuterSize();
            this.tabbar.cells=function(id,name){ return this._cells.call(this,that,id,name); };
            return this.tabbar;
        }
        /**
        *   @desc: attaches a dhtmlxFolders to a window
        *   @type: public
        */
        win.attachFolders = function() {
            var obj = document.createElement("DIV");
            obj.id = "dhxFoldersObj_"+that._genStr(12);
            obj.style.width = "100%";
            obj.style.height = "100%";
            obj.style.overflow = "hidden";
            document.body.appendChild(obj);
            this.attachObject(obj.id);
            this.folders = new dhtmlxFolders(obj.id);
            this.folders.setSizes();
            return this.folders;
        }
        /**
        *   @desc: attaches a dhtmlxAccordion to a window
        *   @type: public
        */
        win.attachAccordion = function() {
            var obj = document.createElement("DIV");
            obj.id = "dhxAccordionObj_"+that._genStr(12);
            obj.style.width = "100%";
            obj.style.height = "100%";
            obj.style.position = "relative";
            document.body.appendChild(obj);
            this.attachObject(obj.id);
            this.accordion = new dhtmlXAccordion(obj.id, that.skin);
            /* // hide header
            if (this._dockCell != null && that.dhxLayout != null) {
                var dockCell = that.dhxLayout.polyObj[this._dockCell];
                if (dockCell != null) { that.dhxLayout.hidePanel(this._dockCell); }
            }
            */
            win._content.childNodes[2].className += " dhtmlxAccordionAttached";
            this.accordion.setSizes();
            return this.accordion;
        }
        /**
        *   @desc: attaches a dhtmlxLayout to a window
        *   @param: view - layout's pattern
        *   @param: skin - layout's skin
        *   @type: public
        */
        win.attachLayout = function(view, skin) {
            var obj = document.createElement("DIV");
            obj.id = "dhxLayoutObj_"+that._genStr(12);
            obj.style.position = "relative";
            document.body.appendChild(obj);
            //
            this.attachObject(obj.id);
            // this.layout = new dhtmlXLayoutObject(obj.id, this);
            // console.log(this._content.style.width, this._content.style.height)
            // var w = parseInt(this._content.style.width);
            // var h = parseInt(this._content.style.height);

            var w = this._content.childNodes[2].offsetWidth;
            var h = this._content.childNodes[2].offsetHeight;
            if (w == 0) { w = parseInt(this._content.style.width); }

            obj.style.left = "0px";
            obj.style.top = "0px";
            //obj.style.width = w-(_isIE&&this._isFullScreened?4:0)+"px";
            //obj.style.height = h-(_isIE&&this._isFullScreened?4:0)+"px";
            obj.style.width = w+"px";
            obj.style.height = h+"px";

            obj._skipChecksOnStartUp = true;

            if (skin == null) { skin = that.skin; }

            this.layout = new dhtmlXLayoutObject(obj, view, skin);
            this.layout._parentWindow = this;
            // alert(w+" "+h)
            // console.log(w,h)

            // this.layout._fixPositionInWin(w, h);
            this.attachEvent("_onBeforeTryResize", this.layout._defineWindowMinDimension);
            return this.layout;
        }
//#}
        /**
        *   @desc: attaches a dhtmlxEditor to a window
        *   @param: skin - not mandatory, editor's skin
        *   @type: public
        */
        win.attachEditor = function(skin) {
            var obj = document.createElement("DIV");
            obj.id = "dhxEditorObj_"+that._genStr(12);
            obj.style.position = "relative";
            obj.style.display = "none";
            obj.style.overflow = "hidden";
            obj.style.width = "100%";
            obj.style.height = "100%";
            document.body.appendChild(obj);
            //
            this.attachObject(obj.id);
            //
            this.editor = new dhtmlXEditor(obj.id, (skin!=null?skin:that.skin));

            return this.editor;

        }
        /**
        *   @desc: sets a window to the fullscreen mode
        *   @param: state - true|false
        *   @type: public
        */
        win.setToFullScreen = function(state) {
            that._setWindowToFullScreen(this, state);
        }
        /**
        *   @desc: shows window's header
        *   @type: public
        */
        win.showHeader = function() {
            that._showWindowHeader(this);
        }
        /**
        *   @desc: hides window's header
        *   @type: public
        */
        win.hideHeader = function() {
            that._hideWindowHeader(this);
        }
        //
        win.progressOff();
        // resize cursor modifications and handlers
        win.canStartResize = false;
        win.onmousemove = function(e) {
            // resize not allowed
            if ((!this._allowResize) || (this._allowResizeGlobal == false)) {
                this.canStartResize = false;
                this.style.cursor = "";
                return;
            }

            if (that.resizingWin != null) { return; }
            if (this._isParked) { return; }
            //
            e = e || event;
            var targetObj = e.target || e.srcElement;
            //
            var useDefaultCursor = true;
            this.canStartResize = true;
            //
            var skin = (this._skinParams!=null?this._skinParams:that.skinParams[that.skin]);
            var hh = skin["header_height"];
            var bwl = skin["border_left_width"] + 2;
            var bwr = skin["border_right_width"] + 2;
            var bhb = skin["border_bottom_height"] + 2;
            // left border
            if (targetObj.className == "dhtmlx_wins_body_border_middle_left") {
                that.resizingDirs = "border_left";
                this.style.cursor = "w-resize";
                this.resizeOffsetX = this.x - e.clientX;
                useDefaultCursor = false;
            }
            // right border
            if (targetObj.className == "dhtmlx_wins_body_border_middle_right") {
                that.resizingDirs = "border_right";
                this.style.cursor = "e-resize";
                this.resizeOffsetXW = this.x + this.w - e.clientX;
                useDefaultCursor = false;
            }
            // bottom border
            if (targetObj.className == "dhtmlx_wins_body_border_bottom_middle") {
                that.resizingDirs = "border_bottom";
                this.style.cursor = "n-resize";
                this.resizeOffsetYH = this.y + this.h - e.clientY;
                useDefaultCursor = false;
            }
            // corner left
            if (targetObj.className == "dhtmlx_wins_body_border_bottom_left") {
                that.resizingDirs = "corner_left";
                this.style.cursor = "sw-resize";
                this.resizeOffsetX = this.x - e.clientX;
                this.resizeOffsetYH = this.y + this.h - e.clientY;
                useDefaultCursor = false;
            }
            // corner right
            if (targetObj.className == "dhtmlx_wins_body_border_bottom_right") {
                that.resizingDirs = "corner_right";
                this.style.cursor = "nw-resize";
                this.resizeOffsetXW = this.x + this.w - e.clientX;
                this.resizeOffsetYH = this.y + this.h - e.clientY;
                useDefaultCursor = false;
            }

            // no matching elements
            if (useDefaultCursor) {
                this.canStartResize = false;
                this.style.cursor = "";
            }
        }
        win.onmousedown = function(e) {
            that._makeActive(this);
            that._bringOnTop(this);
            if (this.canStartResize) {
                that._blockSwitcher("none");
                that.resizingWin = this;
                if (!that._effects["resize"]) {
                    that._carcass.x = that.resizingWin.x;
                    that._carcass.y = that.resizingWin.y;
                    that._carcass.w = that.resizingWin.w+(_isIE?0:-2);
                    that._carcass.h = that.resizingWin.h+(_isIE?0:-2);
                    that._carcass.style.left = that._carcass.x+"px";
                    that._carcass.style.top = that._carcass.y+"px";
                    that._carcass.style.width = that._carcass.w+"px";
                    that._carcass.style.height = that._carcass.h+"px";
                    that._carcass.style.zIndex = that.resizingWin.style.zIndex+1;
                    that._carcass.style.cursor = this.style.cursor;
                    that._carcass._keepInViewport = this._keepInViewport;
                    that._carcass.style.display = "";
                }
                // vpcover
                that._vpcover.style.zIndex = that.resizingWin.style.zIndex-1;
                that._vpcover.style.display = "";
                if (this.layout) { this.callEvent("_onBeforeTryResize", [this]); }
                if (_isOpera) {
                    e = e||event;
                    e.returnValue = false;
                    e.cancelBubble = true;
                }
            }
        }
        // add buttons
        this._addDefaultButtons(win);
        //
//#wind_buttons:09062008{
        // return button handler
        win.button = function(id) {
            var b = null;
            if (this.btns[id] != null) { b = this.btns[id]; }
            return b;
        }
//#}
        //
        // attach content obj|url
        /**
        *   @desc: attaches an object into a window
        *   @param: obj - object or object id
        *   @param: autoSize - set true to adjust a window to object's dimension
        *   @type: public
        */
        win.attachObject = function(obj, autoSize) {
            if (typeof(obj) == "string") { obj = document.getElementById(obj); }
            if (autoSize) {
                obj.style.visibility = "hidden";
                obj.style.display = "";
                var objW = obj.offsetWidth;
                var objH = obj.offsetHeight;
            }
            that._attachContent(this, "obj", obj);
            if (autoSize) {
                obj.style.visibility = "visible";
                var skinParams = that.skinParams[that.skin];
                var newW = objW + skinParams["border_left_width"] + skinParams["border_right_width"];
                var newH = objH + skinParams["header_height"] + skinParams["border_bottom_height"];
                this.setDimension(newW, newH);
            }
        }
        /**
        *   @desc: appends an object into a window
        *   @param: obj - object or object id
        *   @type: public
        */
        win.appendObject = function(obj) {
            if (typeof(obj) == "string") { obj = document.getElementById(obj); }
            that._attachContent(this, "obj", obj, true);
        }
        /**
        *   @desc: attaches an html string as an object into a window
        *   @param: str - html string
        *   @type: public
        */
        win.attachHTMLString = function(str) {
            that._attachContent(this, "str", str);
        }
        /**
        *   @desc: attaches an url into a window
        *   @param: url
        *   @param: ajax - loads an url with ajax
        *   @type: public
        */
        win.attachURL = function(url, ajax) {
            that._attachContent(this, (ajax==true?"urlajax":"url"), url, false);
        }
        /**
        *   @desc: centers a window in the viewport
        *   @type: public
        */
        win.center = function() {
            that._centerWindow(this, false);
        }
        /**
        *   @desc: centers a window on the screen
        *   @type: public
        */
        win.centerOnScreen = function() {
            that._centerWindow(this, true);
        }
        //
        this._attachContent(win, "empty", null);
        win.bringToTop();
        //
        return this.wins[id];
    }

    this._diableOnSelectInWin = function(obj, state) {
        for (var q=0; q<obj.childNodes.length; q++) {
            var child = obj.childNodes[q];
            if ((child.tagName == "TD") || (child.tagName == "TR") || (child.tagName == "TABLE")  || (child.tagName == "DIV")) {
                if (child.getAttribute("clearonselect") != null) {
                    if (state) {
                        child.onselectstart = function(e) { e = e || event; e.returnValue = false; }

                    } else {
                        child.onselectstart = null;
                    }
                }
            }
            if (child.childNodes.length > 0) { this._diableOnSelectInWin(child, state); }
            child = null;
        }
    }
    this._redrawWindow = function(win) {
        if (win._isFullScreened) return;
        //
        win.style.left = win.x + "px";
        win.style.top = win.y + "px";
        // win.style.width = win.w + "px";
        // win.style.height = win.h + "px";
        win.style.width = (win.w == "100%" ? win.w : win.w+"px");
        win.style.height = (win.h == "100%" ? win.h : win.h+"px");
        if (win.w == "100%") {
            var winW = "100%";
            win.w = win.offsetWidth;
        }
        if (win.h == "100%") {
            var winH = "100%";
            win.h = win.offsetHeight;
        }
        // inner elements
        win.childNodes[0].style.height = win.h + "px";
        var p = win.childNodes[0].childNodes[0].childNodes[1].childNodes[0];
        var s = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
        p.style.height = win.h-s["header_height"] + "px";
        p.childNodes[0].style.height = win.h-s["header_height"] + "px";
        // title width
        // win.childNodes[2].className = "title_"+this.skin;
        var trObj = win.childNodes[3].childNodes[0].childNodes[0].childNodes[0];
        var tdVis = 0;
        for (var q=0; q<trObj.childNodes.length; q++) { if (trObj.childNodes[q].className == "dhtmlx_wins_btn_visible") { tdVis++; } }
        // tdVis
        // var wdth = win.childNodes[3].offsetLeft - win.childNodes[2].offsetLeft - 5;
        var wdth = win.w /* window width */ - tdVis*18 /* icons */ - 30 /* other gaps */;
        if (wdth < 0) { wdth = 0; }
        //
        win.childNodes[2].style.width = wdth + "px";
        // content div
        var w = win.w - s["border_left_width"] - s["border_right_width"];
        var h = win.h - s["header_height"] - s["border_bottom_height"];
        if (w < 0) { w = 0; }
        if (h < 0) { h = 0; }
        //
        var bd = p.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
        //
        /*
        if (win._manageAddons) {
            win._manageAddons(w, h);
        } else {
            bd.style.width = w + "px";
            bd.style.height = h + "px";
        }
        */

            if (bd == null) {
                bd = win._content;
            }
            // new
            bd.style.width = w + "px";
            bd.style.height = h + "px";
            //
        if (winW != null) { win.w = winW; }
        if (winH != null) { win.h = winH; }
    }

    this.zIndexStep = 50;
    this._getTopZIndex = function(ignoreSticked) {
        var topZIndex = 0;
        for (var a in this.wins) {
            if (ignoreSticked == true) {
                if (this.wins[a].zi > topZIndex) { topZIndex = this.wins[a].zi; }
            } else {
                if (this.wins[a].zi > topZIndex && !this.wins[a]._isSticked) { topZIndex = this.wins[a].zi; }
            }
        }
        return topZIndex;
    }

    this.movingWin = null;
//#wind_move:09062008{
    this._moveWindow = function(e) {

        if (this.movingWin != null) {
            //
            if (!this.movingWin._allowMove || !this.movingWin._allowMoveGlobal) { return; }
            if (this._effects["move"] == true) {
                //
                this.movingWin.oldMoveX = this.movingWin.x;
                this.movingWin.oldMoveY = this.movingWin.y;
                //
                this.movingWin.x = e.clientX + this.movingWin.moveOffsetX;
                this.movingWin.y = e.clientY + this.movingWin.moveOffsetY;
                //
                // check out of viewport
                this._fixWindowPositionInViewport(this.movingWin);
                //
                this._redrawWindow(this.movingWin);
                //
                // if (this._compoEnabled) { this._compoFixMove(this.movingWin); }
            } else {
                // console.log(1)
                if (this._carcass.style.display != "") {
                    this._carcass.style.display = "";
                }
                this._carcass.x = e.clientX + this.movingWin.moveOffsetX;
                this._carcass.y = e.clientY + this.movingWin.moveOffsetY;
                this._fixWindowPositionInViewport(this._carcass);
                this._carcass.style.left = this._carcass.x+"px";
                this._carcass.style.top = this._carcass.y+"px";
                /*
                this._carcass.style.width = this.movingWin.style.width;
                this._carcass.style.height = this.movingWin.style.height;
                this._carcass.style.zIndex = this.movingWin.style.zIndex+10;
                this._carcass.style.display = "";
                */
            }
        }

        if (this.resizingWin != null) {
            //
            if (!this.resizingWin._allowResize) { return; }
            //
            // resize through left border
            if (this.resizingDirs == "border_left" || this.resizingDirs == "corner_left") {
                if (this._effects["resize"]) {
                    var ofs = e.clientX + this.resizingWin.resizeOffsetX;
                    var sign = (ofs > this.resizingWin.x ? -1 : 1);
                    newW = this.resizingWin.w + Math.abs(ofs - this.resizingWin.x)*sign;
                    if ((newW < this.resizingWin.minW) && (sign < 0)) {
                        this.resizingWin.x = this.resizingWin.x + this.resizingWin.w - this.resizingWin.minW;
                        this.resizingWin.w = this.resizingWin.minW;
                    } else {
                        this.resizingWin.w = newW;
                        this.resizingWin.x = ofs;
                    }
                    this._redrawWindow(this.resizingWin);
                } else {
                    var ofs = e.clientX + this.resizingWin.resizeOffsetX;
                    var sign = (ofs > this._carcass.x ? -1 : 1);
                    newW = this._carcass.w + Math.abs(ofs - this._carcass.x)*sign;
                    if ((newW < this.resizingWin.minW) && (sign < 0)) {
                        this._carcass.x = this._carcass.x + this._carcass.w - this.resizingWin.minW;
                        this._carcass.w = this.resizingWin.minW;
                    } else {
                        this._carcass.w = newW;
                        this._carcass.x = ofs;
                    }
                    this._carcass.style.left = this._carcass.x+"px";
                    this._carcass.style.width = this._carcass.w+"px";
                }
            }
            // resize through right border
            if (this.resizingDirs == "border_right" || this.resizingDirs == "corner_right") {
                if (this._effects["resize"]) {
                    var ofs = e.clientX - (this.resizingWin.x + this.resizingWin.w) + this.resizingWin.resizeOffsetXW;
                    newW = this.resizingWin.w + ofs;
                    if (newW < this.resizingWin.minW) { newW = this.resizingWin.minW; }
                    this.resizingWin.w = newW;
                    this._redrawWindow(this.resizingWin);
                } else {
                    var ofs = e.clientX - (this._carcass.x + this._carcass.w) + this.resizingWin.resizeOffsetXW;
                    newW = this._carcass.w + ofs;
                    if (newW < this.resizingWin.minW) { newW = this.resizingWin.minW; }
                    this._carcass.w = newW;
                    this._carcass.style.width = this._carcass.w+"px";
                    // this._redrawWindow(this.resizingWin);
                }
            }
            // resize through bottom border
            if (this.resizingDirs == "border_bottom" || this.resizingDirs == "corner_left" || this.resizingDirs == "corner_right") {
                if (this._effects["resize"]) {
                    var ofs = e.clientY - (this.resizingWin.y + this.resizingWin.h) + this.resizingWin.resizeOffsetYH;
                    newH = this.resizingWin.h + ofs;
                    if (newH < this.resizingWin.minH) { newH = this.resizingWin.minH; }
                    this.resizingWin.h = newH;
                    //if (this._compoEnabled) {
                    //  this._compoFixResize(this.resizingWin, this.resizingDirs);
                    //} else {
                        this._redrawWindow(this.resizingWin);
                    //}
                } else {
                    var ofs = e.clientY - (this._carcass.y + this._carcass.h) + this.resizingWin.resizeOffsetYH;
                    newH = this._carcass.h + ofs;
                    if (newH < this.resizingWin.minH) { newH = this.resizingWin.minH; }
                    this._carcass.h = newH;
                    this._carcass.style.height = this._carcass.h+"px";
                }
            }
            //
            // if (this._compoEnabled) { this._compoFixResize(this.resizingWin, this.resizingDirs); }
        }
    }

    this._stopMove = function() {
        if (this.movingWin != null) {
            if (this._effects["move"]) {
                var win = this.movingWin;
                this.movingWin = null;
                this._blockSwitcher("");
                // cursor
                win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].style.cursor =
                "";
                win.childNodes[2].style.cursor = "";
                // fixing mozilla artefakts
                if (_isFF) {
                    win.h++;
                    this._redrawWindow(win);
                    win.h--;
                    this._redrawWindow(win);
                }
            } else {
                this._carcass.style.display = "none";
                var win = this.movingWin;
                this.movingWin = null;
                this._blockSwitcher("");
                win.setPosition(parseInt(this._carcass.style.left), parseInt(this._carcass.style.top));
            }
            // vpcover
            this._vpcover.style.display = "none";
            // events
            if (!(win.oldMoveX == win.x && win.oldMoveY == win.y)) {
                //
                if (win.checkEvent("onMoveFinish")) {
                    win.callEvent("onMoveFinish",[win]);
                } else {
                    this.callEvent("onMoveFinish",[win]);
                }
            }
        }
        if (this.resizingWin != null) {
            var win = this.resizingWin;
            this.resizingWin = null;
            this._blockSwitcher("");
            if (!this._effects["resize"]) {
                this._carcass.style.display = "none";
                win.setPosition(this._carcass.x, this._carcass.y);
                win.setDimension(this._carcass.w+(_isIE?0:2), this._carcass.h+(_isIE?0:2));
            }
            // sizes in attached components
            this._fixInnerObjs(win);
            // event in layout
            if (win.layout) { win.layout.callEvent("onResize", []); }
            // opera fix
            if (_isOpera) {
                win._content.childNodes[2].style.border="#FFFFFF 0px solid";
                var w = win._content.childNodes[2];
                window.setTimeout(function(){ w.style.border="none"; }, 1);
            }
            // vpcover
            this._vpcover.style.display = "none";
            // events
            if (win.checkEvent("onResizeFinish")) {
                win.callEvent("onResizeFinish",[win]);
            } else {
                this.callEvent("onResizeFinish",[win]);
            }
        }
    }
//#}

    // check viewport overflow
    this._fixWindowPositionInViewport = function(win) {
        var skin = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
        if (win._keepInViewport) { // keep strongly in viewport
            if (win.x < 0) { win.x = 0; }
            if (win.x + win.w > this.vp.offsetWidth) { win.x = this.vp.offsetWidth - win.w; }
            // if (win.y < 0) { win.y = 0; }
            if (win.y + win.h > this.vp.offsetHeight) { win.y = this.vp.offsetHeight - win.h; }
            if (win.y < 0) { win.y = 0; }
        } else {
            // if (win.y < 0) { win.y = 0; }
            if (win.y + skin["header_height"] > this.vp.offsetHeight) { win.y = this.vp.offsetHeight - skin["header_height"]; }
            if (win.y < 0) { win.y = 0; }
            if (win.x + win.w - 10 < 0) { win.x = 10 - win.w; }
            if (win.x > this.vp.offsetWidth - 10) { win.x = this.vp.offsetWidth - 10; }
        }
    }

    // check and correct window dimensions
    this._fixWindowDimensionInViewport = function(win) {
        if (win.w < win.minW) { win.w = win.minW; }
        if (win.h < win.minH) { win.h = win.minH; }
    }

    this._bringOnTop = function(win) {
        var cZIndex = win.zi;
        var topZIndex = this._getTopZIndex(win._isSticked);
        for (var a in this.wins) {
            if (this.wins[a] != win) {
                if (win._isSticked || (!win._isSticked && !this.wins[a]._isSticked)) {
                    if (this.wins[a].zi > cZIndex) {
                        this.wins[a].zi = this.wins[a].zi - this.zIndexStep;
                        this.wins[a].style.zIndex = this.wins[a].zi;
                    }
                }
            }
        }
        win.zi = topZIndex;
        win.style.zIndex = win.zi;
    }

    this._makeActive = function(win, ignoreFocusEvent) {
        for (var a in this.wins) {
            if (this.wins[a] == win) {
                var needEvent = false;
                if (this.wins[a].className != "dhtmlx_window_active" && !ignoreFocusEvent) { needEvent = true; }
                this.wins[a].className = "dhtmlx_window_active";
                this.wins[a].childNodes[1].src = this.wins[a].icons[0];
                if (needEvent == true) {
                    if (win.checkEvent("onFocus")) {
                        win.callEvent("onFocus",[win]);
                    } else {
                        this.callEvent("onFocus",[win]);
                    }
                }
            } else {
                this.wins[a].className = "dhtmlx_window_inactive";
                this.wins[a].childNodes[1].src = this.wins[a].icons[1];
            }
        }
    }

    this._getActive = function() {
        var win = null;
        for (var a in this.wins) {
            if (this.wins[a].className == "dhtmlx_window_active") {
                win = this.wins[a];
            }
        }
        return win;
    }

    this._centerWindow = function(win, onScreen) {
        if (win._isMaximized == true) { return; }
        if (win._isParked == true) { return; }
        if (onScreen == true) {
            var vpw = (_isIE?document.body.offsetWidth:window.innerWidth);
            var vph = (_isIE?document.body.offsetHeight:window.innerHeight);
        } else {
            var vpw =
            (this.vp==document.body?document.body.offsetWidth:(Number(parseInt(this.vp.style.width))&&String(this.vp.style.width).search("%")==-1?parseInt(this.vp.style.width):this.vp.offsetWidth));
            var vph =
            (this.vp==document.body?document.body.offsetHeight:(Number(parseInt(this.vp.style.height))&&String(this.vp.style.height).search("%")==-1?parseInt(this.vp.style.height):this.vp.offsetHeight));
        }
        var newX = Math.round((vpw/2) - (win.w/2));
        var newY = Math.round((vph/2) - (win.h/2));
        win.x = newX;
        win.y = newY;
        this._fixWindowPositionInViewport(win);
        this._redrawWindow(win);
    }

    this._switchProgress = function(win, state) {
        if (state == true) {
            win.childNodes[1].style.display = "none";
            win.childNodes[4].style.display = "";
        } else {
            win.childNodes[4].style.display = "none";
            win.childNodes[1].style.display = "";
        }
    }

    this._addDefaultButtons = function(win) {
//#wind_buttons:09062008{
        // stick
        var btnStick = document.createElement("DIV");
        btnStick.className = "button_stick_default";
        btnStick.title = "Stick";
        btnStick.isVisible = false;
        btnStick._isEnabled = true;
        btnStick.isPressed = false;
        win._isSticked = false;
        btnStick.label = "stick";
        btnStick._doOnClick = function() {
            this.isPressed = true;
            that._stickWindow(win);
        }

        // sticked
        var btnSticked = document.createElement("DIV");
        btnSticked.className = "button_sticked_default";
        btnSticked.title = "Unstick";
        btnSticked.isVisible = false;
        btnSticked._isEnabled = true;
        btnSticked.isPressed = false;
        btnSticked.label = "sticked";
        btnSticked._doOnClick = function() {
            this.isPressed = false;
            that._unstickWindow(win);
        }

        // help
        var btnHelp = document.createElement("DIV");
        btnHelp.className = "button_help_default";
        btnHelp.title = "Help";
        btnHelp.isVisible = false;
        btnHelp._isEnabled = true;
        btnHelp.isPressed = false;
        btnHelp.label = "help";
        btnHelp.that = this;
        btnHelp._doOnClick = function() { that._needHelp(win); }

        // park
        var btnPark = document.createElement("DIV");
        btnPark.className = "button_park_default";
        btnPark.titleIfParked = "Park Down";
        btnPark.titleIfNotParked = "Park Up";
        btnPark.title = btnPark.titleIfNotParked;
        btnPark.isVisible = true;
        btnPark._isEnabled = true;
        btnPark.isPressed = false;
        btnPark.label = "park";
        win._isParked = false;
        win._isParkedAllowed = true;
        btnPark._doOnClick = function() { that._parkWindow(win); }

        // minmax maximize
        var btnMinMax1 = document.createElement("DIV");
        btnMinMax1.className = "button_minmax1_default";
        btnMinMax1.title = "Maximize";
        btnMinMax1.isVisible = true;
        btnMinMax1._isEnabled = true;
        btnMinMax1.isPressed = false;
        btnMinMax1.label = "minmax1";
        win._isMaximized = false;
        btnMinMax1._doOnClick = function() { that._maximizeWindow(win); }

        // minmax restore
        var btnMinMax2 = document.createElement("DIV");
        btnMinMax2.className = "button_minmax2_default";
        btnMinMax2.title = "Restore";
        btnMinMax2.isVisible = false;
        btnMinMax2._isEnabled = true;
        btnMinMax2.isPressed = false;
        btnMinMax2.label = "minmax2";
        btnMinMax2._doOnClick = function() { that._restoreWindow(win); }

        // close
        var btnClose = document.createElement("DIV");
        btnClose.className = "button_close_default";
        btnClose.title = "Close";
        btnClose.isVisible = true;
        btnClose._isEnabled = true;
        btnClose.isPressed = false;
        btnClose.label = "close";
        btnClose._doOnClick = function() { that._closeWindow(win); }

        //
        win.btns = {};
        win.btns["stick"] = btnStick;
        win.btns["sticked"] = btnSticked;
        win.btns["help"] = btnHelp;
        win.btns["park"] = btnPark;
        win.btns["minmax1"] = btnMinMax1;
        win.btns["minmax2"] = btnMinMax2;
        win.btns["close"] = btnClose;

        var b = win.childNodes[3].childNodes[0].childNodes[0].childNodes[0];

        // events
        for (var a in win.btns) {

            var btn = win.btns[a];

            // add on header
            var td = document.createElement("TD");
            td.className = "dhtmlx_wins_btn_" + (btn.isVisible ? "visible" : "hidden");
            b.appendChild(td);
            td.appendChild(btn);
            // attach events
            this._attachEventsOnButton(win, btn);
            //
            btn = null;
        }
//#}
    }
//#wind_buttons:09062008{
    this._attachEventsOnButton = function(win, btn) {
        // add events

        btn.onmouseover = function() {
            if (this._isEnabled) {
                this.className = "button_"+this.label+"_over_" + (this.isPressed ? "pressed": "default");
            } else {
                this.className = "button_"+this.label+"_disabled";
            }
        }
        btn.onmouseout = function() {
            if (this._isEnabled) {
                this.isPressed = false;
                this.className = "button_"+this.label+"_default";
            } else {
                this.className = "button_"+this.label+"_disabled";
            }
        }
        btn.onmousedown = function() {
            if (this._isEnabled) {
                this.isPressed = true;
                this.className = "button_"+this.label+"_over_pressed";
            } else {
                this.className = "button_"+this.label+"_disabled";
            }
        }
        btn.onmouseup = function() {
            if (this._isEnabled) {
                var wasPressed = this.isPressed;
                this.isPressed = false;
                this.className = "button_"+this.label+"_over_default";
                if (wasPressed) {
                    // events
                    if (this.checkEvent("onClick")) {
                        this.callEvent("onClick", [win, this]);
                    } else {
                        this._doOnClick();
                    }
                }
            } else {
                this.className = "button_"+this.label+"_disabled";
            }
        }
/**
*   @desc: shows a button
*   @type:  public
*/
        btn.show = function() {
            that._showButton(win, this.label);
        }
/**
*   @desc: hides a button
*   @type:  public
*/
        btn.hide = function() {
            that._hideButton(win, this.label);
        }
/**
*   @desc: enables a button
*   @type:  public
*/

        btn.enable = function() {
            that._enableButton(win, this.label);
        }

/**
*   @desc: disables a button
*   @type:  public
*/
        btn.disable = function() {
            that._disableButton(win, this.label);
        }
/**
*   @desc: checks if a button is enabled
*   @returns: true if enabled, otherwise - false
*   @type:  public
*/
        btn.isEnabled = function() {
            return this._isEnabled;
        }

/**
*   @desc: checks  if a button is hidden
*   @returns: true if hidden, otherwise - false
*   @type:  public
*/
        btn.isHidden = function() {
            return (!this.isVisible);
        }
        btn.dhx_Event = this.dhx_Event;
        btn.dhx_Event();
    }
//#}
//#wind_park:09062008{
    this._parkWindow = function(win) {
        if (!win._isParkedAllowed) { return; }
        if (this.enableParkEffect && win.parkBusy) { return; }
        if (win._isParked) {
            if (this.enableParkEffect) {
                win.parkBusy = true;
                // win.childNodes[0].childNodes[0].childNodes[1].style.display = "";
                win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "";
                this._doParkDown(win);
            } else {
                win.h = win.lastParkH;
                win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "";
                win.btns["park"].title = win.btns["park"].titleIfNotParked;
                if (win._allowResizeGlobal == true) {
                    this._enableButton(win, "minmax1");
                    this._enableButton(win, "minmax2");
                }
            }
        } else {
            win.lastParkH = (String(win.h).search(/\%$/)==-1?win.h:win.offsetHeight);
            if (win._allowResizeGlobal == true) {
                this._disableButton(win, "minmax1");
                this._disableButton(win, "minmax2");
            }
            //
            if (this.enableParkEffect) {
                win.parkBusy = true;
                this._doParkUp(win);
            } else {
                var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
                win.h = skinParams["header_height"] + skinParams["border_bottom_height"];
                win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "none";
                win.btns["park"].title = win.btns["park"].titleIfParked;
            }
        }
        if (!this.enableParkEffect) {
            win._isParked = !win._isParked;
            this._redrawWindow(win);
            // events
            if (!win._isParked) {
                // sizes
                this._fixInnerObjs(win);
                // opera fix
                if (_isOpera) {
                    win._content.childNodes[2].style.border="#FFFFFF 0px solid";
                    var w = win._content.childNodes[2];
                    window.setTimeout(function(){ w.style.border="none"; }, 1);
                }
                // onParkDown event
                if (win.checkEvent("onParkDown")) {
                    win.callEvent("onParkDown", [win]);
                } else {
                    this.callEvent("onParkDown", [win]);
                }
            } else {
                // bottom border fix for opera
                if (_isOpera) {
                    win.childNodes[0].border = 1;
                    win.childNodes[0].border = 0;
                }
                // onParkUp event
                if (win.checkEvent("onParkUp")) {
                    win.callEvent("onParkUp", [win]);
                } else {
                    this.callEvent("onParkUp", [win]);
                }
            }
        }
    }

    this._allowParking = function(win) {
        win._isParkedAllowed = true;
        this._enableButton(win, "park");
    }
    this._denyParking = function(win) {
        win._isParkedAllowed = false;
        this._disableButton(win, "park");
    }

    // park with effects
    this.enableParkEffect = true;
    this.parkStartSpeed = 80;
    this.parkSpeed = this.parkStartSpeed;
    this.parkTM = null;
    this.parkTMTime = 5;

    this._doParkUp = function(win) {
        if (String(win.h).search(/\%$/) != -1) {
            win.h = win.offsetHeight;
        }
        win.h -= this.parkSpeed;
        var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
        if (win.h <= skinParams["header_height"] + skinParams["border_bottom_height"]) {
            // end purkUp
            win.h = skinParams["header_height"] + skinParams["border_bottom_height"];
            // win.childNodes[0].childNodes[0].childNodes[1].style.display = "none";
            win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "none";
            win.btns["park"].title = win.btns["park"].titleIfParked;
            win._isParked = true;
            win.parkBusy = false;
            this._redrawWindow(win, true);
            // bottom border fix for opera
            if (_isOpera) {
                win.childNodes[0].border = 1;
                win.childNodes[0].border = 0;
            }
            // onParkUp event
            if (win.checkEvent("onParkUp")) {
                win.callEvent("onParkUp", [win]);
            } else {
                this.callEvent("onParkUp", [win]);
            }
        } else {
            // continue purkUp
            this._redrawWindow(win);
            this.parkTM = window.setTimeout(function(){that._doParkUp(win);}, this.parkTMTime);
        }
    }

    this._doParkDown = function(win) {
        win.h += this.parkSpeed;

        if (win.h >= win.lastParkH) {
            win.h = win.lastParkH;
            win.btns["park"].title = win.btns["park"].titleIfNotParked;
            if (win._allowResizeGlobal == true) {
                this._enableButton(win, "minmax1");
                this._enableButton(win, "minmax2");
            }
            win._isParked = false;
            win.parkBusy = false;
            this._redrawWindow(win);
            // fix sizes
            this._fixInnerObjs(win);
            // opera fix
            if (_isOpera) {
                win._content.childNodes[2].style.border="#FFFFFF 0px solid";
                var w = win._content.childNodes[2];
                window.setTimeout(function(){ w.style.border="none"; }, 1);
            }
            // onParkDown event
            if (win.checkEvent("onParkDown")) {
                win.callEvent("onParkDown", [win]);
            } else {
                this.callEvent("onParkDown", [win]);
            }
        } else {
            // continue purkDown
            this._redrawWindow(win);
            this.parkTM = window.setTimeout(function(){ that._doParkDown(win); }, this.parkTMTime);
        }
    }
//#}
//#wind_buttons:09062008{
    this._enableButton = function(win, btn) {
        win.btns[btn]._isEnabled = true;
        win.btns[btn].className = "button_"+win.btns[btn].label+"_default";
    }

    this._disableButton = function(win, btn) {
        win.btns[btn]._isEnabled = false;
        win.btns[btn].className = "button_"+win.btns[btn].label+"_disabled";
    }
//#}
    // header control
    this._showWindowHeader = function(win) {
        win.childNodes[1].style.display = "";
        win.childNodes[2].style.display = "";
        win.childNodes[3].style.display = "";
        for (var a in win._skinParams) { delete win._skinParams[a]; }
        win._skinParams = null;
        var h = this.skinParams[this.skin]["header_height"]+"px";
        win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // td class="dhtmlx_wins_td_header_full"
        win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // table class="dhtmlx_wins_header"
        var hdr = win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        for (var q=0; q<hdr.childNodes.length; q++) { hdr.childNodes[q].style.height = h; }
        this._redrawWindow(win);
    }
    this._hideWindowHeader = function(win) {
        win.childNodes[1].style.display = "none";
        win.childNodes[2].style.display = "none";
        win.childNodes[3].style.display = "none";
        win._skinParams = {};
        for (var a in this.skinParams[this.skin]) { win._skinParams[a] = Number(this.skinParams[this.skin][a]).valueOf(); }
        win._skinParams["header_height"] = win._skinParams["border_bottom_height"];
        var h = win._skinParams["header_height"]+"px";
        win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // td class="dhtmlx_wins_td_header_full"
        win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // table class="dhtmlx_wins_header"
        var hdr = win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        for (var q=0; q<hdr.childNodes.length; q++) { hdr.childNodes[q].style.height = h; }
        this._redrawWindow(win);
    }
    // resize
    this._allowReszieGlob = function(win) {
        win._allowResizeGlobal = true;
        this._enableButton(win, "minmax1");
        this._enableButton(win, "minmax2");
    }

    this._denyResize = function(win) {
        win._allowResizeGlobal = false;
        this._disableButton(win, "minmax1");
        this._disableButton(win, "minmax2");
    }

    this._maximizeWindow = function(win) {
        if (win._allowResizeGlobal == false) { return; }
        win.lastMaximizeX = win.x;
        win.lastMaximizeY = win.y;
        win.lastMaximizeW = win.w;
        win.lastMaximizeH = win.h;
        win.x = 0;
        win.y = 0;
        win._isMaximized = true;
        win._allowMove = false;
        win._allowResize = false;
        // win.w = (win.maxW == "auto" ? (this.vp == document.body ? document.body.offsetWidth:parseInt(this.vp.style.width)) : win.maxW);
        // win.h = (win.maxH == "auto" ? (this.vp == document.body ? document.body.offsetHeight:parseInt(this.vp.style.height)) : win.maxH);
        //
        win.w = (win.maxW == "auto" ? (this.vp == document.body ? "100%" : (this.vp.style.width != "" && String(this.vp.style.width).search("%") ==
        -1 ? parseInt(this.vp.style.width) : this.vp.offsetWidth)) : win.maxW);
        win.h = (win.maxH == "auto" ? (this.vp == document.body ? "100%" : (this.vp.style.height != "" && String(this.vp.style.width).search("%") ==
        -1 ? parseInt(this.vp.style.height) : this.vp.offsetHeight)) : win.maxH);
        //
        this._hideButton(win, "minmax1");
        this._showButton(win, "minmax2");
        this._redrawWindow(win);
        // sizes in attached components
        this._fixInnerObjs(win);
        // event
        if (win.checkEvent("onMaximize")) {
            win.callEvent("onMaximize", [win]);
        } else {
            this.callEvent("onMaximize", [win]);
        }
    }

    this._restoreWindow = function(win) {
        if (win._allowResizeGlobal == false) { return; }
        if (win.layout) { win.layout._defineWindowMinDimension(win); }
        win.x = win.lastMaximizeX;
        win.y = win.lastMaximizeY;
        win.w = win.lastMaximizeW;
        win.h = win.lastMaximizeH;
        win._isMaximized = false;
        win._allowMove = win._allowMoveGlobal;
        win._allowResize = true;
        this._fixWindowDimensionInViewport(win);
        this._hideButton(win, "minmax2");
        this._showButton(win, "minmax1");
        this._redrawWindow(win);
        // sizes in attached components
        this._fixInnerObjs(win);
        // events
        if (win.checkEvent("onMinimize")) {
            win.callEvent("onMinimize", [win]);
        } else {
            this.callEvent("onMinimize", [win]);
        }
    }
//#wind_buttons:09062008{
    this._showButton = function(win, btn) {
        win.btns[btn].isVisible = true;
        // win.btns[btn].parentNode.className = "dhtmlx_wins_btn_visible";
        var p = win.btns[btn].parentNode;
        p.className = "dhtmlx_wins_btn_visible";
        p = null;
    }

    this._hideButton = function(win, btn) {
        win.btns[btn].isVisible = false;
        // win.btns[btn].parentNode.className = "dhtmlx_wins_btn_hidden";
        var p = win.btns[btn].parentNode;
        p.className = "dhtmlx_wins_btn_hidden";
        p = null;
    }
//#}
    this._showWindow = function(win) {
        win.style.display = "";
        // event
        if (win.checkEvent("onShow")) {
            win.callEvent("onShow", [win]);
        } else {
            this.callEvent("onShow", [win]);
        }
        // fixed 24.03.2008
        var w = this._getActive();
        if (w == null) {
            this._bringOnTop(win);
            this._makeActive(win);
        } else if (this._isWindowHidden(w)) {
            this._bringOnTop(win);
            this._makeActive(win);
        }
    }

    this._hideWindow = function(win) {
        win.style.display = "none";
        // event
        if (win.checkEvent("onHide")) {
            win.callEvent("onHide", [win]);
        } else {
            this.callEvent("onHide", [win]);
        }
        // fixed 24.03.2008
        var w = this.getTopmostWindow(true);
        if (w != null) {
            this._bringOnTop(w);
            this._makeActive(w);
        }
    }

    this._isWindowHidden = function(win) {
        var isHidden = (win.style.display == "none");
        return isHidden;
    }

    this._closeWindow = function(win) {
        // event
        if (win.checkEvent("onClose")) {
            if (!win.callEvent("onClose", [win])) return;
        } else {
            if(!this.callEvent("onClose", [win])) return;
        }
        // closing
        // for (var a in win.btns) { this._removeButtonGlobal(win, a, win.btns[a]); }
        this._removeWindowGlobal(win);
        /*
        this.vp.removeChild(win);
        delete this.wins[win.idd];
        // make active latest window
        */
        var latest = { "zi": 0 };
        for (var a in this.wins) { if (this.wins[a].zi > latest.zi) { latest = this.wins[a]; } }
        if (latest != null) { this._makeActive(latest); }
    }

    this._needHelp = function(win) {
        // event only
        if (win.checkEvent("onHelp")) {
            win.callEvent("onHelp", [win]);
        } else {
            this.callEvent("onHelp", [win]);
        }
    }

    this._attachContent = function(win, type, obj, append) {
        // clear old content
        if (append !== true) {
            while (win._content.childNodes[2].childNodes.length > 0) {
            win._content.childNodes[2].removeChild(win._content.childNodes[2].childNodes[0]); }
        }
        // attach
        if (type == "url") {
            var fr = document.createElement("IFRAME");
            fr.frameBorder = 0;
            fr.border = 0;
            fr.style.width = "100%";
            fr.style.height = "100%";
            fr.src = obj;
            win._content.childNodes[2].appendChild(fr);
            win._frame = fr;
            if (_isIE) {
                win._frame.onreadystatechange = function(a) { if (win._frame.readyState == "complete") { that.callEvent("onContentLoaded", [win]); }
                }
            } else {
                win._frame.onload = function() { that.callEvent("onContentLoaded", [win]); }
            }
        } else if (type == "urlajax") {
            var xmlParser = function(){
                this.dhxWindowObject.attachHTMLString(this.xmlDoc.responseText);
                that.callEvent("onContentLoaded", [win]);
                this.destructor();
            }
            var xmlLoader = new dtmlXMLLoaderObject(xmlParser, window);
            xmlLoader.dhxWindowObject = win;
            xmlLoader.loadXML(obj);
        } else if (type == "obj") {
            win._frame = null;
            win._content.childNodes[2].appendChild(obj);
            win._content.childNodes[2].style.overflow = (append===true?"auto":"hidden");
            obj.style.display = "";
        } else if (type == "str") {
            win._frame = null;
            win._content.childNodes[2].innerHTML = obj;
        }
    }

    this._setWindowIcon = function(win, iconEnabled, iconDisabled) {
        win.iconsPresent = true;
        win.icons[0] = this.imagePath + iconEnabled;
        win.icons[1] = this.imagePath + iconDisabled;
        win.childNodes[1].src = win.icons[win.isOnTop()?0:1];
    }

    this._getWindowIcon = function(win) {
        if (win.iconsPresent) {
            return new Array(win.icons[0], win.icons[1]);
        } else {
            return new Array(null, null);
        }
    }

    this._clearWindowIcons = function(win) {
        win.iconsPresent = false;
        win.icons[0] = this.imagePath + this.pathPrefix + this.skin + "/active/icon_blank.gif";
        win.icons[1] = this.imagePath + this.pathPrefix + this.skin + "/inactive/icon_blank.gif";
        win.childNodes[1].src = win.icons[win.isOnTop()?0:1];
    }

    this._restoreWindowIcons = function(win) {
        win.iconsPresent = true;
        win.icons[0] = this.imagePath + this.pathPrefix + this.skin + "/active/icon_normal.gif";
        win.icons[1] = this.imagePath + this.pathPrefix + this.skin + "/inactive/icon_normal.gif";
        win.childNodes[1].src = win.icons[win.className=="dhtmlx_window_active"?0:1];
    }

    this._attachWindowContentTo = function(win, obj, w, h) {

        var data = win._content;
        data.parentNode.removeChild(data);
        win.hide();
        //
        data.style.left = "0px";
        data.style.top = "0px";
        data.style.width = (w!=null?w:obj.offsetWidth)+"px";
        data.style.height = (h!=null?h:obj.offsetHeight)+"px";
        data.style.position = "relative";
        //
        obj.appendChild(data);

    }

    this._setWindowToFullScreen = function(win, state) {
        if (state == true) {
            //
            var data = win._content;
            data.parentNode.removeChild(data);
            win.hide();
            win._isFullScreened = true;
            //
            data.style.left = "0px";
            data.style.top = "0px";
            // data.style.width = document.body.offsetWidth+"px";
            // data.style.height = document.body.offsetHeight+"px";

            data.style.width = document.body.offsetWidth-(_isIE?4:0)+"px";
            if (document.body.offsetHeight == 0) {
                if (window.innerHeight) {
                    data.style.height = window.innerHeight+"px";
                } else {
                    data.style.height = document.body.scrollHeight+"px";
                }
            } else {

                data.style.height = document.body.offsetHeight-(_isIE?4:0)+"px";
            }

            data.style.position = "absolute";

            document.body.appendChild(data);

        } else if (state == false) {

            var data = win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1];
            var base = win._content;
            document.body.removeChild(base);
            data.appendChild(base);
            win._isFullScreened = false;
            win.setDimension(win.w, win.h);
            //
            win.show();
            win.bringToTop();
            win.center();
            //
        }
        this._fixInnerObjs(win);
    }

    this._isWindowOnTop = function(win) {
        var state = (this.getTopmostWindow() == win);
        return state;
    }

    this._bringOnBottom = function(win) {
        for (var a in this.wins) {
            if (this.wins[a].zi < win.zi) {
                this.wins[a].zi += this.zIndexStep;
                this.wins[a].style.zIndex = this.wins[a].zi;
            }
        }
        win.zi = 50;
        win.style.zIndex = win.zi;
        //
        this._makeActive(this.getTopmostWindow());
    }

    this._isWindowOnBottom = function(win) {
        var state = true;
        for (var a in this.wins) {
            if (this.wins[a] != win) {
                state = state && (this.wins[a].zi > win.zi);
            }
        }
        return state;
    }

    this._stickWindow = function(win) {
        win._isSticked = true;
        this._hideButton(win, "stick");
        this._showButton(win, "sticked");
        this._bringOnTop(win);
    }

    this._unstickWindow = function(win) {
        win._isSticked = false;
        this._hideButton(win, "sticked");
        this._showButton(win, "stick");
        this._bringOnTopAnyStickedWindows();
    }
//#wind_buttons:09062008{
    // add user button
    this._addUserButton = function(win, id, pos, title, label) {
        var btn = document.createElement("DIV");

        btn.className = "button_"+label+"_default";
        btn.title = title;
        btn.isVisible = true;
        btn._isEnabled = true;
        btn.isPressed = false;
        btn.label = label;
        //
        win.btns[id] = btn;
        //
        btn._doOnClick = function() {}
        // events

        // btn.that = this;
        // btn.win = win;
        var b = win.childNodes[3].childNodes[0].childNodes[0].childNodes[0];
        // add on header
        var td = document.createElement("TD");
        td.className = "dhtmlx_wins_btn_" + (btn.isVisible ? "visible" : "hidden");
        if (pos > b.childNodes.length) {
            b.appendChild(td);
        } else {
            if (pos < 0) { pos = 0; }
            b.insertBefore(td, b.childNodes[pos]);
        }

        td.appendChild(btn);

        // attach events
        this._attachEventsOnButton(win, btn);
    }

    // remove user button
    this._removeUserButton = function(win, id, btn) {
        this._removeButtonGlobal(win, id, btn);
    }
//#}
    // add iframe blockers before drag and resize
    this._blockSwitcher = function(state) {
        for (var a in this.wins) {
            var winContent = this.wins[a]._content;
            var cover = null;
            for (var q=0; q<winContent.childNodes.length; q++) { if (winContent.childNodes[q].className == "dhx_content_cover_blocker") { cover =
            winContent.childNodes[q]; } }
            if (cover != null) { cover.style.display = (state?"":"none"); }
        }
    }

    this.resizingWin = null;
    this.modalWin = null;
    this.resizingDirs = "none";

    // init functions

    this._createViewport();
//#wind_move:09062008{
    this._doOnMouseUp = function() {
        that._stopMove();
    }
    this._doOnMoseMove = function(e) {
        e = e||event;
        if (that!=null) { that._moveWindow(e); }
    }
//#}
    this._resizeTM = null;
    this._resizeTMTime = 200;
    this._doOnResize = function() {
        window.clearTimeout(that._resizeTM);
        that._resizeTM = window.setTimeout(function(){that._autoResizeViewport();}, that._resizeTMTime);
    }
    this._doOnUnload = function() {
        that.unload();
    }
    this._doOnSelectStart = function(e) {
        e = e||event;
        if (that.movingWin != null || that.resizingWin != null) { e.returnValue = false; }
    }
    if (_isIE) {
        document.body.attachEvent("onselectstart", this._doOnSelectStart);
    }
    dhtmlxEvent(window, "resize", this._doOnResize);
    dhtmlxEvent(document.body, "unload", this._doOnUnload);
//#wind_move:09062008{
    dhtmlxEvent(document.body, "mouseup", this._doOnMouseUp);
    dhtmlxEvent(this.vp, "mousemove", this._doOnMoseMove);
    dhtmlxEvent(this.vp, "mouseup", this._doOnMouseUp);
//#}


    this._setWindowModal = function(win, state) {

        if (state == true) {

            this._makeActive(win);
            this._bringOnTop(win);
            this.modalWin = win;
            win._isModal = true;
            //
            this.modalCoverI.style.zIndex = win.zi - 2;
            this.modalCoverI.style.display = "";
            //
            this.modalCoverD.style.zIndex = win.zi - 2;
            this.modalCoverD.style.display = "";
        } else {
            this.modalWin = null;
            win._isModal = false;
            //
            this.modalCoverI.style.zIndex = 0;
            this.modalCoverI.style.display = "none";
            //
            this.modalCoverD.style.zIndex = 0;
            this.modalCoverD.style.display = "none";
        }
    }

    this._bringOnTopAnyStickedWindows = function() {
        var wins = new Array();
        for (var a in this.wins) { if (this.wins[a]._isSticked) { wins[wins.length] = this.wins[a]; } }
        for (var q=0; q<wins.length; q++) { this._bringOnTop(wins[q]); }
        // if no more sticked search any non-top active and move them on top
        if (wins.length == 0) {
            for (var a in this.wins) {
                if (this.wins[a].className == "dhtmlx_window_active") { this._bringOnTop(this.wins[a]); }
            }
        }
    }

    /**
    *   @desc: unloads an object and clears memory
    *   @param: id - button's id
    *   @type: public
    */
    this.unload = function() {
        this._clearAll();
    }

    this._removeButtonGlobal = function(win, id, btn) {
//#wind_buttons:09062008{
        // clear functions
        this._parseNestedForEvents(btn);
        for (var a in btn) {
            if (typeof(btn[a]) == "function") {
                var k = (btn[a].toString()).split("\n");
                if (!(k.length == 3 && k[1].search(/\[native\scode\]/gi) != -1)) { btn[a] = null; }
            }
        }
        // remove from page
        var p = btn.parentNode;
        p.removeChild(btn);
        delete win.btns[id];
        btn = null;
        p = null;
//#}
    }

    this._removeWindowGlobal = function(win) {
        // modal check
        if (this.modalWin == win) { this._setWindowModal(win, false); }
        // clear functions
        this._parseNestedForEvents(win);
//#wind_buttons:09062008{
        if (!_isOpera) {
            for (var a in win.btns) {
                this._removeButtonGlobal(win, a, win.btns[a]);
            }
        }
//#}
        if (!_isOpera) {
            for (var a in win) {
                if (typeof(win[a]) == "function") {
                    var k = (win[a].toString()).split("\n");
                    if (!(k.length == 3 && k[1].search(/\[native\scode\]/gi) != -1)) { win[a] = null; }
                }
            }
        }
        // remove from page
        win._content = null;
        var p = win.parentNode;
        p.removeChild(win);
        delete this.wins[win.idd];
        win = null;
        p = null;
    }

    this._removeEvents = function(obj) {
        obj.onmouseover = null;
        obj.onmouseout = null;
        obj.onmousemove = null;
        obj.onclick = null;
        obj.ondblclick = null;
        obj.onmouseenter = null;
        obj.onmouseleave = null;
        obj.onmouseup = null;
        obj.onmousewheel = null;
        obj.onmousedown = null;
        obj.onselectstart = null;
        obj.onfocus = null;
        obj.style.display = "";
    }
    this._parseNestedForEvents = function(obj) {
        this._removeEvents(obj);
        for (var q=0; q<obj.childNodes.length; q++) {
            if (obj.childNodes[q].tagName != null) { this._parseNestedForEvents(obj.childNodes[q]); }
        }
    }

    this._attachStatusBar = function() {

    }

    this._attachWebMenu = function() {
        return null;
    }

    this._attachWebToolbar = function() {
        return null;
    }

    this._fixInnerObjs = function(win) {
        if (win.grid) { win.grid.setSizes(); win.grid.setSizes(); }
        if (win.tabbar) { win.tabbar.adjustOuterSize(); }
        if (win.menu) { win.menu._redistribTopLevelPositions(); }
        if (win.accordion) { win.accordion.setSizes(); }
        if (win.layout) { win.layout.setSizes(win); }
        if (win.folders) { win.folders.setSizes(); }
        if (win.editor) { if (_isOpera) { window.setTimeout(function(){win.editor.adjustSize();},10); } else { win.editor.adjustSize(); } }
    }

    this._clearAll = function() {
        this._clearDocumentEvents();
        for (var a in this.wins) {
            this._diableOnSelectInWin(this.wins[a]);
            this._removeWindowGlobal(this.wins[a]);
        }
        // modal covers and vp
        this.modalCoverD.style.display = "";
        this._parseNestedForEvents(this.modalCoverD);
        this.modalCoverD.parentNode.removeChild(this.modalCoverD);
        this.modalCoverD = null;
        this._parseNestedForEvents(this.modalCoverI);
        this.modalCoverI.style.display = "";
        this.modalCoverI.parentNode.removeChild(this.modalCoverI);
        this.modalCoverI = null;
        if (this.vp != document.body) { this.vp.parentNode.removeChild(this.vp); }
        this.vp = null;
        // skin params
        for (var a in this.skinParams) { delete this.skinParams[a]; }
        this.skinParams = null;
        that = null;
        // self functions
        for (var a in this) { if (typeof(this[a]) == "function") { this[a] = null; } }
        for (var a in this) { delete this[a]; }
        //
        // console.log(this)
    }

    this._clearDocumentEvents = function() {
        if (_isIE) {
            window.detachEvent("onresize", this._doOnResize);
            document.body.detachEvent("onselectstart", this._doOnSelectStart);
            document.body.detachEvent("onmouseup", this._doOnMouseUp);
            document.body.detachEvent("onunload", this._doOnUnload);
            this.vp.detachEvent("onmousemove", this._doOnMoseMove);
            this.vp.detachEvent("onmouseup", this._doOnMouseUp);
        } else {
            window.removeEventListener("resize", this._doOnResize, false);
            document.body.removeEventListener("mouseup", this._doOnMouseUp, false);
            document.body.removeEventListener("unload", this._doOnUnload, false);
            this.vp.removeEventListener("mousemove", this._doOnMoseMove, false);
            this.vp.removeEventListener("mouseup", this._doOnMouseUp, false);
        }
    }

    /* additional features */
    if (this._enableStatusBar != null) { this._enableStatusBar(); }
    if (this._enableWebMenu != null) { this._enableWebMenu(); }
    if (this._enableWebToolbar != null) { this._enableWebToolbar(); }

    this._genStr = function(w) {
        var s = ""; var z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        for (var q=0; q<w; q++) { s = s + z.charAt(Math.round(Math.random() * z.length)); }
        return s;
    }

    // events
    this.dhx_Event = function() {
        this.dhx_SeverCatcherPath="";
        /**
        *   @desc: attaches an event handler
        *   @param: original - event's original name
        *   @param: catcher - event handler
        *   @param: CallObj - object that will call the event
        *   @type: public
        */
        this.attachEvent = function(original, catcher, CallObj) {
            original = original.toLowerCase();
            CallObj = CallObj||this;
            original = 'ev_'+original;
            if ((!this[original]) || (!this[original].addEvent)) {
                var z = new this.eventCatcher(CallObj);
                z.addEvent(this[original]);
                this[original] = z;
            }
            return (original + ':' + this[original].addEvent(catcher)); //return ID (event name & event ID)
        }
        this.callEvent = function(name,arg0) {
            name = name.toLowerCase();
            if (this["ev_"+name]) { return this["ev_"+name].apply(this,arg0); }
            return true;
        }
        /**
        *   @desc: returns true if the event exists
        *   @param: name - event's name
        *   @type: public
        */
        this.checkEvent = function(name) {
            name = name.toLowerCase();
            if (this["ev_"+name]) { return true; }
            return false;
        }
        this.eventCatcher = function(obj) {
            var dhx_catch = new Array();
            var m_obj = obj;
            var z = function() {
                if (dhx_catch) var res = true;
                for (var i=0; i<dhx_catch.length; i++) { if (dhx_catch[i] != null) { var zr = dhx_catch[i].apply(m_obj, arguments); res = res && zr;
                } }
                return res;
            }
            z.addEvent = function(ev) {
                if (typeof(ev) != "function") ev = eval(ev);
                if (ev) return dhx_catch.push( ev ) - 1;
                return false;
            }
            z.removeEvent = function(id) { dhx_catch[id] = null; }
            return z;
        }
        /**
        *   @desc: removes an event handler
        *   @param: id - event's id
        *   @type: public
        */
        this.detachEvent = function(id) {
            if (id != false) {
                var list = id.split(':'); //get EventName and ID
                this[list[0]].removeEvent(list[1]); //remove event
            }
        }
    }
    this.dhx_Event();
    return this;
};

//v.1.3 build 81009

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/

/*_TOPICS_
@0:Initialization
@1:Selection control
@2:Add/delete
@3:Reserved
@4:Methods of Option object
*/

/**
*  Build combobox from existing select control.
*
*
*  @param   parent      {string} id of existing select control
*  @param   size      {int } size of control, optional
*  @return            {object} combobox object
*  @type   public
*  @topic   0
*
*/

function dhtmlXComboFromSelect(parent,size){
   if (typeof(parent)=="string")
      parent=document.getElementById(parent);


   size=size||parent.getAttribute("width")||(window.getComputedStyle?window.getComputedStyle(parent,null)["width"]:(parent.currentStyle?parent.currentStyle["width"]:0));
   if ((!size)||(size=="auto"))
        size=parent.offsetWidth||100;

   var z=document.createElement("SPAN");

    if(parent.style.direction=="rtl") z.style.direction = "rtl";

   parent.parentNode.insertBefore(z,parent);
   parent.style.display='none';

    var s_type = parent.getAttribute('opt_type');

   var w= new dhtmlXCombo(z,parent.name,size,s_type,parent.tabIndex);

   var x=new Array();
   var sel=0;
   for (var i=0; i<parent.options.length; i++){
      if (parent.options[i].selected) sel=i;
      var label=parent.options[i].innerHTML;
      var val=parent.options[i].getAttribute("value");
      if ((typeof(val)=="undefined")||(val===null)) val=label;
      x[i]={value:val,text:label,img_src:parent.options[i].getAttribute("img_src")};
   }

    w.addOption(x);


   parent.parentNode.removeChild(parent);
   w.selectOption(sel,null,true);
   if (parent.onchange)
        w.attachEvent("onChange",parent.onchange);
   return w;
}

var dhtmlXCombo_optionTypes = [];
/**
*     @desc: build combobox
*     @param: parent - (string) id of existing object which will be used as container
*     @param: name - (string) name of combobox - will be used in FORM
*     @param: width - (int) size of combobox
*     @param: tabIndex - (int) tab index, optional
*     @type: public
*     @topic: 0
*/
function dhtmlXCombo(parent,name,width,optionType,tabIndex){
      if (typeof(parent)=="string")
         parent=document.getElementById(parent);

      this.dhx_Event();
      this.optionType = (optionType != window.undefined && dhtmlXCombo_optionTypes[optionType]) ? optionType : 'default';
      this._optionObject = dhtmlXCombo_optionTypes[this.optionType];

      this._disabled = false;

      if(parent.style.direction == "rtl") this.rtl = true;
      else this.rtl = false;

      if (!window.dhx_glbSelectAr){
          window.dhx_glbSelectAr=new Array();
          window.dhx_openedSelect=null;
          window.dhx_SelectId=1;
          dhtmlxEvent(document.body,"click",this.closeAll);
          dhtmlxEvent(document.body,"keydown",function(e){ try { if ((e||event).keyCode==9)  window.dhx_glbSelectAr[0].closeAll(); } catch(e) {} return true; } );
      }

     if (parent.tagName=="SELECT")
         return dhtmlXComboFromSelect(parent);
      else
         this._createSelf(parent,name,width,tabIndex);
      dhx_glbSelectAr.push(this);
}

/**
*     @desc: change control size
*     @param: new_size - (int) new size value
*     @type: public
*     @topic: 0
*/
   dhtmlXCombo.prototype.setSize = function(new_size){
      this.DOMlist.style.width=new_size+"px";
      if (this.DOMlistF) this.DOMlistF.style.width=new_size+"px";
      this.DOMelem.style.width=new_size+"px";
      this.DOMelem_input.style.width = (new_size-19)+'px';
   }
/**
*     @desc: switch between combobox and auto-filter modes
*     @param: mode - (boolean) enable filtering mode
*     @param: url - (string) url for filtering from XML, optional
*     @param: cache - (boolean) XML caching, optional
*     @param: autosubload - (boolean) enable auto load additional suggestions on selecting last loaded option
*     @type: public
*     @topic: 0
*/
   dhtmlXCombo.prototype.enableFilteringMode = function(mode,url,cache,autosubload){
      this._filter=convertStringToBoolean(mode);

      if (url){
         this._xml=url;
         this._autoxml=convertStringToBoolean(autosubload);
      }
      if (convertStringToBoolean(cache)) this._xmlCache=[];
      //this.DOMelem_button.style.display=(this._filter?"none":"");
   }

   dhtmlXCombo.prototype.setFilteringParam=function(name,value){
        if (!this._prs) this._prs=[];
        this._prs.push([name,value]);
   }
/**
*     @desc: disable combobox
*     @param: mode - (boolean) disable combobox
*     @type: public
*     @topic: 1
*/
   dhtmlXCombo.prototype.disable = function(mode){
      var z=convertStringToBoolean(mode);
      if (this._disabled==z) return;
      this.DOMelem_input.disabled=z;
      this._disabled=z;
   }
/**
*     @desc: switch to readonly mode
*     @param: mode - (boolean) readonly mode
*     @param: autosearch - (boolean) true by default
*     @type: public
*     @topic: 1
*/
   dhtmlXCombo.prototype.readonly = function(mode,autosearch){
        this.DOMelem_input.readOnly=mode ? true : false;
        if(autosearch===false || mode===false){
            this.DOMelem.onkeyup=function(ev){ }
        } else {
            var that = this;
            this.DOMelem.onkeyup=function(ev){
                ev=ev||window.event;
                if (ev.keyCode!=9) ev.cancelBubble=true;
                if((ev.keyCode >= 48 && ev.keyCode <= 57)||(ev.keyCode >= 65 && ev.keyCode <= 90)){
                    for(var i=0; i<that.optionsArr.length; i++){
                        var text = that.optionsArr[i].text;
                        if(text.toString().toUpperCase().indexOf(String.fromCharCode(ev.keyCode)) == 0){
                                that.selectOption(i);
                                break;
                        }
                    }
                    ev.cancelBubble=true;
                }
            }
        }
    }

/**
*     @desc: get Option by value
*     @param: value - (string) value of option in question
*     @type: public
*     @return: option object
*     @topic: 2
*/
   dhtmlXCombo.prototype.getOption = function(value)
   {
      for(var i=0; i<this.optionsArr.length; i++)
         if(this.optionsArr[i].value==value)
            return this.optionsArr[i];
      return null;
   }
/**
*     @desc: get Option by label
*     @param: label - (string) label of option in question
*     @type: public
*     @return: option object
*     @topic: 2
*/
   dhtmlXCombo.prototype.getOptionByLabel = function(value)
   {
      value=value.replace(/&/g,"&amp;")
      for(var i=0; i<this.optionsArr.length; i++)
         if(this.optionsArr[i].text==value)
            return this.optionsArr[i];
      return null;
   }
/**
*     @desc: get Option by index
*     @param: ind - (int) index of option in question
*     @type: public
*     @return: option object
*     @topic: 2
*/
   dhtmlXCombo.prototype.getOptionByIndex = function(ind){
      return this.optionsArr[ind];
   }
/**
*     @desc: clear all options from combobox
*     @type: public
*     @param: value - (bool) clear current value as well
*     @topic: 2
*/
   dhtmlXCombo.prototype.clearAll = function(all)
   {
      if (all) this.setComboText("");
      this.optionsArr=new Array();
      this.redrawOptions();
      if (all) this._confirmSelection();
   }
/**
*     @desc: delete option by value
*     @param: value - (string) value of option in question
*     @type: public
*     @topic: 2
*/
   dhtmlXCombo.prototype.deleteOption = function(value)
   {
        var ind=this.getIndexByValue(value);
      if(ind<0) return;
      if (this.optionsArr[ind]==this._selOption) this._selOption=null;
      this.optionsArr.splice(ind, 1);
      this.redrawOptions();
   }

/**
*     @desc: enable/disable immideatly rendering after changes in combobox
*     @param: mode - (boolean) enable/disable
*     @type: public
*     @topic: 1
*/
   dhtmlXCombo.prototype.render=function(mode){
      this._skiprender=(!convertStringToBoolean(mode));
      this.redrawOptions();
   }

/**
*     @desc: update option in combobox
*     @param: oldvalue - (string) index of option in question
*     @param: avalue - (variable)
*     @type: public
*     @topic: 2
*/
   dhtmlXCombo.prototype.updateOption = function(oldvalue, avalue, atext, acss)
   {
      var dOpt=this.getOption(oldvalue);
      if (typeof(avalue)!="object") avalue={text:atext,value:avalue,css:acss};
      dOpt.setValue(avalue);
        this.redrawOptions();
   }
/**
*     @desc: add new option
*     @param: value - (variable) - different input for different kinds of options - please refer to examples
*     @type: public
*     @topic: 2
*/
   dhtmlXCombo.prototype.addOption = function(options)
   {
      if (!arguments[0].length || typeof(arguments[0])!="object")
         args = [arguments];
      else
         args = options;

      this.render(false);
        for (var i=0; i<args.length; i++) {
            var attr = args[i];
         if (attr.length){
               attr.value = attr[0]||"";
               attr.text = attr[1]||"";
               attr.css = attr[2]||"";
         }
            this._addOption(attr);
        }
      this.render(true);
   }

   dhtmlXCombo.prototype._addOption = function(attr)
   {
         dOpt = new this._optionObject();
         this.optionsArr.push(dOpt);
         dOpt.setValue.apply(dOpt,[attr]);
         this.redrawOptions();
   }


/**
*     @desc: return index of item by value
*     @param: value - (string) value of option in question
*     @type: public
*     @return: option index
*     @topic: 2
*/
   dhtmlXCombo.prototype.getIndexByValue = function(val){
      for(var i=0; i<this.optionsArr.length; i++)
         if(this.optionsArr[i].value == val) return i;
      return -1;
   }

/**
*     @desc: get value of selected item
*     @type: public
*     @return: option value
*     @topic: 2
*/
   dhtmlXCombo.prototype.getSelectedValue = function(){
      return (this._selOption?this._selOption.value:null);
   }
/**
*     @desc: get current text in combobox
*     @type: public
*     @return: combobox text
*     @topic: 2
*/
   dhtmlXCombo.prototype.getComboText = function(){
      return this.DOMelem_input.value;
   }
/**
*     @desc: set text in covmbobox
*     @param: text - (string) new text label
*     @type: public
*     @topic: 2
*/
   dhtmlXCombo.prototype.setComboText = function(text){
      this.DOMelem_input.value=text;
   }

/**
*     @desc: set text in covmbobox
*     @param: text - (string) new text label
*     @type: public
*     @topic: 2
*/
   dhtmlXCombo.prototype.setComboValue = function(text){
      this.setComboText(text);
      for(var i=0; i<this.optionsArr.length; i++)
         if (this.optionsArr[i].data()[0]==text)
         return this.selectOption(i,null,true);
      this.DOMelem_hidden_input.value=text;
   }

/**
*     @desc: get value which will be sent with form
*     @type: public
*     @return: combobox value
*     @topic: 2
*/
   dhtmlXCombo.prototype.getActualValue = function(){
      return this.DOMelem_hidden_input.value;
   }
/**
*     @desc: get text of selected option
*     @type: public
*     @return: text of option
*     @topic: 2
*/
   dhtmlXCombo.prototype.getSelectedText = function(){
      return (this._selOption?this._selOption.text:"");
   }
/**
*     @desc: get index of selected option
*     @type: public
*     @return: option index
*     @topic: 2
*/
   dhtmlXCombo.prototype.getSelectedIndex = function(){
      for(var i=0; i<this.optionsArr.length; i++)
         if(this.optionsArr[i] == this._selOption) return i;
      return -1;
   }
/**
*     @desc: set name used while form submit
*     @param: name - (string) new combobox name
*     @type: public
*     @topic: 2
*/
   dhtmlXCombo.prototype.setName = function(name){
        this.DOMelem_hidden_input.name = name;
        this.DOMelem_hidden_input2 = name+"_new_value";
        this.name = name;
   }
/**
*     @desc: show combox ( reversion to hide command )
*     @param: mode - (boolean) enable/disable
*     @type: public
*     @topic: 1
*/
   dhtmlXCombo.prototype.show = function(mode){
      if (convertStringToBoolean(mode))
         this.DOMelem.style.display = "";
      else
         this.DOMelem.style.display = "none";
   }

/**
*     @desc: destroy object and any related HTML elements
*     @type: public
*     @topic: 0
*/
   dhtmlXCombo.prototype.destructor = function()
   {
      var _sID = this._inID;
      this.DOMParent.removeChild(this.DOMelem);
      this.DOMlist.parentNode.removeChild(this.DOMlist);
      var s=dhx_glbSelectAr;
      this.DOMParent=this.DOMlist=this.DOMelem=0;
      this.DOMlist.combo=this.DOMelem.combo=0;
      for(var i=0; i<s.length; i++)
      {
         if(s[i]._inID == _sID)
         {
            s[i] = null;
            s.splice(i,1);
            return;
         }
      }
   }

/**
*     @desc: create self HTML
*     @type: private
*     @topic: 0
*/
      dhtmlXCombo.prototype._createSelf = function(selParent, name, width, tab)
      {
         if (width.toString().indexOf("%")!=-1){
            var self = this;
            var resWidht=parseInt(width)/100;
            window.setInterval(function(){
               if (!selParent.parentNode) return;
               var ts=selParent.parentNode.offsetWidth*resWidht-2;
               if (ts<0) return;
               if (ts==self._lastTs) return;
               self.setSize(self._lastTs=ts);},500);
            var width=parseInt(selParent.offsetWidth); //mm
         }

         var width=parseInt(width||100); //mm
         this.ListPosition = "Bottom"; //set optionlist positioning
         this.DOMParent = selParent;
         this._inID = null;
         this.name = name;

         this._selOption = null; //selected option object pointer
         this.optionsArr = Array();

            var opt = new this._optionObject();
            opt.DrawHeader(this,name, width,tab);
         //HTML select part 2 - options list DIV element
         this.DOMlist = document.createElement("DIV");
         this.DOMlist.className = 'dhx_combo_list';
         if(this.rtl) this.DOMlist.className = 'dhx_combo_list_rtl'; //rtl
         this.DOMlist.style.width=width-(_isIE?0:0)+"px";
         if (_isOpera || _isKHTML )
                this.DOMlist.style.overflow="auto";
         this.DOMlist.style.display = "none";
         document.body.insertBefore(this.DOMlist,document.body.firstChild);
         if (_isIE)    {
            this.DOMlistF = document.createElement("IFRAME");
            this.DOMlistF.style.border="0px";
            this.DOMlistF.className = 'dhx_combo_list';
            this.DOMlistF.style.width=width-(_isIE?0:0)+"px";
            this.DOMlistF.style.display = "none";
            this.DOMlistF.src="javascript:false;";
            document.body.insertBefore(this.DOMlistF,document.body.firstChild);
            }



         this.DOMlist.combo=this.DOMelem.combo=this;

         this.DOMelem_input.onkeydown = this._onKey;
          this.DOMelem_input.onkeypress = this._onKeyF;
         this.DOMelem_input.onblur = this._onBlur;
         this.DOMelem.onclick = this._toggleSelect;
         this.DOMlist.onclick = this._selectOption;
         this.DOMlist.onmousedown = function(){
            this._skipBlur=true;
         }

         this.DOMlist.onkeydown = function(e){
            this.combo.DOMelem_input.focus();
            (e||event).cancelBubble=true;
            this.combo.DOMelem_input.onkeydown(e)
         }
          this.DOMlist.onmouseover = this._listOver;

      }

      dhtmlXCombo.prototype._listOver = function(e)
      {
         e = e||event;
         e.cancelBubble = true;
         var node = (_isIE?event.srcElement:e.target);
         var that = this.combo;
         if ( node.parentNode == that.DOMlist ) {
            if(that._selOption) that._selOption.deselect();
            if(that._tempSel) that._tempSel.deselect();

            var i=0;
            for (i; i<that.DOMlist.childNodes.length; i++) {
               if (that.DOMlist.childNodes[i]==node) break;
            }
            var z=that.optionsArr[i];
           that._tempSel=z;
           that._tempSel.select();

            if ((that._autoxml)&&((i+1)==that._lastLength))
                that._fetchOptions(i+1,that._lasttext||"");
         }

      }

/**
*     @desc: place option list in necessary place on screen
*     @type: private
*     @topic: 0
*/
      dhtmlXCombo.prototype._positList = function()
      {
        //if(this.ListAutoPosit) this.enableOptionAutoPositioning(true); //mm auto posit
         var pos=this.getPosition(this.DOMelem);
         if(this.ListPosition == 'Bottom'){
            this.DOMlist.style.top = pos[1]+this.DOMelem.offsetHeight+"px";
            this.DOMlist.style.left = pos[0]+"px";
         }
         else if(this.ListPosition == 'Top'){ //mm
                this.DOMlist.style.top = pos[1] - this.DOMlist.offsetHeight+"px";

                this.DOMlist.style.left = pos[0]+"px"; //mm
          }
          else{
            this.DOMlist.style.top = pos[1]+"px";
            this.DOMlist.style.left = pos[0]+this.DOMelem.offsetWidth+"px";
         }

      }

      dhtmlXCombo.prototype.getPosition = function(oNode,pNode){

                  if(!pNode)
                        var pNode = document.body

                  var oCurrentNode=oNode;
                  var iLeft=0;
                  var iTop=0;
                  while ((oCurrentNode)&&(oCurrentNode!=pNode)){//.tagName!="BODY"){
               iLeft+=oCurrentNode.offsetLeft-oCurrentNode.scrollLeft;
               iTop+=oCurrentNode.offsetTop-oCurrentNode.scrollTop;
               oCurrentNode=oCurrentNode.offsetParent;//isIE()?:oCurrentNode.parentNode;
                  }
              if (pNode == document.body ){
                 if (_isIE){
                 if (document.documentElement.scrollTop)
                  iTop+=document.documentElement.scrollTop;
                 if (document.documentElement.scrollLeft)
                  iLeft+=document.documentElement.scrollLeft;
                  }
                  else
                       if (!_isFF){
                             iLeft+=document.body.offsetLeft;
                           iTop+=document.body.offsetTop;
                  }
                 }
                     return new Array(iLeft,iTop);
               }
/**
*     @desc: correct current selection ( move it to first visible option )
*     @type: private
*     @topic: 2
*/
      dhtmlXCombo.prototype._correctSelection = function(){
         if (this.getComboText()!="")
         for (var i=0; i<this.optionsArr.length; i++)
            if (!this.optionsArr[i].isHidden()){
               return this.selectOption(i,true,false);
           }
         this.unSelectOption();
      }
/**
*     @desc: select next option in combobox
*     @param: step - (int) step size
*     @type: private
*     @topic: 2
*/
      dhtmlXCombo.prototype.selectNext = function(step){
         var z=this.getSelectedIndex()+step;
         while (this.optionsArr[z]){
            if (!this.optionsArr[z].isHidden())
               return this.selectOption(z,false,false);
            z+=step;
         }
      }
/**
*     @desc: on keypressed handler
*     @type: private
*     @topic: 0
*/
      dhtmlXCombo.prototype._onKeyF = function(e){
         var that=this.parentNode.combo;
         var ev=e||event;
         ev.cancelBubble=true;
         if (ev.keyCode=="13" || ev.keyCode=="9" ){
            that._confirmSelection();
            that.closeAll();
        } else
        if (ev.keyCode=="27" ){
            that._resetSelection();
            that.closeAll();
        } else that._activeMode=true;
         if (ev.keyCode=="13" || ev.keyCode=="27" ){ //enter
            that.callEvent("onKeyPressed",[ev.keyCode])
            return false;
         }
         return true;
      }
/**
*     @desc: on keyup handler
*     @type: private
*     @topic: 0
*/
      dhtmlXCombo.prototype._onKey = function(e){
         var that=this.parentNode.combo;
         (e||event).cancelBubble=true;
         var ev=(e||event).keyCode;
         if (ev>15 && ev<19) return true; //shift,alt,ctrl
        if (ev==27) return;
        if ((that.DOMlist.style.display!="block")&&(ev!="13")&&(ev!="9")&&((!that._filter)||(that._filterAny)))
            that.DOMelem.onclick(e||event);

        if ((ev!="13")&&(ev!="9")){
            window.setTimeout(function(){ that._onKeyB(ev); },1);
            if (ev=="40" || ev=="38")
                return false;
        }
         else if (ev==9){
            that.closeAll();
            (e||event).cancelBubble=false;
         }
      }
      dhtmlXCombo.prototype._onKeyB = function(ev)
      {
         if (ev=="40"){  //down
            var z=this.selectNext(1);
         } else if (ev=="38"){ //up
            this.selectNext(-1);
         } else{
            this.callEvent("onKeyPressed",[ev])
            if (this._filter) return this.filterSelf((ev==8)||(ev==46));
            for(var i=0; i<this.optionsArr.length; i++)
               if (this.optionsArr[i].data()[1]==this.DOMelem_input.value){
//                  ev.cancelBubble=true;
                  this.selectOption(i,false,false);
                  return false;
                  }
            this.unSelectOption();
         }
         return true;
      }


/**
*     @desc: on data change handler
*     @type: private
*     @topic: 0
*/
      dhtmlXCombo.prototype._onBlur = function()
      {
          var self = this.parentNode._self;
          window.setTimeout(function(){
            if (self.DOMlist._skipBlur) return !(self.DOMlist._skipBlur=false);
            self._confirmSelection();
            self.callEvent("onBlur",[]);
          },100)

      }
/**
*     @desc: redraw combobox options
*     @type: private
*     @topic: 2
*/
      dhtmlXCombo.prototype.redrawOptions = function(){
         if (this._skiprender) return;
         for(var i=this.DOMlist.childNodes.length-1; i>=0; i--)
            this.DOMlist.removeChild(this.DOMlist.childNodes[i]);
         for(var i=0; i<this.optionsArr.length; i++)
            this.DOMlist.appendChild(this.optionsArr[i].render());





      }
/**
*     @desc: load list of options from XML
*     @param: url - (string) xml url
*     @type: public
*     @topic: 0
*/
      dhtmlXCombo.prototype.loadXML = function(url,afterCall){
         this._load=true;
         if ((this._xmlCache)&&(this._xmlCache[url])){
            this._fillFromXML(this,null,null,null,this._xmlCache[url]);
            if (afterCall) afterCall();
        }
         else{
            var xml=(new dtmlXMLLoaderObject(this._fillFromXML,this,true,true));
            if (afterCall) xml.waitCall=afterCall;
            if (this._prs)
                for (var i=0; i<this._prs.length; i++)
                    url+=[getUrlSymbol(url),escape(this._prs[i][0]),"=",escape(this._prs[i][1])].join("");
            xml._cPath=url;
            xml.loadXML(url);
         }
      }

/**
*     @desc: load list of options from XML string
*     @param: astring - (string) xml string
*     @type: public
*     @topic: 0
*/
      dhtmlXCombo.prototype.loadXMLString = function(astring){
         var xml=(new dtmlXMLLoaderObject(this._fillFromXML,this,true,true));
         xml.loadXMLString(astring);
      }

/**
*     @desc: on XML load handler
*     @type: private
*     @topic: 0
*/
      dhtmlXCombo.prototype._fillFromXML = function(obj,b,c,d,xml){
         if (obj._xmlCache) obj._xmlCache[xml._cPath]=xml;

         //check that XML is correct
         var toptag=xml.getXMLTopNode("complete");
         if (toptag.tagName!="complete") return;
         var top=xml.doXPath("//complete");
         var options=xml.doXPath("//option");

         obj.render(false);
         if ((!top[0])||(!top[0].getAttribute("add"))){
            obj.clearAll();
            obj._lastLength=options.length;
             if (obj._xml){
             if ((!options) || (!options.length))
                obj.closeAll();
             else {
                    if (obj._activeMode){
                        obj._positList();
                        obj.DOMlist.style.display="block";
                        if (_isIE) obj._IEFix(true);
                    }
             }}
         } else
            obj._lastLength+=options.length;

         for (var i=0; i<options.length; i++) {
            var attr = new Object();
            attr.text = options[i].firstChild?options[i].firstChild.nodeValue:"";
            for (var j=0; j<options[i].attributes.length; j++) {
               var a = options[i].attributes[j];
               if (a)
                  attr[a.nodeName] = a.nodeValue;
            }
            obj._addOption(attr);
         }
         obj.render(true);

         if ((obj._load)&&(obj._load!==true))
            obj.loadXML(obj._load);
         else{
            obj._load=false;
             if ((!obj._lkmode)&&(!obj._filter))
               obj._correctSelection();
            }

         var selected=xml.doXPath("//option[@selected]");
         if (selected.length)
            obj.selectOption(obj.getIndexByValue(selected[0].getAttribute("value")),false,true);

      }
/**
*     @desc: deselect option
*     @type: public
*     @topic: 1
*/
      dhtmlXCombo.prototype.unSelectOption = function(){
         if (this._selOption)
            this._selOption.deselect();
         this._selOption=null;
      }

      dhtmlXCombo.prototype._confirmSelection = function(data,status){
        if(arguments.length==0){
            var z=this.getOptionByLabel(this.DOMelem_input.value);
            data = z?z.value:this.DOMelem_input.value;
            status = (z==null);
            if (data==this.getActualValue()) return;
        }

        this.DOMelem_hidden_input.value=data;
        this.DOMelem_hidden_input2.value = (status?"true":"false");
        this.callEvent("onChange",[]);
        this._activeMode=false;
      }
      dhtmlXCombo.prototype._resetSelection = function(data,status){
            var z=this.getOption(this.DOMelem_hidden_input.value);
            this.setComboValue(z?z.data()[0]:this.DOMelem_hidden_input.value)
            this.setComboText(z?z.data()[1]:this.DOMelem_hidden_input.value)
      }

/**
*     @desc: select option
*     @param: ind - (int) index of option in question
*     @param: filter - (boolean) enable autocomplit range, optional
*     @param: conf - (boolean) true for real selection, false for pre-selection
*     @type: public
*     @topic: 1
*/
      dhtmlXCombo.prototype.selectOption = function(ind,filter,conf){
         if (arguments.length<3) conf=true;
         this.unSelectOption();
         var z=this.optionsArr[ind];
         if (!z)  return;
         this._selOption=z;
         this._selOption.select();

         var corr=this._selOption.content.offsetTop+this._selOption.content.offsetHeight-this.DOMlist.scrollTop-this.DOMlist.offsetHeight;
         if (corr>0) this.DOMlist.scrollTop+=corr;
            corr=this.DOMlist.scrollTop-this._selOption.content.offsetTop;
         if (corr>0) this.DOMlist.scrollTop-=corr;

         var data=this._selOption.data();

         if (conf){
            this.setComboText(data[1]);
            this._confirmSelection(data[0],false);
         }

         if ((this._autoxml)&&((ind+1)==this._lastLength))
            this._fetchOptions(ind+1,this._lasttext||"");

         if (filter){
            var text=this.getComboText();
            if (text!=data[1]){
               this.setComboText(data[1]);
               dhtmlXRange(this.DOMelem_input,text.length+1,data[1].length);
            }
         }
         else
            this.setComboText(data[1]);
         this._selOption.RedrawHeader(this);

         /*Event*/
         this.callEvent("onSelectionChange",[]);
      }
/**
*     @desc: option on select handler
*     @type: private
*     @topic: 2
*/
      dhtmlXCombo.prototype._selectOption = function(e)
      {
         (e||event).cancelBubble = true;
         var node=(_isIE?event.srcElement:e.target);
         var that=this.combo;
         while (!node._self) {
            node = node.parentNode;
            if (!node)
               return;
         }

         var i=0;
         for (i; i<that.DOMlist.childNodes.length; i++) {
            if (that.DOMlist.childNodes[i]==node) break;
         }
         that.selectOption(i,false,true);
         that.closeAll();
         that.callEvent("onBlur",[])
         that._activeMode=false;
      }
/**
*     @desc: open list of options
*     @type: public
*     @topic: 2
*/
   dhtmlXCombo.prototype.openSelect = function(){



      if (this._disabled) return;
      this.closeAll();
      this._positList();
      this.DOMlist.style.display="block";
      this.callEvent("onOpen",[]);
      if(this._tempSel) this._tempSel.deselect();
      if(this._selOption) this._selOption.select();
      if(this._selOption){
        var corr=this._selOption.content.offsetTop+this._selOption.content.offsetHeight-this.DOMlist.scrollTop-this.DOMlist.offsetHeight;
         if (corr>0) this.DOMlist.scrollTop+=corr;
            corr=this.DOMlist.scrollTop-this._selOption.content.offsetTop;
         if (corr>0) this.DOMlist.scrollTop-=corr;
    }
      /* if (this.autoOptionSize){
            var x=this.DOMlist.offsetWidth;

            for ( var i=0; i<this.optionsArr.length; i++){
                if(i==0) alert("this.DOMlist.childNodes[i].scrollWidth ="+ this.DOMlist.childNodes[i].scrollWidth + "> x= "+ x);
                if (this.DOMlist.childNodes[i].scrollWidth > x)
                    x=this.DOMlist.childNodes[i].scrollWidth;
            }

            this.DOMlist.style.width=x+"px";
        }*/


      if (_isIE) this._IEFix(true);
      this.DOMelem_input.focus();

      if (this._filter) this.filterSelf();
   }
/**
*     @desc: open(close) list
*     @type: private
*     @topic: 2
*/
   dhtmlXCombo.prototype._toggleSelect = function(e)
   {
      var that=this.combo;
      if ( that.DOMlist.style.display == "block" ) {
      that.closeAll();
      } else {
         that.openSelect();
      }
      (e||event).cancelBubble = true;
   }

    dhtmlXCombo.prototype._fetchOptions=function(ind,text){
          if (text=="") { this.closeAll();  return this.clearAll();   }
         var url=this._xml+((this._xml.indexOf("?")!=-1)?"&":"?")+"pos="+ind+"&mask="+encodeURIComponent(text);
         this._lasttext=text;
         if (this._load) this._load=url;
         else this.loadXML(url);
    }
/**
*     @desc: filter list of options
*     @type: private
*     @topic: 2
*/
    dhtmlXCombo.prototype.filterSelf = function(mode)
   {
      var text=this.getComboText();
      if (this._xml){
         this._lkmode=mode;
         this._fetchOptions(0,text);
      }
      try{ var filter=new RegExp("^"+text,"i"); } catch (e){ var filter=new RegExp("^"+text.replace(/([\[\]\{\}\(\)\+\*\\])/g,"\\$1")); }
      this.filterAny=false;
      for(var i=0; i<this.optionsArr.length; i++){
         var z=filter.test(this.optionsArr[i].text);
         this.filterAny|=z;
         this.optionsArr[i].hide(!z);
      }
      if (!this.filterAny) {
          this.closeAll();
          this._activeMode=true;
      }
      else {
          if (this.DOMlist.style.display!="block")
                this.openSelect();
          if (_isIE) this._IEFix(true);
        }

        if (!mode)
         this._correctSelection();
        else this.unSelectOption();
   }




/**
*     @desc: set hidden iframe for IE
*     @type: private
*     @topic: 2
*/
   dhtmlXCombo.prototype._IEFix = function(mode){
      this.DOMlistF.style.display=(mode?"block":"none");
        this.DOMlistF.style.top=this.DOMlist.style.top;
        this.DOMlistF.style.left=this.DOMlist.style.left;
   }
/**
*     @desc: close opened combobox list
*     @type: public
*     @topic: 1
*/
   dhtmlXCombo.prototype.closeAll = function()
   {
      if(window.dhx_glbSelectAr)
         for (var i=0; i<dhx_glbSelectAr.length; i++){
            if (dhx_glbSelectAr[i].DOMlist.style.display=="block") {
               dhx_glbSelectAr[i].DOMlist.style.display = "none";
               if (_isIE) dhx_glbSelectAr[i]._IEFix(false);
            }
            dhx_glbSelectAr[i]._activeMode=false;
        }
   }
/**
*     @desc: create selection range in input control
*     @param: InputId - (string) id of input ( object can be used as well )
*     @param: Start - (int) start selection position
*     @param: End - (int) end selection position
*     @type: public
*     @topic: 0
*/
function dhtmlXRange(InputId, Start, End)
{
   var Input = typeof(InputId)=='object' ? InputId : document.getElementById(InputId);
   try{    Input.focus();   } catch(e){};
   var Length = Input.value.length;
   Start--;
   if (Start < 0 || Start > End || Start > Length)
      Start = 0;
   if (End > Length)
      End = Length;
   if (Start==End) return;
   if (Input.setSelectionRange) {
      Input.setSelectionRange(Start, End);
   } else if (Input.createTextRange) {
      var range = Input.createTextRange();
      range.moveStart('character', Start);
      range.moveEnd('character', End-Length);
      range.select();
   }
}
/**
*     @desc: combobox option object constructor
*     @type: public
*     @topic: 0
*/
      dhtmlXCombo_defaultOption = function(){
         this.init();
      }
/**
*     @desc: option initialization function
*     @type: private
*     @topic: 4
*/
      dhtmlXCombo_defaultOption.prototype.init = function(){
         this.value = null;
         this.text = "";
         this.selected = false;
         this.css = "";
      }
/**
*     @desc: mark option as selected
*     @type: public
*     @topic: 4
*/
      dhtmlXCombo_defaultOption.prototype.select = function(){
         if (this.content)
            this.content.className="dhx_selected_option";
      }
/**
*     @desc: hide option
*     @param: mode - (boolean)
*     @type: public
*     @topic: 4
*/
      dhtmlXCombo_defaultOption.prototype.hide = function(mode){
         this.render().style.display=mode?"none":"";
      }
/**
*     @desc: return hide state of option
*     @type: public
*     @return: hide state of option
*     @topic: 4
*/
      dhtmlXCombo_defaultOption.prototype.isHidden = function(){
         return (this.render().style.display=="none");
      }
/**
*     @desc: mark option as not selected
*     @type: public
*     @topic: 4
*/
      dhtmlXCombo_defaultOption.prototype.deselect = function(){
         if (this.content) this.render();
            this.content.className="";
      }
/**
*     @desc: set value of option
*     @param: value - (string) value
*     @param: text - (string) text
*     @param: css - (string) css style string
*     @type: public
*     @topic: 4
*/
dhtmlXCombo_defaultOption.prototype.setValue = function(attr){
    this.value = attr.value||"";
    this.text = attr.text||"";
    this.css = attr.css||"";
   this.content=null;
}


/**
*     @desc: render option
*     @type: private
*     @topic: 4
*/
      dhtmlXCombo_defaultOption.prototype.render = function(){
         if (!this.content){
            this.content=document.createElement("DIV");
        this.content._self = this;

            this.content.style.cssText='width:100%; overflow:hidden;'+this.css;
            if (_isOpera || _isKHTML ) this.content.style.padding="2px 0px 2px 0px";
            this.content.innerHTML=this.text;
            this._ctext=_isIE?this.content.innerText:this.content.textContent;
         }
         return this.content;
      }
/**
*     @desc: return option data
*     @type: public
*     @return: array of data related to option
*     @topic: 4
*/
      dhtmlXCombo_defaultOption.prototype.data = function(){
         if (this.content)
            return [this.value,this._ctext ? this._ctext : this.text];
      }

dhtmlXCombo_defaultOption.prototype.DrawHeader = function(self, name, width, tab)
{
    var z=document.createElement("DIV");
    z.style.width = width+"px";
    z.className = 'dhx_combo_box';
    z._self = self;
    self.DOMelem = z;
    this._DrawHeaderInput(self, name, width,tab);
    this._DrawHeaderButton(self, name, width);
    self.DOMParent.appendChild(self.DOMelem);
}

dhtmlXCombo_defaultOption.prototype._DrawHeaderInput = function(self, name, width,tab)
{

    if(self.rtl && _isIE)  {
        var z=document.createElement('textarea');
        z.style.overflow = "hidden";
        z.style.whiteSpace="nowrap"
    }
    else {
        var z=document.createElement('input');
        z.setAttribute("autocomplete","off");
        z.type = 'text';
    }
    //heresyrt_combo
    z.className = 'dhx_combo_input_new';
    //z.className = 'dhx_combo_input';

   if(self.rtl) {
    z.style.left = "18px";
    z.style.direction = "rtl";
    z.style.unicodeBidi = "bidi-override";
   }


   if (tab) z.tabIndex=tab;
   z.style.width = (width-19)+'px';
   self.DOMelem.appendChild(z);
   self.DOMelem_input = z;

   z = document.createElement('input');
   z.type = 'hidden';
   z.name = name;
   self.DOMelem.appendChild(z);
   self.DOMelem_hidden_input = z;

   z = document.createElement('input');
   z.type = 'hidden';
   z.name = name+"_new_value";
   z.value="true";
   self.DOMelem.appendChild(z);
   self.DOMelem_hidden_input2 = z;
}

dhtmlXCombo_defaultOption.prototype._DrawHeaderButton = function(self, name, width)
{
   var z=document.createElement('img');
   z.className = (self.rtl)?'dhx_combo_img_rtl':'dhx_combo_img';

   //heresyrt_combo
   z.src = (window.dhx_globalImgPath?dhx_globalImgPath:"")+'combo_select_new.gif';
   //z.src = (window.dhx_globalImgPath?dhx_globalImgPath:"")+'combo_select.gif';
   self.DOMelem.appendChild(z);
   self.DOMelem_button=z;
}

dhtmlXCombo_defaultOption.prototype.RedrawHeader = function(self)
{
}


dhtmlXCombo_optionTypes['default'] = dhtmlXCombo_defaultOption;

dhtmlXCombo.prototype.dhx_Event=function()
{
   this.dhx_SeverCatcherPath="";

   this.attachEvent = function(original, catcher, CallObj)
   {
      CallObj = CallObj||this;
      original = 'ev_'+original;
       if ( ( !this[original] ) || ( !this[original].addEvent ) ) {
           var z = new this.eventCatcher(CallObj);
           z.addEvent( this[original] );
           this[original] = z;
       }
       return ( original + ':' + this[original].addEvent(catcher) );   //return ID (event name & event ID)
   }
   this.callEvent=function(name,arg0){
         if (this["ev_"+name]) return this["ev_"+name].apply(this,arg0);
       return true;
   }
   this.checkEvent=function(name){
         if (this["ev_"+name]) return true;
       return false;
   }

   this.eventCatcher = function(obj)
   {
       var dhx_catch = new Array();
       var m_obj = obj;
       var func_server = function(catcher,rpc)
                         {
                           catcher = catcher.split(":");
                     var postVar="";
                     var postVar2="";
                           var target=catcher[1];
                     if (catcher[1]=="rpc"){
                           postVar='<?xml version="1.0"?><methodCall><methodName>'+catcher[2]+'</methodName><params>';
                        postVar2="</params></methodCall>";
                        target=rpc;
                     }
                           var z = function() {
                                   }
                           return z;
                         }
       var z = function()
             {
                   if (dhx_catch)
                      var res=true;
                   for (var i=0; i<dhx_catch.length; i++) {
                      if (dhx_catch[i] != null) {
                           var zr = dhx_catch[i].apply( m_obj, arguments );
                           res = res && zr;
                      }
                   }
                   return res;
                }
       z.addEvent = function(ev)
                {
                       if ( typeof(ev) != "function" )
                           if (ev && ev.indexOf && ev.indexOf("server:") == 0)
                               ev = new func_server(ev,m_obj.rpcServer);
                           else
                               ev = eval(ev);
                       if (ev)
                           return dhx_catch.push( ev ) - 1;
                       return false;
                }
       z.removeEvent = function(id)
                   {
                     dhx_catch[id] = null;
                   }
       return z;
   }

   this.detachEvent = function(id)
   {
      if (id != false) {
         var list = id.split(':');            //get EventName and ID
         this[ list[0] ].removeEvent( list[1] );   //remove event
      }
   }
}

//v.1.3 build 81009

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/**
*     @desc: enables or disables options auto positioning
*     @param: flag - (boolean) true/false
*     @type: public
*/
dhtmlXCombo.prototype.enableOptionAutoPositioning = function(fl){
    if(!this.ListAutoPosit) this.ListAutoPosit = 1;
    this.attachEvent("onOpen",function(){this._setOptionAutoPositioning(fl);})
}

/**
*     @desc: set options auto positioning mode enables/disables
*     @param: flag - (boolean) true/false
*     @type: private
*/
dhtmlXCombo.prototype._setOptionAutoPositioning = function(fl){

    if((typeof(fl)!="undefined")&&(!convertStringToBoolean(fl))){
        this.ListPosition = "Bottom";
        this.ListAutoPosit = 0;
        return true
    }

    var pos = this.getPosition(this.DOMelem);
    var bottom = this._getClientHeight() - pos[1] - this.DOMelem.offsetHeight;
    var height = (this.autoHeight)?(this.DOMlist.scrollHeight):parseInt(this.DOMlist.offsetHeight);

    if((bottom < height)&&(pos[1] > height)){
        this.ListPosition = "Top";
    }
    else this.ListPosition = "Bottom";
    this._positList();
}

/**
*     @desc: gets client height
*     @return: client height
*     @type: private
*/
dhtmlXCombo.prototype._getClientHeight = function(){
    return ((document.compatMode=='CSS1Compat') &&(!window.opera))?document.documentElement.clientHeight:document.body.clientHeight;
}

/**
*     @desc: set width of combo list
*     @param: width - (number) width
*     @type: public
*/

dhtmlXCombo.prototype.setOptionWidth = function(width){
    if(arguments.length > 0){
        this.DOMlist.style.width = width+"px";
        if (this.DOMlistF) this.DOMlistF.style.width = width+"px";
    }
}

/**
*     @desc: set height of combo list
*     @param: height - (number) height
*     @type: public
*/

dhtmlXCombo.prototype.setOptionHeight = function(height){

    if(arguments.length>0){
        if(_isIE)
            this.DOMlist.style.height = this.DOMlistF.style.height =  height+"px";
        else
            this.DOMlist.style.height = height+"px";
        this._positList();
    }

}

/**
*     @desc: enables or disables options auto width
*     @param: flag - (boolean) true/false
*     @type: public
*/
dhtmlXCombo.prototype.enableOptionAutoWidth = function(fl){
    if(!this._listWidthConf) this._listWidthConf = parseInt(this.DOMlist.style.width);
    if(arguments.length == 0){ var fl = 1; }
    if(convertStringToBoolean(fl)) {
        this.autoOptionWidth = 1;
        awOnOpen = this.attachEvent("onOpen",function(){this._setOptionAutoWidth()});
    }
    else {
        if(typeof(awOnOpen)!= "undefined"){
            this.autoOptionWidth = 0;
            this.detachEvent(awOnOpen);
            this.setOptionWidth(this._listWidthConf);
        }
    }
}

/**
*     @desc: set options auto width
*     @param: flag - (boolean) true/false
*     @type: private
*/
dhtmlXCombo.prototype._setOptionAutoWidth = function(){
    this.setOptionWidth(1);
    var x = this.DOMlist.offsetWidth;
    for ( var i=0; i<this.optionsArr.length; i++){
        var optWidth = (_isFF)?(this.DOMlist.childNodes[i].scrollWidth - 2):this.DOMlist.childNodes[i].scrollWidth;
        if (optWidth > x){
            x = this.DOMlist.childNodes[i].scrollWidth;
        }
    }
    this.setOptionWidth(x);
}

/**
*     @desc: enables or disables list auto height
*     @param: flag - (boolean) true/false
*     @param: maxHeight - (int) height limitation (if a list height is bigger than maxHeight, a vertical scroll appears)
*     @type: public
*/
dhtmlXCombo.prototype.enableOptionAutoHeight = function(fl,maxHeight){
    if(!this._listHeightConf) this._listHeightConf = (this.DOMlist.style.height=="")?100:parseInt(this.DOMlist.style.height);
    if(arguments.length==0) var fl = 1;
    this.autoHeight = convertStringToBoolean(fl);
    if(this.autoHeight){
        ahOnOpen = this.attachEvent("onOpen",function(){
            this._setOptionAutoHeight(fl,maxHeight);
            if(_isIE) this._setOptionAutoHeight(fl,maxHeight);
        })
    }
    else {
        if(typeof(ahOnOpen)!= "undefined"){
            this.detachEvent(ahOnOpen);
            this.setOptionHeight(this._listHeightConf);
        }
    }

}

/**
*     @desc: set auto height
*     @param: flag - (boolean) true/false
*     @param: maxHeight - (int) height limitation (if a list height is bigger than maxHeight, a vertical scroll appears)
*     @type: private
*/
dhtmlXCombo.prototype._setOptionAutoHeight = function(fl,maxHeight){
    if(convertStringToBoolean(fl)){
        this.setOptionHeight(1);
        var height = 0;
        if (this.optionsArr.length > 0){
            if(this.DOMlist.scrollHeight > this.DOMlist.offsetHeight){
                height= this.DOMlist.scrollHeight + 2;
            }
            else height= this.DOMlist.offsetHeight;
            if((arguments.length > 1)&&(maxHeight)){
                var maxHeight = parseInt(maxHeight);
                height = (height>maxHeight)?maxHeight:height;
            }
            this.setOptionHeight(height)
        }
    }
}

//v.1.3 build 81009

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/

dhtmlXCombo_imageOption = function(){
    this.init();
}
dhtmlXCombo_imageOption.prototype = new dhtmlXCombo_defaultOption;

dhtmlXCombo_imageOption.prototype.setValue = function(attr){
    this.value = attr.value||"";
    this.text = attr.text||"";
    this.css = attr.css||"";
    this.img_src = attr.img_src||this.getDefImage();
}
dhtmlXCombo_imageOption.prototype.render = function(){
    if (!this.content) {
        this.content=document.createElement("DIV");
        this.content._self = this;
        this.content.style.cssText='width:100%; overflow:hidden; '+this.css;
        var html = '';
        if (this.img_src != '')
            html += '<img style="float:left;" src="'+this.img_src+'" />';
        html += '<div style="float:left">'+this.text+'</div>';
        this.content.innerHTML=html;
//        this.content.firstChild.onclick = function(e) {(e||event).cancelBubble=true;}
    }
    return this.content;
}
dhtmlXCombo_imageOption.prototype.data = function(){
    return [this.value,this.text,this.img_src];
}


dhtmlXCombo_imageOption.prototype.DrawHeader = function(self, name, width)
{
    var z=document.createElement("DIV");
    z.style.width = width+"px";
    //heresyrt_combo
    //z.className = 'dhx_combo_box';
    z.className = 'dhx_combo_box_new';
    z._self = self;
    self.DOMelem = z;
    this._DrawHeaderImage(self, name, width);
    this._DrawHeaderInput(self, name, width-23);
    this._DrawHeaderButton(self, name, width);
    self.DOMParent.appendChild(self.DOMelem);
}

dhtmlXCombo_imageOption.prototype._DrawHeaderImage = function(self, name, width)
{
    var z= document.createElement('img');
    //z.src='';

       z.className = (self.rtl)? 'dhx_combo_option_img_rtl':'dhx_combo_option_img';
    z.style.visibility = 'hidden';
    self.DOMelem.appendChild(z);
    self.DOMelem_image=z;
}

dhtmlXCombo_imageOption.prototype.RedrawHeader = function(self)
{
    self.DOMelem_image.style.visibility = 'visible';
    self.DOMelem_image.src = this.img_src;
}

dhtmlXCombo_imageOption.prototype.getDefImage = function(self){ return ""; }

/**
    @descr: set default image for image based options
    @param: url - url of default image
    @type: public
*/
dhtmlXCombo.prototype.setDefaultImage=function(url){
    dhtmlXCombo_imageOption.prototype.getDefImage=function(){
        return url;
    }
}


dhtmlXCombo_optionTypes['image'] = dhtmlXCombo_imageOption;

/*
    CHECKBOX OPTION
*/
dhtmlXCombo_checkboxOption = function(){
    this.init();
}
dhtmlXCombo_checkboxOption.prototype = new dhtmlXCombo_defaultOption;

dhtmlXCombo_checkboxOption.prototype.setValue = function(attr){
    this.value = attr.value||"";
    this.text = attr.text||"";
    this.css = attr.css||"";
    this.checked = attr.checked||0; //set checkbox state
}
dhtmlXCombo_checkboxOption.prototype.render = function(){
    if (!this.content) {
        this.content=document.createElement("DIV");
        this.content._self = this;
        this.content.style.cssText='width:100%; overflow:hidden; '+this.css;
        var html = '';
        if(this.checked)  //set checkbox state
            html += '<input style="float:left;" type="checkbox" checked   />';
        else html += '<input style="float:left;" type="checkbox" />';
        html += '<div style="float:left">'+this.text+'</div>';
        this.content.innerHTML=html;
        this.content.firstChild.onclick = function(e) {(e||event).cancelBubble=true; this.parentNode.parentNode.combo.DOMelem_input.focus();  }
    }
    return this.content;
}
dhtmlXCombo_checkboxOption.prototype.data = function(){
    return [this.value,this.text,this.render().firstChild.checked];
}


dhtmlXCombo_checkboxOption.prototype.DrawHeader = function(self, name, width)
{
    self.DOMelem = document.createElement("DIV");
    self.DOMelem.style.width = width+"px";
    self.DOMelem.className = 'dhx_combo_box';
    self.DOMelem._self = self;
    this._DrawHeaderCheckbox(self, name, width);
    this._DrawHeaderInput(self, name, width-18);
    this._DrawHeaderButton(self, name, width);
    self.DOMParent.appendChild(self.DOMelem);
}

dhtmlXCombo_checkboxOption.prototype._DrawHeaderCheckbox = function(self, name, width)
{
    var z= document.createElement('input');
    z.type='checkbox';
    z.className = (self.rtl)? 'dhx_combo_option_img_rtl':'dhx_combo_option_img';
    z.style.visibility = 'hidden';
    z.onclick = function(e) {(e||event).cancelBubble=true;}
    self.DOMelem.appendChild(z);
    self.DOMelem_checkbox = z;
}

dhtmlXCombo_checkboxOption.prototype.RedrawHeader = function(self)
{
    self.DOMelem_checkbox.style.visibility = '';
    self.DOMelem_checkbox.checked = this.content.firstChild.checked;
}


dhtmlXCombo_optionTypes['checkbox'] = dhtmlXCombo_checkboxOption;

/**
*     @desc: gets list of checked options values
*     @return:  list of checked option values separated by commas
*     @type: public
*/
dhtmlXCombo.prototype.getChecked=function(){
      var res=[];
      for(var i=0; i<this.optionsArr.length; i++)
         if(this.optionsArr[i].data()[2])
            res.push(this.optionsArr[i].value)
      return res;
}

/**
*     @desc: sets option checked
*     @param: index - option index
*     @type: public
*/
dhtmlXCombo.prototype.setChecked=function(index){
    this.optionsArr[index].content.firstChild.checked=true;
}

//v.1.3 build 81009

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
dhtmlXCombo.prototype.attachChildCombo = function(_chcombo,xml){
    if(!this._child_combos){
        this._child_combos = [];
    }

    this._has_childen = 1;

    this._child_combos[this._child_combos.length] = _chcombo;

    _chcombo.show(0);

    var that = this;
    var _arg_length = arguments.length;

    this.attachEvent("onChange",function(){
        for(var i = 0; i < that._child_combos.length; i++){

            if(that._child_combos[i]==_chcombo){
                _chcombo.show(1);
                _chcombo.callEvent("onMasterChange",[that.getActualValue(),that]);
            }

        }

        if(that.getActualValue()=="") {
            that.showSubCombo(that,0);
            return;
        }

            if(_chcombo._xml){
                if(_arg_length ==1) xml = _chcombo._xml;
                _chcombo._xml = that.deleteParentVariable(xml)+((_chcombo._xml.indexOf("?")!=-1)?"&":"?")+"parent="+that.getActualValue();
            }
            else{
                if(xml){
                    _chcombo.clearAll(true);
                    xml = that.deleteParentVariable(xml) +((xml.indexOf("?")!=-1)?"&":"?")+"parent="+that.getActualValue();
                    _chcombo.loadXML(xml);
                }

            }
    })
}

dhtmlXCombo.prototype.setAutoSubCombo = function(xml,name){
    if(arguments.length == 1) name = "subcombo";
    if(!this._parentCombo){
        var z = new dhtmlXCombo(this.DOMParent,name,this.DOMelem.style.width)
        z._parentCombo  = this;
    }
    else {
        var z = new dhtmlXCombo(this._parentCombo.DOMParent,name,this._parentCombo.DOMelem.style.width)
        z._parentCombo = this._parentCombo;
    }
    if(this._filter) z._filter = 1;
    if(this._xml){
        if(arguments.length > 0)
            z._xml = xml;
        else
            z._xml = this._xml;
        xml = z._xml;
        z._autoxml = this._autoxml;
        if(this._xmlCache) z._xmlCache=[];
     }

    this.attachChildCombo(z,xml)
    return z;
}

dhtmlXCombo.prototype.detachChildCombo = function(_chcombo){
    for(var i = 0; i < this._child_combos.length; i++){
        this._child_combos[i] == _chcombo;
        this._child_combos.splice(i,1);
    }
    _chcombo.show(1);
}

dhtmlXCombo.prototype.showSubCombo = function(combo,state){
    if(combo._child_combos){
        for(var i = 0; i < combo._child_combos.length; i++){
            combo._child_combos[i].show(state);
            combo.showSubCombo(combo._child_combos[i],0);
        }
    }
}

dhtmlXCombo.prototype.deleteParentVariable = function(str){
    str = str.replace(/parent\=[^&]*/g,"").replace(/\?\&/,"?");
    return str;
}


//(c)dhtmlx ltd. www.dhtmlx.com
//v.2.0 build 81107

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/*_TOPICS_
@0:Initialization
@1:Selection control
@2:Add/delete
@3:Private
@4:Node/level control
@5:Checkboxes/user data manipulation
@6:Appearence control
@7: Handlers
*/

function xmlPointer(data){
    this.d=data;
}
xmlPointer.prototype={
    text:function(){ if (!_isFF) return this.d.xml; var x = new XMLSerializer();   return x.serializeToString(this.d); },
    get:function(name){return this.d.getAttribute(name); },
    exists:function(){return !!this.d },
    content:function(){return this.d.firstChild?this.d.firstChild.data:""; }, // <4k in FF
    each:function(name,f,t,i){  var a=this.d.childNodes; var c=new xmlPointer(); if (a.length) for (i=i||0; i<a.length; i++) if (a[i].tagName==name) { c.d=a[i]; if(f.apply(t,[c,i])==-1) return; } },
    get_all:function(){ var a={}; var b=this.d.attributes; for (var i=0; i<b.length; i++) a[b[i].name]=b[i].value; return a; },
    sub:function(name){ var a=this.d.childNodes; var c=new xmlPointer(); if (a.length) for (var i=0; i<a.length; i++) if (a[i].tagName==name) { c.d=a[i]; return c; } },
    up:function(name){ return new xmlPointer(this.d.parentNode);  },
    set:function(name,val){ this.d.setAttribute(name,val);  },
    clone:function(name){ return new xmlPointer(this.d); },
    sub_exists:function(name){ var a=this.d.childNodes; if (a.length) for (var i=0; i<a.length; i++) if (a[i].tagName==name) return true;  return false;  },
    through:function(name,rule,v,f,t){  var a=this.d.childNodes; if (a.length) for (var i=0; i<a.length; i++) { if (a[i].tagName==name && a[i].getAttribute(rule)!=null && a[i].getAttribute(rule)!="" &&  (!v || a[i].getAttribute(rule)==v )) { var c=new xmlPointer(a[i]);  f.apply(t,[c,i]); } var w=this.d; this.d=a[i]; this.through(name,rule,v,f,t); this.d=w;  } }
}



/**
*     @desc: tree constructor
*     @param: htmlObject - parent html object or id of parent html object
*     @param: width - tree width
*     @param: height - tree height
*     @param: rootId - id of virtual root node (same as tree node id attribute in xml)
*     @type: public
*     @topic: 0
*/
function dhtmlXTreeObject(htmlObject, width, height, rootId){
    if (_isIE) try { document.execCommand("BackgroundImageCache", false, true); } catch (e){}
    if (typeof(htmlObject)!="object")
      this.parentObject=document.getElementById(htmlObject);
    else
      this.parentObject=htmlObject;

    this.parentObject.style.overflow="hidden";
    this._itim_dg=true;
    this.dlmtr=",";
    this.dropLower=false;
    this.enableIEImageFix();

   this.xmlstate=0;
   this.mytype="tree";
   this.smcheck=true;   //smart checkboxes
   this.width=width;
   this.height=height;
   this.rootId=rootId;
   this.childCalc=null;
      this.def_img_x="18px";
      this.def_img_y="18px";
      this.def_line_img_x="18px";
      this.def_line_img_y="18px";

    this._dragged=new Array();
   this._selected=new Array();

   this.style_pointer="pointer";
   if (_isIE)  this.style_pointer="hand";

   this._aimgs=true;
   this.htmlcA=" [";
   this.htmlcB="]";
   this.lWin=window;
   this.cMenu=0;
   this.mlitems=0;
   this.iconURL="";
   this.dadmode=0;
   this.slowParse=false;
   this.autoScroll=true;
   this.hfMode=0;
   this.nodeCut=new Array();
   this.XMLsource=0;
   this.XMLloadingWarning=0;
   this._idpull={};
   this._pullSize=0;
   this.treeLinesOn=true;
   this.tscheck=false;
   this.timgen=true;
   this.dpcpy=false;
    this._ld_id=null;
    this._oie_onXLE=[];
   this.imPath="treeGfx/";
   this.checkArray=new Array("iconUncheckAll.gif","iconCheckAll.gif","iconCheckGray.gif","iconUncheckDis.gif","iconCheckDis.gif","iconCheckDis.gif");
   this.radioArray=new Array("radio_off.gif","radio_on.gif","radio_on.gif","radio_off.gif","radio_on.gif","radio_on.gif");

   this.lineArray=new Array("line2.gif","line3.gif","line4.gif","blank.gif","blank.gif","line1.gif");
   this.minusArray=new Array("minus2.gif","minus3.gif","minus4.gif","minus.gif","minus5.gif");
   this.plusArray=new Array("plus2.gif","plus3.gif","plus4.gif","plus.gif","plus5.gif");
   this.imageArray=new Array("leaf.gif","folderOpen.gif","folderClosed.gif");
   this.cutImg= new Array(0,0,0);
   this.cutImage="but_cut.gif";

   this.dragger= new dhtmlDragAndDropObject();
//create root
   this.htmlNode=new dhtmlXTreeItemObject(this.rootId,"",0,this);
   this.htmlNode.htmlNode.childNodes[0].childNodes[0].style.display="none";
   this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[0].className="hiddenRow";
//init tree structures
   this.allTree=this._createSelf();
   this.allTree.appendChild(this.htmlNode.htmlNode);
    if(_isFF){
         this.allTree.childNodes[0].width="100%";
         this.allTree.childNodes[0].style.overflow="hidden";
    }

   var self=this;
   this.allTree.onselectstart=new Function("return false;");
   if (_isMacOS)
        this.allTree.oncontextmenu = function(e){ return self._doContClick(e||window.event); };
   this.allTree.onmousedown = function(e){ return self._doContClick(e||window.event); };

   this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this,true,this.no_cashe);
   if (_isIE) this.preventIECashing(true);




    if (window.addEventListener) window.addEventListener("unload",function(){try{  self.destructor(); } catch(e){}},false);
    if (window.attachEvent) window.attachEvent("onunload",function(){ try{ self.destructor(); } catch(e){}});

    this.dhx_Event();
    this._onEventSet={onMouseIn:function(){this.ehlt=true;},onMouseOut:function(){this.ehlt=true;},onSelect:function(){this._onSSCF=true;}}

    this.setImagesPath=this.setImagePath;
    this.setIconsPath=this.setIconPath;

   return this;
};


/**
*     @desc: set default data transfer mode
*     @param: mode - data mode (json,xml,csv)
*     @type: public
*     @topic: 0
*/
dhtmlXTreeObject.prototype.setDataMode=function(mode){
        this._datamode=mode;
}



dhtmlXTreeObject.prototype._doContClick=function(ev){
    if (ev.button!=2) {
        if(this._acMenu){
            if (this._acMenu.hideContextMenu)
                this._acMenu.hideContextMenu()
            else
                this.cMenu._contextEnd();
        }
        return true;
    }

    var el=(_isIE?ev.srcElement:ev.target);
    while ((el)&&(el.tagName!="BODY")) {
        if (el.parentObject) break;
         el=el.parentNode;
     }

    if ((!el)||(!el.parentObject)) return true;

    var obj=el.parentObject;
        this._acMenu=(obj.cMenu||this.cMenu);
        if (this._acMenu){
            if (!(this.callEvent("onBeforeContextMenu", [
                    obj.id
                ]))) return true;
            if (_isIE)
               ev.srcElement.oncontextmenu = function(){ event.cancelBubble=true; return false; };
             if (_isFF)
                ev.target.oncontextmenu = function(e){ e.cancelBubble=true; return false; };

            if (this._acMenu.showContextMenu){

var dEl0=window.document.documentElement;
var dEl1=window.document.body;
var corrector = new Array((dEl0.scrollLeft||dEl1.scrollLeft),(dEl0.scrollTop||dEl1.scrollTop));
if (_isIE){
    var x= ev.clientX+corrector[0];
    var y = ev.clientY-corrector[1];
} else {
    var x= ev.pageX;
    var y = ev.pageY;
}

                this._acMenu.showContextMenu(x-1,y-1)
                this.contextID=this._acMenu.contextMenuZoneId=obj.id;
                ev.cancelBubble=true;
                this._acMenu._skip_hide=true;
            } else {
                el.contextMenuId=obj.id;
                el.contextMenu=this._acMenu;
                el.a=this._acMenu._contextStart;
                el.a(el, ev);
                el.a=null;
            }

            return false;
        }
    return true;
}


/**
*     @desc: replace IMG tag with background images - solve problem with IE image caching , not works for IE6 SP1
*     @param: mode - true/false - enable/disable fix
*     @type: public
*     @topic: 0
*/
dhtmlXTreeObject.prototype.enableIEImageFix=function(mode){
    if (!mode){

    this._getImg=function(id){ return document.createElement((id==this.rootId)?"div":"img"); }
    this._setSrc=function(a,b){ a.src=b; }
    this._getSrc=function(a){ return a.src; }
    }   else    {

    this._getImg=function(){ var z=document.createElement("DIV"); z.innerHTML="&nbsp;"; z.className="dhx_bg_img_fix"; return z; }
    this._setSrc=function(a,b){ a.style.backgroundImage="url("+b+")"; }
    this._getSrc=function(a){ var z=a.style.backgroundImage;  return z.substr(4,z.length-5); }
    }
}

/**
*   @desc: deletes tree and clears memory
*   @type: public
*/
dhtmlXTreeObject.prototype.destructor=function(){
    for (var a in this._idpull){
        var z=this._idpull[a];
        if (!z) continue;
        z.parentObject=null;z.treeNod=null;z.childNodes=null;z.span=null;z.tr.nodem=null;z.tr=null;z.htmlNode.objBelong=null;z.htmlNode=null;
        this._idpull[a]=null;
        }
    this.parentObject.innerHTML="";
    this.XMLLoader.destructor();
    for(var a in this){
        this[a]=null;
        }
}

function cObject(){
    return this;
}
cObject.prototype= new Object;
cObject.prototype.clone = function () {
       function _dummy(){};
       _dummy.prototype=this;
       return new _dummy();
    }

/**
*   @desc: tree node constructor
*   @param: itemId - node id
*   @param: itemText - node label
*   @param: parentObject - parent item object
*   @param: treeObject - tree object
*   @param: actionHandler - onclick event handler(optional)
*   @param: mode - do not show images
*   @type: private
*   @topic: 0
*/
function dhtmlXTreeItemObject(itemId,itemText,parentObject,treeObject,actionHandler,mode){
   this.htmlNode="";
   this.acolor="";
   this.scolor="";
   this.tr=0;
   this.childsCount=0;
   this.tempDOMM=0;
   this.tempDOMU=0;
   this.dragSpan=0;
   this.dragMove=0;
   this.span=0;
   this.closeble=1;
   this.childNodes=new Array();
   this.userData=new cObject();


   this.checkstate=0;
   this.treeNod=treeObject;
   this.label=itemText;
   this.parentObject=parentObject;
   this.actionHandler=actionHandler;
   this.images=new Array(treeObject.imageArray[0],treeObject.imageArray[1],treeObject.imageArray[2]);


   this.id=treeObject._globalIdStorageAdd(itemId,this);
   if (this.treeNod.checkBoxOff ) this.htmlNode=this.treeNod._createItem(1,this,mode);
   else  this.htmlNode=this.treeNod._createItem(0,this,mode);

   this.htmlNode.objBelong=this;
   return this;
   };


/**
*     @desc: register node
*     @type: private
*     @param: itemId - node id
*     @param: itemObject - node object
*     @topic: 3
*/
   dhtmlXTreeObject.prototype._globalIdStorageAdd=function(itemId,itemObject){
      if (this._globalIdStorageFind(itemId,1,1)) {   itemId=itemId +"_"+(new Date()).valueOf(); return this._globalIdStorageAdd(itemId,itemObject); }
         this._idpull[itemId]=itemObject;
         this._pullSize++;
      return itemId;
   };

/**
*     @desc: unregister node
*     @type: private
*     @param: itemId - node id
*     @topic: 3
*/
   dhtmlXTreeObject.prototype._globalIdStorageSub=function(itemId){
        if (this._idpull[itemId]){
            this._unselectItem(this._idpull[itemId]);
            this._idpull[itemId]=null;
            this._pullSize--;
        }
        if ((this._locker)&&(this._locker[itemId])) this._locker[itemId]=false;
   };

/**
*     @desc: return node object
*     @param: itemId - node id
*     @type: private
*     @topic: 3
*/
   dhtmlXTreeObject.prototype._globalIdStorageFind=function(itemId,skipXMLSearch,skipParsing,isreparse){
        var z=this._idpull[itemId]
        if (z){

            return z;
            }

        return null;
   };


/**
*     @desc: escape string
*     @param: itemId - item ID
*     @type: private
*     @topic: 3
*/
   dhtmlXTreeObject.prototype._escape=function(str){
        switch(this.utfesc){
        case "none":
            return str;
            break;
        case "utf8":
         return encodeURI(str);
            break;
        default:
         return escape(str);
            break;
        }
   }



/**
*     @desc: create and return  new line in tree
*     @type: private
*     @param: htmlObject - parent Node object
*     @param: node - item object
*     @topic: 2
*/
   dhtmlXTreeObject.prototype._drawNewTr=function(htmlObject,node)
   {
      var tr =document.createElement('tr');
      var td1=document.createElement('td');
      var td2=document.createElement('td');
      td1.appendChild(document.createTextNode(" "));
      td2.colSpan=3;
      td2.appendChild(htmlObject);
      tr.appendChild(td1);  tr.appendChild(td2);
      return tr;
   };
/**
*     @desc: load tree from xml string
*     @type: public
*     @param: xmlString - XML string
*     @param: afterCall - function which will be called after xml loading
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.loadXMLString=function(xmlString,afterCall){
        var that=this;
      if (!this.parsCount) this.callEvent("onXLS",[that,null]);
      this.xmlstate=1;

        if (afterCall) this.XMLLoader.waitCall=afterCall;
      this.XMLLoader.loadXMLString(xmlString);  };
/**
*     @desc: load tree from xml file
*     @type: public
*     @param: file - link to XML file
*     @param: afterCall - function which will be called after xml loading
*     @topic: 0
*/
    dhtmlXTreeObject.prototype.loadXML=function(file,afterCall){
      if (this._datamode && this._datamode!="xml") return this["load"+this._datamode.toUpperCase()](file,afterCall);
        var that=this;
      if (!this.parsCount) this.callEvent("onXLS",[that,this._ld_id]);
      this._ld_id=null;
      this.xmlstate=1;
      this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this,true,this.no_cashe);

      if (afterCall) this.XMLLoader.waitCall=afterCall;
      this.XMLLoader.loadXML(file);
   };
/**
*     @desc: create new child node
*     @type: private
*     @param: parentObject - parent node object
*     @param: itemId - new node id
*     @param: itemText - new node text
*     @param: itemActionHandler - function fired on node select event
*     @param: image1 - image for node without children;
*     @param: image2 - image for closed node;
*     @param: image3 - image for opened node
*     @param: optionStr - string of otions
*     @param: childs - node childs flag (for dynamical trees) (optional)
*     @param: beforeNode - node, after which new node will be inserted (optional)
*     @topic: 2
*/
   dhtmlXTreeObject.prototype._attachChildNode=function(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs,beforeNode,afterNode){

         if (beforeNode && beforeNode.parentObject) parentObject=beforeNode.parentObject;
         if (((parentObject.XMLload==0)&&(this.XMLsource))&&(!this.XMLloadingWarning))
         {
            parentObject.XMLload=1;
                this._loadDynXML(parentObject.id);

         }

         var Count=parentObject.childsCount;
         var Nodes=parentObject.childNodes;


            if (afterNode){
            if (afterNode.tr.previousSibling.previousSibling){
               beforeNode=afterNode.tr.previousSibling.nodem;
               }
            else
               optionStr=optionStr.replace("TOP","")+",TOP";
               }

         if (beforeNode)
            {
            var ik,jk;
            for (ik=0; ik<Count; ik++)
               if (Nodes[ik]==beforeNode)
               {
               for (jk=Count; jk!=ik; jk--)
                  Nodes[1+jk]=Nodes[jk];
               break;
               }
            ik++;
            Count=ik;
            }


         if (optionStr) {
             var tempStr=optionStr.split(",");
            for (var i=0; i<tempStr.length; i++)
            {
               switch(tempStr[i])
               {
                  case "TOP": if (parentObject.childsCount>0) { beforeNode=new Object; beforeNode.tr=parentObject.childNodes[0].tr.previousSibling; }
                     parentObject._has_top=true;
                     for  (ik=Count; ik>0; ik--)
                        Nodes[ik]=Nodes[ik-1];
                        Count=0;
                     break;
               }
            };
          };

            var n;
        if (!(n=this._idpull[itemId]) || n.span!=-1){
            n=Nodes[Count]=new dhtmlXTreeItemObject(itemId,itemText,parentObject,this,itemActionHandler,1);
            itemId = Nodes[Count].id;
            parentObject.childsCount++;
        }

        if(!n.htmlNode) {
           n.label=itemText;
           n.htmlNode=this._createItem((this.checkBoxOff?1:0),n);
           n.htmlNode.objBelong=n;
          }

         if(image1) n.images[0]=image1;
         if(image2) n.images[1]=image2;
         if(image3) n.images[2]=image3;


         var tr=this._drawNewTr(n.htmlNode);
         if ((this.XMLloadingWarning)||(this._hAdI))
            n.htmlNode.parentNode.parentNode.style.display="none";


            if ((beforeNode)&&(beforeNode.tr.nextSibling))
               parentObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr.nextSibling);
            else
               if (this.parsingOn==parentObject.id){
                  this.parsedArray[this.parsedArray.length]=tr;
                        }
               else
                   parentObject.htmlNode.childNodes[0].appendChild(tr);


               if ((beforeNode)&&(!beforeNode.span)) beforeNode=null;

            if (this.XMLsource) if ((childs)&&(childs!=0)) n.XMLload=0; else n.XMLload=1;
            n.tr=tr;
            tr.nodem=n;

            if (parentObject.itemId==0)
                tr.childNodes[0].className="hiddenRow";

            if ((parentObject._r_logic)||(this._frbtr))
                this._setSrc(n.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0],this.imPath+this.radioArray[0]);


          if (optionStr) {
             var tempStr=optionStr.split(",");

            for (var i=0; i<tempStr.length; i++)
            {
               switch(tempStr[i])
               {
                     case "SELECT": this.selectItem(itemId,false); break;
                  case "CALL": this.selectItem(itemId,true);   break;
                  case "CHILD":  n.XMLload=0;  break;
                  case "CHECKED":
                     if (this.XMLloadingWarning)
                        this.setCheckList+=this.dlmtr+itemId;
                     else
                        this.setCheck(itemId,1);
                        break;
                  case "HCHECKED":
                        this._setCheck(n,"unsure");
                        break;
                  case "OPEN": n.openMe=1;  break;
               }
            };
          };

      if (!this.XMLloadingWarning)
      {
             if ((this._getOpenState(parentObject)<0)&&(!this._hAdI)) this.openItem(parentObject.id);

             if (beforeNode)
                {
             this._correctPlus(beforeNode);
             this._correctLine(beforeNode);
                }
             this._correctPlus(parentObject);
             this._correctLine(parentObject);
             this._correctPlus(n);
             if (parentObject.childsCount>=2)
             {
                   this._correctPlus(Nodes[parentObject.childsCount-2]);
                   this._correctLine(Nodes[parentObject.childsCount-2]);
             }
             if (parentObject.childsCount!=2) this._correctPlus(Nodes[0]);

         if (this.tscheck) this._correctCheckStates(parentObject);

            if (this._onradh) {
                if (this.xmlstate==1){
                    var old=this.onXLE;
                    this.onXLE=function(id){ this._onradh(itemId); if (old) old(id); }
                    }
                else
                    this._onradh(itemId);
            }

      }
   return n;
};




/**
*     @desc: create new node as a child to specified with parentId
*     @type: deprecated
*     @param: parentId - parent node id
*     @param: itemId - new node id
*     @param: itemText - new node text
*     @param: itemActionHandler - function fired on node select event (optional)
*     @param: image1 - image for node without children; (optional)
*     @param: image2 - image for closed node; (optional)
*     @param: image3 - image for opened node (optional)
*     @param: optionStr - options string (optional)
*     @param: children - node children flag (for dynamical trees) (optional)
*     @topic: 2
*/
   dhtmlXTreeObject.prototype.insertNewItem=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){
      var parentObject=this._globalIdStorageFind(parentId);
      if (!parentObject) return (-1);
      var nodez=this._attachChildNode(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children);

        return nodez;
   };
/**
*     @desc: create new node as a child to specified with parentId
*     @type: public
*     @param: parentId - parent node id
*     @param: itemId - new node id
*     @param: itemText - new node label
*     @param: itemActionHandler - function fired on node select event (optional)
*     @param: image1 - image for node without children; (optional)
*     @param: image2 - image for closed node; (optional)
*     @param: image3 - image for opened node (optional)
*     @param: optionStr - options string (optional)
*     @param: children - node children flag (for dynamical trees) (optional)
*     @topic: 2
*/
   dhtmlXTreeObject.prototype.insertNewChild=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){
      return this.insertNewItem(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children);
   }
/**
*     @desc: parse xml
*     @type: private
*     @param: dhtmlObject - jsTree object
*     @param: node - top XML node
*     @param: parentId - parent node id
*     @param: level - level of tree
*     @topic: 2
*/
    dhtmlXTreeObject.prototype._parseXMLTree=function(a,b,c,d,xml){
        var p=new xmlPointer(xml.getXMLTopNode("tree"));
        a._parse(p);
        a._p=p;
    }

    dhtmlXTreeObject.prototype._parseItem=function(c,temp,preNode,befNode){
        var id;
        if (this._srnd && (!this._idpull[id=c.get("id")] || !this._idpull[id].span))
        {
            this._addItemSRND(temp.id,id,c);
            return;
        }

  var a=c.get_all();

        if ((typeof(this.waitUpdateXML)=="object")&&(!this.waitUpdateXML[a.id])){
            this._parse(c,a.id,1);
            return;
        }






                  var zST=[];
                  if (a.select) zST.push("SELECT");
                  if (a.top) zST.push("TOP");
                  if (a.call) this.nodeAskingCall=a.id;
                  if (a.checked==-1) zST.push("HCHECKED");
                     else if (a.checked) zST.push("CHECKED");
                  if (a.open) zST.push("OPEN");

                  if (this.waitUpdateXML){
                        if (this._globalIdStorageFind(a.id))
                            var newNode=this.updateItem(a.id,a.text,a.im0,a.im1,a.im2,a.checked);
                        else{
                            if (this.npl==0) zST.push("TOP");
                            else preNode=temp.childNodes[this.npl];

                            var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,0,preNode);
                            preNode=null;
                        }
                     }
                  else
                     var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,(befNode||0),preNode);
                  if (a.tooltip)
                    newNode.span.parentNode.parentNode.title=a.tooltip;

                  if (a.style)
                            if (newNode.span.style.cssText)
                                newNode.span.style.cssText+=(";"+a.style);
                            else
                                newNode.span.setAttribute("style",newNode.span.getAttribute("style")+"; "+a.style);

                        if (a.radio) newNode._r_logic=true;

                  if (a.nocheckbox){
                     newNode.span.parentNode.previousSibling.previousSibling.childNodes[0].style.display='none';
                     newNode.nocheckbox=true;
                  }
                        if (a.disabled){
                            if (a.checked!=null) this._setCheck(newNode,a.checked);
                            this.disableCheckbox(newNode,1);
                            }


                  newNode._acc=a.child||0;

                  if (this.parserExtension) this.parserExtension._parseExtension.call(this,c,a,(temp?temp.id:0));

                  this.setItemColor(newNode,a.aCol,a.sCol);
                  if (a.locked=="1")    this.lockItem(newNode.id,true,true);

                  if ((a.imwidth)||(a.imheight))   this.setIconSize(a.imwidth,a.imheight,newNode);
                  if ((a.closeable=="0")||(a.closeable=="1"))  this.setItemCloseable(newNode,a.closeable);
                  var zcall="";
                  if (a.topoffset) this.setItemTopOffset(newNode,a.topoffset);
                  if ((!this.slowParse)||(typeof(this.waitUpdateXML)=="object")){
                    if (c.sub_exists("item"))
                        zcall=this._parse(c,a.id,1);
                  }

                  if (zcall!="") this.nodeAskingCall=zcall;


        c.each("userdata",function(u){
                this.setUserData(c.get("id"),u.get("name"),u.content());
          },this)


    }
    dhtmlXTreeObject.prototype._parse=function(p,parentId,level,start){
        if (this._srnd && !this.parentObject.offsetHeight) {
            var self=this;
            return window.setTimeout(function(){
                self._parse(p,parentId,level,start);
            },100);
        }
        if (!p.exists()) return;

        this.skipLock=true; //disable item locking
        //loading flags

        this.parsCount=this.parsCount?(this.parsCount+1):1;
        this.XMLloadingWarning=1;


        if (!parentId) {          //top level
            parentId=p.get("id");
            if (p.get("radio"))
                this.htmlNode._r_logic=true;
            this.parsingOn=parentId;
            this.parsedArray=new Array();
            this.setCheckList="";
            this.nodeAskingCall="";
        }

        var temp=this._globalIdStorageFind(parentId);
        if (!temp) return dhtmlxError.throwError("DataStructure","XML reffers to not existing parent");

        if ((temp.childsCount)&&(!start)&&(!this._edsbps)&&(!temp._has_top))
            var preNode=temp.childNodes[temp.childsCount-1];
        else
            var preNode=0;

        this.npl=0;

        p.each("item",function(c,i){

        temp.XMLload=1;
        if ((this._epgps)&&(this._epgpsC==this.npl)){
            this._setNextPageSign(temp,this.npl+1*(start||0),level,node);
            return -1;
        }

          this._parseItem(c,temp,preNode);


              this.npl++;



      },this,start);


      if (!level) {
          p.each("userdata",function(u){
                this.setUserData(p.get("id"),u.get("name"),u.content());
          },this);

         temp.XMLload=1;
         if (this.waitUpdateXML){
            this.waitUpdateXML=false;
            for (var i=temp.childsCount-1; i>=0; i--)
                if (temp.childNodes[i]._dmark)
                    this.deleteItem(temp.childNodes[i].id);
            }

         var parsedNodeTop=this._globalIdStorageFind(this.parsingOn);

         for (var i=0; i<this.parsedArray.length; i++)
               temp.htmlNode.childNodes[0].appendChild(this.parsedArray[i]);

         this.lastLoadedXMLId=parentId;
         this.XMLloadingWarning=0;

         var chArr=this.setCheckList.split(this.dlmtr);
         for (var n=0; n<chArr.length; n++)
            if (chArr[n]) this.setCheck(chArr[n],1);

               if ((this.XMLsource)&&(this.tscheck)&&(this.smcheck)&&(temp.id!=this.rootId)){
                if (temp.checkstate===0)
                    this._setSubChecked(0,temp);
                else if (temp.checkstate===1)
                    this._setSubChecked(1,temp);
            }

         if (this.onXLE) this.onXLE(this,parentId);
         this._redrawFrom(this,null,start)


         if (p.get("order") && p.get("order")!="none")
            this._reorderBranch(temp,p.get("order"),true);

                     if (this.nodeAskingCall!="")   this.selectItem(this.nodeAskingCall,true);
         if (this._branchUpdate) this._branchUpdateNext(p);
         }


      if (this.parsCount==1) {



         if ((!this._edsbps)||(!this._edsbpsA.length)){
                var that=this;
                window.setTimeout( function(){  that.callEvent("onXLE",[that,parentId]); },1);
                this.xmlstate=0;
                }
             this.skipLock=false;
         }
      this.parsCount--;



        if ((this._epgps)&&(start))
            this._setPrevPageSign(temp,(start||0),level,node);

      return this.nodeAskingCall;
  };


dhtmlXTreeObject.prototype._branchUpdateNext=function(p){
    p.each("item",function(c){
        var nid=c.get("id");
        if (this._idpull[nid] && (!this._idpull[nid].XMLload))  return;
        this._branchUpdate++;
        this.smartRefreshItem(c.get("id"),c);
    },this)
    this._branchUpdate--;
}

  dhtmlXTreeObject.prototype.checkUserData=function(node,parentId){
      if ((node.nodeType==1)&&(node.tagName == "userdata"))
      {
         var name=node.getAttribute("name");
            if ((name)&&(node.childNodes[0]))
               this.setUserData(parentId,name,node.childNodes[0].data);
      }
  }




/**
*     @desc: reset tree images from selected level
*     @type: private
*     @param: dhtmlObject - tree
*     @param: itemObject - current item
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._redrawFrom=function(dhtmlObject,itemObject,start,visMode){
      if (!itemObject) {
      var tempx=dhtmlObject._globalIdStorageFind(dhtmlObject.lastLoadedXMLId);
      dhtmlObject.lastLoadedXMLId=-1;
      if (!tempx) return 0;
      }
      else tempx=itemObject;
      var acc=0;

      for (var i=(start?start-1:0); i<tempx.childsCount; i++)
      {
         if ((!this._branchUpdate)||(this._getOpenState(tempx)==1))
             if ((!itemObject)||(visMode==1)) tempx.childNodes[i].htmlNode.parentNode.parentNode.style.display="";
         if (tempx.childNodes[i].openMe==1)
            {
            this._openItem(tempx.childNodes[i]);
            tempx.childNodes[i].openMe=0;
            }

         dhtmlObject._redrawFrom(dhtmlObject,tempx.childNodes[i]);


      };

      if ((!tempx.unParsed)&&((tempx.XMLload)||(!this.XMLsource)))
      tempx._acc=acc;
      dhtmlObject._correctLine(tempx);
      dhtmlObject._correctPlus(tempx);

   };

/**
*     @desc: create and return main html element of tree
*     @type: private
*     @topic: 0
*/
   dhtmlXTreeObject.prototype._createSelf=function(){
      var div=document.createElement('div');
      div.className="containerTableStyle";
      div.style.width=this.width;
      div.style.height=this.height;
/////////////////////////////////////////
//    heresyrt (s)
//    좌측메뉴에서 하단의 X축 스크롤 제거
/////////////////////////////////////////
      div.style.overflowY="auto";
      div.style.overflowX="hidden";
/////////////////////////////////////////
//    heresyrt (e)
/////////////////////////////////////////
      this.parentObject.appendChild(div);
      return div;
   };

/**
*     @desc: collapse target node
*     @type: private
*     @param: itemObject - item object
*     @topic: 4
*/
   dhtmlXTreeObject.prototype._xcloseAll=function(itemObject)
   {
        if (itemObject.unParsed) return;
      if (this.rootId!=itemObject.id) {
          var Nodes=itemObject.htmlNode.childNodes[0].childNodes;
            var Count=Nodes.length;

          for (var i=1; i<Count; i++)
             Nodes[i].style.display="none";

          this._correctPlus(itemObject);
      }

       for (var i=0; i<itemObject.childsCount; i++)
            if (itemObject.childNodes[i].childsCount)
             this._xcloseAll(itemObject.childNodes[i]);
   };
/**
*     @desc: expand target node
*     @type: private
*     @param: itemObject - item object
*     @topic: 4
*/
   dhtmlXTreeObject.prototype._xopenAll=function(itemObject)
   {
      this._HideShow(itemObject,2);
      for (var i=0; i<itemObject.childsCount; i++)
         this._xopenAll(itemObject.childNodes[i]);
   };
/**
*     @desc: set correct tree-line and node images
*     @type: private
*     @param: itemObject - item object
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._correctPlus=function(itemObject){
        if (!itemObject.htmlNode) return;
        var imsrc=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[0].lastChild;
        var imsrc2=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0];

       var workArray=this.lineArray;
      if ((this.XMLsource)&&(!itemObject.XMLload))
      {
            var workArray=this.plusArray;
            this._setSrc(imsrc2,this.imPath+itemObject.images[2]);
                if (this._txtimg) return (imsrc.innerHTML="[+]");
      }
      else
      if ((itemObject.childsCount)||(itemObject.unParsed))
      {
         if ((itemObject.htmlNode.childNodes[0].childNodes[1])&&( itemObject.htmlNode.childNodes[0].childNodes[1].style.display!="none" ))
            {
            if (!itemObject.wsign) var workArray=this.minusArray;
            this._setSrc(imsrc2,this.iconURL+itemObject.images[1]);
                if (this._txtimg) return (imsrc.innerHTML="[-]");
            }
         else
            {
            if (!itemObject.wsign) var workArray=this.plusArray;
            this._setSrc(imsrc2,this.iconURL+itemObject.images[2]);
                if (this._txtimg) return (imsrc.innerHTML="[+]");
            }
      }
      else
      {
         this._setSrc(imsrc2,this.iconURL+itemObject.images[0]);
       }


      var tempNum=2;
      if (!itemObject.treeNod.treeLinesOn) this._setSrc(imsrc,this.imPath+workArray[3]);
      else {
          if (itemObject.parentObject) tempNum=this._getCountStatus(itemObject.id,itemObject.parentObject);
          this._setSrc(imsrc,this.imPath+workArray[tempNum]);
         }
   };

/**
*     @desc: set correct tree-line images
*     @type: private
*     @param: itemObject - item object
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._correctLine=function(itemObject){
      if (!itemObject.htmlNode) return;
      var sNode=itemObject.parentObject;
      if (sNode)
         if ((this._getLineStatus(itemObject.id,sNode)==0)||(!this.treeLinesOn))
               for(var i=1; i<=itemObject.childsCount; i++){
                  if (!itemObject.htmlNode.childNodes[0].childNodes[i]) break;
                  itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage="none";
                  itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat="";
                }
            else
               for(var i=1; i<=itemObject.childsCount; i++){
                 if (!itemObject.htmlNode.childNodes[0].childNodes[i]) break;
                 itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage="url("+this.imPath+this.lineArray[5]+")";
                 itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat="repeat-y";
         }
   };
/**
*     @desc: return type of node
*     @type: private
*     @param: itemId - item id
*     @param: itemObject - parent node object
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._getCountStatus=function(itemId,itemObject){
      if (itemObject.childsCount<=1) { if (itemObject.id==this.rootId) return 4; else  return 0; }

      if (itemObject.childNodes[0].id==itemId) if (itemObject.id==this.rootId) return 2; else return 1;
      if (itemObject.childNodes[itemObject.childsCount-1].id==itemId) return 0;

      return 1;
   };
/**
*     @desc: return type of node
*     @type: private
*     @param: itemId - node id
*     @param: itemObject - parent node object
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._getLineStatus =function(itemId,itemObject){
         if (itemObject.childNodes[itemObject.childsCount-1].id==itemId) return 0;
         return 1;
      }

/**
*     @desc: open/close node
*     @type: private
*     @param: itemObject - node object
*     @param: mode - open/close mode [1-close 2-open](optional)
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._HideShow=function(itemObject,mode){
      if ((this.XMLsource)&&(!itemObject.XMLload)) {
            if (mode==1) return; //close for not loaded node - ignore it
            itemObject.XMLload=1;
            this._loadDynXML(itemObject.id);
            return; };

      var Nodes=itemObject.htmlNode.childNodes[0].childNodes; var Count=Nodes.length;
      if (Count>1){
         if ( ( (Nodes[1].style.display!="none") || (mode==1) ) && (mode!=2) ) {
//nb:solves standard doctype prb in IE
          this.allTree.childNodes[0].border = "1";
          this.allTree.childNodes[0].border = "0";
         nodestyle="none";
         }
         else  nodestyle="";

      for (var i=1; i<Count; i++)
         Nodes[i].style.display=nodestyle;
      }
      this._correctPlus(itemObject);
   }

/**
*     @desc: return node state
*     @type: private
*     @param: itemObject - node object
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._getOpenState=function(itemObject){
      var z=itemObject.htmlNode.childNodes[0].childNodes;
      if (z.length<=1) return 0;
      if    (z[1].style.display!="none") return 1;
      else return -1;
   }



/**
*     @desc: ondblclick item  event handler
*     @type: private
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.onRowClick2=function(){
      var that=this.parentObject.treeNod;
      if (!that.callEvent("onDblClick",[this.parentObject.id,that])) return 0;
      if ((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
         that._HideShow(this.parentObject);
      else
         that._HideShow(this.parentObject,2);

    if    (that.checkEvent("onOpenEnd"))
           if (!that.xmlstate)
                that.callEvent("onOpenEnd",[this.parentObject.id,that._getOpenState(this.parentObject)]);
            else{
                that._oie_onXLE.push(that.onXLE);
                that.onXLE=that._epnFHe;
                }
   };
/**
*     @desc: onclick item event handler
*     @type: private
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.onRowClick=function(){
    var that=this.parentObject.treeNod;
      if (!that.callEvent("onOpenStart",[this.parentObject.id,that._getOpenState(this.parentObject)])) return 0;
      if ((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
         that._HideShow(this.parentObject);
      else
         that._HideShow(this.parentObject,2);


   if    (that.checkEvent("onOpenEnd"))
           if (!that.xmlstate)
                that.callEvent("onOpenEnd",[this.parentObject.id,that._getOpenState(this.parentObject)]);
            else{
                that._oie_onXLE.push(that.onXLE);
                that.onXLE=that._epnFHe;
                }

   };

      dhtmlXTreeObject.prototype._epnFHe=function(that,id,flag){
        if (id!=this.rootId)
            this.callEvent("onOpenEnd",[id,that.getOpenState(id)]);
        that.onXLE=that._oie_onXLE.pop();

        if (!flag && !that._oie_onXLE.length)
            if (that.onXLE) that.onXLE(that,id);
    }



/**
*     @desc: onclick item image event handler
*     @type: private
*     @edition: Professional
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.onRowClickDown=function(e){
            e=e||window.event;
         var that=this.parentObject.treeNod;
         that._selectItem(this.parentObject,e);
      };


/*****
SELECTION
*****/

/**
*     @desc: retun selected item id
*     @type: public
*     @return: id of selected item
*     @topic: 1
*/
   dhtmlXTreeObject.prototype.getSelectedItemId=function()
   {
        var str=new Array();
        for (var i=0; i<this._selected.length; i++) str[i]=this._selected[i].id;
      return (str.join(this.dlmtr));
   };

/**
*     @desc: visual select item in tree
*     @type: private
*     @param: node - tree item object
*     @edition: Professional
*     @topic: 0
*/
   dhtmlXTreeObject.prototype._selectItem=function(node,e){
        if (this._onSSCF) this._onSSCFold=this.getSelectedItemId();

            this._unselectItems();

                    this._markItem(node);
        if (this._onSSCF) {
            var z=this.getSelectedItemId();
            if (z!=this._onSSCFold)
                this.callEvent("onSelect",[z]);
        }
    }
    dhtmlXTreeObject.prototype._markItem=function(node){
              if (node.scolor)  node.span.style.color=node.scolor;
              node.span.className="selectedTreeRow";
             node.i_sel=true;
             this._selected[this._selected.length]=node;
    }

/**
*     @desc: retun node index in children collection by Id
*     @type: public
*     @param: itemId - node id
*     @return: node index
*     @topic: 2
*/
   dhtmlXTreeObject.prototype.getIndexById=function(itemId){
         var z=this._globalIdStorageFind(itemId);
         if (!z) return null;
         return this._getIndex(z);
   };
   dhtmlXTreeObject.prototype._getIndex=function(w){
        var z=w.parentObject;
        for (var i=0; i<z.childsCount; i++)
            if (z.childNodes[i]==w) return i;
   };





/**
*     @desc: visual unselect item in tree
*     @type: private
*     @param: node - tree item object
*     @edition: Professional
*     @topic: 0
*/
   dhtmlXTreeObject.prototype._unselectItem=function(node){
        if ((node)&&(node.i_sel))
            {

          node.span.className="standartTreeRow";
          if (node.acolor)  node.span.style.color=node.acolor;
            node.i_sel=false;
            for (var i=0; i<this._selected.length; i++)
                    if (!this._selected[i].i_sel) {
                        this._selected.splice(i,1);
                        break;
                 }

            }
       }

/**
*     @desc: visual unselect items in tree
*     @type: private
*     @param: node - tree item object
*     @edition: Professional
*     @topic: 0
*/
   dhtmlXTreeObject.prototype._unselectItems=function(){
      for (var i=0; i<this._selected.length; i++){
            var node=this._selected[i];
         node.span.className="standartTreeRow";
          if (node.acolor)  node.span.style.color=node.acolor;
         node.i_sel=false;
         }
         this._selected=new Array();
       }


/**
*     @desc: select node text event handler
*     @type: private
*     @param: e - event object
*     @param: htmlObject - node object
*     @param: mode - if false - call onSelect event
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.onRowSelect=function(e,htmlObject,mode){
      e=e||window.event;

        var obj=this.parentObject;
      if (htmlObject) obj=htmlObject.parentObject;
        var that=obj.treeNod;

        var lastId=that.getSelectedItemId();
        if ((!e)||(!e.skipUnSel))
            that._selectItem(obj,e);

      if (!mode) {
         if ((e)&&(e.button==2))
            that.callEvent("onRightClick",[obj.id,e]);

         if (obj.actionHandler) obj.actionHandler(obj.id,lastId);
         else that.callEvent("onClick",[obj.id,lastId]);
         }
   };





/**
*     @desc: fix checkbox state
*     @type: private
*     @topic: 0
*/
dhtmlXTreeObject.prototype._correctCheckStates=function(dhtmlObject){

   if (!this.tscheck) return;
   if (!dhtmlObject) return;
   if (dhtmlObject.id==this.rootId) return;
   //calculate state
   var act=dhtmlObject.childNodes;
   var flag1=0; var flag2=0;
   if (dhtmlObject.childsCount==0) return;
   for (var i=0; i<dhtmlObject.childsCount; i++){
      if (act[i].dscheck) continue;
      if (act[i].checkstate==0) flag1=1;
      else if (act[i].checkstate==1) flag2=1;
         else { flag1=1; flag2=1; break; }
         }

   if ((flag1)&&(flag2)) this._setCheck(dhtmlObject,"unsure");
   else if (flag1)  this._setCheck(dhtmlObject,false);
      else  this._setCheck(dhtmlObject,true);

      this._correctCheckStates(dhtmlObject.parentObject);
}

/**
*     @desc: checbox select action
*     @type: private
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.onCheckBoxClick=function(e){
          if (!this.treeNod.callEvent("onBeforeCheck",[this.parentObject.id,this.parentObject.checkstate]))
            return;

      if (this.parentObject.dscheck) return true;
      if (this.treeNod.tscheck)
         if (this.parentObject.checkstate==1) this.treeNod._setSubChecked(false,this.parentObject);
         else this.treeNod._setSubChecked(true,this.parentObject);
      else
         if (this.parentObject.checkstate==1) this.treeNod._setCheck(this.parentObject,false);
         else this.treeNod._setCheck(this.parentObject,true);
      this.treeNod._correctCheckStates(this.parentObject.parentObject);

      return this.treeNod.callEvent("onCheck",[this.parentObject.id,this.parentObject.checkstate]);
   };
/**
*     @desc: create HTML elements for tree node
*     @type: private
*     @param: acheck - enable/disable checkbox
*     @param: itemObject - item object
*     @param: mode - mode
*     @topic: 0
*/
   dhtmlXTreeObject.prototype._createItem=function(acheck,itemObject,mode){

     var table=document.createElement('table');
     table.cellSpacing=0;table.cellPadding=0;
     table.border=0;

     if(this.hfMode)table.style.tableLayout="fixed";
     table.style.margin=0;table.style.padding=0;

     var tbody=document.createElement('tbody');
     var tr=document.createElement('tr');

     var td1=document.createElement('td');
     td1.className="standartTreeImage";

     if(this._txtimg){
         var img0=document.createElement("div");
         td1.appendChild(img0);
         img0.className="dhx_tree_textSign";
    }
            else
            {
         var img0=this._getImg(itemObject.id);
            img0.border="0";
            if (img0.tagName=="IMG") img0.align="absmiddle";
            td1.appendChild(img0); img0.style.padding=0; img0.style.margin=0;
            img0.style.width=this.def_line_img_x; img0.style.height=this.def_line_img_y;
            }

      var td11=document.createElement('td');
//         var inp=document.createElement("input");            inp.type="checkbox"; inp.style.width="12px"; inp.style.height="12px";
         var inp=this._getImg(this.cBROf?this.rootId:itemObject.id);
         inp.checked=0; this._setSrc(inp,this.imPath+this.checkArray[0]); inp.style.width="16px"; inp.style.height="16px";
            //can cause problems with hide/show check
         if (!acheck) ((!_isIE)?td11:inp).style.display="none";

         // td11.className="standartTreeImage";
               //if (acheck)
            td11.appendChild(inp);
            if ((!this.cBROf)&&(inp.tagName=="IMG")) inp.align="absmiddle";
            inp.onclick=this.onCheckBoxClick;
            inp.treeNod=this;
            inp.parentObject=itemObject;
            if (!window._KHTMLrv) td11.width="20px";
            else td11.width="16px";

      var td12=document.createElement('td');
         td12.className="standartTreeImage";
         var img=this._getImg(this.timgen?itemObject.id:this.rootId);
            img.onmousedown=this._preventNsDrag; img.ondragstart=this._preventNsDrag;
            img.border="0";
            if (this._aimgs){
               img.parentObject=itemObject;
               if (img.tagName=="IMG") img.align="absmiddle";
               img.onclick=this.onRowSelect; }
            if (!mode) this._setSrc(img,this.iconURL+this.imageArray[0]);
            td12.appendChild(img); img.style.padding=0; img.style.margin=0;
         if (this.timgen)
            {
                td12.style.width=img.style.width=this.def_img_x; img.style.height=this.def_img_y; }
         else
            {
                img.style.width="0px"; img.style.height="0px";
                if (_isOpera)    td12.style.display="none";
                }


      var td2=document.createElement('td');
         td2.className="standartTreeRow";

            itemObject.span=document.createElement('span');
            itemObject.span.className="standartTreeRow";
            if (this.mlitems) {
                itemObject.span.style.width=this.mlitems;
               //   if (!_isIE)
                    itemObject.span.style.display="block";
                }
            else td2.noWrap=true;
                if (!window._KHTMLrv) td2.style.width="100%";

//      itemObject.span.appendChild(document.createTextNode(itemObject.label));
         itemObject.span.innerHTML=itemObject.label;
      td2.appendChild(itemObject.span);
      td2.parentObject=itemObject;        td1.parentObject=itemObject;
      td2.onclick=this.onRowSelect; td1.onclick=this.onRowClick; td2.ondblclick=this.onRowClick2;
      if (this.ettip)
            tr.title=itemObject.label;

      if (this.dragAndDropOff) {
         if (this._aimgs) { this.dragger.addDraggableItem(td12,this); td12.parentObject=itemObject; }
         this.dragger.addDraggableItem(td2,this);
         }

      itemObject.span.style.paddingLeft="5px";      itemObject.span.style.paddingRight="5px";   td2.style.verticalAlign="";
       td2.style.fontSize="10pt";       td2.style.cursor=this.style_pointer;
      tr.appendChild(td1);            tr.appendChild(td11);            tr.appendChild(td12);
      tr.appendChild(td2);
      tbody.appendChild(tr);
      table.appendChild(tbody);

      if (this.ehlt){//highlighting
        tr.onmousemove=this._itemMouseIn;
        tr[(_isIE)?"onmouseleave":"onmouseout"]=this._itemMouseOut;
      }
      if(this.checkEvent && this.checkEvent("onRightClick"))
         tr.oncontextmenu=Function("e","this.childNodes[0].parentObject.treeNod.callEvent('onRightClick',[this.childNodes[0].parentObject.id,(e||window.event)]); return false;");


      return table;
   };


/**
*     @desc: set path to images directory
*     @param: newPath - path to images directory (related to the page with tree or absolute http url)
*     @type: public
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.setImagePath=function( newPath ){ this.imPath=newPath; if (!this.iconURL) this.iconURL=newPath; };
    /**
    *   @desc: set path to external images used as tree icons
    *   @type: public
    *   @param: path - url (or relative path) of images folder with closing "/"
    *   @topic: 0,7
    */
    dhtmlXTreeObject.prototype.setIconPath=function(path){
        this.iconURL=path;
    }



/**
*     @desc: set function called when tree node selected
*     @param: (function) func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event: onRightClick
*     @depricated: use grid.attachEvent("onRightClick",func); instead
*     @eventdesc:  Event occurs after right mouse button was clicked.
         Assigning this handler can disable default context menu, and incompattible with dhtmlXMenu integration.
*     @eventparam: (string) ID of clicked item
*     @eventparam: (object) event object
*/
   dhtmlXTreeObject.prototype.setOnRightClickHandler=function(func){  this.attachEvent("onRightClick",func);   };

/**
*     @desc: set function called when tree node clicked, also can be forced to call from API
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event: onClick
*     @depricated: use grid.attachEvent("onClick",func); instead
*     @eventdesc: Event raises immideatly after text part of item in tree was clicked, but after default onClick functionality was processed.
              Richt mouse button click can be catched by onRightClick event handler.
*     @eventparam:  ID of clicked item
*     @eventparam:  ID of previously selected item
*/
   dhtmlXTreeObject.prototype.setOnClickHandler=function(func){  this.attachEvent("onClick",func);  };

/**
*     @desc: set function called when tree node selected or unselected, include any select change caused by any functionality
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event: onSelect
*     @depricated: use grid.attachEvent("onSelect",func); instead
*     @eventdesc: Event raises immideatly after selection in tree was changed
*     @eventparam:  selected item ID ( list of IDs in case of multiselection)
*/
   dhtmlXTreeObject.prototype.setOnSelectStateChange=function(func){  this.attachEvent("onSelect",func); this._onSSCF=true;  };


/**
*     @desc: enables dynamic loading from XML
*     @type: public
*     @param: filePath - name of script returning XML; in case of virtual loading - user defined function
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.setXMLAutoLoading=function(filePath){  this.XMLsource=filePath; };

   /**
*     @desc: set function called before checkbox checked/unchecked
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event: onCheck
*     @depricated: use tree.attachEvent("onCheck",func); instead
*     @eventdesc: Event raises right before item in tree was checked/unchecked. can be canceled (return false from event handler)
*     @eventparam: ID of item which will be checked/unchecked
*     @eventparam: Current checkbox state. 1 - item checked, 0 - item unchecked.
*       @eventreturn: true - confirm changing checked state; false - deny chaning checked state;
*/
   dhtmlXTreeObject.prototype.setOnCheckHandler=function(func){ this.attachEvent("onCheck",func);  };


/**
*     @desc: set function called before tree node opened/closed
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event:  onOpen
*     @depricated: use grid.attachEvent("onOpenStart",func); instead
*     @eventdesc: Event raises immideatly after item in tree got command to open/close , and before item was opened//closed. Event also raised for unclosable nodes and nodes without open/close functionality - in that case result of function will be ignored.
            Event does not occur if node was opened by dhtmlXtree API.
*     @eventparam: ID of node which will be opened/closed
*     @eventparam: Current open state of tree item. 0 - item has not children, -1 - item closed, 1 - item opened.
*     @eventreturn: true - confirm opening/closing; false - deny opening/closing;
*/
   dhtmlXTreeObject.prototype.setOnOpenHandler=function(func){  this.attachEvent("onOpenStart",func);   };
/**
*     @desc: set function called before tree node opened/closed
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event:  onOpenStart
*     @depricated: use grid.attachEvent("onOpenStart",func); instead
*     @eventdesc: Event raises immideatly after item in tree got command to open/close , and before item was opened//closed. Event also raised for unclosable nodes and nodes without open/close functionality - in that case result of function will be ignored.
            Event not raised if node opened by dhtmlXtree API.
*     @eventparam: ID of node which will be opened/closed
*     @eventparam: Current open state of tree item. 0 - item has not children, -1 - item closed, 1 - item opened.
*     @eventreturn: true - confirm opening/closing; false - deny opening/closing;
*/
   dhtmlXTreeObject.prototype.setOnOpenStartHandler=function(func){  this.attachEvent("onOpenStart",func);    };

/**
*     @desc: set function called after tree node opened/closed
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event:  onOpenEnd
*     @depricated: use grid.attachEvent("onOpenEnd",func); instead
*     @eventdesc: Event raises immideatly after item in tree was opened//closed. Event also raised for unclosable nodes and nodes without open/close functionality - in that case result of function will be ignored.
            Event not raised if node opened by dhtmlXtree API.
*     @eventparam: ID of node which will be opened/closed
*     @eventparam: Current open state of tree item. 0 - item has not children, -1 - item closed, 1 - item opened.
*/
   dhtmlXTreeObject.prototype.setOnOpenEndHandler=function(func){  this.attachEvent("onOpenEnd",func);  };

   /**
*     @desc: set function called when tree node double clicked
*     @param: func - event handling function
*     @type: public
*     @topic: 0,7
*     @event: onDblClick
*     @depricated: use grid.attachEvent("onDblClick",func); instead
*     @eventdesc: Event raised immideatly after item in tree was doubleclicked, before default onDblClick functionality was processed.
         Beware using both onClick and onDblClick events, because component can  generate onClick event before onDblClick event while doubleclicking item in tree.
         ( that behavior depend on used browser )
*     @eventparam:  ID of item which was doubleclicked
*     @eventreturn:  true - confirm opening/closing; false - deny opening/closing;
*/
   dhtmlXTreeObject.prototype.setOnDblClickHandler=function(func){ this.attachEvent("onDblClick",func);   };









   /**
*     @desc: expand target node and all sub nodes
*     @type: public
*     @param: itemId - node id
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.openAllItems=function(itemId)
   {
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      this._xopenAll(temp);
   };

/**
*     @desc: return open/close state
*     @type: public
*     @param: itemId - node id
*     @return: -1 - close, 1 - opened, 0 - node doesn't have children
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.getOpenState=function(itemId){
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return "";
      return this._getOpenState(temp);
   };

/**
*     @desc: collapse target node and all sub nodes
*     @type: public
*     @param: itemId - node id
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.closeAllItems=function(itemId)
   {
        if (itemId===window.undefined) itemId=this.rootId;

      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      this._xcloseAll(temp);

//nb:solves standard doctype prb in IE
         this.allTree.childNodes[0].border = "1";
       this.allTree.childNodes[0].border = "0";

   };


/**
*     @desc: set user data for target node
*     @type: public
*     @param: itemId - target node id
*     @param: name - key for user data
*     @param: value - user data value
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.setUserData=function(itemId,name,value){
      var sNode=this._globalIdStorageFind(itemId,0,true);
         if (!sNode) return;
         if(name=="hint")
             sNode.htmlNode.childNodes[0].childNodes[0].title=value;
            if (typeof(sNode.userData["t_"+name])=="undefined"){
                 if (!sNode._userdatalist) sNode._userdatalist=name;
                else sNode._userdatalist+=","+name;
            }
            sNode.userData["t_"+name]=value;
   };

/**
*     @desc: get user data from target node
*     @type: public
*     @param: itemId - target node id
*     @param: name - key for user data
*     @return: value of user data
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.getUserData=function(itemId,name){
      var sNode=this._globalIdStorageFind(itemId,0,true);
      if (!sNode) return;
      return sNode.userData["t_"+name];
   };




/**
*     @desc: get node color (text color)
*     @param: itemId - id of node
*     @type: public
*     @return: color of node (empty string for default color);
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.getItemColor=function(itemId)
   {
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;

      var res= new Object();
      if (temp.acolor) res.acolor=temp.acolor;
      if (temp.scolor) res.scolor=temp.scolor;
      return res;
   };
/**
*     @desc: set node text color
*     @param: itemId - id of node
*     @param: defaultColor - node color
*     @param: selectedColor - selected node color
*     @type: public
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.setItemColor=function(itemId,defaultColor,selectedColor)
   {
      if ((itemId)&&(itemId.span))
         var temp=itemId;
      else
         var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
         else {
         if (temp.i_sel)
            {  if (selectedColor) temp.span.style.color=selectedColor; }
         else
            {  if (defaultColor) temp.span.style.color=defaultColor;  }

         if (selectedColor) temp.scolor=selectedColor;
         if (defaultColor) temp.acolor=defaultColor;
         }
   };

/**
*     @desc: return node text
*     @param: itemId - id of node
*     @type: public
*     @return: text of item (with HTML formatting, if any)
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.getItemText=function(itemId)
   {
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      return(temp.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0].innerHTML);
   };
/**
*     @desc: return parent item id
*     @param: itemId - id of node
*     @type: public
*     @return: id of parent item
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.getParentId=function(itemId)
   {
      var temp=this._globalIdStorageFind(itemId);
      if ((!temp)||(!temp.parentObject)) return "";
      return temp.parentObject.id;
   };



/**
*     @desc: change item id
*     @type: public
*     @param: itemId - old node id
*     @param: newItemId - new node id
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.changeItemId=function(itemId,newItemId)
   {
    if (itemId==newItemId) return;
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
        temp.id=newItemId;
        temp.span.contextMenuId=newItemId;
        this._idpull[newItemId]=this._idpull[itemId];
        delete this._idpull[itemId];
   };


/**
*     @desc: mark selected item as cut
*     @type: public
*     @topic: 2
*/
   dhtmlXTreeObject.prototype.doCut=function(){
      if (this.nodeCut) this.clearCut();
      this.nodeCut=(new Array()).concat(this._selected);
        for (var i=0; i<this.nodeCut.length; i++){
          var tempa=this.nodeCut[i];
            tempa._cimgs=new Array();
          tempa._cimgs[0]=tempa.images[0];
          tempa._cimgs[1]=tempa.images[1];
          tempa._cimgs[2]=tempa.images[2];
          tempa.images[0]=tempa.images[1]=tempa.images[2]=this.cutImage;
          this._correctPlus(tempa);
        }
   };

/**
*     @desc: insert previously cut branch
*     @param: itemId - id of new parent node
*     @type: public
*     @topic: 2
*/
   dhtmlXTreeObject.prototype.doPaste=function(itemId){
      var tobj=this._globalIdStorageFind(itemId);
      if (!tobj) return 0;
        for (var i=0; i<this.nodeCut.length; i++){
               if (this._checkPNodes(tobj,this.nodeCut[i])) continue;
                this._moveNode(this.nodeCut[i],tobj);
               }
      this.clearCut();
   };

/**
*     @desc: clear cut
*     @type: public
*     @topic: 2
*/
   dhtmlXTreeObject.prototype.clearCut=function(){
      for (var i=0; i<this.nodeCut.length; i++)
         {
          var tempa=this.nodeCut[i];
          tempa.images[0]=tempa._cimgs[0];
          tempa.images[1]=tempa._cimgs[1];
          tempa.images[2]=tempa._cimgs[2];
          this._correctPlus(tempa);
         }
          this.nodeCut=new Array();
   };



   /**
*     @desc: move node with subnodes
*     @type: private
*     @param: itemObject - moved node object
*     @param: targetObject - new parent node
*     @topic: 2
*/
   dhtmlXTreeObject.prototype._moveNode=function(itemObject,targetObject){

      return this._moveNodeTo(itemObject,targetObject);

   }

   /**
*     @desc: fix order of nodes in collection
*     @type: private
*     @param: target - parent item node
*     @param: zParent - before node
*     @edition: Professional
*     @topic: 2
*/

dhtmlXTreeObject.prototype._fixNodesCollection=function(target,zParent){
      var flag=0; var icount=0;
      var Nodes=target.childNodes;
      var Count=target.childsCount-1;

      if (zParent==Nodes[Count]) return;
      for (var i=0; i<Count; i++)
         if (Nodes[i]==Nodes[Count]) {  Nodes[i]=Nodes[i+1]; Nodes[i+1]=Nodes[Count]; }

//         Count=target.childsCount;
      for (var i=0; i<Count+1; i++)
         {
         if (flag) {
            var temp=Nodes[i];
            Nodes[i]=flag;
            flag=temp;
               }
         else
         if (Nodes[i]==zParent) {   flag=Nodes[i]; Nodes[i]=Nodes[Count];  }
         }
   };

/**
*     @desc: recreate branch
*     @type: private
*     @param: itemObject - moved node object
*     @param: targetObject - new parent node
*     @param: level - top level flag
*     @param: beforeNode - node for sibling mode
*     @mode: mode - DragAndDrop mode (0 - as child, 1 as sibling)
*     @edition: Professional
*     @topic: 2
*/
dhtmlXTreeObject.prototype._recreateBranch=function(itemObject,targetObject,beforeNode,level){
    var i; var st="";
    if (beforeNode){
    for (i=0; i<targetObject.childsCount; i++)
        if (targetObject.childNodes[i]==beforeNode) break;

    if (i!=0)
        beforeNode=targetObject.childNodes[i-1];
    else{
        st="TOP";
        beforeNode="";
        }
    }

   var t2=this._onradh; this._onradh=null;
   var newNode=this._attachChildNode(targetObject,itemObject.id,itemObject.label,0,itemObject.images[0],itemObject.images[1],itemObject.images[2],st,0,beforeNode);

   //copy user data
   newNode._userdatalist=itemObject._userdatalist;
   newNode.userData=itemObject.userData.clone();
   newNode.XMLload=itemObject.XMLload;
   if (t2){
    this._onradh=t2; this._onradh(newNode.id); }


   for (var i=0; i<itemObject.childsCount; i++)
      this._recreateBranch(itemObject.childNodes[i],newNode,0,1);


   return newNode;
}

/**
*     @desc: move single node
*     @type: private
*     @param: itemObject - moved node object
*     @param: targetObject - new parent node
*     @mode: mode - DragAndDrop mode (0 - as child, 1 as sibling)
*     @topic: 2
*/
   dhtmlXTreeObject.prototype._moveNodeTo=function(itemObject,targetObject,beforeNode){
    //return;
    if   (itemObject.treeNod._nonTrivialNode)
        return itemObject.treeNod._nonTrivialNode(this,targetObject,beforeNode,itemObject);

    if    (targetObject.mytype)
       var framesMove=(itemObject.treeNod.lWin!=targetObject.lWin);
    else
          var framesMove=(itemObject.treeNod.lWin!=targetObject.treeNod.lWin);

   if (!this.callEvent("onDrag",[itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),itemObject.treeNod,targetObject.treeNod])) return false;
      if ((targetObject.XMLload==0)&&(this.XMLsource))
         {
         targetObject.XMLload=1;
            this._loadDynXML(targetObject.id);
         }
    this.openItem(targetObject.id);

   var oldTree=itemObject.treeNod;
   var c=itemObject.parentObject.childsCount;
   var z=itemObject.parentObject;


   if ((framesMove)||(oldTree.dpcpy)) {//interframe drag flag
        var _otiid=itemObject.id;
      itemObject=this._recreateBranch(itemObject,targetObject,beforeNode);
        if (!oldTree.dpcpy) oldTree.deleteItem(_otiid);
        }
   else
      {

      var Count=targetObject.childsCount; var Nodes=targetObject.childNodes;
            if (Count==0) targetObject._open=true;
            oldTree._unselectItem(itemObject);
           Nodes[Count]=itemObject;
            itemObject.treeNod=targetObject.treeNod;
            targetObject.childsCount++;

            var tr=this._drawNewTr(Nodes[Count].htmlNode);

            if (!beforeNode)
               {
                  targetObject.htmlNode.childNodes[0].appendChild(tr);
               if (this.dadmode==1) this._fixNodesCollection(targetObject,beforeNode);
               }
            else
               {
               targetObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr);
               this._fixNodesCollection(targetObject,beforeNode);
               Nodes=targetObject.childNodes;
               }


         }

            if ((!oldTree.dpcpy)&&(!framesMove))   {
                var zir=itemObject.tr;

                if ((document.all)&&(navigator.appVersion.search(/MSIE\ 5\.0/gi)!=-1))
                    {
                    window.setTimeout(function() { zir.parentNode.removeChild(zir); } , 250 );
                    }
                else   //if (zir.parentNode) zir.parentNode.removeChild(zir,true);

                itemObject.parentObject.htmlNode.childNodes[0].removeChild(itemObject.tr);

                //itemObject.tr.removeNode(true);
            if ((!beforeNode)||(targetObject!=itemObject.parentObject)){
               for (var i=0; i<z.childsCount; i++){
                  if (z.childNodes[i].id==itemObject.id) {
                  z.childNodes[i]=0;
                  break;            }}}
               else z.childNodes[z.childsCount-1]=0;

            oldTree._compressChildList(z.childsCount,z.childNodes);
            z.childsCount--;
            }


      if ((!framesMove)&&(!oldTree.dpcpy)) {
       itemObject.tr=tr;
      tr.nodem=itemObject;
      itemObject.parentObject=targetObject;

      if (oldTree!=targetObject.treeNod) {  if(itemObject.treeNod._registerBranch(itemObject,oldTree)) return;      this._clearStyles(itemObject);  this._redrawFrom(this,itemObject.parentObject);   };

      this._correctPlus(targetObject);
      this._correctLine(targetObject);

      this._correctLine(itemObject);
      this._correctPlus(itemObject);

         //fix target siblings
      if (beforeNode)
      {

         this._correctPlus(beforeNode);
         //this._correctLine(beforeNode);
      }
      else
      if (targetObject.childsCount>=2)
      {

         this._correctPlus(Nodes[targetObject.childsCount-2]);
         this._correctLine(Nodes[targetObject.childsCount-2]);
      }

      this._correctPlus(Nodes[targetObject.childsCount-1]);
      //this._correctLine(Nodes[targetObject.childsCount-1]);


      if (this.tscheck) this._correctCheckStates(targetObject);
      if (oldTree.tscheck) oldTree._correctCheckStates(z);

      }

      //fix source parent

      if (c>1) { oldTree._correctPlus(z.childNodes[c-2]);
               oldTree._correctLine(z.childNodes[c-2]);
               }


//      if (z.childsCount==0)
          oldTree._correctPlus(z);
            oldTree._correctLine(z);


      this.callEvent("onDrop",[itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),oldTree,targetObject.treeNod]);
      return itemObject.id;
   };



/**
*     @desc: recursive set default styles for node
*     @type: private
*     @param: itemObject - target node object
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._clearStyles=function(itemObject){
        if (!itemObject.htmlNode) return; //some weird case in SRND mode
         var td1=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[1];
         var td3=td1.nextSibling.nextSibling;

         itemObject.span.innerHTML=itemObject.label;
         itemObject.i_sel=false;

         if (itemObject._aimgs)
             this.dragger.removeDraggableItem(td1.nextSibling);

         if (this.checkBoxOff) {
            td1.childNodes[0].style.display="";
            td1.childNodes[0].onclick=this.onCheckBoxClick;
            this._setSrc(td1.childNodes[0],this.imPath+this.checkArray[itemObject.checkstate]);
            }
         else td1.childNodes[0].style.display="none";
         td1.childNodes[0].treeNod=this;

         this.dragger.removeDraggableItem(td3);
         if (this.dragAndDropOff) this.dragger.addDraggableItem(td3,this);
         if (this._aimgs) this.dragger.addDraggableItem(td1.nextSibling,this);

         td3.childNodes[0].className="standartTreeRow";
         td3.onclick=this.onRowSelect; td3.ondblclick=this.onRowClick2;
         td1.previousSibling.onclick=this.onRowClick;

         this._correctLine(itemObject);
         this._correctPlus(itemObject);
         for (var i=0; i<itemObject.childsCount; i++) this._clearStyles(itemObject.childNodes[i]);

   };
/**
*     @desc: register node and all children nodes
*     @type: private
*     @param: itemObject - node object
*     @topic: 2
*/
   dhtmlXTreeObject.prototype._registerBranch=function(itemObject,oldTree){
      if (oldTree) oldTree._globalIdStorageSub(itemObject.id);
      itemObject.id=this._globalIdStorageAdd(itemObject.id,itemObject);
      itemObject.treeNod=this;
         for (var i=0; i<itemObject.childsCount; i++)
            this._registerBranch(itemObject.childNodes[i],oldTree);
      return 0;
   };


/**
*     @desc: enable three state checkboxes
*     @beforeInit: 1
*     @param: mode - 1 - on, 0 - off;
*     @type: public
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableThreeStateCheckboxes=function(mode) { this.tscheck=convertStringToBoolean(mode); };


/**
*     @desc: set function called when mouse is over tree node
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event: onMouseIn
*     @depricated: use grid.attachEvent("onMouseIn",func); instead
*     @eventdesc: Event raised immideatly after mouse started moving over item
*     @eventparam:  ID of item
*/
   dhtmlXTreeObject.prototype.setOnMouseInHandler=function(func){
        this.ehlt=true;
        this.attachEvent("onMouseIn",func);
    };

/**
*     @desc: set function called when mouse is out of tree node
*     @param: func - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event: onMouseOut
*     @depricated: use grid.attachEvent("onMouseOut",func); instead
*     @eventdesc: Event raised immideatly after mouse moved out of item
*     @eventparam:  ID of clicked item
*/
   dhtmlXTreeObject.prototype.setOnMouseOutHandler=function(func){
        this.ehlt=true;
        this.attachEvent("onMouseOut",func);
    };









/**
*     @desc: enable tree images
*     @beforeInit: 1
*     @param: mode - 1 - on, 0 - off;
*     @type: public
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableTreeImages=function(mode) { this.timgen=convertStringToBoolean(mode); };



/**
*     @desc: enable mode with fixed tables (looks better, but has no horisontal scrollbar)
*     @beforeInit: 1
*     @param: mode - 1 - on, 0 - off;
*     @type: private
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableFixedMode=function(mode) { this.hfMode=convertStringToBoolean(mode); };

/**
*     @desc: show/hide checkboxes (all checkboxes in tree)
*     @type: public
*     @param: mode - true/false
*     @param: hidden - if set to true, checkboxes not rendered but can be shown by showItemCheckbox
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableCheckBoxes=function(mode, hidden){ this.checkBoxOff=convertStringToBoolean(mode); this.cBROf=(!(this.checkBoxOff||convertStringToBoolean(hidden)));
    };
/**
*     @desc: set default images for nodes (must be called before XML loading)
*     @type: public
*     @param: a0 - image for node without children;
*     @param: a1 - image for closed node;
*     @param: a2 - image for opened node
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.setStdImages=function(image1,image2,image3){
                  this.imageArray[0]=image1; this.imageArray[1]=image2; this.imageArray[2]=image3;};

/**
*     @desc: enable/disable tree lines (parent-child threads)
*     @type: public
*     @param: mode - enable/disable tree lines
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.enableTreeLines=function(mode){
      this.treeLinesOn=convertStringToBoolean(mode);
   }

/**
*     @desc: set images used for parent-child threads drawing (lines, plus, minus)
*     @type: public
*     @param: arrayName - name of array: plus, minus
*     @param: image1 - line crossed image
*     @param: image2 - image with top line
*     @param: image3 - image with bottom line
*     @param: image4 - image without line
*     @param: image5 - single root image
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.setImageArrays=function(arrayName,image1,image2,image3,image4,image5){
      switch(arrayName){
      case "plus": this.plusArray[0]=image1; this.plusArray[1]=image2; this.plusArray[2]=image3; this.plusArray[3]=image4; this.plusArray[4]=image5; break;
      case "minus": this.minusArray[0]=image1; this.minusArray[1]=image2; this.minusArray[2]=image3; this.minusArray[3]=image4;  this.minusArray[4]=image5; break;
      }
   };

/**
*     @desc: expand node
*     @param: itemId - id of node
*     @type: public
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.openItem=function(itemId){
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      else return this._openItem(temp);
   };

/**
*     @desc: expand node
*     @param: item - tree node object
*     @type: private
*     @editing: pro
*     @topic: 4
*/
   dhtmlXTreeObject.prototype._openItem=function(item){
           var state=this._getOpenState(item);
           if ((state<0)||(((this.XMLsource)&&(!item.XMLload)))){
               if    (!this.callEvent("onOpenStart",[item.id,state])) return 0;
               this._HideShow(item,2);
                   if    (this.checkEvent("onOpenEnd")){
                           if (this.onXLE==this._epnFHe) this._epnFHe(this,item.id,true);
                           if (!this.xmlstate || !this.XMLsource)
                                this.callEvent("onOpenEnd",[item.id,this._getOpenState(item)]);
                            else{
                                this._oie_onXLE.push(this.onXLE);
                                this.onXLE=this._epnFHe;
                                }
                            }
               } else if (this._srnd) this._HideShow(item,2);
           if (item.parentObject) this._openItem(item.parentObject);
   };

/**
*     @desc: collapse node
*     @param: itemId - id of node
*     @type: public
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.closeItem=function(itemId){
      if (this.rootId==itemId) return 0;
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
         if (temp.closeble)
            this._HideShow(temp,1);
   };


























/**
*     @desc: get node level (position in hierarchy)
*     @param: itemId - id of node
*     @type: public
*     @return: node level (0 if no such item in hierarchy - probably super root)
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.getLevel=function(itemId){
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      return this._getNodeLevel(temp,0);
   };



/**
*     @desc: prevent node from closing
*     @param: itemId - id of node
*     @param: flag -  if 0 - node can't be closed, else node can be closed
*     @type: public
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.setItemCloseable=function(itemId,flag)
   {
      flag=convertStringToBoolean(flag);
      if ((itemId)&&(itemId.span))
         var temp=itemId;
      else
         var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
         temp.closeble=flag;
   };

   /**
*     @desc: recursive function used for node level calculation
*     @param: itemObject - pointer to node object
*     @param: count - counter of levels
*     @type: private
*     @topic: 4
*/
   dhtmlXTreeObject.prototype._getNodeLevel=function(itemObject,count){
      if (itemObject.parentObject) return this._getNodeLevel(itemObject.parentObject,count+1);
      return(count);
   };

   /**
*     @desc: return number of children
*     @param: itemId - id of node
*     @type: public
*     @return: number of child items for loaded branches; true - for not loaded branches
*     @topic: 4
*/
   dhtmlXTreeObject.prototype.hasChildren=function(itemId){
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      else
         {
            if ( (this.XMLsource)&&(!temp.XMLload) ) return true;
            else
               return temp.childsCount;
         };
   };


   /**
*     @desc: get number of leafs (nodes without children)
*     @param: itemNode -  node object
*     @type: private
*     @edition: Professional
*     @topic: 4
*/
   dhtmlXTreeObject.prototype._getLeafCount=function(itemNode){
      var a=0;
      for (var b=0; b<itemNode.childsCount; b++)
         if (itemNode.childNodes[b].childsCount==0) a++;
      return a;
   }


/**
*     @desc: set new node text (HTML allowed)
*     @param: itemId - id of node
*     @param: newLabel - node text
*     @param: newTooltip - (optional)tooltip for the node
*     @type: public
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.setItemText=function(itemId,newLabel,newTooltip)
   {
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      temp.label=newLabel;
      temp.span.innerHTML=newLabel;

          temp.span.parentNode.parentNode.title=newTooltip||"";
   };

/**
*     @desc: get item's tooltip
*     @param: itemId - id of node
*     @type: public
*     @topic: 6
*/
    dhtmlXTreeObject.prototype.getItemTooltip=function(itemId){
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return "";
      return (temp.span.parentNode.parentNode._dhx_title||temp.span.parentNode.parentNode.title||"");
   };

/**
*     @desc: refresh tree branch from xml (XML with child nodes rerequested from server)
*     @param: itemId - id of node, if not defined tree super root used.
*     @type: public
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.refreshItem=function(itemId){
      if (!itemId) itemId=this.rootId;
      var temp=this._globalIdStorageFind(itemId);
      this.deleteChildItems(itemId);
        this._loadDynXML(itemId);
   };

   /**
*     @desc: set item images
*     @param: itemId - id of node
*     @param: image1 - node without children icon
*     @param: image2 - closed node icon
*     @param: image3 - open node icon
*     @type: public
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.setItemImage2=function(itemId, image1,image2,image3){
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
            temp.images[1]=image2;
            temp.images[2]=image3;
            temp.images[0]=image1;
      this._correctPlus(temp);
   };
/**
*     @desc: set item icons (mostly usefull for childless nodes)
*     @param: itemId - id of node
*     @param: image1 - node without children icon or closed node icon (if image2 specified)
*     @param: image2 - open node icon (optional)
*     @type: public
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.setItemImage=function(itemId,image1,image2)
   {
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
         if (image2)
         {
            temp.images[1]=image1;
            temp.images[2]=image2;
         }
         else temp.images[0]=image1;
      this._correctPlus(temp);
   };


/**
*     @desc: Returns the list of all subitems Ids from the next level of tree, separated by commas.
*     @param: itemId - id of node
*     @type: public
*     @return: list of all subitems from the next level of tree, separated by commas.
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.getSubItems =function(itemId)
   {
      var temp=this._globalIdStorageFind(itemId,0,1);
      if (!temp) return 0;

      var z="";
      for (i=0; i<temp.childsCount; i++){
         if (!z) z=temp.childNodes[i].id;
            else z+=this.dlmtr+temp.childNodes[i].id;

                                                         }

      return z;
   };




/**
*     @desc: Returns the list of all sub items from all next levels of tree, separated by commas.
*     @param: itemId - id of node
*     @edition: Professional
*     @type: private
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._getAllScraggyItems =function(node)
   {
      var z="";
      for (var i=0; i<node.childsCount; i++)
        {
            if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0))
            {
                    if (node.childNodes[i].unParsed)
                        var zb=this._getAllScraggyItemsXML(node.childNodes[i].unParsed,1);
                    else
                       var zb=this._getAllScraggyItems(node.childNodes[i])

                 if (zb)
                        if (z) z+=this.dlmtr+zb;
                        else z=zb;
         }
            else
               if (!z) z=node.childNodes[i].id;
             else z+=this.dlmtr+node.childNodes[i].id;
         }
          return z;
   };





/**
*     @desc: Returns the list of all children items from all next levels of tree, separated by commas.
*     @param: itemId - id of node
*     @type: private
*     @edition: Professional
*     @topic: 6
*/

   dhtmlXTreeObject.prototype._getAllFatItems =function(node)
   {
      var z="";
      for (var i=0; i<node.childsCount; i++)
        {
            if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0))
            {
             if (!z) z=node.childNodes[i].id;
                else z+=this.dlmtr+node.childNodes[i].id;

                    if (node.childNodes[i].unParsed)
                        var zb=this._getAllFatItemsXML(node.childNodes[i].unParsed,1);
                    else
                       var zb=this._getAllFatItems(node.childNodes[i])

                 if (zb) z+=this.dlmtr+zb;
         }
         }
          return z;
   };


/**
*     @desc: Returns the list of all children items from all next levels of tree, separated by commas.
*     @param: itemId - id of node
*     @type: private
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._getAllSubItems =function(itemId,z,node)
   {
      if (node) temp=node;
      else {
      var temp=this._globalIdStorageFind(itemId);
         };
      if (!temp) return 0;

      z="";
      for (var i=0; i<temp.childsCount; i++)
         {
         if (!z) z=temp.childNodes[i].id;
            else z+=this.dlmtr+temp.childNodes[i].id;
         var zb=this._getAllSubItems(0,z,temp.childNodes[i])

         if (zb) z+=this.dlmtr+zb;
         }


          return z;
   };





/**
*     @desc: select node ( and optionaly fire onselect event)
*     @type: public
*     @param: itemId - node id
*     @param: mode - If true, script function for selected node will be called.
*     @param: preserve - preserve earlier selected nodes
*     @topic: 1
*/
   dhtmlXTreeObject.prototype.selectItem=function(itemId,mode,preserve){
      mode=convertStringToBoolean(mode);
         var temp=this._globalIdStorageFind(itemId);
      if ((!temp)||(!temp.parentObject)) return 0;

            if (this.XMLloadingWarning)
                temp.parentObject.openMe=1;
            else
                this._openItem(temp.parentObject);

      //temp.onRowSelect(0,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],mode);
        var ze=null;
        if (preserve)  {
            ze=new Object; ze.ctrlKey=true;
            if (temp.i_sel) ze.skipUnSel=true;
        }
      if (mode)
         this.onRowSelect(ze,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],false);
      else
         this.onRowSelect(ze,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],true);
   };

/**
*     @desc: retun selected node text
*     @type: public
*     @return: text of selected node (or list of all selected nodes text if more than one selected)
*     @topic: 1
*/
   dhtmlXTreeObject.prototype.getSelectedItemText=function()
   {
        var str=new Array();
        for (var i=0; i<this._selected.length; i++) str[i]=this._selected[i].span.innerHTML;
      return (str.join(this.dlmtr));
   };




/**
*     @desc: correct childNode list after node deleting
*     @type: private
*     @param: Count - childNodes collection length
*     @param: Nodes - childNodes collection
*     @topic: 4
*/
   dhtmlXTreeObject.prototype._compressChildList=function(Count,Nodes)
   {
      Count--;
      for (var i=0; i<Count; i++)
      {
         if (Nodes[i]==0) { Nodes[i]=Nodes[i+1]; Nodes[i+1]=0;}
      };
   };
/**
*     @desc: delete node
*     @type: private
*     @param: itemId - target node id
*     @param: htmlObject - target node object
*     @param: skip - node unregistration mode (optional, used by private methods)
*     @topic: 2
*/
   dhtmlXTreeObject.prototype._deleteNode=function(itemId,htmlObject,skip){
   if ((!htmlObject)||(!htmlObject.parentObject)) return 0;
   var tempos=0; var tempos2=0;
   if (htmlObject.tr.nextSibling)  tempos=htmlObject.tr.nextSibling.nodem;
   if (htmlObject.tr.previousSibling)  tempos2=htmlObject.tr.previousSibling.nodem;

      var sN=htmlObject.parentObject;
      var Count=sN.childsCount;
      var Nodes=sN.childNodes;
            for (var i=0; i<Count; i++)
            {
               if (Nodes[i].id==itemId) {
               if (!skip) sN.htmlNode.childNodes[0].removeChild(Nodes[i].tr);
               Nodes[i]=0;
               break;
               }
            }
      this._compressChildList(Count,Nodes);
      if (!skip) {
        sN.childsCount--;
                 }

      if (tempos) {
      this._correctPlus(tempos);
      this._correctLine(tempos);
               }
      if (tempos2) {
      this._correctPlus(tempos2);
      this._correctLine(tempos2);
               }
      if (this.tscheck) this._correctCheckStates(sN);

      if (!skip) {
        this._globalIdStorageRecSub(htmlObject);
                 }
   };
/**
*     @desc: set state of node's checkbox
*     @type: public
*     @param: itemId - target node id
*     @param: state - checkbox state (0/1/"unsure")
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.setCheck=function(itemId,state){
      var sNode=this._globalIdStorageFind(itemId,0,1);
      if (!sNode) return;

        if (state==="unsure")
            this._setCheck(sNode,state);
        else
        {
      state=convertStringToBoolean(state);
        if ((this.tscheck)&&(this.smcheck)) this._setSubChecked(state,sNode);
      else this._setCheck(sNode,state);
        }
      if (this.smcheck)
         this._correctCheckStates(sNode.parentObject);
   };

   dhtmlXTreeObject.prototype._setCheck=function(sNode,state){
        if (!sNode) return;
        if (((sNode.parentObject._r_logic)||(this._frbtr))&&(state))
            if (this._frbtrs){
                if (this._frbtrL)   this.setCheck(this._frbtrL.id,0);
                this._frbtrL=sNode;
            } else
                for (var i=0; i<sNode.parentObject.childsCount; i++)
                    this._setCheck(sNode.parentObject.childNodes[i],0);

      var z=sNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0];

      if (state=="unsure") sNode.checkstate=2;
      else if (state) sNode.checkstate=1; else sNode.checkstate=0;
      if (sNode.dscheck) sNode.checkstate=sNode.dscheck;
      this._setSrc(z,this.imPath+((sNode.parentObject._r_logic||this._frbtr)?this.radioArray:this.checkArray)[sNode.checkstate]);
   };

/**
*     @desc: change state of node's checkbox and all children checkboxes
*     @type: public
*     @param: itemId - target node id
*     @param: state - checkbox state
*     @topic: 5
*/
dhtmlXTreeObject.prototype.setSubChecked=function(itemId,state){
   var sNode=this._globalIdStorageFind(itemId);
   this._setSubChecked(state,sNode);
   this._correctCheckStates(sNode.parentObject);
}



/**
*     @desc: change state of node's checkbox and all childnodes checkboxes
*     @type: private
*     @param: itemId - target node id
*     @param: state - checkbox state
*     @param: sNode - target node object (optional, used by private methods)
*     @topic: 5
*/
   dhtmlXTreeObject.prototype._setSubChecked=function(state,sNode){
      state=convertStringToBoolean(state);
      if (!sNode) return;
        if (((sNode.parentObject._r_logic)||(this._frbtr))&&(state))
            for (var i=0; i<sNode.parentObject.childsCount; i++)
                this._setSubChecked(0,sNode.parentObject.childNodes[i]);


        if (sNode._r_logic||this._frbtr)
           this._setSubChecked(state,sNode.childNodes[0]);
        else
      for (var i=0; i<sNode.childsCount; i++)
         {
             this._setSubChecked(state,sNode.childNodes[i]);
         };
      var z=sNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0];

      if (state) sNode.checkstate=1;
      else    sNode.checkstate=0;
      if (sNode.dscheck)  sNode.checkstate=sNode.dscheck;



      this._setSrc(z,this.imPath+((sNode.parentObject._r_logic||this._frbtr)?this.radioArray:this.checkArray)[sNode.checkstate]);
   };

/**
*     @desc: get state of nodes's checkbox
*     @type: public
*     @param: itemId - target node id
*     @return: node state (0 - unchecked,1 - checked, 2 - third state)
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.isItemChecked=function(itemId){
      var sNode=this._globalIdStorageFind(itemId);
      if (!sNode) return;
      return   sNode.checkstate;
   };







/**
*     @desc: delete all children of node
*     @type: public
*     @param: itemId - node id
*     @topic: 2
*/
    dhtmlXTreeObject.prototype.deleteChildItems=function(itemId)
   {
      var sNode=this._globalIdStorageFind(itemId);
      if (!sNode) return;
      var j=sNode.childsCount;
      for (var i=0; i<j; i++)
      {
         this._deleteNode(sNode.childNodes[0].id,sNode.childNodes[0]);
      };
   };

/**
*     @desc: delete node
*     @type: public
*     @param: itemId - node id
*     @param: selectParent - If true parent of deleted item get selection, else no selected items leaving in tree.
*     @topic: 2
*/
dhtmlXTreeObject.prototype.deleteItem=function(itemId,selectParent){
    if ((!this._onrdlh)||(this._onrdlh(itemId))){
        var z=this._deleteItem(itemId,selectParent);

    }

    //nb:solves standard doctype prb in IE
      this.allTree.childNodes[0].border = "1";
      this.allTree.childNodes[0].border = "0";
}
/**
*     @desc: delete node
*     @type: private
*     @param: id - node id
*     @param: selectParent - If true parent of deleted item get selection, else no selected items leaving in tree.
*     @param: skip - unregistering mode (optional, used by private methods)
*     @topic: 2
*/
dhtmlXTreeObject.prototype._deleteItem=function(itemId,selectParent,skip){
      selectParent=convertStringToBoolean(selectParent);
      var sNode=this._globalIdStorageFind(itemId);
      if (!sNode) return;
        var pid=this.getParentId(itemId);

      var zTemp=sNode.parentObject;
      this._deleteNode(itemId,sNode,skip);
      this._correctPlus(zTemp);
      this._correctLine(zTemp);

      if  ((selectParent)&&(pid!=this.rootId)) this.selectItem(pid,1);
      return    zTemp;
   };

/**
*     @desc: uregister all child nodes of target node
*     @type: private
*     @param: itemObject - node object
*     @topic: 3
*/
   dhtmlXTreeObject.prototype._globalIdStorageRecSub=function(itemObject){
      for(var i=0; i<itemObject.childsCount; i++)
      {
         this._globalIdStorageRecSub(itemObject.childNodes[i]);
         this._globalIdStorageSub(itemObject.childNodes[i].id);
      };
      this._globalIdStorageSub(itemObject.id);

          /*anti memory leaking*/
        var z=itemObject;
//      var par=z.span.parentNode.parentNode.childNodes;
//      par[0].parentObject=null;
//      par[1].childNodes[0].parentObject=null;
//      par[2].childNodes[0].parentObject=null;
//      par[2].childNodes[0].treeNod=null;
//      par[2].parentObject=null;
//      par[3].parentObject=null;
        z.span=null;
        z.tr.nodem=null;
        z.tr=null;
        z.htmlNode=null;
   };

/**
*     @desc: create new node next to specified
*     @type: public
*     @param: itemId - node id
*     @param: newItemId - new node id
*     @param: itemText - new node text
*     @param: itemActionHandler - function fired on node select event (optional)
*     @param: image1 - image for node without children; (optional)
*     @param: image2 - image for closed node; (optional)
*     @param: image3 - image for opened node (optional)
*     @param: optionStr - options string (optional)
*     @param: children - node children flag (for dynamical trees) (optional)
*     @topic: 2
*/
   dhtmlXTreeObject.prototype.insertNewNext=function(itemId,newItemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){
      var sNode=this._globalIdStorageFind(itemId);
      if ((!sNode)||(!sNode.parentObject)) return (0);

      var nodez=this._attachChildNode(0,newItemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children,sNode);

        return nodez;
   };



/**
*     @desc: retun node id by index
*     @type: public
*     @param: itemId - parent node id
*     @param: index - index of node, 0 based
*     @return: node id
*     @topic: 1
*/
   dhtmlXTreeObject.prototype.getItemIdByIndex=function(itemId,index){
       var z=this._globalIdStorageFind(itemId);
       if ((!z)||(index>z.childsCount)) return null;
          return z.childNodes[index].id;
   };

/**
*     @desc: retun child node id by index
*     @type: public
*     @param: itemId - parent node id
*     @param: index - index of child node
*     @return: node id
*     @topic: 1
*/
   dhtmlXTreeObject.prototype.getChildItemIdByIndex=function(itemId,index){
       var z=this._globalIdStorageFind(itemId);
       if ((!z)||(index>=z.childsCount)) return null;
          return z.childNodes[index].id;
   };





/**
*     @desc: set function called when drag-and-drop event occured
*     @param: aFunc - event handling function
*     @type: deprecated
*     @topic: 0,7
*     @event:    onDrag
*     @depricated: use grid.attachEvent("onDrag",func); instead
*     @eventdesc: Event occured after item was dragged and droped on another item, but before item moving processed.
      Event also raised while programmatic moving nodes.
*     @eventparam:  ID of source item
*     @eventparam:  ID of target item
*     @eventparam:  if node droped as sibling then contain id of item before whitch source node will be inserted
*     @eventparam:  source Tree object
*     @eventparam:  target Tree object
*     @eventreturn:  true - confirm drag-and-drop; false - deny drag-and-drop;
*/
   dhtmlXTreeObject.prototype.setDragHandler=function(func){ this.attachEvent("onDrag",func); };

   /**
*     @desc: clear selection from node
*     @param: htmlNode - pointer to node object
*     @type: private
*     @topic: 1
*/
    dhtmlXTreeObject.prototype._clearMove=function(){
        if (this._lastMark){
            this._lastMark.className=this._lastMark.className.replace(/dragAndDropRow/g,"");
            this._lastMark=null;
        }

        this.allTree.className=this.allTree.className.replace(" selectionBox","");
   };

   /**
*     @desc: enable/disable drag-and-drop
*     @type: public
*     @param: mode - enabled/disabled [ can be true/false/temporary_disabled - last value mean that tree can be D-n-D can be switched to true later ]
*     @param: rmode - enabled/disabled drag and drop on super root
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableDragAndDrop=function(mode,rmode){
        if  (mode=="temporary_disabled"){
            this.dADTempOff=false;
            mode=true;                  }
        else
            this.dADTempOff=true;

      this.dragAndDropOff=convertStringToBoolean(mode);
         if (this.dragAndDropOff) this.dragger.addDragLanding(this.allTree,this);
        if (arguments.length>1)
            this._ddronr=(!convertStringToBoolean(rmode));
       };

/**
*     @desc: set selection on node
*     @param: node - pointer to node object
*     @type: private
*     @topic: 1
*/
   dhtmlXTreeObject.prototype._setMove=function(htmlNode,x,y){
      if (htmlNode.parentObject.span) {
      //window.status=x;
      var a1=getAbsoluteTop(htmlNode);
      var a2=getAbsoluteTop(this.allTree);

      this.dadmodec=this.dadmode;//this.dadmode;
      this.dadmodefix=0;


            var zN=htmlNode.parentObject.span;
            zN.className+=" dragAndDropRow";
            this._lastMark=zN;

         this._autoScroll(null,a1,a2);

      }
   };

dhtmlXTreeObject.prototype._autoScroll=function(node,a1,a2){
         if (this.autoScroll)
         {
            if (node){
                a1=getAbsoluteTop(node);
                a2=getAbsoluteTop(this.allTree);
            }
            //scroll down
            if ( (a1-a2-parseInt(this.allTree.scrollTop))>(parseInt(this.allTree.offsetHeight)-50) )
               this.allTree.scrollTop=parseInt(this.allTree.scrollTop)+20;
            //scroll top
            if ( (a1-a2)<(parseInt(this.allTree.scrollTop)+30) )
               this.allTree.scrollTop=parseInt(this.allTree.scrollTop)-20;
         }
}

/**
*     @desc: create html element for dragging
*     @type: private
*     @param: htmlObject - html node object
*     @topic: 1
*/
dhtmlXTreeObject.prototype._createDragNode=function(htmlObject,e){
      if (!this.dADTempOff) return null;

     var obj=htmlObject.parentObject;
     if (!this.callEvent("onBeforeDrag",[obj.id])) return null;
    if (!obj.i_sel)
         this._selectItem(obj,e);


      var dragSpan=document.createElement('div');

            var text=new Array();
            if (this._itim_dg)
                    for (var i=0; i<this._selected.length; i++)
                        text[i]="<table cellspacing='0' cellpadding='0'><tr><td><img width='18px' height='18px' src='"+this._getSrc(this._selected[i].span.parentNode.previousSibling.childNodes[0])+"'></td><td>"+this._selected[i].span.innerHTML+"</td></tr><table>";
            else
                text=this.getSelectedItemText().split(this.dlmtr);

            dragSpan.innerHTML=text.join("");
         dragSpan.style.position="absolute";
         dragSpan.className="dragSpanDiv";
      this._dragged=(new Array()).concat(this._selected);
     return dragSpan;
}



/**
*     @desc: focus item in tree
*     @type: private
*     @param: item - node object
*     @edition: Professional
*     @topic: 0
*/
dhtmlXTreeObject.prototype._focusNode=function(item){
      var z=getAbsoluteTop(item.htmlNode)-getAbsoluteTop(this.allTree);
      if ((z>(this.allTree.scrollTop+this.allTree.offsetHeight-30))||(z<this.allTree.scrollTop))
      this.allTree.scrollTop=z;
   };













///DragAndDrop

dhtmlXTreeObject.prototype._preventNsDrag=function(e){
   if ((e)&&(e.preventDefault)) { e.preventDefault(); return false; }
   return false;
}

dhtmlXTreeObject.prototype._drag=function(sourceHtmlObject,dhtmlObject,targetHtmlObject){
      if (this._autoOpenTimer) clearTimeout(this._autoOpenTimer);

      if (!targetHtmlObject.parentObject){
            targetHtmlObject=this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0];
            this.dadmodec=0;
            }

      this._clearMove();
      var z=sourceHtmlObject.parentObject.treeNod;
        if ((z)&&(z._clearMove))   z._clearMove("");

       if ((!this.dragMove)||(this.dragMove()))
          {
              if ((!z)||(!z._clearMove)||(!z._dragged)) var col=new Array(sourceHtmlObject.parentObject);
              else var col=z._dragged;
                var trg=targetHtmlObject.parentObject;

                for (var i=0; i<col.length; i++){
                   var newID=this._moveNode(col[i],trg);
                   if ((this.dadmodec)&&(newID!==false)) trg=this._globalIdStorageFind(newID,true,true);
                   if ((newID)&&(!this._sADnD)) this.selectItem(newID,0,1);
                }

         }
        if (z) z._dragged=new Array();


}

dhtmlXTreeObject.prototype._dragIn=function(htmlObject,shtmlObject,x,y){

                    if (!this.dADTempOff) return 0;
                    var fobj=shtmlObject.parentObject;
                    var tobj=htmlObject.parentObject;
                    if ((!tobj)&&(this._ddronr)) return;
                    if (!this.callEvent("onDragIn",[fobj.id,tobj?tobj.id:null,fobj.treeNod,this]))
                        return 0;

                    if (!tobj)
                        this.allTree.className+=" selectionBox";
                    else
                    {
                        if (fobj.childNodes==null){
                            this._setMove(htmlObject,x,y);
                            return htmlObject;
                        }

                        var stree=fobj.treeNod;
                        for (var i=0; i<stree._dragged.length; i++)
                            if (this._checkPNodes(tobj,stree._dragged[i])){
                                this._autoScroll(htmlObject);
                                return 0;
                            }

                       this._setMove(htmlObject,x,y);
                       if (this._getOpenState(tobj)<=0){
                           this._autoOpenId=tobj.id;
                             this._autoOpenTimer=window.setTimeout(new callerFunction(this._autoOpenItem,this),1000);
                                    }
                    }

                return htmlObject;

}
dhtmlXTreeObject.prototype._autoOpenItem=function(e,treeObject){
   treeObject.openItem(treeObject._autoOpenId);
};
dhtmlXTreeObject.prototype._dragOut=function(htmlObject){
this._clearMove();
if (this._autoOpenTimer) clearTimeout(this._autoOpenTimer);
 }





//#complex_move:01112006{

/**
*     @desc: move item (inside of tree)
*     @type:  public
*     @param: itemId - item Id
*     @param: mode - moving mode (left,up,down,item_child,item_sibling,item_sibling_next,up_strict,down_strict)
*     @param: targetId - target Node in item_child and item_sibling mode
*     @param: targetTree - used for moving between trees (optional)
*     @return: node id
*     @topic: 2
*/
dhtmlXTreeObject.prototype.moveItem=function(itemId,mode,targetId,targetTree)
{
      var sNode=this._globalIdStorageFind(itemId);
      if (!sNode) return (0);

      switch(mode){
      case "right": alert('Not supported yet');
         break;
      case "item_child":
              var tNode=(targetTree||this)._globalIdStorageFind(targetId);
              if (!tNode) return (0);
            (targetTree||this)._moveNodeTo(sNode,tNode,0);
         break;
      case "item_sibling":
              var tNode=(targetTree||this)._globalIdStorageFind(targetId);
              if (!tNode) return (0);
            (targetTree||this)._moveNodeTo(sNode,tNode.parentObject,tNode);
         break;
      case "item_sibling_next":
              var tNode=(targetTree||this)._globalIdStorageFind(targetId);
              if (!tNode) return (0);
                  if ((tNode.tr)&&(tNode.tr.nextSibling)&&(tNode.tr.nextSibling.nodem))
                (targetTree||this)._moveNodeTo(sNode,tNode.parentObject,tNode.tr.nextSibling.nodem);
                else
                    (targetTree||this)._moveNodeTo(sNode,tNode.parentObject);
         break;
      case "left": if (sNode.parentObject.parentObject)
            this._moveNodeTo(sNode,sNode.parentObject.parentObject,sNode.parentObject);
         break;
      case "up": var z=this._getPrevNode(sNode);
               if ((z==-1)||(!z.parentObject)) return;
               this._moveNodeTo(sNode,z.parentObject,z);
         break;
      case "up_strict": var z=this._getIndex(sNode);
                          if (z!=0)
                         this._moveNodeTo(sNode,sNode.parentObject,sNode.parentObject.childNodes[z-1]);
         break;
      case "down_strict": var z=this._getIndex(sNode);
                            var count=sNode.parentObject.childsCount-2;
                            if (z==count)
                             this._moveNodeTo(sNode,sNode.parentObject);
                            else if (z<count)
                             this._moveNodeTo(sNode,sNode.parentObject,sNode.parentObject.childNodes[z+2]);
         break;
      case "down": var z=this._getNextNode(this._lastChild(sNode));
               if ((z==-1)||(!z.parentObject)) return;
               if (z.parentObject==sNode.parentObject)
                  var z=this._getNextNode(z);
                        if (z==-1){
                        this._moveNodeTo(sNode,sNode.parentObject);
                        }
                        else
                        {
                       if ((z==-1)||(!z.parentObject)) return;
                       this._moveNodeTo(sNode,z.parentObject,z);
                        }
         break;
      }
}


//#}







/**
*     @desc: load xml for tree branch
*     @param: id - id of parent node
*     @param: src - path to xml, optional
*     @type: private
*     @topic: 1
*/
   dhtmlXTreeObject.prototype._loadDynXML=function(id,src) {
        src=src||this.XMLsource;
        var sn=(new Date()).valueOf();
        this._ld_id=id;

            this.loadXML(src+getUrlSymbol(src)+"uid="+sn+"&id="+this._escape(id));
        };







/**
*     @desc: check possibility of drag-and-drop
*     @type: private
*     @param: itemId - draged node id
*     @param: htmlObject - droped node object
*     @param: shtmlObject - sourse node object
*     @topic: 6
*/
    dhtmlXTreeObject.prototype._checkPNodes=function(item1,item2){
      if (item2==item1) return 1
      if (item1.parentObject) return this._checkPNodes(item1.parentObject,item2); else return 0;
   };










/**
*   @desc:  prevent caching in IE  by adding random value to URL string
*   @param: mode - enable/disable random value ( disabled by default )
*   @type: public
*   @topic: 0
*/
dhtmlXTreeObject.prototype.preventIECaching=function(mode){
      this.no_cashe = convertStringToBoolean(mode);
      this.XMLLoader.rSeed=this.no_cashe;
}
dhtmlXTreeObject.prototype.preventIECashing=dhtmlXTreeObject.prototype.preventIECaching;





/**
*     @desc: disable checkbox
*     @param: itemId - Id of tree item
*     @param: mode - 1 - on, 0 - off;
*     @type: public
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.disableCheckbox=function(itemId,mode) {
            if (typeof(itemId)!="object")
             var sNode=this._globalIdStorageFind(itemId,0,1);
            else
                var sNode=itemId;
         if (!sNode) return;
            sNode.dscheck=convertStringToBoolean(mode)?(((sNode.checkstate||0)%3)+3):((sNode.checkstate>2)?(sNode.checkstate-3):sNode.checkstate);
            this._setCheck(sNode);
                if (sNode.dscheck<3) sNode.dscheck=false;
         };




/**
*     @desc: set escaping mode (used for escaping ID in requests)
*     @param: mode - escaping mode ("utf8" for UTF escaping)
*     @type: public
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.setEscapingMode=function(mode){
        this.utfesc=mode;
        }


/**
*     @desc: enable item highlighting (item text highlited on mouseover)
*     @beforeInit: 1
*     @param: mode - 1 - on, 0 - off;
*     @type: public
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableHighlighting=function(mode) { this.ehlt=true; this.ehlta=convertStringToBoolean(mode); };

/**
*     @desc: called on mouse out
*     @type: private
*     @topic: 0
*/
   dhtmlXTreeObject.prototype._itemMouseOut=function(){
        var that=this.childNodes[3].parentObject;
        var tree=that.treeNod;
        tree.callEvent("onMouseOut",[that.id]);
        if (that.id==tree._l_onMSI) tree._l_onMSI=null;
        if (!tree.ehlta) return;
        that.span.className=that.span.className.replace("_lor","");
   }
/**
*     @desc: called on mouse in
*     @type: private
*     @topic: 0
*/
   dhtmlXTreeObject.prototype._itemMouseIn=function(){
        var that=this.childNodes[3].parentObject;
        var tree=that.treeNod;

        if (tree._l_onMSI!=that.id) tree.callEvent("onMouseIn",[that.id]);
        tree._l_onMSI=that.id;
        if (!tree.ehlta) return;
        that.span.className=that.span.className.replace("_lor","");
        that.span.className=that.span.className.replace(/((standart|selected)TreeRow)/,"$1_lor");
   }

/**
*     @desc: enable active images (clickable and dragable). By default only text part of the node is active
*     @beforeInit: 1
*     @param: mode - 1 - on, 0 - off;
*     @type: public
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableActiveImages=function(mode){this._aimgs=convertStringToBoolean(mode); };

/**
*     @desc: focus item in tree (scroll to it if necessary)
*     @type: public
*     @param: itemId - item Id
*     @topic: 0
*/
dhtmlXTreeObject.prototype.focusItem=function(itemId){
      var sNode=this._globalIdStorageFind(itemId);
      if (!sNode) return (0);
      this._focusNode(sNode);
   };


/**
*     @desc: Returns the list of all children from all next levels of tree, separated by default delimiter.
*     @param: itemId - id of node
*     @type: public
*     @return: list of all children items from all next levels of tree, separated by default delimiter
*     @topic: 6
*/
   dhtmlXTreeObject.prototype.getAllSubItems =function(itemId){
      return this._getAllSubItems(itemId);
   }

/**
*     @desc: Returns the list of all items which doesn't have child nodes.
*     @type: public
*     @return: list of all items which doesn't have child nodes.
*     @topic: 6
*/
    dhtmlXTreeObject.prototype.getAllChildless =function(){
        return this._getAllScraggyItems(this.htmlNode);
    }
    dhtmlXTreeObject.prototype.getAllLeafs=dhtmlXTreeObject.prototype.getAllChildless;


/**
*     @desc: Returns the list of all children from all next levels of tree, separated by default delimiter.
*     @param: itemId - id of node
*     @edition: Professional
*     @type: private
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._getAllScraggyItems =function(node)
   {
      var z="";
      for (var i=0; i<node.childsCount; i++)
        {
            if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0))
            {
                    if (node.childNodes[i].unParsed)
                        var zb=this._getAllScraggyItemsXML(node.childNodes[i].unParsed,1);
                    else
                       var zb=this._getAllScraggyItems(node.childNodes[i])

                 if (zb)
                        if (z) z+=this.dlmtr+zb;
                        else z=zb;
         }
            else
               if (!z) z=node.childNodes[i].id;
             else z+=this.dlmtr+node.childNodes[i].id;
         }
          return z;
   };





/**
*     @desc: Returns the list of all children from all next levels of tree, separated by default delimiter.
*     @param: itemId - id of node
*     @type: private
*     @edition: Professional
*     @topic: 6
*/
   dhtmlXTreeObject.prototype._getAllFatItems =function(node)
   {
      var z="";
      for (var i=0; i<node.childsCount; i++)
        {
            if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0))
            {
             if (!z) z=node.childNodes[i].id;
                else z+=this.dlmtr+node.childNodes[i].id;

                    if (node.childNodes[i].unParsed)
                        var zb=this._getAllFatItemsXML(node.childNodes[i].unParsed,1);
                    else
                       var zb=this._getAllFatItems(node.childNodes[i])

                 if (zb) z+=this.dlmtr+zb;
         }
         }
          return z;
   };

/**
*     @desc: Returns the list of all items which have child nodes, separated by default delimiter.
*     @type: public
*     @return: list of all items which has child nodes, separated by default delimiter.
*     @topic: 6
*/
    dhtmlXTreeObject.prototype.getAllItemsWithKids =function(){
        return this._getAllFatItems(this.htmlNode);
    }
    dhtmlXTreeObject.prototype.getAllFatItems=dhtmlXTreeObject.prototype.getAllItemsWithKids;



/**
*     @desc: return list of identificators of nodes with checked checkboxes, separated by default delimiter
*     @type: public
*     @return: list of ID of items with checked checkboxes, separated by default delimiter
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.getAllChecked=function(){
      return this._getAllChecked("","",1);
   }
/**
*     @desc: return list of identificators of nodes with unchecked checkboxes, separated by default delimiter
*     @type: public
*     @return: list of ID of items with unchecked checkboxes, separated by default delimiter
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.getAllUnchecked=function(itemId){
        if (itemId)
            itemId=this._globalIdStorageFind(itemId);
      return this._getAllChecked(itemId,"",0);
    }


/**
*     @desc: return list of identificators of nodes with third state checkboxes, separated by default delimiter
*     @type: public
*     @return: list of ID of items with third state checkboxes, separated by default delimiter
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.getAllPartiallyChecked=function(){
      return this._getAllChecked("","",2);
   }


/**
*     @desc: return list of identificators of nodes with checked and third state checkboxes, separated by default delimiter
*     @type: public
*     @return: list of ID of items with checked and third state checkboxes, separated by default delimiter
*     @topic: 5
*/
   dhtmlXTreeObject.prototype.getAllCheckedBranches=function(){
        var temp= this._getAllChecked("","",1);
        if (temp!="") temp+=this.dlmtr;
         return temp+this._getAllChecked("","",2);
   }

/**
*     @desc: return list of identificators of nodes with checked checkboxes
*     @type: private
*     @param: node - node object (optional, used by private methods)
*     @param: list - initial identificators list (optional, used by private methods)
*     @topic: 5
*/
   dhtmlXTreeObject.prototype._getAllChecked=function(htmlNode,list,mode){
      if (!htmlNode) htmlNode=this.htmlNode;

      if (htmlNode.checkstate==mode)
         if (!htmlNode.nocheckbox)  { if (list) list+=this.dlmtr+htmlNode.id; else list=htmlNode.id;  }
      var j=htmlNode.childsCount;
      for (var i=0; i<j; i++)
      {
         list=this._getAllChecked(htmlNode.childNodes[i],list,mode);
      };


      if (list) return list; else return "";
   };

/**
*     @desc: set individual item style
*     @type: public
*     @param: itemId - node id
*     @param: style_string - valid CSS string
*     @topic: 2
*/
dhtmlXTreeObject.prototype.setItemStyle=function(itemId,style_string){
      var temp=this._globalIdStorageFind(itemId);
      if (!temp) return 0;
      if (!temp.span.style.cssText)
            temp.span.setAttribute("style",temp.span.getAttribute("style")+"; "+style_string);
        else
          temp.span.style.cssText+=(";"+style_string);
}

/**
*     @desc: enable draging item image with item text
*     @type: public
*     @param: mode - true/false
*     @topic: 1
*/
dhtmlXTreeObject.prototype.enableImageDrag=function(mode){
    this._itim_dg=convertStringToBoolean(mode);
}

/**
*     @desc: set function called when tree item draged over another item
*     @param: func - event handling function
*     @type: depricated
*     @edition: Professional
*     @topic: 4
*     @event: onDragIn
*     @depricated: use grid.attachEvent("onDragIn",func); instead
*     @eventdesc: Event raised when item draged other other dropable target
*     @eventparam:  ID draged item
*     @eventparam:  ID potencial drop landing
*     @eventparam:  source object
*     @eventparam:  target object
*     @eventreturn: true - allow drop; false - deny drop;
*/
    dhtmlXTreeObject.prototype.setOnDragIn=function(func){
        this.attachEvent("onDragIn",func);
        };

/**
*     @desc: enable/disable auto scrolling while drag-and-drop
*     @type: public
*     @param: mode - enabled/disabled
*     @topic: 0
*/
   dhtmlXTreeObject.prototype.enableDragAndDropScrolling=function(mode){ this.autoScroll=convertStringToBoolean(mode); };


dhtmlXTreeObject.prototype.setSkin=function(name){
    this.parentObject.className+=" dhxtree_"+name;
}
dhtmlXTreeObject.prototype.dhx_Event=function()
{
   this.dhx_SeverCatcherPath="";

   this.attachEvent = function(original, catcher, CallObj)
   {
      if (this._onEventSet && this._onEventSet[original])
        this._onEventSet[original].apply(this,[]);

      CallObj = CallObj||this;
      original = 'ev_'+original;
       if ( ( !this[original] ) || ( !this[original].addEvent ) ) {
           var z = new this.eventCatcher(CallObj);
           z.addEvent( this[original] );
           this[original] = z;
       }
       return ( original + ':' + this[original].addEvent(catcher) );   //return ID (event name & event ID)
   }
   this.callEvent=function(name,a){
         if (this["ev_"+name]) return this["ev_"+name].apply(this,a);
         return true;
   }
   this.checkEvent=function(name){
         if (this["ev_"+name]) return true;
         return false;
   }

   this.eventCatcher = function(obj)
   {
       var dhx_catch = new Array();
       var m_obj = obj;
       var z = function()
             {
                   if (dhx_catch)
                      var res=true;
                   for (var i=0; i<dhx_catch.length; i++) {
                      if (dhx_catch[i] != null) {
                           var zr = dhx_catch[i].apply( m_obj, arguments );
                           res = res && zr;
                      }
                   }
                   return res;
                }
       z.addEvent = function(ev)
                {
                       if ( typeof(ev) != "function" )
                               ev = eval(ev);
                       if (ev)
                           return dhx_catch.push( ev ) - 1;
                       return false;
                }
       z.removeEvent = function(id)
                   {
                     dhx_catch[id] = null;
                   }
       return z;
   }

   this.detachEvent = function(id)
   {
      if (id != false) {
         var list = id.split(':');            //get EventName and ID
         this[ list[0] ].removeEvent( list[1] );   //remove event
      }
   }
}
//(c)dhtmlx ltd. www.dhtmlx.com

//v.2.0 build 81107

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/*_TOPICS_
@0:initialization
@1:selection control
@2:rows control
@3:colums control
@4:cells controll
@5:data manipulation
@6:appearence control
@7:overal control
@8:tools
@9:treegrid
@10: event handlers
@11: paginal output
*/

var globalActiveDHTMLGridObject;
String.prototype._dhx_trim=function(){
    return this.replace(/&nbsp;/g, " ").replace(/(^[ \t]*)|([ \t]*$)/g, "");
}

function dhtmlxArray(ar){
    return dhtmlXHeir((ar||new Array()), dhtmlxArray._master);
};
dhtmlxArray._master={
    _dhx_find:function(pattern){
        for (var i = 0; i < this.length; i++){
            if (pattern == this[i])
                return i;
        }
        return -1;
    },
    _dhx_insertAt:function(ind, value){
        this[this.length]=null;
        for (var i = this.length-1; i >= ind; i--)
            this[i]=this[i-1]
        this[ind]=value
    },
    _dhx_removeAt:function(ind){
            this.splice(ind,1)
    },
    _dhx_swapItems:function(ind1, ind2){
        var tmp = this[ind1];
        this[ind1]=this[ind2]
        this[ind2]=tmp;
    }
}

/**
*   @desc: dhtmlxGrid constructor
*   @param: id - (optional) id of div element to base grid on
*   @returns: dhtmlxGrid object
*   @type: public
*/
function dhtmlXGridObject(id){
    if (_isIE)
        try{
            document.execCommand("BackgroundImageCache", false, true);
        }
        catch (e){}

    if (id){
        if (typeof (id) == 'object'){
            this.entBox=id
            this.entBox.id="cgrid2_"+this.uid();
        } else
            this.entBox=document.getElementById(id);
    } else {
        this.entBox=document.createElement("DIV");
        this.entBox.id="cgrid2_"+this.uid();
    }
    this.entBox.innerHTML="";
    this.dhx_Event();

    var self = this;

    this._wcorr=0;
    this.cell=null;
    this.row=null;
    this.iconURL="";
    this.editor=null;
    this._f2kE=true;
    this._dclE=true;
    this.combos=new Array(0);
    this.defVal=new Array(0);
    this.rowsAr={
    };

    this.rowsBuffer=dhtmlxArray();
    this.rowsCol=dhtmlxArray(); //array of rows by index

    this._data_cache={
    };

    this._ecache={
    }

    this._ud_enabled=true;
    this.xmlLoader=new dtmlXMLLoaderObject(this.doLoadDetails, this, true, this.no_cashe);

    this._maskArr=[];
    this.selectedRows=dhtmlxArray(); //selected rows array

    this.UserData={};//hash of row related userdata (and for grid - "gridglobaluserdata")
    this._sizeFix=this._borderFix=0;
    /*MAIN OBJECTS*/

    this.entBox.className+=" gridbox";

    this.entBox.style.width=this.entBox.getAttribute("width")
        ||(window.getComputedStyle
            ? (this.entBox.style.width||window.getComputedStyle(this.entBox, null)["width"])
            : (this.entBox.currentStyle
                ? this.entBox.currentStyle["width"]
                : this.entBox.style.width||0))
        ||"100%";

    this.entBox.style.height=this.entBox.getAttribute("height")
        ||(window.getComputedStyle
            ? (this.entBox.style.height||window.getComputedStyle(this.entBox, null)["height"])
            : (this.entBox.currentStyle
                ? this.entBox.currentStyle["height"]
                : this.entBox.style.height||0))
        ||"100%";
    //cursor and text selection
    this.entBox.style.cursor='default';

    this.entBox.onselectstart=function(){
        return false
    }; //avoid text select
    this.obj=document.createElement("TABLE");
    this.obj.cellSpacing=0;
    this.obj.cellPadding=0;
    this.obj.style.width="100%"; //nb:
    this.obj.style.tableLayout="fixed";
    this.obj.className="c_obj".substr(2);

    this.hdr=document.createElement("TABLE");
    this.hdr.style.border="1px solid gray"; //FF 1.0 fix
    this.hdr.cellSpacing=0;
    this.hdr.cellPadding=0;

    if ((!_isOpera)||(_OperaRv >= 8.5))
        this.hdr.style.tableLayout="fixed";
    this.hdr.className="c_hdr".substr(2);
    this.hdr.width="100%";

    this.xHdr=document.createElement("TABLE");
    this.xHdr.className="xhdr";
    this.xHdr.cellPadding=0;
    this.xHdr.cellSpacing=0;
    this.xHdr.style.width='100%'
    var r = this.xHdr.insertRow(0)
    var c = r.insertCell(0);
    r.insertCell(1).innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    r.childNodes[1].style.width='100%';
    r.childNodes[1].className='xhdr_last';
    c.appendChild(this.hdr)
    this.objBuf=document.createElement("DIV");
    this.objBuf.appendChild(this.obj);
    this.entCnt=document.createElement("TABLE");
    this.entCnt.insertRow(0).insertCell(0)
    this.entCnt.insertRow(1).insertCell(0);

    this.entCnt.cellPadding=0;
    this.entCnt.cellSpacing=0;
    this.entCnt.width="100%";
    this.entCnt.height="100%";

    this.entCnt.style.tableLayout="fixed";

    this.objBox=document.createElement("DIV");
    this.objBox.style.width="100%";
    this.objBox.style.height=this.entBox.style.height;
    this.objBox.style.overflow="auto";
    this.objBox.style.position="relative";
    this.objBox.appendChild(this.objBuf);
    this.objBox.className="objbox";

    this.hdrBox=document.createElement("DIV");
    this.hdrBox.style.width="100%"

    if (((_isOpera)&&(_OperaRv < 9)))
        this.hdrSizeA=25;
    else
        this.hdrSizeA=200;

    this.hdrBox.style.height=this.hdrSizeA+"px";

    if (_isIE)
        this.hdrBox.style.overflowX="hidden";
    else
        this.hdrBox.style.overflow="hidden";

    this.hdrBox.style.position="relative";
    this.hdrBox.appendChild(this.xHdr);

    this.preloadImagesAr=new Array(0)

    this.sortImg=document.createElement("IMG")
    this.sortImg.style.display="none";
    this.hdrBox.insertBefore(this.sortImg, this.xHdr)
    this.entCnt.rows[0].cells[0].style.verticalAlign="top";
    this.entCnt.rows[0].cells[0].appendChild(this.hdrBox);
    this.entCnt.rows[1].cells[0].appendChild(this.objBox);

    this.entBox.appendChild(this.entCnt);
    //add links to current object
    this.entBox.grid=this;
    this.objBox.grid=this;
    this.hdrBox.grid=this;
    this.obj.grid=this;
    this.hdr.grid=this;
    /*PROPERTIES*/
    this.cellWidthPX=new Array(0);                      //current width in pixels
    this.cellWidthPC=new Array(0);                      //width in % if cellWidthType set in pc
    this.cellWidthType=this.entBox.cellwidthtype||"px"; //px or %

    this.delim=this.entBox.delimiter||",";
    this._csvDelim=",";

    this.hdrLabels=[];
    this.columnIds=[];
    this.columnColor=[];
    this.cellType=dhtmlxArray();
    this.cellAlign=[];
    this.initCellWidth=[];
    this.fldSort=[];
    this.imgURL="./";
    this.isActive=false; //fl to indicate if grid is in work now
    this.isEditable=true;
    this.useImagesInHeader=false; //use images in header or not
    this.pagingOn=false;          //paging on/off
    this.rowsBufferOutSize=0;     //number of rows rendered at a moment
    /*EVENTS*/
    dhtmlxEvent(window, "unload", function(){
        try{
            self.destructor();
        }
        catch (e){}
    });

    /*XML LOADER(S)*/
    /**
    *   @desc: set one of predefined css styles (xp, mt, gray, light, clear, modern)
    *   @param: name - style name
    *   @type: public
    *   @topic: 0,6
    */
    this.setSkin=function(name){
        this.entBox.className="gridbox gridbox_"+name;
//#alter_css:06042008{
        this.enableAlterCss("ev_"+name, "odd_"+name, this.isTreeGrid())
        this._fixAlterCss()
//#}
        this._sizeFix=this._borderFix=0;

        switch (name){
            case "clear":
                this._topMb=document.createElement("DIV");
                this._topMb.className="topMumba";
                this._topMb.innerHTML="<img style='left:0px'   src='"+this.imgURL
                    +"skinC_top_left.gif'><img style='right:0px' src='"+this.imgURL+"skinC_top_right.gif'>";
                this.entBox.appendChild(this._topMb);
                this._botMb=document.createElement("DIV");
                this._botMb.className="bottomMumba";
                this._botMb.innerHTML="<img style='left:0px'   src='"+this.imgURL
                    +"skinD_bottom_left.gif'><img style='right:0px' src='"+this.imgURL+"skinD_bottom_right.gif'>";
                this.entBox.appendChild(this._botMb);
                this.entBox.style.position="relative";
                this._gcCorr=20;
                break;

            case "glassy_blue":
                this.forceDivInHeader=true;
                break;
            case "dhx_black":
            case "dhx_blue":
            case "modern":
            case "newmodern":
            case "light":
                this._sizeFix=1;
                this.forceDivInHeader=true;
				this._srdh=25;
                break;

            case "xp":
                this.forceDivInHeader=true;
                this._srdh=22;
                if ((_isIE)&&(document.compatMode != "BackCompat"))
                    this._srdh=25;

                this._sizeFix=1;
                break;

            case "mt":
                this._srdh=22;
                if ((_isIE)&&(document.compatMode != "BackCompat"))
                    this._srdh=25;

                this._sizeFix=1;
                this._borderFix=(_isIE ? 1 : 0);
                break;

            case "gray":
                if ((_isIE)&&(document.compatMode != "BackCompat"))
                    this._srdh=22;
                this._sizeFix=1;
                this._borderFix=(_isIE ? 1 : 0);
                break;
            case "sbdark":
                if (_isFF) this._gcCorr=1;
                break;
        }

        if (_isIE&&this.hdr){
            var d = this.hdr.parentNode;
            d.removeChild(this.hdr);
            d.appendChild(this.hdr);
        }
        this.setSizes();
    }

    if (_isIE)
        this.preventIECaching(true);
    if (window.dhtmlDragAndDropObject)
        this.dragger=new dhtmlDragAndDropObject();

    /*METHODS. SERVICE*/
    /**
    *   @desc: on scroll grid inner actions
    *   @type: private
    *   @topic: 7
    */
    this._doOnScroll=function(e, mode){
        this.callEvent("onScroll", [
            this.objBox.scrollLeft,
            this.objBox.scrollTop
        ]);

        this.doOnScroll(e, mode);
    }
    /**
    *   @desc: on scroll grid more inner action
    *   @type: private
    *   @topic: 7
    */
    this.doOnScroll=function(e, mode){
        this.hdrBox.scrollLeft=this.objBox.scrollLeft;

        if (this.ftr)
            this.ftr.parentNode.scrollLeft=this.objBox.scrollLeft;

        if (mode)
            return;

        if (this._srnd){
            if (this._dLoadTimer)
                window.clearTimeout(this._dLoadTimer);
            this._dLoadTimer=window.setTimeout(function(){
                self._update_srnd_view();
            }, 100);
        }
    }
    /**
    *    @desc: attach grid to some object in DOM
    *    @param: obj - object to attach to
    *   @type: public
    *   @topic: 0,7
    */
    this.attachToObject=function(obj){
        obj.appendChild(this.entBox)
        this.objBox.style.height=this.entBox.style.height;
    }
    /**
    *   @desc: initialize grid
    *   @param: fl - if to parse on page xml data island
    *   @type: public
    *   @topic: 0,7
    */
    this.init=function(fl){
        if ((this.isTreeGrid())&&(!this._h2)){
            this._h2=new dhtmlxHierarchy();

            if ((this._fake)&&(!this._realfake))
                this._fake._h2=this._h2;
            this._tgc={
                imgURL: null
                };
        }

        if (!this._hstyles)
            return;

        this.editStop()
        /*TEMPORARY STATES*/
        this.lastClicked=null;                //row clicked without shift key. used in multiselect only
        this.resized=null;                    //hdr cell that is resized now
        this.fldSorted=this.r_fldSorted=null; //hdr cell last sorted
        this.gridWidth=0;
        this.gridHeight=0;
        //empty grid if it already was initialized
        this.cellWidthPX=new Array(0);
        this.cellWidthPC=new Array(0);

        if (this.hdr.rows.length > 0){
            this.clearAll(true);
        }

        var hdrRow = this.hdr.insertRow(0);

        for (var i = 0; i < this.hdrLabels.length; i++){
            hdrRow.appendChild(document.createElement("TH"));
            hdrRow.childNodes[i]._cellIndex=i;
            hdrRow.childNodes[i].style.height="0px";
        }

        if (_isIE)
            hdrRow.style.position="absolute";
        else
            hdrRow.style.height='auto';

        var hdrRow = this.hdr.insertRow(_isKHTML ? 2 : 1);

        hdrRow._childIndexes=new Array();
        var col_ex = 0;

        for (var i = 0; i < this.hdrLabels.length; i++){
            hdrRow._childIndexes[i]=i-col_ex;

            if ((this.hdrLabels[i] == this.splitSign)&&(i != 0)){
                if (_isKHTML)
                    hdrRow.insertCell(i-col_ex);
                hdrRow.cells[i-col_ex-1].colSpan=(hdrRow.cells[i-col_ex-1].colSpan||1)+1;
                hdrRow.childNodes[i-col_ex-1]._cellIndex++;
                col_ex++;
                hdrRow._childIndexes[i]=i-col_ex;
                continue;
            }

            hdrRow.insertCell(i-col_ex);

            hdrRow.childNodes[i-col_ex]._cellIndex=i;
            hdrRow.childNodes[i-col_ex]._cellIndexS=i;
            this.setColumnLabel(i, this.hdrLabels[i]);
        }

        if (col_ex == 0)
            hdrRow._childIndexes=null;
        this._cCount=this.hdrLabels.length;

        if (_isIE)
            window.setTimeout(function(){
                self.setSizes();
            }, 1);

        //create virtual top row
        if (!this.obj.firstChild)
            this.obj.appendChild(document.createElement("TBODY"));

        var tar = this.obj.firstChild;

        if (!tar.firstChild){
            tar.appendChild(document.createElement("TR"));
            tar=tar.firstChild;

            if (_isIE)
                tar.style.position="absolute";
            else
                tar.style.height='auto';

            for (var i = 0; i < this.hdrLabels.length; i++){
                tar.appendChild(document.createElement("TH"));
                tar.childNodes[i].style.height="0px";
            }
        }

        this._c_order=null;

        if (this.multiLine != true)
            this.obj.className+=" row20px";

        //
        //this.combos = new Array(this.hdrLabels.length);
        //set sort image to initial state
        this.sortImg.style.position="absolute";
        this.sortImg.style.display="none";
        this.sortImg.src=this.imgURL+"sort_desc.gif";
        this.sortImg.defLeft=0;
        //create and kill a row to set initial size
        //this.addRow("deletethisrtowafterresize",new Array("",""))
        this.entCnt.rows[0].style.display='' //display header

        if (this.noHeader){
            this.entCnt.rows[0].style.display='none';
        }
        else {
            this.noHeader=false
        }

//#header_footer:06042008{
        this.attachHeader();
        this.attachHeader(0, 0, "_aFoot");
//#}
        this.setSizes();

        if (fl)
            this.parseXML()
        this.obj.scrollTop=0

        if (this.dragAndDropOff)
            this.dragger.addDragLanding(this.entBox, this);

        if (this._initDrF)
            this._initD();

        if (this._init_point)
            this._init_point();
    };
    /**
    *    @desc: sets sizes of grid elements
    *   @type: private
    *   @topic: 0,7
    */
    this.setSizes=function(fl){
        if ((!this.hdr.rows[0]))
            return;

        if (!this.entBox.offsetWidth){
            if (this._sizeTime)
                window.clearTimeout(this._sizeTime);
            this._sizeTime=window.setTimeout(function(){
                self.setSizes()
            }, 250);
            return;
        }

        if (((_isFF)&&(this.entBox.style.height == "100%"))||(this._fixLater)){
            this.entBox.style.height=this.entBox.parentNode.clientHeight;
            this._fixLater=true;
        }

        if (fl&&this.gridWidth == this.entBox.offsetWidth&&this.gridHeight == this.entBox.offsetHeight){
            return false
        } else if (fl){
            this.gridWidth=this.entBox.offsetWidth
            this.gridHeight=this.entBox.offsetHeight
        }

        if ((!this.hdrBox.offsetHeight)&&(this.hdrBox.offsetHeight > 0))
            this.entCnt.rows[0].cells[0].height=this.hdrBox.offsetHeight+"px";

        var gridWidth = parseInt(this.entBox.offsetWidth)-(this._gcCorr||0);
        var gridHeight = parseInt(this.entBox.offsetHeight)-(this._sizeFix||0);

        var _isVSroll = (this.objBox.scrollHeight > this.objBox.offsetHeight);

        if (((!this._ahgr)&&(_isVSroll))||((this._ahgrM)&&(this._ahgrM < this.objBox.scrollHeight)))
            gridWidth-=(this._scrFix||(_isFF ? 17 : 17));

        var len = this.hdr.rows[0].cells.length
        //                var pcx_widht=(this._fake?(gridWidth-this._fake.entBox.offsetWidth):gridWidth);

        for (var i = 0; i < this._cCount; i++){
            if (this.cellWidthType == 'px'&&this.cellWidthPX.length < len){
                this.cellWidthPX[i]=this.initCellWidth[i]-this._wcorr;
            }
            else if (this.cellWidthType == '%'&&this.cellWidthPC.length < len){
                this.cellWidthPC[i]=this.initCellWidth[i];
            }

            if (this.cellWidthType == '%'&&this.cellWidthPC.length != 0&&this.cellWidthPC[i]){
                this.cellWidthPX[i]=parseInt(gridWidth*this.cellWidthPC[i] / 100);
            }
        }

        var wcor = this.entBox.offsetWidth-this.entBox.clientWidth;

        var summ = 0;
        var fcols = new Array();

        for (var i = 0; i < this._cCount; i++)
            if ((this.initCellWidth[i] == "*")&&((!this._hrrar)||(!this._hrrar[i])))
                fcols[fcols.length]=i;
            else
                summ+=parseInt(this.cellWidthPX[i]);

        if (fcols.length){
            var ms = Math.floor((gridWidth-summ-wcor) / fcols.length);

            if (ms < 0)
                ms=1;

            for (var i = 0; i < fcols.length; i++){
                var min = (this._drsclmW ? this._drsclmW[fcols[i]] : 0);
                this.cellWidthPX[fcols[i]]=(min ? (min > ms ? min : ms) : ms)-this._wcorr;
                summ+=ms;
            }
            if (!this._rseb){
                this._setAutoResize();
                this._rseb=true;
            }
        }

        var summ = 0;

        for (var i = 0; i < this._cCount; i++)summ+=parseInt(this.cellWidthPX[i])

        if (_isOpera)
            summ-=1;

        this.chngCellWidth();

        if ((this._awdth)&&(this._awdth[0])){
            //convert percents to PX
            if (this.cellWidthType == '%'){
                this.cellWidthType="px";
                this.cellWidthPC=[];
            }
            var gs = (summ > this._awdth[1]
                ? this._awdth[1]
                : (summ < this._awdth[2]
                    ? this._awdth[2]
                    : summ))
                +(this._borderFix||0)*2;


            if (this._fake)
                for (var i = 0; i < this._fake._cCount; i++) gs+=parseInt(this._fake.cellWidthPX[i])
                this.entBox.style.width=gs+((_isVSroll&&(!this._ahgr||(this._ahgrM  && this._ahgrM  < this.objBox.scrollHeight) )) ? (_isFF ? 20 : 18) : 0)+"px";
            if (this._fake && !this._realfake)
                this._fake._correctSplit();
        }

        this.objBuf.style.width=summ+"px";

        if ((this.ftr)&&(!this._realfake))
            this.ftr.style.width=summ+"px";

        this.objBuf.childNodes[0].style.width=summ+"px";
        //if (_isOpera) this.hdr.style.width = summ + this.cellWidthPX.length*2 + "px";
        //set auto page size of dyn scroll
        this.doOnScroll(0, 1);

        //set header part of container visible height to header's height
        //this.entCnt.rows[0].cells[0].style.height = this.hdr.offsetHeight;

        this.hdr.style.border="0px solid gray"; //FF 1.0 fix
        /*                         if ((_isMacOS)&&(_isFF))
                                            var zheight=20;
                                         else*/
        var zheight = this.hdr.offsetHeight+(this._borderFix ? this._borderFix : 0);

        if (this.ftr)
            zheight+=this.ftr.offsetHeight;

        if (this._ahgr)
            if (this.objBox.scrollHeight){
                if (_isIE)
                    var z2 = this.objBox.scrollHeight;
                else
                    var z2 = this.objBox.childNodes[0].scrollHeight;
                var scrfix =
                    this.parentGrid
                        ? 1
                        : ((this.objBox.offsetWidth < this.objBox.scrollWidth)
                            ? (_isFF
                                ? 20
                                : 18)
                            : 1);

                if (this._ahgrMA)
                    z2=this.entBox.parentNode.offsetHeight-zheight-scrfix-(this._sizeFix ? this._sizeFix : 0)*2;

                if (((this._ahgrM)&&((this._ahgrF ? (z2+zheight+scrfix) : z2) > this._ahgrM)))
                    gridHeight=this._ahgrM*1+(this._ahgrF ? 0 : (zheight+scrfix));
                else
                    gridHeight=z2+zheight+scrfix;

                this.entBox.style.height=gridHeight+"px";
            }

        if (this.ftr)
            zheight-=this.ftr.offsetHeight;

        var aRow = this.entCnt.rows[1].cells[0].childNodes[0];

        if (!this.noHeader)
            aRow.style.top=(zheight-this.hdrBox.offsetHeight)+"px";

        if (this._topMb){
            this._topMb.style.top=(zheight||0)+"px";
            this._topMb.style.width=(gridWidth+20)+"px";
        }

        if (this._botMb){
            this._botMb.style.top=(gridHeight-3)+"px";
            this._botMb.style.width=(gridWidth+20)+"px";
        }

        //nb 072006:
        aRow.style.height=Math.max((((gridHeight-zheight-1) < 0&&_isIE)
            ? 20
            : (gridHeight-zheight-1))
            -(this.ftr
                ? this.ftr.offsetHeight
                : 0)-(_isIE&&(document.compatMode == "BackCompat")&&this._fake?(this._sizeFix||0)*2:0),0)
            +"px";

        /*if (this._fake && !this._realfake)
            this._fake.entCnt.rows[1].cells[0].childNodes[0].style.height=aRow.style.height;
*/
        if (this.ftr&&this.entBox.offsetHeight > this.ftr.offsetHeight)
            this.entCnt.style.height=this.entBox.offsetHeight-this.ftr.offsetHeight+"px";

        if (this._srdh)
            this.doOnScroll();
    };

    /**
    *   @desc: changes cell width
    *   @param: [ind] - index of row in grid
    *   @type: private
    *   @topic: 4,7
    */
    this.chngCellWidth=function(){
    	try {
	        if ((_isOpera)&&(this.ftr))
	            this.ftr.width=this.objBox.scrollWidth+"px";
	        var l = this._cCount;
	
	        for (var i = 0; i < l; i++){
	            this.hdr.rows[0].cells[i].style.width=this.cellWidthPX[i]+"px";
	            this.obj.rows[0].childNodes[i].style.width=this.cellWidthPX[i]+"px";
	
	            if (this.ftr)
	                this.ftr.rows[0].cells[i].style.width=this.cellWidthPX[i]+"px";
	        }
    	} catch (er){
            alert("1024*768 사이즈로 조정후 재조회 하세요");
            return null;
        }
    }
    /**
    *   @desc: set delimiter character used in list values (default is ",")
    *   @param: delim - delimiter as string
    *   @before_init: 1
    *   @type: public
    *   @topic: 0
    */
    this.setDelimiter=function(delim){
        this.delim=delim;
    }
    /**
    *   @desc: set width of columns in percents
    *   @type: public
    *   @before_init: 1
    *   @param: wp - list of column width in percents
    *   @topic: 0,7
    */
    this.setInitWidthsP=function(wp){
        this.cellWidthType="%";
        this.initCellWidth=wp.split(this.delim.replace(/px/gi, ""));
        this._setAutoResize();
    }
    /**
    *   @desc:
    *   @type: private
    *   @topic: 0
    */
    this._setAutoResize=function(){
        var el = window;
        var self = this;

        if (el.addEventListener){
            if ((_isFF)&&(_FFrv < 1.8))
                el.addEventListener("resize", function(){
                    if (!self.entBox)
                        return;

                    var z = self.entBox.style.width;
                    self.entBox.style.width="1px";

                    window.setTimeout(function(){
                        self.entBox.style.width=z;
                        self.setSizes();

                        if (self._fake)
                            self._fake._correctSplit();
                    }, 10);
                }, false);
            else
                el.addEventListener("resize", function(){
                    if (self.setSizes)
                        self.setSizes();

                    if (self._fake)
                        self._fake._correctSplit();
                }, false);
        }

        else if (el.attachEvent)
            el.attachEvent("onresize", function(){
                if (self._resize_timer)
                    window.clearTimeout(self._resize_timer);

                if (self.setSizes)
                    self._resize_timer=window.setTimeout(function(){
                        self.setSizes();

                        if (self._fake)
                            self._fake._correctSplit();
                    }, 500);
            });
        this._setAutoResize=function(){
        };
    }
    /**
    *   @desc: set width of columns in pixels
    *   @type: public
    *   @before_init: 1
    *   @param: wp - list of column width in pixels
    *   @topic: 0,7
    */
    this.setInitWidths=function(wp){
        this.cellWidthType="px";
        this.initCellWidth=wp.split(this.delim);

        if (_isFF){
            for (var i = 0; i < this.initCellWidth.length; i++)
                if (this.initCellWidth[i] != "*")
                    this.initCellWidth[i]=parseInt(this.initCellWidth[i])-2;
        }
    }

    /**
    *   @desc: set multiline rows support to enabled or disabled state
    *   @type: public
    *   @before_init: 1
    *   @param: state - true or false
    *   @topic: 0,7
    */
    this.enableMultiline=function(state){
        this.multiLine=convertStringToBoolean(state);
    }

    /**
    *   @desc: set multiselect mode to enabled or disabled state
    *   @type: public
    *   @param: state - true or false
    *   @topic: 0,7
    */
    this.enableMultiselect=function(state){
        this.selMultiRows=convertStringToBoolean(state);
    }

    /**
    *   @desc: set path to grid internal images (sort direction, any images used in editors, checkbox, radiobutton)
    *   @type: public
    *   @param: path - url (or relative path) of images folder with closing "/"
    *   @topic: 0,7
    */
    this.setImagePath=function(path){
        this.imgURL=path;
    }
    this.setImagesPath=this.setImagePath;
    /**
    *   @desc: set path to external images used in grid ( tree and img column types )
    *   @type: public
    *   @param: path - url (or relative path) of images folder with closing "/"
    *   @topic: 0,7
    */
    this.setIconPath=function(path){
        this.iconURL=path;
    }
    this.setIconsPath=this.setIconPath;
//#column_resize:06042008{
    /**
    *   @desc: part of column resize routine
    *   @type: private
    *   @param: ev - event
    *   @topic: 3
    */
    this.changeCursorState=function(ev){
        var el = ev.target||ev.srcElement;

        if (el.tagName != "TD")
            el=this.getFirstParentOfType(el, "TD")

        if ((el.tagName == "TD")&&(this._drsclmn)&&(!this._drsclmn[el._cellIndex]))
            return el.style.cursor="default";
        var check = (ev.layerX||0)+(((!_isIE)&&(ev.target.tagName == "DIV")) ? el.offsetLeft : 0);

        if ((el.offsetWidth-(ev.offsetX||(parseInt(this.getPosition(el, this.hdrBox))-check)*-1)) < (_isOpera?20:10)){
            el.style.cursor="E-resize";
        }
        else{
            el.style.cursor="default";
        }

        if (_isOpera)
            this.hdrBox.scrollLeft=this.objBox.scrollLeft;
    }
    /**
    *   @desc: part of column resize routine
    *   @type: private
    *   @param: ev - event
    *   @topic: 3
    */
    this.startColResize=function(ev){
        this.resized=null;
        var el = ev.target||ev.srcElement;
        if (el.tagName != "TD")
            el=this.getFirstParentOfType(el, "TD")
        var x = ev.clientX;
        var tabW = this.hdr.offsetWidth;
        var startW = parseInt(el.offsetWidth)

        if (el.tagName == "TD"&&el.style.cursor != "default"){
            if ((this._drsclmn)&&(!this._drsclmn[el._cellIndex]))
                return;
            this.entBox.onmousemove=function(e){
                this.grid.doColResize(e||window.event, el, startW, x, tabW)
            }
            document.body.onmouseup=function(){
                self.stopColResize();
            }
        }
    }
    /**
    *   @desc: part of column resize routine
    *   @type: private
    *   @param: ev - event
    *   @topic: 3
    */
    this.stopColResize=function(){
        this.entBox.onmousemove=""; //removeEventListener("mousemove")//
        document.body.onmouseup="";
        this.setSizes();
        this.doOnScroll(0, 1)
        this.callEvent("onResizeEnd", [this]);
    }
    /**
    *   @desc: part of column resize routine
    *   @param: el - element (column resizing)
    *   @param: startW - started width
    *   @param: x - x coordinate to resize from
    *   @param: tabW - started width of header table
    *   @type: private
    *   @topic: 3
    */
    this.doColResize=function(ev, el, startW, x, tabW){
        el.style.cursor="E-resize";
        this.resized=el;
        var fcolW = startW+(ev.clientX-x);
        var wtabW = tabW+(ev.clientX-x)

        if (!(this.callEvent("onResize", [
            el._cellIndex,
            fcolW,
            this
        ])))
            return;

        if (_isIE)
            this.objBox.scrollLeft=this.hdrBox.scrollLeft;

        if (el.colSpan > 1){
            var a_sizes = new Array();

            for (var i = 0;
                i < el.colSpan;
                i++)a_sizes[i]=Math.round(fcolW*this.hdr.rows[0].childNodes[el._cellIndexS+i].offsetWidth/el.offsetWidth);

            for (var i = 0; i < el.colSpan; i++)
                this._setColumnSizeR(el._cellIndexS+i*1, a_sizes[i]);
        } else
            this._setColumnSizeR(el._cellIndex, fcolW);
        this.doOnScroll(0, 1);

        this.objBuf.childNodes[0].style.width="";
        if (_isOpera || _isFF)
            this.setSizes();


    }

    /**
    *   @desc: set width of grid columns ( zero row of header and body )
    *   @type: private
    *   @topic: 7
    */
    this._setColumnSizeR=function(ind, fcolW){
        if (fcolW > ((this._drsclmW&&!this._notresize) ? (this._drsclmW[ind]||10) : 10)){
            this.obj.rows[0].childNodes[ind].style.width=fcolW+"px";
            this.hdr.rows[0].childNodes[ind].style.width=fcolW+"px";

            if (this.ftr)
                this.ftr.rows[0].childNodes[ind].style.width=fcolW+"px";

            if (this.cellWidthType == 'px'){
                this.cellWidthPX[ind]=fcolW;
            }
            else {
                var gridWidth = parseInt(this.entBox.offsetWidth);

                if (this.objBox.scrollHeight > this.objBox.offsetHeight)
                    gridWidth-=(this._scrFix||(_isFF ? 17 : 17));
                var pcWidth = Math.round(fcolW / gridWidth*100)
                this.cellWidthPC[ind]=pcWidth;
            }
            if (this.sortImg.style.display!="none")
                this.setSortImgPos();
        }
    }
//#}
//#sorting:06042008{
    /**
    *    @desc: sets position and visibility of sort arrow
    *    @param: state - true/false - show/hide image
    *    @param: ind - index of field
    *    @param: order - asc/desc - type of image
    *    @param: row - one based index of header row ( used in multirow headers, top row by default )
    *   @type: public
    *   @topic: 7
    */
    this.setSortImgState=function(state, ind, order, row){
        order=(order||"asc").toLowerCase();

        if (!convertStringToBoolean(state)){
            this.sortImg.style.display="none";
            this.fldSorted=null;
            return;
        }

        if (order == "asc")
            this.sortImg.src=this.imgURL+"sort_asc.gif";
        else
            this.sortImg.src=this.imgURL+"sort_desc.gif";
        this.sortImg.style.display="";
        this.fldSorted=this.hdr.rows[0].childNodes[ind];
        var r = this.hdr.rows[row||1];

        for (var i = 0; i < r.childNodes.length; i++)
            if (r.childNodes[i]._cellIndex == ind)
                this.r_fldSorted=r.childNodes[i];
        this.setSortImgPos();
    }

    /**
    *    @desc: sets position and visibility of sort arrow
    *    @param: ind - index of field
    *    @param: ind - index of field
    *    @param: hRowInd - index of row in case of complex header, one-based, optional

    *   @type: private
    *   @topic: 7
    */
    this.setSortImgPos=function(ind, mode, hRowInd, el){
        if (this._hrrar && this._hrrar[this.r_fldSorted?this.r_fldSorted._cellIndex:ind]) return;
        if (!el){
            if (!ind)
                var el = this.r_fldSorted;
            else
                var el = this.hdr.rows[hRowInd||0].cells[ind];
        }

        if (el != null){
            var pos = this.getPosition(el, this.hdrBox)
            var wdth = el.offsetWidth;
            this.sortImg.style.left=Number(pos[0]+wdth-13)+"px"; //Number(pos[0]+5)+"px";
            this.sortImg.defLeft=parseInt(this.sortImg.style.left)
            this.sortImg.style.top=Number(pos[1]+5)+"px";

            if ((!this.useImagesInHeader)&&(!mode))
                this.sortImg.style.display="inline";
            this.sortImg.style.left=this.sortImg.defLeft+"px"; //-parseInt(this.hdrBox.scrollLeft)
        }
    }
//#}
    /**
    *   @desc: manage activity of the grid.
    *   @param: fl - true to activate,false to deactivate
    *   @type: private
    *   @topic: 1,7
    */
    this.setActive=function(fl){
        if (arguments.length == 0)
            var fl = true;

        if (fl == true){
            //document.body.onkeydown = new Function("","document.getElementById('"+this.entBox.id+"').grid.doKey()")//
            if (globalActiveDHTMLGridObject&&(globalActiveDHTMLGridObject != this))
                globalActiveDHTMLGridObject.editStop();

            globalActiveDHTMLGridObject=this;
            this.isActive=true;
        } else {
            this.isActive=false;
        }
    };
    /**
    *     @desc: called on click occured
    *     @type: private
    */
    this._doClick=function(ev){
        var selMethod = 0;
        var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target, "TD");
        if (!el) return;
        var fl = true;

        //mm
        //markers start
        if (this.markedCells){
            var markMethod = 0;

            if (ev.shiftKey||ev.metaKey){
                markMethod=1;
            }

            if (ev.ctrlKey){
                markMethod=2;
            }
            this.doMark(el, markMethod);
            return true;
        }
        //markers end
        //mm

        if (this.selMultiRows != false){
            if (ev.shiftKey&&this.row != null){
                selMethod=1;
            }

            if (ev.ctrlKey||ev.metaKey){
                selMethod=2;
            }
        }
        this.doClick(el, fl, selMethod)
    };

//#context_menu:06042008{
    /**
    *   @desc: called onmousedown inside grid area
    *   @type: private
    */
    this._doContClick=function(ev){
        var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target, "TD");

        if ((!el)||( typeof (el.parentNode.idd) == "undefined"))
            return true;

        if (ev.button == 2||(_isMacOS&&ev.ctrlKey)){
            if (!this.callEvent("onRightClick", [
                el.parentNode.idd,
                el._cellIndex,
                ev
            ])){
                var z = function(e){
                    document.body.oncontextmenu=Function("return true;");
                    (e||event).cancelBubble=true;
                    return false;
                }

                if (_isIE)
                    ev.srcElement.oncontextmenu=z;

                else if (!_isMacOS)
                    document.body.oncontextmenu=z;

                return false;
            }

            if (this._ctmndx){
                if (!(this.callEvent("onBeforeContextMenu", [
                    el.parentNode.idd,
                    el._cellIndex,
                    this
                ])))
                    return true;

                if (_isIE)
                    ev.srcElement.oncontextmenu=function(){
                        event.cancelBubble=true;
                        return false;
                    };

                if (this._ctmndx.showContextMenu){

var dEl0=window.document.documentElement;
var dEl1=window.document.body;
var corrector = new Array((dEl0.scrollLeft||dEl1.scrollLeft),(dEl0.scrollTop||dEl1.scrollTop));
if (_isIE){
    var x= ev.clientX+corrector[0];
    var y = ev.clientY-corrector[1];
} else {
    var x= ev.pageX;
    var y = ev.pageY;
}

                    this._ctmndx.showContextMenu(ev.clientX-1,ev.clientY-1)
                    this.contextID=this._ctmndx.contextMenuZoneId=el.parentNode.idd+"_"+el._cellIndex;
                    this._ctmndx._skip_hide=true;
                } else {
                    el.contextMenuId=el.parentNode.idd+"_"+el._cellIndex;
                    el.contextMenu=this._ctmndx;
                    el.a=this._ctmndx._contextStart;
                    el.a(el, ev);
                    el.a=null;
                }
            }
        }

        else if (this._ctmndx){
            if (this._ctmndx.hideContextMenu)
                this._ctmndx.hideContextMenu()
            else
                this._ctmndx._contextEnd();
        }
        return true;
    }
//#}
    /**
    *    @desc: occures on cell click (supports treegrid)
    *   @param: [el] - cell to click on
    *   @param:   [fl] - true if to call onRowSelect function
    *   @param: [selMethod] - 0 - simple click, 1 - shift, 2 - ctrl
    *   @param: show - true/false - scroll row to view, true by defaul
    *   @type: private
    *   @topic: 1,2,4,9
    */
    this.doClick=function(el, fl, selMethod, show){

        var psid = this.row ? this.row.idd : 0;

        this.setActive(true);

        if (!selMethod)
            selMethod=0;

        if (this.cell != null)
            this.cell.className=this.cell.className.replace(/cellselected/g, "");

        if (el.tagName == "TD"){
            if (this.checkEvent("onSelectStateChanged"))
                var initial = this.getSelectedId();
            var prow = this.row;

        if (selMethod == 1){
                var elRowIndex = this.rowsCol._dhx_find(el.parentNode)
                var lcRowIndex = this.rowsCol._dhx_find(this.lastClicked)

                if (elRowIndex > lcRowIndex){
                    var strt = lcRowIndex;
                    var end = elRowIndex;
                } else {
                    var strt = elRowIndex;
                    var end = lcRowIndex;
                }

                for (var i = 0; i < this.rowsCol.length; i++)
                    if ((i >= strt&&i <= end)){
                        if (this.rowsCol[i]&&(!this.rowsCol[i]._sRow)){
                            if (this.rowsCol[i].className.indexOf("rowselected")
                                == -1&&this.callEvent("onBeforeSelect", [
                                this.rowsCol[i].idd,
                                psid
                            ])){
                                this.rowsCol[i].className+=" rowselected";
                                this.selectedRows[this.selectedRows.length]=this.rowsCol[i]
                            }
                        } else {
                            this.clearSelection();
                            return this.doClick(el, fl, 0, show);
                        }
                    }
            } else if (selMethod == 2){
                if (el.parentNode.className.indexOf("rowselected") != -1){
                    el.parentNode.className=el.parentNode.className.replace(/rowselected/g, "");
                    this.selectedRows._dhx_removeAt(this.selectedRows._dhx_find(el.parentNode))
                    var skipRowSelection = true;
                }
            }
            this.editStop()
            if (typeof (el.parentNode.idd) == "undefined")
                return true;

            if ((!skipRowSelection)&&(!el.parentNode._sRow)){
                if (this.callEvent("onBeforeSelect", [
                    el.parentNode.idd,
                    psid
                ])){
                    if (selMethod == 0)
                        this.clearSelection();
                    this.cell=el;
                    if ((prow == el.parentNode)&&(this._chRRS))
                        fl=false;
                    this.row=el.parentNode;
                    this.row.className+=" rowselected"

                    if (this.selectedRows._dhx_find(this.row) == -1)
                        this.selectedRows[this.selectedRows.length]=this.row;
                }
            }

            if (this.cell && this.cell.parentNode.className.indexOf("rowselected") != -1)
                this.cell.className=this.cell.className.replace(/cellselected/g, "")+" cellselected";

            if (selMethod != 1)
                if (!this.row)
                    return;
            this.lastClicked=el.parentNode;

            var rid = this.row.idd;
            var cid = this.cell;

            if (fl&& typeof (rid) != "undefined" && cid)
                self.onRowSelectTime=setTimeout(function(){
                    self.callEvent("onRowSelect", [
                        rid,
                        cid._cellIndex
                    ]);
                }, 100)

            if (this.checkEvent("onSelectStateChanged")){
                var afinal = this.getSelectedId();

                if (initial != afinal)
                    this.callEvent("onSelectStateChanged", [afinal,initial]);
            }
        }
        this.isActive=true;
        if (show !== false && this.cell && this.cell.parentNode.idd)
            this.moveToVisible(this.cell)
    }

    /**
    *   @desc: select all rows in grid, it doesn't fire any events
    *   @param: edit - switch selected cell to edit mode
    *   @type: public
    *   @topic: 1,4
    */
    this.selectAll=function(){
        this.clearSelection();
        this.selectedRows=dhtmlxArray([].concat(this.rowsCol));

        for (var i = this.rowsCol.length-1; i >= 0; i--){
            if (this.rowsCol[i]._cntr)
                this.selectedRows.splice(i, 1);
            else
                this.rowsCol[i].className+=" rowselected";
        }

        if (this.selectedRows.length){
            this.row=this.selectedRows[0];
            this.cell=this.row.cells[0];
        }

        if ((this._fake)&&(!this._realfake))
            this._fake.selectAll();
    }
    /**
    *   @desc: set selection to specified row-cell
    *   @param: r - row object or row index
    *   @param: cInd - cell index
    *   @param: [fl] - true if to call onRowSelect function
      *   @param: preserve - preserve previously selected rows true/false (false by default)
      *   @param: edit - switch selected cell to edit mode
    *   @param: show - true/false - scroll row to view, true by defaul
    *   @type: public
    *   @topic: 1,4
    */
    this.selectCell=function(r, cInd, fl, preserve, edit, show){
        if (!fl)
            fl=false;

        if (typeof (r) != "object")
            r=this.render_row(r)
        if (!r || r==-1) return null;

            var c = r.childNodes[cInd];

        if (!c)
            c=r.childNodes[0];

        if (preserve)
            this.doClick(c, fl, 3, show)
        else
            this.doClick(c, fl, 0, show)

        if (edit)
            this.editCell();
    }
    /**
    *   @desc: moves specified cell to visible area (scrolls)
    *   @param: cell_obj - object of the cell to work with
    *   @param: onlyVScroll - allow only vertical positioning

    *   @type: private
    *   @topic: 2,4,7
    */
    this.moveToVisible=function(cell_obj, onlyVScroll){
        if (!cell_obj.offsetHeight){
            //row is in not rendered part of the grid
            var h=this.rowsBuffer._dhx_find(cell_obj.parentNode)*this._srdh;
            return this.objBox.scrollTop=h;
        }
        try{
            var distance = cell_obj.offsetLeft+cell_obj.offsetWidth+20;

            var scrollLeft = 0;

            if (distance > (this.objBox.offsetWidth+this.objBox.scrollLeft)){
                if (cell_obj.offsetLeft > this.objBox.scrollLeft)
                    scrollLeft=cell_obj.offsetLeft-5
            } else if (cell_obj.offsetLeft < this.objBox.scrollLeft){
                distance-=cell_obj.offsetWidth*2/3;
                if (distance < this.objBox.scrollLeft)
                    scrollLeft=cell_obj.offsetLeft-5
            }

            if ((scrollLeft)&&(!onlyVScroll))
                this.objBox.scrollLeft=scrollLeft;

            var distance = cell_obj.offsetTop+cell_obj.offsetHeight+20;

            if (distance > (this.objBox.offsetHeight+this.objBox.scrollTop)){
                var scrollTop = distance-this.objBox.offsetHeight;
            } else if (cell_obj.offsetTop < this.objBox.scrollTop){
                var scrollTop = cell_obj.offsetTop-5
            }

            if (scrollTop)
                this.objBox.scrollTop=scrollTop;
        }
        catch (er){}
    }
    /**
    *   @desc: creates Editor object and switch cell to edit mode if allowed
    *   @type: public
    *   @topic: 4
    */
    this.editCell=function(){
        if (this.editor&&this.cell == this.editor.cell)
            return; //prevent reinit for same cell

        this.editStop();

        if ((this.isEditable != true)||(!this.cell))
            return false;
        var c = this.cell;

//#locked_row:11052006{
        if (c.parentNode._locked)
            return false;
//#}

        this.editor=this.cells4(c);

        //initialize editor
        if (this.editor != null){
            if (this.editor.isDisabled()){
                this.editor=null;
                return false;
            }

            if (this.callEvent("onEditCell", [
                0,
                this.row.idd,
                this.cell._cellIndex
            ]) != false&&this.editor.edit){
                this._Opera_stop=(new Date).valueOf();
                c.className+=" editable";
                this.editor.edit();
                this.callEvent("onEditCell", [
                    1,
                    this.row.idd,
                    this.cell._cellIndex
                ])
            } else { //preserve editing
                this.editor=null;
            }
        }
    }
    /**
    *   @desc: retuns value from editor(if presents) to cell and closes editor
    *   @mode: if true - current edit value will be reverted to previous one
    *   @type: public
    *   @topic: 4
    */
    this.editStop=function(mode){
        if (_isOpera)
            if (this._Opera_stop){
                if ((this._Opera_stop*1+50) > (new Date).valueOf())
                    return;

                this._Opera_stop=null;
            }

        if (this.editor&&this.editor != null){
            this.editor.cell.className=this.editor.cell.className.replace("editable", "");

            if (mode){
                var t = this.editor.val;
                this.editor.detach();
                this.editor.setValue(t);
                this.editor=null;
                return;
            }

            if (this.editor.detach())
                this.cell.wasChanged=true;

            var g = this.editor;
            this.editor=null;
            var z = this.callEvent("onEditCell", [
                2,
                this.row.idd,
                this.cell._cellIndex,
                g.getValue(),
                g.val
            ]);

            if (( typeof (z) == "string")||( typeof (z) == "number"))
                g[g.setImage ? "setLabel" : "setValue"](z);

            else if (!z)
                g[g.setImage ? "setLabel" : "setValue"](g.val);
        }
    }
    /**
    *   @desc:
    *   @type: private
    */
    this._nextRowCell=function(row, dir, pos){
        row=this._nextRow(this.rowsCol._dhx_find(row), dir);

        if (!row)
            return null;

        return row.childNodes[row._childIndexes ? row._childIndexes[pos] : pos];
    }
    /**
    *   @desc:
    *   @type: private
    */
    this._getNextCell=function(acell, dir, i){

        acell=acell||this.cell;

        var arow = acell.parentNode;

        if (this._tabOrder){
            i=this._tabOrder[acell._cellIndex];

            if (typeof i != "undefined")
                if (i < 0)
                    acell=this._nextRowCell(arow, dir, Math.abs(i)-1);
                else
                    acell=arow.childNodes[i];
        } else {
            var i = acell._cellIndex+dir;

            if (i >= 0&&i < this._cCount){
                if (arow._childIndexes)
                    i=arow._childIndexes[acell._cellIndex]+dir;
                acell=arow.childNodes[i];
            } else {

                acell=this._nextRowCell(arow, dir, (dir == 1 ? 0 : (this._cCount-1)));
            }
        }

        if (!acell){
            if ((dir == 1)&&this.tabEnd){
                this.tabEnd.focus();
                this.tabEnd.focus();
            }

            if ((dir == -1)&&this.tabStart){
                this.tabStart.focus();
                this.tabStart.focus();
            }
            return null;
        }

        //tab out

        // tab readonly
        if (acell.style.display != "none"
            &&(!this.smartTabOrder||!this.cells(acell.parentNode.idd, acell._cellIndex).isDisabled()))
            return acell;
        return this._getNextCell(acell, dir);
    // tab readonly

    }
    /**
    *   @desc:
    *   @type: private
    */
    this._nextRow=function(ind, dir){
        var r = this.render_row(ind+dir);
        if (!r || r==-1) return null;
        if (r&&r.style.display == "none")
            return this._nextRow(ind+dir, dir);

        return r;
    }
    /**
    *   @desc:
    *   @type: private
    */
    this.scrollPage=function(dir){
        var master = this._realfake?this._fake:this;
        var new_ind = Math.floor((master._r_select||this.getRowIndex(this.row.idd)||0)+(dir)*this.objBox.offsetHeight / (this._srdh||20));

        if (new_ind < 0)
            new_ind=0;
        if (new_ind >= this.rowsBuffer.length)
            new_ind=this.rowsBuffer.length-1;

        if (this._srnd && !this.rowsBuffer[new_ind]){
            this.objBox.scrollTop+=Math.floor((dir)*this.objBox.offsetHeight / (this._srdh||20))*(this._srdh||20);
            master._r_select=new_ind;
        } else {
            this.selectCell(new_ind, this.cell._cellIndex, true, false,false,(this.multiLine || this._srnd));
            if (!this.multiLine && !this._srnd)
                this.objBox.scrollTop=this.getRowById(this.getRowId(new_ind)).offsetTop;
            master._r_select=null;
        }
    }

    /**
    *   @desc: manages keybord activity in grid
    *   @type: private
    *   @topic: 7
    */
    this.doKey=function(ev){
        if (!ev)
            return true;

        if ((ev.target||ev.srcElement).value !== window.undefined){
            var zx = (ev.target||ev.srcElement);

            if ((!zx.parentNode)||(zx.parentNode.className.indexOf("editable") == -1))
                return true;
        }

        if ((globalActiveDHTMLGridObject)&&(this != globalActiveDHTMLGridObject))
            return globalActiveDHTMLGridObject.doKey(ev);

        if (this.isActive == false){
            //document.body.onkeydown = "";
            return true;
        }

        if (this._htkebl)
            return true;

        if (!this.callEvent("onKeyPress", [
            ev.keyCode,
            ev.ctrlKey,
            ev.shiftKey,
            ev
        ]))
            return false;

        var code = "k"+ev.keyCode+"_"+(ev.ctrlKey ? 1 : 0)+"_"+(ev.shiftKey ? 1 : 0);

        if (this.cell){ //if selection exists in grid only
            if (this._key_events[code]){
                if (false === this._key_events[code].call(this))
                    return true;

                if (ev.preventDefault)
                    ev.preventDefault();
                ev.cancelBubble=true;
                return false;
            }

            if (this._key_events["k_other"])
                this._key_events.k_other.call(this, ev);
        }

        return true;
    }
    /**
    *   @desc: selects row (?)for comtatibility with previous version
    *   @param: cell - cell object(or cell's child)
    *   @invoke: click on cell(or cell content)
    *   @type: private
    *   @topic: 1,2
    */
    this.getRow=function(cell){
        if (!cell)
            cell=window.event.srcElement;

        if (cell.tagName != 'TD')
            cell=cell.parentElement;
        r=cell.parentElement;

        if (this.cellType[cell._cellIndex] == 'lk')
            eval(this.onLink+"('"+this.getRowId(r.rowIndex)+"',"+cell._cellIndex+")");
        this.selectCell(r, cell._cellIndex, true)
    }
    /**
    *   @desc: selects row (and first cell of it)
    *   @param: r - row index or row object
    *   @param: fl - if true, then call function on select
     *   @param: preserve - preserve previously selected rows true/false (false by default)
     *   @param: show - true/false - scroll row to view, true by defaul
    *   @type: public
    *   @topic: 1,2
    */
    this.selectRow=function(r, fl, preserve, show){
        if (typeof (r) != 'object')
            r=this.render_row(r);
        this.selectCell(r, 0, fl, preserve, false, show)
    };

    /**
    *   @desc: called when row was double clicked
    *   @type: private
    *   @topic: 1,2
    */
    this.wasDblClicked=function(ev){
        var el = this.getFirstParentOfType(_isIE ? ev.srcElement : ev.target, "TD");

        if (el){
            var rowId = el.parentNode.idd;
            return this.callEvent("onRowDblClicked", [
                rowId,
                el._cellIndex
            ]);
        }
    }

    /**
    *   @desc: called when header was clicked
    *   @type: private
    *   @topic: 1,2
    */
    this._onHeaderClick=function(e, el){
        var that = this.grid;
        el=el||that.getFirstParentOfType(_isIE ? event.srcElement : e.target, "TD");

        if (this.grid.resized == null){
            if (!(this.grid.callEvent("onHeaderClick", [
                el._cellIndexS,
                (e||window.event)
            ])))
                return false;
//#sorting:06042008{
            that.sortField(el._cellIndexS, false, el)
//#}
        }
    }

    /**
    *   @desc: deletes selected row(s)
    *   @type: public
    *   @topic: 2
    */
    this.deleteSelectedRows=function(){
        var num = this.selectedRows.length //this.obj.rows.length

        if (num == 0)
            return;

        var tmpAr = this.selectedRows;
        this.selectedRows=dhtmlxArray()
        for (var i = num-1; i >= 0; i--){
            var node = tmpAr[i]

            if (!this.deleteRow(node.idd, node)){
                this.selectedRows[this.selectedRows.length]=node;
            }
            else {
                if (node == this.row){
                    var ind = i;
                }
            }
/*
                           this.rowsAr[node.idd] = null;
                           var posInCol = this.rowsCol._dhx_find(node)
                           this.rowsCol[posInCol].parentNode.removeChild(this.rowsCol[posInCol]);//nb:this.rowsCol[posInCol].removeNode(true);
                           this.rowsCol._dhx_removeAt(posInCol)*/
        }

        if (ind){
            try{
                if (ind+1 > this.rowsCol.length) //this.obj.rows.length)
                    ind--;
                this.selectCell(ind, 0, true)
            }
            catch (er){
                this.row=null
                this.cell=null
            }
        }
    }

    /**
    *   @desc: gets selected row id
    *   @returns: id of selected row (list of ids with default delimiter) or null if non row selected
    *   @type: public
    *   @topic: 1,2,9
    */
    this.getSelectedRowId=function(){
        var selAr = new Array(0);
        var uni = {
        };

        for (var i = 0; i < this.selectedRows.length; i++){
            var id = this.selectedRows[i].idd;

            if (uni[id])
                continue;

            selAr[selAr.length]=id;
            uni[id]=true;
        }

        //..
        if (selAr.length == 0)
            return null;
        else
            return selAr.join(this.delim);
    }

    /**
    *   @desc: gets index of selected cell
    *   @returns: index of selected cell or -1 if there is no selected sell
    *   @type: public
    *   @topic: 1,4
    */
    this.getSelectedCellIndex=function(){
        if (this.cell != null)
            return this.cell._cellIndex;
        else
            return -1;
    }
    /**
    *   @desc: gets width of specified column in pixels
    *   @param: ind - column index
    *   @returns: column width in pixels
    *   @type: public
    *   @topic: 3,7
    */
    this.getColWidth=function(ind){
        return parseInt(this.cellWidthPX[ind])+((_isFF) ? 2 : 0);
    }

    /**
    *   @desc: sets width of specified column in pixels (soen't works with procent based grid)
    *   @param: ind - column index
    *   @param: value - new width value
    *   @type: public
    *   @topic: 3,7
    */
    this.setColWidth=function(ind, value){
        if (this.cellWidthType == 'px')
            this.cellWidthPX[ind]=parseInt(value)-+((_isFF) ? 2 : 0);
        else
            this.cellWidthPC[ind]=parseInt(value);
        this.setSizes();
    }
    /**
    *   @desc: gets row index by id (grid only)
    *   @param: row_id - row id
    *   @returns: row index or -1 if there is no row with specified id
    *   @type: public
    *   @topic: 2
    */
    this.getRowIndex=function(row_id){
        for (var i = 0; i < this.rowsBuffer.length; i++)
            if (this.rowsBuffer[i]&&this.rowsBuffer[i].idd == row_id)
                return i;
    }
    /**
    *   @desc: gets row id by index
    *   @param: ind - row index
    *   @returns: row id or null if there is no row with specified index
    *   @type: public
    *   @topic: 2
    */
    this.getRowId=function(ind){
        return this.rowsBuffer[ind] ? this.rowsBuffer[ind].idd : this.undefined;
    }
    /**
    *   @desc: sets new id for row by its index
    *   @param: ind - row index
    *   @param: row_id - new row id
    *   @type: public
    *   @topic: 2
    */
    this.setRowId=function(ind, row_id){
        this.changeRowId(this.getRowId(ind), row_id)
    }
    /**
    *   @desc: changes id of the row to the new one
    *   @param: oldRowId - row id to change
    *   @param: newRowId - row id to set
    *   @type:public
    *   @topic: 2
    */
    this.changeRowId=function(oldRowId, newRowId){
        if (oldRowId == newRowId)
            return;
        /*
                          for (var i=0; i<row.childNodes.length; i++)
                              if (row.childNodes[i]._code)
                                  this._compileSCL("-",row.childNodes[i]);      */
        var row = this.rowsAr[oldRowId]
        row.idd=newRowId;

        if (this.UserData[oldRowId]){
            this.UserData[newRowId]=this.UserData[oldRowId]
            this.UserData[oldRowId]=null;
        }

        if (this._h2&&this._h2.get[oldRowId]){
            this._h2.get[newRowId]=this._h2.get[oldRowId];
            this._h2.get[newRowId].id=newRowId;
            delete this._h2.get[oldRowId];
        }

        this.rowsAr[oldRowId]=null;
        this.rowsAr[newRowId]=row;

        for (var i = 0; i < row.childNodes.length; i++)
            if (row.childNodes[i]._code)
                row.childNodes[i]._code=this._compileSCL(row.childNodes[i]._val, row.childNodes[i]);

        this.callEvent("onRowIdChange",[oldRowId,newRowId]);
    }
    /**
    *   @desc: sets ids to every column. Can be used then to retreive the index of the desired colum
    *   @param: [ids] - delimitered list of ids (default delimiter is ","), or empty if to use values set earlier
    *   @type: public
    *   @topic: 3
    */
    this.setColumnIds=function(ids){
        this.columnIds=ids.split(this.delim)
    }
    /**
    *   @desc: sets ids to specified column.
    *   @param: ind- index of column
    *   @param: id- id of column
    *   @type: public
    *   @topic: 3
    */
    this.setColumnId=function(ind, id){
        this.columnIds[ind]=id;
    }
    /**
    *   @desc: gets column index by column id
    *   @param: id - column id
    *   @returns: index of the column
    *   @type: public
    *   @topic: 3
    */
    this.getColIndexById=function(id){
        for (var i = 0; i < this.columnIds.length; i++)
            if (this.columnIds[i] == id)
                return i;
    }
    /**
    *   @desc: gets column id of column specified by index
    *   @param: cin - column index
    *   @returns: column id
    *   @type: public
    *   @topic: 3
    */
    this.getColumnId=function(cin){
        return this.columnIds[cin];
    }

    /**
    *   @desc: gets label of column specified by index
    *   @param: cin - column index
    *   @returns: column label
    *   @type: public
    *   @topic: 3
    */
    this.getColumnLabel=function(cin, ind){
        var z = this.hdr.rows[(ind||0)+1];
        for (var i=0; i<z.cells.length; i++)
            if (z.cells[i]._cellIndexS==cin) return(_isIE ? z.cells[i].innerText : z.cells[i].textContent);
        return "";
    }


    /**
    *   @desc: sets row text BOLD
    *   @param: row_id - row id
    *   @type: public
    *   @topic: 2,6
    */
    this.setRowTextBold=function(row_id){
        var r=this.getRowById(row_id)
        if (r) r.style.fontWeight="bold";
    }
    /**
    *   @desc: sets style to row
    *   @param: row_id - row id
    *   @param: styleString - style string in common format (exmpl: "color:red;border:1px solid gray;")
    *   @type: public
    *   @topic: 2,6
    */
    this.setRowTextStyle=function(row_id, styleString){
        var r = this.getRowById(row_id)
        if (!r) return;
        for (var i = 0; i < r.childNodes.length; i++){
            var pfix = "";

            if (_isIE)
                r.childNodes[i].style.cssText=pfix+"width:"+r.childNodes[i].style.width+";"+styleString;
            else
                r.childNodes[i].style.cssText=pfix+"width:"+r.childNodes[i].style.width+";"+styleString;
        }
    }
    /**
    *   @desc: sets background color of row (via bgcolor attribute)
    *   @param: row_id - row id
    *   @param: color - color value
    *   @type: public
    *   @topic: 2,6
    */
    this.setRowColor=function(row_id, color){
        var r = this.getRowById(row_id)

        for (var i = 0; i < r.childNodes.length; i++)r.childNodes[i].bgColor=color;
    }
    /**
    *   @desc: sets style to cell
    *   @param: row_id - row id
    *   @param: ind - cell index
    *   @param: styleString - style string in common format (exmpl: "color:red;border:1px solid gray;")
    *   @type: public
    *   @topic: 2,6
    */
    this.setCellTextStyle=function(row_id, ind, styleString){
        var r = this.getRowById(row_id)

        if (!r)
            return;

        var cell = r.childNodes[r._childIndexes ? r._childIndexes[ind] : ind];

        if (!cell)
            return;
        var pfix = "";

        if (_isIE)
            cell.style.cssText=pfix+"width:"+cell.style.width+";"+styleString;
        else
            cell.style.cssText=pfix+"width:"+cell.style.width+";"+styleString;
    }

    /**
    *   @desc: sets row text weight to normal
    *   @param: row_id - row id
    *   @type: public
    *   @topic: 2,6
    */
    this.setRowTextNormal=function(row_id){
        var r=this.getRowById(row_id);
        if (r) r.style.fontWeight="normal";
    }
    /**
    *   @desc: determines if row with specified id exists
    *   @param: row_id - row id
    *   @returns: true if exists, false otherwise
    *   @type: public
    *   @topic: 2,7
    */
    this.doesRowExist=function(row_id){
        if (this.getRowById(row_id) != null)
            return true
        else
            return false
    }



    /**
    *   @desc: gets number of columns in grid
    *   @returns: number of columns in grid
    *   @type: public
    *   @topic: 3,7
    */
    this.getColumnsNum=function(){
        return this._cCount;
    }


//#moving_rows:06042008{
    /**
    *   @desc: moves row one position up if possible
    *   @param: row_id -  row id
    *   @type: public
    *   @topic: 2
    */
    this.moveRowUp=function(row_id){
        var r = this.getRowById(row_id)

        if (this.isTreeGrid())
            return this.moveRowUDTG(row_id, -1);

        var rInd = this.rowsCol._dhx_find(r)
        if ((r.previousSibling)&&(rInd != 0)){
            r.parentNode.insertBefore(r, r.previousSibling)
            this.rowsCol._dhx_swapItems(rInd, rInd-1)
            this.setSizes();
            var bInd=this.rowsBuffer._dhx_find(r);
            this.rowsBuffer._dhx_swapItems(bInd,bInd-1);

            if (this._cssEven)
                this._fixAlterCss(rInd-1);
        }
    }
    /**
    *   @desc: moves row one position down if possible
    *   @param: row_id -  row id
    *   @type: public
    *   @topic: 2
    */
    this.moveRowDown=function(row_id){
        var r = this.getRowById(row_id)

        if (this.isTreeGrid())
            return this.moveRowUDTG(row_id, 1);

        var rInd = this.rowsCol._dhx_find(r);
        if (r.nextSibling){
            this.rowsCol._dhx_swapItems(rInd, rInd+1)

            if (r.nextSibling.nextSibling)
                r.parentNode.insertBefore(r, r.nextSibling.nextSibling)
            else
                r.parentNode.appendChild(r)
            this.setSizes();

            var bInd=this.rowsBuffer._dhx_find(r);
            this.rowsBuffer._dhx_swapItems(bInd,bInd+1);

            if (this._cssEven)
                this._fixAlterCss(rInd);
        }
    }
//#}
//#co_excell:06042008{
    /**
    * @desc: gets Combo object of specified column. Use it to change select box value for cell before editor opened
    *   @type: public
    *   @topic: 3,4
    *   @param: col_ind - index of the column to get combo object for
    */
    this.getCombo=function(col_ind){
        if (!this.combos[col_ind]){
            this.combos[col_ind]=new dhtmlXGridComboObject();
        }
        return this.combos[col_ind];
    }
//#}
    /**
    *   @desc: sets user data to row
    *   @param: row_id -  row id. if empty then user data is set for grid (not row)
    *   @param: name -  name of user data block
    *   @param: value -  value of user data block
    *   @type: public
    *   @topic: 2,5
    */
    this.setUserData=function(row_id, name, value){
        try{
            if (row_id == "")
                row_id="gridglobaluserdata";

            if (!this.UserData[row_id])
                this.UserData[row_id]=new Hashtable()
            this.UserData[row_id].put(name, value)
        }
        catch (er){
            alert("UserData Error:"+er.description)
        }
    }
    /**
    *   @desc: gets user Data
    *   @param: row_id -  row id. if empty then user data is for grid (not row)
    *   @param: name -  name of user data
    *   @returns: value of user data
    *   @type: public
    *   @topic: 2,5
    */
    this.getUserData=function(row_id, name){
        this.getRowById(row_id); //parse row if necessary

        if (row_id == "")
            row_id="gridglobaluserdata";
        var z = this.UserData[row_id];
        return(z ? z.get(name) : "");
    }

    /**
    *   @desc: manage editibility of the grid
    *   @param: [fl] - set not editable if FALSE, set editable otherwise
    *   @type: public
    *   @topic: 7
    */
    this.setEditable=function(fl){
        this.isEditable=convertStringToBoolean(fl);
    }
    /**
    *   @desc: selects row by ID
    *   @param: row_id - row id
    *   @param: multiFL - VOID. select multiple rows
    *   @param: show - true/false - scroll row to view, true by defaul
    *   @param: call - true to call function on select
    *   @type: public
    *   @topic: 1,2
    */
    this.selectRowById=function(row_id, multiFL, show, call){
        if (!call)
            call=false;
        this.selectCell(this.getRowById(row_id), 0, call, multiFL, false, show);
    }

    /**
    *   @desc: removes selection from the grid
    *   @type: public
    *   @topic: 1,9
    */
    this.clearSelection=function(){
        this.editStop()

        for (var i = 0; i < this.selectedRows.length; i++){
            var r = this.rowsAr[this.selectedRows[i].idd];

            if (r)
                r.className=r.className.replace(/rowselected/g, "");
        }

        //..
        this.selectedRows=dhtmlxArray()
        this.row=null;

        if (this.cell != null){
            this.cell.className=this.cell.className.replace(/cellselected/g, "");
            this.cell=null;
        }
    }
    /**
    *   @desc: copies row content to another existing row
    *   @param: from_row_id - id of the row to copy content from
    *   @param: to_row_id - id of the row to copy content to
    *   @type: public
    *   @topic: 2,5
    */
    this.copyRowContent=function(from_row_id, to_row_id){
        var frRow = this.getRowById(from_row_id)

        if (!this.isTreeGrid())
            for (var i = 0; i < frRow.cells.length; i++){
                this.cells(to_row_id, i).setValue(this.cells(from_row_id, i).getValue())
            }
        else
            this._copyTreeGridRowContent(frRow, from_row_id, to_row_id);

        //for Mozilla (to avaoid visual glitches)
        if (!_isIE)
            this.getRowById(from_row_id).cells[0].height=frRow.cells[0].offsetHeight
    }
    /**
    *   @desc: sets new column header label
    *   @param: col - header column index
    *   @param: label - new label for the cpecified header's column. Can contai img:[imageUrl]Text Label
    *   @param: ind - header row index (default is 0)
    *   @type: public
    *   @topic: 3,6
    */
    this.setColumnLabel=function(c, label, ind){
        var z = this.hdr.rows[ind||1];
        var col = (z._childIndexes ? z._childIndexes[c] : c);
        if (!z.cells[col]) return;
        if (!this.useImagesInHeader){
            var hdrHTML = "<div class='hdrcell'>"

            if (label.indexOf('img:[') != -1){
                var imUrl = label.replace(/.*\[([^>]+)\].*/, "$1");
                label=label.substr(label.indexOf("]")+1, label.length)
                hdrHTML+="<img width='18px' height='18px' align='absmiddle' src='"+imUrl+"' hspace='2'>"
            }
            hdrHTML+=label;
            hdrHTML+="</div>";

            z.cells[col].innerHTML=hdrHTML;

            if (this._hstyles[col])
                z.cells[col].style.cssText=this._hstyles[col];
        } else { //if images in header header
            z.cells[col].style.textAlign="left";
            z.cells[col].innerHTML="<img src='"+this.imgURL+""+label+"' onerror='this.src = \""+this.imgURL
                +"imageloaderror.gif\"'>";
            //preload sorting headers (asc/desc)
            var a = new Image();
            a.src=this.imgURL+""+label.replace(/(\.[a-z]+)/, ".desc$1");
            this.preloadImagesAr[this.preloadImagesAr.length]=a;
            var b = new Image();
            b.src=this.imgURL+""+label.replace(/(\.[a-z]+)/, ".asc$1");
            this.preloadImagesAr[this.preloadImagesAr.length]=b;
        }

        if ((label||"").indexOf("#") != -1){
            var t = label.match(/(^|{)#([^}]+)(}|$)/);

            if (t){
                var tn = "_in_header_"+t[2];

                if (this[tn])
                    this[tn]((this.forceDivInHeader ? z.cells[col].firstChild : z.cells[col]), col, label.split(t[0]));
            }
        }
    }
    /**
    *   @desc: deletes all rows in grid
    *   @param: header - (boolean) enable/disable cleaning header
    *   @type: public
    *   @topic: 5,7,9
    */
    this.clearAll=function(header){
        if (!this.obj.rows[0]) return; //call before initilization
        if (this._h2){
            this._h2=new dhtmlxHierarchy();

            if (this._fake){
                if (this._realfake)
                    this._h2=this._fake._h2;
                else
                    this._fake._h2=this._h2;
            }
        }

        this.limit=this._limitC=0;
        this.editStop(true);

        if (this._dLoadTimer)
            window.clearTimeout(this._dLoadTimer);

        if (this._dload){
            this.objBox.scrollTop=0;
            this.limit=this._limitC||0;
            this._initDrF=true;
        }

        var len = this.rowsCol.length;

        //for some case
        len=this.obj.rows.length;

        for (var i = len-1; i > 0; i--){
            var t_r = this.obj.rows[i];
            t_r.parentNode.removeChild(t_r);
        }

        if (header){
            this._master_row=null;
            this.obj.rows[0].parentNode.removeChild(this.obj.rows[0]);

            for (var i = this.hdr.rows.length-1; i >= 0; i--){
                var t_r = this.hdr.rows[i];
                t_r.parentNode.removeChild(t_r);
            }

            if (this.ftr){
                this.ftr.parentNode.removeChild(this.ftr);
                this.ftr=null;
            }
            this._aHead=this.ftr=this._aFoot=null;
            this._hrrar=[];
            this.columnIds=[];
            this.combos=[];
        }

        //..
        this.row=null;
        this.cell=null;

        this.rowsCol=dhtmlxArray()
        this.rowsAr=[]; //array of rows by idd
        this._RaSeCol=[];
        this.rowsBuffer=dhtmlxArray()
        this.UserData=[]
        this.selectedRows=dhtmlxArray();

        if (this.pagingOn || this._srnd)
            this.xmlFileUrl="";
        if (this.pagingOn)
            this.changePage(1);

        //  if (!this._fake){
        /*
           if ((this._hideShowColumn)&&(this.hdr.rows[0]))
              for (var i=0; i<this.hdr.rows[0].cells.length; i++)
                  this._hideShowColumn(i,"");
       this._hrrar=new Array();*/
        //}
        if (this._contextCallTimer)
            window.clearTimeout(this._contextCallTimer);

        if (this._sst)
            this.enableStableSorting(true);
        this._fillers=this.undefined;
        this.setSortImgState(false);
        this.setSizes();
        //this.obj.scrollTop = 0;

        this.callEvent("onClearAll", []);
    }

//#sorting:06042008{
    /**
    *   @desc: sorts grid by specified field
    *    @invoke: header click
    *   @param: [ind] - index of the field
    *   @param: [repeatFl] - if to repeat last sorting
    *   @type: private
    *   @topic: 3
    */
    this.sortField=function(ind, repeatFl, r_el){
        if (this.getRowsNum() == 0)
            return false;

        var el = this.hdr.rows[0].cells[ind];

        if (!el)
            return; //somehow
        // if (this._dload  && !this.callEvent("onBeforeSorting",[ind,this]) ) return true;

        if (el.tagName == "TH"&&(this.fldSort.length-1) >= el._cellIndex
            &&this.fldSort[el._cellIndex] != 'na'){ //this.entBox.fieldstosort!="" &&
            var data=this.getSortingState();
            var sortType= ( data[0]==ind && data[1]=="asc" ) ? "des" : "asc";

            if (!this.callEvent("onBeforeSorting", [
                ind,
                this.fldSort[ind],
                sortType
            ]))
                return;
            this.sortImg.src=this.imgURL+"sort_"+(sortType == "asc" ? "asc" : "desc")+".gif";

            //for header images
            if (this.useImagesInHeader){
                var cel = this.hdr.rows[1].cells[el._cellIndex].firstChild;

                if (this.fldSorted != null){
                    var celT = this.hdr.rows[1].cells[this.fldSorted._cellIndex].firstChild;
                    celT.src=celT.src.replace(/\.[ascde]+\./, ".");
                }
                cel.src=cel.src.replace(/(\.[a-z]+)/, "."+sortType+"$1")
            }
            //.
            this.sortRows(el._cellIndex, this.fldSort[el._cellIndex], sortType)
            this.fldSorted=el;
            this.r_fldSorted=r_el;
            var c = this.hdr.rows[1];
            var c = r_el.parentNode;
            var real_el = c._childIndexes ? c._childIndexes[el._cellIndex] : el._cellIndex;
            this.setSortImgPos(false, false, false, r_el);
        }
    }

//#}
    /**
    *   @desc: specify if values passed to Header are images file names
    *   @param: fl - true to treat column header values as image names
    *   @type: public
    *   @before_init: 1
    *   @topic: 0,3
    */
    this.enableHeaderImages=function(fl){
        this.useImagesInHeader=fl;
    }

    /**
    *   @desc: set header label and default params for new headers
    *   @param: hdrStr - header string with delimiters
    *   @param: splitSign - string used as a split marker, optional. Default is "#cspan"
    *   @param: styles - array of header styles
    *   @type: public
    *   @before_init: 1
    *   @topic: 0,3
    */
    this.setHeader=function(hdrStr, splitSign, styles){
        if (typeof (hdrStr) != "object")
            var arLab = this._eSplit(hdrStr);
        else
            arLab=[].concat(hdrStr);

        var arWdth = new Array(0);
        var arTyp = new dhtmlxArray(0);
        var arAlg = new Array(0);
        var arVAlg = new Array(0);
        var arSrt = new Array(0);

        for (var i = 0; i < arLab.length; i++){
            arWdth[arWdth.length]=Math.round(100 / arLab.length);
            arTyp[arTyp.length]="ed";
            arAlg[arAlg.length]="left";
            arVAlg[arVAlg.length]=""; //top
            arSrt[arSrt.length]="na";
        }

        this.splitSign=splitSign||"#cspan";
        this.hdrLabels=arLab;
        this.cellWidth=arWdth;
        this.cellType=arTyp;
        this.cellAlign=arAlg;
        this.cellVAlign=arVAlg;
        this.fldSort=arSrt;
        this._hstyles=styles||[];
    }
    /**
   *   @desc:
   *   @param: str - ...
   *   @type: private
   */
    this._eSplit=function(str){
        if (![].push)
            return str.split(this.delim);

        var a = "r"+(new Date()).valueOf();
        var z = this.delim.replace(/([\|\+\*\^])/g, "\\$1")
        return(str||"").replace(RegExp(z, "g"), a).replace(RegExp("\\\\"+a, "g"), this.delim).split(a);
    }

    /**
    *   @desc: get column type by column index
    *   @param: cInd - column index
    *   @returns:  type code
    *   @type: public
    *   @topic: 0,3,4
    */
    this.getColType=function(cInd){
        return this.cellType[cInd];
    }

    /**
    *   @desc: get column type by column ID
    *   @param: cID - column id
    *   @returns:  type code
    *   @type: public
    *   @topic: 0,3,4
    */
    this.getColTypeById=function(cID){
        return this.cellType[this.getColIndexById(cID)];
    }

    /**
    *   @desc: set column types
    *   @param: typeStr - type codes list (default delimiter is ",")
    *   @before_init: 2
    *   @type: public
    *   @topic: 0,3,4
    */
    this.setColTypes=function(typeStr){
        this.cellType=dhtmlxArray(typeStr.split(this.delim));
        this._strangeParams=new Array();

        for (var i = 0; i < this.cellType.length; i++){
            if ((this.cellType[i].indexOf("[") != -1)){
                var z = this.cellType[i].split(/[\[\]]+/g);
                this.cellType[i]=z[0];
                this.defVal[i]=z[1];

                if (z[1].indexOf("=") == 0){
                    this.cellType[i]="math";
                    this._strangeParams[i]=z[0];
                }
            }
            if (!window["eXcell_"+this.cellType[i]]) dhtmlxError.throwError("Configuration","Incorrect cell type: "+this.cellType[i],[this,this.cellType[i]]);
        }
    }
    /**
    *   @desc: set column sort types (avaialble: str, int, date, na or function object for custom sorting)
    *   @param: sortStr - sort codes list with default delimiter
    *   @before_init: 1
    *   @type: public
    *   @topic: 0,3,4
    */
    this.setColSorting=function(sortStr){
        this.fldSort=sortStr.split(this.delim)

    }
    /**
    *   @desc: set align of values in columns
    *   @param: alStr - list of align values (possible values are: right,left,center,justify). Default delimiter is ","
    *   @before_init: 1
    *   @type: public
    *   @topic: 0,3
    */
    this.setColAlign=function(alStr){
        this.cellAlign=alStr.split(this.delim)
    }
/**
*   @desc: set vertical align of columns
*   @param: valStr - vertical align values list for columns (possible values are: baseline,sub,super,top,text-top,middle,bottom,text-bottom)
*   @before_init: 1
*   @type: public
*   @topic: 0,3
*/
    this.setColVAlign=function(valStr){
        this.cellVAlign=valStr.split(this.delim)
    }

/**
*   @desc: create grid with no header. Call before initialization, but after setHeader. setHeader have to be called in any way as it defines number of columns
*   @param: fl - true to use no header in the grid
*   @type: public
*   @before_init: 1
*   @topic: 0,7
*/
    this.setNoHeader=function(fl){
            this.noHeader=convertStringToBoolean(fl);
    }
    /**
    *   @desc: scrolls row to the visible area
    *   @param: rowID - row id
    *   @type: public
    *   @topic: 2,7
    */
    this.showRow=function(rowID){
        this.getRowById(rowID)
        if (this.pagingOn){
            var newPage=Math.floor(this.getRowIndex(rowID) / this.rowsBufferOutSize)+1;
            if (newPage!=this.currentPage)
            this.changePage(newPage);
        }

        if (this._h2) this.openItem(this._h2.get[rowID].parent.id);
        var c = this.getRowById(rowID).childNodes[0];

        while (c&&c.style.display == "none")
            c=c.nextSibling;

        if (c)
            this.moveToVisible(c, true)
    }

    /**
    *   @desc: modify default style of grid and its elements. Call before or after Init
    *   @param: ss_header - style def. expression for header
    *   @param: ss_grid - style def. expression for grid cells
    *   @param: ss_selCell - style def. expression for selected cell
    *   @param: ss_selRow - style def. expression for selected Row
    *   @type: public
    *   @before_init: 2
    *   @topic: 0,6
    */
    this.setStyle=function(ss_header, ss_grid, ss_selCell, ss_selRow){
        this.ssModifier=[
            ss_header,
            ss_grid,
            ss_selCell,
            ss_selCell,
            ss_selRow
        ];

        var prefs = ["#"+this.entBox.id+" table.hdr td", "#"+this.entBox.id+" table.obj td",
            "#"+this.entBox.id+" table.obj tr.rowselected td.cellselected",
            "#"+this.entBox.id+" table.obj td.cellselected", "#"+this.entBox.id+" table.obj tr.rowselected td"];

        for (var i = 0; i < prefs.length; i++)
            if (this.ssModifier[i]){
                if (_isIE)
                    document.styleSheets[0].addRule(prefs[i], this.ssModifier[i]);
                else
                    document.styleSheets[0].insertRule(prefs[i]+" { "+this.ssModifier[i]+" } ", 0);
            }
    }
    /**
    *   @desc: colorize columns  background.
    *   @param: clr - colors list
    *   @type: public
    *   @before_init: 1
    *   @topic: 3,6
    */
    this.setColumnColor=function(clr){
        this.columnColor=clr.split(this.delim)
    }
//#alter_css:06042008{
    /**
    *   @desc: set even/odd css styles
    *   @param: cssE - name of css class for even rows
    *   @param: cssU - name of css class for odd rows
    *   @param: perLevel - true/false - mark rows not by order, but by level in treegrid
    *   @param: levelUnique - true/false - creates additional unique css class based on row level
    *   @type: public
    *   @before_init: 1
    *   @topic: 3,6
    */
    this.enableAlterCss=function(cssE, cssU, perLevel, levelUnique){
        if (cssE||cssU)
            this.attachEvent("onGridReconstructed",function(){
                if (!this._cssSP){
                    this._fixAlterCss();
                    if (this._fake)
                        this._fake._fixAlterCss();
                }
            });

        this._cssSP=perLevel;
        this._cssSU=levelUnique;
        this._cssEven=cssE;
        this._cssUnEven=cssU;
    }
//#}
    /**
    *   @desc: recolor grid from defined point
    *   @type: private
    *   @before_init: 1
    *   @topic: 3,6
    */
    this._fixAlterCss=function(ind){
//#alter_css:06042008{
        if (this._cssSP&&this._h2)
            return this._fixAlterCssTGR(ind);
        if (!this._cssEven && !this._cssUnEven) return;
        ind=ind||0;
        var j = ind;

        for (var i = ind; i < this.rowsCol.length; i++){
            if (!this.rowsCol[i])
                continue;

            if (this.rowsCol[i].style.display != "none"){
                if (this.rowsCol[i].className.indexOf("rowselected") != -1){
                    if (j%2 == 1)
                        this.rowsCol[i].className=this._cssUnEven+" rowselected "+(this.rowsCol[i]._css||"");
                    else
                        this.rowsCol[i].className=this._cssEven+" rowselected "+(this.rowsCol[i]._css||"");
                } else {
                    if (j%2 == 1)
                        this.rowsCol[i].className=this._cssUnEven+" "+(this.rowsCol[i]._css||"");
                    else
                        this.rowsCol[i].className=this._cssEven+" "+(this.rowsCol[i]._css||"");
                }
                j++;
            }
        }
//#}
    }


    /**
    *    @desc: returns absolute left and top position of specified element
    *    @returns: array of two values: absolute Left and absolute Top positions
    *    @param: oNode - element to get position of
    *   @type: private
    *   @topic: 8
    */
    this.getPosition=function(oNode, pNode){
        if (!pNode)
            var pNode = document.body

        var oCurrentNode = oNode;
        var iLeft = 0;
        var iTop = 0;

        while ((oCurrentNode)&&(oCurrentNode != pNode)){ //.tagName!="BODY"){
            iLeft+=oCurrentNode.offsetLeft-oCurrentNode.scrollLeft;
            iTop+=oCurrentNode.offsetTop-oCurrentNode.scrollTop;
            oCurrentNode=oCurrentNode.offsetParent; //isIE()?:oCurrentNode.parentNode;
        }

        if (pNode == document.body){
            if (_isIE){
                if (document.documentElement.scrollTop)
                    iTop+=document.documentElement.scrollTop;

                if (document.documentElement.scrollLeft)
                    iLeft+=document.documentElement.scrollLeft;
            } else if (!_isFF){
                iLeft+=document.body.offsetLeft;
                iTop+=document.body.offsetTop;
            }
        }
        return new Array(iLeft, iTop);
    }
    /**
    *   @desc: gets nearest parent of specified type
    *   @param: obj - input object
    *   @param: tag - string. tag to find as parent
    *   @returns: object. nearest paraent object (including spec. obj) of specified type.
    *   @type: private
    *   @topic: 8
    */
    this.getFirstParentOfType=function(obj, tag){
        while (obj&&obj.tagName != tag&&obj.tagName != "BODY"){
            obj=obj.parentNode;
        }
        return obj;
    }



    /*INTERNAL EVENT HANDLERS*/
    this.objBox.onscroll=function(){
        this.grid._doOnScroll();
    };
//#column_resize:06042008{
    if ((!_isOpera)||(_OperaRv > 8.5)){
        this.hdr.onmousemove=function(e){
            this.grid.changeCursorState(e||window.event);
        };
        this.hdr.onmousedown=function(e){
            return this.grid.startColResize(e||window.event);
        };
    }
//#}
//#tooltips:06042008{
    this.obj.onmousemove=this._drawTooltip;
//#}
    this.obj.onclick=function(e){
        this.grid._doClick(e||window.event);
        if (this.grid._sclE)
            this.grid.editCell(e||window.event);
        (e||event).cancelBubble=true;
    };
//#context_menu:06042008{
    if (_isMacOS){
        this.entBox.oncontextmenu=function(e){
            return this.grid._doContClick(e||window.event);
        };
    } else
        this.entBox.onmousedown=function(e){
            return this.grid._doContClick(e||window.event);
        };

//#}
    this.obj.ondblclick=function(e){
        if (!this.grid.wasDblClicked(e||window.event))
            return false;
        if (this.grid._dclE)
            this.grid.editCell(e||window.event);
        (e||event).cancelBubble=true;
        if (_isOpera) return false; //block context menu for Opera 9+
    };
    this.hdr.onclick=this._onHeaderClick;
    this.sortImg.onclick=function(){
        self._onHeaderClick.apply({
            grid: self
            }, [
            null,
            self.r_fldSorted
        ]);
    };

    this.hdr.ondblclick=this._onHeaderDblClick;


    if (!document.body._dhtmlxgrid_onkeydown){
        dhtmlxEvent(document, _isOpera?"keypress":"keydown",function(e){ //starting from Opera 9.5
            if (globalActiveDHTMLGridObject)
                return globalActiveDHTMLGridObject.doKey(e||window.event);
        });
        document.body._dhtmlxgrid_onkeydown=true;
    }

    dhtmlxEvent(document.body, "click", function(){
        if (self.editStop)
            self.editStop();
    });

    //activity management
    this.entBox.onbeforeactivate=function(){
        this._still_active=null;
        this.grid.setActive();
        event.cancelBubble=true;
    };

    this.entBox.onbeforedeactivate=function(){
        if (this.grid._still_active)
            this.grid._still_active=null;
        else
            this.grid.isActive=false;
        event.cancelBubble=true;
    };

    if (this.entBox.style.height.toString().indexOf("%") != -1)
        this._setAutoResize();

    /* deprecated names */
    this.setColHidden=this.setColumnsVisibility
    this.enableCollSpan = this.enableColSpan
    this.setMultiselect=this.enableMultiselect;
    this.setMultiLine=this.enableMultiline;
    this.deleteSelectedItem=this.deleteSelectedRows;
    this.getSelectedId=this.getSelectedRowId;
    this.getHeaderCol=this.getColumnLabel;
    this.isItemExists=this.doesRowExist;
    this.getColumnCount=this.getColumnsNum;
    this.setSelectedRow
