

var xc={};xc.version='1.0.0 Beta 1';xc.rootPath='';xc.Globals={};xc.Globals.RowStates={Unchanged:0,Added:1,Modified:2,Deleted:3,Cancelled:4};xc.Globals.RowVersions={Original:0,Current:1};xc.Globals.EditActions={ReadOnly:0,Edit:1,Delete:2,Add:4}

xc.Globals.GridEditModes={Single:0,Batch:1}

xc.Globals.Requests={Page:1,Save:2}

xc.Grid=function(name,dataView,options){if(!options){options=[];}

this.options=options;this.dataView=dataView;this.pager=new xc.Pager(this);this.pager.pageChanged.addHandler(this._pageChanged,this);if(this.dataView){this.dataView.pageChanged.addHandler(this._dataChanged,this);this.dataView.requestStateChanged.addHandler(this._stateChanged,this);this.dataView.dataRefreshed.addHandler(this._dataRefreshed,this);}

this.name=name;this.columnCollection={};this.editActions=options.editActions!==undefined?options.editActions:xc.Globals.EditActions.Edit|xc.Globals.EditActions.Delete|xc.Globals.EditActions.Add;this._allowedEditActions=this._calculateMode();this.defaultColumnWidth=options.defaultColumnWidth!==undefined?options.defaultColumnWidth:100;this.autoColumnWidth=options.autoColumnWidth!==undefined?options.autoColumnWidth:true;this.height=options.height!==undefined?options.height:0;this.footerHeight=options.footerHeight!==undefined?options.footerHeight:20;this.headerHeight=options.headerHeight!==undefined?options.headerHeight:24;this.buttonRowHeight=options.buttonRowHeight!==undefined?options.buttonRowHeight:30;this.wrapCells=options.wrapCells!==undefined?options.wrapCells:false;this.wrapHeader=options.wrapHeader!==undefined?options.wrapHeader:false;this.cellsOverflow=options.cellsOverflow!==undefined?options.cellsOverflow:"hidden";this.headerOverflow=options.headerOverflow!==undefined?options.headerOverflow:"hidden";this.columnCollection=this._generateColumns();this.activeRow=-1;this.editRow=-1;this.editMode=options.editMode!==undefined?options.editMode:xc.Globals.GridEditModes.Single;this.editColumnDelimiter=options.editColumnDelimiter!==undefined?options.editColumnDelimiter:"&nbsp;&nbsp;";this.selectAllowed=options.selectAllowed!==undefined?options.selectAllowed:true;this.sortingAllowed=options.sortingAllowed!==undefined?options.sortingAllowed:true;this.renderHeader=options.renderHeader!==undefined?options.renderHeader:true;this.renderFooter=options.renderFooter!==undefined?options.renderFooter:true;this.cellClicked=new xc.Event();this.beginEdit=new xc.Event();this.endEdit=new xc.Event();this.cancelEdit=new xc.Event();this.rowDelete=new xc.Event();this.root=document.createElement("div");this.root.className=options.className!==undefined?options.className:"xcGridMainDIV";this.progressIndicator=options.progressIndicator!==undefined?options.progressIndicator:"images/progress.gif";this.progressText=options.progressText!==undefined?options.progressText:"Loading...";this.rootCA={};this.tableCA={};this.headerRowCA={};this.headerCellCA={};this.footerRowCA={};this.footerCellCA={};this.bodyRowCA={};this.bodyCellCA={};}

xc.Grid.prototype._calculateMode=function(){return this.dataView.editActions&this.editActions;}

xc.Grid.prototype.canContinue=function(){var result=true;for(var i=0;i<this.dataView.rows.length;i++){if(this.dataView.rows[i].hasErrors){result=false;}}

return result;}

xc.Grid.prototype._dataRefreshed=function(sender,params){this.render();}

xc.Grid.prototype._sortingChanged=function(e,column){this._acceptChanges();if(this.canContinue()){if(!this.dataView.isRequestInProcess()){var order=this.dataView.getOrderBy(column);order=(order=='asc')?'desc':'asc';this.dataView.setOrderBy(column+' '+order);}}}

xc.Grid.prototype._stateChanged=function(sender,params){if(params){this.renderProgress();}else if(this.progressElement!=null){this.progressElement=null;}}

xc.Grid.prototype._pageChanged=function(sender,params){xc.removeObjectEventHandlers();this.activeRow=-1;if(this.dataView){this.dataView.requestPage(params);}}

xc.Grid.prototype._dataChanged=function(sender,params){this.render();}

xc.Grid.prototype.renderProgress=function(){var height=100;var width=250;var gridLocation=xc.getElementLocation(this.root);this.progressElement=document.createElement("table");this.progressElement.border=0;this.progressElement.cellpadding=0;this.progressElement.cellspacing=0;this.progressElement.style.position="absolute";this.progressElement.style.left=gridLocation.x+Math.round((this.root.offsetWidth-width)/2)+"px";this.progressElement.style.top=gridLocation.y+Math.round((this.root.offsetHeight-height)/2)+"px";var tbody=document.createElement("tbody");this.progressElement.appendChild(tbody);var row=document.createElement("tr");tbody.appendChild(row);var cell=document.createElement("td");row.appendChild(cell);cell.style.width=width+"px";cell.style.height=height+"px";cell.className="xcProgress";cell.appendChild(document.createTextNode(this.progressText+" "));image=document.createElement("img");image.src=xc.rootPath+this.progressIndicator;cell.appendChild(image);this.root.appendChild(this.progressElement);}

xc.Grid.prototype.render=function(){if(this.dataView){this.root.innerHTML="";this.root.style.height="";this.root.style.width="";this.table=document.createElement("table");this.table.className="xcGridTable";this.tbody=document.createElement("tbody");if(this.renderHeader){this.headerRow=document.createElement("tr");}

else{this.headerHeight=0;}

if(this.renderFooter){this.footerRow=document.createElement("tr");}

else{this.footerHeight=0;}

this._distributeHeight();if(this.renderHeader){this.tbody.appendChild(this._renderHeader());}

this._renderCells();for(var i=0;i<this.rows.length;i++){this.tbody.appendChild(this.rows[i]);}

if(this.blankSpace>0){var blankR=document.createElement("tr");var blankC=document.createElement("td");blankC.style.height=this.blankSpace+"px";blankR.appendChild(blankC);this.tbody.appendChild(blankR);}

if(this.renderFooter){this.tbody.appendChild(this._renderFooter());}

if((this._allowedEditActions&xc.Globals.EditActions.Add)||this.editMode==xc.Globals.GridEditModes.Batch){this.tbody.appendChild(this._renderEditButtons());}

this.table.appendChild(this.tbody);this.root.appendChild(this.table);this.root.appendChild(this._1());}else{this.renderProgress();}

return this.root;}

