0byt3m1n1
Path:
/
data
/
applications
/
aps
/
tikiwiki
/
3.2.0-5
/
standard
/
htdocs
/
lib
/
jquery
/
jquery.sheet
/
[
Home
]
File: jquery.sheet.min.js
jQuery.fn.extend({sheet:function(E){E=jQuery.extend({urlGet:"documentation.html table:first",urlSave:"save.html",title:"",editable:true,urlBaseCss:"jquery.sheet.base.css",urlTheme:"theme/ui.theme.css",urlMenu:"menu.html",urlMenuJs:"plugins/jquery.clickmenu.pack.js",urlMenuCss:"plugins/clickmenu.css",urlScrollTo:"plugins/jquery.scrollTo-1.4.0-min.js",loading:"Loading Spreadsheet...",newColumnWidth:"120px",ajaxSaveType:"POST",buildSheet:false,calcOff:false,log:false,lockFormulas:false,parent:this,colMargin:"25px",fnBefore:function(){},fnAfter:function(){},fnSave:function(){jS.saveSheet()},fnOpen:function(){},fnClose:function(){}},E);E.fnBefore();jS.getCss(E.urlBaseCss);E.width=jQuery(E.parent).width();E.height=jQuery(E.parent).height();jQuery.fn.sheet.settings=jS.s=E;var B=jQuery(jS.s.parent).html();jQuery(jS.s.parent).html(jS.s.loading);if(jS.s.log){jQuery(jS.s.parent).after('<textarea id="'+jS.id.log+'" />')}var G=jQuery('<div id="'+jS.id.ui+'"><table class="tableControl"><colgroup><col style="width: '+jS.s.colMargin+';" width="'+jS.s.colMargin+'"><col /></colgroup><tbody><tr style="height: '+jS.s.colMargin+';"><td><div id="'+jS.id.barCorner+'" onclick="jS.cellEditAbandon();" /></td><td style="height: '+jS.s.colMargin+'; vertical-align: middle;"><div style="overflow: hidden;" id="'+jS.id.barTopParent+'" /></td></tr><tr style="position: relative;"><td width="'+jS.s.colMargin+'" style="vertical-align: top; overflow: hidden; width: '+jS.s.colMargin+';"><div style="overflow: hidden;" id="'+jS.id.barLeftParent+'" /></td><td id="'+jS.id.paneParent+'" style="position: relative;"><div id="'+jS.id.pane+'" /></td></tr></tbody></table></div>');for(var A in cE.fn){var C=A.toLowerCase();if(C!=A){cE.fn[C]=cE.fn[A]}}function D(I,H){jQuery(I).find("table:first").addClass(jS.cl.sheet).attr("id",jS.id.sheet);jQuery(I).find("."+jS.cl.uiCell).removeClass(jS.cl.uiCell);jQuery(I).find("td").css("background-color","").css("color","");if(H){return I}}if(jS.s.buildSheet==false){jQuery(G).find("#"+jS.id.pane).load(jS.s.urlGet,function(){D(this);jS.sheetInit(G);E.fnAfter()})}else{var F;if(jS.s.buildSheet.toLowerCase().match("x")){F=D(jS.buildSheet(),true)}else{F=D(B,true)}jQuery(G).find("#"+jS.id.pane).html(F);jS.sheetInit(G);E.fnAfter()}}});var jS=jQuery.sheet={version:"0.41",s:{},obj:{parent:function(){return jQuery(jS.s.parent)},ui:function(){return jQuery("#"+jS.id.ui)},sheet:function(){return jQuery("#"+jS.id.sheet)},bar:function(){return jQuery("."+jS.cl.bar)},barTop:function(){return jQuery("#"+jS.id.barTop)},barTopParent:function(){return jQuery("#"+jS.id.barTopParent)},barLeft:function(){return jQuery("#"+jS.id.barLeft)},barLeftParent:function(){return jQuery("#"+jS.id.barLeftParent)},barCorner:function(){return jQuery("#"+jS.id.barCorner)},barSelected:function(){return jQuery("."+jS.cl.barSelected)},cell:function(){return jQuery("."+jS.cl.cell)},controls:function(){return jQuery("#"+jS.id.controls)},formula:function(){return jQuery("#"+jS.id.formula)},label:function(){return jQuery("#"+jS.id.label)},fx:function(){return jQuery("#"+jS.id.fx)},pane:function(){return jQuery("#"+jS.id.pane)},paneParent:function(){return jQuery("#"+jS.id.paneParent)},log:function(){return jQuery("#"+jS.id.log)},menu:function(){return jQuery("#"+jS.id.menu)},title:function(){return jQuery("#"+jS.id.title)},uiDefault:function(){return jQuery("."+jS.cl.uiDefault)},uiActive:function(){return jQuery("."+jS.cl.uiActive)},uiBase:function(){return jQuery("."+jS.cl.uiBase)},uiCell:function(){return jQuery("."+jS.cl.uiCell)},toggle:function(){return jQuery("."+jS.cl.toggle)},tableBody:function(){return document.getElementById(jS.id.sheet)},title:function(){return jQuery("#"+jS.id.title)}},id:{sheet:"jSheet",ui:"jSheetUI",barTop:"jSheetBarTop",barTopParent:"jSheetBarTopParent",barLeft:"jSheetBarLeft",barLeftParent:"jSheetBarLeftParent",barCorner:"jSheetBarCorner",controls:"jSheetControls",formula:"jSheetControls_formula",label:"jSheetControls_loc",fx:"jSheetControls_fx",pane:"jSheetEditPane",paneParent:"jSheetEditPaneParent",log:"jSheetLog",menu:"jSheetMenu",title:"sheetTitle"},cl:{sheet:"jSheet",bar:"jSheetBar",cell:"jSheetCellActive",calcOff:"jSheetCalcOff",barSelected:"jSheetBarItemSelected",uiDefault:"ui-state-default",uiActive:"ui-state-active",uiBase:"ui-widget-content",uiParent:"ui-widget ui-widget-content ui-corner-all",uiBar:"ui-widget-header ui-helper-clearfix",uiPane:"ui-widget-content",uiMenuUl:"ui-widget-header",uiMenuLi:"ui-widget-header",uiMenuHighlighted:"ui-state-highlight",uiControl:"ui-widget-content",uiCell:"themeRoller_activeCell",uiCellHighlighted:"ui-state-highlight",toggle:"cellStyleToggle"},ERROR:function(){return cE.ERROR},sheetInit:function(A){jS.obj.parent().html(A);jS.sheetDecorate();jS.barAdjustor()},attr:{width:function(A){return jQuery(A).outerWidth()},height:function(A){return jQuery(A).outerHeight()}},makeBarItemLeft:function(){jS.obj.barLeft().remove();var B=jQuery('<table border="1px" id="'+jS.id.barLeft+'" width="100%" />');var A=jQuery("<tbody />");jS.obj.sheet().find("tr").each(function(D){var C=jS.attr.height(jQuery(this).find("td:first"));var E=jQuery("<tr />").height(C);var F=jQuery("<td>"+(D+1)+"</td>").height(C).css("vertical-align","middle");if(jS.s.editable){jS.getResizeControl.height(F)}E.append(F);jQuery(A).append(E)});B.append(A);jS.obj.barLeftParent().append(B);jS.barHeightSync()},makeBarItemTop:function(){jS.obj.barTop().remove();var A=jS.attr.width(jS.obj.sheet());var B=jQuery('<table border="1px" id="'+jS.id.barTop+'" />').width(A);B.height(jS.s.colMargin);B.append(jS.obj.sheet().find("colgroup").clone());var C=jQuery("<tr class='"+jS.cl.bar+"' />");var D="";jS.obj.sheet().find("tr:eq(0) td").each(function(F){var E=cE.columnLabelString(F+1);D+="<td>"+E+"</td>"});jQuery(C).append(D);jQuery(B).find("colgroup").after("<tbody />");jQuery(B).find("tbody").html(C);if(jS.s.editable){jS.getResizeControl.width(jQuery(B).find("td"))}jS.obj.barTopParent().append(B)},toggleHide:{row:function(A){if(!A){A=jS.obj.cell().parent().attr("rowIndex")}if(A){var B=jS.obj.barLeft().find("tr").eq(A);if(B.is(":visible")){B.hide();jS.obj.sheet().find("tr").eq(A).hide()}else{B.show();jS.obj.sheet().find("tr").eq(A).show()}}else{alert("No row selected.")}},rowAll:function(){jS.obj.sheet().find("tr").show();jS.obj.barLeft().find("tr").show()},column:function(A){if(!A){A=jS.obj.cell().attr("cellIndex")}if(A){var B=jS.obj.barTop().find("colgroup col").eq(A);if(B.is(":visible")){jS.obj.sheet().find("tbody tr").each(function(){jQuery(this).find("td").eq(A).hide()});jS.obj.barTop().find("tbody tr td").eq(A);B.hide();jS.obj.sheet().find("colgroup col").eq(A).hide();jS.toggleHide.columnSizeManage()}}else{alert("Now column selected.")}},columnAll:function(){},columnSizeManage:function(){var A=jS.obj.barTop().width();var B=0;jS.obj.barTop().find("colgroup col").each(function(){var C=jQuery(this);if(C.is(":hidden")){B+=parseInt(C.css("width").replace("px",""))}});jS.obj.barTop().width(A);jS.obj.sheet().width(A)}},getResizeControl:{height:function(A){jQuery(A).mousedown(function(B){jS.barResizer(B,this,"row");return false}).dblclick(function(){var B=jQuery.trim(jQuery(this).text());B=parseInt(B)-1;jS.cellSetActiveMultiRow(B)})},width:function(A){jQuery(A).mousedown(function(B){jS.barResizer(B,this,"column");return false}).dblclick(function(){var B=cE.columnLabelIndex(jQuery.trim(jQuery(this).text()));B=parseInt(B)-1;jS.cellSetActiveMultiColumn(B)})}},makeControls:function(B){jS.obj.controls().remove();if(jS.s.editable){jS.obj.pane().find("td").mousedown(jS.cellOnMouseDown).click(jS.cellOnClick);var A=jQuery('<div id="'+jS.id.controls+'" />');var C=jS.sheetTitle(true);if(jS.s.urlMenu){jQuery.getScript(jS.s.urlMenuJs,function(){jS.getCss(jS.s.urlMenuCss);var D=jQuery("<div />").load(jS.s.urlMenu,function(){A.prepend(D.html());jS.obj.menu().clickMenu().append(' <span id="'+jS.id.title+'">'+C+"</span>").find("."+jS.cl.toggle).click(function(E){jS.cellStyleToggle(E)});jS.sheetSyncSize();jS.obj.menu()})})}else{A.append(' <span id="'+jS.id.title+'">'+C+"</span>");jS.sheetSyncSize()}A.append('<table style="width: 100%;"><tr><td style="width: 35px; text-align: right;" id="'+jS.id.label+'"></td><td style="width: 10px;" id="'+jS.id.fx+'">fx</td><td><textarea id="'+jS.id.formula+'"></textarea></td></tr></table>');if(jS.s.urlScrollTo){jQuery.getScript(jS.s.urlScrollTo)}A.keydown(function(D){return jS.formulaKeyDown(D)});jQuery(B).prepend(A)}},sheetDecorate:function(){jS.obj.sheet().find('[style!="height"] tr').innerHeight(jS.s.colMargin);jS.obj.sheet().find('[style!="height"] tr').outerHeight(jS.s.colMargin);jS.formatSheet();jS.makeBarItemLeft();jS.makeBarItemTop();jS.makeControls(jS.obj.ui());if(!jS.s.calcOff){jS.calc(jS.obj.tableBody())}},formatSheet:function(){if(!jS.obj.parent().find("tbody").length>0){jS.obj.sheet().wrap("<tbody />")}if(!jS.obj.parent().find("colgroup").length>0){var A=jQuery("<colgroup />");jS.obj.sheet().find("tr:first").find("td").each(function(){var B=jQuery(this).width();jQuery("<col />").width(B).attr("width",B).appendTo(A)});A.insertBefore(jS.obj.sheet().parent())}},getCss:function(A){jQuery("head").append('<link rel="stylesheet" type="text/css" href="'+A+'"></link>')},themeRoller:{start:function(){jS.getCss(jS.s.urlTheme);jS.obj.parent().addClass(jS.cl.uiParent);jS.obj.barLeft().find("td").addClass(jS.cl.uiBar);jS.obj.barTop().find("td").addClass(jS.cl.uiBar);jS.obj.barCorner().addClass(jS.cl.uiBar);jS.obj.pane().addClass(jS.cl.uiPane);jS.obj.menu().css("font-size","12px").css("padding-top","2px").css("padding-left","2px").find("ul").addClass(jS.cl.uiMenuUl).andSelf().find("li").css("border","none").addClass(jS.cl.uiMenuLi).hover(function(){jQuery(this).addClass(jS.cl.uiMenuHighlighted)},function(){jQuery(this).removeClass(jS.cl.uiMenuHighlighted)});jS.obj.sheet().addClass("ui-widget-content");jS.obj.barLeft().addClass(jS.cl.uiBar);jS.obj.barTop().addClass(jS.cl.uiBar);jS.obj.title().addClass(jS.cl.uiControl);jS.obj.fx().addClass(jS.cl.uiControl);jS.obj.label().addClass(jS.cl.uiControl);jS.obj.formula().addClass(jS.cl.uiControl)},cell:function(A){jS.themeRoller.clearCell();if(A){jQuery(A).addClass(jS.cl.uiCellHighlighted).addClass(jS.cl.uiCell)}},clearCell:function(){jS.obj.uiActive().removeClass(jS.cl.uiActive);jS.obj.uiCell().removeAttr("style").removeClass(jS.cl.uiCellHighlighted).removeClass(jS.cl.uiCell)},newBar:function(A){jQuery(A).addClass(jS.cl.uiBar)},barTop:function(A){jS.obj.barTop().find("td").eq(A).addClass(jS.cl.uiActive)},barLeft:function(A){jS.obj.barLeft().find("td").eq(A).addClass(jS.cl.uiActive)},barObj:function(A){jQuery(A).addClass(jS.cl.uiActive)},clearBar:function(){jS.obj.barTopParent().find("."+jS.cl.uiActive).removeClass(jS.cl.uiActive);jS.obj.barLeftParent().find("."+jS.cl.uiActive).removeClass(jS.cl.uiActive)}},manageHtmlToText:function(A){A=jQuery.trim(A);if(A.charAt(0)!="="){A=A.replace(/ /g," ").replace(/>/g,">").replace(/</g,"<").replace(/\t/g,"").replace(/\n/g,"").replace(/<br>/g,"\r").replace(/<BR>/g,"\n");jS.log("from html to text")}return A},manageTextToHtml:function(A){A=jQuery.trim(A);if(A.charAt(0)!="="){A=A.replace(/\t/g," ").replace(/ /g," ").replace(/>/g,">").replace(/</g,"<").replace(/\n/g,"<br>").replace(/\r/g,"<br>");jS.log("from text to html")}return A},sheetDecorateRemove:function(A){jQuery(A).find("."+jS.cl.cell).removeClass(jS.cl.cell);jQuery("col",A).each(function(C){var B=jQuery(this).css("width")+"px";jQuery(A).find("col").eq(C).attr("width",B)});jQuery(A).find("td").css("height","")},cellIsEdit:false,cellClick:function(B,A){A[0]--;A[1]--;switch(B){case"up":A[0]--;break;case"down":A[0]++;break;case"left":A[1]--;break;case"right":A[1]++;break}jS.obj.sheet().find("tr").eq(A[0]).find("td:visible").eq(A[1]).click()},cellOnMouseDown:function(A){jS.cellSetActiveMulti(A);if(jQuery(A.target).attr("cellIndex")){return false}},cellOnClick:function(A,B){if(!B){B=this}switch(jS.s.lockFormulas){case true:if(!jQuery(B).attr("formula")){jS.cellOnClickManage(B);jS.followMe()}break;default:jS.cellOnClickManage(B);jS.followMe()}},cellOnClickManage:function(A){switch(!jQuery(A).hasClass(jS.cl.cell)){case true:var B=jS.getTdLocation(A);if(B){jS.cellSetFocus(B,jS.obj.label(),jS.obj.formula());jS.cellEdit(B[0],B[1],A)}jS.log("click: "+B);break;default:jS.cellIsEdit=true;jS.cellTextArea(A,false,true);jS.log("click, textarea over table activated")}},cellSetFocus:function(D,A,C){var B=C.val();switch(B.charAt(0)){case"=":if("=([:,*/+-".indexOf(B.charAt(B.length))>=0){C.val(B);jQuery(C).focus();return false}break}},cellEdit:function(C,B,D){if(!D[0]){D=jS.getTd(jS.obj.tableBody(),C,B)}D=jQuery(D);jS.cellEditDone();jS.obj.label().html(cE.columnLabelString(B)+C);var A=D.attr("formula");if(!A||A.length<=0){A=jS.manageHtmlToText(D.html())}jS.obj.formula().val(A).focus().select();jS.cellSetActive(D)},cellSetActive:function(B){var A=jS.getTdLocation(B);jQuery(B).addClass(jS.cl.cell);jS.obj.barLeft().find("td").eq(A[0]--).addClass(jS.cl.barSelected);jS.obj.barTop().find("td").eq(A[1]--).addClass(jS.cl.barSelected);jS.themeRoller.cell(B);jS.themeRoller.barLeft(A[0]--);jS.themeRoller.barTop(A[1]--)},cellEditDone:function(I){switch(jS.cellIsEdit){case true:var H=cE.parseLocation(jS.obj.label().html());if(H){var F=jQuery(jS.getTd(jS.obj.tableBody(),H[0],H[1]));var G=false;if(F.hasClass(jS.cl.cell)){var J=jS.cellTextArea(F,true);var M=false;var U=false;var L=false;var D=false;var E=false;var P=false;var A=false;var R=false;var C=false;var T=false;var S=false;var Q=F.attr("formula");var B=F.attr("prevVal");var K=jS.attr.height(F);if(J){if(J.charAt(0)=="="){if(J!=Q){D=true;jS.log("edit, new formula, possibly had formula")}else{if(Q){M=true;jS.log("no edit, has formula")}else{jS.log("no edit, has formula, unknown action")}}}else{if(Q){P=true;jS.log("edit, new value, had formula")}else{if(!isNaN(parseInt(J))){if((J!=B&&J!=jS.obj.formula().val())||(F.text()!=J)){C=true;jS.log("edit, from number to number, possibly in function")}else{U=true;jS.log("no edit, is a number")}}else{A=true;jS.log("possible edit from textarea, has value")}}}}else{if(F.html().length>0&&Q){E=true;jS.log("edit, null value from formula")}else{if(F.html().length>0&&Q){R=true;jS.log("edit, null value from formula")}else{L=true;jS.log("no edit, null value")}}}F.removeAttr("prevVal");J=jS.manageTextToHtml(J);if(M){F.html(B)}else{if(D){G=true;S=true;F.attr("formula",J).html("")}else{if(E){G=true;S=true;F.removeAttr("formula").html(J)}else{if(P){G=true;S=true;F.removeAttr("formula").html(J)}else{if(A){S=true;F.html(J)}else{if(U){F.html(J)}else{if(L){F.html(J)}else{if(C){G=true;S=true;F.html(J)}else{if(R){G=true;S=true;F.removeAttr("formula").html("")}}}}}}}}}if(G&&!jS.obj.sheet().hasClass(jS.cl.calcOff)){jS.calc(jS.obj.tableBody())}if(I!=false){jS.sheetClearActive()}if(S){F.parent().height(K);jS.obj.barLeft().find("tr").eq(H[0]-1).height(jS.attr.height(F.parent()))}jS.obj.formula().focus().select();jS.cellIsEdit=false}}break;default:var H=cE.parseLocation(jS.obj.label().html());try{if(!jQuery.browser.safari){var K=jS.attr.height(jS.obj.cell().parent());jS.obj.cell().parent().height(K)}else{var N=jS.obj.barLeft().find("tr").eq(H[0]-1).attr("height");jS.obj.cell().parent().attr("height",N);jS.barHeightSync()}}catch(O){}jS.sheetClearActive()}},cellEditAbandon:function(){jS.themeRoller.clearCell();jS.themeRoller.clearBar();var A=jS.cellTextArea(jS.obj.cell(),true);if(A){jS.obj.cell().html(jS.manageTextToHtml(A));jS.sheetClearActive();if(A.charAt(0)=="="){jS.calc(jS.obj.tableBody())}}jS.obj.label().html("");return false},formulaKeyDown:function(B,F){var H=jS.getTdLocation(jS.obj.cell());function G(K){var I=jS.obj.cell();var J=jS.manageHtmlToText(I.html());var L=I.attr("formula");var M=jS.obj.formula().val();if((J==M||M==L||M==J)&&!K.ctrlKey){jS.cellClick("",H)}else{jS.cellClick("down",H)}}function D(I){switch(I.shiftKey){case true:jS.cellClick("left",H);break;case false:jS.cellClick("right",H);break}}function E(I){switch(I.ctrlKey){case true:switch(I.keyCode){case key.ENTER:G(I);break}break}switch(I.keyCode){case key.TAB:D(I);return false;break}}function C(I){switch(I.ctrlKey){case true:if(I.keyCode==key.ENTER){G(I)}else{jS.cellIsEdit=true}return true;break;default:switch(I.keyCode){case key.ESCAPE:jS.cellEditAbandon();break;case key.TAB:D(I);return false;break;case key.ENTER:G(I);return false;break;case key.LEFT:jS.cellClick("left",H);return false;break;case key.UP:jS.cellClick("up",H);return false;break;case key.RIGHT:jS.cellClick("right",H);return false;break;case key.DOWN:jS.cellClick("down",H);return false;break;default:jS.cellIsEdit=true}}}var A=true;switch(F){case true:A=E(B);break;default:A=C(B);break}return A},cellStyleToggle:function(A){var C=jQuery(A.target).attr("setclass");var B=jQuery(A.target).attr("removeclass").split(",");jQuery(B).each(function(){if(jS.obj.uiCell().hasClass(this)){jS.obj.uiCell().removeClass(this)}});if(jS.obj.uiCell().hasClass(C)){jS.obj.uiCell().removeClass(C)}else{jS.obj.uiCell().addClass(C)}return false},context:{},calc:function(B,A){return cE.calc(new jS.tableCellProvider(B.id),jS.context,A)},cellTextArea:function(I,E,B,D){var H;I=jQuery(I);if(!B){var A=jQuery(I).find("textarea");var F=A.val();if(F||jS.obj.formula().attr("disabled")){jS.log("Textarea value used");H=F;A.remove();I.css("text-align","").css("vertical-align","")}else{jS.log("Formula value used");H=jS.obj.formula().val()}jS.obj.formula().removeAttr("disabled")}else{jS.obj.formula().attr("disabled","true");if(D){H=D}else{H=jS.obj.formula().val()}var A=jQuery('<textarea id="tempText" />');var G=I.width();var C=I.height();if(C<75){C=75}else{A.css("border","0px")}A.removeAttr("disabled").height(C).width(G).val(jQuery.trim(H)).css("position","absolute").click(function(){return false}).keydown(function(J){return jS.formulaKeyDown(J,true)});if(I.attr("formula")){I.attr("prevVal",I.text()).removeAttr("formula")}I.css("text-align","left").css("vertical-align","top").html(A);I.find("textarea").focus()}if(E){return H}},refreshLabelsColumns:function(){var A=0;jS.obj.barTopParent().find("td").each(function(B){jQuery(this).text(cE.columnLabelString(B+1));A+=jQuery(this).width()});return A},refreshLabelsRows:function(){jS.obj.barLeftParent().find("td").each(function(A){jQuery(this).text((A+1))})},addRowMulti:function(B){if(!B){B=prompt("How many rows would you like to add?")}if(B){for(var A=0;A<=B;A++){jS.addRow()}}},addColumnMulti:function(B){if(!B){B=prompt("How many columns would you like to add?")}if(B){for(var A=0;A<=B;A++){jS.addColumn()}}},addRow:function(E){if(!E){E=":last"}else{if(E==true){var F=jS.getTdLocation(jS.obj.cell());E=":eq("+(F[0]-1)+")"}else{E=":eq("+(E-1)+")"}}jS.cellEditAbandon();var C=jS.obj.sheet().find("tr"+E);var B=C.clone();jQuery("td",B).html("").attr("class","").attr("formula","").css("background-color","").removeAttr("function").mousedown(jS.cellOnMouseDown).click(jS.cellOnClick);B.insertAfter(C);var D=jS.obj.barLeft().find("tr"+E);var A=D.clone();jS.themeRoller.newBar(A);A.find("td").html(parseInt(D.text())+1).removeClass(jS.cl.uiActive).addClass(jS.cl.uiDefault);jS.log("New row at: "+(parseInt(D.text())+1));jS.getResizeControl.height(jQuery(A).find("td"));A.insertAfter(D);if(E){jS.obj.barLeft().find("td").each(function(G){jQuery(this).text((G+1))})}jS.barHeightSync()},addColumn:function(E){if(!E){E=":last"}else{if(E==true){var G=jS.getTdLocation(jS.obj.cell());E=":eq("+(G[1]-1)+")"}else{E=":eq("+(E-1)+")"}}jS.cellEditAbandon();var A=cE.columnLabelIndex(jS.obj.barTop().find("td"+E).html());var D=cE.columnLabelString(A+1);jS.log("New Column: "+A+", "+D);var C=jS.obj.barTop().find("col"+E);C.clone().insertAfter(C).width(jS.s.newColumnWidth);var H=jS.obj.barTop().find("td"+E);jS.getResizeControl.width(H.clone().html(D).insertAfter(H));jS.obj.sheet().find("col"+E).clone().insertAfter("#"+jS.id.sheet+" col"+E).width(jS.s.newColumnWidth);var F="<td></td>";var B=0;jS.obj.sheet().find("tr").each(function(I){jQuery(this).find("td"+E).after(F);B++});jS.log("Sheet length: "+B);jS.obj.pane().find("tr td").unbind("click").mousedown(jS.cellOnMouseDown).click(jS.cellOnClick);if(E){jS.obj.barTop().find("td").each(function(I){jQuery(this).text(cE.columnLabelString(I+1))})}jS.barHeightSync()},deleteRow:function(){if(jS.obj.cell()[0]){var A=confirm("Are you sure that you want to delete that row? Fomulas will not be updated.");if(A){var B=jS.getTdLocation(jS.obj.cell());B=B[0]-1;jS.obj.barLeftParent().find("td").eq(B).parent().remove();jS.obj.sheet().find("tr").eq(B).remove();jS.obj.formula().val("");jS.refreshLabelsRows()}}},deleteColumn:function(){if(jS.obj.cell()[0]){var B=confirm("Are you sure that you want to delete that column? Fomulas will not be updated.");if(B){var C=jS.getTdLocation(jS.obj.cell());C=C[1]-1;jS.obj.barTop().find("td").eq(C).remove();jS.obj.barTop().find("colgroup col").eq(C).remove();jS.obj.sheet().find("colgroup col").eq(C).remove();jS.obj.sheet().find("tr").each(function(D){jQuery(this).find("td").eq(C).remove()});jS.obj.formula().val("");var A=jS.refreshLabelsColumns();jS.obj.sheet().width(A);jS.obj.barTop().width(A)}}},sheetTitle:function(E,D){var C="";if(E){var A=new Array();A[3]=jS.s.title;A[2]=jS.obj.sheet().attr("sheettitle");A[1]=jS.obj.sheet().find('td:contains("sheettitle")').text().split(":")[1];A[0]="Untitled Spreadsheet";var B=A.length;while(!C){C=A[B];B--}return C}else{if(!D){D=prompt("What would you like the sheet's title to be?",jS.obj.title().text())}switch(D){case"":D="Untitled Spreadsheet";break;case null:D=jS.sheetTitle(true)}jS.obj.sheet().attr("sheettitle",D);jS.obj.title().html(D)}},viewSource:function(C){var D=jS.obj.sheet().clone()[0];jS.sheetDecorateRemove(D);if(C){var B=jS.HTMLtoPrettySource(D)}else{var B=jS.HTMLtoCompactSource(D)}var A=window.open();A.document.write("<html><body><xmp>"+B+"\n</xmp></body></html>");A.document.close();return false},saveSheet:function(){var A=jS.obj.sheet().clone()[0];jS.sheetDecorateRemove(A);var B=jQuery("<div />").html(A).html();jQuery.ajax({url:jS.s.urlSave,type:jS.s.ajaxSaveType,data:"s="+B,dataType:"html",success:function(C){alert("Success! - "+C)}})},HTMLtoCompactSource:function(F){var B="";if(F.nodeType==1){B+="<"+F.tagName;D=false;var H=F.attributes.length;for(var E=0,D=false;E<H;E++){var C=F.attributes[E].name;var G=F.getAttribute(C);if(G){if(C=="contentEditable"&&G=="inherit"){continue}if(C=="class"){D=true;jQuery(G).removeClass(jS.cl.cell)}if(typeof (G)=="string"){B+=" "+C+'="'+G.replace(/"/g,"'")+'"'}else{if(C=="style"&&G.cssText){B+=' style="'+G.cssText+'"'}}}}if(F.tagName=="TABLE"&&!D){B+=' class="jSheet"'}if(F.tagName=="COL"){B+="/>"}else{B+=">";var A="";jQuery(F.childNodes).each(function(){A+=jS.HTMLtoCompactSource(this)});B+=A;B+="</"+F.tagName+">"}}else{if(F.nodeType==3){B+=F.data.replace(/^\s*(.*)\s*$/g,"$1")}}return B},HTMLtoPrettySource:function(E,F){if(!F){F=""}var B="";if(E.nodeType==1){B+="\n"+F+"<"+E.tagName;var H=E.attributes.length;for(var D=0;D<H;D++){var C=E.attributes[D].name;var G=E.getAttribute(C);if(G){if(C=="contentEditable"&&G=="inherit"){continue}if(typeof (G)=="string"){B+=" "+C+'="'+G.replace(/"/g,"'")+'"'}else{if(C=="style"&&G.cssText){B+=' style="'+G.cssText+'"'}}}}if(E.childNodes.length<=0){B+="/>"}else{B+=">";var A="";var H=E.childNodes.length;for(var D=0;D<H;D++){A+=jS.HTMLtoPrettySource(E.childNodes[D],F+" ")}B+=A;if(A.indexOf("\n")>=0){B+="\n"+F}B+="</"+E.tagName+">"}}else{if(E.nodeType==3){B+=E.data.replace(/^\s*(.*)\s*$/g,"$1")}}return B},barAdjustor:function(){var A=jS.obj.pane();jS.obj.barTop().css("left","-"+A.scrollLeft());jS.obj.barLeft().css("top","-"+A.scrollTop());window.setTimeout("jS.barAdjustor()",5)},barHeightSync:function(){if(jQuery.browser.safari){jS.obj.barLeft().find("tr").each(function(A){var B=jS.attr.height(jQuery(this).find("td:first"));if(!B){B=jQuery(this).find("td:first").attr("height")}jS.obj.sheet().find("tr").eq(A).find("td:first").attr("height",B).height(B);jS.obj.sheet().find("tr").eq(A).attr("height",B).height(B)})}},followMe:function(){if(jS.s.urlScrollTo){jS.obj.pane().stop().scrollTo(jS.obj.cell(),{margin:true,axis:"xy",duration:800,offset:-jS.s.height/3})}},count:{rows:function(){return parseInt(jQuery.trim(jS.obj.barLeft().find("tr:last").text()))},columns:function(){return parseInt(jS.columnLabelIndex(jQuery.trim(jS.obj.barTop().find("td:last").text())))}},openSheet:function(A,B){function C(){jS.makeBarItemTop();jS.makeBarItemLeft();jS.sheetTitle(true);if(jS.s.editable){jS.obj.pane().find("td").mousedown(jS.cellOnMouseDown).click(jS.cellOnClick)}if(!jS.s.calcOff){jS.calc(jS.obj.tableBody())}jS.themeRoller.start()}if(confirm("Are you sure you want to open a different sheet? All unsaved changes will be lost.")){if(!B){jS.cellEditAbandon();jS.obj.pane().load(A,function(){C()})}else{jS.obj.pane().html(jS.buildSheet(B));C()}}},newSheet:function(){jS.openSheet("",prompt("What size would you like to make your spreadsheet? Example: '5x10' creates a sheet that is 5 columns by 10 rows."))},importRow:function(B){jS.addRow();var A="";jS.obj.sheet().find("tr:last td").each(function(C){jQuery(this).removeAttr("formula");try{if((B[C]+"").charAt(0)=="="){jQuery(this).attr("formula",B[C])}else{jQuery(this).html(B[C])}}catch(D){A+=D+";\n"}});if(A){alert(A)}jS.calc(jS.obj.sheet())},importColumn:function(A){jS.addColumn();var B="";jS.obj.sheet().find("tr").each(function(C){var E=jQuery(this).find("td:last");try{if((A[C]+"").charAt(0)=="="){E.attr("formula",A[C])}else{E.html(A[C])}}catch(D){B+=D+";\n"}});if(B){alert(B)}jS.calc(jS.obj.sheet())},buildSheet:function(J){var A;if(!J){A=jS.s.buildSheet.toLowerCase().split("x")}else{A=J.toLowerCase().split("x")}var E=parseInt(A[0]);var G=parseInt(A[1]);var C=jS.s.newColumnWidth;var H=jQuery('<table border="1px" class="'+jS.cl.sheet+'" id="'+jS.id.sheet+'"><colgroup /><tbody><tr /></tbody></table>');var B='<col width="'+C+'" style="width: '+C+'" />';var D="<td />";for(var F=E;F>=1;F--){jQuery(H).find("colgroup").prepend(B);jQuery(H).find("tbody tr").prepend(D).height(jS.s.colMargin)}var I=jQuery("<div />").html(jQuery(H).find("tbody tr")).html();for(var F=G;F>=1;F--){jQuery(H).find("tbody").prepend(I)}jQuery(H).width(jS.attr.width(jQuery(H).find("tr:first")));return H},sheetSyncSize:function(){var B=jS.s.height;if(!B){B=400}var A=jS.s.width;if(jS.s.editable){jQuery.each(jQuery.browser,function(C,D){if((C=="mozilla"&&D==true)||(C=="safari"&&D==true)){if(jS.s.urlMenu){B=B-89}else{B=B-87}A=A-30}else{if(C=="msie"&&D==true){if(jS.s.urlMenu){B=B-86}else{B=B-66}A=A-38;jS.obj.pane().height(B-30)}}})}else{jQuery.each(jQuery.browser,function(C,D){if((C=="mozilla"&&D==true)||(C=="safari"&&D==true)){B=B-31;A=A-30}else{if(C=="msie"&&D==true){B=B-31;A=A-38}}})}jS.obj.pane().height(B).width(A);jS.obj.barLeftParent().height(B);jS.obj.barTopParent().height(jS.s.colMargin).width(A);jS.obj.parent().find("col:eq(1)").width(A);jS.obj.barCorner().height(jS.obj.barTopParent().height());jS.themeRoller.start()},barResizer:function(B,F,D){var E={xyDimension:0,getIndex:function(H){return parseInt(cE.columnLabelIndex(jQuery.trim(jQuery(H).text())))-1},get:function(I,H){return jQuery(I).find("col").eq(H)},getSize:function(I){var H=jS.attr.width(I);return H},setSize:function(I,H){jQuery(I).width(H)}};var C={xyDimension:1,getIndex:function(H){return parseInt(jQuery.trim(jQuery(H).text()))-1},get:function(I,H){return jQuery(I).find("tr").eq(H)},getSize:function(I){var H=jS.attr.height(I);return H},setSize:function(I,H){jQuery(I).height(H)}};if(jQuery.browser.safari){E.getSize=function(J){var H=jS.attr.width(J);var I=jQuery(J).attr("width");return(H?H:I)};E.setSize=function(I,H){jQuery(I).css("width",H).attr("width",H)};C.get=function(I,H){return jQuery(I).find("tr").eq(H).find("td:first")};C.getSize=function(I){var H=jS.attr.height(I);return H};C.setSize=function(I,H){jQuery(I).css("height",H).attr("height",H)}}var G;if(D=="row"){G=C}else{G=E}var A={start:function(H){jS.cellEditDone();jS.cellEditAbandon();jS.log("start resize");var L=jQuery(F).parent().parent().parent();var K=jS.cellFindXY(F)[G.xyDimension];var N=[H.pageX,H.pageY][G.xyDimension];var J=G.getIndex(F);var M=G.getSize(G.get(L,J));var I=parseInt(N)-(parseInt(K)+parseInt(M));if(Math.abs(I)<=35||jQuery.browser.safari){jS.themeRoller.barObj(F);G.dragInfo={startXY:[H.pageX,H.pageY],srcTable:L,srcItem:G.get(L,J),dstItem:G.get(jS.obj.sheet(),J),edgeDelta:I,startSizes:G.getSize(G.get(L,J)),i:J};jQuery(document).mousemove(A.drag).mouseup(A.stop);if(G.xyDimension){jS.obj.barLeft().find("tr").eq(G.dragInfo.i).outerHeight(G.dragInfo.startSizes);jS.obj.barLeft().find("tr").eq(G.dragInfo.i).find("td").css("height","").attr("height","")}}},drag:function(H){var L=this;if(G.dragInfo.srcTable){var J=G.dragInfo.startSizes;var I=parseInt([H.pageX,H.pageY][G.xyDimension])-parseInt(G.dragInfo.startXY[G.xyDimension])+parseInt(G.dragInfo.startSizes);var K=0;if(I>0){J=Math.max(I-K,3)}K+=J;G.setSize(G.dragInfo.srcItem,J);if(!G.xyDimension){G.setSize(G.dragInfo.srcTable,K)}return false}},stop:function(H){var L=this;if(G.dragInfo.srcTable){var K=G.getSize(G.dragInfo.srcItem);var M=G.getSize(G.dragInfo.srcTable);G.setSize(G.dragInfo.dstItem,K);if(!G.xyDimension){G.setSize(jS.obj.sheet(),M)}if(G.xyDimension){G.setSize(G.dragInfo.srcItem,G.getSize(G.dragInfo.dstItem));var J=jS.obj.barLeft().find("tr").eq(G.dragInfo.i).find("td").attr("height");var I=jS.obj.barLeft().find("tr").eq(G.dragInfo.i).find("td").css("height");h=(J?J:I);jS.obj.barLeft().find("tr").eq(G.dragInfo.i).outerHeight("height",h)}}G.dragInfo={};jQuery(document).unbind("mousemove").unbind("mouseup");jS.log("stop resizing");jS.themeRoller.clearBar()}};A.start(B)},cellFindXY:function(A){var B=curtop=0;A=jQuery(A)[0];if(A.offsetParent){do{B+=A.offsetLeft;curtop+=A.offsetTop}while(A=A.offsetParent)}return[B,curtop]},cellFind:function(A){if(!A){A=prompt("What are you looking for in this spreadsheet?")}if(A){var B=jS.obj.sheet().find('td:contains("'+A+'")');if(B.length<1){B=jS.obj.sheet().find('td:contains("'+A.toLowerCase()+'")')}if(B.length<1){B=jS.obj.sheet().find('td:contains("'+A.toUpperCase()+'")')}B=B.eq(0);if(B.length>0){B.click()}else{alert("No results found.")}}},cellSetActiveMulti:function(A){var B={startRow:A.target.parentNode.rowIndex,startColumn:A.target.cellIndex};jS.obj.sheet().mousemove(function(C){B.endRow=C.target.parentNode.rowIndex;B.endColumn=C.target.cellIndex;for(var E=B.startRow;E<=B.endRow;E++){for(var D=B.startColumn;D<=B.endColumn;D++){var F=jS.getTd(jS.obj.tableBody(),E+1,D+1);jQuery(F).addClass(jS.cl.uiCell).addClass(jS.cl.uiCellHighlighted)}}if(jQuery(C.target).attr("id")=="tempText"){return true}else{return false}}).mouseup(function(){jS.obj.sheet().unbind("mousemove").unbind("mouseup")});return false},cellSetActiveMultiColumn:function(A){jS.obj.sheet().find("tr").each(function(){var B=jQuery(this).find("td").eq(A);jQuery(B).addClass(jS.cl.uiCell).addClass(jS.cl.uiCellHighlighted)});jS.themeRoller.barTop(A)},cellSetActiveMultiRow:function(A){jS.obj.sheet().find("tr").eq(A).find("td").addClass(jS.cl.uiCell).addClass(jS.cl.uiCellHighlighted);jS.themeRoller.barLeft(A)},sheetClearActive:function(){jS.obj.formula().val("");jS.obj.cell().removeClass(jS.cl.cell);jS.obj.barSelected().removeClass(jS.cl.barSelected)},getIndexTr:function(A){return A-1},getIndexTd:function(A){return A-1},getTd:function(F,E,B,A,C){if(!A){A=jS.getIndexTr(E)}if(F.rows){var D=F.rows[A];if(D){if(!C){C=jS.getIndexTd(B)}return D.cells[C]}}return null},getTdLocation:function(C){var A=jQuery(C).attr("cellIndex")+1;var B=jQuery(C).parent().attr("rowIndex")+1;return[B--,A--]},tableCellProvider:function(A){this.tableBodyId=A;this.cells={}},tableCell:function(C,B,A){this.tableBodyId=C.id;this.row=B;this.col=A;this.indexTr=jS.getIndexTr(B);this.indexTd=jS.getIndexTd(A);this.value=jS.EMPTY_VALUE},EMPTY_VALUE:{},log:function(A){switch(jS.s.log){case true:jS.obj.log().prepend(A+"; <br />\n");break}}};jS.tableCellProvider.prototype={getCell:function(D,B){if(typeof (B)=="string"){B=cE.columnLabelIndex(B)}var C=D+","+B;var A=this.cells[C];if(!A){var F=jS.obj.tableBody();if(F){var E=jS.getTd(F,D,B);if(E){A=this.cells[C]=new jS.tableCell(F,D,B)}}}return A},getNumberOfColumns:function(B){var C=jS.obj.tableBody();if(C){var A=C.rows[jS.getIndexTr(B)];if(A){return A.cells.length}}return 0},toString:function(){result="";jS.obj.sheet().find("tr").each(function(){result+=this.innerHTML.replace(/\n/g,"")+"\n"});return result}};jS.tableCell.prototype={getTd:function(){return jS.getTd(jS.obj.tableBody(),this.row,this.col,this.indexTr,this.indexTd)},setValue:function(A,B){this.error=B;this.value=A;this.getTd().innerHTML=(A?A:"")},getValue:function(){var A=this.value;if(A===jS.EMPTY_VALUE&&!this.getFormula()){A=this.getTd().innerHTML;A=this.value=(A.length>0?cE.parseFormulaStatic(A):null)}return(A===jS.EMPTY_VALUE?null:A)},getFormat:function(){return jQuery(this.getTd()).attr("format")},setFormat:function(A){jQuery(this.getTd()).attr("format",A)},getFormulaFunc:function(){return this.formulaFunc},setFormulaFunc:function(A){this.formulaFunc=A},getFormula:function(){return jQuery(this.getTd()).attr("formula")},setFormula:function(A){if(A&&A.length>0){jQuery(this.getTd()).attr("formula",A)}else{jQuery(this.getTd()).removeAttr("formula")}}};var key={BACKSPACE:8,CAPS_LOCK:20,COMMA:188,CONTROL:17,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};var cE=jQuery.calculationEngine={TEST:{},ERROR:"#VALUE!",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},CLEAN:function(A){if(typeof (A)=="string"){A=A.replace(cE.RE_AMP,"&").replace(cE.RE_NBSP," ").replace(/\n/g,"").replace(/\r/g,"")}return A}},fn:{HTML:function(A){return jQuery(A)},IMG:function(A){return jQuery('<img src="'+A+'" style="border: ;"/>')},AVERAGE:function(B){var A=cE.foldPrepare(B,arguments);return cE.fn.SUM(A)/cE.fn.COUNT(A)},AVG:function(A){return cE.fn.AVERAGE(A)},COUNT:function(A){return cE.fold(cE.foldPrepare(A,arguments),cE.cFN.COUNT,0)},SUM:function(A){return cE.fold(cE.foldPrepare(A,arguments),cE.cFN.SUM,0,true)},MAX:function(A){return cE.fold(cE.foldPrepare(A,arguments),cE.cFN.MAX,Number.MIN_VALUE,true)},MIN:function(A){return cE.fold(cE.foldPrepare(A,arguments),cE.cFN.MIN,Number.MAX_VALUE,true)},ABS:function(A){return Math.abs(cE.fn.N(A))},CEILING:function(A){return Math.ceil(cE.fn.N(A))},FLOOR:function(A){return Math.floor(cE.fn.N(A))},INT:function(A){return Math.floor(cE.fn.N(A))},ROUND:function(A){return Math.round(cE.fn.N(A))},RAND:function(A){return Math.random()},RND:function(A){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)},IF:function(v,t,f){t=cE.cFN.CLEAN(t);f=cE.cFN.CLEAN(f);try{v=eval(v)}catch(e){}try{t=eval(t)}catch(e){}try{t=eval(t)}catch(e){}if(v=="true"||v==true||v>0||v=="TRUE"){return t}else{return f}},FIXED:function(G,B,H){if(B==null){B=2}var F=Math.pow(10,B);var J=String(Math.round(cE.fn.N(G)*F)/F);var A=J.indexOf(".");if(A<0){A=J.length;J+="."}for(var C=J.length-A-1;C<B;C++){J+="0"}if(H==true){return J}var E=J.replace("-","").split(".");var I=[];var D=true;while(E[0].length>0){if(!D){I.unshift(",")}I.unshift(E[0].slice(-3));E[0]=E[0].slice(0,-3);D=false}if(B>0){I.push(".");var D=true;while(E[1].length>0){if(!D){I.push(",")}I.push(E[1].slice(0,3));E[1]=E[1].slice(3);D=false}}if(G<0){return"-"+I.join("")}return I.join("")},TRIM:function(A){if(typeof (A)=="string"){A=jQuery.trim(A)}return A},HYPERLINK:function(B,A){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=cE.fn.FIXED(B,A,false);if(B>=0){return D+C}return"-"+D+C.slice(1)},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(cE.RE_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)}},calc:function(D,A,C){var B={cellProvider:D,context:(A!=null?A:{}),row:1,col:1,done:false,stack:[],calcMore:function(E){B.fuel=E;return cE.calcLoop(B)}};return B.calcMore(C)},cell:function(){prototype:{getError=function(){return this.error},getValue=function(){return this.value},setValue=function(A,B){this.value=A;this.error=B},getFormula=function(){return this.formula},setFormula=function(A){this.formula=A},getFormulaFunc=function(){return this.formulaFunc},setFormulaFunc=function(A){this.formulaFunc=A},toString=function(){return"Cell:["+this.getFormula()+": "+this.getValue()+": "+this.getError()+"]"}}},columnLabelIndex:function(C){var A=0;for(var B=0;B<C.length;B++){var D=C.charCodeAt(B)-65+1;A=(A*26)+D}return A},parseLocation:function(B){if(B!=null&&B.length>0&&B!=" "){for(var A=0;A<B.length;A++){if(B.charCodeAt(A)<=57){break}}return[parseInt(B.substring(A)),cE.columnLabelIndex(B.substring(0,A))]}return null},columnLabelString:function(C){var B=(C-1).toString(26).toUpperCase();var E=[];for(var D=0;D<B.length;D++){var A=B.charCodeAt(D);if(D<=0&&B.length>1){A=A-1}if(A<=57){E.push(String.fromCharCode(A-48+65))}else{E.push(String.fromCharCode(A+10))}}return E.join("")},RE_N:/[\$,\s]/g,RE_REF_CELL:/\$?([a-zA-Z]+)\$?([0-9]+)/g,RE_REF_RANGE:/\$?([a-zA-Z]+)\$?([0-9]+):\$?([a-zA-Z]+)\$?([0-9]+)/g,parseFormula:function(G,D,C){var B=null;var F=null;if(C!=null&&C.cellProvider!=null){B=C.cellProvider.nrows;F=C.cellProvider.ncols}var E=G.replace(cE.RE_REF_RANGE,function(K,M,J,P,L){var Q=[];var I=cE.columnLabelIndex(M.toUpperCase());var S=parseInt(J);var O=cE.columnLabelIndex(P.toUpperCase());var N=parseInt(L);if(F!=null){O=Math.min(O,F)}if(B!=null){N=Math.min(N,B)}for(var H=S;H<=N;H++){for(var R=I;R<=O;R++){Q.push(cE.columnLabelString(R)+H)}}return"["+Q.join(",")+"]"});var A=E.replace(cE.RE_REF_CELL,function(H,J,I){J=J.toUpperCase();if(D!=null){D[J+I]=[parseInt(I),cE.columnLabelIndex(J)]}return"(getCell(("+I+"),'"+J+"').getValue())"});return A},parseFormulaStatic:function(C){if(C==null){return null}var B=C.replace(cE.RE_N,"");var A=parseFloat(B);if(isNaN(A)){A=parseInt(B)}if(isNaN(A)){A=(C.charAt(0)=="'"?C.substring(1):C)}return A},calcLoop:function(calcState){with(calcState){if(done==true){return null}while(fuel==null||fuel>0){if(stack.length>0){var workFunc=stack.pop();if(workFunc!=null){workFunc(calcState)}}else{if(cellProvider.formulaCells!=null){if(cellProvider.formulaCells.length>0){var loc=cellProvider.formulaCells.shift();cE.visitCell(calcState,loc[0],loc[1])}else{done=true;return null}}else{if(cE.visitCell(calcState,row,col)==true){done=true;return null}if(col>=cellProvider.getNumberOfColumns(row)){row=row+1;col=1}else{col=col+1}}}if(fuel!=null){fuel-=1}}}return calcState.calcMore},visitCell:function(calcState,r,c){with(calcState){var cell=cellProvider.getCell(r,c);if(cell==null){return true}var value=cell.getValue();if(value==null){var formula=cell.getFormula();if(formula!=null){var firstChar=formula.charAt(0);if(firstChar=="="){var formulaFunc=cell.getFormulaFunc();if(formulaFunc==null||formulaFunc.formula!=formula){formulaFunc=null;try{var dependencies={};var body=cE.parseFormula(formula.substring(1),dependencies,calcState);formulaFunc=eval("var Calc_spreadsheet_formula = function(__CELL_PROVIDER, __CONTEXT, __STD_FUNCS) { with (__CELL_PROVIDER) {with (__STD_FUNCS) { with (__CONTEXT) { return ("+body+"); }}}}; Calc_spreadsheet_formula");formulaFunc.formula=formula;formulaFunc.dependencies=dependencies;cell.setFormulaFunc(formulaFunc)}catch(e){cell.setValue(e,e)}}if(formulaFunc!=null){stack.push(cE.makeFormulaEval(r,c));var dependencies=formulaFunc.dependencies;for(var k in dependencies){if(dependencies[k] instanceof Array&&cE.checkCycles(stack,dependencies[k][0],dependencies[k][1])==true){cell.setValue(cE.ERROR,"cycle detected");stack.pop();return false}}for(var k in dependencies){if(dependencies[k] instanceof Array){stack.push(cE.makeCellVisit(dependencies[k][0],dependencies[k][1]))}}}}else{cell.setValue(cE.parseFormulaStatic(formula))}}}}return false},makeCellVisit:function(C,A){var B=function(D){return cE.visitCell(D,C,A)};B.row=C;B.col=A;return B},RE_AMP:/&/g,RE_LT:/</g,RE_GT:/>/g,RE_NBSP:/ /,makeFormulaEval:function(C,A){var B=function(F){var D=F.cellProvider.getCell(C,A);if(D!=null){var H=D.getFormulaFunc();if(H!=null){try{var E=H(F.cellProvider,F.context,cE.fn);if(typeof (E)=="string"){E=E.replace(cE.RE_AMP,"&").replace(cE.RE_LT,"<").replace(cE.RE_GT,">").replace(cE.RE_NBSP,"&nbps;")}else{if(typeof (E)=="object"){E=jQuery("<div />").html(E).html()}}D.setValue(E)}catch(G){D.setValue(cE.ERROR+": "+G,G)}}}};B.row=C;B.col=A;return B},checkCycles:function(A,E,B){for(var C=0;C<A.length;C++){var D=A[C];if(D.row!=null&&D.col!=null&&D.row==E&&D.col==B){return true}}return false},foldPrepare:function(A,B){if(A!=null&&A instanceof Object&&A.length!=null){return A}return B},fold:function(B,E,A,D){for(var C=0;C<B.length;C++){A=E(A,(D==true?cE.fn.N(B[C]):B[C]))}return A}};