forked from electricg/sharejs-server
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bcsocket.js
313 lines (292 loc) · 81.4 KB
/
bcsocket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
(function(){
var f,aa=aa||{},k=this;function ba(a){a=a.split(".");for(var b=k,c;c=a.shift();)if(null!=b[c])b=b[c];else return null;return b}function ca(){}
function da(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function m(a){return"array"==da(a)}function ea(a){var b=da(a);return"array"==b||"object"==b&&"number"==typeof a.length}function n(a){return"string"==typeof a}function fa(a){return"function"==da(a)}var ga="closure_uid_"+(1E9*Math.random()>>>0),ha=0;function ia(a,b,c){return a.call.apply(a.bind,arguments)}
function ja(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function p(a,b,c){p=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?ia:ja;return p.apply(null,arguments)}var q=Date.now||function(){return+new Date};
function r(a,b){function c(){}c.prototype=b.prototype;a.pa=b.prototype;a.prototype=new c;a.Ic=function(a,c,g){return b.prototype[c].apply(a,Array.prototype.slice.call(arguments,2))}};function ka(a,b){for(var c=a.split("%s"),d="",e=Array.prototype.slice.call(arguments,1);e.length&&1<c.length;)d+=c.shift()+e.shift();return d+c.join("%s")}function la(a){if(!ma.test(a))return a;-1!=a.indexOf("&")&&(a=a.replace(na,"&"));-1!=a.indexOf("<")&&(a=a.replace(oa,"<"));-1!=a.indexOf(">")&&(a=a.replace(pa,">"));-1!=a.indexOf('"')&&(a=a.replace(qa,"""));-1!=a.indexOf("'")&&(a=a.replace(ra,"'"));return a}var na=/&/g,oa=/</g,pa=/>/g,qa=/"/g,ra=/'/g,ma=/[&<>"']/;
function sa(){return Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^q()).toString(36)}function ta(a,b){return a<b?-1:a>b?1:0};var w,ua,va,wa;function xa(){return k.navigator?k.navigator.userAgent:null}wa=va=ua=w=!1;var ya;if(ya=xa()){var za=k.navigator;w=0==ya.lastIndexOf("Opera",0);ua=!w&&(-1!=ya.indexOf("MSIE")||-1!=ya.indexOf("Trident"));va=!w&&-1!=ya.indexOf("WebKit");wa=!w&&!va&&!ua&&"Gecko"==za.product}var Aa=w,x=ua,Ba=wa,y=va;function Ca(){var a=k.document;return a?a.documentMode:void 0}var Da;
a:{var Ea="",Fa;if(Aa&&k.opera)var Ga=k.opera.version,Ea="function"==typeof Ga?Ga():Ga;else if(Ba?Fa=/rv\:([^\);]+)(\)|;)/:x?Fa=/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/:y&&(Fa=/WebKit\/(\S+)/),Fa)var Ha=Fa.exec(xa()),Ea=Ha?Ha[1]:"";if(x){var Ia=Ca();if(Ia>parseFloat(Ea)){Da=String(Ia);break a}}Da=Ea}var Ja={};
function z(a){var b;if(!(b=Ja[a])){b=0;for(var c=String(Da).replace(/^[\s\xa0]+|[\s\xa0]+$/g,"").split("."),d=String(a).replace(/^[\s\xa0]+|[\s\xa0]+$/g,"").split("."),e=Math.max(c.length,d.length),g=0;0==b&&g<e;g++){var h=c[g]||"",l=d[g]||"",u=RegExp("(\\d*)(\\D*)","g"),s=RegExp("(\\d*)(\\D*)","g");do{var v=u.exec(h)||["","",""],t=s.exec(l)||["","",""];if(0==v[0].length&&0==t[0].length)break;b=ta(0==v[1].length?0:parseInt(v[1],10),0==t[1].length?0:parseInt(t[1],10))||ta(0==v[2].length,0==t[2].length)||
ta(v[2],t[2])}while(0==b)}b=Ja[a]=0<=b}return b}var Ka=k.document,La=Ka&&x?Ca()||("CSS1Compat"==Ka.compatMode?parseInt(Da,10):5):void 0;function Ma(a){if(Error.captureStackTrace)Error.captureStackTrace(this,Ma);else{var b=Error().stack;b&&(this.stack=b)}a&&(this.message=String(a))}r(Ma,Error);Ma.prototype.name="CustomError";function Na(a,b){b.unshift(a);Ma.call(this,ka.apply(null,b));b.shift()}r(Na,Ma);Na.prototype.name="AssertionError";function Oa(a,b){throw new Na("Failure"+(a?": "+a:""),Array.prototype.slice.call(arguments,1));};var Pa=RegExp("^(?:([^:/?#.]+):)?(?://(?:([^/?#]*)@)?([^/#?]*?)(?::([0-9]+))?(?=[/#?]|$))?([^?#]+)?(?:\\?([^#]*))?(?:#(.*))?$");function Qa(a){if(Ra){Ra=!1;var b=k.location;if(b){var c=b.href;if(c&&(c=(c=Qa(c)[3]||null)&&decodeURIComponent(c))&&c!=b.hostname)throw Ra=!0,Error();}}return a.match(Pa)}var Ra=y;function Sa(a){var b=[],c=0,d;for(d in a)b[c++]=a[d];return b}function Ta(a){var b=[],c=0,d;for(d in a)b[c++]=d;return b}var Ua="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function Va(a,b){for(var c,d,e=1;e<arguments.length;e++){d=arguments[e];for(c in d)a[c]=d[c];for(var g=0;g<Ua.length;g++)c=Ua[g],Object.prototype.hasOwnProperty.call(d,c)&&(a[c]=d[c])}};var A=Array.prototype,Wa=A.indexOf?function(a,b,c){return A.indexOf.call(a,b,c)}:function(a,b,c){c=null==c?0:0>c?Math.max(0,a.length+c):c;if(n(a))return n(b)&&1==b.length?a.indexOf(b,c):-1;for(;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1},Xa=A.forEach?function(a,b,c){A.forEach.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=n(a)?a.split(""):a,g=0;g<d;g++)g in e&&b.call(c,e[g],g,a)};
function Ya(a){var b;a:{b=Za;for(var c=a.length,d=n(a)?a.split(""):a,e=0;e<c;e++)if(e in d&&b.call(void 0,d[e],e,a)){b=e;break a}b=-1}return 0>b?null:n(a)?a.charAt(b):a[b]}function $a(a){return A.concat.apply(A,arguments)}function ab(a){var b=a.length;if(0<b){for(var c=Array(b),d=0;d<b;d++)c[d]=a[d];return c}return[]};function bb(a,b){this.O={};this.j=[];this.o=0;var c=arguments.length;if(1<c){if(c%2)throw Error("Uneven number of arguments");for(var d=0;d<c;d+=2)this.set(arguments[d],arguments[d+1])}else if(a){a instanceof bb?(c=a.ba(),d=a.N()):(c=Ta(a),d=Sa(a));for(var e=0;e<c.length;e++)this.set(c[e],d[e])}}f=bb.prototype;f.N=function(){cb(this);for(var a=[],b=0;b<this.j.length;b++)a.push(this.O[this.j[b]]);return a};f.ba=function(){cb(this);return this.j.concat()};f.wa=function(a){return B(this.O,a)};
f.remove=function(a){return B(this.O,a)?(delete this.O[a],this.o--,this.j.length>2*this.o&&cb(this),!0):!1};function cb(a){if(a.o!=a.j.length){for(var b=0,c=0;b<a.j.length;){var d=a.j[b];B(a.O,d)&&(a.j[c++]=d);b++}a.j.length=c}if(a.o!=a.j.length){for(var e={},c=b=0;b<a.j.length;)d=a.j[b],B(e,d)||(a.j[c++]=d,e[d]=1),b++;a.j.length=c}}f.get=function(a,b){return B(this.O,a)?this.O[a]:b};f.set=function(a,b){B(this.O,a)||(this.o++,this.j.push(a));this.O[a]=b};f.n=function(){return new bb(this)};
function B(a,b){return Object.prototype.hasOwnProperty.call(a,b)};function db(a){if("function"==typeof a.N)return a.N();if(n(a))return a.split("");if(ea(a)){for(var b=[],c=a.length,d=0;d<c;d++)b.push(a[d]);return b}return Sa(a)}function C(a,b,c){if("function"==typeof a.forEach)a.forEach(b,c);else if(ea(a)||n(a))Xa(a,b,c);else{var d;if("function"==typeof a.ba)d=a.ba();else if("function"!=typeof a.N)if(ea(a)||n(a)){d=[];for(var e=a.length,g=0;g<e;g++)d.push(g)}else d=Ta(a);else d=void 0;for(var e=db(a),g=e.length,h=0;h<g;h++)b.call(c,e[h],d&&d[h],a)}};function D(a,b){var c;if(a instanceof D)this.D=void 0!==b?b:a.D,eb(this,a.oa),c=a.gb,E(this),this.gb=c,fb(this,a.ia),gb(this,a.Da),hb(this,a.I),ib(this,a.R.n()),c=a.Pa,E(this),this.Pa=c;else if(a&&(c=Qa(String(a)))){this.D=!!b;eb(this,c[1]||"",!0);var d=c[2]||"";E(this);this.gb=d?decodeURIComponent(d):"";fb(this,c[3]||"",!0);gb(this,c[4]);hb(this,c[5]||"",!0);ib(this,c[6]||"",!0);c=c[7]||"";E(this);this.Pa=c?decodeURIComponent(c):""}else this.D=!!b,this.R=new jb(null,0,this.D)}f=D.prototype;
f.oa="";f.gb="";f.ia="";f.Da=null;f.I="";f.Pa="";f.qc=!1;f.D=!1;f.toString=function(){var a=[],b=this.oa;b&&a.push(kb(b,lb),":");if(b=this.ia){a.push("//");var c=this.gb;c&&a.push(kb(c,lb),"@");a.push(encodeURIComponent(String(b)));b=this.Da;null!=b&&a.push(":",String(b))}if(b=this.I)this.ia&&"/"!=b.charAt(0)&&a.push("/"),a.push(kb(b,"/"==b.charAt(0)?mb:nb));(b=this.R.toString())&&a.push("?",b);(b=this.Pa)&&a.push("#",kb(b,ob));return a.join("")};f.n=function(){return new D(this)};
function eb(a,b,c){E(a);a.oa=c?b?decodeURIComponent(b):"":b;a.oa&&(a.oa=a.oa.replace(/:$/,""))}function fb(a,b,c){E(a);a.ia=c?b?decodeURIComponent(b):"":b}function gb(a,b){E(a);if(b){b=Number(b);if(isNaN(b)||0>b)throw Error("Bad port number "+b);a.Da=b}else a.Da=null}function hb(a,b,c){E(a);a.I=c?b?decodeURIComponent(b):"":b}function ib(a,b,c){E(a);b instanceof jb?(a.R=b,a.R.wb(a.D)):(c||(b=kb(b,pb)),a.R=new jb(b,0,a.D))}function F(a,b,c){E(a);a.R.set(b,c)}
function qb(a,b,c){E(a);m(c)||(c=[String(c)]);rb(a.R,b,c)}function G(a){E(a);F(a,"zx",sa());return a}function E(a){if(a.qc)throw Error("Tried to modify a read-only Uri");}f.wb=function(a){this.D=a;this.R&&this.R.wb(a);return this};function sb(a){return a instanceof D?a.n():new D(a,void 0)}function tb(a,b,c,d){var e=new D(null,void 0);a&&eb(e,a);b&&fb(e,b);c&&gb(e,c);d&&hb(e,d);return e}function kb(a,b){return n(a)?encodeURI(a).replace(b,ub):null}
function ub(a){a=a.charCodeAt(0);return"%"+(a>>4&15).toString(16)+(a&15).toString(16)}var lb=/[#\/\?@]/g,nb=/[\#\?:]/g,mb=/[\#\?]/g,pb=/[\#\?@]/g,ob=/#/g;function jb(a,b,c){this.C=a||null;this.D=!!c}function H(a){if(!a.h&&(a.h=new bb,a.o=0,a.C))for(var b=a.C.split("&"),c=0;c<b.length;c++){var d=b[c].indexOf("="),e=null,g=null;0<=d?(e=b[c].substring(0,d),g=b[c].substring(d+1)):e=b[c];e=decodeURIComponent(e.replace(/\+/g," "));e=I(a,e);a.add(e,g?decodeURIComponent(g.replace(/\+/g," ")):"")}}f=jb.prototype;
f.h=null;f.o=null;f.add=function(a,b){H(this);this.C=null;a=I(this,a);var c=this.h.get(a);c||this.h.set(a,c=[]);c.push(b);this.o++;return this};f.remove=function(a){H(this);a=I(this,a);return this.h.wa(a)?(this.C=null,this.o-=this.h.get(a).length,this.h.remove(a)):!1};f.wa=function(a){H(this);a=I(this,a);return this.h.wa(a)};f.ba=function(){H(this);for(var a=this.h.N(),b=this.h.ba(),c=[],d=0;d<b.length;d++)for(var e=a[d],g=0;g<e.length;g++)c.push(b[d]);return c};
f.N=function(a){H(this);var b=[];if(n(a))this.wa(a)&&(b=$a(b,this.h.get(I(this,a))));else{a=this.h.N();for(var c=0;c<a.length;c++)b=$a(b,a[c])}return b};f.set=function(a,b){H(this);this.C=null;a=I(this,a);this.wa(a)&&(this.o-=this.h.get(a).length);this.h.set(a,[b]);this.o++;return this};f.get=function(a,b){var c=a?this.N(a):[];return 0<c.length?String(c[0]):b};function rb(a,b,c){a.remove(b);0<c.length&&(a.C=null,a.h.set(I(a,b),ab(c)),a.o+=c.length)}
f.toString=function(){if(this.C)return this.C;if(!this.h)return"";for(var a=[],b=this.h.ba(),c=0;c<b.length;c++)for(var d=b[c],e=encodeURIComponent(String(d)),d=this.N(d),g=0;g<d.length;g++){var h=e;""!==d[g]&&(h+="="+encodeURIComponent(String(d[g])));a.push(h)}return this.C=a.join("&")};f.n=function(){var a=new jb;a.C=this.C;this.h&&(a.h=this.h.n(),a.o=this.o);return a};function I(a,b){var c=String(b);a.D&&(c=c.toLowerCase());return c}
f.wb=function(a){a&&!this.D&&(H(this),this.C=null,C(this.h,function(a,c){var d=c.toLowerCase();c!=d&&(this.remove(c),rb(this,d,a))},this));this.D=a};function vb(a){a=String(a);if(/^\s*$/.test(a)?0:/^[\],:{}\s\u2028\u2029]*$/.test(a.replace(/\\["\\\/bfnrtu]/g,"@").replace(/"[^"\\\n\r\u2028\u2029\x00-\x08\x0a-\x1f]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:[\s\u2028\u2029]*\[)+/g,"")))try{return eval("("+a+")")}catch(b){}throw Error("Invalid JSON string: "+a);}function wb(a){return eval("("+a+")")}function xb(a){var b=[];yb(new zb,a,b);return b.join("")}function zb(){this.$a=void 0}
function yb(a,b,c){switch(typeof b){case "string":Ab(b,c);break;case "number":c.push(isFinite(b)&&!isNaN(b)?b:"null");break;case "boolean":c.push(b);break;case "undefined":c.push("null");break;case "object":if(null==b){c.push("null");break}if(m(b)){var d=b.length;c.push("[");for(var e="",g=0;g<d;g++)c.push(e),e=b[g],yb(a,a.$a?a.$a.call(b,String(g),e):e,c),e=",";c.push("]");break}c.push("{");d="";for(g in b)Object.prototype.hasOwnProperty.call(b,g)&&(e=b[g],"function"!=typeof e&&(c.push(d),Ab(g,c),
c.push(":"),yb(a,a.$a?a.$a.call(b,g,e):e,c),d=","));c.push("}");break;case "function":break;default:throw Error("Unknown type: "+typeof b);}}var Bb={'"':'\\"',"\\":"\\\\","/":"\\/","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\x0B":"\\u000b"},Cb=/\uffff/.test("\uffff")?/[\\\"\x00-\x1f\x7f-\uffff]/g:/[\\\"\x00-\x1f\x7f-\xff]/g;
function Ab(a,b){b.push('"',a.replace(Cb,function(a){if(a in Bb)return Bb[a];var b=a.charCodeAt(0),e="\\u";16>b?e+="000":256>b?e+="00":4096>b&&(e+="0");return Bb[a]=e+b.toString(16)}),'"')};function Db(a){return Eb(a||arguments.callee.caller,[])}
function Eb(a,b){var c=[];if(0<=Wa(b,a))c.push("[...circular reference...]");else if(a&&50>b.length){c.push(Fb(a)+"(");for(var d=a.arguments,e=0;d&&e<d.length;e++){0<e&&c.push(", ");var g;g=d[e];switch(typeof g){case "object":g=g?"object":"null";break;case "string":break;case "number":g=String(g);break;case "boolean":g=g?"true":"false";break;case "function":g=(g=Fb(g))?g:"[fn]";break;default:g=typeof g}40<g.length&&(g=g.substr(0,40)+"...");c.push(g)}b.push(a);c.push(")\n");try{c.push(Eb(a.caller,
b))}catch(h){c.push("[exception trying to get caller]\n")}}else a?c.push("[...long stack...]"):c.push("[end]");return c.join("")}function Fb(a){if(Gb[a])return Gb[a];a=String(a);if(!Gb[a]){var b=/function ([^\(]+)/.exec(a);Gb[a]=b?b[1]:"[Anonymous]"}return Gb[a]}var Gb={};function Hb(a,b,c,d,e){this.reset(a,b,c,d,e)}Hb.prototype.Hb=null;Hb.prototype.Gb=null;var Ib=0;Hb.prototype.reset=function(a,b,c,d,e){"number"==typeof e||Ib++;d||q();this.Ba=a;this.sc=b;delete this.Hb;delete this.Gb};Hb.prototype.bc=function(a){this.Ba=a};function Jb(a){this.tc=a;this.Lb=this.lb=this.Ba=this.Ua=null}function J(a,b){this.name=a;this.value=b}J.prototype.toString=function(){return this.name};var Kb=new J("SEVERE",1E3),Lb=new J("WARNING",900),Mb=new J("INFO",800),Nb=new J("CONFIG",700),Ob=new J("FINE",500);f=Jb.prototype;f.getParent=function(){return this.Ua};f.bc=function(a){this.Ba=a};function Pb(a){if(a.Ba)return a.Ba;if(a.Ua)return Pb(a.Ua);Oa("Root logger has no level set.");return null}
f.log=function(a,b,c){if(a.value>=Pb(this).value)for(fa(b)&&(b=b()),a=this.oc(a,b,c),b="log:"+a.sc,k.console&&(k.console.timeStamp?k.console.timeStamp(b):k.console.markTimeline&&k.console.markTimeline(b)),k.msWriteProfilerMark&&k.msWriteProfilerMark(b),b=this;b;){c=b;var d=a;if(c.Lb)for(var e=0,g=void 0;g=c.Lb[e];e++)g(d);b=b.getParent()}};
f.oc=function(a,b,c){var d=new Hb(a,String(b),this.tc);if(c){d.Hb=c;var e;var g=arguments.callee.caller;try{var h;var l=ba("window.location.href");if(n(c))h={message:c,name:"Unknown error",lineNumber:"Not available",fileName:l,stack:"Not available"};else{var u,s,v=!1;try{u=c.lineNumber||c.Jc||"Not available"}catch(t){u="Not available",v=!0}try{s=c.fileName||c.filename||c.sourceURL||k.$googDebugFname||l}catch(K){s="Not available",v=!0}h=!v&&c.lineNumber&&c.fileName&&c.stack&&c.message&&c.name?c:{message:c.message||
"Not available",name:c.name||"UnknownError",lineNumber:u,fileName:s,stack:c.stack||"Not available"}}e="Message: "+la(h.message)+'\nUrl: <a href="view-source:'+h.fileName+'" target="_new">'+h.fileName+"</a>\nLine: "+h.lineNumber+"\n\nBrowser stack:\n"+la(h.stack+"-> ")+"[end]\n\nJS stack traversal:\n"+la(Db(g)+"-> ")}catch(Hd){e="Exception trying to expose exception! You win, we lose. "+Hd}d.Gb=e}return d};f.J=function(a,b){this.log(Kb,a,b)};f.fa=function(a,b){this.log(Lb,a,b)};
f.info=function(a,b){this.log(Mb,a,b)};var Qb={},Rb=null;function Sb(a){Rb||(Rb=new Jb(""),Qb[""]=Rb,Rb.bc(Nb));var b;if(!(b=Qb[a])){b=new Jb(a);var c=a.lastIndexOf("."),d=a.substr(c+1),c=Sb(a.substr(0,c));c.lb||(c.lb={});c.lb[d]=b;b.Ua=c;Qb[a]=b}return b};function L(a,b){a&&a.log(Ob,b,void 0)};function M(){this.r=Sb("goog.net.BrowserChannel")}function Tb(a,b,c,d){a.info("XMLHTTP TEXT ("+b+"): "+Ub(a,c)+(d?" "+d:""))}M.prototype.debug=function(a){this.info(a)};function Vb(a,b,c){a.J((c||"Exception")+b)}M.prototype.info=function(a){var b=this.r;b&&b.info(a,void 0)};M.prototype.fa=function(a){var b=this.r;b&&b.fa(a,void 0)};M.prototype.J=function(a){var b=this.r;b&&b.J(a,void 0)};
function Ub(a,b){if(!b||b==Wb)return b;try{var c=wb(b);if(c)for(var d=0;d<c.length;d++)if(m(c[d])){var e=c[d];if(!(2>e.length)){var g=e[1];if(m(g)&&!(1>g.length)){var h=g[0];if("noop"!=h&&"stop"!=h)for(var l=1;l<g.length;l++)g[l]=""}}}return xb(c)}catch(u){return a.debug("Exception parsing expected JS array - probably was not JS"),b}};function Xb(a,b){this.P=b?wb:vb}Xb.prototype.parse=function(a){return this.P(a)};function N(){0!=Yb&&(Zb[this[ga]||(this[ga]=++ha)]=this)}var Yb=0,Zb={};N.prototype.ob=!1;N.prototype.La=function(){if(!this.ob&&(this.ob=!0,this.u(),0!=Yb)){var a=this[ga]||(this[ga]=++ha);delete Zb[a]}};N.prototype.u=function(){if(this.Rb)for(;this.Rb.length;)this.Rb.shift()()};var $b="closure_listenable_"+(1E6*Math.random()|0);function ac(a){try{return!(!a||!a[$b])}catch(b){return!1}}var bc=0;function cc(a,b,c,d,e){this.ea=a;this.Wa=null;this.src=b;this.type=c;this.Ka=!!d;this.Qa=e;this.key=++bc;this.na=this.Ja=!1}function dc(a){a.na=!0;a.ea=null;a.Wa=null;a.src=null;a.Qa=null};function O(a){this.src=a;this.s={};this.Ha=0}O.prototype.add=function(a,b,c,d,e){var g=this.s[a];g||(g=this.s[a]=[],this.Ha++);var h=ec(g,b,d,e);-1<h?(a=g[h],c||(a.Ja=!1)):(a=new cc(b,this.src,a,!!d,e),a.Ja=c,g.push(a));return a};O.prototype.remove=function(a,b,c,d){if(!(a in this.s))return!1;var e=this.s[a];b=ec(e,b,c,d);return-1<b?(dc(e[b]),A.splice.call(e,b,1),0==e.length&&(delete this.s[a],this.Ha--),!0):!1};
function fc(a,b){var c=b.type;if(!(c in a.s))return!1;var d=a.s[c],e=Wa(d,b),g;(g=0<=e)&&A.splice.call(d,e,1);g&&(dc(b),0==a.s[c].length&&(delete a.s[c],a.Ha--));return g}O.prototype.Za=function(a){var b=0,c;for(c in this.s)if(!a||c==a){for(var d=this.s[c],e=0;e<d.length;e++)++b,dc(d[e]);delete this.s[c];this.Ha--}return b};O.prototype.za=function(a,b,c,d){a=this.s[a];var e=-1;a&&(e=ec(a,b,c,d));return-1<e?a[e]:null};
function ec(a,b,c,d){for(var e=0;e<a.length;++e){var g=a[e];if(!g.na&&g.ea==b&&g.Ka==!!c&&g.Qa==d)return e}return-1};var gc=!x||x&&9<=La,hc=x&&!z("9");!y||z("528");Ba&&z("1.9b")||x&&z("8")||Aa&&z("9.5")||y&&z("528");Ba&&!z("8")||x&&z("9");function P(a,b){this.type=a;this.currentTarget=this.target=b;this.defaultPrevented=this.la=!1;this.$b=!0}P.prototype.u=function(){};P.prototype.La=function(){};P.prototype.preventDefault=function(){this.defaultPrevented=!0;this.$b=!1};function ic(a){ic[" "](a);return a}ic[" "]=ca;function Q(a,b){P.call(this,a?a.type:"");this.relatedTarget=this.currentTarget=this.target=null;this.charCode=this.keyCode=this.button=this.screenY=this.screenX=this.clientY=this.clientX=this.offsetY=this.offsetX=0;this.metaKey=this.shiftKey=this.altKey=this.ctrlKey=!1;this.Fb=this.state=null;if(a){var c=this.type=a.type;this.target=a.target||a.srcElement;this.currentTarget=b;var d=a.relatedTarget;if(d){if(Ba){var e;a:{try{ic(d.nodeName);e=!0;break a}catch(g){}e=!1}e||(d=null)}}else"mouseover"==c?
d=a.fromElement:"mouseout"==c&&(d=a.toElement);this.relatedTarget=d;this.offsetX=y||void 0!==a.offsetX?a.offsetX:a.layerX;this.offsetY=y||void 0!==a.offsetY?a.offsetY:a.layerY;this.clientX=void 0!==a.clientX?a.clientX:a.pageX;this.clientY=void 0!==a.clientY?a.clientY:a.pageY;this.screenX=a.screenX||0;this.screenY=a.screenY||0;this.button=a.button;this.keyCode=a.keyCode||0;this.charCode=a.charCode||("keypress"==c?a.keyCode:0);this.ctrlKey=a.ctrlKey;this.altKey=a.altKey;this.shiftKey=a.shiftKey;this.metaKey=
a.metaKey;this.state=a.state;this.Fb=a;a.defaultPrevented&&this.preventDefault()}}r(Q,P);Q.prototype.preventDefault=function(){Q.pa.preventDefault.call(this);var a=this.Fb;if(a.preventDefault)a.preventDefault();else if(a.returnValue=!1,hc)try{if(a.ctrlKey||112<=a.keyCode&&123>=a.keyCode)a.keyCode=-1}catch(b){}};Q.prototype.u=function(){};var jc="closure_lm_"+(1E6*Math.random()|0),R={},kc=0;function lc(a,b,c,d,e){if(m(b)){for(var g=0;g<b.length;g++)lc(a,b[g],c,d,e);return null}c=mc(c);if(ac(a))a=a.Ta(b,c,d,e);else{if(!b)throw Error("Invalid event type");var g=!!d,h=nc(a);h||(a[jc]=h=new O(a));c=h.add(b,c,!1,d,e);c.Wa||(d=oc(),c.Wa=d,d.src=a,d.ea=c,a.addEventListener?a.addEventListener(b,d,g):a.attachEvent(b in R?R[b]:R[b]="on"+b,d),kc++);a=c}return a}
function oc(){var a=pc,b=gc?function(c){return a.call(b.src,b.ea,c)}:function(c){c=a.call(b.src,b.ea,c);if(!c)return c};return b}function qc(a,b,c,d,e){if(m(b))for(var g=0;g<b.length;g++)qc(a,b[g],c,d,e);else c=mc(c),ac(a)?a.xb(b,c,d,e):a&&(a=nc(a))&&(b=a.za(b,c,!!d,e))&&rc(b)}
function rc(a){if("number"==typeof a||!a||a.na)return!1;var b=a.src;if(ac(b))return fc(b.V,a);var c=a.type,d=a.Wa;b.removeEventListener?b.removeEventListener(c,d,a.Ka):b.detachEvent&&b.detachEvent(c in R?R[c]:R[c]="on"+c,d);kc--;(c=nc(b))?(fc(c,a),0==c.Ha&&(c.src=null,b[jc]=null)):dc(a);return!0}function sc(a,b,c,d){var e=1;if(a=nc(a))if(b=a.s[b])for(b=ab(b),a=0;a<b.length;a++){var g=b[a];g&&g.Ka==c&&!g.na&&(e&=!1!==tc(g,d))}return Boolean(e)}
function tc(a,b){var c=a.ea,d=a.Qa||a.src;a.Ja&&rc(a);return c.call(d,b)}
function pc(a,b){if(a.na)return!0;if(!gc){var c=b||ba("window.event"),d=new Q(c,this),e=!0;if(!(0>c.keyCode||void 0!=c.returnValue)){a:{var g=!1;if(0==c.keyCode)try{c.keyCode=-1;break a}catch(h){g=!0}if(g||void 0==c.returnValue)c.returnValue=!0}c=[];for(g=d.currentTarget;g;g=g.parentNode)c.push(g);for(var g=a.type,l=c.length-1;!d.la&&0<=l;l--)d.currentTarget=c[l],e&=sc(c[l],g,!0,d);for(l=0;!d.la&&l<c.length;l++)d.currentTarget=c[l],e&=sc(c[l],g,!1,d)}return e}return tc(a,new Q(b,this))}
function nc(a){a=a[jc];return a instanceof O?a:null}var uc="__closure_events_fn_"+(1E9*Math.random()>>>0);function mc(a){return fa(a)?a:a[uc]||(a[uc]=function(b){return a.handleEvent(b)})};function S(){N.call(this);this.V=new O(this);this.hc=this}r(S,N);S.prototype[$b]=!0;f=S.prototype;f.vb=null;f.addEventListener=function(a,b,c,d){lc(this,a,b,c,d)};f.removeEventListener=function(a,b,c,d){qc(this,a,b,c,d)};
f.dispatchEvent=function(a){var b,c=this.vb;if(c)for(b=[];c;c=c.vb)b.push(c);var c=this.hc,d=a.type||a;if(n(a))a=new P(a,c);else if(a instanceof P)a.target=a.target||c;else{var e=a;a=new P(d,c);Va(a,e)}var e=!0,g;if(b)for(var h=b.length-1;!a.la&&0<=h;h--)g=a.currentTarget=b[h],e=vc(g,d,!0,a)&&e;a.la||(g=a.currentTarget=c,e=vc(g,d,!0,a)&&e,a.la||(e=vc(g,d,!1,a)&&e));if(b)for(h=0;!a.la&&h<b.length;h++)g=a.currentTarget=b[h],e=vc(g,d,!1,a)&&e;return e};
f.u=function(){S.pa.u.call(this);this.V&&this.V.Za(void 0);this.vb=null};f.Ta=function(a,b,c,d){return this.V.add(String(a),b,!1,c,d)};f.xb=function(a,b,c,d){return this.V.remove(String(a),b,c,d)};function vc(a,b,c,d){b=a.V.s[String(b)];if(!b)return!0;b=ab(b);for(var e=!0,g=0;g<b.length;++g){var h=b[g];if(h&&!h.na&&h.Ka==c){var l=h.ea,u=h.Qa||h.src;h.Ja&&fc(a.V,h);e=!1!==l.call(u,d)&&e}}return e&&!1!=d.$b}f.za=function(a,b,c,d){return this.V.za(String(a),b,c,d)};function wc(a,b){S.call(this);this.da=a||1;this.ra=b||k;this.kb=p(this.Hc,this);this.ub=q()}r(wc,S);f=wc.prototype;f.xa=!1;f.l=null;f.setInterval=function(a){this.da=a;this.l&&this.xa?(this.stop(),this.start()):this.l&&this.stop()};f.Hc=function(){if(this.xa){var a=q()-this.ub;0<a&&a<0.8*this.da?this.l=this.ra.setTimeout(this.kb,this.da-a):(this.l&&(this.ra.clearTimeout(this.l),this.l=null),this.dispatchEvent(xc),this.xa&&(this.l=this.ra.setTimeout(this.kb,this.da),this.ub=q()))}};
f.start=function(){this.xa=!0;this.l||(this.l=this.ra.setTimeout(this.kb,this.da),this.ub=q())};f.stop=function(){this.xa=!1;this.l&&(this.ra.clearTimeout(this.l),this.l=null)};f.u=function(){wc.pa.u.call(this);this.stop();delete this.ra};var xc="tick";function yc(a,b,c){if(fa(a))c&&(a=p(a,c));else if(a&&"function"==typeof a.handleEvent)a=p(a.handleEvent,a);else throw Error("Invalid listener argument");return 2147483647<b?-1:k.setTimeout(a,b||0)};function zc(){}zc.prototype.Cb=null;function Ac(a){var b;(b=a.Cb)||(b={},Bc(a)&&(b[0]=!0,b[1]=!0),b=a.Cb=b);return b};var Cc;function Dc(){}r(Dc,zc);function Ec(a){return(a=Bc(a))?new ActiveXObject(a):new XMLHttpRequest}function Bc(a){if(!a.Mb&&"undefined"==typeof XMLHttpRequest&&"undefined"!=typeof ActiveXObject){for(var b=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"],c=0;c<b.length;c++){var d=b[c];try{return new ActiveXObject(d),a.Mb=d}catch(e){}}throw Error("Could not create ActiveXObject. ActiveX might be disabled, or MSXML might not be installed");}return a.Mb}Cc=new Dc;function Fc(a){S.call(this);this.headers=new bb;this.ib=a||null;this.S=!1;this.hb=this.f=null;this.Ob=this.Sa="";this.ja=0;this.q="";this.ca=this.sb=this.Ra=this.pb=!1;this.Ga=0;this.eb=null;this.Zb=Gc;this.fb=this.fc=!1}r(Fc,S);var Gc="";Fc.prototype.r=Sb("goog.net.XhrIo");var Hc=/^https?$/i,Ic=["POST","PUT"];f=Fc.prototype;
f.send=function(a,b,c,d){if(this.f)throw Error("[goog.net.XhrIo] Object is active with another request="+this.Sa+"; newUri="+a);b=b?b.toUpperCase():"GET";this.Sa=a;this.q="";this.ja=0;this.Ob=b;this.pb=!1;this.S=!0;this.f=this.ib?Ec(this.ib):Ec(Cc);this.hb=this.ib?Ac(this.ib):Ac(Cc);this.f.onreadystatechange=p(this.Sb,this);try{L(this.r,T(this,"Opening Xhr")),this.sb=!0,this.f.open(b,String(a),!0),this.sb=!1}catch(e){L(this.r,T(this,"Error opening Xhr: "+e.message));Jc(this,e);return}a=c||"";var g=
this.headers.n();d&&C(d,function(a,b){g.set(b,a)});d=Ya(g.ba());c=k.FormData&&a instanceof k.FormData;!(0<=Wa(Ic,b))||d||c||g.set("Content-Type","application/x-www-form-urlencoded;charset=utf-8");C(g,function(a,b){this.f.setRequestHeader(b,a)},this);this.Zb&&(this.f.responseType=this.Zb);"withCredentials"in this.f&&(this.f.withCredentials=this.fc);try{Kc(this),0<this.Ga&&(this.fb=Lc(this.f),L(this.r,T(this,"Will abort after "+this.Ga+"ms if incomplete, xhr2 "+this.fb)),this.fb?(this.f.timeout=this.Ga,
this.f.ontimeout=p(this.qa,this)):this.eb=yc(this.qa,this.Ga,this)),L(this.r,T(this,"Sending request")),this.Ra=!0,this.f.send(a),this.Ra=!1}catch(h){L(this.r,T(this,"Send error: "+h.message)),Jc(this,h)}};function Lc(a){return x&&z(9)&&"number"==typeof a.timeout&&void 0!==a.ontimeout}function Za(a){return"content-type"==a.toLowerCase()}
f.qa=function(){"undefined"!=typeof aa&&this.f&&(this.q="Timed out after "+this.Ga+"ms, aborting",this.ja=8,L(this.r,T(this,this.q)),this.dispatchEvent("timeout"),this.abort(8))};function Jc(a,b){a.S=!1;a.f&&(a.ca=!0,a.f.abort(),a.ca=!1);a.q=b;a.ja=5;Mc(a);Nc(a)}function Mc(a){a.pb||(a.pb=!0,a.dispatchEvent("complete"),a.dispatchEvent("error"))}
f.abort=function(a){this.f&&this.S&&(L(this.r,T(this,"Aborting")),this.S=!1,this.ca=!0,this.f.abort(),this.ca=!1,this.ja=a||7,this.dispatchEvent("complete"),this.dispatchEvent("abort"),Nc(this))};f.u=function(){this.f&&(this.S&&(this.S=!1,this.ca=!0,this.f.abort(),this.ca=!1),Nc(this,!0));Fc.pa.u.call(this)};f.Sb=function(){this.ob||(this.sb||this.Ra||this.ca?Oc(this):this.wc())};f.wc=function(){Oc(this)};
function Oc(a){if(a.S&&"undefined"!=typeof aa)if(a.hb[1]&&4==U(a)&&2==Pc(a))L(a.r,T(a,"Local request error detected and ignored"));else if(a.Ra&&4==U(a))yc(a.Sb,0,a);else if(a.dispatchEvent("readystatechange"),4==U(a)){L(a.r,T(a,"Request complete"));a.S=!1;try{var b=Pc(a),c,d;a:switch(b){case 200:case 201:case 202:case 204:case 206:case 304:case 1223:d=!0;break a;default:d=!1}if(!(c=d)){var e;if(e=0===b){var g=Qa(String(a.Sa))[1]||null;if(!g&&self.location)var h=self.location.protocol,g=h.substr(0,
h.length-1);e=!Hc.test(g?g.toLowerCase():"")}c=e}if(c)a.dispatchEvent("complete"),a.dispatchEvent("success");else{a.ja=6;var l;try{l=2<U(a)?a.f.statusText:""}catch(u){L(a.r,"Can not get status: "+u.message),l=""}a.q=l+" ["+Pc(a)+"]";Mc(a)}}finally{Nc(a)}}}function Nc(a,b){if(a.f){Kc(a);var c=a.f,d=a.hb[0]?ca:null;a.f=null;a.hb=null;b||a.dispatchEvent("ready");try{c.onreadystatechange=d}catch(e){(c=a.r)&&c.J("Problem encountered resetting onreadystatechange: "+e.message,void 0)}}}
function Kc(a){a.f&&a.fb&&(a.f.ontimeout=null);"number"==typeof a.eb&&(k.clearTimeout(a.eb),a.eb=null)}f.isActive=function(){return!!this.f};function U(a){return a.f?a.f.readyState:0}function Pc(a){try{return 2<U(a)?a.f.status:-1}catch(b){return-1}}function Qc(a){try{return a.f?a.f.responseText:""}catch(b){return L(a.r,"Can not get responseText: "+b.message),""}}f.Kb=function(){return n(this.q)?this.q:String(this.q)};function T(a,b){return b+" ["+a.Ob+" "+a.Sa+" "+Pc(a)+"]"};function Rc(){this.Yb=q()}new Rc;Rc.prototype.set=function(a){this.Yb=a};Rc.prototype.reset=function(){this.set(q())};Rc.prototype.get=function(){return this.Yb};function Sc(a){N.call(this);this.e=a;this.j={}}r(Sc,N);var Tc=[];f=Sc.prototype;f.Ta=function(a,b,c,d){m(b)||(Tc[0]=b,b=Tc);for(var e=0;e<b.length;e++){var g=lc(a,b[e],c||this.handleEvent,d||!1,this.e||this);if(!g)break;this.j[g.key]=g}return this};f.xb=function(a,b,c,d,e){if(m(b))for(var g=0;g<b.length;g++)this.xb(a,b[g],c,d,e);else c=c||this.handleEvent,e=e||this.e||this,c=mc(c),d=!!d,b=ac(a)?a.za(b,c,d,e):a?(a=nc(a))?a.za(b,c,d,e):null:null,b&&(rc(b),delete this.j[b.key]);return this};
f.Za=function(){var a=this.j,b=rc,c;for(c in a)b.call(void 0,a[c],c,a);this.j={}};f.u=function(){Sc.pa.u.call(this);this.Za()};f.handleEvent=function(){throw Error("EventHandler.handleEvent not implemented");};function Uc(a,b,c){N.call(this);this.rc=a;this.da=b;this.e=c;this.lc=p(this.xc,this)}r(Uc,N);f=Uc.prototype;f.ab=!1;f.Xb=0;f.l=null;f.stop=function(){this.l&&(k.clearTimeout(this.l),this.l=null,this.ab=!1)};f.u=function(){Uc.pa.u.call(this);this.stop()};f.xc=function(){this.l=null;this.ab&&!this.Xb&&(this.ab=!1,Vc(this))};function Vc(a){a.l=yc(a.lc,a.da);a.rc.call(a.e)};function V(a,b,c,d,e){this.b=a;this.a=b;this.Y=c;this.B=d;this.Fa=e||1;this.qa=Wc;this.qb=new Sc(this);this.Va=new wc;this.Va.setInterval(Xc)}f=V.prototype;f.v=null;f.F=!1;f.ua=null;f.zb=null;f.Ea=null;f.sa=null;f.T=null;f.w=null;f.W=null;f.k=null;f.Ia=0;f.K=null;f.ta=null;f.q=null;f.g=-1;f.ac=!0;f.Z=!1;f.ma=0;f.Xa=null;var Wc=45E3,Xc=250;
function Yc(a,b){switch(a){case 0:return"Non-200 return code ("+b+")";case 1:return"XMLHTTP failure (no data)";case 2:return"HttpConnection timeout";default:return"Unknown error"}}var Zc={},$c={};function ad(){return!x||x&&10<=La}f=V.prototype;f.X=function(a){this.v=a};f.setTimeout=function(a){this.qa=a};f.dc=function(a){this.ma=a};function bd(a,b,c){a.sa=1;a.T=G(b.n());a.W=c;a.Eb=!0;cd(a,null)}function dd(a,b,c,d,e){a.sa=1;a.T=G(b.n());a.W=null;a.Eb=c;e&&(a.ac=!1);cd(a,d)}
function cd(a,b){a.Ea=q();ed(a);a.w=a.T.n();qb(a.w,"t",a.Fa);a.Ia=0;a.k=a.b.nb(a.b.bb()?b:null);0<a.ma&&(a.Xa=new Uc(p(a.gc,a,a.k),a.ma));a.qb.Ta(a.k,"readystatechange",a.Dc);var c;if(a.v){c=a.v;var d={},e;for(e in c)d[e]=c[e];c=d}else c={};a.W?(a.ta="POST",c["Content-Type"]="application/x-www-form-urlencoded",a.k.send(a.w,a.ta,a.W,c)):(a.ta="GET",a.ac&&!y&&(c.Connection="close"),a.k.send(a.w,a.ta,null,c));a.b.H(fd);if(d=a.W)for(c="",d=d.split("&"),e=0;e<d.length;e++){var g=d[e].split("=");if(1<g.length){var h=
g[0],g=g[1],l=h.split("_");c=2<=l.length&&"type"==l[1]?c+(h+"="+g+"&"):c+(h+"=redacted&")}}else c=null;a.a.info("XMLHTTP REQ ("+a.B+") [attempt "+a.Fa+"]: "+a.ta+"\n"+a.w+"\n"+c)}f.Dc=function(a){a=a.target;var b=this.Xa;b&&3==U(a)?(this.a.debug("Throttling readystatechange."),b.l||b.Xb?b.ab=!0:Vc(b)):this.gc(a)};
f.gc=function(a){try{if(a==this.k)a:{var b=U(this.k),c=this.k.ja,d=Pc(this.k);if(!ad()||y&&!z("420+")){if(4>b)break a}else if(3>b||3==b&&!Aa&&!Qc(this.k))break a;this.Z||4!=b||7==c||(8==c||0>=d?this.b.H(gd):this.b.H(hd));id(this);var e=Pc(this.k);this.g=e;var g=Qc(this.k);g||this.a.debug("No response text for uri "+this.w+" status "+e);this.F=200==e;this.a.info("XMLHTTP RESP ("+this.B+") [ attempt "+this.Fa+"]: "+this.ta+"\n"+this.w+"\n"+b+" "+e);this.F?(4==b&&W(this),this.Eb?(jd(this,b,g),Aa&&this.F&&
3==b&&(this.qb.Ta(this.Va,xc,this.Cc),this.Va.start())):(Tb(this.a,this.B,g,null),kd(this,g)),this.F&&!this.Z&&(4==b?this.b.ka(this):(this.F=!1,ed(this)))):(400==e&&0<g.indexOf("Unknown SID")?(this.q=3,X(),this.a.fa("XMLHTTP Unknown SID ("+this.B+")")):(this.q=0,X(),this.a.fa("XMLHTTP Bad status "+e+" ("+this.B+")")),W(this),ld(this))}else this.a.fa("Called back with an unexpected xmlhttp")}catch(h){this.a.debug("Failed call to OnXmlHttpReadyStateChanged_"),this.k&&Qc(this.k)?Vb(this.a,h,"ResponseText: "+
Qc(this.k)):Vb(this.a,h,"No response text")}finally{}};function jd(a,b,c){for(var d=!0;!a.Z&&a.Ia<c.length;){var e=md(a,c);if(e==$c){4==b&&(a.q=4,X(),d=!1);Tb(a.a,a.B,null,"[Incomplete Response]");break}else if(e==Zc){a.q=4;X();Tb(a.a,a.B,c,"[Invalid Chunk]");d=!1;break}else Tb(a.a,a.B,e,null),kd(a,e)}4==b&&0==c.length&&(a.q=1,X(),d=!1);a.F=a.F&&d;d||(Tb(a.a,a.B,c,"[Invalid Chunked Response]"),W(a),ld(a))}
f.Cc=function(){var a=U(this.k),b=Qc(this.k);this.Ia<b.length&&(id(this),jd(this,a,b),this.F&&4!=a&&ed(this))};function md(a,b){var c=a.Ia,d=b.indexOf("\n",c);if(-1==d)return $c;c=Number(b.substring(c,d));if(isNaN(c))return Zc;d+=1;if(d+c>b.length)return $c;var e=b.substr(d,c);a.Ia=d+c;return e}
function nd(a,b){a.Ea=q();ed(a);var c=b?window.location.hostname:"";a.w=a.T.n();F(a.w,"DOMAIN",c);F(a.w,"t",a.Fa);try{a.K=new ActiveXObject("htmlfile")}catch(d){a.a.J("ActiveX blocked");W(a);a.q=7;X();ld(a);return}var e="<html><body>";b&&(e+='<script>document.domain="'+c+'"\x3c/script>');e+="</body></html>";a.K.open();a.K.write(e);a.K.close();a.K.parentWindow.m=p(a.Ac,a);a.K.parentWindow.d=p(a.Wb,a,!0);a.K.parentWindow.rpcClose=p(a.Wb,a,!1);c=a.K.createElement("div");a.K.parentWindow.document.body.appendChild(c);
c.innerHTML='<iframe src="'+a.w+'"></iframe>';a.a.info("TRIDENT REQ ("+a.B+") [ attempt "+a.Fa+"]: GET\n"+a.w);a.b.H(fd)}f.Ac=function(a){Y(p(this.zc,this,a),0)};f.zc=function(a){if(!this.Z){var b=this.a;b.info("TRIDENT TEXT ("+this.B+"): "+Ub(b,a));id(this);kd(this,a);ed(this)}};f.Wb=function(a){Y(p(this.yc,this,a),0)};f.yc=function(a){this.Z||(this.a.info("TRIDENT TEXT ("+this.B+"): "+a?"success":"failure"),W(this),this.F=a,this.b.ka(this),this.b.H(od))};f.pc=function(){id(this);this.b.ka(this)};
f.cancel=function(){this.Z=!0;W(this)};function ed(a){a.zb=q()+a.qa;pd(a,a.qa)}function pd(a,b){if(null!=a.ua)throw Error("WatchDog timer not null");a.ua=Y(p(a.Bc,a),b)}function id(a){a.ua&&(k.clearTimeout(a.ua),a.ua=null)}
f.Bc=function(){this.ua=null;var a=q();0<=a-this.zb?(this.F&&this.a.J("Received watchdog timeout even though request loaded successfully"),this.a.info("TIMEOUT: "+this.w),2!=this.sa&&this.b.H(gd),W(this),this.q=2,X(),ld(this)):(this.a.fa("WatchDog timer called too early"),pd(this,this.zb-a))};function ld(a){a.b.Nb()||a.Z||a.b.ka(a)}function W(a){id(a);var b=a.Xa;b&&"function"==typeof b.La&&b.La();a.Xa=null;a.Va.stop();a.qb.Za();a.k&&(b=a.k,a.k=null,b.abort(),b.La());a.K&&(a.K=null)}f.Kb=function(){return this.q};
function kd(a,b){try{a.b.Tb(a,b),a.b.H(od)}catch(c){Vb(a.a,c,"Error in httprequest callback")}};function qd(a,b,c,d,e){(new M).debug("TestLoadImageWithRetries: "+e);if(0==d)c(!1);else{var g=e||0;d--;rd(a,b,function(e){e?c(!0):k.setTimeout(function(){qd(a,b,c,d,g)},g)})}}
function rd(a,b,c){function d(a,b){return function(){try{e.debug("TestLoadImage: "+b),g.onload=null,g.onerror=null,g.onabort=null,g.ontimeout=null,k.clearTimeout(h),c(a)}catch(d){Vb(e,d)}}}var e=new M;e.debug("TestLoadImage: loading "+a);var g=new Image,h=null;g.onload=d(!0,"loaded");g.onerror=d(!1,"error");g.onabort=d(!1,"abort");g.ontimeout=d(!1,"timeout");h=k.setTimeout(function(){if(g.ontimeout)g.ontimeout()},b);g.src=a};function sd(a,b){this.b=a;this.a=b;this.P=new Xb(0,!0)}f=sd.prototype;f.v=null;f.A=null;f.Ya=!1;f.ec=null;f.Na=null;f.tb=null;f.I=null;f.c=null;f.g=-1;f.L=null;f.va=null;f.X=function(a){this.v=a};f.cc=function(a){this.P=a};
f.mb=function(a){this.I=a;a=td(this.b,this.I);X();this.ec=q();var b=this.b.Ib;null!=b?(this.L=this.b.correctHostPrefix(b[0]),(this.va=b[1])?(this.c=1,ud(this)):(this.c=2,vd(this))):(qb(a,"MODE","init"),this.A=new V(this,this.a,void 0,void 0,void 0),this.A.X(this.v),dd(this.A,a,!1,null,!0),this.c=0)};function ud(a){var b=wd(a.b,a.va,"/mail/images/cleardot.gif");G(b);qd(b.toString(),5E3,p(a.mc,a),3,2E3);a.H(fd)}
f.mc=function(a){if(a)this.c=2,vd(this);else{X();var b=this.b;b.a.debug("Test Connection Blocked");b.g=b.U.g;Z(b,9)}a&&this.H(hd)};
function vd(a){a.a.debug("TestConnection: starting stage 2");var b=a.b.Fc;if(null!=b)a.a.debug("TestConnection: skipping stage 2, precomputed result is "+b?"Buffered":"Unbuffered"),X(),b?(X(),xd(a.b,a,!1)):(X(),xd(a.b,a,!0));else if(a.A=new V(a,a.a,void 0,void 0,void 0),a.A.X(a.v),b=yd(a.b,a.L,a.I),X(),ad())qb(b,"TYPE","xmlhttp"),dd(a.A,b,!1,a.L,!1);else{qb(b,"TYPE","html");var c=a.A;a=Boolean(a.L);c.sa=3;c.T=G(b.n());nd(c,a)}}f.nb=function(a){return this.b.nb(a)};
f.abort=function(){this.A&&(this.A.cancel(),this.A=null);this.g=-1};f.Nb=function(){return!1};
f.Tb=function(a,b){this.g=a.g;if(0==this.c)if(this.a.debug("TestConnection: Got data for stage 1"),b){try{var c=this.P.parse(b)}catch(d){Vb(this.a,d);zd(this.b,this);return}this.L=this.b.correctHostPrefix(c[0]);this.va=c[1]}else this.a.debug("TestConnection: Null responseText"),zd(this.b,this);else if(2==this.c)if(this.Ya)X(),this.tb=q();else if("11111"==b){if(X(),this.Ya=!0,this.Na=q(),c=this.Na-this.ec,ad()||500>c)this.g=200,this.A.cancel(),this.a.debug("Test connection succeeded; using streaming connection"),
X(),xd(this.b,this,!0)}else X(),this.Na=this.tb=q(),this.Ya=!1};
f.ka=function(){this.g=this.A.g;if(!this.A.F)this.a.debug("TestConnection: request failed, in state "+this.c),0==this.c?X():2==this.c&&X(),zd(this.b,this);else if(0==this.c)this.a.debug("TestConnection: request complete for initial check"),this.va?(this.c=1,ud(this)):(this.c=2,vd(this));else if(2==this.c){this.a.debug("TestConnection: request complete for stage 2");var a=!1;(a=ad()?this.Ya:200>this.tb-this.Na?!1:!0)?(this.a.debug("Test connection succeeded; using streaming connection"),X(),xd(this.b,
this,!0)):(this.a.debug("Test connection failed; not using streaming"),X(),xd(this.b,this,!1))}};f.bb=function(){return this.b.bb()};f.isActive=function(){return this.b.isActive()};f.H=function(a){this.b.H(a)};function Ad(a,b,c){this.Db=a||null;this.c=Bd;this.t=[];this.Q=[];this.a=new M;this.P=new Xb(0,!0);this.Ib=b||null;this.Fc=null!=c?c:null}function Cd(a,b){this.Qb=a;this.map=b}f=Ad.prototype;f.v=null;f.ya=null;f.p=null;f.i=null;f.I=null;f.Oa=null;f.Bb=null;f.L=null;f.jc=!0;f.Ca=0;f.uc=0;f.Ma=!1;f.e=null;f.G=null;f.M=null;f.$=null;f.U=null;f.yb=null;f.ic=!0;f.Aa=-1;f.Pb=-1;f.g=-1;f.aa=0;f.ga=0;f.kc=5E3;f.Ec=1E4;f.rb=2;f.Jb=2E4;f.ma=0;f.cb=!1;f.ha=8;var Bd=1,Dd=new S;
function Ed(a){P.call(this,"statevent",a)}r(Ed,P);function Fd(a,b){P.call(this,"timingevent",a);this.size=b}r(Fd,P);var fd=1,hd=2,gd=3,od=4;function Gd(a){P.call(this,"serverreachability",a)}r(Gd,P);var Wb="y2f%";f=Ad.prototype;f.mb=function(a,b,c,d,e){this.a.debug("connect()");X();this.I=b;this.ya=c||{};d&&void 0!==e&&(this.ya.OSID=d,this.ya.OAID=e);this.a.debug("connectTest_()");Id(this)&&(this.U=new sd(this,this.a),this.U.X(this.v),this.U.cc(this.P),this.U.mb(a))};
f.disconnect=function(){this.a.debug("disconnect()");Jd(this);if(3==this.c){var a=this.Ca++,b=this.Oa.n();F(b,"SID",this.Y);F(b,"RID",a);F(b,"TYPE","terminate");Kd(this,b);a=new V(this,this.a,this.Y,a,void 0);a.sa=2;a.T=G(b.n());b=new Image;b.src=a.T;b.onload=b.onerror=p(a.pc,a);a.Ea=q();ed(a)}Ld(this)};function Jd(a){a.U&&(a.U.abort(),a.U=null);a.i&&(a.i.cancel(),a.i=null);a.M&&(k.clearTimeout(a.M),a.M=null);Md(a);a.p&&(a.p.cancel(),a.p=null);a.G&&(k.clearTimeout(a.G),a.G=null)}
f.X=function(a){this.v=a};f.dc=function(a){this.ma=a};f.Nb=function(){return 0==this.c};f.cc=function(a){this.P=a};function Nd(a){a.p||a.G||(a.G=Y(p(a.Vb,a),0),a.aa=0)}
f.Vb=function(a){this.G=null;this.a.debug("startForwardChannel_");if(Id(this))if(this.c==Bd)if(a)this.a.J("Not supposed to retry the open");else{this.a.debug("open_()");this.Ca=Math.floor(1E5*Math.random());a=this.Ca++;var b=new V(this,this.a,"",a,void 0);b.X(this.v);var c=Od(this),d=this.Oa.n();F(d,"RID",a);this.Db&&F(d,"CVER",this.Db);Kd(this,d);bd(b,d,c);this.p=b;this.c=2}else 3==this.c&&(a?Pd(this,a):0==this.t.length?this.a.debug("startForwardChannel_ returned: nothing to send"):this.p?this.a.J("startForwardChannel_ returned: connection already in progress"):
(Pd(this),this.a.debug("startForwardChannel_ finished, sent request")))};function Pd(a,b){var c,d;b?6<a.ha?(a.t=a.Q.concat(a.t),a.Q.length=0,c=a.Ca-1,d=Od(a)):(c=b.B,d=b.W):(c=a.Ca++,d=Od(a));var e=a.Oa.n();F(e,"SID",a.Y);F(e,"RID",c);F(e,"AID",a.Aa);Kd(a,e);c=new V(a,a.a,a.Y,c,a.aa+1);c.X(a.v);c.setTimeout(Math.round(0.5*a.Jb)+Math.round(0.5*a.Jb*Math.random()));a.p=c;bd(c,e,d)}function Kd(a,b){if(a.e){var c=a.e.getAdditionalParams(a);c&&C(c,function(a,c){F(b,c,a)})}}
function Od(a){var b=Math.min(a.t.length,1E3),c=["count="+b],d;6<a.ha&&0<b?(d=a.t[0].Qb,c.push("ofs="+d)):d=0;for(var e=0;e<b;e++){var g=a.t[e].Qb,h=a.t[e].map,g=6>=a.ha?e:g-d;try{C(h,function(a,b){c.push("req"+g+"_"+b+"="+encodeURIComponent(a))})}catch(l){c.push("req"+g+"_type="+encodeURIComponent("_badmap")),a.e&&a.e.badMapError(a,h)}}a.Q=a.Q.concat(a.t.splice(0,b));return c.join("&")}function Qd(a){a.i||a.M||(a.Ab=1,a.M=Y(p(a.Ub,a),0),a.ga=0)}
function Rd(a){if(a.i||a.M)return a.a.J("Request already in progress"),!1;if(3<=a.ga)return!1;a.a.debug("Going to retry GET");a.Ab++;a.M=Y(p(a.Ub,a),Sd(a,a.ga));a.ga++;return!0}
f.Ub=function(){this.M=null;if(Id(this)){this.a.debug("Creating new HttpRequest");this.i=new V(this,this.a,this.Y,"rpc",this.Ab);this.i.X(this.v);this.i.dc(this.ma);var a=this.Bb.n();F(a,"RID","rpc");F(a,"SID",this.Y);F(a,"CI",this.yb?"0":"1");F(a,"AID",this.Aa);Kd(this,a);if(ad())F(a,"TYPE","xmlhttp"),dd(this.i,a,!0,this.L,!1);else{F(a,"TYPE","html");var b=this.i,c=Boolean(this.L);b.sa=3;b.T=G(a.n());nd(b,c)}this.a.debug("New Request created")}};
function Id(a){if(a.e){var b=a.e.okToMakeRequest(a);if(0!=b)return a.a.debug("Handler returned error code from okToMakeRequest"),Z(a,b),!1}return!0}function xd(a,b,c){a.a.debug("Test Connection Finished");a.yb=a.ic&&c;a.g=b.g;a.a.debug("connectChannel_()");a.nc(Bd,0);a.Oa=td(a,a.I);Nd(a)}function zd(a,b){a.a.debug("Test Connection Failed");a.g=b.g;Z(a,2)}
f.Tb=function(a,b){if(0!=this.c&&(this.i==a||this.p==a))if(this.g=a.g,this.p==a&&3==this.c)if(7<this.ha){var c;try{c=this.P.parse(b)}catch(d){c=null}if(m(c)&&3==c.length){var e=c;if(0==e[0])a:if(this.a.debug("Server claims our backchannel is missing."),this.M)this.a.debug("But we are currently starting the request.");else{if(this.i)if(this.i.Ea+3E3<this.p.Ea)Md(this),this.i.cancel(),this.i=null;else break a;else this.a.fa("We do not have a BackChannel established");Rd(this);X()}else this.Pb=e[1],
c=this.Pb-this.Aa,0<c&&(e=e[2],this.a.debug(e+" bytes (in "+c+" arrays) are outstanding on the BackChannel"),37500>e&&this.yb&&0==this.ga&&!this.$&&(this.$=Y(p(this.vc,this),6E3)))}else this.a.debug("Bad POST response data returned"),Z(this,11)}else b!=Wb&&(this.a.debug("Bad data returned - missing/invald magic cookie"),Z(this,11));else if(this.i==a&&Md(this),!/^[\s\xa0]*$/.test(b)){c=this.P.parse(b);for(var e=this.e&&this.e.channelHandleMultipleArrays?[]:null,g=0;g<c.length;g++){var h=c[g];this.Aa=
h[0];h=h[1];2==this.c?"c"==h[0]?(this.Y=h[1],this.L=this.correctHostPrefix(h[2]),h=h[3],this.ha=null!=h?h:6,this.c=3,this.e&&this.e.channelOpened(this),this.Bb=yd(this,this.L,this.I),Qd(this)):"stop"==h[0]&&Z(this,7):3==this.c&&("stop"==h[0]?(e&&0!=e.length&&(this.e.channelHandleMultipleArrays(this,e),e.length=0),Z(this,7)):"noop"!=h[0]&&(e?e.push(h):this.e&&this.e.channelHandleArray(this,h)),this.ga=0)}e&&0!=e.length&&this.e.channelHandleMultipleArrays(this,e)}};
f.correctHostPrefix=function(a){return this.jc?this.e?this.e.correctHostPrefix(a):a:null};f.vc=function(){null!=this.$&&(this.$=null,this.i.cancel(),this.i=null,Rd(this),X())};function Md(a){null!=a.$&&(k.clearTimeout(a.$),a.$=null)}
f.ka=function(a){this.a.debug("Request complete");var b;if(this.i==a)Md(this),this.i=null,b=2;else if(this.p==a)this.p=null,b=1;else return;this.g=a.g;if(0!=this.c)if(a.F)1==b?(q(),Dd.dispatchEvent(new Fd(Dd,a.W?a.W.length:0)),Nd(this),this.Q.length=0):Qd(this);else{var c=a.Kb();if(3==c||7==c||0==c&&0<this.g)this.a.debug("Not retrying due to error type");else{this.a.debug("Maybe retrying, last error: "+Yc(c,this.g));var d;if(d=1==b)this.p||this.G?(this.a.J("Request already in progress"),d=!1):this.c==
Bd||this.aa>=(this.Ma?0:this.rb)?d=!1:(this.a.debug("Going to retry POST"),this.G=Y(p(this.Vb,this,a),Sd(this,this.aa)),this.aa++,d=!0);if(d||2==b&&Rd(this))return;this.a.debug("Exceeded max number of retries")}this.a.debug("Error: HTTP request failed");switch(c){case 1:Z(this,5);break;case 4:Z(this,10);break;case 3:Z(this,6);break;case 7:Z(this,12);break;default:Z(this,2)}}};function Sd(a,b){var c=a.kc+Math.floor(Math.random()*a.Ec);a.isActive()||(a.a.debug("Inactive channel"),c*=2);return c*b}
f.nc=function(a){if(!(0<=Wa(arguments,this.c)))throw Error("Unexpected channel state: "+this.c);};function Z(a,b){a.a.info("Error code "+b);if(2==b||9==b){var c=null;a.e&&(c=a.e.getNetworkTestImageUri(a));var d=p(a.Gc,a);c||(c=new D("//www.google.com/images/cleardot.gif"),G(c));rd(c.toString(),1E4,d)}else X();Td(a,b)}f.Gc=function(a){a?(this.a.info("Successfully pinged google.com"),X()):(this.a.info("Failed to ping google.com"),X(),Td(this,8))};
function Td(a,b){a.a.debug("HttpChannel: error - "+b);a.c=0;a.e&&a.e.channelError(a,b);Ld(a);Jd(a)}function Ld(a){a.c=0;a.g=-1;if(a.e)if(0==a.Q.length&&0==a.t.length)a.e.channelClosed(a);else{a.a.debug("Number of undelivered maps, pending: "+a.Q.length+", outgoing: "+a.t.length);var b=ab(a.Q),c=ab(a.t);a.Q.length=0;a.t.length=0;a.e.channelClosed(a,b,c)}}function td(a,b){var c=wd(a,null,b);a.a.debug("GetForwardChannelUri: "+c);return c}
function yd(a,b,c){b=wd(a,a.bb()?b:null,c);a.a.debug("GetBackChannelUri: "+b);return b}function wd(a,b,c){var d=sb(c);if(""!=d.ia)b&&fb(d,b+"."+d.ia),gb(d,d.Da);else var e=window.location,d=tb(e.protocol,b?b+"."+e.hostname:e.hostname,e.port,c);a.ya&&C(a.ya,function(a,b){F(d,b,a)});F(d,"VER",a.ha);Kd(a,d);return d}f.nb=function(a){if(a&&!this.cb)throw Error("Can't create secondary domain capable XhrIo object.");a=new Fc;a.fc=this.cb;return a};f.isActive=function(){return!!this.e&&this.e.isActive(this)};
function Y(a,b){if(!fa(a))throw Error("Fn must not be null and must be a function");return k.setTimeout(function(){a()},b)}f.H=function(){Dd.dispatchEvent(new Gd(Dd))};function X(){Dd.dispatchEvent(new Ed(Dd))}f.bb=function(){return this.cb||!ad()};function Ud(){}f=Ud.prototype;f.channelHandleMultipleArrays=null;f.okToMakeRequest=function(){return 0};f.channelOpened=function(){};f.channelHandleArray=function(){};f.channelError=function(){};f.channelClosed=function(){};f.getAdditionalParams=function(){return{}};
f.getNetworkTestImageUri=function(){return null};f.isActive=function(){return!0};f.badMapError=function(){};f.correctHostPrefix=function(a){return a};var $,Vd,Wd=[].slice;Vd={0:"Ok",4:"User is logging out",6:"Unknown session ID",7:"Stopped by server",8:"General network error",2:"Request failed",9:"Blocked by a network administrator",5:"No data from server",10:"Got bad data from the server",11:"Got a bad response from the server"};
$=function(a,b){var c,d,e,g,h,l,u,s,v,t,K;s=this;a||(a="channel");a.match(/:\/\//)&&a.replace(/^ws/,"http");b||(b={});m(b||"string"===typeof b)&&(b={});l=b.reconnectTime||3E3;null!==b.affinity&&(b.extraParams||(b.extraParams={}),b.affinityParam||(b.affinityParam="a"),this.affinity=b.affinity||sa(),b.extraParams[b.affinityParam]=this.affinity);K=function(a){s.readyState=s.readyState=a};K(this.CLOSED);t=null;g=b.Kc;c=function(){var a,b;b=arguments[0];a=2<=arguments.length?Wd.call(arguments,1):[];try{return"function"===
typeof s[b]?s[b].apply(s,a):void 0}catch(c){throw a=c,"undefined"!==typeof console&&null!==console&&console.error(a.stack),a;}};d=new Ud;d.channelOpened=function(){g=t;K($.OPEN);return c("onopen")};e=null;d.channelError=function(a,b){var d;d=Vd[b];e=b;s.readyState!==$.CLOSED&&K($.jb);try{return c("onerror",d,b)}catch(g){}};u=null;d.channelClosed=function(a,d,g){var v;if(s.readyState!==$.CLOSED){t=null;a=e?Vd[e]:"Closed";K($.CLOSED);b.reconnect&&7!==e&&0!==e&&(v=6===e?0:l,clearTimeout(u),u=setTimeout(h,
v));try{c("onclose",a,d,g)}catch(Xd){}return e=null}};d.channelHandleArray=function(a,b){return c("onmessage",b)};h=function(){if(t)throw Error("Reconnect() called from invalid state");K($.CONNECTING);c("onconnecting");clearTimeout(u);t=new Ad(b.appVersion,null!=g?g.Ib:void 0);b.crossDomainXhr&&(t.cb=!0);t.e=d;e=null;if(b.failFast){var h=t;h.Ma=!0;h.a.info("setFailFast: true");(h.p||h.G)&&h.aa>(h.Ma?0:h.rb)&&(h.a.info("Retry count "+h.aa+" > new maxRetries "+(h.Ma?0:h.rb)+". Fail immediately!"),h.p?
(h.p.cancel(),h.ka(h.p)):(k.clearTimeout(h.G),h.G=null,Z(h,2)))}return t.mb(""+a+"/test",""+a+"/bind",b.extraParams,null!=g?g.Y:void 0,null!=g?g.Aa:void 0)};this.open=function(){if(s.readyState!==s.CLOSED)throw Error("Already open");return h()};this.close=function(){clearTimeout(u);e=0;if(s.readyState!==$.CLOSED)return K($.jb),t.disconnect()};this.sendMap=v=function(a){var b;if((b=s.readyState)===$.jb||b===$.CLOSED)throw Error("Cannot send to a closed connection");b=t;if(0==b.c)throw Error("Invalid operation: sending map when state is closed");
1E3==b.t.length&&b.a.J("Already have 1000 queued maps upon queueing "+xb(a));b.t.push(new Cd(b.uc++,a));2!=b.c&&3!=b.c||Nd(b)};this.send=function(a){return"string"===typeof a?v({_S:a}):v({JSON:xb(a)})};h();return this};$.prototype.CONNECTING=$.CONNECTING=$.CONNECTING=0;$.prototype.OPEN=$.OPEN=$.OPEN=1;$.prototype.CLOSING=$.CLOSING=$.jb=2;$.prototype.CLOSED=$.CLOSED=$.CLOSED=3;("undefined"!==typeof exports&&null!==exports?exports:window).BCSocket=$;
})();
;(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S=[].slice,x=function(e,t){return function(){return e.apply(t,arguments)}},T=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};window.sharejs=c={version:"0.6.3"},v=function(e){return setTimeout(e,0)},r=function(){function e(){}return e.prototype.on=function(e,t){var n;return this._events||(this._events={}),(n=this._events)[e]||(n[e]=[]),this._events[e].push(t),this},e.prototype.removeListener=function(e,t){var n,r,i,s=this;this._events||(this._events={}),r=(i=this._events)[e]||(i[e]=[]),n=0;while(n<r.length)r[n]===t&&(r[n]=void 0),n++;return v(function(){var t;return s._events[e]=function(){var n,r,i=this._events[e],s=[];for(n=0,r=i.length;n<r;n++)t=i[n],t&&s.push(t);return s}.call(s)}),this},e.prototype.emit=function(){var e,t,n,r,i,s=arguments[0],o=2<=arguments.length?S.call(arguments,1):[];if((r=this._events)!=null?!r[s]:!void 0)return this;i=this._events[s];for(t=0,n=i.length;t<n;t++)e=i[t],e&&e.apply(this,o);return this},e.prototype.once=function(e,t){var n,r=this;return this.on(e,n=function(){var i=1<=arguments.length?S.call(arguments,0):[];return r.removeListener(e,n),t.apply(r,i)})},e}(),r.mixin=function(e){var t=e.prototype||e;return t.on=r.prototype.on,t.removeListener=r.prototype.removeListener,t.emit=r.prototype.emit,t.once=r.prototype.once,e},c._bt=a=function(e,t,n,r){var i,s=function(e,n,r,i){return t(r,e,n,"left"),t(i,n,e,"right")};return e.transformX=e.transformX=i=function(e,t){var o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T;n(e),n(t),l=[];for(v=0,b=t.length;v<b;v++){d=t[v],f=[],o=0;while(o<e.length){c=[],s(e[o],d,f,c),o++;if(c.length!==1){if(c.length===0){x=e.slice(o);for(m=0,w=x.length;m<w;m++)u=x[m],r(f,u);d=null;break}T=i(e.slice(o),c),a=T[0],p=T[1];for(g=0,E=a.length;g<E;g++)u=a[g],r(f,u);for(y=0,S=p.length;y<S;y++)h=p[y],r(l,h);d=null;break}d=c[0]}d!=null&&r(l,d),e=f}return[e,l]},e.transform=e.transform=function(e,n,r){var s,o,u,a,f;if(r!=="left"&&r!=="right")throw new Error("type must be 'left' or 'right'");return n.length===0?e:e.length===1&&n.length===1?t([],e[0],n[0],r):r==="left"?(a=i(e,n),s=a[0],u=a[1],s):(f=i(n,e),u=f[0],o=f[1],o)}},y={},y.name="text",y.create=function(){return""},g=function(e,t,n){return e.slice(0,t)+n+e.slice(t)},f=function(e){var t,n;if(typeof e.p!="number")throw new Error("component missing position field");n=typeof e.i,t=typeof e.d;if(!(n==="string"^t==="string"))throw new Error("component needs an i or d field");if(!(e.p>=0))throw new Error("position cannot be negative")},l=function(e){var t,n,r;for(n=0,r=e.length;n<r;n++)t=e[n],f(t);return!0},y.apply=function(e,t){var n,r,i,s;l(t);for(i=0,s=t.length;i<s;i++){n=t[i];if(n.i!=null)e=g(e,n.p,n.i);else{r=e.slice(n.p,n.p+n.d.length);if(n.d!==r)throw new Error("Delete component '"+n.d+"' does not match deleted text '"+r+"'");e=e.slice(0,n.p)+e.slice(n.p+n.d.length)}}return e},y._append=u=function(e,t){var n,r,i;if(t.i===""||t.d==="")return;return e.length===0?e.push(t):(n=e[e.length-1],n.i!=null&&t.i!=null&&n.p<=(r=t.p)&&r<=n.p+n.i.length?e[e.length-1]={i:g(n.i,t.p-n.p,t.i),p:n.p}:n.d!=null&&t.d!=null&&t.p<=(i=n.p)&&i<=t.p+t.d.length?e[e.length-1]={d:g(t.d,n.p-t.p,n.d),p:t.p}:e.push(t))},y.compose=function(e,t){var n,r,i,s;l(e),l(t),r=e.slice();for(i=0,s=t.length;i<s;i++)n=t[i],u(r,n);return r},y.compress=function(e){return y.compose([],e)},y.normalize=function(e){var t,n,r,i,s=[];if(e.i!=null||e.p!=null)e=[e];for(n=0,r=e.length;n<r;n++)t=e[n],(i=t.p)==null&&(t.p=0),u(s,t);return s},w=function(e,t,n){return t.i!=null?t.p<e||t.p===e&&n?e+t.i.length:e:e<=t.p?e:e<=t.p+t.d.length?t.p:e-t.d.length},y.transformCursor=function(e,t,n){var r,i,s,o=n==="right";for(i=0,s=t.length;i<s;i++)r=t[i],e=w(e,r,o);return e},y._tc=b=function(e,t,n,r){var i,s,o,a,f,c;l([t]),l([n]);if(t.i!=null)u(e,{i:t.i,p:w(t.p,n,r==="right")});else if(n.i!=null)c=t.d,t.p<n.p&&(u(e,{d:c.slice(0,n.p-t.p),p:t.p}),c=c.slice(n.p-t.p)),c!==""&&u(e,{d:c,p:t.p+n.i.length});else if(t.p>=n.p+n.d.length)u(e,{d:t.d,p:t.p-n.d.length});else if(t.p+t.d.length<=n.p)u(e,t);else{a={d:"",p:t.p},t.p<n.p&&(a.d=t.d.slice(0,n.p-t.p)),t.p+t.d.length>n.p+n.d.length&&(a.d+=t.d.slice(n.p+n.d.length-t.p)),o=Math.max(t.p,n.p),s=Math.min(t.p+t.d.length,n.p+n.d.length),i=t.d.slice(o-t.p,s-t.p),f=n.d.slice(o-n.p,s-n.p);if(i!==f)throw new Error("Delete ops delete different text in the same region of the document");a.d!==""&&(a.p=w(a.p,n),u(e,a))}return e},d=function(e){return e.i!=null?{d:e.i,p:e.p}:{i:e.d,p:e.p}},y.invert=function(e){var t,n,r,i=e.slice().reverse(),s=[];for(n=0,r=i.length;n<r;n++)t=i[n],s.push(d(t));return s},c.types||(c.types={}),a(y,b,l,u),c.types.text=y,y.api={provides:{text:!0},getLength:function(){return this.snapshot.length},getText:function(){return this.snapshot},insert:function(e,t,n){var r=[{p:e,i:t}];return this.submitOp(r,n),r},del:function(e,t,n){var r=[{p:e,d:this.snapshot.slice(e,e+t)}];return this.submitOp(r,n),r},_register:function(){return this.on("remoteop",function(e){var t,n,r,i=[];for(n=0,r=e.length;n<r;n++)t=e[n],t.i!==void 0?i.push(this.emit("insert",t.p,t.i)):i.push(this.emit("delete",t.p,t.d));return i})}},c.extendDoc=function(e,t){return n.prototype[e]=t},n=function(){function e(e,t,n){this.connection=e,this.name=t,this.shout=x(this.shout,this),this.flush=x(this.flush,this),n||(n={}),this.version=n.v,this.snapshot=n.snaphot,n.type&&this._setType(n.type),this.state="closed",this.autoOpen=!1,this._create=n.create,this.inflightOp=null,this.inflightCallbacks=[],this.inflightSubmittedIds=[],this.pendingOp=null,this.pendingCallbacks=[],this.serverOps={}}return e.prototype._xf=function(e,t){var n,r;return this.type.transformX?this.type.transformX(e,t):(n=this.type.transform(e,t,"left"),r=this.type.transform(t,e,"right"),[n,r])},e.prototype._otApply=function(e,t){var n=this.snapshot;this.snapshot=this.type.apply(this.snapshot,e),this.emit("change",e,n);if(t)return this.emit("remoteop",e,n)},e.prototype._connectionStateChanged=function(e,t){switch(e){case"disconnected":this.state="closed",this.inflightOp&&this.inflightSubmittedIds.push(this.connection.id),this.emit("closed");break;case"ok":this.autoOpen&&this.open();break;case"stopped":typeof this._openCallback=="function"&&this._openCallback(t)}return this.emit(e,t)},e.prototype._setType=function(e){var t,n,r;if(this.type)return;typeof e=="string"&&(e=E[e]);if(!e||!e.compose)throw new Error("Support for types without compose() is not implemented");this.type=e;if(e.api){r=e.api;for(t in r)n=r[t],this[t]=n;return typeof this._register=="function"?this._register():void 0}return this.provides={}},e.prototype._onMessage=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w;switch(!1){case e.open!==!0:return this.state="open",this._create=!1,this.created==null&&(this.created=!!e.create),e.type&&this._setType(e.type),e.create?(this.created=!0,this.snapshot=this.type.create()):(this.created!==!0&&(this.created=!1),e.snapshot!==void 0&&(this.snapshot=e.snapshot)),e.meta&&(this.meta=e.meta),e.v!=null&&(this.version=e.v),this.inflightOp?(u={doc:this.name,op:this.inflightOp,v:this.version},this.inflightSubmittedIds.length&&(u.dupIfSource=this.inflightSubmittedIds),this.connection.send(u)):this.flush(),this.emit("open"),typeof this._openCallback=="function"?this._openCallback(null):void 0;case e.open!==!1:return e.error&&(typeof console!="undefined"&&console!==null&&console.error("Could not open document: "+e.error),this.emit("error",e.error),typeof this._openCallback=="function"&&this._openCallback(e.error)),this.state="closed",this.emit("closed"),typeof this._closeCallback=="function"&&this._closeCallback(),this._closeCallback=null;case e.op!==null||r!=="Op already submitted":break;case!(e.op===void 0&&e.v!==void 0||e.op&&(d=e.meta.source,T.call(this.inflightSubmittedIds,d)>=0)):i=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,r=e.error;if(r){this.type.invert?(a=this.type.invert(i),this.pendingOp&&(v=this._xf(this.pendingOp,a),this.pendingOp=v[0],a=v[1]),this._otApply(a,!0)):this.emit("error","Op apply failed ("+r+") and the op could not be reverted"),m=this.inflightCallbacks;for(l=0,h=m.length;l<h;l++)t=m[l],t(r)}else{if(e.v!==this.version)throw new Error("Invalid version from server");this.serverOps[this.version]=i,this.version++,this.emit("acknowledge",i),g=this.inflightCallbacks;for(c=0,p=g.length;c<p;c++)t=g[c],t(null,i)}return this.flush();case!e.op:if(e.v<this.version)return;if(e.doc!==this.name)return this.emit("error","Expected docName '"+this.name+"' but got "+e.doc);if(e.v!==this.version)return this.emit("error","Expected version "+this.version+" but got "+e.v);return s=e.op,this.serverOps[this.version]=s,n=s,this.inflightOp!==null&&(y=this._xf(this.inflightOp,n),this.inflightOp=y[0],n=y[1]),this.pendingOp!==null&&(b=this._xf(this.pendingOp,n),this.pendingOp=b[0],n=b[1]),this.version++,this._otApply(n,!0);case!e.meta:w=e.meta,o=w.path,f=w.value;switch(o!=null?o[0]:void 0){case"shout":return this.emit("shout",f);default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled meta op:",e):void 0}break;default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled document message:",e):void 0}},e.prototype.flush=function(){if(this.connection.state!=="ok"||this.inflightOp!==null||this.pendingOp===null)return;return this.inflightOp=this.pendingOp,this.inflightCallbacks=this.pendingCallbacks,this.pendingOp=null,this.pendingCallbacks=[],this.connection.send({doc:this.name,op:this.inflightOp,v:this.version})},e.prototype.submitOp=function(e,t){return this.type.normalize!=null&&(e=this.type.normalize(e)),this.snapshot=this.type.apply(this.snapshot,e),this.pendingOp!==null?this.pendingOp=this.type.compose(this.pendingOp,e):this.pendingOp=e,t&&this.pendingCallbacks.push(t),this.emit("change",e),setTimeout(this.flush,0)},e.prototype.shout=function(e){return this.connection.send({doc:this.name,meta:{path:["shout"],value:e}})},e.prototype.open=function(e){var t,n=this;this.autoOpen=!0;if(this.state!=="closed")return;return t={doc:this.name,open:!0},this.snapshot===void 0&&(t.snapshot=null),this.type&&(t.type=this.type.name),this.version!=null&&(t.v=this.version),this._create&&(t.create=!0),this.connection.send(t),this.state="opening",this._openCallback=function(t){return n._openCallback=null,typeof e=="function"?e(t):void 0}},e.prototype.close=function(e){return this.autoOpen=!1,this.state==="closed"?typeof e=="function"?e():void 0:(this.connection.send({doc:this.name,open:!1}),this.state="closed",this.emit("closing"),this._closeCallback=e)},e}(),r.mixin(n),c.Doc=n,i=function(){function e(e,t,n){var r,i,s=this;t!=null&&typeof t=="function"?(n=t,t=void 0):typeof n!="function"&&(n=o),this.debug=this.debugAll,this.reconnectInterval=1e3,this.timeoutInterval=2e3,this.forcedClose=!1,this.url=e,this.protocols=t,this.readyState=n.CONNECTING,this.URL=e,i=!1,r=function(e){var t;return s.ws=new n(s.url),s.debug&&console.debug("ReconnectingWebSocket","attempt-connect",s.url),t=setTimeout(function(){return s.debug&&console.debug("ReconnectingWebSocket","connection-timeout",s.url),i=!0,s.ws.close(),i=!1},s.timeoutInterval),s.ws.onopen=function(r){return clearTimeout(t),s.debug&&console.debug("ReconnectingWebSocket","onopen",s.url),s.readyState=n.OPEN,e=!1,s.onopen(r)},s.ws.onclose=function(o){return clearTimeout(t),s.ws=null,s.forcedClose?(s.readyState=n.CLOSED,s.onclose(o)):(s.readyState=n.CONNECTING,s.onconnecting(o),!e&&!i&&(s.debug&&console.debug("ReconnectingWebSocket","onclose",s.url),s.onclose(o)),setTimeout(function(){return r(!0)},s.reconnectInterval))},s.ws.onmessage=function(e){return s.debug&&console.debug("ReconnectingWebSocket","onmessage",s.url,e.data),s.onmessage(e)},s.ws.onerror=function(e){return s.debug&&console.debug("ReconnectingWebSocket","onerror",s.url,e),s.onerror(e)}},r(this.url)}return e.prototype.onopen=function(){},e.prototype.onclose=function(){},e.prototype.onconnecting=function(){},e.prototype.onmessage=function(){},e.prototype.onerror=function(){},e.prototype.send=function(e){if(this.ws)return this.debug&&console.debug("ReconnectingWebSocket","send",this.url,e),this.ws.send(e);throw"INVALID_STATE_ERR : Pausing to reconnect websocket"},e.prototype.close=function(){if(this.ws)return this.forcedClose=!0,this.ws.close()},e.prototype.debugAll=!1,e.prototype.refresh=function(){if(this.ws)return this.ws.close()},e}(),E=c.types,e=window.BCSocket,s=window.SockJS,o=window.WebSocket,e?m="channel":s?m="sockjs":m="websocket",t=function(){function t(t,n){var r=this;this.docs={},this.state="connecting",m==null&&t.match(/^ws:/)&&(m="websocket"),this.socket=function(){switch(m){case"channel":return new e(t,{reconnect:!0});case"sockjs":return new i(t,s);case"websocket":return new i(t);default:return new e(t,{reconnect:!0})}}(),this.socket.onmessage=function(e){var t;if(m==="sockjs"||m==="websocket")e=JSON.parse(e.data);if(e.auth===null)return r.lastError=e.error,r.disconnect(),r.emit("connect failed",e.error);if(e.auth){r.id=e.auth,r.setState("ok");return}return t=e.doc,t!==void 0?r.lastReceivedDoc=t:e.doc=t=r.lastReceivedDoc,r.docs[t]?r.docs[t]._onMessage(e):typeof console!="undefined"&&console!==null?console.error("Unhandled message",e):void 0},this.connected=!1,this.socket.onclose=function(e){r.setState("disconnected",e);if(e==="Closed"||e==="Stopped by server")return r.setState("stopped",r.lastError||e)},this.socket.onerror=function(e){return r.emit("error",e)},this.socket.onopen=function(){return r.send({auth:n?n:null}),r.lastError=r.lastReceivedDoc=r.lastSentDoc=null,r.setState("handshaking")},this.socket.onconnecting=function(){return r.setState("connecting")}}return t.prototype.setState=function(e,t){var n,r,i,s;if(this.state===e)return;this.state=e,e==="disconnected"&&delete this.id,this.emit(e,t),i=this.docs,s=[];for(r in i)n=i[r],s.push(n._connectionStateChanged(e,t));return s},t.prototype.send=function(e){var t;e.doc&&(t=e.doc,t===this.lastSentDoc?delete e.doc:this.lastSentDoc=t);if(m==="sockjs"||m==="websocket")e=JSON.stringify(e);return this.socket.send(e)},t.prototype.disconnect=function(){return this.socket.close()},t.prototype.makeDoc=function(e,t,r){var i,s=this;if(this.docs[e])throw new Error("Doc "+e+" already open");return i=new n(this,e,t),this.docs[e]=i,i.open(function(t){return t&&delete s.docs[e],t||i.on("closed",function(){if(!i.autoOpen)return delete s.docs[e]}),r(t,t?void 0:i)})},t.prototype.openExisting=function(e,t){var n;return this.state==="stopped"?t("connection closed"):this.docs[e]?this._ensureOpenState(this.docs[e],t):n=this.makeDoc(e,{},t)},t.prototype.open=function(e,t,n){var r;if(this.state==="stopped")return n("connection closed");if(this.state==="connecting"){this.on("handshaking",function(){return this.open(e,t,n),n=null});return}typeof t=="function"&&(n=t,t="text"),n||(n=function(){}),typeof t=="string"&&(t=E[t]);if(!t)throw new Error("OT code for document type missing");if(e==null)throw new Error("Server-generated random doc names are not currently supported");if(this.docs[e]){r=this.docs[e],r.type===t?this._ensureOpenState(r,n):n("Type mismatch",r);return}return this.makeDoc(e,{create:!0,type:t.name},n)},t.prototype._ensureOpenState=function(e,t){switch(e.state){case"open":t(null,e);break;case"opening":this.on("open",function(){return t(null,e)});break;case"closed":e.open(function(n){return t(n,n?void 0:e)})}},t}(),r.mixin(t),c.Connection=t,h=window.BCSocket!==void 0,p=window.SockJS!==void 0,h?m="channel":p?m="sockjs":m="websocket",c.open=function(){var e={},n=function(n,r){var i,s,o,u;return n==null&&(o=window.location,u=m==="websocket"?"ws:":o.protocol,n=""+u+"//"+o.host+"/"+m),e[n]||(i=new t(n,r),s=function(){return delete e[n]},i.on("disconnected",s),i.on("connect failed",s),e[n]=i),e[n]},r=function(e){var t,n,r=0,i=e.docs;for(n in i)t=i[n],(t.state!=="closed"||t.autoOpen)&&r++;if(r===0)return e.disconnect()};return function(e,t,i,s){var o,u,a;return typeof i=="function"&&(s=i,i={}),typeof i=="string"&&(i={origin:i}),a=i.origin,o=i.authentication,u=n(a,o),u.open(e,t,function(e,t){return e?(s(e),r(u)):(t.on("closed",function(){return r(u)}),s(null,t))}),u.on("connect failed"),u}}()}).call(this)
;// Generated by CoffeeScript 1.6.2
(function() {
var applyToShareJS;
applyToShareJS = function(editorDoc, delta, doc) {
var delLen, i, rm, startPos, _i, _len, _ref;
startPos = 0;
i = 0;
while (i < delta.from.line) {
startPos += editorDoc.lineInfo(i).text.length + 1;
i++;
}
startPos += delta.from.ch;
if (delta.to.line === delta.from.line && delta.to.ch === delta.from.ch) {
doc.insert(startPos, delta.text.join('\n'));
} else {
delLen = 0;
_ref = delta.removed;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
rm = _ref[_i];
delLen += rm.length;
}
delLen += delta.removed.length - 1;
doc.del(startPos, delLen);
if (delta.text) {
doc.insert(startPos, delta.text.join('\n'));
}
}
if (delta.next) {
return applyToShareJS(editorDoc, delta.next, doc);
}
};
window.sharejs.extendDoc('attach_cm', function(editor, keepEditorContents) {
var check, editorListener, sharedoc, suppress;
if (!this.provides.text) {
throw new Error('Only text documents can be attached to CodeMirror 2 or 3');
}
sharedoc = this;
check = function() {
return window.setTimeout(function() {
var editorText, otText;
editorText = editor.getValue('\n');
otText = sharedoc.getText();
if (editorText !== otText) {
console.error("Text does not match!");
console.error("editor: " + editorText);
console.error("ot: " + otText);
return editor.setValue(sharedoc.getText());
}
}, 0);
};
if (keepEditorContents) {
this.del(0, sharedoc.getText('\n').length);
this.insert(0, editor.getValue());
} else {
editor.setValue(sharedoc.getText());
}
check();
suppress = false;
editorListener = function(ed, change) {
if (suppress) {
return;
}
applyToShareJS(editor, change, sharedoc);
return check();
};
editor.on('change', editorListener);
this.on('insert', function(pos, text) {
suppress = true;
editor.replaceRange(text, editor.posFromIndex(pos));
suppress = false;
return check();
});
this.on('delete', function(pos, text) {
var from, to;
suppress = true;
from = editor.posFromIndex(pos);
to = editor.posFromIndex(pos + text.length);
editor.replaceRange('', from, to);
suppress = false;
return check();
});
this.detach_cm = function() {
editor.off('change', editorListener);
return delete this.detach_cm;
};
});
}).call(this);
;// Generated by CoffeeScript 1.6.2
(function() {
var applyChange;
applyChange = function(doc, oldval, newval) {
var commonEnd, commonStart;
if (oldval === newval) {
return;
}
commonStart = 0;
while (oldval.charAt(commonStart) === newval.charAt(commonStart)) {
commonStart++;
}
commonEnd = 0;
while (oldval.charAt(oldval.length - 1 - commonEnd) === newval.charAt(newval.length - 1 - commonEnd) && commonEnd + commonStart < oldval.length && commonEnd + commonStart < newval.length) {
commonEnd++;
}
if (oldval.length !== commonStart + commonEnd) {
doc.del(commonStart, oldval.length - commonStart - commonEnd);
}
if (newval.length !== commonStart + commonEnd) {
return doc.insert(commonStart, newval.slice(commonStart, newval.length - commonEnd));
}
};
window.sharejs.extendDoc('attach_textarea', function(elem) {
var delete_listener, doc, event, genOp, insert_listener, prevvalue, replaceText, _i, _len, _ref,
_this = this;
doc = this;
elem.value = this.getText();
prevvalue = elem.value;
replaceText = function(newText, transformCursor) {
var newSelection, scrollTop;
newSelection = [transformCursor(elem.selectionStart), transformCursor(elem.selectionEnd)];
scrollTop = elem.scrollTop;
elem.value = newText;
if (elem.scrollTop !== scrollTop) {
elem.scrollTop = scrollTop;
}
if (window.document.activeElement === elem) {
return elem.selectionStart = newSelection[0], elem.selectionEnd = newSelection[1], newSelection;
}
};
this.on('insert', insert_listener = function(pos, text) {
var transformCursor;
transformCursor = function(cursor) {
if (pos < cursor) {
return cursor + text.length;
} else {
return cursor;
}
};
prevvalue = elem.value.replace(/\r\n/g, '\n');
return replaceText(prevvalue.slice(0, pos) + text + prevvalue.slice(pos), transformCursor);
});
this.on('delete', delete_listener = function(pos, text) {
var transformCursor;
transformCursor = function(cursor) {
if (pos < cursor) {
return cursor - Math.min(text.length, cursor - pos);
} else {
return cursor;
}
};
prevvalue = elem.value.replace(/\r\n/g, '\n');
return replaceText(prevvalue.slice(0, pos) + prevvalue.slice(pos + text.length), transformCursor);
});
genOp = function(event) {
var onNextTick;
onNextTick = function(fn) {
return setTimeout(fn, 0);
};
return onNextTick(function() {
if (elem.value !== prevvalue) {
prevvalue = elem.value;
return applyChange(doc, doc.getText(), elem.value.replace(/\r\n/g, '\n'));
}
});
};
_ref = ['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
if (elem.addEventListener) {
elem.addEventListener(event, genOp, false);
} else {
elem.attachEvent('on' + event, genOp);
}
}
return elem.detach_share = function() {
var _j, _len1, _ref1, _results;
_this.removeListener('insert', insert_listener);
_this.removeListener('delete', delete_listener);
_ref1 = ['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste'];
_results = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
event = _ref1[_j];
if (elem.removeEventListener) {
_results.push(elem.removeEventListener(event, genOp, false));
} else {
_results.push(elem.detachEvent('on' + event, genOp));
}
}
return _results;
};
});
}).call(this);
;(function(){var e,t,n,r,i,s,o,u,a,f=!0,l=[].slice,c=window.sharejs;typeof f!="undefined"&&f!==null?u=c.types.text:u=require("./text"),s={},s.name="json",s.create=function(){return null},s.invertComponent=function(e){var t={p:e.p};return e.si!==void 0&&(t.sd=e.si),e.sd!==void 0&&(t.si=e.sd),e.oi!==void 0&&(t.od=e.oi),e.od!==void 0&&(t.oi=e.od),e.li!==void 0&&(t.ld=e.li),e.ld!==void 0&&(t.li=e.ld),e.na!==void 0&&(t.na=-e.na),e.lm!==void 0&&(t.lm=e.p[e.p.length-1],t.p=e.p.slice(0,e.p.length-1).concat([e.lm])),t},s.invert=function(e){var t,n,r,i=e.slice().reverse(),o=[];for(n=0,r=i.length;n<r;n++)t=i[n],o.push(s.invertComponent(t));return o},s.checkValidOp=function(){},i=function(e){return Object.prototype.toString.call(e)==="[object Array]"},s.checkList=function(e){if(!i(e))throw new Error("Referenced element not a list")},s.checkObj=function(e){if(e.constructor!==Object)throw new Error("Referenced element not an object (it was "+JSON.stringify(e)+")")},s.apply=function(e,n){var r,i,o,u,a,f,l,c,h,p,d,v,m,g,y;s.checkValidOp(n),n=t(n),i={data:t(e)};try{for(f=d=0,m=n.length;d<m;f=++d){r=n[f],h=null,p=null,u=i,l="data",y=r.p;for(v=0,g=y.length;v<g;v++){c=y[v],h=u,p=l,u=u[l],l=c;if(h==null)throw new Error("Path invalid")}if(r.na!==void 0){if(typeof u[l]!="number")throw new Error("Referenced element not a number");u[l]+=r.na}else if(r.si!==void 0){if(typeof u!="string")throw new Error("Referenced element not a string (it was "+JSON.stringify(u)+")");h[p]=u.slice(0,l)+r.si+u.slice(l)}else if(r.sd!==void 0){if(typeof u!="string")throw new Error("Referenced element not a string");if(u.slice(l,l+r.sd.length)!==r.sd)throw new Error("Deleted string does not match");h[p]=u.slice(0,l)+u.slice(l+r.sd.length)}else if(r.li!==void 0&&r.ld!==void 0)s.checkList(u),u[l]=r.li;else if(r.li!==void 0)s.checkList(u),u.splice(l,0,r.li);else if(r.ld!==void 0)s.checkList(u),u.splice(l,1);else if(r.lm!==void 0)s.checkList(u),r.lm!==l&&(o=u[l],u.splice(l,1),u.splice(r.lm,0,o));else if(r.oi!==void 0)s.checkObj(u),u[l]=r.oi;else{if(r.od===void 0)throw new Error("invalid / missing instruction in op");s.checkObj(u),delete u[l]}}}catch(b){throw a=b,a}return i.data},s.pathMatches=function(e,t,n){var r,i,s,o;if(e.length!==t.length)return!1;for(r=s=0,o=e.length;s<o;r=++s){i=e[r];if(i!==t[r]&&(!n||r!==e.length-1))return!1}return!0},s.append=function(e,n){var r;return n=t(n),e.length!==0&&s.pathMatches(n.p,(r=e[e.length-1]).p)?r.na!==void 0&&n.na!==void 0?e[e.length-1]={p:r.p,na:r.na+n.na}:r.li!==void 0&&n.li===void 0&&n.ld===r.li?r.ld!==void 0?delete r.li:e.pop():r.od!==void 0&&r.oi===void 0&&n.oi!==void 0&&n.od===void 0?r.oi=n.oi:n.lm!==void 0&&n.p[n.p.length-1]===n.lm?null:e.push(n):e.push(n)},s.compose=function(e,n){var r,i,o,u;s.checkValidOp(e),s.checkValidOp(n),i=t(e);for(o=0,u=n.length;o<u;o++)r=n[o],s.append(i,r);return i},s.normalize=function(e){var t,n,r,o,u=[];i(e)||(e=[e]);for(n=0,r=e.length;n<r;n++)t=e[n],(o=t.p)==null&&(t.p=[]),s.append(u,t);return u},t=function(e){return JSON.parse(JSON.stringify(e))},s.canOpAffectOp=function(e,t){var n,r,i,s;if(e.length===0)return!0;if(t.length===0)return!1;t=t.slice(0,t.length-1),e=e.slice(0,e.length-1);for(n=i=0,s=e.length;i<s;n=++i){r=e[n];if(n>=t.length)return!1;if(r!==t[n])return!1}return!0},s.transformComponent=function(e,n,r,i){var o,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N;n=t(n),n.na!==void 0&&n.p.push(0),r.na!==void 0&&r.p.push(0),s.canOpAffectOp(r.p,n.p)&&(o=r.p.length-1),s.canOpAffectOp(n.p,r.p)&&(a=n.p.length-1),c=n.p.length,v=r.p.length,n.na!==void 0&&n.p.pop(),r.na!==void 0&&r.p.pop();if(r.na)return a!=null&&v>=c&&r.p[a]===n.p[a]&&(n.ld!==void 0?(d=t(r),d.p=d.p.slice(c),n.ld=s.apply(t(n.ld),[d])):n.od!==void 0&&(d=t(r),d.p=d.p.slice(c),n.od=s.apply(t(n.od),[d]))),s.append(e,n),e;a!=null&&v>c&&n.p[a]===r.p[a]&&(n.ld!==void 0?(d=t(r),d.p=d.p.slice(c),n.ld=s.apply(t(n.ld),[d])):n.od!==void 0&&(d=t(r),d.p=d.p.slice(c),n.od=s.apply(t(n.od),[d])));if(o!=null){f=c===v;if(r.na===void 0)if(r.si!==void 0||r.sd!==void 0){if(n.si!==void 0||n.sd!==void 0){if(!f)throw new Error("must be a string?");l=function(e){var t={p:e.p[e.p.length-1]};return e.si!=null?t.i=e.si:t.d=e.sd,t},E=l(n),S=l(r),b=[],u._tc(b,E,S,i);for(T=0,N=b.length;T<N;T++)w=b[T],p={p:n.p.slice(0,o)},p.p.push(w.p),w.i!=null&&(p.si=w.i),w.d!=null&&(p.sd=w.d),s.append(e,p);return e}}else if(r.li!==void 0&&r.ld!==void 0){if(r.p[o]===n.p[o]){if(!f)return e;if(n.ld!==void 0){if(n.li===void 0||i!=="left")return e;n.ld=t(r.li)}}}else if(r.li!==void 0)n.li!==void 0&&n.ld===void 0&&f&&n.p[o]===r.p[o]?i==="right"&&n.p[o]++:r.p[o]<=n.p[o]&&n.p[o]++,n.lm!==void 0&&f&&r.p[o]<=n.lm&&n.lm++;else if(r.ld!==void 0){if(n.lm!==void 0&&f){if(r.p[o]===n.p[o])return e;y=r.p[o],h=n.p[o],x=n.lm,(y<x||y===x&&h<x)&&n.lm--}if(r.p[o]<n.p[o])n.p[o]--;else if(r.p[o]===n.p[o]){if(v<c)return e;if(n.ld!==void 0){if(n.li===void 0)return e;delete n.ld}}}else if(r.lm!==void 0)if(n.lm!==void 0&&c===v){h=n.p[o],x=n.lm,m=r.p[o],g=r.lm;if(m!==g)if(h===m){if(i!=="left")return e;n.p[o]=g,h===x&&(n.lm=g)}else h>m&&n.p[o]--,h>g?n.p[o]++:h===g&&m>g&&(n.p[o]++,h===x&&n.lm++),x>m?n.lm--:x===m&&x>h&&n.lm--,x>g?n.lm++:x===g&&(g>m&&x>h||g<m&&x<h?i==="right"&&n.lm++:x>h?n.lm++:x===m&&n.lm--)}else n.li!==void 0&&n.ld===void 0&&f?(h=r.p[o],x=r.lm,y=n.p[o],y>h&&n.p[o]--,y>x&&n.p[o]++):(h=r.p[o],x=r.lm,y=n.p[o],y===h?n.p[o]=x:(y>h&&n.p[o]--,y>x?n.p[o]++:y===x&&h>x&&n.p[o]++));else if(r.oi!==void 0&&r.od!==void 0){if(n.p[o]===r.p[o]){if(n.oi===void 0||!f)return e;if(i==="right")return e;n.od=r.oi}}else if(r.oi!==void 0){if(n.oi!==void 0&&n.p[o]===r.p[o]){if(i!=="left")return e;s.append(e,{p:n.p,od:r.oi})}}else if(r.od!==void 0&&n.p[o]===r.p[o]){if(!f)return e;if(n.oi===void 0)return e;delete n.od}}return s.append(e,n),e},typeof f!="undefined"&&f!==null?(c.types||(c.types={}),c._bt(s,s.transformComponent,s.checkValidOp,s.append),c.types.json=s):(module.exports=s,require("./helpers").bootstrapTransform(s,s.transformComponent,s.checkValidOp,s.append)),typeof f=="undefined"&&(s=require("./json")),typeof f!="undefined"&&f!==null&&(r=c.extendDoc,c.extendDoc=function(t,n){return e.prototype[t]=n,r(t,n)}),n=function(e){return e.length===1&&e[0].constructor===Array?e[0]:e},e=function(){function e(e,t){this.doc=e,this.path=t}return e.prototype.at=function(){var e=1<=arguments.length?l.call(arguments,0):[];return this.doc.at(this.path.concat(n(e)))},e.prototype.parent=function(){return this.path.length?this.doc.at(this.path.slice(0,this.path.length-1)):void 0},e.prototype.get=function(){return this.doc.getAt(this.path)},e.prototype.set=function(e,t){return this.doc.setAt(this.path,e,t)},e.prototype.insert=function(e,t,n){return this.doc.insertAt(this.path,e,t,n)},e.prototype.del=function(e,t,n){return this.doc.deleteTextAt(this.path,t,e,n)},e.prototype.remove=function(e){return this.doc.removeAt(this.path,e)},e.prototype.push=function(e,t){return this.insert(this.get().length,e,t)},e.prototype.move=function(e,t,n){return this.doc.moveAt(this.path,e,t,n)},e.prototype.add=function(e,t){return this.doc.addAt(this.path,e,t)},e.prototype.on=function(e,t){return this.doc.addListener(this.path,e,t)},e.prototype.removeListener=function(e){return this.doc.removeListener(e)},e.prototype.getLength=function(){return this.get().length},e.prototype.getText=function(){return this.get()},e}(),a=function(e,t){var n,r,i,s={data:e},o="data",u=s;for(r=0,i=t.length;r<i;r++){n=t[r],u=u[o],o=n;if(typeof u=="undefined")throw new Error("bad path")}return{elem:u,key:o}},o=function(e,t){var n,r,i,s;if(e.length!==t.length)return!1;for(r=i=0,s=e.length;i<s;r=++i){n=e[r];if(n!==t[r])return!1}return!0},s.api={provides:{json:!0},at:function(){var t=1<=arguments.length?l.call(arguments,0):[];return new e(this,n(t))},get:function(){return this.snapshot},set:function(e,t){return this.setAt([],e,t)},getAt:function(e){var t=a(this.snapshot,e),n=t.elem,r=t.key;return n[r]},setAt:function(e,t,n){var r=a(this.snapshot,e),i=r.elem,s=r.key,o={p:e};if(i.constructor===Array)o.li=t,typeof i[s]!="undefined"&&(o.ld=i[s]);else{if(typeof i!="object")throw new Error("bad path");o.oi=t,typeof i[s]!="undefined"&&(o.od=i[s])}return this.submitOp([o],n)},removeAt:function(e,t){var n,r=a(this.snapshot,e),i=r.elem,s=r.key;if(typeof i[s]=="undefined")throw new Error("no element at that path");n={p:e};if(i.constructor===Array)n.ld=i[s];else{if(typeof i!="object")throw new Error("bad path");n.od=i[s]}return this.submitOp([n],t)},insertAt:function(e,t,n,r){var i=a(this.snapshot,e),s=i.elem,o=i.key,u={p:e.concat(t)};return s[o].constructor===Array?u.li=n:typeof s[o]=="string"&&(u.si=n),this.submitOp([u],r)},moveAt:function(e,t,n,r){var i=[{p:e.concat(t),lm:n}];return this.submitOp(i,r)},addAt:function(e,t,n){var r=[{p:e,na:t}];return this.submitOp(r,n)},deleteTextAt:function(e,t,n,r){var i=a(this.snapshot,e),s=i.elem,o=i.key,u=[{p:e.concat(n),sd:s[o].slice(n,n+t)}];return this.submitOp(u,r)},addListener:function(e,t,n){var r={path:e,event:t,cb:n};return this._listeners.push(r),r},removeListener:function(e){var t=this._listeners.indexOf(e);return t<0?!1:(this._listeners.splice(t,1),!0)},_register:function(){return this._listeners=[],this.on("change",function(e){var t,n,r,i,s,o,u,a,f,l,c,h=[];for(u=0,f=e.length;u<f;u++){t=e[u];if(t.na!==void 0||t.si!==void 0||t.sd!==void 0)continue;s=[],c=this._listeners;for(r=a=0,l=c.length;a<l;r=++a){i=c[r],n={p:i.path,na:0},o=this.type.transformComponent([],n,t,"left");if(o.length===0)s.push(r);else{if(o.length!==1)throw new Error("Bad assumption in json-api: xforming an 'si' op will always result in 0 or 1 components.");i.path=o[0].p}}s.sort(function(e,t){return t-e}),h.push(function(){var e,t,n=[];for(e=0,t=s.length;e<t;e++)r=s[e],n.push(this._listeners.splice(r,1));return n}.call(this))}return h}),this.on("remoteop",function(e){var t,n,r,i,s,u,a,f,l=[];for(a=0,f=e.length;a<f;a++)t=e[a],s=t.na===void 0?t.p.slice(0,t.p.length-1):t.p,l.push(function(){var e,a,f,l=this._listeners,c=[];for(e=0,a=l.length;e<a;e++){f=l[e],u=f.path,i=f.event,n=f.cb;if(o(u,s))switch(i){case"insert":t.li!==void 0&&t.ld===void 0?c.push(n(t.p[t.p.length-1],t.li)):t.oi!==void 0&&t.od===void 0?c.push(n(t.p[t.p.length-1],t.oi)):t.si!==void 0?c.push(n(t.p[t.p.length-1],t.si)):c.push(void 0);break;case"delete":t.li===void 0&&t.ld!==void 0?c.push(n(t.p[t.p.length-1],t.ld)):t.oi===void 0&&t.od!==void 0?c.push(n(t.p[t.p.length-1],t.od)):t.sd!==void 0?c.push(n(t.p[t.p.length-1],t.sd)):c.push(void 0);break;case"replace":t.li!==void 0&&t.ld!==void 0?c.push(n(t.p[t.p.length-1],t.ld,t.li)):t.oi!==void 0&&t.od!==void 0?c.push(n(t.p[t.p.length-1],t.od,t.oi)):c.push(void 0);break;case"move":t.lm!==void 0?c.push(n(t.p[t.p.length-1],t.lm)):c.push(void 0);break;case"add":t.na!==void 0?c.push(n(t.na)):c.push(void 0);break;default:c.push(void 0)}else this.type.canOpAffectOp(u,s)?i==="child op"?(r=t.p.slice(u.length),c.push(n(r,t))):c.push(void 0):c.push(void 0)}return c}.call(this));return l})}}}).call(this)