xc.Grid.prototype._1=function(){var cDiv=document.createElement("div");cDiv.style.height="10px";cDiv.style.textAlign="center";var cLink=document.createElement("a");cLink.className="xcCDiv";cLink.target="_blank";cLink.href="#";cLink.appendChild(document.createTextNode(" "));cDiv.appendChild(cLink);return cDiv;}

xc.Grid.prototype._distributeHeight=function(){var bodyHeight=this.height-(this.footerHeight+this.headerHeight);var rest=0;var rowHeight=0;if(bodyHeight>0){this.wrapCells=false;this.wrapHeader=false;var rowHeight=Math.round(this.height/this.dataView.pageSize);if(this.dataView.pageSize>this.dataView.rows.length){var rest=this.height-rowHeight*this.dataView.rows.length}}

this.rowHeight=rowHeight;this.blankSpace=rest;}

xc.Grid.prototype._renderHeader=function(){ this.headerCells=[]; for(var i=0;i<this.columnCollection.columns.length;i++){this.headerCells[i]=document.createElement("td");this.headerCells[i].className="xcGridHeaderCell";var innerDiv=document.createElement("div");innerDiv.className="xcGridHeaderDIV";if(!this.selectAllowed){innerDiv.appendChild(document.createTextNode(this.columnCollection.columns[i].caption));}

else{var a=document.createElement("a");a.appendChild(document.createTextNode(this.columnCollection.columns[i].caption));xc.registerObjectEventHandler(a,"click",this,"_sortingChanged",this.columnCollection.columns[i].name);a.href="javascript: void 0;";a.className="xcGridHeaderLink";innerDiv.appendChild(a);}

if(!this.wrapCells){innerDiv.style.whiteSpace="nowrap";}else{innerDiv.style.whiteSpace="normal";}

if(!this.autoColumnWidth){innerDiv.style.width=this.columnCollection.columns[i].width+"px";}

innerDiv.style.overflow=this.cellsOverflow;this.headerCells[i].style.height=this.headerHeight+"px";this.headerCells[i].appendChild(innerDiv);this.headerRow.appendChild(this.headerCells[i]);}

if(this._allowedEditActions!=xc.Globals.EditActions.ReadOnly){this.headerCells[this.headerCells.length]=document.createElement("td");this.headerCells[this.headerCells.length-1].className="xcGridHeaderCell";var innerDiv=document.createElement("div");innerDiv.className="xcGridHeaderDIV";if(!this.selectAllowed){innerDiv.appendChild(document.createTextNode(" "));}

this.headerCells[this.headerCells.length-1].style.height=this.headerHeight+"px";this.headerCells[this.headerCells.length-1].appendChild(innerDiv);this.headerRow.appendChild(this.headerCells[this.headerCells.length-1]);}

return this.headerRow;}

xc.Grid.prototype._cellClick=function(e,params){if(this.editRow!=-1&&params.row!=this.editRow){this._endEdit(null,{row:this.editRow});}

this.__renderActiveRow(params);this.cellClicked.dispatch(this,null);}

xc.Grid.prototype.__renderActiveRow=function(params){if(this.selectAllowed&&params.row!=this.editRow){if(params.row!=-1){for(var i=0;i<this.columnCollection.columns.length;i++){if(this.cells[params.row][i]){this.cells[params.row][i].className="xcGridActiveRowCell";}}}

if(this.activeRow!=-1&&this.activeRow!=params.row){for(var i=0;i<this.columnCollection.columns.length;i++){if(this.cells[this.activeRow][i]){if(this.dataView.rows[this.activeRow].rowState==xc.Globals.RowStates.Deleted||this.dataView.rows[this.activeRow].rowState==xc.Globals.RowStates.Cancelled)

{this.cells[this.activeRow][i].className="xcGridDeletedRowCell";}else if(this.dataView.rows[this.activeRow].hasErrors){this.cells[this.activeRow][i].className="xcGridErrorRowCell";}else{this.cells[this.activeRow][i].className=(this.activeRow%2==0)?"xcGridCell":"xcGridAlternatingCell";}}}}

if(this._allowedEditActions!=xc.Globals.EditActions.ReadOnly){if(params.row!=-1){this.editCells[params.row].className="xcGridActiveRowCell";}

if(this.activeRow!=-1&&this.activeRow!=params.row){if(this.dataView.rows[this.activeRow].rowState==xc.Globals.RowStates.Deleted||this.dataView.rows[this.activeRow].rowState==xc.Globals.RowStates.Cancelled)

{this.editCells[this.activeRow].className="xcGridDeletedRowCell";}else if(this.dataView.rows[this.activeRow].hasErrors){this.editCells[this.activeRow].className="xcGridErrorRowCell";}else{this.editCells[this.activeRow].className=(this.activeRow%2==0)?"xcGridCell":"xcGridAlternatingCell";}}}

this.activeRow=params.row;}}

xc.Grid.prototype._editClick=function(e,params){this._beginEdit(e,params);}

xc.Grid.prototype._beginEdit=function(e,params){if(this.editRow!=-1&&params.row!=this.editRow){this._endEdit(null,{row:this.editRow});}

this.editRow=params.row;for(var i=0;i<this.columnCollection.columns.length;i++){var pattern=new RegExp("{"+this.columnCollection.columns[i].name+"}");var columnWidth=(this.cells[params.row][i].clientWidth-5)+"px";this.cells[params.row][i].innerHTML=this.columnCollection.columns[i].editTemplate.replace(pattern,this.__processNull(this.dataView.rows[params.row].getValue(this.columnCollection.columns[i].name)));this.cells[params.row][i].className="xcGridEditCell";document.getElementById(this.name+"_"+this.columnCollection.columns[i].name).style.width=columnWidth;xc.registerObjectEventHandler(document.getElementById(this.name+"_"+this.columnCollection.columns[i].name),"keyup",this,"_editCellKeyPressed",{row:params.row,column:i});}

this.editCells[params.row].removeChild(this.editCells[params.row].firstChild);this.editCells[params.row].className="xcGridEditCell";this.editCells[params.row].appendChild(this.__renderUpdateLinks(params.row));this.beginEdit.dispatch(e,params);}

xc.Grid.prototype._editCellKeyPressed=function(e,params){switch(e.keyCode){case 13:this._endEdit(e,{row:params.row,column:params.column});break;case 27:this._cancelEdit(e,{row:params.row,column:params.column});break;}}

xc.Grid.prototype._updateClick=function(e,params){this._endEdit(e,params);}

xc.Grid.prototype._acceptClick=function(e,params){this._acceptChanges();}

xc.Grid.prototype._acceptChanges=function(){if(this.editRow!=-1){this._endEdit(null,{row:this.editRow});}

if(this.editMode==xc.Globals.GridEditModes.Batch){this.dataView.acceptChanges(xc.Globals.GridEditModes.Batch);if(!this.canContinue()){this.render();}}}

xc.Grid.prototype._addClick=function(e,params){this._addRow(e,params);}

