/*dhtmlxTreeGrid v.1.4 build 70813 Demo Edition
Copyright Scand LLC http://www.scbr.com
This version of Software is for demo purposes only. To use this product please contact info@scbr.com to obtain license*/
 

 
dhtmlXGridObject.prototype._updateTGRState=function(z){if (!z.update || z.id==0)return;this.rowsAr[z.id].imgTag.src=this.imgURL+z.state+".gif";z.update=false;};dhtmlXGridObject.prototype.doExpand=function(obj){this.editStop();var row = obj.parentNode.parentNode.parentNode;var r=this._h2.get[row.idd];if(r.state=="plus")this.expandKids(row,true)
 else
 if((r.state=="minus")&&(!r._closeable))
 this.collapseKids(row)
};function dhtmlxHierarchy(){var z={id:0, childs:[], level:-1, parent:null, index:0, state:"blank"};this.order=[z];this.get={"0":z};this.swap=function(a,b){var p=a.parent;var z=a.index;p.childs[z]=b;p.childs[b.index]=a;a.index=b.index;b.index=z;};this.forEachChild=function(id,funct,that){var z=this.get[id];for (var i=0;i<z.childs.length;i++){funct.apply(that,[z.childs[i]]);if (z.childs[i].childs.length)this.forEachChild(z.childs[i].id,funct,that);};};this.change=function(id,name,val){var z=this.get[id];if (z[name]==val)return;z[name]=val;z.update=true;};this.add=function(id,parentId){return this.addAfter(id,parentId);};this.addAfter=function(id,parentId,afterId,fix){var z=this.get[parentId||0];if (afterId)var ind=this.get[afterId].index+(fix?0:1);else var ind=z.childs.length;var x={id:id, childs:[], level:z.level+1, parent:z, index:ind, state:"blank"};if (z.childs.length==0)this.change(parentId,"state","plus");if (afterId){for (var i=ind;i<z.childs.length;i++)z.childs[i].index++;z.childs=z.childs.slice(0,ind).concat([x]).concat(z.childs.slice(ind,z.childs.length));}else
 z.childs.push(x);this.get[id]=x;return x;};this.addBefore=function(id,parentId,beforeId){return this.addAfter(id,parentId,beforeId,true)
 };this.remove=function(id){var z=this.get[id||0];for (var i=0;i<z.childs.length;i++)this.deleteAll(z.childs[i].id)
 
 z.parent.childs=z.parent.childs.slice(0,z.index).concat(z.parent.childs.slice(z.index+1));for (var i=z.index;i<z.parent.childs.length;i++)z.parent.childs[i].index--;delete this.get[id];};this.deleteAll=function(id){var z=this.get[id||0];for (var i=0;i<z.childs.length;i++)this.deleteAll(z.childs[i].id)
 
 z.parent.childs=[];delete this.get[id];};return this;};dhtmlXGridObject.prototype._getOpenLenght=function(id,start){var z=this._h2.get[id].childs;start+=z.length;for (var i=0;i<z.length;i++)if (z[i].childs.length && z[i].state=='minus')start+=this._getOpenLenght(z[i].id,0);return start;};dhtmlXGridObject.prototype.collapseKids=function(curRow){var r=this._h2.get[curRow.idd];if (r.state!="minus")return;if ((this._spnFH)&&(!this._spnFH(curRow.idd,1))) return;var start = curRow.rowIndex;this._h2.change(r.id,"state","plus");this._updateTGRState(r);var len=this._getOpenLenght(this.rowsCol[start-1].idd,0);for (var i=0;i<len;i++)this.rowsCol[0].parentNode.removeChild(this.rowsCol[start+i]);this.rowsCol.splice(start,len);if (this._cssEven && !this._cssSP)this._fixAlterCss(start);if (this._epnFH)this._epnFH(curRow.idd,-1);this.setSizes();};dhtmlXGridObject.prototype._massInsert=function(r,start,ind){var anew=[];for(var i=0;i<r.childs.length;i++){var ra=this.rowsAr[r.childs[i].id];if (start)start.parentNode.insertBefore(ra,start);else
 this.obj.rows[0].parentNode.appendChild(ra);anew.push(ra)
 };this.rowsCol=dhtmlXHeir(this.rowsCol.slice(0,ind).concat(anew).concat(this.rowsCol.slice(ind)),this._aEx);var dx=0;for(var i=0;i<r.childs.length;i++)if (r.childs[i].state=="minus")dx+=this._massInsert(r.childs[i],this.rowsCol[ind+i+dx+1],ind+i+dx+1);return r.childs.length+dx;};dhtmlXGridObject.prototype.expandKids=function(curRow){var r=this._h2.get[curRow.idd];if ((!r.childs.length)&&(!r._xml_await)) return;if (r.state!="plus")return;if (!r._loading)if ((this._spnFH)&&(!this._spnFH(r.id,-1))) return;var start = this.getRowIndex(r.id)+1;if(r.childs.length){r._loading=false;this._h2.change(r.id,"state","minus")
 this._updateTGRState(r);var len=this._massInsert(r,this.rowsCol[start],start);if (this._cssEven && !this._cssSP)this._fixAlterCss(start);}else{if (r._xml_await){if ((this._slowParse)&&(curRow._xml)){this._reParse(curRow);return this.expandKids(curRow);};if(this.kidsXmlFile.indexOf("?")!=-1)
 var s = "&";else
 var s = "?";curRow._loading=true;this.loadXML(this.kidsXmlFile+""+s+"id="+r.id);};};this.setSizes();if (!r._loading)if (this._epnFH)this._epnFH(curRow.idd,1);};dhtmlXGridObject.prototype.kidsXmlFile = "";dhtmlXGridObject.prototype.sortTreeRows = function(col,type,order){this.forEachRow(function(id){var z=this._h2.get[id];var label=this.cells(id,col).getValue();if(type=='int'){z._sort=parseFloat(label);z._sort=isNaN(z._sort)?-99999999999999:z._sort;}else
 z._sort=label;});var self=this;var pos=1;var neg=-1;if (order=="des"){pos=-1;neg=1;};var funct=null;if(type=='cus')funct=function(a,b){return self._customSorts[col](a._sort,b._sort,order);};if(type=='str')funct=function(a,b){return (a._sort<b._sort?neg:(a._sort==b._sort?0:pos))};if(type=='int')funct=function(a,b){return (a._sort<b._sort?neg:(a._sort==b._sort?0:pos))};if(type=='date')funct=function(a,b){return (Date.parse(new Date(a._sort))-Date.parse(new Date(b._sort)))*pos};this._sortTreeRows(funct,0);for (var i=0;i<this.rowsCol.length;i++)this.rowsCol[i].parentNode.removeChild(this.rowsCol[i]);this.rowsCol=new dhtmlxArray();this._renderSort(0,true);this.callEvent("onGridReconstructed",[]);};dhtmlXGridObject.prototype._sortTreeRows = function(funct,id){var ar=this._h2.get[id].childs;ar.sort(funct);for (var i=0;i<ar.length;i++)if (ar[i].childs.length)this._sortTreeRows(funct,ar[i].id);};dhtmlXGridObject.prototype._renderSort = function(id,mode){var ar=this._h2.get[id].childs;for (var i=0;i<ar.length;i++){if (mode){var row=this.rowsAr[ar[i].id];this.obj.rows[0].parentNode.appendChild(row)
 this.rowsCol.push(row);};ar[i].index=i;if (ar[i].childs.length)if (ar[i].state=="minus")this._renderSort(ar[i].id,true);};};dhtmlXGridObject.prototype._fixAlterCssTG = function(){};dhtmlXGridObject.prototype._fixAlterCssTGR = function(){this._h2.forEachChild(0,function(x){this.rowsAr[x.id].className=((x.level%2)?(this._cssUnEven+" "+this._cssUnEven):(this._cssEven+" "+this._cssEven))+"_"+x.level;},this);};dhtmlXGridObject.prototype.moveRowUDTG = function(id,dir){var x=this._h2.get[id];var p=x.parent.childs[x.index+dir]
 if ((!p)|| (p.parent!=x.parent)) return;var state=[x.state,p.state];this.collapseKids(this.rowsAr[x.id]);this.collapseKids(this.rowsAr[p.id]);var ind = this.rowsCol._dhx_find(this.rowsAr[id]);var nod=this.rowsCol[0].parentNode.removeChild(this.rowsCol[ind]);var tar=this.rowsCol[ind+((dir==1)?2:dir)];if (tar)tar.parentNode.insertBefore(nod,tar);else
 this.rowsCol[0].parentNode.appendChild(nod);this.rowsCol._dhx_swapItems(ind,ind+dir)
 this._h2.swap(p,x);if (state[0]=="minus")this.expandKids(this.rowsAr[x.id]);if (state[1]=="minus")this.expandKids(this.rowsAr[p.id]);};function eXcell_tree(cell){if (cell){this.cell = cell;this.grid = this.cell.parentNode.grid;};this.edit = function(){if ((this.er)||(this.grid._edtc)) return;this.er=this.cell.parentNode.valTag;this.val=this.er.innerHTML;this.er.innerHTML="<textarea class='dhx_combo_edit' type='text' style='height:"+(this.cell.offsetHeight-6)+"px;width:100%;border:0px;margin:0px;padding:0px;padding-top:"+(_isFF?1:2)+"px;overflow:hidden;'></textarea>";this.er.childNodes[0].onmousedown = function(e){(e||event).cancelBubble = true};this.er.childNodes[0].onselectstart=function(e){if (!e)e=event;e.cancelBubble=true;return true;};if (_isFF)this.er.style.top="1px";this.er.className+=" editable";this.er.firstChild.onclick = function(e){(e||event).cancelBubble = true};this.er.firstChild.value=this.val;this.er.firstChild.focus();};this.detach = function(){if (!this.er)return;this.er.innerHTML=this.er.firstChild.value;this.er.className=this.er.className.replace("editable","");var z=(this.val!=this.er.innerHMTL);if (_isFF)this.er.style.top="2px";if (this.grid._onCCH)this.grid._onCCH(this.cell.parentNode.idd,this.cell._cellIndex,this.er.innerHTML);this.er=null;return (z);};this.getValue = function(){return this.getLabel();};this.setValueA = function(content){this.cell.parentNode.valTag.innerHTML=content;if (this.grid._onCCH)this.grid._onCCH(this.cell.parentNode.idd,this.cell._cellIndex,content);};this.setImage = function(url){this.cell.parentNode.nextSibling.src=this.grid.imgURL+"/"+url;};this.getImage = function(){this.grid._h2.get[this.cell.parentNode.idd].image;};this.setLabel = function(val){this.setValueA(val);};this.getLabel = function(val){return this.cell.parentNode.valTag.innerHTML;};this.setValue = function(valAr){if (typeof(valAr)!="object")
 valAr = valAr.split("^");if ((this.grid._tgc.imgURL==null)||(this.grid._tgc.imgURL!=this.grid.imgURL)){var _tgc={};_tgc.spacer="<span class='space'><img src='"+this.grid.imgURL+"blanc.gif' height='1px' class='space'></span>";_tgc.imst="<img src='"+this.grid.imgURL;_tgc.imact="' align='absmiddle' onclick='this."+(_isKHTML?"":"parentNode.")+"parentNode.parentNode.parentNode.parentNode.grid.doExpand(this);event.cancelBubble=true;'>"
 _tgc.plus=_tgc.imst+"plus.gif"+_tgc.imact;_tgc.minus=_tgc.imst+"minus.gif"+_tgc.imact;_tgc.blank=_tgc.imst+"blank.gif"+_tgc.imact;_tgc.start="<div style=' overflow:hidden;white-space : nowrap;height:"+(_isIE?20:18)+"px;'>";_tgc.itemim="' align='absmiddle' "+(this.grid._img_height?(" height=\""+this.grid._img_height+"\""):"")+(this.grid._img_width?(" width=\""+this.grid._img_width+"\""):"")+" ><span "+(_isFF?"style='position:relative;top:2px;'":"")+"id='nodeval'>";_tgc.close="</span></div>";this.grid._tgc=_tgc;};var _h2=this.grid._h2;var _tgc=this.grid._tgc;var rid=this.cell.parentNode.idd;var pid=valAr[0];if (_h2.get[rid])return alert("Not unique ID :: "+rid+", row skiped");var prow=_h2.get[(pid||0)];if ((this.grid._add_trgr || this.grid._add_trgr=="0")&& prow.childs.length){if (this.grid._add_trgr==0)var row =_h2.addBefore(rid,(pid||0),prow.childs[0].id);else
 var row =_h2.addAfter(rid,(pid||0),prow.childs[this.grid._add_trgr-1].id);delete this.grid._add_trgr;}else
 var row =_h2.add(rid,(pid||0))
 
 
 if ((!this.grid.kidsXmlFile)&&(!this.grid._slowParse)) valAr[2]=0;row.has_kids=(valAr[2]||0);row._xml_await=(valAr[2]!=0);row.image=valAr[3];row.label=valAr[1];var html=[_tgc.start];for(var i=0;i<row.level;i++)html.push(_tgc.spacer);if(valAr[2]!="" && valAr[2]!=0){html.push(_tgc.plus);row.state="plus"
 }else
 html.push(_tgc.blank);html.push(_tgc.imst);html.push(valAr[3]);html.push(_tgc.itemim);html.push(valAr[1]);html.push(_tgc.close);this.cell.innerHTML=html.join("");this.cell.parentNode.imgTag=this.cell.childNodes[0].childNodes[row.level];this.cell.parentNode.valTag=this.cell.childNodes[0].childNodes[row.level+2];if (_isKHTML)this.cell.vAlign="top";if (prow.id!=0 && prow.state=="plus"){this.grid._updateTGRState(prow);this.cell.parentNode._skipInsert=true;};this.grid.callEvent("onCellChanged",[rid,this.cell._cellIndex,valAr[1]]);};};eXcell_tree.prototype = new eXcell;dhtmlXGridObject.prototype._removeTrGrRow=function(node){var ind=this.getRowIndex(node.idd);var x=this._h2.get[node.idd];if (ind!=-1){var len=1;if (x.state=="minus")len+=this._getOpenLenght(x.id,0)
 for (var i=0;i<len;i++)this.obj.rows[0].parentNode.removeChild(this.rowsCol[i+ind]);this.rowsCol.splice(ind,len);};this._h2.forEachChild(x.id,function(x){delete this.rowsAr[x.id];},this);delete this.rowsAr[x.id];if (x.parent.childs.length==1){this._h2.change(x.parent.id,"state","blank");this._updateTGRState(x.parent);};this._h2.remove(x.id);if (this._math_summ && x.parent)this._recalc_summ(x.parent);};dhtmlXGridObject.prototype.openItem=function(rowId){var y=this._h2.get[rowId||0];var x=this.getRowById(rowId||0);if (!x)return;if (y.parent && y.parent.id!=0)this.openItem(y.parent.id);this.expandKids(x);};dhtmlXGridObject.prototype._addRowClassic=dhtmlXGridObject.prototype.addRow;dhtmlXGridObject.prototype.addRow=function(new_id,text,ind,parent_id,img,child){parent_id=parent_id||0;var trcol=this.cellType._dhx_find("tree");if (typeof(text)=="string") text=text.split(this.delim);var last_row=null;if ((trcol!=-1)&&((text[trcol]||"").toString().search(/\^/gi)==-1)){var def=text[trcol];var d=parent_id.toString().split(",");for (var i=0;i<d.length;i++){text[trcol]=d[i]+"^"+def+"^"+(child?1:0)+"^"+(img||"leaf.gif");if (d[i]!=0)if ((!ind)||(ind==0)){ind=this.getRowIndex(d[i]);if (ind!=-1){if (this._h2.get[d[i]].state=="minus")ind+=this._getOpenLenght(d[i],0)+1;if ((this._slowParse)&&(this.rowsCol[ind]._xml)) this._reParse(this.rowsCol[ind]);};};if(!this._add_trgr){if (this._h2.get[parent_id].state!="minus")this._add_trgr=this._h2.get[parent_id].childs.count+1;else
 if(this.rowsCol[ind-1])this._add_trgr=this.trackParent(this._h2.get[this.rowsCol[ind-1].idd],(parent_id||0))
 else this._add_trgr=0;};last_row=this._addRowClassic(new_id,text,((!parent_id)&&(!ind)&&(ind!="0"))?window.undefined:ind);};return last_row;};return this._addRowClassic(new_id,text,ind);};dhtmlXGridObject.prototype.trackParent=function(x,id){if (x.id==id)return 0;if (x.parent.id==id)return x.index+1;return this.trackParent(x.parent,id);};dhtmlXGridObject.prototype.addRowBefore=function(new_id,text,sibl_id,img,child){var sb=this.rowsAr[sibl_id];if (!sb)return;var ind=this.getRowIndex(sibl_id);this._add_trgr=this._h2.get[sibl_id].index;return this.addRow(new_id,text,ind,this._h2.get[sibl_id].parent.id,img,child);};dhtmlXGridObject.prototype.addRowAfter=function(new_id,text,sibl_id,img,child){var sb=this.rowsAr[sibl_id];if (!sb)return;var ind=this.getRowIndex(sibl_id);this._add_trgr=this._h2.get[sibl_id].index+1;if (this._h2.get[sibl_id].state=="minus")ind+=this._getOpenLenght(sibl_id,0)+1;else ind++;return this.addRow(new_id,text,ind,this._h2.get[sibl_id].parent.id,img,child);};dhtmlXGridObject.prototype.getLevel=function(rowId){var z=this._h2.get[rowId||0];if (!z)return -1;return z.level;};dhtmlXGridObject.prototype._fixHiddenRowsAllTG=function(ind,state){for (i in this.rowsAr){if ((this.rowsAr[i])&&(this.rowsAr[i].childNodes))
 this.rowsAr[i].childNodes[ind].style.display=state;};};
