This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
forked from DanBricklin/socialcalc
-
Notifications
You must be signed in to change notification settings - Fork 6
/
socialcalc.min.js
13 lines (13 loc) · 392 KB
/
socialcalc.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
var SocialCalc;SocialCalc||(SocialCalc={}),SocialCalc.FormatNumber={},SocialCalc.FormatNumber.format_definitions={},SocialCalc.FormatNumber.separatorchar=",",SocialCalc.FormatNumber.decimalchar=".",SocialCalc.FormatNumber.daynames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],SocialCalc.FormatNumber.daynames3=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],SocialCalc.FormatNumber.monthnames3=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],SocialCalc.FormatNumber.monthnames=["January","February","March","April","May","June","July","August","September","October","November","December"],SocialCalc.FormatNumber.allowedcolors={BLACK:"#000000",BLUE:"#0000FF",CYAN:"#00FFFF",GREEN:"#00FF00",MAGENTA:"#FF00FF",RED:"#FF0000",WHITE:"#FFFFFF",YELLOW:"#FFFF00"},SocialCalc.FormatNumber.alloweddates={H:"h]",M:"m]",MM:"mm]",S:"s]",SS:"ss]"},SocialCalc.FormatNumber.commands={copy:1,color:2,integer_placeholder:3,fraction_placeholder:4,decimal:5,currency:6,general:7,separator:8,date:9,comparison:10,section:11,style:12},SocialCalc.FormatNumber.datevalues={julian_offset:2415019,seconds_in_a_day:86400,seconds_in_an_hour:3600},SocialCalc.FormatNumber.formatNumberWithFormat=function(e,t,o){var a,l,r,i,n,c,s,d,u,p,m,h,C,f,S,g,v,b,y,w,x,F,T,k,E,_,P,R,L,M,D,A,I,N,O,U,B,z,G,V=SocialCalc.Constants,H=SocialCalc.FormatNumber,j="";if("string"==typeof e&&!e.length)return"";if(G=e-0,!isFinite(G))return"string"==typeof e?H.formatTextWithFormat(e,t):"NaN";e=G;var K=0>G?1:0;K&&(G=-G);var W=0==G?1:0;if(o=o||V.FormatNumber_DefaultCurrency,H.parse_format_string(H.format_definitions,t),v=H.format_definitions[t],!v)throw"Format not parsed error!";if(b=v.sectioninfo.length-1,v.hascomparison)for(b=0,y=0,F=0;;F++){if(a=v.operators[F],l=v.operands[F],!a){y&&(t="General",H.parse_format_string(H.format_definitions,t),v=H.format_definitions[t],b=0);break}if(a!=H.commands.section){if(a==H.commands.comparison){if(E=l.indexOf(":"),w=l.substring(0,E),x=l.substring(E+1)-0,"<"==w&&x>e||"<="==w&&x>=e||"="==w&&e==x||"<>"==w&&e!=x||">="==w&&e>=x||">"==w&&e>x)break;y=1}}else{if(!y)break;y=0,b++}}else b>0&&(1==b?K?(K=0,b=1):b=0:(2==b||3==b)&&(K?(K=0,b=1):b=W?2:0));if(k=v.sectioninfo[b],k.commas>0)for(E=0;E<k.commas;E++)G/=1e3;if(k.percent>0)for(E=0;E<k.percent;E++)G*=100;for(_=1,E=0;E<k.fractiondigits;E++)_*=10;if(P=Math.floor(G*_+.5),P/=_,"number"!=typeof P)return"NaN";if(!isFinite(P))return"NaN";if(R=P+"",0==P&&(k.fractiondigits||k.integerdigits)&&(K=0),R.indexOf("e")>=0)return e+"";if(L=R.match(/^\+{0,1}(\d*)(?:\.(\d*)){0,1}$/),!L)return"NaN";if(M=L[1],M&&"0"!=M||(M=""),D=L[2],D||(D=""),k.hasdate){if(0>e)return"??-???-?? ??:??:??";for(c=(e-Math.floor(e))*H.datevalues.seconds_in_a_day,s=e*H.datevalues.seconds_in_a_day,d=Math.floor(c/H.datevalues.seconds_in_an_hour),m=Math.floor(s/H.datevalues.seconds_in_an_hour),c-=d*H.datevalues.seconds_in_an_hour,u=Math.floor(c/60),h=Math.floor(s/60),p=c-60*u,_=1,E=0;E<k.fractiondigits;E++)_*=10;for(p=Math.floor(p*_+.5),p/=_,C=Math.floor(s*_+.5),C/=_,p>=60&&(p=0,u++,h++,u>=60&&(u=0,d++,m++,d>=24&&(d=0,e++))),D=p-Math.floor(p)+"",D=D.substring(2),S=SocialCalc.FormatNumber.convert_date_julian_to_gregorian(Math.floor(e+H.datevalues.julian_offset)),g=0,mspos=k.sectionstart;(a=v.operators[mspos],l=v.operands[mspos],a)&&a!=H.commands.section;mspos++)a==H.commands.date?("am/pm"!=l.toLowerCase()&&"a/p"!=l.toLowerCase()||f||(d>=12?(d-=12,f="a/p"==l.toLowerCase()?V.s_FormatNumber_pm1:V.s_FormatNumber_pm):f="a/p"==l.toLowerCase()?V.s_FormatNumber_am1:V.s_FormatNumber_am,l.indexOf(f)<0&&(f=f.toLowerCase())),!g||"m"!=l&&"mm"!=l||(v.operands[mspos]+="in"),g="h"==l.charAt(0)?1:0):a!=H.commands.copy&&(g=0);for(g=0,--mspos;(a=v.operators[mspos],l=v.operands[mspos],a)&&a!=H.commands.section;mspos--)a==H.commands.date?(!g||"m"!=l&&"mm"!=l||(v.operands[mspos]+="in"),g="ss"==l?1:0):a!=H.commands.copy&&(g=0)}for(A=0,I=0,N=0,O="",U="",B=V.FormatNumber_separatorchar,B.indexOf(" ")>=0&&(B=B.replace(/ /g," ")),z=V.FormatNumber_decimalchar,z.indexOf(" ")>=0&&(z=z.replace(/ /g," ")),T=k.sectionstart;a=v.operators[T];)if(l=v.operands[T++],a==H.commands.copy)j+=l;else if(a==H.commands.color)O=l;else if(a==H.commands.style)U=l;else if(a==H.commands.integer_placeholder){if(K&&(j+="-",K=0),A++,1==A&&M.length>k.integerdigits)for(;I<M.length-k.integerdigits;I++)j+=M.charAt(I),k.thousandssep&&(r=M.length-I-1,r>2&&r%3==0&&(j+=B));M.length<k.integerdigits&&A<=k.integerdigits-M.length?("0"==l||"?"==l)&&(j+="0"==l?"0":" ",k.thousandssep&&(r=k.integerdigits-A,r>2&&r%3==0&&(j+=B))):(j+=M.charAt(I),k.thousandssep&&(r=M.length-I-1,r>2&&r%3==0&&(j+=B)),I++)}else if(a==H.commands.fraction_placeholder)N>=D.length?("0"==l||"?"==l)&&(j+="0"==l?"0":" "):j+=D.charAt(N),N++;else if(a==H.commands.decimal)K&&(j+="-",K=0),j+=z;else if(a==H.commands.currency)K&&(j+="-",K=0),j+=l;else if(a==H.commands.general){if(0!=G){var X=Math.floor(Math.LOG10E*Math.log(G));if(X=Math.pow(10,13-X),G=Math.floor(X*G+.5)/X,!isFinite(G))return"NaN"}if(K&&(j+="-"),R=G+"",R.indexOf("e")>=0){j+=R;continue}if(L=R.match(/^\+{0,1}(\d*)(?:\.(\d*)){0,1}$/),M=L[1],M&&"0"!=M||(M=""),D=L[2],D||(D=""),I=0,N=0,M.length)for(;I<M.length;I++)j+=M.charAt(I),k.thousandssep&&(r=M.length-I-1,r>2&&r%3==0&&(j+=B));else j+="0";if(D.length)for(j+=z;N<D.length;N++)j+=D.charAt(N)}else if(a==H.commands.date)n=l.toLowerCase(),"y"==n||"yy"==n?j+=(S.year+"").substring(2):"yyyy"==n?j+=S.year+"":"d"==n?j+=S.day+"":"dd"==n?(i=1e3+S.day,j+=(i+"").substr(2)):"ddd"==n?(i=Math.floor(e+6)%7,j+=V.s_FormatNumber_daynames3[i]):"dddd"==n?(i=Math.floor(e+6)%7,j+=V.s_FormatNumber_daynames[i]):"m"==n?j+=S.month+"":"mm"==n?(i=1e3+S.month,j+=(i+"").substr(2)):"mmm"==n?j+=V.s_FormatNumber_monthnames3[S.month-1]:"mmmm"==n?j+=V.s_FormatNumber_monthnames[S.month-1]:"mmmmm"==n?j+=V.s_FormatNumber_monthnames[S.month-1].charAt(0):"h"==n?j+=d+"":"h]"==n?j+=m+"":"mmin"==n?(i=1e3+u+"",j+=i.substr(2)):"mm]"==n?100>h?(i=1e3+h+"",j+=i.substr(2)):j+=h+"":"min"==n?j+=u+"":"m]"==n?j+=h+"":"hh"==n?(i=1e3+d+"",j+=i.substr(2)):"s"==n?(i=Math.floor(p),j+=i+""):"ss"==n?(i=1e3+Math.floor(p)+"",j+=i.substr(2)):"am/pm"==n||"a/p"==n?j+=f:"ss]"==n&&(100>C?(i=1e3+Math.floor(C)+"",j+=i.substr(2)):(i=Math.floor(C),j+=i+""));else{if(a==H.commands.section)break;if(a==H.commands.comparison)continue;j+="!! Parse error !!"}return O&&(j='<span style="color:'+O+';">'+j+"</span>"),U&&(j='<span style="'+U+';">'+j+"</span>"),j},SocialCalc.FormatNumber.formatTextWithFormat=function(e,t){var o,a,l,r,i=(SocialCalc.Constants,SocialCalc.FormatNumber),n=e+"",c="",s="",d="";if(i.parse_format_string(i.format_definitions,t),thisformat=i.format_definitions[t],!thisformat)throw"Format not parsed error!";if(o=thisformat.sectioninfo.length-1,0==o)o=0;else{if(3!=o)return n;o=3}for(a=thisformat.sectioninfo[o],l=a.sectionstart;op=thisformat.operators[l];)r=thisformat.operands[l++],op==i.commands.copy?c+="@"==r?n:r.replace(/ /g," "):op==i.commands.color?s=r:op==i.commands.style&&(d=r);return s&&(c='<span style="color:'+s+';">'+c+"</span>"),d&&(c='<span style="'+d+';">'+c+"</span>"),c},SocialCalc.FormatNumber.parse_format_string=function(e,t){var o,a,l,r,i,n,c,s,d,u,p,m,h,C,f,S,g,v=SocialCalc.FormatNumber,b=1;if(!e[t]){for(o={operators:[],operands:[],sectioninfo:[{}]},e[t]=o,a=0,sectioninfo=o.sectioninfo[a],sectioninfo.sectionstart=0,sectioninfo.integerdigits=0,sectioninfo.fractiondigits=0,sectioninfo.commas=0,sectioninfo.percent=0,S=0;S<t.length;S++)if(g=t.charAt(S),c){if('"'==g){c=0,o.operators.push(v.commands.copy),o.operands.push(s);continue}s+=g}else if(d){if("]"==g){if(d=0,p=SocialCalc.FormatNumber.parse_format_bracket(u),p.operator==v.commands.separator){sectioninfo.thousandssep=1;continue}p.operator==v.commands.date&&(sectioninfo.hasdate=1),p.operator==v.commands.comparison&&(o.hascomparison=1),o.operators.push(p.operator),o.operands.push(p.operand);continue}u+=g}else if(r)o.operators.push(v.commands.copy),o.operands.push(g),r=!1;else if(i)o.operators.push(v.commands.copy),o.operands.push(g+g+g+g+g),i=!1;else if(n)o.operators.push(v.commands.copy),o.operands.push(" "),n=!1;else{if(m){if("general".charAt(m)==g.toLowerCase()){m++,7==m&&(o.operators.push(v.commands.general),o.operands.push(g),m=0);continue}m=0}if(f){if(f.charAt(0)==g){f+=g;continue}o.operators.push(v.commands.date),o.operands.push(f),sectioninfo.hasdate=1,f=""}h?(h+=g,C=h.toLowerCase(),C!="am/pm".substring(0,C.length)&&C!="a/p".substring(0,C.length)?ampstr="":("am/pm"==C||"a/p"==C)&&(o.operators.push(v.commands.date),o.operands.push(h),h="")):"#"==g||"0"==g||"?"==g?b?(sectioninfo.integerdigits++,sectioninfo.commas&&(sectioninfo.thousandssep=1,sectioninfo.commas=0),l=1,o.operators.push(v.commands.integer_placeholder),o.operands.push(g)):(sectioninfo.fractiondigits++,l=1,o.operators.push(v.commands.fraction_placeholder),o.operands.push(g)):"."==g?(l=0,o.operators.push(v.commands.decimal),o.operands.push(g),b=0):"$"==g?(l=0,o.operators.push(v.commands.currency),o.operands.push(g)):","==g?l?sectioninfo.commas++:(o.operators.push(v.commands.copy),o.operands.push(g)):"%"==g?(l=0,sectioninfo.percent++,o.operators.push(v.commands.copy),o.operands.push(g)):'"'==g?(l=0,c=1,s=""):"["==g?(l=0,d=1,u=""):"\\"==g?(r=1,l=0):"*"==g?(i=1,l=0):"_"==g?(n=1,l=0):";"==g?(a++,o.sectioninfo[a]={},sectioninfo=o.sectioninfo[a],sectioninfo.sectionstart=1+o.operators.length,sectioninfo.integerdigits=0,sectioninfo.fractiondigits=0,sectioninfo.commas=0,sectioninfo.percent=0,b=1,l=0,o.operators.push(v.commands.section),o.operands.push(g)):"g"==g.toLowerCase()?(m=1,l=0):"a"==g.toLowerCase()?(h=g,l=0):"dmyhHs".indexOf(g)>=0?f=g:(l=0,o.operators.push(v.commands.copy),o.operands.push(g))}f&&(o.operators.push(v.commands.date),o.operands.push(f),sectioninfo.hasdate=1)}},SocialCalc.FormatNumber.parse_format_bracket=function(e){var t,o=SocialCalc.FormatNumber,a=SocialCalc.Constants,l={};return"$"==e.charAt(0)?(l.operator=o.commands.currency,t=e.match(/^\$(.+?)(\-.+?){0,1}$/),t?l.operand=t[1]||a.FormatNumber_defaultCurrency||"$":l.operand=e.substring(1)||a.FormatNumber_defaultCurrency||"$"):"?$"==e?(l.operator=o.commands.currency,l.operand="[?$]"):o.allowedcolors[e.toUpperCase()]?(l.operator=o.commands.color,l.operand=o.allowedcolors[e.toUpperCase()]):(t=e.match(/^style=([^"]*)$/))?(l.operator=o.commands.style,l.operand=t[1]):","==e?(l.operator=o.commands.separator,l.operand=e):o.alloweddates[e.toUpperCase()]?(l.operator=o.commands.date,l.operand=o.alloweddates[e.toUpperCase()]):(t=e.match(/^[<>=]/))?(t=e.match(/^([<>=]+)(.+)$/),l.operator=o.commands.comparison,l.operand=t[1]+":"+t[2]):(l.operator=o.commands.copy,l.operand="["+e+"]"),l},SocialCalc.FormatNumber.convert_date_gregorian_to_julian=function(e,t,o){var a;return a=o-32075+SocialCalc.intFunc(1461*(e+4800+SocialCalc.intFunc((t-14)/12))/4),a+=SocialCalc.intFunc(367*(t-2-12*SocialCalc.intFunc((t-14)/12))/12),a-=SocialCalc.intFunc(3*SocialCalc.intFunc((e+4900+SocialCalc.intFunc((t-14)/12))/100)/4)},SocialCalc.FormatNumber.convert_date_julian_to_gregorian=function(e){var t,o,a,l,r;return t=e+68569,o=Math.floor(4*t/146097),t-=Math.floor((146097*o+3)/4),a=Math.floor(4e3*(t+1)/1461001),t=t-Math.floor(1461*a/4)+31,l=Math.floor(80*t/2447),r=t-Math.floor(2447*l/80),t=Math.floor(l/11),l=l+2-12*t,a=100*(o-49)+a+t,{year:a,month:l,day:r}},SocialCalc.intFunc=function(e){return 0>e?-Math.floor(-e):Math.floor(e)};var SocialCalc;SocialCalc||(SocialCalc={}),SocialCalc.Formula={},SocialCalc.Formula.ParseState={num:1,alpha:2,coord:3,string:4,stringquote:5,numexp1:6,numexp2:7,alphanumeric:8,specialvalue:9},SocialCalc.Formula.TokenType={num:1,coord:2,op:3,name:4,error:5,string:6,space:7},SocialCalc.Formula.CharClass={num:1,numstart:2,op:3,eof:4,alpha:5,incoord:6,error:7,quote:8,space:9,specialstart:10},SocialCalc.Formula.CharClassTable={" ":9,"!":3,'"':8,"'":8,"#":10,$:6,"%":3,"&":3,"(":3,")":3,"*":3,"+":3,",":3,"-":3,".":2,"/":3,0:1,1:1,2:1,3:1,4:1,5:1,6:1,7:1,8:1,9:1,":":3,"<":3,"=":3,">":3,A:5,B:5,C:5,D:5,E:5,F:5,G:5,H:5,I:5,J:5,K:5,L:5,M:5,N:5,O:5,P:5,Q:5,R:5,S:5,T:5,U:5,V:5,W:5,X:5,Y:5,Z:5,"^":3,_:5,a:5,b:5,c:5,d:5,e:5,f:5,g:5,h:5,i:5,j:5,k:5,l:5,m:5,n:5,o:5,p:5,q:5,r:5,s:5,t:5,u:5,v:5,w:5,x:5,y:5,z:5},SocialCalc.Formula.UpperCaseTable={a:"A",b:"B",c:"C",d:"D",e:"E",f:"F",g:"G",h:"H",i:"I",j:"J",k:"K",l:"L",m:"M",n:"N",o:"O",p:"P",q:"Q",r:"R",s:"S",t:"T",u:"U",v:"V",w:"W",x:"X",y:"Y",z:"Z",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z"},SocialCalc.Formula.SpecialConstants={"#NULL!":"0,e#NULL!","#NUM!":"0,e#NUM!","#DIV/0!":"0,e#DIV/0!","#VALUE!":"0,e#VALUE!","#REF!":"0,e#REF!","#NAME?":"0,e#NAME?"},SocialCalc.Formula.TokenPrecedence={"!":1,":":2,",":2,M:-3,P:-3,"%":4,"^":5,"*":6,"/":6,"+":7,"-":7,"&":8,"<":9,">":9,G:9,L:9,N:9},SocialCalc.Formula.TokenOpExpansion={G:">=",L:"<=",M:"-",N:"<>",P:"+"},SocialCalc.Formula.TypeLookupTable={unaryminus:{"n*":"|n*:1|","e*":"|e*:1|","t*":"|t*:e#VALUE!|",b:"|b:n|"},unaryplus:{"n*":"|n*:1|","e*":"|e*:1|","t*":"|t*:e#VALUE!|",b:"|b:n|"},unarypercent:{"n*":"|n:n%|n*:n|","e*":"|e*:1|","t*":"|t*:e#VALUE!|",b:"|b:n|"},plus:{"n%":"|n%:n%|nd:n|nt:n|ndt:n|n$:n|n:n|n*:n|b:n|e*:2|t*:e#VALUE!|",nd:"|n%:n|nd:nd|nt:ndt|ndt:ndt|n$:n|n:nd|n*:n|b:n|e*:2|t*:e#VALUE!|",nt:"|n%:n|nd:ndt|nt:nt|ndt:ndt|n$:n|n:nt|n*:n|b:n|e*:2|t*:e#VALUE!|",ndt:"|n%:n|nd:ndt|nt:ndt|ndt:ndt|n$:n|n:ndt|n*:n|b:n|e*:2|t*:e#VALUE!|",n$:"|n%:n|nd:n|nt:n|ndt:n|n$:n$|n:n$|n*:n|b:n|e*:2|t*:e#VALUE!|",nl:"|n%:n|nd:n|nt:n|ndt:n|n$:n|n:n|n*:n|b:n|e*:2|t*:e#VALUE!|",n:"|n%:n|nd:nd|nt:nt|ndt:ndt|n$:n$|n:n|n*:n|b:n|e*:2|t*:e#VALUE!|",b:"|n%:n%|nd:nd|nt:nt|ndt:ndt|n$:n$|n:n|n*:n|b:n|e*:2|t*:e#VALUE!|","t*":"|n*:e#VALUE!|t*:e#VALUE!|b:e#VALUE!|e*:2|","e*":"|e*:1|n*:1|t*:1|b:1|"},concat:{t:"|t:t|th:th|tw:tw|tl:t|tr:tr|t*:2|e*:2|",th:"|t:th|th:th|tw:t|tl:th|tr:t|t*:t|e*:2|",tw:"|t:tw|th:t|tw:tw|tl:tw|tr:tw|t*:t|e*:2|",tl:"|t:tl|th:th|tw:tw|tl:tl|tr:tr|t*:t|e*:2|","t*":"|t*:t|e*:2|","e*":"|e*:1|n*:1|t*:1|"},oneargnumeric:{"n*":"|n*:n|","e*":"|e*:1|","t*":"|t*:e#VALUE!|",b:"|b:n|"},twoargnumeric:{"n*":"|n*:n|t*:e#VALUE!|e*:2|","e*":"|e*:1|n*:1|t*:1|","t*":"|t*:e#VALUE!|n*:e#VALUE!|e*:2|"},propagateerror:{"n*":"|n*:2|e*:2|","e*":"|e*:2|","t*":"|t*:2|e*:2|",b:"|b:2|e*:2|"}},SocialCalc.Formula.ParseFormulaIntoTokens=function(e){var t,o,a,l,r,i,n,c,s=SocialCalc.Formula,d=SocialCalc.Constants,u=s.ParseState,p=s.TokenType,m=s.CharClass,h=s.CharClassTable,C=s.UpperCaseTable,f=s.ParsePushToken,S=/^\$?[A-Z]{1,2}\$?[1-9]\d*$/i,g=[],v="",b=0,l=!1;for(t=0;t<=e.length;t++)t<e.length?(o=e.charAt(t),a=h[o]):(o="",a=m.eof),b==u.num&&(a==m.num?v+=o:a!=m.numstart||l?"E"==o||"e"==o?(v+=o,l=!1,b=u.numexp1):(f(g,v,p.num,0),l=!1,b=0):(l=!0,v+=o)),b==u.numexp1&&(a==u.num?b=u.numexp2:"+"!=o&&"-"!=o||"E"!=C[v.charAt(v.length-1)]?"E"==o||"e"==o||(f(g,d.s_parseerrexponent,p.error,0),b=0):v+=o),b==u.numexp2&&(a==m.num?v+=o:(f(g,v,p.num,0),b=0)),b==u.alpha&&(a==m.num?b=u.coord:a==m.alpha||"."==o?v+=o:a==m.incoord?b=u.coord:a==m.op||a==m.numstart||a==m.space||a==m.eof?(f(g,v.toUpperCase(),p.name,0),b=0):(f(g,d.s_parseerrchar,p.error,0),b=0)),b==u.coord&&(a==m.num?v+=o:a==m.incoord?v+=o:a==m.alpha?b=u.alphanumeric:a==m.op||a==m.numstart||a==m.eof||a==m.space?(c=S.test(v)?p.coord:p.name,f(g,v.toUpperCase(),c,0),b=0):(f(g,d.s_parseerrchar,p.error,0),b=0)),b==u.alphanumeric&&(a==m.num||a==m.alpha?v+=o:a==m.op||a==m.numstart||a==m.space||a==m.eof?(f(g,v.toUpperCase(),p.name,0),b=0):(f(g,d.s_parseerrchar,p.error,0),b=0)),b==u.string?a==m.quote?b=u.stringquote:a==m.eof?(f(g,d.s_parseerrstring,p.error,0),b=0):v+=o:b==u.stringquote?a==m.quote?(v+=o,b=u.string):(f(g,v,p.string,0),b=0):b==u.specialvalue&&("!"==v.charAt(v.length-1)?(f(g,v,p.name,0),b=0):a==m.eof?(f(g,d.s_parseerrspecialvalue,p.error,0),b=0):v+=o),0==b&&(a==m.num?(v=o,b=u.num):a==m.numstart?(v=o,l=!0,b=u.num):a==m.alpha||a==m.incoord?(v=o,b=u.alpha):a==m.specialstart?(v=o,b=u.specialvalue):a==m.op?(v=o,g.length>0?(r=g[g.length-1],i=r.type,n=r.text,i==m.op&&(("<"==n||">"==n)&&"="==v||"<"==n&&">"==v)&&(v=n+v,g.pop(),g.length>0?(r=g[g.length-1],i=r.type,n=r.text):(i=m.eof,n="EOF"))):(i=m.eof,n="EOF"),c=p.op,0==g.length||i==m.op&&")"!=n&&"%"!=n?"-"==v?(v="M",o="M"):"+"==v?(v="P",o="P"):")"==v&&"("==n||"("!=v&&(c=p.error,v=d.s_parseerrtwoops):v.length>1&&(">="==v?(v="G",o="G"):"<="==v?(v="L",o="L"):"<>"==v?(v="N",o="N"):(c=p.error,v=d.s_parseerrtwoops)),f(g,v,c,o),b=0):a==m.quote?(v="",b=u.string):a==m.space||a==m.eof||f(g,d.s_parseerrchar,p.error,0));return g},SocialCalc.Formula.ParsePushToken=function(e,t,o,a){e.push({text:t,type:o,opcode:a})},SocialCalc.Formula.evaluate_parsed_formula=function(e,t,o){var a,l,r=SocialCalc.Formula;r.TokenType;return l=r.ConvertInfixToPolish(e),a=r.EvaluatePolish(e,l,t,o)},SocialCalc.Formula.ConvertInfixToPolish=function(e){var t,o,a,l,r,i,n=SocialCalc.Formula,c=SocialCalc.Constants,s=n.TokenType,d=n.TokenPrecedence,u=[],p=[],m="",h=-1;for(t=0;t<e.length;t++)if(o=e[t],a=o.type,l=o.text,a==s.num||a==s.coord||a==s.string)u.push(t);else if(a==s.name)p.push(t),u.push(h);else{if(a==s.space)continue;if(","==l){for(;p.length&&"("!=e[p[p.length-1]].text;)u.push(p.pop());if(0==p.length){m=c.s_parseerrmissingopenparen;break}}else if("("==l)p.push(t);else if(")"==l){for(;p.length&&"("!=e[p[p.length-1]].text;)u.push(p.pop());if(0==p.length){m=c.s_parseerrcloseparennoopen;break}p.pop(),p.length&&e[p[p.length-1]].type==s.name&&u.push(p.pop())}else{if(a!=s.op){if(a==s.error){m=l;break}m="Internal error while processing parsed formula. ";break}for(p.length&&e[p[p.length-1]].type==s.name&&u.push(p.pop());p.length&&e[p[p.length-1]].type==s.op&&"("!=e[p[p.length-1]].text&&(r=d[o.opcode],i=d[e[p[p.length-1]].opcode],!(r>=0&&i>r))&&!(0>r&&(r=-r,0>i&&(i=-i),i>=r));)u.push(p.pop());p.push(t)}}for(;p.length>0;){if("("==e[p[p.length-1]].text){m=c.s_parseerrmissingcloseparen;break}u.push(p.pop())}return m?m:u},SocialCalc.Formula.EvaluatePolish=function(e,t,o,a){var l,r,i,n,c,s,d,u,p,m,h,C,f,S,g=SocialCalc.Formula,v=SocialCalc.Constants,b=g.TokenType,y=g.LookupResultType,w=g.TypeLookupTable,x=g.OperandAsNumber,F=g.OperandAsText,T=g.OperandValueAndType,k=g.OperandsAsCoordOnSheet,E=SocialCalc.format_number_for_display||function(e,t,o){return e+""},_="",P=-1,R={value:"",type:"e#VALUE!",error:v.s_parseerrmissingoperand},L=[],M=function(e,t){L.push({type:e,value:t})};if(!(e.length&&t instanceof Array))return{value:"",type:"e#VALUE!",error:"string"==typeof t?t:""};for(l=0;l<t.length;l++)if(r=t[l],r!=P)if(i=e[r],n=i.type,c=i.text,n==b.num)M("n",c-0);else if(n==b.coord)M("coord",c);else if(n==b.string)M("t",c);else if(n==b.op){if(L.length<=0)return R;if("M"==c)s=x(o,L),m=y(s.type,s.type,w.unaryminus),M(m,-s.value);else if("P"==c)s=x(o,L),m=y(s.type,s.type,w.unaryplus),M(m,s.value);else if("%"==c)s=x(o,L),m=y(s.type,s.type,w.unarypercent),M(m,.01*s.value);else if("&"==c){if(L.length<=1)return R;d=F(o,L),s=F(o,L),m=y(s.type,s.type,w.concat),M(m,s.value+d.value)}else if(":"==c){if(L.length<=1)return R;s=g.OperandsAsRangeOnSheet(o,L),s.error&&(_=_||s.error),M(s.type,s.value)}else if("!"==c){if(L.length<=1)return R;s=k(o,L),s.error&&(_=_||s.error),M(s.type,s.value)}else if("<"==c||"L"==c||"="==c||"G"==c||">"==c||"N"==c){if(L.length<=1){_=v.s_parseerrmissingoperand;break}d=T(o,L),s=T(o,L),"n"==s.type.charAt(0)&&"n"==d.type.charAt(0)?(C=0,"<"==c?C=s.value<d.value?1:0:"L"==c?C=s.value<=d.value?1:0:"="==c?C=s.value==d.value?1:0:"G"==c?C=s.value>=d.value?1:0:">"==c?C=s.value>d.value?1:0:"N"==c&&(C=s.value!=d.value?1:0),M("nl",C)):"e"==s.type.charAt(0)?M(s.type,0):"e"==d.type.charAt(0)?M(d.type,0):(u=s.type.charAt(0),p=d.type.charAt(0),"n"==u?s.value=E(s.value,"n",""):"b"==u&&(s.value=""),"n"==p?d.value=E(d.value,"n",""):"b"==p&&(d.value=""),C=0,s.value=s.value.toLowerCase(),d.value=d.value.toLowerCase(),"<"==c?C=s.value<d.value?1:0:"L"==c?C=s.value<=d.value?1:0:"="==c?C=s.value==d.value?1:0:"G"==c?C=s.value>=d.value?1:0:">"==c?C=s.value>d.value?1:0:"N"==c&&(C=s.value!=d.value?1:0),M("nl",C))}else{if(L.length<=1){_=v.s_parseerrmissingoperand;break}d=x(o,L),s=x(o,L),"+"==c?(m=y(s.type,d.type,w.plus),M(m,s.value+d.value)):"-"==c?(m=y(s.type,d.type,w.plus),M(m,s.value-d.value)):"*"==c?(m=y(s.type,d.type,w.plus),M(m,s.value*d.value)):"/"==c?0!=d.value?M("n",s.value/d.value):M("e#DIV/0!",0):"^"==c&&(s.value=Math.pow(s.value,d.value),s.type="n",isNaN(s.value)&&(s.value=0,s.type="e#NUM!"),M(s.type,s.value))}}else{if(n!=b.name){_=v.s_InternalError+"Unknown token "+n+" ("+c+"). ";break}if(_=g.CalculateFunction(c,L,o))break}else M("start",0);return value=L[0]?L[0].value:"",u=L[0]?L[0].type:"","name"==u&&(s=SocialCalc.Formula.LookupName(o,value),value=s.value,u=s.type,_=_||s.error),"coord"==u&&(s=T(o,L),value=s.value,u=s.type,"b"==u&&(u="n",value=0)),L.length>1&&!_&&(_+=v.s_parseerrerrorinformula),h=u,"e"==u.charAt(0)?_=_||u.substring(1)||v.s_calcerrerrorvalueinformula:"range"==u&&(f=value.match(/^(.*)\|(.*)\|/),S=f[1].indexOf("!"),S>=0?f[1]=f[1].substring(S+1)+"!"+f[1].substring(0,S).toUpperCase():f[1]=f[1].toUpperCase(),value=f[1]+":"+f[2].toUpperCase(),a||(_=v.s_formularangeresult+" "+value)),_&&"e"!=h.charAt(0)&&(value=_,h="e"),"n"!=h.charAt(0)||!isNaN(value)&&isFinite(value)||(value=0,h="e#NUM!",_=isNaN(value)?v.s_calcerrnumericnan:v.s_calcerrnumericoverflow),{value:value,type:h,error:_}},SocialCalc.Formula.LookupResultType=function(e,t,o){var a,l,r,i=o[e];return i||(i=o[e.charAt(0)+"*"])?(a=i.indexOf("|"+t+":"),a>=0?(l=i.indexOf("|",a+1),0>l?"e#VALUE! (internal error, incorrect LookupResultType "+i+")":(r=i.substring(a+t.length+2,l),"1"==r?e:"2"==r?t:r)):(a=i.indexOf("|"+t.charAt(0)+"*:"),a>=0?(l=i.indexOf("|",a+1),0>l?"e#VALUE! (internal error, incorrect LookupResultType "+i+")":(r=i.substring(a+4,l),"1"==r?e:"2"==r?t:r)):"e#VALUE!")):"e#VALUE! (internal error, missing LookupResultType "+e.charAt(0)+"*)"},SocialCalc.Formula.TopOfStackValueAndType=function(e,t){var o=SocialCalc.Formula,a={type:"",value:""},l=t.length;return l?(a.value=t[l-1].value,a.type=t[l-1].type,t.pop(),"name"==a.type&&(a=o.LookupName(e,a.value)),a):(a.error=SocialCalc.Constants.s_InternalError+"no operand on stack",a)},SocialCalc.Formula.OperandAsNumber=function(e,t){var o,a,l=SocialCalc.Formula.OperandValueAndType(e,t);return o=l.type.charAt(0),"n"==o?l.value=l.value-0:"b"==o?(l.type="n",l.value=0):"e"==o?l.value=0:(a=SocialCalc.DetermineValueType?SocialCalc.DetermineValueType(l.value):{value:l.value-0,type:"n"},"n"==a.type.charAt(0)?(l.value=a.value-0,l.type=a.type):(l.value=0,l.type=a.type)),l},SocialCalc.Formula.OperandAsText=function(e,t){var o,a=SocialCalc.Formula.OperandValueAndType(e,t);return o=a.type.charAt(0),"t"==o||("n"==o?(a.value=SocialCalc.format_number_for_display?SocialCalc.format_number_for_display(a.value,a.type,""):a.value=a.value+"",a.type="t"):"b"==o?(a.value="",a.type="t"):"e"==o?a.value="":(t.value=a.value+"",t.type="t")),a},SocialCalc.Formula.OperandValueAndType=function(e,t){var o,a,l,r,i=SocialCalc.Formula,n={type:"",value:""},c=t.length;if(!c)return n.error=SocialCalc.Constants.s_InternalError+"no operand on stack",n;if(n.value=t[c-1].value,n.type=t[c-1].type,t.pop(),"name"==n.type&&(n=i.LookupName(e,n.value)),"range"==n.type&&(n=i.StepThroughRangeDown(t,n.value)),"coord"==n.type){if(r=e,l=n.value.indexOf("!"),-1!=l){if(r=i.FindInSheetCache(n.value.substring(l+1)),null==r)return n.type="e#REF!",n.error=SocialCalc.Constants.s_sheetunavailable+" "+n.value.substring(l+1),n.value=0,n;n.value=n.value.substring(0,l)}r?(a=r.cells[SocialCalc.Formula.PlainCoord(n.value)],a?(o=a.valuetype,n.value=a.datavalue):o="b"):(o="e#N/A",n.value=0),n.type=o||"b","b"==n.type&&(n.value=0)}return n},SocialCalc.Formula.OperandAsCoord=function(e,t){var o=(SocialCalc.Formula,{type:"",value:""}),a=t.length;return o.value=t[a-1].value,o.type=t[a-1].type,t.pop(),"name"==o.type&&(o=SocialCalc.Formula.LookupName(e,o.value)),"coord"==o.type?o:(o.value=SocialCalc.Constants.s_calcerrcellrefmissing,o.type="e#REF!",o)},SocialCalc.Formula.OperandsAsCoordOnSheet=function(e,t){var o,a,l,r,i={},n={},c=SocialCalc.Formula,s=t.length;return i.value=t[s-1].value,i.type=t[s-1].type,t.pop(),o=c.OperandAsSheetName(e,t),a=c.FindInSheetCache(o.value),null==a?(n.type="e#REF!",n.value=0,n.error=SocialCalc.Constants.s_sheetunavailable+" "+o.value,n):("name"==i.type&&(i=c.LookupName(a,i.value)),n.type=i.type,"coord"==i.type?n.value=i.value+"!"+o.value:"range"==i.type?(l=i.value.indexOf("|"),r=i.value.indexOf("|",l+1),n.value=i.value.substring(0,l)+"!"+o.value+"|"+i.value.substring(l+1,r)+"|"):"e"==i.type.charAt(0)?n.value=i.value:(n.error=SocialCalc.Constants.s_calcerrcellrefmissing,n.type="e#REF!",n.value=0),n)},SocialCalc.Formula.OperandsAsRangeOnSheet=function(e,t){var o,a,l,r,i={},n=SocialCalc.Formula,c=SocialCalc.Constants,s=t.length;return i.value=t[s-1].value,i.type=t[s-1].type,t.pop(),o=n.OperandAsCoord(e,t),"coord"!=o.type?{value:0,type:"e#REF!"}:(a=e,l=o.value.indexOf("!"),-1!=l&&(r=o.value.indexOf("|",l+1),0>r&&(r=o.value.length),a=n.FindInSheetCache(o.value.substring(l+1,r)),null==a)?{value:0,type:"e#REF!",errortext:c.s_sheetunavailable+" "+o.value.substring(l+1,r)}:("name"==i.type&&(i=n.LookupName(a,i.value)),"coord"==i.type?{value:o.value+"|"+i.value+"|",type:"range"}:{value:c.s_calcerrcellrefmissing,type:"e#REF!"}))},SocialCalc.Formula.OperandAsSheetName=function(e,t){var o,a,l=(SocialCalc.Formula,{type:"",value:""}),r=t.length;if(l.value=t[r-1].value,l.type=t[r-1].type,t.pop(),"name"==l.type){if(o=SocialCalc.Formula.LookupName(e,l.value),!o.value)return l;l.value=o.value,l.type=o.type}return"coord"==l.type&&(a=e.cells[SocialCalc.Formula.PlainCoord(l.value)],a?(l.value=a.datavalue,l.type=a.valuetype):(l.value="",l.type="b")),"t"==l.type.charAt(0)?l:(l.value="",l.error=SocialCalc.Constants.s_calcerrsheetnamemissing,l)},SocialCalc.Formula.LookupName=function(e,t){var o,a,l,r=e.names,i={},n=!1;if(r[t.toUpperCase()]){if(i.value=r[t.toUpperCase()].definition,"="==i.value.charAt(0)){if(e.checknamecirc){if(e.checknamecirc[t])return i.type="e#NAME?",i.error=SocialCalc.Constants.s_circularnameref+' "'+t+'".',i}else e.checknamecirc={},n=!0;if(e.checknamecirc[t]=!0,l=SocialCalc.Formula.ParseFormulaIntoTokens(i.value.substring(1)),i=SocialCalc.Formula.evaluate_parsed_formula(l,e,1),delete e.checknamecirc[t],n&&delete e.checknamecirc,"range"!=i.type)return i}return o=i.value.indexOf(":"),-1!=o?(i.type="range",i.value=i.value.substring(0,o)+"|"+i.value.substring(o+1)+"|",i.value=i.value.toUpperCase()):(i.type="coord",i.value=i.value.toUpperCase()),i}return(a=SocialCalc.Formula.SpecialConstants[t.toUpperCase()])?(o=a.indexOf(","),i.value=a.substring(0,o)-0,i.type=a.substring(o+1),i):(i.value="",i.type="e#NAME?",i.error=SocialCalc.Constants.s_calcerrunknownname+' "'+t+'"',i)},SocialCalc.Formula.StepThroughRangeDown=function(e,t){var o,a,l,r,i,n,c,s,d,u,p=SocialCalc.Formula;for(r=t.indexOf("|"),i=t.indexOf("|",r+1),o=t.substring(0,r),a=t.substring(r+1,i),l=t.substring(i+1)-0,r=o.indexOf("!"),-1!=r?(n=o.substring(r),o=o.substring(0,r)):n="",r=a.indexOf("!"),-1!=r&&(a=a.substring(0,r)),c=p.OrderRangeParts(o,a),u=0,d=c.r1;d<=c.r2;d++)for(s=c.c1;s<=c.c2;s++)if(u++,u>l)return(d!=c.r2||s!=c.c2)&&p.PushOperand(e,"range",o+n+"|"+a+"|"+u),{value:SocialCalc.crToCoord(s,d)+n,type:"coord"}},SocialCalc.Formula.DecodeRangeParts=function(e,t){var o,a,l,r,i,n,c,s=SocialCalc.Formula;return l=t.indexOf("|"),r=t.indexOf("|",l+1),o=t.substring(0,l),a=t.substring(l+1,r),l=o.indexOf("!"),-1!=l?(i=o.substring(l+1),o=o.substring(0,l)):i="",l=a.indexOf("!"),-1!=l&&(a=a.substring(0,l)),n=e,i&&(n=s.FindInSheetCache(i),null==n)?null:(c=s.OrderRangeParts(o,a),{sheetdata:n,sheetname:i,col1num:c.c1,ncols:c.c2-c.c1+1,row1num:c.r1,nrows:c.r2-c.r1+1})},SocialCalc.Formula.FunctionList||(SocialCalc.Formula.FunctionList={}),SocialCalc.Formula.FunctionClasses=null,SocialCalc.Formula.FunctionArgDefs={},SocialCalc.Formula.CalculateFunction=function(e,t,o){var a,l,r,i,n,c=SocialCalc.Formula,s="";if(a=c.FunctionList[e]){if(l=[],r=a[0],i=a[1],c.CopyFunctionArgs(t,l),100!=i)if(0>i){if(l.length<-i)return s=c.FunctionArgsError(e,t)}else if(l.length!=i)return s=c.FunctionArgsError(e,t);s=r(e,t,l,o)}else n=e,t.length&&"start"==t[t.length-1].type?(t.pop(),c.PushOperand(t,"name",n)):s=SocialCalc.Constants.s_sheetfuncunknownfunction+" "+n+". ";return s},SocialCalc.Formula.PushOperand=function(e,t,o){e.push({type:t,value:o})},SocialCalc.Formula.CopyFunctionArgs=function(e,t){var t;for(SocialCalc.Formula;e.length>0&&"start"!=e[e.length-1].type;)t.push(e.pop());e.pop()},SocialCalc.Formula.FunctionArgsError=function(e,t){var o=SocialCalc.Constants.s_calcerrincorrectargstofunction+" "+e+". ";return SocialCalc.Formula.PushOperand(t,"e#VALUE!",o),o},SocialCalc.Formula.FunctionSpecificError=function(e,t,o,a){return SocialCalc.Formula.PushOperand(t,o,a),a},SocialCalc.Formula.CheckForErrorValue=function(e,t){return"e"==t.type.charAt(0)?(e.push(t),!0):!1},SocialCalc.Formula.FillFunctionInfo=function(){var e,t,o,a,l,r=SocialCalc.Formula,i=SocialCalc.Constants;if(!r.FunctionClasses){for(e in r.FunctionList)t=r.FunctionList[e],t[2]&&(r.FunctionArgDefs[t[2]]=i["s_farg_"+t[2]]||""),t[3]||i["s_fdef_"+e]&&(r.FunctionList[e][3]=i["s_fdef_"+e]);for(r.FunctionClasses={},l=0;l<i.function_classlist.length;l++)a=i.function_classlist[l],r.FunctionClasses[a]={name:i["s_fclass_"+a],items:[]};for(e in r.FunctionList)for(t=r.FunctionList[e],o=t[4]?t[4].split(","):[],o.push("all"),l=0;l<o.length;l++)a=o[l],r.FunctionClasses[a].items.push(e);for(a in r.FunctionClasses)r.FunctionClasses[a].items.sort()}},SocialCalc.Formula.FunctionArgString=function(e){var t,o,a,l=SocialCalc.Formula,r=l.FunctionList[e],i=r[2];if(!i){if(t=r[1],0!=t){if(t>0){for(a="v1",o=2;t>=o;o++)a+=", v"+o;return a}if(0>t){for(a="v1",o=2;-t>o;o++)a+=", v"+o;return a+", ..."}return"nargs: "+t}i=" "}return a=l.FunctionArgDefs[i]||i},SocialCalc.Formula.SeriesFunctions=function(e,t,o,a){for(var l,r,i,n,c,s,d,u,p,m=SocialCalc.Formula,h=m.OperandValueAndType,C=m.LookupResultType,f=m.TypeLookupTable.plus,S=function(e,o){t.push({type:e,value:o})},g=0,v="",b=0,y=0,w=0,x=1;o.length>0;)l=h(a,o),r=l.type.charAt(0),"n"==r&&(b+=1),"b"!=r&&(y+=1),"b"==r&&(w+=1),"n"==r?(i=l.value-0,g+=i,x*=i,n=void 0!=n?i>n?i:n:i,c=void 0!=c?c>i?i:c:i,1==b?(u=i,p=0):(s=u+(i-u)/b,d=p+(i-u)*(i-s),p=d,u=s),v=C(l.type,v||l.type,f)):"e"==r&&"e"!=v.charAt(0)&&(v=l.type);switch(v=v||"n",e){case"SUM":S(v,g);break;case"PRODUCT":S(v,x);break;case"MIN":S(v,c||0);break;case"MAX":S(v,n||0);break;case"COUNT":S("n",b);break;case"COUNTA":S("n",y);break;case"COUNTBLANK":S("n",w);break;case"AVERAGE":b>0?S(v,g/b):S("e#DIV/0!",0);break;case"STDEV":b>1?S(v,Math.sqrt(d/(b-1))):S("e#DIV/0!",0);break;case"STDEVP":b>1?S(v,Math.sqrt(d/b)):S("e#DIV/0!",0);break;case"VAR":b>1?S(v,d/(b-1)):S("e#DIV/0!",0);break;case"VARP":b>1?S(v,d/b):S("e#DIV/0!",0)}return null},SocialCalc.Formula.FunctionList.AVERAGE=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.COUNT=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.COUNTA=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.COUNTBLANK=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.MAX=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.MIN=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.PRODUCT=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.STDEV=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.STDEVP=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.SUM=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.VAR=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],SocialCalc.Formula.FunctionList.VARP=[SocialCalc.Formula.SeriesFunctions,-1,"vn",null,"stat"],
SocialCalc.Formula.SumProductFunction=function(e,t,o,a){for(var l,r=[],n=0,c=SocialCalc.Formula,s=0,d=0,u=function(e,o){t.push({type:e,value:o})};o.length>0;){if(l=c.TopOfStackValueAndType(a,o),"range"!=l.type)return void u("e#VALUE!",0);if(rangeinfo=c.DecodeRangeParts(a,l.value),s){if(s!=rangeinfo.ncols)return void u("e#VALUE!",0)}else s=rangeinfo.ncols;if(d){if(d!=rangeinfo.nrows)return void u("e#VALUE!",0)}else d=rangeinfo.nrows;for(i=0;i<rangeinfo.ncols;i++)for(j=0;j<rangeinfo.nrows;j++)k=i*rangeinfo.nrows+j,cellcr=SocialCalc.crToCoord(rangeinfo.col1num+i,rangeinfo.row1num+j),cell=rangeinfo.sheetdata.GetAssuredCell(cellcr),value="n"==cell.valuetype?cell.datavalue:0,r[k]=(r[k]||1)*value}for(i=0;i<r.length;i++)n+=r[i];u("n",n)},SocialCalc.Formula.FunctionList.SUMPRODUCT=[SocialCalc.Formula.SumProductFunction,-1,"rangen","","stat"],SocialCalc.Formula.DSeriesFunctions=function(e,t,o,a){var l,r,i,n,c,s,d,u,p,m,h,C,f,S,g,v,b,y,w,x,F,T,k,E,_,P,R=SocialCalc.Formula,L=(R.OperandValueAndType,R.LookupResultType),M=R.TypeLookupTable.plus,D=function(e,o){t.push({type:e,value:o})},l={},A=0,I="",N=0,O=0,U=0,B=1;if(i=R.TopOfStackValueAndType(a,o),n=R.OperandValueAndType(a,o),c=R.TopOfStackValueAndType(a,o),"range"!=i.type||"range"!=c.type)return R.FunctionArgsError(e,t);if(s=R.DecodeRangeParts(a,i.value),d=R.DecodeRangeParts(a,c.value),u=R.FieldToColnum(s.sheetdata,s.col1num,s.ncols,s.row1num,n.value,n.type),0>=u)return void D("e#VALUE!",0);for(p=s.col1num+u-1,S=[],m=0;m<d.ncols;m++){if(f=d.sheetdata.GetAssuredCell(SocialCalc.crToCoord(d.col1num+m,d.row1num)),criterianum=R.FieldToColnum(s.sheetdata,s.col1num,s.ncols,s.row1num,f.datavalue,f.valuetype),criterianum<=0)return void D("e#VALUE!",0);S.push(s.col1num+criterianum-1)}for(m=1;m<s.nrows;m++){g=!1;e:for(h=1;h<d.nrows;h++){for(C=0;C<d.ncols;C++)if(v=SocialCalc.crToCoord(d.col1num+C,d.row1num+h),f=d.sheetdata.GetAssuredCell(v),b=f.datavalue,("string"!=typeof b||0!=b.length)&&(y=S[C],w=SocialCalc.crToCoord(y,s.row1num+m),f=d.sheetdata.GetAssuredCell(w),!R.TestCriteria(f.datavalue,f.valuetype||"b",b)))continue e;g=!0;break e}g&&(r=SocialCalc.crToCoord(p,s.row1num+m),f=s.sheetdata.GetAssuredCell(r),l.value=f.datavalue,l.type=f.valuetype,x=l.type.charAt(0),"n"==x&&(N+=1),"b"!=x&&(O+=1),"b"==x&&(U+=1),"n"==x?(v1=l.value-0,A+=v1,B*=v1,F=void 0!=F?v1>F?v1:F:v1,T=void 0!=T?v1<T?v1:T:v1,1==N?(_=v1,P=0):(k=_+(v1-_)/N,E=P+(v1-_)*(v1-k),P=E,_=k),I=L(l.type,I||l.type,M)):"e"==x&&"e"!=I.charAt(0)&&(I=l.type))}switch(I=I||"n",e){case"DSUM":D(I,A);break;case"DPRODUCT":D(I,B);break;case"DMIN":D(I,T||0);break;case"DMAX":D(I,F||0);break;case"DCOUNT":D("n",N);break;case"DCOUNTA":D("n",O);break;case"DAVERAGE":N>0?D(I,A/N):D("e#DIV/0!",0);break;case"DSTDEV":N>1?D(I,Math.sqrt(E/(N-1))):D("e#DIV/0!",0);break;case"DSTDEVP":N>1?D(I,Math.sqrt(E/N)):D("e#DIV/0!",0);break;case"DVAR":N>1?D(I,E/(N-1)):D("e#DIV/0!",0);break;case"DVARP":N>1?D(I,E/N):D("e#DIV/0!",0);break;case"DGET":1==N?D(I,A):0==N?D("e#VALUE!",0):D("e#NUM!",0)}},SocialCalc.Formula.FunctionList.DAVERAGE=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DCOUNT=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DCOUNTA=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DGET=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DMAX=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DMIN=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DPRODUCT=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DSTDEV=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DSTDEVP=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DSUM=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DVAR=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FunctionList.DVARP=[SocialCalc.Formula.DSeriesFunctions,3,"dfunc","","stat"],SocialCalc.Formula.FieldToColnum=function(e,t,o,a,l,r){var i,n,c;if("n"==r.charAt(0))return i=l-0,0>=i||i>o?0:Math.floor(i);if("t"!=r.charAt(0))return 0;for(l=l?l.toLowerCase():"",i=0;o>i;i++)if(n=e.GetAssuredCell(SocialCalc.crToCoord(t+i,a)),c=n.datavalue,c=(c+"").toLowerCase(),c==l)return i+1;return 0},SocialCalc.Formula.LookupFunctions=function(e,t,o,a){var l,r,i,n,c,s,d,u,p,m,h,C,f,S,g,v,l,b=SocialCalc.Formula,y=b.OperandValueAndType,w=(b.LookupResultType,b.TypeLookupTable.plus,function(e,o){t.push({type:e,value:o})});if(l=y(a,o),"string"==typeof l.value&&(l.value=l.value.toLowerCase()),r=b.TopOfStackValueAndType(a,o),i=1,"MATCH"==e){if(o.length){if(i=b.OperandAsNumber(a,o),"n"!=i.type.charAt(0))return void w("e#VALUE!",0);if(o.length)return b.FunctionArgsError(e,t),0;i=i.value-0}}else{if(n=b.OperandAsNumber(a,o),"n"!=n.type.charAt(0))return void w("e#VALUE!",0);if(n=Math.floor(n.value),o.length){if(i=b.OperandAsNumber(a,o),"n"!=i.type.charAt(0))return void w("e#VALUE!",0);if(o.length)return b.FunctionArgsError(e,t),0;i=i.value?1:0}}if(l.type=l.type.charAt(0),"n"==l.type&&(l.value=l.value-0),"range"!=r.type)return b.FunctionArgsError(e,t),0;if(c=b.DecodeRangeParts(a,r.value,r.type),!c)return void w("e#REF!",0);if(s=0,d=0,u=0,p=0,"HLOOKUP"==e){if(u=1,n>c.nrows)return void w("e#REF!",0)}else if("VLOOKUP"==e){if(p=1,n>c.ncols)return void w("e#REF!",0)}else{if("MATCH"!=e)return b.FunctionArgsError(e,t),0;if(c.ncols>1){if(c.nrows>1)return void w("e#N/A",0);u=1}else p=1}if(1>n&&"MATCH"!=e)return w("e#VALUE!",0),0;for(;;){if(v=SocialCalc.crToCoord(c.col1num+s,c.row1num+d),f=c.sheetdata.GetAssuredCell(v),S=f.datavalue,g=f.valuetype?f.valuetype.charAt(0):"b","n"==g&&(S-=0),i){if("n"==l.type&&"n"==g){if(l.value==S)break;if(i>0&&l.value>S||0>i&&l.value<S)m=1,h=s,C=d;else if(m){m=2;break}}else if("t"==l.type&&"t"==g){if(S="string"==typeof S?S.toLowerCase():"",l.value==S)break;if(i>0&&l.value>S||0>i&&l.value<S)m=1,h=s,C=d;else if(m){m=2;break}}}else if("n"==l.type&&"n"==g){if(l.value==S)break}else if("t"==l.type&&"t"==g&&(S="string"==typeof S?S.toLowerCase():"",l.value==S))break;if(d+=p,s+=u,d>=c.nrows||s>=c.ncols){if(m){m=2;break}return void w("e#N/A",0)}}2==m&&(d=C,s=h),"MATCH"==e?(S=s+d+1,g="n"):(v=SocialCalc.crToCoord(c.col1num+s+("VLOOKUP"==e?n-1:0),c.row1num+d+("HLOOKUP"==e?n-1:0)),f=c.sheetdata.GetAssuredCell(v),S=f.datavalue,g=f.valuetype),w(g,S)},SocialCalc.Formula.FunctionList.HLOOKUP=[SocialCalc.Formula.LookupFunctions,-3,"hlookup","","lookup"],SocialCalc.Formula.FunctionList.MATCH=[SocialCalc.Formula.LookupFunctions,-2,"match","","lookup"],SocialCalc.Formula.FunctionList.VLOOKUP=[SocialCalc.Formula.LookupFunctions,-3,"vlookup","","lookup"],SocialCalc.Formula.IndexFunction=function(e,t,o,a){var l,r,i,n,c,s,d,u=SocialCalc.Formula,p=function(e,o){t.push({type:e,value:o})};if(l=u.TopOfStackValueAndType(a,o),"range"!=l.type)return u.FunctionArgsError(e,t),0;if(i=u.DecodeRangeParts(a,l.value,l.type),r=i.sheetname?"!"+i.sheetname:"",n={value:0},c={value:0},o.length){if(n=u.OperandAsNumber(a,o),"n"!=n.type.charAt(0)||n.value<0)return void p("e#VALUE!",0);if(o.length){if(c=u.OperandAsNumber(a,o),"n"!=c.type.charAt(0)||c.value<0)return void p("e#VALUE!",0);if(o.length)return u.FunctionArgsError(e,t),0}else 1==i.nrows&&(c.value=n.value,n.value=0)}return n.value>i.nrows||c.value>i.ncols?void p("e#REF!",0):(0==n.value?0==c.value?1==i.nrows&&1==i.ncols?(s=SocialCalc.crToCoord(i.col1num,i.row1num)+r,d="coord"):(s=SocialCalc.crToCoord(i.col1num,i.row1num)+r+"|"+SocialCalc.crToCoord(i.col1num+i.ncols-1,i.row1num+i.nrows-1)+"|",d="range"):1==i.nrows?(s=SocialCalc.crToCoord(i.col1num+c.value-1,i.row1num)+r,d="coord"):(s=SocialCalc.crToCoord(i.col1num+c.value-1,i.row1num)+r+"|"+SocialCalc.crToCoord(i.col1num+c.value-1,i.row1num+i.nrows-1)+"|",d="range"):0==c.value?1==i.ncols?(s=SocialCalc.crToCoord(i.col1num,i.row1num+n.value-1)+r,d="coord"):(s=SocialCalc.crToCoord(i.col1num,i.row1num+n.value-1)+r+"|"+SocialCalc.crToCoord(i.col1num+i.ncols-1,i.row1num+n.value-1)+"|",d="range"):(s=SocialCalc.crToCoord(i.col1num+c.value-1,i.row1num+n.value-1)+r,d="coord"),void p(d,s))},SocialCalc.Formula.FunctionList.INDEX=[SocialCalc.Formula.IndexFunction,-1,"index","","lookup"],SocialCalc.Formula.CountifSumifFunctions=function(e,t,o,a){var l,r,i,n,c,s,d=0,u="",p=0,m=SocialCalc.Formula,h=m.OperandValueAndType,C=m.LookupResultType,f=m.TypeLookupTable.plus,S=function(e,o){t.push({type:e,value:o})};if(l=m.TopOfStackValueAndType(a,o),r=m.OperandAsText(a,o),"SUMIF"==e)if(1==o.length)i=m.TopOfStackValueAndType(a,o);else{if(0!=o.length)return m.FunctionArgsError(e,t),0;i={value:l.value,type:l.type}}else i={value:l.value,type:l.type};if("n"==r.type.charAt(0)?r.value=r.value+"":"e"==r.type.charAt(0)?r.value=null:"b"==r.type.charAt(0)&&(r.value=null),"coord"!=l.type&&"range"!=l.type)return m.FunctionArgsError(e,t),0;if("SUMIF"==e&&"coord"!=i.type&&"range"!=i.type)return m.FunctionArgsError(e,t),0;for(o.push(l),n=[],n.push(i);o.length;)c=h(a,o),s=h(a,n),m.TestCriteria(c.value,c.type,r.value)&&(p+=1,"n"==s.type.charAt(0)?(d+=s.value-0,u=C(s.type,u||s.type,f)):"e"==s.type.charAt(0)&&"e"!=u.charAt(0)&&(u=s.type));u=u||"n","SUMIF"==e?S(u,d):"COUNTIF"==e&&S("n",p)},SocialCalc.Formula.FunctionList.COUNTIF=[SocialCalc.Formula.CountifSumifFunctions,2,"rangec","","stat"],SocialCalc.Formula.FunctionList.SUMIF=[SocialCalc.Formula.CountifSumifFunctions,-2,"sumif","","stat"],SocialCalc.Formula.IfFunction=function(e,t,o,a){var l,r;if(l=SocialCalc.Formula.OperandValueAndType(a,o),r=l.type.charAt(0),"n"!=r&&"b"!=r)return void t.push({type:"e#VALUE!",value:0});var i,n;if(i=o.pop(),1==o.length)n=o.pop();else{if(0!=o.length)return void scf.FunctionArgsError(e,t);n={type:"n",value:0}}t.push(l.value?i:n)},SocialCalc.Formula.FunctionList.IF=[SocialCalc.Formula.IfFunction,-2,"iffunc","","test"],SocialCalc.Formula.DateFunction=function(e,t,o,a){var l=SocialCalc.Formula,r=0,i=l.OperandAsNumber(a,o),n=l.OperandAsNumber(a,o),c=l.OperandAsNumber(a,o),s=l.LookupResultType(i.type,n.type,l.TypeLookupTable.twoargnumeric);s=l.LookupResultType(s,c.type,l.TypeLookupTable.twoargnumeric),"n"==s.charAt(0)&&(r=SocialCalc.FormatNumber.convert_date_gregorian_to_julian(Math.floor(i.value),Math.floor(n.value),Math.floor(c.value))-SocialCalc.FormatNumber.datevalues.julian_offset,s="nd"),l.PushOperand(t,s,r)},SocialCalc.Formula.FunctionList.DATE=[SocialCalc.Formula.DateFunction,3,"date","","datetime"],SocialCalc.Formula.TimeFunction=function(e,t,o,a){var l=SocialCalc.Formula,r=0,i=l.OperandAsNumber(a,o),n=l.OperandAsNumber(a,o),c=l.OperandAsNumber(a,o),s=l.LookupResultType(i.type,n.type,l.TypeLookupTable.twoargnumeric);s=l.LookupResultType(s,c.type,l.TypeLookupTable.twoargnumeric),"n"==s.charAt(0)&&(r=(60*i.value*60+60*n.value+c.value)/86400,s="nt"),l.PushOperand(t,s,r)},SocialCalc.Formula.FunctionList.TIME=[SocialCalc.Formula.TimeFunction,3,"hms","","datetime"],SocialCalc.Formula.DMYFunctions=function(e,t,o,a){var l,r,i,n=SocialCalc.Formula,c=0,s=n.OperandAsNumber(a,o),d=n.LookupResultType(s.type,s.type,n.TypeLookupTable.oneargnumeric);if("n"==d.charAt(0))switch(l=SocialCalc.FormatNumber.convert_date_julian_to_gregorian(Math.floor(s.value+SocialCalc.FormatNumber.datevalues.julian_offset)),e){case"DAY":c=l.day;break;case"MONTH":c=l.month;break;case"YEAR":c=l.year;break;case"WEEKDAY":if(r={value:1},o.length){if(r=n.OperandAsNumber(a,o),"n"!=r.type.charAt(0)||r.value<1||r.value>3)return void n.PushOperand(t,"e#VALUE!",0);if(o.length)return void n.FunctionArgsError(e,t)}i=6,r.value>1&&(i-=1),c=Math.floor(s.value+i)%7+(r.value<3?1:0)}n.PushOperand(t,d,c)},SocialCalc.Formula.FunctionList.DAY=[SocialCalc.Formula.DMYFunctions,1,"v","","datetime"],SocialCalc.Formula.FunctionList.MONTH=[SocialCalc.Formula.DMYFunctions,1,"v","","datetime"],SocialCalc.Formula.FunctionList.YEAR=[SocialCalc.Formula.DMYFunctions,1,"v","","datetime"],SocialCalc.Formula.FunctionList.WEEKDAY=[SocialCalc.Formula.DMYFunctions,-1,"weekday","","datetime"],SocialCalc.Formula.HMSFunctions=function(e,t,o,a){var l,r,i,n,c=SocialCalc.Formula,s=0,d=c.OperandAsNumber(a,o),u=c.LookupResultType(d.type,d.type,c.TypeLookupTable.oneargnumeric);if("n"==u.charAt(0)){if(d.value<0)return void c.PushOperand(t,"e#NUM!",0);n=d.value-Math.floor(d.value),n*=24,l=Math.floor(n),n-=Math.floor(n),n*=60,r=Math.floor(n),n-=Math.floor(n),n*=60,i=Math.floor(n+(d.value>=0?.5:-.5)),"HOUR"==e?s=l:"MINUTE"==e?s=r:"SECOND"==e&&(s=i)}c.PushOperand(t,u,s)},SocialCalc.Formula.FunctionList.HOUR=[SocialCalc.Formula.HMSFunctions,1,"v","","datetime"],SocialCalc.Formula.FunctionList.MINUTE=[SocialCalc.Formula.HMSFunctions,1,"v","","datetime"],SocialCalc.Formula.FunctionList.SECOND=[SocialCalc.Formula.HMSFunctions,1,"v","","datetime"],SocialCalc.Formula.ExactFunction=function(e,t,o,a){var l=SocialCalc.Formula,r=0,i="nl",n=l.OperandValueAndType(a,o),c=n.type.charAt(0),s=l.OperandValueAndType(a,o),d=s.type.charAt(0);"t"==c?"t"==d?r=n.value==s.value?1:0:"b"==d?r=n.value.length?0:1:"n"==d?r=n.value==s.value+""?1:0:"e"==d?(r=s.value,i=s.type):r=0:"n"==c?"n"==d?r=n.value-0==s.value-0?1:0:"b"==d?r=0:"t"==d?r=n.value+""==s.value?1:0:"e"==d?(r=s.value,i=s.type):r=0:"b"==c?"t"==d?r=s.value.length?0:1:"b"==d?r=1:"n"==d?r=0:"e"==d?(r=s.value,i=s.type):r=0:"e"==c&&(r=n.value,i=n.type),l.PushOperand(t,i,r)},SocialCalc.Formula.FunctionList.EXACT=[SocialCalc.Formula.ExactFunction,2,"","","text"],SocialCalc.Formula.ArgList={FIND:[1,1,0],LEFT:[1,0],LEN:[1],LOWER:[1],MID:[1,0,0],PROPER:[1],REPLACE:[1,0,0,1],REPT:[1,0],RIGHT:[1,0],SUBSTITUTE:[1,1,1,0],TRIM:[1],UPPER:[1]},SocialCalc.Formula.StringFunctions=function(e,t,o,a){var l,r,i,n,c,s,d=SocialCalc.Formula,u=0,p="e#VALUE!",m=o.length,h=d.ArgList[e],C=[],f=[];for(l=1;m>=l;l++){if(l>h.length)return void d.FunctionArgsError(e,t);if(0==h[l-1]?r=d.OperandAsNumber(a,o):1==h[l-1]?r=d.OperandAsText(a,o):-1==h[l-1]&&(r=d.OperandValueAndType(a,o)),C[l]=r.value,f[l]=r.type,"e"==r.type.charAt(0))return void d.PushOperand(t,r.type,u)}switch(e){case"FIND":i=f[3]?C[3]-1:0,0>i?u="Start is before string":(u=C[2].indexOf(C[1],i),u>=0?(u+=1,p="n"):u="Not found");break;case"LEFT":n=f[2]?C[2]-0:1,0>n?u="Negative length":(u=C[1].substring(0,n),p="t");break;case"LEN":u=C[1].length,p="n";break;case"LOWER":u=C[1].toLowerCase(),p="t";break;case"MID":c=C[2]-0,n=C[3]-0,1>n||1>c?u="Bad arguments":(u=C[1].substring(c-1,c+n-1),p="t");break;case"PROPER":u=C[1].replace(/\b\w+\b/g,function(e){return e.substring(0,1).toUpperCase()+e.substring(1)}),p="t";break;case"REPLACE":c=C[2]-0,n=C[3]-0,0>n||1>c?u="Bad arguments":(u=C[1].substring(0,c-1)+C[4]+C[1].substring(c-1+n),p="t");break;case"REPT":if(s=C[2]-0,0>s)u="Negative count";else{for(u="";s>0;s--)u+=C[1];p="t"}break;case"RIGHT":n=f[2]?C[2]-0:1,0>n?u="Negative length":(u=C[1].slice(-n),p="t");break;case"SUBSTITUTE":if(fulltext=C[1],oldtext=C[2],newtext=C[3],null!=C[4]){if(which=C[4]-0,which<=0){u="Non-positive instance number";break}}else which=0;for(s=0,oldpos=0,u="";;){if(pos=fulltext.indexOf(oldtext,oldpos),!(pos>=0)){u+=fulltext.substring(oldpos);break}if(s++,u+=fulltext.substring(oldpos,pos),0==which)u+=newtext;else{if(which==s){u+=newtext+fulltext.substring(pos+oldtext.length);break}u+=oldtext}oldpos=pos+oldtext.length}p="t";break;case"TRIM":u=C[1],u=u.replace(/^ */,""),u=u.replace(/ *$/,""),u=u.replace(/ +/g," "),p="t";break;case"UPPER":u=C[1].toUpperCase(),p="t"}d.PushOperand(t,p,u)},SocialCalc.Formula.FunctionList.FIND=[SocialCalc.Formula.StringFunctions,-2,"find","","text"],SocialCalc.Formula.FunctionList.LEFT=[SocialCalc.Formula.StringFunctions,-2,"tc","","text"],SocialCalc.Formula.FunctionList.LEN=[SocialCalc.Formula.StringFunctions,1,"txt","","text"],SocialCalc.Formula.FunctionList.LOWER=[SocialCalc.Formula.StringFunctions,1,"txt","","text"],SocialCalc.Formula.FunctionList.MID=[SocialCalc.Formula.StringFunctions,3,"mid","","text"],SocialCalc.Formula.FunctionList.PROPER=[SocialCalc.Formula.StringFunctions,1,"v","","text"],SocialCalc.Formula.FunctionList.REPLACE=[SocialCalc.Formula.StringFunctions,4,"replace","","text"],SocialCalc.Formula.FunctionList.REPT=[SocialCalc.Formula.StringFunctions,2,"tc","","text"],SocialCalc.Formula.FunctionList.RIGHT=[SocialCalc.Formula.StringFunctions,-1,"tc","","text"],SocialCalc.Formula.FunctionList.SUBSTITUTE=[SocialCalc.Formula.StringFunctions,-3,"subs","","text"],SocialCalc.Formula.FunctionList.TRIM=[SocialCalc.Formula.StringFunctions,1,"v","","text"],SocialCalc.Formula.FunctionList.UPPER=[SocialCalc.Formula.StringFunctions,1,"v","","text"],SocialCalc.Formula.IsFunctions=function(e,t,o,a){var l=SocialCalc.Formula,r=0,i="nl",n=l.OperandValueAndType(a,o),c=n.type.charAt(0);switch(e){case"ISBLANK":r="b"==n.type?1:0;break;case"ISERR":r="e"==c?"e#N/A"==n.type?0:1:0;break;case"ISERROR":r="e"==c?1:0;break;case"ISLOGICAL":r="nl"==n.type?1:0;break;case"ISNA":r="e#N/A"==n.type?1:0;break;case"ISNONTEXT":r="t"==c?0:1;break;case"ISNUMBER":r="n"==c?1:0;break;case"ISTEXT":r="t"==c?1:0}l.PushOperand(t,i,r)},SocialCalc.Formula.FunctionList.ISBLANK=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.FunctionList.ISERR=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.FunctionList.ISERROR=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.FunctionList.ISLOGICAL=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.FunctionList.ISNA=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.FunctionList.ISNONTEXT=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.FunctionList.ISNUMBER=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.FunctionList.ISTEXT=[SocialCalc.Formula.IsFunctions,1,"v","","test"],SocialCalc.Formula.NTVFunctions=function(e,t,o,a){var l=SocialCalc.Formula,r=0,i="e#VALUE!",n=l.OperandValueAndType(a,o),c=n.type.charAt(0);switch(e){case"N":r="n"==c?n.value-0:0,i="n";break;case"T":r="t"==c?n.value+"":"",i="t";break;case"VALUE":"n"==c||"b"==c?(r=n.value||0,i="n"):"t"==c&&(n=SocialCalc.DetermineValueType(n.value),"n"!=n.type.charAt(0)?(r=0,i="e#VALUE!"):(r=n.value-0,i="n"))}"e"==c&&(i=n.type),l.PushOperand(t,i,r)},SocialCalc.Formula.FunctionList.N=[SocialCalc.Formula.NTVFunctions,1,"v","","math"],SocialCalc.Formula.FunctionList.T=[SocialCalc.Formula.NTVFunctions,1,"v","","text"],SocialCalc.Formula.FunctionList.VALUE=[SocialCalc.Formula.NTVFunctions,1,"v","","text"],SocialCalc.Formula.Math1Functions=function(e,t,o,a){var l,r,i,n={},c=SocialCalc.Formula;if(l=c.OperandAsNumber(a,o),r=l.value,n.type=c.LookupResultType(l.type,l.type,c.TypeLookupTable.oneargnumeric),"n"==n.type)switch(e){case"ABS":r=Math.abs(r);break;case"ACOS":r>=-1&&1>=r?r=Math.acos(r):n.type="e#NUM!";break;case"ASIN":r>=-1&&1>=r?r=Math.asin(r):n.type="e#NUM!";break;case"ATAN":r=Math.atan(r);break;case"COS":r=Math.cos(r);break;case"DEGREES":r=180*r/Math.PI;break;case"EVEN":r=0>r?-r:r,r!=Math.floor(r)?r=Math.floor(r+1)+Math.floor(r+1)%2:r+=r%2,l.value<0&&(r=-r);break;case"EXP":r=Math.exp(r);break;case"FACT":for(i=1,r=Math.floor(r);r>0;r--)i*=r;r=i;break;case"INT":r=Math.floor(r);break;case"LN":0>=r&&(n.type="e#NUM!",n.error=SocialCalc.Constants.s_sheetfunclnarg),r=Math.log(r);break;case"LOG10":0>=r&&(n.type="e#NUM!",n.error=SocialCalc.Constants.s_sheetfunclog10arg),r=Math.log(r)/Math.log(10);break;case"ODD":r=0>r?-r:r,r!=Math.floor(r)?r=Math.floor(r+1)+(1-Math.floor(r+1)%2):r+=1-r%2,l.value<0&&(r=-r);break;case"RADIANS":r=r*Math.PI/180;break;case"SIN":r=Math.sin(r);break;case"SQRT":r>=0?r=Math.sqrt(r):n.type="e#NUM!";break;case"TAN":0!=Math.cos(r)?r=Math.tan(r):n.type="e#NUM!"}return n.value=r,t.push(n),null},SocialCalc.Formula.FunctionList.ABS=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.ACOS=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.ASIN=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.ATAN=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.COS=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.DEGREES=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.EVEN=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.EXP=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.FACT=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.INT=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.LN=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.LOG10=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.ODD=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.RADIANS=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.SIN=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.SQRT=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.FunctionList.TAN=[SocialCalc.Formula.Math1Functions,1,"v","","math"],SocialCalc.Formula.Math2Functions=function(e,t,o,a){var l,r,i,n,c,s,d={},u=SocialCalc.Formula;if(l=u.OperandAsNumber(a,o),r=u.OperandAsNumber(a,o),i=0,d.type=u.LookupResultType(l.type,r.type,u.TypeLookupTable.twoargnumeric),"n"==d.type)switch(e){case"ATAN2":0==l.value&&0==r.value?d.type="e#DIV/0!":d.value=Math.atan2(r.value,l.value);break;case"POWER":d.value=Math.pow(l.value,r.value),isNaN(d.value)&&(d.value=0,d.type="e#NUM!");break;case"MOD":0==r.value?d.type="e#DIV/0!":(n=l.value/r.value,n=Math.floor(n),d.value=l.value-n*r.value);break;case"TRUNC":if(c=1,r.value>=0){for(r.value=Math.floor(r.value),s=0;s<r.value;s++)c*=10;d.value=Math.floor(Math.abs(l.value)*c)/c}else if(r.value<0){for(r.value=Math.floor(-r.value),s=0;s<r.value;s++)c*=10;d.value=Math.floor(Math.abs(l.value)/c)*c}l.value<0&&(d.value=-d.value)}return t.push(d),null},SocialCalc.Formula.FunctionList.ATAN2=[SocialCalc.Formula.Math2Functions,2,"xy","","math"],SocialCalc.Formula.FunctionList.MOD=[SocialCalc.Formula.Math2Functions,2,"","","math"],SocialCalc.Formula.FunctionList.POWER=[SocialCalc.Formula.Math2Functions,2,"","","math"],SocialCalc.Formula.FunctionList.TRUNC=[SocialCalc.Formula.Math2Functions,2,"valpre","","math"],SocialCalc.Formula.LogFunction=function(e,t,o,a){var l,r,i={},n=SocialCalc.Formula;if(i.value=0,l=n.OperandAsNumber(a,o),i.type=n.LookupResultType(l.type,l.type,n.TypeLookupTable.oneargnumeric),1==o.length){if(r=n.OperandAsNumber(a,o),"n"!=r.type.charAt(0)||r.value<=0)return n.FunctionSpecificError(e,t,"e#NUM!",SocialCalc.Constants.s_sheetfunclogsecondarg),0}else{if(0!=o.length)return n.FunctionArgsError(e,t),0;r={value:Math.E,type:"n"}}if("n"==i.type){if(l.value<=0)return n.FunctionSpecificError(e,t,"e#NUM!",SocialCalc.Constants.s_sheetfunclogfirstarg),0;i.value=Math.log(l.value)/Math.log(r.value)}t.push(i)},SocialCalc.Formula.FunctionList.LOG=[SocialCalc.Formula.LogFunction,-1,"log","","math"],SocialCalc.Formula.RoundFunction=function(e,t,o,a){var l,r,i,n,c=SocialCalc.Formula,s=0,d="e#VALUE!",u=c.OperandValueAndType(a,o),d=c.LookupResultType(u.type,u.type,c.TypeLookupTable.oneargnumeric);if(1==o.length){if(l=c.OperandValueAndType(a,o),"n"!=l.type.charAt(0))return c.FunctionSpecificError(e,t,"e#NUM!",SocialCalc.Constants.s_sheetfuncroundsecondarg),0}else{if(0!=o.length)return c.FunctionArgsError(e,t),0;l={value:0,type:"n"}}if("n"==d)if(l.value=l.value-0,0==l.value)s=Math.round(u.value);else if(l.value>0){for(r=1,l.value=Math.floor(l.value),n=0;n<l.value;n++)r*=10;i=Math.round(u.value*r),s=i/r}else if(l.value<0){for(r=1,l.value=Math.floor(-l.value),n=0;n<l.value;n++)r*=10;i=Math.round(u.value/r),s=i*r}c.PushOperand(t,d,s)},SocialCalc.Formula.FunctionList.ROUND=[SocialCalc.Formula.RoundFunction,-1,"vp","","math"],SocialCalc.Formula.CeilingFloorFunctions=function(e,t,o,a){var l,r,i,n=SocialCalc.Formula,c=function(e,o){t.push({type:e,value:o})};if(l=n.OperandValueAndType(a,o),i=l.type.charAt(0),"n"!=i)return void c("e#VALUE!",0);if(0==l.value)return void c("n",0);if(1==o.length){if(r=n.OperandValueAndType(a,o),i=l.type.charAt(0),"n"!=i)return void c("e#VALUE!",0)}else{if(0!=o.length)return void c("e#VALUE!",0);r={type:"n",value:l.value>0?1:-1}}if(0==r.value)return void c("n",0);if(r.value*l.value<0)return void c("e#NUM!",0);switch(e){case"CEILING":c("n",Math.ceil(l.value/r.value)*r.value);break;case"FLOOR":c("n",Math.floor(l.value/r.value)*r.value)}},SocialCalc.Formula.FunctionList.CEILING=[SocialCalc.Formula.CeilingFloorFunctions,-1,"vsig","","math"],SocialCalc.Formula.FunctionList.FLOOR=[SocialCalc.Formula.CeilingFloorFunctions,-1,"vsig","","math"],SocialCalc.Formula.AndOrFunctions=function(e,t,o,a){var l,r,i=SocialCalc.Formula,n="";for("AND"==e?r=1:"OR"==e&&(r=0);o.length;)l=i.OperandValueAndType(a,o),"n"==l.type.charAt(0)?(l.value=l.value-0,"AND"==e?r=0!=l.value?r:0:"OR"==e&&(r=0!=l.value?1:r),n=i.LookupResultType(l.type,n||"nl",i.TypeLookupTable.propagateerror)):"e"==l.type.charAt(0)&&"e"!=n.charAt(0)&&(n=l.type);n.length<1&&(n="e#VALUE!",r=0),i.PushOperand(t,n,r)},SocialCalc.Formula.FunctionList.AND=[SocialCalc.Formula.AndOrFunctions,-1,"vn","","test"],SocialCalc.Formula.FunctionList.OR=[SocialCalc.Formula.AndOrFunctions,-1,"vn","","test"],SocialCalc.Formula.NotFunction=function(e,t,o,a){var l=0,r=SocialCalc.Formula,i=r.OperandValueAndType(a,o),n=r.LookupResultType(i.type,i.type,r.TypeLookupTable.propagateerror);"n"==i.type.charAt(0)||"b"==i.type?(l=i.value-0!=0?0:1,n="nl"):"t"==i.type.charAt(0)&&(n="e#VALUE!"),r.PushOperand(t,n,l)},SocialCalc.Formula.FunctionList.NOT=[SocialCalc.Formula.NotFunction,1,"v","","test"],SocialCalc.Formula.ChooseFunction=function(e,t,o,a){var l,r,i,n=0,c=SocialCalc.Formula,s=c.OperandAsNumber(a,o);for("n"!=s.type.charAt(0)&&(s.value=0),s.value=Math.floor(s.value),r=0;o.length;)if(i=c.TopOfStackValueAndType(a,o),r+=1,s.value==r){n=i.value,l=i.type;break}l?c.PushOperand(t,l,n):c.PushOperand(t,"e#VALUE!",0)},SocialCalc.Formula.FunctionList.CHOOSE=[SocialCalc.Formula.ChooseFunction,-2,"choose","","lookup"],SocialCalc.Formula.ColumnsRowsFunctions=function(e,t,o,a){var l,r,i=0,n=SocialCalc.Formula,c=n.TopOfStackValueAndType(a,o);"coord"==c.type?(i=1,l="n"):"range"==c.type?(r=n.DecodeRangeParts(a,c.value),"COLUMNS"==e?i=r.ncols:"ROWS"==e&&(i=r.nrows),l="n"):(i=0,l="e#VALUE!"),n.PushOperand(t,l,i)},SocialCalc.Formula.FunctionList.COLUMNS=[SocialCalc.Formula.ColumnsRowsFunctions,1,"range","","lookup"],SocialCalc.Formula.FunctionList.ROWS=[SocialCalc.Formula.ColumnsRowsFunctions,1,"range","","lookup"],SocialCalc.Formula.ZeroArgFunctions=function(e,t,o,a){var l,r,i,n,c,s={value:0};switch(e){case"FALSE":s.type="nl",s.value=0;break;case"NA":s.type="e#N/A";break;case"NOW":l=new Date,r=l.getTimezoneOffset(),l=l.getTime()/1e3,i=25569,n=86400,c=i+l/n-r/1440,s.value=c,s.type="ndt",SocialCalc.Formula.FreshnessInfo["volatile"].NOW=!0;break;case"PI":s.type="n",s.value=Math.PI;break;case"TODAY":l=new Date,r=l.getTimezoneOffset(),l=l.getTime()/1e3,i=25569,n=86400,c=i+l/n-r/1440,s.value=Math.floor(c),s.type="nd",SocialCalc.Formula.FreshnessInfo["volatile"].TODAY=!0;break;case"TRUE":s.type="nl",s.value=1}return t.push(s),null},SocialCalc.Formula.FunctionList.FALSE=[SocialCalc.Formula.ZeroArgFunctions,0,"","","test"],SocialCalc.Formula.FunctionList.NA=[SocialCalc.Formula.ZeroArgFunctions,0,"","","test"],SocialCalc.Formula.FunctionList.NOW=[SocialCalc.Formula.ZeroArgFunctions,0,"","","datetime"],SocialCalc.Formula.FunctionList.PI=[SocialCalc.Formula.ZeroArgFunctions,0,"","","math"],SocialCalc.Formula.FunctionList.TODAY=[SocialCalc.Formula.ZeroArgFunctions,0,"","","datetime"],SocialCalc.Formula.FunctionList.TRUE=[SocialCalc.Formula.ZeroArgFunctions,0,"","","test"],SocialCalc.Formula.DDBFunction=function(e,t,o,a){var l,r,i,n,c=SocialCalc.Formula,s=c.OperandAsNumber(a,o),d=c.OperandAsNumber(a,o),u=c.OperandAsNumber(a,o),p=c.OperandAsNumber(a,o);if(!(c.CheckForErrorValue(t,s)||c.CheckForErrorValue(t,d)||c.CheckForErrorValue(t,u)||c.CheckForErrorValue(t,p))){if(u.value<1)return c.FunctionSpecificError(e,t,"e#NUM!",SocialCalc.Constants.s_sheetfuncddblife),0;if(l={value:2,type:"n"},o.length>0&&(l=c.OperandAsNumber(a,o)),0!=o.length)return c.FunctionArgsError(e,t),0;if(!c.CheckForErrorValue(t,l)){for(r=0,i=0,n=1;n<=p.value-0&&n<=u.value;n++)r=(s.value-i)*(l.value/u.value),s.value-i-r<d.value&&(r=s.value-i-d.value),i+=r;c.PushOperand(t,"n$",r)}}},SocialCalc.Formula.FunctionList.DDB=[SocialCalc.Formula.DDBFunction,-4,"ddb","","financial"],SocialCalc.Formula.SLNFunction=function(e,t,o,a){var l,r=SocialCalc.Formula,i=r.OperandAsNumber(a,o),n=r.OperandAsNumber(a,o),c=r.OperandAsNumber(a,o);if(!r.CheckForErrorValue(t,i)&&!r.CheckForErrorValue(t,n)&&!r.CheckForErrorValue(t,c)){if(c.value<1)return r.FunctionSpecificError(e,t,"e#NUM!",SocialCalc.Constants.s_sheetfuncslnlife),0;l=(i.value-n.value)/c.value,r.PushOperand(t,"n$",l)}},SocialCalc.Formula.FunctionList.SLN=[SocialCalc.Formula.SLNFunction,3,"csl","","financial"],SocialCalc.Formula.SYDFunction=function(e,t,o,a){var l,r,i=SocialCalc.Formula,n=i.OperandAsNumber(a,o),c=i.OperandAsNumber(a,o),s=i.OperandAsNumber(a,o),d=i.OperandAsNumber(a,o);if(!(i.CheckForErrorValue(t,n)||i.CheckForErrorValue(t,c)||i.CheckForErrorValue(t,s)||i.CheckForErrorValue(t,d))){if(s.value<1||d.value<=0)return i.PushOperand(t,"e#NUM!",0),0;r=(s.value+1)*s.value/2,l=(n.value-c.value)*(s.value-d.value+1)/r,i.PushOperand(t,"n$",l)}},SocialCalc.Formula.FunctionList.SYD=[SocialCalc.Formula.SYDFunction,4,"cslp","","financial"],SocialCalc.Formula.InterestFunctions=function(e,t,o,a){var l,r,i,n,c,s,d,u,p,m,h,C,f,S,g,v,b,y,w,x,u,F,T,k=SocialCalc.Formula,E=k.OperandAsNumber(a,o),_=k.OperandAsNumber(a,o),P=k.OperandAsNumber(a,o);if(l=k.LookupResultType(E.type,_.type,k.TypeLookupTable.twoargnumeric),l=k.LookupResultType(l,P.type,k.TypeLookupTable.twoargnumeric),o.length&&(i=k.OperandAsNumber(a,o),l=k.LookupResultType(l,i.type,k.TypeLookupTable.twoargnumeric),o.length&&(n=k.OperandAsNumber(a,o),l=k.LookupResultType(l,n.type,k.TypeLookupTable.twoargnumeric),o.length))){if("RATE"!=e)return k.FunctionArgsError(e,t),0;c=k.OperandAsNumber(a,o),l=k.LookupResultType(l,c.type,k.TypeLookupTable.twoargnumeric)}if("n"==l)switch(e){case"FV":u=E.value,p=_.value,m=P.value,s=null!=i?i.value:0,h=null!=n&&n.value?1:0,d=0==u?-s-m*p:-(s*Math.pow(1+u,p)+m*(1+u*h)*(Math.pow(1+u,p)-1)/u),r=d,l="n$";break;case"NPER":if(u=E.value,m=_.value,s=P.value,d=null!=i?i.value:0,h=null!=n&&n.value?1:0,0==u){if(0==m)return void k.PushOperand(t,"e#NUM!",0);p=(s+d)/-m}else{if(f=m*(1+u*h)/u,S=s+f,0==S||-1>=u)return void k.PushOperand(t,"e#NUM!",0);if(g=(f-d)/S,0>=g)return void k.PushOperand(t,"e#NUM!",0);v=Math.log(g),b=Math.log(1+u),p=v/b}r=p,l="n";break;case"PMT":if(u=E.value,p=_.value,s=P.value,d=null!=i?i.value:0,h=null!=n&&n.value?1:0,0==p)return void k.PushOperand(t,"e#NUM!",0);m=0==u?(d-s)/p:(0-d-s*Math.pow(1+u,p))/((1+u*h)*(Math.pow(1+u,p)-1)/u),r=m,l="n$";break;case"PV":if(u=E.value,p=_.value,m=P.value,d=null!=i?i.value:0,h=null!=n&&n.value?1:0,-1==u)return void k.PushOperand(t,"e#DIV/0!",0);s=0==u?-d-m*p:(-d-m*(1+u*h)*(Math.pow(1+u,p)-1)/u)/Math.pow(1+u,p),r=s,l="n$";break;case"RATE":for(p=E.value,m=_.value,s=P.value,d=null!=i?i.value:0,h=null!=n&&n.value?1:0,C=null!=c?c.value:.1,w=100,x=0,delta=1,epsilon=1e-7,u=C||1e-8;(delta>=0?delta:-delta)>epsilon&&u!=F;)if(delta=d+s*Math.pow(1+u,p)+m*(1+u*h)*(Math.pow(1+u,p)-1)/u,null!=y?(T=(delta-y)/(u-F)||.001,F=u,u-=delta/T,y=delta):(F=u,u=1.1*u,y=delta),x++,x>=w)return void k.PushOperand(t,"e#NUM!",0);r=u,l="n%"}k.PushOperand(t,l,r)},SocialCalc.Formula.FunctionList.FV=[SocialCalc.Formula.InterestFunctions,-3,"fv","","financial"],SocialCalc.Formula.FunctionList.NPER=[SocialCalc.Formula.InterestFunctions,-3,"nper","","financial"],SocialCalc.Formula.FunctionList.PMT=[SocialCalc.Formula.InterestFunctions,-3,"pmt","","financial"],
SocialCalc.Formula.FunctionList.PV=[SocialCalc.Formula.InterestFunctions,-3,"pv","","financial"],SocialCalc.Formula.FunctionList.RATE=[SocialCalc.Formula.InterestFunctions,-3,"rate","","financial"],SocialCalc.Formula.NPVFunction=function(e,t,o,a){var l,r,i,n,c,s=SocialCalc.Formula,r=s.OperandAsNumber(a,o);if(!s.CheckForErrorValue(t,r)){for(i=0,l="n",n=1;o.length;)if(c=s.OperandValueAndType(a,o),"n"==c.type.charAt(0)){if(n*=1+r.value,0==n)return void s.PushOperand(t,"e#DIV/0!",0);i+=c.value/n,l=s.LookupResultType(c.type,l||c.type,s.TypeLookupTable.plus)}else if("e"==c.type.charAt(0)&&"e"!=l.charAt(0)){l=c.type;break}"n"==l.charAt(0)&&(l="n$"),s.PushOperand(t,l,i)}},SocialCalc.Formula.FunctionList.NPV=[SocialCalc.Formula.NPVFunction,-2,"npv","","financial"],SocialCalc.Formula.IRRFunction=function(e,t,o,a){var l,r,i,n,c,s,d,u,p,m,h,C,f=[],S=[],g=SocialCalc.Formula;for(f.push(o.pop());f.length;)if(l=g.OperandValueAndType(a,f),"n"==l.type.charAt(0))S.push(l.value);else if("e"==l.type.charAt(0))return void g.PushOperand(t,"e#VALUE!",0);if(!S.length)return void g.PushOperand(t,"e#NUM!",0);if(r={value:0},o.length){if(r=g.OperandAsNumber(a,o),"n"!=r.type.charAt(0)&&"b"!=r.type.charAt(0))return void g.PushOperand(t,"e#VALUE!",0);if(o.length)return void g.FunctionArgsError(e,t)}for(r.value=r.value||.1,n=20,c=0,s=1e-7,d=r.value,m=1;(m>=0?m:-m)>s&&d!=u;){for(m=0,h=1,C=0;C<S.length;C++){if(h*=1+d,0==h)return void g.PushOperand(t,"e#DIV/0!",0);m+=S[C]/h}if(null!=i?(p=(m-i)/(d-u),u=d,d-=m/p,i=m):(u=d,d=1.1*d,i=m),c++,c>=n)return void g.PushOperand(t,"e#NUM!",0)}g.PushOperand(t,"n%",d)},SocialCalc.Formula.FunctionList.IRR=[SocialCalc.Formula.IRRFunction,-1,"irr","","financial"],SocialCalc.Formula.SheetCache={sheets:{},waitingForLoading:null,constants:{asloaded:0,recalcing:1,recalcdone:2},loadsheet:null},SocialCalc.Formula.FindInSheetCache=function(e){var t=SocialCalc.Formula.SheetCache,o=SocialCalc.Formula.NormalizeSheetName(e);return t.sheets[o]?t.sheets[o].sheet:t.waitingForLoading?null:t.loadsheet?(alert("Using SocialCalc.Formula.SheetCache.loadsheet - deprecated"),SocialCalc.Formula.AddSheetToCache(o,t.loadsheet(o))):(t.waitingForLoading=o,null)},SocialCalc.Formula.AddSheetToCache=function(e,t,o){var a=null,l=SocialCalc.Formula.SheetCache,r=l.constants,i=SocialCalc.Formula.NormalizeSheetName(e);return t&&(a=new SocialCalc.Sheet,a.ParseSheetSave(t)),l.sheets[i]={sheet:a,recalcstate:r.asloaded,name:i},SocialCalc.Formula.FreshnessInfo.sheets[i]="undefined"==typeof o||o===!1,a},SocialCalc.Formula.NormalizeSheetName=function(e){return SocialCalc.Callbacks.NormalizeSheetName?SocialCalc.Callbacks.NormalizeSheetName(e):e.toLowerCase()},SocialCalc.Formula.RemoteFunctionInfo={waitingForServer:null},SocialCalc.Formula.FreshnessInfo={sheets:{},"volatile":{},recalc_completed:!1},SocialCalc.Formula.FreshnessInfoReset=function(){var e=SocialCalc.Formula.FreshnessInfo,t=SocialCalc.Formula.SheetCache;for(var o in e.sheets)e.sheets[o]===!1&&delete t.sheets[o];e.sheets={},e["volatile"]={},e.recalc_completed=!1},SocialCalc.Formula.PlainCoord=function(e){return-1==e.indexOf("$")?e:e.replace(/\$/g,"")},SocialCalc.Formula.OrderRangeParts=function(e,t){var o,a,l={};return o=SocialCalc.coordToCr(e),a=SocialCalc.coordToCr(t),o.col>a.col?(l.c1=a.col,l.c2=o.col):(l.c1=o.col,l.c2=a.col),o.row>a.row?(l.r1=a.row,l.r2=o.row):(l.r1=o.row,l.r2=a.row),l},SocialCalc.Formula.TestCriteria=function(e,t,o){var a,l,r,i,n;if(null==o)return!1;if(o+="",a=o.charAt(0),"="==a||"<"==a||">"==a?l=o.substring(1):(a=o.substring(0,2),"<="==a||"<>"==a||">="==a?l=o.substring(2):(a="none",l=o)),r=SocialCalc.DetermineValueType(l),!r.type){if("none"==a)return!1;if("b"==t.charAt(0)){if("="==a)return!0}else if("<>"==a)return!0;return!1}if(i=!1,"n"==r.type.charAt(0)&&"t"==t.charAt(0)&&(n=SocialCalc.DetermineValueType(e),"n"==n.type.charAt(0)&&(e=n.value,t=n.type)),"n"==t.charAt(0)&&"n"==r.type.charAt(0))switch(e-=0,r.value=r.value-0,a){case"<":i=e<r.value;break;case"<=":i=e<=r.value;break;case"=":case"none":i=e==r.value;break;case">=":i=e>=r.value;break;case">":i=e>r.value;break;case"<>":i=e!=r.value}else if("e"==t.charAt(0))i=!1;else if("e"==r.type.charAt(0))i=!1;else{if("n"==t.charAt(0)&&(e=SocialCalc.format_number_for_display(e,"n","")),"n"==r.type.charAt(0))return!1;switch(e=e?e.toLowerCase():"",r.value=r.value?r.value.toLowerCase():"",a){case"<":i=e<r.value;break;case"<=":i=e<=r.value;break;case"=":i=e==r.value;break;case"none":i=e.substring(0,r.value.length)==r.value;break;case">=":i=e>=r.value;break;case">":i=e>r.value;break;case"<>":i=e!=r.value}}return i};var SocialCalc;SocialCalc||(SocialCalc={}),SocialCalc.Callbacks={expand_wiki:null,expand_markup:function(e,t,o){return SocialCalc.default_expand_markup(e,t,o)},MakePageLink:null,NormalizeSheetName:null},SocialCalc.Cell=function(e){this.coord=e,this.datavalue="",this.datatype=null,this.formula="",this.valuetype="b",this.readonly=!1},SocialCalc.CellProperties={coord:1,datavalue:1,datatype:1,formula:1,valuetype:1,errors:1,comment:1,readonly:1,bt:2,br:2,bb:2,bl:2,layout:2,font:2,color:2,bgcolor:2,cellformat:2,nontextvalueformat:2,textvalueformat:2,colspan:2,rowspan:2,cssc:2,csss:2,mod:2,displaystring:3,parseinfo:3,hcolspan:3,hrowspan:3},SocialCalc.CellPropertiesTable={bt:"borderstyle",br:"borderstyle",bb:"borderstyle",bl:"borderstyle",layout:"layout",font:"font",color:"color",bgcolor:"color",cellformat:"cellformat",nontextvalueformat:"valueformat",textvalueformat:"valueformat"},SocialCalc.Sheet=function(){SocialCalc.ResetSheet(this),this.statuscallback=null,this.statuscallbackparams=null},SocialCalc.ResetSheet=function(e,t){e.cells={},e.attribs={lastcol:1,lastrow:1,defaultlayout:0,usermaxcol:0,usermaxrow:0},e.rowattribs={hide:{},height:{}},e.colattribs={width:{},hide:{}},e.names={},e.layouts=[],e.layouthash={},e.fonts=[],e.fonthash={},e.colors=[],e.colorhash={},e.borderstyles=[],e.borderstylehash={},e.cellformats=[],e.cellformathash={},e.valueformats=[],e.valueformathash={},e.copiedfrom="",e.changes=new SocialCalc.UndoStack,e.renderneeded=!1,e.changedrendervalues=!0,e.recalcchangedavalue=!1,e.hiddencolrow="",e.sci=new SocialCalc.SheetCommandInfo(e)},SocialCalc.Sheet.prototype.ResetSheet=function(){SocialCalc.ResetSheet(this)},SocialCalc.Sheet.prototype.AddCell=function(e){return this.cells[e.coord]=e},SocialCalc.Sheet.prototype.GetAssuredCell=function(e){return this.cells[e]||this.AddCell(new SocialCalc.Cell(e))},SocialCalc.Sheet.prototype.ParseSheetSave=function(e){SocialCalc.ParseSheetSave(e,this)},SocialCalc.Sheet.prototype.CellFromStringParts=function(e,t,o){return SocialCalc.CellFromStringParts(this,e,t,o)},SocialCalc.Sheet.prototype.CreateSheetSave=function(e,t){return SocialCalc.CreateSheetSave(this,e,t)},SocialCalc.Sheet.prototype.CellToString=function(e){return SocialCalc.CellToString(this,e)},SocialCalc.Sheet.prototype.CanonicalizeSheet=function(e){return SocialCalc.CanonicalizeSheet(this,e)},SocialCalc.Sheet.prototype.EncodeCellAttributes=function(e){return SocialCalc.EncodeCellAttributes(this,e)},SocialCalc.Sheet.prototype.EncodeSheetAttributes=function(){return SocialCalc.EncodeSheetAttributes(this)},SocialCalc.Sheet.prototype.DecodeCellAttributes=function(e,t,o){return SocialCalc.DecodeCellAttributes(this,e,t,o)},SocialCalc.Sheet.prototype.DecodeSheetAttributes=function(e){return SocialCalc.DecodeSheetAttributes(this,e)},SocialCalc.Sheet.prototype.ScheduleSheetCommands=function(e,t){return SocialCalc.ScheduleSheetCommands(this,e,t)},SocialCalc.Sheet.prototype.SheetUndo=function(){return SocialCalc.SheetUndo(this)},SocialCalc.Sheet.prototype.SheetRedo=function(){return SocialCalc.SheetRedo(this)},SocialCalc.Sheet.prototype.CreateAuditString=function(){return SocialCalc.CreateAuditString(this)},SocialCalc.Sheet.prototype.GetStyleNum=function(e,t){return SocialCalc.GetStyleNum(this,e,t)},SocialCalc.Sheet.prototype.GetStyleString=function(e,t){return SocialCalc.GetStyleString(this,e,t)},SocialCalc.Sheet.prototype.RecalcSheet=function(){return SocialCalc.RecalcSheet(this)},SocialCalc.ParseSheetSave=function(e,t){var o,a,l,r,i,n,c,s,d,u=e.split(/\r\n|\n/),p=[],m=SocialCalc.Constants;for(a=0;a<u.length;a++){switch(o=u[a],p=o.split(":"),p[0]){case"cell":c=t.GetAssuredCell(p[1]),l=2,t.CellFromStringParts(c,p,l);break;case"col":for(n=p[1],l=2;r=p[l++];)switch(r){case"w":t.colattribs.width[n]=p[l++];break;case"hide":t.colattribs.hide[n]=p[l++];break;default:throw m.s_pssUnknownColType+" '"+r+"'"}break;case"row":for(n=p[1]-0,l=2;r=p[l++];)switch(r){case"h":t.rowattribs.height[n]=p[l++]-0;break;case"hide":t.rowattribs.hide[n]=p[l++];break;default:throw m.s_pssUnknownRowType+" '"+r+"'"}break;case"sheet":for(s=t.attribs,l=1;r=p[l++];)switch(r){case"c":s.lastcol=p[l++]-0;break;case"r":s.lastrow=p[l++]-0;break;case"w":s.defaultcolwidth=p[l++]+"";break;case"h":s.defaultrowheight=p[l++]-0;break;case"tf":s.defaulttextformat=p[l++]-0;break;case"ntf":s.defaultnontextformat=p[l++]-0;break;case"layout":s.defaultlayout=p[l++]-0;break;case"font":s.defaultfont=p[l++]-0;break;case"tvf":s.defaulttextvalueformat=p[l++]-0;break;case"ntvf":s.defaultnontextvalueformat=p[l++]-0;break;case"color":s.defaultcolor=p[l++]-0;break;case"bgcolor":s.defaultbgcolor=p[l++]-0;break;case"circularreferencecell":s.circularreferencecell=p[l++];break;case"recalc":s.recalc=p[l++];break;case"needsrecalc":s.needsrecalc=p[l++];break;case"usermaxcol":s.usermaxcol=p[l++]-0;break;case"usermaxrow":s.usermaxrow=p[l++]-0;break;default:l+=1}break;case"name":d=SocialCalc.decodeFromSave(p[1]).toUpperCase(),t.names[d]={desc:SocialCalc.decodeFromSave(p[2])},t.names[d].definition=SocialCalc.decodeFromSave(p[3]);break;case"layout":p=u[a].match(/^layout\:(\d+)\:(.+)$/),t.layouts[p[1]-0]=p[2],t.layouthash[p[2]]=p[1]-0;break;case"font":t.fonts[p[1]-0]=p[2],t.fonthash[p[2]]=p[1]-0;break;case"color":t.colors[p[1]-0]=p[2],t.colorhash[p[2]]=p[1]-0;break;case"border":t.borderstyles[p[1]-0]=p[2],t.borderstylehash[p[2]]=p[1]-0;break;case"cellformat":i=SocialCalc.decodeFromSave(p[2]),t.cellformats[p[1]-0]=i,t.cellformathash[i]=p[1]-0;break;case"valueformat":i=SocialCalc.decodeFromSave(p[2]),t.valueformats[p[1]-0]=i,t.valueformathash[i]=p[1]-0;break;case"version":break;case"copiedfrom":t.copiedfrom=p[1]+":"+p[2];break;case"clipboardrange":case"clipboard":break;case"":break;default:throw alert(m.s_pssUnknownLineType+" '"+p[0]+"'"),m.s_pssUnknownLineType+" '"+p[0]+"'"}p=null}},SocialCalc.CellFromStringParts=function(e,t,o,a){for(var t,l,r;l=o[a++];)switch(l){case"v":t.datavalue=SocialCalc.decodeFromSave(o[a++])-0,t.datatype="v",t.valuetype="n";break;case"t":t.datavalue=SocialCalc.decodeFromSave(o[a++]),t.datatype="t",t.valuetype=SocialCalc.Constants.textdatadefaulttype;break;case"vt":r=o[a++],t.valuetype=r,"n"==r.charAt(0)?(t.datatype="v",t.datavalue=SocialCalc.decodeFromSave(o[a++])-0):(t.datatype="t",t.datavalue=SocialCalc.decodeFromSave(o[a++]));break;case"vtf":r=o[a++],t.valuetype=r,"n"==r.charAt(0)?t.datavalue=SocialCalc.decodeFromSave(o[a++])-0:t.datavalue=SocialCalc.decodeFromSave(o[a++]),t.formula=SocialCalc.decodeFromSave(o[a++]),t.datatype="f";break;case"vtc":r=o[a++],t.valuetype=r,"n"==r.charAt(0)?t.datavalue=SocialCalc.decodeFromSave(o[a++])-0:t.datavalue=SocialCalc.decodeFromSave(o[a++]),t.formula=SocialCalc.decodeFromSave(o[a++]),t.datatype="c";break;case"ro":ro=SocialCalc.decodeFromSave(o[a++]),t.readonly="yes"==ro.toLowerCase();break;case"e":t.errors=SocialCalc.decodeFromSave(o[a++]);break;case"b":t.bt=o[a++]-0,t.br=o[a++]-0,t.bb=o[a++]-0,t.bl=o[a++]-0;break;case"l":t.layout=o[a++]-0;break;case"f":t.font=o[a++]-0;break;case"c":t.color=o[a++]-0;break;case"bg":t.bgcolor=o[a++]-0;break;case"cf":t.cellformat=o[a++]-0;break;case"ntvf":t.nontextvalueformat=o[a++]-0;break;case"tvf":t.textvalueformat=o[a++]-0;break;case"colspan":t.colspan=o[a++]-0;break;case"rowspan":t.rowspan=o[a++]-0;break;case"cssc":t.cssc=o[a++];break;case"csss":t.csss=SocialCalc.decodeFromSave(o[a++]);break;case"mod":a+=1;break;case"comment":t.comment=SocialCalc.decodeFromSave(o[a++]);break;default:throw SocialCalc.Constants.s_cfspUnknownCellType+" '"+l+"'"}},SocialCalc.sheetfields=["defaultrowheight","defaultcolwidth","circularreferencecell","recalc","needsrecalc","usermaxcol","usermaxrow"],SocialCalc.sheetfieldsshort=["h","w","circularreferencecell","recalc","needsrecalc","usermaxcol","usermaxrow"],SocialCalc.sheetfieldsxlat=["defaulttextformat","defaultnontextformat","defaulttextvalueformat","defaultnontextvalueformat","defaultcolor","defaultbgcolor","defaultfont","defaultlayout"],SocialCalc.sheetfieldsxlatshort=["tf","ntf","tvf","ntvf","color","bgcolor","font","layout"],SocialCalc.sheetfieldsxlatxlt=["cellformat","cellformat","valueformat","valueformat","color","color","font","layout"],SocialCalc.CreateSheetSave=function(e,t,o){var a,l,r,i,n,c,s,d,u,p,m,h=[];e.CanonicalizeSheet(o||SocialCalc.Constants.doCanonicalizeSheet);var C=e.xlt;for(m=t?SocialCalc.ParseRange(t):{cr1:{row:1,col:1},cr2:{row:C.maxrow,col:C.maxcol}},l=m.cr1,r=m.cr2,h.push("version:1.5"),i=l.row;i<=r.row;i++)for(n=l.col;n<=r.col;n++)c=SocialCalc.crToCoord(n,i),a=e.cells[c],a&&(s=e.CellToString(a),0!=s.length&&(s="cell:"+c+s,h.push(s)));for(n=1;n<=C.maxcol;n++)c=SocialCalc.rcColname(n),e.colattribs.width[c]&&h.push("col:"+c+":w:"+e.colattribs.width[c]),e.colattribs.hide[c]&&h.push("col:"+c+":hide:"+e.colattribs.hide[c]);for(i=1;i<=C.maxrow;i++)e.rowattribs.height[i]&&h.push("row:"+i+":h:"+e.rowattribs.height[i]),e.rowattribs.hide[i]&&h.push("row:"+i+":hide:"+e.rowattribs.hide[i]);for(s="sheet:c:"+C.maxcol+":r:"+C.maxrow,u=0;u<SocialCalc.sheetfields.length;u++)d=SocialCalc.encodeForSave(e.attribs[SocialCalc.sheetfields[u]]),d&&(s+=":"+SocialCalc.sheetfieldsshort[u]+":"+d);for(u=0;u<SocialCalc.sheetfieldsxlat.length;u++)d=e.attribs[SocialCalc.sheetfieldsxlat[u]],d&&(s+=":"+SocialCalc.sheetfieldsxlatshort[u]+":"+C[SocialCalc.sheetfieldsxlatxlt[u]+"sxlat"][d]);for(h.push(s),u=1;u<C.newborderstyles.length;u++)h.push("border:"+u+":"+C.newborderstyles[u]);for(u=1;u<C.newcellformats.length;u++)h.push("cellformat:"+u+":"+SocialCalc.encodeForSave(C.newcellformats[u]));for(u=1;u<C.newcolors.length;u++)h.push("color:"+u+":"+C.newcolors[u]);for(u=1;u<C.newfonts.length;u++)h.push("font:"+u+":"+C.newfonts[u]);for(u=1;u<C.newlayouts.length;u++)h.push("layout:"+u+":"+C.newlayouts[u]);for(u=1;u<C.newvalueformats.length;u++)h.push("valueformat:"+u+":"+SocialCalc.encodeForSave(C.newvalueformats[u]));for(u=0;u<C.namesorder.length;u++)p=C.namesorder[u],h.push("name:"+SocialCalc.encodeForSave(p).toUpperCase()+":"+SocialCalc.encodeForSave(e.names[p].desc)+":"+SocialCalc.encodeForSave(e.names[p].definition));return t&&h.push("copiedfrom:"+SocialCalc.crToCoord(l.col,l.row)+":"+SocialCalc.crToCoord(r.col,r.row)),h.push(""),delete e.xlt,h.join("\n")},SocialCalc.CellToString=function(e,t){var t,o,a,l,r,i,n,c,s;return o="",t?(a=SocialCalc.encodeForSave(t.datavalue),"v"==t.datatype?o+="n"==t.valuetype?":v:"+a:":vt:"+t.valuetype+":"+a:"t"==t.datatype?o+=t.valuetype==SocialCalc.Constants.textdatadefaulttype?":t:"+a:":vt:"+t.valuetype+":"+a:(l=SocialCalc.encodeForSave(t.formula),"f"==t.datatype?o+=":vtf:"+t.valuetype+":"+a+":"+l:"c"==t.datatype&&(o+=":vtc:"+t.valuetype+":"+a+":"+l)),t.readonly&&(o+=":ro:yes"),t.errors&&(o+=":e:"+SocialCalc.encodeForSave(t.errors)),r=t.bt||"",i=t.br||"",n=t.bb||"",c=t.bl||"",e.xlt?(s=e.xlt,(r||i||n||c)&&(o+=":b:"+s.borderstylesxlat[r||0]+":"+s.borderstylesxlat[i||0]+":"+s.borderstylesxlat[n||0]+":"+s.borderstylesxlat[c||0]),t.layout&&(o+=":l:"+s.layoutsxlat[t.layout]),t.font&&(o+=":f:"+s.fontsxlat[t.font]),t.color&&(o+=":c:"+s.colorsxlat[t.color]),t.bgcolor&&(o+=":bg:"+s.colorsxlat[t.bgcolor]),t.cellformat&&(o+=":cf:"+s.cellformatsxlat[t.cellformat]),t.textvalueformat&&(o+=":tvf:"+s.valueformatsxlat[t.textvalueformat]),t.nontextvalueformat&&(o+=":ntvf:"+s.valueformatsxlat[t.nontextvalueformat])):((r||i||n||c)&&(o+=":b:"+r+":"+i+":"+n+":"+c),t.layout&&(o+=":l:"+t.layout),t.font&&(o+=":f:"+t.font),t.color&&(o+=":c:"+t.color),t.bgcolor&&(o+=":bg:"+t.bgcolor),t.cellformat&&(o+=":cf:"+t.cellformat),t.textvalueformat&&(o+=":tvf:"+t.textvalueformat),t.nontextvalueformat&&(o+=":ntvf:"+t.nontextvalueformat)),t.colspan&&(o+=":colspan:"+t.colspan),t.rowspan&&(o+=":rowspan:"+t.rowspan),t.cssc&&(o+=":cssc:"+t.cssc),t.csss&&(o+=":csss:"+SocialCalc.encodeForSave(t.csss)),t.mod&&(o+=":mod:"+t.mod),t.comment&&(o+=":comment:"+SocialCalc.encodeForSave(t.comment)),o):o},SocialCalc.CanonicalizeSheet=function(e,t){var o,a,l,r,i,n,c,s,d,u,p,m,h,C=0,f=0,S=["borderstyle","cellformat","color","font","layout","valueformat"],g={};g.namesorder=[];for(c in e.names)g.namesorder.push(c);if(g.namesorder.sort(),!SocialCalc.Constants.doCanonicalizeSheet||!t){for(n=0;n<S.length;n++){for(c=S[n],g["new"+c+"s"]=e[c+"s"],o=e[c+"s"].length,d=new Array(o),d[0]="",m=1;o>m;m++)d[m]=m;g[c+"sxlat"]=d}return g.maxrow=e.attribs.lastrow,g.maxcol=e.attribs.lastcol,void(e.xlt=g)}for(n=0;n<S.length;n++)c=S[n],g[c+"sUsed"]={};var v=g.colorsUsed,b=g.borderstylesUsed,y=g.fontsUsed,w=g.layoutsUsed,x=g.cellformatsUsed,F=g.valueformatsUsed;for(a in e.cells)l=SocialCalc.coordToCr(a),r=e.cells[a],i=!1,r.valuetype&&"b"!=r.valuetype&&(i=!0),r.color&&(v[r.color]=1,i=!0),r.bgcolor&&(v[r.bgcolor]=1,i=!0),r.bt&&(b[r.bt]=1,i=!0),r.br&&(b[r.br]=1,i=!0),r.bb&&(b[r.bb]=1,i=!0),r.bl&&(b[r.bl]=1,i=!0),r.layout&&(w[r.layout]=1,i=!0),r.font&&(y[r.font]=1,i=!0),r.cellformat&&(x[r.cellformat]=1,i=!0),r.textvalueformat&&(F[r.textvalueformat]=1,i=!0),r.nontextvalueformat&&(F[r.nontextvalueformat]=1,i=!0),i&&(l.row>C&&(C=l.row),l.col>f&&(f=l.col));for(m=0;m<SocialCalc.sheetfieldsxlat.length;m++)h=e.attribs[SocialCalc.sheetfieldsxlat[m]],h&&(g[SocialCalc.sheetfieldsxlatxlt[m]+"sUsed"][h]=1);c={height:1,hide:1};for(h in c)for(l in e.rowattribs[h])l>C&&(C=l);c={hide:1,width:1};for(h in c)for(a in e.colattribs[h])l=SocialCalc.coordToCr(a+"1"),l.col>f&&(f=l.col);for(n=0;n<S.length;n++){c=S[n],s=[],u=g[c+"sUsed"];for(h in u)s.push(e[c+"s"][h]);for(s.sort(),s.unshift(""),d=[""],p=e[c+"hash"],m=1;m<s.length;m++)d[p[s[m]]]=m;g[c+"sxlat"]=d,g["new"+c+"s"]=s}g.maxrow=C||1,g.maxcol=f||1,e.xlt=g},SocialCalc.EncodeCellAttributes=function(e,t){var o,a,l,r={},i=function(e){r[e]={def:!0,val:""}},n=function(e){for(var t=0;t<e.length;t++)i(e[t])},c=function(e,t){r[e].def=!1,r[e].val=t||""},s=function(e,t){"*"!=t&&(r[e].def=!1,r[e].val=t)},d=e.GetAssuredCell(t);for(i("alignhoriz"),d.cellformat&&c("alignhoriz",e.cellformats[d.cellformat]),n(["alignvert","padtop","padright","padbottom","padleft"]),d.layout&&(parts=e.layouts[d.layout].match(/^padding:\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+);vertical-align:\s*(\S+);/),s("padtop",parts[1]),s("padright",parts[2]),s("padbottom",parts[3]),s("padleft",parts[4]),s("alignvert",parts[5])),n(["fontfamily","fontlook","fontsize"]),d.font&&(parts=e.fonts[d.font].match(/^(\*|\S+? \S+?) (\S+?) (\S.*)$/),s("fontfamily",parts[3]),s("fontsize",parts[2]),s("fontlook",parts[1])),i("textcolor"),d.color&&c("textcolor",e.colors[d.color]),i("bgcolor"),d.bgcolor&&c("bgcolor",e.colors[d.bgcolor]),n(["numberformat","textformat"]),d.nontextvalueformat&&c("numberformat",e.valueformats[d.nontextvalueformat]),d.textvalueformat&&c("textformat",e.valueformats[d.textvalueformat]),n(["colspan","rowspan"]),c("colspan",d.colspan||1),c("rowspan",d.rowspan||1),o=0;4>o;o++)a="trbl".charAt(o),l="b"+a,i(l),c(l,d[l]?e.borderstyles[d[l]]:""),i(l+"thickness"),i(l+"style"),i(l+"color"),d[l]&&(parts=e.borderstyles[d[l]].match(/(\S+)\s+(\S+)\s+(\S.+)/),c(l+"thickness",parts[1]),c(l+"style",parts[2]),c(l+"color",parts[3]));return n(["cssc","csss","mod"]),c("cssc",d.cssc||""),c("csss",d.csss||""),c("mod",d.mod||"n"),r},SocialCalc.EncodeSheetAttributes=function(e){var t,o=e.attribs,a={},l=function(e){a[e]={def:!0,val:""}},r=function(e){for(var t=0;t<e.length;t++)l(e[t])},i=function(e,o){a[e].def=!1,a[e].val=o||t},n=function(e,t){"*"!=t&&(a[e].def=!1,a[e].val=t)};return l("colwidth"),o.defaultcolwidth&&i("colwidth",o.defaultcolwidth),l("rowheight"),o.rowheight&&i("rowheight",o.defaultrowheight),l("textalignhoriz"),o.defaulttextformat&&i("textalignhoriz",e.cellformats[o.defaulttextformat]),l("numberalignhoriz"),o.defaultnontextformat&&i("numberalignhoriz",e.cellformats[o.defaultnontextformat]),r(["alignvert","padtop","padright","padbottom","padleft"]),o.defaultlayout&&(parts=e.layouts[o.defaultlayout].match(/^padding:\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+);vertical-align:\s*(\S+);/),n("padtop",parts[1]),n("padright",parts[2]),n("padbottom",parts[3]),n("padleft",parts[4]),n("alignvert",parts[5])),r(["fontfamily","fontlook","fontsize"]),o.defaultfont&&(parts=e.fonts[o.defaultfont].match(/^(\*|\S+? \S+?) (\S+?) (\S.*)$/),n("fontfamily",parts[3]),n("fontsize",parts[2]),n("fontlook",parts[1])),l("textcolor"),o.defaultcolor&&i("textcolor",e.colors[o.defaultcolor]),l("bgcolor"),o.defaultbgcolor&&i("bgcolor",e.colors[o.defaultbgcolor]),r(["numberformat","textformat"]),o.defaultnontextvalueformat&&i("numberformat",e.valueformats[o.defaultnontextvalueformat]),o.defaulttextvalueformat&&i("textformat",e.valueformats[o.defaulttextvalueformat]),l("recalc"),o.recalc&&i("recalc",o.recalc),l("usermaxcol"),o.usermaxcol&&i("usermaxcol",o.usermaxcol),l("usermaxrow"),o.usermaxrow&&i("usermaxrow",o.usermaxrow),a},SocialCalc.DecodeCellAttributes=function(e,t,o,a){var l,r,n,c=e.GetAssuredCell(t),s=!1,d=function(e,t,a){var l;o[e]&&(l=o[e].def?"":o[e].val,l!=(t||"")&&p(a+" "+l))},u="",p=function(e){u&&(u+="\n"),u+="set "+(a||t)+" "+e,s=!0};for(d("alignhoriz",e.cellformats[c.cellformat],"cellformat"),l=o.alignvert.def&&o.padtop.def&&o.padright.def&&o.padbottom.def&&o.padleft.def?"":"padding:"+(o.padtop.def?"* ":o.padtop.val+" ")+(o.padright.def?"* ":o.padright.val+" ")+(o.padbottom.def?"* ":o.padbottom.val+" ")+(o.padleft.def?"*":o.padleft.val)+";vertical-align:"+(o.alignvert.def?"*;":o.alignvert.val+";"),l!=(e.layouts[c.layout]||"")&&p("layout "+l),l=o.fontlook.def&&o.fontsize.def&&o.fontfamily.def?"":(o.fontlook.def?"* ":o.fontlook.val+" ")+(o.fontsize.def?"* ":o.fontsize.val+" ")+(o.fontfamily.def?"*":o.fontfamily.val),l!=(e.fonts[c.font]||"")&&p("font "+l),d("textcolor",e.colors[c.color],"color"),d("bgcolor",e.colors[c.bgcolor],"bgcolor"),d("numberformat",e.valueformats[c.nontextvalueformat],"nontextvalueformat"),d("textformat",e.valueformats[c.textvalueformat],"textvalueformat"),i=0;i<4;i++)r="trbl".charAt(i),n="b"+r,d(n,e.borderstyles[c[n]],n);return d("cssc",c.cssc,"cssc"),d("csss",c.csss,"csss"),o.mod&&(l=o.mod.def?"n":o.mod.val,l!=(c.mod||"n")&&("n"==l&&(l=""),p("mod "+l))),s?u:null},SocialCalc.DecodeSheetAttributes=function(e,t){var o,a=e.attribs,l=!1,r=function(e,o,a){var l;t[e]&&(l=t[e].def?"":t[e].val,l!=(o||"")&&n(a+" "+l))},i="",n=function(e){i&&(i+="\n"),i+="set sheet "+e,l=!0};return r("colwidth",a.defaultcolwidth,"defaultcolwidth"),r("rowheight",a.defaultrowheight,"defaultrowheight"),r("textalignhoriz",e.cellformats[a.defaulttextformat],"defaulttextformat"),r("numberalignhoriz",e.cellformats[a.defaultnontextformat],"defaultnontextformat"),o=t.alignvert.def&&t.padtop.def&&t.padright.def&&t.padbottom.def&&t.padleft.def?"":"padding:"+(t.padtop.def?"* ":t.padtop.val+" ")+(t.padright.def?"* ":t.padright.val+" ")+(t.padbottom.def?"* ":t.padbottom.val+" ")+(t.padleft.def?"*":t.padleft.val)+";vertical-align:"+(t.alignvert.def?"*;":t.alignvert.val+";"),o!=(e.layouts[a.defaultlayout]||"")&&n("defaultlayout "+o),o=t.fontlook.def&&t.fontsize.def&&t.fontfamily.def?"":(t.fontlook.def?"* ":t.fontlook.val+" ")+(t.fontsize.def?"* ":t.fontsize.val+" ")+(t.fontfamily.def?"*":t.fontfamily.val),o!=(e.fonts[a.defaultfont]||"")&&n("defaultfont "+o),r("textcolor",e.colors[a.defaultcolor],"defaultcolor"),r("bgcolor",e.colors[a.defaultbgcolor],"defaultbgcolor"),r("numberformat",e.valueformats[a.defaultnontextvalueformat],"defaultnontextvalueformat"),r("textformat",e.valueformats[a.defaulttextvalueformat],"defaulttextvalueformat"),r("recalc",e.attribs.recalc,"recalc"),r("usermaxcol",e.attribs.usermaxcol,"usermaxcol"),r("usermaxrow",e.attribs.usermaxrow,"usermaxrow"),l?i:null},SocialCalc.SheetCommandInfo=function(e){this.sheetobj=e,this.parseobj=null,this.timerobj=null,this.firsttimerdelay=50,this.timerdelay=1,this.maxtimeslice=100,this.saveundo=!1,this.CmdExtensionCallbacks={},this.cmdextensionbusy=""},SocialCalc.ScheduleSheetCommands=function(e,t,o){var a=e.sci;a.parseobj=new SocialCalc.Parse(t),a.saveundo=o,a.sheetobj.statuscallback&&e.statuscallback(a,"cmdstart","",a.sheetobj.statuscallbackparams),a.saveundo&&a.sheetobj.changes.PushChange(""),a.timerobj=window.setTimeout(function(){SocialCalc.SheetCommandsTimerRoutine(a)},a.firsttimerdelay)},SocialCalc.SheetCommandsTimerRoutine=function(e){var t,o=new Date;for(e.timerobj=null;!e.parseobj.EOF();){if(t=SocialCalc.ExecuteSheetCommand(e.sheetobj,e.parseobj,e.saveundo),t&&alert(t),e.parseobj.NextLine(),e.cmdextensionbusy.length>0)return void(e.sheetobj.statuscallback&&e.sheetobj.statuscallback(e,"cmdextension",e.cmdextensionbusy,e.sheetobj.statuscallbackparams));if(new Date-o>=e.maxtimeslice)return void(e.timerobj=window.setTimeout(function(){SocialCalc.SheetCommandsTimerRoutine(e)},e.timerdelay))}e.sheetobj.statuscallback&&e.sheetobj.statuscallback(e,"cmdend","",e.sheetobj.statuscallbackparams)},SocialCalc.ResumeFromCmdExtension=function(e){e.cmdextensionbusy="",SocialCalc.SheetCommandsTimerRoutine(e)},SocialCalc.ExecuteSheetCommand=function(e,t,o){var a,l,r,i,n,c,s,d,u,p,m,h,C,f,S,g,v,b,y,w,x,F,T,k,E,_,P,R,L,M,D,A,I,N,O,U,B,z,G,V,H,j,K,W,X,$,Y,q,J,Z,Q,ee,te,oe,ae,le,re,ie,ne,ce,se,de=e.attribs,ue=e.changes,pe=SocialCalc.CellProperties,me=SocialCalc.Constants,he=function(){var e=SocialCalc.ParseRange(i);h=e.cr1,C=e.cr2,C.col>de.lastcol&&(de.lastcol=C.col),C.row>de.lastrow&&(de.lastrow=C.row)};switch(u="",a=t.RestOfStringNoMove(),o&&e.changes.AddDo(a),l=t.NextToken()){case"set":if(i=t.NextToken(),n=t.NextToken(),r=t.RestOfString(),p="set "+i+" "+n,"sheet"==i)switch(e.renderneeded=!0,n){case"defaultcolwidth":o&&ue.AddUndo(p,de[n]),de[n]=r;break;case"defaultcolor":case"defaultbgcolor":o&&ue.AddUndo(p,e.GetStyleString("color",de[n])),de[n]=e.GetStyleNum("color",r);break;case"defaultlayout":o&&ue.AddUndo(p,e.GetStyleString("layout",de[n])),de[n]=e.GetStyleNum("layout",r);break;case"defaultfont":o&&ue.AddUndo(p,e.GetStyleString("font",de[n])),"* * *"==r&&(r=""),de[n]=e.GetStyleNum("font",r);break;case"defaulttextformat":case"defaultnontextformat":o&&ue.AddUndo(p,e.GetStyleString("cellformat",de[n])),de[n]=e.GetStyleNum("cellformat",r);break;case"defaulttextvalueformat":case"defaultnontextvalueformat":o&&ue.AddUndo(p,e.GetStyleString("valueformat",de[n])),de[n]=e.GetStyleNum("valueformat",r);for(g in e.cells)delete e.cells[g].displaystring;break;case"lastcol":case"lastrow":o&&ue.AddUndo(p,de[n]-0),c=r-0,"number"==typeof c&&(de[n]=c>0?c:1);break;case"recalc":o&&ue.AddUndo(p,de[n]),"off"==r?de.recalc=r:delete de.recalc;break;case"usermaxcol":case"usermaxrow":o&&ue.AddUndo(p,de[n]-0),c=r-0,"number"==typeof c&&(de[n]=c>0?c:0);break;default:u=me.s_escUnknownSheetCmd+a}else if(/^[a-z]{1,2}(:[a-z]{1,2})?$/i.test(i))for(e.renderneeded=!0,i=i.toUpperCase(),s=i.indexOf(":"),s>=0?(h=SocialCalc.coordToCr(i.substring(0,s)+"1"),C=SocialCalc.coordToCr(i.substring(s+1)+"1")):(h=SocialCalc.coordToCr(i+"1"),C=h),f=h.col;f<=C.col;f++)"width"==n?(g=SocialCalc.rcColname(f),o&&ue.AddUndo("set "+g+" width",e.colattribs.width[g]),r.length>0?e.colattribs.width[g]=r:delete e.colattribs.width[g]):"hide"==n&&(e.hiddencolrow="col",g=SocialCalc.rcColname(f),o&&ue.AddUndo("set "+g+" hide",e.colattribs.hide[g]),r.length>0?e.colattribs.hide[g]=r:delete e.colattribs.hide[g]);else if(/^\d+(:\d+)?$/i.test(i))for(e.renderneeded=!0,i=i.toUpperCase(),s=i.indexOf(":"),s>=0?(h=SocialCalc.coordToCr("A"+i.substring(0,s)),C=SocialCalc.coordToCr("A"+i.substring(s+1))):(h=SocialCalc.coordToCr("A"+i),C=h),S=h.row;S<=C.row;S++)"height"==n?(o&&ue.AddUndo("set "+S+" height",e.rowattribs.height[S]),r.length>0?e.rowattribs.height[S]=r:delete e.rowattribs.height[S]):"hide"==n&&(e.hiddencolrow="row",o&&ue.AddUndo("set "+S+" hide",e.rowattribs.hide[S]),r.length>0?e.rowattribs.hide[S]=r:delete e.rowattribs.hide[S]);else if(/^[a-z]{1,2}\d+(:[a-z]{1,2}\d+)?$/i.test(i))for(he(),h.row!=C.row||h.col!=C.col||e.celldisplayneeded||e.renderneeded?(e.renderneeded=!0,e.celldisplayneeded=""):e.celldisplayneeded=SocialCalc.crToCoord(h.col,h.row),S=h.row;S<=C.row;S++)for(f=h.col;f<=C.col;f++)g=SocialCalc.crToCoord(f,S),v=e.GetAssuredCell(g),v.readonly&&"readonly"!=n||(o&&ue.AddUndo("set "+g+" all",e.CellToString(v)),"value"==n?(s=r.indexOf(" "),v.datavalue=r.substring(s+1)-0,delete v.errors,v.datatype="v",v.valuetype=r.substring(0,s),delete v.displaystring,delete v.parseinfo,de.needsrecalc="yes"):"text"==n?(s=r.indexOf(" "),v.datavalue=SocialCalc.decodeFromSave(r.substring(s+1)),delete v.errors,v.datatype="t",v.valuetype=r.substring(0,s),delete v.displaystring,delete v.parseinfo,de.needsrecalc="yes"):"formula"==n?(v.datavalue=0,delete v.errors,v.datatype="f",v.valuetype="e#N/A",v.formula=r,delete v.displaystring,delete v.parseinfo,de.needsrecalc="yes"):"constant"==n?(s=r.indexOf(" "),d=r.substring(s+1).indexOf(" "),v.datavalue=r.substring(s+1,s+1+d)-0,v.valuetype=r.substring(0,s),"e"==v.valuetype.charAt(0)?v.errors=v.valuetype.substring(1):delete v.errors,v.datatype="c",v.formula=r.substring(s+d+2),delete v.displaystring,delete v.parseinfo,de.needsrecalc="yes"):"empty"==n?(v.datavalue="",delete v.errors,v.datatype=null,v.formula="",v.valuetype="b",delete v.displaystring,delete v.parseinfo,de.needsrecalc="yes"):"all"==n?(r.length>0?(v=new SocialCalc.Cell(g),e.CellFromStringParts(v,r.split(":"),1),e.cells[g]=v):delete e.cells[g],de.needsrecalc="yes"):/^b[trbl]$/.test(n)?(v[n]=e.GetStyleNum("borderstyle",r),e.renderneeded=!0):"color"==n||"bgcolor"==n?v[n]=e.GetStyleNum("color",r):"layout"==n||"cellformat"==n?v[n]=e.GetStyleNum(n,r):"font"==n?("* * *"==r&&(r=""),v[n]=e.GetStyleNum("font",r)):"textvalueformat"==n||"nontextvalueformat"==n?(v[n]=e.GetStyleNum("valueformat",r),delete v.displaystring):"cssc"==n?(r=r.replace(/[^a-zA-Z0-9\-]/g,""),v.cssc=r):"csss"==n?(r=r.replace(/\n/g,""),v.csss=r):"mod"==n?(r=r.replace(/[^yY]/g,"").toLowerCase(),v.mod=r):"comment"==n?v.comment=SocialCalc.decodeFromSave(r):"readonly"==n?v.readonly="yes"==r.toLowerCase():u=me.s_escUnknownSetCoordCmd+a);break;case"merge":if(e.renderneeded=!0,i=t.NextToken(),r=t.RestOfString(),he(),v=e.GetAssuredCell(h.coord),v.readonly)break;o&&ue.AddUndo("unmerge "+h.coord),C.col>h.col?v.colspan=C.col-h.col+1:delete v.colspan,C.row>h.row?v.rowspan=C.row-h.row+1:delete v.rowspan,e.changedrendervalues=!0;break;case"unmerge":if(e.renderneeded=!0,i=t.NextToken(),r=t.RestOfString(),he(),v=e.GetAssuredCell(h.coord),v.readonly)break;o&&ue.AddUndo("merge "+h.coord+":"+SocialCalc.crToCoord(h.col+(v.colspan||1)-1,h.row+(v.rowspan||1)-1)),delete v.colspan,delete v.rowspan,e.changedrendervalues=!0;break;case"erase":case"cut":for(e.renderneeded=!0,e.changedrendervalues=!0,i=t.NextToken(),r=t.RestOfString(),he(),o&&ue.AddUndo("changedrendervalues"),"cut"==l&&(o&&ue.AddUndo("loadclipboard",SocialCalc.encodeForSave(SocialCalc.Clipboard.clipboard)),SocialCalc.Clipboard.clipboard=SocialCalc.CreateSheetSave(e,i)),S=h.row;S<=C.row;S++)for(f=h.col;f<=C.col;f++)g=SocialCalc.crToCoord(f,S),v=e.GetAssuredCell(g),v.readonly||(o&&ue.AddUndo("set "+g+" all",e.CellToString(v)),"all"==r?delete e.cells[g]:"formulas"==r?(v.datavalue="",v.datatype=null,v.formula="",v.valuetype="b",delete v.errors,delete v.displaystring,delete v.parseinfo,v.comment&&delete v.comment):"formats"==r&&(b=new SocialCalc.Cell(g),b.datavalue=v.datavalue,b.datatype=v.datatype,b.formula=v.formula,b.valuetype=v.valuetype,v.comment&&(b.comment=v.comment),e.cells[g]=b));de.needsrecalc="yes";break;case"fillright":case"filldown":for(e.renderneeded=!0,e.changedrendervalues=!0,o&&ue.AddUndo("changedrendervalues"),i=t.NextToken(),r=t.RestOfString(),he(),"fillright"==l?(y=!0,w=h.row,x=h.col+1):(y=!1,w=h.row+1,
x=h.col),S=w;S<=C.row;S++)for(f=x;f<=C.col;f++)if(g=SocialCalc.crToCoord(f,S),v=e.GetAssuredCell(g),!v.readonly){if(o&&ue.AddUndo("set "+g+" all",e.CellToString(v)),y?(F=SocialCalc.crToCoord(h.col,S),k=f-x+1,T=0):(F=SocialCalc.crToCoord(f,h.row),k=0,T=S-w+1),E=e.GetAssuredCell(F),"all"==r||"formats"==r)for(n in pe)1!=pe[n]&&(void 0===typeof E[n]||3==pe[n]?delete v[n]:v[n]=E[n]);("all"==r||"formulas"==r)&&(v.datavalue=E.datavalue,v.datatype=E.datatype,v.valuetype=E.valuetype,"f"==v.datatype?v.formula=SocialCalc.OffsetFormulaCoords(E.formula,k,T):v.formula=E.formula,delete v.parseinfo,v.errors=E.errors),delete v.displaystring}de.needsrecalc="yes";break;case"copy":i=t.NextToken(),r=t.RestOfString(),o&&ue.AddUndo("loadclipboard",SocialCalc.encodeForSave(SocialCalc.Clipboard.clipboard)),SocialCalc.Clipboard.clipboard=SocialCalc.CreateSheetSave(e,i);break;case"loadclipboard":r=t.RestOfString(),o&&ue.AddUndo("loadclipboard",SocialCalc.encodeForSave(SocialCalc.Clipboard.clipboard)),SocialCalc.Clipboard.clipboard=SocialCalc.decodeFromSave(r);break;case"clearclipboard":o&&ue.AddUndo("loadclipboard",SocialCalc.encodeForSave(SocialCalc.Clipboard.clipboard)),SocialCalc.Clipboard.clipboard="";break;case"paste":if(e.renderneeded=!0,e.changedrendervalues=!0,o&&ue.AddUndo("changedrendervalues"),i=t.NextToken(),r=t.RestOfString(),he(),!SocialCalc.Clipboard.clipboard)break;for(_=new SocialCalc.Sheet,_.ParseSheetSave(SocialCalc.Clipboard.clipboard),P=SocialCalc.ParseRange(_.copiedfrom),k=h.col-P.cr1.col,T=h.row-P.cr1.row,R=Math.max(C.col-h.col+1,P.cr2.col-P.cr1.col+1),L=Math.max(C.row-h.row+1,P.cr2.row-P.cr1.row+1),h.col+R-1>de.lastcol&&(de.lastcol=h.col+R-1),h.row+L-1>de.lastrow&&(de.lastrow=h.row+L-1),S=h.row;S<h.row+L;S++)for(f=h.col;f<h.col+R;f++)if(g=SocialCalc.crToCoord(f,S),v=e.GetAssuredCell(g),!v.readonly){if(o&&ue.AddUndo("set "+g+" all",e.CellToString(v)),F=SocialCalc.crToCoord(P.cr1.col+(f-h.col)%(P.cr2.col-P.cr1.col+1),P.cr1.row+(S-h.row)%(P.cr2.row-P.cr1.row+1)),E=_.GetAssuredCell(F),"all"==r||"formats"==r)for(n in pe)1!=pe[n]&&(void 0===typeof E[n]||3==pe[n]?delete v[n]:(M=SocialCalc.CellPropertiesTable[n],M&&E[n]?v[n]=e.GetStyleNum(M,_.GetStyleString(M,E[n])):v[n]=E[n]));("all"==r||"formulas"==r)&&(v.datavalue=E.datavalue,v.datatype=E.datatype,v.valuetype=E.valuetype,"f"==v.datatype?v.formula=SocialCalc.OffsetFormulaCoords(E.formula,k,T):v.formula=E.formula,delete v.parseinfo,v.errors=E.errors,E.comment?v.comment=E.comment:v.comment&&delete v.comment),delete v.displaystring}de.needsrecalc="yes";break;case"sort":for(e.renderneeded=!0,e.changedrendervalues=!0,o&&ue.AddUndo("changedrendervalues"),i=t.NextToken(),he(),$=[],Y=[],q=0,J=0;3>=J;J++)$[J]=t.NextToken(),Y[J]=t.NextToken(),$[J]&&(q=J);for(Q={},Z=[],ee=[],te=[],S=h.row;S<=C.row;S++){for(f=h.col;f<=C.col;f++)g=SocialCalc.crToCoord(f,S),v=e.cells[g],v?(Q[g]=e.CellToString(v),o&&ue.AddUndo("set "+g+" all",Q[g])):o&&ue.AddUndo("set "+g+" all");for(Z.push(Z.length),ee.push([]),te.push([]),slast=te.length-1,J=0;q>=J;J++)g=$[J]+S,v=e.GetAssuredCell(g),m=v.datavalue,ae=v.valuetype.charAt(0)||"b","t"==ae&&(m=m.toLowerCase()),ee[slast].push(m),te[slast].push(ae)}for(oe=function(e,t){var o,a,l,r,i;for(o=0;q>=o;o++)if("up"==Y[o]?(a=e,l=t):(a=t,l=e),r=te[a][o],tb=te[l][o],"t"==r?"t"==tb?(a=ee[a][o],l=ee[l][o],i=a>l?1:l>a?-1:0):"n"==tb?i=1:"b"==tb?i="up"==Y[o]?-1:1:"e"==tb&&(i=-1):"n"==r?"t"==tb?i=-1:"n"==tb?(a=ee[a][o]-0,l=ee[l][o]-0,i=a>l?1:l>a?-1:0):"b"==tb?i="up"==Y[o]?-1:1:"e"==tb&&(i=-1):"e"==r?"e"==tb?(a=ee[a][o],l=ee[l][o],i=a>l?1:l>a?-1:0):i="b"==tb&&"up"==Y[o]?-1:1:"b"==r&&(i="b"==tb?0:"up"==Y[o]?1:-1),i)return i;return i=e>t?1:t>e?-1:0},Z.sort(oe),S=h.row;S<=C.row;S++)for(le=Z[S-h.row],f=h.col;f<=C.col;f++)g=SocialCalc.crToCoord(f,S),re=SocialCalc.crToCoord(f,le+h.row),Q[re]?(v=new SocialCalc.Cell(g),e.CellFromStringParts(v,Q[re].split(":"),1),"f"==v.datatype&&(v.formula=SocialCalc.OffsetFormulaCoords(v.formula,0,S-h.row-le)),e.cells[g]=v):delete e.cells[g];de.needsrecalc="yes";break;case"insertcol":case"insertrow":for(e.renderneeded=!0,e.changedrendervalues=!0,i=t.NextToken(),r=t.RestOfString(),he(),"insertcol"==l?(k=1,D=h.col,T=0,A=1,I=h.col,O=h.col,N=1,U=de.lastrow,o&&ue.AddUndo("deletecol "+h.coord)):(k=0,D=1,T=1,A=h.row,I=1,O=de.lastcol,N=h.row,U=h.row,o&&ue.AddUndo("deleterow "+h.coord)),S=de.lastrow;S>=A;S--)for(f=de.lastcol;f>=D;f--)F=SocialCalc.crToCoord(f,S),g=SocialCalc.crToCoord(f+k,S+T),e.cells[F]?e.cells[g]=e.cells[F]:delete e.cells[g];for(S=N;U>=S;S++)for(f=I;O>=f;f++){g=SocialCalc.crToCoord(f,S),v=new SocialCalc.Cell(g),e.cells[g]=v,F=SocialCalc.crToCoord(f-k,S-T),E=e.GetAssuredCell(F);for(n in pe)2==pe[n]&&(v[n]=E[n])}for(g in e.cells)v=e.cells[g],v&&"f"==v.datatype&&(v.formula=SocialCalc.AdjustFormulaCoords(v.formula,h.col,k,h.row,T)),v&&delete v.parseinfo;for(ie in e.names)e.names[ie]&&(ne=e.names[ie].definition,ce="","="==ne.charAt(0)&&(ce="=",ne=ne.substring(1)),e.names[ie].definition=ce+SocialCalc.AdjustFormulaCoords(ne,h.col,k,h.row,T));for(S=de.lastrow;S>=A&&"insertrow"==l;S--){B=S+T;for(n in e.rowattribs)m=e.rowattribs[n][S],e.rowattribs[n][B]!=m&&(m?e.rowattribs[n][B]=m:delete e.rowattribs[n][B])}for(f=de.lastcol;f>=D&&"insertcol"==l;f--){G=SocialCalc.rcColname(f),z=SocialCalc.rcColname(f+k);for(n in e.colattribs)m=e.colattribs[n][G],e.colattribs[n][z]!=m&&(m?e.colattribs[n][z]=m:delete e.colattribs[n][z])}de.lastcol+=k,de.lastrow+=T,de.needsrecalc="yes";break;case"deletecol":case"deleterow":for(e.renderneeded=!0,e.changedrendervalues=!0,i=t.NextToken(),r=t.RestOfString(),H=de.lastcol,V=de.lastrow,he(),"deletecol"==l?(k=h.col-C.col-1,T=0,x=C.col+1,w=1):(k=0,T=h.row-C.row-1,x=1,w=C.row+1),S=w;V-T>=S;S++)for(f=x;H-k>=f;f++)if(g=SocialCalc.crToCoord(f+k,S+T),v=e.cells[g],v&&v.readonly)return u;for(S=w;V-T>=S;S++)for(f=x;H-k>=f;f++)g=SocialCalc.crToCoord(f+k,S+T),o&&(w-T>S||x-k>f)&&(v=e.cells[g],v?ue.AddUndo("set "+g+" all",e.CellToString(v)):ue.AddUndo("erase "+g+" all")),F=SocialCalc.crToCoord(f,S),v=e.cells[F],v?e.cells[g]=v:delete e.cells[g];for(g in e.cells)v=e.cells[g],v&&("f"==v.datatype?(W=v.formula,v.formula=SocialCalc.AdjustFormulaCoords(W,h.col,k,h.row,T),v.formula!=W&&(delete v.parseinfo,o&&-1!=v.formula.indexOf("#REF!")&&(X=SocialCalc.coordToCr(g),ue.AddUndo("set "+SocialCalc.rcColname(X.col-k)+(X.row-T)+" formula "+W)))):delete v.parseinfo);for(ie in e.names)e.names[ie]&&(ne=e.names[ie].definition,ce="","="==ne.charAt(0)&&(ce="=",ne=ne.substring(1)),e.names[ie].definition=ce+SocialCalc.AdjustFormulaCoords(ne,h.col,k,h.row,T));for(S=w;V-T>=S&&"deleterow"==l;S++){j=S+T;for(n in e.rowattribs)m=e.rowattribs[n][S],e.rowattribs[n][j]!=m&&(o&&ue.AddUndo("set "+j+" "+n,e.rowattribs[n][j]),m?e.rowattribs[n][j]=m:delete e.rowattribs[n][j])}for(f=x;H-k>=f&&"deletecol"==l;f++){G=SocialCalc.rcColname(f),K=SocialCalc.rcColname(f+k);for(n in e.colattribs)m=e.colattribs[n][G],e.colattribs[n][K]!=m&&(o&&ue.AddUndo("set "+K+" "+n,e.colattribs[n][K]),m?e.colattribs[n][K]=m:delete e.colattribs[n][K])}if(o)if("deletecol"==l)for(f=h.col;f<=C.col;f++)ue.AddUndo("insertcol "+SocialCalc.rcColname(f));else for(S=h.row;S<=C.row;S++)ue.AddUndo("insertrow "+S);"deletecol"==l?h.col<=H&&(C.col<=H?de.lastcol+=k:de.lastcol=h.col-1):h.row<=V&&(C.row<=V?de.lastrow+=T:de.lastrow=h.row-1),de.needsrecalc="yes";break;case"movepaste":case"moveinsert":var Ce,fe,Se,ge,ve,be,ye;for(e.renderneeded=!0,e.changedrendervalues=!0,o&&ue.AddUndo("changedrendervalues"),i=t.NextToken(),fe=t.NextToken(),r=t.RestOfString(),""==r&&(r="all"),he(),Se=SocialCalc.coordToCr(fe),k=Se.col-h.col,T=Se.row-h.row,R=C.col-h.col+1,L=C.row-h.row+1,Ce={},S=h.row;S<=C.row;S++)for(f=h.col;f<=C.col;f++)if(g=SocialCalc.crToCoord(f,S),v=e.GetAssuredCell(g),!v.readonly&&(o&&ue.AddUndo("set "+g+" all",e.CellToString(v)),e.cells[g])){Ce[g]=new SocialCalc.Cell(g);for(n in pe)void 0!==typeof v[n]&&(Ce[g][n]=v[n],"all"==r&&delete v[n],"formulas"==r&&(1==pe[n]||3==pe[n])&&delete v[n],"formats"==r&&2==pe[n]&&delete v[n]);"formulas"==r&&(v.datavalue="",v.datatype=null,v.formula="",v.valuetype="b"),"all"==r&&delete e.cells[g]}if("moveinsert"==l&&(ge=!1,ve=!1,0==T&&(Se.col<h.col||Se.col>C.col)?Se.col<h.col?(be=h.col-Se.col,ge=-1):(Se.col-=1,k=Se.col-C.col,be=Se.col-C.col,ge=1):0==k&&(Se.row<h.row||Se.row>C.row)?Se.row<h.row?(be=h.row-Se.row,ve=-1):(Se.row-=1,T=Se.row-C.row,be=Se.row-C.row,ve=1):l="movepaste"),ye={},ve)for(S=0;be>S;S++)for(f=h.col;f<=C.col;f++){if(0>ve?(F=SocialCalc.crToCoord(f,Se.row+be-S-1),g=SocialCalc.crToCoord(f,C.row-S)):(F=SocialCalc.crToCoord(f,Se.row-be+S+1),g=SocialCalc.crToCoord(f,h.row+S)),E=e.GetAssuredCell(F),o&&ue.AddUndo("set "+F+" all",e.CellToString(E)),v=e.GetAssuredCell(g),"all"==r||"formats"==r)for(n in pe)1!=pe[n]&&(void 0===typeof E[n]||3==pe[n]?delete v[n]:v[n]=E[n]);("all"==r||"formulas"==r)&&(v.datavalue=E.datavalue,v.datatype=E.datatype,v.valuetype=E.valuetype,v.formula=E.formula,delete v.parseinfo,v.errors=E.errors),delete v.displaystring,ye[F]=g}if(ge)for(f=0;be>f;f++)for(S=h.row;S<=C.row;S++){if(0>ge?(F=SocialCalc.crToCoord(Se.col+be-f-1,S),g=SocialCalc.crToCoord(C.col-f,S)):(F=SocialCalc.crToCoord(Se.col-be+f+1,S),g=SocialCalc.crToCoord(h.col+f,S)),E=e.GetAssuredCell(F),o&&ue.AddUndo("set "+F+" all",e.CellToString(E)),v=e.GetAssuredCell(g),"all"==r||"formats"==r)for(n in pe)1!=pe[n]&&(void 0===typeof E[n]||3==pe[n]?delete v[n]:v[n]=E[n]);("all"==r||"formulas"==r)&&(v.datavalue=E.datavalue,v.datatype=E.datatype,v.valuetype=E.valuetype,v.formula=E.formula,delete v.parseinfo,v.errors=E.errors),delete v.displaystring,ye[F]=g}for(Se.col+R-1>de.lastcol&&(de.lastcol=Se.col+R-1),Se.row+L-1>de.lastrow&&(de.lastrow=Se.row+L-1),S=h.row;S<h.row+L;S++)for(f=h.col;f<h.col+R;f++)if(g=SocialCalc.crToCoord(f+k,S+T),v=e.GetAssuredCell(g),!v.readonly)if(o&&ue.AddUndo("set "+g+" all",e.CellToString(v)),F=SocialCalc.crToCoord(f,S),ye[F]=g,"all"!=r||Ce[F]){if(E=Ce[F],E||(E=e.GetAssuredCell(F)),"all"==r||"formats"==r)for(n in pe)1!=pe[n]&&(void 0===typeof E[n]||3==pe[n]?delete v[n]:v[n]=E[n]);("all"==r||"formulas"==r)&&(v.datavalue=E.datavalue,v.datatype=E.datatype,v.valuetype=E.valuetype,v.formula=E.formula,delete v.parseinfo,v.errors=E.errors,E.comment?v.comment=E.comment:v.comment&&delete v.comment),delete v.displaystring}else delete e.cells[g];for(g in e.cells)v=e.cells[g],v&&("f"==v.datatype?(W=v.formula,v.formula=SocialCalc.ReplaceFormulaCoords(W,ye),v.formula!=W&&(delete v.parseinfo,o&&!ye[g]&&ue.AddUndo("set "+g+" formula "+W))):delete v.parseinfo);for(ie in e.names)e.names[ie]&&(ne=e.names[ie].definition,W=ne,ce="","="==ne.charAt(0)&&(ce="=",ne=ne.substring(1)),e.names[ie].definition=ce+SocialCalc.ReplaceFormulaCoords(ne,ye),o&&e.names[ie].definition!=W&&ue.AddUndo("name define "+ie+" "+W));de.needsrecalc="yes";break;case"name":if(i=t.NextToken(),ie=t.NextToken(),r=t.RestOfString(),ie=ie.toUpperCase().replace(/[^A-Z0-9_\.]/g,""),""==ie)break;if("define"==i){if(""==r)break;e.names[ie]?(o&&ue.AddUndo("name define "+ie+" "+e.names[ie].definition),e.names[ie].definition=r):(o&&ue.AddUndo("name delete "+ie),e.names[ie]={definition:r,desc:""})}else"desc"==i?e.names[ie]&&(o&&ue.AddUndo("name desc "+ie+" "+e.names[ie].desc),e.names[ie].desc=r):"delete"==i&&(o&&(e.names[ie].desc&&ue.AddUndo("name desc "+ie+" "+e.names[ie].desc),ue.AddUndo("name define "+ie+" "+e.names[ie].definition)),delete e.names[ie]);de.needsrecalc="yes";break;case"recalc":de.needsrecalc="yes",e.recalconce=!0;break;case"redisplay":e.renderneeded=!0;break;case"changedrendervalues":e.changedrendervalues=!0;break;case"startcmdextension":ie=t.NextToken(),se=e.sci.CmdExtensionCallbacks[ie],se&&se.func(ie,se.data,e,t,o);break;default:u=me.s_escUnknownCmd+a}return u},SocialCalc.SheetUndo=function(e){var t,o=e.changes.TOS(),a=o?o.undo.length-1:-1,l="";for(t=a;t>=0;t--)l&&(l+="\n"),l+=o.undo[t];e.changes.Undo(),e.ScheduleSheetCommands(l,!1)},SocialCalc.SheetRedo=function(e){var t,o,a=e.changes.Redo();if(!a)return void e.ScheduleSheetCommands("",!1);t=e.changes.TOS();var l="";for(o=0;t&&o<t.command.length;o++)l&&(l+="\n"),l+=t.command[o];e.ScheduleSheetCommands(l,!1)},SocialCalc.CreateAuditString=function(e){var t,o,a="",l=e.changes.stack,r=e.changes.tos;for(t=0;r>=t;t++)for(o=0;o<l[t].command.length;o++)a+=l[t].command[o]+"\n";return a},SocialCalc.GetStyleNum=function(e,t,o){var a;return 0==o.length?0:(a=e[t+"hash"][o],a||(e[t+"s"].length<1&&e[t+"s"].push(""),a=e[t+"s"].push(o)-1,e[t+"hash"][o]=a,e.changedrendervalues=!0),a)},SocialCalc.GetStyleString=function(e,t,o){return o?e[t+"s"][o]:null},SocialCalc.OffsetFormulaCoords=function(e,t,o){var a,l,r,i,n,c,s="",d=SocialCalc.Formula;if(!d)return"Need SocialCalc.Formula";var u=d.TokenType,p=u.op,m=u.string,h=u.coord,C=d.TokenOpExpansion;for(a=d.ParseFormulaIntoTokens(e),i=0;i<a.length;i++)r=a[i].type,l=a[i].text,r==h?(c="",n=SocialCalc.coordToCr(l),"$"!=l.charAt(0)?n.col+=t:c+="$",c+=SocialCalc.rcColname(n.col),-1==l.indexOf("$",1)?n.row+=o:c+="$",c+=n.row,(n.row<1||n.col<1)&&(c="#REF!"),s+=c):s+=r==m?l.indexOf('"')>=0?'"'+l.replace(/"/,'""')+'"':'"'+l+'"':r==p?C[l]||l:l;return s},SocialCalc.AdjustFormulaCoords=function(e,t,o,a,l){var r,i,n,c,s="",d=!1,u=SocialCalc.Formula;if(!u)return"Need SocialCalc.Formula";var p=u.TokenType,m=p.op,h=p.string,C=p.coord,f=u.TokenOpExpansion;for(parseinfo=SocialCalc.Formula.ParseFormulaIntoTokens(e),n=0;n<parseinfo.length;n++)r=parseinfo[n].type,i=parseinfo[n].text,r==m&&("!"==i?d=!0:":"!=i&&(d=!1),i=f[i]||i),r==C?(cr=SocialCalc.coordToCr(i),(0>o&&cr.col>=t&&cr.col<t-o||0>l&&cr.row>=a&&cr.row<a-l)&&(d||(cr.col=0,cr.row=0)),d||(cr.col>=t&&(cr.col+=o),cr.row>=a&&(cr.row+=l)),c="$"==i.charAt(0)?"$"+SocialCalc.rcColname(cr.col):SocialCalc.rcColname(cr.col),c+=-1!=i.indexOf("$",1)?"$"+cr.row:cr.row,(cr.row<1||cr.col<1)&&(c="#REF!"),i=c):r==h&&(i=i.indexOf('"')>=0?'"'+i.replace(/"/,'""')+'"':'"'+i+'"'),s+=i;return s},SocialCalc.ReplaceFormulaCoords=function(e,t){var o,a,l,r,i,n="",c=!1,s=SocialCalc.Formula;if(!s)return"Need SocialCalc.Formula";var d=s.TokenType,u=d.op,p=d.string,m=d.coord,h=s.TokenOpExpansion;for(parseinfo=SocialCalc.Formula.ParseFormulaIntoTokens(e),l=0;l<parseinfo.length;l++)o=parseinfo[l].type,a=parseinfo[l].text,o==u&&("!"==a?c=!0:":"!=a&&(c=!1),a=h[a]||a),o==m?(cr=SocialCalc.coordToCr(a),i=SocialCalc.crToCoord(cr.col,cr.row),t[i]&&!c&&(cr=SocialCalc.coordToCr(t[i]),r="$"==a.charAt(0)?"$"+SocialCalc.rcColname(cr.col):SocialCalc.rcColname(cr.col),r+=-1!=a.indexOf("$",1)?"$"+cr.row:cr.row,a=r)):o==p&&(a=a.indexOf('"')>=0?'"'+a.replace(/"/,'""')+'"':'"'+a+'"'),n+=a;return n},SocialCalc.RecalcInfo={sheet:null,currentState:0,state:{idle:0,start_calc:1,order:2,calc:3,start_wait:4,done_wait:5},recalctimer:null,maxtimeslice:100,timeslicedelay:1,starttime:0,queue:[],LoadSheet:function(e){return!1}},SocialCalc.RecalcData=function(){this.inrecalc=!0,this.celllist=[],this.celllistitem=0,this.calclist=null,this.calclistlength=0,this.firstcalc=null,this.lastcalc=null,this.nextcalc=null,this.count=0,this.checkinfo={}},SocialCalc.RecalcCheckInfo=function(){this.oldcoord=null,this.parsepos=0,this.inrange=!1,this.inrangestart=!1,this.cr1=null,this.cr2=null,this.c1=null,this.c2=null,this.r1=null,this.r2=null,this.c=null,this.r=null},SocialCalc.RecalcSheet=function(e){var t=SocialCalc.RecalcInfo;return t.currentState!=t.state.idle?void t.queue.push(e):(delete e.attribs.circularreferencecell,SocialCalc.Formula.FreshnessInfoReset(),SocialCalc.RecalcClearTimeout(),t.sheet=e,t.currentState=t.state.start_calc,t.starttime=new Date,e.statuscallback&&e.statuscallback(t,"calcstart",null,e.statuscallbackparams),void SocialCalc.RecalcSetTimeout())},SocialCalc.RecalcSetTimeout=function(){var e=SocialCalc.RecalcInfo;e.recalctimer=window.setTimeout(SocialCalc.RecalcTimerRoutine,e.timeslicedelay)},SocialCalc.RecalcClearTimeout=function(){var e=SocialCalc.RecalcInfo;e.recalctimer&&(window.clearTimeout(e.recalctimer),e.recalctimer=null)},SocialCalc.RecalcLoadedSheet=function(e,t,o,a){var l,r=SocialCalc.RecalcInfo,i=SocialCalc.Formula;l=SocialCalc.Formula.AddSheetToCache(e||i.SheetCache.waitingForLoading,t,a),o&&l&&"off"!=l.attribs.recalc&&(l.previousrecalcsheet=r.sheet,r.sheet=l,r.currentState=r.state.start_calc),i.SheetCache.waitingForLoading=null,SocialCalc.RecalcSetTimeout()},SocialCalc.RecalcTimerRoutine=function(){var e,t,o,a,l,r=new Date,i=0,n=SocialCalc.Formula;if(!n)return"Need SocialCalc.Formula";var c=SocialCalc.RecalcInfo,s=c.sheet;if(s){var d=s.recalcdata,u=function(e,t){s.statuscallback&&s.statuscallback(d,e,t,s.statuscallbackparams)};if(SocialCalc.RecalcClearTimeout(),c.currentState==c.state.start_calc){d=new SocialCalc.RecalcData,s.recalcdata=d;for(o in s.cells)o&&d.celllist.push(o);d.calclist={},c.currentState=c.state.order}if(c.currentState==c.state.order){for(;d.celllistitem<d.celllist.length;)if(o=d.celllist[d.celllistitem++],a=SocialCalc.RecalcCheckCell(s,o),new Date-r>=c.maxtimeslice)return u("calcorder",{coord:o,total:d.celllist.length,count:d.celllistitem}),void SocialCalc.RecalcSetTimeout();return u("calccheckdone",d.calclistlength),d.nextcalc=d.firstcalc,c.currentState=c.state.calc,void SocialCalc.RecalcSetTimeout()}if(c.currentState==c.state.start_wait){if(c.currentState=c.state.done_wait,c.LoadSheet&&(l=c.LoadSheet(n.SheetCache.waitingForLoading)))return;return void SocialCalc.RecalcLoadedSheet(null,"",!1)}if(c.currentState==c.state.done_wait)return c.currentState=c.state.calc,void SocialCalc.RecalcSetTimeout();for(c.currentState!=c.state.calc&&alert("Recalc state error: "+c.currentState+". Error in SocialCalc code."),o=s.recalcdata.nextcalc;o;){if(t=s.cells[o],e=n.evaluate_parsed_formula(t.parseinfo,s,!1),n.SheetCache.waitingForLoading)return d.nextcalc=o,d.count+=i,u("calcloading",{sheetname:n.SheetCache.waitingForLoading}),c.currentState=c.state.start_wait,void SocialCalc.RecalcSetTimeout();if(n.RemoteFunctionInfo.waitingForServer)return d.nextcalc=o,d.count+=i,u("calcserverfunc",{funcname:n.RemoteFunctionInfo.waitingForServer,coord:o,total:d.calclistlength,count:d.count}),void(c.currentState=c.state.done_wait);if((t.datavalue!=e.value||t.valuetype!=e.type)&&(t.datavalue=e.value,t.valuetype=e.type,delete t.displaystring,s.recalcchangedavalue=!0),e.error&&(t.errors=e.error),i++,o=s.recalcdata.calclist[o],new Date-r>=c.maxtimeslice)return d.nextcalc=o,d.count+=i,u("calcstep",{coord:o,total:d.calclistlength,count:d.count}),void SocialCalc.RecalcSetTimeout()}if(d.inrecalc=!1,delete s.recalcdata,delete s.attribs.needsrecalc,c.sheet=s.previousrecalcsheet||null,c.sheet)return c.currentState=c.state.calc,void SocialCalc.RecalcSetTimeout();n.FreshnessInfo.recalc_completed=!0,c.currentState=c.state.idle,u("calcfinished",new Date-c.starttime),c.queue.length>0&&(s=c.queue.shift(),s.RecalcSheet())}},SocialCalc.RecalcCheckCell=function(e,t){var o,a,l,r,i,n,c,s,d,u,p=SocialCalc.Formula;if(!p)return"Need SocialCalc.Formula";var m=p.TokenType,h=m.op,C=m.name,f=m.coord,S=e.recalcdata,g=S.checkinfo,v=!1,b=null,y=t;e:for(;y;)if(d=e.cells[y],u=g[y],!d||"f"!=d.datatype||u&&"object"!=typeof u)y=b,g[y]&&(b=g[y].oldcoord);else{for(u||(u=new SocialCalc.RecalcCheckInfo,g[y]=u),d.errors&&delete d.errors,d.parseinfo||(d.parseinfo=p.ParseFormulaIntoTokens(d.formula)),o=d.parseinfo,r=u.parsepos;r<o.length;r++){if(u.inrange){if(u.inrangestart&&(u.cr1.col>u.cr2.col?(u.c1=u.cr2.col,u.c2=u.cr1.col):(u.c1=u.cr1.col,u.c2=u.cr2.col),u.c=u.c1-1,u.cr1.row>u.cr2.row?(u.r1=u.cr2.row,u.r2=u.cr1.row):(u.r1=u.cr1.row,u.r2=u.cr2.row),u.r=u.r1,u.inrangestart=!1),u.c+=1,u.c>u.c2){if(u.r+=1,u.r>u.r2){u.inrange=!1;continue}u.c=u.c1}if(i=SocialCalc.crToCoord(u.c,u.r),u.parsepos=r,u.oldcoord=b,b=y,y=i,g[y]&&"object"==typeof g[y])return d.errors=SocialCalc.Constants.s_caccCircRef+t,g[t]=!0,S.firstcalc?S.calclist[S.lastcalc]=t:S.firstcalc=t,S.lastcalc=t,S.calclistlength++,e.attribs.circularreferencecell=y+"|"+b,d.errors;continue e}if(l=o[r].type,a=o[r].text,l==h&&("!"==a?v=!0:":"!=a&&(v=!1)),l==C)if(n=p.LookupName(e,a),"range"==n.type){if(c=n.value.indexOf("|"),-1!=c){u.cr1=SocialCalc.coordToCr(n.value.substring(0,c)),s=n.value.indexOf("|",c+1),u.cr2=SocialCalc.coordToCr(n.value.substring(c+1,s)),u.inrange=!0,u.inrangestart=!0,r-=1;continue}}else"coord"==n.type&&(l=f,a=n.value);if(l==f){if(r>=2&&o[r-1].type==h&&":"==o[r-1].text&&o[r-2].type==f&&!v){u.cr1=SocialCalc.coordToCr(o[r-2].text),u.cr2=SocialCalc.coordToCr(a),u.inrange=!0,u.inrangestart=!0,r-=1;continue}if(!v){if(-1!=a.indexOf("$")&&(a=a.replace(/\$/g,"")),u.parsepos=r+1,u.oldcoord=b,b=y,y=a,g[y]&&"object"==typeof g[y])return d.errors=SocialCalc.Constants.s_caccCircRef+t,g[t]=!0,S.firstcalc?S.calclist[S.lastcalc]=t:S.firstcalc=t,S.lastcalc=t,S.calclistlength++,e.attribs.circularreferencecell=y+"|"+b,d.errors;continue e}}}v=!1,g[y]=!0,S.firstcalc?S.calclist[S.lastcalc]=y:S.firstcalc=y,S.lastcalc=y,S.calclistlength++,y=b,b=g[y]?g[y].oldcoord:null}return""},SocialCalc.Parse=function(e){this.str=e,this.pos=0,this.delimiter=" ",this.lineEnd=e.indexOf("\n"),this.lineEnd<0&&(this.lineEnd=e.length)},SocialCalc.Parse.prototype.NextToken=function(){if(this.pos<0)return"";var e=this.str.indexOf(this.delimiter,this.pos),t=this.pos;return e>this.lineEnd&&(e=this.lineEnd),e>=0?(this.pos=e+1,this.str.substring(t,e)):(this.pos=this.lineEnd,this.str.substring(t,this.lineEnd))},SocialCalc.Parse.prototype.RestOfString=function(){var e=this.pos;return this.pos<0||this.pos>=this.lineEnd?"":(this.pos=this.lineEnd,this.str.substring(e,this.lineEnd))},SocialCalc.Parse.prototype.RestOfStringNoMove=function(){return this.pos<0||this.pos>=this.lineEnd?"":this.str.substring(this.pos,this.lineEnd)},SocialCalc.Parse.prototype.NextLine=function(){this.pos=this.lineEnd+1,this.lineEnd=this.str.indexOf("\n",this.pos),this.lineEnd<0&&(this.lineEnd=this.str.length)},SocialCalc.Parse.prototype.EOF=function(){return this.pos<0||this.pos>=this.str.length?!0:!1},SocialCalc.UndoStack=function(){this.stack=[],this.tos=-1,this.maxRedo=0,this.maxUndo=50},SocialCalc.UndoStack.prototype.PushChange=function(e){for(;this.stack.length>0&&this.stack.length-1>this.tos;)this.stack.pop();this.stack.push({command:[],type:e,undo:[]}),this.maxRedo&&this.stack.length>this.maxRedo&&this.stack.shift(),this.maxUndo&&this.stack.length>this.maxUndo&&(this.stack[this.stack.length-this.maxUndo-1].undo=[]),this.tos=this.stack.length-1},SocialCalc.UndoStack.prototype.AddDo=function(){for(var e=[],t=0;t<arguments.length;t++)null!=arguments[t]&&e.push(arguments[t]);var o=e.join(" ");this.stack[this.stack.length-1].command.push(o)},SocialCalc.UndoStack.prototype.AddUndo=function(){for(var e=[],t=0;t<arguments.length;t++)null!=arguments[t]&&e.push(arguments[t]);var o=e.join(" ");this.stack[this.stack.length-1].undo.push(o)},SocialCalc.UndoStack.prototype.TOS=function(){return this.tos>=0?this.stack[this.tos]:null},SocialCalc.UndoStack.prototype.Undo=function(){return this.tos>=0&&(!this.maxUndo||this.tos>this.stack.length-this.maxUndo-1)?(this.tos-=1,!0):!1},SocialCalc.UndoStack.prototype.Redo=function(){return this.tos<this.stack.length-1?(this.tos+=1,!0):!1},SocialCalc.Clipboard={clipboard:""},SocialCalc.RenderContext=function(e){var t=e.attribs,o=SocialCalc.Constants;if(this.sheetobj=e,this.hideRowsCols=!1,this.showGrid=!1,this.showRCHeaders=!1,this.rownamewidth=o.defaultRowNameWidth,this.pixelsPerRow=o.defaultAssumedRowHeight,this.cellskip={},this.coordToCR={},this.colwidth=[],this.totalwidth=0,this.rowpanes=[],this.colpanes=[],this.colunhideleft=[],this.colunhideright=[],this.rowunhidetop=[],this.rowunhidebottom=[],this.maxcol=0,this.maxrow=0,this.highlights={},this.cursorsuffix="",this.highlightTypes={cursor:{style:o.defaultHighlightTypeCursorStyle,className:o.defaultHighlightTypeCursorClass},range:{style:o.defaultHighlightTypeRangeStyle,className:o.defaultHighlightTypeRangeClass},cursorinsertup:{style:"color:#FFF;backgroundColor:#A6A6A6;backgroundRepeat:repeat-x;backgroundPosition:top left;backgroundImage:url("+o.defaultImagePrefix+"cursorinsertup.gif);",className:o.defaultHighlightTypeCursorClass},cursorinsertleft:{style:"color:#FFF;backgroundColor:#A6A6A6;backgroundRepeat:repeat-y;backgroundPosition:top left;backgroundImage:url("+o.defaultImagePrefix+"cursorinsertleft.gif);",className:o.defaultHighlightTypeCursorClass},range2:{style:"color:#000;backgroundColor:#FFF;backgroundImage:url("+o.defaultImagePrefix+"range2.gif);",className:""}},this.cellIDprefix=o.defaultCellIDPrefix,this.defaultlinkstyle=null,this.defaultHTMLlinkstyle={type:"html"},this.defaultfontstyle=o.defaultCellFontStyle,this.defaultfontsize=o.defaultCellFontSize,this.defaultfontfamily=o.defaultCellFontFamily,this.defaultlayout=o.defaultCellLayout,this.defaultpanedividerwidth=o.defaultPaneDividerWidth,this.defaultpanedividerheight=o.defaultPaneDividerHeight,this.gridCSS=o.defaultGridCSS,this.commentClassName=o.defaultCommentClass,this.commentCSS=o.defaultCommentStyle,this.commentNoGridClassName=o.defaultCommentNoGridClass,this.commentNoGridCSS=o.defaultCommentNoGridStyle,this.readonlyClassName=o.defaultReadonlyClass,this.readonlyCSS=o.defaultReadonlyStyle,this.readonlyNoGridClassName=o.defaultReadonlyNoGridClass,this.readonlyNoGridCSS=o.defaultReadonlyNoGridStyle,this.readonlyComment=o.defaultReadonlyComment,this.classnames={colname:o.defaultColnameClass,rowname:o.defaultRownameClass,selectedcolname:o.defaultSelectedColnameClass,selectedrowname:o.defaultSelectedRownameClass,upperleft:o.defaultUpperLeftClass,skippedcell:o.defaultSkippedCellClass,panedivider:o.defaultPaneDividerClass,unhideleft:o.defaultUnhideLeftClass,unhideright:o.defaultUnhideRightClass,unhidetop:o.defaultUnhideTopClass,unhidebottom:o.defaultUnhideBottomClass},this.explicitStyles={colname:o.defaultColnameStyle,rowname:o.defaultRownameStyle,selectedcolname:o.defaultSelectedColnameStyle,selectedrowname:o.defaultSelectedRownameStyle,upperleft:o.defaultUpperLeftStyle,skippedcell:o.defaultSkippedCellStyle,panedivider:o.defaultPaneDividerStyle,unhideleft:o.defaultUnhideLeftStyle,unhideright:o.defaultUnhideRightStyle,unhidetop:o.defaultUnhideTopStyle,unhidebottom:o.defaultUnhideBottomStyle},this.cellskip=null,this.needcellskip=!0,this.fonts=[],this.layouts=[],this.needprecompute=!0,!t)throw o.s_rcMissingSheet;this.rowpanes[0]={first:1,last:t.lastrow},this.colpanes[0]={first:1,last:t.lastcol},this.usermaxcol=t.usermaxcol,this.usermaxrow=t.usermaxrow},SocialCalc.RenderContext.prototype.PrecomputeSheetFontsAndLayouts=function(){SocialCalc.PrecomputeSheetFontsAndLayouts(this)},SocialCalc.RenderContext.prototype.CalculateCellSkipData=function(){SocialCalc.CalculateCellSkipData(this)},SocialCalc.RenderContext.prototype.CalculateColWidthData=function(){SocialCalc.CalculateColWidthData(this)},SocialCalc.RenderContext.prototype.SetRowPaneFirstLast=function(e,t,o){this.rowpanes[e]={first:t,last:o}},SocialCalc.RenderContext.prototype.SetColPaneFirstLast=function(e,t,o){this.colpanes[e]={first:t,last:o}},SocialCalc.RenderContext.prototype.CoordInPane=function(e,t,o){return SocialCalc.CoordInPane(this,e,t,o)},SocialCalc.RenderContext.prototype.CellInPane=function(e,t,o,a){return SocialCalc.CellInPane(this,e,t,o,a)},SocialCalc.RenderContext.prototype.InitializeTable=function(e){SocialCalc.InitializeTable(this,e)},SocialCalc.RenderContext.prototype.RenderSheet=function(e,t){return SocialCalc.RenderSheet(this,e,t)},SocialCalc.RenderContext.prototype.RenderColGroup=function(){return SocialCalc.RenderColGroup(this)},SocialCalc.RenderContext.prototype.RenderColHeaders=function(){return SocialCalc.RenderColHeaders(this)},SocialCalc.RenderContext.prototype.RenderSizingRow=function(){return SocialCalc.RenderSizingRow(this)},SocialCalc.RenderContext.prototype.RenderRow=function(e,t,o){return SocialCalc.RenderRow(this,e,t,o)},SocialCalc.RenderContext.prototype.RenderSpacingRow=function(){return SocialCalc.RenderSpacingRow(this)},SocialCalc.RenderContext.prototype.RenderCell=function(e,t,o,a,l,r){return SocialCalc.RenderCell(this,e,t,o,a,l,r)},SocialCalc.PrecomputeSheetFontsAndLayouts=function(e){var t,o,a,l,r,i,n,c,s=e.sheetobj,d=s.attribs;for(d.defaultfont&&(t=s.fonts[d.defaultfont],t=t.replace(/^\*/,SocialCalc.Constants.defaultCellFontStyle),t=t.replace(/(.+)\*(.+)/,"$1"+SocialCalc.Constants.defaultCellFontSize+"$2"),t=t.replace(/\*$/,SocialCalc.Constants.defaultCellFontFamily),o=t.match(/^(\S+? \S+?) (\S+?) (\S.*)$/),e.defaultfontstyle=o[1],e.defaultfontsize=o[2],e.defaultfontfamily=o[3]),i=1;i<s.fonts.length;i++)n=s.fonts[i],n=n.replace(/^\*/,e.defaultfontstyle),n=n.replace(/(.+)\*(.+)/,"$1"+e.defaultfontsize+"$2"),n=n.replace(/\*$/,e.defaultfontfamily),o=n.match(/^(\S+?) (\S+?) (\S+?) (\S.*)$/),e.fonts[i]={style:o[1],weight:o[2],size:o[3],family:o[4]};for(a=/^padding:\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+);vertical-align:\s*(\S+);/,l=SocialCalc.Constants.defaultCellLayout.match(a),r=d.defaultlayout?s.layouts[d.defaultlayout].match(a):["","*","*","*","*","*"],i=1;i<s.layouts.length;i++){for(n=s.layouts[i],o=n.match(a),c=1;5>=c;c++)"*"==o[c]&&(o[c]="*"!=r[c]?r[c]:l[c]);e.layouts[i]="padding:"+o[1]+" "+o[2]+" "+o[3]+" "+o[4]+";vertical-align:"+o[5]+";"}e.needprecompute=!1},SocialCalc.CalculateCellSkipData=function(e){var t,o,a,l,r,i,n,c,s,d=e.sheetobj;d.rowattribs,d.colattribs;for(e.maxrow=0,e.maxcol=0,e.cellskip={},t=1;t<=d.attribs.lastrow;t++)for(o=1;o<=d.attribs.lastcol;o++)if(a=SocialCalc.crToCoord(o,t),l=d.cells[a],void 0!==l&&!e.cellskip[a]&&(r=l.colspan||1,i=l.rowspan||1,r>1||i>1))for(n=t;t+i>n;n++)for(c=o;o+r>c;c++)s=SocialCalc.crToCoord(c,n),s==a?e.coordToCR[a]={row:t,col:o}:e.cellskip[s]=a,n>e.maxrow&&(maxrow=n),c>e.maxcol&&(maxcol=c);e.needcellskip=!1},SocialCalc.CalculateColWidthData=function(e){var t,o,a,l,r=e.sheetobj;r.colattribs;for(l=e.showRCHeaders?e.rownamewidth-0:0,colpane=0;colpane<e.colpanes.length;colpane++)for(t=e.colpanes[colpane].first;t<=e.colpanes[colpane].last;t++)o=SocialCalc.rcColname(t),"yes"==r.colattribs.hide[o]?e.colwidth[t]=0:(a=r.colattribs.width[o]||r.attribs.defaultcolwidth||SocialCalc.Constants.defaultColWidth,("blank"==a||"auto"==a)&&(a=""),e.colwidth[t]=a+"",l+=a&&a-0>0?a-0:10);e.totalwidth=l},SocialCalc.InitializeTable=function(e,t){t.style.borderCollapse="collapse",t.cellSpacing="0",t.cellPadding="0",t.style.width=e.totalwidth+"px"},SocialCalc.RenderSheet=function(e,t,o){var a,l,r,i,n,c;for(e.sheetobj.changedrendervalues&&(e.needcellskip=!0,e.needprecompute=!0,e.sheetobj.changedrendervalues=!1),e.needcellskip&&e.CalculateCellSkipData(),e.needprecompute&&e.PrecomputeSheetFontsAndLayouts(),e.CalculateColWidthData(),r=document.createElement("table"),e.InitializeTable(r),i=e.RenderColGroup(),r.appendChild(i),n=document.createElement("tbody"),n.appendChild(e.RenderSizingRow()),e.showRCHeaders&&(a=e.RenderColHeaders(),a&&n.appendChild(a)),l=0;l<e.rowpanes.length;l++){for(rownum=e.rowpanes[l].first;rownum<=e.rowpanes[l].last;rownum++)a=e.RenderRow(rownum,l,o),n.appendChild(a);l<e.rowpanes.length-1&&(a=e.RenderSpacingRow(),n.appendChild(a))}return r.appendChild(n),t&&(c=t.parentNode,c&&c.replaceChild(r,t)),r},SocialCalc.RenderRow=function(e,t,o,a){var l,r,i,n,c=e.sheetobj,s=document.createElement("tr");if(e.showRCHeaders){if(r=document.createElement("td"),e.classnames&&(r.className=e.classnames.rowname),e.explicitStyles&&(r.style.cssText=e.explicitStyles.rowname),r.width=e.rownamewidth,r.style.verticalAlign="top",r.innerHTML=t+"",t<e.rowpanes[e.rowpanes.length-1].last&&"yes"==c.rowattribs.hide[t+1]){var d=document.createElement("div");d.style.position="relative";var u=document.createElement("div");e.classnames&&(u.className=e.classnames.unhidetop),e.explicitStyles&&(u.style.cssText=e.explicitStyles.unhidetop),e.rowunhidetop[t]=u,d.appendChild(u),r.appendChild(d)}if(t>1&&"yes"==c.rowattribs.hide[t-1]){var u=document.createElement("div");e.classnames&&(u.className=e.classnames.unhidebottom),e.explicitStyles&&(u.style.cssText=e.explicitStyles.unhidebottom),e.rowunhidebottom[t]=u,r.appendChild(u)}s.appendChild(r)}for(i=0;i<e.colpanes.length;i++){for(l=e.colpanes[i].first;l<=e.colpanes[i].last;l++)r=e.RenderCell(t,l,o,i,null,a),r&&s.appendChild(r);
i<e.colpanes.length-1&&(r=document.createElement("td"),r.width=e.defaultpanedividerwidth,e.classnames.panedivider&&(r.className=e.classnames.panedivider),e.explicitStyles.panedivider&&(r.style.cssText=e.explicitStyles.panedivider),n=document.createElement("div"),n.style.width=e.defaultpanedividerwidth+"px",n.style.overflow="hidden",r.appendChild(n),s.appendChild(r))}return"yes"==c.rowattribs.hide[t]&&(s.style.cssText+=";display:none"),s},SocialCalc.RenderSpacingRow=function(e){var t,o,a,l,r=(e.sheetobj,document.createElement("tr"));for(e.showRCHeaders&&(o=document.createElement("td"),o.width=e.rownamewidth,o.height=e.defaultpanedividerheight,e.classnames.panedivider&&(o.className=e.classnames.panedivider),e.explicitStyles.panedivider&&(o.style.cssText=e.explicitStyles.panedivider),r.appendChild(o)),a=0;a<e.colpanes.length;a++){for(t=e.colpanes[a].first;t<=e.colpanes[a].last;t++)o=document.createElement("td"),l=e.colwidth[t],l&&(o.width=l),o.height=e.defaultpanedividerheight,e.classnames.panedivider&&(o.className=e.classnames.panedivider),e.explicitStyles.panedivider&&(o.style.cssText=e.explicitStyles.panedivider),o&&r.appendChild(o);a<e.colpanes.length-1&&(o=document.createElement("td"),o.width=e.defaultpanedividerwidth,o.height=e.defaultpanedividerheight,e.classnames.panedivider&&(o.className=e.classnames.panedivider),e.explicitStyles.panedivider&&(o.style.cssText=e.explicitStyles.panedivider),r.appendChild(o))}return r},SocialCalc.RenderColHeaders=function(e){var t,o,a=e.sheetobj,l=document.createElement("tr");if(!e.showRCHeaders)return null;for(o=document.createElement("td"),e.classnames&&(o.className=e.classnames.upperleft),e.explicitStyles&&(o.style.cssText=e.explicitStyles.upperleft),o.width=e.rownamewidth,l.appendChild(o),colpane=0;colpane<e.colpanes.length;colpane++){for(t=e.colpanes[colpane].first;t<=e.colpanes[colpane].last;t++){if(o=document.createElement("td"),e.classnames&&(o.className=e.classnames.colname),e.explicitStyles&&(o.style.cssText=e.explicitStyles.colname),"yes"==a.colattribs.hide[SocialCalc.rcColname(t)]&&(o.style.cssText+=";display:none"),o.innerHTML=SocialCalc.rcColname(t),t<e.colpanes[e.colpanes.length-1].last&&"yes"==a.colattribs.hide[SocialCalc.rcColname(t+1)]){var r=document.createElement("div");e.classnames&&(r.className=e.classnames.unhideleft),e.explicitStyles&&(r.style.cssText=e.explicitStyles.unhideleft),e.colunhideleft[t]=r,o.appendChild(r)}t>1&&"yes"==a.colattribs.hide[SocialCalc.rcColname(t-1)]&&(r=document.createElement("div"),e.classnames&&(r.className=e.classnames.unhideright),e.explicitStyles&&(r.style.cssText=e.explicitStyles.unhideright),e.colunhideright[t]=r,o.appendChild(r)),l.appendChild(o)}colpane<e.colpanes.length-1&&(o=document.createElement("td"),o.width=e.defaultpanedividerwidth,e.classnames.panedivider&&(o.className=e.classnames.panedivider),e.explicitStyles.panedivider&&(o.style.cssText=e.explicitStyles.panedivider),l.appendChild(o))}return l},SocialCalc.RenderColGroup=function(e){var t,o,a,l,r=e.sheetobj,i=document.createElement("colgroup");for(e.showRCHeaders&&(a=document.createElement("col"),a.width=e.rownamewidth,i.appendChild(a)),t=0;t<e.colpanes.length;t++){for(o=e.colpanes[t].first;o<=e.colpanes[t].last;o++)a=document.createElement("col"),"yes"==r.colattribs.hide[SocialCalc.rcColname(o)]?a.width="1":(l=e.colwidth[o],l&&(a.width=l),i.appendChild(a));t<e.colpanes.length-1&&(a=document.createElement("col"),a.width=e.defaultpanedividerwidth,i.appendChild(a))}return i},SocialCalc.RenderSizingRow=function(e){var t,o,a,l,r=e.sheetobj,i=document.createElement("tr");for(e.showRCHeaders&&(a=document.createElement("td"),a.style.width=e.rownamewidth+"px",a.height="1",i.appendChild(a)),t=0;t<e.colpanes.length;t++){for(o=e.colpanes[t].first;o<=e.colpanes[t].last;o++)a=document.createElement("td"),"yes"==r.colattribs.hide[SocialCalc.rcColname(o)]?a.width="1":(l=e.colwidth[o],l&&(a.width=l)),a.height="1",i.appendChild(a);t<e.colpanes.length-1&&(a=document.createElement("td"),a.width=e.defaultpanedividerwidth,a.height="1",i.appendChild(a))}return i},SocialCalc.RenderCell=function(e,t,o,a,l,r,i){var n,c,s,d,u,p,m,h=e.sheetobj,C="";t-=0,o-=0;var f=SocialCalc.crToCoord(o,t);if(e.cellskip[f])return e.CoordInPane(e.cellskip[f],a,l)?null:(s=r?SocialCalc.CreatePseudoElement():document.createElement("td"),e.classnames.skippedcell&&(s.className=e.classnames.skippedcell),e.explicitStyles.skippedcell&&(s.style.cssText=e.explicitStyles.skippedcell),s.innerHTML=" ",s);if(s=r?SocialCalc.CreatePseudoElement():document.createElement("td"),e.cellIDprefix&&(s.id=e.cellIDprefix+f),u=h.cells[f],u||(u=new SocialCalc.Cell(f)),m=h.attribs,scc=SocialCalc.Constants,u.colspan>1){for(d=1,n=1;n<u.colspan;n++)"yes"!=h.colattribs.hide[SocialCalc.rcColname(o+n)]&&e.CellInPane(t,o+n,a,l)&&d++;s.colSpan=d}if(u.rowspan>1){for(d=1,n=1;n<u.rowspan;n++)"yes"!=h.rowattribs.hide[t+n+""]&&e.CellInPane(t+n,o,a,l)&&d++;s.rowSpan=d}return void 0==u.displaystring&&(u.displaystring=SocialCalc.FormatValueForDisplay(h,u.datavalue,f,i||e.defaultlinkstyle)),s.innerHTML=u.displaystring,n=u.layout||m.defaultlayout,C+=n&&"undefined"!=typeof e.layouts[n]?e.layouts[n]:scc.defaultCellLayout,n=u.font||m.defaultfont,n&&"undefined"!=typeof e.fonts[n]?(c=e.fonts[n],C+="font-style:"+c.style+";font-weight:"+c.weight+";font-size:"+c.size+";font-family:"+c.family+";"):(scc.defaultCellFontSize&&(C+="font-size:"+scc.defaultCellFontSize+";"),scc.defaultCellFontFamily&&(C+="font-family:"+scc.defaultCellFontFamily+";")),n=u.color||m.defaultcolor,n&&"undefined"!=typeof h.colors[n]&&(C+="color:"+h.colors[n]+";"),n=u.bgcolor||m.defaultbgcolor,n&&"undefined"!=typeof h.colors[n]&&(C+="background-color:"+h.colors[n]+";"),n=u.cellformat,n&&"undefined"!=typeof h.cellformats[n]?C+="text-align:"+h.cellformats[n]+";":(c=u.valuetype.charAt(0),"t"==c?(n=m.defaulttextformat,n&&"undefined"!=typeof h.cellformats[n]&&(C+="text-align:"+h.cellformats[n]+";")):"n"==c?(n=m.defaultnontextformat,C+=n&&"undefined"!=typeof h.cellformats[n]?"text-align:"+h.cellformats[n]+";":"text-align:right;"):C+="text-align:left;"),(u.colspan>1||u.rowspan>1)&&(p=h.cells[SocialCalc.crToCoord(o+(u.colspan||1)-1,t+(u.rowspan||1)-1)]),n=u.bt,n&&"undefined"!=typeof h.borderstyles[n]&&(C+="border-top:"+h.borderstyles[n]+";"),n="undefined"!=typeof p?p.br:u.br,n&&"undefined"!=typeof h.borderstyles[n]?C+="border-right:"+h.borderstyles[n]+";":e.showGrid&&(c=e.CellInPane(t,o+(u.colspan||1),a,l)?SocialCalc.crToCoord(o+(u.colspan||1),t):"nomatch",e.cellskip[c]&&(c=e.cellskip[c]),h.cells[c]&&h.cells[c].bl||(C+="border-right:"+e.gridCSS)),n="undefined"!=typeof p?p.bb:u.bb,n&&"undefined"!=typeof h.borderstyles[n]?C+="border-bottom:"+h.borderstyles[n]+";":e.showGrid&&(c=e.CellInPane(t+(u.rowspan||1),o,a,l)?SocialCalc.crToCoord(o,t+(u.rowspan||1)):"nomatch",e.cellskip[c]&&(c=e.cellskip[c]),h.cells[c]&&h.cells[c].bt||(C+="border-bottom:"+e.gridCSS)),n=u.bl,n&&"undefined"!=typeof h.borderstyles[n]&&(C+="border-left:"+h.borderstyles[n]+";"),u.comment&&(s.title=u.comment,e.showGrid?(e.commentClassName&&(s.className=(s.className?s.className+" ":"")+e.commentClassName),C+=e.commentCSS):(e.commentNoGridClassName&&(s.className=(s.className?s.className+" ":"")+e.commentNoGridClassName),C+=e.commentNoGridCSS)),u.readonly&&(u.comment||(s.title=e.readonlyComment),e.showGrid?(e.readonlyClassName&&(s.className=(s.className?s.className+" ":"")+e.readonlyClassName),C+=e.readonlyCSS):(e.readonlyNoGridClassName&&(s.className=(s.className?s.className+" ":"")+e.readonlyNoGridClassName),C+=e.readonlyNoGridCSS)),s.style.cssText=C,c=e.highlights[f],c&&("cursor"==c&&(c+=e.cursorsuffix),e.highlightTypes[c].className&&(s.className=(s.className?s.className+" ":"")+e.highlightTypes[c].className),SocialCalc.setStyles(s,e.highlightTypes[c].style)),"yes"==h.colattribs.hide[SocialCalc.rcColname(o)]&&(s.style.cssText+=";display:none"),"yes"==h.rowattribs.hide[t]&&(s.style.cssText+=";display:none"),s},SocialCalc.CoordInPane=function(e,t,o,a){var l=e.coordToCR[t];if(!l||!l.row||!l.col)throw"Bad coordToCR for "+t;return e.CellInPane(l.row,l.col,o,a)},SocialCalc.CellInPane=function(e,t,o,a,l){var r=e.rowpanes[a],i=e.colpanes[l];if(!r||!i)throw"CellInPane called with unknown panes "+a+"/"+l;return t<r.first||t>r.last?!1:o<i.first||o>i.last?!1:!0},SocialCalc.CreatePseudoElement=function(){return{style:{cssText:""},innerHTML:"",className:""}},SocialCalc.rcColname=function(e){e>702&&(e=702),1>e&&(e=1);var t=(e-1)%26+65,o=Math.floor((e-1)/26);return o?String.fromCharCode(o+64)+String.fromCharCode(t):String.fromCharCode(t)},SocialCalc.letters=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],SocialCalc.crToCoord=function(e,t){var o;1>e&&(e=1),e>702&&(e=702),1>t&&(t=1);var a=(e-1)%26,l=Math.floor((e-1)/26);return o=l?SocialCalc.letters[l-1]+SocialCalc.letters[a]+t:SocialCalc.letters[a]+t},SocialCalc.coordToCol={},SocialCalc.coordToRow={},SocialCalc.coordToCr=function(e){var t,o,a,l=SocialCalc.coordToRow[e];if(l)return{row:l,col:SocialCalc.coordToCol[e]};for(t=0,l=0,o=0;o<e.length;o++)a=e.charCodeAt(o),36==a||(57>=a?l=10*l+a-48:a>=97?t=26*t+a-96:a>=65&&(t=26*t+a-64));return SocialCalc.coordToCol[e]=t,SocialCalc.coordToRow[e]=l,{row:l,col:t}},SocialCalc.ParseRange=function(e){var t,o,a,l;return e||(e="A1:A1"),e=e.toUpperCase(),t=e.indexOf(":"),t>=0?(o=e.substring(0,t),a=SocialCalc.coordToCr(o),a.coord=o,o=e.substring(t+1),l=SocialCalc.coordToCr(o),l.coord=o):(a=SocialCalc.coordToCr(e),a.coord=e,l=SocialCalc.coordToCr(e),l.coord=e),{cr1:a,cr2:l}},SocialCalc.decodeFromSave=function(e){if("string"!=typeof e)return e;if(-1==e.indexOf("\\"))return e;var t=e.replace(/\\c/g,":");return t=t.replace(/\\n/g,"\n"),t.replace(/\\b/g,"\\")},SocialCalc.decodeFromAjax=function(e){if("string"!=typeof e)return e;if(-1==e.indexOf("\\"))return e;var t=e.replace(/\\c/g,":");return t=t.replace(/\\n/g,"\n"),t=t.replace(/\\e/g,"]]"),t.replace(/\\b/g,"\\")},SocialCalc.encodeForSave=function(e){return"string"!=typeof e?e:(-1!=e.indexOf("\\")&&(e=e.replace(/\\/g,"\\b")),-1!=e.indexOf(":")&&(e=e.replace(/:/g,"\\c")),-1!=e.indexOf("\n")&&(e=e.replace(/\n/g,"\\n")),e)},SocialCalc.special_chars=function(e){return/[&<>"]/.test(e)&&(e=e.replace(/&/g,"&"),e=e.replace(/</g,"<"),e=e.replace(/>/g,">"),e=e.replace(/"/g,""")),e},SocialCalc.Lookup=function(e,t){for(i=0;i<t.length;i++)if(t[i]>e)return i>0?i-1:null;return t.length-1},SocialCalc.setStyles=function(e,t){var o,a,l,r,i;if(t)for(o=t.split(";"),a=0;a<o.length;a++)l=o[a].indexOf(":"),-1!=l&&(r=o[a].substring(0,l),i=o[a].substring(l+1),r&&i&&(e.style[r]=i))},SocialCalc.GetViewportInfo=function(){var e={};return window.innerWidth?(e.width=window.innerWidth,e.height=window.innerHeight,e.horizontalScroll=window.pageXOffset,e.verticalScroll=window.pageYOffset):document.documentElement&&document.documentElement.clientWidth?(e.width=document.documentElement.clientWidth,e.height=document.documentElement.clientHeight,e.horizontalScroll=document.documentElement.scrollLeft,e.verticalScroll=document.documentElement.scrollTop):document.body.clientWidth&&(e.width=document.body.clientWidth,e.height=document.body.clientHeight,e.horizontalScroll=document.body.scrollLeft,e.verticalScroll=document.body.scrollTop),e},SocialCalc.GetElementPosition=function(e){for(var t=0,o=0;e&&"relative"!=SocialCalc.GetComputedStyle(e,"position");)t+=e.offsetLeft,o+=e.offsetTop,e=e.offsetParent;return{left:t,top:o}},SocialCalc.GetElementPositionWithScroll=function(e){var t=e.getBoundingClientRect();return{left:t.left,right:t.right,top:t.top,bottom:t.bottom,width:t.width?t.width:t.right-t.left,height:t.height?t.height:t.bottom-t.top}},SocialCalc.GetElementFixedParent=function(e){for(;e&&"HTML"!=e.tagName;){if("fixed"==SocialCalc.GetComputedStyle(e,"position"))return e;e=e.parentNode}return!1},SocialCalc.GetComputedStyle=function(e,t){var o;return o="undefined"!=typeof e.currentStyle?e.currentStyle:document.defaultView.getComputedStyle(e,null),o[t]},SocialCalc.LookupElement=function(e,t){var o;for(o=0;o<t.length;o++)if(t[o].element==e)return t[o];return null},SocialCalc.AssignID=function(e,t,o){e.idPrefix&&(t.id=e.idPrefix+o)},SocialCalc.GetCellContents=function(e,t){var o="",a=e.cells[t];if(a)switch(a.datatype){case"v":o=a.datavalue+"";break;case"t":o="'"+a.datavalue;break;case"f":o="="+a.formula;break;case"c":o=a.formula}return o},SocialCalc.FormatValueForDisplay=function(e,t,o,a){var l,r,i,n,c=e.attribs,s=(SocialCalc.Constants,e.cells[o]);if(s||(s=new SocialCalc.Cell(o)),n=t,r=s.valuetype||"",i=r.substring(1),r=r.charAt(0),s.errors||"e"==r)return n=s.errors||i||"Error in cell";if("t"==r){if(l=e.valueformats[s.textvalueformat-0]||e.valueformats[c.defaulttextvalueformat-0]||"","formula"==l)return n="f"==s.datatype?SocialCalc.special_chars("="+s.formula)||" ":"c"==s.datatype?SocialCalc.special_chars("'"+s.formula)||" ":SocialCalc.special_chars("'"+n)||" ";n=SocialCalc.format_text_for_display(n,s.valuetype,l,e,a,s.nontextvalueformat)}else if("n"==r){if(l=s.nontextvalueformat,(null==l||""==l)&&(l=c.defaultnontextvalueformat),l=e.valueformats[l-0],(null==l||"none"==l)&&(l=""),"formula"==l)return n="f"==s.datatype?SocialCalc.special_chars("="+s.formula)||" ":"c"==s.datatype?SocialCalc.special_chars("'"+s.formula)||" ":SocialCalc.special_chars("'"+n)||" ";if("forcetext"==l)return n="f"==s.datatype?SocialCalc.special_chars("="+s.formula)||" ":"c"==s.datatype?SocialCalc.special_chars(s.formula)||" ":SocialCalc.special_chars(n)||" ";n=SocialCalc.format_number_for_display(n,s.valuetype,l)}else n=" ";return n},SocialCalc.format_text_for_display=function(e,t,o,a,l,r){var o,i,n,c,s,d;return i=t.substring(1),d=e,("none"==o||null==o)&&(o=""),/^(text-|custom|hidden)/.test(o)||(o=""),(""==o||"General"==o)&&("h"==i&&(o="text-html"),("w"==i||"r"==i)&&(o="text-wiki"),"l"==i&&(o="text-link"),i||(o="text-plain")),"text-html"==o||(SocialCalc.Callbacks.expand_wiki&&/^text-wiki/.test(o)?d=SocialCalc.Callbacks.expand_wiki(d,a,l,o):"text-wiki"==o?d=SocialCalc.Callbacks.expand_markup&&SocialCalc.Callbacks.expand_markup(d,a,l)||SocialCalc.special_chars("wiki-text:"+d):"text-url"==o?(n=SocialCalc.special_chars(d),c=encodeURI(d),d='<a href="'+c+'">'+n+"</a>"):"text-link"==o?d=SocialCalc.expand_text_link(d,a,l,o):"text-image"==o?(c=encodeURI(d),d='<img src="'+c+'">'):"text-custom:"==o.substring(0,12)?(n=SocialCalc.special_chars(d),n=n.replace(/ /g," "),n=n.replace(/\n/g,"<br>"),c=encodeURI(d),s={},s.r=d,s.s=n,s.u=c,d=o.substring(12),d=d.replace(/@(r|s|u)/g,function(e,t){return s[t]})):"custom"==o.substring(0,6)?(d=SocialCalc.special_chars(d),d=d.replace(/ /g," "),d=d.replace(/\n/g,"<br>"),d+=" (custom format)"):"hidden"==o?d=" ":null!=r&&""!=r&&"none"!=a.valueformats[r-0]&&""!=a.valueformats[r-0]?(o=a.valueformats[r],d=SocialCalc.format_number_for_display(e,t,o)):(d=SocialCalc.special_chars(d),d=d.replace(/ /g," "),d=d.replace(/\n/g,"<br>"))),d},SocialCalc.format_number_for_display=function(e,t,o){var a,l,r=SocialCalc.Constants;return a=e-0,l=t.substring(1),("Auto"==o||""==o)&&(o="%"==l?r.defaultFormatp:"$"==l?r.defaultFormatc:"dt"==l?r.defaultFormatdt:"d"==l?r.defaultFormatd:"t"==l?r.defaultFormatt:"l"==l?"logical":"General"),"logical"==o?a?r.defaultDisplayTRUE:r.defaultDisplayFALSE:"hidden"==o?" ":SocialCalc.FormatNumber.formatNumberWithFormat(e,o,"")},SocialCalc.DetermineValueType=function(e){var t,o,a,l,r,i,n,c,s,d,u=e+"",p="t";return t=u.replace(/^\s+/,""),t=t.replace(/\s+$/,""),0==u.length?p="":u.match(/^\s+$/)||(t.match(/^[-+]?\d*(?:\.)?\d*(?:[eE][-+]?\d+)?$/)?(u=t-0,isNaN(u)?u=e+"":p="n"):t.match(/^[-+]?\d*(?:\.)?\d*\s*%$/)?(u=(t.slice(0,-1)-0)/100,p="n%"):t.match(/^[-+]?\$\s*\d*(?:\.)?\d*\s*$/)&&t.match(/\d/)?(u=t.replace(/\$/,"")-0,p="n$"):t.match(/^[-+]?(\d*,\d*)+(?:\.)?\d*$/)?(u=t.replace(/,/g,"")-0,p="n"):t.match(/^[-+]?(\d*,\d*)+(?:\.)?\d*\s*%$/)?(u=(t.replace(/[%,]/g,"")-0)/100,p="n%"):t.match(/^[-+]?\$\s*(\d*,\d*)+(?:\.)?\d*$/)&&t.match(/\d/)?(u=t.replace(/[\$,]/g,"")-0,p="n$"):(o=u.match(/^(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{1,4})\s*$/))?(a=o[3]-0,a=1e3>a?a+2e3:a,u=SocialCalc.FormatNumber.convert_date_gregorian_to_julian(a,o[1]-0,o[2]-0)-2415019,p="nd"):(o=u.match(/^(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})\s*$/))?(a=o[1]-0,a=1e3>a?a+2e3:a,u=SocialCalc.FormatNumber.convert_date_gregorian_to_julian(a,o[2]-0,o[3]-0)-2415019,p="nd"):(o=u.match(/^(\d{1,2}):(\d{1,2})\s*$/))?(l=o[1]-0,r=o[2]-0,24>l&&60>r&&(u=l/24+r/1440,p="nt")):(o=u.match(/^(\d{1,2}):(\d{1,2}):(\d{1,2})\s*$/))?(l=o[1]-0,r=o[2]-0,i=o[3]-0,24>l&&60>r&&60>i&&(u=l/24+r/1440+i/86400,p="nt")):(o=u.match(/^\s*([-+]?\d+) (\d+)\/(\d+)\s*$/))?(s=o[1]-0,c=o[2]-0,n=o[3]-0,n&&n>0&&(u=s+(0>s?-c/n:c/n),p="n")):(d=SocialCalc.InputConstants[u.toUpperCase()])?(c=d.indexOf(","),u=d.substring(0,c)-0,p=d.substring(c+1)):t.length>7&&"http://"==t.substring(0,7).toLowerCase()?(u=t,p="tl"):t.match(/<([A-Z][A-Z0-9]*)\b[^>]*>[\s\S]*?<\/\1>/i)&&(u=t,p="th")),{value:u,type:p}},SocialCalc.InputConstants={TRUE:"1,nl",FALSE:"0,nl","#N/A":"0,e#N/A","#NULL!":"0,e#NULL!","#NUM!":"0,e#NUM!","#DIV/0!":"0,e#DIV/0!","#VALUE!":"0,e#VALUE!","#REF!":"0,e#REF!","#NAME?":"0,e#NAME?"},SocialCalc.default_expand_markup=function(e,t,o){var a=e;return a=SocialCalc.special_chars(a),a=a.replace(/ /g," "),a=a.replace(/\n/g,"<br>")},SocialCalc.expand_text_link=function(e,t,o,a){var l,r,i,n=SocialCalc.Constants,c="",s=SocialCalc.ParseCellLinkText(e+"");return l=s.desc?SocialCalc.special_chars(s.desc):s.pagename?n.defaultPageLinkFormatString:n.defaultLinkFormatString,e.length>7&&"http://"==e.substring(0,7).toLowerCase()&&">"!=e.charAt(e.length-1)&&(l=l.substring(7)),r=s.newwin||!o?' target="_blank"':"",s.pagename?SocialCalc.Callbacks.MakePageLink&&(c=SocialCalc.Callbacks.MakePageLink(s.pagename,s.workspacename,o,a)):c=encodeURI(s.url),i='<a href="'+c+'"'+r+">"+l+"</a>"},SocialCalc.ParseCellLinkText=function(e){var t={url:"",desc:"",newwin:!1,pagename:"",workspace:""},o=!1,a=e.length-1,l=0,r=e.lastIndexOf("<"),i=e.lastIndexOf("["),n=e.lastIndexOf("{"),c=-1;return">"==e.charAt(a)&&-1!=r||"]"==e.charAt(a)&&-1!=i||!("}"!=e.charAt(a)||"]"!=e.charAt(a-1)||-1==n||-1==i||n>i)?(">"==e.charAt(a)?(c=r-1,r>0&&"<"==e.charAt(c)&&">"==e.charAt(a-1)&&(c--,a--,t.newwin=!0)):"]"==e.charAt(a)?(c=i-1,o=!0,i>0&&"["==e.charAt(c)&&"]"==e.charAt(a-1)&&(c--,a--,t.newwin=!0)):"}"==e.charAt(a)&&(c=n-1,o=!0,wsend=i,a--,i>0&&"["==e.charAt(i-1)&&"]"==e.charAt(a-1)&&(wsend=i-1,a--,t.newwin=!0)," "==e.charAt(wsend-1)&&wsend--,t.workspace=e.substring(n+1,wsend)||"")," "==e.charAt(c)&&c--,'"'==e.charAt(l)&&'"'==e.charAt(c)&&(l++,c--)):(a++,c=a),o?t.pagename=e.substring(i+1,a)||"":t.url=e.substring(r+1,a)||"",c>=l&&(t.desc=e.substring(l,c+1)),t},SocialCalc.ConvertSaveToOtherFormat=function(e,t,o){var a,l,r,i,n,c,s,d,u,p,m="";if("scsave"==t)return e;if(""==e)return"";if(a=new SocialCalc.Sheet,a.ParseSheetSave(e),o)throw"SocialCalc.ConvertSaveToOtherFormat: Not doing recalc.";if(r=a.copiedfrom?SocialCalc.ParseRange(a.copiedfrom):{cr1:{row:1,col:1},cr2:{row:a.attribs.lastrow,col:a.attribs.lastcol}},"html"==t)return l=new SocialCalc.RenderContext(a),a.copiedfrom&&(l.rowpanes[0]={first:r.cr1.row,last:r.cr2.row},l.colpanes[0]={first:r.cr1.col,last:r.cr2.col}),i=document.createElement("div"),n=l.RenderSheet(null,l.defaultHTMLlinkstyle),i.appendChild(n),delete l,delete a,m=i.innerHTML,delete n,delete i,m;for(c=r.cr1.row;c<=r.cr2.row;c++){for(s=r.cr1.col;s<=r.cr2.col;s++)d=SocialCalc.crToCoord(s,c),u=a.GetAssuredCell(d),p=u.errors?u.errors:u.datavalue+"","csv"==t?(-1!=p.indexOf('"')&&(p=p.replace(/"/g,'""')),/[, \n"]/.test(p)&&(p='"'+p+'"'),s>r.cr1.col&&(p=","+p)):"tab"==t&&(-1!=p.indexOf("\n")&&(-1!=p.indexOf('"')&&(p=p.replace(/"/g,'""')),p='"'+p+'"'),s>r.cr1.col&&(p=" "+p)),m+=p;m+="\n"}return m},SocialCalc.ConvertOtherFormatToSave=function(e,t){var o,a,l,r,i,n,c,s,d,u,p,m,h="",C=function(){u++,u>m&&(m=u),p=SocialCalc.crToCoord(u,d),SocialCalc.SetConvertedCell(o,p,i),i=""};if("scsave"==t)return e;if(o=new SocialCalc.Sheet,a=e.split(/\r\n|\n/),m=0,"csv"==t){for(d=0,n=!1,l=0;l<a.length&&(l!=a.length-1||""!=a[l]);l++)for(n?i+="\n":(i="",d++,u=0),r=a[l],c=0;c<r.length;c++)s=r.charAt(c),'"'!=s?(","!=s||n?i+=s:C(),c!=r.length-1||n||C()):n?c<r.length-1&&'"'==r.charAt(c+1)?(c++,i+='"'):(n=!1,c==r.length-1&&C()):n=!0;m>0&&(o.attribs.lastrow=d,o.attribs.lastcol=m,h=o.CreateSheetSave("A1:"+SocialCalc.crToCoord(m,d)))}if("tab"==t){for(d=0,n=!1,l=0;l<a.length&&(l!=a.length-1||""!=a[l]);l++)for(n?i+="\n":(i="",d++,u=0),r=a[l],c=0;c<r.length;c++){if(s=r.charAt(c),'"'==s){if(n){c<r.length-1?'"'==r.charAt(c+1)?(c++,i+='"'):" "==r.charAt(c+1)&&(c++,n=!1,C()):(n=!1,C());continue}if(""==i){n=!0;continue}}" "!=s||n?i+=s:C(),c!=r.length-1||n||C()}m>0&&(o.attribs.lastrow=d,o.attribs.lastcol=m,h=o.CreateSheetSave("A1:"+SocialCalc.crToCoord(m,d)))}return h},SocialCalc.SetConvertedCell=function(e,t,o){var a,l;a=e.GetAssuredCell(t),l=SocialCalc.DetermineValueType(o),"n"==l.type&&l.value==o?(a.datatype="v",a.valuetype="n",a.datavalue=l.value):"t"==l.type.charAt(0)?(a.datatype="t",a.valuetype=l.type,a.datavalue=l.value):(a.datatype="c",a.valuetype=l.type,a.datavalue=l.value,a.formula=o)};var SocialCalc;SocialCalc||(SocialCalc={}),SocialCalc.Constants={textdatadefaulttype:"t",s_BrowserNotSupported:"Browser not supported.",s_InternalError:"Internal SocialCalc error (probably an internal bug): ",s_pssUnknownColType:"Unknown col type item",s_pssUnknownRowType:"Unknown row type item",s_pssUnknownLineType:"Unknown line type",s_cfspUnknownCellType:"Unknown cell type item",doCanonicalizeSheet:!0,s_escUnknownSheetCmd:"Unknown sheet command: ",s_escUnknownSetCoordCmd:"Unknown set coord command: ",s_escUnknownCmd:"Unknown command: ",s_caccCircRef:"Circular reference to ",defaultRowNameWidth:"30",defaultAssumedRowHeight:15,defaultCellIDPrefix:"cell_",defaultCellLayout:"padding:2px 2px 1px 2px;vertical-align:top;",defaultCellFontStyle:"normal normal",defaultCellFontSize:"small",defaultCellFontFamily:"Verdana,Arial,Helvetica,sans-serif",defaultPaneDividerWidth:"2",defaultPaneDividerHeight:"3",defaultGridCSS:"1px solid #C0C0C0;",defaultCommentClass:"",defaultCommentStyle:"background-repeat:no-repeat;background-position:top right;background-image:url(images/sc-commentbg.gif);",defaultCommentNoGridClass:"",defaultCommentNoGridStyle:"",defaultReadonlyClass:"",defaultReadonlyStyle:"background-repeat:no-repeat;background-position:top right;background-image:url(images/sc-lockbg.gif);",defaultReadonlyNoGridClass:"",defaultReadonlyNoGridStyle:"",defaultReadonlyComment:"Locked cell",defaultColWidth:"80",defaultMinimumColWidth:10,defaultHighlightTypeCursorClass:"",defaultHighlightTypeCursorStyle:"color:#FFF;backgroundColor:#A6A6A6;",defaultHighlightTypeRangeClass:"",defaultHighlightTypeRangeStyle:"color:#000;backgroundColor:#E5E5E5;",defaultColnameClass:"",defaultColnameStyle:"font-size:small;text-align:center;color:#FFFFFF;background-color:#808080;cursor:e-resize;",defaultSelectedColnameClass:"",defaultSelectedColnameStyle:"font-size:small;text-align:center;color:#FFFFFF;background-color:#404040;cursor:e-resize;",defaultRownameClass:"",defaultRownameStyle:"font-size:small;text-align:right;color:#FFFFFF;background-color:#808080;",defaultSelectedRownameClass:"",defaultSelectedRownameStyle:"font-size:small;text-align:right;color:#FFFFFF;background-color:#404040;",defaultUpperLeftClass:"",defaultUpperLeftStyle:"font-size:small;",defaultSkippedCellClass:"",defaultSkippedCellStyle:"font-size:small;background-color:#CCC",defaultPaneDividerClass:"",defaultPaneDividerStyle:"font-size:small;background-color:#C0C0C0;padding:0px;",defaultUnhideLeftClass:"",defaultUnhideLeftStyle:"float:right;width:9px;height:12px;cursor:pointer;background-image:url(images/sc-unhideleft.gif);padding:0;",defaultUnhideRightClass:"",defaultUnhideRightStyle:"float:left;width:9px;height:12px;cursor:pointer;background-image:url(images/sc-unhideright.gif);padding:0;",defaultUnhideTopClass:"",defaultUnhideTopStyle:"float:left;position:absolute;bottom:-4px;width:12px;height:9px;cursor:pointer;background-image:url(images/sc-unhidetop.gif);padding:0;",defaultUnhideBottomClass:"",defaultUnhideBottomStyle:"float:left;width:12px;height:9px;cursor:pointer;background-image:url(images/sc-unhidebottom.gif);padding:0;",s_rcMissingSheet:"Render Context must have a sheet object",defaultLinkFormatString:'<span style="font-size:smaller;text-decoration:none !important;background-color:#66B;color:#FFF;">Link</span>',defaultPageLinkFormatString:'<span style="font-size:smaller;text-decoration:none !important;background-color:#66B;color:#FFF;">Page</span>',defaultFormatp:"#,##0.0%",defaultFormatc:"[$$]#,##0.00",defaultFormatdt:"d-mmm-yyyy h:mm:ss",defaultFormatd:"d-mmm-yyyy",defaultFormatt:"[h]:mm:ss",defaultDisplayTRUE:"TRUE",defaultDisplayFALSE:"FALSE",defaultImagePrefix:"images/sc-",defaultTableEditorIDPrefix:"te_",defaultPageUpDnAmount:15,AllowCtrlS:!0,defaultTableControlThickness:20,cteGriddivClass:"",s_statusline_executing:"Executing...",s_statusline_displaying:"Displaying...",s_statusline_ordering:"Ordering...",s_statusline_calculating:"Calculating...",s_statusline_calculatingls:"Calculating... Loading Sheet...",s_statusline_doingserverfunc:"doing server function ",s_statusline_incell:" in cell ",s_statusline_calcstart:"Calculation start...",s_statusline_sum:"SUM",s_statusline_recalcneeded:'<span style="color:#999;">(Recalc needed)</span>',s_statusline_circref:'<span style="color:red;">Circular reference: ',s_inputboxdisplaymultilinetext:"[Multi-line text: Click icon on right to edit]",defaultInputEchoClass:"",defaultInputEchoStyle:"filter:alpha(opacity=90);opacity:.9;backgroundColor:#FFD;border:1px solid #884;fontSize:small;padding:2px 10px 1px 2px;cursor:default;",defaultInputEchoPromptClass:"",defaultInputEchoPromptStyle:"filter:alpha(opacity=90);opacity:.9;backgroundColor:#FFD;borderLeft:1px solid #884;borderRight:1px solid #884;borderBottom:1px solid #884;fontSize:small;fontStyle:italic;padding:2px 10px 1px 2px;cursor:default;",ietUnknownFunction:"Unknown function ",CH_radius1:29,CH_radius2:41,s_CHfillAllTooltip:"Fill Contents and Formats Down/Right",s_CHfillContentsTooltip:"Fill Contents Only Down/Right",s_CHmovePasteAllTooltip:"Move Contents and Formats",s_CHmovePasteContentsTooltip:"Move Contents Only",s_CHmoveInsertAllTooltip:"Slide Contents and Formats within Row/Col",s_CHmoveInsertContentsTooltip:"Slide Contents within Row/Col",s_CHindicatorOperationLookup:{Fill:"Fill",FillC:"Fill Contents",Move:"Move",MoveI:"Slide",MoveC:"Move Contents",MoveIC:"Slide Contents"},s_CHindicatorDirectionLookup:{Down:" Down",Right:" Right",Horizontal:" Horizontal",Vertical:" Vertical"},defaultTCSliderThickness:9,defaultTCButtonThickness:20,defaultTCThumbThickness:15,TCmainStyle:"backgroundColor:#EEE;",TCmainClass:"",TCendcapStyle:"backgroundColor:#FFF;",TCendcapClass:"",TCpanesliderStyle:"backgroundColor:#CCC;",TCpanesliderClass:"",s_panesliderTooltiph:"Drag to lock pane vertically",s_panesliderTooltipv:"Drag to lock pane horizontally",TClessbuttonStyle:"backgroundColor:#AAA;",TClessbuttonClass:"",TClessbuttonRepeatWait:300,TClessbuttonRepeatInterval:20,TCmorebuttonStyle:"backgroundColor:#AAA;",TCmorebuttonClass:"",TCmorebuttonRepeatWait:300,TCmorebuttonRepeatInterval:20,TCscrollareaStyle:"backgroundColor:#DDD;",TCscrollareaClass:"",TCscrollareaRepeatWait:500,TCscrollareaRepeatInterval:100,TCthumbClass:"",TCthumbStyle:"backgroundColor:#CCC;",TCPStrackinglineClass:"",TCPStrackinglineStyle:"overflow:hidden;position:absolute;zIndex:100;",TCPStrackinglineThickness:"2px",TCTDFSthumbstatusvClass:"",TCTDFSthumbstatusvStyle:"height:20px;width:auto;border:3px solid #808080;overflow:hidden;backgroundColor:#FFF;fontSize:small;position:absolute;zIndex:100;",TCTDFSthumbstatushClass:"",TCTDFSthumbstatushStyle:"height:20px;width:auto;border:1px solid black;padding:2px;backgroundColor:#FFF;fontSize:small;position:absolute;zIndex:100;",TCTDFSthumbstatusrownumClass:"",TCTDFSthumbstatusrownumStyle:"color:#FFF;background-color:#808080;font-size:small;white-space:nowrap;padding:3px;",TCTDFStopOffsetv:0,TCTDFSleftOffsetv:-80,s_TCTDFthumbstatusPrefixv:"Row ",TCTDFStopOffseth:-30,TCTDFSleftOffseth:0,s_TCTDFthumbstatusPrefixh:"Col ",TooltipOffsetX:2,TooltipOffsetY:10,TDpopupElementClass:"",TDpopupElementStyle:"border:1px solid black;padding:1px 2px 2px 2px;textAlign:center;backgroundColor:#FFF;fontSize:7pt;fontFamily:Verdana,Arial,Helvetica,sans-serif;position:absolute;width:auto;zIndex:110;",SCToolbarbackground:"background-color:#404040;",SCTabbackground:"background-color:#CCC;",SCTabselectedCSS:"font-size:small;padding:6px 30px 6px 8px;color:#FFF;background-color:#404040;cursor:default;border-right:1px solid #CCC;",SCTabplainCSS:"font-size:small;padding:6px 30px 6px 8px;color:#FFF;background-color:#808080;cursor:default;border-right:1px solid #CCC;",SCToolbartext:"font-size:x-small;font-weight:bold;color:#FFF;padding-bottom:4px;",SCFormulabarheight:30,SCStatuslineheight:20,SCStatuslineCSS:"font-size:10px;padding:3px 0px;",SCFormatNumberFormats:"[cancel]:|[break]:|%loc!Default!:|[custom]:|%loc!Automatic!:general|%loc!Auto w/ commas!:[,]General|[break]:|00:00|000:000|0000:0000|00000:00000|[break]:|%loc!Formula!:formula|%loc!Hidden!:hidden|[newcol]:1234:0|1,234:#,##0|1,234.5:#,##0.0|1,234.56:#,##0.00|1,234.567:#,##0.000|1,234.5678:#,##0.0000|[break]:|1,234%:#,##0%|1,234.5%:#,##0.0%|1,234.56%:#,##0.00%|[newcol]:|$1,234:$#,##0|$1,234.5:$#,##0.0|$1,234.56:$#,##0.00|[break]:|(1,234):#,##0_);(#,##0)|(1,234.5):#,##0.0_);(#,##0.0)|(1,234.56):#,##0.00_);(#,##0.00)|[break]:|($1,234):#,##0_);($#,##0)|($1,234.5):$#,##0.0_);($#,##0.0)|($1,234.56):$#,##0.00_);($#,##0.00)|[newcol]:|1/24/06:m/d/yy|01/24/2006:mm/dd/yyyy|24/1/06:d/m/yy|24/01/2006:dd/mm/yyyy|2006-01-24:yyyy-mm-dd|24-Jan-06:d-mmm-yy|24-Jan-2006:dd-mmm-yyyy|January 24, 2006:mmmm d, yyyy|[break]:|1\\c23:h:mm|1\\c23 PM:h:mm AM/PM|1\\c23\\c45:h:mm:ss|01\\c23\\c45:hh:mm:ss|26\\c23 (h\\cm):[hh]:mm|69\\c45 (m\\cs):[mm]:ss|69 (s):[ss]|[newcol]:|2006-01-24 01\\c23\\c45:yyyy-mm-dd hh:mm:ss|January 24, 2006:mmmm d, yyyy hh:mm:ss|Wed:ddd|Wednesday:dddd|",SCFormatTextFormats:"[cancel]:|[break]:|%loc!Default!:|[custom]:|%loc!Automatic!:general|%loc!Plain Text!:text-plain|HTML:text-html|%loc!Wikitext!:text-wiki|%loc!Link!:text-link|%loc!Formula!:formula|%loc!Hidden!:hidden|",SCFormatPadsizes:"[cancel]:|[break]:|%loc!Default!:|[custom]:|%loc!No padding!:0px|[newcol]:|1 pixel:1px|2 pixels:2px|3 pixels:3px|4 pixels:4px|5 pixels:5px|6 pixels:6px|7 pixels:7px|8 pixels:8px|[newcol]:|9 pixels:9px|10 pixels:10px|11 pixels:11px|12 pixels:12px|13 pixels:13px|14 pixels:14px|16 pixels:16px|18 pixels:18px|[newcol]:|20 pixels:20px|22 pixels:22px|24 pixels:24px|28 pixels:28px|36 pixels:36px|",SCFormatFontsizes:"[cancel]:|[break]:|%loc!Default!:|[custom]:|X-Small:x-small|Small:small|Medium:medium|Large:large|X-Large:x-large|[newcol]:|6pt:6pt|7pt:7pt|8pt:8pt|9pt:9pt|10pt:10pt|11pt:11pt|12pt:12pt|14pt:14pt|16pt:16pt|[newcol]:|18pt:18pt|20pt:20pt|22pt:22pt|24pt:24pt|28pt:28pt|36pt:36pt|48pt:48pt|72pt:72pt|[newcol]:|8 pixels:8px|9 pixels:9px|10 pixels:10px|11 pixels:11px|12 pixels:12px|13 pixels:13px|14 pixels:14px|[newcol]:|16 pixels:16px|18 pixels:18px|20 pixels:20px|22 pixels:22px|24 pixels:24px|28 pixels:28px|36 pixels:36px|",SCFormatFontfamilies:"[cancel]:|[break]:|%loc!Default!:|[custom]:|Verdana:Verdana,Arial,Helvetica,sans-serif|Arial:arial,helvetica,sans-serif|Courier:'Courier New',Courier,monospace|",SCFormatFontlook:"[cancel]:|[break]:|%loc!Default!:|%loc!Normal!:normal normal|%loc!Bold!:normal bold|%loc!Italic!:italic normal|%loc!Bold Italic!:italic bold",SCFormatTextAlignhoriz:"[cancel]:|[break]:|%loc!Default!:|%loc!Left!:left|%loc!Center!:center|%loc!Right!:right|",SCFormatNumberAlignhoriz:"[cancel]:|[break]:|%loc!Default!:|%loc!Left!:left|%loc!Center!:center|%loc!Right!:right|",SCFormatAlignVertical:"[cancel]:|[break]:|%loc!Default!:|%loc!Top!:top|%loc!Middle!:middle|%loc!Bottom!:bottom|",
SCFormatColwidth:"[cancel]:|[break]:|%loc!Default!:|[custom]:|[newcol]:|20 pixels:20|40:40|60:60|80:80|100:100|120:120|140:140|160:160|[newcol]:|180 pixels:180|200:200|220:220|240:240|260:260|280:280|300:300|",SCFormatRecalc:"[cancel]:|[break]:|%loc!Auto!:|%loc!Manual!:off|",SCFormatUserMaxCol:"[cancel]:|[break]:|%loc!Default!:|[custom]:|[newcol]:|Unlimited:0|10:10|20:20|30:30|40:40|50:50|60:60|80:80|100:100|",SCFormatUserMaxRow:"[cancel]:|[break]:|%loc!Default!:|[custom]:|[newcol]:|Unlimited:0|10:10|20:20|30:30|40:40|50:50|60:60|80:80|100:100|",ISCButtonBorderNormal:"#404040",ISCButtonBorderHover:"#999",ISCButtonBorderDown:"#FFF",ISCButtonDownBackground:"#888",s_PopupListCancel:"[Cancel]",s_PopupListCustom:"Custom",s_loc_align_center:"Align Center",s_loc_align_left:"Align Left",s_loc_align_right:"Align Right",s_loc_alignment:"Alignment",s_loc_audit:"Audit",s_loc_audit_trail_this_session:"Audit Trail This Session",s_loc_auto:"Auto",s_loc_auto_sum:"Auto Sum",s_loc_auto_wX_commas:"Auto w/ commas",s_loc_automatic:"Automatic",s_loc_background:"Background",s_loc_bold:"Bold",s_loc_bold_XampX_italics:"Bold & Italics",s_loc_bold_italic:"Bold Italic",s_loc_borders:"Borders",s_loc_borders_off:"Borders Off",s_loc_borders_on:"Borders On",s_loc_bottom:"Bottom",s_loc_bottom_border:"Bottom Border",s_loc_cell_settings:"CELL SETTINGS",s_loc_csv_format:"CSV format",s_loc_cancel:"Cancel",s_loc_category:"Category",s_loc_center:"Center",s_loc_clear:"Clear",s_loc_clear_socialcalc_clipboard:"Clear SocialCalc Clipboard",s_loc_clipboard:"Clipboard",s_loc_color:"Color",s_loc_column_:"Column ",s_loc_comment:"Comment",s_loc_copy:"Copy",s_loc_custom:"Custom",s_loc_cut:"Cut",s_loc_default:"Default",s_loc_default_alignment:"Default Alignment",s_loc_default_column_width:"Default Column Width",s_loc_default_font:"Default Font",s_loc_default_format:"Default Format",s_loc_default_padding:"Default Padding",s_loc_delete:"Delete",s_loc_delete_column:"Delete Column",s_loc_delete_contents:"Delete Contents",s_loc_delete_row:"Delete Row",s_loc_description:"Description",s_loc_display_clipboard_in:"Display Clipboard in",s_loc_down:"Down",s_loc_edit:"Edit",s_loc_existing_names:"Existing Names",s_loc_family:"Family",s_loc_fill_down:"Fill Down",s_loc_fill_right:"Fill Right",s_loc_font:"Font",s_loc_format:"Format",s_loc_formula:"Formula",s_loc_function_list:"Function List",s_loc_functions:"Functions",s_loc_grid:"Grid",s_loc_hidden:"Hidden",s_loc_horizontal:"Horizontal",s_loc_insert_column:"Insert Column",s_loc_insert_row:"Insert Row",s_loc_italic:"Italic",s_loc_last_sort:"Last Sort",s_loc_left:"Left",s_loc_left_border:"Left Border",s_loc_link:"Link",s_loc_link_input_box:"Link Input Box",s_loc_list:"List",s_loc_load_socialcalc_clipboard_with_this:"Load SocialCalc Clipboard With This",s_loc_major_sort:"Major Sort",s_loc_manual:"Manual",s_loc_merge_cells:"Merge Cells",s_loc_middle:"Middle",s_loc_minor_sort:"Minor Sort",s_loc_move_insert:"Move Insert",s_loc_move_paste:"Move Paste",s_loc_multiXline_input_box:"Multi-line Input Box",s_loc_name:"Name",s_loc_names:"Names",s_loc_no_padding:"No padding",s_loc_normal:"Normal",s_loc_number:"Number",s_loc_number_horizontal:"Number Horizontal",s_loc_ok:"OK",s_loc_padding:"Padding",s_loc_page_name:"Page Name",s_loc_paste:"Paste",s_loc_paste_formats:"Paste Formats",s_loc_plain_text:"Plain Text",s_loc_recalc:"Recalc",s_loc_recalculation:"Recalculation",s_loc_redo:"Redo",s_loc_right:"Right",s_loc_right_border:"Right Border",s_loc_sheet_settings:"SHEET SETTINGS",s_loc_save:"Save",s_loc_save_to:"Save to",s_loc_set_cell_contents:"Set Cell Contents",s_loc_set_cells_to_sort:"Set Cells To Sort",s_loc_set_value_to:"Set Value To",s_loc_set_to_link_format:"Set to Link format",s_loc_setXclear_move_from:"Set/Clear Move From",s_loc_show_cell_settings:"Show Cell Settings",s_loc_show_sheet_settings:"Show Sheet Settings",s_loc_show_in_new_browser_window:"Show in new browser window",s_loc_size:"Size",s_loc_socialcalcXsave_format:"SocialCalc-save format",s_loc_sort:"Sort",s_loc_sort_:"Sort ",s_loc_sort_cells:"Sort Cells",s_loc_swap_colors:"Swap Colors",s_loc_tabXdelimited_format:"Tab-delimited format",s_loc_text:"Text",s_loc_text_horizontal:"Text Horizontal",s_loc_this_is_aXbrXsample:"This is a<br>sample",s_loc_top:"Top",s_loc_top_border:"Top Border",s_loc_undone_steps:"UNDONE STEPS",s_loc_url:"URL",s_loc_undo:"Undo",s_loc_unmerge_cells:"Unmerge Cells",s_loc_up:"Up",s_loc_value:"Value",s_loc_vertical:"Vertical",s_loc_wikitext:"Wikitext",s_loc_workspace:"Workspace",s_loc_XnewX:"[New]",s_loc_XnoneX:"[None]",s_loc_Xselect_rangeX:"[select range]",SVStatuslineheight:20,SVStatuslineCSS:"font-size:10px;padding:3px 0px;",FormatNumber_separatorchar:",",FormatNumber_decimalchar:".",FormatNumber_defaultCurrency:"$",s_FormatNumber_daynames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],s_FormatNumber_daynames3:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],s_FormatNumber_monthnames:["January","February","March","April","May","June","July","August","September","October","November","December"],s_FormatNumber_monthnames3:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],s_FormatNumber_am:"AM",s_FormatNumber_am1:"A",s_FormatNumber_pm:"PM",s_FormatNumber_pm1:"P",s_parseerrexponent:"Improperly formed number exponent",s_parseerrchar:"Unexpected character in formula",s_parseerrstring:"Improperly formed string",s_parseerrspecialvalue:"Improperly formed special value",s_parseerrtwoops:"Error in formula (two operators inappropriately in a row)",s_parseerrmissingopenparen:"Missing open parenthesis in list with comma(s). ",s_parseerrcloseparennoopen:"Closing parenthesis without open parenthesis. ",s_parseerrmissingcloseparen:"Missing close parenthesis. ",s_parseerrmissingoperand:"Missing operand. ",s_parseerrerrorinformula:"Error in formula.",s_calcerrerrorvalueinformula:"Error value in formula",s_parseerrerrorinformulabadval:"Error in formula resulting in bad value",s_formularangeresult:"Formula results in range value:",s_calcerrnumericnan:"Formula results in an bad numeric value",s_calcerrnumericoverflow:"Numeric overflow",s_sheetunavailable:"Sheet unavailable:",s_calcerrcellrefmissing:"Cell reference missing when expected.",s_calcerrsheetnamemissing:"Sheet name missing when expected.",s_circularnameref:"Circular name reference to name",s_calcerrunknownname:"Unknown name",s_calcerrincorrectargstofunction:"Incorrect arguments to function",s_sheetfuncunknownfunction:"Unknown function",s_sheetfunclnarg:"LN argument must be greater than 0",s_sheetfunclog10arg:"LOG10 argument must be greater than 0",s_sheetfunclogsecondarg:"LOG second argument must be numeric greater than 0",s_sheetfunclogfirstarg:"LOG first argument must be greater than 0",s_sheetfuncroundsecondarg:"ROUND second argument must be numeric",s_sheetfuncddblife:"DDB life must be greater than 1",s_sheetfuncslnlife:"SLN life must be greater than 1",s_fdef_ABS:"Absolute value function. ",s_fdef_ACOS:"Trigonometric arccosine function. ",s_fdef_AND:"True if all arguments are true. ",s_fdef_ASIN:"Trigonometric arcsine function. ",s_fdef_ATAN:"Trigonometric arctan function. ",s_fdef_ATAN2:"Trigonometric arc tangent function (result is in radians). ",s_fdef_AVERAGE:"Averages the values. ",s_fdef_CHOOSE:"Returns the value specified by the index. The values may be ranges of cells. ",s_fdef_COLUMNS:"Returns the number of columns in the range. ",s_fdef_COS:"Trigonometric cosine function (value is in radians). ",s_fdef_COUNT:"Counts the number of numeric values, not blank, text, or error. ",s_fdef_COUNTA:"Counts the number of non-blank values. ",s_fdef_COUNTBLANK:'Counts the number of blank values. (Note: "" is not blank.) ',s_fdef_COUNTIF:'Counts the number of number of cells in the range that meet the criteria. The criteria may be a value ("x", 15, 1+3) or a test (>25). ',s_fdef_DATE:'Returns the appropriate date value given numbers for year, month, and day. For example: DATE(2006,2,1) for February 1, 2006. Note: In this program, day "1" is December 31, 1899 and the year 1900 is not a leap year. Some programs use January 1, 1900, as day "1" and treat 1900 as a leap year. In both cases, though, dates on or after March 1, 1900, are the same. ',s_fdef_DAVERAGE:"Averages the values in the specified field in records that meet the criteria. ",s_fdef_DAY:"Returns the day of month for a date value. ",s_fdef_DCOUNT:"Counts the number of numeric values, not blank, text, or error, in the specified field in records that meet the criteria. ",s_fdef_DCOUNTA:"Counts the number of non-blank values in the specified field in records that meet the criteria. ",s_fdef_DDB:"Returns the amount of depreciation at the given period of time (the default factor is 2 for double-declining balance). ",s_fdef_DEGREES:"Converts value in radians into degrees. ",s_fdef_DGET:"Returns the value of the specified field in the single record that meets the criteria. ",s_fdef_DMAX:"Returns the maximum of the numeric values in the specified field in records that meet the criteria. ",s_fdef_DMIN:"Returns the maximum of the numeric values in the specified field in records that meet the criteria. ",s_fdef_DPRODUCT:"Returns the result of multiplying the numeric values in the specified field in records that meet the criteria. ",s_fdef_DSTDEV:"Returns the sample standard deviation of the numeric values in the specified field in records that meet the criteria. ",s_fdef_DSTDEVP:"Returns the standard deviation of the numeric values in the specified field in records that meet the criteria. ",s_fdef_DSUM:"Returns the sum of the numeric values in the specified field in records that meet the criteria. ",s_fdef_DVAR:"Returns the sample variance of the numeric values in the specified field in records that meet the criteria. ",s_fdef_DVARP:"Returns the variance of the numeric values in the specified field in records that meet the criteria. ",s_fdef_EVEN:"Rounds the value up in magnitude to the nearest even integer. ",s_fdef_EXACT:'Returns "true" if the values are exactly the same, including case, type, etc. ',s_fdef_EXP:"Returns e raised to the value power. ",s_fdef_FACT:"Returns factorial of the value. ",s_fdef_FALSE:'Returns the logical value "false". ',s_fdef_FIND:'Returns the starting position within string2 of the first occurrence of string1 at or after "start". If start is omitted, 1 is assumed. ',s_fdef_FV:"Returns the future value of repeated payments of money invested at the given rate for the specified number of periods, with optional present value (default 0) and payment type (default 0 = at end of period, 1 = beginning of period). ",s_fdef_HLOOKUP:"Look for the matching value for the given value in the range and return the corresponding value in the cell specified by the row offset. If rangelookup is 1 (the default) and not 0, match if within numeric brackets (match<=value) instead of exact match. ",s_fdef_HOUR:"Returns the hour portion of a time or date/time value. ",s_fdef_IF:"Results in true-value if logical-expression is TRUE or non-zero, otherwise results in false-value. ",s_fdef_INDEX:"Returns a cell or range reference for the specified row and column in the range. If range is 1-dimensional, then only one of rownum or colnum are needed. If range is 2-dimensional and rownum or colnum are zero, a reference to the range of just the specified column or row is returned. You can use the returned reference value in a range, e.g., sum(A1:INDEX(A2:A10,4)). ",s_fdef_INT:"Returns the value rounded down to the nearest integer (towards -infinity). ",s_fdef_IRR:"Returns the interest rate at which the cash flows in the range have a net present value of zero. Uses an iterative process that will return #NUM! error if it does not converge. There may be more than one possible solution. Providing the optional guess value may help in certain situations where it does not converge or finds an inappropriate solution (the default guess is 10%). ",s_fdef_ISBLANK:'Returns "true" if the value is a reference to a blank cell. ',s_fdef_ISERR:'Returns "true" if the value is of type "Error" but not "NA". ',s_fdef_ISERROR:'Returns "true" if the value is of type "Error". ',s_fdef_ISLOGICAL:'Returns "true" if the value is of type "Logical" (true/false). ',s_fdef_ISNA:'Returns "true" if the value is the error type "NA". ',s_fdef_ISNONTEXT:'Returns "true" if the value is not of type "Text". ',s_fdef_ISNUMBER:'Returns "true" if the value is of type "Number" (including logical values). ',s_fdef_ISTEXT:'Returns "true" if the value is of type "Text". ',s_fdef_LEFT:"Returns the specified number of characters from the text value. If count is omitted, 1 is assumed. ",s_fdef_LEN:"Returns the number of characters in the text value. ",s_fdef_LN:"Returns the natural logarithm of the value. ",s_fdef_LOG:"Returns the logarithm of the value using the specified base. ",s_fdef_LOG10:"Returns the base 10 logarithm of the value. ",s_fdef_LOWER:"Returns the text value with all uppercase characters converted to lowercase. ",s_fdef_MATCH:"Look for the matching value for the given value in the range and return position (the first is 1) in that range. If rangelookup is 1 (the default) and not 0, match if within numeric brackets (match<=value) instead of exact match. If rangelookup is -1, act like 1 but the bracket is match>=value. ",s_fdef_MAX:"Returns the maximum of the numeric values. ",s_fdef_MID:"Returns the specified number of characters from the text value starting from the specified position. ",s_fdef_MIN:"Returns the minimum of the numeric values. ",s_fdef_MINUTE:"Returns the minute portion of a time or date/time value. ",s_fdef_MOD:"Returns the remainder of the first value divided by the second. ",s_fdef_MONTH:"Returns the month part of a date value. ",s_fdef_N:"Returns the value if it is a numeric value otherwise an error. ",s_fdef_NA:"Returns the #N/A error value which propagates through most operations. ",s_fdef_NOT:"Returns FALSE if value is true, and TRUE if it is false. ",s_fdef_NOW:"Returns the current date/time. ",s_fdef_NPER:"Returns the number of periods at which payments invested each period at the given rate with optional future value (default 0) and payment type (default 0 = at end of period, 1 = beginning of period) has the given present value. ",s_fdef_NPV:"Returns the net present value of cash flows (which may be individual values and/or ranges) at the given rate. The flows are positive if income, negative if paid out, and are assumed at the end of each period. ",s_fdef_ODD:"Rounds the value up in magnitude to the nearest odd integer. ",s_fdef_OR:"True if any argument is true ",s_fdef_PI:"The value 3.1415926... ",s_fdef_PMT:"Returns the amount of each payment that must be invested at the given rate for the specified number of periods to have the specified present value, with optional future value (default 0) and payment type (default 0 = at end of period, 1 = beginning of period). ",s_fdef_POWER:"Returns the first value raised to the second value power. ",s_fdef_PRODUCT:"Returns the result of multiplying the numeric values. ",s_fdef_PROPER:"Returns the text value with the first letter of each word converted to uppercase and the others to lowercase. ",s_fdef_PV:"Returns the present value of the given number of payments each invested at the given rate, with optional future value (default 0) and payment type (default 0 = at end of period, 1 = beginning of period). ",s_fdef_RADIANS:"Converts value in degrees into radians. ",s_fdef_RATE:"Returns the rate at which the given number of payments each invested at the given rate has the specified present value, with optional future value (default 0) and payment type (default 0 = at end of period, 1 = beginning of period). Uses an iterative process that will return #NUM! error if it does not converge. There may be more than one possible solution. Providing the optional guess value may help in certain situations where it does not converge or finds an inappropriate solution (the default guess is 10%). ",s_fdef_REPLACE:"Returns text1 with the specified number of characters starting from the specified position replaced by text2. ",s_fdef_REPT:"Returns the text repeated the specified number of times. ",s_fdef_RIGHT:"Returns the specified number of characters from the text value starting from the end. If count is omitted, 1 is assumed. ",s_fdef_ROUND:"Rounds the value to the specified number of decimal places. If precision is negative, then round to powers of 10. The default precision is 0 (round to integer). ",s_fdef_ROWS:"Returns the number of rows in the range. ",s_fdef_SECOND:"Returns the second portion of a time or date/time value (truncated to an integer). ",s_fdef_SIN:"Trigonometric sine function (value is in radians) ",s_fdef_SLN:"Returns the amount of depreciation at each period of time using the straight-line method. ",s_fdef_SQRT:"Square root of the value ",s_fdef_STDEV:"Returns the sample standard deviation of the numeric values. ",s_fdef_STDEVP:"Returns the standard deviation of the numeric values. ",s_fdef_SUBSTITUTE:'Returns text1 with the all occurrences of oldtext replaced by newtext. If "occurrence" is present, then only that occurrence is replaced. ',s_fdef_SUM:"Adds the numeric values. The values to the sum function may be ranges in the form similar to A1:B5. ",s_fdef_SUMIF:'Sums the numeric values of cells in the range that meet the criteria. The criteria may be a value ("x", 15, 1+3) or a test (>25). If range2 is present, then range1 is tested and the corresponding range2 value is summed. ',s_fdef_SYD:"Depreciation by Sum of Year's Digits method. ",s_fdef_T:"Returns the text value or else a null string. ",s_fdef_TAN:"Trigonometric tangent function (value is in radians) ",s_fdef_TIME:"Returns the time value given the specified hour, minute, and second. ",s_fdef_TODAY:'Returns the current date (an integer). Note: In this program, day "1" is December 31, 1899 and the year 1900 is not a leap year. Some programs use January 1, 1900, as day "1" and treat 1900 as a leap year. In both cases, though, dates on or after March 1, 1900, are the same. ',s_fdef_TRIM:"Returns the text value with leading, trailing, and repeated spaces removed. ",s_fdef_TRUE:'Returns the logical value "true". ',s_fdef_TRUNC:"Truncates the value to the specified number of decimal places. If precision is negative, truncate to powers of 10. ",s_fdef_UPPER:"Returns the text value with all lowercase characters converted to uppercase. ",s_fdef_VALUE:"Converts the specified text value into a numeric value. Various forms that look like numbers (including digits followed by %, forms that look like dates, etc.) are handled. This may not handle all of the forms accepted by other spreadsheets and may be locale dependent. ",s_fdef_VAR:"Returns the sample variance of the numeric values. ",s_fdef_VARP:"Returns the variance of the numeric values. ",s_fdef_VLOOKUP:"Look for the matching value for the given value in the range and return the corresponding value in the cell specified by the column offset. If rangelookup is 1 (the default) and not 0, match if within numeric brackets (match>=value) instead of exact match. ",s_fdef_WEEKDAY:"Returns the day of week specified by the date value. If type is 1 (the default), Sunday is day and Saturday is day 7. If type is 2, Monday is day 1 and Sunday is day 7. If type is 3, Monday is day 0 and Sunday is day 6. ",s_fdef_YEAR:"Returns the year part of a date value. ",s_fdef_SUMPRODUCT:"Sums the pairwise products of 2 or more ranges. The ranges must be of equal length.",s_fdef_CEILING:"Rounds the given number up to the nearest integer or multiple of significance. Significance is the value to whose multiple of ten the value is to be rounded up (.01, .1, 1, 10, etc.)",s_fdef_FLOOR:"Rounds the given number down to the nearest multiple of significance. Significance is the value to whose multiple of ten the number is to be rounded down (.01, .1, 1, 10, etc.)",s_farg_v:"value",s_farg_vn:"value1, value2, ...",s_farg_xy:"valueX, valueY",s_farg_choose:"index, value1, value2, ...",s_farg_range:"range",s_farg_rangec:"range, criteria",s_farg_date:"year, month, day",s_farg_dfunc:"databaserange, fieldname, criteriarange",s_farg_ddb:"cost, salvage, lifetime, period, [factor]",s_farg_find:"string1, string2, [start]",s_farg_fv:"rate, n, payment, [pv, [paytype]]",s_farg_hlookup:"value, range, row, [rangelookup]",s_farg_iffunc:"logical-expression, true-value, [false-value]",s_farg_index:"range, rownum, colnum",s_farg_irr:"range, [guess]",s_farg_tc:"text, count",s_farg_log:"value, base",s_farg_match:"value, range, [rangelookup]",s_farg_mid:"text, start, length",s_farg_nper:"rate, payment, pv, [fv, [paytype]]",s_farg_npv:"rate, value1, value2, ...",s_farg_pmt:"rate, n, pv, [fv, [paytype]]",s_farg_pv:"rate, n, payment, [fv, [paytype]]",s_farg_rate:"n, payment, pv, [fv, [paytype, [guess]]]",s_farg_replace:"text1, start, length, text2",s_farg_vp:"value, [precision]",s_farg_valpre:"value, precision",s_farg_csl:"cost, salvage, lifetime",s_farg_cslp:"cost, salvage, lifetime, period",s_farg_subs:"text1, oldtext, newtext, [occurrence]",s_farg_sumif:"range1, criteria, [range2]",s_farg_hms:"hour, minute, second",s_farg_txt:"text",s_farg_vlookup:"value, range, col, [rangelookup]",s_farg_weekday:"date, [type]",s_farg_dt:"date",s_farg_rangen:"range1, range2, ...",s_farg_vsig:"value, [significance]",function_classlist:["all","stat","lookup","datetime","financial","test","math","text"],s_fclass_all:"All",s_fclass_stat:"Statistics",s_fclass_lookup:"Lookup",s_fclass_datetime:"Date & Time",s_fclass_financial:"Financial",s_fclass_test:"Test",s_fclass_math:"Math",s_fclass_text:"Text",lastone:null},SocialCalc.ConstantsDefaultClasses={defaultComment:"",defaultCommentNoGrid:"",defaultHighlightTypeCursor:"",defaultHighlightTypeRange:"",defaultColname:"",defaultSelectedColname:"",defaultRowname:"",defaultSelectedRowname:"",defaultUpperLeft:"",defaultSkippedCell:"",defaultPaneDivider:"",cteGriddiv:"",defaultInputEcho:{classname:"",style:"filter:alpha(opacity=90);opacity:.9;"},TCmain:"",TCendcap:"",TCpaneslider:"",TClessbutton:"",TCmorebutton:"",TCscrollarea:"",TCthumb:"",TCPStrackingline:"",TCTDFSthumbstatus:"",TDpopupElement:""},SocialCalc.ConstantsSetClasses=function(e){var t,o=SocialCalc.ConstantsDefaultClasses,a=SocialCalc.Constants;e=e||"";for(t in o)"string"==typeof o[t]?(a[t+"Class"]=e+(o[t]||t),void 0!==a[t+"Style"]&&(a[t+"Style"]="")):"object"==typeof o[t]&&(a[t+"Class"]=e+(o[t].classname||t),a[t+"Style"]=o[t].style)},SocialCalc.ConstantsSetImagePrefix=function(e){var t=SocialCalc.Constants;for(var o in t)"string"==typeof t[o]&&(t[o]=t[o].replace(t.defaultImagePrefix,e));t.defaultImagePrefix=e};var SocialCalc;SocialCalc||(SocialCalc={}),SocialCalc.TableEditor=function(e){var t=SocialCalc.Constants;this.context=e,this.toplevel=null,this.fullgrid=null,this.noEdit=!1,this.width=null,this.tablewidth=null,this.height=null,this.tableheight=null,this.inputBox=null,this.inputEcho=null,this.verticaltablecontrol=null,this.horizontaltablecontrol=null,this.logo=null,this.cellhandles=null,this.timeout=null,this.busy=!1,this.ensureecell=!1,this.deferredCommands=[],this.gridposition=null,this.headposition=null,this.firstscrollingrow=null,this.firstscrollingrowtop=null,this.lastnonscrollingrow=null,this.lastvisiblerow=null,this.firstscrollingcol=null,this.firstscrollingcolleft=null,this.lastnonscrollingcol=null,this.lastvisiblecol=null,this.rowpositions=[],this.colpositions=[],this.rowheight=[],this.colwidth=[],this.ecell=null,this.state="start",this.workingvalues={},this.imageprefix=t.defaultImagePrefix,this.idPrefix=t.defaultTableEditorIDPrefix,this.pageUpDnAmount=t.defaultPageUpDnAmount,this.recalcFunction=function(e){return e.context.sheetobj.RecalcSheet?void e.context.sheetobj.RecalcSheet(SocialCalc.EditorSheetStatusCallback,e):null},this.ctrlkeyFunction=function(e,t){var o,a,l,r,i,n;switch(t){case"[ctrl-c]":case"[ctrl-x]":return o=e.pasteTextarea,o.value="",a=SocialCalc.GetEditorCellElement(e,e.ecell.row,e.ecell.col),a&&(l=SocialCalc.GetElementPosition(a.element),o.style.left=l.left-1+"px",o.style.top=l.top-1+"px"),i=e.range.hasrange?SocialCalc.crToCoord(e.range.left,e.range.top)+":"+SocialCalc.crToCoord(e.range.right,e.range.bottom):e.ecell.coord,n=SocialCalc.ConvertSaveToOtherFormat(SocialCalc.CreateSheetSave(e.context.sheetobj,i),"tab"),r="[ctrl-c]"==t||e.noEdit||e.ECellReadonly()?"copy "+i+" formulas":"cut "+i+" formulas",e.EditorScheduleSheetCommands(r,!0,!1),o.style.display="block",o.value=n,o.focus(),o.select(),window.setTimeout(function(){var t=e.pasteTextarea;t.blur(),t.style.display="none",SocialCalc.KeyboardFocus()},200),!0;case"[ctrl-v]":return e.noEdit||e.ECellReadonly()?!0:(o=e.pasteTextarea,o.value="",a=SocialCalc.GetEditorCellElement(e,e.ecell.row,e.ecell.col),a&&(l=SocialCalc.GetElementPosition(a.element),o.style.left=l.left-1+"px",o.style.top=l.top-1+"px"),o.style.display="block",o.value="",o.focus(),window.setTimeout(function(){var t=e.pasteTextarea,o=t.value;t.blur(),t.style.display="none";var a="",l=SocialCalc.ConvertSaveToOtherFormat(SocialCalc.Clipboard.clipboard,"tab");o=o.replace(/\r\n/g,"\n"),o==l||o.length-l.length==1&&o.substring(0,o.length-1)==l||(a="loadclipboard "+SocialCalc.encodeForSave(SocialCalc.ConvertOtherFormatToSave(o,"tab"))+"\n");var r;r=e.range.hasrange?SocialCalc.crToCoord(e.range.left,e.range.top):e.ecell.coord,a+="paste "+r+" formulas",e.EditorScheduleSheetCommands(a,!0,!1),SocialCalc.KeyboardFocus()},200),!0);case"[ctrl-z]":return e.EditorScheduleSheetCommands("undo",!0,!1),!1;case"[ctrl-s]":if(!SocialCalc.Constants.AllowCtrlS)break;return window.setTimeout(function(){var t=e.context.sheetobj,o=t.GetAssuredCell(e.ecell.coord),a=o.nontextvalueformat?t.valueformats[o.nontextvalueformat-0]||"":"",l=window.prompt("Advanced Feature:\n\nCustom Numeric Format or Command",a);if(null!=l){if(l.match(/^cmd:/))r=l.substring(4);else{if(l.match(/^edit:/))return r=l.substring(5),void(SocialCalc.CtrlSEditor&&SocialCalc.CtrlSEditor(r));i=e.range.hasrange?SocialCalc.crToCoord(e.range.left,e.range.top)+":"+SocialCalc.crToCoord(e.range.right,e.range.bottom):e.ecell.coord,r="set "+i+" nontextvalueformat "+l}e.EditorScheduleSheetCommands(r,!0,!1)}},200),!1}return!0},e.sheetobj.statuscallback=SocialCalc.EditorSheetStatusCallback,e.sheetobj.statuscallbackparams=this,this.StatusCallback={},this.MoveECellCallback={},this.RangeChangeCallback={},this.SettingsCallbacks={},this.ecell={coord:"A1",row:1,col:1},e.highlights[this.ecell.coord]="cursor",this.range={hasrange:!1},this.range2={hasrange:!1}},SocialCalc.TableEditor.prototype.CreateTableEditor=function(e,t){return SocialCalc.CreateTableEditor(this,e,t)},SocialCalc.TableEditor.prototype.ResizeTableEditor=function(e,t){return SocialCalc.ResizeTableEditor(this,e,t)},SocialCalc.TableEditor.prototype.SaveEditorSettings=function(){return SocialCalc.SaveEditorSettings(this)},SocialCalc.TableEditor.prototype.LoadEditorSettings=function(e,t){return SocialCalc.LoadEditorSettings(this,e,t)},SocialCalc.TableEditor.prototype.EditorRenderSheet=function(){SocialCalc.EditorRenderSheet(this)},SocialCalc.TableEditor.prototype.EditorScheduleSheetCommands=function(e,t,o){SocialCalc.EditorScheduleSheetCommands(this,e,t,o)},SocialCalc.TableEditor.prototype.ScheduleSheetCommands=function(e,t){this.context.sheetobj.ScheduleSheetCommands(e,t)},SocialCalc.TableEditor.prototype.SheetUndo=function(){this.context.sheetobj.SheetUndo()},SocialCalc.TableEditor.prototype.SheetRedo=function(){this.context.sheetobj.SheetRedo()},SocialCalc.TableEditor.prototype.EditorStepSet=function(e,t){SocialCalc.EditorStepSet(this,e,t)},SocialCalc.TableEditor.prototype.GetStatuslineString=function(e,t,o){return SocialCalc.EditorGetStatuslineString(this,e,t,o)},SocialCalc.TableEditor.prototype.EditorMouseRegister=function(){return SocialCalc.EditorMouseRegister(this)},SocialCalc.TableEditor.prototype.EditorMouseUnregister=function(){return SocialCalc.EditorMouseUnregister(this)},SocialCalc.TableEditor.prototype.EditorMouseRange=function(e){return SocialCalc.EditorMouseRange(this,e)},SocialCalc.TableEditor.prototype.EditorProcessKey=function(e,t){return SocialCalc.EditorProcessKey(this,e,t)},SocialCalc.TableEditor.prototype.EditorAddToInput=function(e,t){return SocialCalc.EditorAddToInput(this,e,t)},SocialCalc.TableEditor.prototype.DisplayCellContents=function(){return SocialCalc.EditorDisplayCellContents(this)},SocialCalc.TableEditor.prototype.EditorSaveEdit=function(e){return SocialCalc.EditorSaveEdit(this,e)},SocialCalc.TableEditor.prototype.EditorApplySetCommandsToRange=function(e,t){return SocialCalc.EditorApplySetCommandsToRange(this,e,t)},SocialCalc.TableEditor.prototype.MoveECellWithKey=function(e){return SocialCalc.MoveECellWithKey(this,e)},SocialCalc.TableEditor.prototype.MoveECell=function(e){return SocialCalc.MoveECell(this,e)},SocialCalc.TableEditor.prototype.ReplaceCell=function(e,t,o){SocialCalc.ReplaceCell(this,e,t,o)},SocialCalc.TableEditor.prototype.UpdateCellCSS=function(e,t,o){SocialCalc.UpdateCellCSS(this,e,t,o)},SocialCalc.TableEditor.prototype.SetECellHeaders=function(e){SocialCalc.SetECellHeaders(this,e)},SocialCalc.TableEditor.prototype.EnsureECellVisible=function(){SocialCalc.EnsureECellVisible(this)},SocialCalc.TableEditor.prototype.ECellReadonly=function(e){return SocialCalc.ECellReadonly(this,e)},SocialCalc.TableEditor.prototype.RangeAnchor=function(e){SocialCalc.RangeAnchor(this,e)},SocialCalc.TableEditor.prototype.RangeExtend=function(e){SocialCalc.RangeExtend(this,e)},SocialCalc.TableEditor.prototype.RangeRemove=function(){SocialCalc.RangeRemove(this)},SocialCalc.TableEditor.prototype.Range2Remove=function(){SocialCalc.Range2Remove(this)},SocialCalc.TableEditor.prototype.FitToEditTable=function(){SocialCalc.FitToEditTable(this)},SocialCalc.TableEditor.prototype.CalculateEditorPositions=function(){SocialCalc.CalculateEditorPositions(this)},SocialCalc.TableEditor.prototype.ScheduleRender=function(){SocialCalc.ScheduleRender(this)},SocialCalc.TableEditor.prototype.DoRenderStep=function(){SocialCalc.DoRenderStep(this)},SocialCalc.TableEditor.prototype.SchedulePositionCalculations=function(){SocialCalc.SchedulePositionCalculations(this)},SocialCalc.TableEditor.prototype.DoPositionCalculations=function(){SocialCalc.DoPositionCalculations(this)},SocialCalc.TableEditor.prototype.CalculateRowPositions=function(e,t,o){return SocialCalc.CalculateRowPositions(this,e,t,o)},SocialCalc.TableEditor.prototype.CalculateColPositions=function(e,t,o){return SocialCalc.CalculateColPositions(this,e,t,o)},SocialCalc.TableEditor.prototype.ScrollRelative=function(e,t){SocialCalc.ScrollRelative(this,e,t)},SocialCalc.TableEditor.prototype.ScrollRelativeBoth=function(e,t){SocialCalc.ScrollRelativeBoth(this,e,t)},SocialCalc.TableEditor.prototype.PageRelative=function(e,t){SocialCalc.PageRelative(this,e,t)},SocialCalc.TableEditor.prototype.LimitLastPanes=function(){SocialCalc.LimitLastPanes(this)},SocialCalc.TableEditor.prototype.ScrollTableUpOneRow=function(){return SocialCalc.ScrollTableUpOneRow(this)},SocialCalc.TableEditor.prototype.ScrollTableDownOneRow=function(){return SocialCalc.ScrollTableDownOneRow(this)},SocialCalc.TableEditor.prototype.ScrollTableLeftOneCol=function(){return SocialCalc.ScrollTableLeftOneCol(this)},SocialCalc.TableEditor.prototype.ScrollTableRightOneCol=function(){return SocialCalc.ScrollTableRightOneCol(this)},SocialCalc.CreateTableEditor=function(e,t,o){var a=SocialCalc.Constants,l=SocialCalc.AssignID;e.toplevel=document.createElement("div"),e.toplevel.style.position="relative",l(e,e.toplevel,"toplevel"),e.width=t,e.height=o,e.griddiv=document.createElement("div"),e.tablewidth=Math.max(0,t-a.defaultTableControlThickness-5),e.tableheight=Math.max(0,o-a.defaultTableControlThickness-5),e.griddiv.style.width=e.tablewidth+"px",e.griddiv.style.height=e.tableheight+"px",e.griddiv.style.overflow="hidden",e.griddiv.style.cursor="default",a.cteGriddivClass&&(e.griddiv.className=a.cteGriddivClass),
l(e,e.griddiv,"griddiv"),e.FitToEditTable(),e.EditorRenderSheet(),e.griddiv.appendChild(e.fullgrid),e.verticaltablecontrol=new SocialCalc.TableControl(e,!0,e.tableheight),e.verticaltablecontrol.CreateTableControl(),l(e,e.verticaltablecontrol.main,"tablecontrolv"),e.horizontaltablecontrol=new SocialCalc.TableControl(e,!1,e.tablewidth),e.horizontaltablecontrol.CreateTableControl(),l(e,e.horizontaltablecontrol.main,"tablecontrolh");var r,i,n,c,s;return r=document.createElement("table"),e.layouttable=r,r.cellSpacing=0,r.cellPadding=0,l(e,r,"layouttable"),i=document.createElement("tbody"),r.appendChild(i),n=document.createElement("tr"),i.appendChild(n),c=document.createElement("td"),c.appendChild(e.griddiv),n.appendChild(c),c=document.createElement("td"),c.appendChild(e.verticaltablecontrol.main),n.appendChild(c),n=document.createElement("tr"),i.appendChild(n),c=document.createElement("td"),c.appendChild(e.horizontaltablecontrol.main),n.appendChild(c),c=document.createElement("td"),c.style.background="url("+e.imageprefix+"logo.gif) no-repeat center center",c.innerHTML="<div style='cursor:pointer;font-size:1px;'><img src='"+e.imageprefix+"1x1.gif' border='0' width='18' height='18'></div>",n.appendChild(c),e.logo=c,l(e,e.logo,"logo"),SocialCalc.TooltipRegister(c.firstChild.firstChild,"SocialCalc",null,e.toplevel),e.toplevel.appendChild(e.layouttable),e.noEdit||(e.inputEcho=new SocialCalc.InputEcho(e),l(e,e.inputEcho.main,"inputecho")),e.cellhandles=new SocialCalc.CellHandles(e),s=document.createElement("textarea"),SocialCalc.setStyles(s,"display:none;position:absolute;height:1px;width:1px;opacity:0;filter:alpha(opacity=0);"),s.value="",e.pasteTextarea=s,l(e,e.pasteTextarea,"pastetextarea"),navigator.userAgent.match(/Safari\//)&&!navigator.userAgent.match(/Chrome\//)&&(window.removeEventListener("beforepaste",SocialCalc.SafariPasteFunction,!1),window.addEventListener("beforepaste",SocialCalc.SafariPasteFunction,!1),window.removeEventListener("beforecopy",SocialCalc.SafariPasteFunction,!1),window.addEventListener("beforecopy",SocialCalc.SafariPasteFunction,!1),window.removeEventListener("beforecut",SocialCalc.SafariPasteFunction,!1),window.addEventListener("beforecut",SocialCalc.SafariPasteFunction,!1)),e.toplevel.appendChild(e.pasteTextarea),SocialCalc.MouseWheelRegister(e.toplevel,{WheelMove:SocialCalc.EditorProcessMouseWheel,editor:e}),SocialCalc.KeyboardSetFocus(e),SocialCalc.EditorSheetStatusCallback(null,"startup",null,e),e.toplevel},SocialCalc.SafariPasteFunction=function(e){e.preventDefault()},SocialCalc.ResizeTableEditor=function(e,t,o){var a=SocialCalc.Constants;e.width=t,e.height=o,e.toplevel.style.width="100%",e.toplevel.style.height=o+"px",e.tablewidth=Math.max(0,t-a.defaultTableControlThickness-5),e.tableheight=Math.max(0,o-a.defaultTableControlThickness),e.griddiv.style.width=e.tablewidth+"px",e.griddiv.style.height=e.tableheight+"px",e.verticaltablecontrol.main.style.height=e.tableheight+"px",e.horizontaltablecontrol.main.style.width=e.tablewidth+"px",e.FitToEditTable(),e.ScheduleRender()},SocialCalc.SaveEditorSettings=function(e){var t,o,a=e.context,l=e.range,r="";for(r+="version:1.0\n",t=0;t<a.rowpanes.length;t++)r+="rowpane:"+t+":"+a.rowpanes[t].first+":"+a.rowpanes[t].last+"\n";for(t=0;t<a.colpanes.length;t++)r+="colpane:"+t+":"+a.colpanes[t].first+":"+a.colpanes[t].last+"\n";e.ecell&&(r+="ecell:"+e.ecell.coord+"\n"),l.hasrange&&(r+="range:"+l.anchorcoord+":"+l.top+":"+l.bottom+":"+l.left+":"+l.right+"\n");for(o in e.SettingsCallbacks)r+=e.SettingsCallbacks[o].save(e,o);return r},SocialCalc.LoadEditorSettings=function(e,t,o){var a,l,r,i,n,c,s,d,u,p=t.split(/\r\n|\n/),m=[],h=e.context;for(h.rowpanes=[{first:1,last:1}],h.colpanes=[{first:1,last:1}],e.ecell=null,e.range={hasrange:!1},e.range2={hasrange:!1},u=e.range,h.highlights={},d=h.highlights,l=0;l<p.length;l++)switch(a=p[l],m=a.split(":"),s=m[0]){case"version":break;case"rowpane":h.rowpanes[m[1]-0]={first:m[2]-0,last:m[3]-0};break;case"colpane":h.colpanes[m[1]-0]={first:m[2]-0,last:m[3]-0};break;case"ecell":e.ecell=SocialCalc.coordToCr(m[1]),e.ecell.coord=m[1],d[m[1]]="cursor";break;case"range":for(u.hasrange=!0,u.anchorcoord=m[1],r=SocialCalc.coordToCr(u.anchorcoord),u.anchorrow=r.row,u.anchorcol=r.col,u.top=m[2]-0,u.bottom=m[3]-0,u.left=m[4]-0,u.right=m[5]-0,i=u.top;i<=u.bottom;i++)for(n=u.left;n<=u.right;n++)c=SocialCalc.crToCoord(n,i),"cursor"!=d[c]&&(d[c]="range");break;default:e.SettingsCallbacks[s]&&e.SettingsCallbacks[s].load(e,s,a,o)}},SocialCalc.EditorRenderSheet=function(e){e.EditorMouseUnregister(),e.fullgrid=e.context.RenderSheet(e.fullgrid),e.ecell&&e.SetECellHeaders("selected"),SocialCalc.AssignID(e,e.fullgrid,"fullgrid"),e.EditorMouseRegister()},SocialCalc.EditorScheduleSheetCommands=function(e,t,o,a){if("start"==e.state||a){if(e.busy&&!a)return void e.deferredCommands.push({cmdstr:t,saveundo:o});switch(t){case"recalc":case"redisplay":e.context.sheetobj.ScheduleSheetCommands(t,!1);break;case"undo":e.SheetUndo();break;case"redo":e.SheetRedo();break;default:e.context.sheetobj.ScheduleSheetCommands(t,o)}}},SocialCalc.EditorSheetStatusCallback=function(e,t,o,a){var l,r,i,n=a.context.sheetobj,c=function(e){for(l in a.StatusCallback)a.StatusCallback[l].func&&a.StatusCallback[l].func(a,e,o,a.StatusCallback[l].params)};switch(t){case"startup":break;case"cmdstart":a.busy=!0,n.celldisplayneeded="";break;case"cmdextension":break;case"cmdend":if(c(t),n.changedrendervalues&&(a.context.PrecomputeSheetFontsAndLayouts(),a.context.CalculateCellSkipData(),n.changedrendervalues=!1),n.celldisplayneeded&&!n.renderneeded&&(cr=SocialCalc.coordToCr(n.celldisplayneeded),r=SocialCalc.GetEditorCellElement(a,cr.row,cr.col),a.ReplaceCell(r,cr.row,cr.col)),a.deferredCommands.length)return i=a.deferredCommands.shift(),void a.EditorScheduleSheetCommands(i.cmdstr,i.saveundo,!0);if(n.attribs.needsrecalc&&("off"!=n.attribs.recalc||n.recalconce)&&a.recalcFunction?(a.FitToEditTable(),n.renderneeded=!1,n.recalconce&&delete n.recalconce,a.recalcFunction(a)):n.renderneeded?(a.FitToEditTable(),n.renderneeded=!1,a.ScheduleRender()):a.SchedulePositionCalculations(),"col"==n.hiddencolrow){for(var s=a.ecell.col;"yes"==n.colattribs.hide[SocialCalc.rcColname(s)];)s++;var d=SocialCalc.crToCoord(s,a.ecell.row);a.MoveECell(d),n.hiddencolrow=""}if("row"==n.hiddencolrow){for(var u=a.ecell.row;"yes"==n.rowattribs.hide[u];)u++;var d=SocialCalc.crToCoord(a.ecell.col,u);a.MoveECell(d),n.hiddencolrow=""}return;case"calcstart":a.busy=!0;break;case"calccheckdone":case"calcorder":case"calcstep":case"calcloading":case"calcserverfunc":break;case"calcfinished":return c(t),void a.ScheduleRender();case"schedrender":a.busy=!0;break;case"renderdone":break;case"schedposcalc":a.busy=!0;break;case"doneposcalc":return void(a.deferredCommands.length?(c(t),i=a.deferredCommands.shift(),a.EditorScheduleSheetCommands(i.cmdstr,i.saveundo,!0)):(a.busy=!1,c(t),"start"==a.state&&a.DisplayCellContents()));default:addmsg("Unknown status: "+t)}c(t)},SocialCalc.EditorGetStatuslineString=function(e,t,o,a){var l,r,i,n,c,s,d,u,p=SocialCalc.Constants;switch(r="",t){case"moveecell":case"rangechange":case"startup":break;case"cmdstart":a.command=!0,document.body.style.cursor="progress",e.griddiv.style.cursor="progress",r=p.s_statusline_executing;break;case"cmdextension":r="Command Extension: "+o;break;case"cmdend":a.command=!1;break;case"schedrender":r=p.s_statusline_displaying;break;case"renderdone":r=" ";break;case"schedposcalc":r=p.s_statusline_displaying;break;case"cmdendnorender":case"doneposcalc":document.body.style.cursor="default",e.griddiv.style.cursor="default";break;case"calcorder":r=p.s_statusline_ordering+Math.floor(100*o.count/(o.total||1))+"%";break;case"calcstep":r=p.s_statusline_calculating+Math.floor(100*o.count/(o.total||1))+"%";break;case"calcloading":r=p.s_statusline_calculatingls+": "+o.sheetname;break;case"calcserverfunc":r=p.s_statusline_calculating+Math.floor(100*o.count/(o.total||1))+"%, "+p.s_statusline_doingserverfunc+o.funcname+p.s_statusline_incell+o.coord;break;case"calcstart":a.calculating=!0,document.body.style.cursor="progress",e.griddiv.style.cursor="progress",r=p.s_statusline_calcstart;break;case"calccheckdone":break;case"calcfinished":a.calculating=!1;break;default:r=t}if(!r&&a.calculating&&(r=p.s_statusline_calculating),!a.calculating&&!a.command&&!r&&e.range.hasrange&&(e.range.left!=e.range.right||e.range.top!=e.range.bottom)){for(u=0,c=e.range.top;c<=e.range.bottom;c++)for(s=e.range.left;s<=e.range.right;s++)d=e.context.sheetobj.cells[SocialCalc.crToCoord(s,c)],d&&d.valuetype&&"n"==d.valuetype.charAt(0)&&(u+=d.datavalue-0);u=SocialCalc.FormatNumber.formatNumberWithFormat(u,"[,]General",""),i=SocialCalc.crToCoord(e.range.left,e.range.top)+":"+SocialCalc.crToCoord(e.range.right,e.range.bottom),r=i+" ("+(e.range.right-e.range.left+1)+"x"+(e.range.bottom-e.range.top+1)+") "+p.s_statusline_sum+"="+u+" "+r}return l=e.ecell.coord+" "+r,a.calculating||"yes"!=e.context.sheetobj.attribs.needsrecalc||(l+=" "+p.s_statusline_recalcneeded),n=e.context.sheetobj.attribs.circularreferencecell,n&&(n=n.replace(/\|/," referenced by "),l+=" "+p.s_statusline_circref+n+"</span>"),l},SocialCalc.EditorMouseInfo={registeredElements:[],editor:null,element:null,ignore:!1,mousedowncoord:"",mouselastcoord:"",mouseresizecol:"",mouseresizeclientx:null,mouseresizedisplay:null},SocialCalc.EditorMouseRegister=function(e){var t,o=SocialCalc.EditorMouseInfo,a=e.fullgrid;for(t=0;t<o.registeredElements.length;t++)if(o.registeredElements[t].editor==e){if(o.registeredElements[t].element==a)return;break}if(t<o.registeredElements.length?o.registeredElements[t].element=a:o.registeredElements.push({element:a,editor:e}),a.addEventListener)a.addEventListener("mousedown",SocialCalc.ProcessEditorMouseDown,!1),a.addEventListener("dblclick",SocialCalc.ProcessEditorDblClick,!1);else{if(!a.attachEvent)throw"Browser not supported";a.attachEvent("onmousedown",SocialCalc.ProcessEditorMouseDown),a.attachEvent("ondblclick",SocialCalc.ProcessEditorDblClick)}o.ignore=!1},SocialCalc.EditorMouseUnregister=function(e){var t,o,a=SocialCalc.EditorMouseInfo;e.fullgrid;for(t=0;t<a.registeredElements.length&&a.registeredElements[t].editor!=e;t++);t<a.registeredElements.length&&(o=a.registeredElements[t].element,o.removeEventListener?(o.removeEventListener("mousedown",SocialCalc.ProcessEditorMouseDown,!1),o.removeEventListener("dblclick",SocialCalc.ProcessEditorDblClick,!1)):o.detachEvent&&(o.detachEvent("onmousedown",SocialCalc.ProcessEditorMouseDown),o.detachEvent("ondblclick",SocialCalc.ProcessEditorDblClick)),a.registeredElements.splice(t,1))},SocialCalc.ProcessEditorMouseDown=function(e){var t,o,a,l,r,i=e||window.event,n=SocialCalc.EditorMouseInfo,c=i.target||i.srcElement;if(!n.ignore){for(r=null;!r&&c;c=c.parentNode)r=SocialCalc.LookupElement(c,n.registeredElements);if(!r)return void(n.editor=null);t=r.editor,n.element=c,l=t.range;var s=SocialCalc.GetElementPositionWithScroll(t.toplevel),d=i.clientX-s.left,u=i.clientY-s.top;if(o=SocialCalc.GridMousePosition(t,d,u))return n.editor=t,o.rowheader&&o.rowtounhide?void SocialCalc.ProcessEditorRowsizeMouseDown(e,c,o):o.colheader&&o.coltoresize?void SocialCalc.ProcessEditorColsizeMouseDown(e,c,o):void(o.coord&&(l.hasrange||e.shiftKey&&t.RangeAnchor(),a=t.MoveECell(o.coord),l.hasrange&&(e.shiftKey?t.RangeExtend():t.RangeRemove()),n.mousedowncoord=a,n.mouselastcoord=a,t.EditorMouseRange(a),SocialCalc.KeyboardSetFocus(t),"start"!=t.state&&t.inputBox&&t.inputBox.element.focus(),document.addEventListener?(document.addEventListener("mousemove",SocialCalc.ProcessEditorMouseMove,!0),document.addEventListener("mouseup",SocialCalc.ProcessEditorMouseUp,!0)):c.attachEvent&&(c.setCapture(),c.attachEvent("onmousemove",SocialCalc.ProcessEditorMouseMove),c.attachEvent("onmouseup",SocialCalc.ProcessEditorMouseUp),c.attachEvent("onlosecapture",SocialCalc.ProcessEditorMouseUp)),i.stopPropagation?i.stopPropagation():i.cancelBubble=!0,i.preventDefault?i.preventDefault():i.returnValue=!1))}},SocialCalc.EditorMouseRange=function(e,t){var o,a,l=e.range;switch(e.state){case"input":o=e.inputBox.GetText(),a=e.workingvalues,("(+-*/,:!&<>=^".indexOf(o.slice(-1))>=0&&"="==o.slice(0,1)||"="==o)&&(a.partialexpr=o),a.partialexpr?t&&(l.hasrange?e.inputBox.SetText(a.partialexpr+SocialCalc.crToCoord(l.left,l.top)+":"+SocialCalc.crToCoord(l.right,l.bottom)):e.inputBox.SetText(a.partialexpr+t)):(e.inputBox.Blur(),e.inputBox.ShowInputBox(!1),e.state="start",e.cellhandles.ShowCellHandles(!0),e.EditorSaveEdit(),e.inputBox.DisplayCellContents(null));break;case"inputboxdirect":e.inputBox.Blur(),e.inputBox.ShowInputBox(!1),e.state="start",e.cellhandles.ShowCellHandles(!0),e.EditorSaveEdit(),e.inputBox.DisplayCellContents(null)}},SocialCalc.ProcessEditorMouseMove=function(e){var t,o,a,l=e||window.event,r=SocialCalc.EditorMouseInfo;if(t=r.editor,t&&!r.ignore){o=r.element;var i=SocialCalc.GetElementPositionWithScroll(t.toplevel),n=l.clientX-i.left,c=l.clientY-i.top;if(a=SocialCalc.GridMousePosition(t,n,c)){if(a&&!a.coord)return void SocialCalc.SetDragAutoRepeat(t,a);SocialCalc.SetDragAutoRepeat(t,null),a.coord&&(a.coord!=r.mouselastcoord&&(e.shiftKey||t.range.hasrange||t.RangeAnchor(r.mousedowncoord),t.MoveECell(a.coord),t.RangeExtend()),r.mouselastcoord=a.coord,t.EditorMouseRange(a.coord),l.stopPropagation?l.stopPropagation():l.cancelBubble=!0,l.preventDefault?l.preventDefault():l.returnValue=!1)}}},SocialCalc.ProcessEditorMouseUp=function(e){var t,o,a,l=e||window.event,r=SocialCalc.EditorMouseInfo;if(t=r.editor,t&&!r.ignore){o=r.element;var i=SocialCalc.GetElementPositionWithScroll(t.toplevel),n=l.clientX-i.left,c=l.clientY-i.top;if(a=SocialCalc.GridMousePosition(t,n,c),SocialCalc.SetDragAutoRepeat(t,null),a)return a.coord||(a.coord=t.ecell.coord),t.range.hasrange?(t.MoveECell(a.coord),t.RangeExtend()):a.coord&&a.coord!=r.mousedowncoord&&(t.RangeAnchor(r.mousedowncoord),t.MoveECell(a.coord),t.RangeExtend()),t.EditorMouseRange(a.coord),l.stopPropagation?l.stopPropagation():l.cancelBubble=!0,l.preventDefault?l.preventDefault():l.returnValue=!1,document.removeEventListener?(document.removeEventListener("mousemove",SocialCalc.ProcessEditorMouseMove,!0),document.removeEventListener("mouseup",SocialCalc.ProcessEditorMouseUp,!0)):o.detachEvent&&(o.detachEvent("onlosecapture",SocialCalc.ProcessEditorMouseUp),o.detachEvent("onmouseup",SocialCalc.ProcessEditorMouseUp),o.detachEvent("onmousemove",SocialCalc.ProcessEditorMouseMove),o.releaseCapture()),r.editor=null,!1}},SocialCalc.ProcessEditorColsizeMouseDown=function(e,t,o){var a=e||window.event,l=SocialCalc.EditorMouseInfo,r=l.editor,i=SocialCalc.GetElementPositionWithScroll(r.toplevel),n=a.clientX-i.left;if(l.mouseresizecolnum=o.coltoresize,l.mouseresizecol=SocialCalc.rcColname(o.coltoresize),l.mousedownclientx=n,l.mousecoltounhide=o.coltounhide,!l.mousecoltounhide){var c=document.createElement("div");l.mouseresizedisplay=c,c.style.width="auto",c.style.position="absolute",c.style.zIndex=100,c.style.top=r.headposition.top+"px",c.style.left=r.colpositions[o.coltoresize]+"px",c.innerHTML='<table cellpadding="0" cellspacing="0"><tr><td style="height:100px;border:1px dashed black;background-color:white;width:'+(r.context.colwidth[l.mouseresizecolnum]-2)+'px;"> </td><td><div style="font-size:small;color:white;background-color:gray;padding:4px;">'+r.context.colwidth[l.mouseresizecolnum]+"</div></td></tr></table>",SocialCalc.setStyles(c.firstChild.lastChild.firstChild.childNodes[0],"filter:alpha(opacity=85);opacity:.85;"),r.toplevel.appendChild(c)}document.addEventListener?(document.addEventListener("mousemove",SocialCalc.ProcessEditorColsizeMouseMove,!0),document.addEventListener("mouseup",SocialCalc.ProcessEditorColsizeMouseUp,!0)):r.toplevel.attachEvent&&(r.toplevel.setCapture(),r.toplevel.attachEvent("onmousemove",SocialCalc.ProcessEditorColsizeMouseMove),r.toplevel.attachEvent("onmouseup",SocialCalc.ProcessEditorColsizeMouseUp),r.toplevel.attachEvent("onlosecapture",SocialCalc.ProcessEditorColsizeMouseUp)),a.stopPropagation?a.stopPropagation():a.cancelBubble=!0,a.preventDefault?a.preventDefault():a.returnValue=!1},SocialCalc.ProcessEditorColsizeMouseMove=function(e){var t=e||window.event,o=SocialCalc.EditorMouseInfo,a=o.editor;if(a){if(!o.mousecoltounhide){var l=SocialCalc.GetElementPositionWithScroll(a.toplevel),r=t.clientX-l.left,i=a.context.colwidth[o.mouseresizecolnum]-0+(r-o.mousedownclientx);i<SocialCalc.Constants.defaultMinimumColWidth&&(i=SocialCalc.Constants.defaultMinimumColWidth);var n=o.mouseresizedisplay;n.innerHTML='<table cellpadding="0" cellspacing="0"><tr><td style="height:100px;border:1px dashed black;background-color:white;width:'+(i-2)+'px;"> </td><td><div style="font-size:small;color:white;background-color:gray;padding:4px;">'+i+"</div></td></tr></table>",SocialCalc.setStyles(n.firstChild.lastChild.firstChild.childNodes[0],"filter:alpha(opacity=85);opacity:.85;")}t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1}},SocialCalc.ProcessEditorColsizeMouseUp=function(e){var t=e||window.event,o=SocialCalc.EditorMouseInfo,a=o.editor;if(a){element=o.element;var l=SocialCalc.GetElementPositionWithScroll(a.toplevel),r=t.clientX-l.left;if(t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1,document.removeEventListener?(document.removeEventListener("mousemove",SocialCalc.ProcessEditorColsizeMouseMove,!0),document.removeEventListener("mouseup",SocialCalc.ProcessEditorColsizeMouseUp,!0)):a.toplevel.detachEvent&&(a.toplevel.detachEvent("onlosecapture",SocialCalc.ProcessEditorColsizeMouseUp),a.toplevel.detachEvent("onmouseup",SocialCalc.ProcessEditorColsizeMouseUp),a.toplevel.detachEvent("onmousemove",SocialCalc.ProcessEditorColsizeMouseMove),a.toplevel.releaseCapture()),o.mousecoltounhide)a.EditorScheduleSheetCommands("set "+SocialCalc.rcColname(o.mousecoltounhide)+" hide",!0,!1);else{var i=a.context.colwidth[o.mouseresizecolnum]-0+(r-o.mousedownclientx);i<SocialCalc.Constants.defaultMinimumColWidth&&(i=SocialCalc.Constants.defaultMinimumColWidth),a.EditorScheduleSheetCommands("set "+o.mouseresizecol+" width "+i,!0,!1),a.timeout&&window.clearTimeout(a.timeout),a.timeout=window.setTimeout(SocialCalc.FinishColsize,1)}return!1}},SocialCalc.FinishColsize=function(){var e=SocialCalc.EditorMouseInfo,t=e.editor;t&&(t.toplevel.removeChild(e.mouseresizedisplay),e.mouseresizedisplay=null,e.editor=null)},SocialCalc.ProcessEditorRowsizeMouseDown=function(e,t,o){var a=e||window.event,l=SocialCalc.EditorMouseInfo,r=l.editor,i=SocialCalc.GetElementPositionWithScroll(r.toplevel);a.clientX-i.left;l.mouserowtounhide=o.rowtounhide,document.addEventListener?(document.addEventListener("mousemove",SocialCalc.ProcessEditorRowsizeMouseMove,!0),document.addEventListener("mouseup",SocialCalc.ProcessEditorRowsizeMouseUp,!0)):r.toplevel.attachEvent&&(r.toplevel.setCapture(),r.toplevel.attachEvent("onmousemove",SocialCalc.ProcessEditorRowsizeMouseMove),r.toplevel.attachEvent("onmouseup",SocialCalc.ProcessEditorRowsizeMouseUp),r.toplevel.attachEvent("onlosecapture",SocialCalc.ProcessEditorRowsizeMouseUp)),a.stopPropagation?a.stopPropagation():a.cancelBubble=!0,a.preventDefault?a.preventDefault():a.returnValue=!1},SocialCalc.ProcessEditorRowsizeMouseMove=function(e){var t=e||window.event,o=SocialCalc.EditorMouseInfo,a=o.editor;a&&(t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1)},SocialCalc.ProcessEditorRowsizeMouseUp=function(e){var t=e||window.event,o=SocialCalc.EditorMouseInfo,a=o.editor;if(a){element=o.element;var l=SocialCalc.GetElementPositionWithScroll(a.toplevel);t.clientX-l.left;return t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1,document.removeEventListener?(document.removeEventListener("mousemove",SocialCalc.ProcessEditorRowsizeMouseMove,!0),document.removeEventListener("mouseup",SocialCalc.ProcessEditorRowsizeMouseUp,!0)):a.toplevel.detachEvent&&(a.toplevel.detachEvent("onlosecapture",SocialCalc.ProcessEditorRowsizeMouseUp),a.toplevel.detachEvent("onmouseup",SocialCalc.ProcessEditorRowsizeMouseUp),a.toplevel.detachEvent("onmousemove",SocialCalc.ProcessEditorRowsizeMouseMove),a.toplevel.releaseCapture()),o.mouserowtounhide&&a.EditorScheduleSheetCommands("set "+o.mouserowtounhide+" hide",!0,!1),!1}},SocialCalc.AutoRepeatInfo={timer:null,mouseinfo:null,repeatinterval:1e3,editor:null,repeatcallback:null},SocialCalc.SetDragAutoRepeat=function(e,t,o){var a,l,r=SocialCalc.AutoRepeatInfo;if(r.repeatcallback=o,!t)return r.timer&&(window.clearTimeout(r.timer),r.timer=null),void(r.mouseinfo=null);if(r.editor=e,r.mouseinfo&&(t.rowheader||t.rowfooter?t.row!=r.mouseinfo.row&&(a=SocialCalc.crToCoord(e.ecell.col,t.row),r.repeatcallback?(l=t.row<r.mouseinfo.row?"left":t.row>r.mouseinfo.row?"right":"",r.repeatcallback(a,l)):(e.MoveECell(a),e.MoveECell(a),e.RangeExtend(),e.EditorMouseRange(a))):(t.colheader||t.colfooter)&&t.col!=r.mouseinfo.col&&(a=SocialCalc.crToCoord(t.col,e.ecell.row),r.repeatcallback?(l=t.row<r.mouseinfo.row?"left":t.row>r.mouseinfo.row?"right":"",r.repeatcallback(a,l)):(e.MoveECell(a),e.RangeExtend(),e.EditorMouseRange(a)))),r.mouseinfo=t,t.distance<5)r.repeatinterval=333;else if(t.distance<10)r.repeatinterval=250;else if(t.distance<25)r.repeatinterval=100;else{if(!(t.distance<35))return void(r.timer&&(window.clearTimeout(r.timer),r.timer=null));r.repeatinterval=75}r.timer||(r.timer=window.setTimeout(SocialCalc.DragAutoRepeat,r.repeatinterval))},SocialCalc.DragAutoRepeat=function(){var e,t,o,a=SocialCalc.AutoRepeatInfo,l=a.mouseinfo;l.rowheader?e="left":l.rowfooter?e="right":l.colheader?e="up":l.colfooter&&(e="down"),a.repeatcallback?(o=SocialCalc.coordToCr(a.editor.ecell.coord),"left"==e&&o.col>1?o.col--:"right"==e?o.col++:"up"==e&&o.row>1?o.row--:"down"==e&&o.row++,t=SocialCalc.crToCoord(o.col,o.row),a.repeatcallback(t,e)):(t=a.editor.MoveECellWithKey("[a"+e+"]shifted"),t&&a.editor.EditorMouseRange(t)),a.timer=window.setTimeout(SocialCalc.DragAutoRepeat,a.repeatinterval)},SocialCalc.ProcessEditorDblClick=function(e){var t,o,a,l,r=e||window.event,i=SocialCalc.EditorMouseInfo,n=r.target||r.srcElement;if(!i.ignore){for(l=null;!l&&n;n=n.parentNode)l=SocialCalc.LookupElement(n,i.registeredElements);if(!l)return void(i.editor=null);t=l.editor;var c=SocialCalc.GetElementPositionWithScroll(t.toplevel),s=r.clientX-c.left,d=r.clientY-c.top;if(o=SocialCalc.GridMousePosition(t,s,d),o&&o.coord){switch(i.editor=t,i.element=n,a=t.range,sheetobj=t.context.sheetobj,t.state){case"start":SocialCalc.EditorOpenCellEdit(t);break;case"input":}r.stopPropagation?r.stopPropagation():r.cancelBubble=!0,r.preventDefault?r.preventDefault():r.returnValue=!1}}},SocialCalc.EditorOpenCellEdit=function(e){var t;return e.ecell&&e.inputBox?e.inputBox.element.disabled?!0:(e.inputBox.ShowInputBox(!0),e.inputBox.Focus(),e.state="inputboxdirect",e.inputBox.SetText(""),e.inputBox.DisplayCellContents(),e.inputBox.Select("end"),t=e.workingvalues,t.partialexpr="",t.ecoord=e.ecell.coord,t.erow=e.ecell.row,void(t.ecol=e.ecell.col)):!0},SocialCalc.EditorProcessKey=function(e,t,o){var a,l,r,i,n=(e.context.sheetobj,e.workingvalues),c=e.range;switch("string"!=typeof t&&(t=""),e.state){case"start":if(o.shiftKey&&"[a"==t.substr(0,2)&&(t+="shifted"),"[enter]"==t&&(t="[adown]"),"[tab]"==t&&(t=o.shiftKey?"[aleft]":"[aright]"),"[a"==t.substr(0,2)||"[pg"==t.substr(0,3)||"[home]"==t)return a=e.MoveECellWithKey(t),!a;if("[del]"==t||"[backspace]"==t){e.noEdit||e.ECellReadonly()||e.EditorApplySetCommandsToRange("empty","");break}if("[esc]"==t){if(c.hasrange){e.RangeRemove(),e.MoveECell(c.anchorcoord);for(i in e.StatusCallback)e.StatusCallback[i].func(e,"specialkey",t,e.StatusCallback[i].params)}return!1}if("[f2]"==t)return e.noEdit||e.ECellReadonly()?!0:(SocialCalc.EditorOpenCellEdit(e),!1);if(t.length>1&&"["==t.substr(0,1)||0==t.length)return e.ctrlkeyFunction&&t.length>0?e.ctrlkeyFunction(e,t):!0;if(!e.ecell)return!0;if(!e.inputBox)return!0;if(e.ECellReadonly())return!0;e.inputBox.element.disabled=!1,e.state="input",e.inputBox.ShowInputBox(!0),e.inputBox.Focus(),e.inputBox.SetText(t),e.inputBox.Select("end"),n.partialexpr="",n.ecoord=e.ecell.coord,n.erow=e.ecell.row,n.ecol=e.ecell.col,e.RangeRemove();break;case"input":if(r=e.inputBox.GetText(),e.inputBox.skipOne)return!1;if("[esc]"==t||"[enter]"==t||"[tab]"==t||t&&"[a"==t.substr(0,2)){if(("(+-*/,:!&<>=^".indexOf(r.slice(-1))>=0&&"="==r.slice(0,1)||"="==r)&&(n.partialexpr=r),n.partialexpr&&(o.shiftKey&&"[a"==t.substr(0,2)&&(t+="shifted"),l=e.MoveECellWithKey(t)))return c.hasrange?e.inputBox.SetText(n.partialexpr+SocialCalc.crToCoord(c.left,c.top)+":"+SocialCalc.crToCoord(c.right,c.bottom)):e.inputBox.SetText(n.partialexpr+l),!1;e.inputBox.Blur(),e.inputBox.ShowInputBox(!1),e.state="start",e.cellhandles.ShowCellHandles(!0),"[esc]"!=t?(e.EditorSaveEdit(),e.ecell.coord!=n.ecoord&&e.MoveECell(n.ecoord),"[enter]"==t&&(t="[adown]"),"[tab]"==t&&(t=o.shiftKey?"[aleft]":"[aright]"),"[a"==t.substr(0,2)&&e.MoveECellWithKey(t)):(e.inputBox.DisplayCellContents(),e.RangeRemove(),e.MoveECell(n.ecoord));break}return n.partialexpr&&"[backspace]"==t?(e.inputBox.SetText(n.partialexpr),n.partialexpr="",e.RangeRemove(),e.MoveECell(n.ecoord),e.inputBox.ShowInputBox(!0),!1):"[f2]"==t?!1:(c.hasrange&&e.RangeRemove(),e.MoveECell(n.ecoord),n.partialexpr&&(e.inputBox.ShowInputBox(!0),n.partialexpr=""),!0);case"inputboxdirect":if(r=e.inputBox.GetText(),"[esc]"==t||"[enter]"==t||"[tab]"==t){e.inputBox.Blur(),e.inputBox.ShowInputBox(!1),e.state="start",e.cellhandles.ShowCellHandles(!0),"[esc]"==t?e.inputBox.DisplayCellContents():(e.EditorSaveEdit(),e.ecell.coord!=n.ecoord&&e.MoveECell(n.ecoord),"[enter]"==t&&(t="[adown]"),"[tab]"==t&&(t=o.shiftKey?"[aleft]":"[aright]"),"[a"==t.substr(0,2)&&e.MoveECellWithKey(t));break}return"[f2]"==t?!1:!0;case"skip-and-start":return e.state="start",e.cellhandles.ShowCellHandles(!0),!1;default:return!0}return!1},SocialCalc.EditorAddToInput=function(e,t,o){var a=e.workingvalues;if(!e.noEdit&&!e.ECellReadonly())switch(e.state){case"start":e.state="input",e.inputBox.ShowInputBox(!0),e.inputBox.element.disabled=!1,e.inputBox.Focus(),e.inputBox.SetText((o||"")+t),e.inputBox.Select("end"),a.partialexpr="",a.ecoord=e.ecell.coord,a.erow=e.ecell.row,a.ecol=e.ecell.col,e.RangeRemove();break;case"input":case"inputboxdirect":e.inputBox.element.focus(),a.partialexpr&&(e.inputBox.SetText(a.partialexpr),a.partialexpr="",e.RangeRemove(),e.MoveECell(a.ecoord)),e.inputBox.SetText(e.inputBox.GetText()+t)}},SocialCalc.EditorDisplayCellContents=function(e){e.inputBox&&e.inputBox.DisplayCellContents()},SocialCalc.EditorSaveEdit=function(e,t){var o,a,l,r,i,n,c=e.context.sheetobj,s=e.workingvalues;l="text t",r="string"==typeof t?t:e.inputBox.GetText(),i=SocialCalc.GetCellContents(c,s.ecoord)+"",r!=i&&(a=r.charAt(0),"="==a&&-1==r.indexOf("\n")?(l="formula",r=r.substring(1)):"'"==a?(l="text t",r=r.substring(1),o=SocialCalc.DetermineValueType(r),"t"==o.type.charAt(0)&&(l="text "+o.type)):0==r.length?l="empty":(o=SocialCalc.DetermineValueType(r),l="n"==o.type&&r==o.value+""?"value n":"t"==o.type.charAt(0)?"text "+o.type:""==o.type?"text t":"constant "+o.type+" "+o.value),"t"==l.charAt(0)&&(r=SocialCalc.encodeForSave(r)),n="set "+s.ecoord+" "+l+" "+r,e.EditorScheduleSheetCommands(n,!0,!1))},SocialCalc.EditorApplySetCommandsToRange=function(e,t){var o,a,l=(e.context.sheetobj,e.ecell),r=e.range;r.hasrange?(coord=SocialCalc.crToCoord(r.left,r.top)+":"+SocialCalc.crToCoord(r.right,r.bottom),o="set "+coord+" "+t,a=e.EditorScheduleSheetCommands(o,!0,!1)):(o="set "+l.coord+" "+t,a=e.EditorScheduleSheetCommands(o,!0,!1)),e.DisplayCellContents()},SocialCalc.EditorProcessMouseWheel=function(e,t,o,a){a.functionobj.editor.busy||(t>0&&a.functionobj.editor.ScrollRelative(!0,-1),0>t&&a.functionobj.editor.ScrollRelative(!0,1))},SocialCalc.GridMousePosition=function(e,t,o){var a,l,r,i={};for(a=1;a<e.rowpositions.length&&!(e.rowheight[a]&&e.rowpositions[a]+e.rowheight[a]>o);a++);for(l=1;l<e.colpositions.length&&!(e.colwidth[l]&&e.colpositions[l]+e.colwidth[l]>t);l++);if(i.row=a,i.col=l,e.headposition){if(t<e.headposition.left&&t>=e.gridposition.left)return i.rowheader=!0,i.distance=e.headposition.left-t,i.rowtounhide="",(unhide=e.context.rowunhidetop[a])&&(pos=SocialCalc.GetElementPosition(unhide),t>=pos.left&&t<pos.left+unhide.offsetWidth&&o>=pos.top&&o<pos.top+unhide.offsetHeight&&(i.rowtounhide=a+1)),(unhide=e.context.rowunhidebottom[a])&&(pos=SocialCalc.GetElementPosition(unhide),t>=pos.left&&t<pos.left+unhide.offsetWidth&&o>=pos.top&&o<pos.top+unhide.offsetHeight&&(i.rowtounhide=a-1)),i;if(o<e.headposition.top&&o>e.gridposition.top){for(i.colheader=!0,i.distance=e.headposition.top-o,i.coltoresize=l-(e.colpositions[l]+e.colwidth[l]/2>t?1:0)||1,(unhide=e.context.colunhideleft[l])&&(pos=SocialCalc.GetElementPosition(unhide),t>=pos.left&&t<pos.left+unhide.offsetWidth&&o>=pos.top&&o<pos.top+unhide.offsetHeight&&(i.coltounhide=l+1)),(unhide=e.context.colunhideright[l])&&(pos=SocialCalc.GetElementPosition(unhide),t>=pos.left&&t<pos.left+unhide.offsetWidth&&o>=pos.top&&o<pos.top+unhide.offsetHeight&&(i.coltounhide=l-1)),r=0;r<e.context.colpanes.length;r++)if(i.coltoresize>=e.context.colpanes[r].first&&i.coltoresize<=e.context.colpanes[r].last)return i;return delete i.coltoresize,i}return t>=e.verticaltablecontrol.controlborder?(i.rowfooter=!0,i.distance=t-e.verticaltablecontrol.controlborder,i):o>=e.horizontaltablecontrol.controlborder?(i.colfooter=!0,i.distance=o-e.horizontaltablecontrol.controlborder,i):t<e.gridposition.left?(i.rowheader=!0,i.distance=e.headposition.left-t,i):o<=e.gridposition.top?(i.colheader=!0,i.distance=e.headposition.top-o,i):(i.coord=SocialCalc.crToCoord(i.col,i.row),e.context.cellskip[i.coord]&&(i.coord=e.context.cellskip[i.coord]),i)}return null},SocialCalc.GetEditorCellElement=function(e,t,o){var a,l,r,i,n=0,c=0;for(a=0;a<e.context.rowpanes.length;a++){if(t>=e.context.rowpanes[a].first&&t<=e.context.rowpanes[a].last)for(l=0;l<e.context.colpanes.length;l++){if(o>=e.context.colpanes[l].first&&o<=e.context.colpanes[l].last){for(n+=t-e.context.rowpanes[a].first+2,r=e.context.colpanes[l].first;o>=r;r++)i=e.context.cellskip[SocialCalc.crToCoord(r,t)],i&&e.context.CoordInPane(i,a,l)||c++;return{element:e.griddiv.firstChild.lastChild.childNodes[n].childNodes[c],rowpane:a,colpane:l}}for(r=e.context.colpanes[l].first;r<=e.context.colpanes[l].last;r++)i=e.context.cellskip[SocialCalc.crToCoord(r,t)],i&&e.context.CoordInPane(i,a,l)||c++;c+=1}n+=e.context.rowpanes[a].last-e.context.rowpanes[a].first+1+1}return null},SocialCalc.MoveECellWithKey=function(e,t){var o,a,l,r,i=!1,n=1;if(!e.ecell)return null;switch("shifted"==t.slice(-7)&&(t=t.slice(0,-7),i=!0),a=e.ecell.row,l=e.ecell.col,r=e.context.sheetobj.cells[e.ecell.coord],t){case"[adown]":a+=r&&r.rowspan||1;break;case"[aup]":a--,n=-1;break;case"[pgdn]":a+=e.pageUpDnAmount-1+(r&&r.rowspan||1);break;case"[pgup]":a-=e.pageUpDnAmount,n=-1;break;case"[aright]":l+=r&&r.colspan||1;break;case"[aleft]":l--,n=-1;break;case"[home]":a=1,l=1;break;default:return null}for(e.context.sheetobj.attribs.usermaxcol&&(l=Math.min(e.context.sheetobj.attribs.usermaxcol,l)),e.context.sheetobj.attribs.usermaxrow&&(a=Math.min(e.context.sheetobj.attribs.usermaxrow,a));"yes"==e.context.sheetobj.colattribs.hide[SocialCalc.rcColname(l)];)l+=n,1>l&&(n=-n,l=1);for(;"yes"==e.context.sheetobj.rowattribs.hide[a];)a+=n,1>a&&(n=-n,a=1);return e.range.hasrange||i&&e.RangeAnchor(),o=e.MoveECell(SocialCalc.crToCoord(l,a)),e.range.hasrange&&(i?e.RangeExtend():e.RangeRemove()),o},SocialCalc.MoveECell=function(e,t){var o,a,l=e.context.highlights,r=SocialCalc.coordToCr(t);if(e.context.sheetobj.attribs.usermaxcol&&r.col>e.context.sheetobj.attribs.usermaxcol&&(r.col=e.context.sheetobj.attribs.usermaxcol),e.context.sheetobj.attribs.usermaxrow&&r.row>e.context.sheetobj.attribs.usermaxrow&&(r.row=e.context.sheetobj.attribs.usermaxrow),
t=SocialCalc.crToCoord(r.col,r.row),e.ecell){if(e.ecell.coord==t)return t;o=SocialCalc.GetEditorCellElement(e,e.ecell.row,e.ecell.col),delete l[e.ecell.coord],e.range2.hasrange&&e.ecell.row>=e.range2.top&&e.ecell.row<=e.range2.bottom&&e.ecell.col>=e.range2.left&&e.ecell.col<=e.range2.right&&(l[e.ecell.coord]="range2"),e.UpdateCellCSS(o,e.ecell.row,e.ecell.col),e.SetECellHeaders(""),e.cellhandles.ShowCellHandles(!1)}t=e.context.cellskip[t]||t,e.ecell=SocialCalc.coordToCr(t),e.ecell.coord=t,o=SocialCalc.GetEditorCellElement(e,e.ecell.row,e.ecell.col),l[t]="cursor";for(a in e.MoveECellCallback)e.MoveECellCallback[a](e);e.UpdateCellCSS(o,e.ecell.row,e.ecell.col),e.SetECellHeaders("selected");for(a in e.StatusCallback)e.StatusCallback[a].func(e,"moveecell",t,e.StatusCallback[a].params);return e.busy?e.ensureecell=!0:(e.ensureecell=!1,e.EnsureECellVisible()),t},SocialCalc.EnsureECellVisible=function(e){var t=0,o=0;e.ecell.row>e.lastnonscrollingrow&&(e.ecell.row<e.firstscrollingrow?t=e.ecell.row-e.firstscrollingrow:e.ecell.row>e.lastvisiblerow&&(t=e.ecell.row-e.lastvisiblerow)),e.ecell.col>e.lastnonscrollingcol&&(e.ecell.col<e.firstscrollingcol?o=e.ecell.col-e.firstscrollingcol:e.ecell.col>e.lastvisiblecol&&(o=e.ecell.col-e.lastvisiblecol)),0!=t||0!=o?e.ScrollRelativeBoth(t,o):e.cellhandles.ShowCellHandles(!0)},SocialCalc.ReplaceCell=function(e,t,o,a){var l,r;if(t&&(l=e.context.RenderCell(o,a,t.rowpane,t.colpane,!0,null))){t.element.innerHTML=l.innerHTML,t.element.style.cssText="",t.element.className=l.className;for(r in l.style)"cssText"!=l.style[r]&&(t.element.style[r]=l.style[r])}},SocialCalc.UpdateCellCSS=function(e,t,o,a){var l,r;if(t&&(l=e.context.RenderCell(o,a,t.rowpane,t.colpane,!0,null))){t.element.style.cssText="",t.element.className=l.className;for(r in l.style)"cssText"!=l.style[r]&&(t.element.style[r]=l.style[r])}},SocialCalc.SetECellHeaders=function(e,t){var o,a,l,r,i,n=e.ecell,c=e.context,s=0,d=0;if(n){for(;"yes"==c.sheetobj.colattribs.hide[SocialCalc.rcColname(n.col)];)n.col++;for(;"yes"==c.sheetobj.rowattribs.hide[n.row];)n.row++;for(n.coord=SocialCalc.crToCoord(n.col,n.row),o=0;o<c.rowpanes.length;o++)l=c.rowpanes[o].first,r=c.rowpanes[o].last,n.row>=l&&n.row<=r&&(i=e.fullgrid.childNodes[1].childNodes[2+s+n.row-l].childNodes[0],i&&(c.classnames&&(i.className=c.classnames[t+"rowname"]),c.explicitStyles&&(i.style.cssText=c.explicitStyles[t+"rowname"]),i.style.verticalAlign="top")),s+=r-l+1+1;for(a=0;a<c.colpanes.length;a++)l=c.colpanes[a].first,r=c.colpanes[a].last,n.col>=l&&n.col<=r&&(i=e.fullgrid.childNodes[1].childNodes[1].childNodes[1+d+n.col-l],i&&(c.classnames&&(i.className=c.classnames[t+"colname"]),c.explicitStyles&&(i.style.cssText=c.explicitStyles[t+"colname"]))),d+=r-l+1+1}},SocialCalc.ECellReadonly=function(e,t){if(!t&&e.ecell&&(t=e.ecell.coord),!t)return!1;var o=e.context.sheetobj.cells[t];return o&&o.readonly},SocialCalc.RangeAnchor=function(e,t){e.range.hasrange&&e.RangeRemove(),e.RangeExtend(t)},SocialCalc.RangeExtend=function(e,t){var o,a,l,r,i,n,c,s=e.context.highlights,d=e.range,u=e.range2;if(t?(c=SocialCalc.coordToCr(t),c.coord=t):c=e.ecell,c){d.hasrange||(d.anchorcoord=c.coord,d.anchorrow=c.row,d.top=c.row,d.bottom=c.row,d.anchorcol=c.col,d.left=c.col,d.right=c.col,d.hasrange=!0),d.anchorrow<c.row?(d.top=d.anchorrow,d.bottom=c.row):(d.top=c.row,d.bottom=d.anchorrow),d.anchorcol<c.col?(d.left=d.anchorcol,d.right=c.col):(d.left=c.col,d.right=d.anchorcol);for(l in s)switch(s[l]){case"range":s[l]="unrange";break;case"range2":s[l]="unrange2"}for(r=d.top;r<=d.bottom;r++)for(i=d.left;i<=d.right;i++)switch(l=SocialCalc.crToCoord(i,r),s[l]){case"unrange":s[l]="range";break;case"cursor":break;case"unrange2":default:s[l]="newrange"}for(r=u.top;u.hasrange&&r<=u.bottom;r++)for(i=u.left;i<=u.right;i++)switch(l=SocialCalc.crToCoord(i,r),s[l]){case"unrange2":s[l]="range2";break;case"range":case"newrange":case"cursor":break;default:s[l]="newrange2"}for(l in s){switch(s[l]){case"unrange":delete s[l];break;case"newrange":s[l]="range";break;case"newrange2":s[l]="range2";break;case"range":case"range2":case"cursor":continue}a=SocialCalc.coordToCr(l),o=SocialCalc.GetEditorCellElement(e,a.row,a.col),e.UpdateCellCSS(o,a.row,a.col)}for(n in e.RangeChangeCallback)e.RangeChangeCallback[n](e);l=SocialCalc.crToCoord(e.range.left,e.range.top),(e.range.left!=e.range.right||e.range.top!=e.range.bottom)&&(l+=":"+SocialCalc.crToCoord(e.range.right,e.range.bottom));for(n in e.StatusCallback)e.StatusCallback[n].func(e,"rangechange",l,e.StatusCallback[n].params)}},SocialCalc.RangeRemove=function(e){var t,o,a,l,r,i,n=e.context.highlights,c=e.range,s=e.range2;if(c.hasrange||s.hasrange){for(l=s.top;s.hasrange&&l<=s.bottom;l++)for(r=s.left;r<=s.right;r++)switch(a=SocialCalc.crToCoord(r,l),n[a]){case"range":n[a]="newrange2";break;case"range2":case"cursor":break;default:n[a]="newrange2"}for(a in n){switch(n[a]){case"range":delete n[a];break;case"newrange2":n[a]="range2";break;case"cursor":continue}o=SocialCalc.coordToCr(a),t=SocialCalc.GetEditorCellElement(e,o.row,o.col),e.UpdateCellCSS(t,o.row,o.col)}c.hasrange=!1;for(i in e.RangeChangeCallback)e.RangeChangeCallback[i](e);for(i in e.StatusCallback)e.StatusCallback[i].func(e,"rangechange","",e.StatusCallback[i].params)}},SocialCalc.Range2Remove=function(e){var t,o,a,l=e.context.highlights,r=e.range2;if(r.hasrange){for(a in l){switch(l[a]){case"range2":delete l[a];break;case"range":case"cursor":continue}o=SocialCalc.coordToCr(a),t=SocialCalc.GetEditorCellElement(e,o.row,o.col),e.UpdateCellCSS(t,o.row,o.col)}r.hasrange=!1}},SocialCalc.FitToEditTable=function(e){var t,o,a,l,r,i,n,c,s=e.context,d=s.sheetobj;d.colattribs;for(l=s.showRCHeaders?s.rownamewidth-0:0,colpane=0;colpane<s.colpanes.length-1;colpane++)for(t=s.colpanes[colpane].first;t<=s.colpanes[colpane].last;t++)o=SocialCalc.rcColname(t),"yes"!=d.colattribs.hide[o]&&(a=d.colattribs.width[o]||d.attribs.defaultcolwidth||SocialCalc.Constants.defaultColWidth,("blank"==a||"auto"==a)&&(a=""),l+=a&&a-0>0?a-0:10);for(t=s.colpanes[colpane].first;1e4>=t&&(o=SocialCalc.rcColname(t),"yes"!=d.colattribs.hide[o]&&(a=d.colattribs.width[o]||d.attribs.defaultcolwidth||SocialCalc.Constants.defaultColWidth,("blank"==a||"auto"==a)&&(a=""),l+=a&&a-0>0?a-0:10),!(l>e.tablewidth));t++);for(s.colpanes[colpane].last=s.sheetobj.attribs.usermaxcol||t,r=s.showRCHeaders?1:0,n=0;n<s.rowpanes.length-1;n++)for(r+=s.rowpanes[n].last-s.rowpanes[n].first+1,i=s.rowpanes[n].first;i<=s.rowpanes[n].last;i++)"yes"==d.rowattribs.hide[i]&&r--;c=e.tableheight-r*s.pixelsPerRow,s.rowpanes[n].last=s.sheetobj.attribs.usermaxrow||s.rowpanes[n].first+Math.floor(c/s.pixelsPerRow)+1},SocialCalc.CalculateEditorPositions=function(e){var t,o,a;e.gridposition=SocialCalc.GetElementPosition(e.griddiv);var l=e.griddiv.firstChild.lastChild.childNodes[1].childNodes[0];for(e.headposition=SocialCalc.GetElementPosition(l),e.headposition.left+=l.offsetWidth,e.headposition.top+=l.offsetHeight,e.rowpositions=[],t=0;t<e.context.rowpanes.length;t++)e.CalculateRowPositions(t,e.rowpositions,e.rowheight);for(a=0;a<e.rowpositions.length&&!(e.rowpositions[a]>e.gridposition.top+e.tableheight);a++);for(e.lastvisiblerow=a-1,e.colpositions=[],o=0;o<e.context.colpanes.length;o++)e.CalculateColPositions(o,e.colpositions,e.colwidth);for(a=0;a<e.colpositions.length&&!(e.colpositions[a]>e.gridposition.left+e.tablewidth);a++);for(e.lastvisiblecol=a-1,e.firstscrollingrow=e.context.rowpanes[e.context.rowpanes.length-1].first;"yes"==e.context.sheetobj.rowattribs.hide[e.firstscrollingrow];)e.firstscrollingrow++;for(e.firstscrollingrowtop=e.rowpositions[e.firstscrollingrow]||e.headposition.top,e.lastnonscrollingrow=e.context.rowpanes.length-1>0?e.context.rowpanes[e.context.rowpanes.length-2].last:0,e.firstscrollingcol=e.context.colpanes[e.context.colpanes.length-1].first;"yes"==e.context.sheetobj.colattribs.hide[SocialCalc.rcColname(e.firstscrollingcol)];)e.firstscrollingcol++;e.firstscrollingcolleft=e.colpositions[e.firstscrollingcol]||e.headposition.left,e.lastnonscrollingcol=e.context.colpanes.length-1>0?e.context.colpanes[e.context.colpanes.length-2].last:0,e.verticaltablecontrol.ComputeTableControlPositions(),e.horizontaltablecontrol.ComputeTableControlPositions()},SocialCalc.ScheduleRender=function(e){e.timeout&&window.clearTimeout(e.timeout),SocialCalc.EditorSheetStatusCallback(null,"schedrender",null,e),e.timeout=window.setTimeout(function(){SocialCalc.DoRenderStep(e)},1)},SocialCalc.DoRenderStep=function(e){e.timeout=null,e.EditorRenderSheet(),SocialCalc.EditorSheetStatusCallback(null,"renderdone",null,e),SocialCalc.EditorSheetStatusCallback(null,"schedposcalc",null,e),e.timeout=window.setTimeout(function(){SocialCalc.DoPositionCalculations(e)},1)},SocialCalc.SchedulePositionCalculations=function(e){SocialCalc.EditorSheetStatusCallback(null,"schedposcalc",null,e),e.timeout=window.setTimeout(function(){SocialCalc.DoPositionCalculations(e)},1)},SocialCalc.DoPositionCalculations=function(e){e.timeout=null,e.CalculateEditorPositions(),e.verticaltablecontrol.PositionTableControlElements(),e.horizontaltablecontrol.PositionTableControlElements(),SocialCalc.EditorSheetStatusCallback(null,"doneposcalc",null,e),e.ensureecell&&e.ecell&&!e.deferredCommands.length&&(e.ensureecell=!1,e.EnsureECellVisible()),e.cellhandles.ShowCellHandles(!0)},SocialCalc.CalculateRowPositions=function(e,t,o,a){var l,r,i,n,c,s,d,u=e.context;u.sheetobj;if(!u.showRCHeaders)throw"Needs showRCHeaders=true";for(d=e.fullgrid.lastChild,l=2,r=0;t>r;r++)l+=u.rowpanes[r].last-u.rowpanes[r].first+2;for(n=0,i=u.rowpanes[r].first;i<=u.rowpanes[r].last;i++)c=d.childNodes[l+n],n++,s=SocialCalc.GetElementPosition(c.firstChild),o[i]||(o[i]=s.top,a[i]=c.firstChild.offsetHeight)},SocialCalc.CalculateColPositions=function(e,t,o,a){var l,r,i,n,c,s,d,u=e.context;u.sheetobj;if(!u.showRCHeaders)throw"Needs showRCHeaders=true";for(d=e.fullgrid.lastChild,l=1,r=0;t>r;r++)l+=u.colpanes[r].last-u.colpanes[r].first+2;for(c=d.childNodes[1],n=0,i=u.colpanes[r].first;i<=u.colpanes[r].last;i++)s=SocialCalc.GetElementPosition(c.childNodes[l+n]),o[i]||(o[i]=s.left,c.childNodes[l+n]&&(a[i]=c.childNodes[l+n].offsetWidth)),n++},SocialCalc.ScrollRelative=function(e,t,o){t?e.ScrollRelativeBoth(o,0):e.ScrollRelativeBoth(0,o)},SocialCalc.ScrollRelativeBoth=function(e,t,o){var a=e.context,l=t>0?1:-1,r=o>0?1:-1,i=a.rowpanes.length,n=i>1?a.rowpanes[i-2].last+1:1;a.rowpanes[i-1].first+t<n&&(t=-a.rowpanes[i-1].first+n);var c=a.colpanes.length,s=c>1?a.colpanes[c-2].last+1:1;for(a.colpanes[c-1].first+o<s&&(o=-a.colpanes[c-1].first+s);"yes"==a.sheetobj.colattribs.hide[SocialCalc.rcColname(a.colpanes[c-1].first+o)];)if(o+=r,1>o){o=0;break}for(;"yes"==a.sheetobj.rowattribs.hide[a.rowpanes[i-1].first+t];)if(t+=l,1>t){t=0;break}return 1!=t&&-1!=t||0!=o?void((0!=t||0!=o)&&(a.rowpanes[i-1].first+=t,a.rowpanes[i-1].last+=t,a.colpanes[c-1].first+=o,a.colpanes[c-1].last+=o,e.LimitLastPanes(),e.FitToEditTable(),e.ScheduleRender())):(1==t?e.ScrollTableUpOneRow():e.ScrollTableDownOneRow(),e.ecell&&e.SetECellHeaders("selected"),void e.SchedulePositionCalculations())},SocialCalc.PageRelative=function(e,t,o){var a,l,r,i,n=e.context,c=t?"rowpanes":"colpanes",s=n[c][n[c].length-1],d=t?"lastvisiblerow":"lastvisiblecol",u=t?e.rowheight:e.colwidth,p=t?SocialCalc.Constants.defaultAssumedRowHeight:SocialCalc.Constants.defaultColWidth;if(o>0)l=e[d],l==s.first&&(l+=1);else{for(r=t?e.tableheight-(e.firstscrollingrowtop-e.gridposition.top):e.tablewidth-(e.firstscrollingcolleft-e.gridposition.left),r-=u[e[d]]>0?u[e[d]]:p,l=s.first-1;l>0&&(a=u[l]>0?u[l]:p,!(a>r));l--)r-=a;i=s.first,l>=i&&(l=i-1),1>l&&(l=1)}s.first=l,s.last=l+1,e.LimitLastPanes(),e.FitToEditTable(),e.ScheduleRender()},SocialCalc.LimitLastPanes=function(e){var t,o=e.context;t=o.rowpanes.length,t>1&&o.rowpanes[t-1].first<=o.rowpanes[t-2].last&&(o.rowpanes[t-1].first=o.rowpanes[t-2].last+1),o.sheetobj.attribs.usermaxrow&&o.rowpanes[t-1].first>o.sheetobj.attribs.usermaxrow&&(o.rowpanes[t-1].first=o.sheetobj.attribs.usermaxrow),t=o.colpanes.length,t>1&&o.colpanes[t-1].first<=o.colpanes[t-2].last&&(o.colpanes[t-1].first=o.colpanes[t-2].last+1),o.sheetobj.attribs.usermaxcol&&o.colpanes[t-1].first>o.sheetobj.attribs.usermaxcol&&(o.colpanes[t-1].first=o.sheetobj.attribs.usermaxcol)},SocialCalc.ScrollTableUpOneRow=function(e){var t,o,a,l,r,i,n,c,s,d,u,p,m={},h=e.context,C=h.sheetobj,f=e.fullgrid;for(p=f.lastChild,t=h.showRCHeaders?2:1,o=0;o<h.rowpanes.length-1;o++)t+=h.rowpanes[o].last-h.rowpanes[o].first+2;if(h.sheetobj.attribs.usermaxrow&&h.sheetobj.attribs.usermaxrow-h.rowpanes[o].first<1)return f;for(p.removeChild(p.childNodes[t]),h.rowpanes[o].first++,h.rowpanes[o].last++,e.FitToEditTable(),h.CalculateColWidthData(),h.sheetobj.attribs.usermaxrow&&h.rowpanes[o].last==h.sheetobj.attribs.usermaxrow||(c=h.RenderRow(h.rowpanes[o].last,o),p.appendChild(c)),maxrowspan=1,n=h.rowpanes[o].first-1,r=0;r<h.colpanes.length;r++)for(l=h.colpanes[r].first;l<=h.colpanes[r].last;l++)coord=SocialCalc.crToCoord(l,n),h.cellskip[coord]||(i=C.cells[coord],i&&i.rowspan>maxrowspan&&(maxrowspan=i.rowspan));if(maxrowspan>1)for(a=1;a<maxrowspan&&!(a+n>=h.rowpanes[o].last);a++)s=h.RenderRow(a+n,o),d=p.childNodes[t+a-1],p.replaceChild(s,d);for(u=h.rowpanes[o].last,r=0;r<h.colpanes.length;r++)for(l=h.colpanes[r].first;l<=h.colpanes[r].last;l++)coord=h.cellskip[SocialCalc.crToCoord(l,u)],coord&&(a=h.coordToCR[coord].row-0,a==h.rowpanes[o].last||a<h.rowpanes[o].first||(i=C.cells[coord],i&&i.rowspan>1&&(m[a]=!0)));for(a in m)s=h.RenderRow(a,o),d=p.childNodes[t+(a-h.rowpanes[o].first)],p.replaceChild(s,d);return f},SocialCalc.ScrollTableDownOneRow=function(e){var t,o,a,l,r,i,n,c,s,d,u,p={},m=e.context,h=m.sheetobj,C=e.fullgrid;for(u=C.lastChild,t=m.showRCHeaders?2:1,o=0;o<m.rowpanes.length-1;o++)t+=m.rowpanes[o].last-m.rowpanes[o].first+2;for(m.sheetobj.attribs.usermaxrow||u.removeChild(u.childNodes[t+(m.rowpanes[o].last-m.rowpanes[o].first)]),m.rowpanes[o].first--,m.rowpanes[o].last--,e.FitToEditTable(),m.CalculateColWidthData(),c=m.RenderRow(m.rowpanes[o].first,o),u.insertBefore(c,u.childNodes[t]),maxrowspan=1,n=m.rowpanes[o].first,r=0;r<m.colpanes.length;r++)for(l=m.colpanes[r].first;l<=m.colpanes[r].last;l++)coord=SocialCalc.crToCoord(l,n),m.cellskip[coord]||(i=h.cells[coord],i&&i.rowspan>maxrowspan&&(maxrowspan=i.rowspan));if(maxrowspan>1)for(a=1;a<maxrowspan&&!(a+n>m.rowpanes[o].last);a++)c=m.RenderRow(a+n,o),s=u.childNodes[t+a],u.replaceChild(c,s);for(d=m.rowpanes[o].last,r=0;r<m.colpanes.length;r++)for(l=m.colpanes[r].first;l<=m.colpanes[r].last;l++)coord=SocialCalc.crToCoord(l,d),i=h.cells[coord],i&&i.rowspan>1?p[d]=!0:(coord=m.cellskip[SocialCalc.crToCoord(l,d)],coord&&(a=m.coordToCR[coord].row-0,a==d||a<m.rowpanes[o].first||(i=h.cells[coord],i&&i.rowspan>1&&(p[a]=!0))));for(a in p)c=m.RenderRow(a,o),s=u.childNodes[t+(a-m.rowpanes[o].first)],u.replaceChild(c,s);return C},SocialCalc.InputBox=function(e,t){e&&(this.element=e,this.editor=t,this.inputEcho=null,t.inputBox=this,e.onmousedown=SocialCalc.InputBoxOnMouseDown,t.MoveECellCallback.formulabar=function(e){"start"==e.state&&t.inputBox.DisplayCellContents(e.ecell.coord)})},SocialCalc.InputBox.prototype.DisplayCellContents=function(e){SocialCalc.InputBoxDisplayCellContents(this,e)},SocialCalc.InputBox.prototype.ShowInputBox=function(e){this.editor.inputEcho.ShowInputEcho(e)},SocialCalc.InputBox.prototype.GetText=function(){return this.element.value},SocialCalc.InputBox.prototype.SetText=function(e){this.element&&(this.element.value=e,this.editor.inputEcho.SetText(e+"_"))},SocialCalc.InputBox.prototype.Focus=function(){SocialCalc.InputBoxFocus(this)},SocialCalc.InputBox.prototype.Blur=function(){return this.element.blur()},SocialCalc.InputBox.prototype.Select=function(e){if(this.element)switch(e){case"end":if(document.selection&&document.selection.createRange)try{var t=document.selection.createRange().duplicate();t.moveToElementText(this.element),t.collapse(!1),t.select()}catch(o){void 0!=this.element.selectionStart&&(this.element.selectionStart=this.element.value.length,this.element.selectionEnd=this.element.value.length)}else void 0!=this.element.selectionStart&&(this.element.selectionStart=this.element.value.length,this.element.selectionEnd=this.element.value.length)}},SocialCalc.InputBoxDisplayCellContents=function(e,t){var o=SocialCalc.Constants;if(e){t||(t=e.editor.ecell.coord);var a=SocialCalc.GetCellContents(e.editor.context.sheetobj,t);-1!=a.indexOf("\n")?(a=o.s_inputboxdisplaymultilinetext,e.element.disabled=!0):e.editor.ECellReadonly()?e.element.disabled=!0:e.element.disabled=!1,e.SetText(a)}},SocialCalc.InputBoxFocus=function(e){if(e){e.element.focus();var t=e.editor;t.state="input";var o=t.workingvalues;o.partialexpr="",o.ecoord=t.ecell.coord,o.erow=t.ecell.row,o.ecol=t.ecell.col}},SocialCalc.InputBoxOnMouseDown=function(e){var t=SocialCalc.Keyboard.focusTable;if(!t)return!0;var o=t.workingvalues;switch(t.state){case"start":t.state="inputboxdirect",o.partialexpr="",o.ecoord=t.ecell.coord,o.erow=t.ecell.row,o.ecol=t.ecell.col,t.inputEcho.ShowInputEcho(!0);break;case"input":o.partialexpr="",t.MoveECell(o.ecoord),t.state="inputboxdirect",SocialCalc.KeyboardFocus();break;case"inputboxdirect":}},SocialCalc.InputEcho=function(e){var t=SocialCalc.Constants;this.editor=e,this.text="",this.interval=null,this.container=null,this.main=null,this.prompt=null,this.functionbox=null,this.container=document.createElement("div"),SocialCalc.setStyles(this.container,"display:none;position:absolute;zIndex:10;"),this.main=document.createElement("div"),t.defaultInputEchoClass&&(this.main.className=t.defaultInputEchoClass),t.defaultInputEchoStyle&&SocialCalc.setStyles(this.main,t.defaultInputEchoStyle),this.main.innerHTML=" ",this.container.appendChild(this.main),this.prompt=document.createElement("div"),t.defaultInputEchoPromptClass&&(this.prompt.className=t.defaultInputEchoPromptClass),t.defaultInputEchoPromptStyle&&SocialCalc.setStyles(this.prompt,t.defaultInputEchoPromptStyle),this.prompt.innerHTML="",this.container.appendChild(this.prompt),SocialCalc.DragRegister(this.main,!0,!0,{MouseDown:SocialCalc.DragFunctionStart,MouseMove:SocialCalc.DragFunctionPosition,MouseUp:SocialCalc.DragFunctionPosition,Disabled:null,positionobj:this.container},this.editor.toplevel),e.toplevel.appendChild(this.container)},SocialCalc.InputEcho.prototype.ShowInputEcho=function(e){return SocialCalc.ShowInputEcho(this,e)},SocialCalc.InputEcho.prototype.SetText=function(e){return SocialCalc.SetInputEchoText(this,e)},SocialCalc.ShowInputEcho=function(e,t){var o,a,l=e.editor;l&&(t?(l.cellhandles.ShowCellHandles(!1),o=SocialCalc.GetEditorCellElement(l,l.ecell.row,l.ecell.col),o&&(a=SocialCalc.GetElementPosition(o.element),e.container.style.left=a.left-1+"px",e.container.style.top=a.top-1+"px"),e.container.style.display="block",e.interval&&window.clearInterval(e.interval),e.interval=window.setInterval(SocialCalc.InputEchoHeartbeat,50)):(e.interval&&window.clearInterval(e.interval),e.container.style.display="none"))},SocialCalc.SetInputEchoText=function(e,t){var o,a,l=SocialCalc.Constants,r=SocialCalc.special_chars(t);r=r.replace(/\n/g,"<br>"),e.text!=r&&(e.main.innerHTML=r,e.text=r);var i=t.match(/.*[\+\-\*\/\&\^\<\>\=\,\(]([A-Za-z][A-Za-z][\w\.]*?)\([^\)]*$/);"="==t.charAt(0)&&i?(o=i[1].toUpperCase(),SocialCalc.Formula.FunctionList[o]?(SocialCalc.Formula.FillFunctionInfo(),a=SocialCalc.special_chars(o+"("+SocialCalc.Formula.FunctionArgString(o)+")")):a=l.ietUnknownFunction+o,e.prompt.innerHTML!=a&&(e.prompt.innerHTML=a,e.prompt.style.display="block")):"none"!=e.prompt.style.display&&(e.prompt.innerHTML="",e.prompt.style.display="none")},SocialCalc.InputEchoHeartbeat=function(){var e=SocialCalc.Keyboard.focusTable;return e?void e.inputEcho.SetText(e.inputBox.GetText()+"_"):!0},SocialCalc.InputEchoMouseDown=function(e){var t=(e||window.event,SocialCalc.Keyboard.focusTable);return t?void t.inputBox.element.focus():!0},SocialCalc.CellHandles=function(e){SocialCalc.Constants;if(!e.noEdit){this.editor=e,this.noCursorSuffix=!1,this.movedmouse=!1,this.draghandle=document.createElement("div"),SocialCalc.setStyles(this.draghandle,"display:none;position:absolute;zIndex:8;border:1px solid white;width:4px;height:4px;fontSize:1px;backgroundColor:#0E93D8;cursor:default;"),this.draghandle.innerHTML=" ",e.toplevel.appendChild(this.draghandle),SocialCalc.AssignID(e,this.draghandle,"draghandle");var t="png";if(navigator.userAgent.match(/MSIE 6\.0/)&&(t="gif"),this.dragpalette=document.createElement("div"),SocialCalc.setStyles(this.dragpalette,"display:none;position:absolute;zIndex:8;width:90px;height:90px;fontSize:1px;textAlign:center;cursor:default;backgroundImage:url("+SocialCalc.Constants.defaultImagePrefix+"drag-handles."+t+");"),this.dragpalette.innerHTML=" ",e.toplevel.appendChild(this.dragpalette),SocialCalc.AssignID(e,this.dragpalette,"dragpalette"),this.dragtooltip=document.createElement("div"),SocialCalc.setStyles(this.dragtooltip,"display:none;position:absolute;zIndex:9;border:1px solid black;width:100px;height:auto;fontSize:10px;backgroundColor:#FFFFFF;"),this.dragtooltip.innerHTML=" ",e.toplevel.appendChild(this.dragtooltip),SocialCalc.AssignID(e,this.dragtooltip,"dragtooltip"),this.fillinghandle=document.createElement("div"),SocialCalc.setStyles(this.fillinghandle,"display:none;position:absolute;zIndex:9;border:1px solid black;width:auto;height:14px;fontSize:10px;backgroundColor:#FFFFFF;"),this.fillinghandle.innerHTML=" ",e.toplevel.appendChild(this.fillinghandle),SocialCalc.AssignID(e,this.fillinghandle,"fillinghandle"),this.draghandle.addEventListener)this.draghandle.addEventListener("mousemove",SocialCalc.CellHandlesMouseMoveOnHandle,!1),this.dragpalette.addEventListener("mousedown",SocialCalc.CellHandlesMouseDown,!1),this.dragpalette.addEventListener("mousemove",SocialCalc.CellHandlesMouseMoveOnHandle,!1);else{if(!this.draghandle.attachEvent)throw"Browser not supported";this.draghandle.attachEvent("onmousemove",SocialCalc.CellHandlesMouseMoveOnHandle),this.dragpalette.attachEvent("onmousedown",SocialCalc.CellHandlesMouseDown),this.dragpalette.attachEvent("onmousemove",SocialCalc.CellHandlesMouseMoveOnHandle)}}},SocialCalc.CellHandles.prototype.ShowCellHandles=function(e,t){return SocialCalc.ShowCellHandles(this,e,t)},SocialCalc.ShowCellHandles=function(e,t,o){var a,l,r,i=e.editor,n=!1,c=1,s=1;if(i){do{if(!t)break;if(l=i.ecell.row,r=i.ecell.col,"start"!=i.state)break;if(l>=i.lastvisiblerow)break;if(r>=i.lastvisiblecol)break;if(l<i.firstscrollingrow)break;if(r<i.firstscrollingcol)break;for(;"yes"==i.context.sheetobj.colattribs.hide[SocialCalc.rcColname(r+c)];)c++;for(;"yes"==i.context.sheetobj.rowattribs.hide[l+s];)s++;if(a=i.context.sheetobj.cells[SocialCalc.crToCoord(r+c-1,l+s-1)],"undefined"!=typeof a&&(c+=(a.colspan||1)-1,s+=(a.rowspan||1)-1),i.rowpositions[l+s]+20>i.horizontaltablecontrol.controlborder)break;if(i.rowpositions[l+s]-10<i.headposition.top)break;if(i.colpositions[r+c]+20>i.verticaltablecontrol.controlborder)break;if(i.colpositions[r+c]-30<i.headposition.left)break;e.draghandle.style.left=i.colpositions[r+c]-1+"px",e.draghandle.style.top=i.rowpositions[l+s]-1+"px",e.draghandle.style.display="block",o&&(e.draghandle.style.display="none",e.dragpalette.style.left=i.colpositions[r+c]-45+"px",e.dragpalette.style.top=i.rowpositions[l+s]-45+"px",e.dragpalette.style.display="block",e.dragtooltip.style.left=i.colpositions[r+c]-45+"px",e.dragtooltip.style.top=i.rowpositions[l+s]+45+"px",e.dragtooltip.style.display="none"),n=!0}while(!1);n||(e.draghandle.style.display="none"),o||(e.dragpalette.style.display="none",e.dragtooltip.style.display="none")}},SocialCalc.CellHandlesMouseMoveOnHandle=function(e){var t=SocialCalc.Constants,o=e||window.event,a=o.target||o.srcElement,l=SocialCalc.Keyboard.focusTable;if(!l)return!0;var r=l.cellhandles;if(!r.editor)return!0;var i=SocialCalc.GetElementPositionWithScroll(l.toplevel),n=o.clientX-i.left,c=o.clientY-i.top;if(!l.cellhandles.mouseDown){if(l.cellhandles.ShowCellHandles(!0,!0),a==r.dragpalette){var s=SocialCalc.SegmentDivHit([t.CH_radius1,t.CH_radius2],l.cellhandles.dragpalette,n,c);if(0==s)return void SocialCalc.CellHandlesHoverTimeout();r.tooltipstimer&&(window.clearTimeout(r.tooltipstimer),r.tooltipstimer=null),r.tooltipswhichhandle=s,r.tooltipstimer=window.setTimeout(SocialCalc.CellHandlesTooltipsTimeout,700)}r.timer&&(window.clearTimeout(r.timer),r.timer=null),r.timer=window.setTimeout(SocialCalc.CellHandlesHoverTimeout,3e3)}},SocialCalc.SegmentDivHit=function(e,t,o,a){var l=t.offsetWidth,r=t.offsetHeight,i=t.offsetLeft,n=t.offsetTop,c=0,s=e,d=Math.sqrt(Math.pow(o-i-(l/2-.5),2)+Math.pow(a-n-(r/2-.5),2));if(2==s.length)return o>=i&&i+l/2>o&&a>=n&&n+r/2>a&&(d<=e[0]?c=-1:d<=e[1]&&(c=1)),o>=i+l/2&&i+l>o&&a>=n&&n+r/2>a&&(d<=e[0]?c=-2:d<=e[1]&&(c=2)),o>=i+l/2&&i+l>o&&a>=n+r/2&&n+r>a&&(d<=e[0]?c=-3:d<=e[1]&&(c=3)),o>=i&&i+l/2>o&&a>=n+r/2&&n+r>a&&(d<=e[0]?c=-4:d<=e[1]&&(c=4)),c;for(;;)if(o>=i&&i+l/2>o&&a>=n&&n+r/2>a){if(quadrant+="1",c=s[0],"number"==typeof c)break;s=c,l/=2,r/=2}else if(o>=i+l/2&&i+l>o&&a>=n&&n+r/2>a){if(quadrant+="2",c=s[1],"number"==typeof c)break;s=c,l/=2,i+=l,r/=2}else if(o>=i+l/2&&i+l>o&&a>=n+r/2&&n+r>a){if(quadrant+="3",c=s[2],"number"==typeof c)break;s=c,l/=2,i+=l,r/=2,n+=r}else{if(!(o>=i&&i+l/2>o&&a>=n+r/2&&n+r>a))return 0;if(quadrant+="4",c=s[3],"number"==typeof c)break;s=c,l/=2,r/=2,n+=r}return c},SocialCalc.CellHandlesHoverTimeout=function(){if(editor=SocialCalc.Keyboard.focusTable,!editor)return!0;var e=editor.cellhandles;e.timer&&(window.clearTimeout(e.timer),e.timer=null),e.tooltipstimer&&(window.clearTimeout(e.tooltipstimer),e.tooltipstimer=null),editor.cellhandles.ShowCellHandles(!0,!1)},SocialCalc.CellHandlesTooltipsTimeout=function(){if(editor=SocialCalc.Keyboard.focusTable,!editor)return!0;var e=editor.cellhandles;e.tooltipstimer&&(window.clearTimeout(e.tooltipstimer),e.tooltipstimer=null);var t=e.tooltipswhichhandle;if(0==t)return void SocialCalc.CellHandlesHoverTimeout();if(-3==t)e.dragtooltip.innerHTML=scc.s_CHfillAllTooltip;else if(3==t)e.dragtooltip.innerHTML=scc.s_CHfillContentsTooltip;else if(-2==t)e.dragtooltip.innerHTML=scc.s_CHmovePasteAllTooltip;else if(-4==t)e.dragtooltip.innerHTML=scc.s_CHmoveInsertAllTooltip;else if(2==t)e.dragtooltip.innerHTML=scc.s_CHmovePasteContentsTooltip;else{if(4!=t)return e.dragtooltip.innerHTML=" ",void(e.dragtooltip.style.display="none");e.dragtooltip.innerHTML=scc.s_CHmoveInsertContentsTooltip}e.dragtooltip.style.display="block"},SocialCalc.CellHandlesMouseDown=function(e){var t,o,a,l=SocialCalc.Constants,r=e||window.event,i=SocialCalc.EditorMouseInfo;if(t=SocialCalc.Keyboard.focusTable,!t)return!0;if(!t.busy){var n=t.cellhandles;n.movedmouse=!1;var c=SocialCalc.GetElementPositionWithScroll(t.toplevel),s=r.clientX-c.left,d=r.clientY-c.top;n.timer&&(window.clearTimeout(n.timer),n.timer=null),n.tooltipstimer&&(window.clearTimeout(n.tooltipstimer),n.tooltipstimer=null),n.dragtooltip.innerHTML=" ",n.dragtooltip.style.display="none",a=t.range;var u=SocialCalc.SegmentDivHit([l.CH_radius1,l.CH_radius2],t.cellhandles.dragpalette,s,d);if(1==u||-1==u||0==u)return void n.ShowCellHandles(!0,!1);switch(i.ignore=!0,-3==u?(n.dragtype="Fill",n.noCursorSuffix=!1):3==u?(n.dragtype="FillC",n.noCursorSuffix=!1):-2==u?(n.dragtype="Move",n.noCursorSuffix=!0):-4==u?(n.dragtype="MoveI",n.noCursorSuffix=!1):2==u?(n.dragtype="MoveC",n.noCursorSuffix=!0):4==u&&(n.dragtype="MoveIC",n.noCursorSuffix=!1),n.filltype=null,n.dragtype){case"Fill":case"FillC":a.hasrange||t.RangeAnchor();break;case"Move":case"MoveI":case"MoveC":case"MoveIC":a.hasrange||t.RangeAnchor(),t.range2.top=t.range.top,t.range2.right=t.range.right,t.range2.bottom=t.range.bottom,t.range2.left=t.range.left,t.range2.hasrange=!0,t.RangeRemove();break;default:return}n.fillinghandle.style.left=s+"px",n.fillinghandle.style.top=d-17+"px",n.fillinghandle.innerHTML=l.s_CHindicatorOperationLookup[n.dragtype]+(l.s_CHindicatorDirectionLookup[t.cellhandles.filltype]||""),n.fillinghandle.style.display="block",n.ShowCellHandles(!0,!1),n.mouseDown=!0,i.editor=t,o=t.ecell.coord,n.startingcoord=o,n.startingX=s,n.startingY=d,i.mouselastcoord=o,SocialCalc.KeyboardSetFocus(t),document.addEventListener?(document.addEventListener("mousemove",SocialCalc.CellHandlesMouseMove,!0),document.addEventListener("mouseup",SocialCalc.CellHandlesMouseUp,!0)):n.draghandle.attachEvent&&(n.draghandle.setCapture(),n.draghandle.attachEvent("onmousemove",SocialCalc.CellHandlesMouseMove),n.draghandle.attachEvent("onmouseup",SocialCalc.CellHandlesMouseUp),n.draghandle.attachEvent("onlosecapture",SocialCalc.CellHandlesMouseUp)),r.stopPropagation?r.stopPropagation():r.cancelBubble=!0,r.preventDefault?r.preventDefault():r.returnValue=!1}},SocialCalc.CellHandlesMouseMove=function(e){var t,o,a,l,r,i,n,c=SocialCalc.Constants,s=e||window.event,d=SocialCalc.EditorMouseInfo;if(t=d.editor){var u=t.cellhandles;o=d.element;var p=SocialCalc.GetElementPositionWithScroll(t.toplevel),m=s.clientX-p.left,h=s.clientY-p.top;if(a=SocialCalc.GridMousePosition(t,m,h)){if(a&&!a.coord)return void SocialCalc.SetDragAutoRepeat(t,a,SocialCalc.CellHandlesDragAutoRepeat);if(SocialCalc.SetDragAutoRepeat(t,null),a.coord){switch(l=SocialCalc.coordToCr(t.cellhandles.startingcoord),r=SocialCalc.coordToCr(a.coord),u.movedmouse=!0,u.dragtype){case"Fill":case"FillC":a.coord==u.startingcoord?(u.filltype=null,u.startingX=m,u.startingY=h):u.filltype?"Down"==u.filltype?(r.col=l.col,r.row<l.row&&(r.row=l.row)):(r.row=l.row,r.col<l.col&&(r.col=l.col)):(Math.abs(h-u.startingY)>10?u.filltype="Down":Math.abs(m-u.startingX)>10&&(u.filltype="Right"),r.col=l.col,r.row=l.row),a.coord=SocialCalc.crToCoord(r.col,r.row),a.coord!=d.mouselastcoord&&(t.MoveECell(a.coord),t.RangeExtend());break;case"Move":case"MoveC":a.coord!=d.mouselastcoord&&(t.MoveECell(a.coord),i=t.range2.right-t.range2.left+a.col,n=t.range2.bottom-t.range2.top+a.row,t.RangeAnchor(SocialCalc.crToCoord(i,n)),t.RangeExtend());break;case"MoveI":case"MoveIC":a.coord==u.startingcoord?(u.filltype=null,u.startingX=m,u.startingY=h):u.filltype?"Vertical"==u.filltype?(r.col=t.range2.left,r.row>=t.range2.top&&r.row<=t.range2.bottom+1&&(r.row=t.range2.bottom+2)):(r.row=t.range2.top,r.col>=t.range2.left&&r.col<=t.range2.right+1&&(r.col=t.range2.right+2)):(Math.abs(h-u.startingY)>10?u.filltype="Vertical":Math.abs(m-u.startingX)>10&&(u.filltype="Horizontal"),r.col=l.col,r.row=l.row),a.coord=SocialCalc.crToCoord(r.col,r.row),a.coord!=d.mouselastcoord&&(t.MoveECell(a.coord),u.filltype?(i=t.range2.right-t.range2.left+r.col,n=t.range2.bottom-t.range2.top+r.row,t.RangeAnchor(SocialCalc.crToCoord(i,n)),t.RangeExtend()):t.RangeRemove())}u.fillinghandle.style.left=m+"px",u.fillinghandle.style.top=h-17+"px",u.fillinghandle.innerHTML=c.s_CHindicatorOperationLookup[u.dragtype]+(c.s_CHindicatorDirectionLookup[t.cellhandles.filltype]||""),u.fillinghandle.style.display="block",d.mouselastcoord=a.coord,s.stopPropagation?s.stopPropagation():s.cancelBubble=!0,s.preventDefault?s.preventDefault():s.returnValue=!1}}}},SocialCalc.CellHandlesDragAutoRepeat=function(e,t){var o=SocialCalc.EditorMouseInfo,a=o.editor;if(a){var l,r,i,n=a.cellhandles,c=SocialCalc.coordToCr(a.cellhandles.startingcoord),s=SocialCalc.coordToCr(e),d=0,u=0;switch("left"==t?u=-1:"right"==t?u=1:"up"==t?d=-1:"down"==t&&(d=1),a.ScrollRelativeBoth(d,u),n.dragtype){case"Fill":case"FillC":n.filltype?"Down"==n.filltype?(s.col=c.col,s.row<c.row&&(s.row=c.row)):(s.row=c.row,s.col<c.col&&(s.col=c.col)):(s.col=c.col,s.row=c.row),l=SocialCalc.crToCoord(s.col,s.row),l!=o.mouselastcoord&&(a.MoveECell(e),a.RangeExtend());break;case"Move":case"MoveC":e!=o.mouselastcoord&&(a.MoveECell(e),r=a.range2.right-a.range2.left+a.ecell.col,i=a.range2.bottom-a.range2.top+a.ecell.row,a.RangeAnchor(SocialCalc.crToCoord(r,i)),a.RangeExtend());break;case"MoveI":case"MoveIC":n.filltype?"Vertical"==n.filltype?(s.col=a.range2.left,s.row>=a.range2.top&&s.row<=a.range2.bottom+1&&(s.row=a.range2.bottom+2)):(s.row=a.range2.top,
s.col>=a.range2.left&&s.col<=a.range2.right+1&&(s.col=a.range2.right+2)):(s.col=c.col,s.row=c.row),l=SocialCalc.crToCoord(s.col,s.row),l!=o.mouselastcoord&&(a.MoveECell(l),r=a.range2.right-a.range2.left+s.col,i=a.range2.bottom-a.range2.top+s.row,a.RangeAnchor(SocialCalc.crToCoord(r,i)),a.RangeExtend())}o.mouselastcoord=l}},SocialCalc.CellHandlesMouseUp=function(e){var t,o,a,l,r,i,n,c,s,d,u,p,m=e||window.event,h=SocialCalc.EditorMouseInfo;if(t=h.editor){var C=t.cellhandles;o=h.element,h.ignore=!1;var f=SocialCalc.GetElementPositionWithScroll(t.toplevel),S=m.clientX-f.left,g=m.clientY-f.top;switch(a=SocialCalc.GridMousePosition(t,S,g),SocialCalc.SetDragAutoRepeat(t,null),C.mouseDown=!1,C.noCursorSuffix=!1,C.fillinghandle.style.display="none",a||(a={}),a.coord||(a.coord=t.ecell.coord),C.dragtype){case"Fill":case"Move":case"MoveI":i=" all";break;case"FillC":case"MoveC":case"MoveIC":i=" formulas"}switch(C.movedmouse||(C.dragtype="Nothing"),C.dragtype){case"Nothing":t.Range2Remove(),t.RangeRemove();break;case"Fill":case"FillC":n=SocialCalc.coordToCr(C.startingcoord),c=SocialCalc.coordToCr(a.coord),C.filltype&&("Down"==C.filltype?c.col=n.col:c.row=n.row),a.coord=SocialCalc.crToCoord(c.col,c.row),t.MoveECell(a.coord),t.RangeExtend(),r="Right"==t.cellhandles.filltype?"right":"down",l="fill"+r+" "+SocialCalc.crToCoord(t.range.left,t.range.top)+":"+SocialCalc.crToCoord(t.range.right,t.range.bottom)+i,t.EditorScheduleSheetCommands(l,!0,!1);break;case"Move":case"MoveC":t.context.cursorsuffix="",l="movepaste "+SocialCalc.crToCoord(t.range2.left,t.range2.top)+":"+SocialCalc.crToCoord(t.range2.right,t.range2.bottom)+" "+t.ecell.coord+i,t.EditorScheduleSheetCommands(l,!0,!1),t.Range2Remove();break;case"MoveI":case"MoveIC":t.context.cursorsuffix="",s=t.range2.right-t.range2.left,d=t.range2.bottom-t.range2.top,u=t.ecell.col-t.range2.left,p=t.ecell.row-t.range2.top,l="moveinsert "+SocialCalc.crToCoord(t.range2.left,t.range2.top)+":"+SocialCalc.crToCoord(t.range2.right,t.range2.bottom)+" "+t.ecell.coord+i,t.EditorScheduleSheetCommands(l,!0,!1),t.Range2Remove(),t.RangeRemove()," Horizontal"==t.cellhandles.filltype&&u>0?t.MoveECell(SocialCalc.crToCoord(t.ecell.col-s-1,t.ecell.row)):" Vertical"==t.cellhandles.filltype&&p>0&&t.MoveECell(SocialCalc.crToCoord(t.ecell.col,t.ecell.row-d-1)),t.RangeAnchor(SocialCalc.crToCoord(t.ecell.col+s,t.ecell.row+d)),t.RangeExtend()}return m.stopPropagation?m.stopPropagation():m.cancelBubble=!0,m.preventDefault?m.preventDefault():m.returnValue=!1,document.removeEventListener?(document.removeEventListener("mousemove",SocialCalc.CellHandlesMouseMove,!0),document.removeEventListener("mouseup",SocialCalc.CellHandlesMouseUp,!0)):C.draghandle.detachEvent&&(C.draghandle.detachEvent("onlosecapture",SocialCalc.CellHandlesMouseUp),C.draghandle.detachEvent("onmouseup",SocialCalc.CellHandlesMouseUp),C.draghandle.detachEvent("onmousemove",SocialCalc.CellHandlesMouseMove),C.draghandle.releaseCapture()),h.editor=null,!1}},SocialCalc.TableControl=function(e,t,o){var a=SocialCalc.Constants;this.editor=e,this.vertical=t,this.size=o,this.main=null,this.endcap=null,this.paneslider=null,this.lessbutton=null,this.morebutton=null,this.scrollarea=null,this.thumb=null,this.controlborder=null,this.endcapstart=null,this.panesliderstart=null,this.lessbuttonstart=null,this.morebuttonstart=null,this.scrollareastart=null,this.scrollareaend=null,this.scrollareasize=null,this.thumbpos=null,this.controlthickness=a.defaultTableControlThickness,this.sliderthickness=a.defaultTCSliderThickness,this.buttonthickness=a.defaultTCButtonThickness,this.thumbthickness=a.defaultTCThumbThickness,this.minscrollingpanesize=this.buttonthickness+this.buttonthickness+this.thumbthickness+20},SocialCalc.TableControl.prototype.CreateTableControl=function(){return SocialCalc.CreateTableControl(this)},SocialCalc.TableControl.prototype.PositionTableControlElements=function(){SocialCalc.PositionTableControlElements(this)},SocialCalc.TableControl.prototype.ComputeTableControlPositions=function(){SocialCalc.ComputeTableControlPositions(this)},SocialCalc.CreateTableControl=function(e){var t,o,a,l=SocialCalc.AssignID,r=SocialCalc.setStyles,i=SocialCalc.Constants,n=function(t,o,a){i["s_"+o+"Tooltip"+a]&&SocialCalc.TooltipRegister(t,i["s_"+o+"Tooltip"+a],null,e.editor.toplevel)},c=e.editor.imageprefix,s=e.vertical?"v":"h";return e.main=document.createElement("div"),t=e.main.style,t.height=(e.vertical?e.size:e.controlthickness)+"px",t.width=(e.vertical?e.controlthickness:e.size)+"px",t.zIndex=0,r(e.main,i.TCmainStyle),t.backgroundImage="url("+c+"main-"+s+".gif)",i.TCmainClass&&(e.main.className=i.TCmainClass),e.main.style.display="none",e.endcap=document.createElement("div"),t=e.endcap.style,t.height=e.controlthickness+"px",t.width=e.controlthickness+"px",t.zIndex=1,t.overflow="hidden",t.position="absolute",r(e.endcap,i.TCendcapStyle),t.backgroundImage="url("+c+"endcap-"+s+".gif)",i.TCendcapClass&&(e.endcap.className=i.TCendcapClass),l(e.editor,e.endcap,"endcap"+s),e.main.appendChild(e.endcap),e.paneslider=document.createElement("div"),t=e.paneslider.style,t.height=(e.vertical?e.sliderthickness:e.controlthickness)+"px",t.overflow="hidden",t.width=(e.vertical?e.controlthickness:e.sliderthickness)+"px",t.position="absolute",t[e.vertical?"top":"left"]="4px",t.zIndex=3,r(e.paneslider,i.TCpanesliderStyle),t.backgroundImage="url("+c+"paneslider-"+s+".gif)",i.TCpanesliderClass&&(e.paneslider.className=i.TCpanesliderClass),l(e.editor,e.paneslider,"paneslider"+s),n(e.paneslider,"paneslider",s),o={MouseDown:SocialCalc.TCPSDragFunctionStart,MouseMove:SocialCalc.TCPSDragFunctionMove,MouseUp:SocialCalc.TCPSDragFunctionStop,Disabled:function(){return e.editor.busy}},o.control=e,SocialCalc.DragRegister(e.paneslider,e.vertical,!e.vertical,o,e.editor.toplevel),e.main.appendChild(e.paneslider),e.lessbutton=document.createElement("div"),t=e.lessbutton.style,t.height=(e.vertical?e.buttonthickness:e.controlthickness)+"px",t.width=(e.vertical?e.controlthickness:e.buttonthickness)+"px",t.zIndex=2,t.overflow="hidden",t.position="absolute",r(e.lessbutton,i.TClessbuttonStyle),t.backgroundImage="url("+c+"less-"+s+"n.gif)",i.TClessbuttonClass&&(e.lessbutton.className=i.TClessbuttonClass),l(e.editor,e.lessbutton,"lessbutton"+s),a={repeatwait:i.TClessbuttonRepeatWait,repeatinterval:i.TClessbuttonRepeatInterval,normalstyle:"backgroundImage:url("+c+"less-"+s+"n.gif);",downstyle:"backgroundImage:url("+c+"less-"+s+"d.gif);",hoverstyle:"backgroundImage:url("+c+"less-"+s+"h.gif);"},o={MouseDown:function(){e.editor.busy||e.editor.ScrollRelative(e.vertical,-1)},Repeat:function(){e.editor.busy||e.editor.ScrollRelative(e.vertical,-1)},Disabled:function(){return e.editor.busy}},SocialCalc.ButtonRegister(e.editor,e.lessbutton,a,o),e.main.appendChild(e.lessbutton),e.morebutton=document.createElement("div"),t=e.morebutton.style,t.height=(e.vertical?e.buttonthickness:e.controlthickness)+"px",t.width=(e.vertical?e.controlthickness:e.buttonthickness)+"px",t.zIndex=2,t.overflow="hidden",t.position="absolute",r(e.morebutton,i.TCmorebuttonStyle),t.backgroundImage="url("+c+"more-"+s+"n.gif)",i.TCmorebuttonClass&&(e.morebutton.className=i.TCmorebuttonClass),l(e.editor,e.morebutton,"morebutton"+s),a={repeatwait:i.TCmorebuttonRepeatWait,repeatinterval:i.TCmorebuttonRepeatInterval,normalstyle:"backgroundImage:url("+c+"more-"+s+"n.gif);",downstyle:"backgroundImage:url("+c+"more-"+s+"d.gif);",hoverstyle:"backgroundImage:url("+c+"more-"+s+"h.gif);"},o={MouseDown:function(){e.editor.busy||e.editor.ScrollRelative(e.vertical,1)},Repeat:function(){e.editor.busy||e.editor.ScrollRelative(e.vertical,1)},Disabled:function(){return e.editor.busy}},SocialCalc.ButtonRegister(e.editor,e.morebutton,a,o),e.main.appendChild(e.morebutton),e.scrollarea=document.createElement("div"),t=e.scrollarea.style,t.height=e.controlthickness+"px",t.width=e.controlthickness+"px",t.zIndex=1,t.overflow="hidden",t.position="absolute",r(e.scrollarea,i.TCscrollareaStyle),t.backgroundImage="url("+c+"scrollarea-"+s+".gif)",i.TCscrollareaClass&&(e.scrollarea.className=i.TCscrollareaClass),l(e.editor,e.scrollarea,"scrollarea"+s),a={repeatwait:i.TCscrollareaRepeatWait,repeatinterval:i.TCscrollareaRepeatWait},o={MouseDown:SocialCalc.ScrollAreaClick,Repeat:SocialCalc.ScrollAreaClick,Disabled:function(){return e.editor.busy}},o.control=e,SocialCalc.ButtonRegister(e.editor,e.scrollarea,a,o),e.main.appendChild(e.scrollarea),e.thumb=document.createElement("div"),t=e.thumb.style,t.height=(e.vertical?e.thumbthickness:e.controlthickness)+"px",t.width=(e.vertical?e.controlthickness:e.thumbthickness)+"px",t.zIndex=2,t.overflow="hidden",t.position="absolute",r(e.thumb,i.TCthumbStyle),e.thumb.style.backgroundImage="url("+c+"thumb-"+s+"n.gif)",i.TCthumbClass&&(e.thumb.className=i.TCthumbClass),l(e.editor,e.thumb,"thumb"+s),o={MouseDown:SocialCalc.TCTDragFunctionStart,MouseMove:SocialCalc.TCTDragFunctionMove,MouseUp:SocialCalc.TCTDragFunctionStop,Disabled:function(){return e.editor.busy}},o.control=e,SocialCalc.DragRegister(e.thumb,e.vertical,!e.vertical,o,e.editor.toplevel),a={normalstyle:"backgroundImage:url("+c+"thumb-"+s+"n.gif)",name:"Thumb",downstyle:"backgroundImage:url("+c+"thumb-"+s+"d.gif)",hoverstyle:"backgroundImage:url("+c+"thumb-"+s+"h.gif)"},SocialCalc.ButtonRegister(e.editor,e.thumb,a,null),e.main.appendChild(e.thumb),e.main},SocialCalc.ScrollAreaClick=function(e,t,o){var a=o.functionobj.control,l=SocialCalc.GetElementPositionWithScroll(a.editor.toplevel),r=a.vertical?t.clientY-l.top:t.clientX-l.left;a.editor.busy||a.editor.PageRelative(a.vertical,r>a.thumbpos?1:-1)},SocialCalc.PositionTableControlElements=function(e){var t,o,a,l=e.editor;e.vertical?(t=e.controlborder+"px",e.endcap.style.top=e.endcapstart+"px",e.endcap.style.left=t,e.paneslider.style.top=e.panesliderstart+"px",e.paneslider.style.left=t,e.lessbutton.style.top=e.lessbuttonstart+"px",e.lessbutton.style.left=t,e.morebutton.style.top=e.morebuttonstart+"px",e.morebutton.style.left=t,e.scrollarea.style.top=e.scrollareastart+"px",e.scrollarea.style.left=t,e.scrollarea.style.height=e.scrollareasize+"px",o=Math.max(l.context.sheetobj.attribs.lastrow,l.firstscrollingrow+1),a=(l.firstscrollingrow-(l.lastnonscrollingrow+1))*(e.scrollareasize-3*e.thumbthickness)/(o-(l.lastnonscrollingrow+1))+e.scrollareastart-1,a=Math.floor(a),e.thumb.style.top=a+"px",e.thumb.style.left=t):(t=e.controlborder+"px",e.endcap.style.left=e.endcapstart+"px",e.endcap.style.top=t,e.paneslider.style.left=e.panesliderstart+"px",e.paneslider.style.top=t,e.lessbutton.style.left=e.lessbuttonstart+"px",e.lessbutton.style.top=t,e.morebutton.style.left=e.morebuttonstart+"px",e.morebutton.style.top=t,e.scrollarea.style.left=e.scrollareastart+"px",e.scrollarea.style.top=t,e.scrollarea.style.width=e.scrollareasize+"px",o=Math.max(l.context.sheetobj.attribs.lastcol,l.firstscrollingcol+1),a=(l.firstscrollingcol-(l.lastnonscrollingcol+1))*(e.scrollareasize-e.thumbthickness)/(o-l.lastnonscrollingcol)+e.scrollareastart-1,a=Math.floor(a),e.thumb.style.left=a+"px",e.thumb.style.top=t),e.thumbpos=a,e.main.style.display="block"},SocialCalc.ComputeTableControlPositions=function(e){var t=e.editor;if(!t.gridposition||!t.headposition)throw"Can't compute table control positions before editor positions";e.vertical?(e.controlborder=t.gridposition.left+t.tablewidth,e.endcapstart=t.gridposition.top,e.panesliderstart=t.firstscrollingrowtop-e.sliderthickness,e.lessbuttonstart=t.firstscrollingrowtop-1,e.morebuttonstart=t.gridposition.top+t.tableheight-e.buttonthickness,e.scrollareastart=t.firstscrollingrowtop-1+e.buttonthickness,e.scrollareaend=e.morebuttonstart-1,e.scrollareasize=e.scrollareaend-e.scrollareastart+1):(e.controlborder=t.gridposition.top+t.tableheight,e.endcapstart=t.gridposition.left,e.panesliderstart=t.firstscrollingcolleft-e.sliderthickness,e.lessbuttonstart=t.firstscrollingcolleft-1,e.morebuttonstart=t.gridposition.left+t.tablewidth-e.buttonthickness,e.scrollareastart=t.firstscrollingcolleft-1+e.buttonthickness,e.scrollareaend=e.morebuttonstart-1,e.scrollareasize=e.scrollareaend-e.scrollareastart+1)},SocialCalc.TCPSDragFunctionStart=function(e,t,o){var a=o.functionobj.control.editor,l=SocialCalc.Constants;SocialCalc.DragFunctionStart(e,t,o),t.trackingline=document.createElement("div"),t.trackingline.style.height=o.vertical?l.TCPStrackinglineThickness:a.tableheight-(a.headposition.top-a.gridposition.top)+"px",t.trackingline.style.width=o.vertical?a.tablewidth-(a.headposition.left-a.gridposition.left)+"px":l.TCPStrackinglineThickness,t.trackingline.style.backgroundImage="url("+a.imageprefix+"trackingline-"+(o.vertical?"v":"h")+".gif)",l.TCPStrackinglineClass&&(t.trackingline.className=l.TCPStrackinglineClass),SocialCalc.setStyles(t.trackingline,l.TCPStrackinglineStyle),o.vertical?(row=SocialCalc.Lookup(t.clientY+o.functionobj.control.sliderthickness,a.rowpositions),t.trackingline.style.top=(a.rowpositions[row]||a.headposition.top)+"px",t.trackingline.style.left=a.headposition.left+"px",a.context.rowpanes.length-1&&(a.context.SetRowPaneFirstLast(1,a.context.rowpanes[0].last+1,a.context.rowpanes[0].last+1),a.FitToEditTable(),a.ScheduleRender())):(col=SocialCalc.Lookup(t.clientX+o.functionobj.control.sliderthickness,a.colpositions),t.trackingline.style.top=a.headposition.top+"px",t.trackingline.style.left=(a.colpositions[col]||a.headposition.left)+"px",a.context.colpanes.length-1&&(a.context.SetColPaneFirstLast(1,a.context.colpanes[0].last+1,a.context.colpanes[0].last+1),a.FitToEditTable(),a.ScheduleRender())),a.griddiv.appendChild(t.trackingline)},SocialCalc.TCPSDragFunctionMove=function(e,t,o){var a,l,r,i,n=o.functionobj.control,c=n.sliderthickness,s=n.editor;if(o.vertical){for(r=n.morebuttonstart-n.minscrollingpanesize-t.offsetY,t.clientY>r&&(t.clientY=r),i=s.headposition.top-c-t.offsetY,t.clientY<i&&(t.clientY=i),a=SocialCalc.Lookup(t.clientY+c,s.rowpositions);"yes"==s.context.sheetobj.rowattribs.hide[a];)a++;t.trackingline.style.top=(s.rowpositions[a]||s.headposition.top)+"px"}else{for(r=n.morebuttonstart-n.minscrollingpanesize-t.offsetX,t.clientX>r&&(t.clientX=r),i=s.headposition.left-c-t.offsetX,t.clientX<i&&(t.clientX=i),l=SocialCalc.Lookup(t.clientX+c,s.colpositions);"yes"==s.context.sheetobj.colattribs.hide[SocialCalc.rcColname(l)];)l++;t.trackingline.style.left=(s.colpositions[l]||s.headposition.left)+"px"}SocialCalc.DragFunctionPosition(e,t,o)},SocialCalc.TCPSDragFunctionStop=function(e,t,o){var a,l,r,i,n=o.functionobj.control,c=n.sliderthickness,s=n.editor;if(o.vertical){for(r=n.morebuttonstart-n.minscrollingpanesize-t.offsetY,t.clientY>r&&(t.clientY=r),i=s.headposition.top-c-t.offsetY,t.clientY<i&&(t.clientY=i),a=SocialCalc.Lookup(t.clientY+c,s.rowpositions),a>s.context.sheetobj.attribs.lastrow&&(a=s.context.sheetobj.attribs.lastrow);"yes"==s.context.sheetobj.rowattribs.hide[a];)a++;!a||a<=s.context.rowpanes[0].first?s.context.rowpanes.length>1&&(s.context.rowpanes.length=1):s.context.rowpanes.length-1?s.timeout||(s.context.SetRowPaneFirstLast(0,s.context.rowpanes[0].first,a-1),s.context.SetRowPaneFirstLast(1,a,a)):(s.context.SetRowPaneFirstLast(0,s.context.rowpanes[0].first,a-1),s.context.SetRowPaneFirstLast(1,a,a))}else{for(r=n.morebuttonstart-n.minscrollingpanesize-t.offsetX,t.clientX>r&&(t.clientX=r),i=s.headposition.left-c-t.offsetX,t.clientX<i&&(t.clientX=i),l=SocialCalc.Lookup(t.clientX+c,s.colpositions),l>s.context.sheetobj.attribs.lastcol&&(l=s.context.sheetobj.attribs.lastcol);"yes"==s.context.sheetobj.colattribs.hide[SocialCalc.rcColname(l)];)l++;!l||l<=s.context.colpanes[0].first?s.context.colpanes.length>1&&(s.context.colpanes.length=1):s.context.colpanes.length-1?s.timeout||(s.context.SetColPaneFirstLast(0,s.context.colpanes[0].first,l-1),s.context.SetColPaneFirstLast(1,l,l)):(s.context.SetColPaneFirstLast(0,s.context.colpanes[0].first,l-1),s.context.SetColPaneFirstLast(1,l,l))}s.FitToEditTable(),s.griddiv.removeChild(t.trackingline),s.ScheduleRender()},SocialCalc.TCTDragFunctionStart=function(e,t,o){var a=o.functionobj.control,l=a.editor,r=SocialCalc.Constants;if(SocialCalc.DragFunctionStart(e,t,o),t.thumbstatus&&(t.thumbstatus.rowmsgele&&(t.thumbstatus.rowmsgele=null),t.thumbstatus.rowpreviewele&&(t.thumbstatus.rowpreviewele=null),l.toplevel.removeChild(t.thumbstatus),t.thumbstatus=null),t.thumbstatus=document.createElement("div"),o.vertical){r.TCTDFSthumbstatusvClass&&(t.thumbstatus.className=r.TCTDFSthumbstatusvClass),SocialCalc.setStyles(t.thumbstatus,r.TCTDFSthumbstatusvStyle),t.thumbstatus.style.top=t.clientY+r.TCTDFStopOffsetv+"px",t.thumbstatus.style.left=a.controlborder-10-l.tablewidth/2+"px",t.thumbstatus.style.width=l.tablewidth/2+"px",t.thumbcontext=new SocialCalc.RenderContext(l.context.sheetobj),t.thumbcontext.showGrid=!0,t.thumbcontext.rowpanes=[{first:1,last:1}];var i=l.context.colpanes[l.context.colpanes.length-1];t.thumbcontext.colpanes=[{first:i.first,last:i.last}],t.thumbstatus.innerHTML='<table cellspacing="0" cellpadding="0"><tr><td valign="top" style="'+r.TCTDFSthumbstatusrownumStyle+'" class="'+r.TCTDFSthumbstatusrownumClass+'"><div>msg</div></td><td valign="top"><div style="overflow:hidden;">preview</div></td></tr></table>',t.thumbstatus.rowmsgele=t.thumbstatus.firstChild.firstChild.firstChild.firstChild.firstChild,t.thumbstatus.rowpreviewele=t.thumbstatus.firstChild.firstChild.firstChild.childNodes[1].firstChild,l.toplevel.appendChild(t.thumbstatus),SocialCalc.TCTDragFunctionRowSetStatus(t,l,l.firstscrollingrow||1)}else r.TCTDFSthumbstatushClass&&(t.thumbstatus.className=r.TCTDFSthumbstatushClass),SocialCalc.setStyles(t.thumbstatus,r.TCTDFSthumbstatushStyle),t.thumbstatus.style.top=a.controlborder+r.TCTDFStopOffseth+"px",t.thumbstatus.style.left=t.clientX+r.TCTDFSleftOffseth+"px",l.toplevel.appendChild(t.thumbstatus),t.thumbstatus.innerHTML=r.s_TCTDFthumbstatusPrefixh+SocialCalc.rcColname(l.firstscrollingcol)},SocialCalc.TCTDragFunctionRowSetStatus=function(e,t,o){var a=SocialCalc.Constants,l=a.s_TCTDFthumbstatusPrefixv+o+" ";e.thumbstatus.rowmsgele.innerHTML=l,e.thumbcontext.rowpanes=[{first:o,last:o}],e.thumbrowshown=o;e.thumbcontext.RenderSheet(e.thumbstatus.rowpreviewele.firstChild,{type:"html"})},SocialCalc.TCTDragFunctionMove=function(e,t,o){var a,l,r=o.functionobj.control,i=(r.thumbthickness,r.editor),n=SocialCalc.Constants;o.vertical?(t.clientY>r.scrollareaend-t.offsetY-r.thumbthickness+2&&(t.clientY=r.scrollareaend-t.offsetY-r.thumbthickness+2),t.clientY<r.scrollareastart-t.offsetY-1&&(t.clientY=r.scrollareastart-t.offsetY-1),t.thumbstatus.style.top=t.clientY+"px",a=(t.clientY+t.offsetY-r.scrollareastart+1)/(r.scrollareasize-r.thumbthickness)*(i.context.sheetobj.attribs.lastrow-i.lastnonscrollingrow)+i.lastnonscrollingrow+1,a=Math.floor(a),a<=i.lastnonscrollingrow&&(a=i.lastnonscrollingrow+1),a>i.context.sheetobj.attribs.lastrow&&(a=i.context.sheetobj.attribs.lastrow),a!=t.thumbrowshown&&SocialCalc.TCTDragFunctionRowSetStatus(t,i,a)):(t.clientX>r.scrollareaend-t.offsetX-r.thumbthickness+2&&(t.clientX=r.scrollareaend-t.offsetX-r.thumbthickness+2),t.clientX<r.scrollareastart-t.offsetX-1&&(t.clientX=r.scrollareastart-t.offsetX-1),t.thumbstatus.style.left=t.clientX+"px",a=(t.clientX+t.offsetX-r.scrollareastart+1)/(r.scrollareasize-r.thumbthickness)*(i.context.sheetobj.attribs.lastcol-i.lastnonscrollingcol)+i.lastnonscrollingcol+1,a=Math.floor(a),a<=i.lastnonscrollingcol&&(a=i.lastnonscrollingcol+1),a>i.context.sheetobj.attribs.lastcol&&(a=i.context.sheetobj.attribs.lastcol),l=n.s_TCTDFthumbstatusPrefixh+SocialCalc.rcColname(a),t.thumbstatus.innerHTML=l),SocialCalc.DragFunctionPosition(e,t,o)},SocialCalc.TCTDragFunctionStop=function(e,t,o){var a,l=o.functionobj.control,r=l.editor;o.vertical?(a=(t.clientY+t.offsetY-l.scrollareastart+1)/(l.scrollareasize-l.thumbthickness)*(r.context.sheetobj.attribs.lastrow-r.lastnonscrollingrow)+r.lastnonscrollingrow+1,a=Math.floor(a),a<=r.lastnonscrollingrow&&(a=r.lastnonscrollingrow+1),a>r.context.sheetobj.attribs.lastrow&&(a=r.context.sheetobj.attribs.lastrow),r.context.SetRowPaneFirstLast(r.context.rowpanes.length-1,a,a+1)):(a=(t.clientX+t.offsetX-l.scrollareastart+1)/(l.scrollareasize-l.thumbthickness)*(r.context.sheetobj.attribs.lastcol-r.lastnonscrollingcol)+r.lastnonscrollingcol+1,a=Math.floor(a),a<=r.lastnonscrollingcol&&(a=r.lastnonscrollingcol+1),a>r.context.sheetobj.attribs.lastcol&&(a=r.context.sheetobj.attribs.lastcol),r.context.SetColPaneFirstLast(r.context.colpanes.length-1,a,a+1)),r.FitToEditTable(),t.thumbstatus.rowmsgele&&(t.thumbstatus.rowmsgele=null),t.thumbstatus.rowpreviewele&&(t.thumbstatus.rowpreviewele=null),r.toplevel.removeChild(t.thumbstatus),t.thumbstatus=null,r.ScheduleRender()},SocialCalc.DragInfo={registeredElements:[],draggingElement:null,startX:0,startY:0,startZ:0,clientX:0,clientY:0,offsetX:0,offsetY:0,relativeOffset:{left:0,top:0}},SocialCalc.DragRegister=function(e,t,o,a,l){var r=SocialCalc.DragInfo;if(a||(a={MouseDown:SocialCalc.DragFunctionStart,MouseMove:SocialCalc.DragFunctionPosition,MouseUp:SocialCalc.DragFunctionPosition,Disabled:null}),r.registeredElements.push({element:e,vertical:t,horizontal:o,functionobj:a,parent:l}),e.addEventListener)e.addEventListener("mousedown",SocialCalc.DragMouseDown,!1);else{if(!e.attachEvent)throw SocialCalc.Constants.s_BrowserNotSupported;e.attachEvent("onmousedown",SocialCalc.DragMouseDown)}},SocialCalc.DragUnregister=function(e){var t,o=SocialCalc.DragInfo;if(e)for(t=0;t<o.registeredElements.length;t++)if(o.registeredElements[t].element==e)return o.registeredElements.splice(t,1),void(e.removeEventListener?e.removeEventListener("mousedown",SocialCalc.DragMouseDown,!1):e.detachEvent("onmousedown",SocialCalc.DragMouseDown))},SocialCalc.DragMouseDown=function(e){var t=e||window.event,o=SocialCalc.DragInfo,a=SocialCalc.LookupElement(t.target||t.srcElement,o.registeredElements);return!a||a&&a.functionobj&&a.functionobj.Disabled&&a.functionobj.Disabled(t,o,a)?void 0:(o.draggingElement=a,a.parent&&(o.relativeOffset=SocialCalc.GetElementPositionWithScroll(a.parent)),o.clientX=t.clientX-o.relativeOffset.left,o.clientY=t.clientY-o.relativeOffset.top,o.startX=o.clientX,o.startY=o.clientY,o.startZ=a.element.style.zIndex,o.offsetX=0,o.offsetY=0,a.element.style.zIndex="100",document.addEventListener?(document.addEventListener("mousemove",SocialCalc.DragMouseMove,!0),document.addEventListener("mouseup",SocialCalc.DragMouseUp,!0)):a.element.attachEvent&&(a.element.setCapture(),a.element.attachEvent("onmousemove",SocialCalc.DragMouseMove),a.element.attachEvent("onmouseup",SocialCalc.DragMouseUp),a.element.attachEvent("onlosecapture",SocialCalc.DragMouseUp)),t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1,a&&a.functionobj&&a.functionobj.MouseDown&&a.functionobj.MouseDown(t,o,a),!1)},SocialCalc.DragMouseMove=function(e){var t=e||window.event,o=SocialCalc.DragInfo,a=o.draggingElement;return o.clientX=t.clientX-o.relativeOffset.left,o.clientY=t.clientY-o.relativeOffset.top,t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,a&&a.functionobj&&a.functionobj.MouseMove&&a.functionobj.MouseMove(t,o,a),!1},SocialCalc.DragMouseUp=function(e){var t=e||window.event,o=SocialCalc.DragInfo,a=o.draggingElement;return o.clientX=t.clientX-o.relativeOffset.left,o.clientY=t.clientY-o.relativeOffset.top,a.element.style.zIndex=o.startZ,a&&a.functionobj&&a.functionobj.MouseUp&&a.functionobj.MouseUp(t,o,a),t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,document.removeEventListener?(document.removeEventListener("mousemove",SocialCalc.DragMouseMove,!0),document.removeEventListener("mouseup",SocialCalc.DragMouseUp,!0)):a.element.detachEvent&&(a.element.detachEvent("onlosecapture",SocialCalc.DragMouseUp),a.element.detachEvent("onmouseup",SocialCalc.DragMouseUp),a.element.detachEvent("onmousemove",SocialCalc.DragMouseMove),a.element.releaseCapture()),o.draggingElement=null,!1},SocialCalc.DragFunctionStart=function(e,t,o){var a=o.functionobj.positionobj||o.element;t.offsetY=parseInt(a.style.top)-t.clientY,t.offsetX=parseInt(a.style.left)-t.clientX},SocialCalc.DragFunctionPosition=function(e,t,o){var a=o.functionobj.positionobj||o.element;o.vertical&&(a.style.top=t.clientY+t.offsetY+"px"),o.horizontal&&(a.style.left=t.clientX+t.offsetX+"px")},SocialCalc.TooltipInfo={registeredElements:[],registered:!1,tooltipElement:null,timer:null,popupElement:null,clientX:0,clientY:0,offsetX:SocialCalc.Constants.TooltipOffsetX,offsetY:SocialCalc.Constants.TooltipOffsetY},SocialCalc.TooltipRegister=function(e,t,o,a){var l=SocialCalc.TooltipInfo;if(l.registeredElements.push({element:e,tiptext:t,functionobj:o,parent:a}),!l.registered){if(document.addEventListener)document.addEventListener("mousemove",SocialCalc.TooltipMouseMove,!1);else{if(!document.attachEvent)throw SocialCalc.Constants.s_BrowserNotSupported;document.attachEvent("onmousemove",SocialCalc.TooltipMouseMove)}l.registered=!0}},SocialCalc.TooltipMouseMove=function(e){var t=e||window.event,o=SocialCalc.TooltipInfo;o.clientX=t.clientX,o.clientY=t.clientY;var a=SocialCalc.LookupElement(t.target||t.srcElement,o.registeredElements);o.timer&&(window.clearTimeout(o.timer),o.timer=null),o.popupElement&&SocialCalc.TooltipHide(),o.tooltipElement=a||null,a&&!SocialCalc.ButtonInfo.buttonDown&&(o.timer=window.setTimeout(SocialCalc.TooltipWaitDone,700),o.tooltipElement.element.addEventListener?o.tooltipElement.element.addEventListener("mousedown",SocialCalc.TooltipMouseDown,!1):o.tooltipElement.element.attachEvent&&o.tooltipElement.element.attachEvent("onmousedown",SocialCalc.TooltipMouseDown))},SocialCalc.TooltipMouseDown=function(e){var t=(e||window.event,SocialCalc.TooltipInfo);t.timer&&(window.clearTimeout(t.timer),t.timer=null),t.popupElement&&SocialCalc.TooltipHide(),t.tooltipElement&&(t.tooltipElement.element.removeEventListener?t.tooltipElement.element.removeEventListener("mousedown",SocialCalc.TooltipMouseDown,!1):t.tooltipElement.element.attachEvent&&t.tooltipElement.element.detachEvent("onmousedown",SocialCalc.TooltipMouseDown),t.tooltipElement=null)},SocialCalc.TooltipDisplay=function(e){var t=SocialCalc.TooltipInfo,o=SocialCalc.Constants,a=e.functionobj&&"number"==typeof e.functionobj.offsetx?e.functionobj.offsetx:t.offsetX,l=e.functionobj&&"number"==typeof e.functionobj.offsety?e.functionobj.offsety:t.offsetY,r=SocialCalc.GetViewportInfo(),i=SocialCalc.GetElementPositionWithScroll(e.parent);t.popupElement=document.createElement("div"),o.TDpopupElementClass&&(t.popupElement.className=o.TDpopupElementClass),SocialCalc.setStyles(t.popupElement,o.TDpopupElementStyle),t.popupElement.innerHTML=e.tiptext,t.clientX>r.width/2?(t.popupElement.style.bottom=i.height-t.clientY+l+i.top+"px",t.popupElement.style.right=i.width-t.clientX+a+i.left+"px"):(t.popupElement.style.bottom=i.height-t.clientY+l+i.top+"px",t.popupElement.style.left=t.clientX+a-i.left+"px"),t.clientY<50&&(t.popupElement.style.bottom=i.height-t.clientY+l-50+i.top+"px"),e.parent.appendChild(t.popupElement)},SocialCalc.TooltipHide=function(){var e=SocialCalc.TooltipInfo;e.popupElement&&(e.popupElement.parentNode.removeChild(e.popupElement),e.popupElement=null)},SocialCalc.TooltipWaitDone=function(){var e=SocialCalc.TooltipInfo;e.timer=null,SocialCalc.TooltipDisplay(e.tooltipElement)},SocialCalc.ButtonInfo={registeredElements:[],buttonElement:null,doingHover:!1,buttonDown:!1,timer:null,relativeOffset:null,clientX:0,clientY:0},SocialCalc.ButtonRegister=function(e,t,o,a){var l=SocialCalc.ButtonInfo;if(o||(o={}),l.registeredElements.push({name:o.name,element:t,editor:e,normalstyle:o.normalstyle,hoverstyle:o.hoverstyle,downstyle:o.downstyle,repeatwait:o.repeatwait,repeatinterval:o.repeatinterval,functionobj:a}),t.addEventListener)t.addEventListener("mousedown",SocialCalc.ButtonMouseDown,!1),t.addEventListener("mouseover",SocialCalc.ButtonMouseOver,!1),t.addEventListener("mouseout",SocialCalc.ButtonMouseOut,!1);else{if(!t.attachEvent)throw SocialCalc.Constants.s_BrowserNotSupported;t.attachEvent("onmousedown",SocialCalc.ButtonMouseDown),t.attachEvent("onmouseover",SocialCalc.ButtonMouseOver),t.attachEvent("onmouseout",SocialCalc.ButtonMouseOut)}},SocialCalc.ButtonMouseOver=function(e){var t=e||window.event,o=SocialCalc.ButtonInfo,a=SocialCalc.LookupElement(t.target||t.srcElement,o.registeredElements);if(a){if(o.buttonDown)return void(o.buttonElement==a&&(o.doingHover=!0));o.buttonElement&&o.buttonElement!=a&&o.doingHover&&SocialCalc.setStyles(o.buttonElement.element,o.buttonElement.normalstyle),o.buttonElement=a,o.doingHover=!0,SocialCalc.setStyles(a.element,a.hoverstyle),a&&a.functionobj&&a.functionobj.MouseOver&&a.functionobj.MouseOver(t,o,a)}},SocialCalc.ButtonMouseOut=function(e){var t=e||window.event,o=SocialCalc.ButtonInfo;if(o.buttonDown)return void(o.doingHover=!1);var a=SocialCalc.LookupElement(t.target||t.srcElement,o.registeredElements);o.doingHover&&(o.buttonElement&&SocialCalc.setStyles(o.buttonElement.element,o.buttonElement.normalstyle),o.buttonElement=null,o.doingHover=!1),a&&a.functionobj&&a.functionobj.MouseOut&&a.functionobj.MouseOut(t,o,a)},SocialCalc.ButtonMouseDown=function(e){var t=e||window.event,o=SocialCalc.ButtonInfo,a=(SocialCalc.GetViewportInfo(),SocialCalc.LookupElement(t.target||t.srcElement,o.registeredElements));a&&(a&&a.functionobj&&a.functionobj.Disabled&&a.functionobj.Disabled(t,o,a)||(o.buttonElement=a,o.buttonDown=!0,SocialCalc.setStyles(a.element,o.buttonElement.downstyle),document.addEventListener?document.addEventListener("mouseup",SocialCalc.ButtonMouseUp,!0):a.element.attachEvent&&(a.element.setCapture(),a.element.attachEvent("onmouseup",SocialCalc.ButtonMouseUp),a.element.attachEvent("onlosecapture",SocialCalc.ButtonMouseUp)),t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1,o.relativeOffset=SocialCalc.GetElementPositionWithScroll(a.editor.toplevel),o.clientX=t.clientX-o.relativeOffset.left,o.clientY=t.clientY-o.relativeOffset.top,a&&a.functionobj&&a.functionobj.MouseDown&&a.functionobj.MouseDown(t,o,a),a.repeatwait&&(o.timer=window.setTimeout(SocialCalc.ButtonRepeat,a.repeatwait))))},SocialCalc.ButtonMouseUp=function(e){var t=e||window.event,o=SocialCalc.ButtonInfo,a=o.buttonElement;o.timer&&(window.clearTimeout(o.timer),o.timer=null),o.buttonDown&&(t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1,document.removeEventListener?document.removeEventListener("mouseup",SocialCalc.ButtonMouseUp,!0):document.detachEvent&&(a.element.detachEvent("onlosecapture",SocialCalc.ButtonMouseUp),a.element.detachEvent("onmouseup",SocialCalc.ButtonMouseUp),a.element.releaseCapture()),o.buttonElement.downstyle&&(o.doingHover?SocialCalc.setStyles(a.element,o.buttonElement.hoverstyle):SocialCalc.setStyles(a.element,o.buttonElement.normalstyle)),o.buttonDown=!1,a&&a.functionobj&&a.functionobj.MouseUp&&a.functionobj.MouseUp(t,o,a))},SocialCalc.ButtonRepeat=function(){var e=SocialCalc.ButtonInfo,t=e.buttonElement;t&&(t&&t.functionobj&&t.functionobj.Repeat&&t.functionobj.Repeat(null,e,t),e.timer=window.setTimeout(SocialCalc.ButtonRepeat,t.repeatinterval||100))},SocialCalc.MouseWheelInfo={registeredElements:[]},SocialCalc.MouseWheelRegister=function(e,t){var o=SocialCalc.MouseWheelInfo;if(o.registeredElements.push({element:e,functionobj:t}),e.addEventListener)e.addEventListener("DOMMouseScroll",SocialCalc.ProcessMouseWheel,!1),e.addEventListener("mousewheel",SocialCalc.ProcessMouseWheel,!1);else{if(!e.attachEvent)throw SocialCalc.Constants.s_BrowserNotSupported;e.attachEvent("onmousewheel",SocialCalc.ProcessMouseWheel)}},SocialCalc.ProcessMouseWheel=function(e){var t,o=e||window.event;if(!SocialCalc.Keyboard.passThru){var a,l=SocialCalc.MouseWheelInfo,r=o.target||o.srcElement;for(a=null;!a&&r;r=r.parentNode)a=SocialCalc.LookupElement(r,l.registeredElements);a&&(t=o.wheelDelta?o.wheelDelta/120:-o.detail/3,t||(t=0),a.functionobj&&a.functionobj.WheelMove&&a.functionobj.WheelMove(o,t,l,a),o.preventDefault&&o.preventDefault(),
o.returnValue=!1)}},SocialCalc.keyboardTables={specialKeysCommon:{8:"[backspace]",9:"[tab]",13:"[enter]",25:"[tab]",27:"[esc]",33:"[pgup]",34:"[pgdn]",35:"[end]",36:"[home]",37:"[aleft]",38:"[aup]",39:"[aright]",40:"[adown]",45:"[ins]",46:"[del]",113:"[f2]"},specialKeysIE:{8:"[backspace]",9:"[tab]",13:"[enter]",25:"[tab]",27:"[esc]",33:"[pgup]",34:"[pgdn]",35:"[end]",36:"[home]",37:"[aleft]",38:"[aup]",39:"[aright]",40:"[adown]",45:"[ins]",46:"[del]",113:"[f2]"},controlKeysIE:{67:"[ctrl-c]",83:"[ctrl-s]",86:"[ctrl-v]",88:"[ctrl-x]",90:"[ctrl-z]"},specialKeysOpera:{8:"[backspace]",9:"[tab]",13:"[enter]",25:"[tab]",27:"[esc]",33:"[pgup]",34:"[pgdn]",35:"[end]",36:"[home]",37:"[aleft]",38:"[aup]",39:"[aright]",40:"[adown]",45:"[ins]",46:"[del]",113:"[f2]"},controlKeysOpera:{67:"[ctrl-c]",83:"[ctrl-s]",86:"[ctrl-v]",88:"[ctrl-x]",90:"[ctrl-z]"},specialKeysSafari:{8:"[backspace]",9:"[tab]",13:"[enter]",25:"[tab]",27:"[esc]",63232:"[aup]",63233:"[adown]",63234:"[aleft]",63235:"[aright]",63272:"[del]",63273:"[home]",63275:"[end]",63276:"[pgup]",63277:"[pgdn]",63237:"[f2]"},controlKeysSafari:{99:"[ctrl-c]",115:"[ctrl-s]",118:"[ctrl-v]",120:"[ctrl-x]",122:"[ctrl-z]"},ignoreKeysSafari:{63236:"[f1]",63238:"[f3]",63239:"[f4]",63240:"[f5]",63241:"[f6]",63242:"[f7]",63243:"[f8]",63244:"[f9]",63245:"[f10]",63246:"[f11]",63247:"[f12]",63289:"[numlock]"},specialKeysFirefox:{8:"[backspace]",9:"[tab]",13:"[enter]",25:"[tab]",27:"[esc]",33:"[pgup]",34:"[pgdn]",35:"[end]",36:"[home]",37:"[aleft]",38:"[aup]",39:"[aright]",40:"[adown]",45:"[ins]",46:"[del]",113:"[f2]"},controlKeysFirefox:{99:"[ctrl-c]",115:"[ctrl-s]",118:"[ctrl-v]",120:"[ctrl-x]",122:"[ctrl-z]"},ignoreKeysFirefox:{16:"[shift]",17:"[ctrl]",18:"[alt]",20:"[capslock]",19:"[pause]",44:"[printscreen]",91:"[windows]",92:"[windows]",112:"[f1]",114:"[f3]",115:"[f4]",116:"[f5]",117:"[f6]",118:"[f7]",119:"[f8]",120:"[f9]",121:"[f10]",122:"[f11]",123:"[f12]",144:"[numlock]",145:"[scrolllock]",224:"[cmd]"}},SocialCalc.Keyboard={areListener:!1,focusTable:null,passThru:null,didProcessKey:!1,statusFromProcessKey:!1,repeatingKeyPress:!1,chForProcessKey:""},SocialCalc.KeyboardSetFocus=function(e){SocialCalc.Keyboard.focusTable=e,SocialCalc.Keyboard.areListener||(document.onkeydown=SocialCalc.ProcessKeyDown,document.onkeypress=SocialCalc.ProcessKeyPress,SocialCalc.Keyboard.areListener=!0),SocialCalc.Keyboard.passThru&&(SocialCalc.Keyboard.passThru.blur&&SocialCalc.Keyboard.passThru.blur(),SocialCalc.Keyboard.passThru=null),window.focus()},SocialCalc.KeyboardFocus=function(){SocialCalc.Keyboard.passThru=null,window.focus()},SocialCalc.ProcessKeyDown=function(e){var t=SocialCalc.keyboardTables;t.didProcessKey=!1,t.statusFromProcessKey=!1,t.repeatingKeyPress=!1;var o="",a=!0;if(!SocialCalc.Keyboard.passThru){if(e=e||window.event,void 0==e.which){if(o=t.specialKeysCommon[e.keyCode],!o&&(e.ctrlKey&&(o=t.controlKeysIE[e.keyCode]),!o))return!0;a=SocialCalc.ProcessKey(o,e),a||(e.preventDefault&&e.preventDefault(),e.returnValue=!1)}else{if(o=t.specialKeysCommon[e.keyCode],!o&&((e.ctrlKey||e.metaKey)&&(o=t.controlKeysIE[e.keyCode]),!o))return!0;a=SocialCalc.ProcessKey(o,e),t.didProcessKey=!0,t.statusFromProcessKey=a,t.chForProcessKey=o}return a}},SocialCalc.ProcessKeyPress=function(e){var t=SocialCalc.keyboardTables,o="";if(e=e||window.event,!SocialCalc.Keyboard.passThru){if(t.didProcessKey)return t.repeatingKeyPress?SocialCalc.ProcessKey(t.chForProcessKey,e):(t.repeatingKeyPress=!0,t.statusFromProcessKey);if(void 0==e.which)o=String.fromCharCode(e.keyCode);else{if(!e.which)return!1;if(void 0==e.charCode){if(0==e.which)return!0;if(e.which<32||144==e.which){if(o=t.specialKeysOpera[e.which])return!0}else o=e.ctrlKey?t.controlKeysOpera[e.keyCode]:String.fromCharCode(e.which)}else{if(0==e.keyCode&&0==e.charCode)return;if(e.keyCode==e.charCode){if(o=t.specialKeysSafari[e.keyCode],!o){if(t.ignoreKeysSafari[e.keyCode])return!0;o=e.metaKey?t.controlKeysSafari[e.keyCode]:String.fromCharCode(e.which)}}else{if(t.specialKeysFirefox[e.keyCode])return!0;o=String.fromCharCode(e.which),(e.ctrlKey||e.metaKey)&&(o=t.controlKeysFirefox[e.which])}}}var a=SocialCalc.ProcessKey(o,e);return a||(e.preventDefault&&e.preventDefault(),e.returnValue=!1),a}},SocialCalc.ProcessKey=function(e,t){var o=SocialCalc.Keyboard.focusTable;return o?o.EditorProcessKey(e,t):!0};var SocialCalc;SocialCalc||(SocialCalc={}),SocialCalc.Popup={},SocialCalc.Popup.Types={},SocialCalc.Popup.Controls={},SocialCalc.Popup.Current={},SocialCalc.Popup.LocalizeString=function(e){return e},SocialCalc.Popup.Create=function(e,t,o){var a=SocialCalc.Popup.Types[e];a&&a.Create&&a.Create(e,t,o),SocialCalc.Popup.imagePrefix=SocialCalc.Constants.defaultImagePrefix},SocialCalc.Popup.SetValue=function(e,t){var o=SocialCalc.Popup,a=o.Types,l=o.Controls;if(!l[e])return void alert("Unknown control "+e);var r=l[e].type,i=a[r],n=l[e].data;i&&i.Create&&(i.SetValue(r,e,t),n.attribs&&n.attribs.changedcallback&&n.attribs.changedcallback(n.attribs,e,t))},SocialCalc.Popup.SetDisabled=function(e,t){var o=SocialCalc.Popup,a=o.Types,l=o.Controls;if(!l[e])return void alert("Unknown control "+e);var r=l[e].type,i=a[r];i&&i.Create&&(o.Current.id&&e==o.Current.id&&(i.Hide(r,o.Current.id),o.Current.id=null),i.SetDisabled(r,e,t))},SocialCalc.Popup.GetValue=function(e){var t=SocialCalc.Popup,o=t.Types,a=t.Controls;if(!a[e])return void alert("Unknown control "+e);var l=a[e].type,r=o[l];return r&&r.Create?r.GetValue(l,e):null},SocialCalc.Popup.Initialize=function(e,t){var o=SocialCalc.Popup,a=o.Types,l=o.Controls;if(!l[e])return void alert("Unknown control "+e);var r=l[e].type,i=a[r];i&&i.Initialize&&i.Initialize(r,e,t)},SocialCalc.Popup.Reset=function(e){var t=SocialCalc.Popup,o=t.Types;t.Controls;o[e].Reset&&o[e].Reset(e)},SocialCalc.Popup.CClick=function(e){var t=SocialCalc.Popup,o=t.Types,a=t.Controls;if(!a[e])return void alert("Unknown control "+e);if(!a[e].data||!a[e].data.disabled){var l=a[e].type,r=o[l];if(t.Current.id&&(o[a[t.Current.id].type].Hide(l,t.Current.id),e==t.Current.id))return void(t.Current.id=null);r&&r.Show&&r.Show(l,e),t.Current.id=e}},SocialCalc.Popup.Close=function(){var e=SocialCalc.Popup;e.Types,e.Controls;e.Current.id&&e.CClick(e.Current.id)},SocialCalc.Popup.Cancel=function(){var e=SocialCalc.Popup,t=e.Types,o=e.Controls;if(e.Current.id){var a=o[e.Current.id].type,l=t[a];l.Cancel(a,e.Current.id),e.Current.id=null}},SocialCalc.Popup.CreatePopupDiv=function(e,t){var o,a=SocialCalc.Popup,l=a.Controls,r=l[e].data,i=document.createElement("div");return i.style.position="absolute",o=SocialCalc.GetElementPosition(r.mainele),i.style.top=o.top+r.mainele.offsetHeight+"px",i.style.left=o.left+"px",i.style.zIndex=100,i.style.backgroundColor="#FFF",i.style.border="1px solid black",t.width&&(i.style.width=t.width),r.mainele.appendChild(i),t.title&&(i.innerHTML='<table cellspacing="0" cellpadding="0" style="border-bottom:1px solid black;"><tr><td style="font-size:10px;cursor:default;width:100%;background-color:#999;color:#FFF;">'+t.title+'</td><td style="font-size:10px;cursor:default;color:#666;" onclick="SocialCalc.Popup.Cancel();"> X </td></tr></table>',t.moveable&&(r.dragregistered=i.firstChild.firstChild.firstChild.firstChild,SocialCalc.DragRegister(r.dragregistered,!0,!0,{MouseDown:SocialCalc.DragFunctionStart,MouseMove:SocialCalc.DragFunctionPosition,MouseUp:SocialCalc.DragFunctionPosition,Disabled:null,positionobj:i},r.mainele))),i},SocialCalc.Popup.EnsurePosition=function(e,t){function o(e){var t=SocialCalc.GetElementPosition(e);return t.height=e.offsetHeight,t.width=e.offsetWidth,t.bottom=t.top+t.height,t.right=t.left+t.width,t}var a=SocialCalc.Popup,l=a.Controls,r=l[e].data,i=r.mainele.firstChild;if(!i)return void alert("No main popup element firstChild.");var n=r.popupele,c=o(n),s=o(t),d=o(i),u=0;d.bottom+c.height<s.bottom&&d.left+c.width<s.right?(n.style.top=d.bottom+"px",n.style.left=d.left+"px",u=1):d.top-c.height>s.top&&d.left+c.width<s.right?(n.style.top=d.top-c.height+"px",n.style.left=d.left+"px",u=2):d.bottom+c.height<s.bottom&&d.right-c.width>s.left?(n.style.top=d.bottom+"px",n.style.left=d.right-c.width+"px",u=3):d.top-c.height>s.top&&d.right-c.width>s.left?(n.style.top=d.top-c.height+"px",n.style.left=d.right-c.width+"px",u=4):d.bottom+c.height<s.bottom&&c.width<s.width?(n.style.top=d.bottom+"px",n.style.left=s.left+Math.floor((s.width-c.width)/2)+"px",u=5):d.top-c.height>s.top&&c.width<s.width?(n.style.top=d.top-c.height+"px",n.style.left=s.left+Math.floor((s.width-c.width)/2)+"px",u=6):c.height<s.height&&d.right+c.width<s.right?(n.style.top=s.top+Math.floor((s.height-c.height)/2)+"px",n.style.left=d.right+"px",u=7):c.height<s.height&&d.left-c.width>s.left&&(n.style.top=s.top+Math.floor((s.height-c.height)/2)+"px",n.style.left=d.left-c.width+"px",u=8)},SocialCalc.Popup.DestroyPopupDiv=function(e,t){e&&(e.innerHTML="",SocialCalc.DragUnregister(t),e.parentNode&&e.parentNode.removeChild(e))},SocialCalc.Popup.RGBToHex=function(e){var t=SocialCalc.Popup;if(""==e)return"000000";var o=e.match(/(\d+)\D+(\d+)\D+(\d+)/);return o?t.ToHex(o[1])+t.ToHex(o[2])+t.ToHex(o[3]):"000000"},SocialCalc.Popup.HexDigits="0123456789ABCDEF",SocialCalc.Popup.ToHex=function(e){var t=SocialCalc.Popup,o=Math.floor(e/16),a=e%16;return t.HexDigits.charAt(o)+t.HexDigits.charAt(a)},SocialCalc.Popup.FromHex=function(e){var t=SocialCalc.Popup,o=t.HexDigits.indexOf(e.charAt(0).toUpperCase()),a=t.HexDigits.indexOf(e.charAt(1).toUpperCase());return 16*(o>=0?o:0)+(a>=0?a:0)},SocialCalc.Popup.HexToRGB=function(e){var t=SocialCalc.Popup;return"rgb("+t.FromHex(e.substring(1,3))+","+t.FromHex(e.substring(3,5))+","+t.FromHex(e.substring(5,7))+")"},SocialCalc.Popup.makeRGB=function(e,t,o){return"rgb("+(e>0?e:0)+","+(t>0?t:0)+","+(o>0?o:0)+")"},SocialCalc.Popup.splitRGB=function(e){var t=e.match(/(\d+)\D+(\d+)\D+(\d+)\D/);return t?{r:t[1]-0,g:t[2]-0,b:t[3]-0}:{r:0,g:0,b:0}},SocialCalc.Popup.Types.List={},SocialCalc.Popup.Types.List.Create=function(e,t,o){var a=SocialCalc.Popup,l=(a.Types,a.Controls),r={type:e,value:"",display:"",data:{}};l[t]=r;var i=r.data;i.attribs=o||{};var n=document.getElementById(t);return n?(i.mainele=n,n.innerHTML='<input style="cursor:pointer;width:50px;font-size:smaller;" onfocus="this.blur();" onclick="SocialCalc.Popup.CClick(\''+t+'\');" value="">',void(i.options=[])):void alert("Missing element "+t)},SocialCalc.Popup.Types.List.SetValue=function(e,t,a){var l,r=SocialCalc.Popup,i=(r.Types,r.Controls),n=i[t].data;for(n.value=a,n.custom=!1,l=0;l<n.options.length;l++)if(o=n.options[l],!(o.a&&(o.a.skip||o.a.custom||o.a.cancel)||o.v!=n.value)){n.display=o.o;break}l==n.options.length&&(n.display="Custom",n.custom=!0),n.mainele&&n.mainele.firstChild&&(n.mainele.firstChild.value=n.display)},SocialCalc.Popup.Types.List.SetDisabled=function(e,t,o){var a=SocialCalc.Popup,l=(a.Types,a.Controls),r=l[t].data;r.disabled=o,r.mainele&&r.mainele.firstChild&&(r.mainele.firstChild.disabled=o)},SocialCalc.Popup.Types.List.GetValue=function(e,t){var o=SocialCalc.Popup,a=(o.Types,o.Controls),l=a[t].data;return l.value},SocialCalc.Popup.Types.List.Initialize=function(e,t,o){var a,l=SocialCalc.Popup,r=(l.Types,l.Controls),i=r[t].data;for(a in o.attribs)i.attribs[a]=o.attribs[a];i.options=o?o.options:[],o.value&&l.SetValue(t,o.value)},SocialCalc.Popup.Types.List.Reset=function(e){var t=SocialCalc.Popup,o=t.Types,a=t.Controls;t.Current.id&&a[t.Current.id].type==e&&(o[e].Hide(e,t.Current.id),t.Current.id=null)},SocialCalc.Popup.Types.List.Show=function(e,t){var o,a=SocialCalc.Popup,l=(a.Types,a.Controls),r=l[t].data,i="";r.popupele=a.CreatePopupDiv(t,r.attribs),r.custom?(i=SocialCalc.Popup.Types.List.MakeCustom(e,t),o=document.createElement("div"),o.innerHTML='<div style="cursor:default;padding:4px;background-color:#CCC;">'+i+"</div>",r.customele=o.firstChild.firstChild.childNodes[1],r.listdiv=null,r.contentele=o):(i=SocialCalc.Popup.Types.List.MakeList(e,t),o=document.createElement("div"),o.innerHTML='<div style="cursor:default;padding:4px;">'+i+"</div>",r.customele=null,r.listdiv=o.firstChild,r.contentele=o),r.mainele&&r.mainele.firstChild&&(r.mainele.firstChild.disabled=!0),r.popupele.appendChild(o),r.attribs.ensureWithin&&SocialCalc.Popup.EnsurePosition(t,r.attribs.ensureWithin)},SocialCalc.Popup.Types.List.MakeList=function(e,t){var o,a,l,r=SocialCalc.Popup,i=(r.Types,r.Controls),n=i[t].data,c='<table cellspacing="0" cellpadding="0"><tr>',s='<td style="vertical-align:top;">';for(c+=s,n.ncols=1,o=0;o<n.options.length;o++){if(a=n.options[o],a.a){if(a.a.newcol){c+="</td>"+s+" </td>"+s,n.ncols+=1;continue}if(a.a.skip){c+='<div style="font-size:x-small;white-space:nowrap;">'+a.o+"</div>";continue}}l=a.v!=n.value||a.a&&(a.a.custom||a.a.cancel)?"":"background-color:#DDF;",c+='<div style="font-size:x-small;white-space:nowrap;'+l+'" onclick="SocialCalc.Popup.Types.List.ItemClicked(\''+t+"','"+o+"');\" onmousemove=\"SocialCalc.Popup.Types.List.MouseMove('"+t+"',this);\">"+a.o+"</div>"}return c+="</td></tr></table>"},SocialCalc.Popup.Types.List.MakeCustom=function(e,t){var o=SocialCalc.Popup.LocalizeString,a=SocialCalc.Popup,l=(a.Types,a.Controls),r=l[t].data,i='style="font-size:smaller;"',n="",c=r.value;return c=SocialCalc.special_chars(c),n='<div style="white-space:nowrap;"><br><input id="customvalue" value="'+c+'"><br><br><input '+i+' type="button" value="'+o("OK")+'" onclick="SocialCalc.Popup.Types.List.CustomOK(\''+t+"');return false;\"><input "+i+' type="button" value="'+o("List")+'" onclick="SocialCalc.Popup.Types.List.CustomToList(\''+t+"');\"><input "+i+' type="button" value="'+o("Cancel")+'" onclick="SocialCalc.Popup.Close();"><br></div>'},SocialCalc.Popup.Types.List.ItemClicked=function(e,t){var o,a,l,r=SocialCalc.Popup,i=(r.Types,r.Controls),n=i[e].data,c=n.options[t].a;return c&&c.custom?(o=n.contentele,a=SocialCalc.Popup.Types.List.MakeCustom("List",e),l=document.createElement("div"),l.innerHTML='<div style="cursor:default;padding:4px;background-color:#CCC;">'+a+"</div>",n.customele=l.firstChild.firstChild.childNodes[1],n.listdiv=null,n.contentele=l,n.popupele.replaceChild(l,o),void(n.attribs.ensureWithin&&SocialCalc.Popup.EnsurePosition(e,n.attribs.ensureWithin))):c&&c.cancel?void SocialCalc.Popup.Close():(SocialCalc.Popup.SetValue(e,n.options[t].v),void SocialCalc.Popup.Close())},SocialCalc.Popup.Types.List.CustomToList=function(e){var t,o,a,l=SocialCalc.Popup,r=(l.Types,l.Controls),i=r[e].data;t=i.contentele,o=SocialCalc.Popup.Types.List.MakeList("List",e),a=document.createElement("div"),a.innerHTML='<div style="cursor:default;padding:4px;">'+o+"</div>",i.customele=null,i.listdiv=a.firstChild,i.contentele=a,i.popupele.replaceChild(a,t),i.attribs.ensureWithin&&SocialCalc.Popup.EnsurePosition(e,i.attribs.ensureWithin)},SocialCalc.Popup.Types.List.CustomOK=function(e){var t=SocialCalc.Popup,o=(t.Types,t.Controls),a=o[e].data;SocialCalc.Popup.SetValue(e,a.customele.value),SocialCalc.Popup.Close()},SocialCalc.Popup.Types.List.MouseMove=function(e,t){var o,a,l=SocialCalc.Popup,r=(l.Types,l.Controls),i=r[e].data,n=i.listdiv;if(n){var c=n.firstChild.firstChild.firstChild;for(o=0;o<i.ncols;o++)for(a=0;a<c.childNodes[2*o].childNodes.length;a++)c.childNodes[2*o].childNodes[a].style.backgroundColor="#FFF";t.style.backgroundColor="#DDF"}},SocialCalc.Popup.Types.List.Hide=function(e,t){var o=SocialCalc.Popup,a=(o.Types,o.Controls),l=a[t].data;o.DestroyPopupDiv(l.popupele,l.dragregistered),l.popupele=null,l.mainele&&l.mainele.firstChild&&(l.mainele.firstChild.disabled=!1)},SocialCalc.Popup.Types.List.Cancel=function(e,t){SocialCalc.Popup.Types.List.Hide(e,t)},SocialCalc.Popup.Types.ColorChooser={},SocialCalc.Popup.Types.ColorChooser.Create=function(e,t,o){var a=SocialCalc.Popup,l=(a.Types,a.Controls),r={type:e,value:"",display:"",data:{}};l[t]=r;var i=r.data;i.attribs=o||{};var n=i.attribs;i.value="";var c=document.getElementById(t);return c?(i.mainele=c,void(c.innerHTML='<div style="cursor:pointer;border:1px solid black;vertical-align:top;width:'+(n.sampleWidth||"15px")+";height:"+(n.sampleHeight||"15px")+';" onclick="SocialCalc.Popup.Types.ColorChooser.ControlClicked(\''+t+"');\"> </div>")):void alert("Missing element "+t)},SocialCalc.Popup.Types.ColorChooser.SetValue=function(e,t,o){var a,l,r=SocialCalc.Popup,i=(r.Types,r.Controls),n=i[t].data,c=n.attribs;n.value=o,n.custom=!1,n.mainele&&n.mainele.firstChild&&(n.value?(n.mainele.firstChild.style.backgroundColor=n.value,a=c.backgroundImage?"url("+r.imagePrefix+c.backgroundImage+")":"",l="center center"):(n.mainele.firstChild.style.backgroundColor="#FFF",c.backgroundImageDefault?(a="url("+r.imagePrefix+c.backgroundImageDefault+")",l="center center"):(a="url("+r.imagePrefix+"defaultcolor.gif)",l="left top")),n.mainele.firstChild.style.backgroundPosition=l,n.mainele.firstChild.style.backgroundImage=a)},SocialCalc.Popup.Types.ColorChooser.SetDisabled=function(e,t,o){var a=SocialCalc.Popup,l=(a.Types,a.Controls),r=l[t].data,i=r.attribs;r.disabled=o,r.mainele&&r.mainele.firstChild&&(o?(r.mainele.firstChild.style.backgroundColor="#DDD",i.backgroundImageDisabled?(img="url("+a.imagePrefix+i.backgroundImageDisabled+")",pos="center center"):(img="url("+a.imagePrefix+"defaultcolor.gif)",pos="left top"),r.mainele.firstChild.style.backgroundPosition=pos,r.mainele.firstChild.style.backgroundImage=img):a.SetValue(t,r.value))},SocialCalc.Popup.Types.ColorChooser.GetValue=function(e,t){var o=SocialCalc.Popup,a=(o.Types,o.Controls),l=a[t].data;return l.value},SocialCalc.Popup.Types.ColorChooser.Initialize=function(e,t,o){var a,l=SocialCalc.Popup,r=(l.Types,l.Controls),i=r[t].data;for(a in o.attribs)i.attribs[a]=o.attribs[a];o.value&&l.SetValue(t,o.value)},SocialCalc.Popup.Types.ColorChooser.Reset=function(e){var t=SocialCalc.Popup,o=t.Types,a=t.Controls;t.Current.id&&a[t.Current.id].type==e&&(o[e].Hide(e,t.Current.id),t.Current.id=null)},SocialCalc.Popup.Types.ColorChooser.Show=function(e,t){var o,a,l=SocialCalc.Popup,r=(l.Types,l.Controls),i=r[t].data,n="";i.oldvalue=i.value,i.popupele=l.CreatePopupDiv(t,i.attribs),i.custom?(n=SocialCalc.Popup.Types.ColorChooser.MakeCustom(e,t),o=document.createElement("div"),o.innerHTML='<div style="cursor:default;padding:4px;background-color:#CCC;">'+n+"</div>",i.customele=o.firstChild.firstChild.childNodes[2],i.contentele=o):(a=SocialCalc.Popup.Types.ColorChooser.CreateGrid(e,t),o=document.createElement("div"),o.style.padding="3px",o.style.backgroundColor="#CCC",o.appendChild(a),i.customele=null,i.contentele=o),i.popupele.appendChild(o),i.attribs.ensureWithin&&SocialCalc.Popup.EnsurePosition(t,i.attribs.ensureWithin)},SocialCalc.Popup.Types.ColorChooser.MakeCustom=function(e,t){var o=SocialCalc.Popup,a=(o.Types,o.Controls),l=a[t].data,r=o.LocalizeString,i='style="font-size:smaller;"',n="";return n='<div style="white-space:nowrap;"><br>#<input id="customvalue" style="width:75px;" value="'+l.value+'"><br><br><input '+i+' type="button" value="'+r("OK")+'" onclick="SocialCalc.Popup.Types.ColorChooser.CustomOK(\''+t+"');return false;\"><input "+i+' type="button" value="'+r("Grid")+'" onclick="SocialCalc.Popup.Types.ColorChooser.CustomToGrid(\''+t+"');\"><br></div>"},SocialCalc.Popup.Types.ColorChooser.ItemClicked=function(e,t){var o=SocialCalc.Popup,a=(o.Types,o.Controls);a[e].data;SocialCalc.Popup.Close()},SocialCalc.Popup.Types.ColorChooser.CustomToList=function(e){var t=SocialCalc.Popup,o=(t.Types,t.Controls);o[e].data},SocialCalc.Popup.Types.ColorChooser.CustomOK=function(e){var t=SocialCalc.Popup,o=(t.Types,t.Controls),a=o[e].data;t.SetValue(e,a.customele.value),t.Close()},SocialCalc.Popup.Types.ColorChooser.Hide=function(e,t){var o=SocialCalc.Popup,a=(o.Types,o.Controls),l=a[t].data;o.DestroyPopupDiv(l.popupele,l.dragregistered),l.popupele=null},SocialCalc.Popup.Types.ColorChooser.Cancel=function(e,t){var o=SocialCalc.Popup,a=(o.Types,o.Controls),l=a[t].data;o.SetValue(t,l.oldvalue),SocialCalc.Popup.Types.ColorChooser.Hide(e,t)},SocialCalc.Popup.Types.ColorChooser.CreateGrid=function(e,t){var o,a,l,r,i,n=SocialCalc.Popup,c=n.Types,s=n.Controls,d=n.LocalizeString,u=s[t].data;u.grid={};var p=u.grid,m=document.createElement("div");for(o=document.createElement("table"),o.cellSpacing=0,o.cellPadding=0,o.style.width="100px",p.table=o,o=document.createElement("tbody"),p.table.appendChild(o),p.tbody=o,a=0;16>a;a++){for(l=document.createElement("tr"),r=0;5>r;r++)i={},p[a+","+r]=i,o=document.createElement("td"),o.style.fontSize="1px",o.innerHTML=" ",o.style.height="10px",1>=r?(o.style.width="17px",o.style.borderRight="3px solid white"):(o.style.width="20px",o.style.backgroundRepeat="no-repeat"),l.appendChild(o),i.ele=o;p.tbody.appendChild(l)}return m.appendChild(p.table),o=document.createElement("div"),o.style.marginTop="3px",o.innerHTML='<table cellspacing="0" cellpadding="0"><tr><td style="width:17px;background-color:#FFF;background-image:url('+n.imagePrefix+'defaultcolor.gif);height:16px;font-size:10px;cursor:pointer;" title="'+d("Default")+'"> </td><td style="width:23px;height:16px;font-size:10px;text-align:center;cursor:pointer;" title="'+d("Custom")+'">#</td><td style="width:60px;height:16px;font-size:10px;text-align:center;cursor:pointer;">'+d("OK")+"</td></tr></table>",p.defaultbox=o.firstChild.firstChild.firstChild.childNodes[0],p.defaultbox.onclick=c.ColorChooser.DefaultClicked,p.custom=o.firstChild.firstChild.firstChild.childNodes[1],p.custom.onclick=c.ColorChooser.CustomClicked,p.msg=o.firstChild.firstChild.firstChild.childNodes[2],p.msg.onclick=c.ColorChooser.CloseOK,m.appendChild(o),p.table.onmousedown=c.ColorChooser.GridMouseDown,c.ColorChooser.DetermineColors(t),c.ColorChooser.SetColors(t),m},SocialCalc.Popup.Types.ColorChooser.gridToG=function(e,t,o){return e[t+","+o]},SocialCalc.Popup.Types.ColorChooser.DetermineColors=function(e){var t,o,a=SocialCalc.Popup,l=a.Types,r=l.ColorChooser,i=a.Controls,n=i[e].data,c=n.grid,s=a.splitRGB(n.value);for(t=2,o=16-Math.floor((s.r+16)/16),c["selectedrow"+t]=o,o=0;16>o;o++)r.gridToG(c,o,t).rgb=a.makeRGB(17*(15-o),0,0);for(t=3,o=16-Math.floor((s.g+16)/16),c["selectedrow"+t]=o,o=0;16>o;o++)r.gridToG(c,o,t).rgb=a.makeRGB(0,17*(15-o),0);for(t=4,o=16-Math.floor((s.b+16)/16),c["selectedrow"+t]=o,o=0;16>o;o++)r.gridToG(c,o,t).rgb=a.makeRGB(0,0,17*(15-o));for(t=1,o=0;16>o;o++)r.gridToG(c,o,t).rgb=a.makeRGB(17*(15-o),17*(15-o),17*(15-o));t=0;var d,u=[0,68,153,204,255],p=["400","310","420","440","442","340","040","042","032","044","024","004","204","314","402","414"];for(o=0;16>o;o++)d=p[o],r.gridToG(c,o,t).rgb="rgb("+u[d.charAt(0)-0]+","+u[d.charAt(1)-0]+","+u[d.charAt(2)-0]+")"},SocialCalc.Popup.Types.ColorChooser.SetColors=function(e){var t,o,a,l,r=SocialCalc.Popup,i=r.Types,n=i.ColorChooser,c=r.Controls,s=c[e].data,d=s.grid;for(t=0;16>t;t++)for(o=0;5>o;o++)a=n.gridToG(d,t,o),a.ele.style.backgroundColor=a.rgb,a.ele.title=r.RGBToHex(a.rgb),d["selectedrow"+o]==t?a.ele.style.backgroundImage="url("+r.imagePrefix+"chooserarrow.gif)":a.ele.style.backgroundImage="";r.SetValue(e,s.value),d.msg.style.backgroundColor=s.value,l=r.splitRGB(s.value||"rgb(255,255,255)"),l.r+l.g+l.b<220?d.msg.style.color="#FFF":d.msg.style.color="#000",s.value?(d.msg.style.backgroundImage="",d.msg.title=r.RGBToHex(s.value)):(d.msg.style.backgroundColor="#FFF",d.msg.style.backgroundImage="url("+r.imagePrefix+"defaultcolor.gif)",d.msg.title="Default")},SocialCalc.Popup.Types.ColorChooser.GridMouseDown=function(e){var t=e||window.event,o=SocialCalc.Popup,a=o.Types,l=a.ColorChooser,r=o.Controls,i=o.Current.id;if(i){var n=r[i].data,c=n.grid;switch(t.type){case"mousedown":c.mousedown=!0;break;case"mouseup":c.mousedown=!1;break;case"mousemove":if(!c.mousedown)return}var s=SocialCalc.GetElementPositionWithScroll(n.mainele),d=t.clientX-s.left,u=t.clientY-s.top,p=SocialCalc.GetElementPositionWithScroll(c.table);p.left-=s.left,p.top-=s.top;var m=Math.floor((u-p.top-2)/10);m=0>m?0:m;var h=Math.floor((d-p.left)/20);m=0>m?0:m>15?15:m,h=0>h?0:h>4?4:h;var C=l.gridToG(c,m,h).ele.style.backgroundColor,f=o.splitRGB(C),S=o.splitRGB(n.value);switch(h){case 2:n.value=o.makeRGB(f.r,S.g,S.b);break;case 3:n.value=o.makeRGB(S.r,f.g,S.b);break;case 4:n.value=o.makeRGB(S.r,S.g,f.b);break;case 0:case 1:n.value=C}l.DetermineColors(i),l.SetColors(i)}},SocialCalc.Popup.Types.ColorChooser.ControlClicked=function(e){var t=SocialCalc.Popup,o=t.Types,a=o.ColorChooser,l=(t.Controls,t.Current.id);return l&&e==l?void a.CloseOK():void t.CClick(e)},SocialCalc.Popup.Types.ColorChooser.DefaultClicked=function(e){var t=(e||window.event,SocialCalc.Popup),o=t.Types,a=(o.ColorChooser,t.Controls),l=t.Current.id;if(l){var r=a[l].data;r.value="",SocialCalc.Popup.SetValue(l,r.value),SocialCalc.Popup.Close()}},SocialCalc.Popup.Types.ColorChooser.CustomClicked=function(e){var t=(e||window.event,SocialCalc.Popup),o=t.Types,a=(o.ColorChooser,t.Controls),l=t.Current.id;if(l){var r,i,n,c=a[l].data;r=c.contentele,i=SocialCalc.Popup.Types.ColorChooser.MakeCustom("ColorChooser",l),n=document.createElement("div"),n.innerHTML='<div style="cursor:default;padding:4px;background-color:#CCC;">'+i+"</div>",c.customele=n.firstChild.firstChild.childNodes[2],c.contentele=n,c.popupele.replaceChild(n,r),c.customele.value=t.RGBToHex(c.value),c.attribs.ensureWithin&&SocialCalc.Popup.EnsurePosition(l,c.attribs.ensureWithin)}},SocialCalc.Popup.Types.ColorChooser.CustomToGrid=function(e){var t,o,a=SocialCalc.Popup,l=(a.Types,a.Controls),r=l[e].data;SocialCalc.Popup.SetValue(e,a.HexToRGB("#"+r.customele.value));var t,i,o;t=r.contentele,i=SocialCalc.Popup.Types.ColorChooser.CreateGrid("ColorChooser",e),o=document.createElement("div"),o.style.padding="3px",o.style.backgroundColor="#CCC",o.appendChild(i),r.customele=null,r.contentele=o,r.popupele.replaceChild(o,t),r.attribs.ensureWithin&&SocialCalc.Popup.EnsurePosition(e,r.attribs.ensureWithin)},SocialCalc.Popup.Types.ColorChooser.CustomOK=function(e){var t=SocialCalc.Popup,o=(t.Types,t.Controls),a=o[e].data;SocialCalc.Popup.SetValue(e,t.HexToRGB("#"+a.customele.value)),SocialCalc.Popup.Close()},SocialCalc.Popup.Types.ColorChooser.CloseOK=function(e){var t=(e||window.event,SocialCalc.Popup),o=t.Types,a=(o.ColorChooser,t.Controls),l=t.Current.id;if(l){var r=a[l].data;SocialCalc.Popup.SetValue(l,r.value),SocialCalc.Popup.Close()}};var SocialCalc;SocialCalc||(alert("Main SocialCalc code module needed"),SocialCalc={}),SocialCalc.TableEditor||alert("SocialCalc TableEditor code module needed"),SocialCalc.CurrentSpreadsheetControlObject=null,SocialCalc.SpreadsheetControl=function(e){var t=SocialCalc.Constants;this.parentNode=null,this.spreadsheetDiv=null,this.requestedHeight=0,this.requestedWidth=0,this.requestedSpaceBelow=0,this.height=0,this.width=0,this.viewheight=0,this.tabs=[],this.tabnums={},this.tabreplacements={},this.currentTab=-1,this.views={},this.sheet=null,this.context=null,this.editor=null,this.spreadsheetDiv=null,this.editorDiv=null,this.sortrange="",this.moverange="",this.idPrefix=e||"SocialCalc-",this.multipartBoundary="SocialCalcSpreadsheetControlSave",this.imagePrefix=t.defaultImagePrefix,this.toolbarbackground=t.SCToolbarbackground,this.tabbackground=t.SCTabbackground,this.tabselectedCSS=t.SCTabselectedCSS,this.tabplainCSS=t.SCTabplainCSS,this.toolbartext=t.SCToolbartext,this.formulabarheight=t.SCFormulabarheight,this.statuslineheight=t.SCStatuslineheight,this.statuslineCSS=t.SCStatuslineCSS,this.ExportCallback=null,this.sheet=new SocialCalc.Sheet,this.context=new SocialCalc.RenderContext(this.sheet),this.context.showGrid=!0,this.context.showRCHeaders=!0,this.editor=new SocialCalc.TableEditor(this.context),this.editor.StatusCallback.statusline={func:SocialCalc.SpreadsheetControlStatuslineCallback,params:{statuslineid:this.idPrefix+"statusline",recalcid1:this.idPrefix+"divider_recalc",recalcid2:this.idPrefix+"button_recalc"}},SocialCalc.CurrentSpreadsheetControlObject=this,this.editor.MoveECellCallback.movefrom=function(e){var t=SocialCalc.GetSpreadsheetControlObject();t.context.cursorsuffix="",e.range2.hasrange&&!e.cellhandles.noCursorSuffix&&(e.ecell.row==e.range2.top&&(e.ecell.col<e.range2.left||e.ecell.col>e.range2.right+1)&&(t.context.cursorsuffix="insertleft"),e.ecell.col==e.range2.left&&(e.ecell.row<e.range2.top||e.ecell.row>e.range2.bottom+1)&&(t.context.cursorsuffix="insertup"))},this.formulabuttons={formulafunctions:{image:"formuladialog.gif",tooltip:"Functions",command:SocialCalc.SpreadsheetControl.DoFunctionList},multilineinput:{image:"multilinedialog.gif",tooltip:"Multi-line Input Box",command:SocialCalc.SpreadsheetControl.DoMultiline},link:{image:"linkdialog.gif",tooltip:"Link Input Box",command:SocialCalc.SpreadsheetControl.DoLink},sum:{image:"sumdialog.gif",tooltip:"Auto Sum",command:SocialCalc.SpreadsheetControl.DoSum}},this.tabnums.edit=this.tabs.length,this.tabs.push({name:"edit",text:"Edit",html:' <div id="%id.edittools" class="default-display"> <span id="%id.undoredo"><img id="%id.button_undo" class="edit-button" src="%img.undo.gif"> <img id="%id.button_redo" class="edit-button" src="%img.redo.gif" > <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.copypaste"><img id="%id.button_copy" src="%img.copy.gif" class="edit-button"> <img id="%id.button_cut" src="%img.cut.gif" class="edit-button"> <img id="%id.button_paste" src="%img.paste.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.formats"><img id="%id.button_delete" src="%img.delete.gif" class="edit-button"> <img id="%id.button_pasteformats" src="%img.pasteformats.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.locktools"><img id="%id.button_lock" src="%img.lock.gif" class="edit-button"> <img id="%id.button_unlock" src="%img.unlock.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.fill"><img id="%id.button_filldown" src="%img.filldown.gif" class="edit-button"> <img id="%id.button_fillright" src="%img.fillright.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.move"><img id="%id.button_movefrom" src="%img.movefromoff.gif" class="edit-button"> <img id="%id.button_movepaste" src="%img.movepasteoff.gif" class="edit-button"> <img id="%id.button_moveinsert" src="%img.moveinsertoff.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.align"><img id="%id.button_alignleft" src="%img.alignleft.gif" class="edit-button"> <img id="%id.button_aligncenter" src="%img.aligncenter.gif" class="edit-button"> <img id="%id.button_alignright" src="%img.alignright.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.grid"><img id="%id.button_borderon" src="%img.borderson.gif" class="edit-button"> <img id="%id.button_borderoff" src="%img.bordersoff.gif" class="edit-button"> <img id="%id.button_swapcolors" src="%img.swapcolors.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.merge"><img id="%id.button_merge" src="%img.merge.gif" class="edit-button"> <img id="%id.button_unmerge" src="%img.unmerge.gif" class="edit-button"> <img src="%img.divider1.gif" class="edit-button"> </span> <span id="%id.insert"><img id="%id.button_insertrow" src="%img.insertrow.gif" class="edit-button"> <img id="%id.button_insertcol" src="%img.insertcol.gif" class="edit-button"> </span><span id="%id.delete"><img id="%id.button_deleterow" src="%img.deleterow.gif" class="edit-button"> <img id="%id.button_deletecol" src="%img.deletecol.gif" class="edit-button"> </span><span id="%id.hide"><img id="%id.button_hiderow" src="%img.hiderow.gif" class="edit-button"> <img id="%id.button_hidecol" src="%img.hidecol.gif" class="edit-button"> </span><span id="%id.recalctools"><img id="%id.divider_recalc" src="%img.divider1.gif" class="edit-button"> <img id="%id.button_recalc" src="%img.recalc.gif" class="edit-button"></span> </div>',
oncreate:null,onclick:null}),this.tabnums.settings=this.tabs.length,this.tabs.push({name:"settings",text:"Format",html:'<div id="%id.settingstools" class="default-hidden"> <div id="%id.sheetsettingstoolbar" class="default-hidden"> <table cellspacing="0" cellpadding="0"><tr><td> <div style="%tbt.">%loc!SHEET SETTINGS!:</div> </td></tr><tr><td> <input id="%id.settings-savesheet" type="button" value="%loc!Save!" onclick="SocialCalc.SettingsControlSave(\'sheet\');"> <input type="button" value="%loc!Cancel!" onclick="SocialCalc.SettingsControlSave(\'cancel\');"> <input type="button" value="%loc!Show Cell Settings!" onclick="SocialCalc.SpreadsheetControlSettingsSwitch(\'cell\');return false;"> </td></tr></table> </div> <div id="%id.cellsettingstoolbar" class="default-hidden"> <table cellspacing="0" cellpadding="0"><tr><td> <div style="%tbt.">%loc!CELL SETTINGS!: <span id="%id.settingsecell"> </span></div> </td></tr><tr><td> <input id="%id.settings-savecell" type="button" value="%loc!Save!" onclick="SocialCalc.SettingsControlSave(\'cell\');"> <input type="button" value="%loc!Cancel!" onclick="SocialCalc.SettingsControlSave(\'cancel\');"> <input type="button" value="%loc!Show Sheet Settings!" onclick="SocialCalc.SpreadsheetControlSettingsSwitch(\'sheet\');return false;"> </td></tr></table> </div></div>',view:"settings",onclick:function(e,t){SocialCalc.SettingsControls.idPrefix=e.idPrefix,SocialCalc.SettingControlReset();var o=e.sheet.EncodeSheetAttributes(),a=e.sheet.EncodeCellAttributes(e.editor.ecell.coord);SocialCalc.SettingsControlLoadPanel(e.views.settings.values.sheetspanel,o),SocialCalc.SettingsControlLoadPanel(e.views.settings.values.cellspanel,a),document.getElementById(e.idPrefix+"settingsecell").innerHTML=e.editor.ecell.coord,SocialCalc.SpreadsheetControlSettingsSwitch("cell"),e.views.settings.element.style.height=e.viewheight+"px",e.views.settings.element.firstChild.style.height=e.viewheight+"px";var l;l=e.editor.range.hasrange?SocialCalc.crToCoord(e.editor.range.left,e.editor.range.top)+":"+SocialCalc.crToCoord(e.editor.range.right,e.editor.range.bottom):e.editor.ecell.coord,document.getElementById(e.idPrefix+"settings-savecell").value=SocialCalc.LocalizeString("Save to")+": "+l},onclickFocus:!0}),this.views.settings={name:"settings",values:{},oncreate:function(e,t){var o=SocialCalc.Constants;t.values.sheetspanel={colorchooser:{id:e.idPrefix+"scolorchooser"},formatnumber:{setting:"numberformat",type:"PopupList",id:e.idPrefix+"formatnumber",initialdata:o.SCFormatNumberFormats},formattext:{setting:"textformat",type:"PopupList",id:e.idPrefix+"formattext",initialdata:o.SCFormatTextFormats},fontfamily:{setting:"fontfamily",type:"PopupList",id:e.idPrefix+"fontfamily",initialdata:o.SCFormatFontfamilies},fontlook:{setting:"fontlook",type:"PopupList",id:e.idPrefix+"fontlook",initialdata:o.SCFormatFontlook},fontsize:{setting:"fontsize",type:"PopupList",id:e.idPrefix+"fontsize",initialdata:o.SCFormatFontsizes},textalignhoriz:{setting:"textalignhoriz",type:"PopupList",id:e.idPrefix+"textalignhoriz",initialdata:o.SCFormatTextAlignhoriz},numberalignhoriz:{setting:"numberalignhoriz",type:"PopupList",id:e.idPrefix+"numberalignhoriz",initialdata:o.SCFormatNumberAlignhoriz},alignvert:{setting:"alignvert",type:"PopupList",id:e.idPrefix+"alignvert",initialdata:o.SCFormatAlignVertical},textcolor:{setting:"textcolor",type:"ColorChooser",id:e.idPrefix+"textcolor"},bgcolor:{setting:"bgcolor",type:"ColorChooser",id:e.idPrefix+"bgcolor"},padtop:{setting:"padtop",type:"PopupList",id:e.idPrefix+"padtop",initialdata:o.SCFormatPadsizes},padright:{setting:"padright",type:"PopupList",id:e.idPrefix+"padright",initialdata:o.SCFormatPadsizes},padbottom:{setting:"padbottom",type:"PopupList",id:e.idPrefix+"padbottom",initialdata:o.SCFormatPadsizes},padleft:{setting:"padleft",type:"PopupList",id:e.idPrefix+"padleft",initialdata:o.SCFormatPadsizes},colwidth:{setting:"colwidth",type:"PopupList",id:e.idPrefix+"colwidth",initialdata:o.SCFormatColwidth},recalc:{setting:"recalc",type:"PopupList",id:e.idPrefix+"recalc",initialdata:o.SCFormatRecalc},usermaxcol:{setting:"usermaxcol",type:"PopupList",id:e.idPrefix+"usermaxcol",initialdata:o.SCFormatUserMaxCol},usermaxrow:{setting:"usermaxrow",type:"PopupList",id:e.idPrefix+"usermaxrow",initialdata:o.SCFormatUserMaxRow}},t.values.cellspanel={name:"cell",colorchooser:{id:e.idPrefix+"scolorchooser"},cformatnumber:{setting:"numberformat",type:"PopupList",id:e.idPrefix+"cformatnumber",initialdata:o.SCFormatNumberFormats},cformattext:{setting:"textformat",type:"PopupList",id:e.idPrefix+"cformattext",initialdata:o.SCFormatTextFormats},cfontfamily:{setting:"fontfamily",type:"PopupList",id:e.idPrefix+"cfontfamily",initialdata:o.SCFormatFontfamilies},cfontlook:{setting:"fontlook",type:"PopupList",id:e.idPrefix+"cfontlook",initialdata:o.SCFormatFontlook},cfontsize:{setting:"fontsize",type:"PopupList",id:e.idPrefix+"cfontsize",initialdata:o.SCFormatFontsizes},calignhoriz:{setting:"alignhoriz",type:"PopupList",id:e.idPrefix+"calignhoriz",initialdata:o.SCFormatTextAlignhoriz},calignvert:{setting:"alignvert",type:"PopupList",id:e.idPrefix+"calignvert",initialdata:o.SCFormatAlignVertical},ctextcolor:{setting:"textcolor",type:"ColorChooser",id:e.idPrefix+"ctextcolor"},cbgcolor:{setting:"bgcolor",type:"ColorChooser",id:e.idPrefix+"cbgcolor"},cbt:{setting:"bt",type:"BorderSide",id:e.idPrefix+"cbt"},cbr:{setting:"br",type:"BorderSide",id:e.idPrefix+"cbr"},cbb:{setting:"bb",type:"BorderSide",id:e.idPrefix+"cbb"},cbl:{setting:"bl",type:"BorderSide",id:e.idPrefix+"cbl"},cpadtop:{setting:"padtop",type:"PopupList",id:e.idPrefix+"cpadtop",initialdata:o.SCFormatPadsizes},cpadright:{setting:"padright",type:"PopupList",id:e.idPrefix+"cpadright",initialdata:o.SCFormatPadsizes},cpadbottom:{setting:"padbottom",type:"PopupList",id:e.idPrefix+"cpadbottom",initialdata:o.SCFormatPadsizes},cpadleft:{setting:"padleft",type:"PopupList",id:e.idPrefix+"cpadleft",initialdata:o.SCFormatPadsizes}},SocialCalc.SettingsControlInitializePanel(t.values.sheetspanel),SocialCalc.SettingsControlInitializePanel(t.values.cellspanel)},replacements:{itemtitle:{regex:/\%itemtitle\./g,replacement:'style="padding:12px 10px 0px 10px;font-weight:bold;"'},sectiontitle:{regex:/\%sectiontitle\./g,replacement:'style="padding:16px 10px 0px 0px;font-weight:bold;vertical-align:top;font-size:small;color:#C00;"'},parttitle:{regex:/\%parttitle\./g,replacement:'style="font-weight:bold;font-size:x-small;padding:0px 0px 3px 0px;"'},itembody:{regex:/\%itembody\./g,replacement:'style="padding:12px 0px 0px 0px;vertical-align:top;font-size:small;"'},bodypart:{regex:/\%bodypart\./g,replacement:'style="padding:0px 10px 0px 0px;font-size:small;vertical-align:top;"'}},divStyle:"border:1px solid black;overflow:auto;",html:'<div id="%id.scolorchooser" style="display:none;position:absolute;z-index:20;"></div> <div id="sample-text-box"> <table cellspacing="0" cellpadding="0"><tr> <td id="sample-text"><div>%loc!This is a<br>sample!</div><div>-1234.5</div></td> </tr></table> </div><table cellspacing="0" cellpadding="0"> <tr><td class="v-top"><table id="%id.sheetsettingstable" class="default-hidden" cellspacing="0" cellpadding="0"><tr> <td %itemtitle.><br>%loc!Default Format!:</td> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Number!</div> <span id="%id.formatnumber"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Text!</div> <span id="%id.formattext"></span> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Default Alignment!:</td> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Text Horizontal!</div> <span id="%id.textalignhoriz"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Number Horizontal!</div> <span id="%id.numberalignhoriz"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Vertical!</div> <span id="%id.alignvert"></span> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Default Font!:</td> <td %itembody.> <table><tr> <td %bodypart.> <div %parttitle.>%loc!Family!</div> <span id="%id.fontfamily"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Bold & Italics!</div> <span id="%id.fontlook"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Size!</div> <span id="%id.fontsize"></span> </td> </tr><tr><td %bodypart.> <div %parttitle.>%loc!Color!</div> <div id="%id.textcolor"></div> </td> <td %bodypart.> <div %parttitle.>%loc!Background!</div> <div id="%id.bgcolor"></div> </td><td> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Default Padding!:</td> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Top!</div> <span id="%id.padtop"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Right!</div> <span id="%id.padright"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Bottom!</div> <span id="%id.padbottom"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Left!</div> <span id="%id.padleft"></span> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Default Column Width!:</td> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.> </div> <span id="%id.colwidth"></span> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Recalculation!:</td> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.> </div> <span id="%id.recalc"></span> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Dimensions!:</td> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Columns!</div> <span id="%id.usermaxcol"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Rows!</div> <span id="%id.usermaxrow"></span> </td> </tr></table> </td></tr></table><table id="%id.cellsettingstable" cellspacing="0" cellpadding="0"><tr> <td %itemtitle.><br>%loc!Format!:</td></tr><tr> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Number!</div> <span id="%id.cformatnumber"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Text!</div> <span id="%id.cformattext"></span> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Alignment!:</td></tr><tr> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Horizontal!</div> <span id="%id.calignhoriz"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Vertical!</div> <span id="%id.calignvert"></span> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Font!:</td></tr><tr> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Family!</div> <span id="%id.cfontfamily"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Bold & Italics!</div> <span id="%id.cfontlook"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Size!</div> <span id="%id.cfontsize"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Color!</div> <div id="%id.ctextcolor"></div> </td> <td %bodypart.> <div %parttitle.>%loc!Background!</div> <div id="%id.cbgcolor"></div> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Borders!:</td></tr><tr> <td %itembody.> <table cellspacing="0" cellpadding="0"> <tr><td %bodypart. colspan="3"><div %parttitle.>%loc!Top!</div></td> <td %bodypart. colspan="3"><div %parttitle.>%loc!Right!</div></td> <td %bodypart. colspan="3"><div %parttitle.>%loc!Bottom!</div></td> <td %bodypart. colspan="3"><div %parttitle.>%loc!Left!</div></td> </tr><tr> <td %bodypart.> <input id="%id.cbt-onoff-bcb" onclick="SocialCalc.SettingsControlOnchangeBorder(this);" type="checkbox"> </td> <td %bodypart.> <div id="%id.cbt-color"></div> </td> <td> </td> <td %bodypart.> <input id="%id.cbr-onoff-bcb" onclick="SocialCalc.SettingsControlOnchangeBorder(this);" type="checkbox"> </td> <td %bodypart.> <div id="%id.cbr-color"></div> </td> <td> </td> <td %bodypart.> <input id="%id.cbb-onoff-bcb" onclick="SocialCalc.SettingsControlOnchangeBorder(this);" type="checkbox"> </td> <td %bodypart.> <div id="%id.cbb-color"></div> </td> <td> </td> <td %bodypart.> <input id="%id.cbl-onoff-bcb" onclick="SocialCalc.SettingsControlOnchangeBorder(this);" type="checkbox"> </td> <td %bodypart.> <div id="%id.cbl-color"></div> </td> <td> </td> </tr></table> </td></tr><tr> <td %itemtitle.><br>%loc!Padding!:</td></tr><tr> <td %itembody.> <table cellspacing="0" cellpadding="0"><tr> <td %bodypart.> <div %parttitle.>%loc!Top!</div> <span id="%id.cpadtop"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Right!</div> <span id="%id.cpadright"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Bottom!</div> <span id="%id.cpadbottom"></span> </td> <td %bodypart.> <div %parttitle.>%loc!Left!</div> <span id="%id.cpadleft"></span> </td> </tr></table> </td></tr></table> </td></tr></table><br>'},this.tabnums.sort=this.tabs.length,this.tabs.push({name:"sort",text:"Sort",html:' <div id="%id.sorttools" class="default-hidden"> <table cellspacing="0" cellpadding="0"><tr> <td class="sort-range" colspan="3"> <div style="%tbt.">%loc!Set Cells To Sort!</div> <select id="%id.sortlist" size="1" onfocus="%s.CmdGotFocus(this);"><option selected>[select range]</option></select> <input type="button" value="%loc!OK!" onclick="%s.DoCmd(this, \'ok-setsort\');" style="font-size:x-small;"> </td> <td class="sort-setsort" colspan="2"> <div style="%tbt."> </div> <input type="button" id="%id.sortbutton" value="%loc!Sort Cells! A1:A1" onclick="%s.DoCmd(this, \'dosort\');" style="visibility:hidden;"> </td> </tr><tr><td class="v-top"> <div style="%tbt.">%loc!Major Sort!</div> <select id="%id.majorsort" size="1" onfocus="%s.CmdGotFocus(this);"></select> </td><td> <input type="radio" name="majorsort" id="%id.majorsortup" value="up" checked><span class="xsmall-white">%loc!Up!</span><br> <input type="radio" name="majorsort" id="%id.majorsortdown" value="down"><span class="xsmall-white">%loc!Down!</span> </td> <td class="v-top"> <div style="%tbt.">%loc!Minor Sort!</div> <select id="%id.minorsort" size="1" onfocus="%s.CmdGotFocus(this);"></select> </td><td> <input type="radio" name="minorsort" id="%id.minorsortup" value="up" checked><span class="xsmall-white">%loc!Up!</span><br> <input type="radio" name="minorsort" id="%id.minorsortdown" value="down"><span class="xsmall-white">%loc!Down!</span> </td> </td> <td class="v-top"> <div style="%tbt.">%loc!Last Sort!</div> <select id="%id.lastsort" size="1" onfocus="%s.CmdGotFocus(this);"></select> </td><td> <input type="radio" name="lastsort" id="%id.lastsortup" value="up" checked><span class="xsmall-white">%loc!Up!</span><br> <input type="radio" name="lastsort" id="%id.lastsortdown" value="down"><span class="xsmall-white">%loc!Down!</span> </td> </tr></table> </div>',onclick:SocialCalc.SpreadsheetControlSortOnclick}),this.editor.SettingsCallbacks.sort={save:SocialCalc.SpreadsheetControlSortSave,load:SocialCalc.SpreadsheetControlSortLoad},this.tabnums.audit=this.tabs.length,this.tabs.push({name:"audit",text:"Audit",html:'<div id="%id.audittools" class="default-hidden"> <div style="%tbt."> </div></div>',view:"audit",onclick:function(e,t){var o,a,l=SocialCalc.LocalizeString,r='<table cellspacing="0" cellpadding="0" style="margin-bottom:10px;"><tr><td style="font-size:small;padding:6px;"><b>'+l("Audit Trail This Session")+":</b><br><br>",i=e.sheet.changes.stack,n=e.sheet.changes.tos;for(o=0;o<i.length;o++)for(o==n+1&&(r+='<br></td></tr><tr><td style="font-size:small;background-color:#EEE;padding:6px;">'+l("UNDONE STEPS")+":<br>"),a=0;a<i[o].command.length;a++)r+=SocialCalc.special_chars(i[o].command[a])+"<br>";e.views.audit.element.innerHTML=r+"</td></tr></table>",SocialCalc.CmdGotFocus(!0)},onclickFocus:!0}),this.views.audit={name:"audit",divStyle:"border:1px solid black;overflow:auto;",html:"Audit Trail"},this.tabnums.comment=this.tabs.length,this.tabs.push({name:"comment",text:"Comment",html:'<div id="%id.commenttools" class="default-hidden"><table cellspacing="0" cellpadding="0"><tr><td class="v-top"><textarea id="%id.commenttext" id="comment-textarea" onfocus="%s.CmdGotFocus(this);"></textarea></td><td class="v-top"> <input type="button" value="%loc!Save!" onclick="%s.SpreadsheetControlCommentSet();" style="font-size:x-small;"></td></tr></table></div>',view:"sheet",onclick:SocialCalc.SpreadsheetControlCommentOnclick,onunclick:SocialCalc.SpreadsheetControlCommentOnunclick}),this.tabnums.names=this.tabs.length,this.tabs.push({name:"names",text:"Names",html:'<div id="%id.namestools" class="default-hidden"> <table cellspacing="0" cellpadding="0"><tr> <td id="names-existing" colspan="5"> <div style="%tbt.">%loc!Existing Names!</div> <select id="%id.nameslist" size="1" onchange="%s.SpreadsheetControlNamesChangedName();" onfocus="%s.CmdGotFocus(this);"><option selected>[New]</option></select> </td></tr><tr> <td id="names-name"> <div style="%tbt.">%loc!Name!</div> <input type="text" id="%id.namesname" onfocus="%s.CmdGotFocus(this);"> </td> <td id="names-description"> <div style="%tbt.">%loc!Description!</div> <input type="text" id="%id.namesdesc" onfocus="%s.CmdGotFocus(this);"> </td> <td id="names-value"> <div style="%tbt.">%loc!Value!</div> <input type="text" id="%id.namesvalue" onfocus="%s.CmdGotFocus(this);"> </td> <td id="names-set"> <div style="%tbt.">%loc!Set Value To!</div> <input type="button" id="%id.namesrangeproposal" value="A1" onclick="%s.SpreadsheetControlNamesSetValue();" style="font-size:x-small;"> </td> <td id="names-save"> <div style="%tbt."> </div> <input type="button" value="%loc!Save!" onclick="%s.SpreadsheetControlNamesSave();" <input type="button" value="%loc!Delete!" onclick="%s.SpreadsheetControlNamesDelete()""> </td> </tr></table></div>',view:"sheet",onclick:SocialCalc.SpreadsheetControlNamesOnclick,onunclick:SocialCalc.SpreadsheetControlNamesOnunclick}),this.tabnums.clipboard=this.tabs.length,this.tabs.push({name:"clipboard",text:"Clipboard",html:'<div id="%id.clipboardtools" class="default-hidden"> <table cellspacing="0" cellpadding="0"><tr> <td class="v-top"> <div style="%tbt."> </div> </td> </tr></table></div>',view:"clipboard",onclick:SocialCalc.SpreadsheetControlClipboardOnclick,onclickFocus:"clipboardtext"}),this.views.clipboard={name:"clipboard",divStyle:"overflow:auto;",html:' <div id="clipboard"><div class=""> <b>%loc!Display Clipboard in!:</b> <input type="radio" id="%id.clipboardformat-tab" name="%id.clipboardformat" checked onclick="%s.SpreadsheetControlClipboardFormat(\'tab\');"> %loc!Tab-delimited format! <input type="radio" id="%id.clipboardformat-csv" name="%id.clipboardformat" onclick="%s.SpreadsheetControlClipboardFormat(\'csv\');"> %loc!CSV format! <input type="radio" id="%id.clipboardformat-scsave" name="%id.clipboardformat" onclick="%s.SpreadsheetControlClipboardFormat(\'scsave\');"> %loc!SocialCalc-save format! </div> <input type="button" value="%loc!Load SocialCalc Clipboard With This!" style="font-size:x-small;" onclick="%s.SpreadsheetControlClipboardLoad();"> <input type="button" value="%loc!Clear SocialCalc Clipboard!" style="font-size:x-small;" onclick="%s.SpreadsheetControlClipboardClear();"> <br> <textarea id="%id.clipboardtext" onfocus="%s.CmdGotFocus(this);"></textarea> </div>'}},SocialCalc.SpreadsheetControl.prototype.InitializeSpreadsheetControl=function(e,t,o,a){return SocialCalc.InitializeSpreadsheetControl(this,e,t,o,a)},SocialCalc.SpreadsheetControl.prototype.DoOnResize=function(){return SocialCalc.DoOnResize(this)},SocialCalc.SpreadsheetControl.prototype.SizeSSDiv=function(){return SocialCalc.SizeSSDiv(this)},SocialCalc.SpreadsheetControl.prototype.ExecuteCommand=function(e,t){return SocialCalc.SpreadsheetControlExecuteCommand(this,e,t)},SocialCalc.SpreadsheetControl.prototype.CreateSheetHTML=function(){return SocialCalc.SpreadsheetControlCreateSheetHTML(this)},SocialCalc.SpreadsheetControl.prototype.CreateSpreadsheetSave=function(e){return SocialCalc.SpreadsheetControlCreateSpreadsheetSave(this,e)},SocialCalc.SpreadsheetControl.prototype.DecodeSpreadsheetSave=function(e){return SocialCalc.SpreadsheetControlDecodeSpreadsheetSave(this,e)},SocialCalc.SpreadsheetControl.prototype.CreateCellHTML=function(e){return SocialCalc.SpreadsheetControlCreateCellHTML(this,e)},SocialCalc.SpreadsheetControl.prototype.CreateCellHTMLSave=function(e){return SocialCalc.SpreadsheetControlCreateCellHTMLSave(this,e)},SocialCalc.SpreadsheetControl.prototype.ParseSheetSave=function(e){return this.sheet.ParseSheetSave(e)},SocialCalc.SpreadsheetControl.prototype.CreateSheetSave=function(){return this.sheet.CreateSheetSave()},SocialCalc.InitializeSpreadsheetControl=function(e,t,o,a,l){var r,i,n,c,s,d,u,p,m=(SocialCalc.Constants,SocialCalc.LocalizeString),h=SocialCalc.LocalizeSubstrings,C=e.tabs,f=e.views;for(e.requestedHeight=o,e.requestedWidth=a,e.requestedSpaceBelow=l,"string"==typeof t&&(t=document.getElementById(t)),null==t&&alert("SocialCalc.SpreadsheetControl not given parent node."),e.parentNode=t,e.spreadsheetDiv=document.createElement("div"),e.SizeSSDiv(),i=t.firstChild;null!=i;i=t.firstChild)t.removeChild(i);for(r='<div id="menu"><div id="settings-bar">',n=0;n<C.length;n++)r+=C[n].html;for(r+='</div><div id="menu-bar"><ul class="menubar-tabs">',n=0;n<C.length;n++)r+=' <li id="%id.'+C[n].name+'tab" onclick="%s.SetTab(this);">'+m(C[n].text)+"</li>";r+=" </ul></div></div>",e.currentTab=0;for(d in e.tabreplacements)r=r.replace(e.tabreplacements[d].regex,e.tabreplacements[d].replacement);r=r.replace(/\%s\./g,"SocialCalc."),r=r.replace(/\%id\./g,e.idPrefix),r=r.replace(/\%tbt\./g,e.toolbartext),r=r.replace(/\%img\./g,e.imagePrefix),r=h(r),e.spreadsheetDiv.innerHTML=r,t.appendChild(e.spreadsheetDiv),e.Buttons={button_undo:{tooltip:"Undo",command:"undo"},button_redo:{tooltip:"Redo",command:"redo"},button_copy:{tooltip:"Copy",command:"copy"},button_cut:{tooltip:"Cut",command:"cut"},button_paste:{tooltip:"Paste",command:"paste"},button_pasteformats:{tooltip:"Paste Formats",command:"pasteformats"},button_lock:{tooltip:"Lock",command:"lock"},button_unlock:{tooltip:"Unlock",command:"unlock"},button_delete:{tooltip:"Delete Contents",command:"delete"},button_filldown:{tooltip:"Fill Down",command:"filldown"},button_fillright:{tooltip:"Fill Right",command:"fillright"},button_movefrom:{tooltip:"Set/Clear Move From",command:"movefrom"},button_movepaste:{tooltip:"Move Paste",command:"movepaste"},button_moveinsert:{tooltip:"Move Insert",command:"moveinsert"},button_alignleft:{tooltip:"Align Left",command:"align-left"},button_aligncenter:{tooltip:"Align Center",command:"align-center"},button_alignright:{tooltip:"Align Right",command:"align-right"},button_borderon:{tooltip:"Borders On",command:"borderon"},button_borderoff:{tooltip:"Borders Off",command:"borderoff"},button_swapcolors:{tooltip:"Swap Colors",command:"swapcolors"},button_merge:{tooltip:"Merge Cells",command:"merge"},button_unmerge:{tooltip:"Unmerge Cells",command:"unmerge"},button_insertrow:{tooltip:"Insert Row",command:"insertrow"},button_insertcol:{tooltip:"Insert Column",command:"insertcol"},button_deleterow:{tooltip:"Delete Row",command:"deleterow"},button_deletecol:{tooltip:"Delete Column",command:"deletecol"},button_hiderow:{tooltip:"Hide Row",command:"hiderow"},button_hidecol:{tooltip:"Hide Column",command:"hidecol"},button_recalc:{tooltip:"Recalc",command:"recalc"}};for(u in e.Buttons)p=document.getElementById(e.idPrefix+u),p?(SocialCalc.TooltipRegister(p,m(e.Buttons[u].tooltip),{},e.spreadsheetDiv),SocialCalc.ButtonRegister(e.editor,p,{},{MouseDown:SocialCalc.DoButtonCmd,command:e.Buttons[u].command})):alert("Button "+(e.idPrefix+u)+" missing");e.formulabarDiv=document.createElement("div"),e.formulabarDiv.id="formula-bar",e.formulabarDiv.style.height=e.formulabarheight+"px",e.formulabarDiv.innerHTML='<input type="text" size="60" value=""> ',e.spreadsheetDiv.appendChild(e.formulabarDiv);new SocialCalc.InputBox(e.formulabarDiv.firstChild,e.editor);for(u in e.formulabuttons)p=document.createElement("img"),p.id=e.idPrefix+u,p.src=(e.formulabuttons[u].skipImagePrefix?"":e.imagePrefix)+e.formulabuttons[u].image,p.className="formula-buttons",SocialCalc.TooltipRegister(p,m(e.formulabuttons[u].tooltip),{},e.spreadsheetDiv),SocialCalc.ButtonRegister(e.editor,p,{},{MouseDown:e.formulabuttons[u].command,Disabled:function(){return e.editor.ECellReadonly()}}),e.formulabarDiv.appendChild(p);for(n=0;n<C.length;n++)C[n].oncreate&&C[n].oncreate(e,C[n].name);e.nonviewheight=e.statuslineheight+e.spreadsheetDiv.firstChild.offsetHeight+e.spreadsheetDiv.lastChild.offsetHeight,e.viewheight=e.height-e.nonviewheight,e.editorDiv=e.editor.CreateTableEditor(e.width,e.viewheight),e.spreadsheetDiv.appendChild(e.editorDiv);for(c in f){r=f[c].html;for(d in f[c].replacements)r=r.replace(f[c].replacements[d].regex,f[c].replacements[d].replacement);r=r.replace(/\%s\./g,"SocialCalc."),r=r.replace(/\%id\./g,e.idPrefix),r=r.replace(/\%tbt\./g,e.toolbartext),r=r.replace(/\%img\./g,e.imagePrefix),s=document.createElement("div"),SocialCalc.setStyles(s,f[c].divStyle),s.style.display="none",s.style.height=e.viewheight+"px",s.id=e.idPrefix+f[c].name+"view",r=h(r),s.innerHTML=r,e.spreadsheetDiv.appendChild(s),f[c].element=s,f[c].oncreate&&f[c].oncreate(e,f[c])}if(f.sheet={name:"sheet",element:e.editorDiv},e.statuslineDiv=document.createElement("div"),e.statuslineDiv.style.cssText=e.statuslineCSS,e.statuslineDiv.style.height=e.statuslineheight-(e.statuslineDiv.style.paddingTop.slice(0,-2)-0)-(e.statuslineDiv.style.paddingBottom.slice(0,-2)-0)+"px",e.statuslineDiv.id=e.idPrefix+"statusline",e.spreadsheetDiv.appendChild(e.statuslineDiv),e.spreadsheetDiv.addEventListener)e.spreadsheetDiv.addEventListener("mousedown",function(){SocialCalc.SetSpreadsheetControlObject(e)},!1),e.spreadsheetDiv.addEventListener("mouseover",function(){SocialCalc.SetSpreadsheetControlObject(e)},!1);else{if(!e.spreadsheetDiv.attachEvent)throw SocialCalc.Constants.s_BrowserNotSupported;e.spreadsheetDiv.attachEvent("onmousedown",function(){SocialCalc.SetSpreadsheetControlObject(e)}),e.spreadsheetDiv.attachEvent("onmouseover",function(){SocialCalc.SetSpreadsheetControlObject(e)})}},SocialCalc.LocalizeString=function(e){var t=SocialCalc.LocalizeStringList[e];return t||(t=SocialCalc.Constants["s_loc_"+e.toLowerCase().replace(/\s/g,"_").replace(/\W/g,"X")]||e,SocialCalc.LocalizeStringList[e]=t),t},SocialCalc.LocalizeStringList={},SocialCalc.LocalizeSubstrings=function(e){var t=SocialCalc.LocalizeString;return e.replace(/%(loc|ssc)!(.*?)!/g,function(e,o,a){return"ssc"==o?SocialCalc.Constants[a]||alert("Missing constant: "+a):t(a)})},SocialCalc.GetSpreadsheetControlObject=function(){var e=SocialCalc.CurrentSpreadsheetControlObject;return e?e:void 0},SocialCalc.SetSpreadsheetControlObject=function(e){SocialCalc.CurrentSpreadsheetControlObject=e,SocialCalc.Keyboard.focusTable&&e&&(SocialCalc.Keyboard.focusTable=e.editor)},SocialCalc.DoOnResize=function(e){var t,o=e.views,a=e.SizeSSDiv();if(a){for(vname in o)t=o[vname].element,t.style.height=e.height-e.nonviewheight+"px";e.editor.ResizeTableEditor(e.width,e.height-e.nonviewheight)}},SocialCalc.SizeSSDiv=function(e){var t,o,a,l,r,i=10,n=10;return a=!1,t=SocialCalc.GetViewportInfo(),o=SocialCalc.GetElementPosition(e.parentNode),o.bottom=0,o.right=0,l=e.parentNode.style,l.marginTop&&(o.top+=l.marginTop.slice(0,-2)-0),l.marginBottom&&(o.bottom+=l.marginBottom.slice(0,-2)-0),l.marginLeft&&(o.left+=l.marginLeft.slice(0,-2)-0),l.marginRight&&(o.right+=l.marginRight.slice(0,-2)-0),r=e.requestedHeight||t.height-(o.top+o.bottom+n)-(e.requestedSpaceBelow||0),e.height!=r&&(e.height=r,e.spreadsheetDiv.style.height=r+"px",a=!0),r=e.requestedWidth||t.width-(o.left+o.right+i)||700,e.width!=r&&(e.width=r,a=!0),e.spreadsheetDiv.style.position="relative",a},SocialCalc.SetTab=function(e){var t,o,a,l,r,i,n,c={},s={},d=SocialCalc.GetSpreadsheetControlObject(),u=d.tabs,p=d.views;if(t="string"==typeof e?e:e.id.slice(d.idPrefix.length,-3),d.editor.busy&&(!u[d.currentTab].view||"sheet"==u[d.currentTab].view))for(r=0;r<u.length;r++)if(u[r].name==t&&u[r].view&&"sheet"!=u[r].view)return;for(d.tabs[d.currentTab].onunclick&&d.tabs[d.currentTab].onunclick(d,d.tabs[d.currentTab].name),r=0;r<u.length;r++)o=u[r].name,c[o]=document.getElementById(d.idPrefix+o+"tab"),s[o]=document.getElementById(d.idPrefix+o+"tools"),o==t?(a=r,s[o].style.display="block",c[o].className="active"):(s[o].style.display="none",c[o].className="inactive");d.currentTab=a,u[a].onclick&&u[a].onclick(d,t);for(i in p)!u[a].view&&"sheet"==i||u[a].view==i?(p[i].element.style.display="block",l=i):p[i].element.style.display="none";u[a].onclickFocus?(n=u[a].onclickFocus,"string"==typeof n&&(n=document.getElementById(d.idPrefix+n),n.focus()),SocialCalc.CmdGotFocus(n)):SocialCalc.KeyboardFocus(),p[l].needsresize&&p[l].onresize&&(p[l].needsresize=!1,p[l].onresize(d,p[l])),"sheet"==l?(d.statuslineDiv.style.display="block",d.editor.ScheduleRender()):d.statuslineDiv.style.display="none"},SocialCalc.SpreadsheetControlStatuslineCallback=function(e,t,o,a){var l,r,i=document.getElementById(a.statuslineid);switch(i&&(i.innerHTML=e.GetStatuslineString(t,o,a)),t){case"cmdendnorender":case"calcfinished":case"doneposcalc":if(l=document.getElementById(a.recalcid1),r=document.getElementById(a.recalcid2),!l||!r)break;"yes"==e.context.sheetobj.attribs.needsrecalc?(l.style.display="inline",r.style.display="inline"):(l.style.display="none",r.style.display="none")}},SocialCalc.UpdateSortRangeProposal=function(e){var t=document.getElementById(SocialCalc.GetSpreadsheetControlObject().idPrefix+"sortlist");e.range.hasrange?t.options[0].text=SocialCalc.crToCoord(e.range.left,e.range.top)+":"+SocialCalc.crToCoord(e.range.right,e.range.bottom):t.options[0].text=SocialCalc.LocalizeString("[select range]")},SocialCalc.LoadColumnChoosers=function(e){var t,o,a,l,r,i,n,c=SocialCalc.LocalizeString;e.sortrange&&-1==e.sortrange.indexOf(":")?(o=SocialCalc.Formula.LookupName(e.sheet,e.sortrange||""),"range"==o.type?(a=o.value.match(/^(.*)\|(.*)\|$/),t=a[1]+":"+a[2]):t="A1:A1"):t=e.sortrange;var s=SocialCalc.ParseRange(t);i=document.getElementById(e.idPrefix+"majorsort"),n=i.selectedIndex,i.options.length=0,i.options[i.options.length]=new Option(c("[None]"),"");for(var l=s.cr1.col;l<=s.cr2.col;l++)r=SocialCalc.rcColname(l),i.options[i.options.length]=new Option(c("Column ")+r,r);i.selectedIndex=n>1&&n<=s.cr2.col-s.cr1.col+1?n:1,i=document.getElementById(e.idPrefix+"minorsort"),n=i.selectedIndex,i.options.length=0,i.options[i.options.length]=new Option(c("[None]"),"");for(var l=s.cr1.col;l<=s.cr2.col;l++)r=SocialCalc.rcColname(l),i.options[i.options.length]=new Option(r,r);i.selectedIndex=n>0&&n<=s.cr2.col-s.cr1.col+1?n:0,i=document.getElementById(e.idPrefix+"lastsort"),n=i.selectedIndex,i.options.length=0,i.options[i.options.length]=new Option(c("[None]"),"");for(var l=s.cr1.col;l<=s.cr2.col;l++)r=SocialCalc.rcColname(l),i.options[i.options.length]=new Option(r,r);i.selectedIndex=n>0&&n<=s.cr2.col-s.cr1.col+1?n:0},SocialCalc.CmdGotFocus=function(e){SocialCalc.Keyboard.passThru=e},SocialCalc.DoButtonCmd=function(e,t,o){
SocialCalc.DoCmd(o.element,o.functionobj.command)},SocialCalc.DoCmd=function(e,t){var o,a,l,r,i,n,c,s,d,u,p,m,h,C,f,S,g,v,b,y,w,x=SocialCalc.GetSpreadsheetControlObject(),F=x.editor;switch(t){case"undo":x.ExecuteCommand("undo","");break;case"redo":x.ExecuteCommand("redo","");break;case"fill-rowcolstuff":case"fill-text":for(l=t.substring(5),i=document.getElementById(x.idPrefix+l+"list"),i.length=0,r=0;r<SocialCalc.SpreadsheetCmdTable[l].length;r++)i.options[r]=new Option(SocialCalc.SpreadsheetCmdTable[l][r].t);t="changed-"+l;case"changed-rowcolstuff":case"changed-text":for(l=t.substring(8),i=document.getElementById(x.idPrefix+l+"list"),n=SocialCalc.SpreadsheetCmdTable.slists[SocialCalc.SpreadsheetCmdTable[l][i.selectedIndex].s],c=document.getElementById(x.idPrefix+l+"slist"),c.length=0,r=0;r<(n.length||0);r++)c.options[r]=new Option(n[r].t,n[r].s);return;case"ok-rowcolstuff":case"ok-text":l=t.substring(3),i=document.getElementById(x.idPrefix+l+"list"),c=document.getElementById(x.idPrefix+l+"slist"),o=SocialCalc.SpreadsheetCmdTable[l][i.selectedIndex].c,a=c[c.selectedIndex].value,SocialCalc.SpreadsheetControlExecuteCommand(e,o,a);break;case"ok-setsort":return p=document.getElementById(x.idPrefix+"sortlist"),0==p.selectedIndex?F.range.hasrange?x.sortrange=SocialCalc.crToCoord(F.range.left,F.range.top)+":"+SocialCalc.crToCoord(F.range.right,F.range.bottom):x.sortrange=F.ecell.coord+":"+F.ecell.coord:x.sortrange=p.options[p.selectedIndex].value,m=document.getElementById(x.idPrefix+"sortbutton"),m.value=SocialCalc.LocalizeString("Sort ")+x.sortrange,m.style.visibility="visible",SocialCalc.LoadColumnChoosers(x),e&&e.blur&&e.blur(),void SocialCalc.KeyboardFocus();case"dosort":if(x.sortrange&&-1==x.sortrange.indexOf(":")){if(C=SocialCalc.Formula.LookupName(x.sheet,x.sortrange||""),"range"!=C.type)return;f=C.value.match(/^(.*)\|(.*)\|$/),h=f[1]+":"+f[2]}else h=x.sortrange;if("A1:A1"==h)return;s="sort "+h+" ",d=document.getElementById(x.idPrefix+"majorsort"),u=document.getElementById(x.idPrefix+"majorsortup"),s+=d.options[d.selectedIndex].value+(u.checked?" up":" down"),d=document.getElementById(x.idPrefix+"minorsort"),d.selectedIndex>0&&(u=document.getElementById(x.idPrefix+"minorsortup"),s+=" "+d.options[d.selectedIndex].value+(u.checked?" up":" down")),d=document.getElementById(x.idPrefix+"lastsort"),d.selectedIndex>0&&(u=document.getElementById(x.idPrefix+"lastsortup"),s+=" "+d.options[d.selectedIndex].value+(u.checked?" up":" down")),x.ExecuteCommand(s,"");break;case"merge":o=SocialCalc.SpreadsheetCmdLookup[t]||"",a=SocialCalc.SpreadsheetCmdSLookup[t]||"",x.ExecuteCommand(o,a),F.range.hasrange&&(F.MoveECell(SocialCalc.crToCoord(F.range.left,F.range.top)),F.RangeRemove());break;case"movefrom":F.range2.hasrange?(x.context.cursorsuffix="",F.Range2Remove(),x.ExecuteCommand("redisplay","")):F.range.hasrange?(F.range2.top=F.range.top,F.range2.right=F.range.right,F.range2.bottom=F.range.bottom,F.range2.left=F.range.left,F.range2.hasrange=!0,F.MoveECell(SocialCalc.crToCoord(F.range.left,F.range.top))):(F.range2.top=F.ecell.row,F.range2.right=F.ecell.col,F.range2.bottom=F.ecell.row,F.range2.left=F.ecell.col,F.range2.hasrange=!0),s=F.range2.hasrange?"":"off",m=document.getElementById(x.idPrefix+"button_movefrom"),m.src=x.imagePrefix+"movefrom"+s+".gif",m=document.getElementById(x.idPrefix+"button_movepaste"),m.src=x.imagePrefix+"movepaste"+s+".gif",m=document.getElementById(x.idPrefix+"button_moveinsert"),m.src=x.imagePrefix+"moveinsert"+s+".gif",F.range2.hasrange&&F.RangeRemove();break;case"movepaste":case"moveinsert":F.range2.hasrange&&(x.context.cursorsuffix="",o=t+" "+SocialCalc.crToCoord(F.range2.left,F.range2.top)+":"+SocialCalc.crToCoord(F.range2.right,F.range2.bottom)+" "+F.ecell.coord,x.ExecuteCommand(o,""),F.Range2Remove(),m=document.getElementById(x.idPrefix+"button_movefrom"),m.src=x.imagePrefix+"movefromoff.gif",m=document.getElementById(x.idPrefix+"button_movepaste"),m.src=x.imagePrefix+"movepasteoff.gif",m=document.getElementById(x.idPrefix+"button_moveinsert"),m.src=x.imagePrefix+"moveinsertoff.gif");break;case"swapcolors":S=x.sheet,g=S.GetAssuredCell(F.ecell.coord),y=S.attribs.defaultcolor?S.colors[S.attribs.defaultcolor]:"rgb(0,0,0)",w=S.attribs.defaultbgcolor?S.colors[S.attribs.defaultbgcolor]:"rgb(255,255,255)",v=g.color?S.colors[g.color]:y,v==w&&(v=""),b=g.bgcolor?S.colors[g.bgcolor]:w,b==y&&(b=""),x.ExecuteCommand("set %C color "+b+"%Nset %C bgcolor "+v,"");break;default:o=SocialCalc.SpreadsheetCmdLookup[t]||"",a=SocialCalc.SpreadsheetCmdSLookup[t]||"",x.ExecuteCommand(o,a)}e&&e.blur&&e.blur(),SocialCalc.KeyboardFocus()},SocialCalc.SpreadsheetCmdLookup={copy:"copy %C all",cut:"cut %C all",paste:"paste %C all",pasteformats:"paste %C formats",lock:"set %C readonly yes",unlock:"set %C readonly no","delete":"erase %C formulas",filldown:"filldown %C all",fillright:"fillright %C all",erase:"erase %C all",borderon:"set %C bt %S%Nset %C br %S%Nset %C bb %S%Nset %C bl %S",borderoff:"set %C bt %S%Nset %C br %S%Nset %C bb %S%Nset %C bl %S",merge:"merge %C",unmerge:"unmerge %C","align-left":"set %C cellformat left","align-center":"set %C cellformat center","align-right":"set %C cellformat right","align-default":"set %C cellformat",insertrow:"insertrow %C",insertcol:"insertcol %C",deleterow:"deleterow %C",deletecol:"deletecol %C",hiderow:"set %H hide yes",hidecol:"set %W hide yes",undo:"undo",redo:"redo",recalc:"recalc"},SocialCalc.SpreadsheetCmdSLookup={borderon:"1px solid rgb(0,0,0)",borderoff:""},SocialCalc.SpreadsheetControlExecuteCommand=function(e,t,o){var a=SocialCalc.GetSpreadsheetControlObject(),l=a.editor,r={};r.P="%",r.N="\n",l.range.hasrange?(r.R=SocialCalc.crToCoord(l.range.left,l.range.top)+":"+SocialCalc.crToCoord(l.range.right,l.range.bottom),r.C=r.R,r.W=SocialCalc.rcColname(l.range.left)+":"+SocialCalc.rcColname(l.range.right),r.H=l.range.top+":"+l.range.bottom):(r.C=l.ecell.coord,r.R=l.ecell.coord+":"+l.ecell.coord,r.W=SocialCalc.rcColname(SocialCalc.coordToCr(l.ecell.coord).col),r.H=SocialCalc.coordToCr(l.ecell.coord).row),r.S=o,t=t.replace(/%C/g,r.C),t=t.replace(/%R/g,r.R),t=t.replace(/%N/g,r.N),t=t.replace(/%S/g,r.S),t=t.replace(/%W/g,r.W),t=t.replace(/%H/g,r.H),t=t.replace(/%P/g,r.P),l.EditorScheduleSheetCommands(t,!0,!1)},SocialCalc.SpreadsheetControlCreateSheetHTML=function(e){var t,o,a,l="";return t=new SocialCalc.RenderContext(e.sheet),o=document.createElement("div"),a=t.RenderSheet(null,{type:"html"}),o.appendChild(a),delete t,l=o.innerHTML,delete a,delete o,l},SocialCalc.SpreadsheetControlCreateCellHTML=function(e,t,o){var a="",l=e.sheet.cells[t];return l?(a=void 0==l.displaystring?SocialCalc.FormatValueForDisplay(e.sheet,l.datavalue,t,o||e.context.defaultHTMLlinkstyle):l.displaystring," "==a&&(a=""),a):""},SocialCalc.SpreadsheetControlCreateCellHTMLSave=function(e,t,o){var a,l,r,i,n,c,s,d,u=[];for(d=t?SocialCalc.ParseRange(t):{cr1:{row:1,col:1},cr2:{row:e.sheet.attribs.lastrow,col:e.sheet.attribs.lastcol}},a=d.cr1,l=d.cr2,u.push("version:1.0"),r=a.row;r<=l.row;r++)for(i=a.col;i<=l.col;i++)n=SocialCalc.crToCoord(i,r),c=e.sheet.cells[n],c&&(s=void 0==c.displaystring?SocialCalc.FormatValueForDisplay(e.sheet,c.datavalue,n,o||e.context.defaultHTMLlinkstyle):c.displaystring," "!=s&&u.push(n+":"+SocialCalc.encodeForSave(s)));return u.push(""),u.join("\n")},SocialCalc.SpreadsheetControl.DoFunctionList=function(){var e,t,o,a=SocialCalc.Formula,l=SocialCalc.Constants,r=l.function_classlist,i=SocialCalc.GetSpreadsheetControlObject(),n=i.idPrefix+"function";if(o=document.getElementById(n+"dialog"),!o){for(a.FillFunctionInfo(),t='<table><tr><td><span style="font-size:x-small;font-weight:bold">%loc!Category!</span><br><select id="'+n+'class" size="'+r.length+'" style="width:120px;" onchange="SocialCalc.SpreadsheetControl.FunctionClassChosen(this.options[this.selectedIndex].value);">',e=0;e<r.length;e++)t+='<option value="'+r[e]+'"'+(0==e?" selected>":">")+SocialCalc.special_chars(a.FunctionClasses[r[e]].name)+"</option>";t+='</select></td><td> </td><td id="'+n+'list"><span style="font-size:x-small;font-weight:bold">%loc!Functions!</span><br><select id="'+n+'name" size="'+r.length+'" style="width:240px;" onchange="SocialCalc.SpreadsheetControl.FunctionChosen(this.options[this.selectedIndex].value);" ondblclick="SocialCalc.SpreadsheetControl.DoFunctionPaste();">',t+=SocialCalc.SpreadsheetControl.GetFunctionNamesStr("all"),t+='</td></tr><tr><td colspan="3"><div id="'+n+'desc" style="width:380px;height:80px;overflow:auto;font-size:x-small;">'+SocialCalc.SpreadsheetControl.GetFunctionInfoStr(a.FunctionClasses[r[0]].items[0])+'</div><div style="width:380px;text-align:right;padding-top:6px;font-size:small;"><input type="button" value="%loc!Paste!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.DoFunctionPaste();"> <input type="button" value="%loc!Cancel!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.HideFunctions();"></div></td></tr></table>';var c=document.createElement("div");c.id=n+"dialog",c.style.position="absolute";var s=SocialCalc.GetViewportInfo(),d=SocialCalc.GetElementPositionWithScroll(i.spreadsheetDiv);c.style.top=s.height/3-d.top+"px",c.style.left=s.width/3-d.left+"px",c.style.zIndex=100,c.style.backgroundColor="#FFF",c.style.border="1px solid black",c.style.width="100%",t='<table cellspacing="0" cellpadding="0" style="border-bottom:1px solid black;"><tr><td style="font-size:10px;cursor:default;width:100%;background-color:#999;color:#FFF;"> %loc!Function List!</td><td style="font-size:10px;cursor:default;color:#666;" onclick="SocialCalc.SpreadsheetControl.HideFunctions();"> X </td></tr></table><div style="background-color:#DDD;">'+t+"</div>",t=SocialCalc.LocalizeSubstrings(t),c.innerHTML=t,SocialCalc.DragRegister(c.firstChild.firstChild.firstChild.firstChild,!0,!0,{MouseDown:SocialCalc.DragFunctionStart,MouseMove:SocialCalc.DragFunctionPosition,MouseUp:SocialCalc.DragFunctionPosition,Disabled:null,positionobj:c},i.spreadsheetDiv),i.spreadsheetDiv.appendChild(c),o=document.getElementById(n+"name"),o.focus(),SocialCalc.CmdGotFocus(o)}},SocialCalc.SpreadsheetControl.GetFunctionNamesStr=function(e){var t,o,a=SocialCalc.Formula,l="";for(o=a.FunctionClasses[e],t=0;t<o.items.length;t++)l+='<option value="'+o.items[t]+'"'+(0==t?" selected>":">")+o.items[t]+"</option>";return l},SocialCalc.SpreadsheetControl.FillFunctionNames=function(e,t){var o,a,l=SocialCalc.Formula;for(t.length=0,a=l.FunctionClasses[e],o=0;o<a.items.length;o++)t.options[o]=new Option(a.items[o],a.items[o]),0==o&&(t.options[o].selected=!0)},SocialCalc.SpreadsheetControl.GetFunctionInfoStr=function(e){var t=SocialCalc.Formula,o=t.FunctionList[e],a=SocialCalc.special_chars,l="<b>"+e+"("+a(t.FunctionArgString(e))+")</b><br>";return l+=a(o[3])},SocialCalc.SpreadsheetControl.FunctionClassChosen=function(e){var t=SocialCalc.GetSpreadsheetControlObject(),o=t.idPrefix+"function",a=SocialCalc.Formula;SocialCalc.SpreadsheetControl.FillFunctionNames(e,document.getElementById(o+"name")),SocialCalc.SpreadsheetControl.FunctionChosen(a.FunctionClasses[e].items[0])},SocialCalc.SpreadsheetControl.FunctionChosen=function(e){var t=SocialCalc.GetSpreadsheetControlObject(),o=t.idPrefix+"function";document.getElementById(o+"desc").innerHTML=SocialCalc.SpreadsheetControl.GetFunctionInfoStr(e)},SocialCalc.SpreadsheetControl.HideFunctions=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=document.getElementById(e.idPrefix+"functiondialog");t.innerHTML="",SocialCalc.DragUnregister(t),SocialCalc.KeyboardFocus(),t.parentNode&&t.parentNode.removeChild(t)},SocialCalc.SpreadsheetControl.DoFunctionPaste=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=e.editor,o=document.getElementById(e.idPrefix+"functionname"),a=document.getElementById(e.idPrefix+"multilinetextarea"),l=o.value+"(";SocialCalc.SpreadsheetControl.HideFunctions(),a?(a.value+=l,a.focus(),SocialCalc.CmdGotFocus(a)):t.EditorAddToInput(l,"=")},SocialCalc.SpreadsheetControl.DoMultiline=function(){var e,t,o,a=SocialCalc.LocalizeSubstrings,l=(SocialCalc.Constants,SocialCalc.GetSpreadsheetControlObject()),r=l.editor,i=r.workingvalues,l=SocialCalc.GetSpreadsheetControlObject(),n=l.idPrefix+"multiline";if(t=document.getElementById(n+"dialog"),!t){switch(r.state){case"start":i.ecoord=r.ecell.coord,i.erow=r.ecell.row,i.ecol=r.ecell.col,r.RangeRemove(),o=SocialCalc.GetCellContents(r.context.sheetobj,i.ecoord);break;case"input":case"inputboxdirect":o=r.inputBox.GetText()}r.inputBox.element.disabled=!0,o=SocialCalc.special_chars(o),e='<textarea id="'+n+'textarea" style="width:380px;height:120px;margin:10px 0px 0px 6px;">'+o+'</textarea><div style="width:380px;text-align:right;padding:6px 0px 4px 6px;font-size:small;">'+a('<input type="button" value="%loc!Set Cell Contents!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.DoMultilinePaste();"> <input type="button" value="%loc!Clear!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.DoMultilineClear();"> <input type="button" value="%loc!Cancel!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.HideMultiline();"></div></div>');var c=document.createElement("div");c.id=n+"dialog",c.style.position="absolute";var s=SocialCalc.GetViewportInfo(),d=SocialCalc.GetElementPositionWithScroll(l.spreadsheetDiv);c.style.top=s.height/3-d.top+"px",c.style.left=s.width/3-d.left+"px",c.style.zIndex=100,c.style.backgroundColor="#FFF",c.style.border="1px solid black",c.style.width="100%",c.innerHTML='<table cellspacing="0" cellpadding="0" style="border-bottom:1px solid black;"><tr><td style="font-size:10px;cursor:default;width:100%;background-color:#999;color:#FFF;">'+a(" %loc!Multi-line Input Box!")+'</td><td style="font-size:10px;cursor:default;color:#666;" onclick="SocialCalc.SpreadsheetControl.HideMultiline();"> X </td></tr></table><div style="background-color:#DDD;">'+e+"</div>",SocialCalc.DragRegister(c.firstChild.firstChild.firstChild.firstChild,!0,!0,{MouseDown:SocialCalc.DragFunctionStart,MouseMove:SocialCalc.DragFunctionPosition,MouseUp:SocialCalc.DragFunctionPosition,Disabled:null,positionobj:c},l.spreadsheetDiv),l.spreadsheetDiv.appendChild(c),t=document.getElementById(n+"textarea"),t.focus(),SocialCalc.CmdGotFocus(t)}},SocialCalc.SpreadsheetControl.HideMultiline=function(){var e=(SocialCalc.Constants,SocialCalc.GetSpreadsheetControlObject()),t=e.editor,o=document.getElementById(e.idPrefix+"multilinedialog");switch(o.innerHTML="",SocialCalc.DragUnregister(o),SocialCalc.KeyboardFocus(),o.parentNode&&o.parentNode.removeChild(o),t.state){case"start":t.inputBox.DisplayCellContents(null);break;case"input":case"inputboxdirect":t.inputBox.element.disabled=!1,t.inputBox.Focus()}},SocialCalc.SpreadsheetControl.DoMultilineClear=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=document.getElementById(e.idPrefix+"multilinetextarea");t.value="",t.focus()},SocialCalc.SpreadsheetControl.DoMultilinePaste=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=e.editor,o=t.workingvalues,a=document.getElementById(e.idPrefix+"multilinetextarea"),l=a.value;switch(SocialCalc.SpreadsheetControl.HideMultiline(),t.state){case"start":o.partialexpr="",o.ecoord=t.ecell.coord,o.erow=t.ecell.row,o.ecol=t.ecell.col;break;case"input":case"inputboxdirect":t.inputBox.Blur(),t.inputBox.ShowInputBox(!1),t.state="start"}t.EditorSaveEdit(l)},SocialCalc.SpreadsheetControl.DoLink=function(){var e,t,o,a,l,r,i=SocialCalc.LocalizeString,n=(SocialCalc.Constants,SocialCalc.GetSpreadsheetControlObject()),c=n.editor,s=c.workingvalues,n=SocialCalc.GetSpreadsheetControlObject(),d=n.idPrefix+"link";if(t=document.getElementById(d+"dialog"),!t){switch(c.state){case"start":s.ecoord=c.ecell.coord,s.erow=c.ecell.row,s.ecol=c.ecell.col,c.RangeRemove(),o=SocialCalc.GetCellContents(c.context.sheetobj,s.ecoord);break;case"input":case"inputboxdirect":o=c.inputBox.GetText()}c.inputBox.element.disabled=!0,"'"==o.charAt(0)&&(o=o.slice(1));var u=SocialCalc.ParseCellLinkText(o);o=SocialCalc.special_chars(o),a=n.sheet.cells[c.ecell.coord],l=a&&a.textvalueformat?"":" checked",r=u.newwin?" checked":"",e='<div style="padding:6px 0px 4px 6px;"><span style="font-size:smaller;">'+i("Description")+'</span><br><input type="text" id="'+d+'desc" style="width:380px;" value="'+SocialCalc.special_chars(u.desc)+'"><br><span style="font-size:smaller;">'+i("URL")+'</span><br><input type="text" id="'+d+'url" style="width:380px;" value="'+SocialCalc.special_chars(u.url)+'"><br>',SocialCalc.Callbacks.MakePageLink&&(e+='<span style="font-size:smaller;">'+i("Page Name")+'</span><br><input type="text" id="'+d+'pagename" style="width:380px;" value="'+SocialCalc.special_chars(u.pagename)+'"><br><span style="font-size:smaller;">'+i("Workspace")+'</span><br><input type="text" id="'+d+'workspace" style="width:380px;" value="'+SocialCalc.special_chars(u.workspace)+'"><br>'),e+=SocialCalc.LocalizeSubstrings('<input type="checkbox" id="'+d+'format"'+l+'> <span style="font-size:smaller;">%loc!Set to Link format!</span><br><input type="checkbox" id="'+d+'popup"'+r+'> <span style="font-size:smaller;">%loc!Show in new browser window!</span></div><div style="width:380px;text-align:right;padding:6px 0px 4px 6px;font-size:small;"><input type="button" value="%loc!Set Cell Contents!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.DoLinkPaste();"> <input type="button" value="%loc!Clear!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.DoLinkClear();"> <input type="button" value="%loc!Cancel!" style="font-size:smaller;" onclick="SocialCalc.SpreadsheetControl.HideLink();"></div></div>');var p=document.createElement("div");p.id=d+"dialog",p.style.position="absolute";var m=SocialCalc.GetViewportInfo(),h=SocialCalc.GetElementPositionWithScroll(n.spreadsheetDiv);p.style.top=m.height/3-h.top+"px",p.style.left=m.width/3-h.left+"px",p.style.zIndex=100,p.style.backgroundColor="#FFF",p.style.border="1px solid black",p.style.width="100%",p.innerHTML='<table cellspacing="0" cellpadding="0" style="border-bottom:1px solid black;"><tr><td style="font-size:10px;cursor:default;width:100%;background-color:#999;color:#FFF;"> '+i("Link Input Box")+'</td><td style="font-size:10px;cursor:default;color:#666;" onclick="SocialCalc.SpreadsheetControl.HideLink();"> X </td></tr></table><div style="background-color:#DDD;">'+e+"</div>",SocialCalc.DragRegister(p.firstChild.firstChild.firstChild.firstChild,!0,!0,{MouseDown:SocialCalc.DragFunctionStart,MouseMove:SocialCalc.DragFunctionPosition,MouseUp:SocialCalc.DragFunctionPosition,Disabled:null,positionobj:p},n.spreadsheetDiv),n.spreadsheetDiv.appendChild(p),t=document.getElementById(d+"url"),t.focus(),SocialCalc.CmdGotFocus(t)}},SocialCalc.SpreadsheetControl.HideLink=function(){var e=(SocialCalc.Constants,SocialCalc.GetSpreadsheetControlObject()),t=e.editor,o=document.getElementById(e.idPrefix+"linkdialog");switch(o.innerHTML="",SocialCalc.DragUnregister(o),SocialCalc.KeyboardFocus(),o.parentNode&&o.parentNode.removeChild(o),t.state){case"start":t.inputBox.DisplayCellContents(null);break;case"input":case"inputboxdirect":t.inputBox.element.disabled=!1,t.inputBox.Focus()}},SocialCalc.SpreadsheetControl.DoLinkClear=function(){var e=SocialCalc.GetSpreadsheetControlObject();document.getElementById(e.idPrefix+"linkdesc").value="",document.getElementById(e.idPrefix+"linkpagename").value="",document.getElementById(e.idPrefix+"linkworkspace").value="";var t=document.getElementById(e.idPrefix+"linkurl");t.value="",t.focus()},SocialCalc.SpreadsheetControl.DoLinkPaste=function(){var e,t,o,a,l=SocialCalc.GetSpreadsheetControlObject(),r=l.editor,i=r.workingvalues,n=document.getElementById(l.idPrefix+"linkdesc"),c=document.getElementById(l.idPrefix+"linkurl"),s=document.getElementById(l.idPrefix+"linkpagename"),d=document.getElementById(l.idPrefix+"linkworkspace"),u=document.getElementById(l.idPrefix+"linkformat"),p=document.getElementById(l.idPrefix+"linkpopup"),m="";switch(p.checked?(e="<<",t=">>",o="[[",a="]]"):(e="<",t=">",o="[",a="]"),m=s&&s.value?d.value?n.value+"{"+d.value+o+s.value+a+"}":n.value+o+s.value+a:n.value+e+c.value+t,SocialCalc.SpreadsheetControl.HideLink(),r.state){case"start":i.partialexpr="",i.ecoord=r.ecell.coord,i.erow=r.ecell.row,i.ecol=r.ecell.col;break;case"input":case"inputboxdirect":r.inputBox.Blur(),r.inputBox.ShowInputBox(!1),r.state="start"}u.checked&&SocialCalc.SpreadsheetControlExecuteCommand(null,"set %C textvalueformat text-link",""),r.EditorSaveEdit(m)},SocialCalc.SpreadsheetControl.DoSum=function(){var e,t,o,a,l,r,i,n=SocialCalc.GetSpreadsheetControlObject(),c=n.editor,s=c.context.sheetobj;if(c.range.hasrange)l=SocialCalc.crToCoord(c.range.left,c.range.top)+":"+SocialCalc.crToCoord(c.range.right,c.range.bottom),e="set "+SocialCalc.crToCoord(c.range.right,c.range.bottom+1)+" formula sum("+l+")";else if(o=c.ecell.row-1,a=c.ecell.col,1>=o)e="set "+c.ecell.coord+" constant e#REF! 0 #REF!";else{for(i=!1;o>0;){if(r=SocialCalc.crToCoord(a,o),t=s.GetAssuredCell(r),t.datatype&&"t"!=t.datatype)i=!0;else if(i){o++;break}o--}e="set "+c.ecell.coord+" formula sum("+SocialCalc.crToCoord(a,o)+":"+SocialCalc.crToCoord(a,c.ecell.row-1)+")"}c.EditorScheduleSheetCommands(e,!0,!1)},SocialCalc.SpreadsheetControlSortOnclick=function(e,t){var o,a,l=[],r=document.getElementById(e.idPrefix+"sortlist");SocialCalc.LoadColumnChoosers(e),e.editor.RangeChangeCallback.sort=SocialCalc.UpdateSortRangeProposal;for(o in e.sheet.names)l.push(o);for(l.sort(),r.length=0,r.options[0]=new Option(SocialCalc.LocalizeString("[select range]")),a=0;a<l.length;a++)o=l[a],r.options[a+1]=new Option(o,o),o==e.sortrange&&(r.options[a+1].selected=!0);""==e.sortrange&&(r.options[0].selected=!0),SocialCalc.UpdateSortRangeProposal(e.editor),SocialCalc.KeyboardFocus()},SocialCalc.SpreadsheetControlSortSave=function(e,t){var o,a,l,r=SocialCalc.GetSpreadsheetControlObject();return o="sort:"+SocialCalc.encodeForSave(r.sortrange)+":",a=document.getElementById(r.idPrefix+"majorsort"),l=document.getElementById(r.idPrefix+"majorsortup"),o+=a.selectedIndex+(l.checked?":up":":down"),a=document.getElementById(r.idPrefix+"minorsort"),a.selectedIndex>0?(l=document.getElementById(r.idPrefix+"minorsortup"),o+=":"+a.selectedIndex+(l.checked?":up":":down")):o+="::",a=document.getElementById(r.idPrefix+"lastsort"),a.selectedIndex>0?(l=document.getElementById(r.idPrefix+"lastsortup"),o+=":"+a.selectedIndex+(l.checked?":up":":down")):o+="::",o+"\n"},SocialCalc.SpreadsheetControlSortLoad=function(e,t,o,a){var l,r,i=SocialCalc.GetSpreadsheetControlObject();return l=o.split(":"),i.sortrange=SocialCalc.decodeFromSave(l[1]),r=document.getElementById(i.idPrefix+"sortbutton"),i.sortrange?(r.value=SocialCalc.LocalizeString("Sort ")+i.sortrange,r.style.visibility="visible"):r.style.visibility="hidden",SocialCalc.LoadColumnChoosers(i),sele=document.getElementById(i.idPrefix+"majorsort"),sele.selectedIndex=l[2]-0,document.getElementById(i.idPrefix+"majorsort"+l[3]).checked=!0,sele=document.getElementById(i.idPrefix+"minorsort"),l[4]?(sele.selectedIndex=l[4]-0,document.getElementById(i.idPrefix+"minorsort"+l[5]).checked=!0):(sele.selectedIndex=0,document.getElementById(i.idPrefix+"minorsortup").checked=!0),sele=document.getElementById(i.idPrefix+"lastsort"),l[6]?(sele.selectedIndex=l[6]-0,document.getElementById(i.idPrefix+"lastsort"+l[7]).checked=!0):(sele.selectedIndex=0,document.getElementById(i.idPrefix+"lastsortup").checked=!0),!0},SocialCalc.SpreadsheetControlCommentOnclick=function(e,t){e.editor.MoveECellCallback.comment=SocialCalc.SpreadsheetControlCommentMoveECell,SocialCalc.SpreadsheetControlCommentDisplay(e,t),SocialCalc.KeyboardFocus()},SocialCalc.SpreadsheetControlCommentDisplay=function(e,t){var o="";e.editor.ecell&&e.editor.ecell.coord&&e.sheet.cells[e.editor.ecell.coord]&&(o=e.sheet.cells[e.editor.ecell.coord].comment||""),document.getElementById(e.idPrefix+"commenttext").value=o},SocialCalc.SpreadsheetControlCommentMoveECell=function(e){SocialCalc.SpreadsheetControlCommentDisplay(SocialCalc.GetSpreadsheetControlObject(),"comment")},SocialCalc.SpreadsheetControlCommentSet=function(){var e=SocialCalc.GetSpreadsheetControlObject();e.ExecuteCommand("set %C comment "+SocialCalc.encodeForSave(document.getElementById(e.idPrefix+"commenttext").value));var t=SocialCalc.GetEditorCellElement(e.editor,e.editor.ecell.row,e.editor.ecell.col);e.editor.ECellReadonly()||(t.element.title=document.getElementById(e.idPrefix+"commenttext").value,e.editor.UpdateCellCSS(t,e.editor.ecell.row,e.editor.ecell.col)),SocialCalc.KeyboardFocus()},SocialCalc.SpreadsheetControlCommentOnunclick=function(e,t){delete e.editor.MoveECellCallback.comment},SocialCalc.SpreadsheetControlNamesOnclick=function(e,t){document.getElementById(e.idPrefix+"namesname").value="",document.getElementById(e.idPrefix+"namesdesc").value="",document.getElementById(e.idPrefix+"namesvalue").value="",e.editor.RangeChangeCallback.names=SocialCalc.SpreadsheetControlNamesRangeChange,e.editor.MoveECellCallback.names=SocialCalc.SpreadsheetControlNamesRangeChange,SocialCalc.SpreadsheetControlNamesRangeChange(e.editor),SocialCalc.SpreadsheetControlNamesFillNameList(),SocialCalc.SpreadsheetControlNamesChangedName()},SocialCalc.SpreadsheetControlNamesFillNameList=function(){var e,t,o=SocialCalc.LocalizeString,a=[],l=SocialCalc.GetSpreadsheetControlObject(),r=document.getElementById(l.idPrefix+"nameslist"),i=document.getElementById(l.idPrefix+"namesname").value.toUpperCase().replace(/[^A-Z0-9_\.]/g,"");for(e in l.sheet.names)a.push(e);for(a.sort(),r.length=0,a.length>0?r.options[0]=new Option(o("[New]")):r.options[0]=new Option(o("[None]")),t=0;t<a.length;t++)e=a[t],r.options[t+1]=new Option(e,e),e==i&&(r.options[t+1].selected=!0);""==i&&(r.options[0].selected=!0)},SocialCalc.SpreadsheetControlNamesChangedName=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=document.getElementById(e.idPrefix+"nameslist"),o=t.options[t.selectedIndex].value;e.sheet.names[o]?(document.getElementById(e.idPrefix+"namesname").value=o,document.getElementById(e.idPrefix+"namesdesc").value=e.sheet.names[o].desc||"",document.getElementById(e.idPrefix+"namesvalue").value=e.sheet.names[o].definition||""):(document.getElementById(e.idPrefix+"namesname").value="",document.getElementById(e.idPrefix+"namesdesc").value="",document.getElementById(e.idPrefix+"namesvalue").value="")},SocialCalc.SpreadsheetControlNamesRangeChange=function(e){var t=SocialCalc.GetSpreadsheetControlObject(),o=document.getElementById(t.idPrefix+"namesrangeproposal");e.range.hasrange?o.value=SocialCalc.crToCoord(e.range.left,e.range.top)+":"+SocialCalc.crToCoord(e.range.right,e.range.bottom):o.value=e.ecell.coord},SocialCalc.SpreadsheetControlNamesOnunclick=function(e,t){delete e.editor.RangeChangeCallback.names,delete e.editor.MoveECellCallback.names},SocialCalc.SpreadsheetControlNamesSetValue=function(){var e=SocialCalc.GetSpreadsheetControlObject();document.getElementById(e.idPrefix+"namesvalue").value=document.getElementById(e.idPrefix+"namesrangeproposal").value,SocialCalc.KeyboardFocus()},SocialCalc.SpreadsheetControlNamesSave=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=document.getElementById(e.idPrefix+"namesname").value;SocialCalc.SetTab(e.tabs[0].name),SocialCalc.KeyboardFocus(),""!=t&&e.ExecuteCommand("name define "+t+" "+document.getElementById(e.idPrefix+"namesvalue").value+"\nname desc "+t+" "+document.getElementById(e.idPrefix+"namesdesc").value)},SocialCalc.SpreadsheetControlNamesDelete=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=document.getElementById(e.idPrefix+"namesname").value;SocialCalc.SetTab(e.tabs[0].name),SocialCalc.KeyboardFocus(),""!=t&&e.ExecuteCommand("name delete "+t),SocialCalc.KeyboardFocus()},SocialCalc.SpreadsheetControlClipboardOnclick=function(e,t){var e=SocialCalc.GetSpreadsheetControlObject();clipele=document.getElementById(e.idPrefix+"clipboardtext"),document.getElementById(e.idPrefix+"clipboardformat-tab").checked=!0,clipele.value=SocialCalc.ConvertSaveToOtherFormat(SocialCalc.Clipboard.clipboard,"tab")},SocialCalc.SpreadsheetControlClipboardFormat=function(e){var t=SocialCalc.GetSpreadsheetControlObject();clipele=document.getElementById(t.idPrefix+"clipboardtext"),clipele.value=SocialCalc.ConvertSaveToOtherFormat(SocialCalc.Clipboard.clipboard,e)},SocialCalc.SpreadsheetControlClipboardLoad=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t="tab";SocialCalc.SetTab(e.tabs[0].name),SocialCalc.KeyboardFocus(),document.getElementById(e.idPrefix+"clipboardformat-csv").checked?t="csv":document.getElementById(e.idPrefix+"clipboardformat-scsave").checked&&(t="scsave"),e.editor.EditorScheduleSheetCommands("loadclipboard "+SocialCalc.encodeForSave(SocialCalc.ConvertOtherFormatToSave(document.getElementById(e.idPrefix+"clipboardtext").value,t)),!0,!1)},SocialCalc.SpreadsheetControlClipboardClear=function(){var e=SocialCalc.GetSpreadsheetControlObject(),t=document.getElementById(e.idPrefix+"clipboardtext");t.value="",e.editor.EditorScheduleSheetCommands("clearclipboard",!0,!1),t.focus()},SocialCalc.SpreadsheetControlClipboardExport=function(){var e=SocialCalc.GetSpreadsheetControlObject();e.ExportCallback&&e.ExportCallback(e),SocialCalc.SetTab(e.tabs[0].name),SocialCalc.KeyboardFocus()},SocialCalc.SpreadsheetControlSettingsSwitch=function(e){SocialCalc.SettingControlReset();var t=SocialCalc.GetSpreadsheetControlObject(),o=document.getElementById(t.idPrefix+"sheetsettingstable"),a=document.getElementById(t.idPrefix+"cellsettingstable"),l=document.getElementById(t.idPrefix+"sheetsettingstoolbar"),r=document.getElementById(t.idPrefix+"cellsettingstoolbar");"sheet"==e?(o.style.display="block",a.style.display="none",l.style.display="block",r.style.display="none",SocialCalc.SettingsControlSetCurrentPanel(t.views.settings.values.sheetspanel)):(o.style.display="none",a.style.display="block",l.style.display="none",r.style.display="block",SocialCalc.SettingsControlSetCurrentPanel(t.views.settings.values.cellspanel))},SocialCalc.SettingsControlSave=function(e){var t,o,a=SocialCalc.GetSpreadsheetControlObject(),l=SocialCalc.SettingsControls,r=l.CurrentPanel,i=SocialCalc.SettingsControlUnloadPanel(r);SocialCalc.SetTab(a.tabs[0].name),SocialCalc.KeyboardFocus(),"sheet"==e?o=a.sheet.DecodeSheetAttributes(i):"cell"==e&&(a.editor.range.hasrange&&(t=SocialCalc.crToCoord(a.editor.range.left,a.editor.range.top)+":"+SocialCalc.crToCoord(a.editor.range.right,a.editor.range.bottom)),o=a.sheet.DecodeCellAttributes(a.editor.ecell.coord,i,t)),o&&a.editor.EditorScheduleSheetCommands(o,!0,!1)},SocialCalc.SpreadsheetControlCreateSpreadsheetSave=function(e,t){var o,a,l,r="",i="";if(t)for(a in t)l="\n"!=t[a].charAt(t[a]-1)?"\n":"",r+="--"+e.multipartBoundary+"\nContent-type: text/plain; charset=UTF-8\n\n"+t[a]+l,i+="part:"+a+"\n";return o="socialcalc:version:1.0\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary="+e.multipartBoundary+"\n--"+e.multipartBoundary+"\nContent-type: text/plain; charset=UTF-8\n\n# SocialCalc Spreadsheet Control Save\nversion:1.0\npart:sheet\npart:edit\npart:audit\n"+i+"--"+e.multipartBoundary+"\nContent-type: text/plain; charset=UTF-8\n\n"+e.CreateSheetSave()+"--"+e.multipartBoundary+"\nContent-type: text/plain; charset=UTF-8\n\n"+e.editor.SaveEditorSettings()+"--"+e.multipartBoundary+"\nContent-type: text/plain; charset=UTF-8\n\n"+e.sheet.CreateAuditString()+r+"--"+e.multipartBoundary+"--\n"},SocialCalc.SpreadsheetControlDecodeSpreadsheetSave=function(e,t){var o,a,l,r,i,n,c,s,d,u,d,p,m={},h=[];if(o=t.search(/^MIME-Version:\s1\.0/im),0>o)return m;if(a=/^Content-Type:\s*multipart\/mixed;\s*boundary=(\S+)/gim,a.lastIndex=o,l=a.exec(t),a.lastIndex<=0)return m;if(r=l[1],i=new RegExp("^--"+r+"(?:\r\n|\n)","mg"),i.lastIndex=a.lastIndex,l=i.exec(t),n=/(?:\r\n|\n)(?:\r\n|\n)/gm,n.lastIndex=i.lastIndex,l=n.exec(t),!l)return m;if(c=n.lastIndex,i.lastIndex=c,l=i.exec(t),
!l)return m;for(s=l.index,d=t.substring(c,s).split(/\r\n|\n/),u=0;u<d.length;u++)switch(line=d[u],p=line.split(":"),p[0]){case"version":break;case"part":h.push(p[1])}for(pnum=0;pnum<h.length;pnum++){if(n.lastIndex=s,l=n.exec(t),!l)return m;if(c=n.lastIndex,pnum==h.length-1&&(i=new RegExp("^--"+r+"--$","mg")),i.lastIndex=c,l=i.exec(t),!l)return m;s=l.index,m[h[pnum]]={start:c,end:s}}return m},SocialCalc.SettingsControls={Controls:{},CurrentPanel:null},SocialCalc.SettingsControlSetCurrentPanel=function(e){SocialCalc.SettingsControls.CurrentPanel=e,SocialCalc.SettingsControls.PopupChangeCallback({panelobj:e},"",null)},SocialCalc.SettingsControlInitializePanel=function(e){var t,o=SocialCalc.SettingsControls;for(t in e)"name"!=t&&(ctrl=o.Controls[e[t].type],ctrl&&ctrl.Initialize&&ctrl.Initialize(e,t))},SocialCalc.SettingsControlLoadPanel=function(e,t){var o,a=SocialCalc.SettingsControls;for(o in e)"name"!=o&&(ctrl=a.Controls[e[o].type],ctrl&&ctrl.SetValue&&ctrl.SetValue(e,o,t[e[o].setting]))},SocialCalc.SettingsControlUnloadPanel=function(e){var t,o=SocialCalc.SettingsControls,a={};for(t in e)"name"!=t&&(ctrl=o.Controls[e[t].type],ctrl&&ctrl.GetValue&&(a[e[t].setting]=ctrl.GetValue(e,t)));return a},SocialCalc.SettingsControls.PopupChangeCallback=function(e,t,o){var a=SocialCalc.Constants,l=document.getElementById("sample-text");if(l&&e&&e.panelobj){var r,i,n,c,s,d=SocialCalc.CurrentSpreadsheetControlObject.idPrefix,u="cell"==e.panelobj.name?"c":"";n=a.defaultCellLayout.match(/^padding.(\S+) (\S+) (\S+) (\S+).vertical.align.(\S+);$/)||[];var p={color:["textcolor"],backgroundColor:["bgcolor","#FFF"],fontSize:["fontsize",a.defaultCellFontSize],fontFamily:["fontfamily"],paddingTop:["padtop",n[1]],paddingRight:["padright",n[2]],paddingBottom:["padbottom",n[3]],paddingLeft:["padleft",n[4]],verticalAlign:["alignvert",n[5]]};for(i in p)r=SocialCalc.Popup.GetValue(d+u+p[i][0])||p[i][1]||"",l.style[i]=r;if("c"==u){p={borderTop:"cbt",borderRight:"cbr",borderBottom:"cbb",borderLeft:"cbl"};for(i in p)r=SocialCalc.SettingsControls.BorderSideGetValue(e.panelobj,p[i]),l.style[i]=r?r.val||"":"";r=SocialCalc.Popup.GetValue(d+"calignhoriz"),l.style.textAlign=r||"left",l.childNodes[1].style.textAlign=r||"right"}else l.style.border="",r=SocialCalc.Popup.GetValue(d+"textalignhoriz"),l.style.textAlign=r||"left",r=SocialCalc.Popup.GetValue(d+"numberalignhoriz"),l.childNodes[1].style.textAlign=r||"right";r=SocialCalc.Popup.GetValue(d+u+"fontlook"),n=r?r.match(/^(\S+) (\S+)$/)||[]:[],l.style.fontStyle=n[1]||"",l.style.fontWeight=n[2]||"",r=SocialCalc.Popup.GetValue(d+u+"formatnumber")||"General",c=SocialCalc.FormatNumber.formatNumberWithFormat(9.8765,r,""),s=SocialCalc.FormatNumber.formatNumberWithFormat(-1234.5,r,""),"??-???-?? ??:??:??"!=s&&(c+="<br>"+s),l.childNodes[1].innerHTML=c}},SocialCalc.SettingsControls.PopupListSetValue=function(e,t,o){if(!o)return void alert(t+" no value");var a=SocialCalc.Popup;o.def?a.SetValue(e[t].id,""):a.SetValue(e[t].id,o.val)},SocialCalc.SettingsControls.PopupListGetValue=function(e,t){var o=e[t];if(!o)return null;var a=SocialCalc.Popup.GetValue(o.id);return a?{def:!1,val:a}:{def:!0,val:0}},SocialCalc.SettingsControls.PopupListInitialize=function(e,t){var o,a,l,r,i=SocialCalc.SettingsControls,n=e[t].initialdata||i.Controls[e[t].type].InitialData||"";n=SocialCalc.LocalizeSubstrings(n);var c=n.split(/\|/),s=[];for(o=0;o<(c.length||0);o++)a=c[o],l=a.indexOf(":"),r=a.substring(0,l),-1!=r.indexOf("\\")&&(r=r.replace(/\\c/g,":"),r=r.replace(/\\b/g,"\\")),r=SocialCalc.special_chars(r),"[custom]"==r?s[o]={o:SocialCalc.Constants.s_PopupListCustom,v:a.substring(l+1),a:{custom:!0}}:"[cancel]"==r?s[o]={o:SocialCalc.Constants.s_PopupListCancel,v:"",a:{cancel:!0}}:"[break]"==r?s[o]={o:"-----",v:"",a:{skip:!0}}:"[newcol]"==r?s[o]={o:"",v:"",a:{newcol:!0}}:s[o]={o:r,v:a.substring(l+1)};SocialCalc.Popup.Create("List",e[t].id,{}),SocialCalc.Popup.Initialize(e[t].id,{options:s,attribs:{changedcallback:SocialCalc.SettingsControls.PopupChangeCallback,panelobj:e}})},SocialCalc.SettingsControls.PopupListReset=function(e){SocialCalc.Popup.Reset("List")},SocialCalc.SettingsControls.Controls.PopupList={SetValue:SocialCalc.SettingsControls.PopupListSetValue,GetValue:SocialCalc.SettingsControls.PopupListGetValue,Initialize:SocialCalc.SettingsControls.PopupListInitialize,OnReset:SocialCalc.SettingsControls.PopupListReset,ChangedCallback:null},SocialCalc.SettingsControls.ColorChooserSetValue=function(e,t,o){if(!o)return void alert(t+" no value");var a=SocialCalc.Popup;o.def?a.SetValue(e[t].id,""):a.SetValue(e[t].id,o.val)},SocialCalc.SettingsControls.ColorChooserGetValue=function(e,t){var o=SocialCalc.Popup.GetValue(e[t].id);return o?{def:!1,val:o}:{def:!0,val:0}},SocialCalc.SettingsControls.ColorChooserInitialize=function(e,t){SocialCalc.SettingsControls;SocialCalc.Popup.Create("ColorChooser",e[t].id,{}),SocialCalc.Popup.Initialize(e[t].id,{attribs:{title:" ",moveable:!0,width:"106px",changedcallback:SocialCalc.SettingsControls.PopupChangeCallback,panelobj:e}})},SocialCalc.SettingsControls.ColorChooserReset=function(e){SocialCalc.Popup.Reset("ColorChooser")},SocialCalc.SettingsControls.Controls.ColorChooser={SetValue:SocialCalc.SettingsControls.ColorChooserSetValue,GetValue:SocialCalc.SettingsControls.ColorChooserGetValue,Initialize:SocialCalc.SettingsControls.ColorChooserInitialize,OnReset:SocialCalc.SettingsControls.ColorChooserReset,ChangedCallback:null},SocialCalc.SettingsControls.BorderSideSetValue=function(e,t,o){var a,l,r,i=(SocialCalc.SettingsControls,e[t].id);return o?(a=document.getElementById(i+"-onoff-bcb"),void(a&&(o.val?(a.checked=!0,a.value=o.val,r=o.val.match(/(\S+)\s+(\S+)\s+(\S.+)/),l=i+"-color",SocialCalc.Popup.SetValue(l,r[3]),SocialCalc.Popup.SetDisabled(l,!1)):(a.checked=!1,a.value=o.val,l=i+"-color",SocialCalc.Popup.SetValue(l,""),SocialCalc.Popup.SetDisabled(l,!0))))):void alert(t+" no value")},SocialCalc.SettingsControls.BorderSideGetValue=function(e,t){var o,a,l=(SocialCalc.SettingsControls,e[t].id);return(o=document.getElementById(l+"-onoff-bcb"))?o.checked?(a=SocialCalc.Popup.GetValue(l+"-color"),a="1px solid "+(a||"rgb(0,0,0)"),{def:!1,val:a}):{def:!1,val:""}:void 0},SocialCalc.SettingsControls.BorderSideInitialize=function(e,t){var o=(SocialCalc.SettingsControls,e[t].id);SocialCalc.Popup.Create("ColorChooser",o+"-color",{}),SocialCalc.Popup.Initialize(o+"-color",{attribs:{title:" ",width:"106px",moveable:!0,changedcallback:SocialCalc.SettingsControls.PopupChangeCallback,panelobj:e}})},SocialCalc.SettingsControlOnchangeBorder=function(e){var t=SocialCalc.SettingsControls,o=t.CurrentPanel,a=e.id.match(/(^.*\-)(\w+)\-(\w+)\-(\w+)$/);if(a){var l=(a[1],a[2]),r=(a[3],a[4]),i=o[l].type;switch(r){case"bcb":e.checked?t.Controls[i].SetValue(t.CurrentPanel,l,{def:!1,val:e.value||"1px solid rgb(0,0,0)"}):t.Controls[i].SetValue(t.CurrentPanel,l,{def:!1,val:""})}}},SocialCalc.SettingsControls.Controls.BorderSide={SetValue:SocialCalc.SettingsControls.BorderSideSetValue,GetValue:SocialCalc.SettingsControls.BorderSideGetValue,OnClick:SocialCalc.SettingsControls.ColorComboOnClick,Initialize:SocialCalc.SettingsControls.BorderSideInitialize,InitialData:{thickness:"1 pixel:1px",style:"Solid:solid"},ChangedCallback:null},SocialCalc.SettingControlReset=function(){var e,t=SocialCalc.SettingsControls;for(e in t.Controls)t.Controls[e].OnReset&&t.Controls[e].OnReset(e)},SocialCalc.OtherSaveParts={},SocialCalc.CtrlSEditor=function(e){var t,o;if(e.length>0)t=SocialCalc.special_chars(SocialCalc.OtherSaveParts[e]||"");else{t="Listing of Parts\n";for(o in SocialCalc.OtherSaveParts)t+=SocialCalc.special_chars("\nPart: "+o+"\n=====\n"+SocialCalc.OtherSaveParts[o]+"\n")}var a=document.createElement("div");a.style.cssText="position:absolute;z-index:500;width:300px;height:300px;left:100px;top:200px;border:1px solid black;background-color:#EEE;text-align:center;",a.id="socialcalc-editbox",a.innerHTML=e+'<br><br><textarea id="socialcalc-editbox-textarea" style="width:250px;height:200px;">'+t+"</textarea><br><br><input type=button onclick=\"SocialCalc.CtrlSEditorDone ('socialcalc-editbox', '"+e+'\');" value="OK">',document.body.appendChild(a);var l=document.getElementById("socialcalc-editbox-textarea");l.focus(),SocialCalc.CmdGotFocus(l)},SocialCalc.CtrlSEditorDone=function(e,t){var o=document.getElementById(e+"-textarea"),a=o.value;t.length>0&&(a.length>0?SocialCalc.OtherSaveParts[t]=a:delete SocialCalc.OtherSaveParts[t]);var l=document.getElementById(e);SocialCalc.KeyboardFocus(),l.parentNode.removeChild(l)};var SocialCalc;SocialCalc||(alert("Main SocialCalc code module needed"),SocialCalc={}),SocialCalc.TableEditor||alert("SocialCalc TableEditor code module needed"),SocialCalc.CurrentSpreadsheetViewerObject=null,SocialCalc.SpreadsheetViewer=function(e){var t=SocialCalc.Constants;this.parentNode=null,this.spreadsheetDiv=null,this.requestedHeight=0,this.requestedWidth=0,this.requestedSpaceBelow=0,this.height=0,this.width=0,this.viewheight=0,this.sheet=null,this.context=null,this.editor=null,this.spreadsheetDiv=null,this.editorDiv=null,this.sortrange="",this.idPrefix=e||"SocialCalc-",this.imagePrefix=t.defaultImagePrefix,this.statuslineheight=t.SVStatuslineheight,this.statuslineCSS=t.SVStatuslineCSS,this.sheet=new SocialCalc.Sheet,this.context=new SocialCalc.RenderContext(this.sheet),this.context.showGrid=!0,this.context.showRCHeaders=!0,this.editor=new SocialCalc.TableEditor(this.context),this.editor.noEdit=!0,this.editor.StatusCallback.statusline={func:SocialCalc.SpreadsheetViewerStatuslineCallback,params:{}},this.hasStatusLine=!0,this.statuslineHTML='<table cellspacing="0" cellpadding="0"><tr><td width="100%" style="overflow:hidden;">{status}</td><td> </td></tr></table>',this.statuslineFull=!0,this.noRecalc=!0,this.repeatingMacroTimer=null,this.repeatingMacroInterval=60,this.repeatingMacroCommands="",SocialCalc.CurrentSpreadsheetViewerObject=this},SocialCalc.SpreadsheetViewer.prototype.InitializeSpreadsheetViewer=function(e,t,o,a){return SocialCalc.InitializeSpreadsheetViewer(this,e,t,o,a)},SocialCalc.SpreadsheetViewer.prototype.LoadSave=function(e){return SocialCalc.SpreadsheetViewerLoadSave(this,e)},SocialCalc.SpreadsheetViewer.prototype.DoOnResize=function(){return SocialCalc.DoOnResize(this)},SocialCalc.SpreadsheetViewer.prototype.SizeSSDiv=function(){return SocialCalc.SizeSSDiv(this)},SocialCalc.SpreadsheetViewer.prototype.DecodeSpreadsheetSave=function(e){return SocialCalc.SpreadsheetViewerDecodeSpreadsheetSave(this,e)},SocialCalc.SpreadsheetViewer.prototype.ParseSheetSave=function(e){return this.sheet.ParseSheetSave(e)},SocialCalc.InitializeSpreadsheetViewer=function(e,t,o,a,l){var r;SocialCalc.Constants,SocialCalc.LocalizeString,SocialCalc.LocalizeSubstrings,e.tabs,e.views;for(e.requestedHeight=o,e.requestedWidth=a,e.requestedSpaceBelow=l,"string"==typeof t&&(t=document.getElementById(t)),null==t&&alert("SocialCalc.SpreadsheetControl not given parent node."),e.parentNode=t,e.spreadsheetDiv=document.createElement("div"),e.SizeSSDiv(),r=t.firstChild;null!=r;r=t.firstChild)t.removeChild(r);t.appendChild(e.spreadsheetDiv),e.nonviewheight=e.hasStatusLine?e.statuslineheight:0,e.viewheight=e.height-e.nonviewheight,e.editorDiv=e.editor.CreateTableEditor(e.width,e.viewheight),e.spreadsheetDiv.appendChild(e.editorDiv),e.hasStatusLine&&(e.statuslineDiv=document.createElement("div"),e.statuslineDiv.style.cssText=e.statuslineCSS,e.statuslineDiv.style.height=e.statuslineheight-(e.statuslineDiv.style.paddingTop.slice(0,-2)-0)-(e.statuslineDiv.style.paddingBottom.slice(0,-2)-0)+"px",e.statuslineDiv.id=e.idPrefix+"statusline",e.spreadsheetDiv.appendChild(e.statuslineDiv),e.editor.StatusCallback.statusline={func:SocialCalc.SpreadsheetViewerStatuslineCallback,params:{spreadsheetobj:e}})},SocialCalc.SpreadsheetViewerLoadSave=function(e,t){var o,a,l,r,i=e.DecodeSpreadsheetSave(t);i&&(i.sheet&&(e.sheet.ResetSheet(),e.sheet.ParseSheetSave(t.substring(i.sheet.start,i.sheet.end))),i.edit&&e.editor.LoadEditorSettings(t.substring(i.edit.start,i.edit.end)),i.startupmacro&&e.editor.EditorScheduleSheetCommands(t.substring(i.startupmacro.start,i.startupmacro.end),!1,!0),i.repeatingmacro&&(o=t.substring(i.repeatingmacro.start,i.repeatingmacro.end),o=o.replace("\r",""),a=o.indexOf("\n"),a>0&&(l=o.substring(0,a)-0,r=l,e.repeatingMacroInterval=l,e.repeatingMacroCommands=o.substring(a+1),r>0&&(e.repeatingMacroTimer=window.setTimeout(SocialCalc.SpreadsheetViewerDoRepeatingMacro,1e3*e.repeatingMacroInterval))))),"off"==e.editor.context.sheetobj.attribs.recalc||e.noRecalc?e.editor.ScheduleRender():e.editor.EditorScheduleSheetCommands("recalc")},SocialCalc.SpreadsheetViewerDoRepeatingMacro=function(){var e=SocialCalc.GetSpreadsheetViewerObject(),t=e.editor;e.repeatingMacroTimer=null,SocialCalc.SheetCommandInfo.CmdExtensionCallbacks.repeatmacro={func:SocialCalc.SpreadsheetViewerRepeatMacroCommand,data:null},t.EditorScheduleSheetCommands(e.repeatingMacroCommands)},SocialCalc.SpreadsheetViewerRepeatMacroCommand=function(e,t,o,a,l){var r=SocialCalc.GetSpreadsheetViewerObject(),i=a.RestOfString(),n=i-0;n>0||(n=r.repeatingMacroInterval),r.repeatingMacroInterval=n,r.repeatingMacroTimer=window.setTimeout(SocialCalc.SpreadsheetViewerDoRepeatingMacro,1e3*r.repeatingMacroInterval)},SocialCalc.SpreadsheetViewerStopRepeatingMacro=function(){var e=SocialCalc.GetSpreadsheetViewerObject();e.repeatingMacroTimer&&(window.clearTimeout(e.repeatingMacroTimer),e.repeatingMacroTimer=null)},SocialCalc.SpreadsheetViewerDoButtonCmd=function(e,t,o){var a=o.element,l=o.functionobj.command,r=SocialCalc.GetSpreadsheetViewerObject(),i=r.editor;switch(l){case"recalc":i.EditorScheduleSheetCommands("recalc")}a&&a.blur&&a.blur(),SocialCalc.KeyboardFocus()},SocialCalc.LocalizeString=function(e){var t=SocialCalc.LocalizeStringList[e];return t||(t=SocialCalc.Constants["s_loc_"+e.toLowerCase().replace(/\s/g,"_").replace(/\W/g,"X")]||e,SocialCalc.LocalizeStringList[e]=t),t},SocialCalc.LocalizeStringList={},SocialCalc.LocalizeSubstrings=function(e){var t=SocialCalc.LocalizeString;return e.replace(/%(loc|ssc)!(.*?)!/g,function(e,o,a){return"ssc"==o?SocialCalc.Constants[a]||alert("Missing constant: "+a):t(a)})},SocialCalc.GetSpreadsheetViewerObject=function(){var e=SocialCalc.CurrentSpreadsheetViewerObject;if(e)return e;throw"No current SpreadsheetViewer object."},SocialCalc.DoOnResize=function(e){var t,o=e.views,a=e.SizeSSDiv();if(a){for(vname in o)t=o[vname].element,t.style.width=e.width+"px",t.style.height=e.height-e.nonviewheight+"px";e.editor.ResizeTableEditor(e.width,e.height-e.nonviewheight)}},SocialCalc.SizeSSDiv=function(e){var t,o,a,l,r,i=10,n=10;return a=!1,t=SocialCalc.GetViewportInfo(),o=SocialCalc.GetElementPosition(e.parentNode),o.bottom=0,o.right=0,l=e.parentNode.style,l.marginTop&&(o.top+=l.marginTop.slice(0,-2)-0),l.marginBottom&&(o.bottom+=l.marginBottom.slice(0,-2)-0),l.marginLeft&&(o.left+=l.marginLeft.slice(0,-2)-0),l.marginRight&&(o.right+=l.marginRight.slice(0,-2)-0),r=e.requestedHeight||t.height-(o.top+o.bottom+n)-(e.requestedSpaceBelow||0),e.height!=r&&(e.height=r,e.spreadsheetDiv.style.height=r+"px",a=!0),r=e.requestedWidth||t.width-(o.left+o.right+i)||700,e.width!=r&&(e.width=r,e.spreadsheetDiv.style.width=r+"px",a=!0),e.spreadsheetDiv.style.position="relative",a},SocialCalc.SpreadsheetViewerStatuslineCallback=function(e,t,o,a){var l=a.spreadsheetobj,r="";switch(l&&l.statuslineDiv&&(r=l.statuslineFull?e.GetStatuslineString(t,o,a):e.ecell.coord,r=l.statuslineHTML.replace(/\{status\}/,r),l.statuslineDiv.innerHTML=r),t){case"cmdendnorender":case"calcfinished":case"doneposcalc":}},SocialCalc.CmdGotFocus=function(e){SocialCalc.Keyboard.passThru=e},SocialCalc.SpreadsheetViewerCreateSheetHTML=function(e){var t,o,a,l="";return t=new SocialCalc.RenderContext(e.sheet),o=document.createElement("div"),a=t.RenderSheet(null,{type:"html"}),o.appendChild(a),delete t,l=o.innerHTML,delete a,delete o,l},SocialCalc.SpreadsheetViewerDecodeSpreadsheetSave=function(e,t){var o,a,l,r,i,n,c,s,d,u,d,p,m={},h=[],C=/[^\n]\r[^\n]/;if(C.test(t)&&(t=t.replace(/([^\n])\r([^\n])/g,"$1\r\n$2")),o=t.search(/^MIME-Version:\s1\.0/im),0>o)return m;if(a=/^Content-Type:\s*multipart\/mixed;\s*boundary=(\S+)/gim,a.lastIndex=o,l=a.exec(t),a.lastIndex<=0)return m;if(r=l[1],i=new RegExp("^--"+r+"(?:\r\n|\n)","mg"),i.lastIndex=a.lastIndex,l=i.exec(t),n=/(?:\r\n|\n)(?:\r\n|\n)/gm,n.lastIndex=i.lastIndex,l=n.exec(t),!l)return m;if(c=n.lastIndex,i.lastIndex=c,l=i.exec(t),!l)return m;for(s=l.index,d=t.substring(c,s).split(/\r\n|\n/),u=0;u<d.length;u++)switch(line=d[u],p=line.split(":"),p[0]){case"version":break;case"part":h.push(p[1])}for(pnum=0;pnum<h.length;pnum++){if(n.lastIndex=s,l=n.exec(t),!l)return m;if(c=n.lastIndex,pnum==h.length-1&&(i=new RegExp("^--"+r+"--$","mg")),i.lastIndex=c,l=i.exec(t),!l)return m;s=l.index,m[h[pnum]]={start:c,end:s}}return m};