Ext.namespace('Ext.ux.grid.livegrid');Ext.ux.grid.livegrid.GridView=function(config){this.addEvents({'beforebuffer':true,'buffer':true,'bufferfailure':true,'cursormove':true});this.horizontalScrollOffset=17;this.loadMask=false;Ext.apply(this,config);this.templates={};this.templates.master=new Ext.Template('<div class="x-grid3" hidefocus="true"><div class="ext-ux-livegrid-liveScroller"><div></div></div>','<div class="x-grid3-viewport"">','<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset">{header}</div></div><div class="x-clear"></div></div>','<div class="x-grid3-scroller" style="overflow-y:hidden !important;"><div class="x-grid3-body">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',"</div>",'<div class="x-grid3-resize-marker">&#160;</div>','<div class="x-grid3-resize-proxy">&#160;</div>',"</div>");Ext.ux.grid.livegrid.GridView.superclass.constructor.call(this);};Ext.extend(Ext.ux.grid.livegrid.GridView,Ext.grid.GridView,{_maskIndex:20001,hdHeight:0,rowClipped:0,liveScroller:null,liveScrollerInset:null,rowHeight:-1,visibleRows:1,lastIndex:-1,lastRowIndex:0,lastScrollPos:0,rowIndex:0,isBuffering:false,requestQueue:-1,loadMask:null,isPrebuffering:false,reset:function(forceReload)
{if(forceReload===false){this.ds.modified=[];this.grid.selModel.clearSelections(true);this.rowIndex=0;this.lastScrollPos=0;this.lastRowIndex=0;this.lastIndex=0;this.adjustVisibleRows();this.adjustScrollerPos(-this.liveScroller.dom.scrollTop,true);this.showLoadMask(false);this.refresh(true);this.fireEvent('cursormove',this,0,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength);return false;}else{var params={};var sInfo=this.ds.sortInfo;if(sInfo){params={dir:sInfo.direction,sort:sInfo.field};}
return this.ds.load({params:params});}},renderUI:function()
{var g=this.grid;var dEnabled=g.enableDragDrop||g.enableDrag;g.enableDragDrop=false;g.enableDrag=false;Ext.ux.grid.livegrid.GridView.superclass.renderUI.call(this);var g=this.grid;g.enableDragDrop=dEnabled;g.enableDrag=dEnabled;if(dEnabled){var dd=new Ext.ux.grid.livegrid.DragZone(g,{ddGroup:g.ddGroup||'GridDD'});}
if(this.loadMask){this.loadMask=new Ext.LoadMask(this.mainBody.dom.parentNode.parentNode,this.loadMask);}},init:function(grid)
{Ext.ux.grid.livegrid.GridView.superclass.init.call(this,grid);grid.on('expand',this._onExpand,this);},initData:function(ds,cm)
{if(this.ds){this.ds.un('bulkremove',this.onBulkRemove,this);this.ds.un('beforeload',this.onBeforeLoad,this);}
if(ds){ds.on('bulkremove',this.onBulkRemove,this);ds.on('beforeload',this.onBeforeLoad,this);}
Ext.ux.grid.livegrid.GridView.superclass.initData.call(this,ds,cm);},renderBody:function()
{var markup=this.renderRows(0,this.visibleRows-1);return this.templates.body.apply({rows:markup});},initElements:function()
{var E=Ext.Element;var el=this.grid.getGridEl().dom.firstChild;var cs=el.childNodes;this.el=new E(el);this.mainWrap=new E(cs[1]);this.liveScroller=new E(cs[0]);this.liveScrollerInset=this.liveScroller.dom.firstChild;this.liveScroller.on('scroll',this.onLiveScroll,this,{buffer:this.scrollDelay});var thd=this.mainWrap.dom.firstChild;this.mainHd=new E(thd);this.hdHeight=thd.offsetHeight;this.innerHd=this.mainHd.dom.firstChild;this.scroller=new E(this.mainWrap.dom.childNodes[1]);if(this.forceFit){this.scroller.setStyle('overflow-x','hidden');}
this.mainBody=new E(this.scroller.dom.firstChild);this.mainBody.on('mousewheel',this.handleWheel,this);this.focusEl=new E(this.scroller.dom.childNodes[1]);this.focusEl.swallowEvent("click",true);this.resizeMarker=new E(cs[2]);this.resizeProxy=new E(cs[3]);},layout:function()
{if(!this.mainBody){return;}
var g=this.grid;var c=g.getGridEl(),cm=this.cm,expandCol=g.autoExpandColumn,gv=this;var csize=c.getSize(true);var vw=csize.width;if(vw<20||csize.height<20){return;}
if(g.autoHeight){this.scroller.dom.style.overflow='visible';}else{this.el.setSize(csize.width,csize.height);var hdHeight=this.mainHd.getHeight();var vh=csize.height-(hdHeight);this.scroller.setSize(vw,vh);if(this.innerHd){this.innerHd.style.width=(vw)+'px';}}
this.liveScroller.dom.style.top=this.hdHeight+"px";if(this.forceFit){if(this.lastViewWidth!=vw){this.fitColumns(false,false);this.lastViewWidth=vw;}}else{this.autoExpand();}
this.adjustVisibleRows();this.adjustBufferInset();this.onLayout(vw,vh);},removeRow:function(row)
{Ext.removeNode(this.getRow(row));},removeRows:function(firstRow,lastRow)
{var bd=this.mainBody.dom;for(var rowIndex=firstRow;rowIndex<=lastRow;rowIndex++){Ext.removeNode(bd.childNodes[firstRow]);}},_onExpand:function(panel)
{this.adjustVisibleRows();this.adjustBufferInset();this.adjustScrollerPos(this.rowHeight*this.rowIndex,true);},onColumnMove:function(cm,oldIndex,newIndex)
{this.indexMap=null;this.replaceLiveRows(this.rowIndex,true);this.updateHeaders();this.updateHeaderSortState();this.afterMove(newIndex);},onColumnWidthUpdated:function(col,w,tw)
{this.adjustVisibleRows();this.adjustBufferInset();},onAllColumnWidthsUpdated:function(ws,tw)
{this.adjustVisibleRows();this.adjustBufferInset();},onRowSelect:function(row)
{if(row<this.rowIndex||row>this.rowIndex+this.visibleRows){return;}
var viewIndex=row-this.rowIndex;this.addRowClass(viewIndex,"x-grid3-row-selected");},onRowDeselect:function(row)
{if(row<this.rowIndex||row>this.rowIndex+this.visibleRows){return;}
var viewIndex=row-this.rowIndex;this.removeRowClass(viewIndex,"x-grid3-row-selected");},onCellSelect:function(row,col)
{if(row<this.rowIndex||row>this.rowIndex+this.visibleRows){return;}
var viewIndex=row-this.rowIndex;var cell=this.getCell(viewIndex,col);if(cell){this.fly(cell).addClass("x-grid3-cell-selected");}},onCellDeselect:function(row,col)
{if(row<this.rowIndex||row>this.rowIndex+this.visibleRows){return;}
var viewIndex=row-this.rowIndex;var cell=this.getCell(viewIndex,col);if(cell){this.fly(cell).removeClass("x-grid3-cell-selected");}},onRowOver:function(e,t)
{var row;if((row=this.findRowIndex(t))!==false){var viewIndex=row-this.rowIndex;this.addRowClass(viewIndex,"x-grid3-row-over");}},onRowOut:function(e,t)
{var row;if((row=this.findRowIndex(t))!==false&&row!==this.findRowIndex(e.getRelatedTarget())){var viewIndex=row-this.rowIndex;this.removeRowClass(viewIndex,"x-grid3-row-over");}},onClear:function()
{this.reset(false);},onBulkRemove:function(store,removedData)
{var record=null;var index=0;var viewIndex=0;var len=removedData.length;var removedInView=false;var removedAfterView=false;var scrollerAdjust=0;if(len==0){return;}
var tmpRowIndex=this.rowIndex;var removedBefore=0;var removedAfter=0;var removedIn=0;for(var i=0;i<len;i++){record=removedData[i][0];index=removedData[i][1];viewIndex=(index!=Number.MIN_VALUE&&index!=Number.MAX_VALUE)?index+this.ds.bufferRange[0]:index;if(viewIndex<this.rowIndex){removedBefore++;}else if(viewIndex>=this.rowIndex&&viewIndex<=this.rowIndex+(this.visibleRows-1)){removedIn++;}else if(viewIndex>=this.rowIndex+this.visibleRows){removedAfter++;}
this.fireEvent("beforerowremoved",this,viewIndex,record);this.fireEvent("rowremoved",this,viewIndex,record);}
var totalLength=this.ds.totalLength;this.rowIndex=Math.max(0,Math.min(this.rowIndex-removedBefore,totalLength-(this.visibleRows-1)));this.lastRowIndex=this.rowIndex;this.adjustScrollerPos(-(removedBefore*this.rowHeight),true);this.updateLiveRows(this.rowIndex,true);this.adjustBufferInset();this.processRows(0,undefined,false);},onRemove:function(ds,record,index)
{this.onBulkRemove(ds,[[record,index]]);},onAdd:function(ds,records,index)
{var recordLen=records.length;if(index==Number.MAX_VALUE||index==Number.MIN_VALUE){this.fireEvent("beforerowsinserted",this,index,index);if(index==Number.MIN_VALUE){this.rowIndex=this.rowIndex+recordLen;this.lastRowIndex=this.rowIndex;this.adjustBufferInset();this.adjustScrollerPos(this.rowHeight*recordLen,true);this.fireEvent("rowsinserted",this,index,index,recordLen);this.processRows();this.fireEvent('cursormove',this,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength);return;}
this.adjustBufferInset();this.fireEvent("rowsinserted",this,index,index,recordLen);return;}
var start=index+this.ds.bufferRange[0];var end=start+(recordLen-1);var len=this.getRows().length;var firstRow=0;var lastRow=0;if(start>this.rowIndex+(this.visibleRows-1)){this.fireEvent("beforerowsinserted",this,start,end);this.fireEvent("rowsinserted",this,start,end,recordLen);this.adjustVisibleRows();this.adjustBufferInset();}
else if(start>=this.rowIndex&&start<=this.rowIndex+(this.visibleRows-1)){firstRow=index;lastRow=index+(recordLen-1);this.lastRowIndex=this.rowIndex;this.rowIndex=(start>this.rowIndex)?this.rowIndex:start;this.insertRows(ds,firstRow,lastRow);if(this.lastRowIndex!=this.rowIndex){this.fireEvent('cursormove',this,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength);}
this.adjustVisibleRows();this.adjustBufferInset();}
else if(start<this.rowIndex){this.fireEvent("beforerowsinserted",this,start,end);this.rowIndex=this.rowIndex+recordLen;this.lastRowIndex=this.rowIndex;this.adjustVisibleRows();this.adjustBufferInset();this.adjustScrollerPos(this.rowHeight*recordLen,true);this.fireEvent("rowsinserted",this,start,end,recordLen);this.processRows(0,undefined,true);this.fireEvent('cursormove',this,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength);}},onBeforeLoad:function(store,options)
{options.params=options.params||{};var apply=Ext.apply;apply(options,{scope:this,callback:function(){this.reset(false);}});apply(options.params,{start:0,limit:this.ds.bufferSize});return true;},onLoad:function(o1,o2,options)
{this.adjustBufferInset();},onDataChange:function(store)
{this.updateHeaderSortState();},liveBufferUpdate:function(records,options,success)
{if(success===true){this.fireEvent('buffer',this,this.ds,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength,options);this.isBuffering=false;this.isPrebuffering=false;this.showLoadMask(false);this.grid.selModel.replaceSelections(records);if(this.isInRange(this.rowIndex)){this.replaceLiveRows(this.rowIndex,options.forceRepaint);}else{this.updateLiveRows(this.rowIndex);}
if(this.requestQueue>=0){var offset=this.requestQueue;this.requestQueue=-1;this.updateLiveRows(offset);}
return;}else{this.fireEvent('bufferfailure',this,this.ds,options);}
this.requestQueue=-1;this.isBuffering=false;this.isPrebuffering=false;this.showLoadMask(false);},handleWheel:function(e)
{if(this.rowHeight==-1){e.stopEvent();return;}
var d=e.getWheelDelta();this.adjustScrollerPos(-(d*this.rowHeight));e.stopEvent();},onLiveScroll:function()
{var scrollTop=this.liveScroller.dom.scrollTop;var cursor=Math.floor((scrollTop)/this.rowHeight);this.rowIndex=cursor;if(cursor==this.lastRowIndex){return;}
this.updateLiveRows(cursor);this.lastScrollPos=this.liveScroller.dom.scrollTop;},refreshRow:function(record)
{var ds=this.ds,index;if(typeof record=='number'){index=record;record=ds.getAt(index);}else{index=ds.indexOf(record);}
var viewIndex=index+this.ds.bufferRange[0];if(viewIndex<this.rowIndex||viewIndex>=this.rowIndex+this.visibleRows){this.fireEvent("rowupdated",this,viewIndex,record);return;}
this.insertRows(ds,index,index,true);this.fireEvent("rowupdated",this,viewIndex,record);},processRows:function(startRow,skipStripe,paintSelections)
{skipStripe=skipStripe||!this.grid.stripeRows;startRow=0;var rows=this.getRows();var cls=' x-grid3-row-alt ';var cursor=this.rowIndex;var index=0;var selections=this.grid.selModel.selections;var ds=this.ds;var row=null;for(var i=startRow,len=rows.length;i<len;i++){index=i+cursor;row=rows[i];row.rowIndex=index;if(paintSelections==true){if(this.grid.selModel.isSelected(this.ds.getAt(index))===true){this.addRowClass(i,"x-grid3-row-selected");}else{this.removeRowClass(i,"x-grid3-row-selected");}
this.fly(row).removeClass("x-grid3-row-over");}
if(!skipStripe){var isAlt=((index+1)%2==0);var hasAlt=(' '+row.className+' ').indexOf(cls)!=-1;if(isAlt==hasAlt){continue;}
if(isAlt){row.className+=" x-grid3-row-alt";}else{row.className=row.className.replace("x-grid3-row-alt","");}}}},insertRows:function(dm,firstRow,lastRow,isUpdate)
{var viewIndexFirst=firstRow+this.ds.bufferRange[0];var viewIndexLast=lastRow+this.ds.bufferRange[0];if(!isUpdate){this.fireEvent("beforerowsinserted",this,viewIndexFirst,viewIndexLast);}
if(isUpdate!==true&&(this.getRows().length+(lastRow-firstRow))>=this.visibleRows){this.removeRows((this.visibleRows-1)-(lastRow-firstRow),this.visibleRows-1);}else if(isUpdate){this.removeRows(viewIndexFirst-this.rowIndex,viewIndexLast-this.rowIndex);}
var lastRenderRow=(firstRow==lastRow)?lastRow:Math.min(lastRow,(this.rowIndex-this.ds.bufferRange[0])+(this.visibleRows-1));var html=this.renderRows(firstRow,lastRenderRow);var before=this.getRow(firstRow-(this.rowIndex-this.ds.bufferRange[0]));if(before){Ext.DomHelper.insertHtml('beforeBegin',before,html);}else{Ext.DomHelper.insertHtml('beforeEnd',this.mainBody.dom,html);}
if(isUpdate===true){var rows=this.getRows();var cursor=this.rowIndex;for(var i=0,max_i=rows.length;i<max_i;i++){rows[i].rowIndex=cursor+i;}}
if(!isUpdate){this.fireEvent("rowsinserted",this,viewIndexFirst,viewIndexLast,(viewIndexLast-viewIndexFirst)+1);this.processRows(0,undefined,true);}},focusCell:function(row,col,hscroll)
{var xy=this.ensureVisible(row,col,hscroll);if(!xy){return;}
this.focusEl.setXY(xy);if(Ext.isGecko){this.focusEl.focus();}else{this.focusEl.focus.defer(1,this.focusEl);}},ensureVisible:function(row,col,hscroll)
{if(typeof row!="number"){row=row.rowIndex;}
if(row<0||row>=this.ds.totalLength){return;}
col=(col!==undefined?col:0);var rowInd=row-this.rowIndex;if(this.rowClipped&&row==this.rowIndex+this.visibleRows-1){this.adjustScrollerPos(this.rowHeight);}else if(row>=this.rowIndex+this.visibleRows){this.adjustScrollerPos(((row-(this.rowIndex+this.visibleRows))+1)*this.rowHeight);}else if(row<=this.rowIndex){this.adjustScrollerPos((rowInd)*this.rowHeight);}
var rowInd=rowInd<0?row:rowInd;var rowEl=this.getRow(rowInd),cellEl;if(!(hscroll===false&&col===0)){while(this.cm.isHidden(col)){col++;}
cellEl=this.getCell(row-this.rowIndex,col);}
if(!rowEl){return;}
var c=this.scroller.dom;return cellEl?Ext.fly(cellEl).getXY():[c.scrollLeft+this.el.getX(),Ext.fly(rowEl).getY()];},isInRange:function(rowIndex)
{var lastRowIndex=Math.min(this.ds.totalLength-1,rowIndex+this.visibleRows);return(rowIndex>=this.ds.bufferRange[0])&&(lastRowIndex<=this.ds.bufferRange[1]);},getPredictedBufferIndex:function(index,inRange,down)
{if(!inRange){var dNear=2*this.nearLimit;return Math.max(0,index-((dNear>=this.ds.bufferSize?this.nearLimit:dNear)));}
if(!down){return Math.max(0,(index-this.ds.bufferSize)+this.visibleRows);}
if(down){return Math.max(0,Math.min(index,this.ds.totalLength-this.ds.bufferSize));}},updateLiveRows:function(index,forceRepaint,forceReload)
{this.fireEvent('cursormove',this,index,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength);var inRange=this.isInRange(index);if(this.isBuffering&&this.isPrebuffering){if(inRange){this.replaceLiveRows(index);}else{this.showLoadMask(true);}}
if(this.isBuffering){this.requestQueue=index;return;}
var lastIndex=this.lastIndex;this.lastIndex=index;var inRange=this.isInRange(index);var down=false;if(inRange&&forceReload!==true){this.replaceLiveRows(index,forceRepaint);if(index>lastIndex){down=true;var totalCount=this.ds.totalLength;if(index+this.visibleRows+this.nearLimit<=this.ds.bufferRange[1]){return;}
if(this.ds.bufferRange[1]+1>=totalCount){return;}}else if(index<lastIndex){down=false;if(this.ds.bufferRange[0]<=0){return;}
if(index-this.nearLimit>this.ds.bufferRange[0]){return;}}else{return;}
this.isPrebuffering=true;}
this.isBuffering=true;var bufferOffset=this.getPredictedBufferIndex(index,inRange,down);if(!inRange){this.showLoadMask(true);}
this.ds.suspendEvents();var sInfo=this.ds.sortInfo;var params={};if(this.ds.lastOptions){Ext.apply(params,this.ds.lastOptions.params);}
params.start=bufferOffset;params.limit=this.ds.bufferSize;if(sInfo){params.dir=sInfo.direction;params.sort=sInfo.field;}
var opts={forceRepaint:forceRepaint,callback:this.liveBufferUpdate,scope:this,params:params};this.fireEvent('beforebuffer',this,this.ds,index,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength,opts);this.ds.load(opts);this.ds.resumeEvents();},showLoadMask:function(show)
{if(this.loadMask==null){if(show){this.loadMask=new Ext.LoadMask(this.mainBody.dom.parentNode.parentNode,this.loadMaskConfig);}else{return;}}
if(show){this.loadMask.show();this.liveScroller.setStyle('zIndex',this._maskIndex);}else{this.loadMask.hide();this.liveScroller.setStyle('zIndex',1);}},replaceLiveRows:function(cursor,forceReplace,processRows)
{var spill=cursor-this.lastRowIndex;if(spill==0&&forceReplace!==true){return;}
var append=spill>0;spill=Math.abs(spill);var bufferRange=this.ds.bufferRange;var cursorBuffer=cursor-bufferRange[0];var lpIndex=Math.min(cursorBuffer+this.visibleRows-1,bufferRange[1]-bufferRange[0]);if(spill>=this.visibleRows||spill==0){this.mainBody.update(this.renderRows(cursorBuffer,lpIndex));}else{if(append){this.removeRows(0,spill-1);if(cursorBuffer+this.visibleRows-spill<=bufferRange[1]-bufferRange[0]){var html=this.renderRows(cursorBuffer+this.visibleRows-spill,lpIndex);Ext.DomHelper.insertHtml('beforeEnd',this.mainBody.dom,html);}}else{this.removeRows(this.visibleRows-spill,this.visibleRows-1);var html=this.renderRows(cursorBuffer,cursorBuffer+spill-1);Ext.DomHelper.insertHtml('beforeBegin',this.mainBody.dom.firstChild,html);}}
if(processRows!==false){this.processRows(0,undefined,true);}
this.lastRowIndex=cursor;},adjustBufferInset:function()
{var liveScrollerDom=this.liveScroller.dom;var g=this.grid,ds=g.store;var c=g.getGridEl();var elWidth=c.getSize().width;var hiddenRows=(ds.totalLength==this.visibleRows-this.rowClipped)?0:Math.max(0,ds.totalLength-(this.visibleRows-this.rowClipped));if(hiddenRows==0){this.scroller.setWidth(elWidth);liveScrollerDom.style.display='none';return;}else{this.scroller.setWidth(elWidth-this.scrollOffset);liveScrollerDom.style.display='';}
var scrollbar=this.cm.getTotalWidth()+this.scrollOffset>elWidth;var contHeight=liveScrollerDom.parentNode.offsetHeight+
((ds.totalLength>0&&scrollbar)?-this.horizontalScrollOffset:0)
-this.hdHeight;liveScrollerDom.style.height=Math.max(contHeight,this.horizontalScrollOffset*2)+"px";if(this.rowHeight==-1){return;}
this.liveScrollerInset.style.height=(hiddenRows==0?0:contHeight+(hiddenRows*this.rowHeight))+"px";},adjustVisibleRows:function()
{if(this.rowHeight==-1){if(this.getRows()[0]){this.rowHeight=this.getRows()[0].offsetHeight;if(this.rowHeight<=0){this.rowHeight=-1;return;}}else{return;}}
var g=this.grid,ds=g.store;var c=g.getGridEl();var cm=this.cm;var size=c.getSize();var width=size.width;var vh=size.height;var vw=width-this.scrollOffset;if(cm.getTotalWidth()>vw){vh-=this.horizontalScrollOffset;}
vh-=this.mainHd.getHeight();var totalLength=ds.totalLength||0;var visibleRows=Math.max(1,Math.floor(vh/this.rowHeight));this.rowClipped=0;if(totalLength>visibleRows&&this.rowHeight/3<(vh-(visibleRows*this.rowHeight))){visibleRows=Math.min(visibleRows+1,totalLength);this.rowClipped=1;}
if(this.visibleRows==visibleRows){return;}
this.visibleRows=visibleRows;if(this.isBuffering){return;}
if(this.rowIndex+(visibleRows-this.rowClipped)>totalLength){this.rowIndex=Math.max(0,totalLength-(visibleRows-this.rowClipped));this.lastRowIndex=this.rowIndex;}
this.updateLiveRows(this.rowIndex,true);},adjustScrollerPos:function(pixels,suspendEvent)
{if(pixels==0){return;}
var liveScroller=this.liveScroller;var scrollDom=liveScroller.dom;if(suspendEvent===true){liveScroller.un('scroll',this.onLiveScroll,this);}
this.lastScrollPos=scrollDom.scrollTop;scrollDom.scrollTop+=pixels;if(suspendEvent===true){scrollDom.scrollTop=scrollDom.scrollTop;liveScroller.on('scroll',this.onLiveScroll,this,{buffer:this.scrollDelay});}}});Ext.namespace('Ext.ux.grid.livegrid');Ext.ux.grid.livegrid.RowSelectionModel=function(config){this.addEvents({'selectiondirty':true});Ext.apply(this,config);this.pendingSelections={};Ext.ux.grid.livegrid.RowSelectionModel.superclass.constructor.call(this);};Ext.extend(Ext.ux.grid.livegrid.RowSelectionModel,Ext.grid.RowSelectionModel,{initEvents:function()
{Ext.ux.grid.livegrid.RowSelectionModel.superclass.initEvents.call(this);this.grid.view.on('rowsinserted',this.onAdd,this);this.grid.store.on('selectionsload',this.onSelectionsLoad,this);},onRefresh:function()
{this.clearSelections(true);},onRemove:function(v,index,r)
{var ranges=this.getPendingSelections();var rangesLength=ranges.length;var selectionChanged=false;if(index==Number.MIN_VALUE||index==Number.MAX_VALUE){if(r){if(this.isIdSelected(r.id)&&index==Number.MIN_VALUE){this.shiftSelections(this.grid.store.bufferRange[1],-1);}
this.selections.remove(r);selectionChanged=true;}
if(index==Number.MIN_VALUE){this.clearPendingSelections(0,this.grid.store.bufferRange[0]);}else{this.clearPendingSelections(this.grid.store.bufferRange[1]);}
if(rangesLength!=0){this.fireEvent('selectiondirty',this,index,1);}}else{selectionChanged=this.isIdSelected(r.id);if(!selectionChanged){return;}
this.selections.remove(r);if(rangesLength!=0){var startRange=ranges[0];var endRange=ranges[rangesLength-1];if(index<=endRange||index<=startRange){this.shiftSelections(index,-1);this.fireEvent('selectiondirty',this,index,1);}}}
if(selectionChanged){this.fireEvent('selectionchange',this);}},onAdd:function(store,index,endIndex,recordLength)
{var ranges=this.getPendingSelections();var rangesLength=ranges.length;if((index==Number.MIN_VALUE||index==Number.MAX_VALUE)){if(index==Number.MIN_VALUE){this.clearPendingSelections(0,this.grid.store.bufferRange[0]);this.shiftSelections(this.grid.store.bufferRange[1],recordLength);}else{this.clearPendingSelections(this.grid.store.bufferRange[1]);}
if(rangesLength!=0){this.fireEvent('selectiondirty',this,index,r);}
return;}
var startRange=ranges[0];var endRange=ranges[rangesLength-1];var viewIndex=index;if(viewIndex<=endRange||viewIndex<=startRange){this.fireEvent('selectiondirty',this,viewIndex,recordLength);this.shiftSelections(viewIndex,recordLength);}},shiftSelections:function(startRow,length)
{var index=0;var newIndex=0;var newRequests={};var ds=this.grid.store;var storeIndex=startRow-ds.bufferRange[0];var newStoreIndex=0;var totalLength=this.grid.store.totalLength;var rec=null;var ranges=this.getPendingSelections();var rangesLength=ranges.length;if(rangesLength==0){return;}
for(var i=0;i<rangesLength;i++){index=ranges[i];if(index<startRow){continue;}
newIndex=index+length;newStoreIndex=storeIndex+length;if(newIndex>=totalLength){break;}
rec=ds.getAt(newStoreIndex);if(rec){this.selections.add(rec);}else{newRequests[newIndex]=true;}}
this.pendingSelections=newRequests;},onSelectionsLoad:function(store,records,ranges)
{this.replaceSelections(records);},hasNext:function()
{return this.last!==false&&(this.last+1)<this.grid.store.getTotalCount();},getCount:function()
{return this.selections.length+this.getPendingSelections().length;},isSelected:function(index)
{if(typeof index=="number"){var orgInd=index;index=this.grid.store.getAt(orgInd);if(!index){var ind=this.getPendingSelections().indexOf(orgInd);if(ind!=-1){return true;}
return false;}}
var r=index;return(r&&this.selections.key(r.id)?true:false);},deselectRow:function(index,preventViewNotify)
{if(this.locked)return;if(this.last==index){this.last=false;}
if(this.lastActive==index){this.lastActive=false;}
var r=this.grid.store.getAt(index);delete this.pendingSelections[index];if(r){this.selections.remove(r);}
if(!preventViewNotify){this.grid.getView().onRowDeselect(index);}
this.fireEvent("rowdeselect",this,index,r);this.fireEvent("selectionchange",this);},selectRow:function(index,keepExisting,preventViewNotify)
{if(this.locked||index<0||index>=this.grid.store.getTotalCount()){return;}
var r=this.grid.store.getAt(index);if(this.fireEvent("beforerowselect",this,index,keepExisting,r)!==false){if(!keepExisting||this.singleSelect){this.clearSelections();}
if(r){this.selections.add(r);delete this.pendingSelections[index];}else{this.pendingSelections[index]=true;}
this.last=this.lastActive=index;if(!preventViewNotify){this.grid.getView().onRowSelect(index);}
this.fireEvent("rowselect",this,index,r);this.fireEvent("selectionchange",this);}},clearPendingSelections:function(startIndex,endIndex)
{if(endIndex==undefined){endIndex=Number.MAX_VALUE;}
var newSelections={};var ranges=this.getPendingSelections();var rangesLength=ranges.length;var index=0;for(var i=0;i<rangesLength;i++){index=ranges[i];if(index<=endIndex&&index>=startIndex){continue;}
newSelections[index]=true;}
this.pendingSelections=newSelections;},replaceSelections:function(records)
{if(!records||records.length==0){return;}
var ds=this.grid.store;var rec=null;var assigned=[];var ranges=this.getPendingSelections();var rangesLength=ranges.length
var selections=this.selections;var index=0;for(var i=0;i<rangesLength;i++){index=ranges[i];rec=ds.getAt(index);if(rec){selections.add(rec);assigned.push(rec.id);delete this.pendingSelections[index];}}
var id=null;for(i=0,len=records.length;i<len;i++){rec=records[i];id=rec.id;if(assigned.indexOf(id)==-1&&selections.containsKey(id)){selections.add(rec);}}},getPendingSelections:function(asRange)
{var index=1;var ranges=[];var currentRange=0;var tmpArray=[];for(var i in this.pendingSelections){tmpArray.push(parseInt(i));}
tmpArray.sort(function(o1,o2){if(o1>o2){return 1;}else if(o1<o2){return-1;}else{return 0;}});if(!asRange){return tmpArray;}
var max_i=tmpArray.length;if(max_i==0){return[];}
ranges[currentRange]=[tmpArray[0],tmpArray[0]];for(var i=0,max_i=max_i-1;i<max_i;i++){if(tmpArray[i+1]-tmpArray[i]==1){ranges[currentRange][1]=tmpArray[i+1];}else{currentRange++;ranges[currentRange]=[tmpArray[i+1],tmpArray[i+1]];}}
return ranges;},clearSelections:function(fast)
{if(this.locked)return;if(fast!==true){var ds=this.grid.store;var s=this.selections;var ind=-1;s.each(function(r){ind=ds.indexOfId(r.id);if(ind!=-1){this.deselectRow(ind+ds.bufferRange[0]);}},this);s.clear();this.pendingSelections={};}else{this.selections.clear();this.pendingSelections={};}
this.last=false;},selectRange:function(startRow,endRow,keepExisting)
{if(this.locked){return;}
if(!keepExisting){this.clearSelections();}
if(startRow<=endRow){for(var i=startRow;i<=endRow;i++){this.selectRow(i,true);}}else{for(var i=startRow;i>=endRow;i--){this.selectRow(i,true);}}}});Ext.namespace('Ext.ux.grid.livegrid');Ext.ux.grid.livegrid.Store=function(config){config=config||{};config.remoteSort=true;this.addEvents('bulkremove','versionchange','beforeselectionsload','selectionsload');Ext.ux.grid.livegrid.Store.superclass.constructor.call(this,config);this.totalLength=0;this.bufferRange=[-1,-1];this.on('clear',function(){this.bufferRange=[-1,-1];},this);if(this.url&&!this.selectionsProxy){this.selectionsProxy=new Ext.data.HttpProxy({url:this.url});}};Ext.extend(Ext.ux.grid.livegrid.Store,Ext.data.Store,{version:null,insert:function(index,records)
{records=[].concat(records);index=index>=this.bufferSize?Number.MAX_VALUE:index;if(index==Number.MIN_VALUE||index==Number.MAX_VALUE){var l=records.length;if(index==Number.MIN_VALUE){this.bufferRange[0]+=l;this.bufferRange[1]+=l;}
this.totalLength+=l;this.fireEvent("add",this,records,index);return;}
var split=false;var insertRecords=records;if(records.length+index>=this.bufferSize){split=true;insertRecords=records.splice(0,this.bufferSize-index)}
this.totalLength+=insertRecords.length;if(this.bufferRange[0]<=-1){this.bufferRange[0]=0;}
if(this.bufferRange[1]<(this.bufferSize-1)){this.bufferRange[1]=Math.min(this.bufferRange[1]+insertRecords.length,this.bufferSize-1);}
for(var i=0,len=insertRecords.length;i<len;i++){this.data.insert(index,insertRecords[i]);insertRecords[i].join(this);}
while(this.getCount()>this.bufferSize){this.data.remove(this.data.last());}
this.fireEvent("add",this,insertRecords,index);if(split==true){this.fireEvent("add",this,records,Number.MAX_VALUE);}},remove:function(record,suspendEvent)
{var index=this._getIndex(record);if(index<0){this.totalLength-=1;if(this.pruneModifiedRecords){this.modified.remove(record);}
this.bufferRange[0]=Math.max(-1,this.bufferRange[0]-1);this.bufferRange[1]=Math.max(-1,this.bufferRange[1]-1);if(suspendEvent!==true){this.fireEvent("remove",this,record,index);}
return index;}
this.bufferRange[1]=Math.max(-1,this.bufferRange[1]-1);this.data.removeAt(index);if(this.pruneModifiedRecords){this.modified.remove(record);}
this.totalLength-=1;if(suspendEvent!==true){this.fireEvent("remove",this,record,index);}
return index;},_getIndex:function(record)
{var index=this.indexOfId(record.id);if(index<0){index=this.findInsertIndex(record);}
return index;},bulkRemove:function(records)
{var rec=null;var recs=[];var ind=0;var len=records.length;var orgIndexes=[];for(var i=0;i<len;i++){rec=records[i];orgIndexes[rec.id]=this._getIndex(rec);}
for(var i=0;i<len;i++){rec=records[i];this.remove(rec,true);recs.push([rec,orgIndexes[rec.id]]);}
this.fireEvent("bulkremove",this,recs);},removeAll:function()
{this.totalLength=0;this.bufferRange=[-1,-1];this.data.clear();if(this.pruneModifiedRecords){this.modified=[];}
this.fireEvent("clear",this);},loadRanges:function(ranges)
{var max_i=ranges.length;if(max_i>0&&!this.selectionsProxy.activeRequest&&this.fireEvent("beforeselectionsload",this,ranges)!==false){var lParams=this.lastOptions.params;var params={};params.ranges=Ext.encode(ranges);if(lParams){if(lParams.sort){params.sort=lParams.sort;}
if(lParams.dir){params.dir=lParams.dir;}}
var options={};for(var i in this.lastOptions){options.i=this.lastOptions.i;}
options.ranges=params.ranges;this.selectionsProxy.load(params,this.reader,this.selectionsLoaded,this,options);}},loadSelections:function(ranges)
{if(ranges.length==0){return;}
this.loadRanges(ranges);},selectionsLoaded:function(o,options,success)
{if(this.checkVersionChange(o,options,success)!==false){var r=o.records;for(var i=0,len=r.length;i<len;i++){r[i].join(this);}
this.fireEvent("selectionsload",this,o.records,Ext.decode(options.ranges));}else{this.fireEvent("selectionsload",this,[],Ext.decode(options.ranges));}},checkVersionChange:function(o,options,success)
{if(o&&success!==false){if(o.version!==undefined){var old=this.version;this.version=o.version;if(this.version!==old){return this.fireEvent('versionchange',this,old,this.version);}}}},findInsertIndex:function(record)
{this.remoteSort=false;var index=Ext.ux.grid.livegrid.Store.superclass.findInsertIndex.call(this,record);this.remoteSort=true;if(this.bufferRange[0]<=0&&index==0){return index;}else if(this.bufferRange[0]>0&&index==0){return Number.MIN_VALUE;}else if(index>=this.bufferSize){return Number.MAX_VALUE;}
return index;},sortData:function(f,direction)
{direction=direction||'ASC';var st=this.fields.get(f).sortType;var fn=function(r1,r2){var v1=st(r1.data[f]),v2=st(r2.data[f]);return v1>v2?1:(v1<v2?-1:0);};this.data.sort(direction,fn);},onMetaChange:function(meta,rtype,o)
{this.version=null;Ext.ux.grid.livegrid.Store.superclass.onMetaChange.call(this,meta,rtype,o);},loadRecords:function(o,options,success)
{this.checkVersionChange(o,options,success);if(!o){this.bufferRange=[-1,-1];}else{options.params=options.params||{};Ext.applyIf(options.params,{start:0,limit:this.bufferSize});this.bufferRange=[options.params.start,Math.max(0,Math.min((options.params.start+options.params.limit)-1,o.totalRecords-1))];}
Ext.ux.grid.livegrid.Store.superclass.loadRecords.call(this,o,options,success);},getAt:function(index)
{if(this.bufferRange[0]==-1){return-1;}
var modelIndex=index-this.bufferRange[0];return this.data.itemAt(modelIndex);},clearFilter:function(){},isFiltered:function(){},collect:function(){},createFilterFn:function(){},sum:function(){},filter:function(){},filterBy:function(){},query:function(){},queryBy:function(){},find:function(){},findBy:function(){}});Ext.namespace('Ext.ux.grid.livegrid');Ext.ux.grid.livegrid.Toolbar=Ext.extend(Ext.Toolbar,{displayMsg:'Displaying {0} - {1} of {2}',emptyMsg:'No data to display',refreshText:"Refresh",initComponent:function()
{Ext.ux.grid.livegrid.Toolbar.superclass.initComponent.call(this);this.bind(this.grid);},updateInfo:function(rowIndex,visibleRows,totalCount)
{if(this.displayEl){var msg=totalCount==0?this.emptyMsg:String.format(this.displayMsg,rowIndex+1,rowIndex+visibleRows,totalCount);this.displayEl.update(msg);}},unbind:function(grid)
{var st=grid.getStore();var vw=grid.view;st.un('loadexception',this.enableLoading,this);st.un('beforeload',this.disableLoading,this);st.un('load',this.enableLoading,this);vw.un('rowremoved',this.onRowRemoved,this);vw.un('rowsinserted',this.onRowsInserted,this);vw.un('beforebuffer',this.beforeBuffer,this);vw.un('cursormove',this.onCursorMove,this);vw.un('buffer',this.onBuffer,this);vw.un('bufferfailure',this.enableLoading,this);this.grid=undefined;},bind:function(grid)
{var st=grid.getStore();var vw=grid.view;st.on('loadexception',this.enableLoading,this);st.on('beforeload',this.disableLoading,this);st.on('load',this.enableLoading,this);vw.on('rowremoved',this.onRowRemoved,this);vw.on('rowsinserted',this.onRowsInserted,this);vw.on('beforebuffer',this.beforeBuffer,this);vw.on('cursormove',this.onCursorMove,this);vw.on('buffer',this.onBuffer,this);vw.on('bufferfailure',this.enableLoading,this);this.grid=grid;},enableLoading:function()
{this.loading.setDisabled(false);},disableLoading:function()
{this.loading.setDisabled(true);},onCursorMove:function(view,rowIndex,visibleRows,totalCount)
{this.updateInfo(rowIndex,visibleRows,totalCount);},onRowsInserted:function(view,start,end)
{this.updateInfo(view.rowIndex,Math.min(view.ds.totalLength,view.visibleRows-view.rowClipped),view.ds.totalLength);},onRowRemoved:function(view,index,record)
{this.updateInfo(view.rowIndex,Math.min(view.ds.totalLength,view.visibleRows-view.rowClipped),view.ds.totalLength);},beforeBuffer:function(view,store,rowIndex,visibleRows,totalCount,options)
{this.loading.disable();this.updateInfo(rowIndex,visibleRows,totalCount);},onBuffer:function(view,store,rowIndex,visibleRows,totalCount)
{this.loading.enable();this.updateInfo(rowIndex,visibleRows,totalCount);},onClick:function(type)
{switch(type){case'refresh':if(this.grid.view.reset(true)){this.loading.disable();}else{this.loading.enable();}
break;}},onRender:function(ct,position)
{Ext.PagingToolbar.superclass.onRender.call(this,ct,position);this.loading=this.addButton({tooltip:this.refreshText,iconCls:"x-tbar-loading",handler:this.onClick.createDelegate(this,["refresh"])});this.addSeparator();if(this.displayInfo){this.displayEl=Ext.fly(this.el.dom).createChild({cls:'x-paging-info'});}}});Ext.namespace('Ext.ux.grid.livegrid');Ext.ux.grid.livegrid.DragZone=function(grid,config){this.view=grid.getView();Ext.ux.grid.livegrid.DragZone.superclass.constructor.call(this,this.view.mainBody.dom,config);if(this.view.lockedBody){this.setHandleElId(Ext.id(this.view.mainBody.dom));this.setOuterHandleElId(Ext.id(this.view.lockedBody.dom));}
this.scroll=false;this.grid=grid;this.ddel=document.createElement('div');this.ddel.className='x-grid-dd-wrap';this.view.ds.on('beforeselectionsload',this.onBeforeSelectionsLoad,this);this.view.ds.on('selectionsload',this.onSelectionsLoad,this);};Ext.extend(Ext.ux.grid.livegrid.DragZone,Ext.dd.DragZone,{ddGroup:"GridDD",isDropValid:true,getDragData:function(e)
{var t=Ext.lib.Event.getTarget(e);var rowIndex=this.view.findRowIndex(t);if(rowIndex!==false){var sm=this.grid.selModel;if(!sm.isSelected(rowIndex)||e.hasModifier()){sm.handleMouseDown(this.grid,rowIndex,e);}
return{grid:this.grid,ddel:this.ddel,rowIndex:rowIndex,selections:sm.getSelections()};}
return false;},onInitDrag:function(e)
{this.view.ds.loadSelections(this.grid.selModel.getPendingSelections(true));var data=this.dragData;this.ddel.innerHTML=this.grid.getDragDropText();this.proxy.update(this.ddel);},onBeforeSelectionsLoad:function()
{this.isDropValid=false;Ext.fly(this.proxy.el.dom.firstChild).addClass('x-dd-drop-waiting');},onSelectionsLoad:function()
{this.isDropValid=true;this.ddel.innerHTML=this.grid.getDragDropText();Ext.fly(this.proxy.el.dom.firstChild).removeClass('x-dd-drop-waiting');},afterRepair:function()
{this.dragging=false;},getRepairXY:function(e,data)
{return false;},onStartDrag:function()
{},onEndDrag:function(data,e)
{},onValidDrop:function(dd,e,id)
{this.hideProxy();},beforeInvalidDrop:function(e,id)
{}});Ext.namespace("Ext.ux.data");Ext.ux.data.DWRProxy=function(config){Ext.apply(this,config);Ext.ux.data.DWRProxy.superclass.constructor.call(this);};Ext.extend(Ext.ux.data.DWRProxy,Ext.data.DataProxy,{dwrFunction:null,loadArgsKey:'dwrFunctionArgs',load:function(params,reader,loadCallback,scope,arg){var dataProxy=this;if(dataProxy.fireEvent("beforeload",dataProxy,params)!==false){var loadArgs=params[this.loadArgsKey]||params;var dwrFunctionArgs=[];if(loadArgs instanceof Array){for(var i=0;i<loadArgs.length;i++){dwrFunctionArgs.push(loadArgs[i]);}}else{for(var loadArgName in loadArgs){dwrFunctionArgs.push(loadArgs[loadArgName]);}}
dwrFunctionArgs.push({callback:function(response){var records=reader.readRecords(response);dataProxy.fireEvent("load",dataProxy,response,loadCallback);loadCallback.call(scope,records,arg,true);},exceptionHandler:function(message,exception){dataProxy.fireEvent("loadexception",dataProxy,message,loadCallback,exception);loadCallback.call(scope,null,arg,false);}});this.dwrFunction.apply(Object,dwrFunctionArgs);}else{callback.call(scope||this,null,arg,false);}}});Ext.ns("Ext.ux.grid.GridSummary");Ext.ux.grid.GridSummary=function(config){Ext.apply(this,config);};Ext.extend(Ext.ux.grid.GridSummary,Ext.util.Observable,{init:function(grid){this.grid=grid;this.cm=grid.getColumnModel();this.view=grid.getView();var v=this.view;v.onLayout=this.onLayout;v.afterMethod('render',this.refreshSummary,this);v.afterMethod('refresh',this.refreshSummary,this);v.afterMethod('syncScroll',this.syncSummaryScroll,this);v.afterMethod('onColumnWidthUpdated',this.doWidth,this);v.afterMethod('onAllColumnWidthsUpdated',this.doAllWidths,this);v.afterMethod('onColumnHiddenUpdated',this.doHidden,this);v.afterMethod('onUpdate',this.refreshSummary,this);v.afterMethod('onRemove',this.refreshSummary,this);grid.store.on('add',this.refreshSummary,this);grid.store.on('remove',this.refreshSummary,this);grid.store.on('clear',this.refreshSummary,this);if(!this.rowTpl){this.rowTpl=new Ext.Template('<div class="x-grid3-summary-row x-grid3-gridsummary-row-offset">','<table class="x-grid3-summary-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">','<tbody><tr>{cells}</tr></tbody>','</table>','</div>');this.rowTpl.disableFormats=true;}
this.rowTpl.compile();if(!this.cellTpl){this.cellTpl=new Ext.Template('<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}">','<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',"</td>");this.cellTpl.disableFormats=true;}
this.cellTpl.compile();},calculate:function(rs,cm){var data={},cfg=cm.config;for(var i=0,len=cfg.length;i<len;i++){var cf=cfg[i],cname=cf.dataIndex;data[cname]=0;if(cf.summaryType){for(var j=0,jlen=rs.length;j<jlen;j++){var r=rs[j];data[cname]=Ext.ux.grid.GridSummary.Calculations[cf.summaryType](r.get(cname),r,cname,data,j);}}}
return data;},onLayout:function(vw,vh){if(Ext.type(vh)!='number'){return;}
if(!this.grid.getGridEl().hasClass('x-grid-hide-gridsummary')){this.scroller.setHeight(vh-this.summary.getHeight());}},syncSummaryScroll:function(){var mb=this.view.scroller.dom;this.view.summaryWrap.dom.scrollLeft=mb.scrollLeft;this.view.summaryWrap.dom.scrollLeft=mb.scrollLeft;},doWidth:function(col,w,tw){var s=this.view.summary.dom;s.firstChild.style.width=tw;s.firstChild.rows[0].childNodes[col].style.width=w;},doAllWidths:function(ws,tw){var s=this.view.summary.dom,wlen=ws.length;s.firstChild.style.width=tw;var cells=s.firstChild.rows[0].childNodes;for(var j=0;j<wlen;j++){cells[j].style.width=ws[j];}},doHidden:function(col,hidden,tw){var s=this.view.summary.dom,display=hidden?'none':'';s.firstChild.style.width=tw;s.firstChild.rows[0].childNodes[col].style.display=display;},renderSummary:function(o,cs,cm){cs=cs||this.view.getColumnData();var cfg=cm.config,buf=[],last=cs.length-1;if(this.summaryLabel&&cfg.length>0)
{cfg[0].summaryRenderer=this.summaryLabeler;}
for(var i=0,len=cs.length;i<len;i++){var c=cs[i],cf=cfg[i],p={};p.id=c.id;p.style=c.style;p.css=i==0?'x-grid3-cell-first ':(i==last?'x-grid3-cell-last ':'');if(cf.summaryType||cf.summaryRenderer){p.value=(cf.summaryRenderer||c.renderer).call(this,o.data[c.name],p,o);}else{p.value='';}
if(p.value==undefined||p.value==="")p.value="&#160;";buf[buf.length]=this.cellTpl.apply(p);}
return this.rowTpl.apply({tstyle:'width:'+this.view.getTotalWidth()+';',cells:buf.join('')});},summaryLabeler:function()
{return this.summaryLabel;},refreshSummary:function(){var g=this.grid,ds=g.store,cs=this.view.getColumnData(),cm=this.cm,rs=ds.getRange(),data=this.calculate(rs,cm),buf=this.renderSummary({data:data},cs,cm);if(!this.view.summaryWrap){this.view.summaryWrap=Ext.DomHelper.insertAfter(this.view.scroller,{tag:'div',cls:'x-grid3-gridsummary-row-inner'},true);}else{this.view.summary.remove();}
this.view.summary=this.view.summaryWrap.insertHtml('afterbegin',buf,true);},toggleSummary:function(visible){var el=this.grid.getGridEl();if(el){if(visible===undefined){visible=el.hasClass('x-grid-hide-gridsummary');}
el[visible?'removeClass':'addClass']('x-grid-hide-gridsummary');this.view.layout();}},getSummaryNode:function(){return this.view.summary}});Ext.ux.grid.GridSummary.Calculations={sum:function(v,record,colName,data,rowIdx){return data[colName]+Ext.num(v,0);},count:function(v,record,colName,data,rowIdx){return rowIdx+1;},max:function(v,record,colName,data,rowIdx){return Math.max(Ext.num(v,0),data[colName]);},min:function(v,record,colName,data,rowIdx){return Math.min(Ext.num(v,0),data[colName]);},average:function(v,record,colName,data,rowIdx){var t=data[colName]+Ext.num(v,0),count=record.store.getCount();return rowIdx==count-1?(t/count):t;}}
Ext.grid.RowExpander=function(config){Ext.apply(this,config);this.addEvents({beforeexpand:true,expand:true,beforecollapse:true,collapse:true});Ext.grid.RowExpander.superclass.constructor.call(this);if(this.tpl){if(typeof this.tpl=='string'){this.tpl=new Ext.Template(this.tpl);}
this.tpl.compile();}
this.state={};this.bodyContent={};};Ext.extend(Ext.grid.RowExpander,Ext.util.Observable,{header:"",width:20,sortable:false,fixed:true,menuDisabled:true,dataIndex:'',id:'expander',lazyRender:true,enableCaching:true,getRowClass:function(record,rowIndex,p,ds){p.cols=p.cols-1;var content=this.bodyContent[record.id];if(!content&&!this.lazyRender){content=this.getBodyContent(record,rowIndex);}
if(content){p.body=content;}
return this.state[record.id]?'x-grid3-row-expanded':'x-grid3-row-collapsed';},init:function(grid){this.grid=grid;var view=grid.getView();view.getRowClass=this.getRowClass.createDelegate(this);view.enableRowBody=true;grid.on('render',function(){view.mainBody.on('mousedown',this.onMouseDown,this);},this);},getBodyContent:function(record,index){if(!this.enableCaching){return this.tpl.apply(record.data);}
var content=this.bodyContent[record.id];if(!content){content=this.tpl.apply(record.data);this.bodyContent[record.id]=content;}
return content;},onMouseDown:function(e,t){if(t.className=='x-grid3-row-expander'){e.stopEvent();var row=e.getTarget('.x-grid3-row');this.toggleRow(row);}},renderer:function(v,p,record){p.cellAttr='rowspan="2"';return'<div class="x-grid3-row-expander">&#160;</div>';},beforeExpand:function(record,body,rowIndex){if(this.fireEvent('beforeexpand',this,record,body,rowIndex)!==false){if(this.tpl&&this.lazyRender){body.innerHTML=this.getBodyContent(record,rowIndex);}
return true;}else{return false;}},isExpanded:function(row)
{if(typeof row=='number'){row=this.grid.view.getRow(row);}
return!Ext.fly(row).hasClass('x-grid3-row-collapsed');},toggleRow:function(row){if(typeof row=='number'){row=this.grid.view.getRow(row);}
this[Ext.fly(row).hasClass('x-grid3-row-collapsed')?'expandRow':'collapseRow'](row);},expandRow:function(row){if(typeof row=='number'){row=this.grid.view.getRow(row);}
var record=this.grid.store.getAt(row.rowIndex);var body=Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body',row);if(this.beforeExpand(record,body,row.rowIndex)){this.state[record.id]=true;Ext.fly(row).replaceClass('x-grid3-row-collapsed','x-grid3-row-expanded');this.fireEvent('expand',this,record,body,row.rowIndex);}},collapseRow:function(row){if(typeof row=='number'){row=this.grid.view.getRow(row);}
var record=this.grid.store.getAt(row.rowIndex);var body=Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body',true);if(this.fireEvent('beforcollapse',this,record,body,row.rowIndex)!==false){this.state[record.id]=false;Ext.fly(row).replaceClass('x-grid3-row-expanded','x-grid3-row-collapsed');this.fireEvent('collapse',this,record,body,row.rowIndex);}}});Ext.namespace("Ext.ux.netbox");Ext.ux.netbox.InputTextMask=function(mask,clearWhenInvalid){if(clearWhenInvalid===undefined){this.clearWhenInvalid=true;}else{this.clearWhenInvalid=clearWhenInvalid;}
this.rawMask=mask;this.viewMask='';this.maskArray=[];var mai=0;var regexp='';for(var i=0;i<mask.length;i++){if(regexp){if(regexp=='X'){regexp='';}
if(mask.charAt(i)=='X'){this.maskArray[mai]=regexp;mai++;regexp='';}else{regexp+=mask.charAt(i);}}else if(mask.charAt(i)=='X'){regexp+='X';this.viewMask+='_';}else if(mask.charAt(i)=='9'||mask.charAt(i)=='L'||mask.charAt(i)=='l'||mask.charAt(i)=='A'){this.viewMask+='_';this.maskArray[mai]=mask.charAt(i);mai++;}else{this.viewMask+=mask.charAt(i);this.maskArray[mai]=RegExp.escape(mask.charAt(i));mai++;}}
this.specialChars=this.viewMask.replace(/(L|l|9|A|_|X)/g,'');};Ext.ux.netbox.InputTextMask.prototype={init:function(field){this.field=field;if(field.rendered){this.assignEl();}else{field.on('render',this.assignEl,this);}
field.on('blur',this.removeValueWhenInvalid,this);field.on('focus',this.processMaskFocus,this);},assignEl:function(){this.inputTextElement=this.field.getEl().dom;this.field.getEl().on('keypress',this.processKeyPress,this);this.field.getEl().on('keydown',this.processKeyDown,this);if(Ext.isSafari||Ext.isIE){this.field.getEl().on('paste',this.startTask,this);this.field.getEl().on('cut',this.startTask,this);}
if(Ext.isGecko||Ext.isOpera){this.field.getEl().on('mousedown',this.setPreviousValue,this);}
if(Ext.isGecko){this.field.getEl().on('input',this.onInput,this);}
if(Ext.isOpera){this.field.getEl().on('input',this.onInputOpera,this);}},onInput:function(){this.startTask(false);},onInputOpera:function(){if(!this.prevValueOpera){this.startTask(false);}else{this.manageBackspaceAndDeleteOpera();}},manageBackspaceAndDeleteOpera:function(){this.inputTextElement.value=this.prevValueOpera.cursorPos.previousValue;this.manageTheText(this.prevValueOpera.keycode,this.prevValueOpera.cursorPos);this.prevValueOpera=null;},setPreviousValue:function(event){this.oldCursorPos=this.getCursorPosition();},getValidatedKey:function(keycode,cursorPosition){var maskKey=this.maskArray[cursorPosition.start];if(maskKey=='9'){return keycode.pressedKey.match(/[0-9]/);}else if(maskKey=='L'){return(keycode.pressedKey.match(/[A-Za-z]/))?keycode.pressedKey.toUpperCase():null;}else if(maskKey=='l'){return(keycode.pressedKey.match(/[A-Za-z]/))?keycode.pressedKey.toLowerCase():null;}else if(maskKey=='A'){return keycode.pressedKey.match(/[A-Za-z0-9]/);}else if(maskKey){return(keycode.pressedKey.match(new RegExp(maskKey)));}
return(null);},removeValueWhenInvalid:function(){if(this.clearWhenInvalid&&this.inputTextElement.value.indexOf('_')>-1){this.inputTextElement.value='';}},managePaste:function(){if(this.oldCursorPos===null){return;}
var valuePasted=this.inputTextElement.value.substring(this.oldCursorPos.start,this.inputTextElement.value.length-(this.oldCursorPos.previousValue.length-this.oldCursorPos.end));if(this.oldCursorPos.start<this.oldCursorPos.end){this.oldCursorPos.previousValue=this.oldCursorPos.previousValue.substring(0,this.oldCursorPos.start)+
this.viewMask.substring(this.oldCursorPos.start,this.oldCursorPos.end)+
this.oldCursorPos.previousValue.substring(this.oldCursorPos.end,this.oldCursorPos.previousValue.length);valuePasted=valuePasted.substr(0,this.oldCursorPos.end-this.oldCursorPos.start);}
this.inputTextElement.value=this.oldCursorPos.previousValue;keycode={unicode:'',isShiftPressed:false,isTab:false,isBackspace:false,isLeftOrRightArrow:false,isDelete:false,pressedKey:''};var charOk=false;for(var i=0;i<valuePasted.length;i++){keycode.pressedKey=valuePasted.substr(i,1);keycode.unicode=valuePasted.charCodeAt(i);this.oldCursorPos=this.skipMaskCharacters(keycode,this.oldCursorPos);if(this.oldCursorPos===false){break;}
if(this.injectValue(keycode,this.oldCursorPos)){charOk=true;this.moveCursorToPosition(keycode,this.oldCursorPos);this.oldCursorPos.previousValue=this.inputTextElement.value;this.oldCursorPos.start=this.oldCursorPos.start+1;}}
if(!charOk&&this.oldCursorPos!==false){this.moveCursorToPosition(null,this.oldCursorPos);}
this.oldCursorPos=null;},processKeyDown:function(e){this.processMaskFormatting(e,'keydown');},processKeyPress:function(e){this.processMaskFormatting(e,'keypress');},startTask:function(setOldCursor){if(this.task===undefined){this.task=new Ext.util.DelayedTask(this.managePaste,this);}
if(setOldCursor!==false){this.oldCursorPos=this.getCursorPosition();}
this.task.delay(0);},skipMaskCharacters:function(keycode,cursorPos){if(cursorPos.start!=cursorPos.end&&(keycode.isDelete||keycode.isBackspace)){return(cursorPos);}
while(this.specialChars.match(RegExp.escape(this.viewMask.charAt(((keycode.isBackspace)?cursorPos.start-1:cursorPos.start))))){if(keycode.isBackspace){cursorPos.dec();}else{cursorPos.inc();}
if(cursorPos.start>=cursorPos.previousValue.length||cursorPos.start<0){return false;}}
return(cursorPos);},isManagedByKeyDown:function(keycode){if(keycode.isDelete||keycode.isBackspace){return(true);}
return(false);},processMaskFormatting:function(e,type){this.oldCursorPos=null;var cursorPos=this.getCursorPosition();var keycode=this.getKeyCode(e,type);if(keycode.unicode===0){return;}
if((keycode.unicode==67||keycode.unicode==99)&&e.ctrlKey){return;}
if((keycode.unicode==88||keycode.unicode==120)&&e.ctrlKey){this.startTask();return;}
if((keycode.unicode==86||keycode.unicode==118)&&e.ctrlKey){this.startTask();return;}
if((keycode.isBackspace||keycode.isDelete)&&Ext.isOpera){this.prevValueOpera={cursorPos:cursorPos,keycode:keycode};return;}
if(type=='keydown'&&!this.isManagedByKeyDown(keycode)){return true;}
if(type=='keypress'&&this.isManagedByKeyDown(keycode)){return true;}
if(this.handleEventBubble(e,keycode,type)){return true;}
return(this.manageTheText(keycode,cursorPos));},manageTheText:function(keycode,cursorPos){if(this.inputTextElement.value.length===0){this.inputTextElement.value=this.viewMask;}
cursorPos=this.skipMaskCharacters(keycode,cursorPos);if(cursorPos===false){return false;}
if(this.injectValue(keycode,cursorPos)){this.moveCursorToPosition(keycode,cursorPos);}
return(false);},processMaskFocus:function(){if(this.inputTextElement.value.length===0){var cursorPos=this.getCursorPosition();this.inputTextElement.value=this.viewMask;this.moveCursorToPosition(null,cursorPos);}},isManagedByBrowser:function(keyEvent,keycode,type){if(((type=='keypress'&&keyEvent.charCode===0)||type=='keydown')&&(keycode.unicode==Ext.EventObject.TAB||keycode.unicode==Ext.EventObject.RETURN||keycode.unicode==Ext.EventObject.ENTER||keycode.unicode==Ext.EventObject.SHIFT||keycode.unicode==Ext.EventObject.CONTROL||keycode.unicode==Ext.EventObject.ESC||keycode.unicode==Ext.EventObject.PAGEUP||keycode.unicode==Ext.EventObject.PAGEDOWN||keycode.unicode==Ext.EventObject.END||keycode.unicode==Ext.EventObject.HOME||keycode.unicode==Ext.EventObject.LEFT||keycode.unicode==Ext.EventObject.UP||keycode.unicode==Ext.EventObject.RIGHT||keycode.unicode==Ext.EventObject.DOWN)){return(true);}
return(false);},handleEventBubble:function(keyEvent,keycode,type){try{if(keycode&&this.isManagedByBrowser(keyEvent,keycode,type)){return true;}
keyEvent.stopEvent();return false;}catch(e){alert(e.message);}},getCursorPosition:function(){var s,e,r;if(this.inputTextElement.createTextRange){r=document.selection.createRange().duplicate();r.moveEnd('character',this.inputTextElement.value.length);if(r.text===''){s=this.inputTextElement.value.length;}else{s=this.inputTextElement.value.lastIndexOf(r.text);}
r=document.selection.createRange().duplicate();r.moveStart('character',-this.inputTextElement.value.length);e=r.text.length;}else{s=this.inputTextElement.selectionStart;e=this.inputTextElement.selectionEnd;}
return this.CursorPosition(s,e,r,this.inputTextElement.value);},moveCursorToPosition:function(keycode,cursorPosition){var p=(!keycode||(keycode&&keycode.isBackspace))?cursorPosition.start:cursorPosition.start+1;if(this.inputTextElement.createTextRange){cursorPosition.range.move('character',p);cursorPosition.range.select();}else{this.inputTextElement.selectionStart=p;this.inputTextElement.selectionEnd=p;}},injectValue:function(keycode,cursorPosition){if(!keycode.isDelete&&keycode.unicode==cursorPosition.previousValue.charCodeAt(cursorPosition.start)){return true;}
var key;if(!keycode.isDelete&&!keycode.isBackspace){key=this.getValidatedKey(keycode,cursorPosition);}else{if(cursorPosition.start==cursorPosition.end){key='_';if(keycode.isBackspace){cursorPosition.dec();}}else{key=this.viewMask.substring(cursorPosition.start,cursorPosition.end);}}
if(key){this.inputTextElement.value=cursorPosition.previousValue.substring(0,cursorPosition.start);this.inputTextElement.value+=key+cursorPosition.previousValue.substring(cursorPosition.start+key.length,cursorPosition.previousValue.length);return true;}
return false;},getKeyCode:function(onKeyDownEvent,type){var keycode={};keycode.unicode=onKeyDownEvent.getKey();keycode.isShiftPressed=onKeyDownEvent.shiftKey;keycode.isDelete=((onKeyDownEvent.getKey()==Ext.EventObject.DELETE&&type=='keydown')||(type=='keypress'&&onKeyDownEvent.charCode===0&&onKeyDownEvent.keyCode==Ext.EventObject.DELETE))?true:false;keycode.isTab=(onKeyDownEvent.getKey()==Ext.EventObject.TAB)?true:false;keycode.isBackspace=(onKeyDownEvent.getKey()==Ext.EventObject.BACKSPACE)?true:false;keycode.isLeftOrRightArrow=(onKeyDownEvent.getKey()==Ext.EventObject.LEFT||onKeyDownEvent.getKey()==Ext.EventObject.RIGHT)?true:false;keycode.pressedKey=String.fromCharCode(keycode.unicode);return(keycode);},CursorPosition:function(start,end,range,previousValue){var cursorPosition={};cursorPosition.start=isNaN(start)?0:start;cursorPosition.end=isNaN(end)?0:end;cursorPosition.range=range;cursorPosition.previousValue=previousValue;cursorPosition.inc=function(){cursorPosition.start++;cursorPosition.end++;};cursorPosition.dec=function(){cursorPosition.start--;cursorPosition.end--;};return(cursorPosition);}};Ext.applyIf(RegExp,{escape:function(str){return str.replace(/([.*+?^=!:${}()|[\]\/\\])/g,'\\$1');}});Ext.ux.InputTextMask=Ext.ux.netbox.InputTextMask;Ext.ux.Multiselect=Ext.extend(Ext.form.Field,{store:null,dataFields:[],data:[],width:100,height:100,displayField:0,valueField:1,allowBlank:true,minLength:0,maxLength:Number.MAX_VALUE,blankText:Ext.form.TextField.prototype.blankText,minLengthText:'Minimum {0} item(s) required',maxLengthText:'Maximum {0} item(s) allowed',copy:false,allowDup:false,allowTrash:false,legend:null,focusClass:undefined,delimiter:',',view:null,dragGroup:null,dropGroup:null,tbar:null,appendOnly:false,sortField:null,sortDir:'ASC',defaultAutoCreate:{tag:"div"},initComponent:function(){Ext.ux.Multiselect.superclass.initComponent.call(this);this.addEvents({'dblclick':true,'click':true,'change':true,'drop':true});},onRender:function(ct,position){var fs,cls,tpl;Ext.ux.Multiselect.superclass.onRender.call(this,ct,position);cls='ux-mselect';fs=new Ext.form.FieldSet({renderTo:this.el,title:this.legend,height:this.height,width:this.width,style:"padding:1px;",tbar:this.tbar});if(!this.legend)try{fs.el.down('.'+fs.headerCls).remove();}catch(e){}
fs.body.addClass(cls);tpl='<tpl for="."><div class="'+cls+'-item';if(Ext.isIE||Ext.isIE7)tpl+='" unselectable=on';else tpl+=' x-unselectable"';tpl+='>{'+this.displayField+'}</div></tpl>';if(!this.store){this.store=new Ext.data.SimpleStore({fields:this.dataFields,data:this.data});}
this.view=new Ext.ux.DDView({multiSelect:true,store:this.store,selectedClass:cls+"-selected",tpl:tpl,allowDup:this.allowDup,copy:this.copy,allowTrash:this.allowTrash,dragGroup:this.dragGroup,dropGroup:this.dropGroup,itemSelector:"."+cls+"-item",isFormField:false,applyTo:fs.body,appendOnly:this.appendOnly,sortField:this.sortField,sortDir:this.sortDir});fs.add(this.view);this.view.on('click',this.onViewClick,this);this.view.on('beforeClick',this.onViewBeforeClick,this);this.view.on('dblclick',this.onViewDblClick,this);this.view.on('drop',function(ddView,n,dd,e,data){return this.fireEvent("drop",ddView,n,dd,e,data);},this);this.hiddenName=this.name;var hiddenTag={tag:"input",type:"hidden",value:"",name:this.name||Ext.id()};if(this.isFormField){this.hiddenField=this.el.createChild(hiddenTag);}else{this.hiddenField=Ext.get(document.body).createChild(hiddenTag);}
fs.doLayout();},initValue:Ext.emptyFn,onViewClick:function(vw,index,node,e){var arrayIndex=this.preClickSelections.indexOf(index);if(arrayIndex!=-1)
{this.preClickSelections.splice(arrayIndex,1);this.view.clearSelections(true);this.view.select(this.preClickSelections);}
this.fireEvent('change',this,this.getValue(),this.hiddenField.dom.value);this.hiddenField.dom.value=this.getValue();this.fireEvent('click',this,e);this.validate();},onViewBeforeClick:function(vw,index,node,e){this.preClickSelections=this.view.getSelectedIndexes();if(this.disabled){return false;}},onViewDblClick:function(vw,index,node,e){return this.fireEvent('dblclick',vw,index,node,e);},getValue:function(valueField){var returnArray=[];var selectionsArray=this.view.getSelectedIndexes();if(selectionsArray.length==0){return'';}
for(var i=0;i<selectionsArray.length;i++){returnArray.push(this.store.getAt(selectionsArray[i]).get(((valueField!=null)?valueField:this.valueField)));}
return returnArray.join(this.delimiter);},setValue:function(values){var index;var selections=[];this.view.clearSelections();this.hiddenField.dom.value='';if(!values||(values=='')){return;}
if(!(values instanceof Array)){values=values.split(this.delimiter);}
for(var i=0;i<values.length;i++){index=this.view.store.indexOf(this.view.store.query(this.valueField,new RegExp('^'+values[i]+'$',"i")).itemAt(0));selections.push(index);}
this.view.select(selections);this.hiddenField.dom.value=this.getValue();this.validate();},reset:function(){this.setValue('');},getRawValue:function(valueField){var tmp=this.getValue(valueField);if(tmp.length){tmp=tmp.split(this.delimiter);}
else{tmp=[];}
return tmp;},setRawValue:function(values){setValue(values);},validateValue:function(value){if(value.length<1){if(this.allowBlank){this.clearInvalid();return true;}else{this.markInvalid(this.blankText);return false;}}
if(value.length<this.minLength){this.markInvalid(String.format(this.minLengthText,this.minLength));return false;}
if(value.length>this.maxLength){this.markInvalid(String.format(this.maxLengthText,this.maxLength));return false;}
return true;}});Ext.reg("multiselect",Ext.ux.Multiselect);Ext.ux.ItemSelector=Ext.extend(Ext.form.Field,{msWidth:200,msHeight:300,hideNavIcons:false,imagePath:"",iconUp:"up2.gif",iconDown:"down2.gif",iconLeft:"left2.gif",iconRight:"right2.gif",iconTop:"top2.gif",iconBottom:"bottom2.gif",drawUpIcon:true,drawDownIcon:true,drawLeftIcon:true,drawRightIcon:true,drawTopIcon:true,drawBotIcon:true,fromStore:null,toStore:null,fromData:null,toData:null,displayField:0,valueField:1,switchToFrom:false,allowDup:false,focusClass:undefined,delimiter:',',readOnly:false,toLegend:null,fromLegend:null,toSortField:null,fromSortField:null,toSortDir:'ASC',fromSortDir:'ASC',toTBar:null,fromTBar:null,bodyStyle:null,border:false,defaultAutoCreate:{tag:"div"},initComponent:function(){Ext.ux.ItemSelector.superclass.initComponent.call(this);this.addEvents({'rowdblclick':true,'change':true});},onRender:function(ct,position){Ext.ux.ItemSelector.superclass.onRender.call(this,ct,position);this.fromMultiselect=new Ext.ux.Multiselect({legend:this.fromLegend,delimiter:this.delimiter,allowDup:this.allowDup,copy:this.allowDup,allowTrash:this.allowDup,dragGroup:this.readOnly?null:"drop2-"+this.el.dom.id,dropGroup:this.readOnly?null:"drop1-"+this.el.dom.id,width:this.msWidth,height:this.msHeight,dataFields:this.dataFields,data:this.fromData,displayField:this.displayField,valueField:this.valueField,store:this.fromStore,isFormField:false,tbar:this.fromTBar,appendOnly:true,sortField:this.fromSortField,sortDir:this.fromSortDir});this.fromMultiselect.on('dblclick',this.onRowDblClick,this);if(!this.toStore){this.toStore=new Ext.data.SimpleStore({fields:this.dataFields,data:this.toData});}
this.toStore.on('add',this.valueChanged,this);this.toStore.on('remove',this.valueChanged,this);this.toStore.on('load',this.valueChanged,this);this.toMultiselect=new Ext.ux.Multiselect({legend:this.toLegend,delimiter:this.delimiter,allowDup:this.allowDup,dragGroup:this.readOnly?null:"drop1-"+this.el.dom.id,dropGroup:this.readOnly?null:"drop2-"+this.el.dom.id+",drop1-"+this.el.dom.id,width:this.msWidth,height:this.msHeight,displayField:this.displayField,valueField:this.valueField,store:this.toStore,isFormField:false,tbar:this.toTBar,sortField:this.toSortField,sortDir:this.toSortDir});this.toMultiselect.on('dblclick',this.onRowDblClick,this);var p=new Ext.Panel({bodyStyle:this.bodyStyle,border:this.border,layout:"table",layoutConfig:{columns:3}});p.add(this.switchToFrom?this.toMultiselect:this.fromMultiselect);var icons=new Ext.Panel({header:false});p.add(icons);p.add(this.switchToFrom?this.fromMultiselect:this.toMultiselect);p.render(this.el);icons.el.down('.'+icons.bwrapCls).remove();if(this.imagePath!=""&&this.imagePath.charAt(this.imagePath.length-1)!="/")
this.imagePath+="/";this.iconUp=this.imagePath+(this.iconUp||'up2.gif');this.iconDown=this.imagePath+(this.iconDown||'down2.gif');this.iconLeft=this.imagePath+(this.iconLeft||'left2.gif');this.iconRight=this.imagePath+(this.iconRight||'right2.gif');this.iconTop=this.imagePath+(this.iconTop||'top2.gif');this.iconBottom=this.imagePath+(this.iconBottom||'bottom2.gif');var el=icons.getEl();if(!this.toSortField){this.toTopIcon=el.createChild({tag:'img',src:this.iconTop,style:{cursor:'pointer',margin:'2px'}});el.createChild({tag:'br'});this.upIcon=el.createChild({tag:'img',src:this.iconUp,style:{cursor:'pointer',margin:'2px'}});el.createChild({tag:'br'});}
this.addIcon=el.createChild({tag:'img',src:this.switchToFrom?this.iconLeft:this.iconRight,style:{cursor:'pointer',margin:'2px'}});el.createChild({tag:'br'});this.removeIcon=el.createChild({tag:'img',src:this.switchToFrom?this.iconRight:this.iconLeft,style:{cursor:'pointer',margin:'2px'}});el.createChild({tag:'br'});if(!this.toSortField){this.downIcon=el.createChild({tag:'img',src:this.iconDown,style:{cursor:'pointer',margin:'2px'}});el.createChild({tag:'br'});this.toBottomIcon=el.createChild({tag:'img',src:this.iconBottom,style:{cursor:'pointer',margin:'2px'}});}
if(!this.readOnly){if(!this.toSortField){this.toTopIcon.on('click',this.toTop,this);this.upIcon.on('click',this.up,this);this.downIcon.on('click',this.down,this);this.toBottomIcon.on('click',this.toBottom,this);}
this.addIcon.on('click',this.fromTo,this);this.removeIcon.on('click',this.toFrom,this);}
if(!this.drawUpIcon||this.hideNavIcons){this.upIcon.dom.style.display='none';}
if(!this.drawDownIcon||this.hideNavIcons){this.downIcon.dom.style.display='none';}
if(!this.drawLeftIcon||this.hideNavIcons){this.addIcon.dom.style.display='none';}
if(!this.drawRightIcon||this.hideNavIcons){this.removeIcon.dom.style.display='none';}
if(!this.drawTopIcon||this.hideNavIcons){this.toTopIcon.dom.style.display='none';}
if(!this.drawBotIcon||this.hideNavIcons){this.toBottomIcon.dom.style.display='none';}
var tb=p.body.first();this.el.setWidth(p.body.first().getWidth());p.body.removeClass();this.hiddenName=this.name;var hiddenTag={tag:"input",type:"hidden",value:"",name:this.name||Ext.id()};this.hiddenField=this.el.createChild(hiddenTag);this.valueChanged(this.toStore);},initValue:Ext.emptyFn,toTop:function(){var selectionsArray=this.toMultiselect.view.getSelectedIndexes();var records=[];if(selectionsArray.length>0){selectionsArray.sort();for(var i=0;i<selectionsArray.length;i++){record=this.toMultiselect.view.store.getAt(selectionsArray[i]);records.push(record);}
selectionsArray=[];for(var i=records.length-1;i>-1;i--){record=records[i];this.toMultiselect.view.store.remove(record);this.toMultiselect.view.store.insert(0,record);selectionsArray.push(((records.length-1)-i));}}
this.toMultiselect.view.refresh();this.toMultiselect.view.select(selectionsArray);},toBottom:function(){var selectionsArray=this.toMultiselect.view.getSelectedIndexes();var records=[];if(selectionsArray.length>0){selectionsArray.sort();for(var i=0;i<selectionsArray.length;i++){record=this.toMultiselect.view.store.getAt(selectionsArray[i]);records.push(record);}
selectionsArray=[];for(var i=0;i<records.length;i++){record=records[i];this.toMultiselect.view.store.remove(record);this.toMultiselect.view.store.add(record);selectionsArray.push((this.toMultiselect.view.store.getCount())-(records.length-i));}}
this.toMultiselect.view.refresh();this.toMultiselect.view.select(selectionsArray);},up:function(){var record=null;var selectionsArray=this.toMultiselect.view.getSelectedIndexes();selectionsArray.sort();var newSelectionsArray=[];if(selectionsArray.length>0){for(var i=0;i<selectionsArray.length;i++){record=this.toMultiselect.view.store.getAt(selectionsArray[i]);if((selectionsArray[i]-1)>=0){this.toMultiselect.view.store.remove(record);this.toMultiselect.view.store.insert(selectionsArray[i]-1,record);newSelectionsArray.push(selectionsArray[i]-1);}}
this.toMultiselect.view.refresh();this.toMultiselect.view.select(newSelectionsArray);}},down:function(){var record=null;var selectionsArray=this.toMultiselect.view.getSelectedIndexes();selectionsArray.sort();selectionsArray.reverse();var newSelectionsArray=[];if(selectionsArray.length>0){for(var i=0;i<selectionsArray.length;i++){record=this.toMultiselect.view.store.getAt(selectionsArray[i]);if((selectionsArray[i]+1)<this.toMultiselect.view.store.getCount()){this.toMultiselect.view.store.remove(record);this.toMultiselect.view.store.insert(selectionsArray[i]+1,record);newSelectionsArray.push(selectionsArray[i]+1);}}
this.toMultiselect.view.refresh();this.toMultiselect.view.select(newSelectionsArray);}},fromTo:function(){var selectionsArray=this.fromMultiselect.view.getSelectedIndexes();var records=[];if(selectionsArray.length>0){for(var i=0;i<selectionsArray.length;i++){record=this.fromMultiselect.view.store.getAt(selectionsArray[i]);records.push(record);}
if(!this.allowDup)selectionsArray=[];for(var i=0;i<records.length;i++){record=records[i];if(this.allowDup){var x=new Ext.data.Record();record.id=x.id;delete x;this.toMultiselect.view.store.add(record);}else{this.fromMultiselect.view.store.remove(record);this.toMultiselect.view.store.add(record);selectionsArray.push((this.toMultiselect.view.store.getCount()-1));}}}
this.toMultiselect.view.refresh();this.fromMultiselect.view.refresh();if(this.toSortField)this.toMultiselect.store.sort(this.toSortField,this.toSortDir);if(this.allowDup)this.fromMultiselect.view.select(selectionsArray);else this.toMultiselect.view.select(selectionsArray);},toFrom:function(){var selectionsArray=this.toMultiselect.view.getSelectedIndexes();var records=[];if(selectionsArray.length>0){for(var i=0;i<selectionsArray.length;i++){record=this.toMultiselect.view.store.getAt(selectionsArray[i]);records.push(record);}
selectionsArray=[];for(var i=0;i<records.length;i++){record=records[i];this.toMultiselect.view.store.remove(record);if(!this.allowDup){this.fromMultiselect.view.store.add(record);selectionsArray.push((this.fromMultiselect.view.store.getCount()-1));}}}
this.fromMultiselect.view.refresh();this.toMultiselect.view.refresh();if(this.fromSortField)this.fromMultiselect.store.sort(this.fromSortField,this.fromSortDir);this.fromMultiselect.view.select(selectionsArray);},valueChanged:function(store){var record=null;var values=[];for(var i=0;i<store.getCount();i++){record=store.getAt(i);values.push(record.get(this.valueField));}
this.hiddenField.dom.value=values.join(this.delimiter);this.fireEvent('change',this,this.getValue(),this.hiddenField.dom.value);},getValue:function(){return this.hiddenField.dom.value;},onRowDblClick:function(vw,index,node,e){return this.fireEvent('rowdblclick',vw,index,node,e);},reset:function(){range=this.toMultiselect.store.getRange();this.toMultiselect.store.removeAll();if(!this.allowDup){this.fromMultiselect.store.add(range);this.fromMultiselect.store.sort(this.displayField,'ASC');}
this.valueChanged(this.toMultiselect.store);}});Ext.reg("itemselector",Ext.ux.ItemSelector);Array.prototype.contains=function(element){return this.indexOf(element)!==-1;};Ext.namespace("Ext.ux");Ext.ux.DDView=function(config){if(!config.itemSelector){var tpl=config.tpl;if(this.classRe.test(tpl)){config.tpl=tpl.replace(this.classRe,'class=$1x-combo-list-item $2$1');}
else{config.tpl=tpl.replace(this.tagRe,'$1 class="x-combo-list-item" $2');}
config.itemSelector=".x-combo-list-item";}
Ext.ux.DDView.superclass.constructor.call(this,Ext.apply(config,{border:false}));};Ext.extend(Ext.ux.DDView,Ext.DataView,{sortDir:'ASC',isFormField:true,classRe:/class=(['"])(.*)\1/,tagRe:/(<\w*)(.*?>)/,reset:Ext.emptyFn,clearInvalid:Ext.form.Field.prototype.clearInvalid,msgTarget:'qtip',afterRender:function(){Ext.ux.DDView.superclass.afterRender.call(this);if(this.dragGroup){this.setDraggable(this.dragGroup.split(","));}
if(this.dropGroup){this.setDroppable(this.dropGroup.split(","));}
if(this.deletable){this.setDeletable();}
this.isDirtyFlag=false;this.addEvents("drop");},validate:function(){return true;},destroy:function(){this.purgeListeners();this.getEl().removeAllListeners();this.getEl().remove();if(this.dragZone){if(this.dragZone.destroy){this.dragZone.destroy();}}
if(this.dropZone){if(this.dropZone.destroy){this.dropZone.destroy();}}},getName:function(){return this.name;},setValue:function(v){if(!this.store){throw"DDView.setValue(). DDView must be constructed with a valid Store";}
var data={};data[this.store.reader.meta.root]=v?[].concat(v):[];this.store.proxy=new Ext.data.MemoryProxy(data);this.store.load();},getValue:function(){var result='(';this.store.each(function(rec){result+=rec.id+',';});return result.substr(0,result.length-1)+')';},getIds:function(){var i=0,result=new Array(this.store.getCount());this.store.each(function(rec){result[i++]=rec.id;});return result;},isDirty:function(){return this.isDirtyFlag;},getTargetFromEvent:function(e){var target=e.getTarget();while((target!==null)&&(target.parentNode!=this.el.dom)){target=target.parentNode;}
if(!target){target=this.el.dom.lastChild||this.el.dom;}
return target;},getDragData:function(e){var target=this.findItemFromChild(e.getTarget());if(target){if(!this.isSelected(target)){delete this.ignoreNextClick;this.onItemClick(target,this.indexOf(target),e);this.ignoreNextClick=true;}
var dragData={sourceView:this,viewNodes:[],records:[],copy:this.copy||(this.allowCopy&&e.ctrlKey)};if(this.getSelectionCount()==1){var i=this.getSelectedIndexes()[0];var n=this.getNode(i);dragData.viewNodes.push(dragData.ddel=n);dragData.records.push(this.store.getAt(i));dragData.repairXY=Ext.fly(n).getXY();}else{dragData.ddel=document.createElement('div');dragData.ddel.className='multi-proxy';this.collectSelection(dragData);}
return dragData;}
return false;},getRepairXY:function(e){return this.dragData.repairXY;},collectSelection:function(data){data.repairXY=Ext.fly(this.getSelectedNodes()[0]).getXY();if(this.preserveSelectionOrder===true){Ext.each(this.getSelectedIndexes(),function(i){var n=this.getNode(i);var dragNode=n.cloneNode(true);dragNode.id=Ext.id();data.ddel.appendChild(dragNode);data.records.push(this.store.getAt(i));data.viewNodes.push(n);},this);}else{var i=0;this.store.each(function(rec){if(this.isSelected(i)){var n=this.getNode(i);var dragNode=n.cloneNode(true);dragNode.id=Ext.id();data.ddel.appendChild(dragNode);data.records.push(this.store.getAt(i));data.viewNodes.push(n);}
i++;},this);}},setDraggable:function(ddGroup){if(ddGroup instanceof Array){Ext.each(ddGroup,this.setDraggable,this);return;}
if(this.dragZone){this.dragZone.addToGroup(ddGroup);}else{this.dragZone=new Ext.dd.DragZone(this.getEl(),{containerScroll:true,ddGroup:ddGroup});if(!this.multiSelect){this.singleSelect=true;}
this.dragZone.getDragData=this.getDragData.createDelegate(this);this.dragZone.getRepairXY=this.getRepairXY;this.dragZone.onEndDrag=this.onEndDrag;}},setDroppable:function(ddGroup){if(ddGroup instanceof Array){Ext.each(ddGroup,this.setDroppable,this);return;}
if(this.dropZone){this.dropZone.addToGroup(ddGroup);}else{this.dropZone=new Ext.dd.DropZone(this.getEl(),{owningView:this,containerScroll:true,ddGroup:ddGroup});this.dropZone.getTargetFromEvent=this.getTargetFromEvent.createDelegate(this);this.dropZone.onNodeEnter=this.onNodeEnter.createDelegate(this);this.dropZone.onNodeOver=this.onNodeOver.createDelegate(this);this.dropZone.onNodeOut=this.onNodeOut.createDelegate(this);this.dropZone.onNodeDrop=this.onNodeDrop.createDelegate(this);}},getDropPoint:function(e,n,dd){if(n==this.el.dom){return"above";}
var t=Ext.lib.Dom.getY(n),b=t+n.offsetHeight;var c=t+(b-t)/2;var y=Ext.lib.Event.getPageY(e);if(y<=c){return"above";}else{return"below";}},isValidDropPoint:function(pt,n,data){if(!data.viewNodes||(data.viewNodes.length!=1)){return true;}
var d=data.viewNodes[0];if(d==n){return false;}
if((pt=="below")&&(n.nextSibling==d)){return false;}
if((pt=="above")&&(n.previousSibling==d)){return false;}
return true;},onNodeEnter:function(n,dd,e,data){if(this.highlightColor&&(data.sourceView!=this)){this.el.highlight(this.highlightColor);}
return false;},onNodeOver:function(n,dd,e,data){var dragElClass=this.dropNotAllowed;var pt=this.getDropPoint(e,n,dd);if(this.isValidDropPoint(pt,n,data)){if(this.appendOnly||this.sortField){return"x-tree-drop-ok-below";}
if(pt){var targetElClass;if(pt=="above"){dragElClass=n.previousSibling?"x-tree-drop-ok-between":"x-tree-drop-ok-above";targetElClass="x-view-drag-insert-above";}else{dragElClass=n.nextSibling?"x-tree-drop-ok-between":"x-tree-drop-ok-below";targetElClass="x-view-drag-insert-below";}
if(this.lastInsertClass!=targetElClass){Ext.fly(n).replaceClass(this.lastInsertClass,targetElClass);this.lastInsertClass=targetElClass;}}}
return dragElClass;},onNodeOut:function(n,dd,e,data){this.removeDropIndicators(n);},onNodeDrop:function(n,dd,e,data){if(this.fireEvent("drop",this,n,dd,e,data)===false){return false;}
var pt=this.getDropPoint(e,n,dd);var insertAt=(this.appendOnly||(n==this.el.dom))?this.store.getCount():n.viewIndex;if(pt=="below"){insertAt++;}
if(data.sourceView==this){if(pt=="below"){if(data.viewNodes[0]==n){data.viewNodes.shift();}}else{if(data.viewNodes[data.viewNodes.length-1]==n){data.viewNodes.pop();}}
if(!data.viewNodes.length){return false;}
if(insertAt>this.store.indexOf(data.records[0])){insertAt--;}}
if(data.node instanceof Ext.tree.TreeNode){var r=data.node.getOwnerTree().recordFromNode(data.node);if(r){data.records=[r];}}
if(!data.records){alert("Programming problem. Drag data contained no Records");return false;}
for(var i=0;i<data.records.length;i++){var r=data.records[i];var dup=this.store.getById(r.id);if(dup&&(dd!=this.dragZone)){if(!this.allowDup&&!this.allowTrash){Ext.fly(this.getNode(this.store.indexOf(dup))).frame("red",1);return true}
var x=new Ext.data.Record();r.id=x.id;delete x;}
if(data.copy){this.store.insert(insertAt++,r.copy());}else{if(data.sourceView){data.sourceView.isDirtyFlag=true;data.sourceView.store.remove(r);}
if(!this.allowTrash)this.store.insert(insertAt++,r);}
if(this.sortField){this.store.sort(this.sortField,this.sortDir);}
this.isDirtyFlag=true;}
this.dragZone.cachedTarget=null;return true;},onEndDrag:function(data,e){var d=Ext.get(this.dragData.ddel);if(d&&d.hasClass("multi-proxy")){d.remove();}},removeDropIndicators:function(n){if(n){Ext.fly(n).removeClass(["x-view-drag-insert-above","x-view-drag-insert-left","x-view-drag-insert-right","x-view-drag-insert-below"]);this.lastInsertClass="_noclass";}},setDeletable:function(imageUrl){if(!this.singleSelect&&!this.multiSelect){this.singleSelect=true;}
var c=this.getContextMenu();this.contextMenu.on("itemclick",function(item){switch(item.id){case"delete":this.remove(this.getSelectedIndexes());break;}},this);this.contextMenu.add({icon:imageUrl||AU.resolveUrl("/images/delete.gif"),id:"delete",text:AU.getMessage("deleteItem")});},getContextMenu:function(){if(!this.contextMenu){this.contextMenu=new Ext.menu.Menu({id:this.id+"-contextmenu"});this.el.on("contextmenu",this.showContextMenu,this);}
return this.contextMenu;},disableContextMenu:function(){if(this.contextMenu){this.el.un("contextmenu",this.showContextMenu,this);}},showContextMenu:function(e,item){item=this.findItemFromChild(e.getTarget());if(item){e.stopEvent();this.select(this.getNode(item),this.multiSelect&&e.ctrlKey,true);this.contextMenu.showAt(e.getXY());}},remove:function(selectedIndices){selectedIndices=[].concat(selectedIndices);for(var i=0;i<selectedIndices.length;i++){var rec=this.store.getAt(selectedIndices[i]);this.store.remove(rec);}},onDblClick:function(e){var item=this.findItemFromChild(e.getTarget());if(item){if(this.fireEvent("dblclick",this,this.indexOf(item),item,e)===false){return false;}
if(this.dragGroup){var targets=Ext.dd.DragDropMgr.getRelated(this.dragZone,true);while(targets.contains(this.dropZone)){targets.remove(this.dropZone);}
if((targets.length==1)&&(targets[0].owningView)){this.dragZone.cachedTarget=null;var el=Ext.get(targets[0].getEl());var box=el.getBox(true);targets[0].onNodeDrop(el.dom,{target:el.dom,xy:[box.x,box.y+box.height-1]},null,this.getDragData(e));}}}},onItemClick:function(item,index,e){if(this.ignoreNextClick){delete this.ignoreNextClick;return;}
if(this.fireEvent("beforeclick",this,index,item,e)===false){return false;}
if(this.multiSelect||this.singleSelect){if(this.multiSelect&&e.shiftKey&&this.lastSelection){this.select(this.getNodes(this.indexOf(this.lastSelection),index),false);}else if(this.isSelected(item)&&e.ctrlKey){this.deselect(item);}else{this.deselect(item);this.select(item,this.multiSelect&&e.ctrlKey);this.lastSelection=item;}
e.preventDefault();}
return true;}});Ext.namespace('Ext.ux');Ext.ux.MonthPicker=function(config){Ext.apply(this,config);Ext.ux.MonthPicker.superclass.constructor.call(this);};Ext.ux.MonthPicker=Ext.extend(Ext.Component,{format:"M, Y",okText:Ext.MessageBox.buttonText.ok,cancelText:Ext.MessageBox.buttonText.cancel,constrainToViewport:true,monthNames:Date.monthNames,startDay:0,minDate:null,maxDate:null,value:0,noPastYears:false,noPastMonths:false,useDayDate:null,initComponent:function(){Ext.ux.MonthPicker.superclass.initComponent.call(this);this.value=this.value?this.value.clearTime():new Date().clearTime();this.activeDate=this.value;this.addEvents('select');if(this.handler){this.on("select",this.handler,this.scope||this);}},focus:function(){if(this.el){this.update(this.activeDate);}},onRender:function(container,position){var m=['<div style="width: 175px; height:175px;"></div>']
m[m.length]='<div class="x-date-mp"></div>';var el=document.createElement("div");el.className="x-date-picker";el.innerHTML=m.join("");container.dom.insertBefore(el,position);this.el=Ext.get(el);this.monthPicker=this.el.down('div.x-date-mp');this.monthPicker.enableDisplayMode('block');this.el.unselectable();this.showMonthPicker();if(Ext.isIE){this.el.repaint();}
this.update(this.value);},createMonthPicker:function(){var minMonth=-1;if(this.noPastMonths){minMonth=new Date().getMonth();}
if(!this.monthPicker.dom.firstChild){var buf=['<table border="0" cellspacing="0">'];for(var i=0;i<6;i++){buf.push('<tr><td class="x-date-mp-month'+(i<minMonth?' x-date-disabled':'')+'"><a href="#">',this.monthNames[i].substr(0,3),'</a></td>','<td class="x-date-mp-month x-date-mp-sep"><a href="#">',this.monthNames[i+6].substr(0,3),'</a></td>',i==0?'<td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-prev"></a></td><td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-next"></a></td></tr>':'<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>');}
buf.push('<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',this.okText,'</button><button type="button" class="x-date-mp-cancel">',this.cancelText,'</button></td></tr>','</table>');this.monthPicker.update(buf.join(''));this.monthPicker.on('click',this.onMonthClick,this);this.monthPicker.on('dblclick',this.onMonthDblClick,this);this.mpMonths=this.monthPicker.select('td.x-date-mp-month');this.mpYears=this.monthPicker.select('td.x-date-mp-year');this.mpMonths.each(function(m,a,i){i+=1;if((i%2)==0){m.dom.xmonth=5+Math.round(i*.5);}else{m.dom.xmonth=Math.round((i-1)*.5);}});}},showMonthPicker:function(){this.createMonthPicker();var size=this.el.getSize();this.monthPicker.setSize(size);this.monthPicker.child('table').setSize(size);this.mpSelMonth=(this.activeDate||this.value).getMonth();this.updateMPMonth(this.mpSelMonth);this.mpSelYear=(this.activeDate||this.value).getFullYear();this.updateMPYear(this.mpSelYear);this.monthPicker.show();},updateMonthPicker:function(){if((this.activeDate&&!isNaN(this.activeDate.getElapsed()))||(this.value&&!isNaN(this.value.getElapsed))){this.mpSelMonth=(this.activeDate||this.value||new Date()).getMonth();this.updateMPMonth(this.mpSelMonth);this.mpSelYear=(this.activeDate||this.value||new Date()).getFullYear();this.updateMPYear(this.mpSelYear);}},updateMPYear:function(y){if(this.noPastYears){var minYear=new Date().getFullYear();if(y<(minYear+4)){y=minYear+4;}}
this.mpyear=y;var ys=this.mpYears.elements;for(var i=1;i<=10;i++){var td=ys[i-1],y2;if((i%2)==0){y2=y+Math.round(i*.5);td.firstChild.innerHTML=y2;td.xyear=y2;}else{y2=y-(5-Math.round(i*.5));td.firstChild.innerHTML=y2;td.xyear=y2;}
var yearDate=new Date(Date.parse(y2+'/1/1'));if(this.minDate&&this.maxDate){if(!yearDate.between(new Date(Date.parse(this.minDate.getFullYear()+'/1/1'))||yearDate,new Date(Date.parse(this.maxDate.getFullYear()+'/1/1'))||yearDate)){Ext.get(td).addClass('x-date-disabled');}else{Ext.get(td).removeClass('x-date-disabled');}}
this.mpYears.item(i-1)[y2==this.mpSelYear?'addClass':'removeClass']('x-date-mp-sel');}
if(this.minDate&&this.maxDate){this.mpMonths.each(function(m,a,i){i+=1;if(this.mpSelYear==this.maxDate.getFullYear()){if(m.dom.xmonth>this.maxDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else if(this.mpSelYear==this.minDate.getFullYear()){if(m.dom.xmonth<this.minDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else{m.removeClass('x-date-disabled');}},this);}},updateMPMonth:function(sm){this.mpMonths.each(function(m,a,i){m[m.dom.xmonth==sm?'addClass':'removeClass']('x-date-mp-sel');});},selectMPMonth:function(m){},getAdjustedDate:function(year,month){return new Date(year,month,this.useDayDate?(Math.min(this.useDayDate,(new Date(year,month,1)).getDaysInMonth())):(this.activeDate||this.value).getDate());},onMonthClick:function(e,t){e.stopEvent();if(!Ext.fly(t.parentNode).hasClass("x-date-disabled")){var el=new Ext.Element(t),pn;if(el.is('button.x-date-mp-cancel')){this.hideMonthPicker();}
else if(el.is('button.x-date-mp-ok')){this.update(this.getAdjustedDate(this.mpSelYear,this.mpSelMonth));this.fireEvent("select",this,this.value,this.oldValue);}
else if(pn=el.up('td.x-date-mp-month',2)){this.mpMonths.removeClass('x-date-mp-sel');pn.addClass('x-date-mp-sel');this.mpSelMonth=pn.dom.xmonth;}
else if(pn=el.up('td.x-date-mp-year',2)){this.mpYears.removeClass('x-date-mp-sel');pn.addClass('x-date-mp-sel');this.mpSelYear=pn.dom.xyear;if(this.minDate&&this.maxDate){this.mpMonths.removeClass('x-date-mp-sel');this.mpMonths.each(function(m,a,i){if(this.mpSelYear==this.maxDate.getFullYear()){if(m.dom.xmonth>this.maxDate.getMonth()){}else{m.addClass('x-date-mp-sel');this.mpSelMonth=m.dom.xmonth;return false;}}else if(this.mpSelYear==this.minDate.getFullYear()){if(m.dom.xmonth<this.minDate.getMonth()){}else{m.addClass('x-date-mp-sel');this.mpSelMonth=m.dom.xmonth;return false;}}else{m.addClass('x-date-mp-sel');this.mpSelMonth=m.dom.xmonth;return false;}},this);}}
else if(el.is('a.x-date-mp-prev')){this.updateMPYear(this.mpyear-10);}
else if(el.is('a.x-date-mp-next')){this.updateMPYear(this.mpyear+10);}
if(this.minDate&&this.maxDate){this.mpMonths.each(function(m,a,i){i+=1;if(this.mpSelYear==this.maxDate.getFullYear()){if(m.dom.xmonth>this.maxDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else if(this.mpSelYear==this.minDate.getFullYear()){if(m.dom.xmonth<this.minDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else{m.removeClass('x-date-disabled');}},this);}}},onMonthDblClick:function(e,t){e.stopEvent();if(!Ext.fly(t.parentNode).hasClass("x-date-disabled")){var el=new Ext.Element(t),pn;if(pn=el.up('td.x-date-mp-month',2)){this.update(this.getAdjustedDate(this.mpSelYear,pn.dom.xmonth));this.fireEvent("select",this,this.value,this.oldValue);}
else if(pn=el.up('td.x-date-mp-year',2)){this.update(this.getAdjustedDate(pn.dom.xyear,this.mpSelMonth));this.fireEvent("select",this,this.value,this.oldValue);}}},hideMonthPicker:function(disableAnim){Ext.menu.MenuMgr.hideAll();},showPrevMonth:function(e){this.update(this.activeDate.add("mo",-1));},showNextMonth:function(e){this.update(this.activeDate.add("mo",1));},showPrevYear:function(){this.update(this.activeDate.add("y",-1));},showNextYear:function(){this.update(this.activeDate.add("y",1));},update:function(date){this.activeDate=date;this.oldValue=this.value||date;this.value=date;if(!this.internalRender){var main=this.el.dom.firstChild;var w=main.offsetWidth;this.el.setWidth(w+this.el.getBorderWidth("lr"));Ext.fly(main).setWidth(w);this.internalRender=true;if(Ext.isOpera&&!this.secondPass){main.rows[0].cells[1].style.width=(w-(main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth))+"px";this.secondPass=true;this.update.defer(10,this,[date]);}}},setValue:function(date){if(date=='Invalid Date'){this.activeDate=null;this.value=null;}else{this.activeDate=date;this.value=date;}}});Ext.reg('ux.monthpicker',Ext.ux.MonthPicker);Ext.ux.MonthItem=function(config){Ext.ux.MonthItem.superclass.constructor.call(this,new Ext.ux.MonthPicker(config),config);this.picker=this.component;this.addEvents('select');this.picker.on("render",function(picker){picker.getEl().swallowEvent("click");picker.container.addClass("x-menu-date-item");});this.picker.on("select",this.onSelect,this,this.picker.value,this.picker.oldValue);};Ext.extend(Ext.ux.MonthItem,Ext.menu.Adapter,{onSelect:function(picker,date,value,oldValue){this.fireEvent("select",this,date,picker,value,oldValue);Ext.ux.MonthItem.superclass.handleClick.call(this);}});Ext.reg('ux.monthitem',Ext.ux.MonthItem);Ext.ux.MonthMenu=function(config){Ext.ux.MonthMenu.superclass.constructor.call(this,config);this.plain=true;var mi=new Ext.ux.MonthItem(config);this.add(mi);this.picker=mi.picker;this.relayEvents(mi,["select"]);};Ext.extend(Ext.ux.MonthMenu,Ext.menu.Menu,{cls:'x-date-menu',setDate:function(d){this.picker.setValue(d);},setMinDate:function(d){this.picker.minDate=d;},setMaxDate:function(d){this.picker.maxDate=d;}});Ext.reg('ux.monthmenu',Ext.ux.MonthMenu);Ext.ux.MonthField=function(config){Ext.ux.MonthField.superclass.constructor.call(this,config);}
Ext.extend(Ext.ux.MonthField,Ext.form.DateField,{format:Ext.ux.MonthPicker.prototype.format,noPastYears:Ext.ux.MonthPicker.prototype.noPastYears,noPastMonths:Ext.ux.MonthPicker.prototype.noPastMonths,useDayDate:Ext.ux.MonthPicker.prototype.useDayDate,onTriggerClick:function(){if(this.disabled){return;}
if(this.menu==null){this.menu=new Ext.ux.MonthMenu();}
Ext.apply(this.menu.picker,{format:this.format,noPastYears:this.noPastYears,noPastMonths:this.noPastMonths,useDayDate:this.useDayDate});this.menu.on(Ext.apply({},this.menuListeners,{scope:this}));this.menu.picker.setValue(this.getValue()||new Date());this.menu.show(this.el,"tl-bl?");}});Ext.reg('ux.monthfield',Ext.ux.MonthField);Ext.namespace('Ext.ux');Ext.ux.UploadForm=function(ct,config){var el;Ext.ux.UploadForm.superclass.constructor.call(this,el,config);Ext.QuickTips.init();this.addEvents({fileadded:true,fileremoved:true,clearqueue:true,startupload:true,stopupload:true,progress:true,uploadsuccess:true,uploadfailure:true});};Ext.extend(Ext.ux.UploadForm,Ext.form.BasicForm,{addText:'Add',buttonWidth:78,clearAllText:'Clear all',defaultAutoCreate:{tag:'form',enctype:'multipart/form-data'},fileCls:'file',maxFileSize:0,maxNameLength:18,pgEtaText:'Rem. time',pgSizeText:'Size/Total',pgSpeedAvgText:'Avg. speed',pgSpeedText:'Speed',stopText:'Stop',uploadProgressText:'Upload progress',uploadText:'Upload',width:200,zeroProgress:{bytes_uploaded:0,bytes_total:0,speed_last:0,speed_average:0,est_sec:0},init:function(ct)
{var autoCreate=true===this.autoCreate?this.defaultAutoCreate:'object'===typeof this.autoCreate?this.autoCreate:false;var el;if(this.detachForm)
{if(false===autoCreate)
{autoCreate=this.defaultAutoCreate;}
el=Ext.DomHelper.append(document.body,autoCreate);}else
{el=autoCreate?Ext.DomHelper.append(ct,autoCreate):ct;}
this.el=Ext.get(el);ct=Ext.get(ct);ct.setStyle('position','relative');this.container=ct;this.progressContainer=this.container;var wrap,showShadow;if(true===this.floating){wrap=this.container.wrap({tag:'div',cls:'x-uf-layer'});this.layer=new Ext.Layer({shadow:'sides'},wrap);this.layer.setWidth(this.width);this.container.addClass('x-uf-layer-form-ct');showShadow=function(){if(this.layer&&this.layer.isVisible()){this.layer.shadow.show(this.layer.dom);}}
this.on({fileadded:{scope:this,fn:showShadow},fileremoved:{scope:this,fn:showShadow},clearqueue:{scope:this,fn:showShadow}});}
this.inputs=new Ext.util.MixedCollection();this.iconPath=this.iconPath?this.iconPath:'lib/ext/resources/images/silk/icons';this.addIcon=this.addIcon?this.addIcon:'add.png';this.addIcon=this.iconPath+'/'+this.addIcon;this.deleteIcon=this.deleteIcon?this.deleteIcon:'delete.png';this.deleteIcon=this.iconPath+'/'+this.deleteIcon;this.uploadIcon=this.uploadIcon?this.uploadIcon:'arrow_up.png';this.uploadIcon=this.iconPath+'/'+this.uploadIcon;this.stopIcon=this.stopIcon?this.stopIcon:'control_stop.png';this.stopIcon=this.iconPath+'/'+this.stopIcon;this.clearIcon=this.clearIcon?this.clearIcon:'cross.png';this.clearIcon=this.iconPath+'/'+this.clearIcon;this.successIcon=this.successIcon?this.successIcon:'accept.png';this.successIcon=this.iconPath+'/'+this.successIcon;this.failureIcon=this.failureIcon?this.failureIcon:'exclamation.png';this.failureIcon=this.iconPath+'/'+this.failureIcon;if(this.maxFileSize){Ext.DomHelper.append(this.el,{tag:'input',type:'hidden',name:'MAX_FILE_SIZE',value:this.maxFileSize});}
if(this.pgCfg&&this.pgCfg.progressTarget){this.progressTarget=Ext.get(this.pgCfg.progressTarget);if(this.progressTarget){this.progressTarget.addClass('x-uf-pginfo-ct');}}
if(this.pgCfg&&this.pgCfg.uploadIdName){this.uploadId=Ext.DomHelper.append(this.el,{tag:'input',type:'hidden',name:this.pgCfg.uploadIdName,value:this.pgCfg.uploadIdValue});}
this.createButtons();this.createProgressInfo();this.createUploadInput(true);this.on({actioncomplete:{scope:this,fn:this.onSuccess},actionfailed:{scope:this,fn:this.onFailure}});},defaultProgressMap:{time_start:'time_start',time_last:'time_last',speed_average:'speed_average',speed_last:'speed_last',bytes_uploaded:'bytes_uploaded',bytes_total:'bytes_total',files_uploaded:'files_uploaded',est_sec:'est_sec'},appendRow:function(inp){var filename=inp.getValue();var o={id:inp.id,fileCls:this.getFileCls(filename),fileName:Ext.util.Format.ellipsis(filename.split(/[\/\\]/).pop(),this.maxNameLength),fileQtip:filename}
var t=new Ext.Template(['<tr id="r-{id}">','<td class="x-unselectable {fileCls} x-tree-node-leaf">','<img class="x-tree-node-icon" src="'+Ext.BLANK_IMAGE_URL+'">','<span class="x-uf-filename" unselectable="on" qtip="{fileQtip}">{fileName}</span>','</td>','<td id="m-{id}" class="x-uf-filedelete"><a id="d-{id}" href="#"><img src="'+this.deleteIcon+'"></a>','</td>','</tr>']);inp.row=t.append(this.tbody,o,true);},createButtons:function(){var ct=Ext.DomHelper.append(this.container,{tag:'div',cls:'x-uf-buttons-ct',children:[{tag:'div',cls:'x-uf-input-ct',children:[{tag:'div',cls:'x-uf-bbtn-ct',id:Ext.id()},{tag:'div',cls:'x-uf-input-wrap'}]},{tag:'div',cls:'x-uf-wait'},{tag:'div',cls:'x-uf-ubtn-ct'},{tag:'div',cls:'x-uf-cbtn-ct'}]},true);this.buttonsWrap=ct;if(this.width)
{}
this.buttonsWrap.enableDisplayMode();this.inputWrap=ct.select('div.x-uf-input-wrap').item(0);this.addBtnCt=ct.select('div.x-uf-input-ct').item(0);var bbtnCtComp=ct.select('div.x-uf-bbtn-ct')
var bbtnCt=bbtnCtComp.item(0);this.browseBtn=new Ext.Button({text:this.addText+'...',cls:'x-btn-text-icon',icon:this.addIcon,minWidth:this.buttonWidth});this.browseBtn.render(bbtnCt);var ubtnCt=ct.select('div.x-uf-ubtn-ct').item(0);this.ubtnCt=ubtnCt;if(!this.externalUploadBtn)
{this.uploadBtn=new Ext.Button({renderTo:ubtnCt,icon:this.uploadIcon,cls:'x-btn-icon',tooltip:this.uploadText,scope:this,handler:this.startUpload});}
if(!this.externalClearBtn&&(!this.fileLimit||this.fileLimit>1))
{var cbtnCt=ct.select('div.x-uf-cbtn-ct').item(0);this.cbtnCt=cbtnCt;this.clearBtn=new Ext.Button({renderTo:cbtnCt,icon:this.clearIcon,cls:'x-btn-icon',tooltip:this.clearAllText,scope:this,handler:this.clearQueue});}
this.waitIcon=ct.select('div.x-uf-wait').item(0);},createProgressInfo:function(){if(this.pgCfg&&true===this.pgCfg.progressBar){this.progressBar=this.createProgressBar();}
if(this.pgCfg){var pgInfoCreate={tag:'div',cls:'x-uf-pginfo-ct'};var pgTargetPos=this.pgCfg.progressTarget;pgTargetPos=('above'===pgTargetPos&&!wrap)?'under':pgTargetPos;if(this.pgCfg&&this.pgCfg.progressTarget&&!this.progressTarget){switch(pgTargetPos){case'under':case'below':this.progressTarget=Ext.DomHelper.append(this.container,pgInfoCreate,true);break;case'above':this.progressTarget=Ext.DomHelper.insertBefore(wrap,pgInfoCreate,true);break;}}}
this.updateProgress(0);},createUploadInput:function(silent){var id=Ext.id();var elemName=this.baseName||id;var inp=Ext.DomHelper.append(this.inputWrap,{tag:'input',type:'file',cls:'x-uf-input',size:1,id:id,name:elemName},true);inp.on('change',this.onFileAdded,this);this.inputs.add(inp);if(typeof silent=="undefined"||!silent)
{this.fireEvent('fileadded',this,id);}
return inp;},defaultProgressCallback:function(options,bSuccess,response){if(this.processingProgress){return;}
this.processingProgress=true;var o;try{o=Ext.decode(response.responseText)||{};}
catch(e){}
if(o&&true===o.success&&this.uploading){this.updateProgress(o);this.pgErrors=0;}
else{this.pgErrors=this.pgErrors||0;this.pgErrors++;if((this.pgCfg.maxPgErrors||10)<this.pgErrors){this.stopProgress();}}
this.processingProgress=false;},findIframe:function(){this.iframe=Ext.get(document.body).select('iframe.x-hidden').item(0);if(this.uploading&&!this.iframe){this.findIframe.defer(200,this);}},formatProgress:function(o){var ro={};var a=this.formatBytes(o.bytes_uploaded);ro.bytes_uploaded=a[0]+' '+a[1];a=this.formatBytes(o.bytes_total);ro.bytes_total=a[0]+' '+a[1];a=this.formatBytes(o.speed_last);ro.speed_last=a[0]+' '+a[1]+'/s';a=this.formatBytes(o.speed_average);ro.speed_average=a[0]+' '+a[1]+'/s';ro.est_sec=this.formatTime(o.est_sec);return(ro);},formatBytes:function(bytes){if(isNaN(bytes)){return['',''];}
var unit,val;if(999>bytes){unit='B';val=bytes;}
else if(999999>bytes){unit='kB';val=Math.round(bytes/1000);}
else if(999999999>bytes){unit='MB';val=Math.round(bytes/100000)/10;}
else if(999999999999>bytes){unit='GB';val=Math.round(bytes/100000000)/10;}
else{unit='TB';val=Math.round(bytes/100000000000)/10;}
return[val,unit];},formatTime:function(seconds){var s=0,m=0,h=0;if(3599<seconds){h=parseInt(seconds/3600);seconds-=h*3600;}
if(59<seconds){m=parseInt(seconds/60);seconds-=m*60;}
m=String.leftPad(m,2,0);h=String.leftPad(h,2,0);s=String.leftPad(seconds,2,0);return("00"!==h?h+':':'')+m+':'+s;},getFileCls:function(name){var atmp=name.split('.');if(1===atmp.length){return this.fileCls;}
else{return this.fileCls+'-'+atmp.pop();}},getProgressTemplate:function(){var tpl=new Ext.Template('<table class="x-uf-pginfo-table"><tbody>','<tr><td class="x-uf-pginfo-label">'+this.pgSizeText+':</td>','<td class="x-uf-pginfo-value">{bytes_uploaded}/{bytes_total}</td></tr>','<tr><td class="x-uf-pginfo-label">'+this.pgSpeedText+':</td>','<td class="x-uf-pginfo-value">{speed_last}</td></tr>','<tr><td class="x-uf-pginfo-label">'+this.pgSpeedAvgText+':</td>','<td class="x-uf-pginfo-value">{speed_average}</td></tr>','<tr><td class="x-uf-pginfo-label">'+this.pgEtaText+':</td>','<td class="x-uf-pginfo-value">{est_sec}</td></tr>','</tbody></table>');tpl.compile();return tpl;},hide:function(animEl){if(this.layer){this.layer.hide(animEl);}},onDeleteFile:function(e,target){this.removeFile(target.id.substr(2));},onFileAdded:function(e,inp){this.inputs.each(function(i){i.setDisplayed(false);});if(!this.table){this.table=Ext.DomHelper.append(this.container,{tag:'table',cls:'x-uf-table',children:[{tag:'tbody'}]},true);this.tbody=this.table.select('tbody').item(0);this.table.on({click:{scope:this,fn:this.onDeleteFile,delegate:'a'}});this.table.enableDisplayMode();}
var inp=this.inputs.itemAt(this.inputs.getCount()-1);inp.un('change',this.onFileAdded,this);if(this.detachForm)
{this.el.insertFirst(inp.dom);}
this.appendRow(inp);if(this.fileLimit&&this.fileLimit<this.inputs.length)
{this.removeFile(this.inputs.itemAt(0).id,true);}
this.createUploadInput();},onSuccess:function(form,action){this.processResponse(form,action);this.fireEvent("uploadsuccess",this);},onFailure:function(form,action){this.processResponse(form,action);this.fireEvent("uploadfailure",this);},processResponse:function(form,action){this.stopUpload();var json=action.response.responseText;var o=action.response.responseText?Ext.decode(json):{};this.inputs.each(function(inp){var msgTarget=Ext.get('m-'+inp.id);var resp=o;if(!o.errors||!o.errors[inp.id]){if(msgTarget){msgTarget.update('<img src="'+this.successIcon+'">');}
if(''!==inp.getValue()){inp.markRemove=true;}}else if(o.errors[inp.id])
{if(msgTarget){msgTarget.update('<img src="'+this.failureIcon+'"'
+' qtip="'+o.errors[inp.id]+'"'
+' qclass="x-form-invalid-tip"'
+' ext:width="200"'
+'>');}}},this);this.inputs.each(function(inp){if(true===inp.markRemove){this.removeFile(inp.id);}},this);this.files=o.files;},remapProgress:function(o){o=o||{};var map=this.pgCfg.map||this.defaultProgressMap;var p,onew={};for(p in map){onew[p]=o[map[p]]||''}
return onew;},clearQueue:function(){if(this.uploading){return;}
this.waitIcon.setDisplayed('none');this.updateProgress(0);this.inputs.each(function(inp){if(!inp.isVisible()){this.removeFile(inp.id,true);}},this);this.fireEvent('clearqueue',this);},removeFile:function(id,suppresEvent){if(this.uploading){return;}
var inp=this.inputs.get(id);if(inp&&inp.row){inp.row.remove();}
if(inp){inp.remove();}
this.inputs.removeKey(id);if(true!==suppresEvent){this.fireEvent('fileremoved',this,id);}},removeIframe:function(){if(this.iframe){this.iframe.remove();}},requestProgress:function(){var conn=new Ext.data.Connection().request(this.pgCfg.options);},setDisabled:function(disable,alsoUpload){if(disable){this.addBtnCt.mask();if(true===alsoUpload){this.ubtnCt.mask();}
if(this.cbtnCt)this.cbtnCt.mask();}
else{this.addBtnCt.unmask();this.ubtnCt.unmask();if(this.cbtnCt)this.cbtnCt.unmask();}},showAt:function(xy,animEl){if(this.layer){this.layer.setXY(xy);this.layer.show(animEl);}},startProgress:function(){var p=this.pgCfg
if(p){if(this.uploadId){if('auto'===p.uploadIdValue){this.uploadId.value=parseInt(Math.random()*1e10);}
p.options.params=p.options.params||{};p.options.params[p.uploadIdName]=this.uploadId.value;}
p.options.scope=p.options.scope||this;p.options.callback=p.options.callback||this.defaultProgressCallback;this.timerId=setInterval(this.requestProgress.createDelegate(this),p.interval||1000);}},startUpload:function(){if(this.isEmpty()){return;}
this.updateProgress(0);if(this.uploading){this.stopUpload();return;}
this.uploading=true;this.waitIcon.setDisplayed('block');this.startProgress();this.setDisabled(true);this.updateUploadBtn();this.submit({url:this.url});this.findIframe();this.fireEvent('startupload',this);},isEmpty:function()
{return(2>this.inputs.getCount());},stopProgress:function(){if(this.timerId){clearInterval(this.timerId);}},stopUpload:function(){if(this.iframe){try{this.iframe.dom.contentWindow.stop();this.removeIframe.defer(250,this);}
catch(e){}}
this.uploading=false;this.setDisabled(false);this.waitIcon.setDisplayed('none');this.stopProgress();this.updateProgress(1);this.updateUploadBtn();this.fireEvent('stopupload',this);},updateUploadBtn:function(){if(!this.externalUploadBtn)
{this.uploadBtn.setIcon(this.uploading?this.stopIcon:this.uploadIcon);this.uploadBtn.setQtip(this.uploading?this.stopText:this.uploadText);}},updateProgress:function(value){var o;if(0===value){o=Ext.apply({},this.zeroProgress);}
if(1===value&&this.lastPgObj){o=this.lastPgObj;o.bytes_uploaded=o.bytes_total;o.est_sec=0;}
if('object'===typeof value){o=this.remapProgress(value);value=o.bytes_total?o.bytes_uploaded/o.bytes_total:0;}
this.lastPgObj=o;var pp;if(this.progressBar){this.progressBar.updateProgress(value);}
if(this.progressTarget){this.getProgressTemplate().overwrite(this.progressTarget,this.formatProgress(o));}
else if(this.pgCfg&&'qtip'===this.pgCfg.progressTarget&&this.progressBar){Ext.QuickTips.tips({target:this.progressBar,title:this.uploadProgressText,text:this.getProgressTemplate().apply(this.formatProgress(o)),width:160,autoHide:true});Ext.QuickTips.enable();}
this.fireEvent('progress',this,o,value);},createProgressBar:function()
{return new Ext.ux.ProgressBar(this.progressContainer);}});Ext.ux.ProgressBar=function(container,config)
{config=config||{};var wrapConfig={tag:'div',cls:'x-uf-progress-wrap',children:[{tag:'div',cls:'x-uf-progress',children:[{tag:'div',cls:'x-uf-progress-bar'}]}]};this.wrap=Ext.DomHelper.append(container,wrapConfig,true);this.progressBarElem=this.wrap.select('div.x-uf-progress-bar').item(0);if(config.progressLabel)
{this.label=Ext.DomHelper.insertBefore(this.wrap,{tag:'div',cls:'x-uf-progress-label',children:[{html:config.progressLabel}]},true);}
this.updateProgress=function(value)
{var pp=Ext.get(this.progressBarElem.dom.parentNode);this.progressBarElem.setWidth(Math.floor(value*pp.dom.offsetWidth));};this.toggle=function()
{this.wrap.toggle();if(this.label)
{this.label.toggle();}}};Ext.namespace('Ext.ux');Ext.ux.MonthPicker=function(config){Ext.apply(this,config);Ext.ux.MonthPicker.superclass.constructor.call(this);};Ext.ux.MonthPicker=Ext.extend(Ext.Component,{format:"M, Y",okText:Ext.MessageBox.buttonText.ok,cancelText:Ext.MessageBox.buttonText.cancel,constrainToViewport:true,monthNames:Date.monthNames,startDay:0,minDate:null,maxDate:null,value:0,noPastYears:false,noPastMonths:false,useDayDate:null,initComponent:function(){Ext.ux.MonthPicker.superclass.initComponent.call(this);this.value=this.value?this.value.clearTime():new Date().clearTime();this.activeDate=this.value;this.addEvents('select');if(this.handler){this.on("select",this.handler,this.scope||this);}},focus:function(){if(this.el){this.update(this.activeDate);}},onRender:function(container,position){var m=['<div style="width: 175px; height:175px;"></div>']
m[m.length]='<div class="x-date-mp"></div>';var el=document.createElement("div");el.className="x-date-picker";el.innerHTML=m.join("");container.dom.insertBefore(el,position);this.el=Ext.get(el);this.monthPicker=this.el.down('div.x-date-mp');this.monthPicker.enableDisplayMode('block');this.el.unselectable();this.showMonthPicker();if(Ext.isIE){this.el.repaint();}
this.update(this.value);},createMonthPicker:function(){var minMonth=-1;if(this.noPastMonths){minMonth=new Date().getMonth();}
if(!this.monthPicker.dom.firstChild){var buf=['<table border="0" cellspacing="0">'];for(var i=0;i<6;i++){buf.push('<tr><td class="x-date-mp-month'+(i<minMonth?' x-date-disabled':'')+'"><a href="#">',this.monthNames[i].substr(0,3),'</a></td>','<td class="x-date-mp-month x-date-mp-sep"><a href="#">',this.monthNames[i+6].substr(0,3),'</a></td>',i==0?'<td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-prev"></a></td><td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-next"></a></td></tr>':'<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>');}
buf.push('<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',this.okText,'</button><button type="button" class="x-date-mp-cancel">',this.cancelText,'</button></td></tr>','</table>');this.monthPicker.update(buf.join(''));this.monthPicker.on('click',this.onMonthClick,this);this.monthPicker.on('dblclick',this.onMonthDblClick,this);this.mpMonths=this.monthPicker.select('td.x-date-mp-month');this.mpYears=this.monthPicker.select('td.x-date-mp-year');this.mpMonths.each(function(m,a,i){i+=1;if((i%2)==0){m.dom.xmonth=5+Math.round(i*.5);}else{m.dom.xmonth=Math.round((i-1)*.5);}});}},showMonthPicker:function(){this.createMonthPicker();var size=this.el.getSize();this.monthPicker.setSize(size);this.monthPicker.child('table').setSize(size);this.mpSelMonth=(this.activeDate||this.value).getMonth();this.updateMPMonth(this.mpSelMonth);this.mpSelYear=(this.activeDate||this.value).getFullYear();this.updateMPYear(this.mpSelYear);this.monthPicker.show();},updateMonthPicker:function(){if((this.activeDate&&!isNaN(this.activeDate.getElapsed()))||(this.value&&!isNaN(this.value.getElapsed))){this.mpSelMonth=(this.activeDate||this.value||new Date()).getMonth();this.updateMPMonth(this.mpSelMonth);this.mpSelYear=(this.activeDate||this.value||new Date()).getFullYear();this.updateMPYear(this.mpSelYear);}},updateMPYear:function(y){if(this.noPastYears){var minYear=new Date().getFullYear();if(y<(minYear+4)){y=minYear+4;}}
this.mpyear=y;var ys=this.mpYears.elements;for(var i=1;i<=10;i++){var td=ys[i-1],y2;if((i%2)==0){y2=y+Math.round(i*.5);td.firstChild.innerHTML=y2;td.xyear=y2;}else{y2=y-(5-Math.round(i*.5));td.firstChild.innerHTML=y2;td.xyear=y2;}
var yearDate=new Date(Date.parse(y2+'/1/1'));if(this.minDate&&this.maxDate){if(!yearDate.between(new Date(Date.parse(this.minDate.getFullYear()+'/1/1'))||yearDate,new Date(Date.parse(this.maxDate.getFullYear()+'/1/1'))||yearDate)){Ext.get(td).addClass('x-date-disabled');}else{Ext.get(td).removeClass('x-date-disabled');}}
this.mpYears.item(i-1)[y2==this.mpSelYear?'addClass':'removeClass']('x-date-mp-sel');}
if(this.minDate&&this.maxDate){this.mpMonths.each(function(m,a,i){i+=1;if(this.mpSelYear==this.maxDate.getFullYear()){if(m.dom.xmonth>this.maxDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else if(this.mpSelYear==this.minDate.getFullYear()){if(m.dom.xmonth<this.minDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else{m.removeClass('x-date-disabled');}},this);}},updateMPMonth:function(sm){this.mpMonths.each(function(m,a,i){m[m.dom.xmonth==sm?'addClass':'removeClass']('x-date-mp-sel');});},selectMPMonth:function(m){},getAdjustedDate:function(year,month){return new Date(year,month,this.useDayDate?(Math.min(this.useDayDate,(new Date(year,month,1)).getDaysInMonth())):(this.activeDate||this.value).getDate());},onMonthClick:function(e,t){e.stopEvent();if(!Ext.fly(t.parentNode).hasClass("x-date-disabled")){var el=new Ext.Element(t),pn;if(el.is('button.x-date-mp-cancel')){this.hideMonthPicker();}
else if(el.is('button.x-date-mp-ok')){this.update(this.getAdjustedDate(this.mpSelYear,this.mpSelMonth));this.fireEvent("select",this,this.value,this.oldValue);}
else if(pn=el.up('td.x-date-mp-month',2)){this.mpMonths.removeClass('x-date-mp-sel');pn.addClass('x-date-mp-sel');this.mpSelMonth=pn.dom.xmonth;}
else if(pn=el.up('td.x-date-mp-year',2)){this.mpYears.removeClass('x-date-mp-sel');pn.addClass('x-date-mp-sel');this.mpSelYear=pn.dom.xyear;if(this.minDate&&this.maxDate){this.mpMonths.removeClass('x-date-mp-sel');this.mpMonths.each(function(m,a,i){if(this.mpSelYear==this.maxDate.getFullYear()){if(m.dom.xmonth>this.maxDate.getMonth()){}else{m.addClass('x-date-mp-sel');this.mpSelMonth=m.dom.xmonth;return false;}}else if(this.mpSelYear==this.minDate.getFullYear()){if(m.dom.xmonth<this.minDate.getMonth()){}else{m.addClass('x-date-mp-sel');this.mpSelMonth=m.dom.xmonth;return false;}}else{m.addClass('x-date-mp-sel');this.mpSelMonth=m.dom.xmonth;return false;}},this);}}
else if(el.is('a.x-date-mp-prev')){this.updateMPYear(this.mpyear-10);}
else if(el.is('a.x-date-mp-next')){this.updateMPYear(this.mpyear+10);}
if(this.minDate&&this.maxDate){this.mpMonths.each(function(m,a,i){i+=1;if(this.mpSelYear==this.maxDate.getFullYear()){if(m.dom.xmonth>this.maxDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else if(this.mpSelYear==this.minDate.getFullYear()){if(m.dom.xmonth<this.minDate.getMonth()){m.addClass('x-date-disabled')}else{m.removeClass('x-date-disabled');}}else{m.removeClass('x-date-disabled');}},this);}}},onMonthDblClick:function(e,t){e.stopEvent();if(!Ext.fly(t.parentNode).hasClass("x-date-disabled")){var el=new Ext.Element(t),pn;if(pn=el.up('td.x-date-mp-month',2)){this.update(this.getAdjustedDate(this.mpSelYear,pn.dom.xmonth));this.fireEvent("select",this,this.value,this.oldValue);}
else if(pn=el.up('td.x-date-mp-year',2)){this.update(this.getAdjustedDate(pn.dom.xyear,this.mpSelMonth));this.fireEvent("select",this,this.value,this.oldValue);}}},hideMonthPicker:function(disableAnim){Ext.menu.MenuMgr.hideAll();},showPrevMonth:function(e){this.update(this.activeDate.add("mo",-1));},showNextMonth:function(e){this.update(this.activeDate.add("mo",1));},showPrevYear:function(){this.update(this.activeDate.add("y",-1));},showNextYear:function(){this.update(this.activeDate.add("y",1));},update:function(date){this.activeDate=date;this.oldValue=this.value||date;this.value=date;if(!this.internalRender){var main=this.el.dom.firstChild;var w=main.offsetWidth;this.el.setWidth(w+this.el.getBorderWidth("lr"));Ext.fly(main).setWidth(w);this.internalRender=true;if(Ext.isOpera&&!this.secondPass){main.rows[0].cells[1].style.width=(w-(main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth))+"px";this.secondPass=true;this.update.defer(10,this,[date]);}}},setValue:function(date){if(date=='Invalid Date'){this.activeDate=null;this.value=null;}else{this.activeDate=date;this.value=date;}}});Ext.reg('ux.monthpicker',Ext.ux.MonthPicker);Ext.ux.MonthItem=function(config){Ext.ux.MonthItem.superclass.constructor.call(this,new Ext.ux.MonthPicker(config),config);this.picker=this.component;this.addEvents('select');this.picker.on("render",function(picker){picker.getEl().swallowEvent("click");picker.container.addClass("x-menu-date-item");});this.picker.on("select",this.onSelect,this,this.picker.value,this.picker.oldValue);};Ext.extend(Ext.ux.MonthItem,Ext.menu.Adapter,{onSelect:function(picker,date,value,oldValue){this.fireEvent("select",this,date,picker,value,oldValue);Ext.ux.MonthItem.superclass.handleClick.call(this);}});Ext.reg('ux.monthitem',Ext.ux.MonthItem);Ext.ux.MonthMenu=function(config){Ext.ux.MonthMenu.superclass.constructor.call(this,config);this.plain=true;var mi=new Ext.ux.MonthItem(config);this.add(mi);this.picker=mi.picker;this.relayEvents(mi,["select"]);};Ext.extend(Ext.ux.MonthMenu,Ext.menu.Menu,{cls:'x-date-menu',setDate:function(d){this.picker.setValue(d);},setMinDate:function(d){this.picker.minDate=d;},setMaxDate:function(d){this.picker.maxDate=d;}});Ext.reg('ux.monthmenu',Ext.ux.MonthMenu);Ext.ux.MonthField=function(config){Ext.ux.MonthField.superclass.constructor.call(this,config);}
Ext.extend(Ext.ux.MonthField,Ext.form.DateField,{format:Ext.ux.MonthPicker.prototype.format,noPastYears:Ext.ux.MonthPicker.prototype.noPastYears,noPastMonths:Ext.ux.MonthPicker.prototype.noPastMonths,useDayDate:Ext.ux.MonthPicker.prototype.useDayDate,onTriggerClick:function(){if(this.disabled){return;}
if(this.menu==null){this.menu=new Ext.ux.MonthMenu();}
Ext.apply(this.menu.picker,{format:this.format,noPastYears:this.noPastYears,noPastMonths:this.noPastMonths,useDayDate:this.useDayDate});this.menu.on(Ext.apply({},this.menuListeners,{scope:this}));this.menu.picker.setValue(this.getValue()||new Date());this.menu.show(this.el,"tl-bl?");}});Ext.reg('ux.monthfield',Ext.ux.MonthField);