/*
===================================================================
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.insertColumn=function(b,a,d,c,f,e,g,h,k){b=parseInt(b);if(b>this._cCount)b=this._cCount;if(!this._cMod)this._cMod=this._cCount;this._processAllArrays(this._cCount,b-1,[a||"&nbsp;",c||100,d||"ed",e||"left",g||"",f||"na",k||"","",this._cMod,c||100]);this._processAllRows("_addColInRow",b);if(typeof a=="object")for(var i=1;i<this.hdr.rows.length;i++)if(a[i-1]=="#rspan"){for(var l=i-1,n= !1,m=null;!n;){for(var m=this.hdr.rows[l],j=0;j<m.cells.length;j++)if(m.cells[j]._cellIndex==b){n=j;break}l--}this.hdr.rows[l+1].cells[j].rowSpan=(this.hdr.rows[l].cells[j].rowSpan||1)+1}else this.setHeaderCol(b,a[i-1]||"&nbsp;",i);else this.setHeaderCol(b,a||"&nbsp;");this._cCount++;this._cMod++;this._master_row=null;this.setSizes()};dhtmlXGridObject.prototype.deleteColumn=function(b){b=parseInt(b);if(this._cCount!=0){if(!this._cMod)this._cMod=this._cCount;if(!(b>=this._cCount))this._processAllArrays(b,this._cCount-1,[null,null,null,null,null,null,null,null,null,null,null]),this._processAllRows("_deleteColInRow",b),this._cCount--,this._master_row=null,this.setSizes()}};dhtmlXGridObject.prototype._processAllRows=function(b,a,d){this[b](this.obj.rows[0],a,d,0);for(var c=this.hdr.rows.length,f=0;f<c;f++)this[b](this.hdr.rows[f],a,d,f);if(this.ftr){c=this.ftr.firstChild.rows.length;for(f=0;f<c;f++)this[b](this.ftr.firstChild.rows[f],a,d,f)}this.forEachRow(function(c){if(this.rowsAr[c]&&this.rowsAr[c].tagName=="TR")this[b](this.rowsAr[c],a,d,-1)})};dhtmlXGridObject.prototype._processAllArrays=function(b,a,d){var c="hdrLabels,initCellWidth,cellType,cellAlign,cellVAlign,fldSort,columnColor,_hrrar,_c_order".split(",");this.cellWidthPX.length&&c.push("cellWidthPX");this.cellWidthPC.length&&c.push("cellWidthPC");this._col_combos&&c.push("_col_combos");this._mCols&&(c[c.length]="_mCols");this.columnIds&&(c[c.length]="columnIds");this._maskArr&&c.push("_maskArr");this._drsclmW&&c.push("_drsclmW");this.clists&&c.push("clists");this._validators&&this._validators.data&&c.push(this._validators.data);c.push("combos");this._customSorts&&c.push("_customSorts");this._aggregators&&c.push("_aggregators");var f=b<=a;if(!this._c_order){this._c_order=[];for(var e=this._cCount,g=0;g<e;g++)this._c_order[g]=g}for(g=0;g<c.length;g++){var h=this[c[g]]||c[g];if(h){if(f){for(var k=h[b],i=b;i<a;i++)h[i]=h[i+1];h[a]=k}else{k=h[b];for(i=b;i>a+1;i--)h[i]=h[i-1];h[a+1]=k}d&&(h[a+(f?0:1)]=d[g])}}};dhtmlXGridObject.prototype.moveColumn=function(b,a){a--;var b=parseInt(b),a=parseInt(a),d=a<b?a+1:a;if(!this.callEvent("onBeforeCMove",[b,d]))return!1;b!=d&&(this.editStop(),this._processAllRows("_moveColInRow",b,a),this._processAllArrays(b,a),this.fldSorted&&this.setSortImgPos(this.fldSorted._cellIndex),this.callEvent("onAfterCMove",[b,d]))};dhtmlXGridObject.prototype._swapColumns=function(b){for(var a=[],d=0;d<this._cCount;d++){var c=b[this._c_order[d]];typeof c=="undefined"&&(c="");a[d]=c}return a};dhtmlXGridObject.prototype._moveColInRow=function(b,a,d){var c=b.childNodes[a],f=b.childNodes[d+1];if(c){f?b.insertBefore(c,f):b.appendChild(c);for(var e=0;e<b.childNodes.length;e++)b.childNodes[e]._cellIndex=b.childNodes[e]._cellIndexS=e}};dhtmlXGridObject.prototype._addColInRow=function(b,a,d,c){var f=a;if(b._childIndexes){if(b._childIndexes[a-1]==b._childIndexes[a]|| !b.childNodes[b._childIndexes[a-1]]){for(var e=b._childIndexes.length;e>=a;e--)b._childIndexes[e]=e?b._childIndexes[e-1]+1:0;b._childIndexes[a]--}else for(e=b._childIndexes.length;e>=a;e--)b._childIndexes[e]=e?b._childIndexes[e-1]+1:0;f=b._childIndexes[a]}var g=b.childNodes[f],h=document.createElement(c?"TD":"TH");c?h._attrs={}:h.style.width=(parseInt(this.cellWidthPX[a])||"100")+"px";g?b.insertBefore(h,g):b.appendChild(h);this.dragAndDropOff&&b.idd&&this.dragger.addDraggableItem(b.childNodes[f],this);for(e=f+1;e<b.childNodes.length;e++)b.childNodes[e]._cellIndex=b.childNodes[e]._cellIndexS=b.childNodes[e]._cellIndex+1;if(b.childNodes[f])b.childNodes[f]._cellIndex=b.childNodes[f]._cellIndexS=a;if(b.idd||typeof b.idd!="undefined")this.cells3(b,a).setValue(""),h.align=this.cellAlign[a],h.style.verticalAlign=this.cellVAlign[a],h.bgColor=this.columnColor[a];else if(h.tagName=="TD")h.innerHTML= !b.idd&&this.forceDivInHeader?"<div class='hdrcell'>&nbsp;</div>":"&nbsp;"};dhtmlXGridObject.prototype._deleteColInRow=function(b,a){b._childIndexes&&(a=b._childIndexes[a]);var d=b.childNodes[a];if(d){if(d.colSpan&&d.colSpan>1&&d.parentNode.idd){var c=d.colSpan-1,f=this.cells4(d).getValue();this.setColspan(d.parentNode.idd,d._cellIndex,1);if(c>1){var e=d._cellIndex*1;this.setColspan(d.parentNode.idd,e+1,c);this.cells(d.parentNode.idd,d._cellIndex*1+1).setValue(f);b._childIndexes.splice(e,1);for(var g=e;g<b._childIndexes.length;g++)b._childIndexes[g]-=1}}else if(b._childIndexes){b._childIndexes.splice(a,1);for(g=a;g<b._childIndexes.length;g++)b._childIndexes[g]--}d&&b.removeChild(d);for(g=a;g<b.childNodes.length;g++)b.childNodes[g]._cellIndex=b.childNodes[g]._cellIndexS=b.childNodes[g]._cellIndex-1}};dhtmlXGridObject.prototype.aw=function(b,a){this._mCol=convertStringToBoolean(b);if(typeof a!="undefined")this._mCols=a.split(",");if(!this._mmevTrue)dhtmlxEvent(this.hdr,"mousedown",this._startColumnMove),dhtmlxEvent(document.body,"mousemove",this._onColumnMove),dhtmlxEvent(document.body,"mouseup",this._stopColumnMove),this._mmevTrue= !0};dhtmlXGridObject.prototype._startColumnMove=function(b){for(var b=b||event,a=b.target||b.srcElement,d=a;d.tagName!="TABLE";)d=d.parentNode;var c=d.grid;if(c&&(c.setActive(),c._mCol&&b.button!=2)){a=c.getFirstParentOfType(a,"TD");if(a.style.cursor!="default")return!0;if(c&& !c._colInMove&&(c.resized=null,!c._mCols||c._mCols[a._cellIndex]=="true"))c._colInMove=a._cellIndex+1;return!0}};dhtmlXGridObject.prototype._onColumnMove=function(b){var b=b||event,a=window.globalActiveDHTMLGridObject;if(a&&a._colInMove){a._showHContext&&a._showHContext(!1);if(typeof a._colInMove!="object"){var d=document.createElement("DIV");d._aIndex=a._colInMove-1;d._bIndex=null;d.innerHTML=a.getHeaderCol(d._aIndex);d.className="dhx_dragColDiv";d.style.position="absolute";document.body.appendChild(d);a._colInMove=d}var c=[];c[0]=document.body.scrollLeft||document.documentElement.scrollLeft;c[1]=document.body.scrollTop||document.documentElement.scrollTop;a._colInMove.style.left=b.clientX+c[0]+8+"px";a._colInMove.style.top=b.clientY+c[1]+8+"px";for(var f=b.target||b.srcElement;f&&typeof f._cellIndexS=="undefined";)f=f.parentNode;if(a._colInMove._oldHe)a._colInMove._oldHe.className=a._colInMove._oldHe.className.replace(/columnTarget(L|R)/g,""),a._colInMove._oldHe=null,a._colInMove._bIndex=null;if(f){var e=a.hdr.rows[1]._childIndexes?a.hdr.rows[1].cells[a.hdr.rows[1]._childIndexes[f._cellIndexS]]:a.hdr.rows[1].cells[f._cellIndexS],d=b.clientX-(getAbsoluteLeft(e)-a.hdrBox.scrollLeft);d/e.offsetWidth>0.5?(e.className+=" columnTargetR",a._colInMove._bIndex=f._cellIndexS):(e.className+=" columnTargetL",a._colInMove._bIndex=f._cellIndexS-1);if(e.offsetLeft<a.objBox.scrollLeft+20)a.objBox.scrollLeft=Math.max(0,e.offsetLeft-20);if(e.offsetLeft+e.offsetWidth-a.objBox.scrollLeft>a.objBox.offsetWidth-20)a.objBox.scrollLeft=Math.min(a.objBox.scrollLeft+e.offsetWidth+20,a.objBox.scrollWidth-a.objBox.offsetWidth);a._colInMove._oldHe=e}b.cancelBubble= !0;return!1}return!0};dhtmlXGridObject.prototype._stopColumnMove=function(b){var b=b||event,a=window.globalActiveDHTMLGridObject;if(a&&a._colInMove){if(typeof a._colInMove=="object"){a._colInMove.parentNode.removeChild(a._colInMove);a._colInMove._bIndex!=null&&a.moveColumn(a._colInMove._aIndex,a._colInMove._bIndex+1);if(a._colInMove._oldHe)a._colInMove._oldHe.className=a._colInMove._oldHe.className.replace(/columnTarget(L|R)/g,"");a._colInMove._oldHe=null;a._colInMove.grid=null;a.resized= !0}a._colInMove=0}return!0};
