
ClientUILib.declarePackage("ClientUI.controls.grid.DataModel");ClientUI.controls.grid.DataModel=Class.create({initialize:function(){},getRow:function(index){return[];},getCount:function(){return 0;},loadRows:function(options){this.eventDataReady.fire(options);},getRequestDelay:function(){return 1000;}});ClientUILib.declarePackage("ClientUI.controls.grid.ArrayDataModel");ClientUILib.requireClass("ClientUI.controls.grid.DataModel");ClientUI.controls.grid.ArrayDataModel=Class.create(ClientUI.controls.grid.DataModel,{initialize:function($super,data){$super();this.data=$A(data||[]);},getRow:function(index){return this.data[index];},getCount:function(){return this.data.length;},getRequestDelay:function(){return 50;}});ClientUILib.declarePackage("ClientUI.controls.grid.FakeArrayDataModel ");ClientUI.controls.grid.FakeArrayDataModel=Class.create(ClientUI.controls.grid.DataModel,{initialize:function($super,rows_count,columns_count,grid_id){$super();this.data=[];this.count=rows_count;this.columns=columns_count;this.gridId=grid_id;this.curr_options;},getRow:function(index){if(!this.data[index]){this.data[index]=[];for(var index2=0;index2<7;index2++){this.data[index][index2]=index2+" : "+index;}
this.data[index][6]=index%2?"value 1":"value 2";}
return this.data[index];},getCount:function(){return this.count;},getRequestDelay:function(){return 150;},getCurrentOptions:function(){if(!this.curr_options){this.curr_options={count:grid.getBody().templFrozen.getElement().rows.length,index:0,startRow:0}}
return this.curr_options;},loadRows:function(options){window.loadingStartTime=(new Date()).getTime();var state_options=options;var state_input=$(this.gridId+"_state_input");var submit_input=$(this.gridId+"_submit_input");var submit_values=state_options.count+","+state_options.index+","+state_options.startRow;state_input.value=submit_values;this.curr_options=options;submit_input.click();}});ClientUILib.declarePackage("ClientUI.layouts.LayoutManager");ClientUI.layouts.LayoutManager=Class.create(ClientUI.common.box.Box,{initialize:function($super,element,parentElement){$super(element,parentElement);this.container=parentElement;if(this.container)
this.container=new ClientUI.common.box.Box($(this.container));this.eventContainerResize=this.containerResize.bindAsEventListener(this);this.registerEvents();},registerEvents:function(){Event.observe(window,"resize",this.eventContainerResize);},destroy:function(){Event.stopObserving(window,"resize",this.eventContainerResize);},containerResize:function(event){this.updateLayout();},updateLayout:function($super){if(this.container){var w=this.container.getWidth();var h=this.container.element.offsetHeight;if(ClientUILib.isGecko){w-=this.container.getBorderWidth("lr")+this.container.getPadding("lr");h-=this.container.getBorderWidth("tb")+this.container.getPadding("tb");}
this.setWidth(w);this.setHeight(h);}
$super();},getContainer:function(){return this.container;}});ClientUILib.declarePackage("ClientUI.layouts.VLayoutManager");ClientUILib.requireClass("ClientUI.common.box.Box");ClientUILib.requireClass("ClientUI.layouts.LayoutManager");var GridLayout_Enum={HEADER:1,BODY:2,FOOTER:3};ClientUI.layouts.VLayoutManager=Class.create(ClientUI.layouts.LayoutManager,{initialize:function($super,element,parentElement,config){$super(element,parentElement);this.registerEvents();},registerEvents:function($super){$super();},destroy:function($super){$super();},addPane:function(align,pane){if(!this.panels){this.panels=[];}
this.panels[align]=pane;this.panels[align].makeAbsolute();},getPane:function(align){return this.panels[align];},updateLayout:function($super){$super();var parentBox=this.getContainer();if(!parentBox)parentBox=this;var height=parentBox.element.offsetHeight;var width=parentBox.getViewportWidth();if(ClientUILib.isGecko){width-=parentBox.getBorderWidth("lr")+parentBox.getPadding("lr");height-=parentBox.getBorderWidth("tb")+parentBox.getPadding("tb");}
if(this.panels){var headerHeight=0;var footerHeight=0;if(this.panels[GridLayout_Enum.HEADER]){headerHeight=this.panels[GridLayout_Enum.HEADER].element.offsetHeight;this.panels[GridLayout_Enum.HEADER].moveTo(0,0);this.panels[GridLayout_Enum.HEADER].setWidth(width);this.panels[GridLayout_Enum.HEADER].updateLayout();}
if(this.panels[GridLayout_Enum.FOOTER]){footerHeight=this.panels[GridLayout_Enum.FOOTER].element.offsetHeight;this.panels[GridLayout_Enum.FOOTER].moveTo(0,height-footerHeight);this.panels[GridLayout_Enum.FOOTER].setWidth(width);this.panels[GridLayout_Enum.FOOTER].updateLayout();}
if(this.panels[GridLayout_Enum.BODY]){var body=this.panels[GridLayout_Enum.BODY];body.setWidth(width);var bodyHeight=height-(headerHeight+footerHeight);body.setHeight(bodyHeight);body.moveTo(0,headerHeight);body.updateLayout();}}}});if(!ClientUI_layouts_VLayoutManager_idGenerator){var ClientUI_layouts_VLayoutManager_idGenerator=0;};ClientUILib.declarePackage("ClientUI.layouts.GridLayoutManager");ClientUILib.requireClass("ClientUI.common.box.Box");ClientUILib.requireClass("ClientUI.layouts.VLayoutManager");ClientUILib.requireClass("ClientUI.layouts.LayoutManager");var GridLayout_Enum={HEADER:1,BODY:2,FOOTER:3};ClientUI.layouts.GridLayoutManager=Class.create(ClientUI.layouts.VLayoutManager,{initialize:function($super,element,parentElement,config){$super(element,parentElement);},updateLayout:function(){ClientUI.layouts.LayoutManager.prototype.updateLayout.call(this);var parentBox=this.getContainer();if(parentBox==null)parentBox=this;var height=parentBox.element.offsetHeight;var width=parentBox.getViewportWidth();if(this.panels){var headerHeight=0;var footerHeight=0;var bodyBottom=0;if(this.panels[GridLayout_Enum.HEADER]){headerHeight=this.panels[GridLayout_Enum.HEADER].element.offsetHeight;this.panels[GridLayout_Enum.HEADER].moveTo(0,0);this.panels[GridLayout_Enum.HEADER].setWidth(width);this.panels[GridLayout_Enum.HEADER].updateLayout();}
if(this.panels[GridLayout_Enum.BODY]){var body=this.panels[GridLayout_Enum.BODY];body.setWidth(width);var bodyHeight=height-headerHeight;body.setHeight(bodyHeight);body.moveTo(0,headerHeight);body.updateLayout();bodyBottom=body.getY()+body.contentBox.getY()+body.scrollBox.getViewportHeight();}
if(this.panels[GridLayout_Enum.FOOTER]){footerHeight=this.panels[GridLayout_Enum.FOOTER].element.offsetHeight;this.panels[GridLayout_Enum.FOOTER].moveTo(0,bodyBottom-footerHeight);this.panels[GridLayout_Enum.FOOTER].setWidth(width);this.panels[GridLayout_Enum.FOOTER].updateLayout();}}}});ClientUILib.declarePackage("ClientUI.controls.grid.GridHeader");ClientUILib.requireClass("ClientUI.common.box.Box");ClientUILib.requireClass("ClientUI.common.box.InlineBox");ClientUI.controls.grid.GridHeader=Class.create(ClientUI.common.box.Box,{initialize:function($super,template,grid){this.grid=grid;this.gridId=this.grid.getElement().id;this.normalizedId=this.grid.options.normalizedId;$super(template);this.eventSepClick=this.OnSepClick.bindAsEventListener(this);this.eventSepMouseDown=this.OnSepMouseDown.bindAsEventListener(this);this.eventSepMouseUp=this.OnSepMouseUp.bindAsEventListener(this);this.eventSepMouseMove=this.OnSepMouseMove.bindAsEventListener(this);this.eventCellMouseDown=this.OnCellMouseDown.bindAsEventListener(this);Event.observe(document,'mousemove',this.eventSepMouseMove,true);Event.observe(document,'mouseup',this.eventSepMouseUp,true);this.createControl(template);},createControl:function(template){var errMsg="";if(!template){errMsg="Invalid template specified for GridHeader.";ClientUILib.log(ClientUILogger.ERROR,errMsg);throw(errMsg);}
if(!this.parseTemplate(template)){errMsg="Unable to parse template. GridHeader requires template specified over table element with one row.";ClientUILib.log(ClientUILogger.ERROR,errMsg);throw(errMsg);}
this.controlCreated=true;this.agjustSeparators();},parseTemplate:function(template){if(!template){return false;}
var childs=template.childNodes;for(var i=0;i<childs.length;i++){if(childs[i].tagName&&childs[i].tagName.toLowerCase()=="div"){this.container=$(childs[i]);this.container.setStyle({"z-index":100});break;}}
var normal=null,frozen=null;var childs=this.container.childNodes;for(var i=0;i<childs.length;i++){if(childs[i].id&&childs[i].id.indexOf("FrozenBox")>=0){frozen=childs[i];}
else if(childs[i].id&&childs[i].id.indexOf("NormalBox")>=0){normal=childs[i];}}
if(!normal||!frozen){errMsg="Unable to parse template for GridHeader. Unable to find FrozenBox or NormalBox.";ClientUILib.log(ClientUILogger.ERROR,errMsg);throw(errMsg);}
this.contentBox=new ClientUI.common.box.Box(normal);this.frozenContentBox=new ClientUI.common.box.Box(frozen);var ch=this.contentBox.getElement().firstChild;while(ch){if(ch.tagName&&ch.tagName.toLowerCase()=="table"){this.headerRow=new ClientUI.common.box.Box($(ch),null,true);break;}
ch=ch.nextSibling;}
ch=this.frozenContentBox.getElement().firstChild;while(ch){if(ch.tagName&&ch.tagName.toLowerCase()=="table"){this.headerFrozenRow=new ClientUI.common.box.Box($(ch),null,true);break;}
ch=ch.nextSibling;}
this.helpObj=new ClientUI.common.box.Box(this.frozenContentBox.getElement(),null,true);var rows=this.headerFrozenRow.getElement().rows;var fcount=(rows.length&&rows[0].cells.length&&rows[0].cells[0].innerHTML)?rows[0].cells.length:0;var ncount=this.headerRow.getElement().rows[0].cells.length;var columns=new Array(fcount+ncount);var eventCellMouseDown=this.eventCellMouseDown.bind(this);var i=0,j=0,cell;this.frozenCells=fcount?this.headerFrozenRow.getElement().rows[0].cells:[];var ids=this.grid.options.ids;var count=this.frozenCells.length;for(i=0;i<count;i++){cell=this.frozenCells[i];columns[j]={columnId:ids[i],styleClass:cell.className,id:cell.id,align:cell.align,valign:cell.vAlign,title:cell.title,minWidth:10,frozen:true,fixedWidth:Validators.getBoolean(cell.getAttribute("fixedWidth"),false),sortable:Validators.getBoolean(cell.getAttribute("sortable"),false),sorted:Validators.getBoolean(cell.getAttribute("sorted"),"desc"),style:Utils.getRule("#"+this.normalizedId+" .dr-sdt-c-"+j).style};if(columns[j].sortable)
Event.observe(cell,'click',eventCellMouseDown);columns[j].object=new ClientUI.common.box.InlineBox(cell,null,true);var details=this._getCellElements(j);columns[j].sep=new ClientUI.common.box.InlineBox(details[0],null,true);columns[j].sep.getElement().columnIndex=j;if(!columns[j].fixedWidth){Event.observe(columns[j].sep.getElement(),'click',this.eventSepClick);Event.observe(columns[j].sep.getElement(),'mousedown',this.eventSepMouseDown);}
else{sep.setStyle({cursor:'auto'});}
j++;}
this.cells=this.headerRow.getElement().rows[0].cells;count=this.cells.length;for(i=0;i<count;i++){cell=this.cells[i];columns[j]={columnId:ids[i],styleClass:cell.className,id:cell.id,align:cell.align,valign:cell.vAlign,title:cell.title,minWidth:10,frozen:false,fixedWidth:Validators.getBoolean(cell.getAttribute("fixedWidth"),false),sortable:Validators.getBoolean(cell.getAttribute("sortable"),false),sorted:null,style:Utils.getRule("#"+this.normalizedId+" .dr-sdt-c-"+((i<count-1)?j:"f")).style};if(columns[j].sortable)
Event.observe(cell,'click',eventCellMouseDown);columns[j].object=new ClientUI.common.box.InlineBox(cell,null,true);var details=this._getCellElements(j);if(details[0]){columns[j].sep=new ClientUI.common.box.InlineBox(details[0],null,true);columns[j].sep.getElement().columnIndex=j;if(!columns[j].fixedWidth){Event.observe(columns[j].sep.getElement(),'click',this.eventSepClick);Event.observe(columns[j].sep.getElement(),'mousedown',this.eventSepMouseDown);}
else{sep.setStyle({cursor:'auto'});}}
j++;}
this._columns=columns;this.frozenSubstrate=new ClientUI.common.box.Box(this.gridId+":hs",this.getElement());this.frozenSubstrate.getElement().name=this.getElement().id+"HRFrm";this.frozenSubstrate.setHeight(this.headerRow.element.offsetHeight);return true;},_getCellElements:function(column){var details=new Array(3);var clientId=this.grid.getElement().id;details[0]=$(clientId+":hsep_"+column);details[1]=$(clientId+":hs_"+column);return details;},agjustSeparators:function(){var i=0;var length=this.frozenCells.length;var delta=4;if(this.cells[0].offsetWidth==this.cells[0].clientWidth){delta--;}
for(var j=0;j<length;i++,j++){this._columns[i].sep.moveToX(this.frozenCells[j].offsetLeft+this.frozenCells[j].offsetWidth-delta);}
var length=this.cells.length-1;for(var j=0;j<length;i++,j++){this._columns[i].sep.moveToX(this.cells[j].offsetLeft+this.cells[j].offsetWidth-delta);}},updateSize:function(){this.setHeight(this.headerRow.element.offsetHeight);this.agjustSeparators();this.updateHeaders();},updateLayout:function($super){if(!this.controlCreated||!this.grid.controlCreated){return;}
$super();var height=this.element.offsetHeight;var frozenContentWidth=this.frozenContentBox.getElement().offsetWidth;this.contentBox.setHeight(height);this.contentBox.moveTo(frozenContentWidth-this.grid.getScrollOffset(),0);this.headerRow.setHeight(height);this.frozenContentBox.setHeight(height);this.frozenContentBox.moveTo(0,0);this.headerFrozenRow.setHeight(height);this.frozenSubstrate.setWidth(frozenContentWidth);this.updateHeaders();},getColumns:function(){return this._columns;},OnSepMouseDown:function(event){this.dragColumnInfo={srcElement:Event.element(event),dragStarted:false,mouseDown:true,startX:Event.pointerX(event),originalX:0};this.dragColumnInfo.object=this.getColumns()[this.dragColumnInfo.srcElement.columnIndex].object;this.dragColumnInfo.sep=this.getColumns()[this.dragColumnInfo.srcElement.columnIndex].sep;this.dragColumnInfo.minWidth=this.getColumns()[this.dragColumnInfo.srcElement.columnIndex].minWidth;Event.stop(event);},OnSepMouseUp:function(event){if(this.dragColumnInfo&&this.dragColumnInfo.dragStarted){this.dragColumnInfo.dragStarted=false;this.dragColumnInfo.mouseDown=false;var delta=Event.pointerX(event)-this.dragColumnInfo.startX;var newWidth=this.dragColumnInfo.object.getWidth()+delta;if(newWidth<this.dragColumnInfo.minWidth){newWidth=this.dragColumnInfo.minWidth;}
setTimeout(function(){this.grid.adjustColumnWidth(this.dragColumnInfo.srcElement.columnIndex,newWidth);}.bind(this),10);}
this._hideSplitter();},OnSepMouseMove:function(event){if(this.dragColumnInfo&&this.dragColumnInfo.mouseDown){if(!this.dragColumnInfo.dragStarted){this.dragColumnInfo.dragStarted=true;this._showSplitter(this.dragColumnInfo.srcElement.columnIndex);}
else{var delta=Event.pointerX(event)-this.dragColumnInfo.startX;var minColumnWidth=this.dragColumnInfo.object.getWidth()-this.dragColumnInfo.minWidth;if(delta>=-minColumnWidth){var x=this.dragColumnInfo.originalX+delta;this.columnSplitter.moveToX(x-6);}}
Event.stop(event);}},OnSepClick:function(event){Event.stop(event);},_showSplitter:function(index){if(!this.columnSplitter){this._createSplitter();}
var pos=this.dragColumnInfo.sep.getX();if(!this.getColumns()[index].frozen){pos+=this.frozenContentBox.getElement().offsetWidth-this.grid.getScrollOffset();}
this.dragColumnInfo.originalX=pos;this.columnSplitter.show();this.columnSplitter.setHeight(this.headerRow.element.offsetHeight+this.grid.getBody().contentBox.element.offsetHeight);this.columnSplitter.moveTo(pos,0);},_hideSplitter:function(){if(this.columnSplitter){this.columnSplitter.hide();}},_createSplitter:function(){this.columnSplitter=new ClientUI.common.box.Box(this.gridId+":cs",this.grid.getElement());this.columnSplitter.makeAbsolute();this.columnSplitter.setWidth(10);},adjustScrollPosition:function(pos){this.contentBox.moveToX(this.frozenContentBox.getElement().offsetWidth-pos);},OnCellMouseDown:function(event){var el=Event.element(event);while(el&&!Element.hasClassName(el,"dr-sdt-hc")){el=el.parentNode;}
if(el){var sortColumnId=el.getAttribute("columnid");if(sortColumnId){var rows=this.grid.getBody().templFrozen.getElement().rows;var startRow=rows&&rows.length>0?this.grid.getBody()._getRowIndex(rows[0].id):0;this.grid.element.fire("grid:onsort",{column:sortColumnId,startRow:startRow,index:this.grid.getBody().currRange.start});Event.stop(event);}}},updateHeaders:function(){var length=this.frozenCells.length;var posX=0;for(var j=0;j<length;j++){posX=this.updateHeader(posX,this.frozenCells[j]);}
length=this.cells.length-1;posX=0;for(var j=0;j<length;j++){posX=this.updateHeader(posX,this.cells[j]);}},updateHeader:function(posX,th){var icon=$(this.gridId+":hs_"+th.id.split("_").last());posX+=th.offsetWidth;if(icon){var newPosX=posX-icon.getWidth();var newPosY=(th.clientHeight-icon.offsetHeight)/2;newPosX=Math.floor(newPosX);newPosY=Math.floor(newPosY);icon.setStyle({left:newPosX+"px",top:newPosY+"px",visibility:"inherit"});}
return posX;},adjustColumnWidth:function(column,width){this._columns[column].style.width=width+"px";if(width<=0)this.getColumns()[column].sep.hide();},resetFakeColumnWidth:function(){this._columns.last().style.width="0px";},setFakeColumnWidth:function(){var width=this.grid.getBody().container.element.clientWidth-this.headerFrozenRow.getElement().offsetWidth-this.headerRow.getElement().offsetWidth;if(width<0){width=0;}
this._columns.last().style.width=width+"px";},hideColumn:function(index,frozen){var column=this._columns.splice(index,1)[0];var input=$(this.grid.getElement().id+"_hc")
input.value=input.value+column.columnId+",";column.col.parentNode.removeChild(column.col);column.bodyCol.parentNode.removeChild(column.bodyCol);column.footerCol.parentNode.removeChild(column.footerCol);var rows;if(frozen){rows=this.headerFrozenRow.getElement().rows;}else{rows=this.headerRow.getElement().rows;}
for(var i=0;i<rows.length;i++){rows[i].removeChild(rows[i].cells[index]);}}});Object.extend(ClientUI.controls.grid.GridHeader.prototype,{sepStyleClass:"dr-sdt-hsep",_columns:[]});ClientUILib.declarePackage("ClientUI.controls.grid.DataCash");ClientUI.controls.grid.DataCash=Class.create({initialize:function(cashSize){var count=parseInt(cashSize/this.PKG_SIZE+1);this.cash=new Array(count);for(var i=0;i<count;i++){this.cash[i]=new Array(this.PKG_SIZE);}},getRow:function(index){var i=parseInt(index/this.PKG_SIZE),j=index%this.PKG_SIZE;return this.cash[i][j];},setRow:function(index,row){var i=parseInt(index/this.PKG_SIZE),j=index%this.PKG_SIZE;this.cash[i][j]=row;}});Object.extend(ClientUI.controls.grid.DataCash.prototype,{PKG_SIZE:20});ClientUILib.declarePackage("ClientUI.controls.grid.GridBody");ClientUILib.requireClass("ClientUI.common.box.Box");ClientUI.controls.grid.GridBody=Class.create(ClientUI.common.box.Box,{initialize:function($super,template,grid){this.grid=grid;this.gridId=grid.getElement().id;$super(template);this._eventOnHScroll=this._onContentHScroll.bindAsEventListener(this);this._eventOnVScroll=this._onContentVScroll.bindAsEventListener(this);this.createControl(template);this.registerEvents();},registerEvents:function(){Event.observe(this.scrollBox.element,"grid:onhcroll",this._eventOnHScroll);Event.observe(this.scrollBox.element,"grid:onvcroll",this._eventOnVScroll);},destroy:function(){Event.stopObserving(this.scrollBox.element,"grid:onhcroll",this._eventOnHScroll);Event.stopObserving(this.scrollBox.element,"grid:onvcroll",this._eventOnVScroll);},_onContentHScroll:function(event){this.grid.adjustScrollPosition(event.memo.pos);},_onDataReady:function(options){window.loadingUpdateTime=(new Date()).getTime();this.invalidate(options);window.loadingInvalidateTime=(new Date()).getTime();},_onContentVScroll:function(event){this.helpObject1.moveToY(this.sizeBox.element.offsetHeight+this.defaultRowHeight+5);this.helpObject2.moveToY(this.sizeBox.element.offsetHeight+this.defaultRowHeight+5);this.setScrollPos(event.memo.pos);this.adjustDataPosition(event.memo.pos);},createControl:function(template){this.scrollInput=$(this.gridId+":si");var childs=template.childNodes;for(var i=0;i<childs.length;i++){if(childs[i].id==this.gridId+":bc"){this.container=new ClientUI.common.box.Box(childs[i],null,true);this.container.makeAbsolute();this.container.setStyle({'z-index':20});if(!ClientUILib.isIE)this.container.setStyle({overflow:'hidden'});break;}}
Event.observe(this.container.getElement(),'keypress',this.synchronizeScroll.bindAsEventListener(this));this.scrollBox=new ClientUI.common.box.ScrollableBox(this.gridId+":scb",this.getElement());this.sizeBox=new ClientUI.common.box.Box(this.gridId+":sb",this.scrollBox.getElement());var normal=null,frozen=null;var childs=this.container.getElement().childNodes;for(var i=0;i<childs.length;i++){if(childs[i].id&&childs[i].id.indexOf("FrozenBox")>=0){frozen=childs[i];}
else if(childs[i].id&&childs[i].id.indexOf("NormalBox")>=0){normal=childs[i];}}
if(!normal||!frozen){errMsg="Unable to parse template for GridBody. Unable to find FrozenBox or NormalBox.";ClientUILib.log(ClientUILogger.ERROR,errMsg);throw(errMsg);}
this.contentBox=new ClientUI.common.box.Box(normal);Event.observe(this.contentBox.getElement(),'keypress',this.synchronizeScroll.bindAsEventListener(this));this.frozenContentBox=new ClientUI.common.box.Box(frozen);this.helpObject1=new ClientUI.common.box.Box(this.gridId+":nho",this.contentBox.getElement());this.helpObject2=new ClientUI.common.box.Box(this.gridId+":fho",this.frozenContentBox.getElement());var ch=this.frozenContentBox.getElement().firstChild;while(ch){if(ch.tagName&&ch.tagName.toLowerCase()=="table"){this.templFrozen=new ClientUI.common.box.Box($(ch),null,true);this.templFrozen.makeAbsolute();break;}
ch=ch.nextSibling;}
ch=this.contentBox.getElement().firstChild;while(ch){if(ch.tagName&&ch.tagName.toLowerCase()=="table"){this.templNormal=new ClientUI.common.box.Box($(ch),null,true);this.templNormal.makeAbsolute();break;}
ch=ch.nextSibling;}
this.parseTemplate(this.templFrozen.getElement(),this.templNormal.getElement());var gridId=this.grid.getElement().id;this.fTable=$(gridId+":f")
this.nTable=$(gridId+":n")
this.controlCreated=true;this.sizeBox.setHeight(this.templNormal.getElement().offsetHeight);},parseTemplate:function(templFrozen,templNormal){var result=false;if(templNormal&&templNormal.rows&&templNormal.rows.length!=0){this.rowsCount=Math.min(templNormal.rows.length,this.grid.dataModel.getCount());this.helpObj=new ClientUI.common.box.Box(templFrozen,null,true);this.countToLoad=0;this.startRow=0;this.startIndex=0;result=true;}
this.currRange=$R(0,this.rowsCount);return result;},setScrollPos:function(pos){this.contentBox.getElement().scrollTop=pos;this.frozenContentBox.getElement().scrollTop=pos;if(ClientUILib.isIE&&!ClientUILib.isIE7){this.contentBox.getElement().scrollTop=pos;this.frozenContentBox.getElement().scrollTop=pos;}},updateSize:function(){var row=this.templNormal.getElement().rows[0];if(row){this.defaultRowHeight=row.cells[0].offsetHeight;}else{var defHeight=this._calcDefaultRowHeight();if(isFinite(defHeight)){this.defaultRowHeight=defHeight;}}},updateLayout:function($super){if(!this.controlCreated||!this.grid.controlCreated){return;}
$super();if(!this.scrollBox||!this.contentBox||!this.sizeBox){return;}
var frozenContentWidth=this.fTable.offsetWidth;var totalWidth=frozenContentWidth+this.nTable.offsetWidth;this.scrollBox.moveTo(0,0);var height=this.element.offsetHeight;var width=this.element.offsetWidth;this.scrollBox.setWidth(width);this.scrollBox.setHeight(height);var scrollLeft=this.grid.getScrollOffset();var fixH=this.grid.getFooter()?this.grid.getFooter().element.offsetHeight:0;if(fixH>height)fixH=0;this.frozenContentBox.moveTo(0,0);this.contentBox.moveTo(frozenContentWidth,0);this.sizeBox.moveTo(0,0);this.sizeBox.setWidth(totalWidth);this.scrollBox.setWidth(width);this.scrollBox.setHeight(height);this.defaultRowHeight=this._calcDefaultRowHeight();this.sizeBox.setHeight(this.defaultRowHeight*this.grid.dataModel.getCount()+fixH);height=this.scrollBox.getElement().clientHeight;this.contentBox.setHeight(height-fixH);this.frozenContentBox.setWidth(frozenContentWidth);this.frozenContentBox.setHeight(height-fixH);this.container.setHeight(height-fixH);var scrollTop=this.scrollBox.element.scrollTop;this.scrollBox.hide();this.helpObject1.moveToY(this.sizeBox.element.offsetHeight+this.defaultRowHeight+5);this.helpObject2.moveToY(this.sizeBox.element.offsetHeight+this.defaultRowHeight+5);this.dataVisible=parseInt(this.contentBox.element.offsetHeight/this.defaultRowHeight,10)+1;this.dataVisible=Math.min(this.dataVisible,this.rowsCount);if(height>0){this.adjustDataPosition(this.currentPos);}
this.scrollBox.show();this.scrollBox.element.scrollTop=scrollTop;var viewWidth=this.scrollBox.getViewportWidth();this.container.setWidth(viewWidth);if(ClientUILib.isIE){this.contentBox.setWidth(viewWidth-frozenContentWidth);}
else{this.contentBox.setWidth(Math.max(this.getWidth(),totalWidth));}
var scrollPos=Math.min(totalWidth-viewWidth,scrollLeft);this.grid.adjustScrollPosition(scrollPos);},adjustScrollPosition:function(pos){this.templNormal.moveToX(-pos);},getScrollYPosition:function(){return this.contentBox.getElement().scrollTop;},adjustDataPosition:function(pos){if(this.currentPos==pos){return;}
this.processedPos=pos;var forwardDir=(this.currentPos<=pos)?true:false;var first=parseInt(pos/this.defaultRowHeight)-1;if(first<0)first=0;var from=Math.max(first-(forwardDir?1:(this.rowsCount-this.dataVisible-1)),0);var to=Math.min(first+(forwardDir?this.rowsCount-1:this.dataVisible+1),this.grid.dataModel.getCount());if(from==0){to=this.rowsCount;}
else if(to==this.grid.dataModel.getCount()){from=to-this.rowsCount;if(from<0){from=0;}}
var range=$R(from,to);if(this.currRange.start==from&&this.currRange.end==to){return;}
if(from>=to){ClientUILib.log(ClientUILogger.WARNING,"!!! GridBody: adjustDataPosition. Pos: "+pos+", From:"+from+", To:"+to);return;}
var task=this._getPendingTask();if(to-from>0){task.timer=null;task.from=from;task.to=to;task.first=first;task.pos=pos;this._setPendingTask(task);}},_getPendingTask:function(){if(!this.pendingTask){this.pendingTask={timer:null,rowsToLoad:[],rowsToLoadIdx:[],from:0,to:0,first:0,pos:0};}
return this.pendingTask;},_setPendingTask:function(task){clearTimeout(this.pendingTask.timer);this.pendingTask.timer=null;this.pendingTask=task;task.timer=setTimeout(function(){this.startLoadData();}.bind(this),this.grid.dataModel.getRequestDelay());},startLoadData:function(){if(this.updateStarted){this._setPendingTask(this._getPendingTask());return;}
this.updateStarted=true;var task=this._getPendingTask();var range=$R(task.from,task.to);var switchType=5;var startIndex=0;var startRowIndx=0;var countToLoad=0;var firstIndex=this._getRowIndex(this.templNormal.getElement().rows[0].id);this.scrollInput.value=task.pos+","+this.currRange.start+","+this.currRange.end+","+firstIndex;if(this.currRange.end<range.start||this.currRange.start>range.end){switchType=0;}
if(switchType===0){startRowIndx=firstIndex;startIndex=range.start;countToLoad=range.end-range.start;}
else{var i,row,rownew,cloned;countToLoad=0;var normalTbl=this.templNormal.getElement();if(range.start>this.currRange.start&&range.start<this.currRange.end){switchType=1;countToLoad=range.start-this.currRange.start;if(countToLoad>0){startRowIndx=firstIndex;startIndex=this.currRange.end;}}
else if(range.start==this.currRange.start){switchType=3;countToLoad=range.end-this.currRange.end;if(countToLoad>0){startIndex=this.currRange.end;var restCount=this.rowsCount-countToLoad;startRowIndx=this._getRowIndex(normalTbl.rows[restCount].id);}}
else{switchType=2;countToLoad=this.currRange.start-range.start;if(countToLoad>0){startIndex=range.start;var restCount=this.rowsCount-countToLoad;startRowIndx=this._getRowIndex(normalTbl.rows[restCount].id);}}}
var process=true;if(startIndex>(task.first+this.dataVisible)||(startIndex+countToLoad)<task.first){process=false;}
if(countToLoad>0&&process){this.updateStarted=true;ClientUILib.log(ClientUILogger.WARNING,"Start loading: index: "+startIndex+", and startRow: "+startRowIndx+", and count: "+countToLoad);this.scrollInput.value=task.pos+","+range.start+","+range.end+","+firstIndex+","+this.currRange.start;this.currRange=range;this.currentPos=task.pos;if(this.grid.options.hideWhenScrolling){this.container.hide();}
var options={index:startIndex,count:countToLoad,startRow:startRowIndx,switchType:switchType};setTimeout(function(){this.updateInterval=screen.updateInterval;screen.updateInterval=1000;this.grid.dataModel.loadRows(options);}.bind(this),10);}
else{this.updateStarted=false;}},forceReRender:function(){if(ClientUILib.isIE&&!ClientUILib.isIE7){var frozenTbl=this.templFrozen.getElement();var normalTbl=this.templNormal.getElement();var tr=frozenTbl.insertRow();frozenTbl.deleteRow(tr.rowIndex);tr=normalTbl.insertRow();normalTbl.deleteRow(tr.rowIndex);}},rearrangeRows:function(options,updateCash,showContainer){var frozenTbl=this.templFrozen.getElement();var normalTbl=this.templNormal.getElement();if(options.switchType===0){var visibleRowPos=this.defaultRowHeight*options.index;var test=this.contentBox.getElement().scrollTop;if(showContainer)this._showContainer();this.templFrozen.moveToY(visibleRowPos);this.templNormal.moveToY(visibleRowPos);this.forceReRender();}
else if(options.switchType===1||options.switchType===2){var ncount=normalTbl.rows.length;var fcount=frozenTbl.rows.length;var frows=new Array(fcount),nrows=new Array(ncount);var j=0,i;var index=options.index;var count=options.count;if(options.switchType===2){count=this.rowsCount-count;}
for(i=count;i<this.rowsCount;i++){if(fcount){frows[j]=frozenTbl.rows[i];}
nrows[j]=normalTbl.rows[i];j++;}
for(i=0;i<count;i++){if(fcount){frows[j]=frozenTbl.rows[i];}
nrows[j]=normalTbl.rows[i];j++;}
var removeChilds=navigator.product=="Gecko";var fbody=frozenTbl.tBodies[0];var nbody=normalTbl.tBodies[0];var fnextSibling=fbody.nextSibling;var nnextSibling=nbody.nextSibling;if(removeChilds){fp=fbody.parentNode;fp.removeChild(fbody);np=nbody.parentNode;np.removeChild(nbody);}
for(i=0;i<ncount;i++){if(fcount){fbody.appendChild(frows[i]);}
nbody.appendChild(nrows[i]);}
if(removeChilds){fp.insertBefore(fbody,fnextSibling);np.insertBefore(nbody,nnextSibling);}
var visibleRowPos=(options.switchType==1)?this.currRange.start*this.defaultRowHeight:options.index*this.defaultRowHeight;if(showContainer)this._showContainer();this.templFrozen.moveToY(visibleRowPos);this.templNormal.moveToY(visibleRowPos);}
else{var visibleRowPos=this.currRange.start*this.defaultRowHeight;if(showContainer)this._showContainer();this.templFrozen.moveToY(visibleRowPos);this.templNormal.moveToY(visibleRowPos);}},_showContainer:function(){this.container.show();if(ClientUILib.isIE){this.setScrollPos(this.currentPos);}},invalidate:function(options){screen.updateInterval=this.updateInterval;this.rearrangeRows(options,true,true);this.container.show();this.updateStarted=false;},processCashedValues:function(options){return options;var opt={switchType:options.switchType};var cash=this.getCash();var count=options.count;var index=options.index;var startRow=options.startRow;var i=0;var rowC;while(i<count&&(rowC=cash.getRow(index+i))!=null)i++;if(i>0){opt.count=i;opt.index=index;opt.startRow=startRow;this._restoreFromCash(opt);options.count-=i;options.index=index+i;options.startRow=startRow+i;if(options.startRow>=this.rowsCount)options.startRow-=this.rowsCount;}
var cnt=0;while(i<count&&!(rowC=cash.getRow(index+i))){i++;cnt++;}
if(i<count){opt.count=options.count-cnt;opt.index=index+i;opt.startRow=startRow+i;if(opt.startRow>=this.rowsCount)opt.startRow-=this.rowsCount;this._restoreFromCash(opt);options.count=cnt;options.index=index+(i-cnt);options.startRow=startRow+(i-cnt);if(options.startRow>=this.rowsCount)options.startRow-=this.rowsCount;}
return options;},ensureVisible:function(index){if(index>=0&&index<this.grid.dataModel.getCount()){var visibleRows=parseInt(this.contentBox.element.offsetHeight/this.defaultRowHeight,10)+1;if(this.grid.dataModel.getCount()>visibleRows){var y=index*this.defaultRowHeight;this.scrollBox.getElement().scrollTop=y;this.currentPos=0;this._onContentVScroll({memo:{pos:y}});}}},reloadData:function(){this.currentPos=-(this.rowsCount*this.defaultRowHeight);this.scrollBox.getElement().scrollTop=0;this.currRange.start=-this.rowsCount;this.currRange.end=-1;this._onContentVScroll({memo:{pos:0}});},_getRowIndex:function(rowId){return Number(rowId.split(this.grid.getElement().id)[1].split(":")[2]);},hideColumn:function(index,frozen){var rows;if(frozen){rows=this.templFrozen.getElement().rows;}else{rows=this.templNormal.getElement().rows;}
for(var i=0;i<rows.length;i++){rows[i].removeChild(rows[i].cells[index]);}},showRow:function(rowIndex){if(rowIndex=="up"){this.scrollBox.getElement().scrollTop=this.scrollBox.getElement().scrollTop-this.nTable.rows[1].offsetTop;}else if(rowIndex=="down"){this.scrollBox.getElement().scrollTop=this.scrollBox.getElement().scrollTop+this.nTable.rows[1].offsetTop;}else{var row=$(this.gridId+":n:"+rowIndex);var offsetTop=this.nTable.offsetTop+row.offsetTop;if(this.contentBox.getElement().scrollTop>offsetTop){this.scrollBox.getElement().scrollTop=offsetTop;}else{offsetTop+=row.offsetHeight;offsetTop-=this.contentBox.getElement().clientHeight;if(this.contentBox.getElement().scrollTop<offsetTop){this.scrollBox.getElement().scrollTop=offsetTop;}}}
this.scrollBox.updateScrollPos();},_calcDefaultRowHeight:function(){var templNormal=this.templNormal.getElement();var length=templNormal.rows.length;if(length){return Math.ceil(templNormal.offsetHeight/length);}else{return 16;}},updateScrollState:function(){this.scrollInput=$(this.gridId+":si");var value=this.scrollInput.value;if(value!=''&&this.sizeBox.getHeight()<Number(value.split(',')[0])){this.restoreScrollState();}
this.scrollInput.value=this.currentPos+","+this.currRange.start+","+this.currRange.end+","+this._getRowIndex(this.templNormal.getElement().rows[0].id);},restoreScrollState:function(){var value=this.scrollInput.value;if(value!=''){var values=value.split(',');this.currentPos=values[0];this.currRange.start=values[1];this.currRange.end=values[2];this.scrollBox.getElement().scrollTop=values[0];var visibleRowPos=this.currRange.start*this.defaultRowHeight;this._showContainer();this.templFrozen.moveToY(visibleRowPos);this.templNormal.moveToY(visibleRowPos);}},synchronizeScroll:function(event){if(Event.KEY_TAB==event.keyCode||Event.KEY_TAB==event.charCode){Event.stop(event);}}});Object.extend(ClientUI.controls.grid.GridBody.prototype,{dataVisible:50,dataDelta:5,currentPos:0});ClientUILib.declarePackage("ClientUI.controls.grid.GridFooter");ClientUILib.requireClass("ClientUI.common.box.Box");ClientUI.controls.grid.GridFooter=Class.create(ClientUI.common.box.Box,{initialize:function($super,template,grid){this.grid=grid;$super(template);this.createControl(template);},createControl:function(template){var errMsg="";if(!template){errMsg="Invalid template specified for GridFooter.";ClientUILib.log(ClientUILogger.ERROR,errMsg);throw(errMsg);}
if(!this.parseTemplate(template)){errMsg="Unable to parse template. GridFooter requires template specified over table element with one row.";ClientUILib.log(ClientUILogger.ERROR,errMsg);throw(errMsg);}
this.controlCreated=true;},parseTemplate:function(template){if(!template){return false;}
var childs=template.childNodes;for(var i=0;i<childs.length;i++){if(childs[i].tagName&&childs[i].tagName.toLowerCase()=="div"){this.container=new ClientUI.common.box.Box(childs[i],null,true);this.container.setStyle({"z-index":100});break;}}
var normal=null,frozen=null;var childs=this.container.getElement().childNodes;for(var i=0;i<childs.length;i++){if(childs[i].id&&childs[i].id.indexOf("FrozenBox")>=0){frozen=childs[i];}
else if(childs[i].id&&childs[i].id.indexOf("NormalBox")>=0){normal=childs[i];}}
if(!normal||!frozen){errMsg="Unable to parse template for GridFooter. Unable to find FrozenBox or NormalBox.";ClientUILib.log(ClientUILogger.ERROR,errMsg);throw(errMsg);}
this.contentBox=new ClientUI.common.box.Box(normal);this.frozenContentBox=new ClientUI.common.box.Box(frozen);var ch=this.contentBox.getElement().firstChild;while(ch){if(ch.tagName&&ch.tagName.toLowerCase()=="table"){this.headerRow=new ClientUI.common.box.Box($(ch),null,true);break;}
ch=ch.nextSibling;}
ch=this.frozenContentBox.getElement().firstChild;while(ch){if(ch.tagName&&ch.tagName.toLowerCase()=="table"){this.headerFrozenRow=new ClientUI.common.box.Box($(ch),null,true);break;}
ch=ch.nextSibling;}
this.helpObj=new ClientUI.common.box.Box(this.frozenContentBox.getElement(),null,true);this.frozenSubstrate=new ClientUI.common.box.Box(this.grid.getElement().id+":fs",this.getElement());this.frozenSubstrate.getElement().name=this.getElement().id+"FRFrm";this.frozenSubstrate.setHeight(this.headerRow.element.offsetHeight);return true;},updateSize:function(){this.setHeight(this.headerRow.element.offsetHeight);},updateLayout:function($super){if(!this.controlCreated||!this.grid.controlCreated){return;}
$super();var height=this.element.offsetHeight;var frozenContentWidth=this.frozenContentBox.getElement().offsetWidth;this.contentBox.setHeight(height);this.contentBox.moveTo(frozenContentWidth-this.grid.getScrollOffset(),0);this.frozenContentBox.setHeight(height);this.frozenContentBox.moveTo(0,0);var viewWidth=this.grid.getBody().scrollBox.getViewportWidth();this.container.setWidth(viewWidth);this.setWidth(viewWidth);this.frozenSubstrate.setWidth(frozenContentWidth);},adjustScrollPosition:function(pos){this.contentBox.moveToX(this.frozenContentBox.getElement().offsetWidth-pos);},hideColumn:function(index,frozen){var rows;if(frozen){rows=this.headerFrozenRow.getElement().rows;}else{rows=this.headerRow.getElement().rows;}
for(var i=0;i<rows.length;i++){rows[i].removeChild(rows[i].cells[index]);}}});ClientUILib.declarePackage("ClientUI.controls.grid.Grid");ClientUILib.requireClass("ClientUI.common.box.Box");ClientUILib.requireClass("ClientUI.controls.grid.GridHeader");ClientUILib.requireClass("ClientUI.controls.grid.GridBody");ClientUILib.requireClass("ClientUI.controls.grid.GridFooter");ClientUI.controls.grid.Grid=Class.create(ClientUI.common.box.Box,{initialize:function($super,element,dataModel,templates){$super(element);this.dataModel=dataModel;this.templates=$A(templates);this.createControl();},createControl:function(){var grid=this;this.layout=new ClientUI.layouts.GridLayoutManager(this.getElement().id+":c",null);var pagePart,item;for(var i=0;i<this.templates.length;i++){item=this.templates[i];switch(item.pane){case GridLayout_Enum.HEADER:{pagePart=new ClientUI.controls.grid.GridHeader($(item.ref),grid);this.layout.addPane(GridLayout_Enum.HEADER,pagePart);break;}
case GridLayout_Enum.BODY:{pagePart=new ClientUI.controls.grid.GridBody($(item.ref),grid);this.layout.addPane(GridLayout_Enum.BODY,pagePart);break;}
case GridLayout_Enum.FOOTER:{pagePart=new ClientUI.controls.grid.GridFooter($(item.ref),grid);this.layout.addPane(GridLayout_Enum.FOOTER,pagePart);break;}}}
this.currentScrollPos=0;this.controlCreated=true;var grid=this;Utils.execOnLoad(function(){grid.getHeader().updateSize();grid.getBody().updateSize();if(grid.getFooter()){grid.getFooter().updateSize();}
grid.updateLayout();grid.getBody().restoreScrollState();},Utils.Condition.ElementPresent(($(this.getElement().id+":c")).parentNode),100);},updateLayout:function($super){$super();var element=$(this.getElement().id+":c")
var height=element.parentNode.offsetHeight;if(element.offsetHeight!=height){element.setStyle({height:height+"px"});}
this.getHeader().resetFakeColumnWidth();if(this.layout){this.layout.updateLayout();}
this.getHeader().setFakeColumnWidth();if(element.offsetHeight!=height){element.setStyle({height:height+"px"});}},getHeader:function(){return this.layout.getPane(GridLayout_Enum.HEADER);},getFooter:function(){return this.layout.getPane(GridLayout_Enum.FOOTER);},getBody:function(){return this.layout.getPane(GridLayout_Enum.BODY);},adjustColumnWidth:function(index,width){this.getHeader().adjustColumnWidth(index,width);this.updateLayout();this.getHeader().agjustSeparators();this.element.fire("grid:onresizecolumn",{index:index,width:width});},adjustScrollPosition:function(pos){if(pos<0){pos=0;}
this.currentScrollPos=pos;this.getHeader().adjustScrollPosition(pos);this.getBody().adjustScrollPosition(pos);if(this.getFooter()){this.getFooter().adjustScrollPosition(pos);}},getScrollOffset:function(){return this.currentScrollPos?this.currentScrollPos:0;},setColumnMinWidth:function(index,width){if(index<0||index>=this.getHeader().getColumns().length)
return false;this.getHeader().getColumns()[index].minWidth=width;return true;},invalidate:function(params){this.getBody().invalidate(params);},adjustColumnsWidth:function(){var columns=this.getHeader().getColumns();for(var i=0;i<columns.length;i++){this.adjustColumnWidth(i,columns[i].width);}},ensureVisible:function(index){this.getBody().ensureVisible(index);},getDataIndex:function(rowIndex){var body=this.getBody();return body.currRange.start+rowIndex;},getRowIndex:function(dataIndex){var body=this.getBody();return(dataIndex>=body.currRange.start&&dataIndex<body.currRange.start+body.rowsCount)?dataIndex-body.currRange.start:-1;},hideColumn:function(column){this.adjustColumnWidth(column,0);},reloadData:function(){this.getBody().reloadData();},updateRowCount:function(newCount){var rowCount=parseInt(newCount);if(rowCount>=0){this.dataModel.count=rowCount;this.updateLayout();}}});ClientUI.controls.grid.Selection=Class.create({initialize:function(){this.ranges=[];},addId:function(id){id=parseInt(id);if(this.isSelectedId(id))
return;var i=0;while(i<this.ranges.length&&id>=this.ranges[i++].indexes[1]);i--;if(this.ranges[i-1]&&id==(this.ranges[i-1].indexes[1]+1)){if(id==(this.ranges[i].indexes[0]-1)){this.ranges[i-1].indexes[1]=this.ranges[i].indexes[1];this.removeRange(i);}else{this.ranges[i-1].indexes[1]++;}}else{if(this.ranges[i]){if(this.ranges[i]&&id==(this.ranges[i].indexes[0]-1)){this.ranges[i].indexes[0]--;}else{if(id==(this.ranges[i].indexes[1]+1)){this.ranges[i].indexes[1]++;}else{if(id<this.ranges[i].indexes[1]){this.addRange(i,new ClientUI.controls.grid.Range(id,id));}else{this.addRange(i+1,new ClientUI.controls.grid.Range(id,id));}}}}else{this.addRange(i,new ClientUI.controls.grid.Range(id,id));}}},addRange:function(index,range){var i=this.ranges.push(range)-2;if(index>=0){while(i>=index)
this.ranges[i+1]=this.ranges[i--];this.ranges[i+1]=range;}},removeRange:function(index){var i=index+1;while(i!=this.ranges.length)
this.ranges[i-1]=this.ranges[i++];this.ranges.pop();},isSelectedId:function(id){var i=0;while(i<this.ranges.length&&id>=this.ranges[i].indexes[0]){if(id>=this.ranges[i].indexes[0]&&id<=this.ranges[i].indexes[1]){return true;}else{i++;}}
return false;},getSelectedIdsQuantity:function(){var number=0;for(var i=0;i<this.ranges.length;i++){number+=this.ranges[i].size();}
return number;},size:function(){return this.getSelectedIdsQuantity();},removeId:function(id){id=parseInt(id);if(!this.isSelectedId(id))
return;var i=0;while(i<this.ranges.length&&id>this.ranges[i++].indexes[1]);i--;if(this.ranges[i]){if(id==(this.ranges[i].indexes[1])){if(id==(this.ranges[i].indexes[0])){this.removeRange(i);}else{this.ranges[i].indexes[1]--;}}else{if(id==(this.ranges[i].indexes[0])){this.ranges[i].indexes[0]++;}else{this.addRange(i+1,new ClientUI.controls.grid.Range(id+1,this.ranges[i].indexes[1]));this.ranges[i].indexes[1]=id-1;}}}},getState:function(){var s=this.clone();return{size:function(){return s.size();},each:function(iterator){s.each(iterator);},isSelected:function(id){return s.isSelectedId(id);}};},clone:function(){var ret=Object.extend(new Object(),this);ret.ranges=new Array(ret.ranges.length);for(var i=0;i<ret.ranges.length;i++){ret.ranges[i]=this.ranges[i].clone();}
return ret;},each:function(iterator){for(var i=0;i<this.ranges.length;i++){this.ranges[i].each(iterator);}},getRanges:function(){return this.ranges;},setRanges:function(ranges){this.ranges=ranges;},initRanges:function(rangeStrRArray){if(rangeStrRArray.length==0){this.ranges=[];return;}
this.ranges=new Array(rangeStrRArray.length);var indexStrRArray;for(var i=0;i<this.ranges.length;i++){indexStrRArray=rangeStrRArray[i].split(",");this.ranges[i]=new ClientUI.controls.grid.Range(parseInt(indexStrRArray[0]),parseInt(indexStrRArray[1]));}},inspectRanges:function(){var ranges=this.getRanges();var ret="";ranges.each(function(r){ret+=r.inspect();});return ret;}});ClientUI.controls.grid.Range=Class.create({initialize:function(startIndex,endIndex){this.indexes=[startIndex,endIndex];},inspect:function(){return this.indexes[0]+","+this.indexes[1]+";";},toString:function(){return this.inspect();},size:function(){return this.indexes[1]-this.indexes[0]+1;;},each:function(iterator){var j=this.indexes[0];while(j<=this.indexes[1]){iterator(j++);}},clone:function(){var ret=Object.extend(new Object(),this);ret.indexes=this.indexes.clone();return ret;}});ClientUI.controls.grid.SelectionManager=Class.create({initialize:function(grid){this.grid=grid;this.selectionFlag;this.firstIndex;this.activeRow=-1;var gridElement=grid.getElement();this.prefix=gridElement.id;this.selection=new ClientUI.controls.grid.Selection();this.inputElement=grid.options.selectionInput;this.isSingleMode="single"==grid.options.selectionMode;this.onselectionchange=grid.options.onselectionchange;this.selectedClass=grid.options.selectedClass;this.activeClass=grid.options.activeClass;this.restoreState();this.setListeners();this.eventKeyPress=this.processKeyDown.bindAsEventListener(this);Event.observe(document,"keydown",this.eventKeyPress);A4J.AJAX.AddListener({onafterajax:function(req,event,data){if(!$(this.prefix+":n")){Event.stopObserving(document,"keydown",this.eventKeyPress);}}.bind(this)});if(document.selection){Event.observe(gridElement,"click",this.resetSelection.bindAsEventListener(this));}
this.eventLostFocus=this.processLostFocus.bindAsEventListener(this);Event.observe(document,"click",this.eventLostFocus);this.eventPreventLostFocus=this.processPreventLostFocus.bindAsEventListener(this);Event.observe(gridElement,"click",this.eventPreventLostFocus);},restoreState:function(){this.selectionFlag=null;var selStrAr=$(this.inputElement).value.split(";");var activeRow=NaN;while(selStrAr.length!=0&&selStrAr[selStrAr.length-1].indexOf(",")==-1&&isNaN(activeRow=Number(selStrAr.pop())));if(!isNaN(activeRow)){this.setActiveRow(activeRow);}
this.selection.initRanges(selStrAr);var i=0;var j;while(i<this.selection.ranges.length){j=this.selection.ranges[i].indexes[0];while(j<=this.selection.ranges[i].indexes[1]){var fElement=$(this.prefix+":f:"+j);var nElement=$(this.prefix+":n:"+j);Element.addClassName(fElement,"dr-sdt-row-selected");Element.addClassName(nElement,"dr-sdt-row-selected");Element.addClassName(fElement,"rich-sdt-row-selected");Element.addClassName(nElement,"rich-sdt-row-selected");Element.addClassName(fElement,this.selectedClass);Element.addClassName(nElement,this.selectedClass);j++;}
i++;}
this.oldState=this.selection.getState();},setListeners:function(){var frows=$(this.prefix+":f").rows;var nrows=$(this.prefix+":n").rows;this.rowCount=nrows.length;var rowIndex;for(var i=0;i<this.rowCount;i++){rowIndex=Number(nrows[i].id.split(this.prefix)[1].split(":")[2]);this.addListener(frows[i],rowIndex);this.addListener(nrows[i],rowIndex);}},addListener:function(tr,rowIndex){if(tr){var listener=this.processClick.bindAsEventListener(this,rowIndex);var cells=tr.cells;for(var i=0;i<cells.length;i++){Utils.DOM.Event.observe(cells[i],"click",listener);}}},processPreventLostFocus:function(){this.inFocus=true;this.preventLostFocus=true;},processLostFocus:function(){if(!this.preventLostFocus){this.lostFocus();}else{this.preventLostFocus=false;}},lostFocus:function(){this.inFocus=false;},processKeyDown:function(event){if($(this.prefix+":n").rows.length>0){if(!event.shiftKey){this.shiftRow=null;}
var range,rowIndex;var activeRow=this.activeRow;var noDefault=false;this.firstIndex=Number($(this.prefix+":n").rows[0].id.split(this.prefix)[1].split(":")[2]);;switch(event.keyCode||event.charCode){case Event.KEY_UP:if(this.inFocus&&activeRow!=null){if(this.firstIndex!=activeRow){rowIndex=(this.rowCount+activeRow-1)%this.rowCount;if(this.isSingleMode||(!event.ctrlKey&&!event.shiftKey)){this.selectionFlag="x";range=[rowIndex,rowIndex];this.setSelection(range);}else if(!event.ctrlKey&&event.shiftKey){if(!this.shiftRow){this.shiftRow=this.activeRow;}
if(this.shiftRow>=this.activeRow){this.addRowToSelection(rowIndex);}else{this.removeRowFromSelection(activeRow);}}
noDefault=true;this.setActiveRow(rowIndex);}else{this.grid.getBody().showRow("up");}}
break;case Event.KEY_DOWN:if(this.inFocus&&activeRow!=null){rowIndex=(activeRow+1)%this.rowCount;if(this.firstIndex!=rowIndex){if(this.isSingleMode||(!event.ctrlKey&&!event.shiftKey)){this.selectionFlag="x";range=[rowIndex,rowIndex];this.setSelection(range);}else if(!event.ctrlKey&&event.shiftKey){if(!this.shiftRow){this.shiftRow=this.activeRow;}
if(this.shiftRow<=this.activeRow){this.addRowToSelection(rowIndex);}else{this.removeRowFromSelection(activeRow);}}
noDefault=true;this.setActiveRow(rowIndex);}else{this.grid.getBody().showRow("down");}}
break;case 65:case 97:if(this.inFocus&&event.ctrlKey&&!this.isSingleMode){this.selectionFlag="a";for(var i=0;i<this.rowCount;i++){this.addRowToSelection(i);}
noDefault=true;}
break;case Event.KEY_TAB:this.lostFocus();}
if(noDefault){this.grid.getBody().showRow(this.activeRow);this.selectionChanged(event);if(event.preventBubble)event.preventBubble();Event.stop(event);}}},processClick:function(event,rowIndex){if(!event.shiftKey){this.shiftRow=null;}
var range;if(event.shiftKey&&!event.ctrlKey&&!event.altKey&&!this.isSingleMode){this.firstIndex=Number($(this.prefix+":n").rows[0].id.split(this.prefix)[1].split(":")[2]);;this.selectionFlag="x";if(!this.shiftRow){this.shiftRow=this.activeRow;}
this.startRow=this.shiftRow;if(((this.startRow<=rowIndex)&&(this.firstIndex<=this.startRow||rowIndex<this.firstIndex))||(this.startRow>rowIndex&&this.firstIndex<this.startRow&&rowIndex<this.firstIndex)){this.endRow=rowIndex;}else{this.endRow=this.startRow;this.startRow=rowIndex;}
range=[this.startRow,this.endRow];this.setSelection(range);}else if(!event.shiftKey&&event.ctrlKey&&!event.altKey&&!this.isSingleMode){if(this.selection.isSelectedId(rowIndex)){this.removeRowFromSelection(rowIndex);}else{this.addRowToSelection(rowIndex);}}else if(this.isSingleMode||(!event.shiftKey&&!event.ctrlKey&&!event.altKey)){this.selectionFlag="x";range=[rowIndex,rowIndex];this.setSelection(range);}
this.setActiveRow(rowIndex);if(event.shiftKey&&!this.isSingleMode){if(window.getSelection){window.getSelection().removeAllRanges();}else if(document.selection){document.selection.empty();}}
this.selectionChanged(event);},selectionChanged:function(event){$(this.inputElement).value=this.selection.inspectRanges()+this.activeRow+";"+(this.selectionFlag?this.selectionFlag:"");var state=this.selection.getState();event.oldSelection=this.oldState;event.newSelection=state;if(this.onselectionchange)this.onselectionchange(event);this.oldState=state;},setShiftRow:function(event){if(event.shiftKey){if(!this.shiftRow){this.shiftRow=this.activeRow;}}else{this.shiftRow=null;}},setSelection:function(range){var i=range[0];range[1]=(range[1]+1)%this.rowCount;do{this.addRowToSelection(i);i=(i+1)%this.rowCount;}while(i!=range[1]);while(i!=range[0]){this.removeRowFromSelection(i);i=(i+1)%this.rowCount;}},resetSelection:function(e){if(e.shiftKey){document.selection.empty();}},addRowToSelection:function(rowIndex){this.selection.addId(rowIndex);var fElement=$(this.prefix+":f:"+rowIndex);var nElement=$(this.prefix+":n:"+rowIndex);Element.addClassName(fElement,"dr-sdt-row-selected");Element.addClassName(nElement,"dr-sdt-row-selected");Element.addClassName(fElement,"rich-sdt-row-selected");Element.addClassName(nElement,"rich-sdt-row-selected");Element.addClassName(fElement,this.selectedClass);Element.addClassName(nElement,this.selectedClass);},removeRowFromSelection:function(rowIndex){this.selection.removeId(rowIndex);var fElement=$(this.prefix+":f:"+rowIndex);var nElement=$(this.prefix+":n:"+rowIndex);Element.removeClassName(fElement,"dr-sdt-row-selected");Element.removeClassName(nElement,"dr-sdt-row-selected");Element.removeClassName(fElement,"rich-sdt-row-selected");Element.removeClassName(nElement,"rich-sdt-row-selected");Element.removeClassName(fElement,this.selectedClass);Element.removeClassName(nElement,this.selectedClass);},setActiveRow:function(rowIndex){var fElement,nElement;if(this.activeRow!=null){fElement=$(this.prefix+":f:"+this.activeRow);nElement=$(this.prefix+":n:"+this.activeRow);Element.removeClassName(fElement,"dr-sdt-row-active");Element.removeClassName(nElement,"dr-sdt-row-active");Element.removeClassName(fElement,"rich-sdt-row-active");Element.removeClassName(nElement,"rich-sdt-row-active");Element.removeClassName(fElement,this.activeClass);Element.removeClassName(nElement,this.activeClass);}
fElement=$(this.prefix+":f:"+rowIndex);nElement=$(this.prefix+":n:"+rowIndex);Element.addClassName(fElement,"dr-sdt-row-active");Element.addClassName(nElement,"dr-sdt-row-active");Element.addClassName(fElement,"rich-sdt-row-active");Element.addClassName(nElement,"rich-sdt-row-active");Element.addClassName(fElement,this.activeClass);Element.addClassName(nElement,this.activeClass);this.activeRow=rowIndex;}});ClientUILib.declarePackage("ClientUI.controls.grid.ScrollableGrid");ClientUI.controls.grid.ScrollableGrid=Class.create(ClientUI.controls.grid.Grid,{initialize:function($super,options){this.startInitTime=(new Date()).getTime();this.options=options;this.client_id=this.options.client_id;this.rows_count=$(this.client_id+"_rows_input").value;this.columns_count=this.options.columnsCount;this.splash_id=this.options.splash_id;this.dataModel=new ClientUI.controls.grid.FakeArrayDataModel(this.rows_count,this.columns_count,this.client_id);this.templates=[{pane:GridLayout_Enum.HEADER,ref:this.client_id+"_"+"GridHeaderTemplate"},{pane:GridLayout_Enum.BODY,ref:this.client_id+"_"+"GridBodyTemplate"},{pane:GridLayout_Enum.FOOTER,ref:this.client_id+"_"+"GridFooterTemplate"}];this.startCreateTime=(new Date()).getTime();$super(this.client_id,this.dataModel,this.templates);this.endCreateTime=(new Date()).getTime();Event.observe(this.element,"grid:onsort",this.onSorted.bindAsEventListener(this));if(this.options.selectionInput){this.selectionManager=new ClientUI.controls.grid.SelectionManager(this);}
this.endInitTime=(new Date()).getTime();this.rowCallbacks=[];},onSortComplete:function(request,event,data){this.dataModel.count=$(this.client_id+"_rows_input").value;var options=request.getJSON("options");Utils.AJAX.updateRows(options,request,this,this.client_id,[this.updateSelectionCallBack],[function(){this.selectionManager.restoreState();this.element.fire("grid:onpostsort",{column:options.column,order:options.order});}]);this.updateLayout();this.getBody().restoreScrollState();},onScrollComplete:function(request,event,data){this.dataModel.count=$(this.client_id+"_rows_input").value;var options=this.dataModel.getCurrentOptions();window.loadingServerTime=(new Date()).getTime();Utils.AJAX.updateRows(options,request,this,this.client_id,[this.updateSelectionCallBack],[function(){this.selectionManager.restoreState();this.element.fire("grid:onpostscroll",{start:this.getBody().currRange.start});}]);this.updateLayout();this.getBody().updateScrollState();window.loadingEndTime=(new Date()).getTime();ClientUILib.log(ClientUILogger.ERROR,"Total time of data loading of "+options.count+" rows is: "+(window.loadingEndTime-window.loadingStartTime)+" miliseconds.");ClientUILib.log(ClientUILogger.WARNING,"...Server load time: "+(window.loadingServerTime-window.loadingStartTime));ClientUILib.log(ClientUILogger.WARNING,"...DOM updated time: "+(window.loadingUpdateTime-window.loadingServerTime));ClientUILib.log(ClientUILogger.WARNING,"...Grid invalidation time: "+(window.loadingInvalidateTime-window.loadingUpdateTime));ClientUILib.log(ClientUILogger.WARNING,"...Selection mng time: "+(window.loadingEndTime-window.loadingInvalidateTime));},onSorted:function(event){this.options.onSortAjaxUpdate(event.memo);},updateSelectionCallBack:function(argMap){if(this.selectionManager){this.selectionManager.addListener(argMap.row,argMap.index);}},setSizes:function(width,height){var style=this.element.style;style.width=width+"px";style.height=height+"px";this.updateLayout();},doCollapse:function(index){var header=this.getHeader();var flength=header.headerFrozenRow.getElement().rows[0].cells.length;var nlength=header.headerRow.getElement().rows[0].cells.length;if(index<flength+nlength-1){var frozen=true;if(index>=flength){index-=flength;frozen=false;}
this.hideColumn(index,frozen);}},collapse:function(index){this.doCollapse(index);},hideColumn:function(index,frozen){this.getHeader().hideColumn(index,frozen);this.getBody().hideColumn(index,frozen);if(this.getFooter()){this.getFooter().hideColumn(index,frozen);}
this.updateLayout();}});