forked from Spreadsheets/WickedGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wickedgrid.min.js
6 lines (6 loc) · 184 KB
/
wickedgrid.min.js
1
2
3
4
5
6
var WickedGrid=function(){"use strict";function e(){}function t(n){this.settings=n,this.element=n.element,this.$element=$(n.element),this.tsv=new TSV,this.cellEvents=new t.event.Cell(this),this.documentEvents=new t.event.Document(this),this.formulaEvents=new t.event.Formula(this),this.cl=t.cl,this.msg=t.msg,this.undo=new t.Undo(this),this.controls={autoFiller:[],bar:{helper:[],corner:[],x:{controls:[],handleFreeze:[],menu:[],menuParent:[],parent:[],th:[],ths:function(){for(var e=[],t=0,n=this.th[wickedGrid.i],i=n.length;t<i;t++)e.push(n[t]);return e}},y:{controls:[],handleFreeze:[],menu:[],parent:[],th:[],ths:function(){for(var e=[],t=0,n=this.th[wickedGrid.i],i=n.length;t<i;t++)e.push(n[t]);return e}}},barMenuLeft:[],barMenuTop:[],barLeft:[],barTop:[],barTopParent:[],chart:[],menu:[],cellsEdited:[],enclosures:[],formula:null,header:null,inPlaceEdit:[],inputs:[],label:null,headerMenu:[],menus:[],pane:[],panes:null,scrolls:null,sheetAdder:null,tab:[],tabContainer:null,tabs:null,title:null,toggleHide:{x:[],y:[]},ui:null},this.i=0,this.sheetCount=0,this.spreadsheets=[];var l=this,s=this.element,o=this.$element,a=[],h=$(window),c=void 0;t.defaults.useStack&&window.thaw!==c?window.thaw:function(e,t){t=t||{};var n,i=0,r=e.length,l=t.each||function(){},s=t.done||function(){};if(e[0].call!==c)for(;i<r;i++)(n=e[i])();else{for(;i<r;i++)n=e[i],l.apply(n);s()}};for(this.setBusy(!0),window.scrollBarSize===c&&(window.scrollBarSize=r()),this.cellHandler=new t.CellHandler(this,t.functions),this.theme=new t.Theme(n.theme),this.highlighter=new t.Highlighter(this.theme.tdHighlighted,this.theme.barHighlight,this.theme.tabActive,function(){});null!==s.firstChild;)a.push(s.removeChild(s.firstChild));s.className+=" "+t.cl.element,o.bind("sheetSwitch",function(e,t,n){l.switchSheet(n)}).bind("sheetRename",function(e,t,n){l.renameSheet(n)}),this.width=n.width||s.clientWidth,this.height=n.height||s.clientHeight,$.nearest||($.nearest=e),this.resizableCells=this.resizableSheet=this.resizable,$.ui?(n.resizableCells||(this.resizableCells=e),n.resizableSheet||(this.resizableSheet=e)):this.resizable=this.resizableCells=this.resizableSheet=this.draggable=e,$.support.boxModel||(n.boxModelCorrection=0),h.resize(function(){l.isBusy()||(l.width=s.clientWidth,l.height=parent.clientHeight,l.sheetSyncSize())}).unload(function(){t.thread.kill()}),t.fn=i({},t.functions,n.formulaFunctions),t.plugin.finance&&(t.fn=i({},t.functions,t.plugin.finance)),n.title=n.title||s.getAttribute("title")||"",this.parseFormula=n.useMultiThreads?this.parseFormulaAsync:this.parseFormulaSync,s.className+=" "+this.theme.parent,null===n.loader&&(n.loader=new t.loader.HTML(a)),this.loader=n.loader.bindWickedGrid(this).bindHandler(this.cellHandler),this.cellContextMenu=null,this.columnMenu=null,this.columnContextMenu=null,this.rowContextMenu=null,this.setupMenus(),this.openSheet().setBusy(!1)}function i(e){for(var t,n,i=1;i<arguments.length;i++){n=arguments[i];for(t in n)n.hasOwnProperty(t)&&!e.hasOwnProperty(t)&&(e[t]=n[t])}return e}function r(){var e=(document,$(document.createElement("p")).css({width:"100%",height:"100%"})),t=$(document.createElement("div")).css({position:"absolute",width:"100px",height:"100px",top:"0",left:"0",visibility:"hidden",overflow:"hidden"}).append(e);$(document.body).append(t);var n=e.width(),i=e.height();t.css("overflow","scroll");var r=e.width(),l=e.height();n==r&&t[0].clientWidth&&(r=t[0].clientWidth),i==l&&t[0].clientHeight&&(l=t[0].clientHeight),t.detach();var s=n-r,o=i-l;return{width:s||15,height:o||15}}function l(e){var t=null,n=l.parser||(l.parser=document.createElement("span"));for(n.innerHTML=e;null!==n.lastChild;)t=n.removeChild(n.lastChild);return t}function s(e){e.onselectstart=function(){return!1},e.unselectable="on",e.style["-moz-user-select"]="none"}var o=void 0;t.prototype={cl:t.cl,msg:t.msg,setupMenus:function(){var e=this.settings;return this.cellContextMenu=new t.CellContextMenu(this,t.menu(this,e.cellContextMenuButtons)),this.columnMenu=new t.ColumnMenu(this,t.menu(this,e.columnMenuButtons)),this.columnContextMenu=new t.ColumnContextMenu(this,t.menu(this,e.columnContextMenuButtons)),this.rowContextMenu=new t.RowContextMenu(this,t.menu(this,e.rowContextMenuButtons)),this},autoFiller:function(){return this.controls.autoFiller[this.i]||null},corner:function(){return this.controls.bar.corner[this.i]||$([])},barHelper:function(){return this.controls.bar.helper[this.i]||(this.controls.bar.helper[this.i]=$([]))},barLeft:function(e){return this.controls.bar.y.th[this.i]&&this.controls.bar.y.th[this.i][e]?this.controls.bar.y.th[this.i][e]:[]},barLeftControls:function(){return this.controls.bar.y.controls[this.i]||$([])},barLefts:function(){return this.controls.bar.y.ths()},barHandleFreezeLeft:function(){return this.controls.bar.y.handleFreeze[this.i]||$([])},barMenuLeft:function(){return this.controls.bar.y.menu[this.i]||$([])},barTop:function(e){return this.controls.bar.x.th[this.i]&&this.controls.bar.x.th[this.i][e]?this.controls.bar.x.th[this.i][e]:[]},barTopControls:function(){return this.controls.bar.x.controls[this.i]||$([])},barTops:function(){return this.controls.bar.x.ths()},barTopParent:function(){return this.controls.bar.x.parent[this.i]||$([])},barHandleFreezeTop:function(){return this.controls.bar.x.handleFreeze[this.i]||$([])},barMenuParentTop:function(){return this.controls.bar.x.menuParent[this.i]||$([])},barMenuTop:function(){return this.controls.bar.x.menu[this.i]||$([])},tdActive:function(){return null!==this.cellLast?this.cellLast.td:null},cellActive:function(){return this.cellLast},menu:function(){return this.controls.menu[this.i]||$([])},cellsEdited:function(){return this.controls.cellsEdited!==o?this.controls.cellsEdited:this.controls.cellsEdited=[]},chart:function(){return this.controls.chart[this.i]||$([])},enclosure:function(){return this.controls.enclosures[this.i]||[]},enclosures:function(){return this.controls.enclosures||[]},formula:function(){return this.controls.formula||$([])},header:function(){return this.controls.header||$([])},highlighted:function(){return this.highlighter.last||$([])},inPlaceEdit:function(){return this.controls.inPlaceEdit[this.i]||$([])},inputs:function(){return this.controls.inputs[this.i]||$([])},label:function(){return this.controls.label||$([])},menus:function(){return this.controls.menus[this.i]||$([])},headerMenu:function(){return this.controls.headerMenu[this.i]||$([])},pane:function(){return this.controls.pane[this.i]||{}},panes:function(){return this.controls.panes||$([])},element:function(){return this.settings.element},scrolls:function(){return this.controls.scrolls||$([])},sheetAdder:function(){return this.controls.sheetAdder||$([])},tab:function(){return this.controls.tab[this.i]||$([])},tabs:function(){return this.controls.tabs||$([])},tabContainer:function(){return this.controls.tabContainer||$([])},title:function(){return this.controls.title||$([])},kill:function(){var n=t.instances.indexOf(this),i=this.element,r=$(i);return!(n<0)&&($(document).unbind("keydown"),this.fullScreen.kill(),(this.inPlaceEdit().destroy||e)(),r.trigger("sheetKill").removeClass(this.theme.element).html(""),this.menus().remove(),t.events.forEach(r.unbind),t.instances.splice(n,1),!0)},trigger:function(e,t){return t=t||[],this.$element.triggerHandler(e,[this].concat(t)),this},getCell:function(e,t,n){var i,r,l;if((i=this.spreadsheets[e])!==o&&(r=i[t])!==o&&(l=r[n])!==o||(l=this.loader.jitCell(e,t,n)),l===o||null===l)return null;if("WickedGrid.Cell"!==l.typeName)throw new Error("Wrong Constructor");return l.sheetIndex=e,l.rowIndex=t,l.columnIndex=n,l},cellFromTd:function(e){if(e.thisCell!==o&&null!==e._cell)return e._cell;for(var n,i,r,l=this.locationFromTd(e),s=this.spreadsheets[this.i],a=s.length,h=l.row,c=l.col;a<=h&&s[a]===o;)s[a++]=[];for(n=s[l.row],i=n.length,c=l.col;i<c&&n[i]===o;)n[i++]=null;return r=n[i]=new t.Cell(this.i,e,this),r.columnIndex=l.col,r.rowIndex=l.row,r},getCellById:function(e,t,n){var i,r=this.loader;return"function"==typeof t?(i=-1,n=t):(i=t,"string"==typeof i&&(i=r.getSpreadsheetIndexByTitle(i))),this.isBusy()?this.whenNotBusy(function(){r.jitCellById(e,i,n)}):r.jitCellById(e,i,n),this},getCells:function(e,t,n){var i,r,l,s,o=0,a=e.length,h=[],c=0;return"function"==typeof t?(s=-1,n=t):(s=t,"string"==typeof s&&(s=loader.getSpreadsheetIndexByTitle(s))),this.whenNotBusy(function(){for(;o<a;o++)i=e[o],"string"==typeof i?!function(e){this.getCellById(i,s,function(t){h[e]=t,c++,c===a&&n.apply(this,h)})}(o):(r=i,l=this.getCell(r.sheet,r.rowIndex,r.columnIndex),null!==l&&(h[o]=l,c++,c===a&&n.apply(jS,h)))}),this},updateCells:function(e,t,n){var i;return"function"==typeof t?(i=-1,n=t):(i=t,"string"==typeof i&&(i=loader.getSpreadsheetIndexByTitle(i))),this.getCells(e,i,function(){for(var e=arguments,t=e.length,i=t-1,r=[],l=0;l<t;l++)!function(t){e[t].updateValue(function(e){i--,r[t]=e,i<0&&n.apply(jS,r)})}(l)}),this},nav:!1,setNav:function(e){for(var n=t.instances,i=0;i<n.length;i++)(n[i]||{}).nav=!1;this.nav=e},addRowMulti:function(e,t,n){function i(t){var i=0;if(t>0){for(;i<t;i++)r.addRow(e,n,!0);r.trigger("sheetAddRow",[e,n,t])}}var r=this;t?i(t):this.settings.prompt(this.msg.addRowMulti,i)},addColumnMulti:function(e,t,n){function i(t){var i=0;if(t>0){for(;i<t;i++)r.addColumn(e,n,!0);r.trigger("sheetAddColumn",[e,n,t])}}var r=this;t?i(t):this.settings.prompt(this.msg.addColumnMulti,i)},addRow:function(e,n,i){var r=this.loader,l=0,s=r.size(this.i),o=s.cols,a=this.spreadsheets[this.i],h=[],c=this.i,u=this.pane();for(void 0===n&&(n=s.rows-1),e&&n++;l<o;l++)h.push(new t.Cell(c,null,this));0===l&&h.push(new t.Cell(c,null,this)),a.splice(n,0,h),r.addRow(this.i,n,h),0===u.actionUI.visibleColumns.length&&(u.actionUI.visibleColumns[0]=0),u.actionUI.visibleRows.splice(n,0,n);for(var d=n+1;d<u.actionUI.visibleRows.length;d++)u.actionUI.visibleRows[d]+=1;u.actionUI.redrawRows(),i!==!0&&this.trigger("sheetAddRow",[n,e,1])},addColumn:function(e,n,i){var r,l,s=this.loader,o=0,a=s.size(this.i),h=a.rows,c=[],u=this.spreadsheets[this.i],d=this.i,f=this.pane();if(void 0===n&&(n=a.cols-1),e&&n++,0===h)return this.addRow(!0);for(;o<h;o++)l=new t.Cell(d,null,this),c.push(l),r=u[o],r.splice(n,0,l);s.addColumn(this.i,n,c),0===f.actionUI.visibleRows.length&&(f.actionUI.visibleColumns[0]=0),f.actionUI.visibleColumns.splice(n,0,n);for(var p=n+1;p<f.actionUI.visibleColumns.length;p++)f.actionUI.visibleColumns[p]+=1;f.actionUI.redrawColumns(),i!==!0&&this.trigger("sheetAddColumn",[n,e,1])},autoFillerNotGroup:!0,updateCellsAfterPasteToFormula:function(e){var t=0,n=this.formula(),i=this.cellLast;e=e||n.val();var r=n.val(),l=r;if(0==i.rowIndex&&0==i.columnIndex||0===r.length)return!1;var s=this.tsv.parse(r);if(s.constructor!==Array)return n.val(s),this.fillUpOrDown(!1,s),!0;for(var o,a,h,c,u=0;u<s.length;u++)i.isEdit=!0,o=s[u],o.forEach(function(e,n){t++,(a=this.spreadsheets[this.i])&&(h=a[u+i.rowIndex])&&(c=h[n+i.columnIndex])&&c&&(this.resolveCell(c,function(){"="==(e+"").charAt(0)?(c.formula=e.substring(1),c.value=""):(c.formula="",c.value=e)}),0==u&&0==n&&(l=e))});return r!=l&&n.val(l),this.fillUpOrDown(!1,l),this.cellEditDone(!0),!0},refreshColumnLabels:function(e){e=e||0;var t=this.barMenuParentTop();if(t&&t.length){var n=t.get(0);$.isFunction(n.destroy)&&n.destroy()}var i,r=this.controls.bar.x.th[this.i];if(r)for(var l=Math.max(e,0);l<r.length;l++)l>0&&(i=r[l],i.innerHTML=i.label=this.cellHandler.columnLabelString(i.cellIndex))},refreshRowLabels:function(e,t){e=e||0;var n,i=this.controls.bar.y.th[this.i];if(i){t=t||i.length;for(var r=e;r<t;r++)r>0&&(n=i[r])!==o&&(n.innerHTML=n.label=n.parentNode.rowIndex)}},isCell:function(e){return"TD"===e.nodeName&&e.parentNode.parentNode.parentNode.parentNode===this.pane()&&e.hasOwnProperty("_cell")},isBar:function(e){return"TH"===e.tagName},readOnly:[],isSheetEditable:function(e){return e=e||this.i,1==this.settings.editable&&!this.readOnly[e]},isFormulaEditable:function(e){return!this.settings.lockFormulas||e.data("formula")===o},toggleFullScreen:function(){this.controls.fullscreen||(this.controls.fullscreen=new t.FullScreen(this)),this.controls.fullscreen.toggle()},renameSheet:function(e){return!n(e)&&(e>-1&&this.sheetTab(),!0)},switchSheet:function(e){return e==-1?this.addSheet():e!=this.i&&(this.setActiveSheet(e),this.sheetSyncSize(),null===this.loader&&this.calc(e)),!0},toggleHideRow:function(e){if(void 0===e&&(e=this.rowLast),void 0!==e){var t=this.pane().actionUI;t.hiddenRows.indexOf(e)>-1?t.showRow(e):t.hideRow(e),this.autoFillerGoToTd()}},toggleHideRowRange:function(e,t){var n=this.pane().actionUI;n.hiddenRows.indexOf(e)>-1?n.showRowRange(e,t):n.hideRowRange(e,t),this.autoFillerGoToTd()},toggleHideColumn:function(e){if(void 0===e&&(e=this.colLast),void 0!==e){var t=this.pane().actionUI;t.hiddenColumns.indexOf(e)>-1?t.showColumn(e):t.hideColumn(e),this.autoFillerGoToTd()}},toggleHideColumnRange:function(e,t){var n=this.pane().actionUI;n.hiddenColumns.indexOf(e)>-1?n.showColumnRange(e,t):n.hideColumnRange(e,t),this.autoFillerGoToTd()},rowShowAll:function(){this.pane().actionUI.rowShowAll()},columnShowAll:function(){this.pane().actionUI.columnShowAll()},hideMenus:function(){return this.columnMenu.hide(),this.columnContextMenu.hide(),this.rowContextMenu.hide(),this},merge:function(e){if(e=e||this.highlighted(),e.length){var t,n,i,r,l=[],s=e[0],o=e[e.length-1],a=this.getTdLocation(s),h=this.getTdLocation(o),c={},u={},d=0,f=0,p=e.length-1,m=(this.settings.element,this);if(a.row){if(this.setDirty(!0),this.setChanged(!0),a.row<h.row?(c.row=a.row,u.row=h.row,i=s):(c.row=h.row,u.row=a.row,i=o),i.hasAttribute("rowSpan")||i.hasAttribute("colSpan"))return!1;a.col<h.col?(c.col=a.col,u.col=h.col):(c.col=h.col,u.col=a.col),f=u.row-c.row+1,d=u.col-c.col+1,r=this.getTdLocation(i),e.forEach(function(){n=e[p],t=n._cell,(t.formula||t.value)&&l.unshift(t.formula?"("+t.formula.substring(1)+")":t.value),m.resolveCell(t,function(){n.cellIndex==r.col&&n.parentNode.rowIndex==r.row||(t.formula="",t.value="",t.defer=i._cell,n.innerHTML="",n.style.visibility="collapse")})}),i._cell.value=$.trim(l.join(" ")),i._cell.formula=$.trim(i._cell.formula?l.join(" "):""),i.setAttribute("rowSpan",f),i.setAttribute("colSpan",d),i.style.display="",i.style.visibility="",i.style.position="",i.style.height=i.clientHeight+"px",i.style.width=i.clientWidth+"px",i.style.position="absolute",this.resolveCell(i._cell),this.cellEvents.done(),this.autoFillerGoToTd(i),this.cellSetActive(i,r)}return!0}},unmerge:function(e){if(e=e||this.highlighted()){var t,n,i=this.getTdLocation(e),r=Math.max(1*e.getAttribute("rowSpan"),1)-1,l=Math.max(1*e.getAttribute("colSpan"),1)-1,s=r+i.row,o=[];if(0==r&&0==l)return!1;do{t=i.col+l;do n=this.getTd(-1,s,t),null!==n&&(n.style.display="",n.style.visibility="",n.removeAttribute("colSpan"),n.removeAttribute("rowSpan"),n._cell.defer=null,this.resolveCell(n._cell),o.push(n));while(t-- >i.col)}while(s-- >i.row);return this.cellEvents.done(),this.autoFillerGoToTd(e),this.cellSetActive(e,i),this.highlighter.set(o),!0}},fillUpOrDown:function(e,t,i){if(this.cellEvents.done(),i=i||this.highlighted(!0),i.length<1)return!1;var r=this.tdActive();if(i.length<1)return!1;var l=this.getTdLocation(i[0].td),s=this.getTdLocation(i[i.length-1].td),o=this.getTdLocation(r),a={row:0,col:0},h=t||r._cell.value,c=!1,u=i.length-1,d=function(){},f=this.settings.$element;if(t=t||r._cell.value,u>=0){if(!t.charAt||"="!=t.charAt(0)){((c=!n(h))||h.length>0)&&c&&""!=h&&(h*=1,e&&(h-=i.length-1),d=function(){h++});do f.one("sheetPreCalculation",function(){i[u].formula="",i[u].value=h+""}),this.resolveCell(i[u]),d();while(u--);return!0}if(u>=0){do e?(a.row=o.row-l.row,a.col=o.col-l.col):(a.row=o.row-s.row,a.col=o.col-s.col),h=this.reparseFormula(t,a),f.one("sheetPreCalculation",function(){i[u].formula=h,i[u].value=""}),this.resolveCell(i[u]);while(u--);return!0}}return!1},toTsv:function(e,t,n){e=e||this.highlighted(!0),e.type&&(e=[e]),n=n||function(e,n){t&&(o.one("sheetPreCalculation",function(){n.formula="",n.value=""}),u.resolveCell(n))};var i,r,l,s,o=this.settings.$element,a=[],h={},c=e.length-1,u=this;if(c>=0){i=this.getTdLocation(e[0].td),r=this.getTdLocation(e[e.length-1].td),h.row=Math.min(i.row,r.row),h.col=Math.min(i.col,r.col);do{var d=this.getTdLocation(e[c].td),f=e[c].formula?"="+e[c].formula:e[c].value;l=Math.abs(d.row-h.row),s=Math.abs(d.col-h.col),a[l]||(a[l]=[]),(f+="").match(/\n/)&&(f='"'+f+'"'),a[l][s]=f||"",n.call(e[c].td,d,e[c])}while(c-- >0);c=a.length-1;do a[c]=a[c].join("\t");while(c-- >0);return a.join("\n")}return""},offsetFormulas:function(e,t,n,i){var r=this,l=this.sheetSize(),s={first:{row:0,col:0},last:{row:l.rows,col:l.cols}},o=[];for(this.cycleCells(function(){var l=this;this.formula&&"string"==typeof this.formula&&r.isFormulaEditable(this.td)&&(this.formula=r.reparseFormula(this.formula,t,e,n,i)),o.push(function(){r.resolveCellWithoutUndo(l,!0)})},s.first,s.last);o.length;)o.pop()();r.cellEvents.done()},cellRegex:/(\$?[a-zA-Z]+|[#]REF[!])(\$?[0-9]+|[#]REF[!])/gi,reparseFormula:function(e,t,n,i,r){var l=this;return e.replace(this.cellRegex,function(e,s,o,a){if("SHEET"==s)return e;t=t||{loc:-1,row:-1};var h,c,u={row:1*o,col:l.cellHandler.columnLabelIndex(s)},d={row:o,col:s,use:!1};if(!n)return l.makeFormula(u,t);if(r){if(i?(u.col&&u.col==n.col-1&&(d.col="#REF!",d.use=!0),u.row&&u.row==n.row-1&&(d.row="#REF!",d.use=!0),u.col>=n.col&&(h=!0),u.row>=n.row&&(c=!0)):(n.col&&u.col==n.col&&(d.col="#REF!",d.use=!0),n.row&&u.row==n.row&&(d.row="#REF!",d.use=!0),n.col&&u.col>n.col&&(h=!0),n.row&&u.row>n.row&&(c=!0)),d.use)return d.col+d.row;if(h)return u.col+=t.col,l.makeFormula(u);if(c)return u.row+=t.row,l.makeFormula(u)}else{if(i?(n.col&&u.col>=n.col&&(h=!0),n.row&&u.row>=n.row&&(c=!0)):(n.col&&u.col>n.col&&(h=!0),n.row&&u.row>n.row&&(c=!0)),h)return u.col+=t.col,l.makeFormula(u);if(c)return u.row+=t.row,l.makeFormula(u)}return e})},makeFormula:function(e,t){return t=i({row:0,col:0},t),e.col+=t.col,e.row+=t.row,e.col<0&&(e.col=0),e.row<0&&(e.row=0),self.cellHandler.parseCellName(e.col,e.row)},cycleCells:function(e,t,n,i){if(i=i||this.i,t=t||{rowIndex:0,col:0},!n){var r=this.sheetSize();n={row:r.rows,col:r.cols}}var l,s,a,h,c=this.spreadsheets[i];for(s=t.col;s<n.col;s++)for(l=t.row;l<n.row;l++)(a=c[l])!==o&&(h=a[s])!==o&&(h.rowIndex=l,h.columnIndex=s,e.call(h,i,l,s))},cycleCellsAll:function(e){var t,n,i,r=this.i;for(t=0;t<=this.sheetCount;t++)this.i=t,n=this.sheetSize(),i={row:n.rows,col:n.cols},this.cycleCells(e,{row:0,col:0},i,t);this.i=r},cycleCellArea:function(e,t){var n,i,r,l,s=this.i,a={cell:[],td:[]},h=this.spreadsheets[s];for(n=t.startRowIndex;n<=t.endRowIndex;n++)if((r=h[n])!==o)for(i=t.startColumnIndex;i<=t.endColumnIndex;i++)(l=r[i])!==o&&(a.cell.push(l),a.td.push(l.td));e&&e(a)},cycleTableArea:function(e,t,n,i){var r,l,s,a,h,c,u=this.pane().tBody.children,d=[],f=t.parentNode.rowIndex,p=t.cellIndex,m=n.parentNode.rowIndex,g=n.cellIndex;for(f<m?(s=f+0,h=m+0):(s=m+0,h=f+0);s<=h&&(r=u[s])!==o;){for(p<g?(a=p+0,c=g+0):(a=g+0,c=p+0);a<=c&&(l=r.children[a])!==o;)i?d.push(l):e(l),a++;s++}i&&e(d)},resizable:function(e,t){e.data("resizable")||e.resizable(t)},busy:[],setBusy:function(e){for(e?this.busy.push(e):this.busy.pop();this.busy.length<1&&this.whenNotBusyStack.length>0;)this.whenNotBusyStack.pop().call(this);return this},isBusy:function(){return this.busy.length>0},whenNotBusyStack:[],whenNotBusy:function(e){this.isBusy()?this.whenNotBusyStack.push(e):e.call(this)},draggable:function(e,t){e.data("jSdraggable")||e.data("jSdraggable",!0).draggable(t)},labelUpdate:function(e){if(e instanceof t.Cell){var n=this.cellHandler.parseCellName(e.columnIndex,e.rowIndex);this.label().text(n)}else this.label().text(e)},cellEdit:function(e,t,n){this.autoFillerNotGroup=!0,this.cellEvents.done();var i,r=e.td;e.uneditable||(this.cellLast=e,this.trigger("sheetCellEdit",[e]),null!==this.cellLast&&r!==this.cellLast.td?this.followMe(e.td):this.autoFillerGoToTd(r),this.labelUpdate(e),i=e.formula.length>0?"="+e.formula:e.value,this.formula().val(i).blur(),this.cellSetActive(e,t,!1,null,n))},cellSetActive:function(e,i,r,l,s){var o=e.td;this.cellLast=e,this.rowLast=e.rowIndex,this.colLast=e.columnIndex,s||this.highlighter.set(e.td).setStart(e).setEnd(e),this.highlighter.setBar("left",o.parentNode.children[0]).setBar("top",o.parentNode.parentNode.children[0].children[o.cellIndex]);var a,h,c=this,u=this.settings;switch(u.cellSelectModel){case t.excelSelectModel:case t.googleDriveSelectModel:a=function(){},h=function(){};break;case t.openOfficeSelectModel:a=function(e){this.isCell(e)&&this.cellEdit(e._cell)},h=function(){}}if(i){var d=this.pane(),f=this.highlighter,p=e.rowIndex,m=e.columnIndex;d.onmousemove=function(t){t=t||window.event;var i=t.target||t.srcElement;if(c.isBusy()||!c.isCell(i))return!1;var l=c.cellFromTd(i),s=!0;r&&(s=e.columnIndex===l.columnIndex||e.rowIndex===l.rowIndex),m===l.columnIndex&&p===l.rowIndex||!s||(a(i),c.cycleTableArea(function(e){f.set(e)},o,i,!0)),c.followMe(i);var h,u=t.clientY,g=t.clientX,w=d.$enclosure.offset(),v=i.cellIndex,y=i.parentNode.rowIndex,b=!1;if(n(v)||n(y))return!1;if(u>w.top&&(b=!0,v--),g>w.left&&(b=!0,y--),b){if(v<1||y<1)return!1;h=i.parentNode.parentNode.children[v].children[y],c.followMe(h,!0)}return m=l.columnIndex,p=l.rowIndex,!0},document.onmouseup=function(){d.onmousemove=null,d.onmousemove=null,d.onmouseup=null,document.onmouseup=null,l&&l()}}},colLast:0,rowLast:0,cellLast:null,orderedGrid:function(e){var t={startRowIndex:e.startRowIndex<e.endRowIndex?e.startRowIndex:e.endRowIndex,startColumnIndex:e.startColumnIndex<e.endColumnIndex?e.startColumnIndex:e.endColumnIndex,endRowIndex:e.endRowIndex>e.startRowIndex?e.endRowIndex:e.startRowIndex,endColumnIndex:e.endColumnIndex>e.startColumnIndex?e.endColumnIndex:e.startColumnIndex};return t},cellStyleToggle:function(e,t,n){if(n=n||this.highlighted(),n.length<1)return!1;this.setDirty(!0);var i,r,l,s=n.length-1,o=this.cellsEdited();if(s>=0){l=n[0].className.match(e);do i=n[s],r=$(i),t&&r._cell.removeClass(t),l?r.removeClass(e):r.addClass(e),i._cell.edited||(i._cell.edited=!0,o.push(i._cell));while(s--);return!0}return!1},cellTypeToggle:function(e,t){if(t=t||this.highlighted(!0),!(t.length<1)){var n,i=t.length-1,r=t[i].cellType==e;if(i>=0)do n=t[i],r?n.cellType=null:n.cellType=e,n.updateValue();while(i--)}},fontReSize:function(e,t){if(t=t||this.highlighted(),t.length<1)return!1;var n=0;switch(e){case"up":n=1;break;case"down":n=-1}var i,r,l,s=t.length-1,o=this.cellsEdited();if(s>=0){do i=t[s],r=$(i),l=1*(r.css("font-size")+"").replace("px",""),r.css("font-size",(l||10)+n+"px"),i._cell.edited||(i._cell.edited=!0,o.push(i._cell));while(s--);return!0}return!1},cellHandler:null,calc:function(e,t){if(this.settings.calcOff)return!1;if(e=e===o?this.i:e,this.readOnly[e]||this.isChanged(e)===!1&&!t)return!1;var n,i=this.loader;return i.cycleCells(e,function(e,t,r){n=i.jitCell(e,t,r),n.updateValue()}),this.trigger("sheetCalculation",[{which:"spreadsheet",index:e}]),this.setChanged(!1),!0},calcAll:function(e){var t,n=0;for(t=this.settings.loader.count;n<t;n++)this.calc(n,e)},resolveCell:function(e,t){var n=!e.needsUpdated,i=this;this.undo.createCells([e],function(r){return i.trigger("sheetPreCalculation",[{which:"cell",cell:e}]).setDirty(!0).setChanged(!0),e.updateValue(function(){"function"==typeof t&&t(e),i.trigger("sheetCalculation",[{which:"cell",cell:e}]),n&&e.updateDependencies()}),r})},resolveCellWithoutUndo:function(e,t){var n=this,i=!e.needsUpdated;this.trigger("sheetPreCalculation",[{which:"cell",cell:e}]).setDirty(!0).setChanged(!0),e.updateValue(function(){"function"==typeof t&&t(e),n.trigger("sheetCalculation",[{which:"cell",cell:e}]),i&&e.updateDependencies()})},addSheet:function(){this.cellEvents.editAbandon(),this.setDirty(!0),this.loader.addSpreadsheet(null,this.sheetCount),t.sheetUI(this,this.ui,this.sheetCount),this.setActiveSheet(this.sheetCount),this.sheetCount++,this.spreadsheets.push([]),this.sheetSyncSize();var e=this.pane();e.inPlaceEdit&&e.inPlaceEdit.goToTd(),this.trigger("sheetAdd",[this.i])},insertSheet:null,deleteSheet:function(e){var t,n=e||this.i,i=this.controls.enclosure;for(i.splice(n,1),this.barHelper().remove(),$(this.enclosure()).remove(),this.menus().remove(),this.tabContainer().children().eq(this.i).remove(),this.spreadsheets.splice(n,1),this.controls.autoFiller.splice(n,1),this.controls.bar.helper.splice(n,1),this.controls.bar.corner.splice(n,1),this.controls.bar.x.controls.splice(n,1),this.controls.bar.x.handleFreeze.splice(n,1),this.controls.bar.x.controls.splice(n,1),this.controls.bar.x.menu.splice(n,1),this.controls.bar.x.menuParent&&this.controls.bar.x.menuParent[n]&&this.controls.bar.x.menuParent.splice(n,1),this.controls.bar.x.parent.splice(n,1),this.controls.bar.x.th.splice(n,1),this.controls.bar.y.controls.splice(n,1),this.controls.bar.y.handleFreeze.splice(n,1),this.controls.bar.y.controls.splice(n,1),this.controls.bar.y.menu.splice(n,1),this.controls.bar.y.menuParent&&this.controls.bar.y.menuParent[n]&&this.controls.bar.y.menuParent.splice(n,1),this.controls.bar.y.parent.splice(n,1),this.controls.bar.y.th.splice(n,1),this.controls.barMenuLeft.splice(n,1),this.controls.barMenuTop.splice(n,1),this.controls.barLeft.splice(n,1),this.controls.barTop.splice(n,1),this.controls.barTopParent.splice(n,1),this.controls.chart.splice(n,1),this.controls.tdMenu.splice(n,1),this.controls.enclosure.splice(n,1),this.controls.inPlaceEdit.splice(n,1),this.controls.menus.splice(n,1),this.controls.menu.splice(n,1),this.controls.pane.splice(n,1),this.controls.tables.splice(n,1),this.controls.table.splice(n,1),t=n+1;t<this.controls.tab.length;++t){var r=this.controls.tab[t].get(0);r.i--}this.controls.tab.splice(n,1),this.controls.toggleHide.x.splice(n,1),this.controls.toggleHide.y.splice(n,1),this.readOnly.splice(n,1),this.i=0,this.sheetCount--,this.sheetCount=Math.max(this.sheetCount,0),0==this.sheetCount&&this.addSheet(),this.setActiveSheet(this.i),this.setDirty(!0),this.setChanged(!0),this.trigger("sheetDelete",[n])},deleteRow:function(e){e=e||this.rowLast;var t,n=this.pane(),i=this.spreadsheets[this.i].splice(e,1)[0],r=0,l=i.length,s=this.settings.loader;for(rowMax=s.size(this.i).rows,this.setChanged(!0),this.offsetFormulas({row:e,col:0},{row:-1,col:0},!1,!0),s.deleteRow(this.i,e);r<l;r++)t=i[r],t.setNeedsUpdated(!1),t.updateDependencies();this.setDirty(!0),this.cellEvents.editAbandon(),n.inPlaceEdit&&n.inPlaceEdit.goToTd(),this.trigger("sheetDeleteRow",e)},deleteColumn:function(e){e=e||this.colLast;var t,n=this.pane(),i=0,r=this.spreadsheets[this.i],l=this.settings.loader,s=l.size(this.i);for(this.setChanged(!0),this.offsetFormulas({row:0,col:e},{row:-1,col:0},!1,!0),l.deleteColumn(this.i,e);i<s.rows;i++)t=r[i].splice(e,1)[0],t.setNeedsUpdated(!1),t.updateDependencies();this.setDirty(!0),this.cellEvents.editAbandon(),n.inPlaceEdit&&n.inPlaceEdit.goToTd(),n.actionUI.visibleColumns.splice(e,1);for(var o=e;o<n.actionUI.visibleColumns.length;o++)n.actionUI.visibleColumns[o]-=1;n.actionUI.redrawColumns(),this.trigger("sheetDeleteColumn",e)},sheetTab:function(e,t){var n="",i=this;return e?(n=this.loader.title(this.i)||this.msg.sheetTitleDefault.replace(/[{]index[}]/gi,this.i+1),t&&t(n),n):this.isSheetEditable()&&this.settings.editableNames?(this.settings.prompt(this.msg.newSheetTitle,function(e){e?(i.setDirty(!0),i.table().attr("title",e),i.tab().html(e),n=e):(n=i.loader.title(i.i),e=n?n:i.msg.sheetTitleDefault.replace(/[{]index[}]/gi,i.i+1)),t&&t($(document.createElement("div")).text(n).html())},i.sheetTab(!0)),null):void 0},followMe:function(e,t){if(e=e||this.tdActive(),null!==e){var n=this.pane();n.actionUI;this.setBusy(!0),this.setBusy(!1),t||this.autoFillerGoToTd(e)}},autoFillerGoToTd:function(e,t,n){if(!this.settings.autoFiller)return this;if(e===o&&null!==this.cellLast&&(e=this.cellLast.td),e&&"cell"==e.type){if(t=t||e.clientHeight,n=n||e.clientWidth,!(e.offsetHeight&&e.offsetWidth&&e.clientHeight&&e.clientWidth))return this.autoFillerHide(),this;var i=$(e).position();this.autoFillerShow(i.top+(t||e.clientHeight)-3+"px",i.left+(n||e.clientWidth)-3+"px")}return this},autoFillerHide:function(){if(!this.settings.autoFiller)return this;var e=this.autoFiller(),t=e.parentNode;return null!==t&&t.removeChild(e),this},autoFillerShow:function(e,t){if(!this.settings.autoFiller)return this;var n=this.autoFiller(),i=this.pane(),r=n.style;return r.top=e,r.left=t,i.insertBefore(n,i.firstChild),this},setActiveSheet:function(e,t){e=t!==o?t.i:e||0,null!==this.cellLast&&(this.cellLast.rowIndex>0||this.cellLast.columnIndex>0)&&(this.cellEvents.done(),this.formula().val(""));var n,i,r=this.panes(),l=0,s=r.length;for(this.autoFillerHide();l<s;l++)e!=l&&(n=r[l],n.actionUI.hide());this.i=e,i=this.enclosure(),this.highlighter.setTab(this.tab()),n=i.pane,n.actionUI.show(),n.inPlaceEdit&&n.inPlaceEdit.goToTd()},getSpreadsheetIndexByTitle:function(e){var t=this.settings.loader.getSpreadsheetIndexByTitle(e);return t},getSpreadsheetTitleByIndex:function(e){return this.settings.loader.json[e].title},openSheet:function(){var e=this,n=this.loader,i=this.element,r=this.$element,l=n.count,s=l-1,a=function(){e.setBusy(!0),e.loader=n;var a,h,c=t.header(e),u=t.ui(e),d=t.spreadsheetAdder(e),f=t.tabs(e),p={initChildren:function(n,i){t.sheetUI(e,n,i),e.trigger("sheetOpened",[i])},done:function(t){e.sheetSyncSize(),e.setActiveSheet(0),e.setDirty(!1),e.setBusy(!1),e.trigger("sheetAllOpened")},lastIndex:s};if(c.ui=u,c.tabContainer=f,u.header=c,u.sheetAdder=d,u.tabContainer=f,f.header=c,f.ui=u,i.appendChild(c),i.appendChild(u),i.appendChild(d),i.appendChild(f),e.resizableSheet(r,{minWidth:.1*i.clientWidth,minHeight:.1*i.clientHeight,start:function(){e.setBusy(!0),this.ui.removeChild(this.enclosure()),u.sheetAdder.hide(),u.tabContainer.hide()},stop:function(){this.ui.appendChild(this.enclosure()),u.sheetAdder.show(),u.tabContainer.show(),e.setBusy(!1).sheetSyncSize();var t=this.pane();t.inPlaceEdit&&t.inPlaceEdit.goToTd()}}),e.insertSheet=function(i,r,l){e.sheetCount++,i=i||null,l=l===o||l,r=r||e.sheetCount-1,null!==i&&e.settings.loader.addSpreadsheet(i);var s,a=function(){e.setBusy(!0);var n=new t.SpreadsheetUI(r,u,p);e.setActiveSheet(-1,n),e.setBusy(!1),e.sheetSyncSize()};if(l)return void a();var h=n.title(r)||e.msg.sheetTitleDefault.replace(/[{]index[}]/gi,r+1);s=t.customTab(e,h).mousedown(function(){return a(),e.tab().insertBefore(this),$(this).remove(),!1}),e.loader.isHidden(r)&&s.hide()},h=new t.SpreadsheetUI(0,u,p),e.sheetCount++,l>0){for(a=1;a<l;a++)e.insertSheet(null,a,!1);e.i=0,h.loaded()}};return this.isDirty?this.settings.confirm(t.msg.openSheet,a):a(),this},newSheet:function(){this.settings.$element.html(this.makeTable()).sheet(this.settings)},sheetSyncSize:function(){var e,n,i,r,l,s,o,a,h,c=this.settings.element,u=this.settings.$element,d=c.clientHeight,f=c.clientWidth,p=this.tabContainer(),m=p[0],g=m.style,w=window.scrollBarSize.width,v=this.ui.style;return d?d<200&&(d=200,u.height(d)):(d=400,u.height(d)),h=m.scrollLeft,g.width="",e=m.clientWidth,n=f-(this.settings.colMargin+w),i=f-2*this.settings.colMargin+"px",r=this.settings.colMargin+w+"px",e>n?(g.height=r,p.addClass(t.cl.tabContainerScrollable),d-=w):(g.height=null,p.removeClass(t.cl.tabContainerScrollable)),g.width=i,m.scrollLeft=h,d-=this.header().outerHeight()+this.settings.boxModelCorrection,d-=m.clientHeight+this.settings.boxModelCorrection,l=d-window.scrollBarSize.height-this.settings.boxModelCorrection+"px",s=f-window.scrollBarSize.width+"px",o=d+"px",a=f+"px",this.panes().each(function(){var e=this.style,t=this.scroll.style,n=this.enclosure.style;e.height=l,e.width=s,n.height=t.height=o,n.width=t.width=a}),v.height=o,v.width=a,this},showSheets:function(){var e=this.settings.loader;this.tabContainer().children().each(function(t){$(this).show(),e.setHidden(t,!1)})},showSheet:function(e){var t=this.settings.loader;this.tabContainer().children().eq(e).show(),t.setHidden(e,!1)},hideSheet:function(e){var t=this.settings.loader;this.tabContainer().children().eq(e).hide(),
t.setHidden(e,!0)},cellChangeStyle:function(e,t,n){if(n=n||this.highlighted(!0),n.length<1)return!1;this.setDirty(this);var i=n.length-1;return i>=0&&(this.undo.createCells(n,function(n){do n[i].td.css(e,t);while(i--);return n}),!0)},cellFind:function(e){function t(e){var t=$(r.tables()[r.i]).children("tbody").children("tr");if(e){var l=t.children('td:contains("'+e+'")');l.length<1&&(l=t.children('td:contains("'+e.toLowerCase()+'")')),l.length<1&&(l=t.children('td:contains("'+e.toUpperCase()+'")')),l=l.eq(0),l.length>0?r.cellEdit(l._cell):n.alert(i.cellNoFind)}}var n=this.settings,i=this.msg,r=this;e?t(e):n.prompt(i.cellFind,t)},cellSetActiveBar:function(e,n,i){var r,l,s,o,a,h,c=this,u=this.settings,d=this.loader.size(),f={},p={},m=function(e){switch(u.cellSelectModel){case t.openOfficeSelectModel:this.row=e.startRowIndex,this.col=e.startColumnIndex,this.td=c.getTd(-1,c.row,c.col),null!==this.td&&null!==c.cellLast&&this.td!==c.cellLast.td&&c.cellEdit(c.td._cell,!1,!0);break;default:this.row=e.endRowIndex,this.col=e.endColumnIndex,this.td=c.getTd(-1,this.row,this.col),null!==this.td&&null!==c.cellLast&&this.td!==c.cellLast.td&&c.cellEdit(this.td._cell,!1,!0)}},g=[],w=this.pane().actionUI.scrolledArea,v=this.highlighter;switch(e){case"column":for(f.row=w.row,p.row=w.row,n<i?(v.startColumnIndex=o=r=f.col=n,v.endColumnIndex=l=p.col=i):(s=!0,v.startColumnIndex=o=r=f.col=i,v.endColumnIndex=l=p.col=n),v.startRowIndex=0,v.endRowIndex=d.rows,g.push(this.col(n+1));o<l;o++)g.push(g[g.length-1].nextSibling);break;case"row":f.row=n,f.col=w.col,p.row=i,p.col=w.col,v.startRowIndex=n,v.startColumnIndex=0,v.endRowIndex=i,v.endColumnIndex=d.cols,a=n;do h=this.getTd(-1,a,0),null!==h&&g.push(h.parentNode);while(a-- >n);break;case"corner":f.row=0,f.col=0,p.col=d.cols,p.row=d.rows,g.push(sheet[0])}new m(v),this.highlighter.set(g)},getTdRange:function(e,t,n,i){this.cellLast.isEdit=!0;var r,l,s,o=this,a=function(e){return e.first.col>e.last.col||e.first.row>e.last.row?{first:this.cellHandler.parseCellName(e.last.col,e.last.row),last:this.cellHandler.parseCellName(e.first.col,e.first.row)}:{first:this.cellHandler.parseCellName(e.first.col,e.first.row),last:this.cellHandler.parseCellName(e.last.col,e.last.row)}},h=function(e){var i=a(e),r=t+"";r=r.match(/=/)?r:"="+r,(n||"("!=r.charAt(r.length-1))&&(r=r+(n?n:"")+"(");var l,s="";return l=i.first!=i.last?i.first+":"+i.last:i.first,"("==r.charAt(r.length-1)&&(s=")"),r+l+s},c="";return e?(r={first:this.getTdLocation([e.target])},l=this.table().mousemove(function(e){r.last=this.getTdLocation([e.target]),c=h(r),i||(o.formula().val(c),o.inPlaceEdit().val(c))}),$(document).one("mouseup",function(){return l.unbind("mousemove"),c}),""):(s=this.highlighted().not(this.tdActive()),s.length?(r={first:this.getTdLocation(s.first()),last:this.getTdLocation(s.last())},c=h(r),i||(this.formula().val(c),this.inPlaceEdit().val(c)),c):"")},getTd:function(e,t,n){e<0&&(e=this.i);var i=this.settings.loader.jitCell(e,t,n);return null===i?i:i.td||null},locationFromTd:function(e){var t=this.pane().actionUI.scrolledArea;return{row:t.row+e.parentNode.rowIndex,col:t.col+e.cellIndex}},getTdLocation:function(e){var t={col:0,row:0},n=0;this.pane();return e===o||null===e?t:e.parentNode===o||e.parentNode.rowIndex+n<0?t:{col:0===e.cellIndex?0:e.cellIndex-1,row:0===e.parentNode.rowIndex?0+n:e.parentNode.rowIndex+n-1}},changed:[],isChanged:function(e){return this.changed[e||this.i]},setChanged:function(e){this.changed[this.i]=e},isDirty:!1,setDirty:function(e){return this.dirty=e,this},appendToFormula:function(e){var t=this.formula(),n=t.val();"="!==n.charAt(0)&&(n="="+n),t.val(n+e)},cols:function(e){return e=e||this.table()[0],e&&e.colGroup&&e.colGroup.children?e.colGroup.children:[]},tables:function(e,t){e=e||this.loader.tables;var n,i,r,l,s,o,a,h,c,u=[],d=e.length-1;do{if(i=t?document.body.removeChild(e[d]):e[d].cloneNode(!0),(l=i.children[0])&&(s=l.children[0])&&l.removeChild(s),r=i.children[1]){h=r.children,a=h[0],r.removeChild(a),n=h.length-1;do c=h[n],o=c.children[0],c.removeChild(o);while(n-- >0)}u[d]=i}while(d-- >0);return u},col:function(e){return this.pane().actionUI.megaTable.col(e)},rowTds:function(e,t){e=e||this.table();var n=this.rows(e);return n.length?(t==o&&(t=n.length-1),n[t]&&n[t].children?n[t].children:[]):[]},rows:function(e){return e=e||this.table()[0],e===o?[]:e.tBody===o?[]:e.tBody.children===o?[]:e.tBody.children},highlighted:function(e){var t,n,i=this.highlighter.last||$([]),r=[];if(!((t=i)&&i.length&&(t=t[0])&&t.tagName))return e?r:$(r);switch(t.tagName){case"TD":n=i.length-1;do r.unshift(e?i[n]._cell:i[n]);while(n-- >0);break;case"TR":n=i.length-1;do i[n].tds&&(r=r.concat(e?i[n]._cells:i[n].tds));while(n-- >0);break;case"COL":i=i.filter("col"),n=i.length-1;do i[n].tds&&(r=r.concat(e?i[n]._cells:i[n].tds));while(n-- >0);break;case"TABLE":r=e?t._cells:t.tds}return e?r:$(r)},sheetSize:function(e){return void 0===e&&(e=this.i),this.settings.loader.size(e)},sortVerticalSelectAscending:function(){return confirm("Do you want to extend your selection?")?(this.sortVertical(),!0):(this.sortVerticalSingle(!1),!0)},sortVerticalSelectDescending:function(){return confirm("Do you want to extend your selection?")?(this.sortVertical(),!1):(this.sortVerticalSingle(!0),!1)},sortVertical:function(e){for(var t,n,i,r,l=this.highlighted(!0),s=l[0].td.parent().prev(),o=l.length,a=(new Date,!0),h=[],c=[],u=0;u<o;)n=l[u],r=n.td,isNaN(n.value)?(a=!1,i=new String(n.value.valueOf())):i=new Number(n.value.valueOf()),i.loc=this.getTdLocation(r),i.row=r.parentNode,i.col=r,i.cell=n,h.push(i),u++;for(e?0==a?h.sort(function(e,t){return t-e}):(h.sort(),h.reverse()):1==a?h.sort(function(e,t){return e-t}):h.sort(),this.undo.createCells(l);t=h.length;)i=h.pop(),c=this.spreadsheets[this.i].splice(i.row.rowIndex,1),n=i.cell,n.value=i.valueOf(),i.row.parentNode.removeChild(i.row),s.after(i.row),i.row.children[0].innerHTML=s[0].rowIndex+t,this.spreadsheets[this.i].splice(s[0].rowIndex+1,0,c[0]),this.track.call(n,!0);this.undo.createCells(l)},sortVerticalSingle:function(e){for(var t,n=this.highlighted(!0),i=n.length,r=0,l=[];r<i;)l.push(n[r].value),r++;for(e?l.sort(function(e,t){return t-e}):l.sort(function(e,t){return e-t});n.length;)t=n.pop(),t.value=l[n.length],t.updateValue()},sortHorizontalSelectAscending:function(){return confirm("Do you want to extend your selection?")?(this.sortHorizontal(),!0):(this.sortHorizontalSingle(!1),!0)},sortHorizontalSelectDescending:function(){return confirm("Do you want to extend your selection?")?(this.sortHorizontal(),!1):(this.sortHorizontalSingle(!0),!1)},sortHorizontal:function(e){for(var t,n,i,r,l,s=this.highlighted(!0),o=this.pane(),a=o.table,h=s[0].td,n=h._cell,c=n.cellIndex,u=a.colGroup,d=this.sheetSize().rows,f=s.length,p=!0,m=[],g=0;g<f;){for(t=0,n=s[g],l=n.td,isNaN(n.value)?(p=!1,i=new String(n.value.valueOf())):i=new Number(n.value.valueOf()),i.tds=[],i.loc=this.getTdLocation(l),i.tr=l.parentNode,i.td=l,i.cell=n;t<=d;)i.tds.push(this.pane().table.children[1].children[t].children[l.cellIndex]),t++;m.push(i),g++}for(e?0==p?m.sort(function(e,t){return t-e}):(m.sort(),m.reverse()):1==p?m.sort(function(e,t){return e-t}):m.sort(),this.undo.createCells(s);m.length;)for(i=m.pop();i.tds.length>1;)l=i.tds.pop(),r=l.parentNode,n=this.spreadsheets[this.i][r.rowIndex].splice(l.cellIndex,1),r.insertBefore(l,r.children[c]),l.col=u.children[m.length+l.cellIndex-1],l.barTop=l.col.bar,n.value=l._cell.value,this.spreadsheets[this.i][r.rowIndex].splice(l.cellIndex,0,n[0]),this.resolveCell(n);this.undo.createCells(s)},sortHorizontalSingle:function(e){for(var t,n=this.highlighted(!0),i=n.length,r=0,l=[];r<i;)l.push(n[r].value),r++;for(e?l.sort(function(e,t){return t-e}):l.sort(function(e,t){return e-t});n.length;)t=n.pop(),t.value=l[n.length],t.updateValue()},tableSize:function(e,t){var n,i,r,l,s,a=(e.pane,0),h=0,c=0;return e=e||this.table()[0],(n=e.tBody)===o||(i=n.children)===o||(r=i[i.length-1])===o||(l=r.children)===o||(s=l[l.length-1])===o?{}:(a=t===!0?r.rowIndex:r.rowIndex+c,h=s.cellIndex,{cols:h,rows:a})},toggleState:function(e){var t=this.settings;if(t.allowToggleState){var n=e||this.tables();t.editable&&(this.evt.cellEditAbandon(),this.trigger("sheetSave",[n])),this.setDirty(!1),this.setChanged(!0),t.editable=!t.editable,this.kill(),t.element.html(n).sheet(t),t=null}},setCellRef:function(e){function t(e){e&&(n.settings.formulaVariables[e]=r.updateValue())}var n=this,i=this.tdActive(),r=i._cell;e?t(e):this.settings.prompt(this.msg.setCellRef,t)},parseFormula:null,print:function(e,n){e=e||this.i;var i,r=window.open();r!==o&&(i=r.document,i.write('<html> <head id="head"></head> <body> <div id="entry" class="'+t.cl.element+'" style="overflow: show;"> </div> </body> </html>'),n!==!0&&$(i.getElementById("head")).append($("style,link").clone()),$(i.getElementById("entry")).append(this.pane().cloneNode(!0)),i.close(),r.focus(),r.print())},preLoad:function(e,t){e=e||"",t=i({skip:["globalizeCultures"],thirdPartyDirectory:"bower_components/"},t);var n=$("script:first"),r=function(){var i;void 0!==this.script&&(i=document.createElement("script"),i.src=e+(this.thirdParty?t.thirdPartyDirectory:"")+this.script,n.after(i)),void 0!==this.css&&(i=document.createElement("link"),i.rel="stylesheet",i.type="text/css",i.href=e+(this.thirdParty?t.thirdPartyDirectory:"")+this.css,n.after(i))};$.each(this.dependencies,r),$.each(this.optional,r)},makeTable:function(e,t,n){document;e=e||{rows:25,cols:10},t=t||120,n=n||15;var i,r,l,s,o=document.createElement("table"),a=document.createElement("colgroup"),h=document.createElement("tbody"),c="width:"+t+"px;",u="height:"+n+"px;";l=e.cols;do r=document.createElement("col"),r.setAttribute("style",c),a.appendChild(r);while(l-- >1);l=e.rows;do{i=document.createElement("tr"),i.setAttribute("style",u),s=e.cols;do i.appendChild(document.createElement("td"));while(s-- >1);h.appendChild(i)}while(l-- >1);return o.appendChild(a),o.appendChild(h),o},killAll:function(){var e=t.instances;if(e){for(var n=0;n<e.length;n++)e[n]&&e[n].kill&&e[n].kill();t.instances=[]}},scrollLocker:function(e){var n=t.instances;n[e].panes().each(function(e){var t;$(t=this.scrollUI).scroll(function(i){var r,l=n.length-1;if(l>-1)do r=n[l].controls.enclosures[e].scrollUI,this!==r&&(r.scrollLeft=t.scrollLeft,r.scrollTop=t.scrollTop);while(l--)})})},switchSheetLocker:function(e){t.instance.forEach(function(){this.$element.bind("sheetSwitch",function(e,n,i){t.instance.forEach(function(e){e.setActiveSheet(i)})})})},I:function(){var e=0;return this.instance?e=0===this.instance.length?0:this.instance.length-1:this.instance=[],e},formulaParser:function(){var e,n=t.calcStack;return n>-1?(e=t.spareFormulaParsers[n],void 0===e&&(e=t.spareFormulaParsers[n]=Formula())):e=t.defaultFormulaParser,e.yy.types=[],e},parseFormulaSync:function(e,n){null===t.defaultFormulaParser&&(t.defaultFormulaParser=Formula());var i=this.formulaParser();n(i.parse(e))},parseFormulaAsync:function(e,n){var i=t.thread();i.busy?i.stash.push(function(){i.busy=!0,i.parseFormula(e,function(e){i.busy=!1,n(e),i.stash.length>0&&i.stash.shift()()})}):(i.busy=!0,i.parseFormula(e,function(e){i.busy=!1,n(e),i.stash.length>0&&i.stash.shift()()}))}},t.event={},t.loader={},t.plugin={},t.calcStack=0,t.instances=[],t.defaultTheme=0,t.themeRollerTheme=0,t.bootstrapTheme=1,t.customTheme=2,t.excelSelectModel=0,t.googleDriveSelectModel=1,t.openOfficeSelectModel=2,t.defaultColumnWidth=120,t.defaultRowHeight=20,t.domRows=40,t.domColumns=35,t.formulaParserUrl="../parser/formula/formula.js",t.threadScopeUrl="../Sheet/threadScope.js",t.defaultFormulaParser=null,t.spareFormulaParsers=[],t.cornerEntity="corner",t.columnEntity="column",t.rowEntity="row",t.events=["sheetAddRow","sheetAddColumn","sheetSwitch","sheetRename","sheetTabSortStart","sheetTabSortUpdate","sheetCellEdit","sheetCellEdited","sheetCalculation","sheetAdd","sheetDelete","sheetDeleteRow","sheetDeleteColumn","sheetOpen","sheetAllOpened","sheetSave","sheetFullScreen","sheetFormulaKeydown"],t.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}",cellLoading:"Loading..."},t.dependencies={coreCss:{css:"wickedgrid.css"},jQueryUI:{script:"jquery-ui/jquery-ui.min.js",thirdParty:!0},jQueryUIThemeRoller:{css:"jquery-ui/themes/smoothness/jquery-ui.min.css",thirdParty:!0},globalize:{script:"globalize/lib/globalize.js",thirdParty:!0},nearest:{script:"jquery-nearest/src/jquery.nearest.min.js",thirdParty:!0},mousewheel:{script:"MouseWheel/MouseWheel.js",thirdParty:!0},operative:{script:"operative/dist/operative.js",thirdParty:!0},megatable:{script:"megaTable.js/megatable.js",thirdParty:!0},infiniscroll:{script:"infiniscroll.js/infinitescroll.js",thirdParty:!0}},t.optional={advancedFn:{script:"src/Plugin/advanced.js"},financeFn:{script:"src/Plugin/finance.js"},colorPicker:{css:"really-simple-color-picker/css/colorPicker.css",script:"really-simple-color-picker/js/jquery.colorPicker.min.js",thirdParty:!0},elastic:{script:"jquery-elastic/jquery.elastic.source.js",thirdParty:!0},globalizeCultures:{script:"globalize/lib/cultures/globalize.cultures.js",thirdParty:!0},raphael:{script:"raphael/raphael.js",thirdParty:!0},gRaphael:{script:"graphael/g.raphael.js",thirdParty:!0},gRaphaelBar:{script:"graphael/g.bar.js",thirdParty:!0},gRaphaelDot:{script:"graphael/g.dot.js",thirdParty:!0},gRaphaelLine:{script:"graphael/g.line.js",thirdParty:!0},gRaphaelPie:{script:"graphael/g.pie.js",thirdParty:!0},thaw:{script:"thaw.js/thaw.js",thirdParty:!0},undoManager:{script:"Javascript-Undo-Manager/lib/undomanager.js",thirdParty:!0},zeroClipboard:{script:"zeroclipboard/dist/ZeroClipboard.min.js",thirdParty:!0}},t.autoFiller=function(e,n){if(!e.settings.autoFiller)return!1;var i=document.createElement("div"),r=document.createElement("div"),l=document.createElement("div");return i.i=e.i,i.className=t.cl.autoFiller+" "+e.theme.autoFiller,r.className=t.cl.autoFillerHandle,l.className=t.cl.autoFillerCover,i.onmousedown=function(){var n=this.tdActive();if(n){var i=e.getTdLocation(n);e.cellSetActive(n,i,!0,t.autoFillerNotGroup,function(){var t=e.highlighted(),r=e.getTdLocation(t.last());e.fillUpOrDown(r.row<i.row||r.col<i.col),e.autoFillerGoToTd(n),e.autoFillerNotGroup=!1})}return!1},n.autoFiller=e.controls.autoFiller[e.i]=i,n.appendChild(i),!0},t.cl={list:function(e){var n=[],i=t.cl;return e.forEach(function(e){if(!i.hasOwnProperty(e))throw new Error("prop "+e+" not found on WickedGrid.cl");n.push(i[e])}),n.join(" ")},autoFiller:"wg-auto-filler",autoFillerHandle:"wg-auto-filler-handle",autoFillerCover:"wg-auto-filler-cover",corner:"wg-corner",barController:"wg-bar-controller",barControllerChild:"wg-bar-controller-child",barHelper:"wg-bar-helper",row:"wg-row",rowFreezeHandle:"wg-row-freeze-handle",column:"wg-column",columnHelper:"wg-column-helper",columnFocus:"wg-column-focus",columnButton:"wg-column-button",columnFreezeHandle:"wg-column-freeze-handle",chart:"wg-chart",formula:"wg-formula",formulaParent:"wg-formula-parent",header:"wg-header",fullScreen:"wg-full-screen",inPlaceEdit:"wg-in-place-edit",headerMenu:"wg-header-menu",menuFixed:"wg-menu-fixed",element:"wg-element",scroll:"wg-scroll",sheetAdder:"wg-sheet-adder",table:"wg-table",label:"wg-loc",pane:"wg-edit-pane",tab:"wg-tab",tabContainer:"wg-tab-container",tabContainerScrollable:"wg-tab-container-scrollable",menu:"wg-menu",menuButton:"wg-menu-button",title:"wg-title",enclosure:"wg-enclosure",ui:"wg-ui"},t.ColumnMenu=function(){function e(e,t){this.wickedGrid=e,this.menu=t,this.index=-1,this.column=null;var n=this,i=this.barHelper=l('<div class="'+e.cl.barHelper+" "+e.cl.columnHelper+'"> <span class="'+e.cl.columnButton+" "+e.theme.columnMenu+" "+e.theme.columnMenuIcon+'"></span> </div>'),r=i.children[0];r.onmousedown=function(){n.showMenu()}}return e.prototype={setColumn:function(e,t){return null!==this.column&&this.column.classList.remove(this.wickedGrid.cl.columnFocus),this.hideMenu(),this.column=e,this.index=t,this},kill:function(){return this.hide(),this.column=null,this.index=-1,this},show:function(){return this.wickedGrid.hideMenus(),this.column.appendChild(this.barHelper),this.column.classList.add(this.wickedGrid.cl.columnFocus),this},hide:function(){return null===this.barHelper.parentNode?this:(this.barHelper.parentNode.removeChild(this.barHelper),this)},showMenu:function(){return this.barHelper.appendChild(this.menu),this},hideMenu:function(){return null===this.menu.parentNode?this:(this.menu.parentNode.removeChild(this.menu),this)}},e}(),t.columnResizer=function(e,t){e.barTopControls().remove();var n,i=document.createElement("div"),r=$(i).addClass(e.cl.barController+" "+e.theme.barResizer).width(t.clientWidth).prependTo(t),l=e.pane();e.controls.bar.x.controls[e.i]=e.barTopControls().add(r),e.resizableCells(r,{handles:"e",start:function(t,n){e.autoFillerHide(),e.setBusy(!0),l.freezeHandleTop&&l.freezeHandleTop.remove()},resize:function(e,n){t.col.style.width=n.size.width+"px",l.inPlaceEdit&&l.inPlaceEdit.goToTd()},stop:function(t,n){e.setBusy(!1),l.inPlaceEdit&&l.inPlaceEdit.goToTd(),e.followMe(),e.setDirty(!0)},minWidth:32}),n=i.children[0],n.style.height=t.clientHeight+"px"},t.customTab=function(e,t){var n=document.createElement("span"),i=$(n).appendTo(e.tabContainer());return n.setAttribute("class",e.cl.tab+" "+e.theme.tab),n.innerHTML=t,i},t.defaults=function(){var e={editable:!0,editableNames:!0,barMenus:!0,freezableCells:!0,allowToggleState:!0,headerMenu:null,newColumnWidth:120,title:null,calcOff:!1,lockFormulas:!1,parent:null,colMargin:20,boxModelCorrection:2,formulaFunctions:{},formulaVariables:{},cellSelectModel:t.excelSelectModel,autoAddCells:!0,resizableCells:!0,resizableSheet:!0,autoFiller:!0,error:function(e){return e.error},endOfNumber:!1,frozenAt:[],columnMenuButtons:null,columnContextMenuButtons:{"Insert column after":function(){return this.addColumn(!1,this.colLast),!1},"Insert column before":function(){return this.addColumn(!0,this.colLast),!1},"Add column to end":function(){return this.addColumn(!0),!1},"Delete this column":function(){return this.deleteColumn(),!1},"Hide column":function(){return this.toggleHideColumn(this.colLast),!1},"Show all columns":function(){this.columnShowAll()},"Toggle freeze columns to here":function(){var e=this.getTdLocation(this.tdActive()).col,t=this.pane().actionUI;t.frozenAt.col=t.frozenAt.col==e?0:e}},rowContextMenuButtons:{"Insert row after":function(){return this.addRow(!0,this.rowLast),!1},"Insert row before":function(){return this.addRow(!1,this.rowLast),!1},"Add row to end":function(){return this.addRow(!0),!1},"Delete this row":function(){return this.deleteRow(),!1},"Hide row":function(){return this.toggleHideRow(this.rowLast),!1},"Show all rows":function(){this.rowShowAll()},"Toggle freeze rows to here":function(){var e=this.getTdLocation(this.tdActive()).row,t=this.pane().actionUI;t.frozenAt.row=t.frozenAt.row==e?0:e}},cellContextMenuButtons:{"Insert row after":function(){return this.addRow(!0,this.rowLast),!1},"Insert row before":function(){return this.addRow(!1,this.rowLast),!1},"Add row to end":function(){return this.addRow(!0),!1},"Delete this row":function(){return this.deleteRow(),!1},line2:"line","Insert column after":function(){return this.addColumn(!0,this.colLast),!1},"Insert column before":function(){return this.addColumn(!1,this.colLast),!1},"Add column to end":function(){return this.addColumn(!0),!1},"Delete this column":function(){return this.deleteColumn(),!1},line3:"line","Add spreadsheet":function(){this.addSheet()},"Delete spreadsheet":function(){this.deleteSheet()}},alert:function(e){alert(e)},prompt:function(e,t,n){t(prompt(e,n))},confirm:function(e,t,n){confirm(e)?t():n&&n()},loader:null,useStack:!0,useMultiThreads:!0};return e.columnMenuButtons=e.columnContextMenuButtons,e}(),t.enclosure=function(e){var n=document.createElement("div"),i=$(n),r=new t.ActionUI(e,n,this.cl.scroll,e.settings.frozenAt[e.i]),l=r.pane;return l.className=t.cl.pane+" "+e.theme.pane,n.className=t.cl.enclosure,n.pane=l,l.enclosure=n,l.$enclosure=i,e.controls.pane[e.i]=l,e.controls.panes=e.panes().add(l),e.controls.enclosures[e.i]=n,n},t.formulaEditor=function(e,n){var i=document.createElement("td");i.className=e.cl.label+" "+e.theme.control,e.controls.label=$(i);var r=document.createElement("textarea");r.className=e.cl.formula+" "+e.theme.controlTextBox,r.onkeydown=function(t){return e.formulaEvents.keydown(t)},r.onkeyup=function(){e.inPlaceEdit().value=r.value},r.onchange=function(){e.inPlaceEdit().value=r.value},r.onpaste=function(t){return e.pasteOverCells(t)},r.onfocus=function(){e.setNav(!1)},r.onfocusout=function(){e.setNav(!0)},r.onblur=function(){e.setNav(!0)},e.controls.formula=$(r);var l=document.createElement("span");l.appendChild(r);var s=document.createElement("table"),o=document.createElement("tr");s.appendChild(o),n.appendChild(s);var a=document.createElement("td");a.className=e.cl.formulaParent,a.appendChild(l),o.appendChild(i),o.appendChild(a),o.appendChild(document.createElement("td")),e.resizableSheet($(l),{minHeight:e.controls.formula.height(),maxHeight:78,handles:"s",resize:function(t,n){e.controls.formula.height(n.size.height)},stop:function(){e.sheetSyncSize()}});for(var h=t.instances,c=0;c<h.length;c++)(h||{}).nav=!1;return e.setNav(!0),$(document).keydown(function(t){return e.documentEvents.keydown(t)}),r},t.header=function(e){e.header().remove(),e.sheetAdder().remove(),e.tabContainer().remove();var n,i,r=e.settings,l=document.createElement("div"),s=document.createElement("h4");return l.className=e.cl.header+" "+e.theme.control,e.controls.header=$(l),r.title?($.isFunction(r.title)&&(r.title=e.title(I)),s.className=e.cl.title,e.controls.title=$(s).html(r.title)):s.style.display="none",l.appendChild(s),e.isSheetEditable()&&(r.headerMenu&&(n=document.createElement("div"),i=$(n),n.className=e.cl.headerMenu+" "+e.cl.menuFixed+" "+e.theme.menuFixed+" "+e.cl.menu,l.appendChild(n),e.controls.headerMenu[e.i]=i.append(r.headerMenu(e)).children().addClass(e.theme.menuFixed),i.find("img").load(function(){e.sheetSyncSize()})),t.formulaEditor(e,l)),l},t.inPlaceEdit=function(t,n,i){if(n=t.cellActive()?n||t.cellActive().td||null:n||null,null===n&&(n=t.rowTds(null,1)[1],t.cellEdit(n._cell)),null!==n){(t.inPlaceEdit().destroy||e)();var r,l,s=t.formula(),o=s.val(),h=t.pane();r=document.createElement("textarea"),l=$(r),h.inPlaceEdit=r,r.i=t.i,r.className=t.cl.inPlaceEdit+" "+t.theme.inPlaceEdit,r.td=n,r.table=n.parentNode.parentNode.parentNode,r.goToTd=function(){r.offset=$(n).position(),r.offset.left||r.offset.right?r.setAttribute("style","left:"+(r.offset.left-1)+"px;top:"+(r.offset.top-1)+"px;width:"+r.td.clientWidth+"px;height:"+r.td.clientHeight+"px;min-width:"+r.td.clientWidth+"px;min-height:"+r.td.clientHeight+"px;"):$(r).hide()},r.goToTd(),r.onkeydown=function(e){switch(e=e||window.event,t.trigger("sheetFormulaKeydown",[!0]),e.keyCode){case a.ENTER:return t.formulaEvents.keydown(e);case a.TAB:return t.formulaEvents.keydown(e);case a.ESCAPE:return t.cellEvents.editAbandon(),!1}},r.onchange=r.onkeyup=function(){s[0].value=r.value},r.onfocus=function(){t.setNav(!1)},r.onblur=r.onfocusout=function(){t.setNav(!0)},r.onpaste=function(e){t.cellEvents.paste(e)},r.destroy=function(){h.inPlaceEdit=null,null!==t.cellLast&&(t.cellLast.isEdit=r.value!=o),r.parentNode.removeChild(r),t.controls.inPlaceEdit[r.i]=!1},h.appendChild(r),r.onfocus(),t.controls.inPlaceEdit[t.i]=r,l.focus().val("").val(s[0].value),i&&l.select(),$.fn.elastic&&$(r).elastic()}},t.menu=function(e,t){if("undefined"==typeof t)throw new Error("no menuEntities defined");var n=document.createElement("div"),i=e.theme.menuHover.split(" ");n.className=e.theme.menu+" "+e.cl.menu,s(n),n.onmouseleave=function(){n.parentNode.removeChild(n)},n.oncontextmenu=function(){return!1},n.onscroll=function(){return!1};for(var r in t)t.hasOwnProperty(r)&&!function(t,r){switch(typeof r){case"function":var l=document.createElement("div");l.className=e.cl.menuButton,l.textContent=t,l.onclick=function(t){return r.call(e,t),n.parentNode.removeChild(n),!1},i.length>0&&(l.onmouseover=function(){for(var e=0,t=n.children.length;e<t;e++)i.forEach(function(t){n.children[e].classList.remove(t)});i.forEach(function(e){l.classList.add(e)})}),n.appendChild(l);break;case"string":if("line"===r){n.appendChild(document.createElement("hr"));break}default:throw new Error("Unknown menu type")}}(r,t[r]);return n},t.rowResizer=function(e,t,n,i){e.barLeftControls().remove();var r,l=t.getBoundingClientRect(),s=l.top+document.body.scrollTop,o=l.left+document.body.scrollLeft,a=document.createElement("div"),h=$(a).addClass(e.cl.barController+" "+e.theme.barResizer).offset({top:s,left:o}).prependTo(t),c=t.parentNode,u=document.createElement("div"),d=$(u).addClass(e.cl.barControllerChild).height(t.clientHeight).prependTo(h);e.controls.bar.y.controls[e.i]=e.barLeftControls().add(h),e.resizableCells(d,{handles:"s",start:function(){e.autoFillerHide(),e.setBusy(!0),i.freezeHandleLeft&&i.freezeHandleLeft.remove()},resize:function(e,n){a.style.height=t.style.height=c.style.height=n.size.height+"px",i.inPlaceEdit&&i.inPlaceEdit.goToTd()},stop:function(t,n){e.setBusy(!1),i.inPlaceEdit&&i.inPlaceEdit.goToTd(),e.followMe(),e.setDirty(!0)},minHeight:15}),r=u.children[0],r.style.width=t.offsetWidth+"px"},t.sheetUI=function(e,n,i){e.i=i;var r=t.enclosure(e),l=r.pane,s=$(l),o=l.actionUI,a=function(t){t=t||window.event;var n=t.target,i=n.parentNode;if(e.isBusy())return!1;if(e.isCell(t.target))return e.cellContextMenu.show(t.pageX,t.pageY),!1;if(e.isBar(n)&&(0!==n.cellIndex||0!==i.rowIndex))return 0===i.rowIndex?e.columnContextMenu.show(t.pageX,t.pageY):e.rowContextMenu.show(t.pageX,t.pageY),!1};if(n.appendChild(r),e.isSheetEditable()&&t.autoFiller(e,l),e.isSheetEditable()){var h=(e.formula(),"");s.mousedown(function(t){return e.setNav(!0),!e.isBusy()&&(e.isCell(t.target)?2==t.button?(a.call(this,t),e.cellEvents.mouseDown(t),!0):(e.cellEvents.mouseDown(t),!1):!e.isBar(t.target)||(2==t.button&&a.call(this,t),h=t.target.entity,o.selectBar(t.target),!1))}),l.onmouseup=function(){h=""},l.onmouseover=function(n){if(n=n||window.event,e.isBusy())return!1;if(!e.isBar(n.target))return!1;var i=n.target||n.srcElement,r=i.index,s=i.entity;if(r<0)return!1;switch(s){case t.columnEntity:o.columnCache.selecting&&i===h?(o.columnCache.last=r,e.cellSetActiveBar(t.columnEntity,o.columnCache.first,o.columnCache.last)):(t.columnResizer(e,i,r,l),e.isSheetEditable()&&(t.columnFreezer(e,r,l),e.columnMenu.setColumn(i).show(n.pageX,n.pageY)));break;case t.rowEntity:o.rowCache.selecting&&i===h?(o.rowCache.last=r,e.cellSetActiveBar(t.rowEntity,o.rowCache.first,o.rowCache.last)):(t.rowResizer(e,i,r,l),e.isSheetEditable()&&t.rowFreezer(e,r,l))}return!0},l.ondblclick=function(t){return e.cellEvents.dblClick(t)},l.oncontextmenu=a,s.disableSelectionSpecial().bind("cellEdit",function(t){if(t.target._cell)return e.cellEvents.edit(t.target._cell)})}t.tab(e),e.setChanged(!0)},t.spreadsheetAdder=function(e){var n=document.createElement("span");return e.isSheetEditable()&&(n.setAttribute("class",t.cl.sheetAdder+" "+t.cl.tab+" "+e.theme.tab),n.setAttribute("title",t.msg.addSheet),n.innerHTML="+",n.onmousedown=function(){return e.addSheet(),!1},n.i=-1),e.controls.sheetAdder=$(n),n},t.tab=function(e){var n=document.createElement("span"),i=e.controls.tab[e.i]=$(n).appendTo(e.tabContainer());return n.setAttribute("class",t.cl.tab+" "+e.theme.tab),e.sheetTab(!0,function(e){n.innerHTML=e}),n.i=e.i,e.controls.tabs=e.tabs().add(i),n},t.tabs=function(e){var n,i=document.createElement("span"),r=$(i);return e.controls.tabContainer=r,i.setAttribute("class",t.cl.tabContainer),i.onmousedown=function(t){t=t||window.event;var n=(t.target||t.srcElement).i;return n>=0&&e.trigger("sheetSwitch",[n]),!1},i.ondblclick=function(t){t=t||window.event;var n=(t.target||t.srcElement).i;return n>=0&&e.trigger("sheetRename",[n]),!1},e.isSheetEditable()&&$.fn.sortable&&r.sortable({placeholder:"ui-state-highlight",axis:"x",forceHelperSize:!0,forcePlaceholderSize:!0,opacity:.6,start:function(t,i){n=i.item.index(),e.trigger("sheetTabSortStart",[t,i])},update:function(t,i){e.trigger("sheetTabSortUpdate",[t,i,n])}}),i},t.thread=function(){function e(){var t=i[n],r=e.limit;return t=void 0===t?i[n]=e.create():i[n],n++,n>r&&(n=0),t}var n=0,i=[];return e.limit=10,e.create=function(){var e=operative({parseFormula:function(e){return formulaParser.yy.types=[],formulaParser.parse(e)},streamJSONSheet:function(e,t,n){Promise.all([gR(e+t)]).then(function(e){var t,i,r=e[0],l=JSON.parse(r),s=0;for(void 0!==l.pop&&(l=l[0]),t=l.rows,i=t.length,l.rows=[],n("sheet",JSON.stringify(l));s<i;s++)n("row",JSON.stringify(t[s]));n()},function(e){n("error",e)})},streamJSONRows:function(e,t,n){var i=0,r=t.length,l=[];if("string"==typeof t)l.push(gR(e+t));else for(;i<r;i++)l.push(gR(e+t[i]));Promise.all(l).then(function(e){for(var t,i,r,l,s=0,o=e,a=o.length;s<a;s++)for(r=JSON.parse(o[s]),l=r.length,t=0;t<l;t++)i=r[t],n("row",JSON.stringify(i));n()},function(e){n("error",e)})},streamJSONSheetRows:function(e,t,n,i){var r=0,l=n.length,s=[gR(e+t)];if("string"==typeof n)s.push(gR(e+n));else for(;r<l;r++)s.push(gR(e+n[r]));Promise.all(s).then(function(e){i("sheet",e[0]);for(var t,n,r,l,s=1,o=e,a=o.length;s<a;s++)for(r=JSON.parse(o[s]),l=r.length,t=0;t<l;t++)n=r[t],i("row",JSON.stringify(n));i()},function(e){i("error",e)})}},[t.formulaParserUrl,t.threadScopeUrl]);return e.stash=[],e.busy=!1,e},e.kill=function(){for(var e=0,t=i.length;e<t;e++)i[e].terminate()},e}(),t.ui=function(e){var n=document.createElement("div");return n.setAttribute("class",t.cl.ui),e.ui=n,n};var a={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,UNKNOWN:229},h={math:Math,toNumbers:function(e){e=this.flatten(e);var t=e.length-1;if(t<0)return[];do e[t]?(e[t]=$.trim(e[t]),isNaN(e[t])?e[t]=0:e[t]=1*e[t]):e[t]=0;while(t--);return e},unique:function(e){var t,n={},i=e.length,r=[];for(t=0;t<i;t+=1)n[e[t]]=e[t];for(t in n)r.push(n[t]);return r},flatten:function(e){for(var t,n=[],i=0,r=e.length;i<r;i++)t=e[i],n=t instanceof Array?n.concat(this.flatten(t)):n.concat(t);return n},insertAt:function(e,t,n){return $(t).each(function(){n>-1&&n<=e.length&&e.splice(n,0,this)}),e},indexOfNearestLessThan:function(e,t){if(0===e.length)return-1;var n,i,r=e.length-1,l=0,s=-1;if(e[r]<t)return r;for(;l<=r;)if(n=l+r>>1,i=e[n],i>t)r=n-1;else{if(!(i<t)){s=l;break}s=n,l=n+1}return s},ofSet:function(e,t){if(0===e.length)return null;var n,i,r,l=e.length-1,s=l,o=e[l],a=e[0],h=0,c=-1,u=-1,d=-1;if(e[l]<t||e[0]>t)return null;for(;h<=l;)if(n=h+l>>1,i=e[n],i>t)c=n,l=n-1;else{if(!(i<t)){c=l;break}h=n+1}if(c>-1){for(r=c;r<=s;){if(e[r]+1!==e[r+1]){u=e[r];break}r++}for(u===-1&&(u=o),r=c;r>=0;){if(e[r]-1!==e[r-1]){d=e[r];break}r--}d===-1&&(d=a)}return{start:d,end:u}},closest:function(e,t,n,i){n=n||0,i=i||e.length-1;for(var r,l;;){if(r=n+i>>1,l=e[r],(r===i||r===n)&&l!==t)return l;if(l>t)i=r;else{if(!(l<t))return l;n=r}}},getClosestNum:function(e,t,n){var i,r,l,s,o=0;if(t.length){
for(r=t[0],i=o,o;o<t.length;o++)l=Math.abs(e-r),s=Math.abs(e-t[o]),s<l&&(i=o,r=t[o]),l=null,s=null;return n?n(r,i):r}return!1},levenshtein:function(){var e=[];return function(t,n){if(t===n)return 0;var i=t.length,r=n.length;if(i&&r){for(var l,s,o,a,h=0,c=0,u=e;h<i;)u[h]=++h;for(;c<r;)for(a=n.charCodeAt(c),l=c,++c,s=c,h=0;h<i;++h)o=l+(t.charCodeAt(h)===a?0:1),l=u[h],s=s<l?s<o?s+1:o:l<o?l+1:o,u[h]=s;return s}return i+r}}(),lSearch:function(e,t){for(var n,i,r=0,l=e.length,s=-1;r<l;r++)n=e[r],i=new Number(this.levenshtein(n,t)),i.item=n,i<s&&(s=i);return void 0!==i?i.item:null}},c={dayDiv:864e5,math:Math,toCentury:function(e,t){return t=t||864e5,this.math.round(this.math.abs(new Date(1900,0,-1)-e)/t)},get:function(e,t){if(t=t||864e5,e.getMonth)return e;if(isNaN(e))return new Date(Globalize.parseDate(e));e*=t;var n=1*new Date(1900,0,-1);return e+=n,e=new Date(e)},week:function(e,t){t=t||864e5;var n=new Date(e.getFullYear(),0,1);return this.math.ceil(((e-n)/t+n.getDay()+1)/7)},toString:function(e,t){return t?Globalize.format(e,Globalize.culture().calendar.patterns[t]):Globalize.format(e)},diff:function(e,t,n,i){switch(i=i||864e5,n){case 0:return this.days360Nasd(e,t,0,!0);case 1:case 2:case 3:var r=this.math.abs(t-e)/i;return r;case 4:return this.days360Euro(e,t)}return 0},diffMonths:function(e,t){var n;return n=12*(t.getFullYear()-e.getFullYear()),n-=e.getMonth()+1,n+=t.getMonth()+1},days360:function(e,t,n,i,r,l){return 360*(t-e)+30*(i-n)+(l-r)},days360Nasd:function(e,t,n,i){var r=e.getDate(),l=e.getMonth(),s=e.getFullYear(),o=t.getDate(),a=t.getMonth(),h=t.getFullYear();return 2==a&&this.isEndOfMonth(o,a,h)&&(2==l&&this.isEndOfMonth(r,l,s)||3==n)&&(o=30),31==o&&(r>=30||3==n)&&(o=30),31==r&&(r=30),i&&2==l&&this.isEndOfMonth(r,l,s)&&(r=30),this.days360(s,h,l,a,r,o)},days360Euro:function(e,t){var n=e.getDate(),i=e.getMonth(),r=e.getFullYear(),l=t.getDate(),s=t.getMonth(),o=t.getFullYear();return 31==n&&(n=30),31==l&&(l=30),this.days360(r,o,i,s,n,l)},isEndOfMonth:function(e,t,n){return e==new Date(n,t+1,0,23,59,59).getDate()},isLeapYear:function(e){return 1==new Date(e,1,29).getMonth()},calcAnnualBasis:function(e,t,n){switch(n){case 0:case 2:case 4:return 360;case 3:return 365;case 1:var i=e.getDate(),r=e.getMonth(),l=e.getFullYear(),s=t.getDate(),o=t.getMonth(),a=t.getFullYear(),h=0;if(l==a)h=this.isLeapYear(l)?366:365;else if(a-1==l&&(r>o||r==o&&i>=s))h=this.isLeapYear(l)?r<2||2==r&&i<=29?366:365:this.isLeapYear(a)&&(o>2||2==o&&29==s)?366:365;else{for(var c=l;c<=a;c++)h+=this.isLeapYear(c)?366:365;h/=a-l+1}return h}return 0},lastDayOfMonth:function(e){return e.setDate(0),e.getDate()},isLastDayOfMonth:function(e){return e.getDate()==this.lastDayOfMonth(e)}},u={math:Math,fromMath:function(e){var t={},n=this;return t.hour=1*(24*e+"").split(".")[0],t.minute=function(e){e=n.math.round(24*e*100)/100,e=(e+"").split(".");var t=0;return e[1]&&(e[1].length<2&&(e[1]+="0"),t=.6*e[1]),n.math.round(t)}(e),t.second=function(e){e=n.math.round(24*e*1e4)/1e4,e=(e+"").split(".");var t=0;if(e[1]){for(var i=0;i<4;i++)e[1].charAt(i)||(e[1]+="0");var r=(.006*e[1]+"").split(".");if(r[1])return r[1]&&r[1].length>2&&(r[1]=r[1].substr(0,2)),n.math.round(.6*r[1])}return t}(e),t},fromString:function(e,t){var n,i,r,l,s=(new Date,e);return t&&(l=s.substr(-2).toLowerCase(),s=s.replace(/(am|pm)/i,"")),s=s.split(":"),n=1*s[0],i=1*s[1],r=1*(s[2]?s[2]:0),t&&"pm"==l&&(n+=12),jFN.TIME(n,i,r)}};return i(Math,{log10:function(e){return Math.log(e)/2.302585092994046},signum:function(e){return e/Math.abs(e)||e},log1p:function(e){var t=0,n=50;if(e<=-1)return"-INF";if(e<0||e>1)return Math.log(1+e);for(var i=1;i<n;i++)i%2===0?t-=Math.pow(e,i)/i:t+=Math.pow(e,i)/i;return t}}),$.printSource=function(e){var t=win.open();t.document.write("<html><body><xmp>"+e+"\n</xmp></body></html>"),t.document.close()},t.event.Cell=function(){function n(e){this.wickedGrid=e}return n.prototype={done:function(t){var n,i=this.wickedGrid,r=i.inPlaceEdit(),l=$(r).is(":focus"),s=i.cellLast,a=i.settings.$element;if((r.destroy||e)(),null!==s&&(s.isEdit||t)){n=i.getCell(s.sheetIndex,s.rowIndex,s.columnIndex);var h=l?$(r):i.formula(),c=n.td;if(i.isFormulaEditable(c)&&null!==c&&n.rowIndex>-1&&n.columnIndex>-1){var u,d=h.val(),f=i.loader;n.edited||(n.edited=!0,i.cellsEdited().push(n)),a.one("sheetPreCalculation",function(){n.parsedFormula=null,"="==d.charAt(0)?n.formula=d=d.substring(1):(n.value=d,n.formula="",null!==(u=n.loadedFrom)&&f.setCellAttributes(u,{cache:o,"data-formula":"",value:d,parsedFormula:null})),n.setNeedsUpdated()}),i.resolveCell(n),n.isEdit=!1,i.trigger("sheetCellEdited",[n])}}},editAbandon:function(t){var n=this.wickedGrid,i=n.cellLast;return(n.inPlaceEdit().destroy||e)(),n.highlighter.clearBar().clear(),t||null===i||i.updateValue(),n.cellLast=null,n.rowLast=0,n.colLast=0,n.highlighter.startRowIndex=0,n.highlighter.startColumnIndex=0,n.highlighter.endRowIndex=0,n.highlighter.endColumnIndex=0,n.labelUpdate(""),n.formula().val("").blur(),n.autoFillerHide(),!1},setHighlightFromKeyCode:function(e){var t=this.wickedGrid,n=t.orderedGrid(t.highlighter),i=t.sheetSize(),r=t.cellActive(),l=t.highlighter;if(null===r)return!1;switch(e.keyCode){case a.UP:if(n.endRowIndex>r.rowIndex){n.endRowIndex--,n.endRowIndex=n.endRowIndex>0?n.endRowIndex:0;break}n.startRowIndex--,n.startRowIndex=n.startRowIndex>0?n.startRowIndex:0;break;case a.DOWN:if(n.startRowIndex===n.endRowIndex){n.endRowIndex++,n.endRowIndex=n.endRowIndex<i.rows?n.endRowIndex:i.rows;break}if(n.startRowIndex<r.rowIndex){n.startRowIndex++,n.startRowIndex=n.startRowIndex<i.rows?n.startRowIndex:i.rows;break}n.endRowIndex++,n.endRowIndex=n.endRowIndex<i.rows?n.endRowIndex:i.rows;break;case a.LEFT:if(n.endColumnIndex>r.columnIndex){n.endColumnIndex--,n.endColumnIndex=n.endColumnIndex>0?n.endColumnIndex:0;break}n.startColumnIndex--,n.startColumnIndex=n.startColumnIndex>0?n.startColumnIndex:0;break;case a.RIGHT:if(n.startColumnIndex<r.columnIndex){n.startColumnIndex++,n.startColumnIndex=n.startColumnIndex<i.cols?n.startColumnIndex:i.cols;break}n.endColumnIndex++,n.endColumnIndex=n.endColumnIndex<i.cols?n.endColumnIndex:i.cols}return l.startRowIndex=n.startRowIndex,l.startColumnIndex=n.startColumnIndex,l.endRowIndex=n.endRowIndex,l.endColumnIndex=n.endColumnIndex,t.cycleCellArea(function(e){l.set(e.td)},n),!1},setActiveFromKeyCode:function(e,t){if(null===this.cellLast)return!1;var n,i,r,l,s=this.wickedGrid,h=s.cellLast,c={rowIndex:h.rowIndex,columnIndex:h.columnIndex},u=!1,d=!1;switch(e.keyCode){case a.UP:c.rowIndex--;break;case a.DOWN:c.rowIndex++;break;case a.LEFT:c.columnIndex--;break;case a.RIGHT:c.columnIndex++;break;case a.ENTER:c=s.cellEvents.incrementAndStayInGrid(s.orderedGrid(s.highlighter),c,!0,e.shiftKey),u=!0,l=s.highlighted(),l.length>1?d=!0:t||(c.rowIndex+=e.shiftKey?-1:1);break;case a.TAB:c=s.cellEvents.incrementAndStayInGrid(s.orderedGrid(s.highlighter),c,!1,e.shiftKey),u=!0,l=s.highlighted(),l.length>1?d=!0:t||(c.columnIndex+=e.shiftKey?-1:1);break;case a.HOME:c.columnIndex=1;break;case a.END:c.columnIndex=this.tdActive().parentNode.children.length-2}if(!h.isEdit||u){if((n=s.spreadsheets[s.i])===o)return!1;if((i=n[c.rowIndex])===o)return!1;if((r=i[c.columnIndex])===o)return!1;if(null!==r)return s.cellEdit(r,null,d),!1}return!0},incrementAndStayInGrid:function(e,t,n,i){return n?i?(t.rowIndex--,t.rowIndex<e.startRowIndex&&(t.rowIndex=e.endRowIndex,t.columnIndex--),t.columnIndex<e.startColumnIndex&&(t.columnIndex=e.endColumnIndex)):(t.rowIndex++,t.rowIndex>e.endRowIndex&&(t.rowIndex=e.startRowIndex,t.columnIndex++),t.columnIndex>e.endColumnIndex&&(t.columnIndex=e.startColumnIndex)):i?(t.columnIndex--,t.columnIndex<e.startColumnIndex&&(t.columnIndex=e.endColumnIndex,t.rowIndex--),t.rowIndex<e.startRowIndex&&(t.rowIndex=e.endRowIndex)):(t.columnIndex++,t.columnIndex>e.endColumnIndex&&(t.columnIndex=e.startColumnIndex,t.rowIndex++),t.rowIndex>e.endRowIndex&&(t.rowIndex=e.startRowIndex)),t},mouseDown:function(e){var t=this.wickedGrid;t.formula().blur(),e.shiftKey?t.getTdRange(e,t.formula().val()):e.target._cell&&this.edit(e.target._cell,!0)},dblClick:function(e){return!this.wickedGrid.isBusy()&&(t.inPlaceEdit(this.wickedGrid),!0)},edit:function(e){var t=this.wickedGrid;return!t.isBusy()&&(t.cellEdit(e),!0)},paste:function(e){if(e=e||window.event,e.ctrlKey||"paste"==e.type){var t=function(){wickedGrid.updateCellsAfterPasteToFormula()},n=$document.one("keyup",function(){t(),t=function(){},n.mouseup()}).one("mouseup",function(){t(),t=function(){},n.keyup()});return wickedGrid.setDirty(!0),wickedGrid.setChanged(!0),!0}return!1}},n}(),t.event.Document=function(){function e(e){this.wickedGrid=e}return e.prototype={enter:function(e){return this.wickedGrid.cellLast.isEdit||e.ctrlKey||$(this.wickedGrid.tdActive()).dblclick(),!1},tab:function(e){this.wickedGrid.cellEvents.setActiveFromKeyCode(e)},findCell:function(e){return!e.ctrlKey||(this.wickedGrid.cellFind(),!1)},redo:function(e){return!(e.ctrlKey&&!this.wickedGrid.cellLast.isEdit)||(this.wickedGrid.undo.undoManager.redo(),!1)},undo:function(e){return!(e.ctrlKey&&!this.wickedGrid.cellLast.isEdit)||(this.wickedGrid.undo.undoManager.undo(),!1)},copy:function(e,t){var n=this.wickedGrid.highlighted(!0),i=this.wickedGrid.formula(),r=i.val(),l=this.wickedGrid.toTsv(n,t);return i.val(l).focus().select(),$document.one("keyup",function(){t?i.val(""):i.val(r)}),!0},cut:function(e){return this.copy(e,!0)},pageUpDown:function(e){var t,n,i=this.wickedGrid.sheetSize(),r=this.wickedGrid.pane(),l=r.clientHeight,s=0;if(e)for(n=this.wickedGrid.cellLast.rowIndex;n>0&&s<l;n--)t=this.wickedGrid.getTd(-1,n,1),null!==t&&!t.getAttribute("data-hidden")&&$(t).is(":hidden")&&$(t).show(),s+=t.parentNode.clientHeight;else for(n=this.wickedGrid.cellLast.rowIndex;n<i.rows&&s<l;n++)t=this.wickedGrid.getTd(-1,n,1),null!==t&&(s+=t.parentNode.clientHeight);return this.wickedGrid.cellEdit(t),!1},keydown:function(e){e=e||window.event;var t=this.wickedGrid;if(t.readOnly[t.i])return!1;if(null!==t.cellLast){if(t.cellLast.rowIndex<0||t.cellLast.columnIndex<0)return!1;var n=t.cellLast.td;if(t.nav){switch(e.keyCode){case a.DELETE:t.toTsv(null,!0),t.formula().val(""),t.cellLast.isEdit=!0;break;case a.TAB:this.tab(e);break;case a.ENTER:t.cellEvents.setActiveFromKeyCode(e);break;case a.LEFT:case a.UP:case a.RIGHT:case a.DOWN:e.shiftKey?t.cellEvents.setHighlightFromKeyCode(e):t.cellEvents.setActiveFromKeyCode(e);break;case a.PAGE_UP:this.pageUpDown(!0);break;case a.PAGE_DOWN:this.pageUpDown();break;case a.HOME:case a.END:t.cellEvents.setActiveFromKeyCode(e);break;case a.V:return e.ctrlKey?t.formulaEvents.If(!t.cellEvents.paste(e),e):($(n).trigger("cellEdit"),!0);case a.Y:return e.ctrlKey?(this.redo(e),!1):($(n).trigger("cellEdit"),!0);case a.Z:return e.ctrlKey?(this.undo(e),!1):($(n).trigger("cellEdit"),!0);case a.ESCAPE:t.cellEvents.editAbandon();break;case a.F:return e.ctrlKey?t.formulaEvents.If(this.findCell(e),e):($(n).trigger("cellEdit"),!0);case a.CAPS_LOCK:case a.SHIFT:case a.ALT:break;case a.CONTROL:return t.formula().focus().select(),!0;default:return t.inPlaceEdit().td!==n&&$(n).trigger("cellEdit"),!0}return!1}}}},e}(),t.event.Formula=function(){function e(e){this.wickedGrid=e}return e.prototype={keydown:function(e){e=e||window.event;var t=this.wickedGrid;if(t.readOnly[t.i])return!1;if(null===t.cellLast)return!1;if(t.cellLast.rowIndex<0||t.cellLast.columnIndex<0)return!1;switch(t.trigger("sheetFormulaKeydown",[!1]),e.keyCode){case a.C:if(e.ctrlKey)return t.documentEvents.copy(e);case a.X:if(e.ctrlKey)return t.documentEvents.cut(e);case a.Y:if(e.ctrlKey)return t.documentEvents.redo(e),!1;break;case a.Z:if(e.ctrlKey)return t.documentEvents.undo(e),!1;break;case a.ESCAPE:return t.cellEvents.editAbandon(),!0;case a.ENTER:return t.cellEvents.setActiveFromKeyCode(e,!0),!1;case a.UNKNOWN:return!1}t.cellLast.isEdit=!0},If:function(e,t){return!!e&&($(this.wickedGrid.tdActive()).dblclick(),!0)}},e}(),t.loader.HTML=function(){function e(e){void 0!==e?(this.tables=e,this.count=e.length):(this.tables=[],this.count=0),this.cellIds={},this.wickedGrid=null,this.handler=null}return e.prototype={bindWickedGrid:function(e){return this.wickedGrid=e,this},bindHandler:function(e){return this.handler=e,this},bindActionUI:function(e,t){t.loadedFrom=this.tables[e]},size:function(e){var t,n,i,r,l={cols:0,rows:0},s=this.tables;return void 0===(t=s[e])?l:void 0===(n=t.querySelectorAll("tr"))?l:void 0===(i=n[0])?l:void 0===(r=i.children)?l:{rows:n.length,cols:r.length}},getWidth:function(e,n){var i,r,l=this.tables,s=l[e];return i=s.querySelectorAll("col"),i.length>n?(r=i[n].style.width.replace("px","")||t.defaultColumnWidth,1*r):t.defaultColumnWidth},getHeight:function(e,n){var i,r,l,s=this.tables,o=s[e];return i=o.querySelectorAll("tr"),i.length>n?(r=i[n],l=r.style.height.replace("px","")||t.defaultRowHeight,1*l):t.defaultRowHeight},isHidden:function(e){var t=this.tables,n=t[e];return"none"===n.style.display},setHidden:function(e,t){var n=this.tables,i=n[e];return t?i.style.display="none":i.style.display="",this},addRow:function(e,t,n){var i,r,l=this.tables[e],s=0,o=this.size(e),a=o.cols,h=o.rows,c=document.createElement("tr");if(void 0===l)return this;for(r=l.querySelector("tBody")||l,i=r.children;s<a;s++)c.appendChild(n[s].loadedFrom=document.createElement("td"));return 0===s&&c.appendChild(n[s].loadedFrom=document.createElement("td")),t===h?r.appendChild(c):t<h&&r.insertBefore(c,i[t]),this},addColumn:function(e,t,n){var i,r,l,s,o=this.tables[e],a=0,h=this.size(e),c=h.rows,u=h.cols;if(void 0===o)return this;if(s=o.querySelector("tBody"),i=s.children,t===u)for(;a<c;a++)r=i[a],l=document.createElement("td"),n[a].loadedFrom=l,r.appendChild(l);else if(t<u)for(;a<c;a++)r=i[a],l=document.createElement("td"),n[a].loadedFrom=l,r.insertBefore(l,r.children[t]);return this},deleteRow:function(e,t){var n,i,r,l,s=this.tables[e];return void 0===s?this:(l=s.querySelector("tBody"),n=l.children,n.length>t&&l.removeChild(n[t]),s.hasAttribute("data-hiddenrows")(i=s.getAttribute("data-hiddenrows").split(","))&&(r=i.indexOf(t))>-1&&(i.splice(r,1),s.setAttribute("data-hiddenrows",i.join(","))),this)},deleteColumn:function(e,t){var n,i,r,l,s,o,a,h=this.tables[e],c=0;if(void 0===h)return this;for(a=h.querySelector("tBody"),n=a.children,l=n.length;c<l;c++)i=n[c],r=i.children,r.length>t&&i.removeChild(r[t]);return h.hasAttribute("data-hiddencolumns")&&(s=h.getAttribute("data-hiddencolumns").split(","))&&(o=s.indexOf(t))>-1&&(s.splice(o,1),h.setAttribute("data-hiddencolumns",s.join(","))),this},setupTD:function(e,t){if(e.covered)return t.style.visibility="hidden",this;var n,i,r,l,s,o=this.wickedGrid,a=e.loadedFrom,h=!1,c=0,u=0,d=e.rowIndex,f=e.columnIndex;if(a.hasAttribute("class")&&(t.className=a.className),a.hasAttribute("style")&&t.setAttribute("style",a.getAttribute("style")),a.hasAttribute("rowspan")&&(t.setAttribute("rowspan",n=a.getAttribute("rowspan")),r=d+1*n,h=!0),a.hasAttribute("colspan")&&(t.setAttribute("colspan",i=a.getAttribute("colspan")),l=f+1*i,h=!0),h){for(void 0===r&&(r=d+1),void 0===l&&(l+=1),t.style.position="absolute",t.style.borderBottomWidth=t.style.borderRightWidth="1px";d<r;d++)c+=this.getHeight(e.sheetIndex,d)+2,e.rowIndex!==d&&null!==(s=o.getCell(e.sheetIndex,d,e.columnIndex))&&(s.covered=!0,s.defer=e);for(;f<l;f++)u+=this.getWidth(e.sheetIndex,f),e.columnIndex!==f&&null!==(s=o.getCell(e.sheetIndex,e.rowIndex,f))&&(s.covered=!0,s.defer=e);c-=1,u-=1,t.style.width=u+"px",t.style.height=c+"px"}return this},getCell:function(e,t,n){var i,r,l,s,o=this.tables;return void 0===(i=o[e])?null:void 0===(r=i.querySelectorAll("tr"))?null:void 0===(l=r[t])?null:void 0===(s=l.children[n])?null:s},jitCell:function(e,n,i){var r=this.getCell(e,n,i);if(null===r)return null;if(void 0!==r.getCell)return r.getCell();var l,s,o,a,h,c,u,d,f,p,m;return s=r.getAttribute("id"),o=r.innerHTML,a=r.getAttribute("data-formula"),h=r.getAttribute("data-celltype"),c=r.getAttribute("data-uneditable"),u=null!==s,d=o.length>0,f=null!==a,p=null!==h,m=null!==c,l=new t.Cell(e,null,this.wickedGrid,this.handler),l.rowIndex=n,l.columnIndex=i,l.loadedFrom=r,l.loader=this,u&&(l.id=s),f&&(l.formula=a),p&&(l.cellType=h),m&&(l.uneditable=c),d?l.value=new String(o):l.value=new String,l.value.cell=l,r.getCell=function(){return l},l},jitCellById:function(e,t,n){switch(this.cellIds[e]){case void 0:break;case null:return this;default:n(this.cellIds[e].requestCell())}var i,r,l,s,o,a,h,c,u,d,f=this,p=this.tables,m=t<0?p.length-1:t+1;for(t<0&&(t=0);t<m;t++)if(i=p[t],s=i.querySelectorAll("tr"),!(s.length<1))for(r=0,l=s.length;r<l;r++)for(o=s[r],c=o.children,a=0,h=c.length;a<h;a++)u=c[a],null!==u&&null!==u.id&&u.id.length>0&&(this.cellIds[u.id]={cell:u,sheetIndex:t,rowIndex:r,columnIndex:a,requestCell:function(){return f.jitCell(this.sheetIndex,this.rowIndex,this.columnIndex)}});return void 0!==this.cellIds[e]?(d=this.cellIds[e].requestCell(),n(d)):this.cellIds[e]=null,this},title:function(e){var t,n=this.tables;return void 0===(t=n[e])?"":t.getAttribute("title")},hideRow:function(e,t){var n,i=e.loadedFrom;return n=i.hasAttribute("data-hiddenrows")?h.toNumbers(i.getAttribute("data-hiddenrows").split(",")):[],n.indexOf(t)<0&&(n.push(t),n.sort(function(e,t){return e-t})),i.setAttribute("data-hiddenrows",n.join(",")),n},hideColumn:function(e,t){var n,i=e.loadedFrom;return n=i.hasAttribute("data-hiddencolumns")?h.toNumbers(i.getAttribute("data-hiddencolumns").split(",")):[],n.indexOf(t)<0&&(n.push(t),n.sort(function(e,t){return e-t})),i.setAttribute("data-hiddencolumns",n.join(",")),n},showRow:function(e,t){var n,i,r=e.loadedFrom;return n=r.hasAttribute("data-hiddenrows")?h.toNumbers(r.getAttribute("data-hiddenrows").split(",")):[],(i=n.indexOf(t))>-1&&n.splice(i,1),r.setAttribute("data-hiddenrows",n.join(",")),n},showColumn:function(e,t){var n,i,r=e.loadedFrom;return n=r.hasAttribute("data-hiddencolumns")?h.toNumbers(r.getAttribute("data-hiddencolumns").split(",")):[],(i=n.indexOf(t))>-1&&n.splice(i,1),r.setAttribute("data-hiddencolumns",n.join(",")),n},hiddenRows:function(e){var t=e.loadedFrom.getAttribute("data-hiddenrows"),n=null;return n=null!==t?h.toNumbers(t.split(",")):[]},hiddenColumns:function(e){var t=e.loadedFrom.getAttribute("data-hiddencolumns"),n=null;return n=null!==t?h.toNumbers(t.split(",")):[]},hasSpreadsheetAtIndex:function(e){return void 0!==this.tables[e]},getSpreadsheetIndexByTitle:function(e){var t,n=this.tables,i=this.count,r=0;for(e=e.toLowerCase();r<i;r++)if(void 0!==n[r]&&(t=n[r].getAttribute("title"),void 0!==t&&null!==t&&t.toLowerCase()==e))return r;return-1},addSpreadsheet:function(e,t){if(e=e||document.createElement("table"),!$(e).find("tbody").length){var n=document.createElement("tbody");$(n).html($(e).html()),$(e).html($(n))}void 0===t?this.tables.push(e):this.tables.splice(t,0,e),this.count=this.tables.length},getCellAttribute:function(e,t){return e.getAttribute(t)},setCellAttribute:function(e,t,n){e.setAttribute(t,n)},setCellAttributes:function(e,t){var n;for(n in t)void 0!==n&&t.hasOwnProperty(n)&&("value"===n?e.innerHTML=t[n]:e.setAttribute(n,t[n]));return this},setDependencies:function(e){return this},addDependency:function(e,t){return this},cycleCells:function(e,t){var n,i,r,l,s,o,a,h=this.tables;if(void 0!==(n=h[e])&&!((o=(i=n.querySelectorAll("tr")).length)<1||i[0].children.length<1)){o--;do{s=i[o],r=s.children,a=r.length;do l=r[a],t.call(l,e,o,a);while(a-- >0)}while(o-- >0);return this}},cycleCellsAll:function(e){var t=this.tables,n=t.length;if(!(n<0)){do this.cycleCells(n,e);while(n-- >0);return this}},toTables:function(){return this.tables},fromSheet:function(e){e=void 0!=e&&e;var t,n,i,r,l,s,o,a,h,c,u,d,f,p,m,g,w,v=[],y=this.wickedGrid,b=1*y.i,C=y.spreadsheets.length-1;if(C<0)return v;do{m=!1,y.i=C,y.evt.cellEditDone(),t=y.obj.pane(),i=document.createElement("table"),r=document.createElement("tBody"),l=document.createElement("colGroup"),i.setAttribute("title",y.obj.table().attr("title")),i.setAttribute("data-frozenatrow",t.action.frozenAt.row),i.setAttribute("data-frozenatcol",t.action.frozenAt.col),i.appendChild(l),i.appendChild(r),v.unshift(i),n=y.spreadsheets[C],o=n.length;do{g=n[o][1].td.parentNode,w=g.style.height,h=document.createElement("tr"),h.style.height=w?w:y.s.colMargin+"px",a=n[o].length;do u=n[o][a],c=document.createElement("td"),d=u.td.attributes,(e||m||d.class||u.formula||u.value||d.style)&&(m=!0,f=d.class?$.trim((d.class.value||"").replace(y.cl.uiCellActive,"").replace(y.cl.uiCellHighlighted,"")):"",p=u.td.parentNode,h.insertBefore(c,h.firstChild),h.style.height||(h.style.height=p.style.height?p.style.height:y.settings.colMargin+"px"),u.formula&&c.setAttribute("data-formula",u.formula),u.cellType&&c.setAttribute("cellType",u.cellType),u.value&&c.setAttribute("value",u.value),u.uneditable&&c.setAttribute("uneditable",u.uneditable),u.cache&&c.setAttribute("cache",u.cache),u.id&&c.setAttribute("id",u.id),d.style&&d.style.value&&c.setAttribute("style",d.style.value),f.length&&(c.className=f),d.rowspan&&(c.rowspan=d.rowspan.value),d.colspan&&(c.colspan=d.colspan.value),1*o==1&&(s=document.createElement("col"),s.style.width=$(y.col(a)).css("width"),l.insertBefore(s,l.firstChild)));while(a-- >1);m&&r.insertBefore(h,r.firstChild)}while(o-- >1)}while(C--);return y.i=b,this.json=v},type:e,typeName:"WickedGrid.loader.HTML",clearCaching:function(){return this}},e.maxStoredDependencies=100,e}(),t.loader.JSON=function(){function e(e){void 0!==e?(this.json=e,this.count=e.length):(this.json=[],this.count=0),this.cellIds={},this.wickedGrid=null,this.handler=null}return e.prototype={bindWickedGrid:function(e){return this.wickedGrid=e,this},bindHandler:function(e){return this.handler=e,this},bindActionUI:function(e,t){t.loadedFrom=this.json[e]},size:function(e){var t,n,i,r,l={cols:0,rows:0},s=this.json;return void 0===(t=s[e])?l:void 0===(n=t.rows)?l:void 0===(i=n[0])?l:void 0===(r=i.columns)?l:{rows:n.length,cols:r.length}},getWidth:function(e,n){var i=this.json,r=i[e]||{},l=r.metadata||{},s=l.widths||[],o=s[n]||t.defaultColumnWidth;return 1*o},getHeight:function(e,n){var i=this.json,r=i[e]||{},l=r.rows||[],s=l[n]||{},o=s.height||t.defaultRowHeight;return 1*o},isHidden:function(e){var t=this.json,n=t[e]||{},i=n.metadata||{};return i.hidden===!0},setHidden:function(e,t){var n=this.json,i=n[e]||{},r=i.metadata||{};return r.hidden=t,this},addRow:function(e,t,n){var i,r,l=this.json[e],s=0,o=this.size(e).cols,a={columns:[]},h=a.columns;if(void 0===l)return this;for(i=l.rows;s<o;s++)r={},n[s]=r,h.push(r);return void 0===t?i.push(a):t<i.length&&i.splice(t,0,a),this},addColumn:function(e,t,n){var i,r,l=this.json[e],s=0,o=this.size(e),a=o.rows,h=o.cols;if(void 0===l)return this;if(i=l.rows,void 0===t)for(;s<a;s++)r={},n[s].loadedFrom=r,i[s].columns.push(r);else if(t<h)for(;s<a;s++)r={},n[s].loadedFrom=r,i[s].columns.splice(t,0,r);return this},deleteRow:function(e,t){var n,i,r,l,s=this.json[e];return void 0===s?this:(n=s.rows,n.length>t&&n.splice(t,1),void 0!==(i=s.metadata)&&void 0!==(r=i.hiddenRows)&&(l=r.indexOf(t))>-1&&r.splice(l,1),this)},deleteColumn:function(e,t){var n,i,r,l,s,o,a,h=this.json[e],c=0;if(void 0===h)return this;for(n=h.rows,l=n.length;c<l;c++)i=n[c],r=i.columns,t.length>t&&r.splice(t,1);return void 0!==(s=h.metadata)&&void 0!==(o=s.hiddenColumns)&&(a=o.indexOf(t))>-1&&o.splice(a,1),this},setupTD:function(e,t){if(e.covered)return t.style.visibility="hidden",this;var n,i,r,l,s,o=this.wickedGrid,a=e.loadedFrom,h=!1,c=0,u=0,d=e.rowIndex,f=e.columnIndex;if(void 0!==a.class&&(t.className=a.class),void 0!==a.id&&t.setAttribute("id",a.id),void 0!==a.style&&t.setAttribute("style",a.style),void 0!==a.rowspan&&(t.setAttribute("rowspan",n=a.rowspan),r=d+1*n,h=!0),void 0!==a.colspan&&(t.setAttribute("colspan",i=a.colspan),l=f+1*i,h=!0),h){for(void 0===r&&(r=d+1),void 0===l&&(l+=1),t.style.position="absolute",t.style.borderBottomWidth=t.style.borderRightWidth="1px";d<r;d++)c+=this.getHeight(e.sheetIndex,d)+2,e.rowIndex!==d&&null!==(s=o.getCell(e.sheetIndex,d,e.columnIndex))&&(s.covered=!0,s.defer=e);for(;f<l;f++)u+=this.getWidth(e.sheetIndex,f),e.columnIndex!==f&&null!==(s=o.getCell(e.sheetIndex,e.rowIndex,f))&&(s.covered=!0,s.defer=e);c-=1,u-=1,t.style.width=u+"px",t.style.height=c+"px"}return this},getCell:function(e,t,n){var i,r,l,s,o=this.json;if(void 0!==(i=o[e])&&void 0!==(r=i.rows)&&void 0!==(l=r[t])&&void 0!==(s=l.columns[n]))return null===s&&(s=l.columns[n]={}),s},jitCell:function(e,n,i){var r=this.getCell(e,n,i);if(void 0===r)return null;if(void 0!==r.getCell)return r.getCell();var l,s,o,a,h,c,u,d,f,p,m,g,w,v,y,b,C,x,E,I,T;if(o=r.id,h=r.value,c=r.cache,u=r.formula,d=r.parsedFormula,f=r.cellType,p=r.uneditable,g=r.dependencies,v=void 0!==o&&null!==o,y=void 0!==h&&null!==h,b=void 0!==c&&null!==c&&(c+"").length>0,C=void 0!==u&&null!==u&&""!==u,x=void 0!==d&&null!==d,E=void 0!==f&&null!==f,I=void 0!==p&&null!==p,T=void 0!==g&&null!==g,l=new t.Cell(e,null,this.wickedGrid,this.handler),l.rowIndex=n,l.columnIndex=i,l.loadedFrom=r,l.loader=this,v&&(l.id=o),C&&(l.formula=u),x&&(l.parsedFormula=d),E&&(l.cellType=f),I&&(l.uneditable=p),y?l.value=new String(h):l.value=new String,b?(l.value.html=c,l.needsUpdated=!1):l.needsUpdated=C||E||l.hasOperator.test(h),T)for(a=g.length,s=0;s<a;s++)w=g[s],m=this.jitCell(w.s,w.r,w.c),null!==m?l.dependencies.push(m):(l.dependencies=[],r.dependencies=[],l.setNeedsUpdated(!0),l.value=new String);return l.value.cell=l,r.getCell=function(){return l},l},jitCellById:function(e,t,n){switch(this.cellIds[e]){case void 0:break;case null:return this;default:n(this.cellIds[e].requestCell())}var i,r,l,s,o,a,h,c,u,d,f=this,p=this.json,m=t<0?p.length-1:t+1;for(t<0&&(t=0);t<m;t++)if(i=p[t],s=i.rows,!(s.length<1))for(r=0,l=s.length;r<l;r++)for(o=s[r],c=o.columns,a=0,h=c.length;a<h;a++)u=c[a],null!==u&&"string"==typeof u.id&&(this.cellIds[u.id]={cell:u,sheetIndex:t,rowIndex:r,columnIndex:a,requestCell:function(){return f.jitCell(this.sheetIndex,this.rowIndex,this.columnIndex)}});return void 0!==this.cellIds[e]?(d=this.cellIds[e].requestCell(),n(d)):this.cellIds[e]=null,this},title:function(e){var t,n=this.json;return void 0===(t=n[e])?"":t.title||""},hideRow:function(e,t){var n=e.loadedFrom,i=n.metadata||(n.metadata={}),r=i.hiddenRows||(i.hiddenRows=[]);return r.indexOf(t)<0&&(r.push(t),r.sort(function(e,t){return e-t})),r},hideColumn:function(e,t){var n=e.loadedFrom,i=n.metadata||(n.metadata={}),r=i.hiddenColumns||(i.hiddenColumns=[]);return r.indexOf(t)<0&&(r.push(t),r.sort(function(e,t){return e-t})),r},showRow:function(e,t){var n,i=e.loadedFrom,r=i.metadata||(i.metadata={}),l=r.hiddenRows||(r.hiddenRows=[]);return(n=l.indexOf(t))>-1&&l.splice(n,1),l},showColumn:function(e,t){var n,i=e.loadedFrom,r=i.metadata||(i.metadata={}),l=r.hiddenColumns||(r.hiddenColumns=[]);return(n=l.indexOf(t))>-1&&l.splice(n,1),l},hiddenRows:function(e){for(var t=e.loadedFrom,n=t.metadata||(t.metadata={}),i=n.hiddenRows||(n.hiddenRows=[]),r=i.length,l=[],s=0;s<r;s++)l.push(i[s]);return l},hiddenColumns:function(e){for(var t=e.loadedFrom,n=t.metadata||(t.metadata={}),i=n.hiddenColumns||(n.hiddenColumns=[]),r=i.length,l=[],s=0;s<r;s++)l.push(i[s]);return l},hasSpreadsheetAtIndex:function(e){return void 0!==this.json[e]},getSpreadsheetIndexByTitle:function(e){var t,n=this.json,i=this.count,r=0;for(e=e.toLowerCase();r<i;r++)if(void 0!==n[r]&&(t=n[r].title,void 0!==t&&null!==t&&t.toLowerCase()==e))return r;return-1},addSpreadsheet:function(e,t){e=e||{},void 0===t?this.json.push(e):this.json.splice(t,0,e),this.count=this.json.length},getCellAttribute:function(e,t){return e[t]},setCellAttribute:function(e,t,n){e[t]=n},setCellAttributes:function(e,t){var n;for(n in t)void 0!==n&&t.hasOwnProperty(n)&&(e[n]=t[n]);return this},setDependencies:function(t){if(t.dependencies.length>e.maxStoredDependencies)return delete t.loadedFrom.dependencies,this;for(var n,i=0,r=t.loadedFrom,l=t.dependencies,s=l.length,o=r.dependencies=[];i<s;i++)n=l[i],o.push({s:n.sheetIndex,r:n.rowIndex,c:n.columnIndex});return this},addDependency:function(e,t){var n=e.loadedFrom;return void 0===n.dependencies&&(n.dependencies=[]),n.dependencies.push({s:t.sheetIndex,r:t.rowIndex,c:t.columnIndex}),this},cycleCells:function(e,t){var n,i,r,l,s,o,a,h=this.json;if(void 0!==(n=h[e])&&!((o=(i=n.rows).length)<1||i[0].columns.length<1)){do{s=i[o],r=s.columns,a=r.length-1;do l=r[a],t.call(l,e,o,a);while(a-- >=0)}while(o-- >=0);return this}},cycleCellsAll:function(e){var t=this.json,n=t.length-1;if(!(n<0)){do this.cycleCells(n,e);while(n-- >0);return this}},toTables:function(){for(var e,t,n,i,r,l,s,o,a,h,c,u,d,f,p,m,g,w,v,y=this.json,b=this.count,C=$([]),x=0;x<b;x++){for(e=y[x],d=$(document.createElement("table")),e.title&&d.attr("title",e.title||""),C=C.add(d),t=e.rows,w=0;w<t.length;w++)for(n=t[w],(u=(n.height+"").replace("px",""))&&(m=$(document.createElement("tr")).attr("height",u).css("height",u+"px").appendTo(d)),i=n.columns,v=0;v<i.length;v++)r=i[v],g=$(document.createElement("td")).appendTo(m),r.class&&g.attr("class",r.class||""),r.style&&g.attr("style",r.style||""),r.formula&&g.attr("data-formula",r.formula?"="+r.formula:""),r.cellType&&g.attr("data-celltype",r.cellType||""),r.value&&g.html(r.value||""),r.uneditable&&g.html(r.uneditable||""),r.rowspan&&g.attr("rowspan",r.rowspan||""),r.colspan&&g.attr("colspan",r.colspan||""),r.id&&g.attr("id",r.id||""),r.cache&&g.html(r.cache);if(l=e.metadata){if(s=l.widths)for(f=$(document.createElement("colgroup")).prependTo(d),v=0;v<s.length;v++)o=(s[v]+"").replace("px",""),p=$(document.createElement("col")).attr("width",o).css("width",o+"px").appendTo(f);(a=l.frozenAt)&&(a.row&&d.attr("data-frozenatrow",a.row),a.col&&d.attr("data-frozenatcol",a.col)),(h=l.hiddenRows)&&d.attr("data-hiddenrows",h.join(",")),(c=l.hiddenColumns)&&d.attr("data-hiddencolumns",c.join(","))}}return C},fromSheet:function(e){e=void 0!=e&&e;var t,n,i,r,l,s,o,a,h,c,u,d,f,p,m=[],g=this.wickedGrid,w=1*g.i,v=g.spreadsheets.length-1;if(v<0)return m;do{d=!1,g.i=v,g.evt.cellEditDone(),t=g.obj.pane(),n={title:g.obj.table().attr("title")||"",rows:[],metadata:{widths:[],frozenAt:{row:t.actionUI.frozenAt.row,col:t.actionUI.frozenAt.col}}},m.unshift(n),i=g.spreadsheets[v],r=i.length-1;do{f=i[r][1].td.parentNode,p=f.style.height,s={columns:[],height:p?p.replace("px",""):g.s.colMargin},l=i[r].length-1;do a=i[r][l],o={},h=a.td.attributes,(e||d||h.class||a.formula||a.value||h.style)&&(d=!0,c=h.class?$.trim((h.class.value||"").replace(g.cl.uiCellActive,"").replace(g.cl.uiCellHighlighted,"")):"",u=a.td.parentNode,s.columns.unshift(o),s.height||(s.height=u.style.height?u.style.height.replace("px",""):g.s.colMargin),a.formula&&(o.formula=a.formula),a.cellType&&(o.cellType=a.cellType),a.value&&(o.value=a.value),a.uneditable&&(o.uneditable=a.uneditable),a.cache&&(o.cache=a.cache),a.id&&(o.id=a.id),h.style&&h.style.value&&(o.style=h.style.value),c.length&&(o.class=c),h.rowspan&&(o.rowspan=h.rowspan.value),h.colspan&&(o.colspan=h.colspan.value),1*r==1&&n.metadata.widths.unshift($(g.col(l)).css("width").replace("px","")));while(l-- >1);d&&n.rows.unshift(s)}while(r-- >1)}while(v--);return g.i=w,this.json=m},type:e,typeName:"WickedGrid.loader.JSON",clearCaching:function(){for(var e,t,n,i,r,l,s,o,a,h=this.json,c=0,u=h.length;c<u;c++)for(e=h[c],n=e.rows,o=n.length,l=0;l<o;l++)for(t=n[l],r=t.columns,a=r.length,s=0;s<a;s++)i=r[s],null!==i&&(delete i.cache,delete i.dependencies,delete i.parsedFormula);return this},download:function(e){e=e||500;var t,n,i,r=window.open(),l=this.json,s=0,o=l.length-1;if(void 0!==r){for(t=r.document,t.write('<html>\t<head id="head"></head>\t<body>\t\t<div id="entry">\t\t</div>\t</body></html>'),n=$(t.getElementById("entry"));s<=o;){if(i=l[s],i.rows.length>e){var a={title:i.title,metadata:i.metadata,rows:[]},h=[],c=0,u=i.rows,d=u.length,f=1,p=0,m=function(e,t){n.append(document.createElement("br")),n.append($(document.createElement("a")).attr("download",i.title+"-part"+t+".json").attr("href",URL.createObjectURL(new Blob([JSON.stringify(e)],{type:"application/json"}))).text(i.title+" - part "+t));
};for(m(a,f);c<d;)p===e&&(p=0,f++,m(h,f),h=[]),h.push(u[c]),p++,c++;h.length>0&&(f++,m(h,f))}else n.append(document.createElement("br")).append($(document.createElement("a")).attr("download",i.title+".json").attr("href",URL.createObjectURL(new Blob([JSON.stringify(i)],{type:"application/json"}))).text(i.title));s++}t.close(),r.focus()}}},e.maxStoredDependencies=100,e}(),t.loader.XML=function(){function e(e){void 0!==e?(this.xml=$.parseXML(e),this.spreadsheets=this.xml.getElementsByTagName("spreadsheets")[0].getElementsByTagName("spreadsheet"),this.count=this.xml.length):(this.xml=null,this.spreadsheets=null,this.count=0)}return e.prototype={size:function(e){var t=this.xml[e],n=t.rows,i=n[0],r=i.columns;return{rows:n.length,cols:r.length}},setWidth:function(e,t,n){var i=this.spreadsheets,r=i[e],l=r.getElementsByTagName("metadata")[0]||{},s=l.getElementsByTagName("width")||[],o=s[t],a=o.textContent||o.text;n.style.width=a+"px"},setRowHeight:function(e,t,n){var i,r,l,s,o=this.spreadsheets;void 0!==(i=o[e])&&void 0!==(r=i.getElementsByTagName("rows")[0].getElementsByTagName("row"))&&void 0!==(l=r[t])&&void 0!==(s=l.attributes.height.nodeValue)&&(n.style.height=s+"px")},setupCell:function(e,t,n,i,r){var l,s,o,a,h=this.spreadsheets;return void 0!==(l=h[e])&&(void 0!==(s=l.getElementsByTagName("rows")[0].getElementsByTagName("row")[t-1])&&(void 0!==(o=s.getElementsByTagName("columns")[0].getElementsByTagName("column")[n-1])&&(i.cellType=o.attributes.cellType.nodeValue||"",void 0!==(a=o.jitCell)&&(i.html=a.html,i.state=a.state,i.cellType=a.cellType,i.value=a.value,i.uneditable=a.uneditable,i.sheet=a.sheet,i.dependencies=a.dependencies),o.attributes.formula?(i.formula=o.attributes.formula.nodeValue||"",r.setAttribute("data-formula",o.attributes.formula.nodeValue||"")):r.innerHTML=i.value=o.attributes.value.nodeValue||"",r.className=o.attributes.class.nodeValue||"",r.setAttribute("style",o.attributes.style.nodeValue||""),o.attributes.rowspan&&r.setAttribute("rowspan",o.attributes.rowspan.nodeValue||""),o.attributes.colspan&&r.setAttribute("colspan",o.attributes.colspan.nodeValue||""),!0)))},getCell:function(e,t,n){return null},jitCell:function(e,t,n){var i,r,l,s=this.spreadsheets;return void 0!==(i=s[e])&&(void 0!==(r=i.getElementsByTagName("rows")[0].getElementsByTagName("row")[t-1])&&(void 0!==(l=r.getElementsByTagName("columns")[0].getElementsByTagName("column")[n-1])&&{td:{cellIndex:n,parentNode:{rowIndex:t},html:function(){}},html:[],state:[],cellType:l.attributes.cellType.nodeValue||"",formula:l.attributes.formula.nodeValue||"",value:l.attributes.value.nodeValue||"",type:"cell",sheet:e,id:null}))},title:function(e){var t,n=this.spreadsheets;return void 0===(t=n[e])?"":t.attributes.title?t.attributes.title.nodeValue:""},getSpreadsheetIndexByTitle:function(e){},addSpreadsheet:function(e,t){void 0===t?this.spreadsheets.append.push(jsonSpreadsheet):this.json.splice(t,0,jsonSpreadsheet),this.count=this.json.length},setCellAttribute:function(e,t,n){},toTables:function(){for(var e,t,n,i,r,l,s,o,a,h,c,u,d=this.xml,f=$([]),p=d.getElementsByTagName("spreadsheets")[0].getElementsByTagName("spreadsheet"),m=0;m<p.length;m++){e=p[m];var g=$(document.createElement("table")).attr("title",e.attributes.title?e.attributes.title.nodeValue:""),w=$(document.createElement("colgroup")).appendTo(g),v=$(document.createElement("tbody")).appendTo(g);f=f.add(g),t=e.getElementsByTagName("rows")[0].getElementsByTagName("row"),l=e.getElementsByTagName("metadata")[0];for(var y=0;y<t.length;y++){n=t[y];var b=$(document.createElement("tr")).appendTo(v);(u=n.attributes.height)&&(u=(u.nodeValue||"").replace("px",""),b.css("height",u).attr("height",u+"px")),i=n.getElementsByTagName("columns")[0].getElementsByTagName("column");for(var C=0;C<i.length;C++){r=i[C];var x=$(document.createElement("td")).appendTo(b),E=r.getElementsByTagName("formula")[0],I=r.getElementsByTagName("cellType")[0],T=r.getElementsByTagName("value")[0],S=r.getElementsByTagName("style")[0],A=r.getElementsByTagName("class")[0],k=r.getElementsByTagName("rowspan")[0],N=r.getElementsByTagName("colspan")[0],R=r.getElementsByTagName("id")[0];E&&x.attr("data-formula","="+(E.textContent||E.text)),I&&x.attr("data-celltype",I.textContent||I.text),T&&x.html(T.textContent||T.text),S&&x.attr("style",S.textContent||S.text),A&&x.attr("class",A.textContent||A.text),k&&x.attr("rowspan",k.textContent||k.text),N&&x.attr("colspan",N.textContent||N.text),R&&x.attr("id",R.textContent||R.text)}}h=l.getElementsByTagName("width");for(var y=0;y<h.length;y++)c=(h[y].textContent||h[y].text).replace("px",""),$(document.createElement("col")).attr("width",c).css("width",c+"px").appendTo(w);s=l.getElementsByTagName("frozenAt")[0],s&&(a=s.getElementsByTagName("col")[0],o=s.getElementsByTagName("row")[0],a&&g.attr("data-frozenatcol",1*(a.textContent||a.text)),o&&g.attr("data-frozenatrow",1*(o.textContent||o.text)))}return f},fromSheet:function(e,t,n){t=void 0!=t&&t;var r,l,s,o,a,h,c,u,d,f,p,m,g,w,v,y="",b=1*e.i,C=e.spreadsheets.length-1;if(C<0)return y;do{m=!1,e.i=C,e.evt.cellEditDone(),p=i({},e.obj.pane().actionUI.frozenAt),g=[],l=e.spreadsheets[C],s=l.length-1,a="";do{c="",o=l[s].length-1;do h="",u=l[s][o],d=u.td[0].attributes,f=d.class?$.trim((d.class.value||"").replace(e.cl.uiCellActive,"").replace(e.cl.uiCellHighlighted,"")):"",(t||m||f||u.formula||u.value||d.style)&&(m=!0,h+="<column>",u.formula&&(h+="<formula>"+u.formula+"</formula>"),u.cellType&&(h+="<cellType>"+u.cellType+"</cellType>"),u.value&&(h+="<value>"+u.value+"</value>"),d.style&&(h+="<style>"+d.style.value+"</style>"),f&&(h+="<class>"+f+"</class>"),d.rowspan&&(h+="<rowspan>"+d.rowspan.value+"</rowspan>"),d.colspan&&(h+="<colspan>"+d.colspan.value+"</colspan>"),d.id&&(h+="<id>"+d.id.value+"</id>"),h+="</column>",c=h+c,1*s==1&&(g[o]="<width>"+$(e.col(o)).css("width").replace("px","")+"</width>"));while(o-- >1);c&&(w=l[s][1].td[0].parentNode,v=w.style.height,a='<row height="'+(v?v.replace("px",""):e.s.colMargin)+'"><columns>'+c+"</columns></row>"+a)}while(s-- >1);r='<spreadsheet title="'+(e.obj.table().attr("title")||"")+'"><rows>'+a+"</rows><metadata>"+(p.row||p.col?"<frozenAt>"+(p.row?"<row>"+p.row+"</row>":"")+(p.col?"<col>"+p.col+"</col>":"")+"</frozenAt>":"")+"<widths>"+g.join("")+"</widths></metadata></spreadsheet>",y=r+y}while(C--);return e.i=b,y='<?xml version="1.0" encoding="UTF-8"?><spreadsheets xmlns="http://www.w3.org/1999/xhtml">'+y+"</spreadsheets>",n!==!0&&(this.xml=$.parseXML(y)),y},type:e,typeName:"WickedGrid.XMLLoader"},e}(),t.ActionUI=function(){var e=$(document),n=function(e,n,i,r){this.wickedGrid=e,this.enclosure=n,this.pane=document.createElement("div"),this.active=!0,this.rowCache={last:null,first:null,selecting:!1},this.columnCache={last:null,first:null,selecting:!1},n.appendChild(this.pane),(this.frozenAt=r)||(this.frozenAt={row:0,col:0}),this.frozenAt.row=Math.max(this.frozenAt.row,0),this.frozenAt.col=Math.max(this.frozenAt.col,0),e.loader.bindActionUI(e.i,this),this.hiddenRows=e.loader.hiddenRows(this),this.visibleRows=[],this.hiddenColumns=e.loader.hiddenColumns(this),this.visibleColumns=[],this.loader=e.loader,this.setupVisibleRows().setupVisibleColumns();var l=this,s=this.loader,o=this.pane,a=this.scrolledArea={row:Math.max(this.frozenAt.row,1),col:Math.max(this.frozenAt.col,1)},h=this.megaTable=new MegaTable({columns:t.domColumns,rows:t.domRows,element:o,updateCell:this._updateCell=function(t,n,i){var r,o=0===l.visibleRows.length?t:l.visibleRows[t],a=0===l.visibleColumns.length?n:l.visibleColumns[n];"object"==typeof i._cell&&null!==i._cell&&(i._cell.td=null);var h=e.getCell(e.i,o,a);if(null!==h){var c=e.spreadsheets[e.i]||(e.spreadsheets[e.i]=[]),u=c[o]||(c[o]=[]);if(u[a]||(u[a]=h),r=h.td,null!==r)for(;null!==r.lastChild;)r.removeChild(r.lastChild);h.td=i,i._cell=h,s.setupTD(h,i),h.updateValue()}},updateCorner:this._updateCorner=function(t,n){t.index=-1,t.entity="corner",t.col=n,t.className=e.cl.corner+" "+e.theme.bar},updateRowHeader:this._updateRowHeader=function(t,n){var i,r;0===l.visibleRows.length?(i=t,r=document.createTextNode(i+1)):(i=t>=l.visibleRows.length?t+l.hiddenRows.length:l.visibleRows[t],r=document.createTextNode(i+1)),n.index=i,n.entity="row",n.className=e.cl.row+" "+e.theme.bar,n.appendChild(r),n.parentNode.style.height=n.style.height=s.getHeight(e.i,i)+"px"},updateColumnHeader:this._updateColumnHeader=function(t,n,i){var r,o;0===l.visibleColumns.length?(r=t,o=document.createTextNode(e.cellHandler.columnLabelString(r))):(r=t>=l.visibleColumns.length?t+l.hiddenColumns.length:l.visibleColumns[t],o=document.createTextNode(e.cellHandler.columnLabelString(r))),n.index=r,n.th=n,n.col=i,n.entity="column",n.className=e.cl.column+" "+e.theme.bar,n.appendChild(o),i.style.width=s.getWidth(e.i,r)+"px"}}),c=this.infiniscroll=new Infiniscroll(o,{scroll:function(e,t){setTimeout(function(){a.col=e,a.row=t,h.update(t,e)},0)},verticalScrollDensity:15,horizontalScrollDensity:25});new MouseWheel(o,c._out),h.table.className+=" "+t.cl.table+" "+e.theme.table,h.table.setAttribute("cellSpacing","0"),h.table.setAttribute("cellPadding","0"),o.scroll=c._out,o.actionUI=this,o.table=h.table,o.tBody=h.tBody};return n.prototype={putTdInView:function(e){for(var t,n,i=0,r=0,l=0;null!==(t=this.directionToSeeTd(e))&&(n=this.scrolledArea,t.left?(r--,this.scrollTo("x",0,n.col-1)):t.right&&(r++,this.scrollTo("x",0,n.col+1)),t.up?(l--,this.scrollTo("y",0,n.row-1)):t.down&&(l++,this.scrollTo("y",0,n.row+1)),i++,!(i<25)););},directionToSeeTd:function(e){var t=this.pane,n={top:0,bottom:t.clientHeight,left:0,right:t.clientWidth},i=e.clientWidth,r=e.clientHeight,l={top:e.offsetTop,bottom:e.offsetTop+r,left:e.offsetLeft,right:e.offsetLeft+i},s=e.parentNode,o=this.scrolledArea;if(!e.col)return null;var a=e.barTop.cellIndex<o.col,h=s.rowIndex<o.row,c={up:h,down:l.bottom>n.bottom&&r<=t.clientHeight,left:a,right:l.right>n.right&&i<=t.clientWidth};return c.up||c.down||c.left||c.right?c:null},hide:function(){var e=this.wickedGrid,t=e.ui,n=this.pane,i=n.parentNode,r=this.infiniscroll;return void 0!==n&&null!==i.parentNode&&(this.deactivate(),r.saveLT(),t.removeChild(n.parentNode)),this},show:function(){var e=this.wickedGrid,t=e.ui,n=this.pane,i=n.parentNode,r=this.infiniscroll;return void 0!==n&&null===i.parentNode&&(t.appendChild(n.parentNode),r.applyLT(),this.activate()),this},deactivate:function(){var e=this.megaTable;return this.active=!1,e.updateCell=e.updateCorner=e.updateRowHeader=e.updateColumnHeader=function(){},this},activate:function(){var e=this.megaTable;return this.active=!0,e.updateCell=this._updateCell,e.updateCorner=this._updateCorner,e.updateRowHeader=this._updateRowHeader,e.updateColumnHeader=this._updateColumnHeader,this},hideRow:function(e){this.hiddenRows=this.loader.hideRow(this,e);var t;return(t=this.visibleRows.indexOf(e))>-1&&this.visibleRows.splice(t,1),this.megaTable.forceRedrawRows(),this},showRow:function(e){return this.hiddenRows=this.loader.showRow(this,e),this.visibleRows.indexOf(e)<0&&(this.visibleRows.push(e),this.visibleRows.sort(function(e,t){return e-t})),this.megaTable.forceRedrawRows(),this},hideRowRange:function(e,t){for(var n,i=this.loader;e<=t;e++)this.hiddenRows=i.hideRow(this,e),(n=this.visibleRows.indexOf(e))>-1&&this.visibleRows.splice(n,1);return this.megaTable.forceRedrawRows(),this},showRowRange:function(e,t){for(var n=this.loader;e<=t;e++)this.hiddenRows=n.showRow(this,e),this.visibleRows.indexOf(e)<0&&this.visibleRows.push(e);return this.visibleRows.sort(function(e,t){return e-t}),this.megaTable.forceRedrawRows(),this},rowShowAll:function(){return this.hiddenRows=[],this.visibleRows=[],this.megaTable.forceRedrawRows(),this},hideColumn:function(e){this.hiddenColumns=this.loader.hideColumn(this,e);var t;return(t=this.hiddenColumns.indexOf(e))>-1&&this.hiddenColumns.splice(t,1),this.megaTable.forceRedrawRows(),this},showColumn:function(e){return this.hiddenColumns=this.loader.showColumn(this,e),this.visibleColumns.indexOf(e)<0&&(this.visibleColumns.push(e),this.visibleColumns.sort(function(e,t){return e-t})),this.megaTable.forceRedrawColumns(),this},hideColumnRange:function(e,t){for(var n,i=this.loader;e<=t;e++)this.hiddenColumns=i.hideColumn(this,e),(n=this.visibleColumns.indexOf(e))>-1&&this.visibleColumns.splice(n,1);return this.megaTable.forceRedrawColumns(),this},showColumnRange:function(e,t){for(var n=this.loader;e<=t;e++)this.hiddenColumns=n.showColumn(this,e),this.visibleColumns.indexOf(e)<0&&this.visibleColumns.push(e);return this.visibleColumns.sort(function(e,t){return e-t}),this.megaTable.forceRedrawColumns(),this},columnShowAll:function(){return this.hiddenColumns=[],this.visibleColumns=[],this.megaTable.forceRedrawColumns(),this},remove:function(){throw new Error("Not yet implemented")},scrollToCell:function(e,t){throw new Error("Not yet implemented")},setupVisibleRows:function(){for(var e=0,t=this.visibleRows=[],n=this.hiddenRows,i=this.loader.size(this.wickedGrid.i).rows;e<i;e++)n.indexOf(e)<0&&t.push(e);return this},setupVisibleColumns:function(){for(var e=0,t=this.visibleColumns=[],n=this.hiddenColumns,i=this.loader.size(this.wickedGrid.i).cols;e<i;e++)n.indexOf(e)<0&&t.push(e);return this},redrawRows:function(){this.megaTable.forceRedrawRows()},redrawColumns:function(){this.megaTable.forceRedrawColumns()},selectBar:function(e){switch(e.entity){case t.columnEntity:return this.selectColumn(e);case t.rowEntity:return this.selectRow(e)}return null},selectColumn:function(t){if(!t)return this;if("bar"!==t.type)return this;var n=this.columnCache,i=t.index;return i<0?this:(n.last=n.first=i,this.wickedGrid.cellSetActiveBar("column",n.first,n.last),n.selecting=!0,e.one("mouseup",function(){n.selecting=!1}),this)},selectRow:function(t){if(t&&"bar"===t.type){var n=this.rowCache,i=t,r=i.index;return!(r<0)&&(n.last=n.first=r,this.wickedGrid.cellSetActiveBar("row",n.first,n.last),n.selecting=!0,e.one("mouseup",function(){n.selecting=!1}),!1)}},pixelScrollDensity:30,maximumVisibleRows:65,maximumVisibleColumns:35},n}(),t.Cell=function(){function e(n,i,r){null===e.cellLoading&&(e.cellLoading=t.msg.cellLoading),void 0!==i&&null!==i?(this.td=i,i.cell=this):this.td=null,this.dependencies=[],this.formula="",this.cellType=null,this.value="",this.valueOverride=null,this.calcCount=0,this.sheetIndex=n,this.rowIndex=null,this.columnIndex=null,this.wickedGrid=r,this.state=[],this.needsUpdated=!0,this.uneditable=!1,this.id=null,this.loader=null,this.loadedFrom=null,this.cellHandler=r.cellHandler,this.waitingCallbacks=[],this.parsedFormula=null,this.defer=null,this.isEdit=!1,this.edited=!1,this.covered=!1}var n=void 0;return e.prototype={clone:function(){var t,n=new e(this.sheetIndex,this.td,this.wickedGrid,this.cellHandler);for(t in this)void 0!==t&&this.hasOwnProperty(t)&&(null!==this[t]&&void 0===this[t].call?n[t]=this[t]:null===this[t]&&(n[t]=this[t]));return n},addDependency:function(t){if(void 0!==t&&null!==t){if(t.type!==e)throw new Error("Wrong Type");this.dependencies.indexOf(t)<0&&this!==t&&(this.dependencies.push(t),null!==this.loader&&this.loader.addDependency(this,t))}},updateValue:function(i){if(this.needsUpdated||this.value.cell===n||null!==this.defer)if(null===this.cellType&&null===this.defer&&this.formula.length<1&&void 0!==this.value&&((this.value+"").length<1||!this.hasOperator.test(this.value))){if(null!==this.td&&(this.td.innerHTML=this.encode(this.value)),this.value=new String(this.value),this.value.cell=this,this.updateDependencies(),i!==n&&i.call(this,this.value),this.waitingCallbacks.length>0)for(;this.waitingCallbacks.length>0;)this.waitingCallbacks.pop().call(this,this.value)}else{var r,l,s,o,a=this,h=this.value,c=this.formula,u=this.cellType,d=this.defer,f=function(e){a.parsedFormula=e,a.resolveFormula(e,function(e){e!==n&&null!==e?(e.cell!==n&&e.cell!==a&&(e=e.valueOf()),t.calcStack--,null!==u&&(s=t.CellTypeHandlers[u])!==n&&(e=s(a,e)),p.call(a,e)):p.call(a,null)})},p=function(e){if(e!==n&&null!==e||(e=new String),e.cell===n){switch(typeof e){case"object":break;case"undefined":e=new String;break;case"number":e=new Number(e);break;case"boolean":e=new Boolean(e);break;case"string":default:e=new String(e)}e.cell=a}if(a.value=e,l=a.displayValue().valueOf(),a.state.shift(),null!==a.loader&&a.loader.setCellAttributes(a.loadedFrom,{cache:"object"!=typeof l?l:null,"data-formula":a.formula,parsedFormula:a.parsedFormula,value:a.value+"",cellType:a.cellType,uneditable:a.uneditable}).setDependencies(a),a.needsUpdated=!1,o=null!==a.valueOverride?a.valueOverride:a.value,i!==n&&i.call(a,o),a.waitingCallbacks.length>0)for(;a.waitingCallbacks.length>0;)a.waitingCallbacks.pop().call(a,o);a.updateDependencies()};if(this.state.length>0)return void(i!==n&&this.waitingCallbacks.push(i));if(null!==d)return void d.updateValue(function(e){switch(e=e.valueOf(),typeof e){case"object":break;case"undefined":e=new String;break;case"number":e=new Number(e);break;case"boolean":e=new Boolean(e);break;case"string":default:e=new String(e)}if(e.cell=a,a.value=e,a.updateDependencies(),a.needsUpdated=!1,a.displayValue(),i!==n&&i.call(a,e),a.waitingCallbacks.length>0)for(;a.waitingCallbacks.length>0;)a.waitingCallbacks.pop().call(a,e)});if(this.oldValue=h,this.state.unshift("updating"),this.fnCount=0,this.valueOverride=null,this.calcCount++,c.length>0){if("="===c.charAt(0)&&(a.formula=c=c.substring(1)),null!==a.td){for(;null!==a.td.lastChild;)a.td.removeChild(a.td.lastChild);a.td.appendChild(document.createTextNode(e.cellLoading))}t.calcStack++,null!==this.parsedFormula?f(this.parsedFormula):this.wickedGrid.parseFormula(c,f)}else if(h!==n&&null!==h&&null!==u&&(s=t.CellTypeHandlers[u])!==n)h=s(a,h),p(h);else{switch(typeof h.valueOf()){case"string":r=a.startOperators[h.charAt(0)],r!==n?a.valueOverride=r.call(a,h):(r=a.endOperators[h.charAt(h.length-1)],r!==n&&(a.valueOverride=r.call(a,h)));break;case"undefined":h=""}p(h)}}else{var m=null!==this.valueOverride?this.valueOverride:this.value;if(this.displayValue(),i!==n&&i.call(this,m),this.waitingCallbacks.length>0)for(;this.waitingCallbacks.length>0;)this.waitingCallbacks.pop().call(this,m)}},updateDependencies:function(){var e,t,n;if(e=this.dependencies,this.dependencies=[],n=e.length-1,n>-1){this.state.unshift("updatingDependencies");do t=e[n],t.updateValue();while(n-- >0);this.state.shift()}0===this.dependencies.length&&(this.dependencies=e)},displayValue:function(){var e=this.value,t=this.td,i=typeof e,r=e.html;if(r===n&&(r="string"===i||null!==e&&"object"===i&&e.toUpperCase!==n&&e.length>0?this.encode(e):e),t===n||null===t)return r;switch(typeof r){case"object":if(null===r)for(;null!==t.lastChild;)t.removeChild(t.lastChild);else if(r.appendChild!==n){if(null===r.parentNode){for(;null!==t.lastChild;)t.removeChild(t.lastChild);t.appendChild(r)}return""}case"string":default:for(;null!==t.lastChild;)t.removeChild(t.lastChild);t.appendChild(document.createTextNode(r))}return t.innerHTML},resolveFormula:function(t,i){"string"==typeof t&&i(t);var r,l,s=this,o=[],a=0,h=t.length,c=this.cellHandler,u=[],d=function(e,t){var n,i=[],r=t.length-1;if(!(r<0)){do switch(n=t[r],typeof n){case"number":i[r]=u[n];break;case"string":i[r]=n;break;case"object":if(n instanceof Array){i[r]=f(n);break}default:i[r]=n}while(r-- >0);return i.unshift(e),i}},f=function(e){var t,n=[],i=e.length-1;if(!(i<0)){do switch(t=e[i],typeof t){case"number":n[i]=u[t];break;case"string":n[i]=t;break;case"object":if(t.hasOwnProperty("args")){n[i]=t,n[i].a=f(t.a);break}if(t instanceof Array){n[i]=f(t);break}default:n[i]=t}while(i-- >0);return n}};for(l=s.wickedGrid.settings.useStack?function(t){var r,l=e.thawIndex,a=e.thaws,h="undefined"==typeof a[l];r=h?e.thaws[l]=new Thaw([]):a[l],e.thawIndex++,e.thawIndex>e.thawLimit&&(e.thawIndex=0),r.add(function(){o.length>0?o.shift()():i(s.value=t!==n?t:null)})}:function(e){o.length>0?o.shift()():i(s.value=e!==n?e:null)};a<h;a++)switch(r=t[a],r.t){case"m":!function(e,t){o.push(function(){l(u[t]=c[e.m].apply(c,d(s,e.a)))})}(r,a);break;case"l":!function(e,t){o.push(function(){var n=d(s,e.a);n.push(function(e){l(u[t]=e)}),c[e.m].apply(c,n)})}(r,a);break;case"v":!function(e,t){o.push(function(){l(u[t]=e.v)})}(r,a);break;case"cell":!function(e,t){o.push(function(){u[t]=e,l()})}(r,a);break;case n:u[a]=r;break;default:throw u[a]=null,new Error("Not implemented:"+r.t)}l()},recurseDependencies:function(t,n){if(n>e.maxRecursion)return this.recurseDependenciesFlat(t),this;var i,r=0,l=this.dependencies,s=l.length;for(void 0===n&&(n=0);r<s;r++)i=l[r],t.call(i),i.recurseDependencies(t,n);return this},recurseDependenciesFlat:function(e){var t,n,i=this.dependencies,r=i.length-1,l=[];if(!(r<0)){do l.push(i[r]);while(r-- >0);do if(t=l[l.length-1],l.length--,e.call(t),n=t.dependencies,r=n.length-1,r>-1)do l.push(n[r]);while(r-- >0);while(l.length>0)}},getAllDependencies:function(){var e=[];return this.recurseDependencies(function(){e.push(this)}),e},setNeedsUpdated:function(e){e!==n?this.needsUpdated=e:this.needsUpdated=!0,this.recurseDependencies(function(){this.needsUpdated=!0})},encode:function(e){switch(typeof e){case"object":return e.getMonth!==n?globalize.format(e,"d"):e}return e&&e.replace?e.replace(/&/gi,"&").replace(/>/gi,">").replace(/</gi,"<").replace(/\t/g,"   ").replace(/ /g," "):e||""},setAttribute:function(e,t){var i=this.td;return i!==n&&(i[e]=t),this.loader.setCellAttribute(this.loadedFrom,e,t),this},setAttributes:function(e){var t,i=this.td;if(i!==n)for(t in e)e.hasOwnProperty(t)&&(i[e]=e[t]);return this.loader.setCellAttributes(this.loadedFrom,e),this},addClass:function(e){var t,i,r=this.td,l=this.loadedFrom;return r!==n&&(r.classList?r.classList.add(e):r.className+=(r.className.length>0?" ":"")+e),l!==n&&(t=this.loader.getCellAttribute(l,"class")||"",i=t.split(" ").indexOf(e),i<0&&(t+=(t.length>0?" ":"")+e,this.loader.setCellAttribute(l,"class",t))),this},removeClass:function(e){var t,i,r=this.td,l=this.loadedFrom;return r!==n&&(r.classList?r.classList.remove(e):(t=(r.className+"").split(" "),i=t.indexOf(e),i>-1&&(t.splice(i,1),r.className=t.join(" ")))),l!==n&&(t=(this.loader.getCellAttribute(l,"class")||"").split(" "),i=t.indexOf(e),i>-1&&(t.splice(i,1),this.loader.setCellAttribute(l,"class",t.join(" ")))),this},hasOperator:/(^[$£])|([%]$)/,startOperators:{$:function(e,t){return this.cellHandler.fn.DOLLAR.call(this,e.substring(1).replace(Globalize.culture().numberFormat[","],""),2,t||"$")},"£":function(e){return this.startOperators.$.call(this,e,"£")}},endOperators:{"%":function(e){return e.substring(0,this.value.length-1)/100}},type:e,typeName:"WickedGrid.Cell"},e.thaws=[],e.thawLimit=500,e.thawIndex=0,e.cellLoading=null,e.maxRecursion=10,e}(),t.CellContextMenu=function(){function e(e,t){this.wickedGrid=e,this.menu=t}return e.prototype={show:function(e,t){var n=this.wickedGrid,i=this.menu,r=i.style;return r.left=e-5+"px",r.top=t-5+"px",n.hideMenus(),n.pane().appendChild(i),this},hide:function(){return null===this.menu.parentNode?this:(this.menu.parentNode.removeChild(this.menu),this)}},e}(),t.CellHandler=function(e){function n(e){return!isNaN(e)}function i(e,t){this.wickedGrid=e,this.fn=t}var r=void 0,l=NaN;return i.prototype={variable:function(e,t){if(arguments.length){var n,i,r=t[0],l=t[1],s=this.wickedGrid.s.formulaVariables;switch(r.toLowerCase()){case"true":return i=new Boolean(!0),i.html="TRUE",i.cell=e,i;case"false":return i=new Boolean(!1),i.html="FALSE",i.cell=e,i}return(n=s[r]&&!l)?n:n&&l?n[l]:""}},time:function(e,t,n){return u.fromString(t,n)},number:function(e,t){switch((isNaN(t)||null===t)&&(t=0),typeof t){case"number":return t;case"string":if(n(t))return 1*t;case"object":if(t.getMonth)return c.toCentury(t)}return t},invertNumber:function(e,t){isNaN(t)&&(t=0);var n=this.number(e,t),i=new Number(n.valueOf()*-1);return n.html&&(i.html=n.html),i},performMath:function(t,i,s,o){s!==r&&null!==s||(s=0),o!==r&&null!==o||(o=0);var a,h,u,d=!0,f=!0,p=[],m=function(e){return e};switch(s.hasOwnProperty("cell")&&s.cell.addDependency(t),o.hasOwnProperty("cell")&&o.cell.addDependency(t),a=typeof s.valueOf()){case"number":break;case"string":n(s)?s*=1:d=!1;break;case"object":s.getMonth?(s=c.toCentury(s),m=c.get):d=!1;break;default:d=!1}switch(h=typeof o.valueOf()){case"number":break;case"string":n(o)?o*=1:f=!1;break;case"object":o.getMonth?o=c.toCentury(o):f=!1;break;default:f=!1}switch(d||"+"===i||(p.push("not a number: "+s),s=0),f||(p.push("not a number: "+o),o=0),p.length,i){case"+":u=s+o;break;case"-":u=s-o;break;case"/":u=s/o,u!=1/0&&u!=l||(u=0);break;case"*":u=s*o;break;case"^":u=e.pow(s,o)}return m(u)},not:function(e,t,n){var i;return t.valueOf()!=n.valueOf()?(i=new Boolean(!0),i.html="TRUE",i.cell=e):(i=new Boolean(!1),i.html="FALSE",i.cell=e),i},concatenate:function(e,t,n){return null===t&&(t=""),null===n&&(n=""),t.toString()+n.toString()},cellValue:function(e,t,n){var i,l=this.wickedGrid,s=this.parseLocation(t.c,t.r);return i=l.getCell(e.sheetIndex,s.row,s.col),null!==i?(i.addDependency(e),i.updateValue(n)):n!==r&&n.call(e,0),this},cellRangeValue:function(e,t,n,i){return this.remoteCellRangeValue(e,e.sheetIndex,t,n,i)},remoteCellValue:function(e,t,n,i){var l,s=this.wickedGrid,o=this.parseLocation(n.c,n.r),a=this.parseSheetLocation(t);return a<0&&(a=s.getSpreadsheetIndexByTitle(t)),l=s.getCell(a,o.row,o.col),null!==l?(l.addDependency(e),l.updateValue(i)):i!==r&&i.call(e,0),this},remoteCellRangeValue:function(e,t,n,l,s){var o,a,h,c,u,d,f,p="string"==typeof t?this.parseSheetLocation(t):t,m=this.parseLocation(n.c,n.r),g=this.parseLocation(l.c,l.r),w=m.row<g.row?m.row:g.row,v=m.row<g.row?g.row:m.row,y=m.col<g.col?m.col:g.col,b=y,C=m.col<g.col?g.col:m.col,x=(C-(y-1))*(v-(w-1)),E=0,I=this.wickedGrid,T=[],S=0;if(p<0&&(p=I.getSpreadsheetIndexByTitle(t)),p<0)return T=new String(""),T.html="#NAME?",s.call(e,T),this;if(u=p+"!"+n.c+n.r+":"+l.c+l.r,o=i.cellRangeCache[u],o!==r){a=!0,d=o.length;for(var A=0;A<d;A++)o[A].cell.needsUpdated&&(a=!1);if(a)return s.call(e,i.cellRangeCache[u]),this}for(f=I.spreadsheets[p],f===r&&(I.spreadsheets[p]=f=[]),T.rowCount=v-w+1,T.columnCount=C-b+1;w<=v;w++)for(b=y,c=f[w]!==r?f[w]:null;b<=C;b++)null===c||(h=c[b])===r?h=I.getCell(p,w,b):(h.sheetIndex=p,h.rowIndex=w,h.columnIndex=b),null!==h&&(h.addDependency(e),function(t){h.updateValue(function(n){T[t]=n,E++,E===x&&(i.cellRangeCache[u]=T,s.call(e,T))})}(S++));return this},callFunction:function(e,t,n){t=t.toUpperCase(),n=n||[];var i,l=this.fn[t];return l!==r?(e.fnCount++,i=l.apply(e,n)):(i=new String,i.html="Function "+t+" Not Found"),i},formulaParser:function(e){var n;return e>-1?(n=t.spareFormulaParsers[e],n===r&&(n=t.spareFormulaParsers[e]=Formula(this))):n=this.wickedGrid.formulaParser,n},parseLocation:function(e,t){return{row:t-1,col:this.columnLabelIndex(e)}},parseSheetLocation:function(e){var t=1*(e+"").replace(/SHEET/i,"")-1;return isNaN(t)?-1:t},parseCellName:function(e,t){var n="";return void 0!==t&&(t++,n=t.toString()),this.columnLabelString(e)+n},alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),columnLabels:{},columnLabelIndex:function(e){return this.columnLabels[e.toUpperCase()]},columnIndexes:[],columnLabelString:function(e){if(!this.columnIndexes.length){var t,n,i,r,l="";for(t=n=i=-1,r=0;r<16385;++r)l="",++i,26==i&&(i=0,++n,26==n&&(n=0,++t)),t>=0&&(l+=this.alphabet[t]),n>=0&&(l+=this.alphabet[n]),i>=0&&(l+=this.alphabet[i]),this.columnIndexes[r]=l,this.columnLabels[l]=r}return this.columnIndexes[e]||""}},i.cellRangeCache={},i}(Math),t.CellRange=function(){function e(e){this.cells=e||[]}return e.prototype={clone:function(){for(var t,n,i=[],r=this.cells,l=r.length,s=0;s<l;s++)t=r[s],n=t.clone(),i.push(n);return new e(i)},type:e,typeName:"WickedGrid.CellRange"},e}(),t.cellTypeHandlers={percent:function(e,t){if(t!==t)return 0;var n,i=isNaN(t)?Globalize.parseFloat(t):1*t;return isNaN(i)?t:(n=new Number(i),n.html=Globalize.format(i,"p"),n)},date:function(e,t){if(t!==t)return 0;var n=Globalize.parseDate(t);return null===n?t:(e.valueOverride=n,e.html=Globalize.format(n,"d"),t)},time:function(e,t){if(t!==t)return 0;var n=Globalize.parseDate(t);return null===n?t:(n.html=Globalize.format(n,"t"),n)},currency:function(e,t){if(t!==t)return 0;var n,i=isNaN(t)?Globalize.parseFloat(t):1*t;return isNaN(i)?t:(n=new Number(i),n.html=Globalize.format(i,"c"),n)},number:function(e,t){if(t!==t)return 0;var n,i;return CellTypeHandlers.endOfNumber||(n=Globalize.culture().numberFormat["."],CellTypeHandlers.endOfNumber=new RegExp("(["+("."==n?".":n)+"])([0-9]*?[1-9]+)?(0)*$")),isNaN(t)?t:(i=new Number(t),i.html=Globalize.format(t+"","n10").replace(CellTypeHandlers.endOfNumber,function(e,t,n){return(n?t:"")+(n||"")}),i)}},t.ColumnContextMenu=function(){function e(e,t){this.wickedGrid=e,this.menu=t}return e.prototype={kill:function(){return null!==this.menu.parentNode&&this.menu.parentNode.removeChild(this.menu),this},show:function(e,t){this.wickedGrid.hideMenus();var n=this.wickedGrid,i=this.menu,r=i.style;return r.left=e-5+"px",r.top=t-5+"px",n.pane().appendChild(i),this},hide:function(){return null===this.menu.parentNode?this:(this.menu.parentNode.removeChild(this.menu),this)}},e}(),t.columnFreezer=function(e){if(!e.settings.freezableCells)return!1;if(e.isBusy())return!1;var t=e.pane(),n=t.actionUI,i=t.tBody,r=n.frozenAt,l=n.scrolledArea;if(!(l.col<=r.col+1))return!1;e.barHelper().remove();var s,o=i.children[0].children[r.col+1],a=t.getBoundingClientRect(),h=a.top+document.body.scrollTop,c=a.left+document.body.scrollLeft,u=document.createElement("div"),d=t.freezeHandleTop=$(u).appendTo(t).addClass(e.theme.columnFreezeHandle+" "+e.cl.barHelper+" "+e.cl.columnFreezeHandle).height(o.clientHeight-1).css("left",o.offsetLeft-u.clientWidth+"px").attr("title",e.msg.dragToFreezeCol);return e.controls.bar.helper[e.i]=e.barHelper().add(u),e.controls.bar.x.handleFreeze[e.i]=d,e.draggable(d,{axis:"x",start:function(){e.setBusy(!0),s=$(document.createElement("div")).css("position","absolute").addClass(e.theme.barFreezeIndicator+" "+e.cl.barHelper).height(o.clientHeight-1).fadeTo(0,.33).appendTo(t)},drag:function(){var e=d.nearest(o.parentNode.children).prev();e.length>0&&"function"==typeof e.position&&s.width(e.position().left+e.width())},stop:function(t,i){s.remove(),e.setBusy(!1),e.setDirty(!0);var r=$.nearest(d,o.parentNode.children);e.barHelper().remove(),l.col=n.frozenAt.col=Math.max(e.getTdLocation(r[0]).col-1,0),e.autoFillerHide()},containment:[c,h,c+t.clientWidth-window.scrollBarSize.width,h]}),!0},t.functions=function(e){function n(e){function n(e,t){return e=e?t?h.toNumbers(e):h.flatten(e):t?0:""}var r,l=this.wickedGrid,s=l.settings.loader,o=document.createElement("div"),a=this.td,c=document.body;c.appendChild(o),e=i({},e,{x:{legend:"",data:[0]},y:{legend:"",data:[0]},title:"",data:[0],legend:""}),o.className=t.cl.chart,o.onmousedown=function(){$(a).mousedown()},o.onmousemove=function(){return $(a).mousemove(),!1},e.data=n(e.data,!0),e.x.data=n(e.x.data,!0),e.y.data=n(e.y.data,!0),e.legend=n(e.legend),e.x.legend=n(e.x.legend),e.y.legend=n(e.y.legend),e.legend=e.legend?e.legend:e.data;var u=s.getWidth(this.sheetIndex,this.columnIndex),d=s.getHeight(this.sheetIndex,this.rowIndex),f=Raphael(o);switch(e.title&&f.text(u/2,10,e.title).attr({"font-size":20}),e.type){case"bar":r=f.barchart(u/8,d/8,.8*u,.8*d,e.data,e.legend).hover(function(){this.flag=f.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":r=f.hbarchart(u/8,d/8,.8*u,.8*d,e.data,e.legend).hover(function(){this.flag=f.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":r=f.linechart(u/8,d/8,.8*u,.8*d,e.x.data,e.y.data,{nostroke:!1,axis:"0 0 1 1",symbol:"circle",smooth:!0}).hoverColumn(function(){if(this.tags=f.set(),this.symbols.length)for(var e=0,t=this.y.length;e<t;e++)this.tags.push(f.tag(this.x,this.y[e],this.values[e],160,10).insertBefore(this).attr([{fill:"#fff"},{fill:this.symbols[e].attr("fill")
}]))},function(){this.tags&&this.tags.remove()});break;case"pie":r=f.piechart(u/2,d/2,(u<d?u:d)/2,e.data,{legend:e.legend}).hover(function(){this.sector.stop(),this.sector.scale(1.1,1.1,this.cx,this.cy),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"),this.label&&(this.label[0].animate({r:5},500,"bounce"),this.label[1].attr({"font-weight":400}))});break;case"dot":r=f.dotchart(u/8,d/8,.8*u,.8*d,e.x.data,e.y.data,e.data,{symbol:"o",max:10,heat:!0,axis:"0 0 1 1",axisxstep:e.x.data.length-1,axisystep:e.y.data.length-1,axisxlabels:e.x.legend?e.x.legend:e.x.data,axisylabels:e.y.legend?e.y.legend:e.y.data,axisxtype:" ",axisytype:" "}).hover(function(){this.marker=this.marker||f.tag(this.x,this.y,this.value,0,this.r+2).insertBefore(this),this.marker.show()},function(){this.marker&&this.marker.hide()})}return r.mousedown(function(){$(a).mousedown().mouseup()}),c.removeChild(o),o}e=e||function(){};var r={ISNUMBER:function(e){var t;return isNaN(e.valueOf())?(t=new Boolean(!1),t.html="FALSE",t):(t=new Boolean(!0),t.html="TRUE",t)},N:function(e){return null==e?0:e instanceof Date?e.getTime():("object"==typeof e&&(e=e.toString()),"string"==typeof e&&(e=parseFloat(e.replace(/[\$,\s]/g,""))),isNaN(e)?0:"number"==typeof e?e:1==e?1:0)},ABS:function(e){return Math.abs(r.N(e))},CEILING:function(e,t){return t=t||1,parseInt(e/t)*t+t},EVEN:function(e){e=Math.round(e);var t=e%2==0;return t||(e>0?e++:e--),e},EXP:function(e){return Math.exp(e)},FLOOR:function(e,t){if(t=t||1,e<0&&t>0||e>0&&t<0){var n=new Number(0);return n.html="#NUM",n}return e>=0?Math.floor(e/t)*t:Math.ceil(e/t)*t},INT:function(e){return Math.floor(r.N(e))},LN:function(e){return Math.log(e)},LOG:function(e,t){return t=t||10,Math.log(e)/Math.log(t)},LOG10:function(e){return r.LOG(e)},MOD:function(e,t){var n=e%t;return t<0&&(n*=-1),n},ODD:function(e){var t=!1;e>0?(e=Math.floor(Math.round(e)),t=!0):e=Math.ceil(e);var n=Math.abs(e);return n%2==0&&n++,t?n:-n},PI:function(){return Math.PI},POWER:function(e,t){return Math.pow(e,t)},SQRT:function(e){return Math.sqrt(e)},RAND:function(){return Math.random()},RND:function(){return Math.random()},ROUND:function(e,t){var n=Math.pow(10,t||0);return Math.round(e*n)/n},ROUNDDOWN:function(e,t){var n=e<0;return e=Math.abs(e),t=t||0,e=Math.floor(e*Math.pow(10,t))/Math.pow(10,t),n?-e:e},ROUNDUP:function(e,t){var n=e<0;return e=Math.abs(e),t=t||0,e=Math.ceil(e*Math.pow(10,t))/Math.pow(10,t),n?-e:e},SUM:function(){for(var e,t=0,n=h.flatten(arguments),i=0,r=n.length,l=isNaN;i<r;i++)if(e=n[i],null!==e&&void 0!==e&&(e=e.valueOf(),!l(e)))switch(typeof e){case"string":t+=1*e;break;default:t+=e}return t},TRUNC:function(e,t){return t=t||0,e+="",0==t?e.split(".").shift():(e.match(".")&&(1==t?e=e.substr(0,e.length-1):t==-1&&(e=e.split(".").shift(),e=e.substr(0,e.length-1)+"0")),e)},AVERAGE:function(){return r.SUM.apply(this,arguments)/r.COUNT.apply(this,arguments)},AVG:function(){return r.AVERAGE.apply(this,arguments)},COUNT:function(){var e=0,t=h.toNumbers(arguments),n=t.length-1;if(n<0)return e;do null!==t[n]&&e++;while(n--);return e},COUNTA:function(){var e=0,t=h.flatten(arguments),n=t.length-1;if(n<0)return e;do t[n]&&e++;while(n--);return e},MAX:function(){var e=h.toNumbers(arguments),t=e[0],n=e.length-1;if(n<0)return 0;do t=e[n]>t?e[n]:t;while(n--);return t},MIN:function(){var e=h.toNumbers(arguments),t=e[0],n=e.length-1;if(n<0)return 0;do t=e[n]<t?e[n]:t;while(n--);return t},ASC:function(e){return e.charCodeAt(0)},CHAR:function(e){return String.fromCharCode(e)},CLEAN:function(e){var t=new RegExp("[cGcLcJcMcIcK\f\n\r\t\v]","g");return e.replace(t,"")},CODE:function(e){return r.ASC(e)},CONCATENATE:function(){var e=h.flatten(arguments),t="";return jQuery.each(e,function(n){t+=e[n]}),t},DOLLAR:function(e,t,n){t=t||2,n=n||"$";var i=new Number(e),l=r.FIXED(e,t,!1);return e>=0?i.html=n+l:i.html="("+n+l.slice(1)+")",i},FIXED:function(e,t,n){t=void 0===t?2:t;var i,r=Math.pow(10,t),e=Math.round(e*r)/r;return i=new String(e.toFixed(t)),i.html=Globalize.format(e,"n"+t),n&&(i.html=i.html.replace(Globalize.culture().numberFormat[","],"")),i},LEFT:function(e,t){return e=e.valueOf().toString(),t=t||1,e.substring(0,t)},LEN:function(e){return e?e.length:0},LOWER:function(e){return e.toLowerCase()},MID:function(e,t,n){if(!e||!t||!n){var i=new Number(0);return i.html="ERROR",i}return e.substring(t-1,n+t-1)},REPLACE:function(e,t,n,i){if(!(e&&t&&n&&i)){var r=new String("");return r.html="ERROR",r}var r=e.split("");return r.splice(t-1,n),r.splice(t-1,0,i),r.join("")},REPT:function(e,t){for(var n="",i=0;i<t;i++)n+=e;return n},RIGHT:function(e,t){return t=t||1,e.substring(e.length-t,e.length)},SEARCH:function(e,t,n){n=n||0,n&&(t=t.split(""),t.splice(0,n-1),t=t.join(""));var i=t.search(e);if(i<0){var r=new String("");return r.html="#VALUE!",r}return n+(n?0:1)+i},SUBSTITUTE:function(e,t,n,i){i=i||0,t=new RegExp(t,"g");var r=1;return e=e.replace(t,function(e,t,l,s){var o=e;return i?r>=i&&(o=n):o=n,r++,o})},TEXT:function(e,t){return e},UPPER:function(e){return e.toUpperCase()},VALUE:function(e){if(jQuery.isNumeric(e))return e*=1;var t=new String("");return t.html="#VALUE!",t},NOW:function(){var e=new Date;return e.html=c.toString(e),e},TODAY:function(){var e=new Date,t=new Number(c.toCentury(e)-1);return t.html=c.toString(e,"d"),t},WEEKENDING:function(e){var t=new Date;return t=new Date(t.getFullYear(),t.getMonth(),t.getDate()+5-t.getDay()-7*(e||0)),t.html=c.toString(t,"d"),t},WEEKDAY:function(e,t){e=c.get(e);var n=e.getDay();switch(t=t?t:1){case 3:switch(n){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(n){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:n++}return n},WEEKNUM:function(e){return e=c.get(e),c.week(e)+1},YEAR:function(e){return e=c.get(e),e.getFullYear()},DAYSFROM:function(e,t,n){return Math.floor((new Date-new Date(e,t-1,n))/c.dayDiv)},DAYS:function(e,t){var n=c.get(e),i=c.get(t),r=864e5;return Math.round(Math.abs(n.getTime()-i.getTime())/r)},DAY:function(e){return e=c.get(e),e.getDate()},DAYS360:function(e,t,n){e=c.get(e),t=c.get(t);var i=e.getDate(),r=t.getDate(),l=c.isLastDayOfMonth(e),s=c.isLastDayOfMonth(t),o=c.diffMonths(e,t);return n?(i=Math.min(i,30),r=Math.min(r,30)):(l&&(i=30),s&&(i<30?(o++,r=1):r=30)),30*o+(r-i)},DATE:function(e,t,n){var i=new Date(e,t-1,n),r=new Number(c.toCentury(i));return r.html=c.toString(i,"d"),r},DATEVALUE:function(e){e=c.get(e);var t=new Number(c.toCentury(e));return t.html=c.toString(e,"d"),t},EDATE:function(e,t){e=c.get(e),e.setMonth(e.getMonth()+t);var n=new Number(c.toCentury(e));return n.html=c.toString(e,"d"),n},EOMONTH:function(e,t){e=c.get(e),e.setMonth(e.getMonth()+t+1),e=new Date(e.getFullYear(),e.getMonth(),0);var n=new Number(c.toCentury(e));return n.html=c.toString(e,"d"),n},HOUR:function(e){return e=u.fromMath(e),e.hour},MINUTE:function(e){return u.fromMath(e).minute},MONTH:function(e){return e=c.get(e),e.getMonth()+1},SECOND:function(e){return u.fromMath(e).second},TIME:function(e,t,n){if(n=n?n:0,t=t?t:0,e=e?e:0,n&&n>60){var i=1*(n/60+"").split(".")[0];n-=60*i,t+=i}if(t&&t>60){var r=1*(t/60+"").split(".")[0];t-=60*r,e+=r}var l=60*e*60*1e3+60*t*1e3+1e3*n;return l/c.dayDiv},TIMEVALUE:function(e){return isNaN(e)?/([0]?[1-9]|1[0-2])[:][0-5][0-9]([:][0-5][0-9])?[ ]?(AM|am|aM|Am|PM|pm|pM|Pm)/.test(e)?u.fromString(e,!0):/([0]?[0-9]|1[0-9]|2[0-3])[:][0-5][0-9]([:][0-5][0-9])?/.test(e)?u.fromString(e):0:e},WORKDAY:function(e,t,n){var i,r={1:!0,2:!0,3:!0,4:!0,5:!0},e=c.get(e),t=t&&!isNaN(t)?t:0,l=0,s=0,o=e;if(n){jQuery.isArray(n)||(n=[n]),n=h.flatten(n);var a={};jQuery.each(n,function(e){n[e]&&(a[c.toString(c.get(n[e]),"d")]=!0)}),n=a}else n={};for(;s<t;)o=new Date(o.setDate(o.getDate()+1)),r[o.getDay()]&&(n[c.toString(o,"d")]||s++),l++;return i=new Number(c.toCentury(o)),i.html=c.toString(o,"d"),i},YEARFRAC:function(e,t,n){if(e=c.get(e),t=c.get(t),!e||!t){var i=new String("");return i.html="#VALUE!",i}n=n?n:0,this.html=[];var r=c.diff(e,t,n),l=c.calcAnnualBasis(e,t,n);return r/l},AND:function(){for(var e,t=0,n=arguments.length;t<n;t++)if(e=arguments[t],void 0===e||void 0!==e.valueOf&&1!=e.valueOf()||1!=e)return r.FALSE();return r.TRUE()},FALSE:function(){var e=new Boolean(!1);return e.html="FALSE",e},IF:function(e,t,n){var i,r=e.valueOf();switch(typeof r){case"boolean":return r===!0?t:n;case"number":return 0!==r?t:n;case"string":if(i=r.toUpperCase(),"TRUE"===i)return t;if("FALSE"===i)return n;if(i.replace(/ /g,"").length>0)return t}return r?t:t},NOT:function(e){var t;return e.valueOf()?(t=new Boolean(!1),t.html="FALSE"):(t=new Boolean(!0),t.html="TRUE"),t},OR:function(){var e,t,n=arguments,i=n.length-1;if(i>-1)do if(t=n[i].valueOf())return e=new Boolean(!0),e.html="TRUE",e;while(i--);return e=new Boolean(!1),e.html="FALSE",e},TRUE:function(){var e=new Boolean(!0);return e.html="TRUE",e},GREATER:function(e,t){var n;return e>t?(n=new Boolean(!0),n.html="TRUE"):(n=new Boolean(!1),n.html="FALSE"),n},LESS:function(e,t){var n;return e<t?(n=new Boolean(!0),n.html="TRUE"):(n=new Boolean(!1),n.html="FALSE"),n},EQUAL:function(e,t){var n,i,r;return void 0!==e&&null!==e||(e=""),void 0!==t&&null!==t||(t=""),i=e+"",r=t+"",i==r?(n=new Boolean(!0),n.html="TRUE"):(n=new Boolean(!1),n.html="FALSE"),n},GREATER_EQUAL:function(e,t){var n;return e>=t?(n=new Boolean(!0),n.html="TRUE"):(n=new Boolean(!1),n.html="FALSE"),n},LESS_EQUAL:function(e,t){var n;return e<=t?(n=new Boolean(!0),n.html="TRUE"):(n=new Boolean(!1),n.html="FALSE"),n},IMG:function(e){var t=new String("");return t.html=$(document.createElement("img")).attr("src",e),t},TRIM:function(e){return"string"==typeof e&&(e=$.trim(e)),e},HYPERLINK:function(e,t){t=t||"LINK";var n=new String(t.valueOf()),i=document.createElement("a");return i.setAttribute("href",e),i.setAttribute("target","_new"),i.innerText=i.textContent=t,n.html=i,n},DROPDOWN:function(){var e,t,n,i,r,l,s,o=this,a=this.wickedGrid,c=this.td,u=0;if(null!==c&&($(c).children().detach(),n=o.value.html),void 0===n||o.needsUpdated||n.length<1){for(t=h.flatten(arguments),t=h.unique(t),null!==this.id?r=this.id+"-dropdown":null!==c&&(r="dropdown"+this.sheetIndex+"_"+this.rowIndex+"_"+this.columnIndex+"_"+a.I),i=document.createElement("select"),i.setAttribute("name",r),i.setAttribute("id",r),i.className="wg-dropdown",i.cell=this,i.onmouseup=function(){null!==this.cell.td&&a.cellEdit(this.cell)},i.onchange=function(){e=new String(this.value),e.html=i,e.cell=o,o.value=e,o.setNeedsUpdated(!1),a.resolveCell(o),a.trigger("sheetCellEdited",[o])},s=t.length<=50?t.length:50;u<s;u++)if(t[u]){var d=document.createElement("option");d.setAttribute("value",t[u]),d.text=d.innerText=t[u],i.appendChild(d)}a.settings.editable?a.settings.$element.bind("sheetKill",function(){c.innerText=c.textContent=o.value.valueOf()}):i.setAttribute("disabled",!0),i.value=o.value||t[0]}return l="object"!=typeof o.value?new String(o.value):o.value,l.html=i,l},RADIO:function(){var e,t,n,i,r,l=this,s=this.wickedGrid,o=this.td;if(null!==o&&(n=l.value.html,$(o).children().detach()),void 0===n||n.length<1||l.needsUpdated){e=h.flatten(arguments),e=h.unique(e),null!==this.id?i=this.id+"-radio":null!==o&&(i="radio"+this.sheetIndex+"_"+this.rowIndex+"_"+this.columnIndex+"_"+s.I),n=document.createElement("span"),n.className="wg-radio",n.onmousedown=function(){null!==this.cell.td&&s.cellEdit(l)},n.cell=l;for(var a=0;a<(e.length<=25?e.length:25);a++)if(e[a]){var c=document.createElement("input"),u=document.createElement("span");c.setAttribute("type","radio"),c.setAttribute("name",i),c.className=i,c.value=e[a],s.settings.editable||c.setAttribute("disabled","disabled"),c.onchange=function(){t=new String(this.value),t.html=n,t.cell=l,l.value=t,l.setNeedsUpdated(!1),s.resolveCell(l),s.trigger("sheetCellEdited",[l])},e[a].valueOf()===l.value.valueOf()&&(c.checked=!0),u.textContent=u.innerText=e[a],n.appendChild(c),u.input=c,u.onmousedown=function(){$(this.input).click()},n.appendChild(u),n.appendChild(document.createElement("br"))}s.settings.$element.bind("sheetKill",function(){o.textContent=o.innerText=l.value.valueOf()})}return r="object"!=typeof l.value?new String(l.value):l.value,r.html=n,r},CHECKBOX:function(e){$.isArray(e)&&(e=e[0]);var t,n,i,r,l,s,o=this,a=this.wickedGrid,h=this.td;if(null!==h&&(t=o.value.html,$(h).children().detach()),void 0===t||t.length<1||o.needsUpdated)switch(null!==this.id?r=this.id+"-checkbox":null!==h&&(r="checkbox"+this.sheetIndex+"_"+this.rowIndex+"_"+this.columnIndex+"_"+a.I),i=document.createElement("input"),i.setAttribute("type","checkbox"),i.setAttribute("name",r),i.setAttribute("id",r),i.className=r,i.value=e,i.onchange=function(){l=this.checked?new String(e):new String(""),l.html=t,l.cell=o,o.value=l,o.setNeedsUpdated(!1),a.resolveCell(o),a.trigger("sheetCellEdited",[o])},a.settings.editable?a.settings.$element.bind("sheetKill",function(){o.value="true"==o.value||i.checked?e:"",null!==o.td&&(o.td.innerText=o.td.textContent=o.value.valueOf())}):i.setAttribute("disabled","true"),t=document.createElement("span"),t.className="wg-checkbox",t.appendChild(i),n=document.createElement("span"),n.textContent=n.innerText=e,t.appendChild(n),t.appendChild(document.createElement("br")),t.onmousedown=function(){null!==this.cell.td&&a.cellEdit(this.cell)},t.cell=o,o.value.valueOf()){case e.valueOf():case"true":i.checked=!0}return s="true"===o.value||i.checked?new String(e):new String(""),s.html=t,s},BARCHART:function(e,t,i){var r=new String("");return r.html=n.call(this,{type:"bar",data:e,legend:t,title:i}),r},HBARCHART:function(e,t,i){var r=new String("");return r.html=n.call(this,{type:"hbar",data:e,legend:t,title:i}),r},LINECHART:function(e,t){var i=new String("");return i.html=n.call(this,{type:"line",x:{data:e},y:{data:t},title:""}),i},PIECHART:function(e,t,i){var r=new String("");return r.html=n.call(this,{type:"pie",data:e,legend:t,title:i}),r},DOTCHART:function(e,t,i,r,l,s){var o=new String("");return o.html=n.call(this,{type:"dot",data:i?i:e,x:{data:e,legend:r},y:{data:t?t:e,legend:l?l:r},title:s}),o},CELLREF:function(e){var t=this.wickedGrid;return t.spreadsheets[e]?t.spreadsheets[e]:"Cell Reference Not Found"},HLOOKUP:function(e,t,n,i){if(void 0===e)return null;var r,l,s=this.wickedGrid,o="",a=0,c=t.length;if(n=n||1,i=void 0===i||i,void 0!==e||isNaN(e)&&"#REF!"!=e||0===e.length){for(;a<c;a++)if(t[a].toString()==e){r=t[a];break}}else h.getClosestNum(e,t,function(t,n){i?r=t:t==e&&(r=t)});return void 0!==r?(l=r.cell,l=s.getCell(l.sheetIndex,n,l.columnIndex),o=null!==l?l.updateValue():""):(o=new String,o.html="#N/A"),o},VLOOKUP:function(e,t,n,i){if(void 0===e)return null;var r,l,s,o=this.wickedGrid,a=0,c=t.length;if(i=void 0===i||i,isNaN(e)&&"#REF!"!=e||0===e.length){for(;a<c;a++)if(t[a].toString()==e){r=t[a];break}}else h.getClosestNum(e,t,function(t,n){i?r=t:t==e&&(r=t)});return void 0!==r?(l=r.cell,l=o.getCell(l.sheetIndex,l.rowIndex,n),s=null!==l?l.value:""):(s=new String,s.html="#N/A"),s},TRANSPOSE:function(e){for(var t,n,i,r,l,s,o=0,a=this.wickedGrid,h=(this.sheetIndex,e[0]),c=h.cell,u=e[e.length-1],d=(u.cell,c.rowIndex),f=c.columnIndex,p=[],m=[],g=e.length,w=!1;o<g;o++)l=e[o],i=l.cell,t=this.rowIndex+(i.columnIndex-f),n=this.columnIndex+(i.rowIndex-d),r=a.getCell(this.sheetIndex,t,n),null!==r&&r!==this&&(""!=r.value&&(w=!0),m.push(r),p.push(i));if(w)return s=new String(""),s.html="#REF!",s;for(o=0,g=m.length;o<g;o++)r=m[o],r!==this&&(i=p[o],r.setNeedsUpdated(),r.defer=i,r.updateValue(),r.addDependency(this));return h.valueOf()},THISROWCELL:function(e){var t=this.wickedGrid;return isNaN(e)&&(e=t.cellHandler.columnLabelIndex(e)),t.getCell(this.sheetIndex,this.rowIndex,e).updateValue()},THISCOLCELL:function(e){var t=this.wickedGrid;return t.getCell(this.sheetIndex,e,this.columnIndex).updateValue()}};return r}(),t.Highlighter=function(){var e=function(e,t,n,i){this.cellCssClass=e.split(/[\s]/),this.barCssClass=t.split(/[\s]/),this.tabsCssClass=n.split(/[\s]/),this.callBack=i,this.last=[],this.lastTop=$([]),this.lastLeft=$([]),this.lastTab=$([]),this.startRowIndex=0,this.startColumnIndex=0,this.endRowIndex=0,this.endColumnIndex=0};return e.prototype={cell:function(e){return this.cellCssClass.forEach(function(t){e.addClass(t)}),this.last.push(e),this},off:function(){for(;this.last.length>0;){var e=this.last.pop();switch(e.type){case t.Cell:this.cellCssClass.forEach(function(t){e.removeClass(t)});break;default:this.cellCssClass.forEach(function(t){e.removeClass(t)})}}return this},set:function(e){void 0!==e.parentNode&&(e=[e]);var t,n,i=this.last;if(i&&i.length>0){t=i.length-1;do i[t].isHighlighted=!1;while(t-- >0)}if(e.length>0){t=e.length-1;do n=e[t],n.isHighlighted||(n.isHighlighted=!0,this.cellCssClass.forEach(function(e){n.className.match(e)||(n.className+=" "+e)}));while(t-- >0)}return this.clear(i),this.last=e,this.callBack(),this},is:function(){return this.last.length>0},clear:function(e){if(this.is()&&(e=e||this.last,e&&e.length)){var t=e.length-1;do e[t].isHighlighted||(this.cellCssClass.forEach(function(n){e[t].className=e[t].className.replace(n,"")}),e[t].isHighlighted=!1);while(t-- >0)}return this.last=$([]),this},setBar:function(e,t){var n=this;switch(e){case"top":this.barCssClass.forEach(function(e){n.lastTop.removeClass(e),n.lastTop=$(t).addClass(e)});break;case"left":this.barCssClass.forEach(function(e){n.lastLeft.removeClass(e),n.lastLeft=$(t).addClass(e)})}return this},clearBar:function(){var e=this;return this.barCssClass.forEach(function(t){e.lastTop.removeClass(t),e.lastLeft.removeClass(t)}),this.lastTop=$([]),this.lastLeft=$([]),this},setTab:function(e){var t=this;return this.clearTab(),this.tabsCssClass.forEach(function(n){t.lastTab=e.addClass(n)}),this},clearTab:function(){var e=this;return this.tabsCssClass.forEach(function(t){e.lastTab.removeClass(t)}),this},setStart:function(e){return this.startRowIndex=e.rowIndex+0,this.startColumnIndex=e.columnIndex+0,this},setEnd:function(e){return this.endRowIndex=e.rowIndex+0,this.endColumnIndex=e.columnIndex+0,this}},e}(),t.SpreadsheetUI=function(){function e(e,t,n){n=n||{},this.i=e,this.ui=t,this.isLast=n.lastIndex===e,this.enclosure=null,this.pane=null,this.spreadsheet=null,this.initChildren=n.initChildren||function(){},this.done=n.done||function(){},this.load()}var t=[];return e.prototype={load:function(e,n,i){this.initChildren(this.ui,this.i),this.enclosure=e,this.pane=n,this.spreadsheet=i,t.push(this.i),this.isLast&&this.loaded()},loaded:function(){this.done(t,this)}},e}(),t.RowContextMenu=function(){function e(e,t){this.wickedGrid=e,this.menu=t}return e.prototype={show:function(e,t){this.wickedGrid.hideMenus();var n=this.wickedGrid,i=this.menu,r=i.style;return r.left=e-5+"px",r.top=t-5+"px",n.pane().appendChild(i),this},hide:function(){var e=this.menu;return null===e.parentNode?this:(e.parentNode.removeChild(e),this)}},e}(),t.rowFreezer=function(e,t,n){if(e.isBusy())return!1;var n=e.pane(),i=n.actionUI,r=(n.table,n.tBody),l=i.frozenAt,s=i.scrolledArea;if(!(s.row<=l.row+1))return!1;e.barHelper().remove();var o,a=r.children[l.row+1].children[0],h=n.getBoundingClientRect(),c=h.top+document.body.scrollTop,u=h.left+document.body.scrollLeft,d=document.createElement("div"),f=n.freezeHandleLeft=$(d).appendTo(n).addClass(e.theme.rowFreezeHandle+" "+e.cl.barHelper+" "+e.cl.rowFreezeHandle).width(a.clientWidth).css("top",a.offsetTop-d.clientHeight+1+"px").attr("title",e.msg.dragToFreezeRow);return e.controls.bar.helper[e.i]=e.barHelper().add(d),e.controls.bar.y.handleFreeze[e.i]=f,e.draggable(f,{axis:"y",start:function(){e.setBusy(!0),o=$(document.createElement("div")).appendTo(n).css("position","absolute").addClass(e.theme.barFreezeIndicator+" "+e.cl.barHelper).width(d.clientWidth).fadeTo(0,.33)},drag:function(){var e=f.nearest(a.parentNode.parentNode.children).prev();e.length&&e.position&&o.height(e.position().top+e.height())},stop:function(t,n){o.remove(),e.setBusy(!1).setDirty(!0);var r=$.nearest(f,a.parentNode.parentNode.children);e.barHelper().remove(),s.row=i.frozenAt.row=Math.max(e.getTdLocation(r.children(0)[0]).row-1,0),e.autoFillerHide()},containment:[u,c,u,c+n.clientHeight-window.scrollBarSize.height]}),!0},t.Theme=function(){function e(n){switch(n=n||t.defaultTheme){case t.customTheme:this.cl=e.customClasses;break;case t.bootstrapTheme:this.cl=e.bootstrapClasses;break;default:case t.themeRollerTheme:this.cl=e.themeRollerClasses}i(this,this.cl)}return e.themeRollerClasses={autoFiller:"ui-state-active",bar:"ui-widget-header",barHighlight:"ui-state-active",rowFreezeHandle:"ui-state-default",columnFreezeHandle:"ui-state-default",columnMenu:"ui-state-default",columnMenuIcon:"ui-icon ui-icon-triangle-1-s",tdActive:"ui-state-active",tdHighlighted:"ui-state-highlight",control:"ui-widget-header ui-corner-top",controlTextBox:"ui-widget-content",fullScreen:"ui-widget-content ui-corner-all",inPlaceEdit:"ui-state-highlight",menu:"ui-widget-header",menuFixed:"",menuUl:"ui-widget-header",menuLi:"ui-widget-header",menuHover:"ui-state-highlight",pane:"ui-widget-content",parent:"ui-widget-content ui-corner-all",table:"ui-widget-content",tab:"ui-widget-header",tabActive:"ui-state-highlight",barResizer:"ui-state-highlight",barFreezer:"ui-state-highlight",barFreezeIndicator:"ui-state-highlight"},e.bootstrapClasses={autoFiller:"btn-info",bar:"input-group-addon",barHighlight:"label-info",rowFreezeHandle:"bg-warning",columnFreezeHandle:"bg-warning",columnMenu:"",columnMenuIcon:"fa fa-sort-desc",tdActive:"active",tdHighlighted:"bg-info disabled",control:"panel-heading",controlTextBox:"form-control",fullScreen:"",inPlaceEdit:"form-control",menu:"panel panel-default",menuFixed:"nav navbar-nav",menuUl:"panel-info",menuLi:"active",menuHover:"bg-primary active",pane:"well",parent:"panel panel-default",table:"table-bordered table-condensed",tab:"btn-default btn-xs",tabActive:"active",barResizer:"bg-info",barFreezer:"bg-warning",barFreezeIndicator:"bg-warning"},e.customClasses={autoFiller:"",bar:"",barHighlight:"",rowFreezeHandle:"",columnFreezeHandle:"",columnMenu:"",columnMenuIcon:"",tdActive:"",tdHighlighted:"",control:"",controlTextBox:"",fullScreen:"",inPlaceEdit:"",menu:"",menuFixed:"",menuUl:"",menuLi:"",menuHover:"",pane:"",parent:"",table:"",tab:"",tabActive:"",barResizer:"",barFreezer:"",barFreezeIndicator:""},e}(),t.Undo=function(){function e(){}function n(t){this.wickedGrid=t,this.cells=[],this.id=-1,"undefined"!=typeof UndoManager?this.undoManager=new UndoManager:this.undoManager={add:e,undo:e,redo:e,register:e}}return n.prototype={createCells:function(e,n,i){"undefined"==typeof i&&(this.id++,i=this.id);var r=this,l=new t.CellRange(e).clone().cells,s="function"==typeof n?new t.CellRange(n(e)).clone().cells:l;return l.id=i,s.id=i,this.undoManager.add({undo:function(){r.removeCells(l,i)},redo:function(){r.createCells(s,null,i)}}),i!==this.id&&this.draw(s),!0},removeCells:function(e,t){var n=0,i=-1;e.id===t&&(i=n),i!==-1&&this.cells.splice(i,1),this.draw(e)},draw:function(e){var t,n,i,r,l=this.wickedGrid;for(t=0;t<e.length;t++)n=e[t],r=l.getTdLocation(n.td),i=n.clone(),l.spreadsheets[n.sheetIndex][r.row][r.col]=i,i.setNeedsUpdated(),i.updateValue();l.pane().actionUI.redrawColumns(),l.pane().actionUI.redrawRows()}},n}(),i($.fn,{wickedGrid:function(e){e=e||{};for(var n in t.defaults)t.defaults.hasOwnProperty(n)&&(e[n]=e.hasOwnProperty(n)?e[n]:t.defaults[n]);return $(this).each(function(){var n=this,i=$(this),r=i.getWickedGrid();if(e.useStack=void 0!==window.thaw&&e.useStack,e.useMultiThreads=void 0!==window.operative&&e.useMultiThreads,r){var l=i.children().detach();r.kill(),i.html(l),t.events.forEach(i.unbind)}e.element=n,e.$element=i,null!=(this.className||"").match(/\bnot-editable\b/i)&&(e.editable=!1),t.events.forEach(function(t){i.bind(t,e[t])}),i.children().each(function(t){var n=1*this.getAttribute("data-frozenatrow"),i=1*this.getAttribute("data-frozenatcol");e.frozenAt[t]||(e.frozenAt[t]={row:0,col:0}),n&&(e.frozenAt[s.i].row=n),i&&(e.frozenAt[s.i].col=i)});var s=new t(e)}),this},disableSelectionSpecial:function(){return this.each(function(){this.onselectstart=function(){return!1},this.unselectable="on",this.style["-moz-user-select"]="none"}),this},getWickedGrid:function(){var e=null;return t.instances.forEach(function(t){e||t.parent!==parent||(e=t)}),e},getCellValue:function(e,t,n,i){var r,l=$(this).getWickedGrid();return l?(r=l.getCell(e,t,n),null!==r&&r.updateValue(i),this):this},setCellValue:function(e,t,n,i,r){var l,s=$(this).getWickedGrid();return s?(i=i||0,(l=s.getCell(i,t,n))?("string"==typeof e&&"="===e.charAt(0)?(l.valueOverride=l.value="",l.formula=e.substring(1)):(l.value=e,l.valueOverride=l.formula=""),l.updateValue(r),this):this):this},setCellFormula:function(e,t,n,i,r){var l,s=$(this).getWickedGrid();return i=i||0,s?(l=s.getCell(i,t,n),null===l?this:(l.formula=e,l.valueOverride=l.value="",l.updateValue(r),this)):this},isSheetFullScreen:function(){var e=$(this).getWickedGrid();return!!e&&e.fullScreen().is(":visible")},serializeCellInputs:function(e){var t=$(this).wickedGrid(),n=t.obj.tables().find(":input");return e?n.serializeArray():n.serialize()},viewSource:function(e){var t="";return $(this).each(function(){t+=e?$(this).toPrettySource():$(this).toCompactSource()}),$.printSource(t),t},toCompactSource:function(){var e=this[0],t="";if(1==e.nodeType){t+="<"+e.tagName.toLowerCase();for(var n=e.attributes.length,i=0;i<n;i++){var r=e.attributes[i].name,l=e.getAttribute(r);if(l){if("contentEditable"==r&&"inherit"==l)continue;"string"==typeof l?t+=" "+r+'="'+l.replace(/"/g,"'")+'"':"style"==r&&l.cssText&&(t+=' style="'+l.cssText+'"')}}if("COL"==e.tagName)t+="/>";else{t+=">";var s="";$(e.childNodes).each(function(){s+=$(this).toCompactSource()}),t+=s,t+="</"+e.tagName.toLowerCase()+">"}}else 3==e.nodeType&&(t+=e.data.replace(/^\s*(.*)\s*$/g,"$1"));return t},toPrettySource:function(e){var t,n,i=this[0],r="";if(e=e||"",1==i.nodeType){for(r+="\n"+e+"<"+i.tagName.toLowerCase(),t=i.attributes.length,n=0;n<t;n++){var l=i.attributes[n].name,s=i.getAttribute(l);if(s){if("contentEditable"==l&&"inherit"==s)continue;"string"==typeof s?r+=" "+l+'="'+$.trim(s.replace(/"/g,"'"))+'"':"style"==l&&s.cssText&&(r+=' style="'+$.trim(s.cssText)+'"')}}if(i.childNodes.length<=0)r+="COL"==i.tagName?"/>":"></"+i.tagName.toLowerCase()+">";else{r+=">";var o="";for(t=i.childNodes.length,n=0;n<t;n++)o+=$(i.childNodes[n]).toPrettySource(e+" ");r+=o,o.indexOf("\n")>=0&&(r+="\n"+e),r+="</"+i.tagName.toLowerCase()+">"}}else 3==i.nodeType&&(r+=i.data.replace(/^\s*(.*)\s*$/g,"$1"));return r}}),void 0===Object.getPrototypeOf&&(Object.getPrototypeOf=function(e){return e||{}}),void 0===Array.prototype.indexOf&&(Array.prototype.indexOf=function(e,t){for(var n=t||0,i=this.length;n<i;n++)if(this[n]===e)return n;return-1}),t}();"undefined"!=typeof module&&(module.exports=WickedGrid);var parser=function(){function e(){this.yy={}}var t=function(e,t,n,i){for(n=n||{},i=e.length;i--;n[e[i]]=t);return n},n=[1,5],i=[1,6],r=[1,8],l=[1,9],s=[1,10],o=[1,13],a=[1,11],h=[1,12],c=[1,14],u=[1,15],d=[1,20],f=[1,18],p=[1,21],m=[1,22],g=[1,17],w=[1,24],v=[1,25],y=[1,26],b=[1,27],C=[1,28],x=[1,29],E=[1,30],I=[1,31],T=[1,32],S=[4,13,14,15,17,18,19,20,21,22,23,35,36],A=[1,35],k=[1,36],N=[1,37],R=[4,13,14,15,17,18,19,20,21,22,23,35,36,38],F=[4,13,14,15,17,18,19,20,21,22,23,35,36,39],L=[4,13,14,15,17,18,19,20,21,22,23,29,35,36],M=[4,14,15,17,18,19,20,35,36],_=[1,71],O=[4,14,17,18,19,35,36],$=[4,14,15,17,18,19,20,21,22,35,36],H=[17,35,36],z={trace:function(){},yy:{},symbols_:{error:2,expressions:3,EOF:4,expression:5,variableSequence:6,TIME_AMPM:7,TIME_24:8,number:9,STRING:10,ESCAPED_STRING:11,LETTERS:12,"&":13,"=":14,"+":15,"(":16,")":17,"<":18,">":19,"-":20,"*":21,"/":22,"^":23,E:24,FUNCTION:25,expseq:26,cellRange:27,cell:28,":":29,SHEET:30,"!":31,NUMBER:32,$:33,REF:34,";":35,",":36,VARIABLE:37,DECIMAL:38,"%":39,$accept:0,$end:1},terminals_:{2:"error",4:"EOF",7:"TIME_AMPM",8:"TIME_24",10:"STRING",11:"ESCAPED_STRING",12:"LETTERS",13:"&",14:"=",15:"+",16:"(",17:")",18:"<",19:">",20:"-",21:"*",22:"/",23:"^",24:"E",25:"FUNCTION",29:":",30:"SHEET",31:"!",32:"NUMBER",33:"$",34:"REF",35:";",36:",",37:"VARIABLE",38:"DECIMAL",39:"%"},productions_:[0,[3,1],[3,2],[5,1],[5,1],[5,1],[5,1],[5,1],[5,1],[5,1],[5,3],[5,3],[5,3],[5,3],[5,4],[5,4],[5,4],[5,3],[5,3],[5,3],[5,3],[5,3],[5,3],[5,2],[5,2],[5,1],[5,3],[5,4],[5,1],[27,1],[27,3],[27,3],[27,5],[28,2],[28,3],[28,3],[28,4],[28,1],[28,2],[28,2],[28,2],[28,3],[28,3],[28,3],[28,3],[28,3],[28,3],[28,4],[28,4],[28,4],[26,1],[26,2],[26,2],[26,3],[26,3],[6,1],[6,3],[9,1],[9,3],[9,2]],performAction:function(e,t,n,i,r,l,s){var o=l.length-1;switch(r){case 1:return null;case 2:var a=i.types;return i.types=[],a;case 3:var h={t:"m",m:"variable",a:[l[o]]};this.$=i.types.length,i.types.push(h);break;case 4:var h={t:"m",m:"time",a:[l[o],!0]};this.$=i.types.length,i.types.push(h);break;case 5:var h={t:"m",m:"time",a:[l[o]]};this.$=i.types.length,i.types.push(h);break;case 6:var h={t:"m",m:"number",a:[l[o]]};this.$=i.types.length,i.types.push(h);break;case 7:var h={t:"v",v:i.escape(l[o].substring(1,l[o].length-1))};this.$=i.types.length,i.types.push(h);break;case 8:var h={t:"v",v:i.escape(l[o].substring(2,l[o].length-2))};this.$=i.types.length,i.types.push(h);break;case 9:var h={t:"v",v:l[o]};i.types.push(h);break;case 10:var h={t:"m",m:"concatenate",a:[l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 11:var h={t:"m",m:"callFunction",a:["EQUAL",[l[o-2],l[o]]]};this.$=i.types.length,i.types.push(h);break;case 12:var h={t:"m",m:"performMath",a:["+",l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 13:this.$=l[o-1];break;case 14:var h={t:"m",m:"callFunction",a:["LESS_EQUAL",[l[o-3],l[o]]]};this.$=i.types.length,i.types.push(h);break;case 15:var h={t:"m",m:"callFunction",a:["GREATER_EQUAL",[l[o-3],l[o]]]};this.$=i.types.length,i.types.push(h);break;case 16:var h={t:"m",m:"not",a:[l[o-3],l[o]]};this.$=i.types.length,i.types.push(h);break;case 17:var h={t:"m",m:"callFunction",a:["GREATER",[l[o-2],l[o]]]};this.$=i.types.length,i.types.push(h);break;case 18:var h={t:"m",m:"callFunction",a:["LESS",[l[o-2],l[o]]]};this.$=i.types.length,i.types.push(h);break;case 19:var h={t:"m",m:"performMath",a:["-",l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 20:var h={t:"m",m:"performMath",a:["*",l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 21:var h={t:"m",m:"performMath",a:["/",l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 22:var h={t:"m",m:"performMath",a:["^",l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 23:var h={t:"m",m:"invertNumber",a:[l[o]]};this.$=i.types.length,i.types.push(h);break;case 24:var h={t:"m",m:"number",a:[l[o]]};this.$=i.types.length,i.types.push(h);break;case 25:break;case 26:var h={t:"m",m:"callFunction",a:[l[o-2]]};this.$=i.types.length,i.types.push(h);break;case 27:var h={t:"m",m:"callFunction",a:[l[o-3],l[o-1]]};this.$=i.types.length,i.types.push(h);break;case 29:var h={t:"l",m:"cellValue",a:[l[o]]};this.$=i.types.length,i.types.push(h);break;case 30:var h={t:"l",m:"cellRangeValue",a:[l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 31:var h={t:"l",m:"remoteCellValue",a:[l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 32:var h={t:"l",m:"remoteCellRangeValue",a:[l[o-4],l[o-2],l[o]]};this.$=i.types.length,i.types.push(h);break;case 33:var h={t:"cell",c:l[o-1],r:l[o]};this.$=i.types.length,i.types.push(h);break;case 34:var h={t:"cell",c:l[o-1],r:l[o]};this.$=i.types.length,i.types.push(h);break;case 35:case 36:var h={t:"cell",c:l[o-2],r:l[o]};this.$=i.types.length,i.types.push(h);break;case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:case 47:case 48:case 49:return"#REF!";case 50:this.$=[l[o]];break;case 53:l[o-2].push(l[o]),this.$=l[o-2];break;
case 54:l[o-2].push(l[o]),this.$=l[o-2];break;case 55:this.$=[l[o]];break;case 56:this.$=l[o-2]instanceof Array?l[o-2]:[l[o-2]],this.$.push(l[o]);break;case 57:this.$=l[o];break;case 58:this.$=l[o-2]+"."+l[o];break;case 59:this.$=.01*l[o-1]+""}},table:[{3:1,4:[1,2],5:3,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{1:[3]},{1:[2,1]},{4:[1,23],13:w,14:v,15:y,18:b,19:C,20:x,21:E,22:I,23:T},t(S,[2,3],{38:[1,33]}),t(S,[2,4]),t(S,[2,5]),t(S,[2,6],{39:[1,34]}),t(S,[2,7]),t(S,[2,8]),t(S,[2,9],{32:A,33:k,34:N}),{5:38,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:39,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:40,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},t(S,[2,25]),{16:[1,41]},t(S,[2,28]),t(R,[2,55]),t(F,[2,57],{38:[1,42]}),t(S,[2,29],{29:[1,43]}),{31:[1,44]},{12:[1,45],34:[1,46]},t(L,[2,37],{32:[1,47],33:[1,49],34:[1,48]}),{1:[2,2]},{5:50,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:51,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:52,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:55,6:4,7:n,8:i,9:7,10:r,11:l,12:s,14:[1,53],15:o,16:a,19:[1,54],20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:57,6:4,7:n,8:i,9:7,10:r,11:l,12:s,14:[1,56],15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:58,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:59,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:60,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:61,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{37:[1,62]},t(F,[2,59]),t(L,[2,33]),{32:[1,63],34:[1,64]},t(L,[2,39]),{13:w,14:v,15:y,17:[1,65],18:b,19:C,20:x,21:E,22:I,23:T},t(M,[2,23],{13:w,21:E,22:I,23:T}),t(M,[2,24],{13:w,21:E,22:I,23:T}),{5:68,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,17:[1,66],20:h,24:c,25:u,26:67,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{32:[1,69]},{12:_,28:70,33:p,34:m},{12:_,28:72,33:p,34:m},{32:[1,73],33:[1,74],34:[1,75]},{32:[1,76],33:[1,78],34:[1,77]},t(L,[2,38]),t(L,[2,40]),{32:[1,79],34:[1,80]},t([4,17,35,36],[2,10],{13:w,14:v,15:y,18:b,19:C,20:x,21:E,22:I,23:T}),t([4,14,17,35,36],[2,11],{13:w,15:y,18:b,19:C,20:x,21:E,22:I,23:T}),t(M,[2,12],{13:w,21:E,22:I,23:T}),{5:81,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},{5:82,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},t(O,[2,18],{13:w,15:y,20:x,21:E,22:I,23:T}),{5:83,6:4,7:n,8:i,9:7,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,27:16,28:19,30:d,32:f,33:p,34:m,37:g},t(O,[2,17],{13:w,15:y,20:x,21:E,22:I,23:T}),t(M,[2,19],{13:w,21:E,22:I,23:T}),t($,[2,20],{13:w,23:T}),t($,[2,21],{13:w,23:T}),t([4,14,15,17,18,19,20,21,22,23,35,36],[2,22],{13:w}),t(R,[2,56]),t(L,[2,35]),t(L,[2,45]),t(S,[2,13]),t(S,[2,26]),{17:[1,84],35:[1,85],36:[1,86]},t(H,[2,50],{13:w,14:v,15:y,18:b,19:C,20:x,21:E,22:I,23:T}),t(F,[2,58]),t(S,[2,30]),{32:A,33:k,34:N},t(S,[2,31],{29:[1,87]}),t(L,[2,34]),{32:[1,88]},t(L,[2,42]),t(L,[2,41]),t(L,[2,43]),{32:[1,89],34:[1,90]},t(L,[2,44]),t(L,[2,46]),t(O,[2,14],{13:w,15:y,20:x,21:E,22:I,23:T}),t(O,[2,16],{13:w,15:y,20:x,21:E,22:I,23:T}),t(O,[2,15],{13:w,15:y,20:x,21:E,22:I,23:T}),t(S,[2,27]),t(H,[2,51],{6:4,9:7,27:16,28:19,5:91,7:n,8:i,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,30:d,32:f,33:p,34:m,37:g}),t(H,[2,52],{6:4,9:7,27:16,28:19,5:92,7:n,8:i,10:r,11:l,12:s,15:o,16:a,20:h,24:c,25:u,30:d,32:f,33:p,34:m,37:g}),{12:_,28:93,33:p,34:m},t(L,[2,36]),t(L,[2,47]),t(L,[2,49]),t(H,[2,53],{13:w,14:v,15:y,18:b,19:C,20:x,21:E,22:I,23:T}),t(H,[2,54],{13:w,14:v,15:y,18:b,19:C,20:x,21:E,22:I,23:T}),t(S,[2,32])],defaultActions:{2:[2,1],23:[2,2]},parseError:function(e,t){if(!t.recoverable)throw new Error(e);this.trace(e)},parse:function(e){function t(e){l.length=l.length-2*e,s.length=s.length-e,o.length=o.length-e}function n(){var e;return e=g.lex()||p,"number"!=typeof e&&(e=r.symbols_[e]||e),e}function i(e){for(var t=l.length-1,n=0;;){if(f.toString()in a[e])return n;if(0===e||t<2)return!1;t-=2,e=l[t],++n}}var r=this,l=[0],s=[null],o=[],a=this.table,h="",c=0,u=0,d=0,f=2,p=1,m=o.slice.call(arguments,1),g=Object.create(this.lexer),w={yy:{}};for(var v in this.yy)Object.prototype.hasOwnProperty.call(this.yy,v)&&(w.yy[v]=this.yy[v]);g.setInput(e,w.yy),w.yy.lexer=g,w.yy.parser=this,"undefined"==typeof g.yylloc&&(g.yylloc={});var y=g.yylloc;o.push(y);var b=g.options&&g.options.ranges;"function"==typeof w.yy.parseError?this.parseError=w.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var C,x,E,I,T,S,A,k,N,R={};;){if(E=l[l.length-1],this.defaultActions[E]?I=this.defaultActions[E]:(null!==C&&"undefined"!=typeof C||(C=n()),I=a[E]&&a[E][C]),"undefined"==typeof I||!I.length||!I[0]){var F,L="";if(!d){F=i(E),N=[];for(S in a[E])this.terminals_[S]&&S>f&&N.push("'"+this.terminals_[S]+"'");return L=g.showPosition?"Parse error on line "+(c+1)+":\n"+g.showPosition()+"\nExpecting "+N.join(", ")+", got '"+(this.terminals_[C]||C)+"'":"Parse error on line "+(c+1)+": Unexpected "+(C==p?"end of input":"'"+(this.terminals_[C]||C)+"'"),this.parseError(L,{text:g.match,token:this.terminals_[C]||C,line:g.yylineno,loc:y,expected:N,recoverable:F!==!1})}if(x!==p&&(F=i(E)),3==d){if(C===p||x===p)throw new Error(L||"Parsing halted while starting to recover from another error.");u=g.yyleng,h=g.yytext,c=g.yylineno,y=g.yylloc,C=n()}if(F===!1)throw new Error(L||"Parsing halted. No suitable error recovery rule available.");t(F),x=C==f?null:C,C=f,E=l[l.length-1],I=a[E]&&a[E][f],d=3}if(I[0]instanceof Array&&I.length>1)throw new Error("Parse Error: multiple actions possible at state: "+E+", token: "+C);switch(I[0]){case 1:l.push(C),s.push(g.yytext),o.push(g.yylloc),l.push(I[1]),C=null,x?(C=x,x=null):(u=g.yyleng,h=g.yytext,c=g.yylineno,y=g.yylloc,d>0&&d--);break;case 2:if(A=this.productions_[I[1]][1],R.$=s[s.length-A],R._$={first_line:o[o.length-(A||1)].first_line,last_line:o[o.length-1].last_line,first_column:o[o.length-(A||1)].first_column,last_column:o[o.length-1].last_column},b&&(R._$.range=[o[o.length-(A||1)].range[0],o[o.length-1].range[1]]),T=this.performAction.apply(R,[h,u,c,w.yy,I[1],s,o].concat(m)),"undefined"!=typeof T)return T;A&&(l=l.slice(0,-1*A*2),s=s.slice(0,-1*A),o=o.slice(0,-1*A)),l.push(this.productions_[I[1]][0]),s.push(R.$),o.push(R._$),k=a[l[l.length-2]][l[l.length-1]],l.push(k);break;case 3:return!0}}return!0}},P=function(){var e=function(){};e.prototype=z.lexer;var t=function(){this.lexer=new e,this.yy={types:[],escape:function(e){return e.replace(/&/gi,"&").replace(/>/gi,">").replace(/</gi,"<").replace(/\n/g,"\n<br>").replace(/\t/g,"   ").replace(/ /g," ")},parseError:function(e,t){this.done=!0;var n=new String;return n.html="<pre>"+e+"</pre>",n.hash=t,n}}};t.prototype=z;var n=new t;return n};"undefined"!=typeof window?window.Formula=P:z.Formula=P;var D=function(){var t={EOF:1,parseError:function(e,t){if(!this.yy.parser)throw new Error(e);this.yy.parser.parseError(e,t)},setInput:function(t,n){return this.yy=n||this.yy||{},this._input=new e.InputReader(t),this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var e=this._input.ch();this.yytext+=e,this.yyleng++,this.offset++,this.match+=e;var t=e.match(/(?:\r\n?|\n).*/g);return t?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,e},unput:function(e){var t=e.length,n=e.split(/(?:\r\n?|\n)/g);this._input.unCh(t,e),this.yytext=this.yytext.substr(0,this.yytext.length-t),this.offset-=t;var i=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),n.length-1&&(this.yylineno-=n.length-1);var r=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===i.length?this.yylloc.first_column:0)+i[i.length-n.length].length-n[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[r[0],r[0]+this.yyleng-t]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(e){this.unput(this.match.slice(e))},pastInput:function(){var e=this._input.toString(),t=e.substr(0,e.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var e=this._input.input.substr(this._input.position,this._input.input.length-1);return(e.substr(0,20)+(e.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var e=this.pastInput(),t=new Array(e.length+1).join("-");return e+this.upcomingInput()+"\n"+t+"^"},test_match:function(e,t){var n,i,r,l;if(this.options.backtrack_lexer&&(r={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,yyleng:this.yyleng,offset:this.offset,_more:this._more,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(r.yylloc.range=this.yylloc.range.slice(0))),i=e.match(/(?:\r\n?|\n).*/g),i&&(this.yylineno+=i.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:null!==i?i[i.length-1].length-i[i.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+e.length},this.yytext+=e,this.match+=e,this.matches=e,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input.addMatch(e),n=this.performAction.call(this,this.yy,this,t,this.conditionStack[this.conditionStack.length-1]),this.done&&!this._input.done&&(this.done=!1),n)return n;if(this._backtrack){for(l in r)r.hasOwnProperty(l)&&(this[l]=r[l]);return null}return null},next:function(){if(this.done)return this.EOF;this._input.done&&(this.done=!0);var e,t,n,i;this._more||(this.yytext="",this.match="");for(var r=this._currentRules(),l=0;l<r.length;l++)if(n=this._input.match(this.rules[r[l]]),null!==n&&(void 0===t||n[0].length>t.length)){if(t=n[0],i=l,this.options.backtrack_lexer){if(e=this.test_match(n[0],r[l]),null!==e)return e;if(this._backtrack){t=void 0;continue}return null}if(!this.options.flex)break}return void 0!==t?(e=this.test_match(t,r[i]),null!==e?e:null):this._input.done?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var e=this.next();return null!==e?e:this.lex()},begin:function(e){this.conditionStack.push(e)},popState:function(){var e=this.conditionStack.length-1;return e>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(e){return e=this.conditionStack.length-1-Math.abs(e||0),e>=0?this.conditionStack[e]:"INITIAL"},pushState:function(e){this.begin(e)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(e,t,n,i){switch(n){case 0:break;case 1:return 25;case 2:return 7;case 3:return 8;case 4:return 30;case 5:return t.yytext=t.yytext.substring(1,t.yytext.length-1),30;case 6:return 10;case 7:return 10;case 8:return 11;case 9:return 11;case 10:return 12;case 11:return 37;case 12:return 37;case 13:return 32;case 14:return 33;case 15:return 13;case 16:return" ";case 17:return 38;case 18:return 29;case 19:return 35;case 20:return 36;case 21:return 21;case 22:return 22;case 23:return 20;case 24:return 15;case 25:return 23;case 26:return 16;case 27:return 17;case 28:return 19;case 29:return 18;case 30:return"PI";case 31:return 24;case 32:return'"';case 33:return"'";case 34:return'"';case 35:return"'";case 36:return"!";case 37:return 14;case 38:return 39;case 39:return 34;case 40:return"#";case 41:return 4}},rules:[/^(?:\s+)/,/^(?:([A-Za-z]{1,})([A-Za-z_0-9]+)?(?=[(]))/,/^(?:([0]?[1-9]|1[0-2])[:][0-5][0-9]([:][0-5][0-9])?[ ]?(AM|am|aM|Am|PM|pm|pM|Pm))/,/^(?:([0]?[0-9]|1[0-9]|2[0-3])[:][0-5][0-9]([:][0-5][0-9])?)/,/^(?:(([A-Za-z0-9]+))(?=[!]))/,/^(?:((['](\\[']|[^'])*['])|(["](\\["]|[^"])*["]))(?=[!]))/,/^(?:((['](\\[']|[^'])*['])))/,/^(?:((["](\\["]|[^"])*["])))/,/^(?:(([\\]['].+?[\\]['])))/,/^(?:(([\\]["].+?[\\]["])))/,/^(?:[A-Z]+(?=[0-9$]))/,/^(?:[A-Za-z]{1,}[A-Za-z_0-9]+)/,/^(?:[A-Za-z_]+)/,/^(?:[0-9]+)/,/^(?:\$)/,/^(?:&)/,/^(?: )/,/^(?:[.])/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:\*)/,/^(?:\/)/,/^(?:-)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\))/,/^(?:>)/,/^(?:<)/,/^(?:PI\b)/,/^(?:E\b)/,/^(?:")/,/^(?:')/,/^(?:\\")/,/^(?:\\')/,/^(?:!)/,/^(?:=)/,/^(?:%)/,/^(?:#REF!)/,/^(?:[#])/,/^(?:$)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],inclusive:!0}}};return t}();return z.lexer=D,e.prototype=z,e.InputReader=function(e,t,n){function i(e){this.done=!1,this.input=e,this.length=e.length,this.matches=[],this.position=0}var r,l,s,o,a=void 0!==RegExp.prototype.sticky;if(a)for(i.prototype={addMatch:function(e){this.matches.push(e),this.position+=e.length,this.done=this.position>=this.length},ch:function e(){var e=this.input[this.position];return this.addMatch(e),e},unCh:function(t){this.position-=t,this.position=e.max(0,this.position),this.done=this.position>=this.length},substring:function(e,t){return e=0!=e?this.position+e:this.position,t=0!=t?e+t:this.length,this.input.substring(e,t)},match:function e(t){var e;return t.lastIndex=this.position,null!==(e=t.exec(this.input))?e:null},toString:function(){return this.matches.join("")}},r=n.rules,s=r.length,o=0;o<s;o++)l=r[o],r[o]=new RegExp(l.source.substring(1),"y");else i.prototype={addMatch:function(e){this.input=this.input.slice(e.length),this.matches.push(e),this.position+=e.length,this.done=this.position>=this.length},ch:function e(){var e=this.input[0];return this.addMatch(e),e},unCh:function(t,n){this.position-=t,this.position=e.max(0,this.position),this.input=n+this.input,this.done=this.position>=this.length},substring:function(e,t){return e=0!=e?this.position+e:this.position,t=0!=t?e+t:this.length,this.input.substring(e,t)},match:function e(t){var e,n=this.input;return null!==(e=n.match(t))?e:null},toString:function(){return this.matches.join("")}};return i}(Math,z,D),z.Parser=e,new e}();"undefined"!=typeof require&&"undefined"!=typeof exports&&(exports.parser=parser,exports.Parser=parser.Parser,exports.parse=function(){return parser.parse.apply(parser,arguments)},exports.main=function(e){e[1]||(console.log("Usage: "+e[0]+" FILE"),process.exit(1));var t=require("fs").readFileSync(require("path").normalize(e[1]),"utf8");return exports.parser.parse(t)},"undefined"!=typeof module&&require.main===module&&exports.main(process.argv.slice(1)));var parser=function(){function e(){this.yy={}}var t=function(e,t,n,i){for(n=n||{},i=e.length;i--;n[e[i]]=t);return n},n=[1,10],i=[1,11],r=[1,12],l=[1,13],s=[5,7,8,9,10],o=[1,19],a=[1,20],h=[5,7,8,9,10,12,13],c=[1,21],u=[5,7,8,9,10,12,13,14,16],d={trace:function(){},yy:{},symbols_:{error:2,grid:3,rows:4,EOF:5,row:6,END_OF_LINE:7,END_OF_LINE_WITH_EMPTY_NEXT_FIRST_COLUMN:8,END_OF_LINE_WITH_NO_COLUMNS:9,END_OF_LINE_WITH_EMPTY_COLUMN:10,string:11,COLUMN_EMPTY:12,COLUMN_STRING:13,CHAR:14,QUOTE_ON:15,QUOTE_OFF:16,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",7:"END_OF_LINE",8:"END_OF_LINE_WITH_EMPTY_NEXT_FIRST_COLUMN",9:"END_OF_LINE_WITH_NO_COLUMNS",10:"END_OF_LINE_WITH_EMPTY_COLUMN",12:"COLUMN_EMPTY",13:"COLUMN_STRING",14:"CHAR",15:"QUOTE_ON",16:"QUOTE_OFF"},productions_:[0,[3,2],[3,1],[4,1],[4,1],[4,1],[4,1],[4,1],[4,2],[4,2],[4,2],[4,2],[4,3],[4,3],[4,3],[4,3],[6,1],[6,1],[6,2],[6,3],[6,1],[6,2],[6,3],[11,1],[11,2],[11,3]],performAction:function(e,t,n,i,r,l,s){var o=l.length-1;switch(r){case 1:return l[o-1];case 2:return[[""]];case 3:this.$=[l[o]];break;case 4:this.$=[];break;case 5:this.$=[""];break;case 6:this.$=[""];break;case 7:this.$=[""];break;case 8:this.$=l[o-1];break;case 9:l[o-1].push([""]),this.$=l[o-1];break;case 10:l[o-1].push([""]),this.$=l[o-1];break;case 11:l[o-1][l[o-1].length-1].push(""),this.$=l[o-1];break;case 12:l[o-2].push(l[o]),this.$=l[o-2];break;case 13:l[o].unshift(""),l[o-2].push(l[o]),this.$=l[o-2];break;case 14:l[o-2].push([""]),l[o-2].push(l[o]),this.$=l[o-2];break;case 15:l[o-2][l[o-2].length-1].push(""),l[o-2].push(l[o]),this.$=l[o-2];break;case 16:this.$=[l[o].join("")];break;case 17:this.$=[""];break;case 18:l[o-1].push(""),this.$=l[o-1];break;case 19:l[o-2].push(""),l[o-2].push(l[o].join("")),this.$=l[o-2];break;case 20:break;case 21:break;case 22:l[o-2].push(l[o].join("")),this.$=l[o-2];break;case 23:this.$=[l[o]];break;case 24:l[o-1].push(l[o]),this.$=l[o-1];break;case 25:this.$=l[o-1]}},table:[{3:1,4:2,5:[1,3],6:4,7:[1,5],8:[1,6],9:[1,7],10:[1,8],11:9,12:n,13:i,14:r,15:l},{1:[3]},{5:[1,14],7:[1,15],8:[1,16],9:[1,17],10:[1,18]},{1:[2,2]},t(s,[2,3],{12:o,13:a}),t(s,[2,4]),t(s,[2,5]),t(s,[2,6]),t(s,[2,7]),t(h,[2,16],{14:c}),t(h,[2,17]),t(h,[2,20]),t(u,[2,23]),{11:22,14:r,15:l},{1:[2,1]},t(s,[2,8],{11:9,6:23,12:n,13:i,14:r,15:l}),t(s,[2,9],{11:9,6:24,12:n,13:i,14:r,15:l}),t(s,[2,10],{11:9,6:25,12:n,13:i,14:r,15:l}),t(s,[2,11],{11:9,6:26,12:n,13:i,14:r,15:l}),t(h,[2,18],{11:27,14:r,15:l}),t(h,[2,21],{11:28,14:r,15:l}),t(u,[2,24]),{14:c,16:[1,29]},t(s,[2,12],{12:o,13:a}),t(s,[2,13],{12:o,13:a}),t(s,[2,14],{12:o,13:a}),t(s,[2,15],{12:o,13:a}),t(h,[2,19],{14:c}),t(h,[2,22],{14:c}),t(u,[2,25])],defaultActions:{3:[2,2],14:[2,1]},parseError:function(e,t){if(!t.recoverable)throw new Error(e);this.trace(e)},parse:function(e){function t(){var e;return e=p.lex()||d,"number"!=typeof e&&(e=n.symbols_[e]||e),e}var n=this,i=[0],r=[null],l=[],s=this.table,o="",a=0,h=0,c=0,u=2,d=1,f=l.slice.call(arguments,1),p=Object.create(this.lexer),m={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(m.yy[g]=this.yy[g]);p.setInput(e,m.yy),m.yy.lexer=p,m.yy.parser=this,"undefined"==typeof p.yylloc&&(p.yylloc={});var w=p.yylloc;l.push(w);var v=p.options&&p.options.ranges;"function"==typeof m.yy.parseError?this.parseError=m.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var y,b,C,x,E,I,T,S,A,k={};;){if(C=i[i.length-1],this.defaultActions[C]?x=this.defaultActions[C]:(null!==y&&"undefined"!=typeof y||(y=t()),x=s[C]&&s[C][y]),"undefined"==typeof x||!x.length||!x[0]){var N="";A=[];for(I in s[C])this.terminals_[I]&&I>u&&A.push("'"+this.terminals_[I]+"'");N=p.showPosition?"Parse error on line "+(a+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[y]||y)+"'":"Parse error on line "+(a+1)+": Unexpected "+(y==d?"end of input":"'"+(this.terminals_[y]||y)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[y]||y,line:p.yylineno,loc:w,expected:A})}if(x[0]instanceof Array&&x.length>1)throw new Error("Parse Error: multiple actions possible at state: "+C+", token: "+y);switch(x[0]){case 1:i.push(y),r.push(p.yytext),l.push(p.yylloc),i.push(x[1]),y=null,b?(y=b,b=null):(h=p.yyleng,o=p.yytext,a=p.yylineno,w=p.yylloc,c>0&&c--);break;case 2:if(T=this.productions_[x[1]][1],k.$=r[r.length-T],k._$={first_line:l[l.length-(T||1)].first_line,last_line:l[l.length-1].last_line,first_column:l[l.length-(T||1)].first_column,last_column:l[l.length-1].last_column},v&&(k._$.range=[l[l.length-(T||1)].range[0],l[l.length-1].range[1]]),E=this.performAction.apply(k,[o,h,a,m.yy,x[1],r,l].concat(f)),"undefined"!=typeof E)return E;T&&(i=i.slice(0,-1*T*2),r=r.slice(0,-1*T),l=l.slice(0,-1*T)),i.push(this.productions_[x[1]][0]),r.push(k.$),l.push(k._$),S=s[i[i.length-2]][i[i.length-1]],i.push(S);break;case 3:return!0}}return!0}};if("undefined"!=typeof GLOBAL&&(GLOBAL.window=GLOBAL),"undefined"==typeof window.TSV){var f=d.parse;d.parse=function(e){var t=this.lexer.setInput;return this.lexer.setInput=function(e){return t.call(this,e),this.begin("BOF"),this},this.parse=f,f.call(this,e)},window.TSV=function(e){var t=function(){};t.prototype=d.lexer;var n=function(){this.lexer=new t,this.yy={}};n.prototype=d;var i=new n;return i.setObj=function(e){i.yy.obj=e},i.yy.handler=e,i}}var p=function(){var e={EOF:1,parseError:function(e,t){if(!this.yy.parser)throw new Error(e);this.yy.parser.parseError(e,t)},setInput:function(e,t){return this.yy=t||this.yy||{},this._input=e,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var e=this._input[0];this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e;var t=e.match(/(?:\r\n?|\n).*/g);return t?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},unput:function(e){var t=e.length,n=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t),this.offset-=t;var i=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var r=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===i.length?this.yylloc.first_column:0)+i[i.length-n.length].length-n[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[r[0],r[0]+this.yyleng-t]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(e){this.unput(this.match.slice(e))},pastInput:function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?"...":"")+e.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var e=this.pastInput(),t=new Array(e.length+1).join("-");return e+this.upcomingInput()+"\n"+t+"^"},test_match:function(e,t){var n,i,r;if(this.options.backtrack_lexer&&(r={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(r.yylloc.range=this.yylloc.range.slice(0))),i=e[0].match(/(?:\r\n?|\n).*/g),i&&(this.yylineno+=i.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:i?i[i.length-1].length-i[i.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+e[0].length},this.yytext+=e[0],this.match+=e[0],this.matches=e,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(e[0].length),this.matched+=e[0],n=this.performAction.call(this,this.yy,this,t,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var l in r)this[l]=r[l];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var e,t,n,i;this._more||(this.yytext="",this.match="");for(var r=this._currentRules(),l=0;l<r.length;l++)if(n=this._input.match(this.rules[r[l]]),n&&(!t||n[0].length>t[0].length)){if(t=n,i=l,this.options.backtrack_lexer){if(e=this.test_match(n,r[l]),e!==!1)return e;if(this._backtrack){t=!1;continue}return!1}if(!this.options.flex)break}return t?(e=this.test_match(t,r[i]),e!==!1&&e):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var e=this.next();return e?e:this.lex()},begin:function(e){this.conditionStack.push(e)},popState:function(){var e=this.conditionStack.length-1;return e>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(e){return e=this.conditionStack.length-1-Math.abs(e||0),e>=0?this.conditionStack[e]:"INITIAL"},pushState:function(e){this.begin(e)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(e,t,n,i){switch(n){case 0:return 14;case 1:return this.popState(),16;case 2:return t.yytext==this.quoteChar?(this.popState(),this.begin("STRING"),16):14;case 3:return this.popState(),this.begin("STRING"),14;case 4:return this.popState(),this.quoteChar=t.yytext.substring(0),this.begin("QUOTE"),15;case 5:return this.quoteChar=t.yytext,this.popState(),this.begin("QUOTE"),15;case 6:return this.begin("PRE_QUOTE"),13;case 7:return this.begin("PRE_QUOTE"),7;case 8:return 14;case 9:return this.popState(),8;case 10:return this.popState(),9;case 11:return this.popState(),7;case 12:return this.popState(),13;case 13:return 14;case 14:this.popState();break;case 15:return"BUFFIN";case 16:return 9;case 17:return 10;case 18:return 12;case 19:return 7;case 20:return this.begin("STRING"),14;case 21:return 5}},rules:[/^(?:(\n|\\n))/,/^(?:([\'\"])(?=$))/,/^(?:([\'\"]))/,/^(?:(?=(\t)))/,/^(?:([\'\"]))/,/^(?:([\'\"]))/,/^(?:(\t|\\t)(?=[\'\"]))/,/^(?:(\n|\\n)(?=[\'\"]))/,/^(?:([a-zA-Z0-9_ ]+|.))/,/^(?:(\n\t|\\n\\t))/,/^(?:(\n\n|\\n\\n))/,/^(?:(\n|\\n))/,/^(?:(\t|\\t))/,/^(?:([a-zA-Z0-9_ ]+|.))/,/^(?:)/,/^(?:(\n\t|\\n\\t)(?=.))/,/^(?:(\n\n|\\n\\n))/,/^(?:(\t\n))/,/^(?:(\t))/,/^(?:(\n))/,/^(?:([a-zA-Z0-9_ ]+|.))/,/^(?:$)/],conditions:{BOF:{rules:[4,6,7,14,15,16,17,18,19,20,21],inclusive:!0},PRE_QUOTE:{rules:[5,6,7,15,16,17,18,19,20,21],inclusive:!0},QUOTE:{rules:[0,1,2,3,6,7,8,15,16,17,18,19,20,21],inclusive:!0},STRING:{rules:[6,7,9,10,11,12,13,15,16,17,18,19,20,21],inclusive:!0},INITIAL:{rules:[6,7,15,16,17,18,19,20,21],inclusive:!0}}};return e}();return d.lexer=p,e.prototype=d,d.Parser=e,new e}();"undefined"!=typeof require&&"undefined"!=typeof exports&&(exports.parser=parser,exports.Parser=parser.Parser,exports.parse=function(){return parser.parse.apply(parser,arguments)},exports.main=function(e){e[1]||(console.log("Usage: "+e[0]+" FILE"),process.exit(1));var t=require("fs").readFileSync(require("path").normalize(e[1]),"utf8");return exports.parser.parse(t)},"undefined"!=typeof module&&require.main===module&&exports.main(process.argv.slice(1)));