xc.Grid.prototype._addRow=function(e,params){if(this.editRow!=-1){this._endEdit(null,{row:this.editRow});}

this.editRow=this.rows.length;this.dataView.addRow();this.cells[this.rows.length]=[];this.rows[this.rows.length]=document.createElement("tr");this.__renderRow(this.rows.length-1);this.render();for(var i=0;i<this.columnCollection.columns.length;i++){var pattern=new RegExp("{"+this.columnCollection.columns[i].name+"}");var columnWidth=(this.cells[this.rows.length-1][i].clientWidth-5)+"px";this.cells[this.rows.length-1][i].innerHTML=this.columnCollection.columns[i].editTemplate.replace(pattern,this.__processNull(this.dataView.rows[this.rows.length-1].getValue(this.columnCollection.columns[i].name)));this.cells[this.rows.length-1][i].className="xcGridEditCell";document.getElementById(this.name+"_"+this.columnCollection.columns[i].name).style.width=columnWidth;}

this.editCells[this.rows.length-1].removeChild(this.editCells[this.rows.length-1].firstChild);this.editCells[this.rows.length-1].className="xcGridEditCell";this.editCells[this.rows.length-1].appendChild(this.__renderUpdateLinks(this.rows.length-1,true));this.rows[this.rows.length-1].appendChild(this.editCells[this.rows.length-1]);}

xc.Grid.prototype._cancelClick=function(e,params){this._cancelEdit(e,params);}

xc.Grid.prototype._cancelNewClick=function(e,params){this.dataView.rows.pop();this.tbody.removeChild(this.rows[params.row]);this.rows.pop();this.editRow=-1;}

xc.Grid.prototype._endEdit=function(e,params){for(var i=0;i<this.columnCollection.columns.length;i++){this.dataView.rows[params.row].setValue(this.columnCollection.columns[i].name,this.__setNull(document.getElementById(this.name+"_"+this.columnCollection.columns[i].name).value));}

this.endEdit.dispatch(e,params);if(this.editMode==xc.Globals.GridEditModes.Single){this.dataView.acceptChanges(xc.Globals.GridEditModes.Single,params.row);}

for(var i=this.rows[params.row].childNodes.length-1;i>=0;i--){this.rows[params.row].removeChild(this.rows[params.row].childNodes[i]);}

this.__renderRow(params.row);this.editCells[params.row].removeChild(this.editCells[params.row].firstChild);if(this.dataView.rows[params.row].hasErrors){this.editCells[params.row].className="xcGridErrorRowCell";}else{this.editCells[params.row].className=(params.row%2==0)?"xcGridCell":"xcGridAlternatingCell";}

this.editCells[params.row].appendChild(this.__renderEditLinks(params.row));this.rows[params.row].appendChild(this.editCells[params.row]);this.editRow=-1;}

xc.Grid.prototype._cancelEdit=function(e,params){for(var i=this.rows[params.row].childNodes.length-1;i>=0;i--){this.rows[params.row].removeChild(this.rows[params.row].childNodes[i]);}

this.__renderRow(params.row);this.editCells[params.row].removeChild(this.editCells[params.row].firstChild);if(this.dataView.rows[params.row].hasErrors){this.editCells[params.row].className="xcGridErrorRowCell";}else{this.editCells[params.row].className=(params.row%2==0)?"xcGridCell":"xcGridAlternatingCell";}

this.editCells[params.row].appendChild(this.__renderEditLinks(params.row));this.rows[params.row].appendChild(this.editCells[params.row]);this.cancelEdit.dispatch(e,params);this.editRow=-1;}

xc.Grid.prototype.__renderEditLinks=function(rowIdx){var innerDiv=document.createElement("div");innerDiv.className="xcGridCellDIV";if(!this.wrapCells){innerDiv.style.whiteSpace="nowrap";}else{innerDiv.style.whiteSpace="normal";}

innerDiv.style.overflow=this.cellsOverflow;if(this._allowedEditActions&xc.Globals.EditActions.Edit){var editLink=document.createElement("a");editLink.className="xcGridEditLink";editLink.innerHTML="edit";editLink.href="javascript: void 0;";xc.registerObjectEventHandler(editLink,"click",this,"_editClick",{row:rowIdx});innerDiv.appendChild(editLink);}

if(this._allowedEditActions&(xc.Globals.EditActions.Edit|xc.Globals.EditActions.Delete)){var span=document.createElement("span");span.innerHTML=this.editColumnDelimiter;;innerDiv.appendChild(span);}

if(this._allowedEditActions&xc.Globals.EditActions.Delete){var deleteLink=document.createElement("a");deleteLink.className="xcGridDeleteLink";deleteLink.innerHTML="delete";deleteLink.href="javascript:void 0;";xc.registerObjectEventHandler(deleteLink,"click",this,"_deleteClick",{row:rowIdx});innerDiv.appendChild(deleteLink);}

return innerDiv;}

xc.Grid.prototype.__renderUpdateLinks=function(rowIdx,isNewRow){var innerDiv=document.createElement("div");innerDiv.className="xcGridCellDIV";if(!this.wrapCells){innerDiv.style.whiteSpace="nowrap";}else{innerDiv.style.whiteSpace="normal";}

innerDiv.style.overflow=this.cellsOverflow;var updateLink=document.createElement("a");updateLink.className="xcGridUpdateLink";updateLink.innerHTML="update";updateLink.href="javascript: void 0;";xc.registerObjectEventHandler(updateLink,"click",this,"_updateClick",{row:rowIdx});var cancelLink=document.createElement("a");cancelLink.className="xcGridCancelLink";cancelLink.innerHTML="cancel";cancelLink.href="javascript: void 0;";if(isNewRow){xc.registerObjectEventHandler(cancelLink,"click",this,"_cancelNewClick",{row:rowIdx});}else{xc.registerObjectEventHandler(cancelLink,"click",this,"_cancelClick",{row:rowIdx});}

var span=document.createElement("span");span.innerHTML=this.editColumnDelimiter;;innerDiv.appendChild(updateLink);innerDiv.appendChild(span);innerDiv.appendChild(cancelLink);return innerDiv;}

xc.Grid.prototype._deleteClick=function(e,params){if(this.editRow!=-1){this._endEdit(null,{row:this.editRow});}

if(this.dataView.rows[params.row].rowState==xc.Globals.RowStates.Added){this.dataView.rows[params.row].rowState=xc.Globals.RowStates.Cancelled;this.dataView.rows[params.row].hasErrors=false;}else{this.dataView.rows[params.row].rowState=xc.Globals.RowStates.Deleted;}

for(var i=this.rows[params.row].childNodes.length-1;i>=0;i--){this.rows[params.row].removeChild(this.rows[params.row].childNodes[i]);}

this.__renderRow(params.row);this.editCells[params.row].removeChild(this.editCells[params.row].firstChild);this.editCells[params.row].className="xcGridDeletedRowCell";var innerDiv=document.createElement("div");if(this.dataView.rows[params.row].rowState==xc.Globals.RowStates.Cancelled){innerDiv.appendChild(document.createTextNode("cancelled"));}else{innerDiv.appendChild(document.createTextNode("deleted"));}

innerDiv.className="xcGridCellDIV";this.editCells[params.row].appendChild(innerDiv);this.rows[params.row].appendChild(this.editCells[params.row]);this.rowDelete.dispatch(e,params);if(this.editMode==xc.Globals.GridEditModes.Single){this.dataView.acceptChanges(xc.Globals.GridEditModes.Single,params.row);}}

