/*
===================================================================
Copyright DHTMLX LTD. http://www.dhtmlx.com
This code is obfuscated and not allowed for any purposes except 
using on sites which belongs to DHTMLX LTD.

Please contact sales@dhtmlx.com to obtain necessary 
license for usage of dhtmlx components.
===================================================================
*/dhtmlXGridObject.prototype.unGroup=function(){if(this._groups)this._dndProblematic= !1,delete this._groups,delete this._gIndex,this._fake&&this._mirror_rowsCol(),this.forEachRow(function(a){this.rowsAr[a].style.display=""}),this._reset_view(),this.callEvent("onGridReconstructed",[]),this.callEvent("onUnGroup",[])};dhtmlXGridObject.prototype._mirror_rowsCol=function(){this._fake._groups=this._groups;this._fake._gIndex=this._gIndex;this.rowsBuffer=dhtmlxArray();for(var a=0;a<this.rowsCol.length;a++)this.rowsCol[a]._cntr||this.rowsBuffer.push(this.rowsCol[a]);this._fake.rowsBuffer=dhtmlxArray();for(a=0;a<this._fake.rowsCol.length;a++)this._fake.rowsCol[a]._cntr||this._fake.rowsBuffer.push(this._fake.rowsCol[a])};dhtmlXGridObject.prototype.groupBy=function(a,d){this._groups&&this.unGroup();this._dndProblematic= !0;this._groups={};if(!d)for(var d=["#title"],b=1;b<this._cCount;b++)d.push("#cspan");this._gmask=document.createElement("TR");this._gmask.origin=d;for(var c,e=0,b=0;b<d.length;b++)if(d[b]=="#cspan")c.colSpan=(parseInt(c.colSpan)||1)+1;else{c=document.createElement("TD");c._cellIndex=b;if(this._hrrar[b])c.style.display="none";c.className="group_row";c.innerHTML="&nbsp;";d[b]=="#title"?this._gmask._title=e:c.align=this.cellAlign[b]||"left";this._gmask.appendChild(c);if(d[b].indexOf("#stat")==0)this._gmask._math= !0,c._counter=[this["_g_"+d[b].replace("#","")],b,e];e++}for(var f in this._groups)this._groups[f]=this.undefined;this._gIndex=a;if(this._fake&& !this._realfake)this._fake._groups=[],this._fake._gIndex=this._gIndex;this._nextRow=function(a,b){var c=this.rowsCol[a+b];return c&&(c.style.display=="none"||c._cntr)?this._nextRow(a+b,b):c};if(!this.__sortRowsBG)this._key_events=dhtmlXHeir({},this._key_events),this._key_events.k38_0_0=function(){if(this.editor&&this.editor.combo)this.editor.shiftPrev();else{var a=this.row.rowIndex;if(a){var b=this._nextRow(a-1,-1);b&&this.selectCell(b,this.cell._cellIndex,!0)}}},this._key_events.k13_1_0=this._key_events.k13_0_1=function(){},this._key_events.k40_0_0=function(){if(this.editor&&this.editor.combo)this.editor.shiftNext();else{var a=this.row.rowIndex;if(a){var b=this._nextRow(a-1,1);b&&this.selectCell(b,this.cell._cellIndex,!0)}}},this.attachEvent("onFilterStart",function(){if(this._groups)this._groups=this.undefined;return!0}),this.attachEvent("onFilterEnd",function(){typeof this._gIndex!="undefined"&&this.groupBy(this._gIndex,this._gmask.origin)}),this.sortRows_bg=this.sortRows,this.sortRows=function(a,b,c){if(typeof this._groups=="undefined")return this.sortRows_bg.apply(this,arguments);this.callEvent("onBeforeSorting",[a,b||"str",c||"asc"])},this.attachEvent("onBeforeSorting",function(a,b,c){if(typeof this._groups=="undefined")return!0;a==this._gIndex?this._sortByGroup(a,b,c):this._sortInGroup(a,b,c);this.setSortImgState(!0,a,c);if(this._fake)this._mirror_rowsCol(),this._fake._groups=[],this._fake._reset_view();this.setSortImgState(!0,a,c);this.callEvent("onAfterSorting",[a,b,c]);return!1}),this.attachEvent("onClearAll",function(){this.unGroup()}),this.attachEvent("onBeforeRowDeleted",function(a){if(!this._groups)return!0;if(!this.rowsAr[a])return!0;var b=this.cells(a,this._gIndex).getValue();b===""&&(b=" ");var c=this._groups[b];this._dec_group(c);return!0}),this.attachEvent("onAfterRowDeleted",function(){this.updateGroups()}),this.attachEvent("onCheckbox",function(a,b,c){this.callEvent("onEditCell",[2,a,b,c?1:0,c?0:1])}),this.attachEvent("onXLE",this.updateGroups),this.attachEvent("onColumnHidden",this.hideGroupColumn),this.attachEvent("onEditCell",function(a,b,c,d,e){if(!this._groups)return!0;if(a==2&&d!=e&&c==this._gIndex){e===""&&(e=" ");this._dec_group(this._groups[e]);var f=this.rowsAr[b],j=this.rowsCol._dhx_find(f),k=this._inc_group(d),g=this.rowsCol[k];if(f==g)g=g.nextSibling;var l=f.parentNode,n=f.rowIndex;l.removeChild(f);g?l.insertBefore(f,g):l.appendChild(f);this.rowsCol._dhx_insertAt(k,f);k<j&&j++;this.rowsCol._dhx_removeAt(j,f);this._fixAlterCss()}else a==2&&d!=e&&(this.updateGroups(),this._updateGroupView(this._groups[this.cells(b,this._gIndex).getValue()||" "]));return!0}),this.__sortRowsBG= !0;this._groupExisting();if(this._hrrar)for(b=0;b<this._hrrar.length;b++)this._hrrar[b]&&this.hideGroupColumn(b,!0);this.callEvent("onGroup",[]);(this._ahgr||this._awdth)&&this.setSizes()};dhtmlXGridObject.prototype._sortInGroup=function(a,d,b){var c=this._groups_get();c.reverse();for(var e=0;e<c.length;e++){for(var f=c[e]._cntr._childs,m={},h=0;h<f.length;h++){var i=this.cells3(f[h],a);m[f[h].idd]=i.getDate?i.getDate():i.getValue()}this._sortCore(a,d,b,m,f)}this._groups_put(c);this.setSizes();this.callEvent("onGridReconstructed",[])};dhtmlXGridObject.prototype._sortByGroup=function(a,d,b){for(var c=this._groups_get(),e=[],f=0;f<c.length;f++)c[f].idd="_sort_"+f,e["_sort_"+f]=c[f]._cntr.text;this._sortCore(a,d,b,e,c);this._groups_put(c);this.callEvent("onGridReconstructed",[]);this.setSizes()};dhtmlXGridObject.prototype._inc_group=function(a,d,b){a===""&&(a=" ");this._groups[a]||(this._groups[a]={text:a,row:this._addPseudoRow(),count:0,state:d?"plus":"minus"});var c=this._groups[a];c.row._cntr=c;var e=this.rowsCol._dhx_find(c.row)+c.count+1;c.count++;b||(this._updateGroupView(c),this.updateGroups());return e};dhtmlXGridObject.prototype._dec_group=function(a){if(a)return a.count--,a.count==0?(a.row.parentNode.removeChild(a.row),this.rowsCol._dhx_removeAt(this.rowsCol._dhx_find(a.row)),delete this._groups[a.text]):this._updateGroupView(a),this._fake&& !this._realfake&&this._fake._dec_group(this._fake._groups[a.text]),this.updateGroups(),!0};dhtmlXGridObject.prototype._insertRowAt_gA=dhtmlXGridObject.prototype._insertRowAt;dhtmlXGridObject.prototype._insertRowAt=function(a,d,b){if(typeof this._groups!="undefined"){var c=this._realfake?this._fake._bfs_cells(a.idd,this._gIndex).getValue():this._bfs_cells3?this._bfs_cells3(a,this._gIndex).getValue():this.cells3(a,this._gIndex).getValue();c||(c=" ");d=this._inc_group(c,a.style.display=="none")}var e=this._insertRowAt_gA(a,d,b);typeof this._groups!="undefined"&&(this.expandGroup(c),this._updateGroupView(this._groups[c]),this.updateGroups());return e};dhtmlXGridObject.prototype._updateGroupView=function(a){if(this._fake&& !this._realfake)return a.row.firstChild.innerHTML="&nbsp;";var d=this._gmask||this._fake._gmask,b="<img style='margin-bottom:-4px' src='"+this.imgURL+a.state+".gif'> ";b+=this.customGroupFormat?this.customGroupFormat(a.text,a.count):a.text+" ( "+a.count+" ) ";a.row.childNodes[d._title].innerHTML=b};dhtmlXGridObject.prototype._addPseudoRow=function(a){for(var d=this._gmask||this._fake._gmask,b=d.cloneNode(!0),c=0;c<b.childNodes.length;c++)if(b.childNodes[c]._cellIndex=d.childNodes[c]._cellIndex,this._realfake)b.childNodes[c].style.display="";var e=this;b.onclick=function(a){e._fake&&e._realfake?e._fake._switchGroupState(e._fake._groups[this._cntr.text].row):e._switchGroupState(this);(a||event).cancelBubble="true"};b.ondblclick=function(a){(a||event).cancelBubble="true"};a||(_isKHTML?this.obj.appendChild(b):this.obj.firstChild.appendChild(b),this.rowsCol.push(b));return b};dhtmlXGridObject.prototype._groups_get=function(){var a=[];this._temp_par=this.obj.parentNode;this._temp_par.removeChild(this.obj);for(var d=[],b=this.rowsCol.length-1;b>=0;b--)this.rowsCol[b]._cntr?(this.rowsCol[b]._cntr._childs=d,d=[],a.push(this.rowsCol[b])):d.push(this.rowsCol[b]),this.rowsCol[b].parentNode.removeChild(this.rowsCol[b]);return a};dhtmlXGridObject.prototype._groups_put=function(a){var d=this.rowsCol.stablesort;this.rowsCol=new dhtmlxArray(0);this.rowsCol.stablesort=d;for(var b=0;b<a.length;b++){var c=a[b]._cntr;this.obj.firstChild.appendChild(c.row);this.rowsCol.push(c.row);c.row.idd=null;for(var e=0;e<c._childs.length;e++)this.obj.firstChild.appendChild(c._childs[e]),this.rowsCol.push(c._childs[e]);delete c._childs}this._temp_par.appendChild(this.obj)};dhtmlXGridObject.prototype._groupExisting=function(a){if(this.getRowsNum()){a=[];this._temp_par=this.obj.parentNode;this._temp_par.removeChild(this.obj);for(var d=[],b=this.rowsCol.length,c=0;c<b;c++){var e=this.cells4(this.rowsCol[c].childNodes[this._gIndex]).getValue();this.rowsCol[c].style.display="";e||(e=" ");if(!this._groups[e]){this._groups[e]={text:e,row:this._addPseudoRow(!0),count:0,state:"minus"};var f=this._groups[e];f.row._cntr=f;this._groups[e]._childs=[];a.push(f.row)}this._groups[e].count++;this._groups[e]._childs.push(this.rowsCol[c]);this.rowsCol[c].parentNode.removeChild(this.rowsCol[c])}for(c=0;c<a.length;c++)this._updateGroupView(a[c]._cntr);this._groups_put(a);if(this._fake&& !this._realfake)this._mirror_rowsCol(),this._fake._groups=[],this._fake._reset_view();this.callEvent("onGridReconstructed",[]);this.updateGroups()}};dhtmlXGridObject.prototype._switchGroupState=function(a){var d=a._cntr;if(this._fake&& !this._realfake)d.state=this._fake._groups[a._cntr.text].row._cntr.state,this._fake._switchGroupState(this._fake._groups[a._cntr.text].row);var b=this.rowsCol._dhx_find(d.row)+1;d.state=d.state=="minus"?"plus":"minus";for(var c=d.state=="plus"?"none":"";this.rowsCol[b]&& !this.rowsCol[b]._cntr;)this.rowsCol[b].style.display=c,b++;this._updateGroupView(d);this.callEvent("onGroupStateChanged",[d.text,d.state=="minus"]);this.setSizes()};dhtmlXGridObject.prototype.expandGroup=function(a){this._groups[a].state=="plus"&&this._switchGroupState(this._groups[a].row)};dhtmlXGridObject.prototype.collapseGroup=function(a){this._groups[a].state=="minus"&&this._switchGroupState(this._groups[a].row)};dhtmlXGridObject.prototype.expandAllGroups=function(){for(var a in this._groups)this._groups[a]&&this._groups[a].state=="plus"&&this._switchGroupState(this._groups[a].row)};dhtmlXGridObject.prototype.collapseAllGroups=function(){for(var a in this._groups)this._groups[a]&&this._groups[a].state=="minus"&&this._switchGroupState(this._groups[a].row)};dhtmlXGridObject.prototype.hideGroupColumn=function(a,d){if(!this._fake){for(var b= -1,c=this._gmask.childNodes,e=0;e<c.length;e++)if(c[e]._cellIndex==a){b=e;break}if(b!= -1)for(var f in this._groups)this._groups[f].row.childNodes[b].style.display=d?"none":""}};dhtmlXGridObject.prototype.groupStat=function(a,d,b){var b=this["_g_"+(b||"stat_total")],c=0,e=0;this.forEachRowInGroup(a,function(a){c=b(c,this.cells(a,d).getValue()*1,e);e++});return c};dhtmlXGridObject.prototype.forEachRowInGroup=function(a,d){var b=this._groups[a].row.nextSibling;if(b)for(;b&& !b._cntr;)d.call(this,b.idd),b=b.nextSibling;else{var c=this._groups[a]._childs;if(c)for(var e=0;e<c.length;e++)d.call(this,c[e].idd)}};dhtmlXGridObject.prototype.updateGroups=function(){if(this._gmask&&this._gmask._math&& !this._parsing)for(var a=this._gmask.childNodes,d=0;d<a.length;d++)a[d]._counter&&this._b_processing.apply(this,a[d]._counter)};dhtmlXGridObject.prototype._b_processing=function(a,d,b){var c=0,e=0;this._ecache[this.cellType[d]]||this.cells5({parentNode:{grid:this}},this.cellType[d]);for(var f=this.rowsCol.length-1;f>=0;f--)this.rowsCol[f]._cntr?(this.cells5(this.rowsCol[f].childNodes[b],this.cellType[d]).setValue(c),e=c=0):(c=a(c,this.cells3(this.rowsCol[f],d).getValue()*1,e),e++)};dhtmlXGridObject.prototype._g_stat_total=function(a,d){return a+d};dhtmlXGridObject.prototype._g_stat_min=function(a,d,b){b||(a=Infinity);return Math.min(a,d)};dhtmlXGridObject.prototype._g_stat_max=function(a,d,b){b||(a= -Infinity);return Math.max(a,d)};dhtmlXGridObject.prototype._g_stat_average=function(a,d,b){return(a*b+d)/(b+1)};dhtmlXGridObject.prototype._g_stat_count=function(a){return a++};
