function tableToGrid(a,b,c){c=$.extend({sortable:true},c||{});jQuery(a).each(function(){if(this.grid){return}jQuery(this).width("99%");var o=jQuery(this).width();var n=jQuery("tr td:first-child input[type=checkbox]:first",jQuery(this));var e=jQuery("tr td:first-child input[type=radio]:first",jQuery(this));var l=n.length>0;var g=!l&&e.length>0;var m=l||g;var j=[];var f=[];jQuery("th",jQuery(this)).each(function(){if(j.length===0&&m){j.push({name:"__selection__",index:"__selection__",width:0,hidden:true});f.push("__selection__")}else{j.push({name:jQuery(this).attr("id")||jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(" ").join("_"),index:jQuery(this).attr("id")||jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(" ").join("_"),width:jQuery(this).width()||150,sortable:c.sortable});f.push(jQuery(this).html())}});var h=[];var d=[];var p=[];jQuery("tbody > tr",jQuery(this)).each(function(){var q={};var r=0;jQuery("td",jQuery(this)).each(function(){if(r===0&&m){var s=jQuery("input",jQuery(this));var t=s.attr("value");d.push(t||h.length);if(s.attr("checked")){p.push(t)}q[j[r].name]=s.attr("value")}else{q[j[r].name]=jQuery(this).html()}r++});if(r>0){h.push(q)}});jQuery(this).empty();jQuery(this).addClass("scroll");jQuery(this).jqGrid(jQuery.extend({datatype:"local",width:o,colNames:f,colModel:j,multiselect:l},b||{}));var k;for(k=0;k<h.length;k++){var i=null;if(d.length>0){i=d[k];if(i&&i.replace){i=encodeURIComponent(i).replace(/[.\-%]/g,"_")}}if(i===null){i=k+1}jQuery(this).jqGrid("addRowData",i,h[k])}for(k=0;k<p.length;k++){jQuery(this).jqGrid("setSelection",p[k])}})};
