EVOLUTION-NINJA
Edit File: jquery.jqGrid.js
!function($){$.fn.jqGrid=function(p){p=$.extend({url:"",height:150,page:1,rowNum:20,records:0,pager:"",colModel:[],rowList:[],colNames:[],sortorder:"asc",sortname:"",imgpath:"",sortascimg:"sort_asc.gif",sortdescimg:"sort_desc.gif",firstimg:"first.gif",previmg:"prev.gif",nextimg:"next.gif",lastimg:"last.gif",altRows:!0,subGrid:!1,subGridModel:[],lastpage:0,lastsort:0,selrow:null,onSelectRow:null,onSortCol:null,ondblClickRow:null,onRightClickRow:null,datatype:"xml",mtype:"GET",viewrecords:!1,recordtext:"Record(s)",loadtext:"Loading...",loadonce:!1,multiselect:!1,multikey:null,selarrrow:[],rowheight:null,loadComplete:null,editurl:null,savedRow:[],shrinkToFit:!0,xReader:{root:"rows",row:"row",page:"rows>page",total:"rows>total",records:"rows>records",repeatitems:!0,cell:"cell",id:"[id]",subgrid:{root:"rows",row:"row",repeatitems:!0,cell:"cell"}},xmlReader:{},jReader:{root:"rows",page:"page",total:"total",records:"records",repeatitems:!0,cell:"cell",id:"id",subgrid:{root:"rows",repeatitems:!0,cell:"cell"}},jsonReader:{}},p||{});var grid={headers:[],cols:[],dragStart:function(t,e){this.resizing={idx:t,startX:e},this.hDiv.style.cursor="e-resize"},dragMove:function(t){if(this.resizing){var e=t-this.resizing.startX,i=this.headers[this.resizing.idx],s=i.width+e;s>30&&(i.el.style.width=s+"px",i.newWidth=s,this.cols[this.resizing.idx].style.width=s+"px",this.newWidth=this.width+e,$("table",this.bDiv).css("width",this.newWidth+"px"),this.hTable.style.width=this.newWidth+"px",this.hDiv.scrollLeft=this.bDiv.scrollLeft)}},dragEnd:function(){if(this.hDiv.style.cursor="default",this.resizing){var t=this.resizing.idx;this.headers[t].width=this.headers[t].newWidth,this.width=this.newWidth,this.resizing=!1}},scroll:function(){this.hDiv.scrollLeft=this.bDiv.scrollLeft}};return $.fn.getUrl=function(){return this[0].p.url},$.fn.getSortName=function(){return this[0].p.sortname},$.fn.getSortOrder=function(){return this[0].p.sortorder},$.fn.getSelectedRow=function(){return this[0].p.selrow},$.fn.getPage=function(){return this[0].p.page},$.fn.getRowNum=function(){return this[0].p.rowNum},$.fn.getMultiRow=function(){return this[0].p.selarrrow},$.fn.getDataType=function(){return this[0].p.datatype},$.fn.getRecords=function(){return this[0].p.records},$.fn.getDataIDs=function(){var t=[];return $("tr:gt(0)",this[0].grid.bDiv).each(function(e){t[e]=this.id}),t},$.fn.setUrl=function(t){return this.each(function(){this.p.url=t})},$.fn.setSortName=function(t){for(var e=this[0],i=0;i<e.p.colModel.length;i++)if(e.p.colModel[i].name==t||e.p.colModel[i].index==t){e.p.lastsort=i,e.p.sortname=t;break}return!1},$.fn.setSortOrder=function(t){return this.each(function(){this.p.sortorder=t})},$.fn.setPage=function(t){return this.each(function(){"number"==typeof t&&t>0&&(this.p.page=t)})},$.fn.setRowNum=function(t){return this.each(function(){"number"==typeof t&&t>0&&(this.p.rowNum=t)})},$.fn.setDataType=function(t){return this.each(function(){this.p.datatype=t})},$.fn.setSelection=function(t){var e,i=this[0],s=$("tbody tr#"+t,i.grid.bDiv);if(!s.html())return!1;if(i.p.multiselect){i.p.selrow=t;var r=i.p.selarrrow.indexOf(i.p.selrow);-1===r?("subgrid"!==$(s).attr("class")&&$(s).addClass("selected"),e=!0,$("#jqg_"+i.p.selrow,i.grid.bDiv).attr("checked",e),i.p.selarrrow.push(i.p.selrow)):("subgrid"!==$(s).attr("class")&&$(s).removeClass("selected"),e=!1,$("#jqg_"+i.p.selrow,i.grid.bDiv).attr("checked",e),i.p.selarrrow.splice(r,1)),i.p.onSelectRow&&i.p.onSelectRow(i.p.selrow,e)}else i.p.selrow&&$("tbody tr#"+i.p.selrow,i.grid.bDiv).removeClass("selected"),i.p.selrow=$(s).attr("id"),"subgrid"!==$(s).attr("class")&&$(s).addClass("selected"),i.p.onSelectRow&&i.p.onSelectRow(i.p.selrow,!0);return!1},$.fn.hideCol=function(t){return this.each(function(){var e=this,i=0;$(this.p.colModel).each(function(s){if(this.name===t&&!this.hidden)return i=$("table",e.grid.hDiv).width(),$("tr th:eq("+s+")",e.grid.hDiv).css({display:"none"}),$("tr",e.grid.bDiv).each(function(t){$("td:eq("+s+")",this).css({display:"none"})}),this.hidden=!0,$("table",e.grid.hDiv).width(i),!1})})},$.fn.showCol=function(t){return this.each(function(){$t=this;$($t.p.colModel).each(function(e){if(this.name===t&&this.hidden)return $("tr th:eq("+e+")",$t.grid.hDiv).css("display",""),$("tr",$t.grid.bDiv).each(function(){$("td:eq("+e+")",this).css("display","")}),this.hidden=!1,!1})})},$.fn.editRow=function(t,e,i){var s,r,d,o=this[0],a=0,l=null,n=[],p=this;return o.p.multiselect||"0"===($("#"+t,o.grid.bDiv).attr("editable")||"0")&&($("#"+t+" td",o.grid.bDiv).each(function(e){if(s=o.p.colModel[e].name,d=!0===o.p.colModel[e].hidden,"cb"!==s&&"subgrid"!==s&&!0===o.p.colModel[e].editable&&!d){null===l&&(l=e),r=$(this).html().replace(/\ \;/gi,""),n[s]=r,$(this).html("");var i=$.extend(o.p.colModel[e].editoptions||{},{id:t+"_"+s,name:s});o.p.colModel[e].edittype||(o.p.colModel[e].edittype="text");var p=function(t,e,i){var s="";switch(t){case"textarea":s=document.createElement("textarea"),e.rows||(e.rows=1),$(s).attr(e),s.innerHTML=i;break;case"checkbox":(s=document.createElement("input")).type="checkbox",s.value=i,i==e.value.split(":")[0]&&(s.checked=!0);break;case"select":var r,d,o=e.value.split(";");s=document.createElement("select"),$(s).attr({id:e.id,name:e.name});for(var a=0;a<o.length;a++)r=o[a].split(":"),(d=document.createElement("option")).value=r[0],d.innerHTML=r[1],r[1]==i&&(d.selected="selected"),s.appendChild(d);break;case"text":(s=document.createElement("input")).type="text",e.size||(e.size=i.length),$(s).attr(e),s.value=i}return s}(o.p.colModel[e].edittype,i,r);$(p).addClass("editable"),$(this).append(p),a++}}),a>0&&(n.id=t,o.p.savedRow.push(n),$("#"+t,o.grid.bDiv).attr("editable","1"),$("#"+t+" td:eq("+l+") input",o.grid.bDiv).focus(),!0===e&&$("#"+t,o.grid.bDiv).bind("keydown",function(e){27===e.keyCode&&p.restoreRow(t),13===e.keyCode&&p.saveRow(t)}),"function"==typeof i&&i(t))),!1},$.fn.saveRow=function(t,e,i,s,r){var d,o,a,l,n=this[0],p={},c=this;return a=$("#"+t,n.grid.bDiv).attr("editable"),i=i||n.p.editurl,"1"===a&&i&&($("#"+t+" td",n.grid.bDiv).each(function(t){"cb"!==(d=n.p.colModel[t].name)&&"subgrid"!==d&&!0===n.p.colModel[t].editable&&(!0===n.p.colModel[t].hidden?p[d]=$(this).html():p[d]=$("input, select>option:selected, textarea",this).val())}),p&&(p.id=t,s&&$.extend(p,s)),n.grid.hDiv.loading||(n.grid.hDiv.loading=!0,$("div.loading",n.grid.hDiv).fadeIn("fast"),$.post(i,p,function(i,s){if("success"===s)if(!0===("function"!=typeof e||e(i))){$("#"+t+" td",n.grid.bDiv).each(function(t){if("cb"!==(d=n.p.colModel[t].name)&&"subgrid"!==d&&!0===n.p.colModel[t].editable){switch(n.p.colModel[t].edittype){case"select":o=$("select>option:selected",this).text();break;case"checkbox":var e=n.p.colModel[t].editoptions.value.split(":")||["Yes","No"];o=$("input",this).attr("checked")?e[0]:e[1];break;case"text":case"textarea":o=$("input, textarea",this).val()}$(this).empty(),$(this).html(o||" ")}}),$("#"+t,n.grid.bDiv).attr("editable","0");for(var a=0;a<n.p.savedRow.length;a++)if(n.p.savedRow[a].id===t){l=a;break}l>=0&&n.p.savedRow.splice(l,1),"function"==typeof r&&r(t,i)}else c.restoreRow(t);else alert("Error Row: "+t+" Result: "+i+" Status: "+s)}),n.grid.hDiv.loading=!1,$("div.loading",n.grid.hDiv).fadeOut("fast"),$("#"+t,n.grid.bDiv).unbind("keydown"))),!1},$.fn.restoreRow=function(t){for(var e,i,s=this[0],r=0;r<s.p.savedRow.length;r++)if(s.p.savedRow[r].id===t){i=r;break}return i>=0&&($("#"+t+" td",s.grid.bDiv).each(function(t){"cb"!==(e=s.p.colModel[t].name)&&"subgrid"!==e&&1==s.p.colModel[t].editable&&($(this).empty(),$(this).html(s.p.savedRow[i][e]||" "))}),$("#"+t,s.grid.bDiv).attr("editable","0"),s.p.savedRow.splice(i,1)),!1},$.fn.getRowData=function(t){var e={};if(t){var i,s=this[0];$("#"+t+" td",s.grid.bDiv).each(function(t){"cb"!==(i=s.p.colModel[t].name)&&"subgrid"!==i&&(e[i]=$(this).text().replace(/\ \;/gi,""))})}return e},$.fn.delRowData=function(t){var e=!1;return t&&this.each(function(){$("#"+t,this.grid.bDiv).each(function(){$(this).remove(),e=!0})}),e},$.fn.setRowData=function(t,e){var i,s=!1,r=!0;return this.each(function(){var d=this;$("#"+t,d.grid.bDiv).attr("id")==t&&e&&(s=!0,$(this.p.colModel).each(function(o){i=this.name,$(e).each(function(){if(this[i])return $("#"+t,d.grid.bDiv).find("td:eq("+o+")").html(this[i]),r=!0,!1;s=s&&r})}))}),s},$.fn.addRowData=function(e,i,s){s||(s="last");var r,d,o,a=!1,l=0,n=0;return i&&this.each(function(){t=this,(d=document.createElement("tr")).id=e||t.p.records+1,t.p.multiselect&&(o=$("<td></td>"),$(o[0],t.grid.bDiv).html("<input type='checkbox' id='jqg_"+e+"' class='cbox'/>"),d.appendChild(o[0]),l=1),t.p.subGrid&&(t.addSubGrid(t.grid.bDiv,d,l),n=1);for(var p=l+n;p<this.p.colModel.length;p++)r=this.p.colModel[p].name,o=$("<td></td>"),$(o[0]).html(" "),t.formatCol($(o[0],t.grid.bDiv),p),$(i).each(function(t){if(this[r])return $(o[0]).html(this[r]),!1}),d.appendChild(o[0]);"last"===s?$("tbody",t.grid.bDiv).append(d):$("tbody tr:eq(1)",t.grid.bDiv).before(d),t.p.records++,$.browser.msie||(t.scrollLeft=t.scrollLeft,$("tbody tr:eq(1) td",t.grid.bDiv).each(function(e){$(this).css("width",t.grid.headers[e].width+"px"),t.grid.cols[e]=this})),a=!0}),a},$.fn.sortGrid=function(t,e){var i=this[0],s=-1;t||(t=i.p.sortname);for(var r=0;r<i.p.colModel.length;r++)if(i.p.colModel[r].index==t||i.p.colModel[r].name==t){s=r;break}if(-1!=s){var d=i.p.colModel[s].sortable;"boolean"!=typeof d&&(d=!0),"boolean"!=typeof e&&(e=!1),d&&i.sortData(t,s,e)}return!1},$.fn.GridUnload=function(){return this.each(function(){var t={id:$(this).attr("id"),cl:$(this).attr("class"),cellSpacing:$(this).attr("cellspacing")||"0",cellPadding:$(this).attr("cellpadding")||"0"};this.p.pager&&($(this.p.pager).unbind(),$(this.p.pager).empty()),$(this).unbind();var e=document.createElement("table");$(e).attr({id:t.id,cellSpacing:t.cellSpacing,cellPadding:t.cellPadding}),e.className=t.cl,$(this.grid.bDiv).remove(),$(this.grid.hDiv).before(e).remove(),this.p=null,this.grid=null}),!1},""!==p.imgpath&&(p.imgpath=p.imgpath+"/",p.sortascimg=p.imgpath+p.sortascimg,p.sortdescimg=p.imgpath+p.sortdescimg,p.firstimg=p.imgpath+p.firstimg,p.previmg=p.imgpath+p.previmg,p.nextimg=p.imgpath+p.nextimg,p.lastimg=p.imgpath+p.lastimg),this.each(function(){if(this.grid)return!1;this.p=p,p=null;var ts=this;if(0===this.p.colNames.length||this.p.colNames.length!==this.p.colModel.length)return alert("Length of colNames <> colModel or 0!"),!1;var onSelectRow=this.p.onSelectRow,ondblClickRow=this.p.ondblClickRow,onSortCol=this.p.onSortCol,loadComplete=this.p.loadComplete,onRightClickRow=this.p.onRightClickRow;"function"!=typeof onSelectRow&&(onSelectRow=!1),"function"!=typeof ondblClickRow&&(ondblClickRow=!1),"function"!=typeof onSortCol&&(onSortCol=!1),"function"!=typeof loadComplete&&(loadComplete=!1),"function"!=typeof onRightClickRow&&(onRightClickRow=!1),Array.indexOf||(Array.prototype.indexOf=function(t){for(var e=0;e<this.length;e++)if(this[e]==t)return e;return-1});var sortkeys=["shiftKey","altKey","ctrlKey"];-1==sortkeys.indexOf(ts.p.multikey)&&(ts.p.multikey=null);var formatCol=function(t,e){var i=ts.p.colModel[e].align||"left";return $(t).css("text-align",i),ts.p.colModel[e].hidden&&$(t).css("display","none"),!1},resizeFirstRow=function(t){return $("tbody tr:eq(1) td",t).each(function(t){$(this).css("width",grid.headers[t].width+"px"),grid.cols[t]=this}),!1},addCell=function(t,e,i,s){var r;return r=document.createElement("td"),$(r,t).html(i),formatCol($(r,t),s),e.appendChild(r),!1},addMulti=function(t,e){var i,s;s=document.createElement("td"),i="jqg_"+e.id,$(s,t).html("<input type='checkbox' id='"+i+"' class='cbox'/>"),formatCol($(s,t),0),e.appendChild(s)},reader=function(t){for(var e=[],i=0,s=0;s<ts.p.colModel.length;s++){var r;"cb"!==(r=ts.p.colModel[s]).name&&"subgrid"!==r.name&&(e[i]="xml"==t?r.xmlmap||r.name:r.jsonmap||r.name,i++)}return e},addXmlData=function(t,e){if(!t)return!1;$("tbody tr:gt(0)",e).remove();var i,s,r=0,d=0,o=0,a=null;if(ts.p.xmlReader.repeatitems||(a=reader("xml")),ts.p.keyIndex)l=function(t){return a.length>=ts.p.keyIndex?$(a[ts.p.keyIndex],t).text():$(ts.p.xmlReader.cell+":eq("+ts.p.keyIndex+")",t).text()};else if(-1===(s=ts.p.xmlReader.id).indexOf("["))var l=function(t,e){return $(s,t).text()||e};else var l=function(t,e){return t.getAttribute(s.replace(/[\[\]]/g,""))||e};return $(ts.p.xmlReader.page,t).each(function(){ts.p.page=this.textContent||this.text}),$(ts.p.xmlReader.total,t).each(function(){ts.p.lastpage=this.textContent||this.text}),$(ts.p.xmlReader.records,t).each(function(){ts.p.records=this.textContent||this.text}),$(ts.p.xmlReader.root+">"+ts.p.xmlReader.row,t).each(function(t){if((i=document.createElement("tr")).id=l(this,t+1),ts.p.multiselect&&(addMulti(e,i),r=1),ts.p.subGrid&&(addSubGrid(e,i,r),d=1),!0===ts.p.xmlReader.repeatitems)$(ts.p.xmlReader.cell,this).each(function(t){addCell(e,i,this.textContent||this.text||" ",t+r+d)});else for(var s,n=0;n<a.length;n++)s=$(a[n],this).text()||" ",addCell(e,i,s,n+r+d);$("tbody",e).append(i),ts.p.rowheight&&(o+=ts.p.rowheight)}),t=null,isMozilla?(ts.scrollLeft=ts.scrollLeft,resizeFirstRow(e)):isMSIE||(resizeFirstRow(e),ts.scrollLeft=ts.scrollLeft),ts.scrollTop=0,ts.p.rowheight&&$(grid.bDiv).css({height:o+2+"px"}),!0===ts.p.altRows&&$("tbody tr:odd",e).addClass("alt"),grid.hDiv.loading=!1,$("div.loading",grid.hDiv).fadeOut("fast"),updatepager(),!1},addJSONData=function(t,e){if(!t)return!1;$("tbody tr:gt(0)",e).remove();var i,s,r,d,o=0,a=0,l=0;if(ts.p.page=t[ts.p.jsonReader.page],ts.p.lastpage=t[ts.p.jsonReader.total],ts.p.records=t[ts.p.jsonReader.records],d=ts.p.keyIndex?ts.p.keyIndex:ts.p.jsonReader.id,!ts.p.jsonReader.repeatitems)var n=reader("json");if(r=t[ts.p.jsonReader.root])for(var p=0;p<r.length;p++){if(s=r[p],(i=document.createElement("tr")).id=s[d]||p+1,ts.p.multiselect&&(addMulti(e,i),o=1),ts.p.subGrid&&(addSubGrid(e,i,o),l=1),!0===ts.p.jsonReader.repeatitems){ts.p.jsonReader.cell&&(s=s[ts.p.jsonReader.cell]);for(var c=0;c<s.length;c++)addCell(e,i,s[c]||" ",c+o+l)}else for(c=0;c<n.length;c++)addCell(e,i,s[n[c]]||" ",c+o+l);$("tbody",e).append(i),ts.p.rowheight&&(a+=ts.p.rowheight)}return t=null,isMozilla?(ts.scrollLeft=ts.scrollLeft,resizeFirstRow(e)):isMSIE||(resizeFirstRow(e),ts.scrollLeft=ts.scrollLeft),ts.scrollTop=0,ts.p.rowheight&&$(grid.bDiv).css({height:a+2+"px"}),!0===ts.p.altRows&&$("tbody tr:odd",e).addClass("alt"),grid.hDiv.loading=!1,$("div.loading",grid.hDiv).fadeOut("fast"),updatepager(),!1},updatepager=function(){return ts.p.pager&&($("span:eq(1)",ts.p.pager).html("/ "+ts.p.lastpage),$("input",ts.p.pager).val(ts.p.page),ts.p.viewrecords&&$(ts.p.pager).find("span:eq(0)").html(ts.p.records+" "+ts.p.recordtext+" ")),!1},populate=function(){if(!grid.hDiv.loading){grid.hDiv.loading=!0,$("div.loading",grid.hDiv).fadeIn("fast");var gdata={page:ts.p.page,rows:ts.p.rowNum,sidx:ts.p.sortname,sord:ts.p.sortorder,_nd:(new Date).getTime()};switch(ts.p.datatype){case"json":$.ajax({url:ts.p.url,type:ts.p.mtype,datatype:"json",data:gdata,complete:function(JSON){addJSONData(eval("("+JSON.responseText+")"),ts.grid.bDiv),loadComplete&&loadComplete()}}),ts.p.loadonce&&(ts.p.datatype="local");break;case"xml":$.ajax({url:ts.p.url,type:ts.p.mtype,dataType:"xml",data:gdata,complete:function(t){addXmlData(t.responseXML,ts.grid.bDiv),loadComplete&&loadComplete()}}),ts.p.loadonce&&(ts.p.datatype="local");break;case"xmlstring":addXmlData(stringToDoc(ts.p.xmlstr),ts.grid.bDiv),ts.p.xmlstr=null,ts.p.datatype="local",loadComplete&&loadComplete();break;case"jsonstring":addJSONData(eval("("+ts.p.jsonstr+")"),ts.grid.bDiv),ts.p.jsonstr=null,ts.p.datatype="local",loadComplete&&loadComplete();break;case"local":sortArrayData()}}return!1},stringToDoc=function(t){var e;if(isSafari2){var i=document.createElement("div");i.innerHTML=t,e=i,i.responseXML=i}else try{e=(new DOMParser).parseFromString(t,"text/xml")}catch(i){(e=new ActiveXObject("Microsoft.XMLDOM")).async=!1,e.loadXML(t)}return e&&e.documentElement&&"parsererror"!=e.documentElement.tagName?e:null},sortArrayData=function(){var t="asc"==ts.p.sortorder?1:-1,e=ts.p.lastsort>=0?ts.p.lastsort:0,i=ts.p.colModel[e].sorttype;findSortKey="float"==i?function(t){var e=parseFloat(t.html().replace(/,/g,""));return isNaN(e)?0:e}:"int"==i?function(t){return IntNum(t.html().replace(/,/g,""))}:"date"==i?function(t){var i=ts.p.colModel[e].datefmt||"Y-m-d";return parseDate(i,t.html()).getTime()}:function(t){return t.html().toUpperCase()};var s=$(grid.bDiv).find("tbody > tr:gt(0)").get();$.each(s,function(t,i){i.sortKey=findSortKey($(i).children("td").eq(e))}),s.sort(function(e,i){return e.sortKey<i.sortKey?-t:e.sortKey>i.sortKey?t:0}),$.each(s,function(t,e){$("tbody",grid.bDiv).append(e),e.sortKey=null}),isMozilla?(ts.scrollLeft=ts.scrollLeft,resizeFirstRow(grid.bDiv)):isMSIE||(resizeFirstRow(grid.bDiv),ts.scrollLeft=ts.scrollLeft),ts.scrollTop=0,grid.hDiv.loading=!1,$("div.loading",grid.hDiv).fadeOut("fast")},parseDate=function(t,e){var i={m:1,d:1,y:1970,h:0,i:0,s:0};t=t.toLowerCase(),e=e.split(/[\\\/:_;.\s-]/),t=t.split(/[\\\/:_;.\s-]/);for(var s=0;s<t.length;s++)i[t[s]]=IntNum(e[s],i[t[s]]);i.m=parseInt(i.m)-1;var r=i.y;return r>=70&&r<=99?i.y=1900+i.y:r>=0&&r<=69&&(i.y=2e3+i.y),new Date(i.y,i.m,i.d,i.h,i.i,i.s,0)},addSubGrid=function(t,e,i){var s,r;return s=document.createElement("td"),$(s,t).html("<img src='"+ts.p.imgpath+"plus.gif'/>").toggle(function(){$(this).html("<img src='"+ts.p.imgpath+"minus.gif'/>"),r=$(this).parent(),populatesubgrid(r);var t="<tr class='subgrid'>"+(1==i?"<td></td>":"")+"<td><img src='"+ts.p.imgpath+"line3.gif'/></td><td colspan='"+parseInt(ts.p.colNames.length-1)+"'><div id='sg_"+$(r).attr("id")+"' class='tablediv'>";$(this).parent().after(t+"</div></td></tr>"),$(".tablediv",ts).css("width",ts.grid.width-20+"px")},function(){$(this).parent().next().remove(".subgrid"),$(this).html("<img src='"+ts.p.imgpath+"plus.gif'/>")}),formatCol($(s,t),i),e.appendChild(s),!1},populatesubgrid=function(t){var e,i;if(i={id:e=$(t).attr("id")},!ts.p.subGridModel[0])return!1;if(ts.p.subGridModel[0].params)for(var s=0;s<ts.p.subGridModel[0].params.length;s++)for(var r=0;r<ts.p.colModel.length;r++)ts.p.colModel[r].name==ts.p.subGridModel[0].params[s]&&(i[ts.p.colModel[r].name]=$("td:eq("+r+")",t).text().replace(/\ \;/gi,""));if(!grid.hDiv.loading)switch(grid.hDiv.loading=!0,$("div.loading",grid.hDiv).fadeIn("fast"),ts.p.datatype){case"xml":$.ajax({type:ts.p.mtype,url:ts.p.subGridUrl,dataType:"xml",data:i,complete:function(t){subGridJXml(t.responseXML,e)}});break;case"json":$.ajax({type:ts.p.mtype,url:ts.p.subGridUrl,dataType:"json",data:i,complete:function(t){subGridJXml(t,e)}})}return!1},subGridCell=function(t,e,i){var s;(s=document.createElement("div")).className="celldiv",$(s).html(e),$(s).width(ts.p.subGridModel[0].width[i]||80),t.appendChild(s)},subGridJXml=function(sjxml,sbid){var trdiv,tddiv,result="",i,cur,sgmap,dummy=document.createElement("span");for(trdiv=document.createElement("div"),trdiv.className="rowdiv",i=0;i<ts.p.subGridModel[0].name.length;i++)tddiv=document.createElement("div"),tddiv.className="celldivth",$(tddiv).html(ts.p.subGridModel[0].name[i]),$(tddiv).width(ts.p.subGridModel[0].width[i]),trdiv.appendChild(tddiv);if(dummy.appendChild(trdiv),sjxml){if("xml"===ts.p.datatype)sgmap=ts.p.xmlReader.subgrid,$(sgmap.root+">"+sgmap.row,sjxml).each(function(){if((trdiv=document.createElement("div")).className="rowdiv",!0===sgmap.repeatitems)$(sgmap.cell,this).each(function(t){subGridCell(trdiv,this.textContent||this.text||" ",t)});else{var t=ts.p.subGridModel[0].mapping;if(t)for(i=0;i<t.length;i++)subGridCell(trdiv,$(t[i],this).text()||" ",i)}dummy.appendChild(trdiv)});else for(sjxml=eval("("+sjxml.responseText+")"),sgmap=ts.p.jsonReader.subgrid,i=0;i<sjxml[sgmap.root].length;i++){if(cur=sjxml[sgmap.root][i],trdiv=document.createElement("div"),trdiv.className="rowdiv",!0===sgmap.repeatitems){sgmap.cell&&(cur=cur[sgmap.cell]);for(var j=0;j<cur.length;j++)subGridCell(trdiv,cur[j]||" ",j)}else for(var f=ts.p.subGridModel[0].mapping,j=0;j<f.length;j++)subGridCell(trdiv,cur[f[j]]||" ",j);dummy.appendChild(trdiv)}$("#sg_"+sbid).append($(dummy).html()),sjxml=null,grid.hDiv.loading=!1,$("div.loading",grid.hDiv).fadeOut("fast")}return!1},setPager=function(){if($(ts.p.pager).append('<span></span> <img id="first" src="'+ts.p.firstimg+'"> <img id="prev" src="'+ts.p.previmg+'"> <input class="selbox" type="text" size="3" maxlength="5" value="0"/><span></span> <img id="next" src="'+ts.p.nextimg+'"> <img id="last" src="'+ts.p.lastimg+'">'),ts.p.rowList.length>0){for(var t="<SELECT class='selbox'>",e=0;e<ts.p.rowList.length;e++)t+="<OPTION value="+ts.p.rowList[e]+">"+ts.p.rowList[e];t+="</SELECT>",$(ts.p.pager).append(" "+t),$(ts.p.pager).find("select").bind("change",function(){ts.p.rowNum=this.value>0?this.value:ts.p.rowNum,populate(),ts.p.selrow=null})}return $(ts.p.pager).find("img").click(function(){var t=IntNum(ts.p.page),e=IntNum(ts.p.lastpage),i=!1,s=!0,r=!0,d=!0,o=!0;0===e||1===e?(s=!1,r=!1,d=!1,o=!1):e>1&&t>=1?1===t?(s=!1,r=!1):t>1&&t<e||t===e&&(d=!1,o=!1):e>1&&0===t&&(d=!1,o=!1,t=e-1),"first"===$(this).attr("id")&&s&&(ts.p.page=1,populate(),i=!0),"prev"===$(this).attr("id")&&r&&(ts.p.page=t-1,populate(),i=!0),"next"===$(this).attr("id")&&d&&(ts.p.page=t+1,populate(),i=!0),"last"===$(this).attr("id")&&o&&(ts.p.page=e,populate(),i=!0),i&&(ts.p.selrow=null,ts.p.multiselect&&(ts.p.selarrrow=[],$("#cb_jqg",ts.grid.hDiv).attr("checked",!1)),ts.p.savedRow=[])}).hover(function(){$(this).addClass("jsHover")},function(){$(this).removeClass("jsHover")}),$("input",ts.p.pager).keypress(function(t){return 13==(t.charCode?t.charCode:t.keyCode?t.keyCode:0)?(ts.p.page=$(this).val()>0?$(this).val():ts.p.page,populate(),ts.p.selrow=null,!1):this}),!1},sortData=function(t,e,i){i||(ts.p.lastsort===e?"asc"===ts.p.sortorder?ts.p.sortorder="desc":"desc"===ts.p.sortorder&&(ts.p.sortorder="asc"):ts.p.sortorder="asc",ts.p.page=1);var s="asc"===ts.p.sortorder?ts.p.sortascimg:ts.p.sortdescimg;s="<img src='"+s+"'>";var r=$("thead:first",grid.hDiv).get(0);return $("tr th div#"+ts.p.colModel[ts.p.lastsort].name+" img",r).remove(),$("tr th div#"+t,r).append(s),ts.p.lastsort=e,ts.p.sortname=ts.p.colModel[e].index||t,onSortCol&&onSortCol(t,e),ts.p.selrow&&"local"==ts.p.datatype&&!ts.p.multiselect&&$("#"+ts.p.selrow,grid.bDiv).removeClass("selected"),ts.p.selrow=null,ts.p.multiselect&&"local"!==ts.p.datatype&&(ts.p.selarrrow=[],$("#cb_jqg",ts.grid.hDiv).attr("checked",!1)),ts.p.savedRow=[],populate(),!1},setGridWidth=function(){for(var t=0,e=0;e<ts.p.colModel.length;e++)t+=IntNum(ts.p.colModel[e].width||150);var i=ts.p.width?ts.p.width:t;for(e=0;e<ts.p.colModel.length;e++)ts.p.shrinkToFit||(ts.p.colModel[e].owidth=ts.p.colModel[e].width),ts.p.colModel[e].width=Math.round(i/t*ts.p.colModel[e].width);return!1},IntNum=function(t,e){return t=parseInt(t,10),isNaN(t)?e||0:t};this.p.subGrid&&(this.p.colNames.unshift(""),this.p.colModel.unshift({name:"subgrid",width:25,sortable:!1,resizable:!1})),this.p.multiselect&&(this.p.colNames.unshift("<input id='cb_jqg' type='checkbox'/>"),this.p.colModel.unshift({name:"cb",width:25,sortable:!1,resizable:!1})),this.p.xmlReader=$.extend(this.p.xReader,this.p.xmlReader),this.p.jsonReader=$.extend(this.p.jReader,this.p.jsonReader),this.p.loadonce&&(this.p.pager=!1),this.p.width&&setGridWidth();var thead=document.createElement("thead"),trow=document.createElement("tr");thead.appendChild(trow);var i=0,th,idn,thdiv,w,res,sort;for(var col in this.p.keyIndex=!1,this.p.colModel){if(this.p.colModel[col].key){this.p.keyIndex=i;break}i++}for(i=0;i<this.p.colNames.length;i++)th=document.createElement("th"),idn=ts.p.colModel[i].name,idn=idn||i+1,thdiv=document.createElement("div"),thdiv.id=""+idn,$(thdiv).html(ts.p.colNames[i]+" "),th.appendChild(thdiv),trow.appendChild(th);this.p.multiselect&&$("#cb_jqg",trow).addClass("cbox").click(function(){this.checked?($("[@id^=jqg_]",grid.bDiv).attr("checked",!0),$("tr:gt(0)",ts.grid.bDiv).each(function(t){$(this).addClass("selected"),ts.p.selarrrow[t]=this.id})):($("[@id^=jqg_]",grid.bDiv).attr("checked",!1),$("tr",grid.bDiv).removeClass("selected"),ts.p.selarrrow=[])}),this.appendChild(thead),thead=$("thead:first",ts).get(0),$("tr:first th",thead).each(function(t){w=ts.p.colModel[t].width||150,void 0===ts.p.colModel[t].resizable&&(ts.p.colModel[t].resizable=!0),res=document.createElement("span"),$(res).html(" "),ts.p.colModel[t].resizable?$(res).mousedown(function(e){return grid.dragStart(t,e.clientX),!1}):$(res).css("cursor","default"),$(this).width(w).prepend(res),ts.p.colModel[t].hidden&&$(this).css("display","none"),grid.headers[t]={width:w,el:this}}),$("tr:first th div",thead).each(function(t){"boolean"!=typeof(sort=ts.p.colModel[t].sortable)&&(sort=!0),sort&&($(this).css("cursor","pointer"),$(this).click(function(){sortData(this.id,t)}))});var tbody=document.createElement("tbody"),td,ptr;for(trow=document.createElement("tr"),trow.style.display="none",tbody.appendChild(trow),i=0;i<ts.p.colNames.length;i++)td=document.createElement("td"),trow.appendChild(td);this.appendChild(tbody);var gw=0;$("tbody tr:first td",ts).each(function(t){w=ts.p.colModel[t].width||150,$(this).css("width",w+"px"),ts.p.colModel[t].hidden?$(this).css("display","none"):w+=IntNum($(this).css("padding-left"))+IntNum($(this).css("padding-right"))+IntNum($(this).css("border-left-width"))+IntNum($(this).css("border-right-width")),grid.cols[t]=this,gw+=w}),grid.width=$(this).width(),0==grid.width&&(grid.width=gw),grid.hTable=document.createElement("table"),grid.hTable.cellSpacing="0",grid.hTable.cellPadding="0",grid.hTable.className="scroll",grid.hTable.appendChild(thead),grid.hDiv=document.createElement("div"),$(grid.hDiv).css({width:grid.width+"px",overflow:"hidden"}).prepend('<div class="loading">'+ts.p.loadtext+"</div>").append(grid.hTable).bind("selectstart",function(){return!1}),$(this).mouseover(function(t){return td=t.target||t.srcElement,ptr=$(td).parents("tr"),"subgrid"!==$(ptr).attr("class")&&($(ptr).addClass("over"),td.title=$(td).text()),!1}).mouseout(function(t){return td=t.target||t.srcElement,ptr=$(td).parents("tr"),$(ptr).removeClass("over"),td.title="",!1}).css("width",grid.width+"px").before(grid.hDiv).click(function(t){ts.p.multikey?t[ts.p.multikey]?(td=t.target||t.srcElement,ptr=$(td).parents("tr"),$(ts).setSelection($(ptr).attr("id"))):(td=t.target||t.srcElement,ptr=$(td).parent("td"),null!==$(ptr).html()&&(td=void 0!==(td=$("[@id^=jqg_]",ptr).attr("checked"))&&td,$("[@id^=jqg_]",ptr).attr("checked",!td))):(td=t.target||t.srcElement,ptr=$(td).parents("tr"),$(ts).setSelection($(ptr).attr("id")))}).bind("reloadGrid",function(t){ts.p.selrow=null,ts.p.multiselect&&(ts.p.selarrrow=[],$("#cb_jqg",ts.grid.hDiv).attr("checked",!1)),populate()}),ondblClickRow&&$(this).dblclick(function(t){td=t.target||t.srcElement,ptr=$(td).parents("tr"),ts.p.ondblClickRow($(ptr).attr("id"))}),onRightClickRow&&$(this).bind("contextmenu",function(t){return td=t.target||t.srcElement,ptr=$(td).parents("tr"),ts.p.onRightClickRow($(ptr).attr("id")),!1}),grid.bDiv=document.createElement("div"),$(grid.bDiv).scroll(function(t){grid.scroll()}).css({height:ts.p.height+(isNaN(ts.p.height)?"":"px"),padding:"0px",margin:"0px",overflow:"auto",width:grid.width+17+"px"}).append(this);var isMSIE=!!$.browser.msie,isMozilla=!!$.browser.mozilla,isSafari2=!(!$.browser.safari||!(parseInt($.browser.version)<=2||parseInt($.browser.version)<=419));isMSIE?(2===$("tbody",this).size()&&$("tbody:first",this).remove(),ts.p.multikey&&$(grid.bDiv).bind("selectstart",function(){return!1})):ts.p.multikey&&$(grid.bDiv).bind("mousedown",function(){return!1}),$(grid.hDiv).mousemove(function(t){grid.dragMove(t.clientX)}).after(grid.bDiv),ts.p.pager&&("scroll"===$(ts.p.pager).attr("class")&&$(ts.p.pager).css({width:grid.width+"px",overflow:"hidden"}),setPager()),$(document).mouseup(function(t){grid.dragEnd()}),ts.formatCol=function(t,e){formatCol(t,e)},ts.addSubGrid=function(t,e,i){addSubGrid(t,e,i)},ts.sortData=function(t,e,i){sortData(t,e,i)},this.grid=grid,populate(),ts.p.shrinkToFit||$("tr:first th",thead).each(function(t){var e=ts.p.colModel[t].owidth,i=e-ts.p.colModel[t].width;i>0&&(grid.headers[t].width=e,$(this).add(grid.cols[t]).width(e),grid.width=grid.width+i,$("table",grid.bDiv).add(grid.hTable).width(grid.width),grid.hDiv.scrollLeft=grid.bDiv.scrollLeft)}),$(window).unload(function(){$(this).unbind(),this.p=null,this.grid=null,$(ts.p.pager).unbind()})})}}(jQuery);