/
jquery.sheet.min.js
1 lines (1 loc) · 132 KB
/
jquery.sheet.min.js
1
var jQuery=window.jQuery||{};var Sheet=(function(i,n,k,m,o,l,g,c,q,j){var h=h||{};h.ActionUI=(function(r,u,s,t,v){var w=function(D,H,N,E,y,J){this.enclosure=D;this.pane=H;this.table=N;this.max=J;this.xIndex=0;this.yIndex=0;this.scrollAxis={x:{},y:{}};this.scrollSize={};this.hiddenColumns=[];this.hiddenRows=[];if(!(this.frozenAt=y)){this.frozenAt={row:0,col:0}}this.frozenAt.row=s.max(this.frozenAt.row,0);this.frozenAt.col=s.max(this.frozenAt.col,0);this.scrolledArea={start:{row:s.max(this.frozenAt.row,1),col:s.max(this.frozenAt.col,1)},end:{row:s.max(this.frozenAt.row,1),col:s.max(this.frozenAt.col,1)}};if(h.ActionUI.prototype.nthCss===null){if(J){h.ActionUI.prototype.nthCss=function(R,Y,T,V,U){var W=[],S=T.length,X=this.repeat;U=U||"{display: none;}";do{if(T[S]>V){W.push(Y+" "+R+":first-child"+X("+"+R,T[S]-1))}}while(S--);if(W.length){return W.join(",")+U}return""}}else{h.ActionUI.prototype.nthCss=function(R,X,T,V,U){var W=[],S=T.length;U=U||"{display: none;}";do{if(T[S]>V){W.push(X+" "+R+":nth-child("+T[S]+")")}}while(S--);if(W.length){return W.join(",")+U}return""}}}var C=this,G="#"+N.getAttribute("id"),O=this.scrollUI=H.scrollOuter=r.createElement("div"),L=H.scrollInner=r.createElement("div"),A=H.scrollStyleX=this.scrollStyleX=new h.StyleUpdater(function(R,S){R=R||[];if(R.length!==C.xIndex||S){C.xIndex=R.length||C.xIndex;S=S||B("col",G,R,C.frozenAt.col+1)+B("td",G+" tr",R,C.frozenAt.col+1);this.setStyle(S);if(R.length){C.scrolledArea.start.col=s.max(R.pop()||1,1);C.scrolledArea.end.col=s.max(R.shift()||1,1)}return true}return false}),z=H.scrollStyleY=this.scrollStyleY=new h.StyleUpdater(function(R,S){R=R||[];if(R.length!==C.yIndex||S){C.yIndex=R.length||C.yIndex;S=S||B("tr",G,R,C.frozenAt.row+1);this.setStyle(S);if(R.length){C.scrolledArea.start.row=s.max(R.pop()||1,1);C.scrolledArea.end.row=s.max(R.shift()||1,1)}return true}return false}),B=this.nthCss;O.setAttribute("class",E);O.appendChild(L);v(O).disableSelectionSpecial();H.appendChild(A.styleElement);H.appendChild(z.styleElement);var K,P,M,Q,F,I,x=N.tBody.children[0];H.resizeScroll=function(R){if(R){K=A.getStyle();P=z.getStyle()}else{K=(N.clientWidth<=D.clientWidth?"":A.getStyle());P=(N.clientHeight<=D.clientHeight?"":z.getStyle())}A.update(null," ");z.update(null," ");if(x===undefined){x=N.tBody.children[0]}M=(x.clientWidth||N.clientWidth)+"px";Q=N.clientHeight+"px";F=D.clientWidth+"px";I=D.clientHeight+"px";L.style.width=M;L.style.height=Q;O.style.width=F;O.style.height=I;C.scrollStart("x");C.scrollStart("y");A.update(null,K);z.update(null,P);if(H.inPlaceEdit){H.inPlaceEdit.goToTd()}};new MouseWheel(H,O)};w.prototype={putTdInView:function(E){var A=0,z=0,D=0,C,B;this.xIndex=0;this.yIndex=0;while((C=this.directionToSeeTd(E))!==null){B=this.scrolledArea.end;if(C.left){z--;this.scrollTo({axis:"x",value:B.col-1})}else{if(C.right){z++;this.scrollTo({axis:"x",value:B.col+1})}}if(C.up){D--;this.scrollTo({axis:"y",value:B.row-1})}else{if(C.down){D++;this.scrollTo({axis:"y",value:B.row+1})}}A++;if(A<25){break}}this.scrollStop()},directionToSeeTd:function(y){var x=this.pane,H={top:0,bottom:x.clientHeight,left:0,right:x.clientWidth},D=y.clientWidth,B=y.clientHeight,F={top:y.offsetTop,bottom:y.offsetTop+B,left:y.offsetLeft,right:y.offsetLeft+D},z=y.parentNode,E=this.scrolledArea.end;if(!y.col){return null}var G=y.barTop.cellIndex<E.col,A=z.rowIndex<E.row,C={up:A,down:F.bottom>H.bottom&&B<=x.clientHeight,left:G,right:F.right>H.right&&D<=x.clientWidth};if(C.up||C.down||C.left||C.right){return C}return null},repeat:function(z,y){var x="";while(y>0){if(y&1){x+=z}y>>=1;z+=z}return x},nthCss:null,redraw:function(){var x=this.pane.style;x.opacity=0.9999;setTimeout(function(){x.opacity=1},0)},hide:function(y,F,I,A){var D=this,E="#"+this.table.getAttribute("id"),H=this.toggleHideStyleX=new h.StyleUpdater(function(){var J=x("col",E,D.hiddenColumns,0)+x("td",E+" tr",D.hiddenColumns,0);this.setStyle(J)}),G=this.toggleHideStyleY=new h.StyleUpdater(function(){var J=x("tr",E,D.hiddenRows,0);this.setStyle(J)}),C,B,x=this.nthCss,z=this.pane;z.appendChild(H.styleElement);z.appendChild(G.styleElement);this.hiddenRows=[];this.hiddenColumns=[];if(y){C=y.length-1;if(C>-1){do{B=y[C];this.toggleHideRow(I[B],B)}while(C--)}}if(F){C=F.length-1;if(C>-1){do{B=F[C];this.toggleHideColumn(A[B],B)}while(C--)}}},remove:function(){},scrollStart:function(C){var D=this.pane,A=D.scrollOuter,B=this.scrollAxis[C],z=this.scrollSize=D.size();B.v=[];B.name=C;switch(C||"x"){case"x":B.value=0;B.max=z.cols;B.min=0;B.size=z.cols;D.scrollStyleX.update();B.scrollStyle=D.scrollStyleX;B.area=A.scrollWidth-A.clientWidth;B.sheetArea=D.table.clientWidth-D.table.corner.clientWidth;B.scrollUpdate=function(){A.scrollLeft=(B.value)*(B.area/B.size)};B.gridSize=100/B.size;break;case"y":B.value=0;B.max=z.rows;B.min=0;B.size=z.rows;D.scrollStyleY.update();B.scrollStyle=D.scrollStyleY;B.area=A.scrollHeight-A.clientHeight;B.sheetArea=D.table.clientHeight-D.table.corner.clientHeight;B.scrollUpdate=function(){A.scrollTop=(B.value)*(B.area/B.size)};B.gridSize=100/B.size;break}var y=B.max;do{var x=new t(B.gridSize*y);x.index=y+1;B.v.unshift(x)}while(y--)},scrollTo:function(A){A=A||{};A.axis=A.axis||"x";A.value=A.value||0;A.pixel=A.pixel||0;if(!this.scrollAxis){this.scrollStart(A.axis)}var z=this.scrollAxis[A.axis];if(!A.value){A.value=f.closest(z.v,s.abs(A.pixel/z.area)*100,z.min).index}A.max=A.max||z.max;var y=((A.value>A.max?A.max:A.value)-z.min),x=[];if(y>=0){do{x.push(y+z.min)}while(y-->0)}z.value=A.value;if(x.length){if(z.scrollStyle){return z.scrollStyle.update(x)}}else{if(z.scrollStyle){return z.scrollStyle.update()}}return false},scrollStop:function(){if(this.scrollAxis.x.scrollUpdate){this.scrollAxis.x.scrollUpdate()}if(this.scrollAxis.y.scrollUpdate){this.scrollAxis.y.scrollUpdate()}},toggleHideRow:function(z,y){var x=v(z);y=s.max(y+1,1);if(x.length&&v.inArray(y,this.hiddenRows)<0){this.hiddenRows.push(y)}else{this.hiddenRows.splice(this.hiddenRows.indexOf(y),1)}this.toggleHideStyleY.update()},rowShowAll:function(){v.each(this.hiddenRows||[],function(x){v(this).removeData("hidden")});this.toggleHideStyleY.setStyle("");this.hiddenRows=[]},toggleHideColumn:function(x,y){var z=v(x);y=s.max(y+1,1);if(z.length&&v.inArray(y,this.hiddenColumns)<0){this.hiddenColumns.push(y)}else{this.hiddenColumns.splice(this.hiddenColumns.indexOf(y),1)}this.toggleHideStyleX.update()},columnShowAll:function(){this.toggleHideStyleX.setStyle("");this.hiddenColumns=[]}};return w})(n,k,c,l,i);h.ColumnAdder=(function(){function r(){this.qty=-1;this.addedFinished=null;this.createBar=null;this.createCell=null}r.prototype={setQty:function(u,t){var s=i.sheet.max;if(s){if(s>t.cols&&s<=t.cols+u){this.qty=s-t.cols}else{if(s&&s<=t.cols+u){return false}}}else{this.qty=u}return true},setAddedFinished:function(s){this.addedFinished=s},setCreateBarFn:function(s){this.createBar=s},setCreateCellFn:function(s){this.createCell=s},createCells:function(x,A,w){var v=(w?0:1),s=A.rows||1,u=x+this.qty,z,t=x,y;for(;t<u;t++){y=this.createBar(t+v);for(z=1;z<=s;z++){this.createCell(z,t+v,y)}}if(this.addedFinished!==null){this.addedFinished({row:0,col:this.qty})}}};return r})();h.RowAdder=(function(){function r(){this.qty=-1;this.addedFinished=null;this.createBar=null;this.createCell=null}r.prototype={setQty:function(v,t,u){var s=i.sheet.max;if(s){if(s>t.rows&&s<=t.rows+v){this.qty=s-t.rows}else{if(s&&s<=t.rows+v){return false}}}else{this.qty=v}return true},setAddedFinished:function(s){this.addedFinished=s},setCreateBarFn:function(s){this.createBar=s},setCreateCellFn:function(s){this.createCell=s},createCells:function(x,A,w){var v=(w?0:1),s=x+this.qty,u=A.cols||1,y,z=x,t;for(;z<s;z++){y=this.createBar(z+v);for(t=1;t<=u;t++){this.createCell(z+v,t,y)}}if(this.addedFinished!==null){this.addedFinished({row:this.qty,col:0})}}};return r})();h.StyleUpdater=(function(r){function s(t){var u=this.styleElement=r.createElement("style");u.styleUpdater=this;this.update=t}if(r.createElement("style").styleSheet){s.prototype={setStyle:function(u){var v=this.styleElement,t=v.styleSheet;t.disabled=false;if(!t.disabled){t.cssText=u}},getStyle:function(){var u=this.styleElement,t=u.styleSheet;t.disabled=false;if(!t.disabled){return t.cssText}return""}}}else{s.prototype={setStyle:function(t){this.styleElement.innerHTML=t},getStyle:function(){return this.styleElement.innerHTML}}}return s})(n);h.JSONLoader=(function(s,r){function t(u){this.json=u;this.count=u.length}t.prototype={size:function(x){var w={cols:0,rows:0},v=this.json,z,y,A,u;if((z=v[x])===undefined){return w}if((y=z.rows)===undefined){return w}if((A=y[0])===undefined){return w}if((u=A.columns)===undefined){return w}return{rows:y.length,cols:u.length}},setWidth:function(u,y,B){var w=this.json,A=w[u],v=A.metadata||{},z=v.widths||[],x=z[y];B.style.width=x+"px"},setRowHeight:function(v,B,y){var w=this.json,z,x,A,u;if((z=w[v])===undefined){return}if((x=z.rows)===undefined){return}if((A=x[B])===undefined){return}if((u=A.height)===undefined){return}y.style.height=u+"px"},setupCell:function(A,x,v,u,y){var B=this.json,w,D,C,z;if((w=B[A])===undefined){return false}if((D=w.rows)===undefined){return}if((C=D[x-1])===undefined){return false}if((z=C.columns[v-1])===undefined){return false}u.cellType=z.cellType||"";if(z.formula){u.formula=z.formula||"";y.setAttribute("data-formula",z.formula||"")}else{y.innerHTML=u.value=z.value||""}y.className=z["class"]||"";y.setAttribute("style",z.style||"");if(z.rowspan){y.setAttribute("rowspan",z.rowspan||"")}if(z.colspan){y.setAttribute("colspan",z.colspan||"")}return true},jitCell:function(v,B,x){var w=this.json,z,y,A,u;if((z=w[v])===undefined){return null}if((y=z.rows)===undefined){return null}if((A=y[B-1])===undefined){return null}if((u=A.columns[x-1])===undefined){return null}return{td:{cellIndex:x,parentNode:{rowIndex:B},html:function(){}},html:[],state:[],calcLast:-1,calcDependenciesLast:-1,cellType:u.cellType||"",formula:u.formula||"",value:u.value||""}},toTables:function(){var M=this.json,C=s([]),z,E,A,w,x,G,F,I,u,H;for(var L=0;L<M.length;L++){z=M[L];var N=s(r.createElement("table"));if(z.title){N.attr("title",z.title||"")}C=C.add(N);E=z.rows;for(var K=0;K<E.length;K++){A=E[K];if(H=(A.height+"").replace("px","")){var v=s(r.createElement("tr")).attr("height",H).css("height",H+"px").appendTo(N)}w=A.columns;for(var J=0;J<w.length;J++){x=w[J];var B=s(r.createElement("td")).appendTo(v);if(x["class"]){B.attr("class",x["class"]||"")}if(x.style){B.attr("style",x.style||"")}if(x.formula){B.attr("data-formula",(x.formula?"="+x.formula:""))}if(x.cellType){B.attr("data-celltype",x.cellType||"")}if(x.value){B.html(x.value||"")}if(x.rowspan){B.attr("rowspan",x.rowspan||"")}if(x.colspan){B.attr("colspan",x.colspan||"")}}}if(G=z.metadata){if(F=G.widths){var D=s(r.createElement("colgroup")).prependTo(N);for(var J=0;J<F.length;J++){I=(F[J]+"").replace("px","");var y=s(r.createElement("col")).attr("width",I).css("width",I+"px").appendTo(D)}}if(u=G.frozenAt){if(u.row){N.attr("data-frozenatrow",u.row)}if(u.col){N.attr("data-frozenatcol",u.col)}}}}return C},fromTables:function(D,y){y=(y==undefined?false:y);var G=[],L=1*D.i,z=D.spreadsheets.length-1,M,B,C,x,E,K,w,u,I,F,H,J,A,v;if(z<0){return G}do{J=false;D.i=z;D.evt.cellEditDone();M={title:(D.obj.table().attr("title")||""),rows:[],metadata:{widths:[],frozenAt:s.extend({},D.obj.pane().actionUI.frozenAt)}};G.unshift(M);B=D.spreadsheets[z];C=B.length-1;do{A=B[C][1].td[0].parentNode;v=A.style.height;K={columns:[],height:(v?v.replace("px",""):D.s.colMargin)};x=B[C].length-1;do{u=B[C][x];w={};I=u.td[0].attributes;if(y||J||I["class"]||u.formula||u.value||I.style){J=true;F=(I["class"]?s.trim((I["class"].value||"").replace(D.cl.uiCellActive,"").replace(D.cl.uiCellHighlighted,"")):"");H=u.td[0].parentNode;K.columns.unshift(w);if(!K.height){K.height=(H.style.height?H.style.height.replace("px",""):D.s.colMargin)}if(u.formula){w.formula=u.formula}if(u.cellType){w.cellType=u.cellType}if(u.value){w.value=u.value}if(I.style&&I.style.value){w.style=I.style.value}if(F.length){w["class"]=F}if(I.rowspan){w.rowspan=I.rowspan.value}if(I.colspan){w.colspan=I.colspan.value}}if(C*1==1){M.metadata.widths.unshift(s(D.col(null,x)).css("width").replace("px",""))}}while(x-->1);if(J){M.rows.unshift(K)}}while(C-->1)}while(z--);D.i=L;return G},getCellValue:function(){}};return t})(jQuery,n);h.XMLLoader=(function(s,r){function t(u){this.xml=s.parseXML(u);this.spreadsheets=this.xml.getElementsByTagName("spreadsheets")[0].getElementsByTagName("spreadsheet");this.count=this.xml.length}t.prototype={size:function(w){var u=this.xml[w],x=u.rows,y=x[0],v=y.columns;return{rows:x.length,cols:v.length}},setWidth:function(C,z,x){var y=this.spreadsheets,B=y[C],A=B.getElementsByTagName("metadata")[0]||{},v=A.getElementsByTagName("width")||[],w=v[z],u=(w.textContent||w.text);x.style.width=u+"px"},setRowHeight:function(v,B,z){var x=this.spreadsheets,w,y,A,u;if((w=x[v])===undefined){return}if((y=w.getElementsByTagName("rows")[0].getElementsByTagName("row"))===undefined){return}if((A=y[B])===undefined){return}if((u=A.attributes.height.nodeValue)===undefined){return}z.style.height=u+"px"},setupCell:function(B,x,w,u,y){var v=this.spreadsheets,A,C,z;if((A=v[B])===undefined){return false}if((C=A.getElementsByTagName("rows")[0].getElementsByTagName("row")[x-1])===undefined){return false}if((z=C.getElementsByTagName("columns")[0].getElementsByTagName("column")[w-1])===undefined){return false}u.cellType=z.attributes.cellType.nodeValue||"";if(z.attributes.formula){u.formula=z.attributes.formula.nodeValue||"";y.setAttribute("data-formula",z.attributes.formula.nodeValue||"")}else{y.innerHTML=u.value=z.attributes.value.nodeValue||""}y.className=z.attributes["class"].nodeValue||"";y.setAttribute("style",z.attributes.style.nodeValue||"");if(z.attributes.rowspan){y.setAttribute("rowspan",z.attributes.rowspan.nodeValue||"")}if(z.attributes.colspan){y.setAttribute("colspan",z.attributes.colspan.nodeValue||"")}return true},toTables:function(){var B=this.xml,F=s([]),z=B.getElementsByTagName("spreadsheets")[0].getElementsByTagName("spreadsheet"),C,J,D,x,A,R,M,X,L,I,K,O,N;for(var U=0;U<z.length;U++){C=z[U];var W=s(r.createElement("table")).attr("title",(C.attributes.title?C.attributes.title.nodeValue:"")),H=s(r.createElement("colgroup")).appendTo(W),v=s(r.createElement("tbody")).appendTo(W);F=F.add(W);J=C.getElementsByTagName("rows")[0].getElementsByTagName("row");M=C.getElementsByTagName("metadata")[0];for(var S=0;S<J.length;S++){D=J[S];var w=s(r.createElement("tr")).appendTo(v);if(N=D.attributes.height){N=(N.nodeValue||"").replace("px","");w.css("height",N).attr("height",N+"px")}x=D.getElementsByTagName("columns")[0].getElementsByTagName("column");for(var Q=0;Q<x.length;Q++){A=x[Q];var E=s(r.createElement("td")).appendTo(w),u=A.getElementsByTagName("formula")[0],T=A.getElementsByTagName("cellType")[0],P=A.getElementsByTagName("value")[0],V=A.getElementsByTagName("style")[0],G=A.getElementsByTagName("class")[0],Y=A.getElementsByTagName("rowspan")[0],y=A.getElementsByTagName("colspan")[0];if(u){E.attr("data-formula","="+(u.textContent||u.text))}if(T){E.attr("data-celltype",T.textContent||T.text)}if(P){E.html(P.textContent||P.text)}if(V){E.attr("style",V.textContent||V.text)}if(G){E.attr("class",G.textContent||G.text)}if(Y){E.attr("rowspan",Y.textContent||Y.text)}if(y){E.attr("colspan",y.textContent||y.text)}}}K=M.getElementsByTagName("width");for(var S=0;S<K.length;S++){O=(K[S].textContent||K[S].text).replace("px","");s(r.createElement("col")).attr("width",O).css("width",O+"px").appendTo(H)}X=M.getElementsByTagName("frozenAt")[0];if(X){I=X.getElementsByTagName("col")[0];L=X.getElementsByTagName("row")[0];if(I){W.attr("data-frozenatcol",(I.textContent||I.text)*1)}if(L){W.attr("data-frozenatrow",(L.textContent||L.text)*1)}}}return F},fromTables:function(F,A){A=(A==undefined?false:A);var I="",P=1*F.i,B=F.spreadsheets.length-1,v,D,E,z,G,N,O,x,w,L,H,J,u,M,K,C,y;if(B<0){return I}do{M=false;F.i=B;F.evt.cellEditDone();u=s.extend({},F.obj.pane().actionUI.frozenAt);K=[];D=F.spreadsheets[B];E=D.length-1;N="";do{x="";z=D[E].length-1;do{O="";w=D[E][z];L=w.td[0].attributes;H=(L["class"]?s.trim((L["class"].value||"").replace(F.cl.uiCellActive,"").replace(F.cl.uiCellHighlighted,"")):"");if(A||M||H||w.formula||w.value||L.style){M=true;O+="<column>";if(w.formula){O+="<formula>"+w.formula+"</formula>"}if(w.cellType){O+="<cellType>"+w.cellType+"</cellType>"}if(w.value){O+="<value>"+w.value+"</value>"}if(L.style){O+="<style>"+L.style.value+"</style>"}if(H){O+="<class>"+H+"</class>"}if(L.rowspan){O+="<rowspan>"+L.rowspan.value+"</rowspan>"}if(L.colspan){O+="<colspan>"+L.colspan.value+"</colspan>"}O+="</column>";x=O+x}if(E*1==1){K[z]="<width>"+s(F.col(null,z)).css("width").replace("px","")+"</width>"}}while(z-->1);if(x){C=D[E][1].td[0].parentNode;y=C.style.height;N='<row height="'+(y?y.replace("px",""):F.s.colMargin)+'"><columns>'+x+"</columns></row>"+N}}while(E-->1);v='<spreadsheet title="'+(F.obj.table().attr("title")||"")+'"><rows>'+N+"</rows><metadata>"+(u.row||u.col?"<frozenAt>"+(u.row?"<row>"+u.row+"</row>":"")+(u.col?"<col>"+u.col+"</col>":"")+"</frozenAt>":"")+"<widths>"+K.join("")+"</widths></metadata></spreadsheet>";I=v+I}while(B--);F.i=P;return'<?xml version="1.0" encoding="UTF-8"?><spreadsheets xmlns="http://www.w3.org/1999/xhtml">'+I+"</spreadsheets>"}};return t})(jQuery,n);i.fn.extend({sheet:function(s){var t=isNaN,r=i.sheet.events;s=s||{};i(this).each(function(){var A=Globalize,x=i(this),z={editable:true,editableNames:true,barMenus:true,freezableCells:true,allowToggleState:true,menuLeft:null,menuRight:null,newColumnWidth:120,title:null,calcOff:false,lockFormulas:false,parent:x,colMargin:18,boxModelCorrection:2,formulaFunctions:{},formulaVariables:{},cellSelectModel:"excel",autoAddCells:true,resizableCells:true,resizableSheet:true,autoFiller:true,minSize:{rows:1,cols:1},error:function(B){return B.error},endOfNumber:false,encode:function(B){switch(typeof B){case"object":if(B.getMonth){return A.format(B,"d")}return B}if(!B){return B||""}if(!B.replace){return B||""}return B.replace(/&/gi,"&").replace(/>/gi,">").replace(/</gi,"<").replace(/\n/g,"\n<br>").replace(/\t/g,"   ").replace(/ /g," ")},frozenAt:[],contextmenuTop:{"Toggle freeze columns to here":function(D){var B=D.getTdLocation(D.obj.tdActive()).col,C=D.obj.pane().actionUI;C.frozenAt.col=(C.frozenAt.col==B?0:B)},"Insert column after":function(B){B.controlFactory.addColumn(B.colLast);return false},"Insert column before":function(B){B.controlFactory.addColumn(B.colLast,true);return false},"Add column to end":function(B){B.controlFactory.addColumn();return false},"Delete this column":function(B){B.deleteColumn();return false},"Hide column":function(B){B.toggleHideColumn();return false}},contextmenuLeft:{"Toggle freeze rows to here":function(C){var D=C.getTdLocation(C.obj.tdActive()).row,B=C.obj.pane().actionUI;B.frozenAt.row=(B.frozenAt.row==D?0:D)},"Insert row after":function(B){B.controlFactory.addRow(B.rowLast);return false},"Insert row before":function(B){B.controlFactory.addRow(B.rowLast,true);return false},"Add row to end":function(B){B.controlFactory.addRow();return false},"Delete this row":function(B){B.deleteRow();return false},"Hide row":function(B){B.toggleHide.row();return false}},contextmenuCell:{Copy:false,Cut:false,"Insert column after":function(B){B.controlFactory.addColumn(B.colLast);return false},"Insert column before":function(B){B.controlFactory.addColumn(B.colLast,true);return false},"Add column to end":function(B){B.controlFactory.addColumn();return false},"Delete this column":function(B){B.deleteColumn();return false},line1:"line","Insert row after":function(B){B.controlFactory.addRow(B.rowLast);return false},"Insert row before":function(B){B.controlFactory.addRow(B.rowLast,true);return false},"Add row to end":function(B){B.controlFactory.addRow();return false},"Delete this row":function(B){B.deleteRow();return false},line2:"line","Add spreadsheet":function(B){B.addSheet()},"Delete spreadsheet":function(B){B.deleteSheet()}},hiddenRows:[],hiddenColumns:[],cellStartingHandlers:{"$":function(C,B){return e.DOLLAR.call(this,C.substring(1).replace(A.culture().numberFormat[","],""),2,B||"$")},"£":function(B){return y.s.cellStartingHandlers["$"].call(this,B,"£")}},cellEndHandlers:{"%":function(B){return B.substring(0,this.value.length-1)/100}},cellTypeHandlers:{percent:function(D){var C=(t(D)?A.parseFloat(D):D*1),B;if(!t(C)){B=new l(C);B.html=A.format(C,"p");return B}return D},date:function(C){var B=A.parseDate(C);B.html=A.format(B,"d");return B},time:function(C){var B=A.parseDate(C);B.html=A.format(B,"t");return B},currency:function(D){var C=(t(D)?A.parseFloat(D):D*1),B;if(!t(C)){B=new l(C);B.html=A.format(C,"c");return B}return D},number:function(D){var C,B;if(!s.endOfNumber){C=A.culture().numberFormat["."];s.endOfNumber=new q("(["+(C=="."?".":C)+"])([0-9]*?[1-9]+)?(0)*$")}if(!t(D)){B=new l(D);B.html=A.format(D+"","n10").replace(s.endOfNumber,function(G,F,E){return(E?F:"")+(E||"")});return B}return D}},alert:function(B){alert(B)},prompt:function(C,D,B){D(prompt(C,B))},confirm:function(D,B,C){if(confirm(D)){B()}else{if(C){C()}}},initCalcRows:40,initCalcCols:20,initScrollRows:0,initScrollCols:0,loader:null};var y=this.jS;if(y){var v=x.children().detach();y.kill();x.html(v);for(var w in r){if(s[r[w]]){x.unbind(r[w])}}}if((this.className||"").match(/\bnotEditable\b/i)!=null){s.editable=false}for(var u in r){if(s[r[u]]){x.bind(r[u],s[r[u]])}}if(!i.sheet.instance.length){i.sheet.instance=[]}this.jS=y=i.sheet.createInstance(i.extend(z,s),i.sheet.instance.length);i.sheet.instance.push(y)});return this},disableSelectionSpecial:function(){this.each(function(){this.onselectstart=function(){return false};this.unselectable="on";this.style["-moz-user-select"]="none"});return this},getSheet:function(){var r=this[0],s=(r.jS||{});return s},getCellValue:function(w,s,r){var t=this[0],u=(t.jS||{});r=(r||0);if(u.updateCellValue){try{return u.updateCellValue(r,w,s)}catch(v){}}return null},setCellValue:function(w,y,t,s){var u=this[0],v=(u.jS||{}),r;s=(s||0);if(v.getCell&&(r=v.getCell(y,t,s))){try{if((w+"").charAt(0)=="="){r.valueOverride=r.value="";r.formula=w.substring(1)}else{r.value=w;r.valueOverride=r.formula=""}r.calcLast=r.calcDependenciesLast=0;v.updateCellValue.call(r);v.updateCellDependencies.call(r);return true}catch(x){}}return false},setCellFormula:function(y,x,t,s){var u=this[0],v=(u.jS||{}),r;s=(s||0);if(v.getCell&&(r=v.getCell(x,t,s))){try{r.formula=y;r.valueOverride=r.value="";r.calcLast=r.calcDependenciesLast=0;v.updateCellValue(s,x,t)}catch(w){}}return this},setCellHtml:function(u,y,t,s){var v=this[0],w=(v.jS||{}),r;s=(s||0);if(w.getCell&&(r=w.getCell(y,t,s))){try{r.html=[u];r.calcLast=r.calcDependenciesLast=0;w.updateCellValue(s,y,t)}catch(x){}}return this},isSheetFullScreen:function(){var r=this[0],s=(r.jS||{});if(s.obj){return s.obj.fullScreen().is(":visible")}return false},serializeCellInputs:function(s){var t=this[0],u=(t.jS||{}),r=u.obj.tables().find(":input");if(s){return r.serializeArray()}else{return r.serialize()}},viewSource:function(r){var s="";i(this).each(function(){if(r){s+=i(this).toPrettySource()}else{s+=i(this).toCompactSource()}});i.print(s);return s},toCompactSource:function(){var v=this[0];var s="";if(v.nodeType==1){s+="<"+v.tagName.toLowerCase();var x=v.attributes.length;for(var u=0;u<x;u++){var t=v.attributes[u].name,w=v.getAttribute(t);if(w){if(t=="contentEditable"&&w=="inherit"){continue}if(typeof(w)=="string"){s+=" "+t+'="'+w.replace(/"/g,"'")+'"'}else{if(t=="style"&&w.cssText){s+=' style="'+w.cssText+'"'}}}}if(v.tagName=="COL"){s+="/>"}else{s+=">";var r="";i(v.childNodes).each(function(){r+=i(this).toCompactSource()});s+=r;s+="</"+v.tagName.toLowerCase()+">"}}else{if(v.nodeType==3){s+=v.data.replace(/^\s*(.*)\s*$/g,"$1")}}return s},toPrettySource:function(w){var v=this[0],y,u;w=w||"";var s="";if(v.nodeType==1){s+="\n"+w+"<"+v.tagName.toLowerCase();y=v.attributes.length;for(u=0;u<y;u++){var t=v.attributes[u].name,x=v.getAttribute(t);if(x){if(t=="contentEditable"&&x=="inherit"){continue}if(typeof(x)=="string"){s+=" "+t+'="'+i.trim(x.replace(/"/g,"'"))+'"'}else{if(t=="style"&&x.cssText){s+=' style="'+i.trim(x.cssText)+'"'}}}}if(v.childNodes.length<=0){if(v.tagName=="COL"){s+="/>"}else{s+="></"+v.tagName.toLowerCase()+">"}}else{s+=">";var r="";y=v.childNodes.length;for(u=0;u<y;u++){r+=i(v.childNodes[u]).toPrettySource(w+" ")}s+=r;if(r.indexOf("\n")>=0){s+="\n"+w}s+="</"+v.tagName.toLowerCase()+">"}}else{if(v.nodeType==3){s+=v.data.replace(/^\s*(.*)\s*$/g,"$1")}}return s}});i.sheet={instance:[],dependencies:{coreCss:{css:"jquery.sheet.css"},formulaParser:{script:"parser/formula/formula.js"},tsvParser:{script:"parser/tsv/tsv.js"},jQueryUI:{script:"jquery-ui/jquery-ui.min.js",thirdParty:true},jQueryUIThemeRoller:{css:"jquery-ui/themes/smoothness/jquery-ui.min.css",thirdParty:true},globalize:{script:"globalize/lib/globalize.js",thirdParty:true},nearest:{script:"jquery-nearest/src/jquery.nearest.min.js",thirdParty:true},mousewheel:{script:"MouseWheel/MouseWheel.js",thirdParty:true}},optional:{advancedFn:{script:"plugins/jquery.sheet.advancedfn.js"},financeFn:{script:"plugins/jquery.sheet.financefn.js"},colorPicker:{css:"really-simple-color-picker/colorPicker.css",script:"really-simple-color-picker/jquery.colorPicker.min.js",thirdParty:true},elastic:{script:"jquery-elastic/jquery.elastic.source.js",thirdParty:true},globalizeCultures:{script:"globalize/lib/cultures/globalize.cultures.js",thirdParty:true},raphael:{script:"raphael/raphael-min.js",thirdParty:true},gRaphael:{script:"graphael/g.raphael.js",thirdParty:true},gRaphaelBar:{script:"graphael/g.bar.js",thirdParty:true},gRaphaelDot:{script:"graphael/g.dot.js",thirdParty:true},gRaphaelLine:{script:"graphael/g.line.js",thirdParty:true},gRaphaelPie:{script:"graphael/g.pie.js",thirdParty:true},undoManager:{script:"Javascript-Undo-Manager/js/undomanager.js",thirdParty:true},zeroClipboard:{script:"zeroclipboard/dist/ZeroClipboard.min.js",thirdParty:true}},events:["sheetAddRow","sheetAddColumn","sheetSwitch","sheetRename","sheetTabSortStart","sheetTabSortUpdate","sheetCellEdit","sheetCellEdited","sheetCalculation","sheetAdd","sheetDelete","sheetDeleteRow","sheetDeleteColumn","sheetOpen","sheetAllOpened","sheetSave","sheetFullScreen","sheetFormulaKeydown"],preLoad:function(u,t){u=u||"";t=i.extend({skip:["globalizeCultures"],thirdPartyDirectory:"bower_components/"},t);var s=function(){if(this.script!==undefined){n.write('<script src="'+u+(this.thirdParty?t.thirdPartyDirectory:"")+this.script+'"><\/script>')}if(this.css!==undefined){n.write('<link rel="stylesheet" type="text/css" href="'+u+(this.thirdParty?t.thirdPartyDirectory:"")+this.css+'"></link>')}};for(var r in t.skip){if(this.dependencies[t.skip[r]]){delete this.dependencies[t.skip[r]]}if(this.optional[t.skip[r]]){delete this.optional[t.skip[r]]}}i.each(this.dependencies,function(){s.call(this)});i.each(this.optional,function(){s.call(this)})},createInstance:function(K,E){var J=this,A=function(I,s){var u=s.parentNode;if(u.lastchild==s){u.appendChild(I)}else{u.insertBefore(I,s.nextSibling)}},r=i(k),w=i(n),B=n.body,y=i(B),F=function(){},H=undefined,D=c,v=isNaN,G=NaN,t=function(s){this.cells=s||[]},C=t.prototype={clone:function(){var I=[];for(var u=0;u<this.cells.length;u++){var s=this.cells[u],L={value:s.value,formula:s.formula,td:s.td,dependencies:s.dependencies,needsUpdated:s.needsUpdated,calcCount:s.calcCount,sheet:s.sheet,calcLast:s.calcLast,html:s.html,state:s.state,jS:s.jS,calcDependenciesLast:s.calcDependenciesLast,style:s.style||s.td.attr("style")||"",cl:s.cl||s.td.attr("class")||""};I.push(L)}return new t(I)}},z={version:"4.x",i:0,I:E,sheetCount:0,spreadsheets:[],controls:{autoFiller:[],bar:{helper:[],corner:[],x:{controls:[],handleFreeze:[],menu:[],menuParent:[],parent:[],td:[],tds:function(){var u=i([]);for(var s in this.td[z.i]){u.pushStack(this.td[z.i][s])}return u}},y:{controls:[],handleFreeze:[],menu:[],parent:[],td:[],tds:function(){var u=i([]);for(var s in this.td[z.i]){u.pushStack(this.td[z.i][s])}return u}}},barMenuLeft:[],barMenuTop:[],barLeft:[],barTop:[],barTopParent:[],chart:[],tdMenu:[],cellsEdited:[],enclosure:[],enclosures:null,formula:null,fullScreen:null,header:null,inPlaceEdit:[],inputs:[],label:null,menuLeft:[],menuRight:[],menus:[],pane:[],panes:null,scrolls:null,sheetAdder:null,table:[],tables:null,tab:[],tabContainer:null,tabs:null,title:null,toggleHide:{x:[],y:[]},ui:null},obj:{autoFiller:function(){return z.controls.autoFiller[z.i]||i([])},barCorner:function(){return z.controls.bar.corner[z.i]||i([])},barHelper:function(){return z.controls.bar.helper[z.i]||(z.controls.bar.helper[z.i]=i([]))},barLeft:function(s){return(z.controls.bar.y.td[z.i]&&z.controls.bar.y.td[z.i][s]?z.controls.bar.y.td[z.i][s]:i([]))},barLeftControls:function(){return z.controls.bar.y.controls[z.i]||i([])},barLefts:function(){return z.controls.bar.y.tds()},barHandleFreezeLeft:function(){return z.controls.bar.y.handleFreeze[z.i]||i([])},barMenuLeft:function(){return z.controls.bar.y.menu[z.i]||i([])},barTop:function(s){return(z.controls.bar.x.td[z.i]&&z.controls.bar.x.td[z.i][s]?z.controls.bar.x.td[z.i][s]:i([]))},barTopControls:function(){return z.controls.bar.x.controls[z.i]||i([])},barTops:function(){return z.controls.bar.x.tds()},barTopParent:function(){return z.controls.bar.x.parent[z.i]||i([])},barHandleFreezeTop:function(){return z.controls.bar.x.handleFreeze[z.i]||i([])},barMenuParentTop:function(){return z.controls.bar.x.menuParent[z.i]||i([])},barMenuTop:function(){return z.controls.bar.x.menu[z.i]||i([])},tdActive:function(){return z.cellLast.td||i([])},tdMenu:function(){return z.controls.tdMenu[z.i]||i([])},cellsEdited:function(){return z.controls.cellsEdited[z.i]||i([])},chart:function(){return z.controls.chart[z.i]||i([])},enclosure:function(){return z.controls.enclosure[z.i]||i([])},enclosures:function(){return z.controls.enclosures||i([])},formula:function(){return z.controls.formula||i([])},fullScreen:function(){return z.controls.fullScreen||i([])},header:function(){return z.controls.header||i([])},highlighted:function(){return z.highlightedLast.obj||i([])},menuRight:function(){return z.controls.menuRight[z.i]||i([])},inPlaceEdit:function(){return z.controls.inPlaceEdit[z.i]||i([])},inputs:function(){return z.controls.inputs[z.i]||i([])},label:function(){return z.controls.label||i([])},menus:function(){return z.controls.menus[z.i]||i([])},menuLeft:function(){return z.controls.menuLeft[z.i]||i([])},pane:function(){return z.controls.pane[z.i]||{}},panes:function(){return z.controls.panes||i([])},parent:function(){return K.parent},scrolls:function(){return z.controls.scrolls||i([])},sheetAdder:function(){return z.controls.sheetAdder||i([])},table:function(){return z.controls.table[z.i]||i([])},tables:function(){return z.controls.tables||i([])},tab:function(){return z.controls.tab[z.i]||i([])},tabs:function(){return z.controls.tabs||i([])},tabContainer:function(){return z.controls.tabContainer||i([])},title:function(){return z.controls.title||i([])}},id:"jS_"+E+"_",cl:{autoFiller:"jSAutoFiller",autoFillerHandle:"jSAutoFillerHandle",autoFillerCover:"jSAutoFillerCover",barCorner:"jSBarCorner",barController:"jSBarController",barHelper:"jSBarHelper",barLeft:"jSBarLeft",barHandleFreezeLeft:"jSBarHandleFreezeLeft",barTop:"jSBarTop",barTopMenuButton:"jSBarTopMenuButton",barHandleFreezeTop:"jSBarHandleFreezeTop",barTopParent:"jSBarTopParent",chart:"jSChart",formula:"jSFormula",formulaParent:"jSFormulaParent",header:"jSHeader",fullScreen:"jSFullScreen",inPlaceEdit:"jSInPlaceEdit",menu:"jSMenu",menuFixed:"jSMenuFixed",parent:"jSParent",scroll:"jSScroll",sheetAdder:"jSSheetAdder",table:"jS",label:"jSLoc",pane:"jSEditPane",tab:"jSTab",tabContainer:"jSTabContainer",tdMenu:"jSTdMenu",title:"jSTitle",enclosure:"jSEnclosure",ui:"jSUI",uiAutoFiller:"ui-state-active",uiBar:"ui-widget-header",uiBarHighlight:"ui-state-active",uiBarHandleFreezeLeft:"ui-state-default",uiBarHandleFreezeTop:"ui-state-default",uiBarMenuTop:"ui-state-default",uiTdActive:"ui-state-active",uiTdHighlighted:"ui-state-highlight",uiControl:"ui-widget-header ui-corner-top",uiControlTextBox:"ui-widget-content",uiFullScreen:"ui-widget-content ui-corner-all",uiInPlaceEdit:"ui-state-highlight",uiMenu:"ui-widget-header",uiMenuUl:"ui-widget-header",uiMenuLi:"ui-widget-header",uiPane:"ui-widget-content",uiParent:"ui-widget-content ui-corner-all",uiTable:"ui-widget-content",uiTab:"ui-widget-header",uiTabActive:"ui-state-highlight"},msg:{addRowMulti:"How many rows would you like to add?",addColumnMulti:"How many columns would you like to add?",cellFind:"What are you looking for in this spreadsheet?",cellNoFind:"No results found.",dragToFreezeCol:"Drag to freeze column",dragToFreezeRow:"Drag to freeze row",addSheet:"Add a spreadsheet",openSheet:"Are you sure you want to open a different sheet? All unsaved changes will be lost.",toggleHideRow:"No row selected.",toggleHideColumn:"No column selected.",loopDetected:"Loop Detected",newSheetTitle:"What would you like the sheet's title to be?",notFoundColumn:"Column not found",notFoundRow:"Row not found",notFoundSheet:"Sheet not found",setCellRef:"Enter the name you would like to reference the cell by.",sheetTitleDefault:"Spreadsheet {index}",maxRowsBrowserLimitation:"You've reached the maximum amount of rows this browser supports. Try using Chrome, FireFox, or Internet Explorer 9+",maxColsBrowserLimitation:"You've reached the maximum amount of columns this browser supports. Try using Chrome, FireFox, or Internet Explorer 9+",maxSizeBrowserLimitationOnOpen:"The spreadsheet you are loading is larger than the maximum size of cells this browser supports. Try using Chrome, Firefox, or Internet Explorer 9+. You can an proceed, but the spreadsheet may not work as intended."},kill:function(){if(!z){return false}i(n).unbind("keydown");this.obj.fullScreen().remove();(this.obj.inPlaceEdit().destroy||F)();K.parent.trigger("sheetKill").removeClass(z.cl.uiParent).html("");K.parent[0].jS=H;this.obj.menus().remove();var s=i.sheet.events.length;for(var u=0;u<s;u++){K.parent.unbind(i.sheet.events[u])}i.sheet.instance.splice(E,1);return true},trigger:function(s,u){u=u||[];return K.parent.triggerHandler(s,[z].concat(u))},spreadsheetsToArray:function(s){if(s||z.spreadsheets.length==0){z.cycleCellsAll(function(I,L,u){z.createCell(I,L,u)})}return z.spreadsheets},spreadsheetToArray:function(u,s){s=(s?s:z.i);if(!z.spreadsheets[s]){z.cycleCells(function(L,M,I){z.createCell(L,M,I)})}return z.spreadsheets[s]},createCell:function(N,Q,S,V,U,Y){var u,O,R,X,T,I,L,s,P,M,Z,W;if(!(u=z.spreadsheets[N])){u=z.spreadsheets[N]=[]}if(!(O=u[Q])){O=u[Q]=[]}if(!(X=z.controls.tables[N])||!(L=X.tBody)||!(s=L.children[Q])||!(P=s.children[S])){return}M=i(P);R=O[S]=P.jSCell={td:M,dependencies:[],formula:P.getAttribute("data-formula")||"",cellType:P.getAttribute("data-celltype")||null,value:P.textContent||P.innerText||"",calcCount:V||0,calcLast:U||-1,calcDependenciesLast:Y||-1,sheet:N,type:"cell",jS:z,state:[],needsUpdated:true,uneditable:P.getAttribute("data-uneditable")||false};if(R.formula&&R.formula.charAt(0)=="="){R.formula=R.formula.substring(1)}T=X.colGroup;while(!(I=T.children[S])){I=n.createElement("col");I.setAttribute("style","width:"+z.s.newColumnWidth+"px;");T.appendChild(I)}z.shortenCellLookupTime(S,R,P,I,s,L,X);if(!(W=z.controls.bar.y.td[N])){W=z.controls.bar.y.td[N]=[]}if(!W[Q]){W[Q]=i(s.children[0])}if(!(Z=z.controls.bar.x.td[N])){Z=z.controls.bar.x.td[N]=[]}if(!Z[S]){Z[S]=i(L.children[0].children[S])}return R},shortenCellLookupTime:function(I,N,P,u,O,s,M){var L;if(!(L=u.jSCells)){L=u.jSCells=[]}L.unshift(N);if(!u.tds){u.tds=[]}u.tds.unshift(P);P.col=u;P.type="cell";P.barLeft=P.barLeft||O.children[0];P.barTop=P.barTop||s.children[0].children[I];if(!O.jSCells){O.jSCells=[]}O.jSCells.unshift(N);if(!O.tds){O.tds=[]}O.tds.unshift(P);if(!M.jSCells){M.jSCells=[]}M.jSCells.unshift(N);if(!M.tds){M.tds=[]}M.tds.unshift(P);P.table=M},createUnboundCell:function(s,u){return u.jSCell={td:i(u),dependencies:[],formula:"",cellType:null,value:"",calcCount:0,calcLast:-1,calcDependenciesLast:-1,sheet:s,type:"cell",jS:z,state:[],needsUpdated:true,uneditable:false}},getCell:function(N,L,I){var u,M,s;I=(I||0);if(z.spreadsheets&&(u=z.spreadsheets[I])&&(M=u[N])&&(s=M[L])){return s}return null},nav:false,setNav:function(I){var s=i.sheet.instance;for(var u=0;u<s.length;u++){(s[u]||{}).nav=false}z.nav=I},controlFactory:{addRowMulti:function(I,M,u,s){function L(N){if(N){if(!v(N)){z.controlFactory.addCells(I,u,parseInt(N),"row",s);z.trigger("sheetAddRow",[I,u,N])}}}if(!M){K.prompt(z.msg.addRowMulti,L)}else{L(M)}},addColumnMulti:function(I,M,u,s){function L(N){if(N){if(!v(N)){z.controlFactory.addCells(I,u,parseInt(N),"col",s);z.trigger("sheetAddColumn",[I,u,N])}}}if(!M){K.prompt(z.msg.addColumnMulti,L)}else{L(M)}},rowAdder:new h.RowAdder(),columnAdder:new h.ColumnAdder(),addCells:function(ac,af,P,I,T){z.autoFillerHide();z.setDirty(true);z.setChanged(true);z.obj.barHelper().remove();var R=z.obj.table(),ad=R[0],L=ad.tBody,Z=ad.colGroup,S=false,X=z.obj.tdActive(),N=z.spreadsheets[z.i]||(z.spreadsheets[z.i]=[]),Y,M,aa=K.newColumnWidth+"px",W=K.colMargin+"px",U=z.cl.barLeft+" "+z.cl.uiBar,ae=z.cl.barTop+" "+z.cl.uiBar,O,Q=K.loader||{},V=Q.setupCell||null,u=z.controls.bar.x.td[z.i]||(z.controls.bar.x.td[z.i]=[]),s=z.controls.bar.y.td[z.i]||(z.controls.bar.y.td[z.i]=[]),ab=ad.size();P=P||1;I=I||"col";switch(I){case"row":if(!ac){ac=ab.rows;S=true}O={row:ac,col:0};Y=this.rowAdder;if(Y.setQty(P,ab)===false){if(!z.isBusy()){K.alert(z.msg.maxRowsBrowserLimitation)}return}Y.setCreateBarFn(function(ag){var ah=n.createElement("tr"),ai=n.createElement("td");ai.setAttribute("class",U);ai.entity="left";ai.type="bar";ai.style.height=W;ah.appendChild(ai);L.insertBefore(ah,L.children[ag+1]);ai.innerHTML=ah.rowIndex;s.splice(ag,0,i(ai));N.splice(ag,0,[]);return ah});Y.setCreateCellFn(function(ak,ai,ah){var al=n.createElement("td"),ag=z.createUnboundCell(z.i,al),aj=N[ak];aj[ai]=ag;if(V){if(V.call(Q,z.i,ak,ai,ag,al)){z.updateCellValue.call(ag)}}ah.insertBefore(al,ah.children[ai]);z.shortenCellLookupTime(ai,ag,al,Z.children[ai],ah,L,ad)});Y.setAddedFinished(function(ah,ag){z.refreshRowLabels(ah);M=ag});break;case"col":if(!ac){ac=ab.cols;S=true}O={row:0,col:ac};Y=this.columnAdder;if(Y.setQty(P,ab)===false){if(!z.isBusy()){K.alert(z.msg.maxColsBrowserLimitation)}return}Y.setCreateBarFn(function(ai){var aj=L.children[0],ak=n.createElement("col"),al=n.createElement("td"),ah,ag=L.children[1];ak.style.width=aa;al.entity="top";al.type="bar";al.innerHTML=d.columnLabelString(ai);al.className=ae;if(ag===undefined){ah=n.createElement("td");ah.setAttribute("class",U);ah.entity="left";ah.type="bar";ag=n.createElement("tr");ag.style.height=W;ag.appendChild(ah);L.appendChild(ag);ah.innerHTML=ag.rowIndex}Z.insertBefore(ak,Z.children[ai]);aj.insertBefore(al,aj.children[ai]);u.splice(ai,0,i(al));return{bar:al,col:ak,barParent:aj}});Y.setCreateCellFn(function(al,ai,aj){var am=n.createElement("td"),ah=z.createUnboundCell(z.i,am),ag=L.children[al],ak=N[al];if(ak===undefined){N[al]=ak=[]}ak[ai]=ah;if(V){if(V.call(Q,z.i,al,ai,ah,am)){z.updateCellValue.call(ah)}}ag.insertBefore(am,ag.children[ai]);z.shortenCellLookupTime(ai,ah,am,aj.col,ag,L,ad)});Y.setAddedFinished(function(ag){z.refreshColumnLabels(ac);M=ag});break}Y.createCells(ac,ab,af);if(!T&&S!=true){z.offsetFormulas(O,M,af)}z.obj.pane().resizeScroll(true);if(X&&X[0]&&X[0].cellIndex&&X[0].parentNode){z.colLast=X[0].cellIndex;z.rowLast=X[0].parentNode.rowIndex}return true},addRow:function(u,s){z.controlFactory.addCells(u,s,1,"row");z.trigger("sheetAddRow",[u,s,1])},addColumn:function(u,s){z.controlFactory.addCells(u,s,1,"col");z.trigger("sheetAddColumn",[u,s,1])},barLeft:function(u){var I=u.tBody.children,s=I.length-1;if(s>0){do{I[s].insertBefore(n.createElement("td"),I[s].children[0])}while(s-->1)}},barTop:function(R){var s=R.colGroup,Q=s.children,N,u=R.tBody.children[0],P=n.createElement("col"),M=n.createElement("td"),O=n.createElement("tr"),L=0;if(u===undefined){s.innerHTML=""}else{L=u.children.length;while(Q.length>L){s.removeChild(Q[Q.length-1])}}P.width=K.colMargin+"px";P.style.width=P.width;s.insertBefore(P,s.children[0]);O.appendChild(M);O.className=z.cl.barTopParent;R.tBody.insertBefore(O,R.tBody.children[0]);R.barTopParent=O;R.corner=M;z.controls.barTopParent[z.i]=i(O);N=c.min(L,K.initCalcCols)-1;if(N>0){do{var I=n.createElement("td");if(!Q[N]){Q[N]=n.createElement("col");s.insertBefore(Q[N],P.nextSibling)}Q[N].bar=I;I.col=Q[N];O.insertBefore(I,M.nextSibling)}while(N-->0)}R.barTop=z.controls.barTopParent[z.i].children();return O},barHandleFreeze:{top:function(I){if(z.isBusy()){return false}var s=z.obj.pane().actionUI,S=s.frozenAt,P=s.scrolledArea;if(!(P.end.col<=S.col+1)){return false}z.obj.barHelper().remove();var O=z.obj.barTop(S.col+1),Q=O.position(),R,L=i(I).offset(),N=n.createElement("div"),u=I.freezeHandleTop=i(N).appendTo(I).addClass(z.cl.uiBarHandleFreezeTop+" "+z.cl.barHelper+" "+z.cl.barHandleFreezeTop).height(O.height()).css("left",(Q.left-N.clientWidth)+"px").attr("title",z.msg.dragToFreezeCol),M=I.table.barTop;z.controls.bar.helper[z.i]=z.obj.barHelper().add(N);z.controls.bar.x.handleFreeze[z.i]=u;z.draggable(u,{axis:"x",start:function(){z.setBusy(true);R=i(n.createElement("div")).appendTo(I).css("position","absolute").addClass("ui-state-highlight "+z.cl.barHelper).height(I.table.corner.clientHeight).fadeTo(0,0.33)},drag:function(){var T=z.nearest(u,M).prev();if(T.length&&T.position){R.width(T.position().left+T.width())}},stop:function(V,T){R.remove();z.setBusy(false);z.setDirty(true);var U=z.nearest(u,M);z.obj.barHelper().remove();P.end.col=s.frozenAt.col=z.getTdLocation(U).col-1;z.autoFillerHide();s.scrollStart("x",z.sheetSize(I.table))},containment:[L.left,L.top,D.min(L.left+I.table.clientWidth,L.left+I.clientWidth-k.scrollBarSize.width),L.top]});return true},left:function(I){if(z.isBusy()){return false}var I=z.obj.pane(),s=I.actionUI,S=s.frozenAt,P=s.scrolledArea;if(!(P.end.row<=(S.row+1))){return false}z.obj.barHelper().remove();var O=i(I.table.tBody.children[S.row+1].children[0]),Q=O.position(),R,L=i(I).offset(),N=n.createElement("div"),u=I.freezeHandleLeft=i(N).appendTo(I).addClass(z.cl.uiBarHandleFreezeLeft+" "+z.cl.barHelper+" "+z.cl.barHandleFreezeLeft).width(O.width()).css("top",(Q.top-N.clientHeight)+"px").attr("title",z.msg.dragToFreezeRow),M=i(I.table.tBody.children);z.controls.bar.helper[z.i]=z.obj.barHelper().add(N);z.controls.bar.y.handleFreeze[z.i]=u;z.draggable(u,{axis:"y",start:function(){z.setBusy(true);R=i(n.createElement("div")).appendTo(I).css("position","absolute").addClass("ui-state-highlight "+z.cl.barHelper).width(N.clientWidth).fadeTo(0,0.33)},drag:function(){var T=z.nearest(u,M).prev();if(T.length&&T.position){R.height(T.position().top+T.height())}},stop:function(V,T){R.remove();z.setBusy(false);z.setDirty(true);var U=z.nearest(u,M);z.obj.barHelper().remove();P.end.row=s.frozenAt.row=D.max(z.getTdLocation(U.children(0)).row-1,0);z.autoFillerHide();I.actionUI.scrollStart("y",z.sheetSize(I.table))},containment:[L.left,L.top,L.left,D.min(L.top+I.table.clientHeight,L.top+I.clientHeight-k.scrollBarSize.height)]});return true},corner:function(){}},menu:function(I,s){var M,u=i([]);switch(I){case"top":M=i(n.createElement("div")).addClass(z.cl.uiMenu+" "+z.cl.tdMenu);z.controls.bar.x.menu[z.i]=M;break;case"left":M=i(n.createElement("div")).addClass(z.cl.uiMenu+" "+z.cl.tdMenu);z.controls.bar.y.menu[z.i]=M;break;case"cell":M=i(n.createElement("div")).addClass(z.cl.uiMenu+" "+z.cl.tdMenu);z.controls.tdMenu[z.i]=M;break}z.controls.menus[z.i]=z.obj.menus().add(M);M.mouseleave(function(){M.hide()}).bind("contextmenu",function(){return false}).appendTo(y).hide().disableSelectionSpecial();for(var L in s){if(s[L]){if(i.isFunction(s[L])){u.pushStack(i(n.createElement("div")).text(L).data("msg",L).click(function(){s[i(this).data("msg")].call(this,z);M.hide();return false}).appendTo(M).hover(function(){u.removeClass("ui-state-highlight");i(this).addClass("ui-state-highlight")},function(){i(this).removeClass("ui-state-highlight")}))}else{if(s[L]=="line"){i(n.createElement("hr")).appendTo(M)}}}}return M},barMenu:{top:function(I,s,u){if(z.isBusy()){return false}var M=z.obj.barMenuTop().hide();if(!M.length){M=z.controlFactory.menu("top",K.contextmenuTop)}z.obj.menus().hide();if(!u){M.css("left",(I.pageX-5)+"px").css("top",(I.pageY-5)+"px").show();return M}var L=z.obj.barMenuParentTop().hide();if(!L.length){L=i(n.createElement("div")).addClass(z.cl.uiBarMenuTop+" "+z.cl.barHelper+" "+z.cl.barTopMenuButton).append(i(n.createElement("span")).addClass("ui-icon ui-icon-triangle-1-s")).mousedown(function(N){L.parent().mousedown().mouseup();var O=L.offset();M.css("left",(N.pageX-5)+"px").css("top",(N.pageY-5)+"px").show()}).blur(function(){if(M){M.hide()}});L.get(0).destroy=function(){L.remove();z.controls.bar.x.menuParent[z.i]=null};z.controls.bar.x.menuParent[z.i]=L}L.prependTo(u).show()},left:function(u,s){if(z.isBusy()){return false}z.obj.barMenuLeft().hide();if(s){z.obj.barHandleFreezeLeft().remove()}var I;I=z.obj.barMenuLeft();if(!I.length){I=z.controlFactory.menu("left",K.contextmenuLeft)}z.obj.menus().hide();I.css("left",(u.pageX-5)+"px").css("top",(u.pageY-5)+"px").show();return true},corner:function(){}},tdMenu:function(s){if(z.isBusy()){return false}z.obj.tdMenu().hide();var u=z.obj.tdMenu();if(!u.length){u=z.controlFactory.menu("cell",K.contextmenuCell)}z.obj.menus().hide();u.css("left",(s.pageX-5)+"px").css("top",(s.pageY-5)+"px").show();return true},header:function(){z.obj.header().remove();z.obj.sheetAdder().remove();z.obj.tabContainer().remove();var Q=n.createElement("div"),I=n.createElement("table"),N=n.createElement("tr"),T,L,U=n.createElement("td"),V,M,u,R,s;Q.appendChild(I);I.appendChild(N);Q.className=z.cl.header+" "+z.cl.uiControl;z.controls.header=i(Q);if(K.title){if(i.isFunction(K.title)){K.title=z.title(z,E)}U.className=z.cl.title;z.controls.title=i(U).html(K.title)}else{i(U).hide()}N.appendChild(U);function S(X){if(i.isFunction(X)){X=i(X.call(z))}else{X=i(X)}if(X.is("ul")){X.find("ul").hide().addClass(z.cl.uiMenuUl);X.find("li").addClass(z.cl.uiMenuLi).hover(function(){i(this).find("ul:first").hide().show()},function(){i(this).find("ul:first").hide()})}return X}if(z.isSheetEditable()){if(K.menuLeft){M=n.createElement("td");M.className=z.cl.menu+" "+z.cl.menuFixed;N.insertBefore(M,U);z.controls.menuLeft[z.i]=i(M).append(S(K.menuLeft));z.controls.menuLeft[z.i].find("img").load(function(){z.sheetSyncSize()})}if(K.menuRight){u=n.createElement("td");u.className=z.cl.menu+" "+z.cl.menuFixed;N.appendChild(u);z.controls.menuRight[z.i]=i(u).append(S(K.menuRight));z.controls.menuRight[z.i].find("img").load(function(){z.sheetSyncSize()})}V=n.createElement("td");V.className=z.cl.label;z.controls.label=i(V);R=n.createElement("textarea");R.className=z.cl.formula;R.onkeydown=z.evt.formula.keydown;R.onkeyup=function(){z.obj.inPlaceEdit().value=this.value};R.onchange=function(){z.obj.inPlaceEdit().value=this.value};R.onpaste=z.evt.pasteOverCells;R.onfocus=function(){z.setNav(false)};R.onfocusout=function(){z.setNav(true)};R.onblur=function(){z.setNav(true)};z.controls.formula=i(R);var P=n.createElement("span");P.appendChild(R);T=n.createElement("table");L=n.createElement("tr");T.appendChild(L);Q.appendChild(T);s=n.createElement("td");s.className=z.cl.formulaParent;s.appendChild(P);L.appendChild(V);L.appendChild(s);z.resizableSheet(i(P),{minHeight:z.controls.formula.height(),maxHeight:78,handles:"s",resize:function(Y,X){z.controls.formula.height(X.size.height)},stop:function(){z.sheetSyncSize()}});var W=i.sheet.instance;for(var O=0;O<W.length;O++){(W||{}).nav=false}z.setNav(true);i(n).keydown(z.evt.document.keydown)}return Q},ui:function(){var s=n.createElement("div");s.setAttribute("class",z.cl.ui);z.obj.ui=s;return s},sheetAdder:function(){var s=n.createElement("span");if(z.isSheetEditable()){s.setAttribute("class",z.cl.sheetAdder+" "+z.cl.tab+" "+z.cl.uiTab+" ui-corner-bottom");s.setAttribute("title",z.msg.addSheet);s.innerHTML=" + ";s.onmousedown=function(){z.addSheet();return false};s.i=-1}return z.controls.sheetAdder=i(s)},tabContainer:function(){var s=n.createElement("span"),u;s.setAttribute("class",z.cl.tabContainer);s.onmousedown=function(L){L=L||k.event;var I=(L.target||L.srcElement).i;if(I>=0){z.trigger("sheetSwitch",[I])}return false};s.ondblclick=function(L){L=L||k.event;var I=(L.target||L.srcElement).i;if(I>=0){z.trigger("sheetRename",[I])}return false};if(z.isSheetEditable()&&i.fn.sortable){return z.controls.tabContainer=i(s).sortable({placeholder:"ui-state-highlight",axis:"x",forceHelperSize:true,forcePlaceholderSize:true,opacity:0.6,start:function(L,I){u=I.item.index();z.trigger("sheetTabSortStart",[L,I])},update:function(L,I){z.trigger("sheetTabSortUpdate",[L,I,u])}})}return z.controls.tabContainer=i(s)},sheetUI:function(S,T,M){z.i=M;z.tuneTableForSheetUse(T);z.readOnly[M]=(T.className||"").match(/\breadonly\b/i)!=null;var O=T.tBody.children.length>0,N=z.controlFactory.enclosure(T),I=N.pane,u=i(I),P=function(X){X=X||k.event;if(z.isBusy()){return false}if(z.isBar(X.target)){var V=X.target.entity,W=z.getBarIndex[V](X.target);if(W<0){return false}if(z.evt.barInteraction.first==z.evt.barInteraction.last){z.controlFactory.barMenu[V](X,W)}}else{z.controlFactory.tdMenu(X)}return false};S.appendChild(N);z.controlFactory.barTop(T);z.controlFactory.barLeft(T);I.appendChild(T);if(z.isSheetEditable()){z.controlFactory.autoFiller(I)}if(z.isSheetEditable()){var Q=z.obj.formula(),U="";u.mousedown(function(V){z.setNav(true);if(z.isBusy()){return false}if(z.isCell(V.target)){if(V.button==2){P.call(this,V);z.evt.cellOnMouseDown(V);return true}z.evt.cellOnMouseDown(V);return false}if(z.isBar(V.target)){if(V.button==2){P.call(this,V)}U=V.target.entity;z.evt.barInteraction.select(V.target);return false}return true});I.onmouseup=function(){U=""};I.onmouseover=function(Z){Z=Z||k.event;var Y=Z.target||Z.srcElement;if(z.isBusy()){return false}if(!z.isBar(Y)){return false}var X=i(Y),V=Y.entity,W=z.getBarIndex[V](Y);if(W<0){return false}if(z.evt.barInteraction.selecting&&V==U){z.evt.barInteraction.last=W;z.cellSetActiveBar(V,z.evt.barInteraction.first,z.evt.barInteraction.last)}else{z.resizeBar[V](X,W,I,T);if(z.isSheetEditable()){z.controlFactory.barHandleFreeze[V](I);if(V=="top"){z.controlFactory.barMenu[V](Z,W,X)}}}return true};I.ondblclick=z.evt.cellOnDblClick;u.bind("contextmenu",P).disableSelectionSpecial().bind("cellEdit",z.evt.cellEdit)}z.themeRoller.start(T);z.createSpreadsheet(T,M);z.checkMinSize(T);z.controlFactory.tab();var L=z.s,s=L.hiddenRows,R=L.hiddenColumns;if(!s.length||!R.length){s=T.attributes["data-hiddenrows"]||{value:""};R=T.attributes["data-hiddencolumns"]||{value:""};if(s.value.length>0){s=f.toNumbers(s.value.split(","))}if(R.value.length>0){R=f.toNumbers(R.value.split(","))}}N.actionUI.hide(s,R,z.rows(T),z.cols(T));z.setChanged(true)},enclosure:function(I){var N=n.createElement("div"),M=n.createElement("div"),u=i(M),s=new h.ActionUI(M,N,I,z.cl.scroll,z.s.frozenAt[z.i],i.sheet.max),L=s.scrollUI;I.size=function(){return z.tableSize(I)};N.size=function(){return z.sheetSize(I)};L.onscroll=function(){if(!z.isBusy()){var P=s.scrollTo({axis:"x",pixel:this.scrollLeft}),O=s.scrollTo({axis:"y",pixel:this.scrollTop});if(P||O){if(P){setTimeout(function(){z.calcVisibleCol(s)},0)}if(O){setTimeout(function(){z.calcVisibleRow(s);z.updateYBarWidthToCorner(s)},0)}z.obj.barHelper().remove();z.autoFillerGoToTd();if(N.inPlaceEdit){N.inPlaceEdit.goToTd()}}}};L.onmousedown=function(){z.obj.barHelper().remove()};M.actionUI=N.actionUI=s;M.scrollUI=N.scrollUI=L;M.appendChild(M.scrollUI);N.setAttribute("class",z.cl.pane+" "+z.cl.uiPane);M.appendChild(N);M.setAttribute("class",z.cl.enclosure);M.pane=N;M.table=I;N.table=I;N.enclosure=M;N.$enclosure=u;I.pane=N;I.enclosure=M;I.$enclosure=u;z.controls.pane[z.i]=N;z.controls.panes=z.obj.panes().add(N);z.controls.enclosure[z.i]=u;z.controls.enclosures=z.obj.enclosures().add(M);return M},tab:function(){var s=n.createElement("span"),u=z.controls.tab[z.i]=i(s).appendTo(z.obj.tabContainer());s.setAttribute("class",z.cl.tab);z.sheetTab(true,function(I){s.innerHTML=I});s.i=z.i;s.setAttribute("class",z.cl.uiTab+" ui-corner-bottom");z.controls.tabs=z.obj.tabs().add(u);return s},inPlaceEdit:function(O,u){O=O||z.obj.tdActive();if(!O.length){O=i(z.rowTds(null,1)[1]);z.cellEdit(O)}if(!O.length){return}(z.obj.inPlaceEdit().destroy||F)();var N=z.obj.formula(),I=N.val(),s,M,L=z.obj.pane();if(!O[0].isHighlighted){return}s=n.createElement("textarea");M=i(s);L.inPlaceEdit=s;s.i=z.i;s.className=z.cl.inPlaceEdit+" "+z.cl.uiInPlaceEdit;s.td=O[0];s.goToTd=function(){this.offset=O.position();if(!this.offset.left&&!this.offset.right){i(s).hide()}else{this.setAttribute("style","left:"+(this.offset.left-1)+"px;top:"+(this.offset.top-1)+"px;width:"+this.td.clientWidth+"px;height:"+this.td.clientHeight+"px;min-width:"+this.td.clientWidth+"px;min-height:"+this.td.clientHeight+"px;")}};s.goToTd();s.onkeydown=z.evt.inPlaceEdit.keydown;s.onchange=s.onkeyup=function(){N[0].value=s.value};s.onfocus=function(){z.setNav(false)};s.onblur=s.onfocusout=function(){z.setNav(true)};s.onpaste=z.evt.pasteOverCells;s.destroy=function(){L.inPlaceEdit=null;z.cellLast.isEdit=(s.value!=I);s.parentNode.removeChild(s);z.controls.inPlaceEdit[s.i]=false};L.appendChild(s);s.onfocus();z.controls.inPlaceEdit[z.i]=s;M.focus().val("").val(N[0].value);if(u){M.select()}if(i.fn.elastic){i(s).elastic()}},autoFiller:function(L){if(!K.autoFiller){return false}var u=n.createElement("div"),s=n.createElement("div"),I=n.createElement("div");u.i=z.i;u.className=z.cl.autoFiller+" "+z.cl.uiAutoFiller;s.className=z.cl.autoFillerHandle;I.className=z.cl.autoFillerCover;u.onmousedown=function(){var N=z.obj.tdActive();if(N){var M=z.getTdLocation(N);z.cellSetActive(N,M,true,z.autoFillerNotGroup,function(){var P=z.highlighted(),O=z.getTdLocation(P.last());z.fillUpOrDown(O.row<M.row||O.col<M.col);z.autoFillerGoToTd(N);z.autoFillerNotGroup=false})}return false};L.autoFiller=z.controls.autoFiller[z.i]=i(u);L.appendChild(u);return true}},autoFillerNotGroup:true,updateCellsAfterPasteToFormula:function(R){var Q=0,P=z.obj.formula(),T=new m();R=R||P.val();var O={row:z.cellLast.row,col:z.cellLast.col},u=P.val(),L=u;if(O.row==0&&O.col==0){return false}var U=tsv.parse(u);if(!i.isArray(U)){P.val(U);z.fillUpOrDown(false,U);return true}for(var N=0;N<U.length;N++){z.cellLast.isEdit=true;var s=U[N];for(var M=0;M<s.length;M++){Q++;var I=z.getTd(z.i,N+O.row,M+O.col);I.row=O.row;I.col=O.col;if(I.length){if(!z.spreadsheets[z.i]||!z.spreadsheets[z.i][N+O.row]||!z.spreadsheets[z.i][N+O.row][M+O.col]){continue}var S=z.spreadsheets[z.i][N+O.row][M+O.col];if(S){K.parent.one("sheetPreCalculation",function(){if((s[M]+"").charAt(0)=="="){S.formula=s[M].substring(1);S.value="";I.data("formula",s[M])}else{S.formula="";S.value=s[M];I.removeData("formula")}});z.calcDependencies.call(S);if(N==0&&M==0){L=s[M]}}}}}if(u!=L){P.val(L)}z.fillUpOrDown(false,L);z.evt.cellEditDone(true);return true},evt:{inPlaceEdit:{enter:function(s){if(s.shiftKey){return true}return z.evt.cellSetActiveFromKeyCode(s,true)},tab:function(s){if(s.shiftKey){return true}return z.evt.cellSetActiveFromKeyCode(s,true)},keydown:function(s){s=s||k.event;z.trigger("sheetFormulaKeydown",[true]);switch(s.keyCode){case p.ENTER:return z.evt.inPlaceEdit.enter(s);break;case p.TAB:return z.evt.inPlaceEdit.tab(s);break;case p.ESCAPE:z.evt.cellEditAbandon();return false;break}}},formula:{keydown:function(s){s=s||k.event;if(z.readOnly[z.i]){return false}if(z.cellLast.row<0||z.cellLast.col<0){return false}z.trigger("sheetFormulaKeydown",[false]);switch(s.keyCode){case p.C:if(s.ctrlKey){return z.evt.document.copy(s)}case p.X:if(s.ctrlKey){return z.evt.document.cut(s)}case p.Y:if(s.ctrlKey){z.evt.document.redo(s);return false}break;case p.Z:if(s.ctrlKey){z.evt.document.undo(s);return false}break;case p.ESCAPE:z.evt.cellEditAbandon();return true;break;case p.ENTER:z.evt.cellSetActiveFromKeyCode(s,true);return false;break}z.cellLast.isEdit=true},If:function(u,s){if(u){z.obj.tdActive().dblclick();return true}return false}},document:{enter:function(s){if(!z.cellLast.isEdit&&!s.ctrlKey){z.obj.tdActive().dblclick()}return false},tab:function(s){z.evt.cellSetActiveFromKeyCode(s)},findCell:function(s){if(s.ctrlKey){z.cellFind();return false}return true},redo:function(s){if(s.ctrlKey&&!z.cellLast.isEdit){z.undo.manager.redo();return false}return true},undo:function(s){if(s.ctrlKey&&!z.cellLast.isEdit){z.undo.manager.undo();return false}return true},copy:function(M,u){var L=z.highlighted(true),N=z.obj.formula(),I=N.val(),s=z.toTsv(L,u);N.val(s).focus().select();w.one("keyup",function(){if(u){N.val("")}else{N.val(I)}});return true},cut:function(s){return this.copy(s,true)},pageUpDown:function(s){var L=z.sheetSize(),P=z.obj.pane(),I=P.clientHeight,M=0,N=0,O,u;if(s){for(u=z.cellLast.row;u>0&&M<I;u--){O=z.getTd(z.i,u,1);if(!O.data("hidden")&&O.is(":hidden")){O.show()}M+=O.parent().height()}}else{for(u=z.cellLast.row;u<L.rows&&M<I;u++){O=z.getTd(z.i,u,1);M+=O.parent().height()}}z.cellEdit(O);return false},keydown:function(s){s=s||k.event;if(z.readOnly[z.i]){return false}if(z.cellLast.row<0||z.cellLast.col<0){return false}var u=z.cellLast.td;if(z.nav){switch(s.keyCode){case p.DELETE:z.toTsv(null,true);z.obj.formula().val("");break;case p.TAB:z.evt.document.tab(s);break;case p.ENTER:z.evt.cellSetActiveFromKeyCode(s);break;case p.LEFT:case p.UP:case p.RIGHT:case p.DOWN:(s.shiftKey?z.evt.cellSetHighlightFromKeyCode(s):z.evt.cellSetActiveFromKeyCode(s));break;case p.PAGE_UP:z.evt.document.pageUpDown(true);break;case p.PAGE_DOWN:z.evt.document.pageUpDown();break;case p.HOME:case p.END:z.evt.cellSetActiveFromKeyCode(s);break;case p.V:if(s.ctrlKey){return z.evt.formula.If(!z.evt.pasteOverCells(s),s)}else{u.trigger("cellEdit");return true}break;case p.Y:if(s.ctrlKey){z.evt.document.redo(s);return false}else{u.trigger("cellEdit");return true}break;case p.Z:if(s.ctrlKey){z.evt.document.undo(s);return false}else{u.trigger("cellEdit");return true}break;case p.ESCAPE:z.evt.cellEditAbandon();break;case p.F:if(s.ctrlKey){return z.evt.formula.If(z.evt.document.findCell(s),s)}else{u.trigger("cellEdit");return true}break;case p.CAPS_LOCK:case p.SHIFT:case p.ALT:break;case p.CONTROL:z.obj.formula().focus().select();return true;break;default:u.trigger("cellEdit");return true;break}return false}}},pasteOverCells:function(u){u=u||k.event;if(u.ctrlKey||u.type=="paste"){var s=function(){z.updateCellsAfterPasteToFormula()};var I=w.one("keyup",function(){s();s=function(){};I.mouseup()}).one("mouseup",function(){s();s=function(){};I.keyup()});z.setDirty(true);z.setChanged(true);return true}return false},cellEditDone:function(I){(z.obj.inPlaceEdit().destroy||F)();if(z.cellLast.isEdit||I){var M=z.obj.formula(),L=z.obj.tdActive();if(z.isFormulaEditable(L)){if(L&&z.cellLast.row>0&&z.cellLast.col>0){var u=M.val(),s=L[0].jSCell;if(!s.edited){s.edited=true;z.controls.cellsEdited[z.i]=z.obj.cellsEdited().add(s)}K.parent.one("sheetPreCalculation",function(){if(u.charAt(0)=="="&&z.formulaParser){L.data("formula",u);s.value=u;s.formula=u}else{L.removeData("formula");s.value=u;s.formula=""}});z.calcDependencies.call(s);z.cellLast.isEdit=false;z.trigger("sheetCellEdited",[s])}}}},cellEditAbandon:function(s){(z.obj.inPlaceEdit().destroy||F)();z.themeRoller.bar.clearActive();z.themeRoller.cell.clearHighlighted(null,true);if(!s){z.calc()}z.cellLast.td=i([]);z.cellLast.row=0;z.cellLast.col=0;z.rowLast=0;z.colLast=0;z.highlightedLast.start={row:0,col:0};z.highlightedLast.end={row:0,col:0};z.labelUpdate("",true);z.obj.formula().val("").blur();z.autoFillerHide();return false},cellSetHighlightFromKeyCode:function(L){var I=z.highlightedLastOrdered(),u=z.sheetSize(),O=z.obj.tdActive(),M=z.getTdLocation(O),N=I.start,s=I.end;switch(L.keyCode){case p.UP:if(N.row<M.row){N.row--;N.row=D.max(N.row,1);break}s.row--;s.row=D.max(s.row,1);break;case p.DOWN:if(N.row===N.end){N.row++;N.row=D.min(N.row,u.rows);break}if(N.row<M.row){N.row++;N.row=D.max(N.row,1);break}s.row++;s.row=D.min(s.row,u.rows);break;case p.LEFT:if(N.col<M.col){N.col--;N.col=D.max(N.col,1);break}s.col--;s.col=D.max(s.col,1);break;case p.RIGHT:if(N.col<M.col){N.col++;N.col=D.min(N.col,u.cols);break}s.col++;s.col=D.min(s.col,u.cols);break}z.highlightedLast.start=N;z.highlightedLast.end=s;z.cycleCellArea(function(P){z.themeRoller.cell.setHighlighted(P.td)},N,s);return false},cellSetActiveFromKeyCode:function(M,s){var N={row:z.cellLast.row,col:z.cellLast.col},L=false,I,u=false;switch(M.keyCode){case p.UP:N.row--;break;case p.DOWN:N.row++;break;case p.LEFT:N.col--;break;case p.RIGHT:N.col++;break;case p.ENTER:N=z.evt.incrementAndStayInGrid(z.highlightedLastOrdered(),N,"row","col",M.shiftKey);L=true;I=z.highlighted();if(I.length>1){u=true}else{if(!s){N.row+=(M.shiftKey?-1:1)}if(K.autoAddCells&&N.row>z.sheetSize().rows){z.controlFactory.addRow()}}break;case p.TAB:N=z.evt.incrementAndStayInGrid(z.highlightedLastOrdered(),N,"col","row",M.shiftKey);L=true;I=z.highlighted();if(I.length>1){u=true}else{if(!s){N.col+=(M.shiftKey?-1:1)}if(K.autoAddCells&&N.col>z.sheetSize().cols){z.controlFactory.addColumn()}}break;case p.HOME:N.col=1;break;case p.END:N.col=z.obj.tdActive().parent().children("td").length-1;break}N.col=N.col||1;N.row=N.row||1;if(!z.cellLast.isEdit||L){var O=z.getTd(z.i,N.row,N.col);if(O){z.cellEdit(O,null,u);return false}}return true},incrementAndStayInGrid:function(L,M,u,s,I){if(I){M[u]--;if(M[u]<L.start[u]){M[u]=L.end[u];M[s]--}if(M[s]<L.start[s]){M[s]=L.end[s]}}else{M[u]++;if(M[u]>L.end[u]){M[u]=L.start[u];M[s]++}if(M[s]>L.end[s]){M[s]=L.start[s]}}return M},cellOnMouseDown:function(s){z.obj.formula().blur();if(s.shiftKey){z.getTdRange(s,z.obj.formula().val())}else{z.cellEdit(i(s.target),true)}},cellOnDblClick:function(s){if(z.isBusy()){return false}z.controlFactory.inPlaceEdit();return true},cellEdit:function(s){if(z.isBusy()){return false}z.controlFactory.inPlaceEdit(null,true);return true},barInteraction:{first:0,last:0,selecting:false,select:function(I){if(!I){return}if(!I.type=="bar"){return}var s=I.entity,u=z.getBarIndex[s](I);if(u<0){return false}z[s+"Last"]=u;z.evt.barInteraction.last=z.evt.barInteraction.first=u;z.cellSetActiveBar(s,z.evt.barInteraction.first,z.evt.barInteraction.last);z.evt.barInteraction.first=z.evt.barInteraction.last=z[s+"Last"]=u;z.evt.barInteraction.selecting=true;w.one("mouseup",function(){z.evt.barInteraction.selecting=false});return false}}},refreshColumnLabels:function(M){M=M||0;var s=z.obj.barMenuParentTop();if((s)&&(s.length)){var L=s.get(0);if(i.isFunction(L.destroy)){L.destroy()}}var I=z.controls.bar.x.td[z.i];if(!I){return}for(var u=c.max(M,0);u<I.length;u++){if(u){I[u].text(d.columnLabelString(I[u][0].cellIndex))}}},refreshRowLabels:function(L,s){L=L||0;var I=z.controls.bar.y.td[z.i];if(!I){return}s=s||I.length;for(var u=L;u<s;u++){if(u){i(I[u]).text(I[u][0].parentNode.rowIndex)}}},isCell:function(s){if(s&&s.tagName&&s.tagName=="TD"&&s.type&&s.type=="cell"){return true}return false},isBar:function(s){if(s&&s.tagName&&s.tagName=="TD"&&s.type&&s.type=="bar"){return true}return false},readOnly:[],isSheetEditable:function(s){s=s||z.i;return(K.editable==true&&!z.readOnly[s])},isFormulaEditable:function(s){if(K.lockFormulas){if(s.data("formula")!==H){return false}}return true},toggleFullScreen:function(){if(!z){return}z.evt.cellEditDone();var I=z.obj.fullScreen(),N=z.obj.pane();if(I.is(":visible")){r.unbind("jSResize");y.removeClass("bodyNoScroll");K.parent=I[0].origParent;K.parent.prepend(I.children());I.remove();z.sheetSyncSize();N.resizeScroll();z.trigger("sheetFullScreen",[false])}else{y.addClass("bodyNoScroll");var L=i(K.parent),I=n.createElement("div"),u=i._data(K.parent[0],"events");I.className=z.cl.fullScreen+" "+z.cl.uiFullScreen+" "+z.cl.parent;I.origParent=L;K.parent=z.controls.fullScreen=i(I).append(L.children()).appendTo(y);r.bind("resize",function(){r.trigger("jSResize")}).bind("jSResize",function(){this.w=r.width();this.h=r.height();K.parent.width(this.w).height(this.h);z.sheetSyncSize();N.resizeScroll()}).trigger("jSResize");L.trigger("sheetFullScreen",[true]);for(var M in u){for(var s=0;s<u[M].length;s++){K.parent.bind(M,u[M][s].handler)}}}},renameSheet:function(s){if(v(s)){return false}if(s>-1){z.sheetTab()}return true},switchSheet:function(s){if(v(s)){return false}if(s==-1){z.addSheet()}else{if(s!=z.i){z.setActiveSheet(s);z.calc(s)}}return true},tuneTableForSheetUse:function(I){var u=i(I);z.controls.table[z.i]=u.addClass(z.cl.table).addClass(z.cl.uiTable).attr("id",z.id+z.i).attr("border","1px").attr("cellpadding","0").attr("cellspacing","0");I.spreadsheetIndex=z.i;z.formatTable(I);z.sheetDecorateRemove(false,u);z.controls.tables=z.obj.tables().add(I);var L=u.attr("data-frozenatrow")*1,s=u.attr("data-frozenatcol")*1;if(!z.s.frozenAt[z.i]){z.s.frozenAt[z.i]={row:0,col:0}}if(L){z.s.frozenAt[z.i].row=L}if(s){z.s.frozenAt[z.i].col=s}},createSpreadsheet:function(u,s){this.createSpreadsheetForArea(u,s)},createSpreadsheetForArea:function(T,O,M,Q,N,U,P){var W=z.rows(T),V,u,S=K.loader||{},s=K.colMargin+"px",L=S.setRowHeight||function(Y,ac,ab){var aa,Z,X=s;if((aa=ab.nextSibling)===undefined){return X}if((Z=aa.style)===undefined){return X}if(Z.height!==undefined){X=Z.height}ab.style.height=X};M=M||0;Q=Q||W.length-1;N=N||0;U=U||W[0].children.length-1;if(M===0&&N===0){T.spreadsheet=z.spreadsheets[O]=[]}V=Q;if(V<0||u<0){return}do{var R=W[V];u=U;if(R===undefined){if(P){z.controlFactory.addCells(null,false,V-(W.length-1),"row");R=W[V]}else{continue}}do{var I=R.children[u];if(I===undefined){if(P){z.controlFactory.addCells(null,false,u-(W[0].children.length-1),"col");I=R.children[u]}else{continue}}if(V>0&&u>0){if(!I.jSCell){z.createCell(O,V,u)}}else{if(u==0&&V>0){I.type="bar";I.entity="left";I.innerHTML=V;I.className=z.cl.barLeft+" "+z.cl.barLeft+"_"+z.i+" "+z.cl.uiBar;L.call(S,O,V,I)}if(V==0&&u>0){I.type="bar";I.entity="top";I.innerHTML=d.columnLabelString(u);I.className=z.cl.barTop+" "+z.cl.barTop+"_"+z.i+" "+z.cl.uiBar}if(V==0&&u==0){I.type="bar";I.entity="corner";I.className=z.cl.uiBar+" "+z.cl.barCorner;z.controls.bar.corner[z.i]=I}}}while(u-->N)}while(V-->M)},updateYBarWidthToCorner:function(M){return;var L=z.obj.corner(),I=M.table,u=I.size().rows,O=K.initCalcRows+M.scrolledArea.end.row,s=(O<u?O:u),N=I.children[s].children[0]},toggleHideRow:function(s){s=s||z.rowLast;if(!s){return}var I=z.rows()[s],u=z.obj.pane().actionUI;u.toggleHideRow(I,s);z.autoFillerGoToTd()},toggleHideColumn:function(u){u=u||z.colLast;if(!u){return}var s=z.cols()[u],I=z.obj.pane().actionUI;I.toggleHideColumn(s,u);z.autoFillerGoToTd()},rowShowAll:function(){z.obj.pane().actionUI.rowShowAll()},columnShowAll:function(){z.obj.pane().actionUI.columnShowAll()},merge:function(P){P=P||z.highlighted();if(!P.length){return}var N=[],u=P[0],M=P[P.length-1],U=z.getTdLocation(u),I=z.getTdLocation(M),X={},S={},R=0,T=0,W=new m(),O=P.length-1,V,Y,L,s,Q;if(U.row){z.setDirty(true);z.setChanged(true);if(U.row<I.row){X.row=U.row;S.row=I.row;L=u}else{X.row=I.row;S.row=U.row;L=M}if(L.getAttribute("rowSpan")||L.getAttribute("colSpan")){return false}s=i(L);if(U.col<I.col){X.col=U.col;S.col=I.col}else{X.col=I.col;S.col=U.col}T=(S.row-X.row)+1;R=(S.col-X.col)+1;Q=z.getTdLocation(L);do{Y=P[O];V=Y.jSCell;if(V.formula||V.value){N.unshift(V.formula?"("+V.formula.substring(1)+")":V.value)}K.parent.one("sheetPreCalculation",function(){if(Y.cellIndex!=Q.col||Y.parentNode.rowIndex!=Q.row){V.formula=null;V.value="";V.html="";V.defer=L.jSCell;V.calcLast=W;Y.removeAttribute("data-formula");Y.removeAttribute("data-celltype");Y.innerHTML="";Y.style.display="none";Y.colSpan=R-(Y.cellIndex-L.cellIndex);Y.rowSpan=T-(Y.parentNode.rowIndex-L.parentNode.rowIndex)}});z.calcDependencies.call(V)}while(O--);L.jSCell.value=N.join(" ");L.jSCell.formula=(L.jSCell.formula?N.join(" "):"");L.jSCell.calcLast=W;L.style.display="";L.setAttribute("rowSpan",T);L.setAttribute("colSpan",R);z.calcDependencies.call(L.jSCell);z.evt.cellEditDone();z.autoFillerGoToTd(s);z.cellSetActive(s,Q)}return true},unmerge:function(s){s=s||z.highlighted();if(!s){return}var I=s[0],O=z.getTdLocation(I),P=new m(),R=D.max(I.getAttribute("rowSpan")*1,1)-1,u=D.max(I.getAttribute("colSpan")*1,1)-1,N=R+O.row,L,Q,M=[];if(R==0&&u==0){return false}do{L=O.col+u;do{Q=z.getTd(z.i,N,L)[0];Q.style.display="";Q.removeAttribute("colSpan");Q.removeAttribute("rowSpan");Q.jSCell.defer=null;z.calcDependencies.call(Q.jSCell,P);M.push(Q)}while(L-->O.col)}while(N-->O.row);z.evt.cellEditDone();z.autoFillerGoToTd(s);z.cellSetActive(s,O);z.themeRoller.cell.setHighlighted(i(M));return true},fillUpOrDown:function(P,R,T){z.evt.cellEditDone();T=T||z.highlighted(true);if(T.length<1){return false}var M=z.obj.tdActive(),Q=new m();if(T.length<1){return false}var N=z.getTdLocation(T[0].td),U=z.getTdLocation(T[T.length-1].td),s=z.getTdLocation(M),I={row:0,col:0},u=R||M[0].jSCell.value,S=false,L=T.length-1,O=function(){};R=R||M[0].jSCell.value;if(L>=0){if(R.charAt&&R.charAt(0)=="="){if(L>=0){do{if(!P){I.row=s.row-U.row;I.col=s.col-U.col}else{I.row=s.row-N.row;I.col=s.col-N.col}u=z.reparseFormula(R,I);K.parent.one("sheetPreCalculation",function(){T[L].formula=u;T[L].value="";T[L].td.data("formula",u)});z.calcDependencies.call(T[L],Q)}while(L--);return true}}else{if((S=!v(u))||u.length>0){if(S&&u!=""){u*=1;if(P){u-=T.length-1}O=function(){u++}}}do{K.parent.one("sheetPreCalculation",function(){T[L].formula="";T[L].value=u+"";T[L].td.removeData("formula")});z.calcDependencies.call(T[L],Q);O()}while(L--);return true}}return false},toTsv:function(T,L,R){T=T||z.highlighted(true);if(T.type){T=[T]}R=R||function(W,V){if(L){K.parent.one("sheetPreCalculation",function(){V.formula="";V.value=""});z.calcDependencies.call(V,Q)}};var O=[],S,N,u={},Q=new m(),I=T.length-1,U,s;if(I>=0){S=z.getTdLocation(T[0].td);N=z.getTdLocation(T[T.length-1].td);u.row=D.min(S.row,N.row);u.col=D.min(S.col,N.col);do{var M=z.getTdLocation(T[I].td),P=(T[I].formula?"="+T[I].formula:T[I].value);U=D.abs(M.row-u.row);s=D.abs(M.col-u.col);if(!O[U]){O[U]=[]}if((P+="").match(/\n/)){P='"'+P+'"'}O[U][s]=(P||"");R.call(T[I].td,M,T[I])}while(I-->0);I=O.length-1;do{O[I]=O[I].join("\t")}while(I-->0);return O.join("\n")}return""},offsetFormulas:function(P,O,I,N){var u=z.sheetSize(),M={first:{row:1,col:1},last:{row:u.rows,col:u.cols}},L=new m(),s=[];z.cycleCells(function(){var Q=this;if(this.formula&&typeof this.formula=="string"&&z.isFormulaEditable(this.td)){this.formula=z.reparseFormula(this.formula,O,P,I,N);this.td.data("formula","="+this.formula)}s.push(function(){z.calcDependencies.call(Q,L,true)})},M.first,M.last);while(s.length){s.pop()()}z.evt.cellEditDone()},reparseFormula:function(M,L,I,s,u){return M.replace(d.regEx.cell,function(O,P,T,U){if(P=="SHEET"){return O}L=L||{loc:0,row:0};var N={row:T*1,col:d.columnLabelIndex(P)},S,R,Q={row:T,col:P,use:false};if(I){if(u){if(s){if(N.col&&N.col==I.col-1){Q.col="#REF!";Q.use=true}if(N.row&&N.row==I.row-1){Q.row="#REF!";Q.use=true}if(N.col>=I.col){S=true}if(N.row>=I.row){R=true}}else{if(I.col&&N.col==I.col){Q.col="#REF!";Q.use=true}if(I.row&&N.row==I.row){Q.row="#REF!";Q.use=true}if(I.col&&N.col>I.col){S=true}if(I.row&&N.row>I.row){R=true}}if(Q.use){return Q.col+Q.row}if(S){N.col+=L.col;return z.makeFormula(N)}if(R){N.row+=L.row;return z.makeFormula(N)}}else{if(s){if(I.col&&N.col>=I.col){S=true}if(I.row&&N.row>=I.row){R=true}}else{if(I.col&&N.col>I.col){S=true}if(I.row&&N.row>I.row){R=true}}if(S){N.col+=L.col;return z.makeFormula(N)}if(R){N.row+=L.row;return z.makeFormula(N)}}}else{return z.makeFormula(N,L)}return O})},makeFormula:function(u,s){s=i.extend({row:0,col:0},s);u.col+=s.col;u.row+=s.row;if(u.col<0){u.col=0}if(u.row<0){u.row=0}return d.parseCellName(u.col,u.row)},cycleCells:function(L,O,M,I){I=I||z.i;O=O||{row:1,col:1};if(!M){var u=z.sheetSize();M={row:u.rows,col:u.cols}}var N=M.row,s;if(N<O.row){return}do{s=M.col;do{L.call(z.spreadsheets[I][N][s],I,N,s)}while(s-->O.col)}while(N-->O.row)},cycleCellsAll:function(L){var M=z.i,I,u,s;for(I=0;I<=z.sheetCount;I++){z.i=I;u=z.sheetSize();s={row:u.rows,col:u.cols};z.cycleCells(L,{row:0,col:0},s,I)}z.i=M},cycleCellArea:function(Q,U,N,M,R){var s={start:{},end:{}},P,T,V,S,L=z.i,u={cell:[],td:[]},O=z.spreadsheets[L],I=(R?"unshift":"push");if(M){s.start=U;s.end=N}else{s.start.row=D.max(D.min(U.row,N.row),1);s.start.col=D.max(D.min(U.col,N.col),1);s.end.row=D.max(U.row,N.row,1);s.end.col=D.max(U.col,N.col,1)}P=s.end.row;do{T=s.end.col;V=O[P]||null;do{if(V){S=V[T]||null;if(S){u.cell[I](S);u.td[I](S.td[0])}}}while(T-->s.start.col)}while(P-->s.start.row);if(Q){Q(u)}},formatTable:function(V){var T=K.newColumnWidth+"px",O=K.colMargin+"px",u=V.children,M=u.length-1,L,I,R,s,Q,U,N,S=K.loader||{},P=S.setWidth||function(W,X,Y){Y.style.width=T};if(M>-1){do{switch(u[M].nodeName){case"TBODY":U=true;R=u[M];break;case"COLGROUP":N=true;s=u[M];break}}while(M--)}else{}if(!R){R=n.createElement("tbody");if(u.length>0){do{R.appendChild(u[0])}while(u.length)}}if(!s||s.children.length<1){s=n.createElement("colgroup");V.appendChild(s);V.appendChild(R);if(R.children.length>0){Q=R.children[0];for(M=0,L=c.min(Q.children.length,K.initCalcCols);M<L;M++){I=n.createElement("col");P.call(S,z.i,M,I);s.appendChild(I)}for(M=0,L=c.min(R.children.length,K.initCalcRows);M<L;M++){R.children[M].style.height=O}}}V.tBody=R;V.colGroup=s;V.removeAttribute("width");V.style.width=""},checkMinSize:function(M){var I=z.tableSize(M),N=K.minSize.rows||0,s=K.minSize.cols||0,L=z.obj.pane().actionUI,u=L.frozenAt;N=c.max((u.row>N?u.row+1:N),1);s=c.max((u.col>s?u.col+1:s),1);if(I.cols<s){z.controlFactory.addColumnMulti(null,s,false,true)}I=z.tableSize(M);if(I.rows<N){z.controlFactory.addRowMulti(null,N,false,true)}},themeRoller:{start:function(s){z.obj.header().addClass(z.cl.uiControl);z.obj.label().addClass(z.cl.uiControl);z.obj.formula().addClass(z.cl.uiControlTextBox)},cell:{setHighlighted:function(L){L=L||i([]);var s,I=z.highlightedLast.obj,u=z.obj.pane().actionUI;if(I&&I.length>0){s=I.length-1;do{I[s].isHighlighted=false}while(s-->0)}if(L.length>0){s=L.length-1;do{if(!L[s].isHighlighted){L[s].isHighlighted=true;if(!L[s].className.match(z.cl.uiTdHighlighted)){L[s].className+=" "+z.cl.uiTdHighlighted}}}while(s-->0)}z.themeRoller.cell.clearHighlighted.call(L,I);u.redraw()},isHighlighted:function(){return(z.highlightedLast.obj.length?true:false)},clearHighlighted:function(I,u){if(z.themeRoller.cell.isHighlighted()){I=I||z.highlightedLast.obj;if(I&&I.length){var s=I.length-1;do{if(!I[s].isHighlighted||u){I[s].className=I[s].className.replace(z.cl.uiTdHighlighted,"");I[s].isHighlighted=false}}while(s-->0)}}if(this.length){z.highlightedLast.obj=this}else{z.highlightedLast.obj=i([])}}},bar:{style:function(s){i(s).addClass(z.cl.uiBar)},setActive:function(s,u){switch(s){case"top":z.highlightedLast.barTop.removeClass(z.cl.uiBarHighlight);z.highlightedLast.barTop=i(u).addClass(z.cl.uiBarHighlight);break;case"left":z.highlightedLast.barLeft.removeClass(z.cl.uiBarHighlight);z.highlightedLast.barLeft=i(u).addClass(z.cl.uiBarHighlight);break}},clearActive:function(){z.highlightedLast.barLeft.removeClass(z.cl.uiBarHighlight);z.highlightedLast.barLeft=i([]);z.highlightedLast.barTop.removeClass(z.cl.uiBarHighlight);z.highlightedLast.barTop=i([])}},tab:{setActive:function(){this.clearActive();z.obj.tab().addClass(z.cl.uiTabActive)},clearActive:function(){z.obj.tabContainer().find("span."+z.cl.uiTabActive).removeClass(z.cl.uiTabActive)}}},resizable:function(u,s){if(!u.data("resizable")){u.resizable(s)}},busy:[],setBusy:function(s){if(s){z.busy.push(s)}else{z.busy.pop()}},isBusy:function(){return(z.busy.length>0)},draggable:function(u,s){if(!u.data("jSdraggable")){u.data("jSdraggable",true).draggable(s)}},nearest:function(u,s){return i(u).nearest(s)},resizeBar:{top:function(N,I,P,u){z.obj.barTopControls().remove();var L=n.createElement("div"),O=i(L).addClass(z.cl.barController+" ui-state-highlight").width(N.width()).height(0).prependTo(N),s,M;z.controls.bar.x.controls[z.i]=z.obj.barTopControls().add(O);z.resizableCells(O,{handles:"e",start:function(R,Q){z.autoFillerHide();z.setBusy(true);s=z.col(u,I);if(P.freezeHandleTop){P.freezeHandleTop.remove()}s.removeAttribute("width")},resize:function(R,Q){s.style.width=Q.size.width+"px";if(P.inPlaceEdit){P.inPlaceEdit.goToTd()}},stop:function(R,Q){z.setBusy(false);P.resizeScroll();z.followMe();z.setDirty(true)},minWidth:32});M=L.children[0];M.style.height=N.outerHeight()+"px";M.style.position="absolute"},left:function(L,O,I,S){z.obj.barLeftControls().remove();var N=L.offset(),T=n.createElement("div"),Q=i(T).addClass(z.cl.barController+" ui-state-highlight").prependTo(L).offset({top:N.top,left:N.left}),R=L[0],M=L.next()[0],U=M.parentNode,u=n.createElement("div"),s=i(u).addClass("jSBarControllerChild").height(L.height()).prependTo(Q),P;z.controls.bar.y.controls[z.i]=z.obj.barLeftControls().add(Q);z.resizableCells(s,{handles:"s",start:function(){z.autoFillerHide();z.setBusy(true);if(I.freezeHandleLeft){I.freezeHandleLeft.remove()}U.removeAttribute("height");R.removeAttribute("height");M.removeAttribute("height")},resize:function(W,V){T.style.height=M.style.height=R.style.height=U.style.height=V.size.height+"px";if(I.inPlaceEdit){I.inPlaceEdit.goToTd()}},stop:function(W,V){z.setBusy(false);I.resizeScroll();z.followMe();z.setDirty(true)},minHeight:15});P=u.children[0];P.style.width=L.outerWidth()+"px";P.style.position="absolute"},corner:function(){}},sheetDecorateRemove:function(u,s){s=s||z.obj.tables();s=(u?s.clone():s);s.find("td."+z.cl.uiTdActive).removeClass(z.cl.uiTdActive);s.find("td."+z.cl.uiTdHighlighted).removeClass(z.cl.uiTdHighlighted);return s},labelUpdate:function(u,s){if(!s){u=d.parseCellName(u.col,u.row);if(u){z.obj.label().text(u)}}else{z.obj.label().text(u)}},cellEdit:function(O,L,I){if(z.cellLast.td.length<1){}z.autoFillerNotGroup=true;z.evt.cellEditDone();if(!O.length){return}var M=z.getTdLocation(O),s=O[0].jSCell,u;if(!s){return}if(s.uneditable){return}z.trigger("sheetCellEdit",[s]);if(!O.is(z.cellLast.td)){z.followMe(O)}else{z.autoFillerGoToTd(O)}z.labelUpdate(M);if(s.formula){u="="+s.formula}else{u=s.value}var N=z.obj.formula().val(u).blur();z.cellSetActive(O,M,L,false,null,I)},cellSetActive:function(M,O,u,Q,N,I){O=O||z.getTdLocation(M);if(O.col!=H){z.cellLast.td=M;z.cellLast.row=z.rowLast=O.row;z.cellLast.col=z.colLast=O.col;if(!I){z.themeRoller.cell.setHighlighted(M);z.highlightedLast.start=O;z.highlightedLast.end=O}if(!M.length){return}z.themeRoller.bar.setActive("left",M[0].barLeft);z.themeRoller.bar.setActive("top",M[0].barTop);var P,R;switch(K.cellSelectModel){case"excel":case"gdrive":P=function(){};R=function(){};break;case"oo":P=function(S){if(z.isCell(S)){z.cellEdit(i(S))}};R=function(){};break}if(u){var s={},L=z.obj.pane();s.last=O;L.onmousemove=function(aa){aa=aa||k.event;var ab=aa.target||aa.srcElement;if(z.isBusy()){return false}var S=z.highlightedLast.end=z.getTdLocation(ab),ac=true;if(S.col<1||S.row<1||S.col==G||S.row==G){return false}if(Q){ac=false;if(O.col==S.col||O.row==S.row){ac=true}}if((s.last.col!=S.col||s.last.row!=S.row)&&ac){P(ab);z.cycleCellArea(function(ae){z.themeRoller.cell.setHighlighted(ae.td)},O,S,false,true)}z.followMe(i(ab));var V=aa.clientY,W=aa.clientX,X=L.$enclosure.offset(),ad=z.getTdLocation(ab),Y=ad.row,U=ad.col,T=false,Z;if(v(Y)||v(U)){return false}if(V>X.top){T=true;Y--}if(W>X.left){T=true;U--}if(T){if(Y<1||U<1){return false}Z=z.spreadsheets[z.i][Y][U];z.followMe(i(Z.td),true)}s.last=S;return true};n.onmouseup=function(){L.onmousemove=null;L.onmousemove=null;L.onmouseup=null;n.onmouseup=null;if(N){N()}}}}},colLast:0,rowLast:0,cellLast:{td:i([]),row:0,col:0,isEdit:false},highlightedLast:{obj:i([]),start:{row:0,col:0},end:{row:0,col:0},barLeft:i([]),barTop:i([])},highlightedLastOrdered:function(){var u=this.highlightedLast,s={start:{},end:{}};s.start.row=c.min(u.start.row,u.end.row);s.start.col=c.min(u.start.col,u.end.col);s.end.row=c.max(u.start.row,u.end.row);s.end.col=c.max(u.start.col,u.end.col);return s},cellStyleToggle:function(O,P,M){M=M||z.highlighted();if(M.length<1){return false}z.setDirty(true);var I,s,N=M.length-1,Q=z.obj.cellsEdited(),u=z.controls.cellsEdited[z.i],L;if(N>=0){L=M[0].className.match(O);do{I=M[N];s=i(I);if(P){s.removeClass(P)}if(L){s.removeClass(O)}else{s.addClass(O)}if(!I.jSCell.edited){I.jSCell.edited=true;u=Q.add(I.jSCell)}}while(N--);return true}return false},cellTypeToggle:function(L,u){u=u||z.highlighted(true);if(u.length<1){return}var I=u.length-1,s=u[I].cellType==L;if(I>=0){do{if(s){u[I].cellType=null}else{u[I].cellType=L}u[I].calcLast=0;z.updateCellValue.call(u[I])}while(I--)}},fontReSize:function(O,M){M=M||z.highlighted();if(M.length<1){return false}var I=0;switch(O){case"up":I=1;break;case"down":I=-1;break}var L,s,N=M.length-1,Q,P=z.obj.cellsEdited(),u=z.controls.cellsEdited[z.i];if(N>=0){do{L=M[N];s=i(L);Q=(s.css("font-size")+"").replace("px","")*1;s.css("font-size",((Q||10)+I)+"px");if(!L.jSCell.edited){L.jSCell.edited=true;u=P.add(L.jSCell)}}while(N--);return true}return false},callStack:0,updateCellValue:function(Q,M,O){var L,R,P,N,s=null;Q=Q||0;M=M||-1;O=O||-1;if(M>-1){if((L=z.spreadsheets[Q])===undefined){s=K.error({error:z.msg.notFoundSheet})}else{if(s===null&&(R=L[M])===undefined){s=K.error({error:z.msg.notFoundRow})}else{if(s===null&&(P=R[O])===undefined){s=K.error({error:z.msg.notFoundColumn})}}}if(s!==null&&K.loader){if((P=K.loader.jitCell(Q,M,O))===null){return s}}}else{P=this}if(P===undefined){throw new j("cell doesn't exist")}P.oldValue=P.value;if(P.result){delete P.result}switch(P.state[P.state.length-1]){case"updating":return K.error({error:z.msg.loopDetected});case"updatingDependencies":return(P.valueOverride!=H?P.valueOverride:P.value)}if(P.defer){return z.updateCellValue.call(P.defer)}P.state.push("updating");P.fnCount=0;P.result=null;if(P.calcLast!=z.calcLast||P.calcDependenciesLast!=z.calcDependenciesLast){P.valueOverride=null;P.calcLast=z.calcLast;P.calcDependenciesLast=z.calcDependenciesLast;P.needsUpdated=true;P.calcCount++;if(P.formula){try{if(P.formula.charAt(0)=="="){P.formula=P.formula.substring(1)}var u;if(z.callStack){if(!P.formulaParser){P.formulaParser=k.Formula(z.cellHandler)}u=P.formulaParser}else{u=z.formulaParser}z.callStack++;u.setObj(P);P.result=u.parse(P.formula)}catch(I){P.result=I.toString()}z.callStack--;if(P.result&&P.cellType&&K.cellTypeHandlers[P.cellType]){P.result=K.cellTypeHandlers[P.cellType].call(P,P.result)}z.filterValue.call(P)}else{if(P.value&&P.cellType&&K.cellTypeHandlers[P.cellType]){P.result=K.cellTypeHandlers[P.cellType].call(P,P.value);z.filterValue.call(P)}else{if(P.value!=H&&P.value.charAt){N=z.s.cellStartingHandlers[P.value.charAt(0)];if(N){P.valueOverride=N.call(P,P.value)}else{N=z.s.cellEndHandlers[P.value.charAt(P.value.length-1)];if(N){P.valueOverride=N.call(P,P.value)}}}z.filterValue.call(P)}}}P.needsUpdated=false;P.state.pop();return(P.valueOverride!=H?P.valueOverride:P.value)},updateCellDependencies:function(){if((this.state||(this.state=[])).length){return}this.state.push("updatingDependencies");var L=this.dependencies||[];this.dependencies=[];var u=L.length-1;if(u>-1){do{var s=L[u],I=z.getTdLocation(s.td);s.calcDependenciesLast=0;z.updateCellValue.call(s);if(I.row>0&&I.col>0){z.updateCellDependencies.call(s)}}while(u--)}this.state.pop()},filterValue:function(){var s,u;if(this.result!=H){this.value=this.result.valueOf();u=this.result.html}else{if(typeof this.value=="string"&&this.value.length>0){s=K.encode(this.value)}}this.td.html(u||s||this.value)},cellHandler:{variable:function(){if(arguments.length){var L=arguments[0],u=arguments[1],M=z.s.formulaVariables,I,s;switch(L.toLowerCase()){case"true":s=new g(true);s.html="TRUE";return s;case"false":s=new g(false);s.html="FALSE";return s}if(I=M[L]&&!u){return I}else{if(I&&u){return I[u]}else{return""}}}},time:function(u,s){return a.fromString(u,s)},number:function(s){switch(typeof s){case"number":return s;case"string":if(!v(s)){return s*1}case"object":if(s.getMonth){return b.toCentury(s)}}return s},numberInverted:function(I){var u=z.cellHandler.number(I),s=new l(u.valueOf()*-1);if(u.html){s.html=u.html}return s},performMath:function(O,N,M){var L,I,P=true,s=true,R=[],Q,u=function(S){return S};switch(L=(typeof N.valueOf())){case"number":break;case"string":if(!v(N)){N*=1}else{P=false}break;case"object":if(N.getMonth){N=b.toCentury(N);u=b.get}else{P=false}break;default:P=false}switch(I=(typeof M.valueOf())){case"number":break;case"string":if(!v(M)){M*=1}else{s=false}break;case"object":if(M.getMonth){M=b.toCentury(M)}else{s=false}break;default:s=false}if(!P){R.push("not a number: "+N);N=0}if(!s){R.push("not a number: "+M);M=0}if(R.length){}switch(O){case"+":Q=N+M;break;case"-":Q=N-M;break;case"/":Q=N/M;if(Q==Infinity||Q==G){Q=0}break;case"*":Q=N*M;break;case"^":Q=D.pow(N,M);break}return u(Q)},cellValue:function(I){var u=d.parseLocation(I),s;s=z.cellHandler.createDependency.call(this,this.sheet,u);z.updateCellValue.call(s);return(s.valueOverride!=H?s.valueOverride:s.value)},createDependency:function(u,M){var I,L,s;if(!(I=z.spreadsheets[u])){return null}if(!(L=I[M.row])){return null}if(!(s=L[M.col])){return null}if(!s.dependencies){s.dependencies=[]}if(i.inArray(this,s.dependencies)<0){s.dependencies.push(this)}return s},cellRangeValue:function(s,u){s=d.parseLocation(s);u=d.parseLocation(u);var Q=[],L=D.max(s.row,u.row),P=D.min(s.row,u.row),I=D.max(s.col,u.col),M=I,N=D.min(s.col,u.col),O;if(L>=P||I>=N){do{I=M;do{O=z.spreadsheets[this.sheet][L][I];z.cellHandler.createDependency.call(this,this.sheet,{row:L,col:I});Q.unshift(z.updateCellValue.call(O))}while(I-->N)}while(L-->P);return Q}return Q},fixedCellValue:function(s){s=s.replace(/\$/g,"");return z.cellHandler.cellValue.call(this,s)},fixedCellRangeValue:function(u,s){u=u.replace(/\$/g,"");s=s.replace(/\$/g,"");return z.cellHandler.cellRangeValue.call(this,u,s)},remoteCellValue:function(u,L){var I=d.parseLocation(L),s=d.parseSheetLocation(u);z.cellHandler.createDependency.call(this,s,I);return z.updateCellValue(s,I.row,I.col)},remoteCellRangeValue:function(M,N,u){M=d.parseSheetLocation(M);N=d.parseLocation(N);u=d.parseLocation(u);var s=[];for(var L=N.row;L<=u.row;L++){for(var I=N.col;I<=u.col;I++){s.push(z.updateCellValue(M,L,I))}}return[s]},callFunction:function(I,u){I=I.toUpperCase();u=u||[];if(i.sheet.fn[I]){this.fnCount++;var s=i.sheet.fn[I].apply(this,u);return s}else{return K.error({error:"Function "+I+" Not Found"})}}},cellLookupHandlers:{fixedCellValue:function(s){return[z.sheet,d.parseLocation(s),d.parseLocation(s)]},fixedCellRangeValue:function(u,I,s){return[d.parseSheetLocation(u),d.parseLocation(I),d.parseLocation(s)]},cellValue:function(s){},cellRangeValue:function(u,I,s){return[z.sheet,d.parseLocation(I),d.parseLocation(s)]},remoteCellValue:function(s,u){return[z.sheet,d.parseLocation(u),d.parseLocation(u)]},remoteCellRangeValue:function(u,I,s){return[d.parseSheetLocation(u),d.parseLocation(I),d.parseLocation(s)]},callFunction:function(){if(arguments[0]=="VLOOKUP"||arguments[0]=="HLOOKUP"&&arguments[1]){if(arguments[1]&&arguments[1][1]){return arguments[1][1]}return[]}}},cellLookup:function(){var s=Formula(i.extend({},z.cellHandler,z.cellLookupHandlers));s.setObj(this);var I=s.parse(this.formula),L=[];for(var M=I[1].row;M<=I[2].row;M++){for(var u=I[1].col;u<=I[2].col;u++){L.push(z.getCell(M,u,I[0]))}}return L},calcLast:0,calcDependenciesLast:0,calc:function(s,I){s=s||z.i;if(z.readOnly[s]||z.isChanged(s)===false&&!I||!z.formulaParser){return false}z.calcLast=new m();var u=z.spreadsheetToArray(null,s);d.calc(s,u,z.updateCellValue);z.trigger("sheetCalculation",[{which:"spreadsheet",sheet:u,index:s}]);z.setChanged(false);return true},calcVisiblePos:{row:-1,col:-1},calcVisibleInit:function(Q){Q=Q||z.i;z.calcLast=z.calcLast||new m();var u=z.spreadsheetToArray(null,Q)||[],M=z.updateCellValue,I=c.min,L=K.initCalcRows,s=K.initCalcCols,O=I(u.length-1,L),R,P,N={row:-1,col:-1};if(O>0){N.row=O;do{if(O>0&&(R=u[O])!==undefined){N.col=P=I(R.length-1,s);if(P>0){do{M.apply(R[P])}while(P-->1)}}}while(O-->1)}this.calcVisiblePos=N;z.trigger("sheetCalculation",[{which:"spreadsheet",sheet:u,index:Q}]);z.setChanged(false)},calcVisibleRow:function(s,X){X=X||z.i;var N=z.spreadsheetToArray(null,X)||[],I=s.scrolledArea.end,u=s.pane.size(),S=z.updateCellValue,R=K.initCalcRows,L=K.initCalcCols,M=(I.row+R)-1,Q=(I.col+L)-1,U,Y,W,O=this.calcVisiblePos,T={row:U,col:O.col},V;M=M<u.rows?M:u.rows;Q=Q<u.cols?Q:u.cols;U=M;if(U>0){do{W=Q;if((Y=N[U])!==undefined){if(W>0){do{if((V=Y[W])===undefined){z.createCell(z.i,U,W);V=N[U][W]}S.apply(V)}while(W-->1)}}else{if(W>0){do{var P=U;while(P>0&&N[P]===undefined){this.createSpreadsheetForArea(s.table,X,P,P,W,W,true);P--}if((Y=N[U])!==undefined){S.apply(Y[W]||(Y[W]=[]))}}while(W-->1)}}}while(U-->O.row)}this.calcVisiblePos=T;z.trigger("sheetCalculation",[{which:"spreadsheet",sheet:N,index:X}]);z.setChanged(false)},calcVisibleCol:function(s,W){W=W||z.i;var N=z.spreadsheetToArray(null,W)||[],I=s.scrolledArea.end,u=s.pane.size(),R=z.updateCellValue,Q=K.initCalcRows,L=K.initCalcCols,M=(I.row+Q)-1,P=(I.col+L)-1,T,X,V,U,O=this.calcVisiblePos,S={row:O.row,col:O.col};M=M<u.rows?M:u.rows;P=P<u.cols?P:u.cols;T=M;if(T>0&&P>0){do{V=P;X=N[T];if(X===undefined||X[V]===undefined){this.createSpreadsheetForArea(s.table,W,T,T,V,V,true);X=N[T]}U=X[V];R.apply(U)}while(T-->1)}this.calcVisiblePos=S;z.trigger("sheetCalculation",[{which:"spreadsheet",sheet:N,index:W}]);z.setChanged(false)},calcDependencies:function(I,u){I=I||new m();z.calcDependenciesLast=I;if(!u){var s=this;z.undo.createCells([this],function(L){z.trigger("sheetPreCalculation",[{which:"cell",cell:s}]);z.setDirty(true);z.setChanged(true);z.updateCellValue.call(s);z.updateCellDependencies.call(s);z.trigger("sheetCalculation",[{which:"cell",cell:s}]);return L})}else{z.trigger("sheetPreCalculation",[{which:"cell",cell:this}]);z.setDirty(true);z.setChanged(true);z.updateCellValue.call(this);z.updateCellDependencies.call(this);z.trigger("sheetCalculation",[{which:"cell",cell:this}])}},addSheet:function(s){s=s||{rows:25,cols:10};if(s){z.evt.cellEditAbandon();z.setDirty(true);z.controlFactory.sheetUI(z.obj.ui,i.sheet.makeTable(s),z.sheetCount);z.setActiveSheet(z.sheetCount);z.sheetCount++;z.sheetSyncSize();z.obj.pane().resizeScroll();z.trigger("sheetAdd",[z.i])}},deleteSheet:function(u){var M=u||z.i,L=z.controls.enclosures.toArray(),s;L.splice(M,1);z.obj.barHelper().remove();z.obj.enclosure().remove();z.controls.enclosures=i(L);z.obj.menus().remove();z.obj.tabContainer().children().eq(z.i).remove();z.spreadsheets.splice(M,1);z.controls.autoFiller.splice(M,1);z.controls.bar.helper.splice(M,1);z.controls.bar.corner.splice(M,1);z.controls.bar.x.controls.splice(M,1);z.controls.bar.x.handleFreeze.splice(M,1);z.controls.bar.x.controls.splice(M,1);z.controls.bar.x.menu.splice(M,1);if(z.controls.bar.x.menuParent&&z.controls.bar.x.menuParent[M]){z.controls.bar.x.menuParent.splice(M,1)}z.controls.bar.x.parent.splice(M,1);z.controls.bar.x.td.splice(M,1);z.controls.bar.y.controls.splice(M,1);z.controls.bar.y.handleFreeze.splice(M,1);z.controls.bar.y.controls.splice(M,1);z.controls.bar.y.menu.splice(M,1);if(z.controls.bar.y.menuParent&&z.controls.bar.y.menuParent[M]){z.controls.bar.y.menuParent.splice(M,1)}z.controls.bar.y.parent.splice(M,1);z.controls.bar.y.td.splice(M,1);z.controls.barMenuLeft.splice(M,1);z.controls.barMenuTop.splice(M,1);z.controls.barLeft.splice(M,1);z.controls.barTop.splice(M,1);z.controls.barTopParent.splice(M,1);z.controls.chart.splice(M,1);z.controls.tdMenu.splice(M,1);z.controls.enclosure.splice(M,1);z.controls.fullScreen=null;z.controls.inPlaceEdit.splice(M,1);z.controls.menus.splice(M,1);z.controls.menuLeft.splice(M,1);z.controls.menuRight.splice(M,1);z.controls.pane.splice(M,1);z.controls.tables.splice(M,1);z.controls.table.splice(M,1);for(s=M+1;s<z.controls.tab.length;++s){var I=z.controls.tab[s].get(0);I.i--}z.controls.tab.splice(M,1);z.controls.toggleHide.x.splice(M,1);z.controls.toggleHide.y.splice(M,1);z.readOnly.splice(M,1);z.i=0;z.sheetCount--;z.sheetCount=D.max(z.sheetCount,0);if(z.sheetCount==0){z.addSheet()}z.setActiveSheet(z.i);z.setDirty(true);z.setChanged(true);z.trigger("sheetDelete",[M])},deleteRow:function(M,u){var L,O,s,N,I=z.sheetSize();if(M){O=s=M}else{O=D.min(z.highlightedLast.start.row,z.highlightedLast.end.row);s=D.max(z.highlightedLast.start.row,z.highlightedLast.end.row)}N=(s-O)+1;if(O<1||I.cols<2||N>=I.rows){return}L=s;do{z.getTd(z.i,L,1).parent().remove()}while(O<L--);z.controls.bar.y.td[z.i].splice(O,N);z.spreadsheets[z.i].splice(O,N);z.refreshRowLabels(O);z.setChanged(true);z.offsetFormulas({row:O,col:0},{row:-N,col:0},false,true);z.setDirty(true);z.evt.cellEditAbandon();z.obj.pane().resizeScroll();z.trigger("sheetDeleteRow",L)},deleteColumn:function(O){var M,s,L,Q,S=z.sheetSize();if(O){s=L=O}else{s=D.min(z.highlightedLast.start.col,z.highlightedLast.end.col);L=D.max(z.highlightedLast.start.col,z.highlightedLast.end.col)}Q=(L-s)+1;if(s<1||S.cols<2||Q>=S.cols){return}M=L;z.obj.barHelper().remove();do{var R=z.obj.table(),u=z.col(R[0],M),P=z.obj.barTop(M).remove(),N=u.tds,I=N.length-1;do{i(N[I]).remove()}while(I--);z.obj.barTop(M).remove();i(u).remove()}while(s<M--);z.controls.bar.x.td[z.i].splice(s,Q);I=z.spreadsheets[z.i].length-Q;do{z.spreadsheets[z.i][I].splice(s,Q)}while(I-->1);z.refreshColumnLabels(s);z.setChanged(true);z.offsetFormulas({row:0,col:s},{row:0,col:-Q},false,true);z.setDirty(true);z.evt.cellEditAbandon();z.obj.pane().resizeScroll();z.trigger("sheetDeleteColumn",M)},sheetTab:function(u,I){var s="";if(u){s=z.obj.table().attr("title")||z.msg.sheetTitleDefault.replace(/[{]index[}]/gi,z.i+1);if(I){I(s)}return s}else{if(z.isSheetEditable()&&K.editableNames){K.prompt(z.msg.newSheetTitle,function(L){if(!L){s=z.obj.table().attr("title");L=(s?s:z.msg.sheetTitleDefault.replace(/[{]index[}]/gi,z.i+1))}else{z.setDirty(true);z.obj.table().attr("title",L);z.obj.tab().html(L);s=L}if(I){I(i(n.createElement("div")).text(s).html())}},z.sheetTab(true));return null}}},tdNotVisible:function(u){var I=z.obj.pane(),L=u[0],S={top:0,bottom:I.clientHeight,left:0,right:I.clientWidth},P=u.width(),N=u.height(),Q={top:L.offsetTop,bottom:L.offsetTop+N,left:L.offsetLeft,right:L.offsetLeft+P},s=u.parent();if(!L.col){return false}var R=i(L.barTop).is(":hidden"),M=s.is(":hidden"),O={up:M,down:Q.bottom>S.bottom&&N<=I.clientHeight,left:R,right:Q.right>S.right&&P<=I.clientWidth};if(O.up||O.down||O.left||O.right){return O}return false},followMe:function(I,s){I=I||z.obj.tdActive();if(!I.length){return}var L=z.obj.pane(),u=L.actionUI;z.setBusy(true);u.putTdInView(I[0]);z.setBusy(false);if(!s){z.autoFillerGoToTd(I)}},autoFillerGoToTd:function(L,u,s){if(!K.autoFiller){return}L=L||z.obj.tdActive();var M=L[0];if(M&&M.type=="cell"){u=u||M.clientHeight;s=s||M.clientWidth;if(!M.offsetHeight||!M.offsetWidth||!M.clientHeight||!M.clientWidth){z.autoFillerHide();return}var I=L.position();z.obj.autoFiller().show().css("top",((I.top+(u||L.height())-3)+"px")).css("left",((I.left+(s||L.width())-3)+"px"))}},autoFillerHide:function(){if(!K.autoFiller){return}z.obj.autoFiller().hide()},setActiveSheet:function(I){I=I||0;if(z.cellLast.row>0||z.cellLast.col>0){z.evt.cellEditDone();z.obj.formula().val("")}var u=z.obj.enclosures(),s=u.length-1,L;z.autoFillerHide();if(s>0){do{if(I!=s){L=u[s];L._scrollLeft=L._scrollLeft||L.scrollUI.scrollLeft;L._scrollTop=L._scrollTop||L.scrollUI.scrollTop;L.style.display="none"}}while(s-->0)}z.i=I;L=u[I];L.style.display="";z.themeRoller.tab.setActive();z.readOnly[I]=(L.table.className||"").match(/\breadonly\b/i)!=null;L.pane.resizeScroll(true);L.scrollUI.scrollLeft=L._scrollLeft||L.scrollUI.scrollLeft;L.scrollUI.scrollTop=L._scrollTop||L.scrollUI.scrollTop;L._scrollLeft=L._scrollTop=null;L.scrollUI.onscroll()},openSheet:function(I){var M=I.length-1,s=[],u=function(){z.setBusy(true);var R=z.controlFactory.header(),Q=z.controlFactory.ui(),N=z.controlFactory.sheetAdder(),O=z.controlFactory.tabContainer(),P;R.ui=Q;R.tabContainer=O;Q.header=R;Q.sheetAdder=N;Q.tabContainer=O;O.header=R;O.ui=Q;K.parent.append(R).append(Q).append(N).append(O);for(P=0;P<I.length;P++){new L(z,P,Q,I[P])}},L=function(S,O,R,Q){var P=this;this.i=O;this.ui=R;this.table=Q;this.isLast=(O==M);this.jS=S;if(i.sheet.max){var N=S.tableSize(Q);if(N.rows>i.sheet.max||N.cols>i.sheet.max){S.trigger("sheetMaxSize",[Q,O]);K.confirm(S.msg.maxSizeBrowserLimitationOnOpen,function(){P.load()})}else{this.load()}}else{this.load()}};L.prototype={load:function(){z.controlFactory.sheetUI(this.ui,this.table,this.i);z.sheetCount++;s.push(this.i);z.trigger("sheetOpened",[this.i]);if(this.isLast){this.loaded()}},loaded:function(){var O=this.jS,N=this.ui;O.resizableSheet(K.parent,{minWidth:K.parent.width()*0.1,minHeight:K.parent.height()*0.1,start:function(){O.setBusy(true);O.obj.enclosure().hide();N.sheetAdder.hide();N.tabContainer.hide()},stop:function(){O.obj.enclosure().show();N.sheetAdder.show();N.tabContainer.show();O.setBusy(false);O.sheetSyncSize();O.obj.pane().resizeScroll()}});O.sheetSyncSize();O.setActiveSheet(0);O.setDirty(false);O.setBusy(false);while(s.length){O.calcVisibleInit(O.i=s.pop())}O.trigger("sheetAllOpened")}};if(z.isDirty){K.confirm(z.msg.openSheet,u)}else{u()}},newSheet:function(){K.parent.html(i.sheet.makeTable()).sheet(K)},sheetSyncSize:function(){var M=K.parent[0].clientHeight;if(!M){M=400;K.parent.height(M)}else{if(M<200){M=200;K.parent.height(M)}}M-=z.obj.header().outerHeight();M-=z.obj.tabContainer().outerHeight()+z.s.boxModelCorrection;var u=K.parent[0].clientWidth,O=z.obj.ui.style,L=(M-k.scrollBarSize.height-K.boxModelCorrection)+"px",s=(u-k.scrollBarSize.width)+"px",N=M+"px",I=u+"px";z.obj.panes().each(function(){var R=this.style,Q=this.actionUI.scrollUI.style,P=this.enclosure.style;R.height=L;R.width=s;P.height=Q.height=N;P.width=Q.width=I});O.height=N;O.width=I},cellChangeStyle:function(I,L,s){s=s||z.highlighted(true);if(s.length<1){return false}z.setDirty(this);var u=s.length-1;if(u>=0){z.undo.createCells(s,function(M){do{M[u].td.css(I,L)}while(u--);return M});return true}return false},cellFind:function(s){function u(L){var I=z.obj.table().children("tbody").children("tr");if(L){var M=I.children('td:contains("'+L+'")');if(M.length<1){M=I.children('td:contains("'+L.toLowerCase()+'")')}if(M.length<1){M=I.children('td:contains("'+L.toUpperCase()+'")')}M=M.eq(0);if(M.length>0){z.cellEdit(M)}else{K.alert(z.msg.cellNoFind)}}}if(!s){K.prompt(z.msg.cellFind,u)}else{u(s)}},cellSetActiveBar:function(Q,I,L){var V=z.sheetSize(),N=D.min(I,L),S=D.max(I,L),s={},R={},U=function(W){switch(K.cellSelectModel){case"oo":this.row=(W?s.row:R.row);this.col=(W?s.col:R.col);this.td=z.getTd(z.i,this.row,this.col);if(!this.td.is(z.cellLast.td)){z.cellEdit(this.td,false,true)}break;default:this.row=(W?R.row:s.row);this.col=(W?R.col:s.col);this.td=z.getTd(z.i,this.row,this.col);if(!this.td.is(z.cellLast.td[0])){z.cellEdit(this.td,false,true)}break}},M=[],O=z.obj.pane().actionUI.scrolledArea,P=z.obj.table(),u,T;switch(Q){case"top":s.row=O.end.row;s.col=N;R.row=O.end.row;R.col=S;z.highlightedLast.start.row=1;z.highlightedLast.start.col=N;z.highlightedLast.end.row=V.rows;z.highlightedLast.end.col=S;u=S;do{M.push(z.col(P[0],u))}while(u-->N);break;case"left":s.row=N;s.col=O.end.col;R.row=S;R.col=O.end.col;z.highlightedLast.start.row=N;z.highlightedLast.start.col=1;z.highlightedLast.end.row=S;z.highlightedLast.end.col=V.cols;T=S;do{M.push(z.getTd(z.i,T,1)[0].parentNode)}while(T-->N);break;case"corner":s.row=1;s.col=1;R.col=V.cols;R.row=V.rows;M.push(P[0]);break}new U(I>L);z.themeRoller.cell.setHighlighted(i(M))},getTdRange:function(L,Q,O,P){z.cellLast.isEdit=true;var u=function(S){if(S.first.col>S.last.col||S.first.row>S.last.row){return{first:d.parseCellName(S.last.col,S.last.row),last:d.parseCellName(S.first.col,S.first.row)}}else{return{first:d.parseCellName(S.first.col,S.first.row),last:d.parseCellName(S.last.col,S.last.row)}}},N=function(V){var S=u(V),U=Q+"";U=(U.match(/=/)?U:"="+U);if(O||U.charAt(U.length-1)!="("){U=U+(O?O:"")+"("}var W,T="";if(S.first!=S.last){W=S.first+":"+S.last}else{W=S.first}if(U.charAt(U.length-1)=="("){T=")"}return U+W+T},s="",I,M,R;if(L){I={first:z.getTdLocation([L.target])};M=z.obj.table().mousemove(function(S){I.last=z.getTdLocation([S.target]);s=N(I);if(!P){z.obj.formula().val(s);z.obj.inPlaceEdit().val(s)}});w.one("mouseup",function(){M.unbind("mousemove");return s})}else{R=z.highlighted().not(z.obj.tdActive());if(R.length){I={first:z.getTdLocation(R.first()),last:z.getTdLocation(R.last())};s=N(I);if(!P){z.obj.formula().val(s);z.obj.inPlaceEdit().val(s)}return s}else{return""}}return""},getTd:function(M,O,u){var I=z.obj.tables()[M],s,L,N;if(!I||!(s=I.tBody)||!(L=s.children[O])||!(N=L.children[u])){N=n.createElement("td")}return i(N)},getTdLocation:function(u){var s={col:0,row:0};u=u||"";if(!u&&!u[0]){return s}u=u[0]||u;if(u.parentNode==H||u.parentNode.rowIndex<0){return s}return{col:parseInt(u.cellIndex),row:parseInt(u.parentNode.rowIndex)}},getBarIndex:{left:function(s){s=s||{};if(!s.parentNode||v(s.parentNode.rowIndex)){return -1}else{return s.parentNode.rowIndex}},top:function(s){s=s||{};if(v(s.cellIndex)){return -1}else{return s.cellIndex}},corner:function(){return 0}},time:{now:new m(),last:new m(),diff:function(){return D.abs(D.ceil(this.last.getTime()-this.now.getTime())/1000).toFixed(5)},set:function(){this.last=this.now;this.now=new m()},get:function(){return this.now.getHours()+":"+this.now.getMinutes()+":"+this.now.getSeconds()}},changed:[],isChanged:function(s){return z.changed[s||z.i]},setChanged:function(s){z.changed[z.i]=s},isDirty:false,setDirty:function(s){z.dirty=s},appendToFormula:function(s){var I=z.obj.formula(),u=I.val();if(u.charAt(0)!="="){u="="+u}I.val(u+s)},undo:{manager:(k.UndoManager?new UndoManager():{undo:F,redo:F,register:F,notLoaded:true}),cells:[],id:0,createCells:function(s,u,M){if(z.undo.manager.notLoaded){this.createCells=function(N,O,P){return O(N)};return this.createCells(s,u,M)}if(M==H){z.undo.id++;M=z.undo.id}var I=new t(s).clone().cells,L=(u?new t(u(s)).clone().cells:I);I.id=M;L.id=M;z.undo.manager.add({undo:function(){z.undo.removeCells(I,M)},redo:function(){z.undo.createCells(L,null,M)}});if(M!=z.undo.id||!u){z.calcLast=new m();z.undo.draw(L)}return true},removeCells:function(u,L){var I=0,s=-1;if(u.id===L){s=I}if(s!==-1){}z.undo.draw(u)},draw:function(I){var u;for(u=0;u<I.length;u++){var M=I[u],L=z.getTdLocation(M.td),s=z.spreadsheets[M.sheet][L.row][L.col];s.value=M.value;s.formula=M.formula;s.td=M.td;s.dependencies=M.dependencies;s.needsUpdated=M.needsUpdated;s.calcCount=M.calcCount;s.sheet=M.sheet;s.calcLast=M.calcLast;s.html=M.html;s.state=M.state;s.jS=M.jS;s.calcDependenciesLast=M.calcDependenciesLast;s.td.attr("style",M.style);s.td.attr("class",M.cl);z.updateCellValue.call(s)}}},cols:function(s){s=s||z.obj.table()[0];if(!s){return[]}if(!s.colGroup){return[]}if(!s.colGroup.children){return[]}return s.colGroup.children},tables:function(R,M){R=R||z.obj.tables();var Q=[],I=R.length-1,u,T,P,s,U,L,S,N,O;do{T=(M?n.body.removeChild(R[I]):R[I].cloneNode(true));if((s=T.children[0])&&(U=s.children[0])){s.removeChild(U)}if(P=T.children[1]){N=P.children;S=N[0];P.removeChild(S);u=N.length-1;do{O=N[u];L=O.children[0];O.removeChild(L)}while(u-->0)}Q[I]=T}while(I-->0);return z.sheetDecorateRemove(false,i(Q))},col:function(u,s){u=u||z.obj.table()[0];var I=z.cols(u);if(s===H){s=I.length-1}return I[s]},rowTds:function(u,s){u=u||z.obj.table();var I=z.rows(u);if(!I.length){return[]}if(s==H){s=I.length-1}if(!I[s]){return[]}if(!I[s].children){return[]}return I[s].children},rows:function(s){s=s||z.obj.table()[0];if(!s){return[]}if(!s.tBody){return[]}if(!s.tBody.children){return[]}return s.tBody.children},highlighted:function(u){var L=z.highlightedLast.obj||i([]),M=[],s,I;if(!(s=L)||!L.length||!(s=s[0])||!s.tagName){return u?M:i(M)}switch(s.tagName){case"TD":I=L.length-1;do{M.unshift(u?L[I].jSCell:L[I])}while(I-->0);break;case"TR":I=L.length-1;do{if(L[I].tds){M=M.concat(u?L[I].jSCells:L[I].tds)}}while(I-->0);break;case"COL":L=L.filter("col");I=L.length-1;do{if(L[I].tds){M=M.concat(u?L[I].jSCells:L[I].tds)}}while(I-->0);break;case"TABLE":M=(u?s.jSCells:s.tds);break}return u?M:i(M)},sheetSize:function(I){var u,M,s={},L=K.minSize;I=I||z.obj.table()[0];if(K.loader!==null){s=K.loader.size(I.spreadsheetIndex);if(L!==null){s.rows=c.max(s.rows,L.rows);s.cols=c.max(s.cols,L.cols)}return s}if((s.cols=K.initScrollCols)>0&&(s.rows=K.initScrollRows)>0){}else{u=z.rowTds(I);M=z.getTdLocation(u[u.length-1]);s.cols=M.col;s.rows=M.row}return s},test:function(){var u=z.highlighted(true);console.log(z.obj.enclosure())},sortVerticalSelectAscending:function(){if(confirm("Do you want to extend your selection?")){z.sortVertical();return true}else{z.sortVerticalSingle(false);return true}},sortVerticalSelectDescending:function(){if(confirm("Do you want to extend your selection?")){z.sortVertical();return false}else{z.sortVerticalSingle(true);return false}},sortVertical:function(R){var P=z.highlighted(true),M=P[0].td.parent().prev(),s=P.length,I=new m(),O=true,S=[],U=[],N,Q=0,T,u,L;while(Q<s){T=P[Q];L=T.td[0];if(!isNaN(T.value)){u=(new l(T.value.valueOf()))}else{O=false;u=(new o(T.value.valueOf()))}u.loc=z.getTdLocation(L);u.row=L.parentNode;u.col=L;u.cell=T;S.push(u);Q++}if(R){if(O==false){S.sort(function(W,V){return V-W})}else{S.sort();S.reverse()}}else{if(O==true){S.sort(function(W,V){return W-V})}else{S.sort()}}z.undo.createCells(P);while(N=S.length){u=S.pop();U=z.spreadsheets[z.i].splice(u.row.rowIndex,1);T=u.cell;T.value=u.valueOf();T.calcLast=0;u.row.parentNode.removeChild(u.row);M.after(u.row);u.row.children[0].innerHTML=M[0].rowIndex+N;z.spreadsheets[z.i].splice(M[0].rowIndex+1,0,U[0]);z.calcDependencies.call(T,I,true)}z.undo.createCells(P)},sortVerticalSingle:function(N){var L=z.highlighted(true),M=L.length,I=0,u=[],s;while(I<M){u.push(L[I].value);I++}if(N){u.sort(function(P,O){return O-P})}else{u.sort(function(P,O){return P-O})}while(L.length){s=L.pop();s.value=u[L.length];s.calcLast=0;z.updateCellValue.call(s);z.updateCellDependencies.call(s)}},sortHorizontalSelectAscending:function(){if(confirm("Do you want to extend your selection?")){z.sortHorizontal();return true}else{z.sortHorizontalSingle(false);return true}},sortHorizontalSelectDescending:function(){if(confirm("Do you want to extend your selection?")){z.sortHorizontal();return false}else{z.sortHorizontalSingle(true);return false}},sortHorizontal:function(R){var P=z.highlighted(true),X=P[0].td[0],T=X.cellIndex,s=X.table.colGroup,Y=z.sheetSize().rows,u=P.length,L=new m(),O=true,U=[],N,Q=0,V,W,I,S,M;while(Q<u){V=0;W=P[Q];M=W.td[0];if(!isNaN(W.value)){I=new l(W.value.valueOf())}else{O=false;I=new o(W.value.valueOf())}I.tds=[];I.loc=z.getTdLocation(M);I.tr=M.parentNode;I.td=M;I.cell=W;while(V<=Y){I.tds.push(z.obj.pane().table.children[1].children[V].children[M.cellIndex]);V++}U.push(I);Q++}if(R){if(O==false){U.sort(function(aa,Z){return Z-aa})}else{U.sort();U.reverse()}}else{if(O==true){U.sort(function(aa,Z){return aa-Z})}else{U.sort()}}z.undo.createCells(P);while(U.length){I=U.pop();while(I.tds.length>1){M=I.tds.pop();S=M.parentNode;W=z.spreadsheets[z.i][S.rowIndex].splice(M.cellIndex,1);S.insertBefore(M,S.children[T]);M.col=s.children[U.length+M.cellIndex-1];M.barTop=M.col.bar;W.value=M.jSCell.value;W.calcLast=L;z.spreadsheets[z.i][S.rowIndex].splice(M.cellIndex,0,W[0]);z.calcDependencies.call(W,L,true)}}z.undo.createCells(P)},sortHorizontalSingle:function(N){var L=z.highlighted(true),M=L.length,I=0,u=[],s;while(I<M){u.push(L[I].value);I++}if(N){u.sort(function(P,O){return O-P})}else{u.sort(function(P,O){return P-O})}while(L.length){s=L.pop();s.value=u[L.length];s.calcLast=0;z.updateCellValue.call(s);z.updateCellDependencies.call(s)}},tableSize:function(I){I=I||z.obj.table()[0];var s=I.tBody||{},M=s.children||[],L=M[M.length-1]||{},u=L.children||[],N=u[u.length-1]||{};return{cols:N.cellIndex||0,rows:L.rowIndex||0}},toggleState:function(s){if(K.allowToggleState){var u=s||z.tables();if(K.editable){z.evt.cellEditAbandon();z.trigger("sheetSave",[u])}z.setDirty(false);z.setChanged(true);K.editable=!K.editable;z.kill();K.parent.html(u).sheet(K);K=null}},setCellRef:function(u){function s(M){if(M){z.s.formulaVariables[M]=z.updateCellValue(z.i,I.row,I.col)}}var L=z.obj.tdActive(),I=z.getTdLocation(L);if(u){s(u)}else{K.prompt(z.msg.setCellRef,s)}},formulaParser:null},x=[];z.setBusy(true);K.parent[0].jS=z;if(!k.console){k.console={log:function(){}}}if(!k.scrollBarSize){k.scrollBarSize=i.sheet.getScrollBarSize()}if(k.Formula){z.formulaParser=k.Formula(z.cellHandler)}K.origHtml=K.parent.children().detach();K.parent.addClass(z.cl.parent);K.parent.bind("sheetSwitch",function(I,u,s){z.switchSheet(s)}).bind("sheetRename",function(I,u,s){z.renameSheet(s)});K.width=(K.width?K.width:K.parent.width());K.height=(K.height?K.height:K.parent.height());if(!i.nearest){z.nearest=F}z.resizableCells=z.resizableSheet=z.resizable;if(!i.ui){z.resizable=z.resizableCells=z.resizableSheet=z.draggable=F}else{if(!K.resizableCells){z.resizableCells=F}if(!K.resizableSheet){z.resizableSheet=F}}if(!i.support.boxModel){K.boxModelCorrection=0}if(!K.barMenus){z.controlFactory.barMenuTop=z.controlFactory.barMenuLeft=F}if(!K.freezableCells){z.controlFactory.barHandleFreeze.top=z.controlFactory.barHandleFreeze.left=F}if(K.calcOff){z.calc=F}if(!k.Raphael){d.chart=F}r.resize(function(){if(z&&!z.isBusy()){K.width=K.parent.width();K.height=K.parent.height();z.sheetSyncSize()}});if(i.sheet.fn){i.sheet.fn=i.extend(i.sheet.fn,K.formulaFunctions);if(i.sheet.advancedfn){i.sheet.fn=i.extend(i.sheet.fn,i.sheet.advancedfn)}if(i.sheet.financefn){i.sheet.fn=i.extend(i.sheet.fn,i.sheet.financefn)}}K.title=K.title||K.parent.attr("title")||"";z.s=K;K.parent.addClass(z.cl.uiParent);if(K.origHtml.length){z.openSheet(K.origHtml)}else{if(K.loader){while(x.length<K.loader.count){x.push(n.createElement("table"))}z.openSheet(i(x))}else{z.openSheet(i(n.createElement("table")))}}z.setBusy(false);return z},makeTable:function(D,t,r){var B=n;D=D||{rows:25,cols:10};t=t||120;r=r||15;var C=n.createElement("table"),s=n.createElement("colgroup"),A=n.createElement("tbody"),x="width:"+t+"px;",v="height:"+r+"px;",z,u,y,w;y=D.cols;do{u=n.createElement("col");u.setAttribute("style",x);s.appendChild(u)}while(y-->1);y=D.rows;do{z=n.createElement("tr");z.setAttribute("style",v);w=D.cols;do{z.appendChild(n.createElement("td"))}while(w-->1);A.appendChild(z)}while(y-->1);C.appendChild(s);C.appendChild(A);return C},killAll:function(){if(i.sheet){var r=i.sheet.instance;if(r){for(var s=0;s<r.length;s++){if(r[s]&&r[s].kill){r[s].kill()}}i.sheet.instance=[]}}},scrollLocker:function(s){var r=i.sheet.instance;r[s].obj.panes().each(function(t){var u;i(u=this.scrollUI).scroll(function(w){var v=r.length-1,x;if(v>-1){do{x=r[v].controls.enclosure[t][0].scrollUI;if(this!==x){x.scrollLeft=u.scrollLeft;x.scrollTop=u.scrollTop}}while(v--)}})})},switchSheetLocker:function(r){i.each(i.sheet.instance,function(){this.s.parent.bind("sheetSwitch",function(u,t,s){i.each(i.sheet.instance,function(){this.setActiveSheet(s)})})})},I:function(){var r=0;if(this.instance){r=(this.instance.length===0?0:this.instance.length-1)}else{this.instance=[]}return r},getScrollBarSize:function(){var x=n,A=i(n.createElement("p")).css({width:"100%",height:"100%"}),z=i(n.createElement("div")).css({position:"absolute",width:"100px",height:"100px",top:"0",left:"0",visibility:"hidden",overflow:"hidden"}).append(A);i(n.body).append(z);var t=A.width(),v=A.height();z.css("overflow","scroll");var r=A.width(),u=A.height();if(t==r&&z[0].clientWidth){r=z[0].clientWidth}if(v==u&&z[0].clientHeight){u=z[0].clientHeight}z.detach();var y=t-r,s=v-u;return{width:y||15,height:s||15}},debugPositionBox:function(r,w,t,s,v){s=s||"#"+c.floor(c.random()*16777215).toString(16);if(t){var u=i([]);u=u.add(this.debugPositionBox(t.left,t.top,null,s,"top-left"));u=u.add(this.debugPositionBox(t.right,t.top,null,s,"top-right"));u=u.add(this.debugPositionBox(t.left,t.bottom,null,s,"bottom-left"));u=u.add(this.debugPositionBox(t.right,t.bottom,null,s,"bottom-right"));return u}return i('<div style="width: 10px; height: 10px; position: absolute;"></div>').css("top",(w-5)+"px").css("left",(r+5)+"px").css("background-color",s).click(function(){console.log(v||"none")}).appendTo("body")}};var d=i.sheet.engine={calc:function(t,r,u){r=r||[];var v=r.length-1,s;if(v>0){do{if(v>0&&r[v]){s=r[v].length-1;if(s>0){do{u(t,v,s)}while(s--)}}}while(v--)}},parseLocation:function(s){for(var r=0;r<s.length;r++){if(s.charCodeAt(r)<=57){break}}return{row:parseInt(s.substring(r)),col:d.columnLabelIndex(s.substring(0,r))}},parseSheetLocation:function(r){return((r+"").replace("SHEET","")*1)-1},parseCellName:function(r,s){return d.columnLabelString(r)+(s||"")},alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),columnLabels:{},columnLabelIndex:function(r){return this.columnLabels[r.toUpperCase()]},columnIndexes:[],columnLabelString:function(v){if(!this.columnIndexes.length){var x="",w,u,t,r;w=u=t=-1;for(r=1;r<16385;++r){x="";++t;if(t==26){t=0;++u;if(u==26){u=0;++w}}if(w>=0){x+=this.alphabet[w]}if(u>=0){x+=this.alphabet[u]}if(t>=0){x+=this.alphabet[t]}this.columnIndexes[r]=x;this.columnLabels[x]=r}}return this.columnIndexes[v]||""},regEx:{n:/[\$,\s]/g,cell:/\$?([a-zA-Z]+|[#]REF[!])\$?([0-9]+|[#]REF[!])/gi,range:/\$?([a-zA-Z]+)\$?([0-9]+):\$?([a-zA-Z]+)\$?([0-9]+)/gi,remoteCell:/\$?(SHEET+)\$?([0-9]+)[:!]\$?([a-zA-Z]+)\$?([0-9]+)/gi,remoteCellRange:/\$?(SHEET+)\$?([0-9]+)[:!]\$?([a-zA-Z]+)\$?([0-9]+):\$?([a-zA-Z]+)\$?([0-9]+)/gi,sheet:/SHEET/i,amp:/&/g,gt:/</g,lt:/>/g,nbsp:/ /g},chart:function(u){var t=this.jS,r=this;function s(w,x){if(!w){if(x){w=0}else{w=""}}else{if(x){w=f.toNumbers(w)}else{w=f.flatten(w)}}return w}u=i.extend({x:{legend:"",data:[0]},y:{legend:"",data:[0]},title:"",data:[0],legend:"",td:this.td,chart:i(n.createElement("div")).addClass(t.cl.chart).mousedown(function(){u.td.mousedown()}),gR:{}},u);t.controls.chart[t.i]=t.obj.chart().add(u.chart);u.data=s(u.data,true);u.x.data=s(u.x.data,true);u.y.data=s(u.y.data,true);u.legend=s(u.legend);u.x.legend=s(u.x.legend);u.y.legend=s(u.y.legend);u.legend=(u.legend?u.legend:u.data);t.s.parent.one("sheetCalculation",function(){var w=u.chart.width(),v=u.chart.height(),x=Raphael(u.chart[0]);if(u.title){x.text(w/2,10,u.title).attr({"font-size":20})}switch(u.type){case"bar":u.gR=x.barchart(w/8,v/8,w*0.8,v*0.8,u.data,u.legend).hover(function(){this.flag=x.popup(this.bar.x,this.bar.y,this.bar.value||"0").insertBefore(this)},function(){this.flag.animate({opacity:0},300,function(){this.remove()})});break;case"hbar":u.gR=x.hbarchart(w/8,v/8,w*0.8,v*0.8,u.data,u.legend).hover(function(){this.flag=x.popup(this.bar.x,this.bar.y,this.bar.value||"0").insertBefore(this)},function(){this.flag.animate({opacity:0},300,function(){this.remove()})});break;case"line":u.gR=x.linechart(w/8,v/8,w*0.8,v*0.8,u.x.data,u.y.data,{nostroke:false,axis:"0 0 1 1",symbol:"circle",smooth:true}).hoverColumn(function(){this.tags=x.set();if(this.symbols.length){for(var y=0,z=this.y.length;y<z;y++){this.tags.push(x.tag(this.x,this.y[y],this.values[y],160,10).insertBefore(this).attr([{fill:"#fff"},{fill:this.symbols[y].attr("fill")}]))}}},function(){this.tags&&this.tags.remove()});break;case"pie":u.gR=x.piechart(w/2,v/2,(w<v?w:v)/2,u.data,{legend:u.legend}).hover(function(){this.sector.stop();this.sector.scale(1.1,1.1,this.cx,this.cy);if(this.label){this.label[0].stop();this.label[0].attr({r:7.5});this.label[1].attr({"font-weight":800})}},function(){this.sector.animate({transform:"s1 1 "+this.cx+" "+this.cy},500,"bounce");if(this.label){this.label[0].animate({r:5},500,"bounce");this.label[1].attr({"font-weight":400})}});break;case"dot":u.gR=x.dotchart(w/8,v/8,w*0.8,v*0.8,u.x.data,u.y.data,u.data,{symbol:"o",max:10,heat:true,axis:"0 0 1 1",axisxstep:u.x.data.length-1,axisystep:u.y.data.length-1,axisxlabels:(u.x.legend?u.x.legend:u.x.data),axisylabels:(u.y.legend?u.y.legend:u.y.data),axisxtype:" ",axisytype:" "}).hover(function(){this.marker=this.marker||x.tag(this.x,this.y,this.value,0,this.r+2).insertBefore(this);this.marker.show()},function(){this.marker&&this.marker.hide()});break}u.gR.mousedown(function(){u.td.mousedown().mouseup()});u.chart.mousemove(function(){u.td.mousemove();return false})});return u.chart}};var e=i.sheet.fn={ISNUMBER:function(s){var r;if(!isNaN(s.valueOf())){r=new g(true);r.html="TRUE";return r}r=new g(false);r.html="FALSE";return r},N:function(r){if(r==null){return 0}if(r instanceof m){return r.getTime()}if(typeof(r)=="object"){r=r.toString()}if(typeof(r)=="string"){r=parseFloat(r.replace(d.regEx.n,""))}if(isNaN(r)){return 0}if(typeof(r)=="number"){return r}if(r==true){return 1}return 0},VERSION:function(){return this.jS.version},ABS:function(r){return c.abs(e.N(r))},CEILING:function(s,r){r=r||1;return(parseInt(s/r)*r)+r},EVEN:function(r){r=c.round(r);var s=(r%2==0);if(!s){if(r>0){r++}else{r--}}return r},EXP:function(r){return c.exp(r)},FLOOR:function(t,s){s=s||1;if((t<0&&s>0)||(t>0&&s<0)){var r=new l(0);r.html="#NUM";return r}if(t>=0){return c.floor(t/s)*s}else{return c.ceil(t/s)*s}},INT:function(r){return c.floor(e.N(r))},LN:function(r){return c.log(r)},LOG:function(r,s){s=s||10;return c.log(r)/c.log(s)},LOG10:function(r){return e.LOG(r)},MOD:function(r,t){var s=r%t;if(t<0){s*=-1}return s},ODD:function(r){var t=false;if(r>0){r=c.floor(c.round(r));t=true}else{r=c.ceil(r)}var s=c.abs(r);if((s%2)==0){s++}if(t){return s}else{return -s}},PI:function(){return c.PI},POWER:function(r,s){return c.pow(r,s)},SQRT:function(r){return c.sqrt(r)},RAND:function(){return c.random()},RND:function(){return c.random()},ROUND:function(t,s){var r=c.pow(10,s||0);return c.round(t*r)/r},ROUNDDOWN:function(s,r){var t=(s<0);s=c.abs(s);r=r||0;s=c.floor(s*c.pow(10,r))/c.pow(10,r);return(t?-s:s)},ROUNDUP:function(s,r){var t=(s<0);s=c.abs(s);r=r||0;s=c.ceil(s*c.pow(10,r))/c.pow(10,r);return(t?-s:s)},SUM:function(){var t=0,r=f.toNumbers(arguments),s=r.length-1;if(s<0){return 0}do{t+=r[s]*1}while(s--);return t},TRUNC:function(r,s){s=s||0;r=r+"";if(s==0){return r.split(".").shift()}if(r.match(".")){if(s==1){r=r.substr(0,r.length-1)}else{if(s==-1){r=r.split(".").shift();r=r.substr(0,r.length-1)+"0"}}}return r},AVERAGE:function(r){return e.SUM(arguments)/e.COUNT(arguments)},AVG:function(r){return e.AVERAGE(r)},COUNT:function(){var t=0,r=f.toNumbers(arguments),s=r.length-1;if(s<0){return t}do{if(r[s]!==null){t++}}while(s--);return t},COUNTA:function(){var t=0,r=f.flatten(arguments),s=r.length-1;if(s<0){return t}do{if(r[s]){t++}}while(s--);return t},MAX:function(){var s=f.toNumbers(arguments),r=s[0],t=s.length-1;if(t<0){return 0}do{r=(s[t]>r?s[t]:r)}while(t--);return r},MIN:function(){var r=f.toNumbers(arguments),t=r[0],s=r.length-1;if(s<0){return 0}do{t=(r[s]<t?r[s]:t)}while(s--);return t},ASC:function(r){return r.charCodeAt(0)},CHAR:function(r){return o.fromCharCode(r)},CLEAN:function(r){var s=new q("[cG\x1BcLcJcMcIcK\x07\x1B\f\n\r\t\v]","g");return r.replace(s,"")},CODE:function(r){return e.ASC(r)},CONCATENATE:function(){var t=f.flatten(arguments),s="",r=this;jQuery.each(t,function(u){s+=t[u]});return s},DOLLAR:function(u,t,x){t=t||2;x=x||"$";var s=new l(u),w=e.FIXED(u,t,false);if(u>=0){s.html=x+w}else{s.html="("+x+w.slice(1)+")"}return s},FIXED:function(u,t,s){t=(t===undefined?2:t);var w=c.pow(10,t),r,u=c.round(u*w)/w;r=new o(u.toFixed(t));r.html=Globalize.format(u,"n"+t);if(s){r.html=r.html.replace(Globalize.culture().numberFormat[","],"")}return r},LEFT:function(r,s){s=s||1;return r.substring(0,s)},LEN:function(r){if(!r){return 0}return r.length},LOWER:function(r){return r.toLowerCase()},MID:function(s,t,r){if(!s||!t||!r){return this.jS.s.error({error:"ERROR"})}return s.substring(t-1,r+t-1)},REPLACE:function(s,v,t,u){if(!s||!v||!t||!u){return this.jS.s.error({error:"ERROR"})}var r=s.split("");r.splice(v-1,t);r.splice(v-1,0,u);return r.join("")},REPT:function(s,u){var r="";for(var t=0;t<u;t++){r+=s}return r},RIGHT:function(r,s){s=s||1;return r.substring(r.length-s,r.length)},SEARCH:function(t,r,u){u=u||0;if(u){r=r.split("");r.splice(0,u-1);r=r.join("")}var s=r.search(t);if(s<0){return this.jS.s.error({error:"#VALUE!"})}return u+(u?0:1)+s},SUBSTITUTE:function(u,r,t,v){v=v||0;r=new q(r,"g");var s=1;u=u.replace(r,function(x,z,A,y){var w=x;if(v){if(s>=v){w=t}}else{w=t}s++;return w});return u},TEXT:function(){return this.jS.s.error({error:"Not Yet Implemented"})},UPPER:function(r){return r.toUpperCase()},VALUE:function(r){if(jQuery.isNumeric(r)){return r*=1}else{return this.jS.s.error({error:"#VALUE!"})}},NOW:function(){var r=new m();r.html=b.toString(r);return r},TODAY:function(){var s=new m(),r=new l(b.toCentury(s)-1);r.html=b.toString(s,"d");return r},WEEKENDING:function(s){var r=new m();r=new m(r.getFullYear(),r.getMonth(),r.getDate()+5-r.getDay()-((s||0)*7));r.html=b.toString(r,"d");return r},WEEKDAY:function(s,t){s=b.get(s);var r=s.getDay();t=(t?t:1);switch(t){case 3:switch(r){case 0:return 7;case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 5:return 5;case 6:return 6}break;case 2:switch(r){case 0:return 6;case 1:return 0;case 2:return 1;case 3:return 2;case 4:return 3;case 5:return 4;case 6:return 5}break;case 1:r++;break}return r},WEEKNUM:function(r){r=b.get(r);return b.week(r)+1},YEAR:function(r){r=b.get(r);return r.getFullYear()},DAYSFROM:function(s,t,r){return c.floor((new m()-new m(s,(t-1),r))/b.dayDiv)},DAYS:function(v,t){var s=b.get(v),r=b.get(t),u=1000*60*60*24;return c.round(c.abs(s.getTime()-r.getTime())/u)},DAY:function(r){r=b.get(r);return r.getDate()},DAYS360:function(w,t,y){w=b.get(w);t=b.get(t);var r=w.getDate(),v=t.getDate(),u=b.isLastDayOfMonth(w),x=b.isLastDayOfMonth(t),s=b.diffMonths(w,t);if(y){r=c.min(r,30);v=c.min(v,30)}else{if(u){r=30}if(x){if(r<30){s++;v=1}else{v=30}}}return(s*30)+(v-r)},DATE:function(u,v,s){var t=new m(u,v-1,s),r=new l(b.toCentury(t));r.html=b.toString(t,"d");return r},DATEVALUE:function(s){s=b.get(s);var r=new l(b.toCentury(s));r.html=b.toString(s,"d");return r},EDATE:function(t,s){t=b.get(t);t.setMonth(t.getMonth()+s);var r=new l(b.toCentury(t));r.html=b.toString(t,"d");return r},EOMONTH:function(t,s){t=b.get(t);t.setMonth(t.getMonth()+s+1);t=new m(t.getFullYear(),t.getMonth(),0);var r=new l(b.toCentury(t));r.html=b.toString(t,"d");return r},HOUR:function(r){r=a.fromMath(r);return r.hour},MINUTE:function(r){return a.fromMath(r).minute},MONTH:function(r){r=b.get(r);return r.getMonth()+1},SECOND:function(r){return a.fromMath(r).second},TIME:function(r,w,s){s=(s?s:0);w=(w?w:0);r=(r?r:0);if(s&&s>60){var t=(((s/60)+"").split(".")[0])*1;s=s-(t*60);w+=t}if(w&&w>60){var v=(((w/60)+"").split(".")[0])*1;w=w-(v*60);r+=v}var u=(r*60*60*1000)+(w*60*1000)+(s*1000);return u/b.dayDiv},TIMEVALUE:function(r){if(!isNaN(r)){return r}if(/([0]?[1-9]|1[0-2])[:][0-5][0-9]([:][0-5][0-9])?[ ]?(AM|am|aM|Am|PM|pm|pM|Pm)/.test(r)){return a.fromString(r,true)}else{if(/([0]?[0-9]|1[0-9]|2[0-3])[:][0-5][0-9]([:][0-5][0-9])?/.test(r)){return a.fromString(r)}}return 0},WORKDAY:function(s,v,u){var w={1:true,2:true,3:true,4:true,5:true},s=b.get(s),v=(v&&!isNaN(v)?v:0),x=0,t=0,r=s,z;if(u){if(!jQuery.isArray(u)){u=[u]}u=f.flatten(u);var y={};jQuery.each(u,function(A){if(u[A]){y[b.toString(b.get(u[A]),"d")]=true}});u=y}else{u={}}while(t<v){r=new m(r.setDate(r.getDate()+1));if(w[r.getDay()]){if(!u[b.toString(r,"d")]){t++}}x++}z=new l(b.toCentury(r));z.html=b.toString(r,"d");return z},YEARFRAC:function(r,v,u){r=b.get(r);v=b.get(v);if(!r||!v){return this.jS.s.error({error:"#VALUE!"})}u=(u?u:0);this.html=[];var t=b.diff(r,v,u),s=b.calcAnnualBasis(r,v,u);return t/s},AND:function(){var s=arguments,t,r=this;i.each(s,function(u){if(s[u].valueOf()!==true&&t==undefined){t=e.FALSE()}});if(!t){t=e.TRUE()}return t},FALSE:function(){var r=new g(false);r.html="FALSE";return r},IF:function(t,s,r){if(t.valueOf()){return s}else{return r}},NOT:function(s){var r;if(!s.valueOf()){r=new g(true);r.html="TRUE"}else{r=new g(false);r.html="FALSE"}return r},OR:function(){var t=arguments,r,u=t.length-1,s;if(u>-1){do{s=t[u].valueOf();if(s){r=new g(true);r.html="TRUE";return r}}while(u--)}r=new g(false);r.html="FALSE";return r},TRUE:function(){var r=new g(true);r.html="TRUE";return r},GREATER:function(t,s){var r;if(t>s){r=new g(true);r.html="TRUE"}else{r=new g(false);r.html="FALSE"}return r},LESS:function(t,s){var r;if(t<s){r=new g(true);r.html="TRUE"}else{r=new g(false);r.html="FALSE"}return r},EQUAL:function(t,s){var r;if(t.valueOf()==s.valueOf()){r=new g(true);r.html="TRUE"}else{r=new g(false);r.html="FALSE"}return r},GREATER_EQUAL:function(t,s){var r;if(t>=s){r=new g(true);r.html="TRUE"}else{r=new g(false);r.html="FALSE"}return r},LESS_EQUAL:function(t,s){var r;if(t<=s){r=new g(true);r.html="TRUE"}else{r=new g(false);r.html="FALSE"}return r},IMG:function(s){var r=new o("");r.html=i(n.createElement("img")).attr("src",s);return r},TRIM:function(r){if(typeof(r)=="string"){r=i.trim(r)}return r},HYPERLINK:function(t,s){s=s||"LINK";var r=new o(s);r.html=i(n.createElement("a")).attr("href",t).attr("target","_new").text(s);return r},DROPDOWN:function(){var B=this,x=this.jS,A,w=this.td.children().detach(),y,t=i(B.td),z,s,C;if(!w.length||B.needsUpdated){A=f.flatten(arguments);A=f.unique(A);y=x.getTdLocation(B.td);s="dropdown"+this.sheet+"_"+y.row+"_"+y.col+"_"+x.I;z=n.createElement("select");z.setAttribute("name",s);z.setAttribute("id",s);z.className="jSDropdown";z.cell=this;z.onmouseup=function(){x.cellEdit(t)};z.onchange=function(){B.value=this.value;x.calcDependencies.call(B,B.calcDependenciesLast)};x.controls.inputs[x.i]=x.obj.inputs().add(z);for(var u=0;u<(A.length<=50?A.length:50);u++){if(A[u]){var r=n.createElement("option");r.setAttribute("value",A[u]);r.text=r.innerText=A[u];z.appendChild(r)}}if(!x.s.editable){z.setAttribute("disabled",true)}else{x.s.parent.bind("sheetKill",function(){t.text(B.value=z.value)})}z.value=B.value||A[0];z.onchange()}if(typeof B.value!="object"){C=new o(B.value)}C.html=z;return C},RADIO:function(){var E=this,y=this.jS,D,x=this.td.children().detach(),A,t,z,r,u,s,F;if(!x.length||E.needsUpdated){D=f.flatten(arguments);D=f.unique(D);A=y.getTdLocation(E.td);t=i(E.td);z=[];s="radio"+this.sheet+"_"+A.row+"_"+A.col+"_"+y.I;u=n.createElement("span");u.className="jSRadio";u.onmousedown=function(){y.cellEdit(t)};u.jSCell=E;y.controls.inputs[y.i]=y.obj.inputs().add(u);for(var w=0;w<(D.length<=25?D.length:25);w++){if(D[w]){var C=n.createElement("input"),B=n.createElement("span");C.setAttribute("type","radio");C.setAttribute("name",s);C.className=s;C.value=D[w];C.onchange=function(){E.value=jQuery(this).val();y.calcDependencies.call(E,E.calcDependenciesLast)};z.push(C);if(D[w]==E.value){C.setAttribute("checked","true");C.onchange()}B.textContent=B.innerText=D[w];u.appendChild(C);u.input=C;B.onclick=function(){i(this).prev().click()};u.appendChild(B);u.appendChild(n.createElement("br"))}}r=i(z);if(!y.s.editable){E.value=r.filter(":checked").val();r.attr("disabled",true)}else{y.s.parent.bind("sheetKill",function(){E.value=r.filter(":checked").val();t.text(E.value)})}}if(typeof E.value!="object"){F=new o(E.value)}F.html=u;return F},CHECKBOX:function(z){if(i.isArray(z)){z=z[0]}var A=this,u=this.jS,t=this.td.children().detach(),x,w,s,y,r,B;if((!t.length||A.needsUpdated)){x=u.getTdLocation(A.td);w=i([]);s=i(A.td);r="checkbox"+this.sheet+"_"+x.row+"_"+x.col+"_"+u.I;w=n.createElement("input");w.setAttribute("type","checkbox");w.setAttribute("name",r);w.className=r;w.value=z;w.onchange=function(){if(i(this).is(":checked")){A.value=z}else{A.value=""}u.calcDependencies.call(A,A.calcDependenciesLast)};if(!u.s.editable){w.setAttribute("disabled","true")}else{u.s.parent.bind("sheetKill",function(){A.value=(A.value=="true"||i(w).is(":checked")?z:"");s.text(A.value)})}t=n.createElement("span");t.className="SCheckbox";t.appendChild(w);y=n.createElement("span");y.textContent=y.innerText=z;t.appendChild(y);t.appendChild(n.createElement("br"));t.onmousedown=function(){u.cellEdit(s)};t.cell=A;u.controls.inputs[u.i]=u.obj.inputs().add(t);if(z==A.value){w.setAttribute("checked",true);w.onchange()}}B=new o(A.value=="true"||i(w).is(":checked")?z:"");B.html=t;return B},BARCHART:function(s,t,u){var r=new o("");r.html=d.chart.call(this,{type:"bar",data:s,legend:t,title:u});return r},HBARCHART:function(s,t,u){var r=new o("");r.html=d.chart.call(this,{type:"hbar",data:s,legend:t,title:u});return r},LINECHART:function(t,s){var r=new o("");r.html=d.chart.call(this,{type:"line",x:{data:t},y:{data:s},title:""});return r},PIECHART:function(s,t,u){var r=new o("");r.html=d.chart.call(this,{type:"pie",data:s,legend:t,title:u});return r},DOTCHART:function(x,v,s,u,t,w){var r=new o("");r.html=d.chart.call(this,{type:"dot",data:(s?s:x),x:{data:x,legend:u},y:{data:(v?v:x),legend:(t?t:u)},title:w});return r},CELLREF:function(r){return(this.jS.spreadsheets[r]?this.jS.spreadsheets[r]:"Cell Reference Not Found")},CALCTIME:function(u,s){u=u||"";s=s||"";var r=this,t=this.jS;this.jS.s.parent.one("sheetCalculation",function(){t.time.last=t.calcLast;r.td.text(u+t.time.diff()+s)});return""},HLOOKUP:function(y,w,v,s){var x=this.jS,u=this.jS.cellLookup.call(this),r={html:"#N/A",value:""};v=v||1;s=s!==undefined?s:true;if(isNaN(y)){var t=w[0].indexOf(y);if(t>-1){r=x.updateCellValue(u[t].sheet,v,x.getTdLocation(u[t].td).col)}}else{f.getClosestNum(y,w[0],function(B,A){var z=x.updateCellValue(u[A].sheet,v,x.getTdLocation(u[A].td).col);if(s){r=z}else{if(z==y){r=z}}})}return r},VLOOKUP:function(y,w,v,s){var x=this.jS,u=this.jS.cellLookup.call(this),r={html:"#N/A",value:""};s=s!==undefined?s:true;if(isNaN(y)){var t=w[0].indexOf(y);if(t>-1){r=x.updateCellValue(u[t].sheet,v,x.getTdLocation(u[t].td).col)}}else{f.getClosestNum(y,w[0],function(B,A){var z=x.updateCellValue(u[A].sheet,x.getTdLocation(u[A].td).row,v);if(s){r=z}else{if(z==y){r=z}}})}return r},THISROWCELL:function(r){var s=this.jS,t=s.getTdLocation(this.td);if(isNaN(r)){r=d.columnLabelIndex(r)}return s.updateCellValue(this.sheet,t.row,r)},THISCOLCELL:function(t){var r=this.jS,s=r.getTdLocation(this.td);return r.updateCellValue(this.sheet,t,s.col)}};var p={BACKSPACE:8,CAPS_LOCK:20,COMMA:188,CONTROL:17,ALT:18,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,C:67,F:70,V:86,X:88,Y:89,Z:90};var f=k.arrHelpers={math:c,toNumbers:function(r){r=this.flatten(r);var s=r.length-1;if(s<0){return[]}do{if(r[s]){r[s]=i.trim(r[s]);if(isNaN(r[s])){r[s]=0}else{r[s]=r[s]*1}}else{r[s]=0}}while(s--);return r},unique:function(r){var t=[],s=r.length;for(var v=0;v<s;v++){for(var u=v+1;u<s;u++){if(r[v]===r[u]){u=++v}}t.push(r[v])}return t},flatten:function(r){var v=[];for(var t=0,s=r.length;t<s;t++){var u=Object.prototype.toString.call(r[t]).split(" ").pop().split("]").shift().toLowerCase();if(u){v=v.concat(/^(array|collection|arguments|object)$/.test(u)?this.flatten(r[t]):r[t])}}return v},insertAt:function(r,t,s){i(t).each(function(){if(s>-1&&s<=r.length){r.splice(s,0,this)}});return r},closest:function(v,s,t,r){v=v||[];s=s||0;t=t||0;r=r||v.length-1;var u;while(true){u=((t+r)>>1);if(u===r||u===t){return v[u]}if(v[u]>s){r=u}else{if(v[u]<s){t=u}else{return v[u]}}}},getClosestNum:function(t,r,v){var u=0,s,y,x,w;if(r.length){y=r[0];s=u;for(u;u<r.length;u++){x=c.abs(t-y);w=c.abs(t-r[u]);if(w<x){s=u;y=r[u]}x=null;w=null}if(v){return v(y,s)}return y}return false}};var b={dayDiv:86400000,math:c,toCentury:function(r,s){s=s||86400000;return this.math.round(this.math.abs((new m(1900,0,-1))-r)/s)},get:function(s,t){t=t||86400000;if(s.getMonth){return s}else{if(isNaN(s)){return new m(Globalize.parseDate(s))}else{s*=t;var r=(new m(1900,0,-1))*1;s+=r;s=new m(s);return s}}},week:function(r,t){t=t||86400000;var s=new m(r.getFullYear(),0,1);return this.math.ceil((((r-s)/t)+s.getDay()+1)/7)},toString:function(r,s){if(!s){return Globalize.format(r)}return Globalize.format(r,Globalize.culture().calendar.patterns[s])},diff:function(v,s,u,t){t=t||86400000;switch(u){case 0:return this.days360Nasd(v,s,0,true);case 1:case 2:case 3:var r=this.math.abs(s-v)/t;return r;case 4:return this.days360Euro(v,s)}return 0},diffMonths:function(t,s){var r;r=(s.getFullYear()-t.getFullYear())*12;r-=t.getMonth()+1;r+=s.getMonth()+1;return r},days360:function(t,w,u,s,r,v){return((w-t)*360)+((s-u)*30)+(v-r)},days360Nasd:function(s,v,r,t){var u=s.getDate(),z=s.getMonth(),y=s.getFullYear(),x=v.getDate(),w=v.getMonth(),A=v.getFullYear();if((w==2&&this.isEndOfMonth(x,w,A))&&((z==2&&this.isEndOfMonth(u,z,y))||r==3)){x=30}if(x==31&&(u>=30||r==3)){x=30}if(u==31){u=30}if(t&&z==2&&this.isEndOfMonth(u,z,y)){u=30}return this.days360(y,A,z,w,u,x)},days360Euro:function(y,t){var r=y.getDate(),v=y.getMonth(),u=y.getFullYear(),w=t.getDate(),s=t.getMonth(),x=t.getFullYear();if(r==31){r=30}if(w==31){w=30}return this.days360(u,x,v,s,r,w)},isEndOfMonth:function(r,t,s){return r==(new m(s,t+1,0,23,59,59)).getDate()},isLeapYear:function(r){return new m(r,1,29).getMonth()==1},calcAnnualBasis:function(r,t,x){switch(x){case 0:case 2:case 4:return 360;case 3:return 365;case 1:var s=r.getDate(),z=r.getMonth(),w=r.getFullYear(),u=t.getDate(),v=t.getMonth(),A=t.getFullYear(),B=0;if(w==A){if(this.isLeapYear(w)){B=366}else{B=365}}else{if(((A-1)==w)&&((z>v)||((z==v)&&s>=u))){if(this.isLeapYear(w)){if(z<2||(z==2&&s<=29)){B=366}else{B=365}}else{if(this.isLeapYear(A)){if(v>2||(v==2&&u==29)){B=366}else{B=365}}else{B=365}}}else{for(var y=w;y<=A;y++){if(this.isLeapYear(y)){B+=366}else{B+=365}}B=B/(A-w+1)}}return B}return 0},lastDayOfMonth:function(r){r.setDate(0);return r.getDate()},isLastDayOfMonth:function(r){return(r.getDate()==this.lastDayOfMonth(r))}};var a=k.times={math:c,fromMath:function(t){var r={},s=this;r.hour=((t*24)+"").split(".")[0]*1;r.minute=function(u){u=s.math.round(u*24*100)/100;u=(u+"").split(".");var v=0;if(u[1]){if(u[1].length<2){u[1]+="0"}v=u[1]*0.6}return s.math.round(v)}(t);r.second=function(x){x=s.math.round(x*24*10000)/10000;x=(x+"").split(".");var v=0;if(x[1]){for(var w=0;w<4;w++){if(!x[1].charAt(w)){x[1]+="0"}}var u=((x[1]*0.006)+"").split(".");if(u[1]){if(u[1]&&u[1].length>2){u[1]=u[1].substr(0,2)}return s.math.round(u[1]*0.6)}}return v}(t);return r},fromString:function(t,x){var u=new m(),y=t,r,w,v,s,z;if(x){z=y.substr(-2).toLowerCase();y=y.replace(/(am|pm)/i,"")}y=y.split(":");w=y[0]*1;v=y[1]*1;s=(y[2]?y[2]:0)*1;if(x&&z=="pm"){w+=12}return e.TIME(w,v,s)}};i.extend(c,{log10:function(r){return c.log(r)/2.302585092994046},signum:function(r){return(r/c.abs(r))||r},log1p:function(r){var s=0,u=50;if(r<=-1){return"-INF"}if(r<0||r>1){return c.log(1+r)}for(var t=1;t<u;t++){if((t%2)===0){s-=c.pow(r,t)/t}else{s+=c.pow(r,t)/t}}return s}});i.print=function(t){var r=win.open();r.document.write("<html><body><xmp>"+t+"\n</xmp></body></html>");r.document.close()};if(!Object.getPrototypeOf){Object.getPrototypeOf=function(r){return r||{}}}if(!Array.prototype.indexOf){i.sheet.max=60;Array.prototype.indexOf=function(t,u){for(var s=(u||0),r=this.length;s<r;s++){if(this[s]===t){return s}}return -1}}return h})(jQuery,document,window,Date,String,Number,Boolean,Math,RegExp,Error);