xc.Grid.prototype.__renderRow=function(rowIdx){for(var i=0;i<this.columnCollection.columns.length;i++){this.cells[rowIdx][i]=document.createElement("td");if(this.dataView.rows[rowIdx].rowState==xc.Globals.RowStates.Deleted||this.dataView.rows[rowIdx].rowState==xc.Globals.RowStates.Cancelled)

{this.cells[rowIdx][i].className="xcGridDeletedRowCell";}else if(this.dataView.rows[rowIdx].hasErrors){this.cells[rowIdx][i].className="xcGridErrorRowCell";}else{this.cells[rowIdx][i].className=(rowIdx%2==0)?"xcGridCell":"xcGridAlternatingCell";}

var innerDiv=document.createElement("div");innerDiv.className="xcGridCellDIV";if(!this.wrapCells){innerDiv.style.whiteSpace="nowrap";}else{innerDiv.style.whiteSpace="normal";}

if(this.rowHeight>0){this.cells[rowIdx][i].style.height=this.rowHeight+"px";}

innerDiv.style.overflow=this.cellsOverflow;if(!this.autoColumnWidth){innerDiv.style.width=this.columnCollection.columns[i].width+"px";}

var cellText=this.__processTemplate(this.columnCollection.columns[i].template,rowIdx);if(this.columnCollection.columns[i].showTooltip){innerDiv.title=(this.dataView.rows[rowIdx].hasErrors)?this.dataView.rows[rowIdx].errorMessage:cellText;}

innerDiv.innerHTML=cellText;this.cells[rowIdx][i].appendChild(innerDiv);xc.registerObjectEventHandler(this.cells[rowIdx][i],"click",this,"_cellClick",{row:rowIdx,column:i});this.rows[rowIdx].appendChild(this.cells[rowIdx][i]);}}

xc.Grid.prototype.__processTemplate=function(template,rowIdx){template=decodeURI(template);for(var i=0;i<this.dataView.columns.getCount();i++){var dataColumn=this.dataView.columns.getItem(i);var pattern=new RegExp("\\{"+dataColumn.columnName+"\\}","g");template=template.replace(pattern,this.__processNull(this.dataView.rows[rowIdx].getValue(dataColumn.columnName)));}

return template;}

xc.Grid.prototype.__processNull=function(value){return value===null?"(null)":value;}

xc.Grid.prototype.__setNull=function(value){return value;}

xc.Grid.prototype._renderCells=function(){this.cells=[];this.rows=[];for(var j=0;j<this.dataView.rows.length;j++){this.rows[j]=document.createElement("tr");this.cells[j]=[];this.__renderRow(j);}

if(this._allowedEditActions!=xc.Globals.EditActions.ReadOnly){this.editCells=[];for(var i=0;i<this.dataView.rows.length;i++){this.editCells[i]=document.createElement("td");if(this.dataView.rows[i].rowState==xc.Globals.RowStates.Deleted||this.dataView.rows[i].rowState==xc.Globals.RowStates.Cancelled)

{this.editCells[i].className="xcGridDeletedRowCell";}else if(this.dataView.rows[i].hasErrors){this.editCells[i].className="xcGridErrorRowCell";}else{this.editCells[i].className=(i%2==0)?"xcGridCell":"xcGridAlternatingCell";}

if(this.rowHeight>0){this.editCells[i].style.height=this.rowHeight+"px";}

if(this.dataView.rows[i].rowState==xc.Globals.RowStates.Deleted||this.dataView.rows[i].rowState==xc.Globals.RowStates.Cancelled){this.editCells[i].appendChild(this.dataView.rows[i].rowState==xc.Globals.RowStates.Deleted?document.createTextNode("deleted"):document.createTextNode("cancelled"));}else{this.editCells[i].appendChild(this.__renderEditLinks(i));}

this.rows[i].appendChild(this.editCells[i]);}}}

xc.Grid.prototype._renderFooter=function(){this.footerCell=document.createElement("td");this.footerCell.style.height=this.footerHeight+"px";this.footerCell.className="xcGridFooterCell";this.footerCell.colSpan=this.columnCollection.columns.length+(this._allowedEditActions!=xc.Globals.EditActions.ReadOnly?1:0);this.footerCell.appendChild(this.pager.render());this.footerRow.appendChild(this.footerCell);return this.footerRow;}

xc.Grid.prototype._renderEditButtons=function(){this.buttonRow=document.createElement("tr");this.buttonCell=document.createElement("td");this.buttonCell.style.height=this.buttonRowHeight+"px";this.buttonCell.className="xcGridButtonCell";this.buttonCell.colSpan=this.columnCollection.columns.length+(this._allowedEditActions!=xc.Globals.EditActions.ReadOnly?1:0);if(this.editMode==xc.Globals.GridEditModes.Batch){this.acceptButton=document.createElement("input");this.acceptButton.type="button";this.acceptButton.value="Commit Changes";xc.registerObjectEventHandler(this.acceptButton,"click",this,"_acceptClick",null);this.buttonCell.appendChild(this.acceptButton);}

if(this._allowedEditActions&xc.Globals.EditActions.Add){var span=document.createElement("span");span.innerHTML="&nbsp;&nbsp;";this.buttonCell.appendChild(span);this.addButton=document.createElement("input");this.addButton.type="button";this.addButton.value="Add Row";xc.registerObjectEventHandler(this.addButton,"click",this,"_addClick",null);this.buttonCell.appendChild(this.addButton);}

this.buttonRow.appendChild(this.buttonCell);return this.buttonRow;}

xc.Grid.prototype._generateColumns=function(){var columnCollection=new xc.GridColumnCollection();if(this.dataView){for(var i=0;i<this.dataView.columns.getCount();i++){var dataColumn=this.dataView.columns.getItem(i);var column=new xc.GridColumn(this,dataColumn.columnName,dataColumn.caption,"{"+dataColumn.columnName+"}");column.width=this.defaultColumnWidth;columnCollection.add(column);}}

return columnCollection;}

xc.GridColumnCollection=function(){}

xc.GridColumnCollection.prototype.add=function(column){if(!this.columns){this.columns=[];}

this.columns[this.columns.length]=column;return;}

xc.GridColumnCollection.prototype.getColumnByName=function(name){for(var i=0;i<this.columns.length;i++){if(this.columns[i].name==name){return this.columns[i];}}

return null;}

