text: /*
  
   (c) 2009-2010 Michael Leibman (michael.leibman@gmail.com)
   All rights reserved.
  
   SlickGrid v1.3.2
  
   TODO:
   - frozen columns
   - consistent events (EventHelper?  jQuery events?)
  
  
   OPTIONS:
   rowHeight                - (default 25px) Row height in pixels.
   enableAddRow             - (default false) If true, a blank row will be displayed at the bottom - typing values in that row will add a new one.
   leaveSpaceForNewRows     - (default false)
   editable                 - (default false) If false, no cells will be switched into edit mode.
   autoEdit                 - (default true) Cell will not automatically go into edit mode when selected.
   enableCellNavigation     - (default true) If false, no cells will be selectable.
   defaultColumnWidth       - (default 80px) Default column width in pixels (if columns[cell].width is not specified).
   enableColumnReorder      - (default true) Allows the user to reorder columns.
   asyncEditorLoading       - (default false) Makes cell editors load asynchronously after a small delay.
   This greatly increases keyboard navigation speed.
   asyncEditorLoadDelay     - (default 100msec) Delay after which cell editor is loaded. Ignored unless asyncEditorLoading is true.
   forceFitColumns          - (default false) Force column sizes to fit into the viewport (avoid horizontal scrolling).
   enableAsyncPostRender    - (default false) If true, async post rendering will occur and asyncPostRender delegates on columns will be called.
   asyncPostRenderDelay     - (default 60msec) Delay after which async post renderer delegate is called.
   autoHeight               - (default false) If true, vertically resizes to fit all rows.
   editorLock               - (default Slick.GlobalEditorLock) A Slick.EditorLock instance to use for controlling concurrent data edits.
   showSecondaryHeaderRow   - (default false) If true, an extra blank (to be populated externally) row will be displayed just below the header columns.
   secondaryHeaderRowHeight - (default 25px) The height of the secondary header row.
   syncColumnCellResize     - (default false) Synchronously resize column cells when column headers are resized
   rowCssClasses            - (default null) A function which (given a row's data item as an argument) returns a space-delimited string of CSS classes that will be applied to the slick-row element. Note that this should be fast, as it is called every time a row is displayed.
  
  
   COLUMN DEFINITION (columns) OPTIONS:
   id                  - Column ID.
   name                - Column name to put in the header.
   toolTip             - Tooltip (if different from name).
   field               - Property of the data context to bind to.
   formatter           - (default 'return value || ""') Function responsible for rendering the contents of a cell. Signature: function formatter(row, cell, value, columnDef, dataContext) { ... return "..."; }
   editor              - An Editor class.
   validator           - An extra validation function to be passed to the editor.
   unselectable        - If true, the cell cannot be selected (and therefore edited).
   cannotTriggerInsert - If true, a new row cannot be created from just the value of this cell.
   setValueHandler     - If true, this handler will be called to set field value instead of context[field].
   width               - Width of the column in pixels.
   resizable           - (default true) If false, the column cannot be resized.
   sortable            - (default false) If true, the column can be sorted (onSort will be called).
   minWidth            - Minimum allowed column width for resizing.
   maxWidth            - Maximum allowed column width for resizing.
   cssClass            - A CSS class to add to the cell.
   rerenderOnResize    - Rerender the column when it is resized (useful for columns relying on cell width or adaptive formatters).
   asyncPostRender     - Function responsible for manipulating the cell DOM node after it has been rendered (called in the background).
   behavior            - Configures the column with one of several available predefined behaviors:  "select", "move", "selectAndMove".
  
  
   EVENTS:
   onSort                -
   onHeaderContextMenu   -
   onClick               -
   onDblClick            -
   onContextMenu         -
   onKeyDown             -
   onAddNewRow           -
   onValidationError     -
   onViewportChanged     -
   onSelectedRowsChanged -
   onColumnsReordered    -
   onColumnsResized      -
   onBeforeMoveRows      -
   onMoveRows            -
   onCellChange          -  Raised when cell has been edited.   Args: row,cell,dataContext.
   onBeforeEditCell      -  Raised before a cell goes into edit mode.  Return false to cancel.  Args: row,cell,dataContext.
   onBeforeDestroy       -  Raised just before the grid control is destroyed (part of the destroy() method).
  
  
   NOTES:
   Cell/row DOM manipulations are done directly bypassing jQuery's DOM manipulation methods.
   This increases the speed dramatically, but can only be done safely because there are no event handlers
   or data associated with any cell/row DOM nodes.  Cell editors must make sure they implement .destroy()
   and do proper cleanup.
  
  
   @param {jQuery}            $container  Container object to create the grid in.
   @param {Array} or {Object} data        An array of objects for databinding.
   @param {Array}             columns     An array of column definitions.
   @param {Object}            options     Grid options.
  */
  if(typeof jQuery==="undefined")throw new Error("SlickGrid requires jquery module to be loaded");if(!jQuery.rule)throw new Error("SlickGrid requires jquery.rule module to be loaded");if(!jQuery.fn.drag)throw new Error("SlickGrid requires jquery.event.drag module to be loaded");
  (function(){function za(){var p=null;this.isActive=function(y){return y?p===y:p!==null};this.activate=function(y){if(y!==p){if(p!==null)throw"SlickGrid.EditorLock.activate: an editController is still active, can't activate another editController";if(!y.commitCurrentEdit)throw"SlickGrid.EditorLock.activate: editController must implement .commitCurrentEdit()";if(!y.cancelCurrentEdit)throw"SlickGrid.EditorLock.activate: editController must implement .cancelCurrentEdit()";p=y}};this.deactivate=function(y){if(p!==
  y)throw"SlickGrid.EditorLock.deactivate: specified editController is not the currently active one";p=null};this.commitCurrentEdit=function(){return p?p.commitCurrentEdit():true};this.cancelCurrentEdit=function(){p&&p.cancelCurrentEdit()}}function Ua(p,y,g,d){function Va(){var a=$("<div style='position:absolute; top:-10000px; left:-10000px; width:100px; height:100px; overflow:scroll;'></div>").appendTo("body"),b={width:a.width()-a[0].clientWidth,height:a.height()-a[0].clientHeight};a.remove();return b}
  function Wa(a){if(a&&a.jquery)a.disableSelection?a.disableSelection():a.attr("unselectable","on").css("MozUserSelect","none").bind("selectstart.ui",function(){return false})}function Xa(a){if(d.enableAutoTooltips)if((a=$(a.target).closest(".slick-cell",x))&&a.length)a.innerWidth()<a[0].scrollWidth?a.attr("title",$.trim(a.text())):a.attr("title","")}function Aa(){return G.length}function Ba(a){return G[a]}function Ya(){G=y;u=G.getLength||Aa;m=G.getItem||Ba;E=E||Va();d=$.extend({},Za,d);Ca.width=d.defaultColumnWidth;
  if(d.enableColumnReorder&&!jQuery.fn.sortable)throw new Error('SlickGrid\'s "enableColumnReorder = true" option requires jquery-ui.sortable module to be loaded');W={commitCurrentEdit:$a,cancelCurrentEdit:ab};p.empty().attr("tabIndex",0).attr("hideFocus",true).css("overflow","hidden").css("outline",0).addClass(A).addClass("ui-widget");switch(p.css("position")){case "absolute":case "relative":case "fixed":break;default:p.css("position","relative");break}R=$("<div class='slick-header ui-state-default' style='overflow:hidden;position:relative;' />").appendTo(p);
  z=$("<div class='slick-header-columns' style='width:100000px' />").appendTo(R);H=$("<div class='slick-header-secondary ui-state-default' style='overflow:hidden;position:relative;' />").appendTo(p);Da=$("<div class='slick-header-columns-secondary' style='width:100000px' />").appendTo(H);d.showSecondaryHeaderRow||H.hide();n=$("<div class='slick-viewport' tabIndex='0' hideFocus style='"+("width:100%;overflow-x:auto;outline:0;position:relative;overflow-y:"+(d.autoHeight?"auto;":"scroll;"))+"'>").appendTo(p);
  x=$("<div class='grid-canvas' tabIndex='0' hideFocus style='overflow:hidden' />").appendTo(n);bb();n.height(p.innerHeight()-R.outerHeight()-(d.showSecondaryHeaderRow?H.outerHeight():0));Wa(z);n.bind("selectstart.ui",function(a){return $(a.target).is("input,textarea")});cb();db();Ea();Fa();n.bind("scroll",la);p.bind("resize",Fa);x.bind("keydown",eb);x.bind("click",fb);x.bind("dblclick",gb);x.bind("contextmenu",hb);x.bind("mouseover",Xa);R.bind("contextmenu",ib)}function cb(){function a(){$(this).addClass("ui-state-hover")}
  function b(){$(this).removeClass("ui-state-hover")}var c;for(c=0;c<g.length;c++){var e=g[c]=$.extend({},Ca,g[c]);S[e.id]=c;var f=$("<div class='ui-state-default slick-header-column' cell="+c+" id='"+e.id+"' />").html("<span class='slick-column-name'>"+e.name+"</span>").width(e.width-ea).attr("title",e.toolTip||e.name).appendTo(z);e.hidden&&f.css("display","none");if(d.enableColumnReorder||e.sortable)f.hover(a,b);e.sortable&&f.append("<span class='slick-sort-indicator' />")}jb();ma();d.enableColumnReorder&&
  kb()}function jb(){z.click(function(a){if(!$(a.target).hasClass("slick-resizable-handle")){a=$(a.target).closest(".slick-header-column");if(a.length&&g[S[a.attr("id")]].sortable)if(d.editorLock.commitCurrentEdit()){if(a.is(".slick-header-column-sorted"))a.find(".slick-sort-indicator").toggleClass("slick-sort-indicator-asc").toggleClass("slick-sort-indicator-desc");else{z.children().removeClass("slick-header-column-sorted");z.find(".slick-sort-indicator").removeClass("slick-sort-indicator-asc slick-sort-indicator-desc");
  a.addClass("slick-header-column-sorted");a.find(".slick-sort-indicator").addClass("slick-sort-indicator-asc")}h.onSort&&h.onSort(g[S[a.attr("id")]],a.find(".slick-sort-indicator").hasClass("slick-sort-indicator-asc"))}}})}function kb(){z.sortable({containment:"parent",axis:"x",cursor:"default",cursorAt:"left",tolerance:"intersection",helper:"clone",placeholder:"slick-sortable-placeholder ui-state-default slick-header-column",forcePlaceholderSize:true,start:function(a,b){$(b.helper).addClass("slick-header-column-active")},
  beforeStop:function(a,b){$(b.helper).removeClass("slick-header-column-active")},stop:function(a){var b;if(d.editorLock.commitCurrentEdit()){var c=z.sortable("toArray"),e={};for(b=0;b<g.length;b++)e[g[b].id]=g[b];for(b=0;b<c.length;b++){z.children()[b].setAttribute("cell",b);S[c[b]]=b;g[b]=e[c[b]]}F();Ga();Ea();M();h.onColumnsReordered&&h.onColumnsReordered();a.stopPropagation();ma()}else $(this).sortable("cancel")}})}function ma(){var a,b,c,e,f,j,s,T,N;e=z.find(".slick-header-column:visible");e.find(".slick-resizable-handle").remove();
  e.each(function(B,na){b=g[na.getAttribute("cell")];if(b.resizable){if(s===undefined)s=B;T=B}});e.each(function(B,na){if(!(s!==undefined&&B<s||d.forceFitColumns&&B>=T)){var Ha=$(this);$("<div class='slick-resizable-handle' />").appendTo(na).bind("dragstart",function(q){if(!d.editorLock.commitCurrentEdit())return false;c=q.pageX;Ha.addClass("slick-header-column-active");var w=q=null;e.each(function(Eb,Ia){g[Ia.getAttribute("cell")].previousWidth=$(Ia).outerWidth()});if(d.forceFitColumns){w=q=0;for(a=
  B+1;a<e.length;a++){b=g[e[a].getAttribute("cell")];if(b.resizable){if(w!==null)if(b.maxWidth)w+=b.maxWidth-b.previousWidth;else w=null;q+=b.previousWidth-Math.max(b.minWidth||0,I)}}}var k=0,r=0;for(a=0;a<=B;a++){b=g[e[a].getAttribute("cell")];if(b.resizable){if(r!==null)if(b.maxWidth)r+=b.maxWidth-b.previousWidth;else r=null;k+=b.previousWidth-Math.max(b.minWidth||0,I)}}if(q===null)q=1E5;if(k===null)k=1E5;if(w===null)w=1E5;if(r===null)r=1E5;j=c+Math.min(q,r);f=c-Math.min(k,w);N=x.width()}).bind("drag",
  function(q){var w=Math.min(j,Math.max(f,q.pageX))-c,k,r;if(w<0){k=w;for(a=B;a>=0;a--){r=a;b=g[r];if(b.resizable){q=Math.max(b.minWidth||0,I);if(k&&b.previousWidth+k<q){k+=b.previousWidth-q;D(r,q,d.syncColumnCellResize)}else{D(r,b.previousWidth+k,d.syncColumnCellResize);k=0}}}if(d.forceFitColumns){k=-w;for(a=B+1;a<e.length;a++){r=e[a].getAttribute("cell");b=g[r];if(b.resizable)if(k&&b.maxWidth&&b.maxWidth-b.previousWidth<k){k-=b.maxWidth-b.previousWidth;D(r,b.maxWidth,d.syncColumnCellResize)}else{D(r,
  b.previousWidth+k,d.syncColumnCellResize);k=0}}}else d.syncColumnCellResize&&x.width(N+w)}else{k=w;for(a=B;a>=0;a--){r=e[a].getAttribute("cell");b=g[r];if(b.resizable)if(k&&b.maxWidth&&b.maxWidth-b.previousWidth<k){k-=b.maxWidth-b.previousWidth;D(r,b.maxWidth,d.syncColumnCellResize)}else{D(r,b.previousWidth+k,d.syncColumnCellResize);k=0}}if(d.forceFitColumns){k=-w;for(a=B+1;a<e.length;a++){r=e[a].getAttribute("cell");b=g[r];if(b.resizable){q=Math.max(b.minWidth||0,I);if(k&&b.previousWidth+k<q){k+=
  b.previousWidth-q;D(r,q,d.syncColumnCellResize)}else{D(r,b.previousWidth+k,d.syncColumnCellResize);k=0}}}}else d.syncColumnCellResize&&x.width(N+w)}}).bind("dragend",function(){var q;Ha.removeClass("slick-header-column-active");for(a=0;a<e.length;a++){var w=e[a].getAttribute("cell");b=g[w];q=$(e[a]).outerWidth();b.previousWidth!==q&&b.rerenderOnResize&&F();b.width=d.forceFitColumns?Math.floor(b.width*(q-b.previousWidth)/b.previousWidth)+b.width:q;d.syncColumnCellResize||D(w,q,true)}J();h.onColumnsResized&&
  h.onColumnsResized()})}})}function db(){x.bind("beforedragstart",function(a){a=$(a.target).closest(".slick-cell");if(a.length===0)return false;if(parseInt(a.parent().attr("row"),10)>=u())return false;a=g[a.attr("cell")];if(a.behavior!=="move"&&a.behavior!=="selectAndMove")return false}).bind("dragstart",function(a){if(!d.editorLock.commitCurrentEdit())return false;a=parseInt($(a.target).closest(".slick-row").attr("row"),10);fa[a]||X([a]);a=$("<div class='slick-reorder-proxy'/>");a.css("position",
  "absolute").css("zIndex","99999").css("width",$(this).innerWidth()).css("height",d.rowHeight*Y.length).appendTo(n);$(this).data("selectionProxy",a).data("insertBefore",-1);a=$("<div class='slick-reorder-guide'/>");a.css("position","absolute").css("zIndex","99998").css("width",$(this).innerWidth()).css("top",-1000).appendTo(n);return a}).bind("drag",function(a){var b=a.clientY-$(this).offset().top;$(this).data("selectionProxy").css("top",b-5);b=Math.max(0,Math.min(Math.round(b/d.rowHeight),u()));if(b!==
  $(this).data("insertBefore")){h.onBeforeMoveRows&&h.onBeforeMoveRows(ga(),b)===false?$(a.dragProxy).css("top",-1000).data("canMove",false):$(a.dragProxy).css("top",b*d.rowHeight).data("canMove",true);$(this).data("insertBefore",b)}}).bind("dragend",function(a){var b=$(a.dragProxy).data("canMove");$(a.dragProxy).remove();$(this).data("selectionProxy").remove();a=$(this).data("insertBefore");$(this).removeData("selectionProxy").removeData("insertBefore");h.onMoveRows&&b&&h.onMoveRows(ga(),a)})}function bb(){var a=
  $("<div class='ui-state-default slick-header-column' cell='' id='' style='visibility:hidden'>-</div>").appendTo(z);ea=a.outerWidth()-a.width();lb=a.outerHeight()-a.height();a.remove();var b=$("<div class='slick-row' />").appendTo(x);a=$("<div class='slick-cell' cell='' id='' style='visibility:hidden'>-</div>").appendTo(b);ha=a.outerWidth()-a.width();Ja=a.outerHeight()-a.height();b.remove();I=Math.max(ea,ha)}function Ea(){var a=$("<style type='text/css' rel='stylesheet' lib='slickgrid"+A+"' />").appendTo($("head")),
  b=d.rowHeight-Ja;$.rule("."+A+" .slick-header-columns-secondary {  height:"+d.secondaryHeaderRowHeight+"px; }").appendTo(a);$.rule("."+A+" .slick-cell { height:"+b+"px; line-height:"+b+"px; }").appendTo(a);for(b=0;b<g.length;b++)$.rule("."+A+" .c"+b+" { width:"+((g[b].currentWidth||g[b].width)-ha)+"px; display: "+(g[b].hidden?"none":"block")+" }").appendTo(a)}function Ga(){$("style[lib=slickgrid"+A+"]").remove()}function mb(){d.editorLock.cancelCurrentEdit();h.onBeforeDestroy&&h.onBeforeDestroy();
  z.sortable&&z.sortable("destroy");p.unbind("resize",J);Ga();p.empty().removeClass(A)}function nb(){return W}function ob(a){return S[a]}function oa(){var a,b,c=[],e=[],f=0,j=d.autoHeight?pa:pa-E.width,s=0;for(a=s=0;a<g.length;a++)if(!g[a].hidden){b=g[a];e.push(b);c.push(b.width);s+=b.width;f+=b.width-Math.max(b.minWidth||0,I)}s=s;for(F();s>j;){if(!f)return;var T=(s-j)/f;for(a=0;a<e.length&&s>j;a++){b=e[a];if(!(!b.resizable||b.minWidth===b.width||b.width===I)){b=Math.floor(T*(b.width-Math.max(b.minWidth||
  0,I)))||1;s-=b;c[a]-=b}}}for(;s<j;){f=j/s;for(a=0;a<e.length&&s<j;a++){b=e[a];if(!(!b.resizable||b.maxWidth===b.width)){b=Math.min(Math.floor(f*b.width)-b.width,b.maxWidth-b.width||1E6)||1;s+=b;c[a]+=b}}}for(a=0;a<g.length;a++)if(g[a]===e[0]){j=c.shift();e.shift().currentWidth=j;D(a,j,true)}J()}function D(a,b,c){g[a].currentWidth=b;z.children().eq(a).css("width",b-ea);c&&$.rule("."+A+" .c"+a,"style[lib=slickgrid"+A+"]").css("width",b-ha)}function pb(a,b){var c=S[a.id];g[c].hidden=!b;z.find("[id="+
  g[c].id+"]").css("display",b?"block":"none");$.rule("."+A+" .c"+c,"style[lib=slickgrid"+A+"]").css("display",b?"block":"none");J();d.forceFitColumns&&oa();ma()}function ga(){return Y.concat()}function X(a){var b,c;if(d.editorLock.isActive()&&!d.editorLock.isActive(W))throw"Grid : setSelectedRows : cannot set selected rows when somebody else has an edit lock";var e={};for(b=0;b<a.length;b++)e[a[b]]=true;for(b=0;b<Y.length;b++){c=Y[b];t[c]&&!e[c]&&$(t[c]).removeClass("ui-state-active selected")}for(b=
  0;b<a.length;b++){c=a[b];t[c]&&!fa[c]&&$(t[c]).addClass("ui-state-active selected")}Y=a.concat();fa=e}function qb(){return d}function rb(a){if(d.editorLock.commitCurrentEdit()){O();d.enableAddRow!==a.enableAddRow&&Ka(u());d=$.extend(d,a);M()}}function sb(a,b){F();G=y=a;u=G.getLength||Aa;m=G.getItem||Ba;b&&n.scrollTop(0)}function tb(){return Da[0]}function ub(){d.showSecondaryHeaderRow=true;H.slideDown("fast",J)}function vb(){d.showSecondaryHeaderRow=false;H.slideUp("fast",J)}function wb(a,b){var c=
  m(b),e="slick-row "+(b<u()&&!c?" loading":"")+(fa[b]?" selected ui-state-active":"")+(b%2==1?" odd":" even");if(d.rowCssClasses)e+=" "+d.rowCssClasses(c);a.push("<div class='ui-widget-content "+e+"' row='"+b+"' style='top:"+d.rowHeight*b+"px'>");e=0;for(var f=g.length;e<f;e++){var j=g[e];a.push("<div "+(j.unselectable?"tabIndex=-1 ":"hideFocus tabIndex=0 ")+"class='slick-cell c"+e+(j.cssClass?" "+j.cssClass:"")+"' cell="+e+">");c&&b<u()&&a.push(j.formatter(b,e,c[j.field],j,c));a.push("</div>")}a.push("</div>")}
  function qa(a,b){for(var c in t)if((c=parseInt(c,10))!==i&&(c<a||c>b))ra(c)}function F(){x[0].innerHTML="";t={};Z={};sa+=C;C=0}function ra(a){var b=t[a];if(b){b.parentNode.removeChild(b);delete t[a];delete Z[a];C--;sa++}}function La(a){var b,c;if(a&&a.length){aa=0;var e=[];b=0;for(c=a.length;b<c;b++){if(v&&i===b)throw"Grid : removeRow : Cannot remove a row that is currently in edit mode";t[a[b]]&&e.push(a[b])}if(C>10&&e.length===C)F();else{b=0;for(a=e.length;b<a;b++)ra(e[b])}}}function Ka(a){La([a])}
  function xb(a,b){if(t[a]){var c=$(t[a]).find(".c[cell="+b+"]");if(c.length!==0){var e=g[b],f=m(a);if(v&&i===a&&o===b)v.setValue(f[e.field]);else{c[0].innerHTML=f?e.formatter(a,b,f[e.field],e,f):"";ta(a)}}}}function yb(a){if(t[a]){$(t[a]).find(".slick-cell").each(function(b){var c=g[b];if(a===i&&b===o&&v)v.setValue(m(i)[c.field]);else this.innerHTML=m(a)?c.formatter(a,b,m(a)[c.field],c,m(a)):""});ta(a)}}function J(){var a=d.rowHeight*(u()+(d.enableAddRow?1:0)+(d.leaveSpaceForNewRows?U-1:0));d.autoHeight?
  n.height(a):n.height(p.innerHeight()-R.outerHeight()-(d.showSecondaryHeaderRow?H.outerHeight():0));pa=n.innerWidth();K=n.innerHeight();ba=U=Math.ceil(K/d.rowHeight);ua=Math.max(50,U+2*ba);var b=0;z.find(".slick-header-column:visible").each(function(){b+=$(this).outerWidth()});x.width(b);a=Math.max(a,K-E.height);n.scrollTop()>a-n.height()+E.height&&n.scrollTop(a-n.height()+E.height);x.height(a);M()}function Fa(){d.forceFitColumns?oa():J()}function Ma(){var a=d.enableAddRow?u():u()-1;for(var b in t)b>=
  a&&ra(b);a=Math.max(d.rowHeight*(u()+(d.enableAddRow?1:0)+(d.leaveSpaceForNewRows?U-1:0)),K-E.height);n.scrollTop()>a-n.height()+E.height&&n.scrollTop(a-n.height()+E.height);x.height(a)}function Na(){return{top:Math.floor(L/d.rowHeight),bottom:Math.floor((L+K)/d.rowHeight)}}function ia(a,b){var c,e,f=x[0],j=C;e=[];var s=[],T=new Date;for(c=a;c<=b;c++)if(!t[c]){C++;s.push(c);wb(e,c);Oa++}var N=document.createElement("div");N.innerHTML=e.join("");c=0;for(e=N.childNodes.length;c<e;c++)t[s[c]]=f.appendChild(N.firstChild);
  if(C-j>P)Pa=(new Date-T)/(C-j)}function Qa(){if(d.enableAsyncPostRender){clearTimeout(va);va=setTimeout(Ra,d.asyncPostRenderDelay,"JavaScript")}}function ta(a){delete Z[a];V=Math.min(V,a);ca=Math.max(ca,a);Qa()}function M(){var a=Na(),b=Math.max(0,a.top-(aa>=0?P:ba)),c=Math.min(d.enableAddRow?u():u()-1,a.bottom+(aa>0?ba:P));C>10&&Math.abs(da-L)>d.rowHeight*ua?F():qa(b,c);ia(b,c);V=Math.max(0,a.top-P);ca=Math.min(d.enableAddRow?u():u()-1,a.bottom+P);Qa();da=L;ja=null}function zb(){Ma(u());F();M()}
  function la(){L=n[0].scrollTop;var a=Math.abs(da-L),b=n[0].scrollLeft;if(b!==wa){R[0].scrollLeft=wa=b;H[0].scrollLeft=wa=b}if(!(a<Math.min(K/4,P*d.rowHeight))){aa=da===L?0:da<L?1:-1;ja&&clearTimeout(ja);if(a<U*d.rowHeight)M();else ja=setTimeout(M,50,"JavaScript");h.onViewportChanged&&h.onViewportChanged()}}function Ra(){for(;V<=ca;){var a=aa>=0?V++:ca--,b=t[a];if(!(!b||Z[a]||a>=u())){var c=m(a);b=b.childNodes;for(var e=0,f=g.length;e<f;e++){var j=g[e];j.asyncPostRender&&!j.hidden&&j.asyncPostRender(b[e],
  V,c,j)}Z[a]=true;va=setTimeout(Ra,d.asyncPostRenderDelay,"JavaScript");return}}}function eb(a){if(!(h.onKeyDown&&m(i)&&!d.editorLock.isActive()&&h.onKeyDown(a,i,o)))switch(a.which){case 27:if(!d.editorLock.isActive())return;d.editorLock.cancelCurrentEdit();l&&l.focus();break;case 9:Q(0,a.shiftKey?-1:1,true);break;case 37:Q(0,-1,false);break;case 39:Q(0,1,false);break;case 38:Q(-1,0,false);break;case 40:Q(1,0,false);break;case 13:if(d.autoEdit)Q(1,0,false);else if(d.editable)if(v)if(i===y.length)Q(1,
  0,false);else{d.editorLock.commitCurrentEdit();l.focus()}else d.editorLock.commitCurrentEdit()&&ka();break;default:return}a.stopPropagation();a.preventDefault();try{a.originalEvent.keyCode=0}catch(b){}}function fb(a){var b=$(a.target).closest(".slick-cell");if(b.length!==0)if(!(l===b[0]&&v!==null)){var c=parseInt(b.parent().attr("row"),10),e=parseInt(b.attr("cell"),10),f=null,j=g[e];if(m(c)&&(j.behavior==="selectAndMove"||j.behavior==="select"))if(f=d.editorLock.commitCurrentEdit()){b=ga();e=$.inArray(c,
  b);if(!a.ctrlKey&&!a.shiftKey)b=[c];else if(e===-1&&a.ctrlKey)b.push(c);else if(e!==-1&&a.ctrlKey)b=$.grep(b,function(s){return s!==c});else if(b.length&&a.shiftKey){a=b.pop();f=Math.min(c,a);e=Math.max(c,a);b=[];for(f=f;f<=e;f++)f!==a&&b.push(f);b.push(a)}X(b);h.onSelectedRowsChanged&&h.onSelectedRowsChanged();return false}if(m(c)&&h.onClick)if(f=d.editorLock.commitCurrentEdit())if(h.onClick(a,c,e)){a.stopPropagation();a.preventDefault();return false}if(d.enableCellNavigation&&!g[e].unselectable)if(f===
  true||f===null&&d.editorLock.commitCurrentEdit())xa(b[0],c===y.length||d.autoEdit)}}function hb(a){var b=$(a.target).closest(".slick-cell");if(b.length!==0)if(!(l===b[0]&&v!==null)){var c=parseInt(b.parent().attr("row"),10);b=parseInt(b.attr("cell"),10);var e=null;if(m(c)&&h.onContextMenu)if(e=d.editorLock.commitCurrentEdit())if(h.onContextMenu(a,c,b)){a.stopPropagation();a.preventDefault();return false}}}function gb(a){var b=$(a.target).closest(".slick-cell");if(b.length!==0)if(!(l===b[0]&&v!==null)){var c=
  parseInt(b.parent().attr("row"),10);b=parseInt(b.attr("cell"),10);var e=null;if(m(c)&&h.onDblClick)if(e=d.editorLock.commitCurrentEdit())if(h.onDblClick(a,c,b)){a.stopPropagation();a.preventDefault();return false}d.editable&&Sa(c,b,true)}}function ib(a){if(h.onHeaderContextMenu&&d.editorLock.commitCurrentEdit()){a.preventDefault();h.onHeaderContextMenu(a)}}function Ab(a,b){for(var c=Math.floor(b/d.rowHeight),e=0,f=0,j=0;j<g.length&&f<b;j++){f+=g[j].width;e++}return{row:c,cell:e-1}}function Bb(a,b){if(l!==
  null){O();$(l).removeClass("selected")}l=a;if(l!==null){i=parseInt($(l).parent().attr("row"),10);o=parseInt($(l).attr("cell"),10);$(l).addClass("selected");Cb();if(d.editable&&b&&Ta(i,o)){clearTimeout(ya);if(d.asyncEditorLoading)ya=setTimeout(ka,d.asyncEditorLoadDelay,"JavaScript");else ka()}else l.focus()}else o=i=null}function xa(a,b){Bb(a,b);a?X([i]):X([]);h.onSelectedRowsChanged&&h.onSelectedRowsChanged()}function Db(){if(document.selection&&document.selection.empty)document.selection.empty();
  else if(window.getSelection){var a=window.getSelection();a&&a.removeAllRanges&&a.removeAllRanges()}}function Ta(a,b){if(a<u()&&!m(a))return false;if(g[b].cannotTriggerInsert&&a>=u())return false;if(!g[b].editor)return false;return true}function O(){if(v){v.destroy();$(l).removeClass("editable invalid");if(m(i)){l.innerHTML=g[o].formatter(i,o,m(i)[g[o].field],g[o],m(i));ta(i)}v=null;$.browser.msie&&Db();d.editorLock.deactivate(W)}}function ka(){if(l){if(!d.editable)throw"Grid : makeSelectedCellEditable : should never get called when options.editable is false";
  clearTimeout(ya);if(Ta(i,o))if(h.onBeforeEditCell&&h.onBeforeEditCell(i,o,m(i))===false)l.focus();else{d.editorLock.activate(W);$(l).addClass("editable");var a=null;if(m(i))a=m(i)[g[o].field];l.innerHTML="";v=new g[o].editor($(l),g[o],a,m(i))}}}function Cb(){if(l){var a=n[0].scrollTop;if((i+2)*d.rowHeight>a+K){n[0].scrollTop=i*d.rowHeight;la()}else if(i*d.rowHeight<a){n[0].scrollTop=(i+2)*d.rowHeight-K;la()}}}function Q(a,b,c){if(l&&d.enableCellNavigation)if(d.editorLock.commitCurrentEdit()){var e=
  t[i+a],f=e?$(e).find(".slick-cell[cell="+(o+b)+"]"):null;if(f&&!f.is("[tabIndex=0]:visible"))f=b>0?f.nextAll("[tabIndex=0]:visible:first"):f.prevAll("[tabIndex=0]:visible:first");if(c&&a===0&&!(e&&f&&f.length))if(!f||!f.length){if(b>0)f=(e=t[i+a+1])?$(e).find(".slick-cell[cell]:first"):null;else f=(e=t[i+a-1])?$(e).find(".slick-cell[cell]:last"):null;if(f&&!f.is("[tabIndex=0]:visible"))f=b>0?f.nextAll("[tabIndex=0]:visible:first"):f.prevAll("[tabIndex=0]:visible:first")}if(e&&f&&f.length){a=parseInt($(e).attr("row"),
  10);xa(f[0],a===y.length||d.autoEdit);v||l.focus()}else l.focus()}}function Sa(a,b,c){if(!(a>u()||a<0||b>=g.length||b<0))if(!(!d.enableCellNavigation||g[b].unselectable))if(d.editorLock.commitCurrentEdit()){t[a]||ia(a,a);b=$(t[a]).find(".slick-cell[cell="+b+"][tabIndex=0]:visible")[0];xa(b,c||a===y.length||d.autoEdit);v||l.focus()}}function $a(){if(v){if(v.isValueChanged()){var a=v.validate();if(a.valid){a=v.getValue();if(i<u()){if(g[o].setValueHandler){O();g[o].setValueHandler(a,g[o],m(i))}else{m(i)[g[o].field]=
  a;O()}h.onCellChange&&h.onCellChange(i,o,m(i))}else if(h.onAddNewRow){O();h.onAddNewRow(g[o],a)}return true}else{$(l).addClass("invalid");$(l).stop(true,true).effect("highlight",{color:"red"},300);h.onValidationError&&h.onValidationError(l,a,i,o,g[o]);v.focus();return false}}O()}return true}function ab(){O()}var Za={rowHeight:25,defaultColumnWidth:80,enableAddRow:false,leaveSpaceForNewRows:false,editable:false,autoEdit:true,enableCellNavigation:true,enableColumnReorder:true,asyncEditorLoading:false,
  asyncEditorLoadDelay:100,forceFitColumns:false,enableAsyncPostRender:false,asyncPostRenderDelay:60,autoHeight:false,editorLock:Slick.GlobalEditorLock,showSecondaryHeaderRow:false,secondaryHeaderRowHeight:25,syncColumnCellResize:false,enableAutoTooltips:true},G,u,m,Ca={resizable:true,sortable:false,minWidth:30,formatter:function(a,b,c){return c===null||c===undefined?"":c}},ua=50,P=5,ba=P,A="slickgrid_"+Math.round(1E6*Math.random()),h=this,R,z,H,Da,n,x,K,pa,ea,lb,ha,Ja,I,i,o,l=null,v=null,W,t={},C=
  0,U,da=0,L=0,wa=0,aa=1,Pa=10,Y=[],fa={},S={},ya=null,ja=null,va=null,Z={},ca=null,V=null,Oa=0,sa=0;this.debug=function(){var a="";a+="\ncounter_rows_rendered:  "+Oa;a+="\ncounter_rows_removed:  "+sa;a+="\nrenderedRows:  "+C;a+="\nnumVisibleRows:  "+U;a+="\nCAPACITY:  "+ua;a+="\nBUFFER:  "+ba;a+="\navgRowRenderTime:  "+Pa;alert(a)};this.benchmark_render_200=function(){F();ia(0,200);qa(0,200)};this.stressTest=function(){console.time("benchmark-stress");ia(0,500);qa(0,500);console.timeEnd("benchmark-stress");
  setTimeout(h.stressTest,50,"JavaScript")};this.benchmarkFn=function(a){var b=new Date,c=new Array(arguments);c.splice(0,1);h[a].call(this,c);alert("Grid : benchmarkFn : "+a+" : "+(new Date-b)+"ms")};Ya();$.extend(this,{slickGridVersion:"1.3.2",onSort:null,onHeaderContextMenu:null,onClick:null,onDblClick:null,onContextMenu:null,onKeyDown:null,onAddNewRow:null,onValidationError:null,onViewportChanged:null,onSelectedRowsChanged:null,onColumnsReordered:null,onColumnsResized:null,onBeforeMoveRows:null,
  onMoveRows:null,onCellChange:null,onBeforeEditCell:null,onBeforeDestroy:null,getOptions:qb,setOptions:rb,setData:sb,destroy:mb,getColumnIndex:ob,setColumnVisibility:pb,autosizeColumns:oa,updateCell:xb,updateRow:yb,removeRow:Ka,removeRows:La,removeAllRows:F,render:M,invalidate:zb,getViewport:Na,resizeCanvas:J,updateRowCount:Ma,getCellFromPoint:Ab,gotoCell:Sa,editCurrentCell:ka,getSelectedRows:ga,setSelectedRows:X,getSecondaryHeaderRow:tb,showSecondaryHeaderRow:ub,hideSecondaryHeaderRow:vb,getEditController:nb})}
  var E;$.extend(true,window,{Slick:{Grid:Ua,EditorLock:za,GlobalEditorLock:new za}})})();