0byt3m1n1
Path:
/
data
/
applications
/
aps
/
tikiwiki
/
7.0-0
/
standard
/
htdocs
/
lib
/
jquery
/
jquery.sheet
/
[
Home
]
File: jquery.sheet.min.js
/* jQuery.sheet() The Web Based Spreadsheet $Id: jquery.sheet.min.js 405 2011-05-23 00:51:25Z RobertLeePlummerJr $ http://code.google.com/p/jquerysheet/ Copyright (C) 2010 Robert Plummer Dual licensed under the LGPL v2 and GPL v2 licenses. http://www.gnu.org/licenses/ */ jQuery.fn.extend({sheet:function(a){jQuery(this).each(function(){var b=jQuery(this);var c=jQuery.extend({urlGet:"sheets/enduser.documentation.html",urlSave:"save.html",editable:true,editableTabs:true,barMenus:true,freezableCells:false,allowToggleState:true,urlMenu:"menu.html",menu:"",newColumnWidth:120,title:null,inlineMenu:null,buildSheet:false,calcOff:false,log:false,lockFormulas:false,parent:b,colMargin:18,fnBefore:function(){},fnAfter:function(){},fnSave:function(){o.getSheet().saveSheet()},fnOpen:function(){var d=prompt("Paste your table html here");if(d){o.getSheet().openSheet(d)}},fnClose:function(){},fnAfterCellEdit:function(){},fnSwitchSheet:function(){},fnPaneScroll:function(){},boxModelCorrection:2,calculations:{},cellSelectModel:"excel",autoAddCells:true,resizable:true,autoFiller:false,minSize:{rows:15,cols:5},forceColWidthsOnStartup:true,alertFormulaErrors:false},a);if(jQuery.sheet.instance){b.sheetInstance=jQuery.sheet.createInstance(c,jQuery.sheet.instance.length,b);jQuery.sheet.instance.push(b.sheetInstance)}else{b.sheetInstance=jQuery.sheet.createInstance(c,0,b);jQuery.sheet.instance=[b.sheetInstance]}b.attr("sheetInstance",jQuery.sheet.instance.length-1)});return this},disableSelectionSpecial:function(){this.each(function(){this.onselectstart=function(){return false};this.unselectable="on";jQuery(this).css("-moz-user-select","none")});return this},getSheet:function(){var a=parseInt(jQuery(this).attr("sheetInstance"));if(!isNaN(a)){return jQuery.sheet.instance[a]}return false}});jQuery.sheet={createInstance:function(d,c,b){var f={version:"2.0.0",i:0,I:c,sheetCount:0,spreadsheets:[],obj:{autoFiller:function(){return jQuery("#"+f.id.autoFiller+f.i)},barCorner:function(){return jQuery("#"+f.id.barCorner+f.i)},barCornerAll:function(){return d.parent.find("div."+f.cl.barCorner)},barCornerParent:function(){return jQuery("#"+f.id.barCornerParent+f.i)},barCornerParentAll:function(){return d.parent.find("td."+f.cl.barCornerParent)},barHelper:function(){return jQuery("div."+f.cl.barHelper)},barLeft:function(){return jQuery("#"+f.id.barLeft+f.i)},barLeftAll:function(){return d.parent.find("div."+f.cl.barLeft)},barLeftParent:function(){return jQuery("#"+f.id.barLeftParent+f.i)},barLeftParentAll:function(){return d.parent.find("div."+f.cl.barLeftParent)},barLeftHandle:function(){return jQuery("#"+f.id.barLeftHandle)},barLeftMenu:function(){return jQuery("#"+f.id.barLeftMenu)},barTop:function(){return jQuery("#"+f.id.barTop+f.i)},barTopAll:function(){return d.parent.find("div."+f.cl.barTop)},barTopParent:function(){return jQuery("#"+f.id.barTopParent+f.i)},barTopParentAll:function(){return d.parent.find("div."+f.cl.barTopParent)},barTopHandle:function(){return jQuery("#"+f.id.barTopHandle)},barTopMenuParent:function(){return jQuery("#"+f.id.barTopMenuParent)},barTopMenu:function(){return jQuery("#"+f.id.barTopMenu)},cellActive:function(){return jQuery(f.cellLast.td)},cellMenu:function(){return jQuery("#"+f.id.cellMenu)},cellHighlighted:function(){return jQuery(f.highlightedLast.td)},chart:function(){return jQuery("div."+f.cl.chart)},controls:function(){return jQuery("#"+f.id.controls)},formula:function(){return jQuery("#"+f.id.formula)},fullScreen:function(){return jQuery("div."+f.cl.fullScreen)},inlineMenu:function(){return jQuery("#"+f.id.inlineMenu)},inPlaceEdit:function(){return jQuery("#"+f.id.inPlaceEdit)},label:function(){return jQuery("#"+f.id.label)},menu:function(){return jQuery("#"+f.id.menu)},pane:function(){return jQuery("#"+f.id.pane+f.i)},paneAll:function(){return d.parent.find("div."+f.cl.pane)},parent:function(){return d.parent},sheet:function(){return jQuery("#"+f.id.sheet+f.i)},sheetAll:function(){return d.parent.find("table."+f.cl.sheet)},tab:function(){return jQuery("#"+f.id.tab+f.i)},tabAll:function(){return this.tabContainer().find("a."+f.cl.tab)},tabContainer:function(){return jQuery("#"+f.id.tabContainer)},tableBody:function(){return document.getElementById(f.id.sheet+f.i)},tableControl:function(){return jQuery("#"+f.id.tableControl+f.i)},tableControlAll:function(){return d.parent.find("table."+f.cl.tableControl)},title:function(){return jQuery("#"+f.id.title)},ui:function(){return jQuery("#"+f.id.ui)},uiActive:function(){return d.parent.find("div."+f.cl.uiActive)}},id:{autoFiller:"jSheetAutoFiller_"+c+"_",barCorner:"jSheetBarCorner_"+c+"_",barCornerParent:"jSheetBarCornerParent_"+c+"_",barLeft:"jSheetBarLeft_"+c+"_",barLeftParent:"jSheetBarLeftParent_"+c+"_",barLeftHandle:"jSheetBarLeftHandle_"+c,barLeftMenu:"jSheetBarLeftMenu_"+c,barTop:"jSheetBarTop_"+c+"_",barTopParent:"jSheetBarTopParent_"+c+"_",barTopHandle:"jSheetBarTopHandle",barTopMenu:"jSheetBarTopMenu_"+c,barTopMenuParent:"jSheetBarTopMenuParent_"+c,cellMenu:"jSheetCellMenu_"+c,controls:"jSheetControls_"+c,formula:"jSheetControls_formula_"+c,inlineMenu:"jSheetInlineMenu_"+c,inPlaceEdit:"jSheetInPlaceEdit_"+c,label:"jSheetControls_loc_"+c,menu:"jSheetMenu_"+c,pane:"jSheetEditPane_"+c+"_",sheet:"jSheet_"+c+"_",tableControl:"tableControl_"+c+"_",tab:"jSheetTab_"+c+"_",tabContainer:"jSheetTabContainer_"+c,title:"jSheetTitle_"+c,ui:"jSheetUI_"+c},cl:{autoFiller:"jSheetAutoFiller",autoFillerHandle:"jSheetAutoFillerHandle",autoFillerConver:"jSheetAutoFillerCover",barCorner:"jSheetBarCorner",barCornerParent:"jSheetBarCornerParent",barHelper:"jSheetBarHelper",barLeftTd:"jSheetBarLeftTd",barLeft:"jSheetBarLeft",barLeftHandle:"jSheetBarLeftHandle",barLeftParent:"jSheetBarLeftParent",barTop:"jSheetBarTop",barTopHandle:"jSheetBarTopHandle",barTopParent:"jSheetBarTopParent",barTopTd:"jSheetBarTopTd",cellActive:"jSheetCellActive",cellHighlighted:"jSheetCellHighighted",chart:"jSheetChart",controls:"jSheetControls",error:"jSheetError",formula:"jSheetControls_formula",formulaParent:"jSheetControls_formulaParent",inlineMenu:"jSheetInlineMenu",fullScreen:"jSheetFullScreen",inPlaceEdit:"jSheetInPlaceEdit",menu:"jSheetMenu",parent:"jSheetParent",sheet:"jSheet",sheetPaneTd:"sheetPane",label:"jSheetControls_loc",pane:"jSheetEditPane",tab:"jSheetTab",tabContainer:"jSheetTabContainer",tabContainerFullScreen:"jSheetFullScreenTabContainer",tableControl:"tableControl",title:"jSheetTitle",toggle:"cellStyleToggle",ui:"jSheetUI",uiAutoFiller:"ui-state-active",uiActive:"ui-state-active",uiBar:"ui-widget-header",uiBarHighlight:"ui-state-highlight",uiBarLeftHandle:"ui-state-default",uiBarLeftMenu:"ui-state-default ui-corner-top",uiBarTopHandle:"ui-state-default",uiBarTopMenu:"ui-state-default ui-corner-top",uiCellActive:"ui-state-active",uiCellHighlighted:"ui-state-highlight",uiControl:"ui-widget-header ui-corner-top",uiControlTextBox:"ui-widget-content",uiError:"ui-state-error",uiFullScreen:"ui-widget-content ui-corner-all",uiInPlaceEdit:"ui-state-active",uiMenu:"ui-state-default",uiMenuUl:"ui-widget-header",uiMenuLi:"ui-widget-header",uiMenuHighlighted:"ui-state-highlight",uiPane:"ui-widget-content",uiParent:"ui-widget-content ui-corner-all",uiSheet:"ui-widget-content",uiTab:"ui-widget-header",uiTabActive:"ui-state-highlight"},msg:{addRowMulti:"How many rows would you like to add?",addColumnMulti:"How many columns would you like to add?",newSheet:"What size would you like to make your spreadsheet? Example: '5x10' creates a sheet that is 5 columns by 10 rows.",openSheet:"Are you sure you want to open a different sheet? All unsaved changes will be lost.",cellFind:"No results found.",toggleHideRow:"No row selected.",toggleHideColumn:"Now column selected.",merge:"Merging is not allowed on the first row.",evalError:"Error, functions as formulas not supported.",menuInsertColumnAfter:"Insert column after",menuInsertColumnBefore:"Insert column before",menuAddColumnEnd:"Add column to end",menuDeleteColumn:"Delete this column",menuInsertRowAfter:"Insert row after",menuInsertRowBefore:"Insert row before",menuAddRowEnd:"Add row to end",menuDeleteRow:"Delete this row",menuAddSheet:"Add spreadsheet",menuDeleteSheet:"Delete spreadsheet"},kill:function(){f.obj.tabContainer().remove();f.obj.fullScreen().remove();f.obj.inPlaceEdit().remove();b.removeClass(f.cl.uiParent).html("").removeAttr("sheetInstance");cE=d=jQuery.sheet.instance[c]=f=null;delete cE;delete d;delete jQuery.sheet.instance[c];delete f},spreadsheetsToArray:function(i){if(i||f.spreadsheets.length==0){f.cycleCellsAll(function(k,l,j){var m=jQuery(this);f.createCell(k,l,j,m.text(),m.attr("formula"))})}return f.spreadsheets},spreadsheetToArray:function(k,j){j=(j?j:f.i);if(k||!f.spreadsheets[j]){f.cycleCells(function(l,m,i){var n=jQuery(this);f.createCell(l,m,i,n.text(),n.attr("formula"))})}},createCell:function(k,n,j,m,p,l,i){if(!f.spreadsheets[k]){f.spreadsheets[k]=[]}if(!f.spreadsheets[k][n]){f.spreadsheets[k][n]=[]}f.spreadsheets[k][n][j]={formula:p,value:m,calcCount:(l?l:0),calcLast:(i?i:-1)};return f.spreadsheets[k][n][j]},nav:false,setNav:function(i){jQuery(jQuery.sheet.instance).each(function(){this.nav=false});f.nav=i},controlFactory:{addRowMulti:function(k,i,j){if(!k){k=prompt(f.msg.addRowMulti)}if(k){if(!isNaN(k)){f.controlFactory.addCells(null,i,null,parseInt(k),"row",j)}}},addColumnMulti:function(k,i,j){if(!k){k=prompt(f.msg.addColumnMulti)}if(k){if(!isNaN(k)){f.controlFactory.addCells(null,i,null,parseInt(k),"col",j)}}},addCells:function(B,D,y,s,n,p){if(d.autoFiller){f.obj.autoFiller().hide()}f.setDirty(true);f.obj.barHelper().remove();var q=f.obj.sheet();var w=q.width();s=(s?s:1);n=(n?n:"col");var k=(n=="row"?f.cellLast.row:f.cellLast.col);if(!B){if(k==-1){B=":last"}else{B=":eq("+k+")"}}else{if(!isNaN(B)){B=":eq("+(B)+")"}}var x;switch(n){case"row":x={bar:f.obj.barLeft().children("div"+B),barParent:f.obj.barLeft(),cells:function(){return q.find("tr"+B)},col:function(){return""},newBar:'<div class="'+f.cl.uiBar+'" style="height: '+(d.colMargin-d.boxModelCorrection)+'px;" />',size:function(){return f.getTdLocation(x.cells().find("td:last"))},loc:function(){return f.getTdLocation(x.cells().find("td:first"))},newCells:function(){var E=x.size().col;var G="";for(var F=0;F<=E;F++){G+="<td />"}return'<tr style="height: '+d.colMargin+'px;">'+G+"</tr>"},newCol:"",reLabel:function(){x.barParent.children().each(function(E){jQuery(this).text(E+1)})},dimensions:function(F,i,E){F.height(i.height(d.colMargin).outerHeight()-d.boxModelCorrection)},offset:{row:s,col:0}};break;case"col":x={bar:f.obj.barTop().children("div"+B),barParent:f.obj.barTop(),cells:function(){var K=q.find("tr:first").children(B);var J=q.find("td:last");var I=f.getTdLocation(K);var H=f.getTdLocation(J);var F=jQuery(f.getTd(f.i,I.row,I.col));var E;for(var G=1;G<=H.row;G++){F.push(f.getTd(f.i,G,I.col))}return F},col:function(){return q.find("col"+B)},newBar:'<div class="'+f.cl.uiBar+'"/>',newCol:"<col />",loc:function(i){i=(i?i:x.cells());return f.getTdLocation(i.first())},newCells:function(){return"<td />"},reLabel:function(){x.barParent.children().each(function(E){jQuery(this).text(jSE.columnLabelString(E))})},dimensions:function(G,i,F){var E=d.newColumnWidth;F.width(E).css("width",E+"px").attr("width",E+"px");G.width(E-d.boxModelCorrection);q.width(w+(E*s))},offset:{row:0,col:s}};break}f.cellUndoable.add(jQuery(q).add(x.barParent));var m=x.cells();var t=x.loc(m);var r=x.col();var v=x.newBar;var u=x.newCells();var l=x.newCol;var A="";var j="";var C="";for(var z=0;z<s;z++){A+=l;j+=v;C+=u}A=jQuery(A);j=jQuery(j);C=jQuery(C);if(D){m.before(C);x.bar.before(j);jQuery(r).before(A)}else{m.after(C);x.bar.after(j);jQuery(r).after(A)}f.setTdIds(q,f.i);x.dimensions(j,C,A);x.reLabel();f.obj.pane().scroll();if(!p&&B!=":last"){f.offsetFormulas(t,x.offset,D)}f.sheetSyncSize();f.cellUndoable.add(jQuery(q).add(x.barParent))},addRow:function(k,j,i){f.controlFactory.addCells(k,j,i,1,"row")},addColumn:function(k,j,i){f.controlFactory.addCells(k,j,i,1,"col")},barLeft:function(k,l){f.obj.barLeft().remove();var i=jQuery('<div border="1px" id="'+f.id.barLeft+f.i+'" class="'+f.cl.barLeft+'" />');var j;if(k){j=function(m,n,p){p.height(parseInt(n.outerHeight())-d.boxModelCorrection)}}else{j=function(m,n,p){p.height(parseInt(n.css("height").replace("px",""))-d.boxModelCorrection)}}l.find("tr").each(function(m){var n=jQuery("<div>"+(m+1)+"</div>");i.append(n);j(m,jQuery(this),n)});f.evt.barMouseDown.height(f.obj.barLeftParent().append(i))},barTop:function(i,l){f.obj.barTop().remove();var k=jQuery('<div id="'+f.id.barTop+f.i+'" class="'+f.cl.barTop+'" />');k.height(d.colMargin);var j;var m;if(i){j=l.find("tr:first").children();m=function(n){return f.attrH.width(n)}}else{j=l.find("col");m=function(n){return parseInt(jQuery(n).css("width").replace("px",""))-d.boxModelCorrection}}j.each(function(q){var p=jSE.columnLabelString(q);var n=m(this);var r=jQuery("<div>"+p+"</div>").width(n).height(d.colMargin);k.append(r)});f.evt.barMouseDown.width(f.obj.barTopParent().append(k))},barTopHandle:function(k,j){if(f.busy){return false}if(j!=0){return false}f.obj.barHelper().remove();var m=f.obj.barTop().children().eq(j);var n=m.position();var l=jQuery('<div id="'+f.id.barTopHandle+'" class="'+f.cl.uiBarTopHandle+" "+f.cl.barHelper+" "+f.cl.barTopHandle+'" />').height(d.colMargin-2).css("left",n.left+"px").appendTo(k);f.draggable(l,{axis:"x",start:function(){f.busy=true},stop:function(){f.busy=false}})},barLeftHandle:function(k,j){if(f.busy){return false}if(j!=0){return false}f.obj.barHelper().remove();var l=f.obj.barLeft().children().eq(j);var n=l.position();var m=jQuery('<div id="'+f.id.barLeftHandle+'" class="'+f.cl.uiBarLeftHandle+" "+f.cl.barHelper+" "+f.cl.barLeftHandle+'" />').width(d.colMargin-6).height(d.colMargin/3).css("top",n.top+"px").appendTo(k);f.draggable(m,{axis:"y",start:function(){f.busy=true},stop:function(){f.busy=false}})},makeMenu:function(j,i){var l;function k(n,m){switch(n){case"line":jQuery("<hr />").appendTo(l);break;default:jQuery("<div>"+n+"</div>").click(function(){m();return false}).appendTo(l)}}switch(j){case"top":l=jQuery('<div id="'+f.id.barTopMenu+'" class="'+f.cl.uiMenu+" "+f.cl.barHelper+'" />');break;case"left":l=jQuery('<div id="'+f.id.barLeftMenu+'" class="'+f.cl.uiMenu+" "+f.cl.barHelper+'" />');break;case"cell":l=jQuery('<div id="'+f.id.cellMenu+'" class="'+f.cl.uiMenu+" "+f.cl.barHelper+'" />');break}l.width(d.newColumnWidth).mouseleave(function(){l.hide()}).appendTo("body").hide();jQuery(i).each(function(){k(this.msg,this.fn)});return l},barTopMenu:function(m,k,l){if(f.busy){return false}var n=f.obj.barTopMenu().hide();if(k){f.obj.barTopHandle().remove()}var n;if(!n.length){n=f.controlFactory.makeMenu("top",[{msg:f.msg.menuInsertColumnAfter,fn:function(){f.controlFactory.addColumn();return false}},{msg:f.msg.menuInsertColumnBefore,fn:function(){f.controlFactory.addColumn(null,true);return false}},{msg:f.msg.menuAddColumnEnd,fn:function(){f.controlFactory.addColumn(":last");return false}},{msg:f.msg.menuDeleteColumn,fn:function(){f.deleteColumn();return false}}])}if(!l){n.css("left",(m.pageX-5)+"px").css("top",(m.pageY-5)+"px").show();return n}var j=f.obj.barTopMenuParent().hide();if(!j.length){j=jQuery('<div id="'+f.id.barTopMenuParent+'" class="'+f.cl.uiBarTopMenu+" "+f.cl.barHelper+'"><span class="ui-icon ui-icon-triangle-1-s" /></span></div>').click(function(i){j.parent().mousedown().mouseup();var p=j.offset();n.css("left",(p.left-(d.newColumnWidth-d.colMargin))+"px").css("top",(p.top+(d.colMargin*0.8))+"px").show()}).blur(function(){if(n){n.hide()}}).height(d.colMargin)}j.appendTo(l).show()},barLeftMenu:function(k,j){if(f.busy){return false}f.obj.barLeftMenu().hide();if(j){f.obj.barLeftHandle().remove()}var l;l=f.obj.barLeftMenu();if(!l.length){l=f.controlFactory.makeMenu("left",[{msg:f.msg.menuInsertRowAfter,fn:function(){f.controlFactory.addRow();return false}},{msg:f.msg.menuInsertRowBefore,fn:function(){f.controlFactory.addRow(null,true);return false}},{msg:f.msg.menuAddRowEnd,fn:function(){f.controlFactory.addRow(":last");return false}},{msg:f.msg.menuDeleteRow,fn:function(){f.deleteRow();return false}}])}l.css("left",(k.pageX-5)+"px").css("top",(k.pageY-5)+"px").show()},cellMenu:function(i){if(f.busy){return false}f.obj.cellMenu().hide();var j=f.obj.cellMenu();if(!j.length){j=f.controlFactory.makeMenu("cell",[{msg:f.msg.menuInsertColumnAfter,fn:function(){f.controlFactory.addColumn();return false}},{msg:f.msg.menuInsertColumnBefore,fn:function(){f.controlFactory.addColumn(null,true);return false}},{msg:f.msg.menuAddColumnEnd,fn:function(){f.controlFactory.addColumn(":last");return false}},{msg:f.msg.menuDeleteColumn,fn:function(){f.deleteColumn();return false}},{msg:"line"},{msg:f.msg.menuInsertRowAfter,fn:function(){f.controlFactory.addRow();return false}},{msg:f.msg.menuInsertRowBefore,fn:function(){f.controlFactory.addRow(null,true);return false}},{msg:f.msg.menuAddRowEnd,fn:function(){f.controlFactory.addRow(":last");return false}},{msg:f.msg.menuDeleteRow,fn:function(){f.deleteRow();return false}},{msg:"line"},{msg:f.msg.menuAddSheet,fn:function(){f.addSheet("5x10")}},{msg:f.msg.menuDeleteSheet,fn:function(){f.deleteSheet()}}])}j.css("left",(i.pageX-5)+"px").css("top",(i.pageY-5)+"px").show()},header:function(){f.obj.controls().remove();f.obj.tabContainer().remove();var l=jQuery('<div id="'+f.id.controls+'" class="'+f.cl.controls+'"></div>');var i=jQuery('<table cellpadding="0" cellspacing="0" border="0"><tr /></table>').prependTo(l);var j=jQuery("<tr />");if(d.title){var p;if(jQuery.isFunction(d.title)){p=f.title(f)}else{p=d.title}j.append(jQuery('<td id="'+f.id.title+'" class="'+f.cl.title+'" />').html(p))}if(d.inlineMenu&&d.editable){var q;if(jQuery.isFunction(d.inlineMenu)){q=d.inlineMenu(f)}else{q=d.inlineMenu}j.append(jQuery('<td id="'+f.id.inlineMenu+'" class="'+f.cl.inlineMenu+'" />').html(q))}if(d.editable){function m(t){var u=jQuery('<td id="'+f.id.menu+'" class="'+f.cl.menu+'" />').html(t.replace(/sheetInstance/g,"jQuery.sheet.instance["+c+"]").replace(/menuInstance/g,c));u.prependTo(j).find("ul").hide().addClass(f.cl.uiMenuUl).first().show();u.find("li").addClass(f.cl.uiMenuLi).hover(function(){jQuery(this).find("ul:first").hide().show()},function(){jQuery(this).find("ul:first").hide()});return u}if(d.menu){m(d.menu)}else{jQuery("<div />").load(d.urlMenu,function(){m(jQuery(this).html())})}var n=jQuery('<table cellpadding="0" cellspacing="0" border="0"><tr><td id="'+f.id.label+'" class="'+f.cl.label+'"></td><td class="'+f.cl.formulaParent+'"><textarea id="'+f.id.formula+'" class="'+f.cl.formula+'"></textarea></td></tr></table>').appendTo(l).find("textarea").keydown(f.evt.keyDownHandler.formulaKeydown).keyup(function(){f.obj.inPlaceEdit().val(f.obj.formula().val())}).change(function(){f.obj.inPlaceEdit().val(f.obj.formula().val())}).bind("paste",f.evt.pasteOverCells).focus(function(){f.setNav(false)}).focusout(function(){f.setNav(true)}).blur(function(){f.setNav(true)});jQuery(jQuery.sheet.instance).each(function(){this.nav=false});f.setNav(true);jQuery(document).unbind("keydown").keydown(f.evt.keyDownHandler.documentKeydown)}j.appendTo(i);var r=jQuery('<div id="'+f.id.tabContainer+'" class="'+f.cl.tabContainer+'" />').mousedown(function(t){b.trigger("switchSpreadsheet",[jQuery(t.target).attr("i")*1]);return false}).dblclick(function(t){b.trigger("renameSpreadsheet",[jQuery(t.target).attr("i")*1]);return});if(d.editable){var s=jQuery('<span class="'+f.cl.uiTab+' ui-corner-bottom" title="Add a spreadsheet" i="-1">+</span>').appendTo(r);if(jQuery.fn.sortable){var k;r.sortable({placeholder:"ui-state-highlight",axis:"x",forceHelperSize:true,forcePlaceholderSize:true,opacity:0.6,cancel:'span[i="-1"]',start:function(u,t){k=t.item.index();b.trigger("tabSortstart",[u,t])},update:function(u,t){b.trigger("tabSortupdate",[u,t,k])}})}}else{jQuery("<span />").appendTo(r)}d.parent.html("").append(l).append('<div id="'+f.id.ui+'" class="'+f.cl.ui+'">').after(r)},sheetUI:function(n,k,l,m){if(!k){f.sheetCount=0;f.i=0}else{f.sheetCount=parseInt(k);f.i=f.sheetCount;k=f.i}var j=f.controlFactory.table().appendTo(f.obj.ui());var q=f.obj.pane().html(n);if(d.autoFiller&&d.editable){q.append(f.controlFactory.autoFiller())}n=f.tuneTableForSheetUse(n);f.sheetDecorate(n);f.controlFactory.barTop(m,n);f.controlFactory.barLeft(m,n);f.sheetTab(true);if(d.editable){var p=f.obj.formula();q.mousedown(function(i){if(f.isTd(i.target)){f.evt.cellOnMouseDown(i);return false}}).bind("contextmenu",function(i){f.controlFactory.cellMenu(i);return false}).disableSelectionSpecial().dblclick(f.evt.cellOnDblClick)}f.themeRoller.start(k);f.setTdIds(n,f.i);f.checkMinSize(n);f.evt.scrollBars(q);f.addTab();if(l){l(j,q)}return j},table:function(){return jQuery('<table cellpadding="0" cellspacing="0" border="0" id="'+f.id.tableControl+f.i+'" class="'+f.cl.tableControl+'"><tbody><tr><td id="'+f.id.barCornerParent+f.i+'" class="'+f.cl.barCornerParent+'"><div style="height: '+d.colMargin+"; width: "+d.colMargin+';" id="'+f.id.barCorner+f.i+'" class="'+f.cl.barCorner+'"'+(d.editable?' onClick="jQuery.sheet.instance['+c+"].cellSetActiveBar('all');\"":"")+' title="Select All"> </div></td><td class="'+f.cl.barTopTd+'"><div id="'+f.id.barTopParent+f.i+'" class="'+f.cl.barTopParent+'"></div></td></tr><tr><td class="'+f.cl.barLeftTd+'"><div style="width: '+d.colMargin+';" id="'+f.id.barLeftParent+f.i+'" class="'+f.cl.barLeftParent+'"></div></td><td class="'+f.cl.sheetPaneTd+'"><div id="'+f.id.pane+f.i+'" class="'+f.cl.pane+'"></div></td></tr></tbody></table>')},chartCache:[],safeImg:function(j,i){return jQuery("<img />").hide().load(function(){jQuery(this).fadeIn(function(){jQuery(this).addClass("safeImg");f.attrH.setHeight(parseInt(i),"cell",false)})}).attr("src",j)},inPlaceEdit:function(p){f.obj.inPlaceEdit().remove();var n=f.obj.formula();var m=p.offset();var l=p.attr("style");var j=p.width();var k=p.height();var i=jQuery('<textarea id="'+f.id.inPlaceEdit+'" class="'+f.cl.inPlaceEdit+" "+f.cl.uiInPlaceEdit+'" />').css("left",m.left).css("top",m.top).width(j).height(k).keydown(f.evt.inPlaceEditOnKeyDown).keyup(function(){n.val(i.val())}).change(function(){n.val(i.val())}).focus(function(){f.setNav(false)}).focusout(function(){f.setNav(true)}).blur(function(){f.setNav(true)}).bind("paste",f.evt.pasteOverCells).appendTo("body").val(n.val()).focus().select();if(jQuery.fn.elastic){i.elastic()}},autoFiller:function(){return jQuery('<div id="'+(f.id.autoFiller+f.i)+'" class="'+f.cl.autoFiller+" "+f.cl.uiAutoFiller+'"><div class="'+f.cl.autoFillerHandle+'" /><div class="'+f.cl.autoFillerCover+'" /></div>').mousedown(function(i){var k=f.cellLast.td;if(k){var j=f.getTdLocation(k);f.cellSetActive(k,j,true,f.autoFillerNotGroup,function(){var m=f.obj.cellHighlighted();var l=f.getTdLocation(m.first());f.fillUpOrDown(l.row<j.row||l.col<j.col);f.autoFillerGoToTd(m.last());f.autoFillerNotGroup=false})}})}},autoFillerNotGroup:true,sizeSync:{},updateCellsAfterPasteToFormula:function(w){var v=0;var t=f.obj.formula();w=(w?w:t.val());var s={row:f.cellLast.row,col:f.cellLast.col};var l=t.val();var n=l;if(s.row==-1&&s.col==-1){return false}var q=jQuery("<div />");var u=jQuery("<div />");var y=l.split(/\n/g);for(var r=0;r<y.length;r++){var k=y[r].split(/\t/g);for(var p=0;p<k.length;p++){v++;var m=jQuery(f.getTd(f.i,r+s.row,p+s.col));if(m.length){var x=f.spreadsheets[f.i][r+s.row][p+s.col];q.append(m.clone());if((k[p]+"").charAt(0)=="="){x.formula=k[p];m.attr("formula",k[p])}else{x.formula=null;x.value=k[p];m.html(k[p]).removeAttr("formula")}u.append(m.clone());if(r==0&&p==0){n=k[p]}}}}if(l!=n){t.val(n)}f.cellUndoable.add(q.children());f.fillUpOrDown(false,false,n);f.cellUndoable.add(u.children());f.setDirty(true);f.evt.cellEditDone(true)},evt:{keyDownHandler:{enterOnInPlaceEdit:function(i){if(!i.shiftKey){return f.evt.cellSetFocusFromKeyCode(i)}else{return true}},enter:function(i){if(!f.cellLast.isEdit&&!i.ctrlKey){f.cellLast.td.dblclick();return false}else{return this.enterOnInPlaceEdit(i)}},tab:function(i){return f.evt.cellSetFocusFromKeyCode(i)},findCell:function(i){if(i.ctrlKey){f.cellFind();return false}return true},redo:function(i){if(i.ctrlKey&&!f.cellLast.isEdit){f.cellUndoable.undoOrRedo();return false}return true},undo:function(i){if(i.ctrlKey&&!f.cellLast.isEdit){f.cellUndoable.undoOrRedo(true);return false}return true},pageUpDown:function(i){var l=f.obj.pane();var k=f.cellLast.td.position().left;var j=0;if(i){j=0;l.scrollTop(l.scrollTop()-l.height())}else{j=l.height()-(d.colMargin*3);l.scrollTop(l.scrollTop()+j)}return f.evt.cellSetFocusFromXY(k,j)},formulaKeydown:function(i){switch(i.keyCode){case key.ESCAPE:f.evt.cellEditAbandon();break;case key.ENTER:f.evt.cellSetFocusFromKeyCode(i);return false;break;default:f.cellLast.isEdit=true}},documentKeydown:function(i){if(f.nav){switch(i.keyCode){case key.TAB:f.evt.keyDownHandler.tab(i);break;case key.ENTER:case key.LEFT:case key.UP:case key.RIGHT:case key.DOWN:(i.shiftKey?f.evt.cellSetHighlightFromKeyCode(i):f.evt.cellSetFocusFromKeyCode(i));break;case key.PAGE_UP:f.evt.keyDownHandler.pageUpDown(true);break;case key.PAGE_DOWN:f.evt.keyDownHandler.pageUpDown();break;case key.HOME:case key.END:f.evt.cellSetFocusFromKeyCode(i);break;case key.V:f.evt.pasteOverCells(i);break;case key.Y:f.evt.keyDownHandler.redo(i);break;case key.Z:f.evt.keyDownHandler.undo(i);break;case key.ESCAPE:f.evt.cellEditAbandon();break;case key.F:f.evt.keyDownHandler.findCell(i);break;case key.CONTROL:case key.CAPS_LOCK:case key.SHIFT:case key.ALT:break;default:f.obj.cellActive().dblclick();return true}return false}}},pasteOverCells:function(k){if(k.ctrlKey||k.type=="paste"){var j=function(){f.updateCellsAfterPasteToFormula()};var i=jQuery(document).one("keyup",function(){j();j=function(){};i.mouseup()}).one("mouseup",function(){j();j=function(){};i.keyup()});return true}},inPlaceEditOnKeyDown:function(i){switch(i.keyCode){case key.ENTER:return f.evt.keyDownHandler.enterOnInPlaceEdit(i);break;case key.TAB:return f.evt.keyDownHandler.tab(i);break;case key.ESCAPE:f.evt.cellEditAbandon();return false;break}},formulaChange:function(i){f.obj.inPlaceEdit().val(f.obj.formula().val())},inPlaceEditChange:function(i){f.obj.formula().val(f.obj.inPlaceEdit().val())},cellEditDone:function(k){switch(f.cellLast.isEdit||k){case true:f.obj.inPlaceEdit().remove();var n=f.obj.formula();var m=f.cellLast.td;switch(f.isFormulaEditable(m)){case true:if(m&&f.cellLast.row>-1&&f.cellLast.col>-1){f.cellUndoable.add(m);var j=n.val();var l=m.text();var i=f.spreadsheets[f.i][f.cellLast.row][f.cellLast.col];if(j.charAt(0)=="="){m.attr("formula",j).html("");i.value=j;i.formula=j}else{m.removeAttr("formula").html(j);i.value=j;i.formula=null}i.calcCount=0;if(j!=l||k){f.calc()}f.attrH.setHeight(f.cellLast.row,"cell");f.cellUndoable.add(m);f.cellLast.isEdit=false;f.setDirty(true);d.fnAfterCellEdit({td:f.cellLast.td,row:f.cellLast.row,col:f.cellLast.col,spreadsheetIndex:f.i,sheetIndex:c})}}break;default:f.attrH.setHeight(f.cellLast.row,"cell",false)}},cellEditAbandon:function(i){f.obj.inPlaceEdit().remove();f.themeRoller.cell.clearActive();f.themeRoller.bar.clearActive();f.themeRoller.cell.clearHighlighted();if(!i){f.calc()}f.cellLast.td=jQuery("<td />");f.cellLast.row=-1;f.cellLast.col=-1;f.rowLast=-1;f.colLast=-1;f.labelUpdate("",true);f.obj.formula().val("");if(d.autoFiller){f.obj.autoFiller().hide()}return false},cellSetFocusFromXY:function(j,i,k){var l=f.getTdFromXY(j,i,k);if(f.isTd(l)){f.themeRoller.cell.clearHighlighted();f.cellEdit(l);return false}else{return true}},cellSetHighlightFromKeyCode:function(l){var m=f.highlightedLast.colLast;var k=f.highlightedLast.rowLast;var i=f.sheetSize();jQuery(f.cellLast.td).mousedown();switch(l.keyCode){case key.UP:k--;break;case key.DOWN:k++;break;case key.LEFT:m--;break;case key.RIGHT:m++;break}function j(p,n){if(p<0){return 0}if(p>n){return n}return p}k=j(k,i.height);m=j(m,i.width);td=f.getTd(f.i,k,m);jQuery(td).mousemove().mouseup();f.highlightedLast.rowLast=k;f.highlightedLast.colLast=m;return false},cellSetFocusFromKeyCode:function(m){var q=f.cellLast.col;var j=f.cellLast.row;var l=false;switch(m.keyCode){case key.UP:j--;break;case key.DOWN:j++;break;case key.LEFT:q--;break;case key.RIGHT:q++;break;case key.ENTER:j++;l=true;if(f.highlightedLast.td.length>1){var k=f.obj.inPlaceEdit();var i=k.val();k.remove();f.updateCellsAfterPasteToFormula(i);return true}else{if(d.autoAddCells){if(f.cellLast.row==f.sheetSize().height){f.controlFactory.addRow(":last")}}}break;case key.TAB:l=true;if(m.shiftKey){q--}else{q++}if(d.autoAddCells){if(f.cellLast.col==f.sheetSize().width){f.controlFactory.addColumn(":last")}}break;case key.HOME:q=0;break;case key.END:q=f.cellLast.td.parent().find("td").length-1;break}q=(q<0?0:q);j=(j<0?0:j);if(!f.cellLast.isEdit||l){var p=f.getTd(f.i,j,q);if(p){f.themeRoller.cell.clearHighlighted();p=jQuery(p);if(p.is(":hidden")){function n(s,r){if(r){q++;s=s.next()}else{q--;s=s.prev()}if(s.is(":hidden")&&s.length){return n(s,r)}return s}p=n(p,q>f.cellLast.col)}f.cellEdit(p);return false}}return true},cellOnMouseDown:function(i){f.obj.formula().blur();if(i.shiftKey){f.getTdRange(i,f.obj.formula().val())}else{f.cellEdit(jQuery(i.target),true)}},cellOnDblClick:function(i){f.cellLast.isEdit=f.isSheetEdit=true;f.controlFactory.inPlaceEdit(f.cellLast.td)},scrollBars:function(j){var i={barLeft:f.obj.barLeftParent(),barTop:f.obj.barTopParent()};j.scroll(function(){i.barTop.scrollLeft(j.scrollLeft());i.barLeft.scrollTop(j.scrollTop());d.fnPaneScroll(j,f.i)})},barMouseDown:{select:function(j,i,k){k(i.target);j.unbind("mouseover").mouseover(function(l){k(l.target)});jQuery(document).one("mouseup",function(){j.unbind("mouseover").unbind("mouseup")});return false},first:0,last:0,height:function(j){var i=function(){};j.unbind("mousedown").mousedown(function(l){var k=f.getBarLeftIndex(l.target);if(k==-1){return false}f.evt.barMouseDown.first=f.evt.barMouseDown.last=f.rowLast=k;f.evt.barMouseDown.select(j,l,i);return false}).bind("contextmenu",function(l){var k=f.getBarLeftIndex(l.target);if(k==-1){return false}j.parent().mousedown().mouseup();f.controlFactory.barLeftMenu(l,k);return false}).parent().mouseover(function(l){if(jQuery(l.target).attr("id")){return false}var k=f.getBarLeftIndex(l.target);if(k==-1){return false}f.resizeBarLeft(l);if(d.editable){f.controlFactory.barLeftHandle(j,k)}});if(d.editable){i=function(l){if(!l){return false}if(jQuery(l).attr("id")){return false}var k=f.getBarLeftIndex(l);if(k==-1){return false}f.rowLast=k;f.evt.barMouseDown.last=k;f.cellSetActiveBar("row",f.evt.barMouseDown.first,f.evt.barMouseDown.last)}}},width:function(k){var i=function(){};var j=0;k.unbind("mousedown").mousedown(function(m){var l=f.getBarTopIndex(m.target);if(l==-1){return false}f.evt.barMouseDown.first=f.evt.barMouseDown.last=f.colLast=l;f.evt.barMouseDown.select(k,m,i);return false}).bind("contextmenu",function(m){var l=f.getBarTopIndex(m.target);if(l==-1){return false}k.parent().mousedown().mouseup();f.controlFactory.barTopMenu(m,l);return false}).parent().mouseover(function(m){if(jQuery(m.target).attr("id")){return false}var l=f.getBarTopIndex(m.target);if(l==-1){return false}f.resizeBarTop(m);if(d.editable){f.controlFactory.barTopHandle(k,l);f.controlFactory.barTopMenu(m,l,jQuery(m.target))}return false});if(d.editable){i=function(m){if(!m){return false}if(jQuery(m).attr("id")){return false}var l=f.getBarTopIndex(m);if(l==-1){return false}f.colLast=l;f.evt.barMouseDown.last=l;f.cellSetActiveBar("col",f.evt.barMouseDown.first,f.evt.barMouseDown.last)}}}}},isTd:function(i){i=(i[0]?i[0]:[i]);if(i[0]){if(!isNaN(i[0].cellIndex)){return true}}return false},isFormulaEditable:function(i){if(d.lockFormulas){if(i.attr("formula")!==undefined){return false}}return true},toggleFullScreen:function(){if(f.obj.fullScreen().is(":visible")){jQuery("body").removeClass("bodyNoScroll");d.parent=b;var i=d.parent.width();var j=d.parent.height();d.width=i;d.height=j;f.obj.tabContainer().insertAfter(d.parent.append(f.obj.fullScreen().children())).removeClass(f.cl.tabContainerFullScreen);f.obj.fullScreen().remove();f.sheetSyncSize()}else{jQuery("body").addClass("bodyNoScroll");var i=h.width()-15;var j=h.height()-35;d.width=i;d.height=j;f.obj.tabContainer().insertAfter(jQuery('<div class="'+f.cl.fullScreen+" "+f.cl.uiFullScreen+'" />').append(d.parent.children()).appendTo("body")).addClass(f.cl.tabContainerFullScreen);d.parent=f.obj.fullScreen();f.sheetSyncSize()}},renameSpreadsheet:function(j){if(isNaN(j)){return false}if(j>-1){f.sheetTab()}},switchSpreadsheet:function(j){if(isNaN(j)){return false}if(j==-1){f.addSheet("5x10")}else{if(j!=f.i){f.setActiveSheet(j);f.calc(j)}}d.fnSwitchSheet(j);return false},tuneTableForSheetUse:function(i){i.addClass(f.cl.sheet).attr("id",f.id.sheet+f.i).attr("border","1px").attr("cellpadding","0").attr("cellspacing","0");i.find("td."+f.cl.cellActive).removeClass(f.cl.cellActive);return i},attrH:{width:function(j,i){return jQuery(j).outerWidth()-(i?0:d.boxModelCorrection)},widthReverse:function(j,i){return jQuery(j).outerWidth()+(i?0:d.boxModelCorrection)},height:function(j,i){return jQuery(j).outerHeight()-(i?0:d.boxModelCorrection)},heightReverse:function(j,i){return jQuery(j).outerHeight()+(i?0:d.boxModelCorrection)},syncSheetWidthFromTds:function(j){var i=0;j=(j?j:f.obj.sheet());j.find("col").each(function(){i+=jQuery(this).width()});j.width(i);return i},setHeight:function(m,s,l,j){var p=0;var n=0;var r;switch(s){case"cell":j=(j?j:f.obj.barLeft().children().eq(m));n=f.attrH.height(jQuery(f.getTd(f.i,m,0)).parent().andSelf(),l);break;case"bar":if(!j){var q=jQuery(f.getTd(f.i,m,0)).parent();var k=q.children();j=q.add(k)}n=f.attrH.heightReverse(f.obj.barLeft().children().eq(m),l);break}if(n){jQuery(j).height(n).css("height",n+"px").attr("height",n+"px")}return j}},setTdIds:function(k,j){if(!g||!k){k=f.obj.sheet();j=f.i}f.spreadsheets[j]=[];k.find("tr").each(function(i){jQuery(this).children().each(function(l){var m=jQuery(this).attr("id",f.getTdId(j,i,l));f.createCell(j,i,l,m.text(),m.attr("formula"))})})},setControlIds:function(){var i=function(j,k){j.each(function(l){jQuery(this).attr("id",k+l)})};i(f.obj.sheetAll().each(function(j){f.setTdIds(jQuery(this),j)}),f.id.sheet);i(f.obj.barTopAll(),f.id.barTop);i(f.obj.barTopParentAll(),f.id.barTopParent);i(f.obj.barLeftAll(),f.id.barLeft);i(f.obj.barLeftParentAll(),f.id.barLeftParent);i(f.obj.barCornerAll(),f.id.barCorner);i(f.obj.barCornerParentAll(),f.id.barCornerParent);i(f.obj.tableControlAll(),f.id.tableControl);i(f.obj.paneAll(),f.id.pane);i(f.obj.tabAll().each(function(k){jQuery(this).attr("i",k)}),f.id.tab)},toggleHide:{row:function(j){if(!j){j=f.obj.cellActive().parent().attr("rowIndex")}if(j){var k=f.obj.barLeft().children().eq(j);if(k.is(":visible")){k.hide();f.obj.sheet().find("tr").eq(j).hide()}else{k.show();f.obj.sheet().find("tr").eq(j).show()}}else{alert(f.msg.toggleHideRow)}},rowAll:function(){f.obj.sheet().find("tr").show();f.obj.barLeft().children().show()},column:function(j){if(!j){j=f.obj.cellActive().attr("cellIndex")}if(j){var k=f.obj.barTop().children().eq(j);if(k.is(":visible")){f.obj.sheet().find("tbody tr").each(function(){jQuery(this).children().eq(j).hide()});k.hide();f.obj.sheet().find("colgroup col").eq(j).hide();f.toggleHide.columnSizeManage()}}else{alert(f.msg.toggleHideColumn)}},columnAll:function(){},columnSizeManage:function(){var i=f.obj.barTop().width();var j=0;var j=0;f.obj.barTop().children().each(function(){var k=jQuery(this);if(k.is(":hidden")){j+=k.width()}});f.obj.barTop().width(i);f.obj.sheet().width(i)}},merge:function(){var m="";var s="";var t=f.obj.cellHighlighted();var q;var j=f.getTdLocation(t.first());var k=f.getTdLocation(t.last());var p=(k.col-j.col)+1;if(t.length>1&&j.row){for(var n=j.col;n<=k.col;n++){var l=jQuery(f.getTd(f.i,j.row,n)).hide();var r=f.spreadsheets[f.i][j.row][n];m=(r.formula?"("+r.formula.replace("=","")+")":r.value)+m;if(n!=j.col){r.formula=null;r.value;l.attr("formula","").html("").hide()}}var r=t.first().show().attr("colspan",p).html(m);f.setDirty(true);f.calc()}else{if(!j.row){alert(f.msg.merge)}}},unmerge:function(){var s=f.obj.cellHighlighted().first();var m=f.getTdLocation(s);var p=s.attr("formula");var r=s.text();r=(p?p:r);var q=s.attr("rowspan");var n=s.attr("colspan");n=parseInt(n?n:1);var j="<td />";var l="";if(n){for(var k=0;k<n;k++){l+=j}}for(var k=m.col;k<n;k++){jQuery(f.getTd(f.i,m.row,k)).show()}s.removeAttr("colspan");f.setDirty(true);f.calc()},fillUpOrDown:function(q,p,r){var t=f.obj.cellHighlighted();var i=f.obj.cellActive();f.cellUndoable.add(t);var s=i.hasClass(f.cl.uiCellHighlighted);var m=f.getTdLocation(t.first());var u=f.getTdLocation(t.last());r=(r?r:f.obj.formula().val());var l={row:0,col:0};var k;var j=r;var n;if(r.charAt(0)=="="){n=function(w,x,v){k=jQuery(this);if(q){l.row=-u.row+x;l.col=-u.col+v}else{l.row=x-m.row;l.col=v-m.col}j=f.reparseFormula(r,l);f.spreadsheets[w][x][v].formula=j;k.attr("formula",j).html("")}}else{if(q&&!isNaN(j)){j*=1;j-=u.row;j-=u.col}n=function(w,x,v){k=jQuery(this);f.spreadsheets[w][x][v].formula=null;f.spreadsheets[w][x][v].value=j;k.removeAttr("formula").html(j);if(!isNaN(j)){j++}}}f.cycleCells(n,m,u);f.setDirty(true);f.calc();f.cellUndoable.add(t)},offsetFormulas:function(p,n,j){var i=f.sheetSize();var m={first:p,last:{row:i.height,col:i.width}};var k={first:{row:0,col:0},last:{row:i.height,col:i.width}};f.log("offsetFormulas from - Col:"+p.col+",Row:"+p.row);f.log("Is before loc:"+(j?"true":"false"));f.log("Offset: - Col:"+n.col+",Row:"+n.row);function l(s,q){var r=false;if(j){if(s>=q){r=true}}else{if(s>q){r=true}}return r}f.cycleCells(function(r,s,q){var u=jQuery(this);var t=u.attr("formula");if(t&&f.isFormulaEditable(u)){t=f.reparseFormula(t,n,function(v){return{row:l(v.row,p.row),col:l(v.col,p.col)}});f.spreadsheets[r][s][q].formula=t;u.attr("formula",t)}},k.first,k.last);f.evt.cellEditDone();f.calc()},reparseFormula:function(k,j,i){return k.replace(jSE.regEx.cell,function(m,n,q,r){var p=jSE.parseLocation(m);if(i){var l=i(p);if(l.col||l.row){if(l.col){p.col+=j.col}if(l.row){p.row+=j.row}return f.makeFormula(p)}}else{return f.makeFormula(p,j)}return m})},makeFormula:function(j,i){i=jQuery.extend({row:0,col:0},i);j.col+=i.col;j.row+=i.row;if(j.col<0){j.col=0}if(j.row<0){j.row=0}return jSE.parseCellName(j.col,j.row)},cycleCells:function(l,p,m,k){k=(k?k:f.i);p=(p?p:{row:0,col:0});if(!m){var j=f.sheetSize(jQuery("#"+f.id.sheet+k));m={row:j.height,col:j.width}}for(var n=p.row;n<=m.row;n++){for(var i=p.col;i<=m.col;i++){var q=f.getTd(k,n,i);if(q){l.apply(q,[k,n,i])}}}},cycleCellsAll:function(m){for(var l=0;l<=f.sheetCount;l++){var k=f.sheetSize(jQuery("#"+f.id.sheet+l));var j={row:k.height,col:k.width};f.cycleCells(m,{row:0,col:0},j,l)}},cycleCellsAndMaintainPoint:function(m,q,n){var p=[];for(var l=(q.row<n.row?q.row:n.row);l<=(q.row>n.row?q.row:n.row);l++){for(var k=(q.col<n.col?q.col:n.col);k<=(q.col>n.col?q.col:n.col);k++){p.push(f.getTd(f.i,l,k));m(p[p.length-1])}}return p},addTab:function(){jQuery('<span class="'+f.cl.uiTab+' ui-corner-bottom"><a class="'+f.cl.tab+'" id="'+f.id.tab+f.i+'" i="'+f.i+'">'+f.sheetTab(true)+"</a></span>").insertBefore(f.obj.tabContainer().find("span:last"))},sheetDecorate:function(i){f.formatSheet(i);f.sheetSyncSizeToCols(i);f.sheetDecorateRemove()},formatSheet:function(k){var i=0;if(k.find("tbody").length<1){k.wrapInner("<tbody />")}if(k.find("colgroup").length<1||k.find("col").length<1){k.remove("colgroup");var j=jQuery("<colgroup />");k.find("tr:first").children().each(function(){var l=d.newColumnWidth;jQuery("<col />").width(l).css("width",(l)+"px").attr("width",(l)+"px").appendTo(j);i+=l});k.find("tr").each(function(){jQuery(this).height(d.colMargin).css("height",d.colMargin+"px").attr("height",d.colMargin+"px")});j.prependTo(k)}k.removeAttr("width").css("width","").width(i)},checkMinSize:function(k){var j=f.sheetSize();var l=0;var i=0;if((j.width)<d.minSize.cols){i=d.minSize.cols-j.width-1}if(i){f.controlFactory.addColumnMulti(i,false,true)}if((j.height)<d.minSize.rows){l=d.minSize.rows-j.height-1}if(l){f.controlFactory.addRowMulti(l,false,true)}},themeRoller:{start:function(){d.parent.addClass(f.cl.uiParent);f.obj.sheet().addClass(f.cl.uiSheet);f.obj.barLeft().children().addClass(f.cl.uiBar);f.obj.barTop().children().addClass(f.cl.uiBar);f.obj.barCornerParent().addClass(f.cl.uiBar);f.obj.controls().addClass(f.cl.uiControl);f.obj.label().addClass(f.cl.uiControl);f.obj.formula().addClass(f.cl.uiControlTextBox)},cell:{setActive:function(){this.clearActive();this.setHighlighted(f.cellLast.td.addClass(f.cl.cellActive))},setHighlighted:function(i){jQuery(i).addClass(f.cl.cellHighlighted+" "+f.cl.uiCellHighlighted)},clearActive:function(){f.obj.cellActive().removeClass(f.cl.cellActive)},isHighlighted:function(){return(f.highlightedLast.td?true:false)},clearHighlighted:function(){if(f.themeRoller.cell.isHighlighted()){f.obj.cellHighlighted().removeClass(f.cl.cellHighlighted+" "+f.cl.uiCellHighlighted)}f.highlightedLast.rowStart=-1;f.highlightedLast.colStart=-1;f.highlightedLast.rowEnd=-1;f.highlightedLast.colEnd=-1;f.highlightedLast.td=jQuery("<td />")}},bar:{style:function(i){jQuery(i).addClass(f.cl.uiBar)},setActive:function(k,j){switch(k){case"top":f.obj.barTop().children().eq(j).addClass(f.cl.uiActive);break;case"left":f.obj.barLeft().children().eq(j).addClass(f.cl.uiActive);break}},clearActive:function(){f.obj.barTop().add(f.obj.barLeft()).children("."+f.cl.uiActive).removeClass(f.cl.uiActive)}},tab:{setActive:function(i){this.clearActive();f.obj.tab().parent().addClass(f.cl.uiTabActive)},clearActive:function(){f.obj.tabContainer().find("span."+f.cl.uiTabActive).removeClass(f.cl.uiTabActive)}},resize:function(){f.resizable(d.parent,{minWidth:d.width*0.5,minHeight:d.height*0.5,start:function(){f.obj.ui().hide()},stop:function(){f.obj.ui().show();d.width=d.parent.width();d.height=d.parent.height();f.sheetSyncSize()}});var i=jQuery("<span />");f.resizable(f.obj.formula().wrap(i).parent(),{minHeight:f.obj.formula().height(),maxHeight:78,handles:"s",resize:function(k,j){f.obj.formula().height(j.size.height);f.sheetSyncSize()}})}},resizable:function(j,i){if(j.attr("resizable")){j.resizable("destroy")}j.resizable(i).attr("resizable",true)},busy:false,draggable:function(j,i){if(j.attr("draggable")){j.resizable("destroy")}j.draggable(i).attr("draggable",true)},resizeBarTop:function(i){f.resizable(jQuery(i.target),{handles:"e",start:function(){f.busy=true;f.obj.barHelper().remove()},stop:function(m,l){f.busy=false;var k=f.getBarTopIndex(this);f.sheetSyncSizeToDivs();var j=f.attrH.width(this,true);f.obj.sheet().find("col").eq(k).width(j).css("width",j+"px").attr("width",j+"px");f.followMe();f.obj.pane().scroll()}})},resizeBarLeft:function(i){f.resizable(jQuery(i.target),{handles:"s",start:function(){f.busy=true;f.obj.barHelper().remove()},stop:function(l,k){f.busy=false;var j=f.getBarLeftIndex(jQuery(this));f.attrH.setHeight(j,"bar",true);f.attrH.setHeight(j,"cell");f.followMe();f.obj.pane().scroll()}})},sheetDecorateRemove:function(j){var i=(j?f.obj.sheetAll().clone():f.obj.sheetAll());jQuery(i).find("td."+f.cl.cellActive).removeClass(f.cl.cellActive+" "+f.cl.uiCellActive);jQuery(i).find("td."+f.cl.cellHighlighted).removeClass(f.cl.cellHighlighted+" "+f.cl.uiCellHighlighted);return i},labelUpdate:function(j,i){if(!i){f.obj.label().html(jSE.parseCellName(j.col,j.row))}else{f.obj.label().html(j)}},cellEdit:function(n,j,k){f.autoFillerNotGroup=true;f.evt.cellEditDone();f.followMe(n);f.obj.pane().scroll();var l=f.getTdLocation(n);f.labelUpdate(l);var i=n.attr("formula");if(!i){i=n.text()}var m=f.obj.formula().val(i).blur();if(!k){}f.cellSetActive(n,l,j)},cellSetActive:function(q,p,l,j,n){if(typeof(p.col)!="undefined"){f.cellLast.td=q;f.cellLast.row=f.rowLast=p.row;f.cellLast.col=f.colLast=p.col;f.themeRoller.bar.clearActive();f.themeRoller.cell.clearHighlighted();f.highlightedLast.td=q;f.themeRoller.cell.setActive();f.themeRoller.bar.setActive("left",f.cellLast.row);f.themeRoller.bar.setActive("top",f.cellLast.col);var i;var m;f.highlightedLast.rowStart=p.row;f.highlightedLast.colStart=p.col;f.highlightedLast.rowLast=p.row;f.highlightedLast.colLast=p.col;switch(d.cellSelectModel){case"excel":case"gdocs":i=function(){};m=f.themeRoller.cell.clearHighlighted;break;case"oo":i=function(r){var s=jQuery(r);if(f.isTd(s)){f.cellEdit(s)}};m=function(){};break}if(l){var k=p;f.obj.pane().mousemove(function(t){var r=f.getTdLocation([t.target]);var s=true;if(j){s=false;if(p.col==r.col||p.row==r.row){s=true}}if((k.col!=r.col||k.row!=r.row)&&s){m();f.highlightedLast.colEnd=r.col;f.highlightedLast.rowEnd=r.row;i(t.target);f.highlightedLast.td=f.cycleCellsAndMaintainPoint(f.themeRoller.cell.setHighlighted,p,r)}k=r});jQuery(document).one("mouseup",function(){f.obj.pane().unbind("mousemove").unbind("mouseup");if(jQuery.isFunction(n)){n()}})}}},colLast:0,rowLast:0,cellLast:{td:jQuery("<td />"),row:-1,col:-1,isEdit:false},highlightedLast:{td:jQuery("<td />"),rowStart:-1,colStart:-1,rowEnd:-1,colEnd:-1},cellStyleToggle:function(k,j){var i=f.obj.cellHighlighted();f.cellUndoable.add(i);if(j){i.removeClass(j)}if(i.hasClass(k)){i.removeClass(k)}else{i.addClass(k)}f.cellUndoable.add(i);return false},fontReSize:function(k){var i=0;switch(k){case"up":i=1;break;case"down":i=-1;break}var j=f.obj.cellHighlighted();f.cellUndoable.add(j);j.each(function(m){cell=jQuery(this);var l=(cell.css("font-size")+"").replace("px","");var n=parseInt(l?l:10)+i;cell.css("font-size",n+"px")});f.cellUndoable.add(j)},callStack:0,updateCellValue:function(k,n,j){if(!f.spreadsheets[k]){return"Error: Sheet not found"}if(!f.spreadsheets[k][n]){return"Error: Row not found"}if(!f.spreadsheets[k][n][j]){return"Error: Column not found"}var i=f.spreadsheets[k][n][j];i.oldValue=i.value;if(i.state){throw ("Error: Loop Detected")}i.state="red";if(i.calcCount<1&&i.calcLast!=f.calcLast){i.calcLast=f.calcLast;i.calcCount++;if(i.formula){try{if(i.formula.charAt(0)=="="){i.formula=i.formula.substring(1,i.formula.length)}var m;if(f.callStack){if(!i.parser){i.parser=(new f.parser)}m=i.parser}else{m=f.Parser}f.callStack++;i.value=m.parse(i.formula,f.cellIdHandlers,{sheet:k,row:n,col:j,cell:i,s:d,editable:d.editable,jS:f})}catch(l){i.value=l.toString().replace(/\n/g,"<br />");b.one("calculation",function(){f.attrH.setHeight(n,"cell",false)});f.alertFormulaError(i.value)}f.callStack--}if(i.html){jQuery(f.getTd(k,n,j)).html(i.html)}else{jQuery(f.getTd(k,n,j)).html(i.value)}}i.state=null;return i.value},cellIdHandlers:{cellValue:function(j){var i=jSE.parseLocation(j);return f.updateCellValue(this.sheet,i.row,i.col)},cellRangeValue:function(p){p=p.split(":");var q=jSE.parseLocation(p[0]);var l=jSE.parseLocation(p[1]);var k=[];for(var n=q.row;n<=l.row;n++){for(var m=q.col;m<=l.col;m++){k.push(f.updateCellValue(this.sheet,n,m))}}return[k]},fixedCellValue:function(i){return f.cellIdHandlers.cellValue.apply(this,[(i+"").replace(/[$]/g,"")])},fixedCellRangeValue:function(i){return f.cellIdHandlers.cellRangeValue.apply(this,[(i+"").replace(/[$]/g,"")])},remoteCellValue:function(k){var i,j;k=k.replace(jSE.regEx.remoteCell,function(p,n,m,l,q){i=(m*1)-1;j=jSE.parseLocation(l+q);return p});return f.updateCellValue(i,j.row,j.col)},remoteCellRangeValue:function(q){var p,r,l;q=q.replace(jSE.regEx.remoteCellRange,function(u,t,s,w,j,v,i){p=(s*1)-1;r=jSE.parseLocation(w+j);l=jSE.parseLocation(v+i);return u});var k=[];for(var n=r.row;n<=l.row;n++){for(var m=r.col;m<=l.col;m++){k.push(f.updateCellValue(p,n,m))}}return[k]},callFunction:function(k,j,i){if(!j){j=[""]}else{if(jQuery.isArray(j)){j=j.reverse()}else{j=[j]}}return(jQuery.sheet.fn[k]?jQuery.sheet.fn[k].apply(i,j):"Error: Function Not Found")}},alertFormulaError:function(i){alert("cell:"+row+" ;"+col+'\nvalue: "'+cell.formula+'"\nerror: \n'+e)},context:{},calcLast:0,calc:function(i){i=(i?i:f.i);f.log("Calculation Started");f.calcLast=new Date();jSE.calc(i,f.spreadsheetsToArray()[i],f.updateCellValue);b.trigger("calculation");f.isSheetEdit=false;f.log("Calculation Ended")},refreshLabelsColumns:function(){var i=0;f.obj.barTop().children().each(function(j){jQuery(this).text(jSE.columnLabelString(j));i+=jQuery(this).width()});return i},refreshLabelsRows:function(){f.obj.barLeft().children().each(function(j){jQuery(this).text((j+1))})},addSheet:function(i){i=(i?i:prompt(f.msg.newSheet));if(i){f.evt.cellEditAbandon();f.setDirty(true);var j=f.controlFactory.sheetUI(jQuery.sheet.makeTable.fromSize(i),f.sheetCount+1,function(k){f.setActiveSheet(f.sheetCount)},true)}},deleteSheet:function(){f.obj.barHelper().remove();f.obj.tableControl().remove();f.obj.tabContainer().children().eq(f.i).remove();f.i=0;f.sheetCount--;f.setControlIds();f.setActiveSheet(f.i);f.setDirty(true)},deleteRow:function(i){f.obj.barLeft().children().eq(f.rowLast).remove();jQuery(f.getTd(f.i,f.rowLast,0)).parent().remove();f.refreshLabelsRows();f.setTdIds();f.obj.pane().scroll();f.offsetFormulas({row:f.rowLast,col:0},{row:-1,col:0});f.setDirty(true);f.evt.cellEditAbandon()},deleteColumn:function(k){f.obj.barHelper().remove();f.obj.barTop().children().eq(f.colLast).remove();f.obj.sheet().find("colgroup col").eq(f.colLast).remove();var m=f.sheetSize();for(var l=0;l<=m.height;l++){jQuery(f.getTd(f.i,l,f.colLast)).remove()}var j=f.refreshLabelsColumns();f.setTdIds();f.obj.sheet().width(j);f.obj.pane().scroll();f.offsetFormulas({row:0,col:f.colLast},{row:0,col:-1});f.setDirty(true);f.evt.cellEditAbandon()},sheetTab:function(j){var i="";if(j){i=f.obj.sheet().attr("title");i=(i?i:"Spreadsheet "+(f.i+1))}else{if(d.editable&&d.editableTabs){var k=prompt("What would you like the sheet's title to be?",f.sheetTab(true));if(!k){i=f.obj.sheet().attr("title");k=(i?i:"Spreadsheet"+(f.i+1))}else{f.setDirty(true);f.obj.sheet().attr("title",k);f.obj.tab().html(k);i=k}}}return jQuery("<div />").text(i).html()},print:function(j){var i=window.open();i.document.write("<html><body><xmp>"+j+"\n</xmp></body></html>");i.document.close()},viewSource:function(j){var k=f.sheetDecorateRemove(true);var i="";if(j){jQuery(k).each(function(){i+=f.HTMLtoPrettySource(this)})}else{i+=jQuery("<div />").html(k).html()}f.print(i);return false},saveSheet:function(){var i=f.sheetDecorateRemove(true);var j=jQuery("<div />").html(i).html();jQuery.ajax({url:d.urlSave,type:"POST",data:"s="+j,dataType:"html",success:function(k){f.setDirty(false);alert("Success! - "+k)}})},HTMLtoCompactSource:function(q){var k="";if(q.nodeType==1){k+="<"+q.tagName;m=false;var s=q.attributes.length;for(var p=0,m=false;p<s;p++){var l=q.attributes[p].name;var r=q.getAttribute(l);if(r){if(l=="contentEditable"&&r=="inherit"){continue}if(l=="class"){m=true}if(typeof(r)=="string"){k+=" "+l+'="'+r.replace(/"/g,"'")+'"'}else{if(l=="style"&&r.cssText){k+=' style="'+r.cssText+'"'}}}}if(q.tagName=="COL"){k+="/>"}else{k+=">";var j="";jQuery(q.childNodes).each(function(){j+=f.HTMLtoCompactSource(this)});k+=j;k+="</"+q.tagName+">"}}else{if(q.nodeType==3){k+=q.data.replace(/^\s*(.*)\s*$/g,"$1")}}return k},HTMLtoPrettySource:function(p,q){if(!q){q=""}var k="";if(p.nodeType==1){k+="\n"+q+"<"+p.tagName;var s=p.attributes.length;for(var m=0;m<s;m++){var l=p.attributes[m].name;var r=p.getAttribute(l);if(r){if(l=="contentEditable"&&r=="inherit"){continue}if(typeof(r)=="string"){k+=" "+l+'="'+r.replace(/"/g,"'")+'"'}else{if(l=="style"&&r.cssText){k+=' style="'+r.cssText+'"'}}}}if(p.childNodes.length<=0){k+="/>"}else{k+=">";var j="";var s=p.childNodes.length;for(var m=0;m<s;m++){j+=f.HTMLtoPrettySource(p.childNodes[m],q+" ")}k+=j;if(j.indexOf("\n")>=0){k+="\n"+q}k+="</"+p.tagName+">"}}else{if(p.nodeType==3){k+=p.data.replace(/^\s*(.*)\s*$/g,"$1")}}return k},followMe:function(k){k=(k?k:jQuery(f.cellLast.td));var j=f.obj.pane();var m=j.offset();var r=j.width();var i=j.height();var q=k.offset();var p=k.width();var n=k.height();var l=20;if((q.left+p+l)>(m.left+r)){j.stop().scrollTo(k,{axis:"x",duration:50,offset:-((r-p)-l)})}else{if(q.left<m.left){j.stop().scrollTo(k,{axis:"x",duration:50})}}if((q.top+n+l)>(m.top+i)){j.stop().scrollTo(k,{axis:"y",duration:50,offset:-((i-n)-l)})}else{if(q.top<m.top){j.stop().scrollTo(k,{axis:"y",duration:50})}}f.autoFillerGoToTd(k,n,p)},autoFillerGoToTd:function(k,i,j){k=(k?k:jQuery(f.cellLast.td));i=(i?i:k.height());j=(j?j:k.width());if(d.autoFiller){if(k.attr("id")){tdPos=k.position();f.obj.autoFiller().show().css("top",((tdPos.top+(i?i:k.height())-3)+"px")).css("left",((tdPos.left+(j?j:k.width())-3)+"px"))}}},isRowHeightSync:[],setActiveSheet:function(j){j=(j?j:0);f.obj.tableControlAll().hide().eq(j).show();f.i=j;f.themeRoller.tab.setActive();if(!f.isRowHeightSync[j]){f.isRowHeightSync[j]=true;f.obj.sheet().find("tr").each(function(i){f.attrH.setHeight(i,"cell")})}f.sheetSyncSize()},openSheetURL:function(i){d.urlGet=i;return f.openSheet()},openSheet:function(l,i){if(!f.isDirty?true:confirm(f.msg.openSheet)){f.controlFactory.header();var k=function(n,m){if(n==(m-1)){f.i=0;f.setActiveSheet();f.themeRoller.resize();for(var n=0;n<=f.sheetCount;n++){f.calc(n)}d.fnAfter()}};if(!l){jQuery("<div />").load(d.urlGet,function(){var m=jQuery(this).find("table");m.each(function(n){f.controlFactory.sheetUI(jQuery(this),n,function(){k(n,m.length)},true)})})}else{var j=jQuery("<div />").html(l).children("table");j.show().each(function(m){f.controlFactory.sheetUI(jQuery(this),m,function(){k(m,j.length)},(i?true:false))})}f.setDirty(false);return true}else{return false}},newSheet:function(){var i=prompt(f.msg.newSheet);if(i){f.openSheet(jQuery.sheet.makeTable.fromSize(i))}},importRow:function(j){f.controlFactory.addRow(null,null,":last");var i="";f.obj.sheet().find("tr:last td").each(function(k){jQuery(this).removeAttr("formula");try{if((j[k]+"").charAt(0)=="="){jQuery(this).attr("formula",j[k])}else{jQuery(this).html(j[k])}}catch(l){i+=l+";\n"}});if(i){alert(i)}f.setTdIds();f.calc()},importColumn:function(i){f.controlFactory.addColumn();var j="";f.obj.sheet().find("tr").each(function(k){var m=jQuery(this).find("td:last");try{if((i[k]+"").charAt(0)=="="){m.attr("formula",i[k])}else{m.html(i[k])}}catch(l){j+=l+";\n"}});if(j){alert(j)}f.setTdIds();f.calc()},exportSheet:{xml:function(j){var l=f.sheetDecorateRemove(true);var i="";var k=["<![CDATA[","]]>"];if(j){k=["",""]}jQuery(l).each(function(){var s="";var q=jQuery(this);var p=0;var r="";q.find("colgroup").children().each(function(t){r+="<c"+t+">"+(jQuery(this).attr("width")+"").replace("px","")+"</c"+t+">"});var m=q.find("tr");var n=m.length;m.each(function(v){var u="";var y=jQuery(this);var x=y.attr("height");var t=(x?x:d.colMargin);var w=y.find("td");p=w.length;w.each(function(A){var F=jQuery(this);var C=F.attr("colspan");C=(C>1?C:"");var E=F.attr("formula");var D=(E?E:F.text());var z=F.attr("class");var B=F.attr("style");u+="<c"+A+(B?' style="'+B+'"':"")+(z?' class="'+z+'"':"")+(C?' colspan="'+C+'"':"")+">"+D+"</c"+A+">"});s+="<r"+v+' h="'+t+'">'+u+"</r"+v+">"});i+='<document title="'+q.attr("title")+'"><metadata><columns>'+p+"</columns><rows>"+n+"</rows><col_widths>"+r+"</col_widths></metadata><data>"+s+"</data></document>"});return"<documents>"+i+"</documents>"},json:function(){var j=f.sheetDecorateRemove(true);var i=[];jQuery(j).each(function(){var l={};l.metadata={};l.data={};var p=jQuery(this);var k=p.find("tr");var m=k.length;var n=0;var q="";k.each(function(r){var t=jQuery(this);var s=t.find("td");n=s.length;l.data["r"+r]={};l.data["r"+r]["h"]=t.attr("height");s.each(function(u){var x=jQuery(this);var v=x.attr("colspan");v=(v>1?v:null);var w=x.attr("formula");l.data["r"+r]["c"+u]={value:(w?w:x.text()),style:x.attr("style"),colspan:v,cl:x.attr("class")}})});l.metadata={columns:n,rows:m,title:p.attr("title"),col_widths:{}};p.find("colgroup").children().each(function(r){l.metadata["col_widths"]["c"+r]=(jQuery(this).attr("width")+"").replace("px","")});i.push(l)});return i},html:function(){return f.sheetDecorateRemove(true)}},sheetSyncSizeToDivs:function(){var i=0;f.obj.barTop().children().each(function(){i+=jQuery(this).width()-d.boxModelCorrection});f.obj.sheet().width(i).attr("width",i+"px").css("width",i+"px");return i},sheetSyncSizeToCols:function(i){var j=0;i=(i?i:f.obj.sheet());i.find("colgroup col").each(function(){j+=jQuery(this).width()});i.width(j)},sheetSyncSize:function(){var j=d.height;if(!j){j=400}else{if(j<200){j=200}}d.parent.height(j).width(d.width);var i=d.width-f.attrH.width(f.obj.barLeftParent())-(d.boxModelCorrection);j=j-f.attrH.height(f.obj.controls())-f.attrH.height(f.obj.barTopParent())-(d.boxModelCorrection*2);f.obj.pane().height(j).width(i).parent().width(i);f.obj.ui().width(i+f.attrH.width(f.obj.barLeftParent()));f.obj.barLeftParent().height(j);f.obj.barTopParent().width(i).parent().width(i)},cellChangeStyle:function(i,j){f.cellUndoable.add(f.obj.cellHighlighted());f.obj.cellHighlighted().css(i,j);f.cellUndoable.add(f.obj.cellHighlighted())},cellFind:function(i){if(!i){i=prompt("What are you looking for in this spreadsheet?")}if(i){var j=f.obj.sheet().find('td:contains("'+i+'")');if(j.length<1){j=f.obj.sheet().find('td:contains("'+i.toLowerCase()+'")')}if(j.length<1){j=f.obj.sheet().find('td:contains("'+i.toUpperCase()+'")')}j=j.eq(0);if(j.length>0){f.cellEdit(j)}else{alert(f.msg.cellFind)}}},cellSetActiveBar:function(n,j,l){var r=f.sheetSize(jQuery("#"+f.id.sheet+f.i));var m=(j<l?j:l);var p=(j<l?l:j);var i=function(w,t,v,s,u){switch(d.cellSelectModel){case"oo":f.cellEdit(jQuery(f.getTd(f.i,s,u)));break;default:f.cellEdit(jQuery(f.getTd(f.i,t,v)));break}i=function(x){return x};return w};var q;var k=[];switch(n){case"col":q=function(){for(var t=0;t<=r.height;t++){for(var s=m;s<=p;s++){k.push(f.getTd(f.i,t,s));f.themeRoller.cell.setHighlighted(i(k[k.length-1],0,j,0,l))}}};break;case"row":q=function(){for(var t=m;t<=p;t++){for(var s=0;s<=r.width;s++){k.push(f.getTd(f.i,t,s));f.themeRoller.cell.setHighlighted(i(k[k.length-1],j,0,l,0))}}};break;case"all":q=function(){i=function(u){f.cellEdit(jQuery(u));i=function(){}};for(var t=0;t<=r.height;t++){for(var s=0;s<=r.width;s++){k.push(f.getTd(f.i,t,s));i(k[k.length-1]);f.themeRoller.cell.setHighlighted(k[k.length-1])}}m={row:0,col:0};p={row:r.height,col:r.width}};break}q();f.highlightedLast.td=k;f.highlightedLast.rowStart=m.row;f.highlightedLast.colStart=m.col;f.highlightedLast.rowEnd=p.row;f.highlightedLast.colEnd=p.col},sheetClearActive:function(){f.obj.formula().val("");f.obj.barSelected().removeClass(f.cl.barSelected)},getTdRange:function(l,r,p,q){f.cellLast.isEdit=true;var j=function(t){if(t.first.col>t.last.col||t.first.row>t.last.row){return{first:jSE.parseCellName(t.last.col,t.last.row),last:jSE.parseCellName(t.first.col,t.first.row)}}else{return{first:jSE.parseCellName(t.first.col,t.first.row),last:jSE.parseCellName(t.last.col,t.last.row)}}};var n=function(w){var t=j(w);var v=r+"";v=(v.match(/=/)?v:"="+v);if(p||v.charAt(v.length-1)!="("){v=v+(p?p:"")+"("}var x;var u="";if(t.first!=t.last){x=t.first+":"+t.last}else{x=t.first}if(v.charAt(v.length-1)=="("){u=")"}return v+x+u};var i="";if(l){var k={first:f.getTdLocation([l.target])};var m=f.obj.sheet().mousemove(function(t){k.last=f.getTdLocation([t.target]);i=n(k);if(!q){f.obj.formula().val(i);f.obj.inPlaceEdit().val(i)}});jQuery(document).one("mouseup",function(){m.unbind("mousemove");return i})}else{var s=f.obj.cellHighlighted().not(f.obj.cellActive());if(s.length){var k={first:f.getTdLocation(s.first()),last:f.getTdLocation(s.last())};i=n(k);if(!q){f.obj.formula().val(i);f.obj.inPlaceEdit().val(i)}return i}else{return""}}},getTdId:function(i,k,j){return c+"_table"+i+"_cell_c"+j+"_r"+k},getTd:function(i,k,j){return document.getElementById(f.getTdId(i,k,j))},getTdLocation:function(i){if(!i||!i[0]){return{col:0,row:0}}return{col:parseInt(i[0].cellIndex),row:parseInt(i[0].parentNode.rowIndex)}},getTdFromXY:function(k,j,l){var n=f.obj.pane();var i=(l?{left:0,top:0}:n.offset());j+=i.top+2;k+=i.left+2;if((j>=i.top&&j<=i.top+n.height())&&(k>=i.left&&k<=i.left+n.width())){var m=jQuery(document.elementFromPoint(k-h.scrollLeft(),j-h.scrollTop()));if(f.isTd(m)){return m}return false}},getBarLeftIndex:function(k){var j=jQuery.trim(jQuery(k).text());if(isNaN(j)){return -1}else{return j-1}},getBarTopIndex:function(l){var j=jQuery.trim(jQuery(l).text());if(!j){return -1}var k=jSE.columnLabelIndex(j);k=parseInt(k);if(isNaN(k)){return -1}else{return k}},EMPTY_VALUE:{},time:{now:new Date(),last:new Date(),diff:function(){return Math.abs(Math.ceil(this.last.getTime()-this.now.getTime())/1000).toFixed(5)},set:function(){this.last=this.now;this.now=new Date()},get:function(){return this.now.getHours()+":"+this.now.getMinutes()+":"+this.now.getSeconds()}},log:function(i){f.time.set();console.log(f.time.get()+", "+f.time.diff()+"; "+i)},replaceWithSafeImg:function(i){(i?i:f.obj.sheet().find("img")).each(function(){var j=jQuery(this).attr("src");jQuery(this).replaceWith(f.controlFactory.safeImg(j,f.getTdLocation(jQuery(this).parent()).row))})},isDirty:false,setDirty:function(i){f.isDirty=i},appendToFormula:function(i,k){var l=f.obj.formula();var j=l.val();if(j.charAt(0)!="="){j="="+j}l.val(j+i)},cellUndoable:{undoOrRedo:function(i){if(d.autoFiller){f.obj.autoFiller().hide()}if(i&&this.i>0){this.i--;this.i--}else{if(!i&&this.i<this.stack.length){this.i++;this.i++}}this.get().clone().each(function(){var j=jQuery(this);var k=j.attr("undoable");if(k){jQuery("#"+k).replaceWith(j.removeAttr("undoable").attr("id",k))}else{f.log("Not available.")}});f.themeRoller.cell.clearActive();f.themeRoller.bar.clearActive();f.themeRoller.cell.clearHighlighted();f.calc()},get:function(){return jQuery(this.stack[this.i])},add:function(k){var l=k.clone().each(function(){var i=jQuery(this);var m=i.attr("id");i.removeAttr("id").attr("undoable",m).removeClass(f.cl.cellHighlighted+" "+f.cl.uiCellHighlighted)});this.stack[this.i++]=l;if(this.stack.length>this.i){for(var j=this.stack.length;j>this.i;j--){this.stack.pop()}}if(this.stack.length>20){this.stack.shift()}},i:0,stack:[]},sheetSize:function(j){var i=f.getTdLocation((j?j:f.obj.sheet()).find("td:last"));return{width:i.col,height:i.row}},toggleState:function(i){if(d.allowToggleState){if(d.editable){f.evt.cellEditAbandon();f.saveSheet()}f.setDirty(false);d.editable=!d.editable;f.obj.tabContainer().remove();var j=(i?i:f.obj.sheetAll().clone());b.children().remove();f.openSheet(j,true)}},setCellRef:function(i){var j=f.obj.cellActive();loc=f.getTdLocation(j);cellRef=(i?i:prompt("Enter the name you would like to reference the cell by."));if(cellRef){f.spreadsheets[cellRef]=f.spreadsheets[f.i][loc.row][loc.col]}f.calc()}};var h=jQuery(window);d.fnBefore();var g;var a=function(){};f.lexer=function(){};f.lexer.prototype=parser.lexer;f.parser=function(){this.lexer=new f.lexer();this.yy={}};f.parser.prototype=parser;f.Parser=new f.parser;if(d.buildSheet){if(typeof(d.buildSheet)=="object"){g=d.buildSheet}else{if(d.buildSheet==true||d.buildSheet=="true"){g=jQuery(d.parent.html())}else{if(d.buildSheet.match(/x/i)){g=jQuery.sheet.makeTable.fromSize(d.buildSheet)}}}}d.origParent=b;d.parent.html("").addClass(f.cl.parent);b.bind("switchSpreadsheet",function(k,j){f.switchSpreadsheet(j)}).bind("renameSpreadsheet",function(k,j){f.renameSpreadsheet(j)});d.width=(d.width?d.width:d.parent.width());d.height=(d.height?d.height:d.parent.height());if(!d.log){f.log=a}if(!jQuery.ui||!d.resizable){f.resizable=f.draggable=a}if(!jQuery.support.boxModel){d.boxModelCorrection=0}if(!jQuery.scrollTo){f.followMe=a}if(!d.barMenus){f.controlFactory.barTopMenu=f.controlFactory.barLeftMenu=a}if(!d.freezableCells){f.controlFactory.barTopHandle=f.controlFactory.barLeftHandle=a}if(d.calcOff){f.calc=a}if(!window.Raphael){jSE.chart=a}h.resize(function(){if(f){d.width=d.parent.width();d.height=d.parent.height();f.sheetSyncSize()}});if(jQuery.sheet.fn){jQuery.sheet.fn=jQuery.extend(jQuery.sheet.fn,d.calculations);if(jQuery.sheet.advancedfn){jQuery.sheet.fn=jQuery.extend(jQuery.sheet.fn,jQuery.sheet.advancedfn)}if(jQuery.sheet.financefn){jQuery.sheet.fn=jQuery.extend(jQuery.sheet.fn,jQuery.sheet.financefn)}}if(!d.alertFormulaErrors){f.alertFormulaError=a}f.openSheet(g,d.forceColWidthsOnStartup);f.s=d;return f},makeTable:{xml:function(b){var a=jQuery("<div />");jQuery(b).find("document").each(function(v){var A=jQuery("<table />");var z=0;var m=jQuery("<colgroup />").appendTo(A);var d=jQuery("<tbody />");var t=jQuery(this).find("metadata");var B=t.find("columns").text();var n=t.find("rows").text();var D=jQuery(this).attr("title");var C=jQuery(this).find("data");var f=t.find("col_widths").children();for(var v=0;v<parseInt(jQuery.trim(B));v++){var p=parseInt(f.eq(v).text().replace("px",""));p=(p?p:120);z+=p;m.append('<col width="'+p+'px" style="width: '+p+'px;" />')}A.width(z).attr("title",D);for(var v=0;v<n;v++){var x=C.find("r"+v);var r=(C.attr("h")+"").replace("px","");r=parseInt(r);var u=jQuery('<tr height="'+(r?r:18)+'px" />');for(var s=0;s<B;s++){var g="<td />";var k=x.find("c"+s);if(k){var q=k.text()+"";var l=k.attr("class");var y=k.attr("style");var h=k.attr("colspan");var c="";if(q.charAt(0)=="="){c=' formula="'+q+'"'}g="<td"+c+(y?' style="'+y+'"':"")+(l?' class="'+l+'"':"")+(h?' colspan="'+h+'"':"")+(r?' height="'+r+'px"':"")+">"+q+"</td>"}u.append(g)}d.append(u)}A.append(d).appendTo(a)});return a.children()},json:function(data,makeEval){sheet=(makeEval==true?eval("("+data+")"):data);var tables=jQuery("<div />");sheet=(jQuery.isArray(sheet)?sheet:[sheet]);for(var i=0;i<sheet.length;i++){var colCount=parseInt(sheet[i].metadata.columns);var rowCount=parseInt(sheet[i].metadata.rows);title=sheet[i].metadata.title;title=(title?title:"Spreadsheet "+i);var table=jQuery("<table />");var tableWidth=0;var colgroup=jQuery("<colgroup />").appendTo(table);var tbody=jQuery("<tbody />");if(sheet[i]["metadata"]["col_widths"]){for(var x=0;x<colCount;x++){var w=120;if(sheet[i]["metadata"]["col_widths"]["c"+x]){var newW=parseInt(sheet[i]["metadata"]["col_widths"]["c"+x].replace("px",""));w=(newW?newW:120);tableWidth+=w}colgroup.append('<col width="'+w+'px" style="width: '+w+'px;" />')}}table.attr("title",title).width(tableWidth);for(var x=0;x<rowCount;x++){var tr=jQuery("<tr />").appendTo(table);tr.attr("height",(sheet[i]["data"]["r"+x].h?sheet[i]["data"]["r"+x].h:18));for(var y=0;y<colCount;y++){var cell=sheet[i]["data"]["r"+x]["c"+y];var cur_val;var colSpan;var style;var cl;if(cell){cur_val=cell.value+"";colSpan=cell.colSpan+"";style=cell.style+"";cl=cell.cl+""}var cur_td=jQuery("<td"+(style?' style="'+style+'"':"")+(cl?' class="'+cl+'"':"")+(colSpan?' colspan="'+colSpan+'"':"")+" />");try{if(typeof(cur_val)=="number"){cur_td.html(cur_val)}else{if(cur_val.charAt(0)=="="){cur_td.attr("formula",cur_val)}else{cur_td.html(cur_val)}}}catch(e){}tr.append(cur_td)}}tables.append(table)}return tables.children()},fromSize:function(n,f,l){if(!n){n="5x10"}n=n.toLowerCase().split("x");var b=parseInt(n[0]);var g=parseInt(n[1]);var m=jQuery("<table />");var a="<td></td>";var d="";for(var c=b;c>=1;c--){d+=a}var k="<tr"+(f?' height="'+f+'px" style="height: '+f+'px;"':"")+">"+d+"</tr>";var j="";for(var c=g;c>=1;c--){j+=k}m.html("<tbody>"+j+"</tbody>");if(l){m.width(b*l)}return m}},killAll:function(){if(jQuery.sheet){if(jQuery.sheet.instance){for(var a=0;a<jQuery.sheet.instance.length;a++){if(jQuery.sheet.instance[a]){if(jQuery.sheet.instance[a].kill){jQuery.sheet.instance[a].kill()}}}}}},paneScrollLocker:function(b,a){jQuery(jQuery.sheet.instance).each(function(c){this.obj.pane().scrollLeft(b.scrollLeft()).scrollTop(b.scrollTop())})},switchSheetLocker:function(a){jQuery(jQuery.sheet.instance).each(function(b){this.setActiveSheet(a)})},I:function(){var a=0;if(this.instance){a=(this.instance.length===0?0:this.instance.length-1)}else{this.instance=[]}return a}};var jSE=jQuery.sheet.engine={calc:function(c,f,g,a){for(var d=0;d<f.length;d++){for(var b=0;b<f[d].length;b++){f[d][b].calcCount=0}}for(var d=0;d<f.length;d++){for(var b=0;b<f[d].length;b++){g(c,d,b)}}},parseLocation:function(b){for(var a=0;a<b.length;a++){if(b.charCodeAt(a)<=57){break}}return{row:parseInt(b.substring(a))-1,col:this.columnLabelIndex(b.substring(0,a))}},parseCellName:function(a,b){return jSE.columnLabelString(a)+(b+1)},columnLabelIndex:function(c){var a=0;for(var b=0;b<c.length;b++){var d=c.toUpperCase().charCodeAt(b)-65;a=(a*26)+d}return(a>=0?a:0)},columnLabelString:function(f){var d=(f).toString(26).toUpperCase();var h=[];for(var g=0;g<d.length;g++){var a=d.charCodeAt(g);if(g<=0&&d.length>1){a=a-1}if(a<=57){h.push(String.fromCharCode(a-48+65))}else{h.push(String.fromCharCode(a+10))}}return h.join("")},cFN:{sum:function(a,b){return a+b},max:function(a,b){return a>b?a:b},min:function(a,b){return a<b?a:b},count:function(a,b){return(b!=null)?a+1:a},divide:function(a,b){return a/b},clean:function(a){if(typeof(a)=="string"){a=a.replace(jSE.regEx.amp,"&").replace(jSE.regEx.nbsp," ").replace(/\n/g,"").replace(/\r/g,"")}return a},sanitize:function(a){if(a){if(isNaN(a)){return a}else{return a*1}}return""}},regEx:{n:/[\$,\s]/g,cell:/\$?([a-zA-Z]+)\$?([0-9]+)/gi,range:/\$?([a-zA-Z]+)\$?([0-9]+):\$?([a-zA-Z]+)\$?([0-9]+)/gi,remoteCell:/\$?(SHEET+)\$?([0-9]+)[:!]\$?([a-zA-Z]+)\$?([0-9]+)/gi,remoteCellRange:/\$?(SHEET+)\$?([0-9]+)[:!]\$?([a-zA-Z]+)\$?([0-9]+):\$?([a-zA-Z]+)\$?([0-9]+)/gi,sheet:/SHEET/i,amp:/&/g,gt:/</g,lt:/>/g,nbsp:/ /g},str:{amp:"&",lt:"<",gt:">",nbsp:"&nbps;"},chart:function(d){var c=this.jS;var a=this;function b(f,g){if(!f){if(g){f=0}else{f=""}}else{if(g){f=arrHelpers.toNumbers(f)}else{f=arrHelpers.flatten(f)}}return f}d=jQuery.extend({x:{legend:"",data:[0]},y:{legend:"",data:[0]},title:"",data:[0],legend:"",chart:jQuery('<div class="'+c.cl.chart+'" />').mousedown(function(){jQuery(this).parent().mousedown()}).mousemove(function(){jQuery(this).parent().mousemove();return false})},d);d.data=b(d.data,true);d.x.data=b(d.x.data,true);d.y.data=b(d.y.data,true);d.legend=b(d.legend);d.x.legend=b(d.x.legend);d.y.legend=b(d.y.legend);d.legend=(d.legend?d.legend:d.data);this.s.origParent.one("calculation",function(){var h=d.chart.width();var f=d.chart.height();var i=Raphael(d.chart[0]);if(i.g){if(d.title){i.g.text(h/2,10,d.title).attr({"font-size":20})}switch(d.type){case"bar":i.g.barchart(h/8,f/8,h*0.8,f*0.8,d.data,d.legend).hover(function(){this.flag=i.g.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":i.g.hbarchart(h/8,f/8,h*0.8,f*0.8,d.data,d.legend).hover(function(){this.flag=i.g.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":i.g.linechart(h/8,f/8,h*0.8,f*0.8,d.x.data,d.y.data,{nostroke:false,axis:"0 0 1 1",symbol:"o",smooth:true}).hoverColumn(function(){this.tags=i.set();try{for(var j=0;j<this.y.length;j++){this.tags.push(i.g.tag(this.x,this.y[j],this.values[j],0,10).insertBefore(this).attr([{fill:"#fff"},{fill:this.symbols[j].attr("fill")}]))}}catch(k){}},function(){this.tags&&this.tags.remove()});break;case"pie":var g=i.g.piechart(h/2,f/2,(h<f?h:f)/2,d.data,{legend:d.legend}).hover(function(){this.sector.stop();this.sector.scale(1.1,1.1,this.cx,this.cy);if(this.label){this.label[0].stop();this.label[0].scale(1.5);this.label[1].attr({"font-weight":800})}},function(){this.sector.animate({scale:[1,1,this.cx,this.cy]},500,"bounce");if(this.label){this.label[0].animate({scale:1},500,"bounce");this.label[1].attr({"font-weight":400})}});break;case"dot":i.g.dotchart(h/8,f/8,h*0.8,f*0.8,d.x.data,d.y.data,d.data,{symbol:"o",max:10,heat:true,axis:"0 0 1 1",axisxstep:d.x.data.length-1,axisystep:d.y.data.length-1,axisxlabels:(d.x.legend?d.x.legend:d.x.data),axisylabels:(d.y.legend?d.y.legend:d.y.data),axisxtype:" ",axisytype:" "}).hover(function(){this.tag=this.tag||i.g.tag(this.x,this.y,this.value,0,this.r+2).insertBefore(this);this.tag.show()},function(){this.tag&&this.tag.hide()});break}c.attrH.setHeight(a.row,"cell",false)}});return d.chart}};var jFN=jQuery.sheet.fn={VERSION:function(){return this.jS.version},IMG:function(a){return jQuery("<img />").attr("src",a)},AVERAGE:function(b){var a=arrHelpers.foldPrepare(b,arguments);return jFN.SUM(a)/jFN.COUNT(a)},AVG:function(a){return jFN.AVERAGE(a)},COUNT:function(a){return arrHelpers.fold(arrHelpers.foldPrepare(a,arguments),jSE.cFN.count,0)},COUNTA:function(){var c=0;var a=arrHelpers.flatten(arguments);for(var b=0;b<a.length;b++){if(a[b]){c++}}return c},SUM:function(a){return arrHelpers.fold(arrHelpers.foldPrepare(a,arguments),jSE.cFN.sum,0,true,jFN.N)},MAX:function(a){return arrHelpers.fold(arrHelpers.foldPrepare(a,arguments),jSE.cFN.max,Number.MIN_VALUE,true,jFN.N)},MIN:function(a){return arrHelpers.fold(arrHelpers.foldPrepare(a,arguments),jSE.cFN.min,Number.MAX_VALUE,true,jFN.N)},MEAN:function(a){return this.SUM(a)/a.length},ABS:function(a){return Math.abs(jFN.N(a))},CEILING:function(a){return Math.ceil(jFN.N(a))},FLOOR:function(a){return Math.floor(jFN.N(a))},INT:function(a){return Math.floor(jFN.N(a))},ROUND:function(b,a){return jFN.FIXED(b,(a?a:0),false)},RAND:function(){return Math.random()},RND:function(){return Math.random()},TRUE:function(){return"TRUE"},FALSE:function(){return"FALSE"},NOW:function(){return new Date()},TODAY:function(){return Date(Math.floor(new Date()))},DAYSFROM:function(b,c,a){return Math.floor((new Date()-new Date(b,(c-1),a))/86400000)},DAYS:function(f,c){var b=new Date(f);var a=new Date(c);var d=1000*60*60*24;return Math.round(Math.abs(b.getTime()-a.getTime())/d)},DATEVALUE:function(a){var b=new Date(a);return b.getDate()+"/"+(b.getMonth()+1)+"/"+b.getFullYear()},IF:function(c,b,a){return(c?b:a)},FIXED:function(j,c,k){if(c==null){c=2}var h=Math.pow(10,c);var b=String(Math.round(jFN.N(j)*h)/h);var a=b.indexOf(".");if(a<0){a=b.length;b+="."}for(var d=b.length-a-1;d<c;d++){b+="0"}if(k==true){return b}var g=b.replace("-","").split(".");var l=[];var f=true;while(g[0].length>0){if(!f){l.unshift(",")}l.unshift(g[0].slice(-3));g[0]=g[0].slice(0,-3);f=false}if(c>0){l.push(".");var f=true;while(g[1].length>0){if(!f){l.push(",")}l.push(g[1].slice(0,3));g[1]=g[1].slice(3);f=false}}if(j<0){return"-"+l.join("")}return l.join("")},TRIM:function(a){if(typeof(a)=="string"){a=jQuery.trim(a)}return a},HYPERLINK:function(b,a){a=(a?a:"LINK");return jQuery('<a href="'+b+'" target="_new">'+a+"</a>")},DOLLAR:function(b,a,d){if(a==null){a=2}if(d==null){d="$"}var c=jFN.FIXED(b,a,false);if(b>=0){this.cell.html=d+c}else{this.cell.html="-"+d+c.slice(1)}return b},VALUE:function(a){return parseFloat(a)},N:function(a){if(a==null){return 0}if(a instanceof Date){return a.getTime()}if(typeof(a)=="object"){a=a.toString()}if(typeof(a)=="string"){a=parseFloat(a.replace(jSE.regEx.n,""))}if(isNaN(a)){return 0}if(typeof(a)=="number"){return a}if(a==true){return 1}return 0},PI:function(){return Math.PI},POWER:function(a,b){return Math.pow(a,b)},SQRT:function(a){return Math.sqrt(a)},DROPDOWN:function(b,f){b=arrHelpers.foldPrepare(b,arguments,true);if(this.editable){var a=this.cell;var d=this.jS;var h="dropdown"+this.sheet+"_"+this.row+"_"+this.col+"_"+this.jS.I;var g=jQuery('<select style="width: 100%;" name="'+h+'" id="'+h+'" />').mousedown(function(){d.cellEdit(jQuery(this).parent(),null,true)});if(!f){g.append('<option value="">Select a value</option>')}for(var c=0;c<(b.length<=50?b.length:50);c++){if(b[c]){g.append('<option value="'+b[c]+'">'+b[c]+"</option>")}}if(jQuery(d.getTd(this.sheet,this.row,this.col)).find("#"+h).length==0){a.selectedValue=d.spreadsheets[this.sheet][this.row][this.col].value}d.s.origParent.one("calculation",function(){jQuery("#"+h).change(function(){a.selectedValue=jQuery(this).val();d.calc()});d.attrH.setHeight(d.getTdLocation(g.parent()).row,"cell",false)});g.val(a.selectedValue);this.cell.html=g}return a.selectedValue},RADIO:function(c){c=arrHelpers.foldPrepare(c,arguments,true);var a=this.cell;if(this.editable){var h="radio"+this.sheet+"_"+this.row+"_"+this.col+"_"+this.jS.I;var f=this.jS;var g=jQuery("<span />").mousedown(function(){f.cellEdit(jQuery(this).parent())});for(var d=0;d<(c.length<=25?c.length:25);d++){if(c[d]){var b=jQuery('<input type="radio" name="'+h+'" class="'+h+'" />').val(c[d]);if(c[d]==a.selectedValue){b.attr("checked","true")}g.append(b).append("<span>"+c[d]+"</span>").append("<br />");f.s.origParent.one("calculation",function(){jQuery("."+h).change(function(){a.selectedValue=jQuery(this).val();f.calc()});f.attrH.setHeight(f.getTdLocation(g.parent()).row,"cell",false)})}}if(jQuery(f.getTd(this.sheet,this.row,this.col)).find("."+h).length==0){a.selectedValue=f.spreadsheets[this.sheet][this.row][this.col].value}this.cell.html=g}return a.selectedValue},CHECKBOX:function(b){b=arrHelpers.foldPrepare(b,arguments)[0];var a=this.cell;if(this.editable){var f=this.jS;var i="checkbox"+this.sheet+"_"+this.row+"_"+this.col+"_"+this.jS.I;var d=jQuery('<input type="checkbox" name="'+i+'" class="'+i+'" />').val(b);var g=jQuery("<span />").append(d).append("<span>"+b+"</span><br />").mousedown(function(){f.cellEdit(jQuery(this).parent())});if(b==a.selectedValue){d.attr("checked",true)}var h=jQuery(f.getTd(this.sheet,this.row,this.col));if(!h.children().length){if(h.text()==a.selectedValue){d.attr("checked",true)}}f.s.origParent.one("calculation",function(){jQuery("."+i).change(function(){a.selectedValue=(jQuery(this).is(":checked")?jQuery(this).val():"");f.calc()})});if(jQuery(f.getTd(this.sheet,this.row,this.col)).find("."+i).length==0){var c=f.spreadsheets[this.sheet][this.row][this.col].value;a.selectedValue=(c=="true"||c==true?b:"")}this.cell.html=g}return a.selectedValue},BARCHART:function(a,b,c){return jSE.chart.apply(this,[{type:"bar",data:a,legend:b,title:c}])},HBARCHART:function(a,b,c){return jSE.chart.apply(this,[{type:"hbar",data:a,legend:b,title:c}])},LINECHART:function(b,a){return jSE.chart.apply(this,[{type:"line",x:{data:b},y:{data:a},title:""}])},PIECHART:function(a,b,c){return jSE.chart.apply(this,[{type:"pie",data:a,legend:b,title:c}])},DOTCHART:function(g,d,a,c,b,f){return jSE.chart.apply(this,[{type:"dot",data:(a?a:g),x:{data:g,legend:c},y:{data:(d?d:g),legend:(b?b:c)},title:f}])},CELLREF:function(a){return(this.jS.spreadsheets[a]?this.jS.spreadsheets[a]:"Cell Reference Not Found")},CALCTIME:function(){var a=this;this.s.origParent.one("calculation",function(){jQuery(a.jS.getTd(a.sheet,a.row,a.col)).text(a.jS.time.diff())});return""}};var key={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,F:70,V:86,Y:89,Z:90};var arrHelpers={foldPrepare:function(b,d,c){var a;if(b!=null&&b instanceof Object&&b.length!=null){a=b}else{a=d}if(c){a=this.unique(a)}return a},fold:function(b,g,a,d,f){for(var c=0;c<b.length;c++){a=g(a,(d==true?f(b[c]):b[c]))}return a},toNumbers:function(a){a=this.flatten(a);for(var b=0;b<a.length;b++){if(a[b]){a[b]=jQuery.trim(a[b]);if(isNaN(a[b])){a[b]=0}else{a[b]=a[b]*1}}else{a[b]=0}}return a},unique:function(b){var d=[];var c=b.length;for(var g=0;g<c;g++){for(var f=g+1;f<c;f++){if(b[g]===b[f]){f=++g}}d.push(b[g])}return d},flatten:function(a){var f=[];for(var c=0,b=a.length;c<b;c++){var d=Object.prototype.toString.call(a[c]).split(" ").pop().split("]").shift().toLowerCase();if(d){f=f.concat(/^(array|collection|arguments|object)$/.test(d)?this.flatten(a[c]):a[c])}}return f},insertAt:function(a,c,b){jQuery(c).each(function(){if(b>-1&&b<=a.length){a.splice(b,0,this)}});return a}};