xc.GridColumn=function(grid,name,caption,template,editTemplate){this.grid=grid;this.name=name;this.caption=caption;this.width=100;this.showTooltip=true;this.template=template;if(editTemplate){this.editTemplate=editTemplate;}else{this.editTemplate="<input class='xcGridEditControl' value='{"+this.name+"}' id='"+this.grid.name+"_"+this.name+"'/>";}}

xc.Pager=function(parentControl){if(!parentControl.options){parentControl.options=[];parentControl.options.pager=[];}

this.parentControl=parentControl;this.style=parentControl.options.pager.style?parentControl.options.pager.style:1;this.type=parentControl.options.pager.type?parentControl.options.pager.type:2;this.range=parentControl.options.pager.range?parentControl.options.pager.range:10;this.displayDisabledItems=parentControl.options.pager.displayDisabledItems?parentControl.options.pager.displayDisabledItems:false;this.nextText=parentControl.options.pager.nextText?parentControl.options.pager.nextText:">";this.lastText=parentControl.options.pager.lastText?parentControl.options.pager.lastText:">>";this.previousText=parentControl.options.pager.previousText?parentControl.options.pager.previousText:"<";this.firstText=parentControl.options.pager.firstText?parentControl.options.pager.firstText:"<<";this.introText=parentControl.options.pager.introText?parentControl.options.pager.introText:"Pages:&nbsp;&nbsp;";this.pageChanged=new xc.Event();}

xc.Pager.prototype._pageChanged=function(e,newPage){this.parentControl._acceptChanges();if(this.parentControl.canContinue()){if(this.parentControl.dataView&&!this.parentControl.dataView.isRequestInProcess()){this.pageChanged.dispatch(this,newPage);}}}

xc.Pager.prototype._pageChangedDropDown=function(e,dropControl){this.parentControl._acceptChanges();if(this.parentControl.canContinue()){if(this.parentControl.dataView&&!this.parentControl.dataView.isRequestInProcess()){this.pageChanged.dispatch(this,dropControl.options[dropControl.selectedIndex].value);}}else{dropControl.options[this.parentControl.dataView.currentPage-1].defaultSelected=true;dropControl.options[this.parentControl.dataView.currentPage-1].selected=true;}}

xc.Pager.prototype._renderBasic=function(pagerCell){if(this.style==1||this.style==4||this.style==5||this.style==6){for(var i=1;i<=this.parentControl.dataView.getPageCount();i++){this.cells[i]=document.createElement("span");if(i==this.parentControl.dataView.currentPage){this.cells[i].className="xcPagerActiveElement";var innerElem=document.createElement("span");innerElem.className="xcPagerActivePage";innerElem.appendChild(document.createTextNode("["+i+"]"));this.cells[i].appendChild(innerElem);}else{this.cells[i].className="xcPagerElement";var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",i);innerElem.href="javascript: void 0;";innerElem.className="xcPagerPageLink";innerElem.appendChild(document.createTextNode(i));this.cells[i].appendChild(innerElem);}

this.cells[i].appendChild(document.createTextNode(" "));pagerCell.appendChild(this.cells[i]);}}}

xc.Pager.prototype._renderDropDown=function(pagerCell,dropCell){if(dropCell){this.__renderPageDropDown(dropCell);}

if(this.style==1||this.style==4||this.style==5||this.style==6){var firstRangePage=Math.max(1,this.parentControl.dataView.currentPage-this.range);var lastRangePage=Math.min(this.parentControl.dataView.getPageCount(),this.parentControl.dataView.currentPage+this.range);if(firstRangePage!=1){var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",this.parentControl.dataView.currentPage-this.range);innerElem.href="javascript: void 0;";innerElem.className="xcPagerPageLink";innerElem.appendChild(document.createTextNode("<<"));pagerCell.appendChild(innerElem);pagerCell.appendChild(document.createTextNode(" "));}

for(var i=firstRangePage;i<=lastRangePage;i++){this.cells[i]=document.createElement("span");if(i==this.parentControl.dataView.currentPage){this.cells[i].className="xcPagerActiveElement";var innerElem=document.createElement("span");innerElem.className="xcPagerActivePage";if(!dropCell){this.__renderPageDropDown(innerElem);}else{innerElem.appendChild(document.createTextNode("["+i+"]"));}

this.cells[i].appendChild(innerElem);}else{this.cells[i].className="xcPagerElement";var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",i);innerElem.href="javascript: void 0;";innerElem.className="xcPagerPageLink";innerElem.appendChild(document.createTextNode(i));this.cells[i].appendChild(innerElem);}

this.cells[i].appendChild(document.createTextNode(" "));pagerCell.appendChild(this.cells[i]);}

if(lastRangePage!=this.parentControl.dataView.getPageCount()){var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",this.parentControl.dataView.currentPage+this.range);innerElem.href="javascript: void 0;";innerElem.className="xcPagerPageLink";innerElem.appendChild(document.createTextNode(">>"));pagerCell.appendChild(innerElem);pagerCell.appendChild(document.createTextNode(" "));}}}

xc.Pager.prototype.__renderPageDropDown=function(dropCell){var dropControl=document.createElement("select");dropControl.className="xcPagerDropDown";for(var i=1;i<=this.parentControl.dataView.getPageCount();i++){var option=document.createElement("option");option.value=i;option.innerHTML=i;if(i==this.parentControl.dataView.currentPage){option.defaultSelected=true;option.selected=true;}

dropControl.appendChild(option);}

xc.registerObjectEventHandler(dropControl,"change",this,"_pageChangedDropDown",dropControl);dropCell.appendChild(dropControl);}

xc.Pager.prototype.__renderFirst=function(pagerCell){var firstCell=document.createElement("span");firstCell.className="xcPagerElement";if(this.parentControl.dataView.currentPage>1){var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",1);innerElem.href="javascript: void 0;";innerElem.className="xcPagerFirstEnabled";innerElem.appendChild(document.createTextNode(this.firstText));firstCell.appendChild(innerElem);firstCell.appendChild(document.createTextNode(" "));pagerCell.appendChild(firstCell);}else{if(this.displayDisabledItems){firstCell.className="xcPagerElement";var innerElem=document.createElement("span");innerElem.className="xcPagerFirstDisabled";innerElem.appendChild(document.createTextNode(this.firstText));firstCell.appendChild(innerElem);firstCell.appendChild(document.createTextNode(" "));pagerCell.appendChild(firstCell);}}}

xc.Pager.prototype.__renderLast=function(pagerCell){var lastCell=document.createElement("span");lastCell.className="xcPagerElement";if(this.parentControl.dataView.currentPage<this.parentControl.dataView.getPageCount()){var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",this.parentControl.dataView.getPageCount());innerElem.href="javascript: void 0;";innerElem.className="xcPagerLastEnabled";innerElem.appendChild(document.createTextNode(this.lastText));lastCell.appendChild(innerElem);pagerCell.appendChild(lastCell);}else{if(this.displayDisabledItems){lastCell.className="xcPagerElement";var innerElem=document.createElement("span");innerElem.className="xcPagerLastDisabled";innerElem.appendChild(document.createTextNode(this.lastText));lastCell.appendChild(innerElem);pagerCell.appendChild(lastCell);}}}

xc.Pager.prototype.__renderNext=function(pagerCell){var nextCell=document.createElement("span");nextCell.className="xcPagerElement";if(this.parentControl.dataView.currentPage<this.parentControl.dataView.getPageCount()){var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",this.parentControl.dataView.currentPage+1);innerElem.href="javascript: void 0;";innerElem.className="xcPagerNextEnabled";innerElem.appendChild(document.createTextNode(this.nextText));nextCell.appendChild(innerElem);nextCell.appendChild(document.createTextNode(" "));pagerCell.appendChild(nextCell);}else{if(this.displayDisabledItems){nextCell.className="xcPagerElement";var innerElem=document.createElement("span");innerElem.className="xcPagerNextDisabled";innerElem.appendChild(document.createTextNode(this.nextText));nextCell.appendChild(innerElem);nextCell.appendChild(document.createTextNode(" "));pagerCell.appendChild(nextCell);}}}

xc.Pager.prototype.__renderPrev=function(pagerCell){var previousCell=document.createElement("span");previousCell.className="xcPagerElement";if(this.parentControl.dataView.currentPage>1){var innerElem=document.createElement("a");xc.registerObjectEventHandler(innerElem,"click",this,"_pageChanged",this.parentControl.dataView.currentPage-1);innerElem.href="javascript: void 0;";innerElem.className="xcPagerPreviousEnabled";innerElem.appendChild(document.createTextNode(this.previousText));previousCell.appendChild(innerElem);previousCell.appendChild(document.createTextNode(" "));pagerCell.appendChild(previousCell);}else{if(this.displayDisabledItems){previousCell.className="xcPagerElement";var innerElem=document.createElement("span");innerElem.className="xcPagerPreviousDisabled";innerElem.appendChild(document.createTextNode(this.previousText));previousCell.appendChild(innerElem);previousCell.appendChild(document.createTextNode(" "));pagerCell.appendChild(previousCell);}}}

xc.Pager.prototype.render=function(){this.root=document.createElement("div");this.table=document.createElement("table");this.table.className="xcPagerTable";this.tbody=document.createElement("tbody");this.row=document.createElement("tr");this.cells=[];var introCell=document.createElement("td");introCell.className="xcPagerIntroText";introCell.innerHTML=this.introText;this.row.appendChild(introCell);var pagerCell=document.createElement("td");pagerCell.className="xcPagerCell";if(this.style==3||this.style==4||this.style==5){this.__renderFirst(pagerCell);}

if(this.style==2||this.style==3||this.style==5||this.style==6){this.__renderPrev(pagerCell);}

if(this.type==1){this._renderBasic(pagerCell);}

if(this.type==2){this._renderDropDown(pagerCell);}

if(this.style==2||this.style==3||this.style==5||this.style==6){this.__renderNext(pagerCell);}

if(this.style==3||this.style==4||this.style==5){this.__renderLast(pagerCell);}

this.row.appendChild(pagerCell);this.tbody.appendChild(this.row);this.table.appendChild(this.tbody);this.root.appendChild(this.table);return this.root;}

xc.DataColumn=function(name,caption,position){this.columnName=name;this.caption=caption;this.position=typeof position=='number'?position:-1;}

xc.DataItem=function(value){this._original=value;}

xc.DataItem.prototype.getValue=function(version){if(version!=xc.Globals.RowVersions.Original&&typeof this._current!="undefined"){return this._current;}else if(typeof this._original!="undefined"){return this._original;}else{return null;}}

xc.DataItem.prototype.setValue=function(value){if(typeof this._current!="undefined"||this._original!=value){this._current=value;return true;}

return false;}

xc.DataRow=function(){this._items=new xc.Collection();this.rowState=xc.Globals.RowStates.Unchanged;this.hasErrors=false;this.errorMessage="";}

xc.DataRow.prototype.getValue=function(index,version){var item;try{item=this._items.getItem(index);}catch(e){return null;}

return item.getValue(version);}

xc.DataRow.prototype.setValue=function(index,value){try{var item=this._items.getItem(index);}catch(e){return;}

if(item.setValue(value)&&this.rowState==xc.Globals.RowStates.Unchanged){this.rowState=xc.Globals.RowStates.Modified;}}

xc.DataView=function(url,provider){this._requestState=false;this._orderBy='';this._url=url;this._provider=provider;this.pageSize=20;this.rowCount=0;this.currentPage=1;this.hasErrors=false;this.editActions=xc.Globals.EditActions.ReadOnly;this.columns=null;this.rows=[];this.pageChanged=new xc.Event();this.requestStateChanged=new xc.Event();this.dataRefreshed=new xc.Event();}

xc.DataView.prototype.getPageCount=function(){if(this.pageSize==0||this.rowCount==0){return 1;}

return Math.ceil(this.rowCount/this.pageSize);}

xc.DataView.prototype.isRequestInProcess=function(){return this._requestState;}

xc.DataView.prototype.getOrderBy=function(column){var rx=new RegExp(column+"(?:\\s+(asc|ASC|desc|DESC))?");var m=rx.exec(this._orderBy);var order='';if(m!=null){order=m[1].toLowerCase();}

return order;}

xc.DataView.prototype.setOrderBy=function(orderBy){if(!this._requestState){this._orderBy=orderBy;this.requestPage(this.currentPage);}}

xc.DataView.prototype.newRow=function(values){var row=new xc.DataRow();for(var i=0;i<this.columns.getCount();i++){var value=null;var columnName=this.columns.getItem(i).columnName;if(typeof values=='object'){if(values.constructor==Array&&typeof values[i]!='undefined'){value=values[i];}else if(values.constructor==Object&&typeof values[columnName]!='undefined'){value=values[columnName];}}

row._items.add(new xc.DataItem(value),columnName);}

return row;}

xc.DataView.prototype.addRow=function(values){var row=this.newRow(values);row.rowState=xc.Globals.RowStates.Added;var index=this.rows.length;this.rows[index]=row;this.rowCount++;return index;}

xc.DataView.prototype.requestPage=function(page){if(!this._requestState){var url=this._url+'?request='+xc.Globals.Requests.Page+'&provider='+this._provider;url+='&size='+this.pageSize+'&page='+page;if(this._orderBy){url+='&order='+encodeURI(this._orderBy);}

var callback={scope:this,success:this._pageReceived,argument:{}};this._requestState=true;this.requestStateChanged.dispatch(this,this._requestState);var request=YAHOO.util.Connect.asyncRequest('GET',url,callback);}}

xc.DataView.prototype._pageReceived=function(o){eval('var json = '+o.responseText);this.applyJson(json);}

xc.DataView.prototype.applyJson=function(json){this.currentPage=json.currentPage;this.rowCount=json.rowCount;this.pageSize=json.pageSize;this.editActions=json.editActions;this.columns=new xc.Collection();for(var i=0;i<json.columns.length;i++){this.columns.add(new xc.DataColumn(json.columns[i],json.columns[i],i),json.columns[i]);}

this.rows=[];for(var i=0;i<json.items.length;i++){var row=this.newRow(json.items[i]);this.rows[this.rows.length]=row;}

this._requestState=false;this.requestStateChanged.dispatch(this,this._requestState);this.pageChanged.dispatch(this,null);}

xc.DataView.prototype.acceptChanges=function(mode,rowIdx){var changes=this._getChanges();if(changes.length>0){changes=xc.toJSONString(changes);this._sendChanges(changes);}else{var changed=false;for(var i=this.rows.length-1;i>=0;i--){if(this.rows[i].rowState==xc.Globals.RowStates.Cancelled){this.rows.splice(i,1);this.rowCount--;changed=true;}}

if(changed){this.dataRefreshed.dispatch(this,null);}}}

xc.DataView.prototype._sendChanges=function(changes){if(!this._requestState){var url=this._url+'?request='+xc.Globals.Requests.Save+'&provider='+this._provider;var post='changes='+encodeURI(changes);var callback={scope:this,success:this._saveReceived,argument:{}};this._requestState=true;this.requestStateChanged.dispatch(this,this._requestState);var request=YAHOO.util.Connect.asyncRequest('POST',url,callback,post);}}

xc.DataView.prototype._saveReceived=function(o){eval('var json = '+o.responseText);this.hasErrors=false;for(var i=0;i<this.rows.length;i++){this.rows[i].hasErrors=false;this.rows[i].errorMessage="";}

for(var i=0;i<json.length;i++){this.hasErrors=true;this.rows[json[i].idx].hasErrors=true;this.rows[json[i].idx].errorMessage=json[i].message;}

for(var i=this.rows.length-1;i>=0;i--){if(!this.rows[i].hasErrors){switch(this.rows[i].rowState){case xc.Globals.RowStates.Added:case xc.Globals.RowStates.Modified:this.rows[i].rowState=xc.Globals.RowStates.Unchanged;for(var j=0;j<this.rows[i]._items.getCount();j++){var item=this.rows[i]._items.getItem(j);if(typeof item._current!="undefined"){var undefined;item._original=item._current;item._current=undefined;}}

break;case xc.Globals.RowStates.Deleted:case xc.Globals.RowStates.Cancelled:this.rows.splice(i,1);this.rowCount--;break;}}}

this._requestState=false;this.requestStateChanged.dispatch(this,this._requestState);this.dataRefreshed.dispatch(this,null);}

xc.DataView.prototype._getChanges=function(){var changes=[];for(var i=0;i<this.rows.length;i++){var row={};switch(this.rows[i].rowState){case xc.Globals.RowStates.Added:case xc.Globals.RowStates.Modified:case xc.Globals.RowStates.Deleted:row.idx=i;row.state=this.rows[i].rowState;row.columns=[];for(var j=0;j<this.rows[i]._items.getCount();j++){var col={};col.name=this.rows[i]._items.getKey(j);if(this.rows[i].rowState==xc.Globals.RowStates.Modified||this.rows[i].rowState==xc.Globals.RowStates.Deleted){col.original=this.rows[i].getValue(j,xc.Globals.RowVersions.Original);}

if(this.rows[i].rowState==xc.Globals.RowStates.Modified||this.rows[i].rowState==xc.Globals.RowStates.Added){var curr=this.rows[i].getValue(j,xc.Globals.RowVersions.Current);if(curr!==col.original){col.current=curr;}}

row.columns[row.columns.length]=col;}

changes[changes.length]=row;break;default:continue;}}

return changes;}

xc.__eventListeners=[];xc.registerObjectEventHandler=function(element,eventtype,listener,handlerName,params){if(document.addEventListener){element.addEventListener(eventtype,function(event){listener[handlerName](event,params);},false);}

else if(document.attachEvent){var handlerRef=function(){listener[handlerName](event,params);};if(!element._xcHandlers){element._xcHandlers=[];}

element.attachEvent("on"+eventtype,handlerRef);xc.__eventListeners.push({instance:element,type:"on"+eventtype,handler:handlerRef});}}

xc.removeObjectEventHandlers=function(){if(document.detachEvent){for(var i=0;i<xc.__eventListeners.length;i++){if(xc.__eventListeners[i]){xc.__eventListeners[i].instance.detachEvent(xc.__eventListeners[i].type,xc.__eventListeners[i].handler);}}}}

xc.Event=function(){this.handlers=[];}

xc.Event.prototype.addHandler=function(handler,target){if(this.handlers){this.handlers[this.handlers.length]={handler:handler,target:target};return true;}

else{return false;}}

xc.Event.prototype.removeHandler=function(target,handler){return true;}

xc.Event.prototype.dispatch=function(sender,params){for(var i=0;i<this.handlers.length;i++){if(this.handlers[i]){if(this.handlers[i].target){this.handlers[i].handler.call(this.handlers[i].target,sender,params);}

else{this.handlers[i].handler(sender,params);}}}}

xc.GridHelper=function(divID,name,dataView,options){this.root=document.getElementById(divID);if(dataView){this.grid=new xc.Grid(name,dataView,options);}

this.cellPropertyList={width:true,style:true};}

xc.GridHelper.prototype.parse=function(){if(this.root&&this.grid){if(xc.getChildrenByTag(this.root,"table")[0]){this._parseDOM();this._applyDOM();}}

else{throw"Either grid container or grid data source does not exist";}

return this.grid;}

xc.GridHelper.prototype._parseDOM=function(){this.table=xc.getChildrenByTag(this.root,"table");if(this.table[0]){this.thead=xc.getChildrenByTag(this.table[0],"thead");this.tbody=xc.getChildrenByTag(this.table[0],"tbody");this.tfoot=xc.getChildrenByTag(this.table[0],"tfoot");if(this.thead[0]){this.headerRow=xc.getChildrenByTag(this.thead[0],"tr");if(this.headerRow[0]){this.headerCells=xc.getChildrenByTag(this.headerRow[0],"td")}

else{this.headerCells=[];}}

else{this.headerRow=[];this.headerCells=[];}

if(this.tbody[0]){this.bodyRow=xc.getChildrenByTag(this.tbody[0],"tr");if(this.bodyRow[0]){this.bodyCells=xc.getChildrenByTag(this.bodyRow[0],"td")}

else{this.bodyCells=[];}}

else{this.bodyRow=[];this.bodyCells=[];}

if(this.tfoot[0]){this.footerRow=xc.getChildrenByTag(this.tfoot[0],"tr");if(this.footerRow[0]){this.footerCells=xc.getChildrenByTag(this.footerRow[0],"td")}

else{this.footerCells=[];}}

else{this.footerRow=[];this.footerCells=[];}}

else{this.thead=[];this.tbody=[];this.tfoot=[];}}

xc.GridHelper.prototype._copyAttributes=function(elementFrom,propertyList){var attributes={};for(var property in elementFrom){if(property in propertyList){attributes[property]=elementFrom[property];alert(property);}}

return attributes;}

xc.GridHelper.prototype._applyDOM=function(){if(this.bodyCells[0]){this.grid.columnCollection=new xc.GridColumnCollection();for(var i=0;i<this.bodyCells.length;i++){var pattern=new RegExp("\\{(.*?)\\}");var template=this.bodyCells[i].innerHTML;if(template.search(pattern)!=-1&&RegExp.$1!=""){var columnName=RegExp.$1;}

else{for(var j=0;j<this.grid.dataView.columns.getCount();j++){if(this.grid.dataView.columns.getItem(j).position==i){var columnName=this.grid.dataView.columns.getItem(j).columnName;break;}}}

var column=new xc.GridColumn(this.grid,columnName,columnName,template);this.grid.columnCollection.add(column);if(this.bodyCells[i].width&&this.bodyCells[i].width!=0){this.grid.autoColumnWidth=false;this.grid.columnCollection.columns[i].width=this.bodyCells[i].width;}

if(this.bodyCells[i].style.width){var widthStl=parseInt(this.bodyCells[i].style.width);if(widthStl!=0&&widthStl!=NaN){this.grid.autoColumnWidth=false;this.grid.columnCollection.columns[i].width=widthStl;}}}}

if(this.thead[0]){if(this.headerCells[0]){ for(var i=0;i<this.headerCells.length;i++){if(this.grid.columnCollection.columns[i]&&this.headerCells[i].innerHTML!=""){this.grid.columnCollection.columns[i].caption=this.headerCells[i].innerHTML;}}}}

if(!this.thead[0]){this.grid.renderHeader=false;}

if(!this.tfoot[0]){this.grid.renderFooter=false;}}

xc.Slider=function(){this.minimum=1;this.maximum=10;this.railWidth=300;this.currentPosition=1;this.root=document.createElement("div");this._sliderWidth=22;this._sliderXOffset=60;this._sliderYOffset=12;}

xc.Slider.prototype.render=function(){var location=xc.getElementLocation(this.root);this.root.innerHTML="<table border='0' cellpadding='0' cellspacing='0'>"+"<tr><td><img alt='Previous' src='images/slider/larrow.gif' /></td>"+"<td><div style='height: 62px; width: "

+this.railWidth+"px; background-image:url(images/slider/background.gif); background-repeat:repeat-x;'></div>"+"<div style='position:absolute; top: "

+(location.y+this._sliderYOffset)+"px; left: "

+(location.x+this._sliderXOffset)+"px; z-index: 1;'><img alt='Slider' src='images/slider/slider.gif' /></div>"+"</td><td><img alt='Next' src='images/slider/rarrow.gif' /></td></tr></table>";this.slider=this.root.childNodes.item(0).childNodes.item(0).childNodes.item(0).childNodes.item(1).childNodes.item(1);this.slider.style.left=parseInt(this.slider.style.left)+20+"px";}

xc.getElementLocation=function(element){var offsetX=0;var offsetY=0;var parent;for(parent=element;parent;parent=parent.offsetParent){if(parent.offsetLeft){offsetX+=parent.offsetLeft;}

if(parent.offsetTop){offsetY+=parent.offsetTop;}}

return{x:offsetX,y:offsetY};}

xc.getChildrenByTag=function(element,tagName){elements=[];var n=element.childNodes;for(var i=0;i<n.length;i++){if(n[i].nodeType==1){if(n[i].tagName.toLowerCase()==tagName.toLowerCase()){elements.push(n[i]);}}}

return elements;}

xc.encodeString=function(string){return(!/[\x00-\x1f\\"]/.test(string))?string:string.replace(/[\x00-\x1f\\"]/g,function(a){var stringescape={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};var b=stringescape[a];if(b){return b;}

b=a.charCodeAt();return'\\u00'+Math.floor(b/16).toString(16)+(b%16).toString(16);});}

xc.toJSONString=function(obj){switch(typeof obj){case'string':return'"'+xc.encodeString(obj)+'"';case'number':case'boolean':return String(obj);case'object':if(obj){switch(obj.constructor){case Array:var a=[];for(var i=0,l=obj.length;i<l;i++){var json=xc.toJSONString(obj[i]);if(json!='undefined'){a[a.length]=json;}}

return'['+a.join(',')+']';case String:return'"'+xc.encodeString(obj)+'"';case Number:case Boolean:return String(obj);case Date:function f(n){return n<10?'0'+n:n;}

return'"'+this.getFullYear()+'-'+

f(this.getMonth()+1)+'-'+

f(this.getDate())+' '+

f(this.getHours())+':'+

f(this.getMinutes())+':'+

f(this.getSeconds())+'"';case Function:case RegExp:return'undefined';case Object:default:var a=[];for(var i in obj){var json=xc.toJSONString(obj[i]);if(json!='undefined'){a[a.length]=(/^[A-Za-z_]\w*$/.test(i)?i:('"'+xc.encodeString(i)+'"'))+':'+json;}}

return'{'+a.join(',')+'}';}}

return'null';case'function':case'undefined':case'unknown':return'undefined';default:return'null';}}

xc.Collection=function(){this._items=[];this._keys=[];this._key_index={};}

xc.Collection.prototype.getCount=function(){return this._items.length;}

xc.Collection.prototype.insert=function(item,index,key){if(index<0||index>this.getCount()){throw new Error("Invalid collection index");}

if(typeof key=='undefined'){key='';}

for(var i=this.getCount();i>index;i--){this._items[i]=this._items[i-1];this._keys[i]=this._keys[i-1];if(this._keys[i]){this._key_index[this._keys[i]]=i;}}

this._items[index]=item;this._keys[index]=key;if(key){this._key_index[key]=index;}}

xc.Collection.prototype.add=function(item,key){this.insert(item,this.getCount(),key);}

xc.Collection.prototype.getItem=function(index){if(typeof index=='number'){if(index<0||index>this.getCount()){throw new Error("Invalid item index");}

return this._items[index];}else{if(typeof this._key_index[index]=='undefined'){throw new Error("Invalid item key");}

return this._items[this._key_index[index]];}}

xc.Collection.prototype.getKey=function(index){if(index<0||index>this.getCount()){throw new Error("Invalid item index");}

return this._keys[index];}

xc.Collection.prototype.getKeys=function(){var ret=[];for(var i=0;i<this.getCount();i++){if(this._keys[i]){ret[ret.length]=this._keys[i];}}

return ret;}
