-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathworker-packages.js
More file actions
11 lines (11 loc) · 335 KB
/
worker-packages.js
File metadata and controls
11 lines (11 loc) · 335 KB
1
2
3
4
5
6
7
8
9
10
11
!function(){var e,n;!function(){n={}}.call(this),function(){!function(){var e=this,t=e._,r={},o=Array.prototype,i=Object.prototype,a=Function.prototype,u=o.push,s=o.slice,c=o.concat,l=i.toString,f=i.hasOwnProperty,d=o.forEach,p=o.map,h=o.reduce,v=o.reduceRight,_=o.filter,m=o.every,g=o.some,y=o.indexOf,b=o.lastIndexOf,w=Array.isArray,E=Object.keys,k=a.bind,S=function(e){return e instanceof S?e:this instanceof S?(this._wrapped=e,void 0):new S(e)};"undefined"!=typeof n?("undefined"!=typeof module&&module.exports&&(n=module.exports=S),n._=S):e._=S,S.VERSION="1.5.1";var O=S.each=S.forEach=function(e,n,t){if(null!=e)if(d&&e.forEach===d)e.forEach(n,t);else if(e.length===+e.length){for(var o=0,i=e.length;i>o;o++)if(n.call(t,e[o],o,e)===r)return}else for(var a in e)if(S.has(e,a)&&n.call(t,e[a],a,e)===r)return};S.map=S.collect=function(e,n,t){var r=[];return null==e?r:p&&e.map===p?e.map(n,t):(O(e,function(e,o,i){r.push(n.call(t,e,o,i))}),r)};var T="Reduce of empty array with no initial value";S.reduce=S.foldl=S.inject=function(e,n,t,r){var o=arguments.length>2;if(null==e&&(e=[]),h&&e.reduce===h)return r&&(n=S.bind(n,r)),o?e.reduce(n,t):e.reduce(n);if(O(e,function(e,i,a){o?t=n.call(r,t,e,i,a):(t=e,o=!0)}),!o)throw new TypeError(T);return t},S.reduceRight=S.foldr=function(e,n,t,r){var o=arguments.length>2;if(null==e&&(e=[]),v&&e.reduceRight===v)return r&&(n=S.bind(n,r)),o?e.reduceRight(n,t):e.reduceRight(n);var i=e.length;if(i!==+i){var a=S.keys(e);i=a.length}if(O(e,function(u,s,c){s=a?a[--i]:--i,o?t=n.call(r,t,e[s],s,c):(t=e[s],o=!0)}),!o)throw new TypeError(T);return t},S.find=S.detect=function(e,n,t){var r;return I(e,function(e,o,i){return n.call(t,e,o,i)?(r=e,!0):void 0}),r},S.filter=S.select=function(e,n,t){var r=[];return null==e?r:_&&e.filter===_?e.filter(n,t):(O(e,function(e,o,i){n.call(t,e,o,i)&&r.push(e)}),r)},S.reject=function(e,n,t){return S.filter(e,function(e,r,o){return!n.call(t,e,r,o)},t)},S.every=S.all=function(e,n,t){n||(n=S.identity);var o=!0;return null==e?o:m&&e.every===m?e.every(n,t):(O(e,function(e,i,a){return(o=o&&n.call(t,e,i,a))?void 0:r}),!!o)};var I=S.some=S.any=function(e,n,t){n||(n=S.identity);var o=!1;return null==e?o:g&&e.some===g?e.some(n,t):(O(e,function(e,i,a){return o||(o=n.call(t,e,i,a))?r:void 0}),!!o)};S.contains=S.include=function(e,n){return null==e?!1:y&&e.indexOf===y?-1!=e.indexOf(n):I(e,function(e){return e===n})},S.invoke=function(e,n){var t=s.call(arguments,2),r=S.isFunction(n);return S.map(e,function(e){return(r?n:e[n]).apply(e,t)})},S.pluck=function(e,n){return S.map(e,function(e){return e[n]})},S.where=function(e,n,t){return S.isEmpty(n)?t?void 0:[]:S[t?"find":"filter"](e,function(e){for(var t in n)if(n[t]!==e[t])return!1;return!0})},S.findWhere=function(e,n){return S.where(e,n,!0)},S.max=function(e,n,t){if(!n&&S.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!n&&S.isEmpty(e))return-1/0;var r={computed:-1/0,value:-1/0};return O(e,function(e,o,i){var a=n?n.call(t,e,o,i):e;a>r.computed&&(r={value:e,computed:a})}),r.value},S.min=function(e,n,t){if(!n&&S.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!n&&S.isEmpty(e))return 1/0;var r={computed:1/0,value:1/0};return O(e,function(e,o,i){var a=n?n.call(t,e,o,i):e;a<r.computed&&(r={value:e,computed:a})}),r.value},S.shuffle=function(e){var n,t=0,r=[];return O(e,function(e){n=S.random(t++),r[t-1]=r[n],r[n]=e}),r};var C=function(e){return S.isFunction(e)?e:function(n){return n[e]}};S.sortBy=function(e,n,t){var r=C(n);return S.pluck(S.map(e,function(e,n,o){return{value:e,index:n,criteria:r.call(t,e,n,o)}}).sort(function(e,n){var t=e.criteria,r=n.criteria;if(t!==r){if(t>r||void 0===t)return 1;if(r>t||void 0===r)return-1}return e.index<n.index?-1:1}),"value")};var R=function(e,n,t,r){var o={},i=C(null==n?S.identity:n);return O(e,function(n,a){var u=i.call(t,n,a,e);r(o,u,n)}),o};S.groupBy=function(e,n,t){return R(e,n,t,function(e,n,t){(S.has(e,n)?e[n]:e[n]=[]).push(t)})},S.countBy=function(e,n,t){return R(e,n,t,function(e,n){S.has(e,n)||(e[n]=0),e[n]++})},S.sortedIndex=function(e,n,t,r){t=null==t?S.identity:C(t);for(var o=t.call(r,n),i=0,a=e.length;a>i;){var u=i+a>>>1;t.call(r,e[u])<o?i=u+1:a=u}return i},S.toArray=function(e){return e?S.isArray(e)?s.call(e):e.length===+e.length?S.map(e,S.identity):S.values(e):[]},S.size=function(e){return null==e?0:e.length===+e.length?e.length:S.keys(e).length},S.first=S.head=S.take=function(e,n,t){return null==e?void 0:null==n||t?e[0]:s.call(e,0,n)},S.initial=function(e,n,t){return s.call(e,0,e.length-(null==n||t?1:n))},S.last=function(e,n,t){return null==e?void 0:null==n||t?e[e.length-1]:s.call(e,Math.max(e.length-n,0))},S.rest=S.tail=S.drop=function(e,n,t){return s.call(e,null==n||t?1:n)},S.compact=function(e){return S.filter(e,S.identity)};var N=function(e,n,t){return n&&S.every(e,S.isArray)?c.apply(t,e):(O(e,function(e){S.isArray(e)||S.isArguments(e)?n?u.apply(t,e):N(e,n,t):t.push(e)}),t)};S.flatten=function(e,n){return N(e,n,[])},S.without=function(e){return S.difference(e,s.call(arguments,1))},S.uniq=S.unique=function(e,n,t,r){S.isFunction(n)&&(r=t,t=n,n=!1);var o=t?S.map(e,t,r):e,i=[],a=[];return O(o,function(t,r){(n?r&&a[a.length-1]===t:S.contains(a,t))||(a.push(t),i.push(e[r]))}),i},S.union=function(){return S.uniq(S.flatten(arguments,!0))},S.intersection=function(e){var n=s.call(arguments,1);return S.filter(S.uniq(e),function(e){return S.every(n,function(n){return S.indexOf(n,e)>=0})})},S.difference=function(e){var n=c.apply(o,s.call(arguments,1));return S.filter(e,function(e){return!S.contains(n,e)})},S.zip=function(){for(var e=S.max(S.pluck(arguments,"length").concat(0)),n=new Array(e),t=0;e>t;t++)n[t]=S.pluck(arguments,""+t);return n},S.object=function(e,n){if(null==e)return{};for(var t={},r=0,o=e.length;o>r;r++)n?t[e[r]]=n[r]:t[e[r][0]]=e[r][1];return t},S.indexOf=function(e,n,t){if(null==e)return-1;var r=0,o=e.length;if(t){if("number"!=typeof t)return r=S.sortedIndex(e,n),e[r]===n?r:-1;r=0>t?Math.max(0,o+t):t}if(y&&e.indexOf===y)return e.indexOf(n,t);for(;o>r;r++)if(e[r]===n)return r;return-1},S.lastIndexOf=function(e,n,t){if(null==e)return-1;var r=null!=t;if(b&&e.lastIndexOf===b)return r?e.lastIndexOf(n,t):e.lastIndexOf(n);for(var o=r?t:e.length;o--;)if(e[o]===n)return o;return-1},S.range=function(e,n,t){arguments.length<=1&&(n=e||0,e=0),t=arguments[2]||1;for(var r=Math.max(Math.ceil((n-e)/t),0),o=0,i=new Array(r);r>o;)i[o++]=e,e+=t;return i};var A=function(){};S.bind=function(e,n){var t,r;if(k&&e.bind===k)return k.apply(e,s.call(arguments,1));if(!S.isFunction(e))throw new TypeError;return t=s.call(arguments,2),r=function(){if(!(this instanceof r))return e.apply(n,t.concat(s.call(arguments)));A.prototype=e.prototype;var o=new A;A.prototype=null;var i=e.apply(o,t.concat(s.call(arguments)));return Object(i)===i?i:o}},S.partial=function(e){var n=s.call(arguments,1);return function(){return e.apply(this,n.concat(s.call(arguments)))}},S.bindAll=function(e){var n=s.call(arguments,1);if(0===n.length)throw new Error("bindAll must be passed function names");return O(n,function(n){e[n]=S.bind(e[n],e)}),e},S.memoize=function(e,n){var t={};return n||(n=S.identity),function(){var r=n.apply(this,arguments);return S.has(t,r)?t[r]:t[r]=e.apply(this,arguments)}},S.delay=function(e,n){var t=s.call(arguments,2);return setTimeout(function(){return e.apply(null,t)},n)},S.defer=function(e){return S.delay.apply(S,[e,1].concat(s.call(arguments,1)))},S.throttle=function(e,n,t){var r,o,i,a=null,u=0;t||(t={});var s=function(){u=t.leading===!1?0:new Date,a=null,i=e.apply(r,o)};return function(){var c=new Date;u||t.leading!==!1||(u=c);var l=n-(c-u);return r=this,o=arguments,0>=l?(clearTimeout(a),a=null,u=c,i=e.apply(r,o)):a||t.trailing===!1||(a=setTimeout(s,l)),i}},S.debounce=function(e,n,t){var r,o=null;return function(){var i=this,a=arguments,u=function(){o=null,t||(r=e.apply(i,a))},s=t&&!o;return clearTimeout(o),o=setTimeout(u,n),s&&(r=e.apply(i,a)),r}},S.once=function(e){var n,t=!1;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},S.wrap=function(e,n){return function(){var t=[e];return u.apply(t,arguments),n.apply(this,t)}},S.compose=function(){var e=arguments;return function(){for(var n=arguments,t=e.length-1;t>=0;t--)n=[e[t].apply(this,n)];return n[0]}},S.after=function(e,n){return function(){return--e<1?n.apply(this,arguments):void 0}},S.keys=E||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var n=[];for(var t in e)S.has(e,t)&&n.push(t);return n},S.values=function(e){var n=[];for(var t in e)S.has(e,t)&&n.push(e[t]);return n},S.pairs=function(e){var n=[];for(var t in e)S.has(e,t)&&n.push([t,e[t]]);return n},S.invert=function(e){var n={};for(var t in e)S.has(e,t)&&(n[e[t]]=t);return n},S.functions=S.methods=function(e){var n=[];for(var t in e)S.isFunction(e[t])&&n.push(t);return n.sort()},S.extend=function(e){return O(s.call(arguments,1),function(n){if(n)for(var t in n)e[t]=n[t]}),e},S.pick=function(e){var n={},t=c.apply(o,s.call(arguments,1));return O(t,function(t){t in e&&(n[t]=e[t])}),n},S.omit=function(e){var n={},t=c.apply(o,s.call(arguments,1));for(var r in e)S.contains(t,r)||(n[r]=e[r]);return n},S.defaults=function(e){return O(s.call(arguments,1),function(n){if(n)for(var t in n)void 0===e[t]&&(e[t]=n[t])}),e},S.clone=function(e){return S.isObject(e)?S.isArray(e)?e.slice():S.extend({},e):e},S.tap=function(e,n){return n(e),e};var D=function(e,n,t,r){if(e===n)return 0!==e||1/e==1/n;if(null==e||null==n)return e===n;e instanceof S&&(e=e._wrapped),n instanceof S&&(n=n._wrapped);var o=l.call(e);if(o!=l.call(n))return!1;switch(o){case"[object String]":return e==String(n);case"[object Number]":return e!=+e?n!=+n:0==e?1/e==1/n:e==+n;case"[object Date]":case"[object Boolean]":return+e==+n;case"[object RegExp]":return e.source==n.source&&e.global==n.global&&e.multiline==n.multiline&&e.ignoreCase==n.ignoreCase}if("object"!=typeof e||"object"!=typeof n)return!1;for(var i=t.length;i--;)if(t[i]==e)return r[i]==n;var a=e.constructor,u=n.constructor;if(a!==u&&!(S.isFunction(a)&&a instanceof a&&S.isFunction(u)&&u instanceof u))return!1;t.push(e),r.push(n);var s=0,c=!0;if("[object Array]"==o){if(s=e.length,c=s==n.length)for(;s--&&(c=D(e[s],n[s],t,r)););}else{for(var f in e)if(S.has(e,f)&&(s++,!(c=S.has(n,f)&&D(e[f],n[f],t,r))))break;if(c){for(f in n)if(S.has(n,f)&&!s--)break;c=!s}}return t.pop(),r.pop(),c};S.isEqual=function(e,n){return D(e,n,[],[])},S.isEmpty=function(e){if(null==e)return!0;if(S.isArray(e)||S.isString(e))return 0===e.length;for(var n in e)if(S.has(e,n))return!1;return!0},S.isElement=function(e){return!(!e||1!==e.nodeType)},S.isArray=w||function(e){return"[object Array]"==l.call(e)},S.isObject=function(e){return e===Object(e)},O(["Arguments","Function","String","Number","Date","RegExp"],function(e){S["is"+e]=function(n){return l.call(n)=="[object "+e+"]"}}),S.isArguments(arguments)||(S.isArguments=function(e){return!(!e||!S.has(e,"callee"))}),"function"!=typeof/./&&(S.isFunction=function(e){return"function"==typeof e}),S.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e))},S.isNaN=function(e){return S.isNumber(e)&&e!=+e},S.isBoolean=function(e){return e===!0||e===!1||"[object Boolean]"==l.call(e)},S.isNull=function(e){return null===e},S.isUndefined=function(e){return void 0===e},S.has=function(e,n){return f.call(e,n)},S.noConflict=function(){return e._=t,this},S.identity=function(e){return e},S.times=function(e,n,t){for(var r=Array(Math.max(0,e)),o=0;e>o;o++)r[o]=n.call(t,o);return r},S.random=function(e,n){return null==n&&(n=e,e=0),e+Math.floor(Math.random()*(n-e+1))};var M={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};M.unescape=S.invert(M.escape);var x={escape:new RegExp("["+S.keys(M.escape).join("")+"]","g"),unescape:new RegExp("("+S.keys(M.unescape).join("|")+")","g")};S.each(["escape","unescape"],function(e){S[e]=function(n){return null==n?"":(""+n).replace(x[e],function(n){return M[e][n]})}}),S.result=function(e,n){if(null==e)return void 0;var t=e[n];return S.isFunction(t)?t.call(e):t},S.mixin=function(e){O(S.functions(e),function(n){var t=S[n]=e[n];S.prototype[n]=function(){var e=[this._wrapped];return u.apply(e,arguments),W.call(this,t.apply(S,e))}})};var j=0;S.uniqueId=function(e){var n=++j+"";return e?e+n:n},S.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var U=/(.)^/,P={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},L=/\\|'|\r|\n|\t|\u2028|\u2029/g;S.template=function(e,n,t){var r;t=S.defaults({},t,S.templateSettings);var o=new RegExp([(t.escape||U).source,(t.interpolate||U).source,(t.evaluate||U).source].join("|")+"|$","g"),i=0,a="__p+='";e.replace(o,function(n,t,r,o,u){return a+=e.slice(i,u).replace(L,function(e){return"\\"+P[e]}),t&&(a+="'+\n((__t=("+t+"))==null?'':_.escape(__t))+\n'"),r&&(a+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),o&&(a+="';\n"+o+"\n__p+='"),i=u+n.length,n}),a+="';\n",t.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{r=new Function(t.variable||"obj","_",a)}catch(u){throw u.source=a,u}if(n)return r(n,S);var s=function(e){return r.call(this,e,S)};return s.source="function("+(t.variable||"obj")+"){\n"+a+"}",s},S.chain=function(e){return S(e).chain()};var W=function(e){return this._chain?S(e).chain():e};S.mixin(S),O(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var n=o[e];S.prototype[e]=function(){var t=this._wrapped;return n.apply(t,arguments),"shift"!=e&&"splice"!=e||0!==t.length||delete t[0],W.call(this,t)}}),O(["concat","join","slice"],function(e){var n=o[e];S.prototype[e]=function(){return W.call(this,n.apply(this._wrapped,arguments))}}),S.extend(S.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this)}.call(this),function(){e=n._}.call(this),"undefined"==typeof Package&&(Package={}),Package.underscore={_:e}}(),function(){var e,n=Package.underscore._;!function(){e={isClient:!0,isServer:!1},"object"==typeof __meteor_runtime_config__&&__meteor_runtime_config__.PUBLIC_SETTINGS&&(e.settings={"public":__meteor_runtime_config__.PUBLIC_SETTINGS})}.call(this),function(){if(e.isServer)var t=Npm.require("fibers/future");"object"==typeof __meteor_runtime_config__&&__meteor_runtime_config__.meteorRelease&&(e.release=__meteor_runtime_config__.meteorRelease),n.extend(e,{_get:function(e){for(var n=1;n<arguments.length;n++){if(!(arguments[n]in e))return void 0;e=e[arguments[n]]}return e},_ensure:function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];t in e||(e[t]={}),e=e[t]}return e},_delete:function(e){for(var n=[e],t=!0,r=1;r<arguments.length-1;r++){var o=arguments[r];if(!(o in e)){t=!1;break}if(e=e[o],"object"!=typeof e)break;n.push(e)}for(var r=n.length-1;r>=0;r--){var o=arguments[r+1];if(t)t=!1;else for(var i in n[r][o])return;delete n[r][o]}},_wrapAsync:function(r){return function(){for(var o,i,a=this,u=n.toArray(arguments),s=function(n){return n?e._debug("Exception in callback of async function",n?n.stack:n):void 0};u.length>0&&"undefined"==typeof u[u.length-1];)u.pop();u.length>0&&u[u.length-1]instanceof Function?o=u.pop():e.isClient?o=s:(i=new t,o=i.resolver()),u.push(e.bindEnvironment(o,s));var c=r.apply(a,u);return i?i.wait():c}}})}.call(this),function(){"use strict";function n(){if(o.setImmediate){var e=function(e){o.setImmediate(e)};return e.implementation="setImmediate",e}return null}function t(){function e(e,n){return"string"==typeof e&&e.substring(0,n.length)===n}function n(n){if(n.source===o&&e(n.data,u)){var t=n.data.substring(u.length);try{a[t]&&a[t]()}finally{delete a[t]}}}if(!o.postMessage||o.importScripts)return null;var t=!0,r=o.onmessage;if(o.onmessage=function(){t=!1},o.postMessage("","*"),o.onmessage=r,!t)return null;var i=0,a={},u="Meteor._setImmediate."+Math.random()+".";o.addEventListener?o.addEventListener("message",n,!1):o.attachEvent("onmessage",n);var s=function(e){++i,a[i]=e,o.postMessage(u+i,"*")};return s.implementation="postMessage",s}function r(){var e=function(e){o.setTimeout(e,0)};return e.implementation="setTimeout",e}var o=this;e._setImmediate=n()||t()||r()}.call(this),function(){var t=function(e){if(Package.livedata){var n=Package.livedata.DDP._CurrentInvocation;if(n.get()&&n.get().isSimulation)throw new Error("Can't set timers inside simulations");return function(){n.withValue(null,e)}}return e},r=function(n,r){return e.bindEnvironment(t(r),function(t){e._debug("Exception from "+n+":",t,t.stack)})};n.extend(e,{setTimeout:function(e,n){return setTimeout(r("setTimeout callback",e),n)},setInterval:function(e,n){return setInterval(r("setInterval callback",e),n)},clearInterval:function(e){return clearInterval(e)},clearTimeout:function(e){return clearTimeout(e)},defer:function(n){e._setImmediate(r("defer callback",n))}})}.call(this),function(){var n=function(e,n){var t=function(){};t.prototype=n.prototype,e.prototype=new t,e.prototype.constructor=e};e.makeErrorType=function(e,t){var r=function(){var n=this;if(Error.captureStackTrace)Error.captureStackTrace(n,r);else{var o=new Error;o.__proto__=r.prototype,o instanceof r&&(n=o)}return t.apply(n,arguments),n.errorType=e,n};return n(r,Error),r},e.Error=e.makeErrorType("Meteor.Error",function(e,n,t){var r=this;r.error=e,r.reason=n,r.details=t,r.message=r.reason?r.reason+" ["+r.error+"]":"["+r.error+"]"})}.call(this),function(){e._noYieldsAllowed=function(e){return e()},e._SynchronousQueue=function(){var e=this;e._tasks=[],e._running=!1},n.extend(e._SynchronousQueue.prototype,{runTask:function(t){var r=this;if(!r.safeToRunTask())throw new Error("Could not synchronously run a task from a running task");r._tasks.push(t);var o=r._tasks;r._tasks=[],r._running=!0;try{for(;!n.isEmpty(o);){var i=o.shift();try{i()}catch(a){if(n.isEmpty(o))throw a;e._debug("Exception in queued task: "+a.stack)}}}finally{r._running=!1}},queueTask:function(e){var t=this,r=n.isEmpty(t._tasks);t._tasks.push(e),r&&setTimeout(n.bind(t.flush,t),0)},flush:function(){var e=this;e.runTask(function(){})},drain:function(){var e=this;if(e.safeToRunTask())for(;!n.isEmpty(e._tasks);)e.flush()},safeToRunTask:function(){var e=this;return!e._running}})}.call(this),function(){var n=[],t=!1;e.startup=function(e){t?e():n.push(e)},e._start=function(){for(;n.length>0;)n.shift()();t=!0}}.call(this),function(){var n=0;e._debug=function(){if(n)return n--,void 0;if("undefined"!=typeof console&&"undefined"!=typeof console.log)if(0==arguments.length)console.log("");else if("function"==typeof console.log.apply){for(var e=!0,t=0;t<arguments.length;t++)"string"!=typeof arguments[t]&&(e=!1);e?console.log.apply(console,[Array.prototype.join.call(arguments," ")]):console.log.apply(console,arguments)}else if("function"==typeof Function.prototype.bind){var r=Function.prototype.bind.call(console.log,console);r.apply(console,arguments)}else Function.prototype.call.call(console.log,console,Array.prototype.slice.call(arguments))},e._suppress_log=function(e){n+=e}}.call(this),function(){var t=0,r=[];e.EnvironmentVariable=function(){this.slot=t++},n.extend(e.EnvironmentVariable.prototype,{get:function(){return r[this.slot]},withValue:function(e,n){var t=r[this.slot];try{r[this.slot]=e;var o=n()}finally{r[this.slot]=t}return o}}),e.bindEnvironment=function(e,t,o){var i=n.clone(r);if(!t)throw new Error("onException must be supplied");return function(){var a=r;try{r=i;var u=e.apply(o,n.toArray(arguments))}catch(s){t(s)}finally{r=a}return u}}}.call(this),function(){e.absoluteUrl=function(t,r){r||"object"!=typeof t||(r=t,t=void 0),r=n.extend({},e.absoluteUrl.defaultOptions,r||{});var o=r.rootUrl;if(!o)throw new Error("Must pass options.rootUrl or set ROOT_URL in the server environment");return/^http[s]?:\/\//i.test(o)||(o="http://"+o),/\/$/.test(o)||(o+="/"),t&&(o+=t),r.secure&&/^http:/.test(o)&&!/http:\/\/localhost[:\/]/.test(o)&&!/http:\/\/127\.0\.0\.1[:\/]/.test(o)&&(o=o.replace(/^http:/,"https:")),r.replaceLocalhost&&(o=o.replace(/^http:\/\/localhost([:\/].*)/,"http://127.0.0.1$1")),o},e.absoluteUrl.defaultOptions={},"object"==typeof __meteor_runtime_config__&&__meteor_runtime_config__.ROOT_URL&&(e.absoluteUrl.defaultOptions.rootUrl=__meteor_runtime_config__.ROOT_URL),e._relativeToSiteRootUrl=function(e){return"object"==typeof __meteor_runtime_config__&&"/"===e.substr(0,1)&&(e=(__meteor_runtime_config__.ROOT_URL_PATH_PREFIX||"")+e),e}}.call(this),"undefined"==typeof Package&&(Package={}),Package.meteor={Meteor:e}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._;!function(){e={},e.active=!1,e.currentComputation=null;var r=function(n){e.currentComputation=n,e.active=!!n},o=function(){return"undefined"!=typeof n?n._debug:"undefined"!=typeof console&&console.log?console.log:function(){}},i=1,a=[],u=!1,s=!1,c=!1,l=[],f=function(){u||(setTimeout(e.flush,0),u=!0)},d=!1;e.Computation=function(e,n){if(!d)throw new Error("Deps.Computation constructor is private; use Deps.autorun");d=!1;var t=this;t.stopped=!1,t.invalidated=!1,t.firstRun=!0,t._id=i++,t._onInvalidateCallbacks=[],t._parent=n,t._func=e,t._recomputing=!1;var r=!0;try{t._compute(),r=!1}finally{t.firstRun=!1,r&&t.stop()}},t.extend(e.Computation.prototype,{onInvalidate:function(n){var t=this;if("function"!=typeof n)throw new Error("onInvalidate requires a function");var r=function(){e.nonreactive(function(){n(t)})};t.invalidated?r():t._onInvalidateCallbacks.push(r)},invalidate:function(){var e=this;if(!e.invalidated){e._recomputing||e.stopped||(f(),a.push(this)),e.invalidated=!0;for(var n,t=0;n=e._onInvalidateCallbacks[t];t++)n();e._onInvalidateCallbacks=[]}},stop:function(){this.stopped||(this.stopped=!0,this.invalidate())},_compute:function(){var n=this;n.invalidated=!1;var t=e.currentComputation;r(n),c=!0;try{n._func(n)}finally{r(t),c=!1}},_recompute:function(){var e=this;for(e._recomputing=!0;e.invalidated&&!e.stopped;)try{e._compute()}catch(n){o()("Exception from Deps recompute:",n.stack||n.message)}e._recomputing=!1}}),e.Dependency=function(){this._dependentsById={}},t.extend(e.Dependency.prototype,{depend:function(n){if(!n){if(!e.active)return!1;n=e.currentComputation}var t=this,r=n._id;return r in t._dependentsById?!1:(t._dependentsById[r]=n,n.onInvalidate(function(){delete t._dependentsById[r]}),!0)},changed:function(){var e=this;for(var n in e._dependentsById)e._dependentsById[n].invalidate()},hasDependents:function(){var e=this;for(var n in e._dependentsById)return!0;return!1}}),t.extend(e,{flush:function(){if(s)throw new Error("Can't call Deps.flush while flushing");if(c)throw new Error("Can't flush inside Deps.autorun");for(s=!0,u=!0;a.length||l.length;){var e=a;a=[];for(var n,t=0;n=e[t];t++)n._recompute();if(l.length){var r=l.shift();try{r()}catch(i){o()("Exception from Deps afterFlush function:",i.stack||i.message)}}}s=!1,u=!1},autorun:function(n){if("function"!=typeof n)throw new Error("Deps.autorun requires a function argument");d=!0;var t=new e.Computation(n,e.currentComputation);return e.active&&e.onInvalidate(function(){t.stop()}),t},nonreactive:function(n){var t=e.currentComputation;r(null);try{return n()}finally{r(t)}},_makeNonreactive:function(n){if(n.$isNonreactive)return n;var r=function(){var r,o=this,i=t.toArray(arguments);return e.nonreactive(function(){r=n.apply(o,i)}),r};return r.$isNonreactive=!0,r},onInvalidate:function(n){if(!e.active)throw new Error("Deps.onInvalidate requires a currentComputation");e.currentComputation.onInvalidate(n)},afterFlush:function(e){l.push(e),f()}})}.call(this),function(){n.flush=e.flush,n.autorun=e.autorun,n.autosubscribe=e.autorun,e.depend=function(e){return e.depend()}}.call(this),"undefined"==typeof Package&&(Package={}),Package.deps={Deps:e}}(),function(){Package.meteor.Meteor;var e;!function(){this.JSON&&(e=this.JSON)}.call(this),"undefined"==typeof Package&&(Package={}),Package.json={JSON:e}}(),function(){Package.meteor.Meteor;var e,n,t,r,o=Package.json.JSON,i=Package.underscore._;!function(){e={},n={};var a={};e.addType=function(e,n){if(i.has(a,e))throw new Error("Type "+e+" already present");a[e]=n};var u=[{matchJSONValue:function(e){return i.has(e,"$date")&&1===i.size(e)},matchObject:function(e){return e instanceof Date},toJSONValue:function(e){return{$date:e.getTime()}},fromJSONValue:function(e){return new Date(e.$date)}},{matchJSONValue:function(e){return i.has(e,"$binary")&&1===i.size(e)},matchObject:function(e){return"undefined"!=typeof Uint8Array&&e instanceof Uint8Array||e&&i.has(e,"$Uint8ArrayPolyfill")},toJSONValue:function(e){return{$binary:t(e)}},fromJSONValue:function(e){return r(e.$binary)}},{matchJSONValue:function(e){return i.has(e,"$escape")&&1===i.size(e)},matchObject:function(e){return i.isEmpty(e)||i.size(e)>2?!1:i.any(u,function(n){return n.matchJSONValue(e)})},toJSONValue:function(n){var t={};return i.each(n,function(n,r){t[r]=e.toJSONValue(n)}),{$escape:t}},fromJSONValue:function(n){var t={};return i.each(n.$escape,function(n,r){t[r]=e.fromJSONValue(n)}),t}},{matchJSONValue:function(e){return i.has(e,"$type")&&i.has(e,"$value")&&2===i.size(e)},matchObject:function(n){return e._isCustomType(n)},toJSONValue:function(e){return{$type:e.typeName(),$value:e.toJSONValue()}},fromJSONValue:function(e){var n=e.$type,t=a[n];return t(e.$value)}}];e._isCustomType=function(e){return e&&"function"==typeof e.toJSONValue&&"function"==typeof e.typeName&&i.has(a,e.typeName())};var s=e._adjustTypesToJSONValue=function(e){if(null===e)return null;var n=c(e);return void 0!==n?n:(i.each(e,function(n,t){if("object"==typeof n||void 0===n){var r=c(n);return r?(e[t]=r,void 0):(s(n),void 0)}}),e)},c=function(e){for(var n=0;n<u.length;n++){var t=u[n];if(t.matchObject(e))return t.toJSONValue(e)}return void 0};e.toJSONValue=function(n){var t=c(n);return void 0!==t?t:("object"==typeof n&&(n=e.clone(n),s(n)),n)};var l=e._adjustTypesFromJSONValue=function(e){if(null===e)return null;var n=f(e);return n!==e?n:(i.each(e,function(n,t){if("object"==typeof n){var r=f(n);if(n!==r)return e[t]=r,void 0;l(n)}}),e)},f=function(e){if("object"==typeof e&&null!==e&&i.size(e)<=2&&i.all(e,function(e,n){return"string"==typeof n&&"$"===n.substr(0,1)}))for(var n=0;n<u.length;n++){var t=u[n];if(t.matchJSONValue(e))return t.fromJSONValue(e)}return e};e.fromJSONValue=function(n){var t=f(n);return t===n&&"object"==typeof n?(n=e.clone(n),l(n),n):t},e.stringify=function(n){return o.stringify(e.toJSONValue(n))},e.parse=function(n){return e.fromJSONValue(o.parse(n))},e.isBinary=function(e){return!!("undefined"!=typeof Uint8Array&&e instanceof Uint8Array||e&&e.$Uint8ArrayPolyfill)},e.equals=function(n,t,r){var o,a=!(!r||!r.keyOrderSensitive);if(n===t)return!0;if(!n||!t)return!1;if("object"!=typeof n||"object"!=typeof t)return!1;if(n instanceof Date&&t instanceof Date)return n.valueOf()===t.valueOf();if(e.isBinary(n)&&e.isBinary(t)){if(n.length!==t.length)return!1;for(o=0;o<n.length;o++)if(n[o]!==t[o])return!1;return!0}if("function"==typeof n.equals)return n.equals(t,r);if(n instanceof Array){if(!(t instanceof Array))return!1;if(n.length!==t.length)return!1;for(o=0;o<n.length;o++)if(!e.equals(n[o],t[o],r))return!1;return!0}var u;if(a){var s=[];return i.each(t,function(e,n){s.push(n)}),o=0,u=i.all(n,function(n,i){return o>=s.length?!1:i!==s[o]?!1:e.equals(n,t[s[o]],r)?(o++,!0):!1}),u&&o===s.length}return o=0,u=i.all(n,function(n,a){return i.has(t,a)?e.equals(n,t[a],r)?(o++,!0):!1:!1}),u&&i.size(t)===o},e.clone=function(n){var t;if("object"!=typeof n)return n;if(null===n)return null;if(n instanceof Date)return new Date(n.getTime());if(e.isBinary(n)){t=e.newBinary(n.length);for(var r=0;r<n.length;r++)t[r]=n[r];return t}if(i.isArray(n)||i.isArguments(n)){for(t=[],r=0;r<n.length;r++)t[r]=e.clone(n[r]);return t}return"function"==typeof n.clone?n.clone():(t={},i.each(n,function(n,r){t[r]=e.clone(n)}),t)}}.call(this),function(){for(var o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={},a=0;a<o.length;a++)i[o.charAt(a)]=a;t=function(e){for(var n=[],t=null,r=null,o=null,i=null,a=0;a<e.length;a++)switch(a%3){case 0:t=63&e[a]>>2,r=(3&e[a])<<4;break;case 1:r|=15&e[a]>>4,o=(15&e[a])<<2;break;case 2:o|=3&e[a]>>6,i=63&e[a],n.push(u(t)),n.push(u(r)),n.push(u(o)),n.push(u(i)),t=null,r=null,o=null,i=null}return null!=t&&(n.push(u(t)),n.push(u(r)),null==o?n.push("="):n.push(u(o)),null==i&&n.push("=")),n.join("")};var u=function(e){return o.charAt(e)},s=function(e){return"="===e?-1:i[e]};e.newBinary=function(e){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer){for(var n=[],t=0;e>t;t++)n.push(0);return n.$Uint8ArrayPolyfill=!0,n}return new Uint8Array(new ArrayBuffer(e))},r=function(n){var t=Math.floor(3*n.length/4);"="==n.charAt(n.length-1)&&(t--,"="==n.charAt(n.length-2)&&t--);for(var r=e.newBinary(t),o=null,i=null,a=null,u=0,c=0;c<n.length;c++){var l=n.charAt(c),f=s(l);switch(c%4){case 0:if(0>f)throw new Error("invalid base64 string");o=f<<2;break;case 1:if(0>f)throw new Error("invalid base64 string");o|=f>>4,r[u++]=o,i=(15&f)<<4;break;case 2:f>=0&&(i|=f>>2,r[u++]=i,a=(3&f)<<6);break;case 3:f>=0&&(r[u++]=a|f)}}return r},n.base64Encode=t,n.base64Decode=r}.call(this),"undefined"==typeof Package&&(Package={}),Package.ejson={EJSON:e,EJSONTest:n}}(),function(){Package.meteor.Meteor,"undefined"==typeof Package&&(Package={}),Package.coffeescript={}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._;!function(){e="object"==typeof e?e:{};var r,o,i,a,u=[].slice;o=function(e){return"string"==typeof e?e:JSON.stringify(e)},a=function(e,n){for(;n.length<e;)n="0"+n;return n},i=function(){var e;return e=new Date,a(2,""+e.getSeconds())+"."+a(3,""+e.getMilliseconds())},n._debug=function(){var e;return e=1<=arguments.length?u.call(arguments,0):[],WebWorker.log(i()+": "+t.map(e,o).join(" "))},r={}}.call(this),"undefined"==typeof Package&&(Package={}),Package.logging={}}(),function(){var e=Package.meteor.Meteor;Package.underscore._,Package.json.JSON;var n;!function(){var t=[];n={},n._onMigrate=function(e,n){n||(n=e,e=void 0),t.push({name:e,callback:n})},n._migrationData=function(){return void 0};var r=!1;n._reload=function(){r||(r=!0,e._debug("reload requested"))}}.call(this),"undefined"==typeof Package&&(Package={}),Package.reload={Reload:n}}(),function(){var e,n,t=Package.meteor.Meteor,r=Package.underscore._,o=Package.ejson.EJSON;!function(){var i=new t.EnvironmentVariable;e=function(e,t){var r=i.get();r&&r.checking(e);try{f(e,t)}catch(o){throw o instanceof n.Error&&o.path&&(o.message+=" in field "+o.path),o}},n={Optional:function(e){return new a(e)},OneOf:function(){return new u(r.toArray(arguments))},Any:["__any__"],Where:function(e){return new s(e)},ObjectIncluding:function(e){return new c(e)},Integer:["__integer__"],Error:t.makeErrorType("Match.Error",function(e){this.message="Match error: "+e,this.path="",this.sanitizedError=new t.Error(400,"Match failed")}),test:function(e,t){try{return f(e,t),!0}catch(r){if(r instanceof n.Error)return!1;throw r}},_failIfArgumentsAreNotAllChecked:function(e,n,t,r){var o=new d(t,r),a=i.withValue(o,function(){return e.apply(n,t)});return o.throwUnlessAllArgumentsHaveBeenChecked(),a}};var a=function(e){this.pattern=e},u=function(e){if(r.isEmpty(e))throw new Error("Must provide at least one choice to Match.OneOf");this.choices=e},s=function(e){this.condition=e},c=function(e){this.pattern=e},l=[[String,"string"],[Number,"number"],[Boolean,"boolean"],[void 0,"undefined"]],f=function(e,t){if(t!==n.Any){for(var i=0;i<l.length;++i)if(t===l[i][0]){if(typeof e===l[i][1])return;throw new n.Error("Expected "+l[i][1]+", got "+typeof e)}if(null===t){if(null===e)return;throw new n.Error("Expected null, got "+o.stringify(e))}if(t===n.Integer){if("number"==typeof e&&(0|e)===e)return;throw new n.Error("Expected Integer, got "+(e instanceof Object?o.stringify(e):e))}if(t===Object&&(t=n.ObjectIncluding({})),t instanceof Array){if(1!==t.length)throw Error("Bad pattern: arrays must have one type element"+o.stringify(t));
if(!r.isArray(e)&&!r.isArguments(e))throw new n.Error("Expected array, got "+o.stringify(e));return r.each(e,function(e,r){try{f(e,t[0])}catch(o){throw o instanceof n.Error&&(o.path=h(r,o.path)),o}}),void 0}if(t instanceof s){if(t.condition(e))return;throw new n.Error("Failed Match.Where validation")}if(t instanceof a&&(t=n.OneOf(void 0,t.pattern)),t instanceof u){for(var i=0;i<t.choices.length;++i)try{return f(e,t.choices[i]),void 0}catch(d){if(!(d instanceof n.Error))throw d}throw new n.Error("Failed Match.OneOf or Match.Optional validation")}if(t instanceof Function){if(e instanceof t)return;throw new n.Error("Expected "+t.name)}var p=!1;if(t instanceof c&&(p=!0,t=t.pattern),"object"!=typeof t)throw Error("Bad pattern: unknown pattern type");if("object"!=typeof e)throw new n.Error("Expected object, got "+typeof e);if(null===e)throw new n.Error("Expected object, got null");if(e.constructor!==Object)throw new n.Error("Expected plain object");var v={},_={};r.each(t,function(e,n){e instanceof a?_[n]=e.pattern:v[n]=e}),r.each(e,function(e,t){try{if(r.has(v,t))f(e,v[t]),delete v[t];else if(r.has(_,t))f(e,_[t]);else if(!p)throw new n.Error("Unknown key")}catch(o){throw o instanceof n.Error&&(o.path=h(t,o.path)),o}}),r.each(v,function(e,t){throw new n.Error("Missing key '"+t+"'")})}},d=function(e,n){var t=this;t.args=r.clone(e),t.args.reverse(),t.description=n};r.extend(d.prototype,{checking:function(e){var n=this;n._checkingOneValue(e)||(r.isArray(e)||r.isArguments(e))&&r.each(e,r.bind(n._checkingOneValue,n))},_checkingOneValue:function(e){for(var n=this,t=0;t<n.args.length;++t)if(e===n.args[t])return n.args.splice(t,1),!0;return!1},throwUnlessAllArgumentsHaveBeenChecked:function(){var e=this;if(!r.isEmpty(e.args))throw new Error("Did not check() all arguments during "+e.description)}});var p=["do","if","in","for","let","new","try","var","case","else","enum","eval","false","null","this","true","void","with","break","catch","class","const","super","throw","while","yield","delete","export","import","public","return","static","switch","typeof","default","extends","finally","package","private","continue","debugger","function","arguments","interface","protected","implements","instanceof"],h=function(e,n){return"number"==typeof e||e.match(/^[0-9]+$/)?e="["+e+"]":(!e.match(/^[a-z_$][0-9a-z_$]*$/i)||r.contains(p,e))&&(e=JSON.stringify([e])),n&&"["!==n[0]?e+"."+n:e+n}}.call(this),"undefined"==typeof Package&&(Package={}),Package.check={check:e,Match:n}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._;!function(){var n=function(){function e(){var e=4022871197,n=function(n){n=n.toString();for(var t=0;t<n.length;t++){e+=n.charCodeAt(t);var r=.02519603282416938*e;e=r>>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=4294967296*r}return 2.3283064365386963e-10*(e>>>0)};return n.version="Mash 0.9",n}return function(n){var t=0,r=0,o=0,i=1;0==n.length&&(n=[+new Date]);var a=e();t=a(" "),r=a(" "),o=a(" ");for(var u=0;u<n.length;u++)t-=a(n[u]),0>t&&(t+=1),r-=a(n[u]),0>r&&(r+=1),o-=a(n[u]),0>o&&(o+=1);a=null;var s=function(){var e=2091639*t+2.3283064365386963e-10*i;return t=r,r=o,o=e-(i=0|e)};return s.uint32=function(){return 4294967296*s()},s.fract53=function(){return s()+1.1102230246251565e-16*(0|2097152*s())},s.version="Alea 0.9",s.args=n,s}(Array.prototype.slice.call(arguments))},r="23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz",o=function(){var e=n.apply(null,arguments),i={},a=function(e){return t.bind(e,i)};return t.extend(i,{_Alea:n,create:o,fraction:e,choice:a(function(e){var n=Math.floor(this.fraction()*e.length);return"string"==typeof e?e.substr(n,1):e[n]}),id:a(function(){for(var e=[],n=0;17>n;n++)e[n]=this.choice(r);return e.join("")}),hexString:a(function(e){for(var n=[],t=0;e>t;++t)n.push(this.choice("0123456789abcdef"));return n.join("")})})},i="undefined"!=typeof window&&window.innerHeight||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientHeight||"undefined"!=typeof document&&document.body&&document.body.clientHeight||1,a="undefined"!=typeof window&&window.innerWidth||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientWidth||"undefined"!=typeof document&&document.body&&document.body.clientWidth||1,u="undefined"!=typeof navigator&&navigator.userAgent||"",s="undefined"!=typeof process&&process.pid||1;e=o([new Date,i,a,u,s,Math.random()])}.call(this),function(){n.uuid=function(){for(var n="0123456789abcdef",t=[],r=0;36>r;r++)t[r]=e.choice(n);t[14]="4",t[19]=n.substr(8|3&parseInt(t[19],16),1),t[8]=t[13]=t[18]=t[23]="-";var o=t.join("");return o}}.call(this),"undefined"==typeof Package&&(Package={}),Package.random={Random:e}}(),function(){Package.meteor.Meteor;var e,n=Package.underscore._;!function(){var t=function(e,n,t,r){return{key:e,value:n,next:t,prev:r}};e=function(){var e=this;e._dict={},e._first=null,e._last=null,e._size=0;var t=n.toArray(arguments);e._stringify=function(e){return e},"function"==typeof t[0]&&(e._stringify=t.shift()),n.each(t,function(n){e.putBefore(n[0],n[1],null)})},n.extend(e.prototype,{_k:function(e){return" "+this._stringify(e)},empty:function(){var e=this;return!e._first},size:function(){var e=this;return e._size},_linkEltIn:function(e){var n=this;e.next?(e.prev=e.next.prev,e.next.prev=e,e.prev&&(e.prev.next=e)):(e.prev=n._last,n._last&&(n._last.next=e),n._last=e),(null===n._first||n._first===e.next)&&(n._first=e)},_linkEltOut:function(e){var n=this;e.next&&(e.next.prev=e.prev),e.prev&&(e.prev.next=e.next),e===n._last&&(n._last=e.prev),e===n._first&&(n._first=e.next)},putBefore:function(e,n,r){var o=this;if(o._dict[o._k(e)])throw new Error("Item "+e+" already present in OrderedDict");var i=r?t(e,n,o._dict[o._k(r)]):t(e,n,null);if(void 0===i.next)throw new Error("could not find item to put this one before");o._linkEltIn(i),o._dict[o._k(e)]=i,o._size++},append:function(e,n){var t=this;t.putBefore(e,n,null)},remove:function(e){var n=this,t=n._dict[n._k(e)];if(void 0===t)throw new Error("Item "+e+" not present in OrderedDict");return n._linkEltOut(t),n._size--,delete n._dict[n._k(e)],t.value},get:function(e){var n=this;return n.has(e)?n._dict[n._k(e)].value:void 0},has:function(e){var t=this;return n.has(t._dict,t._k(e))},forEach:function(n){for(var t=this,r=0,o=t._first;null!==o;){var i=n(o.value,o.key,r);if(i===e.BREAK)return;o=o.next,r++}},first:function(){var e=this;return e.empty()?void 0:e._first.key},firstValue:function(){var e=this;return e.empty()?void 0:e._first.value},last:function(){var e=this;return e.empty()?void 0:e._last.key},lastValue:function(){var e=this;return e.empty()?void 0:e._last.value},prev:function(e){var n=this;if(n.has(e)){var t=n._dict[n._k(e)];if(t.prev)return t.prev.key}return null},next:function(e){var n=this;if(n.has(e)){var t=n._dict[n._k(e)];if(t.next)return t.next.key}return null},moveBefore:function(e,n){var t=this,r=t._dict[t._k(e)],o=n?t._dict[t._k(n)]:null;if(void 0===r)throw new Error("Item to move is not present");if(void 0===o)throw new Error("Could not find element to move this one before");o!==r.next&&(t._linkEltOut(r),r.next=o,t._linkEltIn(r))},indexOf:function(n){var t=this,r=null;return t.forEach(function(o,i,a){return t._k(i)===t._k(n)?(r=a,e.BREAK):void 0}),r},_checkRep:function(){var e=this;n.each(e._dict,function(e,n){if(n.next===n)throw new Error("Next is a loop");if(n.prev===n)throw new Error("Prev is a loop")})}}),e.BREAK={"break":!0}}.call(this),"undefined"==typeof Package&&(Package={}),Package["ordered-dict"]={OrderedDict:e}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._,r=Package.json.JSON,o=Package.ejson.EJSON,i=Package["ordered-dict"].OrderedDict,a=Package.deps.Deps,u=Package.random.Random;!function(){e=function(e){this.name=e,this.docs={},this._observeQueue=new n._SynchronousQueue,this.next_qid=1,this.queries={},this._savedOriginals=null,this.paused=!1},e._applyChanges=function(e,n){t.each(n,function(n,t){void 0===n?delete e[t]:e[t]=n})};var s=function(e){var n=new Error(e);return n.name="MinimongoError",n};e.prototype.find=function(n,t){return 0===arguments.length&&(n={}),new e.Cursor(this,n,t)},e.Cursor=function(n,t,r){var o=this;r||(r={}),this.collection=n,e._selectorIsId(t)?(o.selector_id=e._idStringify(t),o.selector_f=e._compileSelector(t),o.sort_f=void 0):(o.selector_id=void 0,o.selector_f=e._compileSelector(t),o.sort_f=r.sort?e._compileSort(r.sort):null),o.skip=r.skip,o.limit=r.limit,o._transform=r.transform&&"undefined"!=typeof a?a._makeNonreactive(r.transform):r.transform,o.db_objects=null,o.cursor_pos=0,"undefined"!=typeof a&&(o.reactive=void 0===r.reactive?!0:r.reactive)},e.Cursor.prototype.rewind=function(){var e=this;e.db_objects=null,e.cursor_pos=0},e.prototype.findOne=function(e,n){return 0===arguments.length&&(e={}),n=n||{},n.limit=1,this.find(e,n).fetch()[0]},e.Cursor.prototype.forEach=function(e){var n=this;for(null===n.db_objects&&(n.db_objects=n._getRawObjects(!0)),n.reactive&&n._depend({addedBefore:!0,removed:!0,changed:!0,movedBefore:!0});n.cursor_pos<n.db_objects.length;){var t=o.clone(n.db_objects[n.cursor_pos++]);n._transform&&(t=n._transform(t)),e(t)}},e.Cursor.prototype.getTransform=function(){var e=this;return e._transform},e.Cursor.prototype.map=function(e){var n=this,t=[];return n.forEach(function(n){t.push(e(n))}),t},e.Cursor.prototype.fetch=function(){var e=this,n=[];return e.forEach(function(e){n.push(e)}),n},e.Cursor.prototype.count=function(){var e=this;return e.reactive&&e._depend({added:!0,removed:!0}),null===e.db_objects&&(e.db_objects=e._getRawObjects(!0)),e.db_objects.length},e.Cursor.prototype._publishCursor=function(e){var t=this;if(!t.collection.name)throw new Error("Can't publish a cursor from a collection without a name.");var r=t.collection.name;return n.Collection._publishCursor(t,e,r)},e._isOrderedChanges=function(e){if(e.added&&e.addedBefore)throw new Error("Please specify only one of added() and addedBefore()");return"function"==typeof e.addedBefore||"function"==typeof e.movedBefore},e.LiveResultsSet=function(){},t.extend(e.Cursor.prototype,{observe:function(n){var t=this;return e._observeFromObserveChanges(t,n)},observeChanges:function(n){var r=this,i=e._isOrderedChanges(n);if(!i&&(r.skip||r.limit))throw new Error("must use ordered observe with skip or limit");var u,s={selector_f:r.selector_f,sort_f:i&&r.sort_f,results_snapshot:null,ordered:i,cursor:this,observeChanges:n.observeChanges};r.reactive&&(u=r.collection.next_qid++,r.collection.queries[u]=s),s.results=r._getRawObjects(i),r.collection.paused&&(s.results_snapshot=i?[]:{});var c=function(e){return e?function(){var n=this,t=arguments;r.collection.paused||r.collection._observeQueue.queueTask(function(){e.apply(n,t)})}:function(){}};s.added=c(n.added),s.changed=c(n.changed),s.removed=c(n.removed),i&&(s.moved=c(n.moved),s.addedBefore=c(n.addedBefore),s.movedBefore=c(n.movedBefore)),n._suppress_initial||r.collection.paused||t.each(s.results,function(e){var n=o.clone(e);delete n._id,i&&s.addedBefore(e._id,n,null),s.added(e._id,n)});var l=new e.LiveResultsSet;return t.extend(l,{collection:r.collection,stop:function(){r.reactive&&delete r.collection.queries[u]}}),r.reactive&&a.active&&a.onInvalidate(function(){l.stop()}),r.collection._observeQueue.drain(),l}}),e.Cursor.prototype._getRawObjects=function(e){var n=this,r=e?[]:{};if(n.selector_id){if(n.skip)return r;if(t.has(n.collection.docs,n.selector_id)){var o=n.collection.docs[n.selector_id];e?r.push(o):r[n.selector_id]=o}return r}for(var i in n.collection.docs){var a=n.collection.docs[i];if(n.selector_f(a)&&(e?r.push(a):r[i]=a),n.limit&&!n.skip&&!n.sort_f&&r.length===n.limit)return r}if(!e)return r;n.sort_f&&r.sort(n.sort_f);var u=n.skip||0,s=n.limit?n.limit+u:r.length;return r.slice(u,s)},e.Cursor.prototype._depend=function(e){var n=this;if(a.active){var r=new a.Dependency;r.depend();var o=t.bind(r.changed,r),i={_suppress_initial:!0};t.each(["added","changed","removed","addedBefore","movedBefore"],function(n){e[n]&&(i[n]=o)}),n.observeChanges(i)}},e.prototype.insert=function(r,i){var a=this;r=o.clone(r),t.has(r,"_id")||(r._id=e._useOID?new e._ObjectID:u.id());var c=e._idStringify(r._id);if(t.has(a.docs,r._id))throw s("Duplicate _id '"+r._id+"'");a._saveOriginal(c,void 0),a.docs[c]=r;var l=[];for(var f in a.queries){var d=a.queries[f];d.selector_f(r)&&(d.cursor.skip||d.cursor.limit?l.push(f):e._insertInResults(d,r))}return t.each(l,function(n){a.queries[n]&&e._recomputeResults(a.queries[n])}),a._observeQueue.drain(),i&&n.defer(function(){i(null,r._id)}),r._id},e.prototype.remove=function(r,o){var i=this,a=[],u=[],s=e._compileSelector(r),c=e._idsMatchedBySelector(r);if(c)t.each(c,function(n){var r=e._idStringify(n);t.has(i.docs,r)&&s(i.docs[r])&&a.push(r)});else for(var l in i.docs){var f=i.docs[l];s(f)&&a.push(l)}for(var d=[],p=0;p<a.length;p++){var h=a[p],v=i.docs[h];t.each(i.queries,function(e,n){e.selector_f(v)&&(e.cursor.skip||e.cursor.limit?u.push(n):d.push({qid:n,doc:v}))}),i._saveOriginal(h,v),delete i.docs[h]}t.each(d,function(n){var t=i.queries[n.qid];t&&e._removeFromResults(t,n.doc)}),t.each(u,function(n){var t=i.queries[n];t&&e._recomputeResults(t)}),i._observeQueue.drain(),o&&n.defer(o)},e.prototype.update=function(r,i,a,u){var s=this;if(!u&&a instanceof Function&&(u=a,a=null),a||(a={}),a.upsert)throw new Error("upsert not yet implemented");var c=e._compileSelector(r),l={};t.each(s.queries,function(e,n){!e.cursor.skip&&!e.cursor.limit||e.paused||(l[n]=o.clone(e.results))});var f={};for(var d in s.docs){var p=s.docs[d];if(c(p)&&(s._saveOriginal(d,p),s._modifyAndNotify(p,i,f),!a.multi))break}t.each(f,function(n,t){var r=s.queries[t];r&&e._recomputeResults(r,l[t])}),s._observeQueue.drain(),u&&n.defer(u)},e.prototype._modifyAndNotify=function(n,r,i){var a=this,u={};for(var s in a.queries){var c=a.queries[s];u[s]=c.ordered?c.selector_f(n):t.has(c.results,e._idStringify(n._id))}var l=o.clone(n);e._modify(n,r);for(s in a.queries){c=a.queries[s];var f=u[s],d=c.selector_f(n);c.cursor.skip||c.cursor.limit?(f||d)&&(i[s]=!0):f&&!d?e._removeFromResults(c,n):!f&&d?e._insertInResults(c,n):f&&d&&e._updateInResults(c,n,l)}},e._insertInResults=function(n,t){var r=o.clone(t);if(delete r._id,n.ordered){if(n.sort_f){var i=e._insertInSortedList(n.sort_f,n.results,t),a=n.results[i+1];a=a?a._id:null,n.addedBefore(t._id,r,a)}else n.addedBefore(t._id,r,null),n.results.push(t);n.added(t._id,r)}else n.added(t._id,r),n.results[e._idStringify(t._id)]=t},e._removeFromResults=function(n,t){if(n.ordered){var r=e._findInOrderedResults(n,t);n.removed(t._id),n.results.splice(r,1)}else{var o=e._idStringify(t._id);n.removed(t._id),delete n.results[o]}},e._updateInResults=function(n,r,i){if(!o.equals(r._id,i._id))throw new Error("Can't change a doc's _id while updating");var a=e._makeChangedFields(r,i);if(!n.ordered)return t.isEmpty(a)||(n.changed(r._id,a),n.results[e._idStringify(r._id)]=r),void 0;var u=e._findInOrderedResults(n,r);if(t.isEmpty(a)||n.changed(r._id,a),n.sort_f){n.results.splice(u,1);var s=e._insertInSortedList(n.sort_f,n.results,r);if(u!==s){var c=n.results[s+1];c=c?c._id:null,n.movedBefore&&n.movedBefore(r._id,c)}}},e._recomputeResults=function(n,t){t||(t=n.results),n.results=n.cursor._getRawObjects(n.ordered),n.paused||e._diffQueryChanges(n.ordered,t,n.results,n)},e._findInOrderedResults=function(e,n){if(!e.ordered)throw new Error("Can't call _findInOrderedResults on unordered query");for(var t=0;t<e.results.length;t++)if(e.results[t]===n)return t;throw Error("object missing from query")},e._binarySearch=function(e,n,t){for(var r=0,o=n.length;o>0;){var i=Math.floor(o/2);e(t,n[r+i])>=0?(r+=i+1,o-=i+1):o=i}return r},e._insertInSortedList=function(n,t,r){if(0===t.length)return t.push(r),0;var o=e._binarySearch(n,t,r);return t.splice(o,0,r),o},e.prototype.saveOriginals=function(){var e=this;if(e._savedOriginals)throw new Error("Called saveOriginals twice without retrieveOriginals");e._savedOriginals={}},e.prototype.retrieveOriginals=function(){var e=this;if(!e._savedOriginals)throw new Error("Called retrieveOriginals without saveOriginals");var n=e._savedOriginals;return e._savedOriginals=null,n},e.prototype._saveOriginal=function(e,n){var r=this;r._savedOriginals&&(t.has(r._savedOriginals,e)||(r._savedOriginals[e]=o.clone(n)))},e.prototype.pauseObservers=function(){if(!this.paused){this.paused=!0;for(var e in this.queries){var n=this.queries[e];n.results_snapshot=o.clone(n.results)}}},e.prototype.resumeObservers=function(){var n=this;if(this.paused){this.paused=!1;for(var t in this.queries){var r=n.queries[t];e._diffQueryChanges(r.ordered,r.results_snapshot,r.results,r),r.results_snapshot=null}n._observeQueue.drain()}},e._idStringify=function(n){if(n instanceof e._ObjectID)return n.valueOf();if("string"==typeof n)return""===n?n:"-"===n.substr(0,1)||"~"===n.substr(0,1)||e._looksLikeObjectID(n)||"{"===n.substr(0,1)?"-"+n:n;if(void 0===n)return"-";if("object"==typeof n&&null!==n)throw new Error("Meteor does not currently support objects other than ObjectID as ids");return"~"+r.stringify(n)},e._idParse=function(n){return""===n?n:"-"===n?void 0:"-"===n.substr(0,1)?n.substr(1):"~"===n.substr(0,1)?r.parse(n.substr(1)):e._looksLikeObjectID(n)?new e._ObjectID(n):n},e._makeChangedFields=function(n,t){var r={};return e._diffObjects(t,n,{leftOnly:function(e){r[e]=void 0},rightOnly:function(e,n){r[e]=n},both:function(e,n,t){o.equals(n,t)||(r[e]=t)}}),r},e._observeFromObserveChanges=function(n,t){var r=n.getTransform();if(r||(r=function(e){return e}),t.addedAt&&t.added)throw new Error("Please specify only one of added() and addedAt()");if(t.changedAt&&t.changed)throw new Error("Please specify only one of changed() and changedAt()");if(t.removed&&t.removedAt)throw new Error("Please specify only one of removed() and removedAt()");return t.addedAt||t.movedTo||t.changedAt||t.removedAt?e._observeOrderedFromObserveChanges(n,t,r):e._observeUnorderedFromObserveChanges(n,t,r)},e._observeUnorderedFromObserveChanges=function(n,t,r){var i={},a=!!t._suppress_initial,u=n.observeChanges({added:function(n,u){var s=e._idStringify(n),c=o.clone(u);c._id=n,i[s]=c,a||t.added&&t.added(r(c))},changed:function(n,u){var s=e._idStringify(n),c=i[s],l=o.clone(c);e._applyChanges(c,u),a||t.changed&&t.changed(r(c),r(l))},removed:function(n){var o=e._idStringify(n),u=i[o];delete i[o],a||t.removed&&t.removed(r(u))}});return a=!1,u},e._observeOrderedFromObserveChanges=function(n,t,r){var a=new i(e._idStringify),u=!!t._suppress_initial,s=!t._no_indices,c=n.observeChanges({addedBefore:function(e,n,i){var c=o.clone(n);if(c._id=e,a.putBefore(e,c,i||null),!u)if(t.addedAt){var l=s?a.indexOf(e):-1;t.addedAt(r(o.clone(c)),l,i)}else t.added&&t.added(r(o.clone(c)))},changed:function(n,i){var u=a.get(n);if(!u)throw new Error("Unknown id for changed: "+n);var c=o.clone(u);if(e._applyChanges(u,i),t.changedAt){var l=s?a.indexOf(n):-1;t.changedAt(r(o.clone(u)),r(c),l)}else t.changed&&t.changed(r(o.clone(u)),r(c))},movedBefore:function(e,n){var i,u=a.get(e);if(t.movedTo&&(i=s?a.indexOf(e):-1),a.moveBefore(e,n||null),t.movedTo){var c=s?a.indexOf(e):-1;t.movedTo(r(o.clone(u)),i,c,n||null)}else t.moved&&t.moved(r(o.clone(u)))},removed:function(e){var n,o=a.get(e);t.removedAt&&(n=s?a.indexOf(e):-1),a.remove(e),t.removedAt&&t.removedAt(r(o),n),t.removed&&t.removed(r(o))}});return u=!1,c}}.call(this),function(){var n=function(e){return t.isArray(e)&&!o.isBinary(e)},i=function(e,r){return n(e)?t.any(e,r):r(e)},a=function(e,r){return r(e)?!0:n(e)&&t.any(e,r)},u=function(e){var n=void 0;for(var t in e){var r="$"===t.substr(0,1);if(void 0===n)n=r;else if(n!==r)throw new Error("Inconsistent selector: "+e)}return!!n},s=function(r){if(null==r)return function(e){return i(e,function(e){return null==e})};if(!t.isObject(r))return function(e){return i(e,function(e){return e===r})};if(r instanceof RegExp)return function(e){return void 0===e?!1:i(e,function(e){return r.test(e)})};if(n(r))return function(t){return n(t)?a(t,function(n){return e._f._equal(r,n)}):!1};if(u(r)){var o=[];return t.each(r,function(e,n){if(!t.has(l,n))throw new Error("Unrecognized operator: "+n);o.push(l[n](e,r.$options))}),function(e){return t.all(o,function(n){return n(e)})}}return function(n){return i(n,function(n){return e._f._equal(r,n)})}},c={$and:function(e){if(!n(e)||t.isEmpty(e))throw Error("$and/$or/$nor must be nonempty array");var r=t.map(e,f);return function(e){return t.all(r,function(n){return n(e)})}},$or:function(e){if(!n(e)||t.isEmpty(e))throw Error("$and/$or/$nor must be nonempty array");var r=t.map(e,f);return function(e){return t.any(r,function(n){return n(e)})}},$nor:function(e){if(!n(e)||t.isEmpty(e))throw Error("$and/$or/$nor must be nonempty array");var r=t.map(e,f);return function(e){return t.all(r,function(n){return!n(e)})}},$where:function(e){return e instanceof Function||(e=Function("return "+e)),function(n){return e.call(n)}}},l={$in:function(r){if(!n(r))throw new Error("Argument to $in must be array");return function(n){return a(n,function(n){return t.any(r,function(t){return e._f._equal(t,n)})})}},$all:function(r){if(!n(r))throw new Error("Argument to $all must be array");return function(o){return n(o)?t.all(r,function(n){return t.any(o,function(t){return e._f._equal(n,t)})}):!1}},$lt:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)<0})}},$lte:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)<=0})}},$gt:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)>0})}},$gte:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)>=0})}},$ne:function(n){return function(t){return!a(t,function(t){return e._f._equal(t,n)})}},$nin:function(e){if(!n(e))throw new Error("Argument to $nin must be array");var t=l.$in(e);return function(e){return void 0===e?!0:!t(e)}},$exists:function(e){return function(n){return e===(void 0!==n)}},$mod:function(e){var n=e[0],t=e[1];return function(e){return i(e,function(e){return e%n===t})}},$size:function(e){return function(t){return n(t)&&e===t.length}},$type:function(n){return function(t){return void 0===t?!1:i(t,function(t){return e._f._type(t)===n})}},$regex:function(e,n){if(void 0!==n){if(/[^gim]/.test(n))throw new Error("Only the i, m, and g regexp options are supported");var t=e instanceof RegExp?e.source:e;e=new RegExp(t,n)}else e instanceof RegExp||(e=new RegExp(e));return function(n){return void 0===n?!1:i(n,function(n){return e.test(n)})}},$options:function(){return function(){return!0}},$elemMatch:function(e){var r=f(e);return function(e){return n(e)?t.any(e,function(e){return r(e)}):!1}},$not:function(e){var n=s(e);return function(e){return!n(e)}}};e._f={_type:function(t){return"number"==typeof t?1:"string"==typeof t?2:"boolean"==typeof t?8:n(t)?4:null===t?10:t instanceof RegExp?11:"function"==typeof t?13:t instanceof Date?9:o.isBinary(t)?5:t instanceof e._ObjectID?7:3},_equal:function(e,n){return o.equals(e,n,{keyOrderSensitive:!0})},_typeorder:function(e){return[-1,1,2,3,4,5,-1,6,7,8,0,9,-1,100,2,100,1,8,1][e]},_cmp:function(n,t){if(void 0===n)return void 0===t?0:-1;if(void 0===t)return 1;var r=e._f._type(n),o=e._f._type(t),i=e._f._typeorder(r),a=e._f._typeorder(o);if(i!==a)return a>i?-1:1;if(r!==o)throw Error("Missing type coercion logic in _cmp");if(7===r&&(r=o=2,n=n.toHexString(),t=t.toHexString()),9===r&&(r=o=1,n=n.getTime(),t=t.getTime()),1===r)return n-t;if(2===o)return t>n?-1:n===t?0:1;if(3===r){var u=function(e){var n=[];for(var t in e)n.push(t),n.push(e[t]);return n};return e._f._cmp(u(n),u(t))}if(4===r)for(var s=0;;s++){if(s===n.length)return s===t.length?0:-1;if(s===t.length)return 1;var c=e._f._cmp(n[s],t[s]);if(0!==c)return c}if(5===r){if(n.length!==t.length)return n.length-t.length;for(s=0;s<n.length;s++){if(n[s]<t[s])return-1;if(n[s]>t[s])return 1}return 0}if(8===r)return n?t?0:1:t?-1:0;if(10===r)return 0;if(11===r)throw Error("Sorting not supported on regular expression");if(13===r)throw Error("Sorting not supported on Javascript code");throw Error("Unknown type to sort")}},e._matches=function(n,t){return e._compileSelector(n)(t)},e._makeLookupFunction=function(r){var o,i,a,u=r.indexOf(".");if(-1===u)o=r;else{o=r.substr(0,u);var s=r.substr(u+1);i=e._makeLookupFunction(s),a=/^\d+(\.|$)/.test(s)}return function(e){if(null==e)return[void 0];var r=e[o];return i?n(r)&&0===r.length?[void 0]:((!n(r)||a)&&(r=[r]),Array.prototype.concat.apply([],t.map(r,i))):[r]}};var f=function(n){var r=[];return t.each(n,function(n,o){if("$"===o.substr(0,1)){if(!t.has(c,o))throw new Error("Unrecognized logical operator: "+o);r.push(c[o](n))}else{var i=e._makeLookupFunction(o),a=s(n);r.push(function(e){var n=i(e);return t.any(n,a)})}}),function(e){return t.all(r,function(n){return n(e)})}};e._compileSelector=function(t){if(t instanceof Function)return function(e){return t.call(e)};if(e._selectorIsId(t))return function(e){return o.equals(e._id,t)};if(!t||"_id"in t&&!t._id)return function(){return!1};if("boolean"==typeof t||n(t)||o.isBinary(t))throw new Error("Invalid selector: "+t);return f(t)},e._compileSort=function(o){var i=[];if(o instanceof Array)for(var a=0;a<o.length;a++)"string"==typeof o[a]?i.push({lookup:e._makeLookupFunction(o[a]),ascending:!0}):i.push({lookup:e._makeLookupFunction(o[a][0]),ascending:"desc"!==o[a][1]});else{if("object"!=typeof o)throw Error("Bad sort specification: ",r.stringify(o));for(var u in o)i.push({lookup:e._makeLookupFunction(u),ascending:o[u]>=0})}if(0===i.length)return function(){return 0};var s=function(r,o){var i,a=!0;return t.each(r,function(r){n(r)||(r=[r]),n(r)&&0===r.length&&(r=[void 0]),t.each(r,function(n){if(a)i=n,a=!1;else{var t=e._f._cmp(i,n);(o&&t>0||!o&&0>t)&&(i=n)}})}),i};return function(n,t){for(var r=0;r<i.length;++r){var o=i[r],a=s(o.lookup(n),o.ascending),u=s(o.lookup(t),o.ascending),c=e._f._cmp(a,u);if(0!==c)return o.ascending?c:-c}return 0}}}.call(this),function(){e._modify=function(n,r){var i=!1;for(var a in r){i="$"===a.substr(0,1);break}var u;if(i){var u=o.clone(n);for(var s in r){var c=e._modifiers[s];if(!c)throw Error("Invalid modifier specified "+s);for(var l in r[s]){if(l.length&&"."===l[l.length-1])throw Error("Invalid mod field name, may not end in a period");var f=r[s][l],d=l.split("."),p=!!e._noCreateModifiers[s],h="$rename"===s,v=e._findModTarget(u,d,p,h),_=d.pop();c(v,_,f,l,u)}}}else{if(r._id&&!o.equals(n._id,r._id))throw Error("Cannot change the _id of a document");for(var a in r){if("$"===a.substr(0,1))throw Error("When replacing document, field name may not start with '$'");if(/\./.test(a))throw Error("When replacing document, field name may not contain '.'")}u=r}t.each(t.keys(n),function(e){"_id"!==e&&delete n[e]});for(var a in u)n[a]=u[a]},e._findModTarget=function(e,n,t,o){for(var i=0;i<n.length;i++){var a=i===n.length-1,u=n[i],s=/^[0-9]+$/.test(u);if(!(!t||"object"==typeof e&&u in e))return void 0;if(e instanceof Array){if(o)return null;if(!s)throw Error("can't append to array using string field name ["+u+"]");for(u=parseInt(u),a&&(n[i]=u);e.length<u;)e.push(null);if(!a)if(e.length===u)e.push({});else if("object"!=typeof e[u])throw Error("can't modify field '"+n[i+1]+"' of list value "+r.stringify(e[u]))}else a||u in e||(e[u]={});if(a)return e;e=e[u]}},e._noCreateModifiers={$unset:!0,$pop:!0,$rename:!0,$pull:!0,$pullAll:!0},e._modifiers={$inc:function(e,n,t){if("number"!=typeof t)throw Error("Modifier $inc allowed for numbers only");if(n in e){if("number"!=typeof e[n])throw Error("Cannot apply $inc modifier to non-number");e[n]+=t}else e[n]=t},$set:function(e,n,t){if("_id"===n&&!o.equals(t,e._id))throw Error("Cannot change the _id of a document");e[n]=o.clone(t)},$unset:function(e,n){void 0!==e&&(e instanceof Array?n in e&&(e[n]=null):delete e[n])},$push:function(e,n,t){var r=e[n];if(void 0===r)e[n]=[t];else{if(!(r instanceof Array))throw Error("Cannot apply $push modifier to non-array");r.push(o.clone(t))}},$pushAll:function(e,n,t){if(!("object"==typeof t&&t instanceof Array))throw Error("Modifier $pushAll/pullAll allowed for arrays only");var r=e[n];if(void 0===r)e[n]=t;else{if(!(r instanceof Array))throw Error("Cannot apply $pushAll modifier to non-array");for(var o=0;o<t.length;o++)r.push(t[o])}},$addToSet:function(n,r,o){var i=n[r];if(void 0===i)n[r]=[o];else{if(!(i instanceof Array))throw Error("Cannot apply $addToSet modifier to non-array");var a=!1;if("object"==typeof o)for(var u in o){"$each"===u&&(a=!0);break}var s=a?o.$each:[o];t.each(s,function(n){for(var t=0;t<i.length;t++)if(e._f._equal(n,i[t]))return;i.push(n)})}},$pop:function(e,n,t){if(void 0!==e){var r=e[n];if(void 0!==r){if(!(r instanceof Array))throw Error("Cannot apply $pop modifier to non-array");"number"==typeof t&&0>t?r.splice(0,1):r.pop()}}},$pull:function(n,t,r){if(void 0!==n){var o=n[t];if(void 0!==o){if(!(o instanceof Array))throw Error("Cannot apply $pull/pullAll modifier to non-array");var i=[];if("object"!=typeof r||r instanceof Array)for(var a=0;a<o.length;a++)e._f._equal(o[a],r)||i.push(o[a]);else for(var u=e._compileSelector(r),a=0;a<o.length;a++)u(o[a])||i.push(o[a]);n[t]=i}}},$pullAll:function(n,t,r){if(!("object"==typeof r&&r instanceof Array))throw Error("Modifier $pushAll/pullAll allowed for arrays only");if(void 0!==n){var o=n[t];if(void 0!==o){if(!(o instanceof Array))throw Error("Cannot apply $pull/pullAll modifier to non-array");for(var i=[],a=0;a<o.length;a++){for(var u=!1,s=0;s<r.length;s++)if(e._f._equal(o[a],r[s])){u=!0;break}u||i.push(o[a])}n[t]=i}}},$rename:function(n,t,r,o,i){if(o===r)throw Error("$rename source must differ from target");if(null===n)throw Error("$rename source field invalid");if("string"!=typeof r)throw Error("$rename target must be a string");if(void 0!==n){var a=n[t];delete n[t];var u=r.split("."),s=e._findModTarget(i,u,!1,!0);if(null===s)throw Error("$rename target field invalid");var c=u.pop();s[c]=a}},$bit:function(){throw Error("$bit is not supported")}}}.call(this),function(){e._diffQueryChanges=function(n,t,r,o){n?e._diffQueryOrderedChanges(t,r,o):e._diffQueryUnorderedChanges(t,r,o)},e._diffQueryUnorderedChanges=function(n,r,i){if(i.moved)throw new Error("_diffQueryUnordered called with a moved observer!");t.each(r,function(r){if(t.has(n,r._id)){var a=n[r._id];i.changed&&!o.equals(a,r)&&i.changed(r._id,e._makeChangedFields(r,a))}else{var u=o.clone(r);delete u._id,i.added&&i.added(r._id,u)}}),i.removed&&t.each(n,function(e){t.has(r,e._id)||i.removed(e._id)})},e._diffQueryOrderedChanges=function(r,i,a){var u={};t.each(i,function(e){u[e._id]&&n._debug("Duplicate _id in new_results"),u[e._id]=!0});var s={};t.each(r,function(e,t){e._id in s&&n._debug("Duplicate _id in old_results"),s[e._id]=t});for(var c=[],l=0,f=i.length,d=new Array(f),p=new Array(f),h=function(e){return s[i[e]._id]},v=0;f>v;v++)if(void 0!==s[i[v]._id]){for(var _=l;_>0&&!(h(d[_-1])<h(v));)_--;p[v]=0===_?-1:d[_-1],d[_]=v,_+1>l&&(l=_+1)}for(var m=0===l?-1:d[l-1];m>=0;)c.push(m),m=p[m];c.reverse(),c.push(i.length),t.each(r,function(e){u[e._id]||a.removed&&a.removed(e._id)});var g=0;t.each(c,function(n){for(var u,c,l,f=i[n]?i[n]._id:null,d=g;n>d;d++)c=i[d],t.has(s,c._id)?(u=r[s[c._id]],l=e._makeChangedFields(c,u),t.isEmpty(l)||a.changed&&a.changed(c._id,l),a.movedBefore&&a.movedBefore(c._id,f)):(l=o.clone(c),delete l._id,a.addedBefore&&a.addedBefore(c._id,l,f),a.added&&a.added(c._id,l));f&&(c=i[n],u=r[s[c._id]],l=e._makeChangedFields(c,u),t.isEmpty(l)||a.changed&&a.changed(c._id,l)),g=n+1})},e._diffObjects=function(e,n,r){t.each(e,function(e,o){t.has(n,o)?r.both&&r.both(o,e,n[o]):r.leftOnly&&r.leftOnly(o,e)}),r.rightOnly&&t.each(n,function(n,o){t.has(e,o)||r.rightOnly(o,n)})}}.call(this),function(){e._looksLikeObjectID=function(e){return 24===e.length&&e.match(/^[0-9a-f]*$/)},e._ObjectID=function(n){var t=this;if(n){if(n=n.toLowerCase(),!e._looksLikeObjectID(n))throw new Error("Invalid hexadecimal string for creating an ObjectID");t._str=n}else t._str=u.hexString(24)},e._ObjectID.prototype.toString=function(){var e=this;return'ObjectID("'+e._str+'")'},e._ObjectID.prototype.equals=function(n){var t=this;
return n instanceof e._ObjectID&&t.valueOf()===n.valueOf()},e._ObjectID.prototype.clone=function(){var n=this;return new e._ObjectID(n._str)},e._ObjectID.prototype.typeName=function(){return"oid"},e._ObjectID.prototype.getTimestamp=function(){var e=this;return parseInt(e._str.substr(0,8),16)},e._ObjectID.prototype.valueOf=e._ObjectID.prototype.toJSONValue=e._ObjectID.prototype.toHexString=function(){return this._str},e._selectorIsId=function(n){return"string"==typeof n||"number"==typeof n||n instanceof e._ObjectID},e._selectorIsIdPerhapsAsObject=function(n){return e._selectorIsId(n)||n&&"object"==typeof n&&n._id&&e._selectorIsId(n._id)&&1===t.size(n)},e._idsMatchedBySelector=function(n){if(e._selectorIsId(n))return[n];if(!n)return null;if(t.has(n,"_id"))return e._selectorIsId(n._id)?[n._id]:n._id&&n._id.$in&&t.isArray(n._id.$in)&&!t.isEmpty(n._id.$in)&&t.all(n._id.$in,e._selectorIsId)?n._id.$in:null;if(n.$and&&t.isArray(n.$and))for(var r=0;r<n.$and.length;++r){var o=e._idsMatchedBySelector(n.$and[r]);if(o)return o}return null},o.addType("oid",function(n){return new e._ObjectID(n)})}.call(this),"undefined"==typeof Package&&(Package={}),Package.minimongo={LocalCollection:e}}(),function(){var e=Package.meteor.Meteor;Package.check.check,Package.check.Match;var n,t,r,o,i,a,u,s,c,l,f=Package.random.Random,d=Package.ejson.EJSON,p=Package.json.JSON,h=Package.underscore._,v=Package.deps.Deps,_=Package.reload.Reload,m=Package.minimongo.LocalCollection;!function(){t={}}.call(this),function(){var n=function(n){return function(){e._debug(new Error("not implemented: "+n).stack)}};r=function(){var t="undefined"!=typeof document?document:{location:location,attachEvent:n("attachEvent"),detachEvent:n("detachEvent"),createElement:n("createElement"),domain:location.hostname},r="undefined"!=typeof window?window:{location:location,WebSocket:WebSocket,XMLHttpRequest:XMLHttpRequest},o={},i=function(){};i.prototype.addEventListener=function(e,n){this._listeners||(this._listeners={}),e in this._listeners||(this._listeners[e]=[]);var t=this._listeners[e];-1===o.arrIndexOf(t,n)&&t.push(n)},i.prototype.removeEventListener=function(e,n){if(this._listeners&&e in this._listeners){var t=this._listeners[e],r=o.arrIndexOf(t,n);return-1!==r?(t.length>1?this._listeners[e]=t.slice(0,r).concat(t.slice(r+1)):delete this._listeners[e],void 0):void 0}},i.prototype.dispatchEvent=function(e){var n=e.type,t=Array.prototype.slice.call(arguments,0);if(this["on"+n]&&this["on"+n].apply(this,t),this._listeners&&n in this._listeners)for(var r=0;r<this._listeners[n].length;r++)this._listeners[n][r].apply(this,t)};var a=function(e,n){if(this.type=e,"undefined"!=typeof n)for(var t in n)n.hasOwnProperty(t)&&(this[t]=n[t])};a.prototype.toString=function(){var e=[];for(var n in this)if(this.hasOwnProperty(n)){var t=this[n];"function"==typeof t&&(t="[function]"),e.push(n+"="+t)}return"SimpleEvent("+e.join(", ")+")"};var u=function(e){var n=this;n._events=e||[],n._listeners={}};u.prototype.emit=function(e){var n=this;if(n._verifyType(e),!n._nuked){var t=Array.prototype.slice.call(arguments,1);if(n["on"+e]&&n["on"+e].apply(n,t),e in n._listeners)for(var r=0;r<n._listeners[e].length;r++)n._listeners[e][r].apply(n,t)}},u.prototype.on=function(e,n){var t=this;t._verifyType(e),t._nuked||(e in t._listeners||(t._listeners[e]=[]),t._listeners[e].push(n))},u.prototype._verifyType=function(e){var n=this;-1===o.arrIndexOf(n._events,e)&&o.log("Event "+p.stringify(e)+" not listed "+p.stringify(n._events)+" in "+n)},u.prototype.nuke=function(){var e=this;e._nuked=!0;for(var n=0;n<e._events.length;n++)delete e[e._events[n]];e._listeners={}};var s="abcdefghijklmnopqrstuvwxyz0123456789_";o.random_string=function(e,n){n=n||s.length;var t,r=[];for(t=0;e>t;t++)r.push(s.substr(Math.floor(Math.random()*n),1));return r.join("")},o.random_number=function(e){return Math.floor(Math.random()*e)},o.random_number_string=function(e){var n=(""+(e-1)).length,t=Array(n+1).join("0");return(t+o.random_number(e)).slice(-n)},o.getOrigin=function(e){e+="/";var n=e.split("/").slice(0,3);return n.join("/")},o.isSameOriginUrl=function(e,n){return n||(n=r.location.href),e.split("/").slice(0,3).join("/")===n.split("/").slice(0,3).join("/")},o.isSameOriginScheme=function(e,n){return n||(n=r.location.href),e.split(":")[0]===n.split(":")[0]},o.getParentDomain=function(e){if(/^[0-9.]*$/.test(e))return e;if(/^\[/.test(e))return e;if(!/[.]/.test(e))return e;var n=e.split(".").slice(1);return n.join(".")},o.objectExtend=function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e};var c="_jp";o.polluteGlobalNamespace=function(){c in r||(r[c]={})},o.closeFrame=function(e,n){return"c"+p.stringify([e,n])},o.userSetCode=function(e){return 1e3===e||e>=3e3&&4999>=e},o.countRTO=function(e){var n;return n=e>100?3*e:e+200},o.log=function(){e._debug.apply(null,arguments)},o.bind=function(e,n){return e.bind?e.bind(n):function(){return e.apply(n,arguments)}},o.flatUrl=function(e){return-1===e.indexOf("?")&&-1===e.indexOf("#")},o.amendUrl=function(e){var n=t.location;if(!e)throw new Error("Wrong url for SockJS");if(!o.flatUrl(e))throw new Error("Only basic urls are supported in SockJS");0===e.indexOf("//")&&(e=n.protocol+e),0===e.indexOf("/")&&(e=n.protocol+"//"+n.host+e),e=e.replace(/[/]+$/,"");var r=e.split("/");return("http:"===r[0]&&/:80$/.test(r[2])||"https:"===r[0]&&/:443$/.test(r[2]))&&(r[2]=r[2].replace(/:(80|443)$/,"")),e=r.join("/")},o.arrIndexOf=function(e,n){for(var t=0;t<e.length;t++)if(e[t]===n)return t;return-1},o.arrSkip=function(e,n){var t=o.arrIndexOf(e,n);if(-1===t)return e.slice();var r=e.slice(0,t);return r.concat(e.slice(t+1))},o.isArray=Array.isArray||function(e){return{}.toString.call(e).indexOf("Array")>=0},o.delay=function(e,n){return"function"==typeof e&&(n=e,e=0),setTimeout(n,e)};var l,f=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d={"\x00":"\\u0000","":"\\u0001","":"\\u0002","":"\\u0003","":"\\u0004","":"\\u0005","":"\\u0006","":"\\u0007","\b":"\\b"," ":"\\t","\n":"\\n","":"\\u000b","\f":"\\f","\r":"\\r","":"\\u000e","":"\\u000f","":"\\u0010","":"\\u0011","":"\\u0012","":"\\u0013","":"\\u0014","":"\\u0015","":"\\u0016","":"\\u0017","":"\\u0018","":"\\u0019","":"\\u001a","":"\\u001b","":"\\u001c","":"\\u001d","":"\\u001e","":"\\u001f",'"':'\\"',"\\":"\\\\","":"\\u007f","":"\\u0080","":"\\u0081","":"\\u0082","":"\\u0083","":"\\u0084","
":"\\u0085","":"\\u0086","":"\\u0087","":"\\u0088","":"\\u0089","":"\\u008a","":"\\u008b","":"\\u008c","":"\\u008d","":"\\u008e","":"\\u008f","":"\\u0090","":"\\u0091","":"\\u0092","":"\\u0093","":"\\u0094","":"\\u0095","":"\\u0096","":"\\u0097","":"\\u0098","":"\\u0099","":"\\u009a","":"\\u009b","":"\\u009c","":"\\u009d","":"\\u009e","":"\\u009f","":"\\u00ad","":"\\u0600","":"\\u0601","":"\\u0602","":"\\u0603","":"\\u0604","":"\\u070f","឴":"\\u17b4","឵":"\\u17b5","":"\\u200c","":"\\u200d","":"\\u200e","":"\\u200f","\u2028":"\\u2028","\u2029":"\\u2029","":"\\u202a","":"\\u202b","":"\\u202c","":"\\u202d","":"\\u202e"," ":"\\u202f","":"\\u2060","":"\\u2061","":"\\u2062","":"\\u2063","":"\\u2064","":"\\u2065","":"\\u2066","":"\\u2067","":"\\u2068","":"\\u2069","":"\\u206a","":"\\u206b","":"\\u206c","":"\\u206d","":"\\u206e","":"\\u206f","":"\\ufeff","":"\\ufff0","":"\\ufff1","":"\\ufff2","":"\\ufff3","":"\\ufff4","":"\\ufff5","":"\\ufff6","":"\\ufff7","":"\\ufff8","":"\\ufff9","":"\\ufffa","":"\\ufffb","":"\\ufffc","�":"\\ufffd","":"\\ufffe","":"\\uffff"},h=/[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g,v=p&&p.stringify||function(e){return f.lastIndex=0,f.test(e)&&(e=e.replace(f,function(e){return d[e]})),'"'+e+'"'},_=function(e){var n,t={},r=[];for(n=0;65536>n;n++)r.push(String.fromCharCode(n));return e.lastIndex=0,r.join("").replace(e,function(e){return t[e]="\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4),""}),e.lastIndex=0,t};o.quote=function(e){var n=v(e);return h.lastIndex=0,h.test(n)?(l||(l=_(h)),n.replace(h,function(e){return l[e]})):n};var m=["websocket","xdr-streaming","xhr-streaming","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"];o.probeProtocols=function(){for(var e={},n=0;n<m.length;n++){var t=m[n];e[t]=T[t]&&T[t].enabled()}return e},o.detectProtocols=function(e,n,t){var r={},o=[];n||(n=m);for(var i=0;i<n.length;i++){var a=n[i];r[a]=e[a]}var u=function(e){var n=e.shift();r[n]?o.push(n):e.length>0&&u(e)};return t.websocket!==!1&&u(["websocket"]),r["xhr-streaming"]&&!t.null_origin?o.push("xhr-streaming"):!r["xdr-streaming"]||t.cookie_needed||t.null_origin?u(["iframe-eventsource","iframe-htmlfile"]):o.push("xdr-streaming"),r["xhr-polling"]&&!t.null_origin?o.push("xhr-polling"):!r["xdr-polling"]||t.cookie_needed||t.null_origin?u(["iframe-xhr-polling","jsonp-polling"]):o.push("xdr-polling"),o};var g="_sockjs_global";o.createHook=function(){var e="a"+o.random_string(8);if(!(g in r)){var n={};r[g]=function(e){return e in n||(n[e]={id:e,del:function(){delete n[e]}}),n[e]}}return r[g](e)},o.attachMessage=function(e){o.attachEvent("message",e)},o.attachEvent=function(e,n){"undefined"!=typeof r.addEventListener?r.addEventListener(e,n,!1):(t.attachEvent("on"+e,n),r.attachEvent("on"+e,n))},o.detachMessage=function(e){o.detachEvent("message",e)},o.detachEvent=function(e,n){"undefined"!=typeof r.addEventListener?r.removeEventListener(e,n,!1):(t.detachEvent("on"+e,n),r.detachEvent("on"+e,n))};var y={},b=!1,w=function(){for(var e in y)y[e](),delete y[e]};o.unload_add=function(e){var n=o.random_string(8);return y[n]=e,b&&o.delay(w),n},o.unload_del=function(e){e in y&&delete y[e]},o.createIframe=function(e,n){var r,i,a=t.createElement("iframe"),u=function(){clearTimeout(r);try{a.onload=null}catch(e){}a.onerror=null},s=function(){a&&(u(),setTimeout(function(){a&&a.parentNode.removeChild(a),a=null},0),o.unload_del(i))},c=function(e){a&&(s(),n(e))},l=function(e,n){try{a&&a.contentWindow&&a.contentWindow.postMessage(e,n)}catch(t){}};return a.src=e,a.style.display="none",a.style.position="absolute",a.onerror=function(){c("onerror")},a.onload=function(){clearTimeout(r),r=setTimeout(function(){c("onload timeout")},2e3)},t.body.appendChild(a),r=setTimeout(function(){c("timeout")},15e3),i=o.unload_add(s),{post:l,cleanup:s,loaded:u}},o.createHtmlfile=function(e,n){var t,i,a,u=new ActiveXObject("htmlfile"),s=function(){clearTimeout(t)},l=function(){u&&(s(),o.unload_del(i),a.parentNode.removeChild(a),a=u=null,CollectGarbage())},f=function(e){u&&(l(),n(e))},d=function(e,n){try{a&&a.contentWindow&&a.contentWindow.postMessage(e,n)}catch(t){}};u.open(),u.write('<html><script>document.domain="'+document.domain+'";'+"</s"+"cript></html>"),u.close(),u.parentWindow[c]=r[c];var p=u.createElement("div");return u.body.appendChild(p),a=u.createElement("iframe"),p.appendChild(a),a.src=e,t=setTimeout(function(){f("timeout")},15e3),i=o.unload_add(l),{post:d,cleanup:l,loaded:s}};var E=function(){};E.prototype=new u(["chunk","finish"]),E.prototype._start=function(e,n,t,i){var a=this;try{a.xhr=new XMLHttpRequest}catch(u){}if(!a.xhr)try{a.xhr=new r.ActiveXObject("Microsoft.XMLHTTP")}catch(u){}(r.ActiveXObject||r.XDomainRequest)&&(n+=(-1===n.indexOf("?")?"?":"&")+"t="+ +new Date),a.unload_ref=o.unload_add(function(){a._cleanup(!0)});try{a.xhr.open(e,n,!0)}catch(s){return a.emit("finish",0,""),a._cleanup(),void 0}if(i&&i.no_credentials||(a.xhr.withCredentials="true"),i&&i.headers)for(var c in i.headers)a.xhr.setRequestHeader(c,i.headers[c]);a.xhr.onreadystatechange=function(){if(a.xhr){var e=a.xhr;switch(e.readyState){case 3:try{var n=e.status,t=e.responseText}catch(e){}1223===n&&(n=204),t&&t.length>0&&a.emit("chunk",n,t);break;case 4:var n=e.status;1223===n&&(n=204),a.emit("finish",n,e.responseText),a._cleanup(!1)}}},a.xhr.send(t)},E.prototype._cleanup=function(e){var n=this;if(n.xhr){if(o.unload_del(n.unload_ref),n.xhr.onreadystatechange=function(){},e)try{n.xhr.abort()}catch(t){}n.unload_ref=n.xhr=null}},E.prototype.close=function(){var e=this;e.nuke(),e._cleanup(!0)};var k=o.XHRCorsObject=function(){var e=this,n=arguments;o.delay(function(){e._start.apply(e,n)})};k.prototype=new E;var S=o.XHRLocalObject=function(e,n,t){var r=this;o.delay(function(){r._start(e,n,t,{no_credentials:!0})})};S.prototype=new E;var O=o.XDRObject=function(e,n,t){var r=this;o.delay(function(){r._start(e,n,t)})};O.prototype=new u(["chunk","finish"]),O.prototype._start=function(e,n,t){var r=this,i=new XDomainRequest;n+=(-1===n.indexOf("?")?"?":"&")+"t="+ +new Date;var a=i.ontimeout=i.onerror=function(){r.emit("finish",0,""),r._cleanup(!1)};i.onprogress=function(){r.emit("chunk",200,i.responseText)},i.onload=function(){r.emit("finish",200,i.responseText),r._cleanup(!1)},r.xdr=i,r.unload_ref=o.unload_add(function(){r._cleanup(!0)});try{r.xdr.open(e,n),r.xdr.send(t)}catch(u){a()}},O.prototype._cleanup=function(e){var n=this;if(n.xdr){if(o.unload_del(n.unload_ref),n.xdr.ontimeout=n.xdr.onerror=n.xdr.onprogress=n.xdr.onload=null,e)try{n.xdr.abort()}catch(t){}n.unload_ref=n.xdr=null}},O.prototype.close=function(){var e=this;e.nuke(),e._cleanup(!0)},o.isXHRCorsCapable=function(){return r.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?1:r.XDomainRequest&&t.domain?2:W.enabled()?3:4};var T=function(e,n,t){if(!(this instanceof T))return new T(e,n,t);var r,i=this;i._options={devel:!1,debug:!1,protocols_whitelist:[],info:void 0,rtt:void 0},t&&o.objectExtend(i._options,t),i._base_url=o.amendUrl(e),i._server=i._options.server||o.random_number_string(1e3),i._options.protocols_whitelist&&i._options.protocols_whitelist.length?r=i._options.protocols_whitelist:(r="string"==typeof n&&n.length>0?[n]:o.isArray(n)?n:null,r&&i._debug('Deprecated API: Use "protocols_whitelist" option instead of supplying protocol list as a second parameter to SockJS constructor.')),i._protocols=[],i.protocol=null,i.readyState=T.CONNECTING,i._ir=X(i._base_url),i._ir.onfinish=function(e,n){i._ir=null,e?(i._options.info&&(e=o.objectExtend(e,i._options.info)),i._options.rtt&&(n=i._options.rtt),i._applyInfo(e,n,r),i._didClose()):i._didClose(1002,"Can't connect to server",!0)}};T.prototype=new i,T.version="0.3.4",T.CONNECTING=0,T.OPEN=1,T.CLOSING=2,T.CLOSED=3,T.prototype._debug=function(){this._options.debug&&o.log.apply(o,arguments)},T.prototype._dispatchOpen=function(){var e=this;e.readyState===T.CONNECTING?(e._transport_tref&&(clearTimeout(e._transport_tref),e._transport_tref=null),e.readyState=T.OPEN,e.dispatchEvent(new a("open"))):e._didClose(1006,"Server lost session")},T.prototype._dispatchMessage=function(e){var n=this;n.readyState===T.OPEN&&n.dispatchEvent(new a("message",{data:e}))},T.prototype._dispatchHeartbeat=function(){var e=this;e.readyState===T.OPEN&&e.dispatchEvent(new a("heartbeat",{}))},T.prototype._didClose=function(e,n,t){var r=this;if(r.readyState!==T.CONNECTING&&r.readyState!==T.OPEN&&r.readyState!==T.CLOSING)throw new Error("INVALID_STATE_ERR");r._ir&&(r._ir.nuke(),r._ir=null),r._transport&&(r._transport.doCleanup(),r._transport=null);var i=new a("close",{code:e,reason:n,wasClean:o.userSetCode(e)});if(!o.userSetCode(e)&&r.readyState===T.CONNECTING&&!t){if(r._try_next_protocol(i))return;i=new a("close",{code:2e3,reason:"All transports failed",wasClean:!1,last_event:i})}r.readyState=T.CLOSED,o.delay(function(){r.dispatchEvent(i)})},T.prototype._didMessage=function(e){var n=this,t=e.slice(0,1);switch(t){case"o":n._dispatchOpen();break;case"a":for(var r=p.parse(e.slice(1)||"[]"),o=0;o<r.length;o++)n._dispatchMessage(r[o]);break;case"m":var r=p.parse(e.slice(1)||"null");n._dispatchMessage(r);break;case"c":var r=p.parse(e.slice(1)||"[]");n._didClose(r[0],r[1]);break;case"h":n._dispatchHeartbeat()}},T.prototype._try_next_protocol=function(e){var n=this;for(n.protocol&&(n._debug("Closed transport:",n.protocol,""+e),n.protocol=null),n._transport_tref&&(clearTimeout(n._transport_tref),n._transport_tref=null);;){var r=n.protocol=n._protocols.shift();if(!r)return!1;if(T[r]&&T[r].need_body===!0&&(!t.body||"undefined"!=typeof t.readyState&&"complete"!==t.readyState))return n._protocols.unshift(r),n.protocol="waiting-for-load",o.attachEvent("load",function(){n._try_next_protocol()}),!0;if(T[r]&&T[r].enabled(n._options)){var i=T[r].roundTrips||1,a=(n._options.rto||0)*i||5e3;n._transport_tref=o.delay(a,function(){n.readyState===T.CONNECTING&&n._didClose(2007,"Transport timeouted")});var u=o.random_string(8),s=n._base_url+"/"+n._server+"/"+u;return n._debug("Opening transport:",r," url:"+s," RTO:"+n._options.rto),n._transport=new T[r](n,s,n._base_url),!0}n._debug("Skipping transport:",r)}},T.prototype.close=function(e,n){var t=this;if(e&&!o.userSetCode(e))throw new Error("INVALID_ACCESS_ERR");return t.readyState!==T.CONNECTING&&t.readyState!==T.OPEN?!1:(t.readyState=T.CLOSING,t._didClose(e||1e3,n||"Normal closure"),!0)},T.prototype.send=function(e){var n=this;if(n.readyState===T.CONNECTING)throw new Error("INVALID_STATE_ERR");return n.readyState===T.OPEN&&n._transport.doSend(o.quote(""+e)),!0},T.prototype._applyInfo=function(e,n,r){var i=this;i._options.info=e,i._options.rtt=n,i._options.rto=o.countRTO(n),i._options.info.null_origin=!t.domain,e.base_url&&(i._base_url=e.base_url);var a=o.probeProtocols();i._protocols=o.detectProtocols(a,r,e),o.isSameOriginScheme(i._base_url)||2!==o.isXHRCorsCapable()||(i._protocols=["jsonp-polling"])};var I=T.websocket=function(e,n){var t=this,i=n+"/websocket";i="https"===i.slice(0,5)?"wss"+i.slice(5):"ws"+i.slice(4),t.ri=e,t.url=i;var a=r.WebSocket||r.MozWebSocket;t.ws=new a(t.url),t.ws.onmessage=function(e){t.ri._didMessage(e.data)},t.unload_ref=o.unload_add(function(){t.ws.close()}),t.ws.onclose=function(){t.ri._didMessage(o.closeFrame(1006,"WebSocket connection broken"))}};I.prototype.doSend=function(e){this.ws.send("["+e+"]")},I.prototype.doCleanup=function(){var e=this,n=e.ws;n&&(n.onmessage=n.onclose=null,n.close(),o.unload_del(e.unload_ref),e.unload_ref=e.ri=e.ws=null)},I.enabled=function(){return!(!r.WebSocket&&!r.MozWebSocket)},I.roundTrips=2;var C=function(){};C.prototype.send_constructor=function(e){var n=this;n.send_buffer=[],n.sender=e},C.prototype.doSend=function(e){var n=this;n.send_buffer.push(e),n.send_stop||n.send_schedule()},C.prototype.send_schedule_wait=function(){var e,n=this;n.send_stop=function(){n.send_stop=null,clearTimeout(e)},e=o.delay(25,function(){n.send_stop=null,n.send_schedule()})},C.prototype.send_schedule=function(){var e=this;if(e.send_buffer.length>0){var n="["+e.send_buffer.join(",")+"]";e.send_stop=e.sender(e.trans_url,n,function(n,t){e.send_stop=null,n===!1?e.ri._didClose(1006,"Sending error "+t):e.send_schedule_wait()}),e.send_buffer=[]}},C.prototype.send_destructor=function(){var e=this;e._send_stop&&e._send_stop(),e._send_stop=null};var R=function(e,n,r){var i=this;if(!("_send_form"in i)){var a=i._send_form=t.createElement("form"),u=i._send_area=t.createElement("textarea");u.name="d",a.style.display="none",a.style.position="absolute",a.method="POST",a.enctype="application/x-www-form-urlencoded",a.acceptCharset="UTF-8",a.appendChild(u),t.body.appendChild(a)}var a=i._send_form,u=i._send_area,s="a"+o.random_string(8);a.target=s,a.action=e+"/jsonp_send?i="+s;var c;try{c=t.createElement('<iframe name="'+s+'">')}catch(l){c=t.createElement("iframe"),c.name=s}c.id=s,a.appendChild(c),c.style.display="none";try{u.value=n}catch(f){o.log("Your browser is seriously broken. Go home! "+f.message)}a.submit();var d=function(){c.onerror&&(c.onreadystatechange=c.onerror=c.onload=null,o.delay(500,function(){c.parentNode.removeChild(c),c=null}),u.value="",r(!0))};return c.onerror=c.onload=d,c.onreadystatechange=function(){"complete"==c.readyState&&d()},d},N=function(e){return function(n,t,r){var o=new e("POST",n+"/xhr_send",t);return o.onfinish=function(e){r(200===e||204===e,"http status "+e)},function(e){r(!1,e)}}},A=function(e,n){var r,i,a=t.createElement("script"),u=function(e){i&&(i.parentNode.removeChild(i),i=null),a&&(clearTimeout(r),a.parentNode.removeChild(a),a.onreadystatechange=a.onerror=a.onload=a.onclick=null,a=null,n(e),n=null)},s=!1,c=null;if(a.id="a"+o.random_string(8),a.src=e,a.type="text/javascript",a.charset="UTF-8",a.onerror=function(){c||(c=setTimeout(function(){s||u(o.closeFrame(1006,"JSONP script loaded abnormally (onerror)"))},1e3))},a.onload=function(){u(o.closeFrame(1006,"JSONP script loaded abnormally (onload)"))},a.onreadystatechange=function(){if(/loaded|closed/.test(a.readyState)){if(a&&a.htmlFor&&a.onclick){s=!0;try{a.onclick()}catch(e){}}a&&u(o.closeFrame(1006,"JSONP script loaded abnormally (onreadystatechange)"))}},"undefined"==typeof a.async&&t.attachEvent)if(/opera/i.test(navigator.userAgent))i=t.createElement("script"),i.text="try{var a = document.getElementById('"+a.id+"'); if(a)a.onerror();}catch(x){};",a.async=i.async=!1;else{try{a.htmlFor=a.id,a.event="onclick"}catch(l){}a.async=!0}"undefined"!=typeof a.async&&(a.async=!0),r=setTimeout(function(){u(o.closeFrame(1006,"JSONP script loaded abnormally (timeout)"))},35e3);var f=t.getElementsByTagName("head")[0];return f.insertBefore(a,f.firstChild),i&&f.insertBefore(i,f.firstChild),u},D=T["jsonp-polling"]=function(e,n){o.polluteGlobalNamespace();var t=this;t.ri=e,t.trans_url=n,t.send_constructor(R),t._schedule_recv()};D.prototype=new C,D.prototype._schedule_recv=function(){var e=this,n=function(n){e._recv_stop=null,n&&(e._is_closing||e.ri._didMessage(n)),e._is_closing||e._schedule_recv()};e._recv_stop=M(e.trans_url+"/jsonp",A,n)},D.enabled=function(){return!0},D.need_body=!0,D.prototype.doCleanup=function(){var e=this;e._is_closing=!0,e._recv_stop&&e._recv_stop(),e.ri=e._recv_stop=null,e.send_destructor()};var M=function(e,n,t){var i="a"+o.random_string(6),a=e+"?c="+escape(c+"."+i),u=0,s=function(e){switch(u){case 0:delete r[c][i],t(e);break;case 1:t(e),u=2;break;case 2:delete r[c][i]}},l=n(a,s);r[c][i]=l;var f=function(){r[c][i]&&(u=1,r[c][i](o.closeFrame(1e3,"JSONP user aborted read")))};return f},x=function(){};x.prototype=new C,x.prototype.run=function(e,n,t,r,o){var i=this;i.ri=e,i.trans_url=n,i.send_constructor(N(o)),i.poll=new en(e,r,n+t,o)},x.prototype.doCleanup=function(){var e=this;e.poll&&(e.poll.abort(),e.poll=null)};var j=T["xhr-streaming"]=function(e,n){this.run(e,n,"/xhr_streaming",an,o.XHRCorsObject)};j.prototype=new x,j.enabled=function(){return r.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest&&!/opera/i.test(navigator.userAgent)},j.roundTrips=2,j.need_body=!0;var U=T["xdr-streaming"]=function(e,n){this.run(e,n,"/xhr_streaming",an,o.XDRObject)};U.prototype=new x,U.enabled=function(){return!!r.XDomainRequest},U.roundTrips=2;var P=T["xhr-polling"]=function(e,n){this.run(e,n,"/xhr",an,o.XHRCorsObject)};P.prototype=new x,P.enabled=j.enabled,P.roundTrips=2;var L=T["xdr-polling"]=function(e,n){this.run(e,n,"/xhr",an,o.XDRObject)};L.prototype=new x,L.enabled=U.enabled,L.roundTrips=2;var W=function(){};W.prototype.i_constructor=function(e,n,t){var r=this;r.ri=e,r.origin=o.getOrigin(t),r.base_url=t,r.trans_url=n;var i=t+"/iframe.html";r.ri._options.devel&&(i+="?t="+ +new Date),r.window_id=o.random_string(8),i+="#"+r.window_id,r.iframeObj=o.createIframe(i,function(e){r.ri._didClose(1006,"Unable to load an iframe ("+e+")")}),r.onmessage_cb=o.bind(r.onmessage,r),o.attachMessage(r.onmessage_cb)},W.prototype.doCleanup=function(){var e=this;if(e.iframeObj){o.detachMessage(e.onmessage_cb);try{e.iframeObj.iframe.contentWindow&&e.postMessage("c")}catch(n){}e.iframeObj.cleanup(),e.iframeObj=null,e.onmessage_cb=e.iframeObj=null}},W.prototype.onmessage=function(e){var n=this;if(e.origin===n.origin){var t=e.data.slice(0,8),r=e.data.slice(8,9),o=e.data.slice(9);if(t===n.window_id)switch(r){case"s":n.iframeObj.loaded(),n.postMessage("s",p.stringify([T.version,n.protocol,n.trans_url,n.base_url]));break;case"t":n.ri._didMessage(o)}}},W.prototype.postMessage=function(e,n){var t=this;t.iframeObj.post(t.window_id+e+(n||""),t.origin)},W.prototype.doSend=function(e){this.postMessage("m",e)},W.enabled=function(){var e=navigator&&navigator.userAgent&&-1!==navigator.userAgent.indexOf("Konqueror");return("function"==typeof r.postMessage||"object"==typeof r.postMessage)&&!e};var B,F=function(e,n){parent!==r?parent.postMessage(B+e+(n||""),"*"):o.log("Can't postMessage, no parent window.",e,n)},q=function(){};q.prototype._didClose=function(e,n){F("t",o.closeFrame(e,n))},q.prototype._didMessage=function(e){F("t",e)},q.prototype._doSend=function(e){this._transport.doSend(e)},q.prototype._doCleanup=function(){this._transport.doCleanup()},o.parent_origin=void 0,T.bootstrap_iframe=function(){var e;B=t.location.hash.slice(1);var n=function(n){if(n.source===parent&&("undefined"==typeof o.parent_origin&&(o.parent_origin=n.origin),n.origin===o.parent_origin)){var t=n.data.slice(0,8),i=n.data.slice(8,9),a=n.data.slice(9);if(t===B)switch(i){case"s":var u=p.parse(a),s=u[0],c=u[1],l=u[2],f=u[3];if(s!==T.version&&o.log('Incompatibile SockJS! Main site uses: "'+s+'", the iframe:'+' "'+T.version+'".'),!o.flatUrl(l)||!o.flatUrl(f))return o.log("Only basic urls are supported in SockJS"),void 0;if(!o.isSameOriginUrl(l)||!o.isSameOriginUrl(f))return o.log("Can't connect to different domain from within an iframe. ("+p.stringify([r.location.href,l,f])+")"),void 0;e=new q,e._transport=new q[c](e,l,f);break;case"m":e._doSend(a);break;case"c":e&&e._doCleanup(),e=null}}};o.attachMessage(n),F("s")};var $=function(e,n){var t=this;o.delay(function(){t.doXhr(e,n)})};$.prototype=new u(["finish"]),$.prototype.doXhr=function(e,n){var t=this,r=(new Date).getTime(),i=new n("GET",e+"/info?cb="+o.random_string(10)),a=o.delay(8e3,function(){i.ontimeout()});i.onfinish=function(e,n){if(clearTimeout(a),a=null,200===e){var o=(new Date).getTime()-r,i=p.parse(n);"object"!=typeof i&&(i={}),t.emit("finish",i,o)}else t.emit("finish")},i.ontimeout=function(){i.close(),t.emit("finish")}};var H=function(e){var n=this,r=function(){var t=new W;t.protocol="w-iframe-info-receiver";var r=function(e){if("string"==typeof e&&"m"===e.substr(0,1)){var r=p.parse(e.substr(1)),o=r[0],i=r[1];n.emit("finish",o,i)}else n.emit("finish");t.doCleanup(),t=null},o={_options:{},_didClose:r,_didMessage:r};t.i_constructor(o,e,e)};t.body?r():o.attachEvent("load",r)};H.prototype=new u(["finish"]);var V=function(){var e=this;o.delay(function(){e.emit("finish",{},2e3)})};V.prototype=new u(["finish"]);var X=function(e){if(o.isSameOriginUrl(e))return new $(e,o.XHRLocalObject);switch(o.isXHRCorsCapable()){case 1:return new $(e,o.XHRLocalObject);case 2:return o.isSameOriginScheme(e)?new $(e,o.XDRObject):new V;case 3:return new H(e);default:return new V}},J=q["w-iframe-info-receiver"]=function(e,n,t){var r=new $(t,o.XHRLocalObject);r.onfinish=function(n,t){e._didMessage("m"+p.stringify([n,t])),e._didClose()}};J.prototype.doCleanup=function(){};var Q=T["iframe-eventsource"]=function(){var e=this;e.protocol="w-iframe-eventsource",e.i_constructor.apply(e,arguments)};Q.prototype=new W,Q.enabled=function(){return"EventSource"in r&&W.enabled()},Q.need_body=!0,Q.roundTrips=3;var Y=q["w-iframe-eventsource"]=function(e,n){this.run(e,n,"/eventsource",nn,o.XHRLocalObject)};Y.prototype=new x;var G=T["iframe-xhr-polling"]=function(){var e=this;e.protocol="w-iframe-xhr-polling",e.i_constructor.apply(e,arguments)};G.prototype=new W,G.enabled=function(){return r.XMLHttpRequest&&W.enabled()},G.need_body=!0,G.roundTrips=3;var z=q["w-iframe-xhr-polling"]=function(e,n){this.run(e,n,"/xhr",an,o.XHRLocalObject)};z.prototype=new x;var K=T["iframe-htmlfile"]=function(){var e=this;e.protocol="w-iframe-htmlfile",e.i_constructor.apply(e,arguments)};K.prototype=new W,K.enabled=function(){return W.enabled()},K.need_body=!0,K.roundTrips=3;var Z=q["w-iframe-htmlfile"]=function(e,n){this.run(e,n,"/htmlfile",on,o.XHRLocalObject)};Z.prototype=new x;var en=function(e,n,t,r){var o=this;o.ri=e,o.Receiver=n,o.recv_url=t,o.AjaxObject=r,o._scheduleRecv()};en.prototype._scheduleRecv=function(){var e=this,n=e.poll=new e.Receiver(e.recv_url,e.AjaxObject),t=0;n.onmessage=function(n){t+=1,e.ri._didMessage(n.data)},n.onclose=function(t){e.poll=n=n.onmessage=n.onclose=null,e.poll_is_closing||("permanent"===t.reason?e.ri._didClose(1006,"Polling error ("+t.reason+")"):e._scheduleRecv())}},en.prototype.abort=function(){var e=this;e.poll_is_closing=!0,e.poll&&e.poll.abort()};var nn=function(e){var n=this,t=new EventSource(e);t.onmessage=function(e){n.dispatchEvent(new a("message",{data:unescape(e.data)}))},n.es_close=t.onerror=function(e,r){var i=r?"user":2!==t.readyState?"network":"permanent";n.es_close=t.onmessage=t.onerror=null,t.close(),t=null,o.delay(200,function(){n.dispatchEvent(new a("close",{reason:i}))})}};nn.prototype=new i,nn.prototype.abort=function(){var e=this;e.es_close&&e.es_close({},!0)};var tn,rn=function(){if(void 0===tn)if("ActiveXObject"in r)try{tn=!!new ActiveXObject("htmlfile")}catch(e){}else tn=!1;return tn},on=function(e){var n=this;o.polluteGlobalNamespace(),n.id="a"+o.random_string(6,26),e+=(-1===e.indexOf("?")?"?":"&")+"c="+escape(c+"."+n.id);var t,i=rn()?o.createHtmlfile:o.createIframe;r[c][n.id]={start:function(){t.loaded()},message:function(e){n.dispatchEvent(new a("message",{data:e}))},stop:function(){n.iframe_close({},"network")}},n.iframe_close=function(e,o){t.cleanup(),n.iframe_close=t=null,delete r[c][n.id],n.dispatchEvent(new a("close",{reason:o}))},t=i(e,function(){n.iframe_close({},"permanent")})};on.prototype=new i,on.prototype.abort=function(){var e=this;e.iframe_close&&e.iframe_close({},"user")};var an=function(e,n){var t=this,r=0;t.xo=new n("POST",e,null),t.xo.onchunk=function(e,n){if(200===e)for(;;){var o=n.slice(r),i=o.indexOf("\n");if(-1===i)break;r+=i+1;var u=o.slice(0,i);t.dispatchEvent(new a("message",{data:u}))}},t.xo.onfinish=function(e,n){t.xo.onchunk(e,n),t.xo=null;var r=200===e?"network":"permanent";t.dispatchEvent(new a("close",{reason:r}))}};return an.prototype=new i,an.prototype.abort=function(){var e=this;e.xo&&(e.xo.close(),e.dispatchEvent(new a("close",{reason:"user"})),e.xo=null)},T.getUtils=function(){return o},T.getIframeTransport=function(){return W},T}(),"function"==typeof define&&define.amd&&define("sockjs",[],function(){return r})}.call(this),function(){t.ClientStream=function(e){var n=this;n._initCommon(),n.HEARTBEAT_TIMEOUT=6e4,n.rawUrl=e,n.socket=null,n.sent_update_available=!1,n.heartbeatTimer=null,"undefined"!=typeof window&&window.addEventListener&&window.addEventListener("online",h.bind(n._online,n),!1),n._launchConnection()},h.extend(t.ClientStream.prototype,{send:function(e){var n=this;n.currentStatus.connected&&n.socket.send(e)},_changeUrl:function(e){var n=this;n.rawUrl=e},_connected:function(n){var t=this;if(t.connectionTimer&&(clearTimeout(t.connectionTimer),t.connectionTimer=null),!t.currentStatus.connected){try{var r=p.parse(n)}catch(o){e._debug("DEBUG: malformed welcome packet",n)}r&&r.server_id?__meteor_runtime_config__.serverId&&__meteor_runtime_config__.serverId!==r.server_id&&!t.sent_update_available&&(t.sent_update_available=!0,h.each(t.eventCallbacks.update_available,function(e){e()
})):e._debug("DEBUG: invalid welcome packet",r),t.currentStatus.status="connected",t.currentStatus.connected=!0,t.currentStatus.retryCount=0,t.statusChanged(),h.each(t.eventCallbacks.reset,function(e){e()})}},_cleanup:function(){var e=this;e._clearConnectionAndHeartbeatTimers(),e.socket&&(e.socket.onmessage=e.socket.onclose=e.socket.onerror=e.socket.onheartbeat=function(){},e.socket.close(),e.socket=null)},_clearConnectionAndHeartbeatTimers:function(){var e=this;e.connectionTimer&&(clearTimeout(e.connectionTimer),e.connectionTimer=null),e.heartbeatTimer&&(clearTimeout(e.heartbeatTimer),e.heartbeatTimer=null)},_heartbeat_timeout:function(){var n=this;e._debug("Connection timeout. No heartbeat received."),n._lostConnection()},_heartbeat_received:function(){var e=this;e._forcedToDisconnect||(e.heartbeatTimer&&clearTimeout(e.heartbeatTimer),e.heartbeatTimer=setTimeout(h.bind(e._heartbeat_timeout,e),e.HEARTBEAT_TIMEOUT))},_sockjsProtocolsWhitelist:function(){var e=["xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],n=navigator&&/iPhone|iPad|iPod/.test(navigator.userAgent)&&/OS 4_|OS 5_/.test(navigator.userAgent);return n||(e=["websocket"].concat(e)),e},_launchConnection:function(){var n=this;n._cleanup(),n.socket=new r(o(n.rawUrl),void 0,{debug:!1,protocols_whitelist:n._sockjsProtocolsWhitelist()}),n.socket.onmessage=function(e){n._heartbeat_received(),"connecting"===n.currentStatus.status?n._connected(e.data):n.currentStatus.connected&&h.each(n.eventCallbacks.message,function(n){n(e.data)})},n.socket.onclose=function(){n._lostConnection()},n.socket.onerror=function(){e._debug("stream error",h.toArray(arguments),(new Date).toDateString())},n.socket.onheartbeat=function(){n._heartbeat_received()},n.connectionTimer&&clearTimeout(n.connectionTimer),n.connectionTimer=setTimeout(h.bind(n._lostConnection,n),n.CONNECT_TIMEOUT)}})}.call(this),function(){var n=function(e,n){return e.length>=n.length&&e.substring(0,n.length)===n},r=function(e,n){return e.length>=n.length&&e.substring(e.length-n.length)===n},a=function(t,o,i){o||(o="http");var a,u=t.match(/^ddp(i?)\+sockjs:\/\//),s=t.match(/^http(s?):\/\//);if(u){var c=t.substr(u[0].length);a="i"===u[1]?o:o+"s";var l=c.indexOf("/"),d=-1===l?c:c.substr(0,l),p=-1===l?"":c.substr(l);return d=d.replace(/\*/g,function(){return Math.floor(10*f.fraction())}),a+"://"+d+p}if(s){a=s[1]?o+"s":o;var h=t.substr(s[0].length);t=a+"://"+h}return-1!==t.indexOf("://")||n(t,"/")||(t=o+"://"+t),t=e._relativeToSiteRootUrl(t),r(t,"/")?t+i:t+"/"+i};o=function(e){return a(e,"http","sockjs")},i=function(e){var n=a(e,"ws","websocket");return n},t.toSockjsUrl=o,h.extend(t.ClientStream.prototype,{on:function(e,n){var t=this;if("message"!==e&&"reset"!==e&&"update_available"!==e)throw new Error("unknown event type: "+e);t.eventCallbacks[e]||(t.eventCallbacks[e]=[]),t.eventCallbacks[e].push(n)},_initCommon:function(){var e=this;e.CONNECT_TIMEOUT=1e4,e.RETRY_BASE_TIMEOUT=1e3,e.RETRY_EXPONENT=2.2,e.RETRY_MAX_TIMEOUT=3e5,e.RETRY_MIN_TIMEOUT=10,e.RETRY_MIN_COUNT=2,e.RETRY_FUZZ=.5,e.eventCallbacks={},e._forcedToDisconnect=!1,e.currentStatus={status:"connecting",connected:!1,retryCount:0},e.statusListeners="undefined"!=typeof v&&new v.Dependency,e.statusChanged=function(){e.statusListeners&&e.statusListeners.changed()},e.retryTimer=null,e.connectionTimer=null},reconnect:function(e){var n=this;return e=e||{},e.url&&n._changeUrl(e.url),n.currentStatus.connected?((e._force||e.url)&&n._lostConnection(),void 0):("connecting"===n.currentStatus.status&&n._lostConnection(),n.retryTimer&&clearTimeout(n.retryTimer),n.retryTimer=null,n.currentStatus.retryCount-=1,n._retryNow(),void 0)},disconnect:function(e){var n=this;e=e||{},n._forcedToDisconnect||(e._permanent&&(n._forcedToDisconnect=!0),n._cleanup(),n.retryTimer&&(clearTimeout(n.retryTimer),n.retryTimer=null),n.currentStatus={status:e._permanent?"failed":"offline",connected:!1,retryCount:0},e._permanent&&e._error&&(n.currentStatus.reason=e._error),n.statusChanged())},_lostConnection:function(){var e=this;e._cleanup(),e._retryLater()},_retryTimeout:function(e){var n=this;if(e<n.RETRY_MIN_COUNT)return n.RETRY_MIN_TIMEOUT;var t=Math.min(n.RETRY_MAX_TIMEOUT,n.RETRY_BASE_TIMEOUT*Math.pow(n.RETRY_EXPONENT,e));return t*=f.fraction()*n.RETRY_FUZZ+(1-n.RETRY_FUZZ/2)},_online:function(){"offline"!=this.currentStatus.status&&this.reconnect()},_retryLater:function(){var e=this,n=e._retryTimeout(e.currentStatus.retryCount);e.retryTimer&&clearTimeout(e.retryTimer),e.retryTimer=setTimeout(h.bind(e._retryNow,e),n),e.currentStatus.status="waiting",e.currentStatus.connected=!1,e.currentStatus.retryTime=(new Date).getTime()+n,e.statusChanged()},_retryNow:function(){var e=this;e._forcedToDisconnect||(e.currentStatus.retryCount+=1,e.currentStatus.status="connecting",e.currentStatus.connected=!1,delete e.currentStatus.retryTime,e.statusChanged(),e._launchConnection())},status:function(){var e=this;return e.statusListeners&&e.statusListeners.depend(),e.currentStatus}})}.call(this),function(){n={},a=["pre1"],t.SUPPORTED_DDP_VERSIONS=a,u=function(e){this.isSimulation=e.isSimulation,this._unblock=e.unblock||function(){},this._calledUnblock=!1,this.userId=e.userId,this._setUserId=e.setUserId||function(){},this._sessionData=e.sessionData},h.extend(u.prototype,{unblock:function(){var e=this;e._calledUnblock=!0,e._unblock()},setUserId:function(e){var n=this;if(n._calledUnblock)throw new Error("Can't call setUserId in a method after calling unblock");n.userId=e,n._setUserId(e)}}),s=function(n){try{var t=p.parse(n)}catch(r){return e._debug("Discarding message with invalid JSON",n),null}return null===t||"object"!=typeof t?(e._debug("Discarding non-object DDP message",n),null):(h.has(t,"cleared")&&(h.has(t,"fields")||(t.fields={}),h.each(t.cleared,function(e){t.fields[e]=void 0}),delete t.cleared),h.each(["fields","params","result"],function(e){h.has(t,e)&&(t[e]=d._adjustTypesFromJSONValue(t[e]))}),t)},c=function(e){var n=d.clone(e);if(h.has(e,"fields")){var t=[];h.each(e.fields,function(e,r){void 0===e&&(t.push(r),delete n.fields[r])}),h.isEmpty(t)||(n.cleared=t),h.isEmpty(n.fields)&&delete n.fields}if(h.each(["fields","params","result"],function(e){h.has(n,e)&&(n[e]=d._adjustTypesToJSONValue(n[e]))}),e.id&&"string"!=typeof e.id)throw new Error("Message id is not a string");return p.stringify(n)},n._CurrentInvocation=new e.EnvironmentVariable}.call(this),function(){if(e.isServer){var r=Npm.require("path");Npm.require("fibers");var o=Npm.require(r.join("fibers","future"))}var i=function(n,r){var o=this;r=h.extend({reloadOnUpdate:!1,reloadWithOutstanding:!1,supportedDDPVersions:a,onConnectionFailure:function(n){e._debug("Failed DDP connection: "+n)},onConnected:function(){}},r),o.onReconnect=null,o._stream="object"==typeof n?n:new t.ClientStream(n),o._lastSessionId=null,o._versionSuggestion=null,o._version=null,o._stores={},o._methodHandlers={},o._nextMethodId=1,o._supportedDDPVersions=r.supportedDDPVersions,o._methodInvokers={},o._outstandingMethodBlocks=[],o._documentsWrittenByStub={},o._serverDocuments={},o._afterUpdateCallbacks=[],o._messagesBufferedUntilQuiescence=[],o._methodsBlockingQuiescence={},o._subsBeingRevived={},o._resetStores=!1,o._updatesForUnknownStores={},o._retryMigrate=null,o._subscriptions={},o._sessionData={},o._userId=null,o._userIdDeps="undefined"!=typeof v&&new v.Dependency,e.isClient&&Package.reload&&!r.reloadWithOutstanding&&_._onMigrate(function(e){if(o._readyToMigrate())return[!0];if(o._retryMigrate)throw new Error("Two migrations in progress?");return o._retryMigrate=e,!1});var i=function(n){try{var t=s(n)}catch(i){return e._debug("Exception while parsing DDP",i),void 0}if(null===t||!t.msg)return e._debug("discarding invalid livedata message",t),void 0;if("connected"===t.msg)o._version=o._versionSuggestion,r.onConnected(),o._livedata_connected(t);else if("failed"==t.msg)if(h.contains(o._supportedDDPVersions,t.version))o._versionSuggestion=t.version,o._stream.reconnect({_force:!0});else{var a="Version negotiation failed; server requested version "+t.version;o._stream.disconnect({_permanent:!0,_error:a}),r.onConnectionFailure(a)}else h.include(["added","changed","removed","ready","updated"],t.msg)?o._livedata_data(t):"nosub"===t.msg?o._livedata_nosub(t):"result"===t.msg?o._livedata_result(t):"error"===t.msg?o._livedata_error(t):e._debug("discarding unknown livedata message type",t)},u=function(){var e={msg:"connect"};o._lastSessionId&&(e.session=o._lastSessionId),e.version=o._versionSuggestion||o._supportedDDPVersions[0],o._versionSuggestion=e.version,e.support=o._supportedDDPVersions,o._send(e),!h.isEmpty(o._outstandingMethodBlocks)&&h.isEmpty(o._outstandingMethodBlocks[0].methods)&&o._outstandingMethodBlocks.shift(),h.each(o._methodInvokers,function(e){e.sentMessage=!1}),o.onReconnect?o._callOnReconnectAndSendAppropriateOutstandingMethods():o._sendOutstandingMethods(),h.each(o._subscriptions,function(e,n){o._send({msg:"sub",id:n,name:e.name,params:e.params})})};e.isServer?(o._stream.on("message",e.bindEnvironment(i,e._debug)),o._stream.on("reset",e.bindEnvironment(u,e._debug))):(o._stream.on("message",i),o._stream.on("reset",u)),e.isClient&&Package.reload&&r.reloadOnUpdate&&o._stream.on("update_available",function(){_._reload()})},g=function(e){var n=this;n.methodId=e.methodId,n.sentMessage=!1,n._callback=e.callback,n._connection=e.connection,n._message=e.message,n._onResultReceived=e.onResultReceived||function(){},n._wait=e.wait,n._methodResult=null,n._dataVisible=!1,n._connection._methodInvokers[n.methodId]=n};h.extend(g.prototype,{sendMessage:function(){var e=this;if(e.gotResult())throw new Error("sendingMethod is called on method with result");e._dataVisible=!1,e.sentMessage=!0,e._wait&&(e._connection._methodsBlockingQuiescence[e.methodId]=!0),e._connection._send(e._message)},_maybeInvokeCallback:function(){var e=this;e._methodResult&&e._dataVisible&&(e._callback(e._methodResult[0],e._methodResult[1]),delete e._connection._methodInvokers[e.methodId],e._connection._outstandingMethodFinished())},receiveResult:function(e,n){var t=this;if(t.gotResult())throw new Error("Methods should only receive results once");t._methodResult=[e,n],t._onResultReceived(e,n),t._maybeInvokeCallback()},dataVisible:function(){var e=this;e._dataVisible=!0,e._maybeInvokeCallback()},gotResult:function(){var e=this;return!!e._methodResult}}),h.extend(i.prototype,{registerStore:function(e,n){var t=this;if(e in t._stores)return!1;var r={};h.each(["update","beginUpdate","endUpdate","saveOriginals","retrieveOriginals"],function(e){r[e]=function(){return n[e]?n[e].apply(n,arguments):void 0}}),t._stores[e]=r;var o=t._updatesForUnknownStores[e];return o&&(r.beginUpdate(o.length,!1),h.each(o,function(e){r.update(e)}),r.endUpdate(),delete t._updatesForUnknownStores[e]),!0},subscribe:function(e){var n=this,t=Array.prototype.slice.call(arguments,1),r={};if(t.length){var o=t[t.length-1];"function"==typeof o?r.onReady=t.pop():!o||"function"!=typeof o.onReady&&"function"!=typeof o.onError||(r=t.pop())}var i,a=h.find(n._subscriptions,function(n){return n.inactive&&n.name===e&&d.equals(n.params,t)});a?(i=a.id,a.inactive=!1,r.onReady&&(a.ready||(a.readyCallback=r.onReady)),r.onError&&(a.errorCallback=r.onError)):(i=f.id(),n._subscriptions[i]={id:i,name:e,params:t,inactive:!1,ready:!1,readyDeps:"undefined"!=typeof v&&new v.Dependency,readyCallback:r.onReady,errorCallback:r.onError},n._send({msg:"sub",id:i,name:e,params:t}));var u={stop:function(){h.has(n._subscriptions,i)&&(n._send({msg:"unsub",id:i}),delete n._subscriptions[i])},ready:function(){if(!h.has(n._subscriptions,i))return!1;var e=n._subscriptions[i];return e.readyDeps&&e.readyDeps.depend(),e.ready}};return v.active&&v.onInvalidate(function(){h.has(n._subscriptions,i)&&(n._subscriptions[i].inactive=!0),v.afterFlush(function(){h.has(n._subscriptions,i)&&n._subscriptions[i].inactive&&u.stop()})}),u},_subscribeAndWait:function(e,n,t){var r=this,i=new o,a=!1;n=n||[],n.push({onReady:function(){a=!0,i["return"]()},onError:function(e){a?t&&t.onLateError&&t.onLateError(e):i["throw"](e)}}),r.subscribe.apply(r,[e].concat(n)),i.wait()},methods:function(e){var n=this;h.each(e,function(e,t){if(n._methodHandlers[t])throw new Error("A method named '"+t+"' is already defined");n._methodHandlers[t]=e})},call:function(e){var n=Array.prototype.slice.call(arguments,1);if(n.length&&"function"==typeof n[n.length-1])var t=n.pop();return this.apply(e,n,t)},apply:function(t,r,i,a){var s=this;a||"function"!=typeof i||(a=i,i={}),i=i||{},a&&(a=e.bindEnvironment(a,function(n){e._debug("Exception while delivering result of invoking '"+t+"'",n,n.stack)}));var c=function(){var e;return function(){return void 0===e&&(e=""+s._nextMethodId++),e}}(),l=n._CurrentInvocation.get(),f=l&&l.isSimulation,p=s._methodHandlers[t];if(p){var v=function(e){s.setUserId(e)},_=new u({isSimulation:!0,userId:s.userId(),setUserId:v,sessionData:s._sessionData});f||s._saveOriginals();try{var m=n._CurrentInvocation.withValue(_,function(){return e.isServer?e._noYieldsAllowed(function(){return p.apply(_,d.clone(r))}):p.apply(_,d.clone(r))})}catch(y){var b=y}f||s._retrieveAndStoreOriginals(c())}if(f){if(a)return a(b,m),void 0;if(b)throw b;return m}if(b&&!b.expected&&e._debug("Exception while simulating the effect of invoking '"+t+"'",b,b.stack),!a)if(e.isClient)a=function(){};else{var w=new o;a=w.resolver()}var E=new g({methodId:c(),callback:a,connection:s,onResultReceived:i.onResultReceived,wait:!!i.wait,message:{msg:"method",method:t,params:r,id:c()}});return i.wait?s._outstandingMethodBlocks.push({wait:!0,methods:[E]}):((h.isEmpty(s._outstandingMethodBlocks)||h.last(s._outstandingMethodBlocks).wait)&&s._outstandingMethodBlocks.push({wait:!1,methods:[]}),h.last(s._outstandingMethodBlocks).methods.push(E)),1===s._outstandingMethodBlocks.length&&E.sendMessage(),w?w.wait():void 0},_saveOriginals:function(){var e=this;h.each(e._stores,function(e){e.saveOriginals()})},_retrieveAndStoreOriginals:function(n){var t=this;if(t._documentsWrittenByStub[n])throw new Error("Duplicate methodId in _retrieveAndStoreOriginals");var r=[];h.each(t._stores,function(o,i){var a=o.retrieveOriginals();h.each(a,function(o,a){if("string"!=typeof a)throw new Error("id is not a string");r.push({collection:i,id:a});var u=e._ensure(t._serverDocuments,i,a);u.writtenByStubs?u.writtenByStubs[n]=!0:(u.document=o,u.flushCallbacks=[],u.writtenByStubs={},u.writtenByStubs[n]=!0)})}),h.isEmpty(r)||(t._documentsWrittenByStub[n]=r)},_unsubscribeAll:function(){var e=this;h.each(h.clone(e._subscriptions),function(n,t){e._send({msg:"unsub",id:t}),delete e._subscriptions[t]})},_send:function(e){var n=this;n._stream.send(c(e))},status:function(){var e=this;return e._stream.status.apply(e._stream,arguments)},reconnect:function(){var e=this;return e._stream.reconnect.apply(e._stream,arguments)},disconnect:function(){var e=this;return e._stream.disconnect.apply(e._stream,arguments)},close:function(){var e=this;return e._stream.disconnect({_permanent:!0})},userId:function(){var e=this;return e._userIdDeps&&e._userIdDeps.depend(),e._userId},setUserId:function(e){var n=this;n._userId!==e&&(n._userId=e,n._userIdDeps&&n._userIdDeps.changed())},_waitingForQuiescence:function(){var e=this;return!h.isEmpty(e._subsBeingRevived)||!h.isEmpty(e._methodsBlockingQuiescence)},_anyMethodsAreOutstanding:function(){var e=this;return h.any(h.pluck(e._methodInvokers,"sentMessage"))},_livedata_connected:function(e){var n=this;if(n._lastSessionId&&(n._resetStores=!0),"string"==typeof e.session){var t=n._lastSessionId===e.session;n._lastSessionId=e.session}t||(n._updatesForUnknownStores={},n._resetStores&&(n._documentsWrittenByStub={},n._serverDocuments={}),n._afterUpdateCallbacks=[],n._subsBeingRevived={},h.each(n._subscriptions,function(e,t){e.ready&&(n._subsBeingRevived[t]=!0)}),n._methodsBlockingQuiescence={},n._resetStores&&h.each(n._methodInvokers,function(e){e.gotResult()?n._afterUpdateCallbacks.push(h.bind(e.dataVisible,e)):e.sentMessage&&(n._methodsBlockingQuiescence[e.methodId]=!0)}),n._messagesBufferedUntilQuiescence=[],n._waitingForQuiescence()||(n._resetStores&&(h.each(n._stores,function(e){e.beginUpdate(0,!0),e.endUpdate()}),n._resetStores=!1),n._runAfterUpdateCallbacks()))},_processOneDataMessage:function(e,n){var t=this;t["_process_"+e.msg](e,n)},_livedata_data:function(e){var n=this,t={};if(n._waitingForQuiescence()){if(n._messagesBufferedUntilQuiescence.push(e),"nosub"===e.msg&&delete n._subsBeingRevived[e.id],h.each(e.subs||[],function(e){delete n._subsBeingRevived[e]}),h.each(e.methods||[],function(e){delete n._methodsBlockingQuiescence[e]}),n._waitingForQuiescence())return;h.each(n._messagesBufferedUntilQuiescence,function(e){n._processOneDataMessage(e,t)}),n._messagesBufferedUntilQuiescence=[]}else n._processOneDataMessage(e,t);(n._resetStores||!h.isEmpty(t))&&(h.each(n._stores,function(e,r){e.beginUpdate(h.has(t,r)?t[r].length:0,n._resetStores)}),n._resetStores=!1,h.each(t,function(e,t){var r=n._stores[t];r?h.each(e,function(e){r.update(e)}):(h.has(n._updatesForUnknownStores,t)||(n._updatesForUnknownStores[t]=[]),Array.prototype.push.apply(n._updatesForUnknownStores[t],e))}),h.each(n._stores,function(e){e.endUpdate()})),n._runAfterUpdateCallbacks()},_runAfterUpdateCallbacks:function(){var e=this,n=e._afterUpdateCallbacks;e._afterUpdateCallbacks=[],h.each(n,function(e){e()})},_pushUpdate:function(e,n,t){h.has(e,n)||(e[n]=[]),e[n].push(t)},_process_added:function(n,t){var r=this,o=e._get(r._serverDocuments,n.collection,n.id);if(o){if(void 0!==o.document)throw new Error("It doesn't make sense to be adding something we know exists: "+n.id);o.document=n.fields||{},o.document._id=m._idParse(n.id)}else r._pushUpdate(t,n.collection,n)},_process_changed:function(n,t){var r=this,o=e._get(r._serverDocuments,n.collection,n.id);if(o){if(void 0===o.document)throw new Error("It doesn't make sense to be changing something we don't think exists: "+n.id);m._applyChanges(o.document,n.fields)}else r._pushUpdate(t,n.collection,n)},_process_removed:function(n,t){var r=this,o=e._get(r._serverDocuments,n.collection,n.id);if(o){if(void 0===o.document)throw new Error("It doesn't make sense to be deleting something we don't know exists: "+n.id);o.document=void 0}else r._pushUpdate(t,n.collection,{msg:"removed",collection:n.collection,id:n.id})},_process_updated:function(n,t){var r=this;h.each(n.methods,function(n){h.each(r._documentsWrittenByStub[n],function(o){var i=e._get(r._serverDocuments,o.collection,o.id);if(!i)throw new Error("Lost serverDoc for "+p.stringify(o));if(!i.writtenByStubs[n])throw new Error("Doc "+p.stringify(o)+" not written by method "+n);delete i.writtenByStubs[n],h.isEmpty(i.writtenByStubs)&&(r._pushUpdate(t,o.collection,{msg:"replace",id:o.id,replace:i.document}),h.each(i.flushCallbacks,function(e){e()}),delete r._serverDocuments[o.collection][o.id])}),delete r._documentsWrittenByStub[n];var o=r._methodInvokers[n];if(!o)throw new Error("No callback invoker for method "+n);r._runWhenAllServerDocsAreFlushed(h.bind(o.dataVisible,o))})},_process_ready:function(e){var n=this;h.each(e.subs,function(e){n._runWhenAllServerDocsAreFlushed(function(){var t=n._subscriptions[e];t&&(t.ready||(t.readyCallback&&t.readyCallback(),t.ready=!0,t.readyDeps&&t.readyDeps.changed()))})})},_runWhenAllServerDocsAreFlushed:function(e){var n=this,t=function(){n._afterUpdateCallbacks.push(e)},r=0,o=function(){--r,0===r&&t()};h.each(n._serverDocuments,function(e){h.each(e,function(e){var t=h.any(e.writtenByStubs,function(e,t){var r=n._methodInvokers[t];return r&&r.sentMessage});t&&(++r,e.flushCallbacks.push(o))})}),0===r&&t()},_livedata_nosub:function(n){var t=this;if(t._livedata_data(n),h.has(t._subscriptions,n.id)){var r=t._subscriptions[n.id].errorCallback;delete t._subscriptions[n.id],r&&n.error&&r(new e.Error(n.error.error,n.error.reason,n.error.details))}},_process_nosub:function(){},_livedata_result:function(n){var t=this;if(h.isEmpty(t._outstandingMethodBlocks))return e._debug("Received method result but no methods outstanding"),void 0;for(var r,o=t._outstandingMethodBlocks[0].methods,i=0;i<o.length&&(r=o[i],r.methodId!==n.id);i++);return r?(o.splice(i,1),h.has(n,"error")?r.receiveResult(new e.Error(n.error.error,n.error.reason,n.error.details)):r.receiveResult(void 0,n.result),void 0):(e._debug("Can't match method response to original method call",n),void 0)},_outstandingMethodFinished:function(){var e=this;if(!e._anyMethodsAreOutstanding()){if(!h.isEmpty(e._outstandingMethodBlocks)){var n=e._outstandingMethodBlocks.shift();if(!h.isEmpty(n.methods))throw new Error("No methods outstanding but nonempty block: "+p.stringify(n));h.isEmpty(e._outstandingMethodBlocks)||e._sendOutstandingMethods()}e._maybeMigrate()}},_sendOutstandingMethods:function(){var e=this;h.isEmpty(e._outstandingMethodBlocks)||h.each(e._outstandingMethodBlocks[0].methods,function(e){e.sendMessage()})},_livedata_error:function(n){e._debug("Received error from server: ",n.reason),n.offendingMessage&&e._debug("For: ",n.offendingMessage)},_callOnReconnectAndSendAppropriateOutstandingMethods:function(){var e=this,n=e._outstandingMethodBlocks;if(e._outstandingMethodBlocks=[],e.onReconnect(),!h.isEmpty(n)){if(h.isEmpty(e._outstandingMethodBlocks))return e._outstandingMethodBlocks=n,e._sendOutstandingMethods(),void 0;h.last(e._outstandingMethodBlocks).wait||n[0].wait||(h.each(n[0].methods,function(n){h.last(e._outstandingMethodBlocks).methods.push(n),1===e._outstandingMethodBlocks.length&&n.sendMessage()}),n.shift()),h.each(n,function(n){e._outstandingMethodBlocks.push(n)})}},_readyToMigrate:function(){var e=this;return h.isEmpty(e._methodInvokers)},_maybeMigrate:function(){var e=this;e._retryMigrate&&e._readyToMigrate()&&(e._retryMigrate(),e._retryMigrate=null)}}),t.Connection=i,n.connect=function(e,n){var t=new i(e,{reloadOnUpdate:n});return l.push(t),t},l=[],n._allSubscriptionsReady=function(){return h.all(l,function(e){return h.all(e._subscriptions,function(e){return e.ready})})}}.call(this),function(){if(e.refresh=function(){},e.isClient){var t="/";"undefined"!=typeof __meteor_runtime_config__&&__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL&&(t=__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL),e.connection=n.connect(t,!0),h.each(["subscribe","methods","call","apply","status","reconnect","disconnect"],function(n){e[n]=h.bind(e.connection[n],e.connection)})}else e.connection=null;e.default_connection=e.connection,e.connect=n.connect}.call(this),"undefined"==typeof Package&&(Package={}),Package.livedata={DDP:n,LivedataTest:t}}(),function(){var e=Package.meteor.Meteor,n=Package.random.Random,t=Package.ejson.EJSON;Package.json.JSON;var r,o=Package.underscore._,i=Package.minimongo.LocalCollection,a=Package.livedata.DDP,u=Package.deps.Deps,s=Package.check.check,c=Package.check.Match;!function(){r=function(){var e=this;e.noConnCollections={}};var e=function(e,n){return e in n||(n[e]=new i(e)),n[e]};o.extend(r.prototype,{open:function(n,t){var r=this;return n?t?(t._mongo_livedata_collections||(t._mongo_livedata_collections={}),e(n,t._mongo_livedata_collections)):e(n,r.noConnCollections):new i}}),r=new r}.call(this),function(){e.Collection=function(t,a){var s=this;if(!(s instanceof e.Collection))throw new Error('use "new" to construct a Meteor.Collection');switch(a&&a.methods&&(a={connection:a}),a&&a.manager&&!a.connection&&(a.connection=a.manager),a=o.extend({connection:void 0,idGeneration:"STRING",transform:null,_driver:void 0,_preventAutopublish:!1},a),a.idGeneration){case"MONGO":s._makeNewID=function(){return new e.Collection.ObjectID};break;case"STRING":default:s._makeNewID=function(){return n.id()}}if(s._transform=a.transform?u._makeNonreactive(a.transform):null,t||null===t||e._debug("Warning: creating anonymous collection. It will not be saved or synchronized over the network. (Pass null for the collection name to turn off this warning.)"),s._connection=t&&null!==a.connection?a.connection?a.connection:e.isClient?e.connection:e.server:null,a._driver||(a._driver=t&&s._connection===e.server&&"undefined"!=typeof MongoInternals&&MongoInternals.defaultRemoteCollectionDriver?MongoInternals.defaultRemoteCollectionDriver():r),s._collection=a._driver.open(t,s._connection),s._name=t,s._connection&&s._connection.registerStore){var c=s._connection.registerStore(t,{beginUpdate:function(e,n){(e>1||n)&&s._collection.pauseObservers(),n&&s._collection.remove({})},update:function(e){var n=i._idParse(e.id),t=s._collection.findOne(n);if("replace"===e.msg){var r=e.replace;return r?t?s._collection.update(n,r):s._collection.insert(r):t&&s._collection.remove(n),void 0}if("added"===e.msg){if(t)throw new Error("Expected not to find a document already present for an add");s._collection.insert(o.extend({_id:n},e.fields))}else if("removed"===e.msg){if(!t)throw new Error("Expected to find a document already present for removed");s._collection.remove(n)}else{if("changed"!==e.msg)throw new Error("I don't know how to deal with this message");if(!t)throw new Error("Expected to find a document to change");if(!o.isEmpty(e.fields)){var a={};o.each(e.fields,function(e,n){void 0===e?(a.$unset||(a.$unset={}),a.$unset[n]=1):(a.$set||(a.$set={}),a.$set[n]=e)}),s._collection.update(n,a)}}},endUpdate:function(){s._collection.resumeObservers()},saveOriginals:function(){s._collection.saveOriginals()},retrieveOriginals:function(){return s._collection.retrieveOriginals()}});if(!c)throw new Error("There is already a collection named '"+t+"'")}s._defineMutationMethods(),Package.autopublish&&!a._preventAutopublish&&s._connection&&s._connection.publish&&s._connection.publish(null,function(){return s.find()},{is_auto:!0})},o.extend(e.Collection.prototype,{_getFindSelector:function(e){return 0==e.length?{}:e[0]},_getFindOptions:function(e){var n=this;return e.length<2?{transform:n._transform}:o.extend({transform:n._transform},e[1])},find:function(){var e=this,n=o.toArray(arguments);return e._collection.find(e._getFindSelector(n),e._getFindOptions(n))},findOne:function(){var e=this,n=o.toArray(arguments);return e._collection.findOne(e._getFindSelector(n),e._getFindOptions(n))}}),e.Collection._publishCursor=function(e,n,t){var r=e.observeChanges({added:function(e,r){n.added(t,e,r)},changed:function(e,r){n.changed(t,e,r)},removed:function(e){n.removed(t,e)}});n.onStop(function(){r.stop()})},e.Collection._rewriteSelector=function(t){if(i._selectorIsId(t)&&(t={_id:t}),!t||"_id"in t&&!t._id)return{_id:n.id()};var r={};return o.each(t,function(n,t){n instanceof RegExp?r[t]=l(n):n&&n.$regex instanceof RegExp?(r[t]=l(n.$regex),void 0!==n.$options&&(r[t].$options=n.$options)):r[t]=o.contains(["$or","$and","$nor"],t)?o.map(n,function(n){return e.Collection._rewriteSelector(n)}):n}),r};var l=function(e){s(e,RegExp);var n={$regex:e.source},t="";return e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),t&&(n.$options=t),n},f=function(n,t){if(!i._selectorIsIdPerhapsAsObject(n))throw new e.Error(403,"Not permitted. Untrusted code may only "+t+" documents by ID.")};o.each(["insert","update","remove"],function(n){e.Collection.prototype[n]=function(){var t,r,i=this,u=o.toArray(arguments);if(u.length&&u[u.length-1]instanceof Function&&(t=u.pop()),e.isClient&&!t&&(t=function(t){t&&e._debug(n+" failed: "+(t.reason||t.stack))}),"insert"===n){if(!u.length)throw new Error("insert requires an argument");if(u[0]=o.extend({},u[0]),"_id"in u[0]){if(r=u[0]._id,!("string"==typeof r||r instanceof e.Collection.ObjectID))throw new Error("Meteor requires document _id fields to be strings or ObjectIDs")}else r=u[0]._id=i._makeNewID()}else u[0]=e.Collection._rewriteSelector(u[0]);var s;if(t&&(s=function(e){t(e,!e&&r)}),i._connection&&i._connection!==e.server){var c=a._CurrentInvocation.get(),l=c&&c.isSimulation;l||"insert"===n||f(u[0],n),i._connection.apply(i._prefix+n,u,s)}else{u.push(s);try{i._collection[n].apply(i._collection,u)}catch(d){if(t)return t(d),null;throw d}}return r}}),e.Collection.prototype._ensureIndex=function(e,n){var t=this;if(!t._collection._ensureIndex)throw new Error("Can only call _ensureIndex on server collections");t._collection._ensureIndex(e,n)},e.Collection.prototype._dropIndex=function(e){var n=this;if(!n._collection._dropIndex)throw new Error("Can only call _dropIndex on server collections");n._collection._dropIndex(e)},e.Collection.prototype._createCappedCollection=function(e){var n=this;if(!n._collection._createCappedCollection)throw new Error("Can only call _createCappedCollection on server collections");n._collection._createCappedCollection(e)},e.Collection.ObjectID=i._ObjectID,function(){var n=function(e,n){var t=["insert","update","remove","fetch","transform"];o.each(o.keys(n),function(n){if(!o.contains(t,n))throw new Error(e+": Invalid key: "+n)});var r=this;if(r._restricted=!0,o.each(["insert","update","remove"],function(t){if(n[t]){if(!(n[t]instanceof Function))throw new Error(e+": Value for `"+t+"` must be a function");r._transform&&(n[t].transform=r._transform),n.transform&&(n[t].transform=u._makeNonreactive(n.transform)),r._validators[t][e].push(n[t])}}),n.update||n.remove||n.fetch){if(n.fetch&&!(n.fetch instanceof Array))throw new Error(e+": Value for `fetch` must be an array");r._updateFetch(n.fetch)}};e.Collection.prototype.allow=function(e){n.call(this,"allow",e)},e.Collection.prototype.deny=function(e){n.call(this,"deny",e)}}(),e.Collection.prototype._defineMutationMethods=function(){var n=this;if(n._restricted=!1,n._insecure=void 0,n._validators={insert:{allow:[],deny:[]},update:{allow:[],deny:[]},remove:{allow:[],deny:[]},fetch:[],fetchAllFields:!1},n._name&&(n._prefix="/"+n._name+"/",n._connection)){var t={};o.each(["insert","update","remove"],function(r){t[n._prefix+r]=function(){s(arguments,[c.Any]);try{if(this.isSimulation)return n._collection[r].apply(n._collection,o.toArray(arguments)),void 0;if("insert"!==r&&f(arguments[0],r),n._restricted){if(0===n._validators[r].allow.length)throw new e.Error(403,"Access denied. No allow validators set on restricted collection for method '"+r+"'.");var t="_validated"+r.charAt(0).toUpperCase()+r.slice(1),i=[this.userId].concat(o.toArray(arguments));n[t].apply(n,i)}else{if(!n._isInsecure())throw new e.Error(403,"Access denied");n._collection[r].apply(n._collection,o.toArray(arguments))}}catch(a){throw"MongoError"===a.name||"MinimongoError"===a.name?new e.Error(409,a.toString()):a}}}),(e.isClient||n._connection===e.server)&&n._connection.methods(t)}},e.Collection.prototype._updateFetch=function(e){var n=this;n._validators.fetchAllFields||(e?n._validators.fetch=o.union(n._validators.fetch,e):(n._validators.fetchAllFields=!0,n._validators.fetch=null))},e.Collection.prototype._isInsecure=function(){var e=this;return void 0===e._insecure?!!Package.insecure:e._insecure};var d=function(e,n){var r=n;return e.transform&&(r=e.transform(t.clone(n))),r};e.Collection.prototype._validatedInsert=function(n,t){var r=this;if(o.any(r._validators.insert.deny,function(e){return e(n,d(e,t))}))throw new e.Error(403,"Access denied");if(o.all(r._validators.insert.allow,function(e){return!e(n,d(e,t))}))throw new e.Error(403,"Access denied");r._collection.insert.call(r._collection,t)};var p=function(e,n){return e.transform?e.transform(n):n};e.Collection.prototype._validatedUpdate=function(n,t,r,a){var u=this;if(!i._selectorIsIdPerhapsAsObject(t))throw new Error("validated update should be of a single ID");var s=[];o.each(r,function(n,t){if("$"!==t.charAt(0))throw new e.Error(403,"Access denied. In a restricted collection you can only update documents, not replace them. Use a Mongo update operator, such as '$set'.");if(!o.has(h,t))throw new e.Error(403,"Access denied. Operator "+t+" not allowed in a restricted collection.");o.each(o.keys(n),function(e){-1!==e.indexOf(".")&&(e=e.substring(0,e.indexOf("."))),o.contains(s,e)||s.push(e)})});var c={transform:null};u._validators.fetchAllFields||(c.fields={},o.each(u._validators.fetch,function(e){c.fields[e]=1}));var l=u._collection.findOne(t,c);if(l){var f;if(o.any(u._validators.update.deny,function(e){return f||(f=p(e,l)),e(n,f,s,r)
}))throw new e.Error(403,"Access denied");if(o.all(u._validators.update.allow,function(e){return f||(f=p(e,l)),!e(n,f,s,r)}))throw new e.Error(403,"Access denied");u._collection.update.call(u._collection,t,r,a)}};var h={$inc:1,$set:1,$unset:1,$addToSet:1,$pop:1,$pullAll:1,$pull:1,$pushAll:1,$push:1,$bit:1};e.Collection.prototype._validatedRemove=function(n,t){var r=this,i={transform:null};r._validators.fetchAllFields||(i.fields={},o.each(r._validators.fetch,function(e){i.fields[e]=1}));var a=r._collection.findOne(t,i);if(a){if(o.any(r._validators.remove.deny,function(e){return e(n,p(e,a))}))throw new e.Error(403,"Access denied");if(o.all(r._validators.remove.allow,function(e){return!e(n,p(e,a))}))throw new e.Error(403,"Access denied");r._collection.remove.call(r._collection,t)}}}.call(this),"undefined"==typeof Package&&(Package={}),Package["mongo-livedata"]={}}(),function(){Package.meteor.Meteor,"undefined"==typeof Package&&(Package={}),Package.startup={}}(),function(){Package.meteor.Meteor;var e,n=Package.underscore._;!function(){function t(e){return JSON.stringify(e)}function r(e,u){var s,c,l,f,d,p=i,h=u[e];switch(h&&"object"==typeof h&&"function"==typeof h.toJSON&&(h=h.toJSON(e)),"function"==typeof o&&(h=o.call(u,e,h)),typeof h){case"string":return t(h);case"number":return isFinite(h)?String(h):"null";case"boolean":case"null":return String(h);case"object":if(!h)return"null";if(i+=a,d=[],"[object Array]"===Object.prototype.toString.apply(h)){for(f=h.length,s=0;f>s;s+=1)d[s]=r(s,h)||"null";return l=0===d.length?"[]":i?"[\n"+i+d.join(",\n"+i)+"\n"+p+"]":"["+d.join(",")+"]",i=p,l}if(o&&"object"==typeof o)for(f=o.length,s=0;f>s;s+=1)"string"==typeof o[s]&&(c=o[s],l=r(c,h),l&&d.push(t(c)+(i?": ":":")+l));else n.each(n.keys(h).sort(),function(e){l=r(e,h),l&&d.push(t(e)+(i?": ":":")+l)});return l=0===d.length?"{}":i?"{\n"+i+d.join(",\n"+i)+"\n"+p+"}":"{"+d.join(",")+"}",i=p,l}}var o,i,a;e=function(e,n,t){var u;if(i="",a="","number"==typeof t)for(u=0;t>u;u+=1)a+=" ";else"string"==typeof t&&(a=t);if(o=n,n&&"function"!=typeof n&&("object"!=typeof n||"number"!=typeof n.length))throw new Error("stringify");return r("",{"":e})}}.call(this),"undefined"==typeof Package&&(Package={}),Package["canonical-stringify"]={stringify:e}}(),function(){Package.meteor.Meteor,"undefined"==typeof Package&&(Package={}),Package["browser-msg"]={}}(),function(){var e,n,t,r,o,i,a,u,s=Package.meteor.Meteor,c=Package.ejson.EJSON,l=Package.underscore._,f=Package.random.Random,d=Package["canonical-stringify"].stringify;!function(){u="object"==typeof u?u:{};var n,t,r,o,i;n=function(){function e(e,n){this.entry=e,this.parentContext=n}return e.prototype.add=function(n){return new e(n,this)},e.prototype.toArray=function(){var e,n,t;for(e=[],n=this;null!=n;)t=n.entry,null!=t&&e.push(t),n=n.parentContext;return e.reverse()},e}(),t=new s.EnvironmentVariable,r=function(){var e;return e=t.get(),null!=e?e.toArray():[]},i=function(e,r){var o;if("function"!=typeof r)throw new Error("withContext: fn arg is not a function: "+r);return o=new n(e,t.get()),t.withValue(o,r)},o=function(e){return t.withValue(null,e)},e={getContext:r,resetContext:o,withContext:i}}.call(this),function(){u="object"==typeof u?u:{};var t,r,o,i,a,l,f,d,p;f=function(e){var n;if(null===e)return"null";if("undefined"==typeof e)return"undefined";if("string"==typeof e)return e;try{return e.toString()}catch(t){return n=t,c.stringify(l(n))}},t=function(){function e(){}return e}(),l=function(e,n){var r,o,i,a,u,s;return null===e?i="null":"undefined"==typeof e?i="undefined":(i=null!==e.message&&"undefined"!=typeof e.message?f(e.message):f(e),null!==e.stack&&"undefined"!=typeof e.stack&&(a=f(e.stack)),e instanceof Error&&(r=null!=(s=e.constructor)?s.name:void 0,null!=r&&(u=f(r)))),o=new t,o.message=i,null!=u&&(o.type=u),null!=a&&(o.stack=a),null!=n&&(o.context=n),o},d=function(e){var n,t,r,o;if(null!=e.stack?s._debug(e.stack):s._debug(e.message),null!=e.context)for(o=e.context,t=0,r=o.length;r>t;t++)n=o[t],s._debug("-",n)},p=function(n){d(l(n,e.getContext()))},r=function(){function e(e){this.reason=e}return e}(),i=function(e,n){var t;try{return e()}catch(o){throw t=o,t instanceof r||p(t),new r(n)}},a=function(e){if("function"!=typeof e)throw new Error("not a function: "+e);return s.defer(function(){return i(e)})},o=function(e){return s.bindEnvironment(e,p,this)},n={bind:o,catcherr:i,defer:a,Failed:r,reportError:p}}.call(this),function(){u="object"==typeof u?u:{};var e=[].slice;t=function(){var t,r;return r=[],t=function(){var t,o,i,a;if(t=1<=arguments.length?e.call(arguments,0):[],null!=r)for(i=0,a=r.length;a>i;i++)o=r[i],n.catcherr(function(){return o.apply(null,t)})},t.listen=function(e){null!=r&&r.push(e)},t.dispose=function(){r=null},t}}.call(this),function(){u="object"==typeof u?u:{},r=function(){function e(){this._done=!1,this._failed=null,this._doneFanout=t()}return e.prototype.callback=function(e){var t=this;if("function"!=typeof e)throw new Error("Result.on: callback is not a function: "+e);return this._done?n.catcherr(function(){return e(t._failed,t._value,t)}):this._doneFanout.listen(n.bind(e)),this},e.prototype.onSuccess=function(e){var t=this;if("function"!=typeof e)throw new Error("Result.onSuccess: callback is not a function: "+e);return this.callback(function(r,o){r||n.catcherr(function(){return e(o,t)})}),this},e.prototype.onFailure=function(e){var t=this;if("function"!=typeof e)throw new Error("Result.onFail: callback is not a function: "+e);return this.callback(function(r){r&&n.catcherr(function(){return e(r,t)})}),this},e.prototype._broadcast=function(){this._doneFanout(this._failed,this._value,this),this._doneFanout.dispose()},e.prototype.complete=function(n){return this._done?this:n instanceof e?(this.from(n),void 0):(this._done=!0,this._value=n,this._broadcast(),this)},e.prototype.fail=function(e){return this._done?this:(this._done=!0,this._failed=null!=e?e:!0,this._broadcast(),this)},e.prototype.into=function(e){return this.callback(function(n,t){return n?e.fail():e.complete(t)}),this},e.prototype.from=function(e){return e.into(this),this},e.prototype._run=function(t,r){var o,i;try{i=t(r)}catch(a){return o=a,n.reportError(o),this.fail(),void 0}i instanceof e?this.from(i):this.complete(i)},e.prototype.then=function(n,t){var r;if(null!=n&&"function"!=typeof n)throw new Error("Result.then: successFn is not a function: "+n);if(null!=t&&"function"!=typeof t)throw new Error("Result.then: failureFn is not a function: "+t);return r=new e,this.callback(function(e,o){null!=e?null!=t?r._run(t,e):r.fail():null!=n?r._run(n,o):r.complete(o)}),r},e.prototype.always=function(e){var n;return n=function(){e()},this.then(n,n)},e.value=function(n){var t;return t=new e,t.complete(n),t},e.completed=function(n){return e.value(n)},e.failed=function(n){var t;return t=new e,t.fail(n),t},e.delay=function(n,t){var r;return r=new e,s.setTimeout(function(){return r.complete(t)},n),r},e.defer=function(t){var r;return r=new e,n.defer(function(){return r.complete(t)}),r},e.join=function(n){var t,r,o,i,a,u,s,c,l;if(0===n.length)return e.completed([]);for(t=new e,u=n.length,o=0,i=[],s=function(e,n){return e.callback(function(e,r){return e?t.fail(e):(i[n]=r,++o,o===u?t.complete(i):void 0)})},r=c=0,l=n.length;l>c;r=++c)a=n[r],s(a,r);return t},e.map=function(n,t){var r,o,i,a,u;for(i=[],a=0,u=n.length;u>a;a++)r=n[a],o=new e,o._run(t,r),i.push(o);return e.join(i)},e.sequence=function(n,t){var r,o,i;return r=new e,o=0,i=function(n){var a;a=new e,a._run(t[o],n),a.callback(function(e,n){return null!=e?(r.fail(e),void 0):(++o,o===t.length?r.complete(n):i(n),void 0)})},e.value(n).callback(function(e,n){return null!=e?(r.fail(e),void 0):(i(n),void 0)}),r},e.prototype.timeout=function(n){var t,r;return r=new e,t=e.delay(n),t.onSuccess(function(){return r.fail("timeout")}),this.into(r),r},e.prototype.debug=function(e){return null==e&&(e="result"),this.callback(function(n,t){null!=n?s._debug(e,"FAILED",n):s._debug(e,"completed",t)}),this},e}()}.call(this),function(){u="object"==typeof u?u:{};var e,n,t,r,i,a;o={},o.isWebWorker=s.isClient&&("undefined"==typeof window||null===window)&&("undefined"==typeof document||null===document)&&"undefined"!=typeof importScripts&&null!==importScripts,o.isWebWorker?o.persistent=!0:s.isClient?o.persistent=!(null!=(e=s.settings)?null!=(n=e["public"])?null!=(t=n.offlineData)?t.disable:void 0:void 0:void 0)&&"undefined"!=typeof openDatabase&&null!==openDatabase&&(!(null!=(r=s.settings)?null!=(i=r["public"])?null!=(a=i.offlineData)?a.disableWorker:void 0:void 0:void 0)&&"undefined"!=typeof SharedWorker&&null!==SharedWorker||("undefined"!=typeof BrowserMsg&&null!==BrowserMsg?BrowserMsg.supported:void 0)):s.isServer&&(o.persistent=!0)}.call(this),function(){u="object"==typeof u?u:{};var r,a,c,l=[].slice;o.isWebWorker||(c={},a=function(e){return c[e]||(c[e]=new t)},r=function(n,t){e.withContext("received broadcast msg "+n,function(){a(n).apply(null,t)})},s.startup(function(){o._usingSharedWebWorker||BrowserMsg.listen({"/awwx/offline-data/broadcast":function(e,n){r(e,n)}})}),i=function(){var e,n;n=arguments[0],e=2<=arguments.length?l.call(arguments,1):[],BrowserMsg.send("/awwx/offline-data/broadcast",n,e)},i.includingSelf=function(){var e,t;t=arguments[0],e=2<=arguments.length?l.call(arguments,1):[],BrowserMsg.send("/awwx/offline-data/broadcast",t,e),n.defer(function(){return a(t).apply(null,e)})},i.listen=function(e,n){a(e).listen(n)})}.call(this),function(){u="object"==typeof u?u:{},a=function(e,n){var t,r,o;for(r=0,o=e.length;o>r;r++)if(t=e[r],c.equals(t,n))return!0;return!1}}.call(this),function(){u="object"==typeof u?u:{};var t,i,f,p,h,v,_,m,g,y,b=[].slice;o.persistent&&(t="awwx/offline-data",i="8",v=this,g=function(e){var n,t,r,o,i;for(n=[],r=e.rows,t=o=0,i=r.length;i>=0?i>o:o>i;t=i>=0?++o:--o)n.push(r.item(t));return n},m=function(e){return l.map(e,function(){return"?"}).join(",")},_=function(){return(new Date).getTime()},p=function(){var e,n,t;for(t=arguments[0],n=2<=arguments.length?b.call(arguments,1):[];n.length>0;)e=n.shift(),function(e){return t=t.then(function(){var n;return n=1<=arguments.length?b.call(arguments,0):[],e.apply(null,n)})}(e);return t},h=function(){var n,t;return n=arguments[0],t=2<=arguments.length?b.call(arguments,1):[],e.withContext(n,function(){return p.apply(null,[r.completed()].concat(b.call(t)))})},f=function(){function o(){this.databaseOpen=new r}return o.prototype.implementation="SQL",o.prototype.processTransaction=function(t,o){var i,a,u;if(!l.isFunction(t))throw new Error("fn should be a function");return u=new r,i=new r,o(n.bind(function(n){e.withContext("SQL transaction",function(){return t(n)}).into(i)}),function(e){n.reportError(e),u.fail()},function(){u.complete()}),a=new r,r.join([i,u]).onSuccess(function(e){var n,t;return n=e[0],t=e[1],a.complete(n)}).onFailure(function(){return a.fail()}),a},o.prototype._transaction=function(e){var n=this;return this.processTransaction(e,function(e,t,r){return n.sqldb.transaction(e,t,r)})},o.prototype.transaction=function(e){var n=this;return this.databaseOpen.then(function(){return n._transaction(e)})},o.prototype.changeVersion=function(e,n){var t=this;return this.processTransaction(n,function(n,r,o){return t.sqldb.changeVersion(t.sqldb.version,e,n,r,o)})},o.prototype.openDatabase=function(n){var r=this;return null==n&&(n={}),e.withContext("open SQL database",function(){r.sqldb=v.openDatabase(t,"","",1048576)})},o.prototype.sql=function(t,o,i){return e.withContext("execute SQL statement: "+o,function(){var e;return e=new r,t.executeSql(o,i,n.bind(function(n,t){e.complete(g(t))}),n.bind(function(t,r){n.reportError(r),e.fail()})),e})},o.prototype.listTables=function(e){var n=this;return h("listTables",function(){return n.sql(e,'SELECT * FROM sqlite_master\n WHERE type="table" AND\n name NOT LIKE "!_%" ESCAPE "!" AND\n name NOT LIKE "sqlite!_%" ESCAPE "!"')},function(e){var n;return function(){var t,r,o;for(o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(n.name);return o}().sort()})},o.prototype.dropTable=function(e,n){var t=this;return h("dropTable "+n,function(){return t.sql(e,"DROP TABLE "+n)})},o.prototype.dropAllTables=function(e){var n=this;return h("dropAllTables",function(){return n.listTables(e)},function(t){var o;return r.join(function(){var n,r,i;for(i=[],n=0,r=t.length;r>n;n++)o=t[n],i.push(this.dropTable(e,o));return i}.call(n))},function(){})},o.prototype.eraseDatabase=function(){var e=this;return h("eraseDatabase",function(){return e.openDatabase(),e.changeVersion("",function(n){return e.dropAllTables(n)})})},o.prototype.createTables=function(e){var n=this;return h("createTables",function(){return r.join([n.sql(e,"CREATE TABLE windows (\n windowId TEXT PRIMARY KEY NOT NULL,\n updateId INTEGER NOT NULL\n)"),n.sql(e,"CREATE TABLE agentWindow (\n singleton INTEGER PRIMARY KEY NOT NULL,\n windowId TEXT NOT NULL\n)"),n.sql(e,"CREATE TABLE docs (\n connection TEXT NOT NULL,\n collectionName TEXT NOT NULL,\n docId TEXT NOT NULL,\n doc TEXT NOT NULL,\n PRIMARY KEY (connection, collectionName, docId)\n)"),n.sql(e,"CREATE TABLE stubDocs (\n connection TEXT NOT NULL,\n methodId TEXT NOT NULL,\n collectionName TEXT NOT NULL,\n docId TEXT NOT NULL,\n PRIMARY KEY (connection, methodId, collectionName, docId)\n)"),n.sql(e,"CREATE TABLE queuedMethods (\n connection TEXT NOT NULL,\n methodId TEXT NOT NULL,\n method TEXT NOT NULL,\n PRIMARY KEY (connection, methodId)\n)"),n.sql(e,"CREATE TABLE windowSubscriptions (\n windowId TEXT NOT NULL,\n connection TEXT NOT NULL,\n subscription TEXT NOT NULL,\n PRIMARY KEY (windowId, connection, subscription)\n)"),n.sql(e,"CREATE TABLE subscriptions (\n connection TEXT NOT NULL,\n subscription TEXT NOT NULL,\n serverReady INTEGER NOT NULL,\n status TEXT NOT NULL,\n error TEXT NOT NULL,\n loaded INTEGER NOT NULL,\n PRIMARY KEY (connection, subscription)\n)"),n.sql(e,"CREATE TABLE methodsHoldingUpSubscriptions (\n connection TEXT NOT NULL,\n subscription TEXT NOT NULL,\n methodId TEXT NOT NULL,\n PRIMARY KEY (connection, subscription, methodId)\n)"),n.sql(e,"CREATE TABLE updates (\n id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n theUpdate TEXT NOT NULL\n)")])})},o.prototype.initializeNewDatabase=function(){var e=this;return h("initializeNewDatabase",function(){return e.changeVersion(i,function(n){return e.createTables(n)})})},o.prototype.resetDatabase=function(){var e=this;return h("resetDatabase",function(){return e.eraseDatabase()},function(){return e.initializeNewDatabase()})},o.prototype.upgradeDatabaseIfNeeded=function(){var e=this;return h("upgradeDatabaseIfNeeded",function(){return e.sqldb.version===i?r.completed():e.resetDatabase()})},o.prototype.open=function(){var e=this;return h("open",function(){return e.openDatabase(),e.upgradeDatabaseIfNeeded().into(e.databaseOpen),e.databaseOpen})},o.prototype.ensureWindow=function(e,n){var t=this;return h("ensureWindow",function(){return t.highestUpdateId(e)},function(r){return t.sql(e,"INSERT OR IGNORE INTO windows (windowId, updateId)\n VALUES (?, ?)",[n,r])})},o.prototype.readAllWindowIds=function(e){var n=this;return h("readKnownWindowIds",function(){return n.sql(e,"SELECT windowId FROM windows UNION\nSELECT windowId FROM windowSubscriptions UNION\nSELECT windowId FROM agentWindow")},function(e){var n,t,r,o;for(o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(n.windowId);return o})},o.prototype.deleteWindows=function(e,n){var t=this;return h("deleteWindows",function(){return t.sql(e,"DELETE FROM windows\n WHERE windowId IN ("+m(n)+")",n)},function(){return t.sql(e,"DELETE FROM windowSubscriptions\n WHERE windowId IN ("+m(n)+")",n)},function(){return t.sql(e,"DELETE FROM agentWindow\n WHERE windowId IN ("+m(n)+")",n)})},o.prototype.readAgentWindow=function(e){var t=this;return h("readAgentWindow",function(){return t.sql(e,"SELECT windowId FROM agentWindow")},function(e){return 0===e.length?null:1===e.length?e[0].windowId:(n.reportError("agentWindow table does not contain a singleton row"),r.failed())})},o.prototype.writeAgentWindow=function(e,n){var t=this;return h("writeAgentWindow",function(){return t.sql(e,"INSERT OR REPLACE INTO agentWindow\n (singleton, windowId) VALUES (0, ?)",[n])})},o.prototype.writeDoc=function(e,n,t,r){var o=this;return h("writeDoc",function(){return o.sql(e,"INSERT OR REPLACE INTO docs\n (connection, collectionName, docId, doc)\n VALUES (?, ?, ?, ?)",[n,t,r._id,c.stringify(r)])})},o.prototype.readDocs=function(e,n){var t=this;return h("readDocs",function(){return t.sql(e,"SELECT collectionName, doc FROM docs WHERE connection=?",[n])},function(e){var n,t,r,o,i;for(t={},o=0,i=e.length;i>o;o++)r=e[o],n=c.parse(r.doc),s._ensure(t,r.collectionName)[n._id]=n;return t})},o.prototype.readDocIdsOfCollection=function(e,n,t){var r=this;return h("readDocIdsOfCollection",function(){return r.sql(e,"SELECT docId FROM docs\n WHERE connection = ? AND\n collectionName = ?",[n,t])},function(e){return l.map(e,function(e){return e.docId})})},o.prototype.deleteDoc=function(e,n,t,r){var o=this;return h("deleteDoc",function(){return o.sql(e,"DELETE FROM docs\n WHERE connection=? AND\n collectionName=? AND\n docID=?",[n,t,r])})},o.prototype.addDocumentWrittenByStub=function(e,n,t,r,o){var i=this;return h("addDocumentWrittenByStub",function(){return i.sql(e,"INSERT INTO stubDocs\n (connection, methodId, collectionName, docId)\n VALUES (?, ?, ?, ?)",[n,t,r,o])})},o.prototype.isDocumentWrittenByAnyStub=function(e,n,t,r){var o=this;return h("isDocumentWrittenByAnyStub",function(){return o.sql(e,"SELECT 1 FROM stubDocs\n WHERE connection=? AND\n collectionName=? AND\n docID=?\n LIMIT 1",[n,t,r])},function(e){return e.length>0})},o.prototype.readDocsWrittenByStub=function(e,n,t){var r=this;return h("readDocsWrittenByStub",function(){return r.sql(e,"SELECT collectionName, docId FROM stubDocs\n WHERE connection=? AND\n methodId=?",[n,t])})},o.prototype.removeDocumentsWrittenByStub=function(e,n,t){var r=this;return h("removeDocumentsWrittenByStub",function(){return r.sql(e,"DELETE FROM stubDocs\n WHERE connection=? AND\n methodId=?",[n,t])})},o.prototype.readMethodsWithDocsWritten=function(e,n){var t=this;return h("readMethodsWithDocsWritten",function(){return t.sql(e,"SELECT DISTINCT methodId FROM stubDocs\n WHERE connection=?\n ORDER BY methodId",[n])},function(e){var n;return function(){var t,r,o;for(o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(n.methodId);return o}()})},o.prototype.addQueuedMethod=function(e,n,t,r,o){var i=this;return h("addQueuedMethod",function(){var a;return a=d({name:r,args:o}),i.sql(e,"INSERT INTO queuedMethods\n (connection, methodId, method)\n VALUES (?, ?, ?)",[n,t,a])})},o.prototype.readQueuedMethods=function(e){var n=this;return h("readQueuedMethods",function(){return n.sql(e,"SELECT connection, methodId, method FROM queuedMethods")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.method),t=u.name,n=u.args,r.push({connection:o.connection,methodId:o.methodId,name:t,args:n});return r})},o.prototype.removeQueuedMethod=function(e,n,t){var r=this;return h("removedQueuedMethod",function(){return r.sql(e,"DELETE FROM queuedMethods\n WHERE connection=? AND\n methodId=?",[n,t])})},o.prototype.addWindowSubscription=function(e,n,t,r,o){var i=this;return h("addWindowSubscription",function(){var a;return a=d({name:r,args:o}),i.sql(e,"INSERT OR IGNORE INTO windowSubscriptions\n (windowId, connection, subscription)\n VALUES (?, ?, ?)",[n,t,a])})},o.prototype.setWindowSubscriptions=function(e,n,t,o){var i=this;return h("setWindowSubscriptions",function(){return i.sql(e,"DELETE FROM windowSubscriptions\n WHERE windowId = ? AND connection = ?",[n,t])},function(){return r.map(o,function(r){var o;return o=d({name:r[0],args:r.slice(1)}),i.sql(e,"INSERT INTO windowSubscriptions\n (windowId, connection, subscription)\n VALUES (?, ?, ?)",[n,t,o])})})},o.prototype._testReadWindowSubscriptions=function(e){var n=this;return h("_testReadWindowSubscriptions",function(){return n.sql(e,"SELECT windowId, connection, subscription\n FROM windowSubscriptions\n ORDER BY windowId, connection, subscription")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({windowId:o.windowId,connection:o.connection,name:t,args:n});return r})},o.prototype.readMergedSubscriptions=function(e){var n=this;return h("readMergedSubscriptions",function(){return n.sql(e,"SELECT DISTINCT connection, subscription\n FROM windowSubscriptions\n ORDER BY connection, subscription")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({connection:o.connection,name:t,args:n});return r})},o.prototype.removeWindowSubscription=function(e,n,t,r,o){var i=this;return h("removeWindowSubscription",function(){var a;return a=d({name:r,args:o}),i.sql(e,"DELETE FROM windowSubscriptions\n WHERE windowId=? AND\n connection=? AND\n subscription=?",[n,t,a])})},o.prototype.ensureSubscription=function(e,n,t,r){var o=this;return h("ensureSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"INSERT OR IGNORE INTO subscriptions\n (connection, subscription, serverReady, loaded, status, error)\n VALUES (?, ?, 0, 0, 'subscribing', '')",[n,i])})},o.prototype.initializeSubscriptions=function(e){var n=this;return h("initializeSubscriptions",function(){return n.sql(e,"UPDATE subscriptions\n SET serverReady = 0,\n status = 'unsubscribed',\n error = ''")})},o.prototype.removeSubscription=function(e,n,t,r){var o=this;return h("removeSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"DELETE FROM subscriptions\n WHERE connection = ? AND\n subscription = ?",[n,i])})},o.prototype.cleanSubscriptions=function(e){var n=this;return h("cleanSubscriptions",function(){return r.join([n.readMergedSubscriptions(e),n.readSubscriptions(e)])},function(t){var o,i,u,s,c,l,f,d,p,h,v,_,m;for(u=t[0],c=t[1],l=[],d=0,h=c.length;h>d;d++)_=c[d],i=_.connection,s=_.name,o=_.args,a(u,{connection:i,name:s,args:o})||l.push({connection:i,name:s,args:o});for(f=[],p=0,v=l.length;v>p;p++)m=l[p],i=m.connection,s=m.name,o=m.args,f.push(n.removeSubscription(e,i,s,o));return r.join(f).then(function(){return l})})},o.prototype._loadSubscription=function(e){var n,t,r,o;return o=c.parse(e.subscription),t=o.name,n=o.args,r={connection:e.connection,name:t,args:n,serverReady:1===e.serverReady,status:e.status,loaded:1===e.loaded},""!==e.error&&(r.error=c.parse(e.error)),r},o.prototype.readSubscription=function(e,n,t,r){var o=this;return h("readSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"SELECT connection, subscription, serverReady, status,\n error, loaded\n FROM subscriptions\n WHERE connection=? AND subscription=?",[n,i])},function(e){return 0===e.length?null:o._loadSubscription(e[0])})},o.prototype.readSubscriptions=function(e){var n=this;return h("readSubscriptions",function(){return n.sql(e,"SELECT connection, subscription, serverReady, status,\n error, loaded\n FROM subscriptions\n ORDER BY connection, subscription")},function(e){return l.map(e,n._loadSubscription)})},o.prototype.haveSubscription=function(e,n,t,r){var o=this;return h("haveSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"SELECT 1 FROM subscriptions\n WHERE connection=? AND\n subscription=?",[n,i])},function(e){return e.length>0})},o.prototype.setSubscriptionServerReady=function(e,n,t,r){var o=this;return h("setSubscriptionServerReady",function(){var i;return i=d({name:t,args:r}),o.sql(e,"UPDATE subscriptions SET serverReady = 1\n WHERE connection=? AND\n subscription=?",[n,i])})},o.prototype.setSubscriptionStatus=function(e,n,t,r,o){var i=this;return h("setSubscriptionStatus",function(){var a;return a=d({name:t,args:r}),i.sql(e,"UPDATE subscriptions SET status=?\n WHERE connection=? AND\n subscription=?",[o,n,a])})},o.prototype.setSubscriptionReady=function(e,n,t,r){var o=this;return h("setSubscriptionReady",function(){var i;return i=d({name:t,args:r}),o.sql(e,"UPDATE subscriptions SET status = 'ready', loaded = 1\n WHERE connection = ? AND subscription = ?",[n,i])})},o.prototype.setSubscriptionError=function(e,n,t,r,o){var i=this;return h("setSubscriptionError",function(){var a;return a=d({name:t,args:r}),i.sql(e,"UPDATE subscriptions\n SET serverReady = 0, status = 'error', error = ?, loaded = 0\n WHERE connection = ? AND\n subscription = ?",[c.stringify(o),n,a])})},o.prototype.setSubscriptionLoaded=function(e,n,t,r){var o=this;return h("setSubscriptionLoaded",function(){var i;return i=d({name:t,args:r}),o.sql(e,"UPDATE subscriptions SET loaded = 1\n WHERE connection=? AND\n subscription=?",[n,i])})},o.prototype._testReadMethodsHoldingUpSubscriptions=function(e){var n=this;return h("_testReadMethodsHoldingUpSubscriptions",function(){return n.sql(e,"SELECT connection, subscription, methodId\n FROM methodsHoldingUpSubscriptions\n ORDER BY connection, subscription, methodId")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({connection:o.connection,name:t,args:n,methodId:o.methodId});return r})},o.prototype.readSubscriptionsHeldUp=function(e){var n=this;return h("readSubscriptionsHeldUp",function(){return n.sql(e,"SELECT DISTINCT connection, subscription\n FROM methodsHoldingUpSubscriptions\n ORDER BY connection, subscription")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({connection:o.connection,name:t,args:n});return r})},o.prototype.addSubscriptionWaitingOnMethods=function(e,n,t,o,i){var a=this;return h("addSubscriptionWaitingOnMethods",function(){var u,s,c,l,f,p;for(s=d({name:t,args:o}),c=[],l=function(t){return c.push(a.sql(e,"INSERT OR IGNORE INTO methodsHoldingUpSubscriptions\n (connection, subscription, methodId)\n VALUES (?, ?, ?)",[n,s,t]))},f=0,p=i.length;p>f;f++)u=i[f],l(u);return r.join(c)})},o.prototype.removeMethodHoldingUpSubscriptions=function(e,n){var t=this;return h("removeMethodHoldingUpSubscriptions",function(){return t.sql(e,"DELETE FROM methodsHoldingUpSubscriptions\n WHERE methodId=?",[n])})},o.prototype.addUpdate=function(e,n){var t=this;return h("addUpdate",function(){var r;return r=c.stringify(n),t.sql(e,"INSERT INTO updates (theUpdate) VALUES (?)",[r])})},o.prototype._loadUpdates=function(e){var n,t,r,o;for(n=[],r=0,o=e.length;o>r;r++)t=e[r],n.push({id:t.id,update:c.parse(t.theUpdate)});return n},o.prototype._testReadUpdates=function(e){var n=this;return h("_testReadUpdates",function(){return n.sql(e,"SELECT id, theUpdate FROM updates ORDER BY id")},function(e){return n._loadUpdates(e)})},o.prototype.highestUpdateId=function(e){var n=this;return h("highestUpdateId",function(){return n.sql(e,"SELECT MAX(id) AS id FROM updates")},function(e){var n;return null!=(n=e[0].id)?n:0})},o.prototype.writeWindowUpdateIndex=function(e,n,t){var r=this;return h("writeWindowUpdateIndex",function(){return r.sql(e,"UPDATE windows SET updateId = ?\n WHERE windowId = ?",[t,n])})},o.prototype.initializeWindowUpdateIndex=function(e,n){var t=this;return h("initializeWindowUpdateIndex",function(){return t.highestUpdateId(e)},function(r){return t.writeWindowUpdateIndex(e,n,r)})},o.prototype._testReadWindows=function(e){var n=this;return h("_testReadWindows",function(){return n.sql(e,"SELECT windowId, updateId FROM windows\n ORDER BY windowId")})},o.prototype.removeUpdatesProcessedByAllWindows=function(e){var n=this;return h("removeUpdatesProcessedByAllWindows",function(){return n.sql(e,"SELECT MIN(updateId) AS minUpdateId FROM windows")},function(t){var r,o,i;return r=null!=(o=null!=(i=t[0])?i.minUpdateId:void 0)?o:0,n.sql(e,"DELETE FROM updates WHERE id <= ?",[r])})},o.prototype.pullUpdatesForWindow=function(e,n){var t,r=this;return t=null,h("pullUpdatesForWindow",function(){return r.sql(e,"SELECT updateId FROM windows WHERE windowId=?",[n])},function(n){var t,o,i;return t=null!=(o=null!=(i=n[0])?i.updateId:void 0)?o:0,r.sql(e,"SELECT theUpdate FROM updates WHERE id > ?",[t])},function(o){var i;return t=function(){var e,n,t,r;for(t=this._loadUpdates(o),r=[],e=0,n=t.length;n>e;e++)i=t[e],r.push(i.update);return r}.call(r),r.initializeWindowUpdateIndex(e,n)},function(){return t})},o}(),y=new f,o._SQLStore=f,o._database=y,o._databaseName=t,o._databaseVersion=i,o.resetDatabase=function(){return y.resetDatabase()},s.startup(function(){!o._disableStartupForTesting&&o.persistent&&y.open()}))}.call(this),function(){u="object"==typeof u?u:{};var a,c,d,p,h,v,_,m,g,y,b,w,E,k,S;o.persistent&&(v=o._database,o._windows={},o._windows.windowsAreDead=S=new t,g=function(){return+new Date},o.isWebWorker?(_=function(e){var n,t,r;for(t=0,r=e.length;r>t;t++)n=e[t],WebWorker.windowIsDead(n);S(e)},p=!1,m=null,w={},WebWorker.addMessageHandler("goodbye",function(e,n){_([n.windowId])}),WebWorker.addMessageHandler("pong",function(e,n){null!=w&&delete w[n.windowId]}),d=function(){return _(l.keys(w)),p=!1,w=null},c=function(){return e.withContext("window check",function(){p||null!=m&&g()-m<9e3||(p=!0,v.transaction(function(e){return v.readAllWindowIds(e)}).then(function(e){var n,t,r,o,i,a,u,c,l,f;for(w={},l=WebWorker.windowIds,r=0,a=l.length;a>r;r++)t=l[r],w[t]=!0;for(o=0,u=e.length;u>o;o++)t=e[o],w[t]=!0;for(m=g(),f=WebWorker.ports,i=0,c=f.length;c>i;i++)n=f[i],n.postMessage({msg:"ping"});s.setTimeout(d,4e3)}))})},s.startup(function(){return c(),s.setInterval(c,1e4)})):(o._windows.thisWindowId=E=f.id(),o._windows.nowAgent=y=new t,w=null,m=null,p=!1,_=function(n){return e.withContext("deadWindows",function(){return v.transaction(function(e){return v.readAgentWindow(e).then(function(t){return null==t||l.contains(n,t)?a(e):r.completed()})}).then(function(){return S(n)})})},h=!1,o._windows.currentlyTheAgent=function(){return h},a=function(t){return e.withContext("becomeTheAgentWindow",function(){return h=!0,n.defer(function(){return y()}),v.writeAgentWindow(t,E)})},b=function(){return e.withContext("startupCheck",function(){return v.transaction(function(e){return v.readAgentWindow(e).then(function(n){var t;return null==n?a(e):(t=localStorage.getItem("/awwx/offline-data/agentWindowClosed"),t===n?a(e):void 0)}).then(function(){localStorage.removeItem("/awwx/offline-data/agentWindowClosed")})})})},c=function(){return e.withContext("window check",function(){return p?void 0:(p=!0,v.transaction(function(e){return v.readAllWindowIds(e)}).then(function(e){var n,t,o;if(!(null!=m&&g()-m<9e3)){for(w={},t=0,o=e.length;o>t;t++)n=e[t],n!==E&&(w[n]=!0);return i("ping"),r.delay(4e3).then(function(){return e})}}).then(function(){return _(l.keys(w))}).then(function(){return p=!1}))})},s.startup(function(){return e.withContext("windows startup",function(){return o._disableStartupForTesting?void 0:o._usingSharedWebWorker?v.transaction(function(e){return v.ensureWindow(e,E)}):(i.listen("ping",function(){return e.withContext("listen ping",function(){i("pong",E)})}),i.listen("pong",function(n){return e.withContext("listen pong",function(){null!=w&&delete w[n]})}),i.listen("goodbye",function(e){return _([e])}),v.transaction(function(e){return v.ensureWindow(e,E)}).then(function(){return b()}).then(function(){return c(),s.setInterval(c,1e4)}),void 0)})}),k=function(){return e.withContext("unload",function(){o._usingSharedWebWorker?o._sharedWebWorker.post({msg:"goodbye",windowId:E}):(h&&localStorage.setItem("/awwx/offline-data/agentWindowClosed",E),i("goodbye",E))})},null!=window.addEventListener&&window.addEventListener("unload",k,!1)))}.call(this),function(){u="object"==typeof u?u:{},o._subscriptionStatus=function(e){var n;return n={status:e.status,loaded:e.loaded},null!=e.error&&(n.error=e.error),n}}.call(this),function(){u="object"==typeof u?u:{};var t,f,p,h,v,_,m,g,y,b,w,E,k,S,O,T,I,C,R,N,A,D,M,x,j,U,P=[].slice;
o.persistent&&(w=o._database,o._test||(o._test={}),o.isWebWorker||(U=o._windows,I=U.nowAgent,A=U.thisWindowId),x=o._windows.windowsAreDead,o._messageAgent=function(){var e,t;if(t=arguments[0],e=2<=arguments.length?P.call(arguments,1):[],o.isWebWorker)throw new Error("oops, messaging agent from agent");o._usingSharedWebWorker?o._sharedWebWorker.post({msg:t,args:e}):o._windows.currentlyTheAgent()?n.defer(function(){return"function"==typeof E[t]?E[t].apply(E,e):void 0}):i.apply(null,[t].concat(P.call(e)))},o.isWebWorker?(WebWorker.addMessageHandler("update",function(e){var n,t,r,o;for(o=WebWorker.ports,t=0,r=o.length;r>t;t++)n=o[t],n!==e&&n.postMessage({msg:"update"})}),p=function(e,n){return WebWorker.addMessageHandler(e,function(){n()})},g=function(){var e,n,t,r;for(r=WebWorker.ports,n=0,t=r.length;t>n;n++)e=r[n],e.postMessage({msg:"update"})}):(E={},p=function(e,n){E[e]=n,i.listen(e,n)},g=function(){i.includingSelf("update")}),h=function(e,n,t){return null!=n&&(n.madeUpdate=!0),w.addUpdate(e,t)},_=function(e,n,t){return h(e,n,{update:"subscriptionStatus",subscription:{connection:t.connection,name:t.name,args:t.args},status:o._subscriptionStatus(t)})},m=function(e,n,t,r,o){return w.readSubscription(e,t,r,o).then(function(t){return _(e,n,t)})},D=function(n,t){return e.withContext("updateSubscriptionsReady",function(){return r.join([w.readSubscriptions(n),w.readSubscriptionsHeldUp(n)]).then(function(e){var o,i,u,s,c,l,f,d,p,h,v;for(f=e[0],d=e[1],s=[],p=0,h=f.length;h>p;p++)v=f[p],i=v.connection,u=v.name,o=v.args,c=v.serverReady,l=v.status,c&&"subscribing"===l&&!a(d,{connection:i,name:u,args:o})&&s.push({connection:i,name:u,args:o});return r.map(s,function(e){var r,o,i;return o=e.connection,i=e.name,r=e.args,w.setSubscriptionReady(n,o,i,r).then(function(){return m(n,t,o,i,r)})})})})},o._test.updateSubscriptionsReady=D,O=function(e){return{name:e.name,args:e.args}},v=o.isWebWorker?function(e){return w.transaction(e)}:function(e){return w.transaction(function(n){return w.readAgentWindow(n).then(function(t){return t===A?e(n):r.failed()})})},this.connectionAgents={},f=function(){function e(e,n){if(this.connectionName=e,this.meteorConnection=n,null!=connectionAgents[this.connectionName])throw new Error("a ConnectionAgent has already been constructed for this connection name: "+this.connectionName);connectionAgents[this.connectionName]=this,this.methodHandlers={},this.collectionAgents={},this.methodsSent={},this.meteorSubscriptionHandles={},this._nMeteorSubscriptionsReady=0,this._deletedRemovedDocs=!1}return e.prototype.deleteRemovedDocuments=function(e){return this._deletedRemovedDocs?r.completed():(this._deletedRemovedDocs=!0,this._eachCollectionAgent(function(n){return n.deleteDocumentsGoneFromServer(e)}))},e.prototype.checkIfReadyToDeleteDocs=function(e){return this.allMeteorSubscriptionsReady()?this.deleteRemovedDocuments(e):void 0},e.prototype._alreadyHaveMeteorSubscription=function(e){return!!this.meteorSubscriptionHandles[d(e)]},e.prototype.allMeteorSubscriptionsReady=function(){return this._nMeteorSubscriptionsReady===l.size(this.meteorSubscriptionHandles)},e.prototype._eachCollectionAgent=function(e){var n,t,o,i;o=[],i=this.collectionAgents;for(t in i)n=i[t],o.push(e(n));return r.join(o)},e.prototype.instantiateCollectionAgent=function(e){var n;(n=this.collectionAgents)[e]||(n[e]=new t(this,e,new s.Collection(e)))},e.prototype.instantiateCollectionAgents=function(e){var n,t,r;for(t=0,r=e.length;r>t;t++)n=e[t],this.instantiateCollectionAgent(n)},e.prototype.meteorSubscriptionReady=function(e){var n=this;return this.instantiateCollectionAgents(l.keys(this.meteorConnection._updatesForUnknownStores)),v(function(t){return w.setSubscriptionServerReady(t,n.connectionName,e.name,e.args).then(function(){return m(t,null,n.connectionName,e.name,e.args)}).then(function(){return D(t,null)}).then(function(){return++n._nMeteorSubscriptionsReady,n.checkIfReadyToDeleteDocs(t)}).then(function(){return g()})})},e.prototype.currentSubscriptions=function(){return l.map(l.keys(this.meteorSubscriptionHandles),c.parse)},e.prototype.oldSubscriptions=function(e){return l.reject(this.currentSubscriptions(),function(n){return a(e,n)})},e.prototype.newSubscriptions=function(e){var n=this;return l.reject(e,function(e){return n._alreadyHaveMeteorSubscription(e)})},e.prototype.stopOldSubscriptions=function(e,n,t){var o,i,a,u,s,c;for(a=[],c=this.oldSubscriptions(t),u=0,s=c.length;s>u;u++)i=c[u],o=d(i),this.meteorSubscriptionHandles[o].stop(),delete this.meteorSubscriptionHandles[o],n.madeUpdate=!0,a.push(w.addUpdate(e,{update:"subscriptionStatus",subscription:{connection:this.connectionName,name:i.name,args:i.args},status:{status:"unsubscribed",loaded:!1}}));return r.join(a)},e.prototype.subscriptionError=function(e,n){var t=this;w.transaction(function(r){return w.setSubscriptionError(r,t.connectionName,e.name,e.args,n).then(function(){return m(r,null,t.connectionName,e.name,e.args)})}).then(function(){return g()})},e.prototype.startNewSubscription=function(e){var n,t,r,o=this;this._deletedRemovedDocs=!1,r=e.name,n=e.args,t=s.subscribe.apply(s,[r].concat(P.call(n),[{onError:function(n){o.subscriptionError(e,n)},onReady:function(){o.meteorSubscriptionReady(e)}}])),this.meteorSubscriptionHandles[d(e)]=t},e.prototype.startNewSubscriptions=function(e,n,t){var o=this;return r.map(this.newSubscriptions(t),function(t){return o.startNewSubscription(t),w.ensureSubscription(e,o.connectionName,t.name,t.args).then(function(){return w.setSubscriptionStatus(e,o.connectionName,t.name,t.args,"subscribing")}).then(function(){return m(e,n,o.connectionName,t.name,t.args)})})},e.prototype.subscribeToSubscriptions=function(e,n,t){return t=l.map(t,O),r.join([this.stopOldSubscriptions(e,n,t),this.startNewSubscriptions(e,n,t)])},e.prototype.checkIfDocumentNowFree=function(e,n,t){return this.collectionAgents[n].updateDocFromServerIfFree(e,t)},e.prototype.methodCompleted=function(e){var n,t=this;n=null,v(function(o){return w.removeQueuedMethod(o,t.connectionName,e).then(function(){return w.readDocsWrittenByStub(o,this.connectionName,e)}).then(function(r){return n=r,w.removeDocumentsWrittenByStub(o,t.connectionName,e)}).then(function(){var e,i,a,u,s,c;for(a=[],u=0,s=n.length;s>u;u++)c=n[u],e=c.collectionName,i=c.docId,a.push(t.checkIfDocumentNowFree(o,e,i));return r.join(a)}).then(function(){return w.removeMethodHoldingUpSubscriptions(o,e)}).then(function(){return D(o,null)})}).then(function(){return g()})},e.prototype.sendQueuedMethod=function(e,n,t){var r=this;this.methodsSent[e]||(this.methodsSent[e]=!0,s.call("/awwx/offline-data/apply",e,n,t,function(t){t&&s._debug("offline method error",n,t),r.methodCompleted(e)}))},e}(),T=function(e){var n;return n="/"===e?s.default_connection:s.connect(e),new f(e,n)},b=function(e){return connectionAgents[e]||(connectionAgents[e]=T(e))},R=function(e){return w.readQueuedMethods(e).then(function(e){var n,t,r,o,i,a,u;for(i=0,a=e.length;a>i;i++)u=e[i],t=u.connection,r=u.methodId,o=u.name,n=u.args,b(t).sendQueuedMethod(r,o,n)})},C=function(){return v(function(e){return R(e)})},N=function(e,n){return w.readMergedSubscriptions(e).then(function(t){var o,i,a,u,s,c;for(s=0,c=t.length;c>s;s++)a=t[s],b(a.connection);u=[];for(i in connectionAgents)o=connectionAgents[i],u.push(o.subscribeToSubscriptions(e,n,l.filter(t,function(e){return e.connection===i})));r.join(u).then(function(){n.madeUpdate&&g()})})},t=function(){function e(e,n,t){this.connectionAgent=e,this.collectionName=n,this.serverCollection=t,this.connectionName=this.connectionAgent.connectionName,this.watchServer()}return e.prototype.offlineDocumentsNotInServerCollection=function(e){var n=this;return w.readDocIdsOfCollection(e,this.connectionName,this.collectionName).then(function(e){return l.reject(e,function(e){return n.serverCollection.findOne(e)})})},e.prototype.deleteDocUnlessWrittenByStub=function(e,n){var t=this;return w.isDocumentWrittenByAnyStub(e,this.connectionName,this.collectionName,n).then(function(r){return r?void 0:w.deleteDoc(e,t.connectionName,t.collectionName,n).then(function(){return t.addDocumentUpdate(e,n,null)})})},e.prototype.deleteDocumentsGoneFromServer=function(e){var n=this;return this.offlineDocumentsNotInServerCollection(e).then(function(t){var o,i,a,u;for(i=[],a=0,u=t.length;u>a;a++)o=t[a],i.push(n.deleteDocUnlessWrittenByStub(e,o));return r.join(i)})},e.prototype.addDocumentUpdate=function(e,n,t){return w.addUpdate(e,{update:"documentUpdated",connectionName:this.connectionName,collectionName:this.collectionName,docId:n,doc:t})},e.prototype.updateDocIfFree=function(e,n,t){var r=this;return w.isDocumentWrittenByAnyStub(e,this.connectionName,this.collectionName,n).then(function(o){return o?void 0:(null!=t?w.writeDoc(e,r.connectionName,r.collectionName,t):w.deleteDoc(e,r.connectionName,r.collectionName,n)).then(function(){return r.addDocumentUpdate(e,n,t)})})},e.prototype.updateDocFromServerIfFree=function(e,n){return this.updateDocIfFree(e,n,this.serverCollection.findOne(n))},e.prototype.serverDocUpdated=function(e,n){var t=this;v(function(r){return t.updateDocIfFree(r,e,n)}).then(function(){return g()})},e.prototype.watchServer=function(){var e=this;this.serverCollection.find().observe({added:function(n){return e.serverDocUpdated(n._id,n)},changed:function(n){return e.serverDocUpdated(n._id,n)},removed:function(n){return e.serverDocUpdated(n._id,null)}})},e}(),j=function(e){var n;return n={madeUpdate:!1},w.transaction(function(t){return e(t,n)}).then(function(){n.madeUpdate&&g()})},M=function(){j(function(e,n){return N(e,n)})},S=new r,y=function(e,n){return w.cleanSubscriptions(e).then(function(t){return r.map(t,function(t){return n.madeUpdate=!0,w.addUpdate(e,{update:"subscriptionStatus",subscription:t,status:{status:"unsubscribed",loaded:!1}})})})},k=function(){j(function(e,n){return y(e,n).then(function(){return w.initializeSubscriptions(e)}).then(function(){return w.readSubscriptions(e)}).then(function(t){return r.map(t,function(t){return _(e,n,t)})}).then(function(){return R(e)})}).then(function(){return S.complete()})},x.listen(function(e){S.then(function(){var n;n={madeUpdate:!1},v(function(t){return w.deleteWindows(t,e).then(function(){return y(t,n)}).then(function(){return N(t,n)})}).then(function(){return n.madeUpdate?g():void 0})})}),s.startup(function(){(o.isWebWorker||!o._usingSharedWebWorker)&&(p("windowSubscriptionsUpdated",function(){M()}),p("newQueuedMethod",function(){C()}),o.isWebWorker?k():I.listen(k))}))}.call(this),"undefined"==typeof Package&&(Package={}),Package["offline-common"]={Context:e,Errors:n,Fanout:t,Result:r,Offline:o,broadcast:i,contains:a}}(),_=Package.underscore._,Meteor=Package.meteor.Meteor,Deps=Package.deps.Deps,JSON=Package.json.JSON,EJSON=Package.ejson.EJSON,Reload=Package.reload.Reload,check=Package.check.check,Match=Package.check.Match,Random=Package.random.Random,DDP=Package.livedata.DDP,OrderedDict=Package["ordered-dict"].OrderedDict,LocalCollection=Package.minimongo.LocalCollection,stringify=Package["canonical-stringify"].stringify,Context=Package["offline-common"].Context,Errors=Package["offline-common"].Errors,Result=Package["offline-common"].Result,Offline=Package["offline-common"].Offline,broadcast=Package["offline-common"].broadcast,function(){!function(){var e,n;!function(){n={}}.call(this),function(){!function(){var e=this,t=e._,r={},o=Array.prototype,i=Object.prototype,a=Function.prototype,u=o.push,s=o.slice,c=o.concat,l=i.toString,f=i.hasOwnProperty,d=o.forEach,p=o.map,h=o.reduce,v=o.reduceRight,_=o.filter,m=o.every,g=o.some,y=o.indexOf,b=o.lastIndexOf,w=Array.isArray,E=Object.keys,k=a.bind,S=function(e){return e instanceof S?e:this instanceof S?(this._wrapped=e,void 0):new S(e)};"undefined"!=typeof n?("undefined"!=typeof module&&module.exports&&(n=module.exports=S),n._=S):e._=S,S.VERSION="1.5.1";var O=S.each=S.forEach=function(e,n,t){if(null!=e)if(d&&e.forEach===d)e.forEach(n,t);else if(e.length===+e.length){for(var o=0,i=e.length;i>o;o++)if(n.call(t,e[o],o,e)===r)return}else for(var a in e)if(S.has(e,a)&&n.call(t,e[a],a,e)===r)return};S.map=S.collect=function(e,n,t){var r=[];return null==e?r:p&&e.map===p?e.map(n,t):(O(e,function(e,o,i){r.push(n.call(t,e,o,i))}),r)};var T="Reduce of empty array with no initial value";S.reduce=S.foldl=S.inject=function(e,n,t,r){var o=arguments.length>2;if(null==e&&(e=[]),h&&e.reduce===h)return r&&(n=S.bind(n,r)),o?e.reduce(n,t):e.reduce(n);if(O(e,function(e,i,a){o?t=n.call(r,t,e,i,a):(t=e,o=!0)}),!o)throw new TypeError(T);return t},S.reduceRight=S.foldr=function(e,n,t,r){var o=arguments.length>2;if(null==e&&(e=[]),v&&e.reduceRight===v)return r&&(n=S.bind(n,r)),o?e.reduceRight(n,t):e.reduceRight(n);var i=e.length;if(i!==+i){var a=S.keys(e);i=a.length}if(O(e,function(u,s,c){s=a?a[--i]:--i,o?t=n.call(r,t,e[s],s,c):(t=e[s],o=!0)}),!o)throw new TypeError(T);return t},S.find=S.detect=function(e,n,t){var r;return I(e,function(e,o,i){return n.call(t,e,o,i)?(r=e,!0):void 0}),r},S.filter=S.select=function(e,n,t){var r=[];return null==e?r:_&&e.filter===_?e.filter(n,t):(O(e,function(e,o,i){n.call(t,e,o,i)&&r.push(e)}),r)},S.reject=function(e,n,t){return S.filter(e,function(e,r,o){return!n.call(t,e,r,o)},t)},S.every=S.all=function(e,n,t){n||(n=S.identity);var o=!0;return null==e?o:m&&e.every===m?e.every(n,t):(O(e,function(e,i,a){return(o=o&&n.call(t,e,i,a))?void 0:r}),!!o)};var I=S.some=S.any=function(e,n,t){n||(n=S.identity);var o=!1;return null==e?o:g&&e.some===g?e.some(n,t):(O(e,function(e,i,a){return o||(o=n.call(t,e,i,a))?r:void 0}),!!o)};S.contains=S.include=function(e,n){return null==e?!1:y&&e.indexOf===y?-1!=e.indexOf(n):I(e,function(e){return e===n})},S.invoke=function(e,n){var t=s.call(arguments,2),r=S.isFunction(n);return S.map(e,function(e){return(r?n:e[n]).apply(e,t)})},S.pluck=function(e,n){return S.map(e,function(e){return e[n]})},S.where=function(e,n,t){return S.isEmpty(n)?t?void 0:[]:S[t?"find":"filter"](e,function(e){for(var t in n)if(n[t]!==e[t])return!1;return!0})},S.findWhere=function(e,n){return S.where(e,n,!0)},S.max=function(e,n,t){if(!n&&S.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!n&&S.isEmpty(e))return-1/0;var r={computed:-1/0,value:-1/0};return O(e,function(e,o,i){var a=n?n.call(t,e,o,i):e;a>r.computed&&(r={value:e,computed:a})}),r.value},S.min=function(e,n,t){if(!n&&S.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!n&&S.isEmpty(e))return 1/0;var r={computed:1/0,value:1/0};return O(e,function(e,o,i){var a=n?n.call(t,e,o,i):e;a<r.computed&&(r={value:e,computed:a})}),r.value},S.shuffle=function(e){var n,t=0,r=[];return O(e,function(e){n=S.random(t++),r[t-1]=r[n],r[n]=e}),r};var C=function(e){return S.isFunction(e)?e:function(n){return n[e]}};S.sortBy=function(e,n,t){var r=C(n);return S.pluck(S.map(e,function(e,n,o){return{value:e,index:n,criteria:r.call(t,e,n,o)}}).sort(function(e,n){var t=e.criteria,r=n.criteria;if(t!==r){if(t>r||void 0===t)return 1;if(r>t||void 0===r)return-1}return e.index<n.index?-1:1}),"value")};var R=function(e,n,t,r){var o={},i=C(null==n?S.identity:n);return O(e,function(n,a){var u=i.call(t,n,a,e);r(o,u,n)}),o};S.groupBy=function(e,n,t){return R(e,n,t,function(e,n,t){(S.has(e,n)?e[n]:e[n]=[]).push(t)})},S.countBy=function(e,n,t){return R(e,n,t,function(e,n){S.has(e,n)||(e[n]=0),e[n]++})},S.sortedIndex=function(e,n,t,r){t=null==t?S.identity:C(t);for(var o=t.call(r,n),i=0,a=e.length;a>i;){var u=i+a>>>1;t.call(r,e[u])<o?i=u+1:a=u}return i},S.toArray=function(e){return e?S.isArray(e)?s.call(e):e.length===+e.length?S.map(e,S.identity):S.values(e):[]},S.size=function(e){return null==e?0:e.length===+e.length?e.length:S.keys(e).length},S.first=S.head=S.take=function(e,n,t){return null==e?void 0:null==n||t?e[0]:s.call(e,0,n)},S.initial=function(e,n,t){return s.call(e,0,e.length-(null==n||t?1:n))},S.last=function(e,n,t){return null==e?void 0:null==n||t?e[e.length-1]:s.call(e,Math.max(e.length-n,0))},S.rest=S.tail=S.drop=function(e,n,t){return s.call(e,null==n||t?1:n)},S.compact=function(e){return S.filter(e,S.identity)};var N=function(e,n,t){return n&&S.every(e,S.isArray)?c.apply(t,e):(O(e,function(e){S.isArray(e)||S.isArguments(e)?n?u.apply(t,e):N(e,n,t):t.push(e)}),t)};S.flatten=function(e,n){return N(e,n,[])},S.without=function(e){return S.difference(e,s.call(arguments,1))},S.uniq=S.unique=function(e,n,t,r){S.isFunction(n)&&(r=t,t=n,n=!1);var o=t?S.map(e,t,r):e,i=[],a=[];return O(o,function(t,r){(n?r&&a[a.length-1]===t:S.contains(a,t))||(a.push(t),i.push(e[r]))}),i},S.union=function(){return S.uniq(S.flatten(arguments,!0))},S.intersection=function(e){var n=s.call(arguments,1);return S.filter(S.uniq(e),function(e){return S.every(n,function(n){return S.indexOf(n,e)>=0})})},S.difference=function(e){var n=c.apply(o,s.call(arguments,1));return S.filter(e,function(e){return!S.contains(n,e)})},S.zip=function(){for(var e=S.max(S.pluck(arguments,"length").concat(0)),n=new Array(e),t=0;e>t;t++)n[t]=S.pluck(arguments,""+t);return n},S.object=function(e,n){if(null==e)return{};for(var t={},r=0,o=e.length;o>r;r++)n?t[e[r]]=n[r]:t[e[r][0]]=e[r][1];return t},S.indexOf=function(e,n,t){if(null==e)return-1;var r=0,o=e.length;if(t){if("number"!=typeof t)return r=S.sortedIndex(e,n),e[r]===n?r:-1;r=0>t?Math.max(0,o+t):t}if(y&&e.indexOf===y)return e.indexOf(n,t);for(;o>r;r++)if(e[r]===n)return r;return-1},S.lastIndexOf=function(e,n,t){if(null==e)return-1;var r=null!=t;if(b&&e.lastIndexOf===b)return r?e.lastIndexOf(n,t):e.lastIndexOf(n);for(var o=r?t:e.length;o--;)if(e[o]===n)return o;return-1},S.range=function(e,n,t){arguments.length<=1&&(n=e||0,e=0),t=arguments[2]||1;for(var r=Math.max(Math.ceil((n-e)/t),0),o=0,i=new Array(r);r>o;)i[o++]=e,e+=t;return i};var A=function(){};S.bind=function(e,n){var t,r;if(k&&e.bind===k)return k.apply(e,s.call(arguments,1));if(!S.isFunction(e))throw new TypeError;return t=s.call(arguments,2),r=function(){if(!(this instanceof r))return e.apply(n,t.concat(s.call(arguments)));A.prototype=e.prototype;var o=new A;A.prototype=null;var i=e.apply(o,t.concat(s.call(arguments)));return Object(i)===i?i:o}},S.partial=function(e){var n=s.call(arguments,1);return function(){return e.apply(this,n.concat(s.call(arguments)))}},S.bindAll=function(e){var n=s.call(arguments,1);if(0===n.length)throw new Error("bindAll must be passed function names");return O(n,function(n){e[n]=S.bind(e[n],e)}),e},S.memoize=function(e,n){var t={};return n||(n=S.identity),function(){var r=n.apply(this,arguments);return S.has(t,r)?t[r]:t[r]=e.apply(this,arguments)}},S.delay=function(e,n){var t=s.call(arguments,2);return setTimeout(function(){return e.apply(null,t)},n)},S.defer=function(e){return S.delay.apply(S,[e,1].concat(s.call(arguments,1)))},S.throttle=function(e,n,t){var r,o,i,a=null,u=0;t||(t={});var s=function(){u=t.leading===!1?0:new Date,a=null,i=e.apply(r,o)};return function(){var c=new Date;u||t.leading!==!1||(u=c);var l=n-(c-u);return r=this,o=arguments,0>=l?(clearTimeout(a),a=null,u=c,i=e.apply(r,o)):a||t.trailing===!1||(a=setTimeout(s,l)),i}},S.debounce=function(e,n,t){var r,o=null;return function(){var i=this,a=arguments,u=function(){o=null,t||(r=e.apply(i,a))},s=t&&!o;return clearTimeout(o),o=setTimeout(u,n),s&&(r=e.apply(i,a)),r}},S.once=function(e){var n,t=!1;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},S.wrap=function(e,n){return function(){var t=[e];return u.apply(t,arguments),n.apply(this,t)}},S.compose=function(){var e=arguments;return function(){for(var n=arguments,t=e.length-1;t>=0;t--)n=[e[t].apply(this,n)];return n[0]}},S.after=function(e,n){return function(){return--e<1?n.apply(this,arguments):void 0}},S.keys=E||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var n=[];for(var t in e)S.has(e,t)&&n.push(t);return n},S.values=function(e){var n=[];for(var t in e)S.has(e,t)&&n.push(e[t]);return n},S.pairs=function(e){var n=[];for(var t in e)S.has(e,t)&&n.push([t,e[t]]);return n},S.invert=function(e){var n={};for(var t in e)S.has(e,t)&&(n[e[t]]=t);return n},S.functions=S.methods=function(e){var n=[];for(var t in e)S.isFunction(e[t])&&n.push(t);return n.sort()},S.extend=function(e){return O(s.call(arguments,1),function(n){if(n)for(var t in n)e[t]=n[t]}),e},S.pick=function(e){var n={},t=c.apply(o,s.call(arguments,1));return O(t,function(t){t in e&&(n[t]=e[t])}),n},S.omit=function(e){var n={},t=c.apply(o,s.call(arguments,1));for(var r in e)S.contains(t,r)||(n[r]=e[r]);return n},S.defaults=function(e){return O(s.call(arguments,1),function(n){if(n)for(var t in n)void 0===e[t]&&(e[t]=n[t])}),e},S.clone=function(e){return S.isObject(e)?S.isArray(e)?e.slice():S.extend({},e):e},S.tap=function(e,n){return n(e),e};var D=function(e,n,t,r){if(e===n)return 0!==e||1/e==1/n;if(null==e||null==n)return e===n;e instanceof S&&(e=e._wrapped),n instanceof S&&(n=n._wrapped);var o=l.call(e);if(o!=l.call(n))return!1;switch(o){case"[object String]":return e==String(n);case"[object Number]":return e!=+e?n!=+n:0==e?1/e==1/n:e==+n;case"[object Date]":case"[object Boolean]":return+e==+n;case"[object RegExp]":return e.source==n.source&&e.global==n.global&&e.multiline==n.multiline&&e.ignoreCase==n.ignoreCase}if("object"!=typeof e||"object"!=typeof n)return!1;for(var i=t.length;i--;)if(t[i]==e)return r[i]==n;var a=e.constructor,u=n.constructor;if(a!==u&&!(S.isFunction(a)&&a instanceof a&&S.isFunction(u)&&u instanceof u))return!1;t.push(e),r.push(n);var s=0,c=!0;if("[object Array]"==o){if(s=e.length,c=s==n.length)for(;s--&&(c=D(e[s],n[s],t,r)););}else{for(var f in e)if(S.has(e,f)&&(s++,!(c=S.has(n,f)&&D(e[f],n[f],t,r))))break;if(c){for(f in n)if(S.has(n,f)&&!s--)break;c=!s}}return t.pop(),r.pop(),c};S.isEqual=function(e,n){return D(e,n,[],[])},S.isEmpty=function(e){if(null==e)return!0;if(S.isArray(e)||S.isString(e))return 0===e.length;for(var n in e)if(S.has(e,n))return!1;return!0},S.isElement=function(e){return!(!e||1!==e.nodeType)},S.isArray=w||function(e){return"[object Array]"==l.call(e)},S.isObject=function(e){return e===Object(e)},O(["Arguments","Function","String","Number","Date","RegExp"],function(e){S["is"+e]=function(n){return l.call(n)=="[object "+e+"]"}}),S.isArguments(arguments)||(S.isArguments=function(e){return!(!e||!S.has(e,"callee"))}),"function"!=typeof/./&&(S.isFunction=function(e){return"function"==typeof e}),S.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e))},S.isNaN=function(e){return S.isNumber(e)&&e!=+e},S.isBoolean=function(e){return e===!0||e===!1||"[object Boolean]"==l.call(e)},S.isNull=function(e){return null===e},S.isUndefined=function(e){return void 0===e},S.has=function(e,n){return f.call(e,n)},S.noConflict=function(){return e._=t,this},S.identity=function(e){return e},S.times=function(e,n,t){for(var r=Array(Math.max(0,e)),o=0;e>o;o++)r[o]=n.call(t,o);return r},S.random=function(e,n){return null==n&&(n=e,e=0),e+Math.floor(Math.random()*(n-e+1))};var M={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};M.unescape=S.invert(M.escape);var x={escape:new RegExp("["+S.keys(M.escape).join("")+"]","g"),unescape:new RegExp("("+S.keys(M.unescape).join("|")+")","g")};S.each(["escape","unescape"],function(e){S[e]=function(n){return null==n?"":(""+n).replace(x[e],function(n){return M[e][n]})}}),S.result=function(e,n){if(null==e)return void 0;var t=e[n];return S.isFunction(t)?t.call(e):t},S.mixin=function(e){O(S.functions(e),function(n){var t=S[n]=e[n];S.prototype[n]=function(){var e=[this._wrapped];return u.apply(e,arguments),W.call(this,t.apply(S,e))}})};var j=0;S.uniqueId=function(e){var n=++j+"";return e?e+n:n},S.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var U=/(.)^/,P={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},L=/\\|'|\r|\n|\t|\u2028|\u2029/g;S.template=function(e,n,t){var r;t=S.defaults({},t,S.templateSettings);var o=new RegExp([(t.escape||U).source,(t.interpolate||U).source,(t.evaluate||U).source].join("|")+"|$","g"),i=0,a="__p+='";e.replace(o,function(n,t,r,o,u){return a+=e.slice(i,u).replace(L,function(e){return"\\"+P[e]}),t&&(a+="'+\n((__t=("+t+"))==null?'':_.escape(__t))+\n'"),r&&(a+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),o&&(a+="';\n"+o+"\n__p+='"),i=u+n.length,n}),a+="';\n",t.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{r=new Function(t.variable||"obj","_",a)}catch(u){throw u.source=a,u}if(n)return r(n,S);var s=function(e){return r.call(this,e,S)};return s.source="function("+(t.variable||"obj")+"){\n"+a+"}",s},S.chain=function(e){return S(e).chain()};var W=function(e){return this._chain?S(e).chain():e};S.mixin(S),O(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var n=o[e];S.prototype[e]=function(){var t=this._wrapped;return n.apply(t,arguments),"shift"!=e&&"splice"!=e||0!==t.length||delete t[0],W.call(this,t)}}),O(["concat","join","slice"],function(e){var n=o[e];S.prototype[e]=function(){return W.call(this,n.apply(this._wrapped,arguments))}}),S.extend(S.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this)}.call(this),function(){e=n._}.call(this),"undefined"==typeof Package&&(Package={}),Package.underscore={_:e}}(),function(){var e,n=Package.underscore._;!function(){e={isClient:!0,isServer:!1},"object"==typeof __meteor_runtime_config__&&__meteor_runtime_config__.PUBLIC_SETTINGS&&(e.settings={"public":__meteor_runtime_config__.PUBLIC_SETTINGS})}.call(this),function(){if(e.isServer)var t=Npm.require("fibers/future");"object"==typeof __meteor_runtime_config__&&__meteor_runtime_config__.meteorRelease&&(e.release=__meteor_runtime_config__.meteorRelease),n.extend(e,{_get:function(e){for(var n=1;n<arguments.length;n++){if(!(arguments[n]in e))return void 0;e=e[arguments[n]]}return e},_ensure:function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];t in e||(e[t]={}),e=e[t]}return e},_delete:function(e){for(var n=[e],t=!0,r=1;r<arguments.length-1;r++){var o=arguments[r];if(!(o in e)){t=!1;break}if(e=e[o],"object"!=typeof e)break;n.push(e)}for(var r=n.length-1;r>=0;r--){var o=arguments[r+1];if(t)t=!1;else for(var i in n[r][o])return;delete n[r][o]}},_wrapAsync:function(r){return function(){for(var o,i,a=this,u=n.toArray(arguments),s=function(n){return n?e._debug("Exception in callback of async function",n?n.stack:n):void 0};u.length>0&&"undefined"==typeof u[u.length-1];)u.pop();u.length>0&&u[u.length-1]instanceof Function?o=u.pop():e.isClient?o=s:(i=new t,o=i.resolver()),u.push(e.bindEnvironment(o,s));var c=r.apply(a,u);return i?i.wait():c}}})}.call(this),function(){"use strict";function n(){if(o.setImmediate){var e=function(e){o.setImmediate(e)};return e.implementation="setImmediate",e}return null}function t(){function e(e,n){return"string"==typeof e&&e.substring(0,n.length)===n}function n(n){if(n.source===o&&e(n.data,u)){var t=n.data.substring(u.length);try{a[t]&&a[t]()}finally{delete a[t]}}}if(!o.postMessage||o.importScripts)return null;var t=!0,r=o.onmessage;if(o.onmessage=function(){t=!1},o.postMessage("","*"),o.onmessage=r,!t)return null;var i=0,a={},u="Meteor._setImmediate."+Math.random()+".";o.addEventListener?o.addEventListener("message",n,!1):o.attachEvent("onmessage",n);var s=function(e){++i,a[i]=e,o.postMessage(u+i,"*")};return s.implementation="postMessage",s}function r(){var e=function(e){o.setTimeout(e,0)};return e.implementation="setTimeout",e}var o=this;e._setImmediate=n()||t()||r()}.call(this),function(){var t=function(e){if(Package.livedata){var n=Package.livedata.DDP._CurrentInvocation;if(n.get()&&n.get().isSimulation)throw new Error("Can't set timers inside simulations");return function(){n.withValue(null,e)}}return e},r=function(n,r){return e.bindEnvironment(t(r),function(t){e._debug("Exception from "+n+":",t,t.stack)})};n.extend(e,{setTimeout:function(e,n){return setTimeout(r("setTimeout callback",e),n)},setInterval:function(e,n){return setInterval(r("setInterval callback",e),n)},clearInterval:function(e){return clearInterval(e)},clearTimeout:function(e){return clearTimeout(e)},defer:function(n){e._setImmediate(r("defer callback",n))}})}.call(this),function(){var n=function(e,n){var t=function(){};t.prototype=n.prototype,e.prototype=new t,e.prototype.constructor=e};e.makeErrorType=function(e,t){var r=function(){var n=this;if(Error.captureStackTrace)Error.captureStackTrace(n,r);else{var o=new Error;o.__proto__=r.prototype,o instanceof r&&(n=o)}return t.apply(n,arguments),n.errorType=e,n};return n(r,Error),r},e.Error=e.makeErrorType("Meteor.Error",function(e,n,t){var r=this;r.error=e,r.reason=n,r.details=t,r.message=r.reason?r.reason+" ["+r.error+"]":"["+r.error+"]"})}.call(this),function(){e._noYieldsAllowed=function(e){return e()},e._SynchronousQueue=function(){var e=this;e._tasks=[],e._running=!1},n.extend(e._SynchronousQueue.prototype,{runTask:function(t){var r=this;if(!r.safeToRunTask())throw new Error("Could not synchronously run a task from a running task");r._tasks.push(t);var o=r._tasks;r._tasks=[],r._running=!0;try{for(;!n.isEmpty(o);){var i=o.shift();try{i()}catch(a){if(n.isEmpty(o))throw a;e._debug("Exception in queued task: "+a.stack)}}}finally{r._running=!1}},queueTask:function(e){var t=this,r=n.isEmpty(t._tasks);t._tasks.push(e),r&&setTimeout(n.bind(t.flush,t),0)},flush:function(){var e=this;e.runTask(function(){})},drain:function(){var e=this;if(e.safeToRunTask())for(;!n.isEmpty(e._tasks);)e.flush()},safeToRunTask:function(){var e=this;return!e._running}})}.call(this),function(){var n=[],t=!1;e.startup=function(e){t?e():n.push(e)},e._start=function(){for(;n.length>0;)n.shift()();t=!0}}.call(this),function(){var n=0;e._debug=function(){if(n)return n--,void 0;if("undefined"!=typeof console&&"undefined"!=typeof console.log)if(0==arguments.length)console.log("");else if("function"==typeof console.log.apply){for(var e=!0,t=0;t<arguments.length;t++)"string"!=typeof arguments[t]&&(e=!1);e?console.log.apply(console,[Array.prototype.join.call(arguments," ")]):console.log.apply(console,arguments)}else if("function"==typeof Function.prototype.bind){var r=Function.prototype.bind.call(console.log,console);r.apply(console,arguments)}else Function.prototype.call.call(console.log,console,Array.prototype.slice.call(arguments))},e._suppress_log=function(e){n+=e}}.call(this),function(){var t=0,r=[];e.EnvironmentVariable=function(){this.slot=t++},n.extend(e.EnvironmentVariable.prototype,{get:function(){return r[this.slot]},withValue:function(e,n){var t=r[this.slot];try{r[this.slot]=e;var o=n()}finally{r[this.slot]=t}return o}}),e.bindEnvironment=function(e,t,o){var i=n.clone(r);if(!t)throw new Error("onException must be supplied");return function(){var a=r;try{r=i;var u=e.apply(o,n.toArray(arguments))}catch(s){t(s)}finally{r=a}return u}}}.call(this),function(){e.absoluteUrl=function(t,r){r||"object"!=typeof t||(r=t,t=void 0),r=n.extend({},e.absoluteUrl.defaultOptions,r||{});var o=r.rootUrl;if(!o)throw new Error("Must pass options.rootUrl or set ROOT_URL in the server environment");return/^http[s]?:\/\//i.test(o)||(o="http://"+o),/\/$/.test(o)||(o+="/"),t&&(o+=t),r.secure&&/^http:/.test(o)&&!/http:\/\/localhost[:\/]/.test(o)&&!/http:\/\/127\.0\.0\.1[:\/]/.test(o)&&(o=o.replace(/^http:/,"https:")),r.replaceLocalhost&&(o=o.replace(/^http:\/\/localhost([:\/].*)/,"http://127.0.0.1$1")),o},e.absoluteUrl.defaultOptions={},"object"==typeof __meteor_runtime_config__&&__meteor_runtime_config__.ROOT_URL&&(e.absoluteUrl.defaultOptions.rootUrl=__meteor_runtime_config__.ROOT_URL),e._relativeToSiteRootUrl=function(e){return"object"==typeof __meteor_runtime_config__&&"/"===e.substr(0,1)&&(e=(__meteor_runtime_config__.ROOT_URL_PATH_PREFIX||"")+e),e}}.call(this),"undefined"==typeof Package&&(Package={}),Package.meteor={Meteor:e}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._;!function(){e={},e.active=!1,e.currentComputation=null;var r=function(n){e.currentComputation=n,e.active=!!n
},o=function(){return"undefined"!=typeof n?n._debug:"undefined"!=typeof console&&console.log?console.log:function(){}},i=1,a=[],u=!1,s=!1,c=!1,l=[],f=function(){u||(setTimeout(e.flush,0),u=!0)},d=!1;e.Computation=function(e,n){if(!d)throw new Error("Deps.Computation constructor is private; use Deps.autorun");d=!1;var t=this;t.stopped=!1,t.invalidated=!1,t.firstRun=!0,t._id=i++,t._onInvalidateCallbacks=[],t._parent=n,t._func=e,t._recomputing=!1;var r=!0;try{t._compute(),r=!1}finally{t.firstRun=!1,r&&t.stop()}},t.extend(e.Computation.prototype,{onInvalidate:function(n){var t=this;if("function"!=typeof n)throw new Error("onInvalidate requires a function");var r=function(){e.nonreactive(function(){n(t)})};t.invalidated?r():t._onInvalidateCallbacks.push(r)},invalidate:function(){var e=this;if(!e.invalidated){e._recomputing||e.stopped||(f(),a.push(this)),e.invalidated=!0;for(var n,t=0;n=e._onInvalidateCallbacks[t];t++)n();e._onInvalidateCallbacks=[]}},stop:function(){this.stopped||(this.stopped=!0,this.invalidate())},_compute:function(){var n=this;n.invalidated=!1;var t=e.currentComputation;r(n),c=!0;try{n._func(n)}finally{r(t),c=!1}},_recompute:function(){var e=this;for(e._recomputing=!0;e.invalidated&&!e.stopped;)try{e._compute()}catch(n){o()("Exception from Deps recompute:",n.stack||n.message)}e._recomputing=!1}}),e.Dependency=function(){this._dependentsById={}},t.extend(e.Dependency.prototype,{depend:function(n){if(!n){if(!e.active)return!1;n=e.currentComputation}var t=this,r=n._id;return r in t._dependentsById?!1:(t._dependentsById[r]=n,n.onInvalidate(function(){delete t._dependentsById[r]}),!0)},changed:function(){var e=this;for(var n in e._dependentsById)e._dependentsById[n].invalidate()},hasDependents:function(){var e=this;for(var n in e._dependentsById)return!0;return!1}}),t.extend(e,{flush:function(){if(s)throw new Error("Can't call Deps.flush while flushing");if(c)throw new Error("Can't flush inside Deps.autorun");for(s=!0,u=!0;a.length||l.length;){var e=a;a=[];for(var n,t=0;n=e[t];t++)n._recompute();if(l.length){var r=l.shift();try{r()}catch(i){o()("Exception from Deps afterFlush function:",i.stack||i.message)}}}s=!1,u=!1},autorun:function(n){if("function"!=typeof n)throw new Error("Deps.autorun requires a function argument");d=!0;var t=new e.Computation(n,e.currentComputation);return e.active&&e.onInvalidate(function(){t.stop()}),t},nonreactive:function(n){var t=e.currentComputation;r(null);try{return n()}finally{r(t)}},_makeNonreactive:function(n){if(n.$isNonreactive)return n;var r=function(){var r,o=this,i=t.toArray(arguments);return e.nonreactive(function(){r=n.apply(o,i)}),r};return r.$isNonreactive=!0,r},onInvalidate:function(n){if(!e.active)throw new Error("Deps.onInvalidate requires a currentComputation");e.currentComputation.onInvalidate(n)},afterFlush:function(e){l.push(e),f()}})}.call(this),function(){n.flush=e.flush,n.autorun=e.autorun,n.autosubscribe=e.autorun,e.depend=function(e){return e.depend()}}.call(this),"undefined"==typeof Package&&(Package={}),Package.deps={Deps:e}}(),function(){Package.meteor.Meteor;var e;!function(){this.JSON&&(e=this.JSON)}.call(this),"undefined"==typeof Package&&(Package={}),Package.json={JSON:e}}(),function(){Package.meteor.Meteor;var e,n,t,r,o=Package.json.JSON,i=Package.underscore._;!function(){e={},n={};var a={};e.addType=function(e,n){if(i.has(a,e))throw new Error("Type "+e+" already present");a[e]=n};var u=[{matchJSONValue:function(e){return i.has(e,"$date")&&1===i.size(e)},matchObject:function(e){return e instanceof Date},toJSONValue:function(e){return{$date:e.getTime()}},fromJSONValue:function(e){return new Date(e.$date)}},{matchJSONValue:function(e){return i.has(e,"$binary")&&1===i.size(e)},matchObject:function(e){return"undefined"!=typeof Uint8Array&&e instanceof Uint8Array||e&&i.has(e,"$Uint8ArrayPolyfill")},toJSONValue:function(e){return{$binary:t(e)}},fromJSONValue:function(e){return r(e.$binary)}},{matchJSONValue:function(e){return i.has(e,"$escape")&&1===i.size(e)},matchObject:function(e){return i.isEmpty(e)||i.size(e)>2?!1:i.any(u,function(n){return n.matchJSONValue(e)})},toJSONValue:function(n){var t={};return i.each(n,function(n,r){t[r]=e.toJSONValue(n)}),{$escape:t}},fromJSONValue:function(n){var t={};return i.each(n.$escape,function(n,r){t[r]=e.fromJSONValue(n)}),t}},{matchJSONValue:function(e){return i.has(e,"$type")&&i.has(e,"$value")&&2===i.size(e)},matchObject:function(n){return e._isCustomType(n)},toJSONValue:function(e){return{$type:e.typeName(),$value:e.toJSONValue()}},fromJSONValue:function(e){var n=e.$type,t=a[n];return t(e.$value)}}];e._isCustomType=function(e){return e&&"function"==typeof e.toJSONValue&&"function"==typeof e.typeName&&i.has(a,e.typeName())};var s=e._adjustTypesToJSONValue=function(e){if(null===e)return null;var n=c(e);return void 0!==n?n:(i.each(e,function(n,t){if("object"==typeof n||void 0===n){var r=c(n);return r?(e[t]=r,void 0):(s(n),void 0)}}),e)},c=function(e){for(var n=0;n<u.length;n++){var t=u[n];if(t.matchObject(e))return t.toJSONValue(e)}return void 0};e.toJSONValue=function(n){var t=c(n);return void 0!==t?t:("object"==typeof n&&(n=e.clone(n),s(n)),n)};var l=e._adjustTypesFromJSONValue=function(e){if(null===e)return null;var n=f(e);return n!==e?n:(i.each(e,function(n,t){if("object"==typeof n){var r=f(n);if(n!==r)return e[t]=r,void 0;l(n)}}),e)},f=function(e){if("object"==typeof e&&null!==e&&i.size(e)<=2&&i.all(e,function(e,n){return"string"==typeof n&&"$"===n.substr(0,1)}))for(var n=0;n<u.length;n++){var t=u[n];if(t.matchJSONValue(e))return t.fromJSONValue(e)}return e};e.fromJSONValue=function(n){var t=f(n);return t===n&&"object"==typeof n?(n=e.clone(n),l(n),n):t},e.stringify=function(n){return o.stringify(e.toJSONValue(n))},e.parse=function(n){return e.fromJSONValue(o.parse(n))},e.isBinary=function(e){return!!("undefined"!=typeof Uint8Array&&e instanceof Uint8Array||e&&e.$Uint8ArrayPolyfill)},e.equals=function(n,t,r){var o,a=!(!r||!r.keyOrderSensitive);if(n===t)return!0;if(!n||!t)return!1;if("object"!=typeof n||"object"!=typeof t)return!1;if(n instanceof Date&&t instanceof Date)return n.valueOf()===t.valueOf();if(e.isBinary(n)&&e.isBinary(t)){if(n.length!==t.length)return!1;for(o=0;o<n.length;o++)if(n[o]!==t[o])return!1;return!0}if("function"==typeof n.equals)return n.equals(t,r);if(n instanceof Array){if(!(t instanceof Array))return!1;if(n.length!==t.length)return!1;for(o=0;o<n.length;o++)if(!e.equals(n[o],t[o],r))return!1;return!0}var u;if(a){var s=[];return i.each(t,function(e,n){s.push(n)}),o=0,u=i.all(n,function(n,i){return o>=s.length?!1:i!==s[o]?!1:e.equals(n,t[s[o]],r)?(o++,!0):!1}),u&&o===s.length}return o=0,u=i.all(n,function(n,a){return i.has(t,a)?e.equals(n,t[a],r)?(o++,!0):!1:!1}),u&&i.size(t)===o},e.clone=function(n){var t;if("object"!=typeof n)return n;if(null===n)return null;if(n instanceof Date)return new Date(n.getTime());if(e.isBinary(n)){t=e.newBinary(n.length);for(var r=0;r<n.length;r++)t[r]=n[r];return t}if(i.isArray(n)||i.isArguments(n)){for(t=[],r=0;r<n.length;r++)t[r]=e.clone(n[r]);return t}return"function"==typeof n.clone?n.clone():(t={},i.each(n,function(n,r){t[r]=e.clone(n)}),t)}}.call(this),function(){for(var o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={},a=0;a<o.length;a++)i[o.charAt(a)]=a;t=function(e){for(var n=[],t=null,r=null,o=null,i=null,a=0;a<e.length;a++)switch(a%3){case 0:t=63&e[a]>>2,r=(3&e[a])<<4;break;case 1:r|=15&e[a]>>4,o=(15&e[a])<<2;break;case 2:o|=3&e[a]>>6,i=63&e[a],n.push(u(t)),n.push(u(r)),n.push(u(o)),n.push(u(i)),t=null,r=null,o=null,i=null}return null!=t&&(n.push(u(t)),n.push(u(r)),null==o?n.push("="):n.push(u(o)),null==i&&n.push("=")),n.join("")};var u=function(e){return o.charAt(e)},s=function(e){return"="===e?-1:i[e]};e.newBinary=function(e){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer){for(var n=[],t=0;e>t;t++)n.push(0);return n.$Uint8ArrayPolyfill=!0,n}return new Uint8Array(new ArrayBuffer(e))},r=function(n){var t=Math.floor(3*n.length/4);"="==n.charAt(n.length-1)&&(t--,"="==n.charAt(n.length-2)&&t--);for(var r=e.newBinary(t),o=null,i=null,a=null,u=0,c=0;c<n.length;c++){var l=n.charAt(c),f=s(l);switch(c%4){case 0:if(0>f)throw new Error("invalid base64 string");o=f<<2;break;case 1:if(0>f)throw new Error("invalid base64 string");o|=f>>4,r[u++]=o,i=(15&f)<<4;break;case 2:f>=0&&(i|=f>>2,r[u++]=i,a=(3&f)<<6);break;case 3:f>=0&&(r[u++]=a|f)}}return r},n.base64Encode=t,n.base64Decode=r}.call(this),"undefined"==typeof Package&&(Package={}),Package.ejson={EJSON:e,EJSONTest:n}}(),function(){Package.meteor.Meteor,"undefined"==typeof Package&&(Package={}),Package.coffeescript={}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._;!function(){e="object"==typeof e?e:{};var r,o,i,a,u=[].slice;o=function(e){return"string"==typeof e?e:JSON.stringify(e)},a=function(e,n){for(;n.length<e;)n="0"+n;return n},i=function(){var e;return e=new Date,a(2,""+e.getSeconds())+"."+a(3,""+e.getMilliseconds())},n._debug=function(){var e;return e=1<=arguments.length?u.call(arguments,0):[],WebWorker.log(i()+": "+t.map(e,o).join(" "))},r={}}.call(this),"undefined"==typeof Package&&(Package={}),Package.logging={}}(),function(){var e=Package.meteor.Meteor;Package.underscore._,Package.json.JSON;var n;!function(){var t=[];n={},n._onMigrate=function(e,n){n||(n=e,e=void 0),t.push({name:e,callback:n})},n._migrationData=function(){return void 0};var r=!1;n._reload=function(){r||(r=!0,e._debug("reload requested"))}}.call(this),"undefined"==typeof Package&&(Package={}),Package.reload={Reload:n}}(),function(){var e,n,t=Package.meteor.Meteor,r=Package.underscore._,o=Package.ejson.EJSON;!function(){var i=new t.EnvironmentVariable;e=function(e,t){var r=i.get();r&&r.checking(e);try{f(e,t)}catch(o){throw o instanceof n.Error&&o.path&&(o.message+=" in field "+o.path),o}},n={Optional:function(e){return new a(e)},OneOf:function(){return new u(r.toArray(arguments))},Any:["__any__"],Where:function(e){return new s(e)},ObjectIncluding:function(e){return new c(e)},Integer:["__integer__"],Error:t.makeErrorType("Match.Error",function(e){this.message="Match error: "+e,this.path="",this.sanitizedError=new t.Error(400,"Match failed")}),test:function(e,t){try{return f(e,t),!0}catch(r){if(r instanceof n.Error)return!1;throw r}},_failIfArgumentsAreNotAllChecked:function(e,n,t,r){var o=new d(t,r),a=i.withValue(o,function(){return e.apply(n,t)});return o.throwUnlessAllArgumentsHaveBeenChecked(),a}};var a=function(e){this.pattern=e},u=function(e){if(r.isEmpty(e))throw new Error("Must provide at least one choice to Match.OneOf");this.choices=e},s=function(e){this.condition=e},c=function(e){this.pattern=e},l=[[String,"string"],[Number,"number"],[Boolean,"boolean"],[void 0,"undefined"]],f=function(e,t){if(t!==n.Any){for(var i=0;i<l.length;++i)if(t===l[i][0]){if(typeof e===l[i][1])return;throw new n.Error("Expected "+l[i][1]+", got "+typeof e)}if(null===t){if(null===e)return;throw new n.Error("Expected null, got "+o.stringify(e))}if(t===n.Integer){if("number"==typeof e&&(0|e)===e)return;throw new n.Error("Expected Integer, got "+(e instanceof Object?o.stringify(e):e))}if(t===Object&&(t=n.ObjectIncluding({})),t instanceof Array){if(1!==t.length)throw Error("Bad pattern: arrays must have one type element"+o.stringify(t));if(!r.isArray(e)&&!r.isArguments(e))throw new n.Error("Expected array, got "+o.stringify(e));return r.each(e,function(e,r){try{f(e,t[0])}catch(o){throw o instanceof n.Error&&(o.path=h(r,o.path)),o}}),void 0}if(t instanceof s){if(t.condition(e))return;throw new n.Error("Failed Match.Where validation")}if(t instanceof a&&(t=n.OneOf(void 0,t.pattern)),t instanceof u){for(var i=0;i<t.choices.length;++i)try{return f(e,t.choices[i]),void 0}catch(d){if(!(d instanceof n.Error))throw d}throw new n.Error("Failed Match.OneOf or Match.Optional validation")}if(t instanceof Function){if(e instanceof t)return;throw new n.Error("Expected "+t.name)}var p=!1;if(t instanceof c&&(p=!0,t=t.pattern),"object"!=typeof t)throw Error("Bad pattern: unknown pattern type");if("object"!=typeof e)throw new n.Error("Expected object, got "+typeof e);if(null===e)throw new n.Error("Expected object, got null");if(e.constructor!==Object)throw new n.Error("Expected plain object");var v={},_={};r.each(t,function(e,n){e instanceof a?_[n]=e.pattern:v[n]=e}),r.each(e,function(e,t){try{if(r.has(v,t))f(e,v[t]),delete v[t];else if(r.has(_,t))f(e,_[t]);else if(!p)throw new n.Error("Unknown key")}catch(o){throw o instanceof n.Error&&(o.path=h(t,o.path)),o}}),r.each(v,function(e,t){throw new n.Error("Missing key '"+t+"'")})}},d=function(e,n){var t=this;t.args=r.clone(e),t.args.reverse(),t.description=n};r.extend(d.prototype,{checking:function(e){var n=this;n._checkingOneValue(e)||(r.isArray(e)||r.isArguments(e))&&r.each(e,r.bind(n._checkingOneValue,n))},_checkingOneValue:function(e){for(var n=this,t=0;t<n.args.length;++t)if(e===n.args[t])return n.args.splice(t,1),!0;return!1},throwUnlessAllArgumentsHaveBeenChecked:function(){var e=this;if(!r.isEmpty(e.args))throw new Error("Did not check() all arguments during "+e.description)}});var p=["do","if","in","for","let","new","try","var","case","else","enum","eval","false","null","this","true","void","with","break","catch","class","const","super","throw","while","yield","delete","export","import","public","return","static","switch","typeof","default","extends","finally","package","private","continue","debugger","function","arguments","interface","protected","implements","instanceof"],h=function(e,n){return"number"==typeof e||e.match(/^[0-9]+$/)?e="["+e+"]":(!e.match(/^[a-z_$][0-9a-z_$]*$/i)||r.contains(p,e))&&(e=JSON.stringify([e])),n&&"["!==n[0]?e+"."+n:e+n}}.call(this),"undefined"==typeof Package&&(Package={}),Package.check={check:e,Match:n}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._;!function(){var n=function(){function e(){var e=4022871197,n=function(n){n=n.toString();for(var t=0;t<n.length;t++){e+=n.charCodeAt(t);var r=.02519603282416938*e;e=r>>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=4294967296*r}return 2.3283064365386963e-10*(e>>>0)};return n.version="Mash 0.9",n}return function(n){var t=0,r=0,o=0,i=1;0==n.length&&(n=[+new Date]);var a=e();t=a(" "),r=a(" "),o=a(" ");for(var u=0;u<n.length;u++)t-=a(n[u]),0>t&&(t+=1),r-=a(n[u]),0>r&&(r+=1),o-=a(n[u]),0>o&&(o+=1);a=null;var s=function(){var e=2091639*t+2.3283064365386963e-10*i;return t=r,r=o,o=e-(i=0|e)};return s.uint32=function(){return 4294967296*s()},s.fract53=function(){return s()+1.1102230246251565e-16*(0|2097152*s())},s.version="Alea 0.9",s.args=n,s}(Array.prototype.slice.call(arguments))},r="23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz",o=function(){var e=n.apply(null,arguments),i={},a=function(e){return t.bind(e,i)};return t.extend(i,{_Alea:n,create:o,fraction:e,choice:a(function(e){var n=Math.floor(this.fraction()*e.length);return"string"==typeof e?e.substr(n,1):e[n]}),id:a(function(){for(var e=[],n=0;17>n;n++)e[n]=this.choice(r);return e.join("")}),hexString:a(function(e){for(var n=[],t=0;e>t;++t)n.push(this.choice("0123456789abcdef"));return n.join("")})})},i="undefined"!=typeof window&&window.innerHeight||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientHeight||"undefined"!=typeof document&&document.body&&document.body.clientHeight||1,a="undefined"!=typeof window&&window.innerWidth||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientWidth||"undefined"!=typeof document&&document.body&&document.body.clientWidth||1,u="undefined"!=typeof navigator&&navigator.userAgent||"",s="undefined"!=typeof process&&process.pid||1;e=o([new Date,i,a,u,s,Math.random()])}.call(this),function(){n.uuid=function(){for(var n="0123456789abcdef",t=[],r=0;36>r;r++)t[r]=e.choice(n);t[14]="4",t[19]=n.substr(8|3&parseInt(t[19],16),1),t[8]=t[13]=t[18]=t[23]="-";var o=t.join("");return o}}.call(this),"undefined"==typeof Package&&(Package={}),Package.random={Random:e}}(),function(){Package.meteor.Meteor;var e,n=Package.underscore._;!function(){var t=function(e,n,t,r){return{key:e,value:n,next:t,prev:r}};e=function(){var e=this;e._dict={},e._first=null,e._last=null,e._size=0;var t=n.toArray(arguments);e._stringify=function(e){return e},"function"==typeof t[0]&&(e._stringify=t.shift()),n.each(t,function(n){e.putBefore(n[0],n[1],null)})},n.extend(e.prototype,{_k:function(e){return" "+this._stringify(e)},empty:function(){var e=this;return!e._first},size:function(){var e=this;return e._size},_linkEltIn:function(e){var n=this;e.next?(e.prev=e.next.prev,e.next.prev=e,e.prev&&(e.prev.next=e)):(e.prev=n._last,n._last&&(n._last.next=e),n._last=e),(null===n._first||n._first===e.next)&&(n._first=e)},_linkEltOut:function(e){var n=this;e.next&&(e.next.prev=e.prev),e.prev&&(e.prev.next=e.next),e===n._last&&(n._last=e.prev),e===n._first&&(n._first=e.next)},putBefore:function(e,n,r){var o=this;if(o._dict[o._k(e)])throw new Error("Item "+e+" already present in OrderedDict");var i=r?t(e,n,o._dict[o._k(r)]):t(e,n,null);if(void 0===i.next)throw new Error("could not find item to put this one before");o._linkEltIn(i),o._dict[o._k(e)]=i,o._size++},append:function(e,n){var t=this;t.putBefore(e,n,null)},remove:function(e){var n=this,t=n._dict[n._k(e)];if(void 0===t)throw new Error("Item "+e+" not present in OrderedDict");return n._linkEltOut(t),n._size--,delete n._dict[n._k(e)],t.value},get:function(e){var n=this;return n.has(e)?n._dict[n._k(e)].value:void 0},has:function(e){var t=this;return n.has(t._dict,t._k(e))},forEach:function(n){for(var t=this,r=0,o=t._first;null!==o;){var i=n(o.value,o.key,r);if(i===e.BREAK)return;o=o.next,r++}},first:function(){var e=this;return e.empty()?void 0:e._first.key},firstValue:function(){var e=this;return e.empty()?void 0:e._first.value},last:function(){var e=this;return e.empty()?void 0:e._last.key},lastValue:function(){var e=this;return e.empty()?void 0:e._last.value},prev:function(e){var n=this;if(n.has(e)){var t=n._dict[n._k(e)];if(t.prev)return t.prev.key}return null},next:function(e){var n=this;if(n.has(e)){var t=n._dict[n._k(e)];if(t.next)return t.next.key}return null},moveBefore:function(e,n){var t=this,r=t._dict[t._k(e)],o=n?t._dict[t._k(n)]:null;if(void 0===r)throw new Error("Item to move is not present");if(void 0===o)throw new Error("Could not find element to move this one before");o!==r.next&&(t._linkEltOut(r),r.next=o,t._linkEltIn(r))},indexOf:function(n){var t=this,r=null;return t.forEach(function(o,i,a){return t._k(i)===t._k(n)?(r=a,e.BREAK):void 0}),r},_checkRep:function(){var e=this;n.each(e._dict,function(e,n){if(n.next===n)throw new Error("Next is a loop");if(n.prev===n)throw new Error("Prev is a loop")})}}),e.BREAK={"break":!0}}.call(this),"undefined"==typeof Package&&(Package={}),Package["ordered-dict"]={OrderedDict:e}}(),function(){var e,n=Package.meteor.Meteor,t=Package.underscore._,r=Package.json.JSON,o=Package.ejson.EJSON,i=Package["ordered-dict"].OrderedDict,a=Package.deps.Deps,u=Package.random.Random;!function(){e=function(e){this.name=e,this.docs={},this._observeQueue=new n._SynchronousQueue,this.next_qid=1,this.queries={},this._savedOriginals=null,this.paused=!1},e._applyChanges=function(e,n){t.each(n,function(n,t){void 0===n?delete e[t]:e[t]=n})};var s=function(e){var n=new Error(e);return n.name="MinimongoError",n};e.prototype.find=function(n,t){return 0===arguments.length&&(n={}),new e.Cursor(this,n,t)},e.Cursor=function(n,t,r){var o=this;r||(r={}),this.collection=n,e._selectorIsId(t)?(o.selector_id=e._idStringify(t),o.selector_f=e._compileSelector(t),o.sort_f=void 0):(o.selector_id=void 0,o.selector_f=e._compileSelector(t),o.sort_f=r.sort?e._compileSort(r.sort):null),o.skip=r.skip,o.limit=r.limit,o._transform=r.transform&&"undefined"!=typeof a?a._makeNonreactive(r.transform):r.transform,o.db_objects=null,o.cursor_pos=0,"undefined"!=typeof a&&(o.reactive=void 0===r.reactive?!0:r.reactive)},e.Cursor.prototype.rewind=function(){var e=this;e.db_objects=null,e.cursor_pos=0},e.prototype.findOne=function(e,n){return 0===arguments.length&&(e={}),n=n||{},n.limit=1,this.find(e,n).fetch()[0]},e.Cursor.prototype.forEach=function(e){var n=this;for(null===n.db_objects&&(n.db_objects=n._getRawObjects(!0)),n.reactive&&n._depend({addedBefore:!0,removed:!0,changed:!0,movedBefore:!0});n.cursor_pos<n.db_objects.length;){var t=o.clone(n.db_objects[n.cursor_pos++]);n._transform&&(t=n._transform(t)),e(t)}},e.Cursor.prototype.getTransform=function(){var e=this;return e._transform},e.Cursor.prototype.map=function(e){var n=this,t=[];return n.forEach(function(n){t.push(e(n))}),t},e.Cursor.prototype.fetch=function(){var e=this,n=[];return e.forEach(function(e){n.push(e)}),n},e.Cursor.prototype.count=function(){var e=this;return e.reactive&&e._depend({added:!0,removed:!0}),null===e.db_objects&&(e.db_objects=e._getRawObjects(!0)),e.db_objects.length},e.Cursor.prototype._publishCursor=function(e){var t=this;if(!t.collection.name)throw new Error("Can't publish a cursor from a collection without a name.");var r=t.collection.name;return n.Collection._publishCursor(t,e,r)},e._isOrderedChanges=function(e){if(e.added&&e.addedBefore)throw new Error("Please specify only one of added() and addedBefore()");return"function"==typeof e.addedBefore||"function"==typeof e.movedBefore},e.LiveResultsSet=function(){},t.extend(e.Cursor.prototype,{observe:function(n){var t=this;return e._observeFromObserveChanges(t,n)},observeChanges:function(n){var r=this,i=e._isOrderedChanges(n);if(!i&&(r.skip||r.limit))throw new Error("must use ordered observe with skip or limit");var u,s={selector_f:r.selector_f,sort_f:i&&r.sort_f,results_snapshot:null,ordered:i,cursor:this,observeChanges:n.observeChanges};r.reactive&&(u=r.collection.next_qid++,r.collection.queries[u]=s),s.results=r._getRawObjects(i),r.collection.paused&&(s.results_snapshot=i?[]:{});var c=function(e){return e?function(){var n=this,t=arguments;r.collection.paused||r.collection._observeQueue.queueTask(function(){e.apply(n,t)})}:function(){}};s.added=c(n.added),s.changed=c(n.changed),s.removed=c(n.removed),i&&(s.moved=c(n.moved),s.addedBefore=c(n.addedBefore),s.movedBefore=c(n.movedBefore)),n._suppress_initial||r.collection.paused||t.each(s.results,function(e){var n=o.clone(e);delete n._id,i&&s.addedBefore(e._id,n,null),s.added(e._id,n)});var l=new e.LiveResultsSet;return t.extend(l,{collection:r.collection,stop:function(){r.reactive&&delete r.collection.queries[u]}}),r.reactive&&a.active&&a.onInvalidate(function(){l.stop()}),r.collection._observeQueue.drain(),l}}),e.Cursor.prototype._getRawObjects=function(e){var n=this,r=e?[]:{};if(n.selector_id){if(n.skip)return r;if(t.has(n.collection.docs,n.selector_id)){var o=n.collection.docs[n.selector_id];e?r.push(o):r[n.selector_id]=o}return r}for(var i in n.collection.docs){var a=n.collection.docs[i];if(n.selector_f(a)&&(e?r.push(a):r[i]=a),n.limit&&!n.skip&&!n.sort_f&&r.length===n.limit)return r}if(!e)return r;n.sort_f&&r.sort(n.sort_f);var u=n.skip||0,s=n.limit?n.limit+u:r.length;return r.slice(u,s)},e.Cursor.prototype._depend=function(e){var n=this;if(a.active){var r=new a.Dependency;r.depend();var o=t.bind(r.changed,r),i={_suppress_initial:!0};t.each(["added","changed","removed","addedBefore","movedBefore"],function(n){e[n]&&(i[n]=o)}),n.observeChanges(i)}},e.prototype.insert=function(r,i){var a=this;r=o.clone(r),t.has(r,"_id")||(r._id=e._useOID?new e._ObjectID:u.id());var c=e._idStringify(r._id);if(t.has(a.docs,r._id))throw s("Duplicate _id '"+r._id+"'");a._saveOriginal(c,void 0),a.docs[c]=r;var l=[];for(var f in a.queries){var d=a.queries[f];d.selector_f(r)&&(d.cursor.skip||d.cursor.limit?l.push(f):e._insertInResults(d,r))}return t.each(l,function(n){a.queries[n]&&e._recomputeResults(a.queries[n])}),a._observeQueue.drain(),i&&n.defer(function(){i(null,r._id)}),r._id},e.prototype.remove=function(r,o){var i=this,a=[],u=[],s=e._compileSelector(r),c=e._idsMatchedBySelector(r);if(c)t.each(c,function(n){var r=e._idStringify(n);t.has(i.docs,r)&&s(i.docs[r])&&a.push(r)});else for(var l in i.docs){var f=i.docs[l];s(f)&&a.push(l)}for(var d=[],p=0;p<a.length;p++){var h=a[p],v=i.docs[h];t.each(i.queries,function(e,n){e.selector_f(v)&&(e.cursor.skip||e.cursor.limit?u.push(n):d.push({qid:n,doc:v}))}),i._saveOriginal(h,v),delete i.docs[h]}t.each(d,function(n){var t=i.queries[n.qid];t&&e._removeFromResults(t,n.doc)}),t.each(u,function(n){var t=i.queries[n];t&&e._recomputeResults(t)}),i._observeQueue.drain(),o&&n.defer(o)},e.prototype.update=function(r,i,a,u){var s=this;if(!u&&a instanceof Function&&(u=a,a=null),a||(a={}),a.upsert)throw new Error("upsert not yet implemented");var c=e._compileSelector(r),l={};t.each(s.queries,function(e,n){!e.cursor.skip&&!e.cursor.limit||e.paused||(l[n]=o.clone(e.results))});var f={};for(var d in s.docs){var p=s.docs[d];if(c(p)&&(s._saveOriginal(d,p),s._modifyAndNotify(p,i,f),!a.multi))break}t.each(f,function(n,t){var r=s.queries[t];r&&e._recomputeResults(r,l[t])}),s._observeQueue.drain(),u&&n.defer(u)},e.prototype._modifyAndNotify=function(n,r,i){var a=this,u={};for(var s in a.queries){var c=a.queries[s];u[s]=c.ordered?c.selector_f(n):t.has(c.results,e._idStringify(n._id))}var l=o.clone(n);e._modify(n,r);for(s in a.queries){c=a.queries[s];var f=u[s],d=c.selector_f(n);c.cursor.skip||c.cursor.limit?(f||d)&&(i[s]=!0):f&&!d?e._removeFromResults(c,n):!f&&d?e._insertInResults(c,n):f&&d&&e._updateInResults(c,n,l)}},e._insertInResults=function(n,t){var r=o.clone(t);if(delete r._id,n.ordered){if(n.sort_f){var i=e._insertInSortedList(n.sort_f,n.results,t),a=n.results[i+1];a=a?a._id:null,n.addedBefore(t._id,r,a)}else n.addedBefore(t._id,r,null),n.results.push(t);n.added(t._id,r)}else n.added(t._id,r),n.results[e._idStringify(t._id)]=t},e._removeFromResults=function(n,t){if(n.ordered){var r=e._findInOrderedResults(n,t);n.removed(t._id),n.results.splice(r,1)}else{var o=e._idStringify(t._id);n.removed(t._id),delete n.results[o]}},e._updateInResults=function(n,r,i){if(!o.equals(r._id,i._id))throw new Error("Can't change a doc's _id while updating");var a=e._makeChangedFields(r,i);if(!n.ordered)return t.isEmpty(a)||(n.changed(r._id,a),n.results[e._idStringify(r._id)]=r),void 0;var u=e._findInOrderedResults(n,r);if(t.isEmpty(a)||n.changed(r._id,a),n.sort_f){n.results.splice(u,1);var s=e._insertInSortedList(n.sort_f,n.results,r);if(u!==s){var c=n.results[s+1];c=c?c._id:null,n.movedBefore&&n.movedBefore(r._id,c)}}},e._recomputeResults=function(n,t){t||(t=n.results),n.results=n.cursor._getRawObjects(n.ordered),n.paused||e._diffQueryChanges(n.ordered,t,n.results,n)},e._findInOrderedResults=function(e,n){if(!e.ordered)throw new Error("Can't call _findInOrderedResults on unordered query");for(var t=0;t<e.results.length;t++)if(e.results[t]===n)return t;throw Error("object missing from query")},e._binarySearch=function(e,n,t){for(var r=0,o=n.length;o>0;){var i=Math.floor(o/2);e(t,n[r+i])>=0?(r+=i+1,o-=i+1):o=i}return r},e._insertInSortedList=function(n,t,r){if(0===t.length)return t.push(r),0;var o=e._binarySearch(n,t,r);return t.splice(o,0,r),o},e.prototype.saveOriginals=function(){var e=this;if(e._savedOriginals)throw new Error("Called saveOriginals twice without retrieveOriginals");e._savedOriginals={}},e.prototype.retrieveOriginals=function(){var e=this;if(!e._savedOriginals)throw new Error("Called retrieveOriginals without saveOriginals");var n=e._savedOriginals;return e._savedOriginals=null,n},e.prototype._saveOriginal=function(e,n){var r=this;r._savedOriginals&&(t.has(r._savedOriginals,e)||(r._savedOriginals[e]=o.clone(n)))},e.prototype.pauseObservers=function(){if(!this.paused){this.paused=!0;for(var e in this.queries){var n=this.queries[e];n.results_snapshot=o.clone(n.results)}}},e.prototype.resumeObservers=function(){var n=this;if(this.paused){this.paused=!1;for(var t in this.queries){var r=n.queries[t];e._diffQueryChanges(r.ordered,r.results_snapshot,r.results,r),r.results_snapshot=null}n._observeQueue.drain()}},e._idStringify=function(n){if(n instanceof e._ObjectID)return n.valueOf();if("string"==typeof n)return""===n?n:"-"===n.substr(0,1)||"~"===n.substr(0,1)||e._looksLikeObjectID(n)||"{"===n.substr(0,1)?"-"+n:n;if(void 0===n)return"-";if("object"==typeof n&&null!==n)throw new Error("Meteor does not currently support objects other than ObjectID as ids");return"~"+r.stringify(n)},e._idParse=function(n){return""===n?n:"-"===n?void 0:"-"===n.substr(0,1)?n.substr(1):"~"===n.substr(0,1)?r.parse(n.substr(1)):e._looksLikeObjectID(n)?new e._ObjectID(n):n},e._makeChangedFields=function(n,t){var r={};return e._diffObjects(t,n,{leftOnly:function(e){r[e]=void 0},rightOnly:function(e,n){r[e]=n},both:function(e,n,t){o.equals(n,t)||(r[e]=t)}}),r},e._observeFromObserveChanges=function(n,t){var r=n.getTransform();if(r||(r=function(e){return e}),t.addedAt&&t.added)throw new Error("Please specify only one of added() and addedAt()");if(t.changedAt&&t.changed)throw new Error("Please specify only one of changed() and changedAt()");if(t.removed&&t.removedAt)throw new Error("Please specify only one of removed() and removedAt()");return t.addedAt||t.movedTo||t.changedAt||t.removedAt?e._observeOrderedFromObserveChanges(n,t,r):e._observeUnorderedFromObserveChanges(n,t,r)},e._observeUnorderedFromObserveChanges=function(n,t,r){var i={},a=!!t._suppress_initial,u=n.observeChanges({added:function(n,u){var s=e._idStringify(n),c=o.clone(u);c._id=n,i[s]=c,a||t.added&&t.added(r(c))},changed:function(n,u){var s=e._idStringify(n),c=i[s],l=o.clone(c);e._applyChanges(c,u),a||t.changed&&t.changed(r(c),r(l))},removed:function(n){var o=e._idStringify(n),u=i[o];delete i[o],a||t.removed&&t.removed(r(u))}});return a=!1,u},e._observeOrderedFromObserveChanges=function(n,t,r){var a=new i(e._idStringify),u=!!t._suppress_initial,s=!t._no_indices,c=n.observeChanges({addedBefore:function(e,n,i){var c=o.clone(n);if(c._id=e,a.putBefore(e,c,i||null),!u)if(t.addedAt){var l=s?a.indexOf(e):-1;t.addedAt(r(o.clone(c)),l,i)}else t.added&&t.added(r(o.clone(c)))},changed:function(n,i){var u=a.get(n);if(!u)throw new Error("Unknown id for changed: "+n);var c=o.clone(u);if(e._applyChanges(u,i),t.changedAt){var l=s?a.indexOf(n):-1;t.changedAt(r(o.clone(u)),r(c),l)}else t.changed&&t.changed(r(o.clone(u)),r(c))},movedBefore:function(e,n){var i,u=a.get(e);if(t.movedTo&&(i=s?a.indexOf(e):-1),a.moveBefore(e,n||null),t.movedTo){var c=s?a.indexOf(e):-1;t.movedTo(r(o.clone(u)),i,c,n||null)}else t.moved&&t.moved(r(o.clone(u)))},removed:function(e){var n,o=a.get(e);t.removedAt&&(n=s?a.indexOf(e):-1),a.remove(e),t.removedAt&&t.removedAt(r(o),n),t.removed&&t.removed(r(o))}});return u=!1,c}}.call(this),function(){var n=function(e){return t.isArray(e)&&!o.isBinary(e)},i=function(e,r){return n(e)?t.any(e,r):r(e)},a=function(e,r){return r(e)?!0:n(e)&&t.any(e,r)},u=function(e){var n=void 0;for(var t in e){var r="$"===t.substr(0,1);if(void 0===n)n=r;else if(n!==r)throw new Error("Inconsistent selector: "+e)}return!!n},s=function(r){if(null==r)return function(e){return i(e,function(e){return null==e})};if(!t.isObject(r))return function(e){return i(e,function(e){return e===r})};if(r instanceof RegExp)return function(e){return void 0===e?!1:i(e,function(e){return r.test(e)})};if(n(r))return function(t){return n(t)?a(t,function(n){return e._f._equal(r,n)}):!1};if(u(r)){var o=[];return t.each(r,function(e,n){if(!t.has(l,n))throw new Error("Unrecognized operator: "+n);o.push(l[n](e,r.$options))}),function(e){return t.all(o,function(n){return n(e)})}}return function(n){return i(n,function(n){return e._f._equal(r,n)})}},c={$and:function(e){if(!n(e)||t.isEmpty(e))throw Error("$and/$or/$nor must be nonempty array");var r=t.map(e,f);return function(e){return t.all(r,function(n){return n(e)})}},$or:function(e){if(!n(e)||t.isEmpty(e))throw Error("$and/$or/$nor must be nonempty array");var r=t.map(e,f);return function(e){return t.any(r,function(n){return n(e)})}},$nor:function(e){if(!n(e)||t.isEmpty(e))throw Error("$and/$or/$nor must be nonempty array");var r=t.map(e,f);return function(e){return t.all(r,function(n){return!n(e)
})}},$where:function(e){return e instanceof Function||(e=Function("return "+e)),function(n){return e.call(n)}}},l={$in:function(r){if(!n(r))throw new Error("Argument to $in must be array");return function(n){return a(n,function(n){return t.any(r,function(t){return e._f._equal(t,n)})})}},$all:function(r){if(!n(r))throw new Error("Argument to $all must be array");return function(o){return n(o)?t.all(r,function(n){return t.any(o,function(t){return e._f._equal(n,t)})}):!1}},$lt:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)<0})}},$lte:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)<=0})}},$gt:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)>0})}},$gte:function(n){return function(t){return i(t,function(t){return e._f._cmp(t,n)>=0})}},$ne:function(n){return function(t){return!a(t,function(t){return e._f._equal(t,n)})}},$nin:function(e){if(!n(e))throw new Error("Argument to $nin must be array");var t=l.$in(e);return function(e){return void 0===e?!0:!t(e)}},$exists:function(e){return function(n){return e===(void 0!==n)}},$mod:function(e){var n=e[0],t=e[1];return function(e){return i(e,function(e){return e%n===t})}},$size:function(e){return function(t){return n(t)&&e===t.length}},$type:function(n){return function(t){return void 0===t?!1:i(t,function(t){return e._f._type(t)===n})}},$regex:function(e,n){if(void 0!==n){if(/[^gim]/.test(n))throw new Error("Only the i, m, and g regexp options are supported");var t=e instanceof RegExp?e.source:e;e=new RegExp(t,n)}else e instanceof RegExp||(e=new RegExp(e));return function(n){return void 0===n?!1:i(n,function(n){return e.test(n)})}},$options:function(){return function(){return!0}},$elemMatch:function(e){var r=f(e);return function(e){return n(e)?t.any(e,function(e){return r(e)}):!1}},$not:function(e){var n=s(e);return function(e){return!n(e)}}};e._f={_type:function(t){return"number"==typeof t?1:"string"==typeof t?2:"boolean"==typeof t?8:n(t)?4:null===t?10:t instanceof RegExp?11:"function"==typeof t?13:t instanceof Date?9:o.isBinary(t)?5:t instanceof e._ObjectID?7:3},_equal:function(e,n){return o.equals(e,n,{keyOrderSensitive:!0})},_typeorder:function(e){return[-1,1,2,3,4,5,-1,6,7,8,0,9,-1,100,2,100,1,8,1][e]},_cmp:function(n,t){if(void 0===n)return void 0===t?0:-1;if(void 0===t)return 1;var r=e._f._type(n),o=e._f._type(t),i=e._f._typeorder(r),a=e._f._typeorder(o);if(i!==a)return a>i?-1:1;if(r!==o)throw Error("Missing type coercion logic in _cmp");if(7===r&&(r=o=2,n=n.toHexString(),t=t.toHexString()),9===r&&(r=o=1,n=n.getTime(),t=t.getTime()),1===r)return n-t;if(2===o)return t>n?-1:n===t?0:1;if(3===r){var u=function(e){var n=[];for(var t in e)n.push(t),n.push(e[t]);return n};return e._f._cmp(u(n),u(t))}if(4===r)for(var s=0;;s++){if(s===n.length)return s===t.length?0:-1;if(s===t.length)return 1;var c=e._f._cmp(n[s],t[s]);if(0!==c)return c}if(5===r){if(n.length!==t.length)return n.length-t.length;for(s=0;s<n.length;s++){if(n[s]<t[s])return-1;if(n[s]>t[s])return 1}return 0}if(8===r)return n?t?0:1:t?-1:0;if(10===r)return 0;if(11===r)throw Error("Sorting not supported on regular expression");if(13===r)throw Error("Sorting not supported on Javascript code");throw Error("Unknown type to sort")}},e._matches=function(n,t){return e._compileSelector(n)(t)},e._makeLookupFunction=function(r){var o,i,a,u=r.indexOf(".");if(-1===u)o=r;else{o=r.substr(0,u);var s=r.substr(u+1);i=e._makeLookupFunction(s),a=/^\d+(\.|$)/.test(s)}return function(e){if(null==e)return[void 0];var r=e[o];return i?n(r)&&0===r.length?[void 0]:((!n(r)||a)&&(r=[r]),Array.prototype.concat.apply([],t.map(r,i))):[r]}};var f=function(n){var r=[];return t.each(n,function(n,o){if("$"===o.substr(0,1)){if(!t.has(c,o))throw new Error("Unrecognized logical operator: "+o);r.push(c[o](n))}else{var i=e._makeLookupFunction(o),a=s(n);r.push(function(e){var n=i(e);return t.any(n,a)})}}),function(e){return t.all(r,function(n){return n(e)})}};e._compileSelector=function(t){if(t instanceof Function)return function(e){return t.call(e)};if(e._selectorIsId(t))return function(e){return o.equals(e._id,t)};if(!t||"_id"in t&&!t._id)return function(){return!1};if("boolean"==typeof t||n(t)||o.isBinary(t))throw new Error("Invalid selector: "+t);return f(t)},e._compileSort=function(o){var i=[];if(o instanceof Array)for(var a=0;a<o.length;a++)"string"==typeof o[a]?i.push({lookup:e._makeLookupFunction(o[a]),ascending:!0}):i.push({lookup:e._makeLookupFunction(o[a][0]),ascending:"desc"!==o[a][1]});else{if("object"!=typeof o)throw Error("Bad sort specification: ",r.stringify(o));for(var u in o)i.push({lookup:e._makeLookupFunction(u),ascending:o[u]>=0})}if(0===i.length)return function(){return 0};var s=function(r,o){var i,a=!0;return t.each(r,function(r){n(r)||(r=[r]),n(r)&&0===r.length&&(r=[void 0]),t.each(r,function(n){if(a)i=n,a=!1;else{var t=e._f._cmp(i,n);(o&&t>0||!o&&0>t)&&(i=n)}})}),i};return function(n,t){for(var r=0;r<i.length;++r){var o=i[r],a=s(o.lookup(n),o.ascending),u=s(o.lookup(t),o.ascending),c=e._f._cmp(a,u);if(0!==c)return o.ascending?c:-c}return 0}}}.call(this),function(){e._modify=function(n,r){var i=!1;for(var a in r){i="$"===a.substr(0,1);break}var u;if(i){var u=o.clone(n);for(var s in r){var c=e._modifiers[s];if(!c)throw Error("Invalid modifier specified "+s);for(var l in r[s]){if(l.length&&"."===l[l.length-1])throw Error("Invalid mod field name, may not end in a period");var f=r[s][l],d=l.split("."),p=!!e._noCreateModifiers[s],h="$rename"===s,v=e._findModTarget(u,d,p,h),_=d.pop();c(v,_,f,l,u)}}}else{if(r._id&&!o.equals(n._id,r._id))throw Error("Cannot change the _id of a document");for(var a in r){if("$"===a.substr(0,1))throw Error("When replacing document, field name may not start with '$'");if(/\./.test(a))throw Error("When replacing document, field name may not contain '.'")}u=r}t.each(t.keys(n),function(e){"_id"!==e&&delete n[e]});for(var a in u)n[a]=u[a]},e._findModTarget=function(e,n,t,o){for(var i=0;i<n.length;i++){var a=i===n.length-1,u=n[i],s=/^[0-9]+$/.test(u);if(t&&!("object"==typeof e&&u in e))return void 0;if(e instanceof Array){if(o)return null;if(!s)throw Error("can't append to array using string field name ["+u+"]");for(u=parseInt(u),a&&(n[i]=u);e.length<u;)e.push(null);if(!a)if(e.length===u)e.push({});else if("object"!=typeof e[u])throw Error("can't modify field '"+n[i+1]+"' of list value "+r.stringify(e[u]))}else a||u in e||(e[u]={});if(a)return e;e=e[u]}},e._noCreateModifiers={$unset:!0,$pop:!0,$rename:!0,$pull:!0,$pullAll:!0},e._modifiers={$inc:function(e,n,t){if("number"!=typeof t)throw Error("Modifier $inc allowed for numbers only");if(n in e){if("number"!=typeof e[n])throw Error("Cannot apply $inc modifier to non-number");e[n]+=t}else e[n]=t},$set:function(e,n,t){if("_id"===n&&!o.equals(t,e._id))throw Error("Cannot change the _id of a document");e[n]=o.clone(t)},$unset:function(e,n){void 0!==e&&(e instanceof Array?n in e&&(e[n]=null):delete e[n])},$push:function(e,n,t){var r=e[n];if(void 0===r)e[n]=[t];else{if(!(r instanceof Array))throw Error("Cannot apply $push modifier to non-array");r.push(o.clone(t))}},$pushAll:function(e,n,t){if(!("object"==typeof t&&t instanceof Array))throw Error("Modifier $pushAll/pullAll allowed for arrays only");var r=e[n];if(void 0===r)e[n]=t;else{if(!(r instanceof Array))throw Error("Cannot apply $pushAll modifier to non-array");for(var o=0;o<t.length;o++)r.push(t[o])}},$addToSet:function(n,r,o){var i=n[r];if(void 0===i)n[r]=[o];else{if(!(i instanceof Array))throw Error("Cannot apply $addToSet modifier to non-array");var a=!1;if("object"==typeof o)for(var u in o){"$each"===u&&(a=!0);break}var s=a?o.$each:[o];t.each(s,function(n){for(var t=0;t<i.length;t++)if(e._f._equal(n,i[t]))return;i.push(n)})}},$pop:function(e,n,t){if(void 0!==e){var r=e[n];if(void 0!==r){if(!(r instanceof Array))throw Error("Cannot apply $pop modifier to non-array");"number"==typeof t&&0>t?r.splice(0,1):r.pop()}}},$pull:function(n,t,r){if(void 0!==n){var o=n[t];if(void 0!==o){if(!(o instanceof Array))throw Error("Cannot apply $pull/pullAll modifier to non-array");var i=[];if("object"!=typeof r||r instanceof Array)for(var a=0;a<o.length;a++)e._f._equal(o[a],r)||i.push(o[a]);else for(var u=e._compileSelector(r),a=0;a<o.length;a++)u(o[a])||i.push(o[a]);n[t]=i}}},$pullAll:function(n,t,r){if(!("object"==typeof r&&r instanceof Array))throw Error("Modifier $pushAll/pullAll allowed for arrays only");if(void 0!==n){var o=n[t];if(void 0!==o){if(!(o instanceof Array))throw Error("Cannot apply $pull/pullAll modifier to non-array");for(var i=[],a=0;a<o.length;a++){for(var u=!1,s=0;s<r.length;s++)if(e._f._equal(o[a],r[s])){u=!0;break}u||i.push(o[a])}n[t]=i}}},$rename:function(n,t,r,o,i){if(o===r)throw Error("$rename source must differ from target");if(null===n)throw Error("$rename source field invalid");if("string"!=typeof r)throw Error("$rename target must be a string");if(void 0!==n){var a=n[t];delete n[t];var u=r.split("."),s=e._findModTarget(i,u,!1,!0);if(null===s)throw Error("$rename target field invalid");var c=u.pop();s[c]=a}},$bit:function(){throw Error("$bit is not supported")}}}.call(this),function(){e._diffQueryChanges=function(n,t,r,o){n?e._diffQueryOrderedChanges(t,r,o):e._diffQueryUnorderedChanges(t,r,o)},e._diffQueryUnorderedChanges=function(n,r,i){if(i.moved)throw new Error("_diffQueryUnordered called with a moved observer!");t.each(r,function(r){if(t.has(n,r._id)){var a=n[r._id];i.changed&&!o.equals(a,r)&&i.changed(r._id,e._makeChangedFields(r,a))}else{var u=o.clone(r);delete u._id,i.added&&i.added(r._id,u)}}),i.removed&&t.each(n,function(e){t.has(r,e._id)||i.removed(e._id)})},e._diffQueryOrderedChanges=function(r,i,a){var u={};t.each(i,function(e){u[e._id]&&n._debug("Duplicate _id in new_results"),u[e._id]=!0});var s={};t.each(r,function(e,t){e._id in s&&n._debug("Duplicate _id in old_results"),s[e._id]=t});for(var c=[],l=0,f=i.length,d=new Array(f),p=new Array(f),h=function(e){return s[i[e]._id]},v=0;f>v;v++)if(void 0!==s[i[v]._id]){for(var _=l;_>0&&!(h(d[_-1])<h(v));)_--;p[v]=0===_?-1:d[_-1],d[_]=v,_+1>l&&(l=_+1)}for(var m=0===l?-1:d[l-1];m>=0;)c.push(m),m=p[m];c.reverse(),c.push(i.length),t.each(r,function(e){u[e._id]||a.removed&&a.removed(e._id)});var g=0;t.each(c,function(n){for(var u,c,l,f=i[n]?i[n]._id:null,d=g;n>d;d++)c=i[d],t.has(s,c._id)?(u=r[s[c._id]],l=e._makeChangedFields(c,u),t.isEmpty(l)||a.changed&&a.changed(c._id,l),a.movedBefore&&a.movedBefore(c._id,f)):(l=o.clone(c),delete l._id,a.addedBefore&&a.addedBefore(c._id,l,f),a.added&&a.added(c._id,l));f&&(c=i[n],u=r[s[c._id]],l=e._makeChangedFields(c,u),t.isEmpty(l)||a.changed&&a.changed(c._id,l)),g=n+1})},e._diffObjects=function(e,n,r){t.each(e,function(e,o){t.has(n,o)?r.both&&r.both(o,e,n[o]):r.leftOnly&&r.leftOnly(o,e)}),r.rightOnly&&t.each(n,function(n,o){t.has(e,o)||r.rightOnly(o,n)})}}.call(this),function(){e._looksLikeObjectID=function(e){return 24===e.length&&e.match(/^[0-9a-f]*$/)},e._ObjectID=function(n){var t=this;if(n){if(n=n.toLowerCase(),!e._looksLikeObjectID(n))throw new Error("Invalid hexadecimal string for creating an ObjectID");t._str=n}else t._str=u.hexString(24)},e._ObjectID.prototype.toString=function(){var e=this;return'ObjectID("'+e._str+'")'},e._ObjectID.prototype.equals=function(n){var t=this;return n instanceof e._ObjectID&&t.valueOf()===n.valueOf()},e._ObjectID.prototype.clone=function(){var n=this;return new e._ObjectID(n._str)},e._ObjectID.prototype.typeName=function(){return"oid"},e._ObjectID.prototype.getTimestamp=function(){var e=this;return parseInt(e._str.substr(0,8),16)},e._ObjectID.prototype.valueOf=e._ObjectID.prototype.toJSONValue=e._ObjectID.prototype.toHexString=function(){return this._str},e._selectorIsId=function(n){return"string"==typeof n||"number"==typeof n||n instanceof e._ObjectID},e._selectorIsIdPerhapsAsObject=function(n){return e._selectorIsId(n)||n&&"object"==typeof n&&n._id&&e._selectorIsId(n._id)&&1===t.size(n)},e._idsMatchedBySelector=function(n){if(e._selectorIsId(n))return[n];if(!n)return null;if(t.has(n,"_id"))return e._selectorIsId(n._id)?[n._id]:n._id&&n._id.$in&&t.isArray(n._id.$in)&&!t.isEmpty(n._id.$in)&&t.all(n._id.$in,e._selectorIsId)?n._id.$in:null;if(n.$and&&t.isArray(n.$and))for(var r=0;r<n.$and.length;++r){var o=e._idsMatchedBySelector(n.$and[r]);if(o)return o}return null},o.addType("oid",function(n){return new e._ObjectID(n)})}.call(this),"undefined"==typeof Package&&(Package={}),Package.minimongo={LocalCollection:e}}(),function(){var e=Package.meteor.Meteor;Package.check.check,Package.check.Match;var n,t,r,o,i,a,u,s,c,l,f=Package.random.Random,d=Package.ejson.EJSON,p=Package.json.JSON,h=Package.underscore._,v=Package.deps.Deps,_=Package.reload.Reload,m=Package.minimongo.LocalCollection;!function(){t={}}.call(this),function(){var n=function(n){return function(){e._debug(new Error("not implemented: "+n).stack)}};r=function(){var t="undefined"!=typeof document?document:{location:location,attachEvent:n("attachEvent"),detachEvent:n("detachEvent"),createElement:n("createElement"),domain:location.hostname},r="undefined"!=typeof window?window:{location:location,WebSocket:WebSocket,XMLHttpRequest:XMLHttpRequest},o={},i=function(){};i.prototype.addEventListener=function(e,n){this._listeners||(this._listeners={}),e in this._listeners||(this._listeners[e]=[]);var t=this._listeners[e];-1===o.arrIndexOf(t,n)&&t.push(n)},i.prototype.removeEventListener=function(e,n){if(this._listeners&&e in this._listeners){var t=this._listeners[e],r=o.arrIndexOf(t,n);return-1!==r?(t.length>1?this._listeners[e]=t.slice(0,r).concat(t.slice(r+1)):delete this._listeners[e],void 0):void 0}},i.prototype.dispatchEvent=function(e){var n=e.type,t=Array.prototype.slice.call(arguments,0);if(this["on"+n]&&this["on"+n].apply(this,t),this._listeners&&n in this._listeners)for(var r=0;r<this._listeners[n].length;r++)this._listeners[n][r].apply(this,t)};var a=function(e,n){if(this.type=e,"undefined"!=typeof n)for(var t in n)n.hasOwnProperty(t)&&(this[t]=n[t])};a.prototype.toString=function(){var e=[];for(var n in this)if(this.hasOwnProperty(n)){var t=this[n];"function"==typeof t&&(t="[function]"),e.push(n+"="+t)}return"SimpleEvent("+e.join(", ")+")"};var u=function(e){var n=this;n._events=e||[],n._listeners={}};u.prototype.emit=function(e){var n=this;if(n._verifyType(e),!n._nuked){var t=Array.prototype.slice.call(arguments,1);if(n["on"+e]&&n["on"+e].apply(n,t),e in n._listeners)for(var r=0;r<n._listeners[e].length;r++)n._listeners[e][r].apply(n,t)}},u.prototype.on=function(e,n){var t=this;t._verifyType(e),t._nuked||(e in t._listeners||(t._listeners[e]=[]),t._listeners[e].push(n))},u.prototype._verifyType=function(e){var n=this;-1===o.arrIndexOf(n._events,e)&&o.log("Event "+p.stringify(e)+" not listed "+p.stringify(n._events)+" in "+n)},u.prototype.nuke=function(){var e=this;e._nuked=!0;for(var n=0;n<e._events.length;n++)delete e[e._events[n]];e._listeners={}};var s="abcdefghijklmnopqrstuvwxyz0123456789_";o.random_string=function(e,n){n=n||s.length;var t,r=[];for(t=0;e>t;t++)r.push(s.substr(Math.floor(Math.random()*n),1));return r.join("")},o.random_number=function(e){return Math.floor(Math.random()*e)},o.random_number_string=function(e){var n=(""+(e-1)).length,t=Array(n+1).join("0");return(t+o.random_number(e)).slice(-n)},o.getOrigin=function(e){e+="/";var n=e.split("/").slice(0,3);return n.join("/")},o.isSameOriginUrl=function(e,n){return n||(n=r.location.href),e.split("/").slice(0,3).join("/")===n.split("/").slice(0,3).join("/")},o.isSameOriginScheme=function(e,n){return n||(n=r.location.href),e.split(":")[0]===n.split(":")[0]},o.getParentDomain=function(e){if(/^[0-9.]*$/.test(e))return e;if(/^\[/.test(e))return e;if(!/[.]/.test(e))return e;var n=e.split(".").slice(1);return n.join(".")},o.objectExtend=function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e};var c="_jp";o.polluteGlobalNamespace=function(){c in r||(r[c]={})},o.closeFrame=function(e,n){return"c"+p.stringify([e,n])},o.userSetCode=function(e){return 1e3===e||e>=3e3&&4999>=e},o.countRTO=function(e){var n;return n=e>100?3*e:e+200},o.log=function(){e._debug.apply(null,arguments)},o.bind=function(e,n){return e.bind?e.bind(n):function(){return e.apply(n,arguments)}},o.flatUrl=function(e){return-1===e.indexOf("?")&&-1===e.indexOf("#")},o.amendUrl=function(e){var n=t.location;if(!e)throw new Error("Wrong url for SockJS");if(!o.flatUrl(e))throw new Error("Only basic urls are supported in SockJS");0===e.indexOf("//")&&(e=n.protocol+e),0===e.indexOf("/")&&(e=n.protocol+"//"+n.host+e),e=e.replace(/[/]+$/,"");var r=e.split("/");return("http:"===r[0]&&/:80$/.test(r[2])||"https:"===r[0]&&/:443$/.test(r[2]))&&(r[2]=r[2].replace(/:(80|443)$/,"")),e=r.join("/")},o.arrIndexOf=function(e,n){for(var t=0;t<e.length;t++)if(e[t]===n)return t;return-1},o.arrSkip=function(e,n){var t=o.arrIndexOf(e,n);if(-1===t)return e.slice();var r=e.slice(0,t);return r.concat(e.slice(t+1))},o.isArray=Array.isArray||function(e){return{}.toString.call(e).indexOf("Array")>=0},o.delay=function(e,n){return"function"==typeof e&&(n=e,e=0),setTimeout(n,e)};var l,f=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d={"\x00":"\\u0000","":"\\u0001","":"\\u0002","":"\\u0003","":"\\u0004","":"\\u0005","":"\\u0006","":"\\u0007","\b":"\\b"," ":"\\t","\n":"\\n","":"\\u000b","\f":"\\f","\r":"\\r","":"\\u000e","":"\\u000f","":"\\u0010","":"\\u0011","":"\\u0012","":"\\u0013","":"\\u0014","":"\\u0015","":"\\u0016","":"\\u0017","":"\\u0018","":"\\u0019","":"\\u001a","":"\\u001b","":"\\u001c","":"\\u001d","":"\\u001e","":"\\u001f",'"':'\\"',"\\":"\\\\","":"\\u007f","":"\\u0080","":"\\u0081","":"\\u0082","":"\\u0083","":"\\u0084","
":"\\u0085","":"\\u0086","":"\\u0087","":"\\u0088","":"\\u0089","":"\\u008a","":"\\u008b","":"\\u008c","":"\\u008d","":"\\u008e","":"\\u008f","":"\\u0090","":"\\u0091","":"\\u0092","":"\\u0093","":"\\u0094","":"\\u0095","":"\\u0096","":"\\u0097","":"\\u0098","":"\\u0099","":"\\u009a","":"\\u009b","":"\\u009c","":"\\u009d","":"\\u009e","":"\\u009f","":"\\u00ad","":"\\u0600","":"\\u0601","":"\\u0602","":"\\u0603","":"\\u0604","":"\\u070f","឴":"\\u17b4","឵":"\\u17b5","":"\\u200c","":"\\u200d","":"\\u200e","":"\\u200f","\u2028":"\\u2028","\u2029":"\\u2029","":"\\u202a","":"\\u202b","":"\\u202c","":"\\u202d","":"\\u202e"," ":"\\u202f","":"\\u2060","":"\\u2061","":"\\u2062","":"\\u2063","":"\\u2064","":"\\u2065","":"\\u2066","":"\\u2067","":"\\u2068","":"\\u2069","":"\\u206a","":"\\u206b","":"\\u206c","":"\\u206d","":"\\u206e","":"\\u206f","":"\\ufeff","":"\\ufff0","":"\\ufff1","":"\\ufff2","":"\\ufff3","":"\\ufff4","":"\\ufff5","":"\\ufff6","":"\\ufff7","":"\\ufff8","":"\\ufff9","":"\\ufffa","":"\\ufffb","":"\\ufffc","�":"\\ufffd","":"\\ufffe","":"\\uffff"},h=/[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g,v=p&&p.stringify||function(e){return f.lastIndex=0,f.test(e)&&(e=e.replace(f,function(e){return d[e]})),'"'+e+'"'},_=function(e){var n,t={},r=[];for(n=0;65536>n;n++)r.push(String.fromCharCode(n));return e.lastIndex=0,r.join("").replace(e,function(e){return t[e]="\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4),""}),e.lastIndex=0,t};o.quote=function(e){var n=v(e);return h.lastIndex=0,h.test(n)?(l||(l=_(h)),n.replace(h,function(e){return l[e]})):n};var m=["websocket","xdr-streaming","xhr-streaming","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"];o.probeProtocols=function(){for(var e={},n=0;n<m.length;n++){var t=m[n];e[t]=T[t]&&T[t].enabled()}return e},o.detectProtocols=function(e,n,t){var r={},o=[];n||(n=m);for(var i=0;i<n.length;i++){var a=n[i];r[a]=e[a]}var u=function(e){var n=e.shift();r[n]?o.push(n):e.length>0&&u(e)};return t.websocket!==!1&&u(["websocket"]),r["xhr-streaming"]&&!t.null_origin?o.push("xhr-streaming"):!r["xdr-streaming"]||t.cookie_needed||t.null_origin?u(["iframe-eventsource","iframe-htmlfile"]):o.push("xdr-streaming"),r["xhr-polling"]&&!t.null_origin?o.push("xhr-polling"):!r["xdr-polling"]||t.cookie_needed||t.null_origin?u(["iframe-xhr-polling","jsonp-polling"]):o.push("xdr-polling"),o};var g="_sockjs_global";o.createHook=function(){var e="a"+o.random_string(8);if(!(g in r)){var n={};r[g]=function(e){return e in n||(n[e]={id:e,del:function(){delete n[e]}}),n[e]}}return r[g](e)},o.attachMessage=function(e){o.attachEvent("message",e)},o.attachEvent=function(e,n){"undefined"!=typeof r.addEventListener?r.addEventListener(e,n,!1):(t.attachEvent("on"+e,n),r.attachEvent("on"+e,n))},o.detachMessage=function(e){o.detachEvent("message",e)},o.detachEvent=function(e,n){"undefined"!=typeof r.addEventListener?r.removeEventListener(e,n,!1):(t.detachEvent("on"+e,n),r.detachEvent("on"+e,n))};var y={},b=!1,w=function(){for(var e in y)y[e](),delete y[e]};o.unload_add=function(e){var n=o.random_string(8);return y[n]=e,b&&o.delay(w),n},o.unload_del=function(e){e in y&&delete y[e]},o.createIframe=function(e,n){var r,i,a=t.createElement("iframe"),u=function(){clearTimeout(r);try{a.onload=null}catch(e){}a.onerror=null},s=function(){a&&(u(),setTimeout(function(){a&&a.parentNode.removeChild(a),a=null},0),o.unload_del(i))},c=function(e){a&&(s(),n(e))},l=function(e,n){try{a&&a.contentWindow&&a.contentWindow.postMessage(e,n)}catch(t){}};return a.src=e,a.style.display="none",a.style.position="absolute",a.onerror=function(){c("onerror")},a.onload=function(){clearTimeout(r),r=setTimeout(function(){c("onload timeout")},2e3)},t.body.appendChild(a),r=setTimeout(function(){c("timeout")},15e3),i=o.unload_add(s),{post:l,cleanup:s,loaded:u}},o.createHtmlfile=function(e,n){var t,i,a,u=new ActiveXObject("htmlfile"),s=function(){clearTimeout(t)},l=function(){u&&(s(),o.unload_del(i),a.parentNode.removeChild(a),a=u=null,CollectGarbage())},f=function(e){u&&(l(),n(e))},d=function(e,n){try{a&&a.contentWindow&&a.contentWindow.postMessage(e,n)}catch(t){}};u.open(),u.write('<html><script>document.domain="'+document.domain+'";'+"</s"+"cript></html>"),u.close(),u.parentWindow[c]=r[c];var p=u.createElement("div");return u.body.appendChild(p),a=u.createElement("iframe"),p.appendChild(a),a.src=e,t=setTimeout(function(){f("timeout")},15e3),i=o.unload_add(l),{post:d,cleanup:l,loaded:s}};var E=function(){};E.prototype=new u(["chunk","finish"]),E.prototype._start=function(e,n,t,i){var a=this;try{a.xhr=new XMLHttpRequest}catch(u){}if(!a.xhr)try{a.xhr=new r.ActiveXObject("Microsoft.XMLHTTP")}catch(u){}(r.ActiveXObject||r.XDomainRequest)&&(n+=(-1===n.indexOf("?")?"?":"&")+"t="+ +new Date),a.unload_ref=o.unload_add(function(){a._cleanup(!0)});try{a.xhr.open(e,n,!0)}catch(s){return a.emit("finish",0,""),a._cleanup(),void 0}if(i&&i.no_credentials||(a.xhr.withCredentials="true"),i&&i.headers)for(var c in i.headers)a.xhr.setRequestHeader(c,i.headers[c]);a.xhr.onreadystatechange=function(){if(a.xhr){var e=a.xhr;switch(e.readyState){case 3:try{var n=e.status,t=e.responseText}catch(e){}1223===n&&(n=204),t&&t.length>0&&a.emit("chunk",n,t);break;case 4:var n=e.status;1223===n&&(n=204),a.emit("finish",n,e.responseText),a._cleanup(!1)}}},a.xhr.send(t)},E.prototype._cleanup=function(e){var n=this;if(n.xhr){if(o.unload_del(n.unload_ref),n.xhr.onreadystatechange=function(){},e)try{n.xhr.abort()}catch(t){}n.unload_ref=n.xhr=null}},E.prototype.close=function(){var e=this;e.nuke(),e._cleanup(!0)};var k=o.XHRCorsObject=function(){var e=this,n=arguments;o.delay(function(){e._start.apply(e,n)})};k.prototype=new E;var S=o.XHRLocalObject=function(e,n,t){var r=this;o.delay(function(){r._start(e,n,t,{no_credentials:!0})})};S.prototype=new E;var O=o.XDRObject=function(e,n,t){var r=this;o.delay(function(){r._start(e,n,t)})};O.prototype=new u(["chunk","finish"]),O.prototype._start=function(e,n,t){var r=this,i=new XDomainRequest;n+=(-1===n.indexOf("?")?"?":"&")+"t="+ +new Date;var a=i.ontimeout=i.onerror=function(){r.emit("finish",0,""),r._cleanup(!1)};i.onprogress=function(){r.emit("chunk",200,i.responseText)},i.onload=function(){r.emit("finish",200,i.responseText),r._cleanup(!1)},r.xdr=i,r.unload_ref=o.unload_add(function(){r._cleanup(!0)});try{r.xdr.open(e,n),r.xdr.send(t)}catch(u){a()}},O.prototype._cleanup=function(e){var n=this;if(n.xdr){if(o.unload_del(n.unload_ref),n.xdr.ontimeout=n.xdr.onerror=n.xdr.onprogress=n.xdr.onload=null,e)try{n.xdr.abort()}catch(t){}n.unload_ref=n.xdr=null}},O.prototype.close=function(){var e=this;e.nuke(),e._cleanup(!0)},o.isXHRCorsCapable=function(){return r.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?1:r.XDomainRequest&&t.domain?2:W.enabled()?3:4};var T=function(e,n,t){if(!(this instanceof T))return new T(e,n,t);var r,i=this;i._options={devel:!1,debug:!1,protocols_whitelist:[],info:void 0,rtt:void 0},t&&o.objectExtend(i._options,t),i._base_url=o.amendUrl(e),i._server=i._options.server||o.random_number_string(1e3),i._options.protocols_whitelist&&i._options.protocols_whitelist.length?r=i._options.protocols_whitelist:(r="string"==typeof n&&n.length>0?[n]:o.isArray(n)?n:null,r&&i._debug('Deprecated API: Use "protocols_whitelist" option instead of supplying protocol list as a second parameter to SockJS constructor.')),i._protocols=[],i.protocol=null,i.readyState=T.CONNECTING,i._ir=X(i._base_url),i._ir.onfinish=function(e,n){i._ir=null,e?(i._options.info&&(e=o.objectExtend(e,i._options.info)),i._options.rtt&&(n=i._options.rtt),i._applyInfo(e,n,r),i._didClose()):i._didClose(1002,"Can't connect to server",!0)}};T.prototype=new i,T.version="0.3.4",T.CONNECTING=0,T.OPEN=1,T.CLOSING=2,T.CLOSED=3,T.prototype._debug=function(){this._options.debug&&o.log.apply(o,arguments)},T.prototype._dispatchOpen=function(){var e=this;e.readyState===T.CONNECTING?(e._transport_tref&&(clearTimeout(e._transport_tref),e._transport_tref=null),e.readyState=T.OPEN,e.dispatchEvent(new a("open"))):e._didClose(1006,"Server lost session")},T.prototype._dispatchMessage=function(e){var n=this;n.readyState===T.OPEN&&n.dispatchEvent(new a("message",{data:e}))},T.prototype._dispatchHeartbeat=function(){var e=this;e.readyState===T.OPEN&&e.dispatchEvent(new a("heartbeat",{}))},T.prototype._didClose=function(e,n,t){var r=this;if(r.readyState!==T.CONNECTING&&r.readyState!==T.OPEN&&r.readyState!==T.CLOSING)throw new Error("INVALID_STATE_ERR");r._ir&&(r._ir.nuke(),r._ir=null),r._transport&&(r._transport.doCleanup(),r._transport=null);var i=new a("close",{code:e,reason:n,wasClean:o.userSetCode(e)});if(!o.userSetCode(e)&&r.readyState===T.CONNECTING&&!t){if(r._try_next_protocol(i))return;i=new a("close",{code:2e3,reason:"All transports failed",wasClean:!1,last_event:i})}r.readyState=T.CLOSED,o.delay(function(){r.dispatchEvent(i)})},T.prototype._didMessage=function(e){var n=this,t=e.slice(0,1);switch(t){case"o":n._dispatchOpen();break;case"a":for(var r=p.parse(e.slice(1)||"[]"),o=0;o<r.length;o++)n._dispatchMessage(r[o]);break;case"m":var r=p.parse(e.slice(1)||"null");n._dispatchMessage(r);break;case"c":var r=p.parse(e.slice(1)||"[]");n._didClose(r[0],r[1]);break;case"h":n._dispatchHeartbeat()}},T.prototype._try_next_protocol=function(e){var n=this;for(n.protocol&&(n._debug("Closed transport:",n.protocol,""+e),n.protocol=null),n._transport_tref&&(clearTimeout(n._transport_tref),n._transport_tref=null);;){var r=n.protocol=n._protocols.shift();if(!r)return!1;if(T[r]&&T[r].need_body===!0&&(!t.body||"undefined"!=typeof t.readyState&&"complete"!==t.readyState))return n._protocols.unshift(r),n.protocol="waiting-for-load",o.attachEvent("load",function(){n._try_next_protocol()}),!0;if(T[r]&&T[r].enabled(n._options)){var i=T[r].roundTrips||1,a=(n._options.rto||0)*i||5e3;n._transport_tref=o.delay(a,function(){n.readyState===T.CONNECTING&&n._didClose(2007,"Transport timeouted")});var u=o.random_string(8),s=n._base_url+"/"+n._server+"/"+u;return n._debug("Opening transport:",r," url:"+s," RTO:"+n._options.rto),n._transport=new T[r](n,s,n._base_url),!0}n._debug("Skipping transport:",r)}},T.prototype.close=function(e,n){var t=this;if(e&&!o.userSetCode(e))throw new Error("INVALID_ACCESS_ERR");return t.readyState!==T.CONNECTING&&t.readyState!==T.OPEN?!1:(t.readyState=T.CLOSING,t._didClose(e||1e3,n||"Normal closure"),!0)},T.prototype.send=function(e){var n=this;if(n.readyState===T.CONNECTING)throw new Error("INVALID_STATE_ERR");return n.readyState===T.OPEN&&n._transport.doSend(o.quote(""+e)),!0},T.prototype._applyInfo=function(e,n,r){var i=this;i._options.info=e,i._options.rtt=n,i._options.rto=o.countRTO(n),i._options.info.null_origin=!t.domain,e.base_url&&(i._base_url=e.base_url);var a=o.probeProtocols();i._protocols=o.detectProtocols(a,r,e),o.isSameOriginScheme(i._base_url)||2!==o.isXHRCorsCapable()||(i._protocols=["jsonp-polling"])};var I=T.websocket=function(e,n){var t=this,i=n+"/websocket";i="https"===i.slice(0,5)?"wss"+i.slice(5):"ws"+i.slice(4),t.ri=e,t.url=i;var a=r.WebSocket||r.MozWebSocket;t.ws=new a(t.url),t.ws.onmessage=function(e){t.ri._didMessage(e.data)},t.unload_ref=o.unload_add(function(){t.ws.close()}),t.ws.onclose=function(){t.ri._didMessage(o.closeFrame(1006,"WebSocket connection broken"))}};I.prototype.doSend=function(e){this.ws.send("["+e+"]")},I.prototype.doCleanup=function(){var e=this,n=e.ws;n&&(n.onmessage=n.onclose=null,n.close(),o.unload_del(e.unload_ref),e.unload_ref=e.ri=e.ws=null)},I.enabled=function(){return!(!r.WebSocket&&!r.MozWebSocket)},I.roundTrips=2;var C=function(){};C.prototype.send_constructor=function(e){var n=this;n.send_buffer=[],n.sender=e},C.prototype.doSend=function(e){var n=this;n.send_buffer.push(e),n.send_stop||n.send_schedule()},C.prototype.send_schedule_wait=function(){var e,n=this;n.send_stop=function(){n.send_stop=null,clearTimeout(e)},e=o.delay(25,function(){n.send_stop=null,n.send_schedule()})},C.prototype.send_schedule=function(){var e=this;if(e.send_buffer.length>0){var n="["+e.send_buffer.join(",")+"]";e.send_stop=e.sender(e.trans_url,n,function(n,t){e.send_stop=null,n===!1?e.ri._didClose(1006,"Sending error "+t):e.send_schedule_wait()}),e.send_buffer=[]}},C.prototype.send_destructor=function(){var e=this;e._send_stop&&e._send_stop(),e._send_stop=null};var R=function(e,n,r){var i=this;if(!("_send_form"in i)){var a=i._send_form=t.createElement("form"),u=i._send_area=t.createElement("textarea");u.name="d",a.style.display="none",a.style.position="absolute",a.method="POST",a.enctype="application/x-www-form-urlencoded",a.acceptCharset="UTF-8",a.appendChild(u),t.body.appendChild(a)}var a=i._send_form,u=i._send_area,s="a"+o.random_string(8);a.target=s,a.action=e+"/jsonp_send?i="+s;var c;try{c=t.createElement('<iframe name="'+s+'">')}catch(l){c=t.createElement("iframe"),c.name=s}c.id=s,a.appendChild(c),c.style.display="none";try{u.value=n}catch(f){o.log("Your browser is seriously broken. Go home! "+f.message)}a.submit();var d=function(){c.onerror&&(c.onreadystatechange=c.onerror=c.onload=null,o.delay(500,function(){c.parentNode.removeChild(c),c=null}),u.value="",r(!0))};return c.onerror=c.onload=d,c.onreadystatechange=function(){"complete"==c.readyState&&d()
},d},N=function(e){return function(n,t,r){var o=new e("POST",n+"/xhr_send",t);return o.onfinish=function(e){r(200===e||204===e,"http status "+e)},function(e){r(!1,e)}}},A=function(e,n){var r,i,a=t.createElement("script"),u=function(e){i&&(i.parentNode.removeChild(i),i=null),a&&(clearTimeout(r),a.parentNode.removeChild(a),a.onreadystatechange=a.onerror=a.onload=a.onclick=null,a=null,n(e),n=null)},s=!1,c=null;if(a.id="a"+o.random_string(8),a.src=e,a.type="text/javascript",a.charset="UTF-8",a.onerror=function(){c||(c=setTimeout(function(){s||u(o.closeFrame(1006,"JSONP script loaded abnormally (onerror)"))},1e3))},a.onload=function(){u(o.closeFrame(1006,"JSONP script loaded abnormally (onload)"))},a.onreadystatechange=function(){if(/loaded|closed/.test(a.readyState)){if(a&&a.htmlFor&&a.onclick){s=!0;try{a.onclick()}catch(e){}}a&&u(o.closeFrame(1006,"JSONP script loaded abnormally (onreadystatechange)"))}},"undefined"==typeof a.async&&t.attachEvent)if(/opera/i.test(navigator.userAgent))i=t.createElement("script"),i.text="try{var a = document.getElementById('"+a.id+"'); if(a)a.onerror();}catch(x){};",a.async=i.async=!1;else{try{a.htmlFor=a.id,a.event="onclick"}catch(l){}a.async=!0}"undefined"!=typeof a.async&&(a.async=!0),r=setTimeout(function(){u(o.closeFrame(1006,"JSONP script loaded abnormally (timeout)"))},35e3);var f=t.getElementsByTagName("head")[0];return f.insertBefore(a,f.firstChild),i&&f.insertBefore(i,f.firstChild),u},D=T["jsonp-polling"]=function(e,n){o.polluteGlobalNamespace();var t=this;t.ri=e,t.trans_url=n,t.send_constructor(R),t._schedule_recv()};D.prototype=new C,D.prototype._schedule_recv=function(){var e=this,n=function(n){e._recv_stop=null,n&&(e._is_closing||e.ri._didMessage(n)),e._is_closing||e._schedule_recv()};e._recv_stop=M(e.trans_url+"/jsonp",A,n)},D.enabled=function(){return!0},D.need_body=!0,D.prototype.doCleanup=function(){var e=this;e._is_closing=!0,e._recv_stop&&e._recv_stop(),e.ri=e._recv_stop=null,e.send_destructor()};var M=function(e,n,t){var i="a"+o.random_string(6),a=e+"?c="+escape(c+"."+i),u=0,s=function(e){switch(u){case 0:delete r[c][i],t(e);break;case 1:t(e),u=2;break;case 2:delete r[c][i]}},l=n(a,s);r[c][i]=l;var f=function(){r[c][i]&&(u=1,r[c][i](o.closeFrame(1e3,"JSONP user aborted read")))};return f},x=function(){};x.prototype=new C,x.prototype.run=function(e,n,t,r,o){var i=this;i.ri=e,i.trans_url=n,i.send_constructor(N(o)),i.poll=new en(e,r,n+t,o)},x.prototype.doCleanup=function(){var e=this;e.poll&&(e.poll.abort(),e.poll=null)};var j=T["xhr-streaming"]=function(e,n){this.run(e,n,"/xhr_streaming",an,o.XHRCorsObject)};j.prototype=new x,j.enabled=function(){return r.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest&&!/opera/i.test(navigator.userAgent)},j.roundTrips=2,j.need_body=!0;var U=T["xdr-streaming"]=function(e,n){this.run(e,n,"/xhr_streaming",an,o.XDRObject)};U.prototype=new x,U.enabled=function(){return!!r.XDomainRequest},U.roundTrips=2;var P=T["xhr-polling"]=function(e,n){this.run(e,n,"/xhr",an,o.XHRCorsObject)};P.prototype=new x,P.enabled=j.enabled,P.roundTrips=2;var L=T["xdr-polling"]=function(e,n){this.run(e,n,"/xhr",an,o.XDRObject)};L.prototype=new x,L.enabled=U.enabled,L.roundTrips=2;var W=function(){};W.prototype.i_constructor=function(e,n,t){var r=this;r.ri=e,r.origin=o.getOrigin(t),r.base_url=t,r.trans_url=n;var i=t+"/iframe.html";r.ri._options.devel&&(i+="?t="+ +new Date),r.window_id=o.random_string(8),i+="#"+r.window_id,r.iframeObj=o.createIframe(i,function(e){r.ri._didClose(1006,"Unable to load an iframe ("+e+")")}),r.onmessage_cb=o.bind(r.onmessage,r),o.attachMessage(r.onmessage_cb)},W.prototype.doCleanup=function(){var e=this;if(e.iframeObj){o.detachMessage(e.onmessage_cb);try{e.iframeObj.iframe.contentWindow&&e.postMessage("c")}catch(n){}e.iframeObj.cleanup(),e.iframeObj=null,e.onmessage_cb=e.iframeObj=null}},W.prototype.onmessage=function(e){var n=this;if(e.origin===n.origin){var t=e.data.slice(0,8),r=e.data.slice(8,9),o=e.data.slice(9);if(t===n.window_id)switch(r){case"s":n.iframeObj.loaded(),n.postMessage("s",p.stringify([T.version,n.protocol,n.trans_url,n.base_url]));break;case"t":n.ri._didMessage(o)}}},W.prototype.postMessage=function(e,n){var t=this;t.iframeObj.post(t.window_id+e+(n||""),t.origin)},W.prototype.doSend=function(e){this.postMessage("m",e)},W.enabled=function(){var e=navigator&&navigator.userAgent&&-1!==navigator.userAgent.indexOf("Konqueror");return("function"==typeof r.postMessage||"object"==typeof r.postMessage)&&!e};var B,F=function(e,n){parent!==r?parent.postMessage(B+e+(n||""),"*"):o.log("Can't postMessage, no parent window.",e,n)},q=function(){};q.prototype._didClose=function(e,n){F("t",o.closeFrame(e,n))},q.prototype._didMessage=function(e){F("t",e)},q.prototype._doSend=function(e){this._transport.doSend(e)},q.prototype._doCleanup=function(){this._transport.doCleanup()},o.parent_origin=void 0,T.bootstrap_iframe=function(){var e;B=t.location.hash.slice(1);var n=function(n){if(n.source===parent&&("undefined"==typeof o.parent_origin&&(o.parent_origin=n.origin),n.origin===o.parent_origin)){var t=n.data.slice(0,8),i=n.data.slice(8,9),a=n.data.slice(9);if(t===B)switch(i){case"s":var u=p.parse(a),s=u[0],c=u[1],l=u[2],f=u[3];if(s!==T.version&&o.log('Incompatibile SockJS! Main site uses: "'+s+'", the iframe:'+' "'+T.version+'".'),!o.flatUrl(l)||!o.flatUrl(f))return o.log("Only basic urls are supported in SockJS"),void 0;if(!o.isSameOriginUrl(l)||!o.isSameOriginUrl(f))return o.log("Can't connect to different domain from within an iframe. ("+p.stringify([r.location.href,l,f])+")"),void 0;e=new q,e._transport=new q[c](e,l,f);break;case"m":e._doSend(a);break;case"c":e&&e._doCleanup(),e=null}}};o.attachMessage(n),F("s")};var $=function(e,n){var t=this;o.delay(function(){t.doXhr(e,n)})};$.prototype=new u(["finish"]),$.prototype.doXhr=function(e,n){var t=this,r=(new Date).getTime(),i=new n("GET",e+"/info?cb="+o.random_string(10)),a=o.delay(8e3,function(){i.ontimeout()});i.onfinish=function(e,n){if(clearTimeout(a),a=null,200===e){var o=(new Date).getTime()-r,i=p.parse(n);"object"!=typeof i&&(i={}),t.emit("finish",i,o)}else t.emit("finish")},i.ontimeout=function(){i.close(),t.emit("finish")}};var H=function(e){var n=this,r=function(){var t=new W;t.protocol="w-iframe-info-receiver";var r=function(e){if("string"==typeof e&&"m"===e.substr(0,1)){var r=p.parse(e.substr(1)),o=r[0],i=r[1];n.emit("finish",o,i)}else n.emit("finish");t.doCleanup(),t=null},o={_options:{},_didClose:r,_didMessage:r};t.i_constructor(o,e,e)};t.body?r():o.attachEvent("load",r)};H.prototype=new u(["finish"]);var V=function(){var e=this;o.delay(function(){e.emit("finish",{},2e3)})};V.prototype=new u(["finish"]);var X=function(e){if(o.isSameOriginUrl(e))return new $(e,o.XHRLocalObject);switch(o.isXHRCorsCapable()){case 1:return new $(e,o.XHRLocalObject);case 2:return o.isSameOriginScheme(e)?new $(e,o.XDRObject):new V;case 3:return new H(e);default:return new V}},J=q["w-iframe-info-receiver"]=function(e,n,t){var r=new $(t,o.XHRLocalObject);r.onfinish=function(n,t){e._didMessage("m"+p.stringify([n,t])),e._didClose()}};J.prototype.doCleanup=function(){};var Q=T["iframe-eventsource"]=function(){var e=this;e.protocol="w-iframe-eventsource",e.i_constructor.apply(e,arguments)};Q.prototype=new W,Q.enabled=function(){return"EventSource"in r&&W.enabled()},Q.need_body=!0,Q.roundTrips=3;var Y=q["w-iframe-eventsource"]=function(e,n){this.run(e,n,"/eventsource",nn,o.XHRLocalObject)};Y.prototype=new x;var G=T["iframe-xhr-polling"]=function(){var e=this;e.protocol="w-iframe-xhr-polling",e.i_constructor.apply(e,arguments)};G.prototype=new W,G.enabled=function(){return r.XMLHttpRequest&&W.enabled()},G.need_body=!0,G.roundTrips=3;var z=q["w-iframe-xhr-polling"]=function(e,n){this.run(e,n,"/xhr",an,o.XHRLocalObject)};z.prototype=new x;var K=T["iframe-htmlfile"]=function(){var e=this;e.protocol="w-iframe-htmlfile",e.i_constructor.apply(e,arguments)};K.prototype=new W,K.enabled=function(){return W.enabled()},K.need_body=!0,K.roundTrips=3;var Z=q["w-iframe-htmlfile"]=function(e,n){this.run(e,n,"/htmlfile",on,o.XHRLocalObject)};Z.prototype=new x;var en=function(e,n,t,r){var o=this;o.ri=e,o.Receiver=n,o.recv_url=t,o.AjaxObject=r,o._scheduleRecv()};en.prototype._scheduleRecv=function(){var e=this,n=e.poll=new e.Receiver(e.recv_url,e.AjaxObject),t=0;n.onmessage=function(n){t+=1,e.ri._didMessage(n.data)},n.onclose=function(t){e.poll=n=n.onmessage=n.onclose=null,e.poll_is_closing||("permanent"===t.reason?e.ri._didClose(1006,"Polling error ("+t.reason+")"):e._scheduleRecv())}},en.prototype.abort=function(){var e=this;e.poll_is_closing=!0,e.poll&&e.poll.abort()};var nn=function(e){var n=this,t=new EventSource(e);t.onmessage=function(e){n.dispatchEvent(new a("message",{data:unescape(e.data)}))},n.es_close=t.onerror=function(e,r){var i=r?"user":2!==t.readyState?"network":"permanent";n.es_close=t.onmessage=t.onerror=null,t.close(),t=null,o.delay(200,function(){n.dispatchEvent(new a("close",{reason:i}))})}};nn.prototype=new i,nn.prototype.abort=function(){var e=this;e.es_close&&e.es_close({},!0)};var tn,rn=function(){if(void 0===tn)if("ActiveXObject"in r)try{tn=!!new ActiveXObject("htmlfile")}catch(e){}else tn=!1;return tn},on=function(e){var n=this;o.polluteGlobalNamespace(),n.id="a"+o.random_string(6,26),e+=(-1===e.indexOf("?")?"?":"&")+"c="+escape(c+"."+n.id);var t,i=rn()?o.createHtmlfile:o.createIframe;r[c][n.id]={start:function(){t.loaded()},message:function(e){n.dispatchEvent(new a("message",{data:e}))},stop:function(){n.iframe_close({},"network")}},n.iframe_close=function(e,o){t.cleanup(),n.iframe_close=t=null,delete r[c][n.id],n.dispatchEvent(new a("close",{reason:o}))},t=i(e,function(){n.iframe_close({},"permanent")})};on.prototype=new i,on.prototype.abort=function(){var e=this;e.iframe_close&&e.iframe_close({},"user")};var an=function(e,n){var t=this,r=0;t.xo=new n("POST",e,null),t.xo.onchunk=function(e,n){if(200===e)for(;;){var o=n.slice(r),i=o.indexOf("\n");if(-1===i)break;r+=i+1;var u=o.slice(0,i);t.dispatchEvent(new a("message",{data:u}))}},t.xo.onfinish=function(e,n){t.xo.onchunk(e,n),t.xo=null;var r=200===e?"network":"permanent";t.dispatchEvent(new a("close",{reason:r}))}};return an.prototype=new i,an.prototype.abort=function(){var e=this;e.xo&&(e.xo.close(),e.dispatchEvent(new a("close",{reason:"user"})),e.xo=null)},T.getUtils=function(){return o},T.getIframeTransport=function(){return W},T}(),"function"==typeof define&&define.amd&&define("sockjs",[],function(){return r})}.call(this),function(){t.ClientStream=function(e){var n=this;n._initCommon(),n.HEARTBEAT_TIMEOUT=6e4,n.rawUrl=e,n.socket=null,n.sent_update_available=!1,n.heartbeatTimer=null,"undefined"!=typeof window&&window.addEventListener&&window.addEventListener("online",h.bind(n._online,n),!1),n._launchConnection()},h.extend(t.ClientStream.prototype,{send:function(e){var n=this;n.currentStatus.connected&&n.socket.send(e)},_changeUrl:function(e){var n=this;n.rawUrl=e},_connected:function(n){var t=this;if(t.connectionTimer&&(clearTimeout(t.connectionTimer),t.connectionTimer=null),!t.currentStatus.connected){try{var r=p.parse(n)}catch(o){e._debug("DEBUG: malformed welcome packet",n)}r&&r.server_id?__meteor_runtime_config__.serverId&&__meteor_runtime_config__.serverId!==r.server_id&&!t.sent_update_available&&(t.sent_update_available=!0,h.each(t.eventCallbacks.update_available,function(e){e()})):e._debug("DEBUG: invalid welcome packet",r),t.currentStatus.status="connected",t.currentStatus.connected=!0,t.currentStatus.retryCount=0,t.statusChanged(),h.each(t.eventCallbacks.reset,function(e){e()})}},_cleanup:function(){var e=this;e._clearConnectionAndHeartbeatTimers(),e.socket&&(e.socket.onmessage=e.socket.onclose=e.socket.onerror=e.socket.onheartbeat=function(){},e.socket.close(),e.socket=null)},_clearConnectionAndHeartbeatTimers:function(){var e=this;e.connectionTimer&&(clearTimeout(e.connectionTimer),e.connectionTimer=null),e.heartbeatTimer&&(clearTimeout(e.heartbeatTimer),e.heartbeatTimer=null)},_heartbeat_timeout:function(){var n=this;e._debug("Connection timeout. No heartbeat received."),n._lostConnection()},_heartbeat_received:function(){var e=this;e._forcedToDisconnect||(e.heartbeatTimer&&clearTimeout(e.heartbeatTimer),e.heartbeatTimer=setTimeout(h.bind(e._heartbeat_timeout,e),e.HEARTBEAT_TIMEOUT))},_sockjsProtocolsWhitelist:function(){var e=["xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],n=navigator&&/iPhone|iPad|iPod/.test(navigator.userAgent)&&/OS 4_|OS 5_/.test(navigator.userAgent);return n||(e=["websocket"].concat(e)),e},_launchConnection:function(){var n=this;n._cleanup(),n.socket=new r(o(n.rawUrl),void 0,{debug:!1,protocols_whitelist:n._sockjsProtocolsWhitelist()}),n.socket.onmessage=function(e){n._heartbeat_received(),"connecting"===n.currentStatus.status?n._connected(e.data):n.currentStatus.connected&&h.each(n.eventCallbacks.message,function(n){n(e.data)})},n.socket.onclose=function(){n._lostConnection()},n.socket.onerror=function(){e._debug("stream error",h.toArray(arguments),(new Date).toDateString())},n.socket.onheartbeat=function(){n._heartbeat_received()},n.connectionTimer&&clearTimeout(n.connectionTimer),n.connectionTimer=setTimeout(h.bind(n._lostConnection,n),n.CONNECT_TIMEOUT)}})}.call(this),function(){var n=function(e,n){return e.length>=n.length&&e.substring(0,n.length)===n},r=function(e,n){return e.length>=n.length&&e.substring(e.length-n.length)===n},a=function(t,o,i){o||(o="http");var a,u=t.match(/^ddp(i?)\+sockjs:\/\//),s=t.match(/^http(s?):\/\//);if(u){var c=t.substr(u[0].length);a="i"===u[1]?o:o+"s";var l=c.indexOf("/"),d=-1===l?c:c.substr(0,l),p=-1===l?"":c.substr(l);return d=d.replace(/\*/g,function(){return Math.floor(10*f.fraction())}),a+"://"+d+p}if(s){a=s[1]?o+"s":o;var h=t.substr(s[0].length);t=a+"://"+h}return-1!==t.indexOf("://")||n(t,"/")||(t=o+"://"+t),t=e._relativeToSiteRootUrl(t),r(t,"/")?t+i:t+"/"+i};o=function(e){return a(e,"http","sockjs")},i=function(e){var n=a(e,"ws","websocket");return n},t.toSockjsUrl=o,h.extend(t.ClientStream.prototype,{on:function(e,n){var t=this;if("message"!==e&&"reset"!==e&&"update_available"!==e)throw new Error("unknown event type: "+e);t.eventCallbacks[e]||(t.eventCallbacks[e]=[]),t.eventCallbacks[e].push(n)},_initCommon:function(){var e=this;e.CONNECT_TIMEOUT=1e4,e.RETRY_BASE_TIMEOUT=1e3,e.RETRY_EXPONENT=2.2,e.RETRY_MAX_TIMEOUT=3e5,e.RETRY_MIN_TIMEOUT=10,e.RETRY_MIN_COUNT=2,e.RETRY_FUZZ=.5,e.eventCallbacks={},e._forcedToDisconnect=!1,e.currentStatus={status:"connecting",connected:!1,retryCount:0},e.statusListeners="undefined"!=typeof v&&new v.Dependency,e.statusChanged=function(){e.statusListeners&&e.statusListeners.changed()},e.retryTimer=null,e.connectionTimer=null},reconnect:function(e){var n=this;return e=e||{},e.url&&n._changeUrl(e.url),n.currentStatus.connected?((e._force||e.url)&&n._lostConnection(),void 0):("connecting"===n.currentStatus.status&&n._lostConnection(),n.retryTimer&&clearTimeout(n.retryTimer),n.retryTimer=null,n.currentStatus.retryCount-=1,n._retryNow(),void 0)},disconnect:function(e){var n=this;e=e||{},n._forcedToDisconnect||(e._permanent&&(n._forcedToDisconnect=!0),n._cleanup(),n.retryTimer&&(clearTimeout(n.retryTimer),n.retryTimer=null),n.currentStatus={status:e._permanent?"failed":"offline",connected:!1,retryCount:0},e._permanent&&e._error&&(n.currentStatus.reason=e._error),n.statusChanged())},_lostConnection:function(){var e=this;e._cleanup(),e._retryLater()},_retryTimeout:function(e){var n=this;if(e<n.RETRY_MIN_COUNT)return n.RETRY_MIN_TIMEOUT;var t=Math.min(n.RETRY_MAX_TIMEOUT,n.RETRY_BASE_TIMEOUT*Math.pow(n.RETRY_EXPONENT,e));return t*=f.fraction()*n.RETRY_FUZZ+(1-n.RETRY_FUZZ/2)},_online:function(){"offline"!=this.currentStatus.status&&this.reconnect()},_retryLater:function(){var e=this,n=e._retryTimeout(e.currentStatus.retryCount);e.retryTimer&&clearTimeout(e.retryTimer),e.retryTimer=setTimeout(h.bind(e._retryNow,e),n),e.currentStatus.status="waiting",e.currentStatus.connected=!1,e.currentStatus.retryTime=(new Date).getTime()+n,e.statusChanged()},_retryNow:function(){var e=this;e._forcedToDisconnect||(e.currentStatus.retryCount+=1,e.currentStatus.status="connecting",e.currentStatus.connected=!1,delete e.currentStatus.retryTime,e.statusChanged(),e._launchConnection())},status:function(){var e=this;return e.statusListeners&&e.statusListeners.depend(),e.currentStatus}})}.call(this),function(){n={},a=["pre1"],t.SUPPORTED_DDP_VERSIONS=a,u=function(e){this.isSimulation=e.isSimulation,this._unblock=e.unblock||function(){},this._calledUnblock=!1,this.userId=e.userId,this._setUserId=e.setUserId||function(){},this._sessionData=e.sessionData},h.extend(u.prototype,{unblock:function(){var e=this;e._calledUnblock=!0,e._unblock()},setUserId:function(e){var n=this;if(n._calledUnblock)throw new Error("Can't call setUserId in a method after calling unblock");n.userId=e,n._setUserId(e)}}),s=function(n){try{var t=p.parse(n)}catch(r){return e._debug("Discarding message with invalid JSON",n),null}return null===t||"object"!=typeof t?(e._debug("Discarding non-object DDP message",n),null):(h.has(t,"cleared")&&(h.has(t,"fields")||(t.fields={}),h.each(t.cleared,function(e){t.fields[e]=void 0}),delete t.cleared),h.each(["fields","params","result"],function(e){h.has(t,e)&&(t[e]=d._adjustTypesFromJSONValue(t[e]))}),t)},c=function(e){var n=d.clone(e);if(h.has(e,"fields")){var t=[];h.each(e.fields,function(e,r){void 0===e&&(t.push(r),delete n.fields[r])}),h.isEmpty(t)||(n.cleared=t),h.isEmpty(n.fields)&&delete n.fields}if(h.each(["fields","params","result"],function(e){h.has(n,e)&&(n[e]=d._adjustTypesToJSONValue(n[e]))}),e.id&&"string"!=typeof e.id)throw new Error("Message id is not a string");return p.stringify(n)},n._CurrentInvocation=new e.EnvironmentVariable}.call(this),function(){if(e.isServer){var r=Npm.require("path");Npm.require("fibers");var o=Npm.require(r.join("fibers","future"))}var i=function(n,r){var o=this;r=h.extend({reloadOnUpdate:!1,reloadWithOutstanding:!1,supportedDDPVersions:a,onConnectionFailure:function(n){e._debug("Failed DDP connection: "+n)},onConnected:function(){}},r),o.onReconnect=null,o._stream="object"==typeof n?n:new t.ClientStream(n),o._lastSessionId=null,o._versionSuggestion=null,o._version=null,o._stores={},o._methodHandlers={},o._nextMethodId=1,o._supportedDDPVersions=r.supportedDDPVersions,o._methodInvokers={},o._outstandingMethodBlocks=[],o._documentsWrittenByStub={},o._serverDocuments={},o._afterUpdateCallbacks=[],o._messagesBufferedUntilQuiescence=[],o._methodsBlockingQuiescence={},o._subsBeingRevived={},o._resetStores=!1,o._updatesForUnknownStores={},o._retryMigrate=null,o._subscriptions={},o._sessionData={},o._userId=null,o._userIdDeps="undefined"!=typeof v&&new v.Dependency,e.isClient&&Package.reload&&!r.reloadWithOutstanding&&_._onMigrate(function(e){if(o._readyToMigrate())return[!0];if(o._retryMigrate)throw new Error("Two migrations in progress?");return o._retryMigrate=e,!1});var i=function(n){try{var t=s(n)}catch(i){return e._debug("Exception while parsing DDP",i),void 0}if(null===t||!t.msg)return e._debug("discarding invalid livedata message",t),void 0;if("connected"===t.msg)o._version=o._versionSuggestion,r.onConnected(),o._livedata_connected(t);else if("failed"==t.msg)if(h.contains(o._supportedDDPVersions,t.version))o._versionSuggestion=t.version,o._stream.reconnect({_force:!0});else{var a="Version negotiation failed; server requested version "+t.version;o._stream.disconnect({_permanent:!0,_error:a}),r.onConnectionFailure(a)}else h.include(["added","changed","removed","ready","updated"],t.msg)?o._livedata_data(t):"nosub"===t.msg?o._livedata_nosub(t):"result"===t.msg?o._livedata_result(t):"error"===t.msg?o._livedata_error(t):e._debug("discarding unknown livedata message type",t)},u=function(){var e={msg:"connect"};o._lastSessionId&&(e.session=o._lastSessionId),e.version=o._versionSuggestion||o._supportedDDPVersions[0],o._versionSuggestion=e.version,e.support=o._supportedDDPVersions,o._send(e),!h.isEmpty(o._outstandingMethodBlocks)&&h.isEmpty(o._outstandingMethodBlocks[0].methods)&&o._outstandingMethodBlocks.shift(),h.each(o._methodInvokers,function(e){e.sentMessage=!1}),o.onReconnect?o._callOnReconnectAndSendAppropriateOutstandingMethods():o._sendOutstandingMethods(),h.each(o._subscriptions,function(e,n){o._send({msg:"sub",id:n,name:e.name,params:e.params})})};e.isServer?(o._stream.on("message",e.bindEnvironment(i,e._debug)),o._stream.on("reset",e.bindEnvironment(u,e._debug))):(o._stream.on("message",i),o._stream.on("reset",u)),e.isClient&&Package.reload&&r.reloadOnUpdate&&o._stream.on("update_available",function(){_._reload()})},g=function(e){var n=this;n.methodId=e.methodId,n.sentMessage=!1,n._callback=e.callback,n._connection=e.connection,n._message=e.message,n._onResultReceived=e.onResultReceived||function(){},n._wait=e.wait,n._methodResult=null,n._dataVisible=!1,n._connection._methodInvokers[n.methodId]=n};h.extend(g.prototype,{sendMessage:function(){var e=this;if(e.gotResult())throw new Error("sendingMethod is called on method with result");e._dataVisible=!1,e.sentMessage=!0,e._wait&&(e._connection._methodsBlockingQuiescence[e.methodId]=!0),e._connection._send(e._message)},_maybeInvokeCallback:function(){var e=this;e._methodResult&&e._dataVisible&&(e._callback(e._methodResult[0],e._methodResult[1]),delete e._connection._methodInvokers[e.methodId],e._connection._outstandingMethodFinished())},receiveResult:function(e,n){var t=this;if(t.gotResult())throw new Error("Methods should only receive results once");t._methodResult=[e,n],t._onResultReceived(e,n),t._maybeInvokeCallback()},dataVisible:function(){var e=this;e._dataVisible=!0,e._maybeInvokeCallback()},gotResult:function(){var e=this;return!!e._methodResult}}),h.extend(i.prototype,{registerStore:function(e,n){var t=this;if(e in t._stores)return!1;var r={};h.each(["update","beginUpdate","endUpdate","saveOriginals","retrieveOriginals"],function(e){r[e]=function(){return n[e]?n[e].apply(n,arguments):void 0}}),t._stores[e]=r;var o=t._updatesForUnknownStores[e];return o&&(r.beginUpdate(o.length,!1),h.each(o,function(e){r.update(e)}),r.endUpdate(),delete t._updatesForUnknownStores[e]),!0},subscribe:function(e){var n=this,t=Array.prototype.slice.call(arguments,1),r={};if(t.length){var o=t[t.length-1];"function"==typeof o?r.onReady=t.pop():!o||"function"!=typeof o.onReady&&"function"!=typeof o.onError||(r=t.pop())}var i,a=h.find(n._subscriptions,function(n){return n.inactive&&n.name===e&&d.equals(n.params,t)});a?(i=a.id,a.inactive=!1,r.onReady&&(a.ready||(a.readyCallback=r.onReady)),r.onError&&(a.errorCallback=r.onError)):(i=f.id(),n._subscriptions[i]={id:i,name:e,params:t,inactive:!1,ready:!1,readyDeps:"undefined"!=typeof v&&new v.Dependency,readyCallback:r.onReady,errorCallback:r.onError},n._send({msg:"sub",id:i,name:e,params:t}));var u={stop:function(){h.has(n._subscriptions,i)&&(n._send({msg:"unsub",id:i}),delete n._subscriptions[i])},ready:function(){if(!h.has(n._subscriptions,i))return!1;var e=n._subscriptions[i];return e.readyDeps&&e.readyDeps.depend(),e.ready}};return v.active&&v.onInvalidate(function(){h.has(n._subscriptions,i)&&(n._subscriptions[i].inactive=!0),v.afterFlush(function(){h.has(n._subscriptions,i)&&n._subscriptions[i].inactive&&u.stop()})}),u},_subscribeAndWait:function(e,n,t){var r=this,i=new o,a=!1;n=n||[],n.push({onReady:function(){a=!0,i["return"]()},onError:function(e){a?t&&t.onLateError&&t.onLateError(e):i["throw"](e)}}),r.subscribe.apply(r,[e].concat(n)),i.wait()},methods:function(e){var n=this;h.each(e,function(e,t){if(n._methodHandlers[t])throw new Error("A method named '"+t+"' is already defined");n._methodHandlers[t]=e})},call:function(e){var n=Array.prototype.slice.call(arguments,1);if(n.length&&"function"==typeof n[n.length-1])var t=n.pop();return this.apply(e,n,t)},apply:function(t,r,i,a){var s=this;a||"function"!=typeof i||(a=i,i={}),i=i||{},a&&(a=e.bindEnvironment(a,function(n){e._debug("Exception while delivering result of invoking '"+t+"'",n,n.stack)}));var c=function(){var e;return function(){return void 0===e&&(e=""+s._nextMethodId++),e}}(),l=n._CurrentInvocation.get(),f=l&&l.isSimulation,p=s._methodHandlers[t];if(p){var v=function(e){s.setUserId(e)},_=new u({isSimulation:!0,userId:s.userId(),setUserId:v,sessionData:s._sessionData});f||s._saveOriginals();try{var m=n._CurrentInvocation.withValue(_,function(){return e.isServer?e._noYieldsAllowed(function(){return p.apply(_,d.clone(r))}):p.apply(_,d.clone(r))})}catch(y){var b=y}f||s._retrieveAndStoreOriginals(c())}if(f){if(a)return a(b,m),void 0;if(b)throw b;return m}if(b&&!b.expected&&e._debug("Exception while simulating the effect of invoking '"+t+"'",b,b.stack),!a)if(e.isClient)a=function(){};else{var w=new o;a=w.resolver()}var E=new g({methodId:c(),callback:a,connection:s,onResultReceived:i.onResultReceived,wait:!!i.wait,message:{msg:"method",method:t,params:r,id:c()}});return i.wait?s._outstandingMethodBlocks.push({wait:!0,methods:[E]}):((h.isEmpty(s._outstandingMethodBlocks)||h.last(s._outstandingMethodBlocks).wait)&&s._outstandingMethodBlocks.push({wait:!1,methods:[]}),h.last(s._outstandingMethodBlocks).methods.push(E)),1===s._outstandingMethodBlocks.length&&E.sendMessage(),w?w.wait():void 0},_saveOriginals:function(){var e=this;h.each(e._stores,function(e){e.saveOriginals()})},_retrieveAndStoreOriginals:function(n){var t=this;if(t._documentsWrittenByStub[n])throw new Error("Duplicate methodId in _retrieveAndStoreOriginals");var r=[];h.each(t._stores,function(o,i){var a=o.retrieveOriginals();h.each(a,function(o,a){if("string"!=typeof a)throw new Error("id is not a string");r.push({collection:i,id:a});var u=e._ensure(t._serverDocuments,i,a);u.writtenByStubs?u.writtenByStubs[n]=!0:(u.document=o,u.flushCallbacks=[],u.writtenByStubs={},u.writtenByStubs[n]=!0)})}),h.isEmpty(r)||(t._documentsWrittenByStub[n]=r)},_unsubscribeAll:function(){var e=this;h.each(h.clone(e._subscriptions),function(n,t){e._send({msg:"unsub",id:t}),delete e._subscriptions[t]})},_send:function(e){var n=this;n._stream.send(c(e))},status:function(){var e=this;return e._stream.status.apply(e._stream,arguments)},reconnect:function(){var e=this;return e._stream.reconnect.apply(e._stream,arguments)},disconnect:function(){var e=this;return e._stream.disconnect.apply(e._stream,arguments)},close:function(){var e=this;return e._stream.disconnect({_permanent:!0})},userId:function(){var e=this;return e._userIdDeps&&e._userIdDeps.depend(),e._userId},setUserId:function(e){var n=this;n._userId!==e&&(n._userId=e,n._userIdDeps&&n._userIdDeps.changed())},_waitingForQuiescence:function(){var e=this;return!h.isEmpty(e._subsBeingRevived)||!h.isEmpty(e._methodsBlockingQuiescence)},_anyMethodsAreOutstanding:function(){var e=this;return h.any(h.pluck(e._methodInvokers,"sentMessage"))},_livedata_connected:function(e){var n=this;if(n._lastSessionId&&(n._resetStores=!0),"string"==typeof e.session){var t=n._lastSessionId===e.session;n._lastSessionId=e.session}t||(n._updatesForUnknownStores={},n._resetStores&&(n._documentsWrittenByStub={},n._serverDocuments={}),n._afterUpdateCallbacks=[],n._subsBeingRevived={},h.each(n._subscriptions,function(e,t){e.ready&&(n._subsBeingRevived[t]=!0)}),n._methodsBlockingQuiescence={},n._resetStores&&h.each(n._methodInvokers,function(e){e.gotResult()?n._afterUpdateCallbacks.push(h.bind(e.dataVisible,e)):e.sentMessage&&(n._methodsBlockingQuiescence[e.methodId]=!0)}),n._messagesBufferedUntilQuiescence=[],n._waitingForQuiescence()||(n._resetStores&&(h.each(n._stores,function(e){e.beginUpdate(0,!0),e.endUpdate()}),n._resetStores=!1),n._runAfterUpdateCallbacks()))},_processOneDataMessage:function(e,n){var t=this;t["_process_"+e.msg](e,n)},_livedata_data:function(e){var n=this,t={};if(n._waitingForQuiescence()){if(n._messagesBufferedUntilQuiescence.push(e),"nosub"===e.msg&&delete n._subsBeingRevived[e.id],h.each(e.subs||[],function(e){delete n._subsBeingRevived[e]}),h.each(e.methods||[],function(e){delete n._methodsBlockingQuiescence[e]}),n._waitingForQuiescence())return;h.each(n._messagesBufferedUntilQuiescence,function(e){n._processOneDataMessage(e,t)}),n._messagesBufferedUntilQuiescence=[]}else n._processOneDataMessage(e,t);(n._resetStores||!h.isEmpty(t))&&(h.each(n._stores,function(e,r){e.beginUpdate(h.has(t,r)?t[r].length:0,n._resetStores)}),n._resetStores=!1,h.each(t,function(e,t){var r=n._stores[t];r?h.each(e,function(e){r.update(e)}):(h.has(n._updatesForUnknownStores,t)||(n._updatesForUnknownStores[t]=[]),Array.prototype.push.apply(n._updatesForUnknownStores[t],e))}),h.each(n._stores,function(e){e.endUpdate()})),n._runAfterUpdateCallbacks()},_runAfterUpdateCallbacks:function(){var e=this,n=e._afterUpdateCallbacks;e._afterUpdateCallbacks=[],h.each(n,function(e){e()})},_pushUpdate:function(e,n,t){h.has(e,n)||(e[n]=[]),e[n].push(t)},_process_added:function(n,t){var r=this,o=e._get(r._serverDocuments,n.collection,n.id);if(o){if(void 0!==o.document)throw new Error("It doesn't make sense to be adding something we know exists: "+n.id);o.document=n.fields||{},o.document._id=m._idParse(n.id)}else r._pushUpdate(t,n.collection,n)},_process_changed:function(n,t){var r=this,o=e._get(r._serverDocuments,n.collection,n.id);if(o){if(void 0===o.document)throw new Error("It doesn't make sense to be changing something we don't think exists: "+n.id);m._applyChanges(o.document,n.fields)}else r._pushUpdate(t,n.collection,n)},_process_removed:function(n,t){var r=this,o=e._get(r._serverDocuments,n.collection,n.id);if(o){if(void 0===o.document)throw new Error("It doesn't make sense to be deleting something we don't know exists: "+n.id);o.document=void 0}else r._pushUpdate(t,n.collection,{msg:"removed",collection:n.collection,id:n.id})},_process_updated:function(n,t){var r=this;h.each(n.methods,function(n){h.each(r._documentsWrittenByStub[n],function(o){var i=e._get(r._serverDocuments,o.collection,o.id);if(!i)throw new Error("Lost serverDoc for "+p.stringify(o));if(!i.writtenByStubs[n])throw new Error("Doc "+p.stringify(o)+" not written by method "+n);delete i.writtenByStubs[n],h.isEmpty(i.writtenByStubs)&&(r._pushUpdate(t,o.collection,{msg:"replace",id:o.id,replace:i.document}),h.each(i.flushCallbacks,function(e){e()}),delete r._serverDocuments[o.collection][o.id])}),delete r._documentsWrittenByStub[n];var o=r._methodInvokers[n];if(!o)throw new Error("No callback invoker for method "+n);r._runWhenAllServerDocsAreFlushed(h.bind(o.dataVisible,o))})},_process_ready:function(e){var n=this;h.each(e.subs,function(e){n._runWhenAllServerDocsAreFlushed(function(){var t=n._subscriptions[e];t&&(t.ready||(t.readyCallback&&t.readyCallback(),t.ready=!0,t.readyDeps&&t.readyDeps.changed()))})})},_runWhenAllServerDocsAreFlushed:function(e){var n=this,t=function(){n._afterUpdateCallbacks.push(e)},r=0,o=function(){--r,0===r&&t()};h.each(n._serverDocuments,function(e){h.each(e,function(e){var t=h.any(e.writtenByStubs,function(e,t){var r=n._methodInvokers[t];return r&&r.sentMessage});t&&(++r,e.flushCallbacks.push(o))})}),0===r&&t()},_livedata_nosub:function(n){var t=this;if(t._livedata_data(n),h.has(t._subscriptions,n.id)){var r=t._subscriptions[n.id].errorCallback;delete t._subscriptions[n.id],r&&n.error&&r(new e.Error(n.error.error,n.error.reason,n.error.details))}},_process_nosub:function(){},_livedata_result:function(n){var t=this;if(h.isEmpty(t._outstandingMethodBlocks))return e._debug("Received method result but no methods outstanding"),void 0;for(var r,o=t._outstandingMethodBlocks[0].methods,i=0;i<o.length&&(r=o[i],r.methodId!==n.id);i++);return r?(o.splice(i,1),h.has(n,"error")?r.receiveResult(new e.Error(n.error.error,n.error.reason,n.error.details)):r.receiveResult(void 0,n.result),void 0):(e._debug("Can't match method response to original method call",n),void 0)},_outstandingMethodFinished:function(){var e=this;if(!e._anyMethodsAreOutstanding()){if(!h.isEmpty(e._outstandingMethodBlocks)){var n=e._outstandingMethodBlocks.shift();if(!h.isEmpty(n.methods))throw new Error("No methods outstanding but nonempty block: "+p.stringify(n));
h.isEmpty(e._outstandingMethodBlocks)||e._sendOutstandingMethods()}e._maybeMigrate()}},_sendOutstandingMethods:function(){var e=this;h.isEmpty(e._outstandingMethodBlocks)||h.each(e._outstandingMethodBlocks[0].methods,function(e){e.sendMessage()})},_livedata_error:function(n){e._debug("Received error from server: ",n.reason),n.offendingMessage&&e._debug("For: ",n.offendingMessage)},_callOnReconnectAndSendAppropriateOutstandingMethods:function(){var e=this,n=e._outstandingMethodBlocks;if(e._outstandingMethodBlocks=[],e.onReconnect(),!h.isEmpty(n)){if(h.isEmpty(e._outstandingMethodBlocks))return e._outstandingMethodBlocks=n,e._sendOutstandingMethods(),void 0;h.last(e._outstandingMethodBlocks).wait||n[0].wait||(h.each(n[0].methods,function(n){h.last(e._outstandingMethodBlocks).methods.push(n),1===e._outstandingMethodBlocks.length&&n.sendMessage()}),n.shift()),h.each(n,function(n){e._outstandingMethodBlocks.push(n)})}},_readyToMigrate:function(){var e=this;return h.isEmpty(e._methodInvokers)},_maybeMigrate:function(){var e=this;e._retryMigrate&&e._readyToMigrate()&&(e._retryMigrate(),e._retryMigrate=null)}}),t.Connection=i,n.connect=function(e,n){var t=new i(e,{reloadOnUpdate:n});return l.push(t),t},l=[],n._allSubscriptionsReady=function(){return h.all(l,function(e){return h.all(e._subscriptions,function(e){return e.ready})})}}.call(this),function(){if(e.refresh=function(){},e.isClient){var t="/";"undefined"!=typeof __meteor_runtime_config__&&__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL&&(t=__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL),e.connection=n.connect(t,!0),h.each(["subscribe","methods","call","apply","status","reconnect","disconnect"],function(n){e[n]=h.bind(e.connection[n],e.connection)})}else e.connection=null;e.default_connection=e.connection,e.connect=n.connect}.call(this),"undefined"==typeof Package&&(Package={}),Package.livedata={DDP:n,LivedataTest:t}}(),function(){var e=Package.meteor.Meteor,n=Package.random.Random,t=Package.ejson.EJSON;Package.json.JSON;var r,o=Package.underscore._,i=Package.minimongo.LocalCollection,a=Package.livedata.DDP,u=Package.deps.Deps,s=Package.check.check,c=Package.check.Match;!function(){r=function(){var e=this;e.noConnCollections={}};var e=function(e,n){return e in n||(n[e]=new i(e)),n[e]};o.extend(r.prototype,{open:function(n,t){var r=this;return n?t?(t._mongo_livedata_collections||(t._mongo_livedata_collections={}),e(n,t._mongo_livedata_collections)):e(n,r.noConnCollections):new i}}),r=new r}.call(this),function(){e.Collection=function(t,a){var s=this;if(!(s instanceof e.Collection))throw new Error('use "new" to construct a Meteor.Collection');switch(a&&a.methods&&(a={connection:a}),a&&a.manager&&!a.connection&&(a.connection=a.manager),a=o.extend({connection:void 0,idGeneration:"STRING",transform:null,_driver:void 0,_preventAutopublish:!1},a),a.idGeneration){case"MONGO":s._makeNewID=function(){return new e.Collection.ObjectID};break;case"STRING":default:s._makeNewID=function(){return n.id()}}if(s._transform=a.transform?u._makeNonreactive(a.transform):null,t||null===t||e._debug("Warning: creating anonymous collection. It will not be saved or synchronized over the network. (Pass null for the collection name to turn off this warning.)"),s._connection=t&&null!==a.connection?a.connection?a.connection:e.isClient?e.connection:e.server:null,a._driver||(a._driver=t&&s._connection===e.server&&"undefined"!=typeof MongoInternals&&MongoInternals.defaultRemoteCollectionDriver?MongoInternals.defaultRemoteCollectionDriver():r),s._collection=a._driver.open(t,s._connection),s._name=t,s._connection&&s._connection.registerStore){var c=s._connection.registerStore(t,{beginUpdate:function(e,n){(e>1||n)&&s._collection.pauseObservers(),n&&s._collection.remove({})},update:function(e){var n=i._idParse(e.id),t=s._collection.findOne(n);if("replace"===e.msg){var r=e.replace;return r?t?s._collection.update(n,r):s._collection.insert(r):t&&s._collection.remove(n),void 0}if("added"===e.msg){if(t)throw new Error("Expected not to find a document already present for an add");s._collection.insert(o.extend({_id:n},e.fields))}else if("removed"===e.msg){if(!t)throw new Error("Expected to find a document already present for removed");s._collection.remove(n)}else{if("changed"!==e.msg)throw new Error("I don't know how to deal with this message");if(!t)throw new Error("Expected to find a document to change");if(!o.isEmpty(e.fields)){var a={};o.each(e.fields,function(e,n){void 0===e?(a.$unset||(a.$unset={}),a.$unset[n]=1):(a.$set||(a.$set={}),a.$set[n]=e)}),s._collection.update(n,a)}}},endUpdate:function(){s._collection.resumeObservers()},saveOriginals:function(){s._collection.saveOriginals()},retrieveOriginals:function(){return s._collection.retrieveOriginals()}});if(!c)throw new Error("There is already a collection named '"+t+"'")}s._defineMutationMethods(),Package.autopublish&&!a._preventAutopublish&&s._connection&&s._connection.publish&&s._connection.publish(null,function(){return s.find()},{is_auto:!0})},o.extend(e.Collection.prototype,{_getFindSelector:function(e){return 0==e.length?{}:e[0]},_getFindOptions:function(e){var n=this;return e.length<2?{transform:n._transform}:o.extend({transform:n._transform},e[1])},find:function(){var e=this,n=o.toArray(arguments);return e._collection.find(e._getFindSelector(n),e._getFindOptions(n))},findOne:function(){var e=this,n=o.toArray(arguments);return e._collection.findOne(e._getFindSelector(n),e._getFindOptions(n))}}),e.Collection._publishCursor=function(e,n,t){var r=e.observeChanges({added:function(e,r){n.added(t,e,r)},changed:function(e,r){n.changed(t,e,r)},removed:function(e){n.removed(t,e)}});n.onStop(function(){r.stop()})},e.Collection._rewriteSelector=function(t){if(i._selectorIsId(t)&&(t={_id:t}),!t||"_id"in t&&!t._id)return{_id:n.id()};var r={};return o.each(t,function(n,t){n instanceof RegExp?r[t]=l(n):n&&n.$regex instanceof RegExp?(r[t]=l(n.$regex),void 0!==n.$options&&(r[t].$options=n.$options)):r[t]=o.contains(["$or","$and","$nor"],t)?o.map(n,function(n){return e.Collection._rewriteSelector(n)}):n}),r};var l=function(e){s(e,RegExp);var n={$regex:e.source},t="";return e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),t&&(n.$options=t),n},f=function(n,t){if(!i._selectorIsIdPerhapsAsObject(n))throw new e.Error(403,"Not permitted. Untrusted code may only "+t+" documents by ID.")};o.each(["insert","update","remove"],function(n){e.Collection.prototype[n]=function(){var t,r,i=this,u=o.toArray(arguments);if(u.length&&u[u.length-1]instanceof Function&&(t=u.pop()),e.isClient&&!t&&(t=function(t){t&&e._debug(n+" failed: "+(t.reason||t.stack))}),"insert"===n){if(!u.length)throw new Error("insert requires an argument");if(u[0]=o.extend({},u[0]),"_id"in u[0]){if(r=u[0]._id,!("string"==typeof r||r instanceof e.Collection.ObjectID))throw new Error("Meteor requires document _id fields to be strings or ObjectIDs")}else r=u[0]._id=i._makeNewID()}else u[0]=e.Collection._rewriteSelector(u[0]);var s;if(t&&(s=function(e){t(e,!e&&r)}),i._connection&&i._connection!==e.server){var c=a._CurrentInvocation.get(),l=c&&c.isSimulation;l||"insert"===n||f(u[0],n),i._connection.apply(i._prefix+n,u,s)}else{u.push(s);try{i._collection[n].apply(i._collection,u)}catch(d){if(t)return t(d),null;throw d}}return r}}),e.Collection.prototype._ensureIndex=function(e,n){var t=this;if(!t._collection._ensureIndex)throw new Error("Can only call _ensureIndex on server collections");t._collection._ensureIndex(e,n)},e.Collection.prototype._dropIndex=function(e){var n=this;if(!n._collection._dropIndex)throw new Error("Can only call _dropIndex on server collections");n._collection._dropIndex(e)},e.Collection.prototype._createCappedCollection=function(e){var n=this;if(!n._collection._createCappedCollection)throw new Error("Can only call _createCappedCollection on server collections");n._collection._createCappedCollection(e)},e.Collection.ObjectID=i._ObjectID,function(){var n=function(e,n){var t=["insert","update","remove","fetch","transform"];o.each(o.keys(n),function(n){if(!o.contains(t,n))throw new Error(e+": Invalid key: "+n)});var r=this;if(r._restricted=!0,o.each(["insert","update","remove"],function(t){if(n[t]){if(!(n[t]instanceof Function))throw new Error(e+": Value for `"+t+"` must be a function");r._transform&&(n[t].transform=r._transform),n.transform&&(n[t].transform=u._makeNonreactive(n.transform)),r._validators[t][e].push(n[t])}}),n.update||n.remove||n.fetch){if(n.fetch&&!(n.fetch instanceof Array))throw new Error(e+": Value for `fetch` must be an array");r._updateFetch(n.fetch)}};e.Collection.prototype.allow=function(e){n.call(this,"allow",e)},e.Collection.prototype.deny=function(e){n.call(this,"deny",e)}}(),e.Collection.prototype._defineMutationMethods=function(){var n=this;if(n._restricted=!1,n._insecure=void 0,n._validators={insert:{allow:[],deny:[]},update:{allow:[],deny:[]},remove:{allow:[],deny:[]},fetch:[],fetchAllFields:!1},n._name&&(n._prefix="/"+n._name+"/",n._connection)){var t={};o.each(["insert","update","remove"],function(r){t[n._prefix+r]=function(){s(arguments,[c.Any]);try{if(this.isSimulation)return n._collection[r].apply(n._collection,o.toArray(arguments)),void 0;if("insert"!==r&&f(arguments[0],r),n._restricted){if(0===n._validators[r].allow.length)throw new e.Error(403,"Access denied. No allow validators set on restricted collection for method '"+r+"'.");var t="_validated"+r.charAt(0).toUpperCase()+r.slice(1),i=[this.userId].concat(o.toArray(arguments));n[t].apply(n,i)}else{if(!n._isInsecure())throw new e.Error(403,"Access denied");n._collection[r].apply(n._collection,o.toArray(arguments))}}catch(a){throw"MongoError"===a.name||"MinimongoError"===a.name?new e.Error(409,a.toString()):a}}}),(e.isClient||n._connection===e.server)&&n._connection.methods(t)}},e.Collection.prototype._updateFetch=function(e){var n=this;n._validators.fetchAllFields||(e?n._validators.fetch=o.union(n._validators.fetch,e):(n._validators.fetchAllFields=!0,n._validators.fetch=null))},e.Collection.prototype._isInsecure=function(){var e=this;return void 0===e._insecure?!!Package.insecure:e._insecure};var d=function(e,n){var r=n;return e.transform&&(r=e.transform(t.clone(n))),r};e.Collection.prototype._validatedInsert=function(n,t){var r=this;if(o.any(r._validators.insert.deny,function(e){return e(n,d(e,t))}))throw new e.Error(403,"Access denied");if(o.all(r._validators.insert.allow,function(e){return!e(n,d(e,t))}))throw new e.Error(403,"Access denied");r._collection.insert.call(r._collection,t)};var p=function(e,n){return e.transform?e.transform(n):n};e.Collection.prototype._validatedUpdate=function(n,t,r,a){var u=this;if(!i._selectorIsIdPerhapsAsObject(t))throw new Error("validated update should be of a single ID");var s=[];o.each(r,function(n,t){if("$"!==t.charAt(0))throw new e.Error(403,"Access denied. In a restricted collection you can only update documents, not replace them. Use a Mongo update operator, such as '$set'.");if(!o.has(h,t))throw new e.Error(403,"Access denied. Operator "+t+" not allowed in a restricted collection.");o.each(o.keys(n),function(e){-1!==e.indexOf(".")&&(e=e.substring(0,e.indexOf("."))),o.contains(s,e)||s.push(e)})});var c={transform:null};u._validators.fetchAllFields||(c.fields={},o.each(u._validators.fetch,function(e){c.fields[e]=1}));var l=u._collection.findOne(t,c);if(l){var f;if(o.any(u._validators.update.deny,function(e){return f||(f=p(e,l)),e(n,f,s,r)}))throw new e.Error(403,"Access denied");if(o.all(u._validators.update.allow,function(e){return f||(f=p(e,l)),!e(n,f,s,r)}))throw new e.Error(403,"Access denied");u._collection.update.call(u._collection,t,r,a)}};var h={$inc:1,$set:1,$unset:1,$addToSet:1,$pop:1,$pullAll:1,$pull:1,$pushAll:1,$push:1,$bit:1};e.Collection.prototype._validatedRemove=function(n,t){var r=this,i={transform:null};r._validators.fetchAllFields||(i.fields={},o.each(r._validators.fetch,function(e){i.fields[e]=1}));var a=r._collection.findOne(t,i);if(a){if(o.any(r._validators.remove.deny,function(e){return e(n,p(e,a))}))throw new e.Error(403,"Access denied");if(o.all(r._validators.remove.allow,function(e){return!e(n,p(e,a))}))throw new e.Error(403,"Access denied");r._collection.remove.call(r._collection,t)}}}.call(this),"undefined"==typeof Package&&(Package={}),Package["mongo-livedata"]={}}(),function(){Package.meteor.Meteor,"undefined"==typeof Package&&(Package={}),Package.startup={}}(),function(){Package.meteor.Meteor;var e,n=Package.underscore._;!function(){function t(e){return JSON.stringify(e)}function r(e,u){var s,c,l,f,d,p=i,h=u[e];switch(h&&"object"==typeof h&&"function"==typeof h.toJSON&&(h=h.toJSON(e)),"function"==typeof o&&(h=o.call(u,e,h)),typeof h){case"string":return t(h);case"number":return isFinite(h)?String(h):"null";case"boolean":case"null":return String(h);case"object":if(!h)return"null";if(i+=a,d=[],"[object Array]"===Object.prototype.toString.apply(h)){for(f=h.length,s=0;f>s;s+=1)d[s]=r(s,h)||"null";return l=0===d.length?"[]":i?"[\n"+i+d.join(",\n"+i)+"\n"+p+"]":"["+d.join(",")+"]",i=p,l}if(o&&"object"==typeof o)for(f=o.length,s=0;f>s;s+=1)"string"==typeof o[s]&&(c=o[s],l=r(c,h),l&&d.push(t(c)+(i?": ":":")+l));else n.each(n.keys(h).sort(),function(e){l=r(e,h),l&&d.push(t(e)+(i?": ":":")+l)});return l=0===d.length?"{}":i?"{\n"+i+d.join(",\n"+i)+"\n"+p+"}":"{"+d.join(",")+"}",i=p,l}}var o,i,a;e=function(e,n,t){var u;if(i="",a="","number"==typeof t)for(u=0;t>u;u+=1)a+=" ";else"string"==typeof t&&(a=t);if(o=n,n&&"function"!=typeof n&&("object"!=typeof n||"number"!=typeof n.length))throw new Error("stringify");return r("",{"":e})}}.call(this),"undefined"==typeof Package&&(Package={}),Package["canonical-stringify"]={stringify:e}}(),function(){Package.meteor.Meteor,"undefined"==typeof Package&&(Package={}),Package["browser-msg"]={}}(),function(){var e,n,t,r,o,i,a,u,s=Package.meteor.Meteor,c=Package.ejson.EJSON,l=Package.underscore._,f=Package.random.Random,d=Package["canonical-stringify"].stringify;!function(){u="object"==typeof u?u:{};var n,t,r,o,i;n=function(){function e(e,n){this.entry=e,this.parentContext=n}return e.prototype.add=function(n){return new e(n,this)},e.prototype.toArray=function(){var e,n,t;for(e=[],n=this;null!=n;)t=n.entry,null!=t&&e.push(t),n=n.parentContext;return e.reverse()},e}(),t=new s.EnvironmentVariable,r=function(){var e;return e=t.get(),null!=e?e.toArray():[]},i=function(e,r){var o;if("function"!=typeof r)throw new Error("withContext: fn arg is not a function: "+r);return o=new n(e,t.get()),t.withValue(o,r)},o=function(e){return t.withValue(null,e)},e={getContext:r,resetContext:o,withContext:i}}.call(this),function(){u="object"==typeof u?u:{};var t,r,o,i,a,l,f,d,p;f=function(e){var n;if(null===e)return"null";if("undefined"==typeof e)return"undefined";if("string"==typeof e)return e;try{return e.toString()}catch(t){return n=t,c.stringify(l(n))}},t=function(){function e(){}return e}(),l=function(e,n){var r,o,i,a,u,s;return null===e?i="null":"undefined"==typeof e?i="undefined":(i=null!==e.message&&"undefined"!=typeof e.message?f(e.message):f(e),null!==e.stack&&"undefined"!=typeof e.stack&&(a=f(e.stack)),e instanceof Error&&(r=null!=(s=e.constructor)?s.name:void 0,null!=r&&(u=f(r)))),o=new t,o.message=i,null!=u&&(o.type=u),null!=a&&(o.stack=a),null!=n&&(o.context=n),o},d=function(e){var n,t,r,o;if(null!=e.stack?s._debug(e.stack):s._debug(e.message),null!=e.context)for(o=e.context,t=0,r=o.length;r>t;t++)n=o[t],s._debug("-",n)},p=function(n){d(l(n,e.getContext()))},r=function(){function e(e){this.reason=e}return e}(),i=function(e,n){var t;try{return e()}catch(o){throw t=o,t instanceof r||p(t),new r(n)}},a=function(e){if("function"!=typeof e)throw new Error("not a function: "+e);return s.defer(function(){return i(e)})},o=function(e){return s.bindEnvironment(e,p,this)},n={bind:o,catcherr:i,defer:a,Failed:r,reportError:p}}.call(this),function(){u="object"==typeof u?u:{};var e=[].slice;t=function(){var t,r;return r=[],t=function(){var t,o,i,a;if(t=1<=arguments.length?e.call(arguments,0):[],null!=r)for(i=0,a=r.length;a>i;i++)o=r[i],n.catcherr(function(){return o.apply(null,t)})},t.listen=function(e){null!=r&&r.push(e)},t.dispose=function(){r=null},t}}.call(this),function(){u="object"==typeof u?u:{},r=function(){function e(){this._done=!1,this._failed=null,this._doneFanout=t()}return e.prototype.callback=function(e){var t=this;if("function"!=typeof e)throw new Error("Result.on: callback is not a function: "+e);return this._done?n.catcherr(function(){return e(t._failed,t._value,t)}):this._doneFanout.listen(n.bind(e)),this},e.prototype.onSuccess=function(e){var t=this;if("function"!=typeof e)throw new Error("Result.onSuccess: callback is not a function: "+e);return this.callback(function(r,o){r||n.catcherr(function(){return e(o,t)})}),this},e.prototype.onFailure=function(e){var t=this;if("function"!=typeof e)throw new Error("Result.onFail: callback is not a function: "+e);return this.callback(function(r){r&&n.catcherr(function(){return e(r,t)})}),this},e.prototype._broadcast=function(){this._doneFanout(this._failed,this._value,this),this._doneFanout.dispose()},e.prototype.complete=function(n){return this._done?this:n instanceof e?(this.from(n),void 0):(this._done=!0,this._value=n,this._broadcast(),this)},e.prototype.fail=function(e){return this._done?this:(this._done=!0,this._failed=null!=e?e:!0,this._broadcast(),this)},e.prototype.into=function(e){return this.callback(function(n,t){return n?e.fail():e.complete(t)}),this},e.prototype.from=function(e){return e.into(this),this},e.prototype._run=function(t,r){var o,i;try{i=t(r)}catch(a){return o=a,n.reportError(o),this.fail(),void 0}i instanceof e?this.from(i):this.complete(i)},e.prototype.then=function(n,t){var r;if(null!=n&&"function"!=typeof n)throw new Error("Result.then: successFn is not a function: "+n);if(null!=t&&"function"!=typeof t)throw new Error("Result.then: failureFn is not a function: "+t);return r=new e,this.callback(function(e,o){null!=e?null!=t?r._run(t,e):r.fail():null!=n?r._run(n,o):r.complete(o)}),r},e.prototype.always=function(e){var n;return n=function(){e()},this.then(n,n)},e.value=function(n){var t;return t=new e,t.complete(n),t},e.completed=function(n){return e.value(n)},e.failed=function(n){var t;return t=new e,t.fail(n),t},e.delay=function(n,t){var r;return r=new e,s.setTimeout(function(){return r.complete(t)},n),r},e.defer=function(t){var r;return r=new e,n.defer(function(){return r.complete(t)}),r},e.join=function(n){var t,r,o,i,a,u,s,c,l;if(0===n.length)return e.completed([]);for(t=new e,u=n.length,o=0,i=[],s=function(e,n){return e.callback(function(e,r){return e?t.fail(e):(i[n]=r,++o,o===u?t.complete(i):void 0)})},r=c=0,l=n.length;l>c;r=++c)a=n[r],s(a,r);return t},e.map=function(n,t){var r,o,i,a,u;for(i=[],a=0,u=n.length;u>a;a++)r=n[a],o=new e,o._run(t,r),i.push(o);return e.join(i)},e.sequence=function(n,t){var r,o,i;return r=new e,o=0,i=function(n){var a;a=new e,a._run(t[o],n),a.callback(function(e,n){return null!=e?(r.fail(e),void 0):(++o,o===t.length?r.complete(n):i(n),void 0)})},e.value(n).callback(function(e,n){return null!=e?(r.fail(e),void 0):(i(n),void 0)}),r},e.prototype.timeout=function(n){var t,r;return r=new e,t=e.delay(n),t.onSuccess(function(){return r.fail("timeout")}),this.into(r),r},e.prototype.debug=function(e){return null==e&&(e="result"),this.callback(function(n,t){null!=n?s._debug(e,"FAILED",n):s._debug(e,"completed",t)}),this},e}()}.call(this),function(){u="object"==typeof u?u:{};var e,n,t;o={},o.isWebWorker=s.isClient&&("undefined"==typeof window||null===window)&&("undefined"==typeof document||null===document)&&"undefined"!=typeof importScripts&&null!==importScripts,o.isWebWorker?o.supported=!0:s.isClient?o.supported="undefined"!=typeof openDatabase&&null!==openDatabase&&(!(null!=(e=s.settings)?null!=(n=e["public"])?null!=(t=n.offlineData)?t.disableWorker:void 0:void 0:void 0)&&"undefined"!=typeof SharedWorker&&null!==SharedWorker||("undefined"!=typeof BrowserMsg&&null!==BrowserMsg?BrowserMsg.supported:void 0)):s.isServer&&(o.supported=!0)}.call(this),function(){u="object"==typeof u?u:{};var r,a,c,l=[].slice;o.isWebWorker||(c={},a=function(e){return c[e]||(c[e]=new t)},r=function(n,t){e.withContext("received broadcast msg "+n,function(){a(n).apply(null,t)})},s.startup(function(){o._usingSharedWebWorker||BrowserMsg.listen({"/awwx/offline-data/broadcast":function(e,n){r(e,n)}})}),i=function(){var e,n;n=arguments[0],e=2<=arguments.length?l.call(arguments,1):[],BrowserMsg.send("/awwx/offline-data/broadcast",n,e)},i.includingSelf=function(){var e,t;t=arguments[0],e=2<=arguments.length?l.call(arguments,1):[],BrowserMsg.send("/awwx/offline-data/broadcast",t,e),n.defer(function(){return a(t).apply(null,e)})},i.listen=function(e,n){a(e).listen(n)})}.call(this),function(){u="object"==typeof u?u:{},a=function(e,n){var t,r,o;for(r=0,o=e.length;o>r;r++)if(t=e[r],c.equals(t,n))return!0;return!1}}.call(this),function(){u="object"==typeof u?u:{};var t,i,f,p,h,v,_,m,g,y,b=[].slice;o.supported&&(t="awwx/offline-data",i="8",v=this,g=function(e){var n,t,r,o,i;for(n=[],r=e.rows,t=o=0,i=r.length;i>=0?i>o:o>i;t=i>=0?++o:--o)n.push(r.item(t));return n},m=function(e){return l.map(e,function(){return"?"}).join(",")},_=function(){return(new Date).getTime()},p=function(){var e,n,t;for(t=arguments[0],n=2<=arguments.length?b.call(arguments,1):[];n.length>0;)e=n.shift(),function(e){return t=t.then(function(){var n;return n=1<=arguments.length?b.call(arguments,0):[],e.apply(null,n)})}(e);return t},h=function(){var n,t;return n=arguments[0],t=2<=arguments.length?b.call(arguments,1):[],e.withContext(n,function(){return p.apply(null,[r.completed()].concat(b.call(t)))})},f=function(){function o(){this.databaseOpen=new r}return o.prototype.implementation="SQL",o.prototype.processTransaction=function(t,o){var i,a,u;if(!l.isFunction(t))throw new Error("fn should be a function");return u=new r,i=new r,o(n.bind(function(n){e.withContext("SQL transaction",function(){return t(n)}).into(i)}),function(e){n.reportError(e),u.fail()},function(){u.complete()}),a=new r,r.join([i,u]).onSuccess(function(e){var n,t;return n=e[0],t=e[1],a.complete(n)}).onFailure(function(){return a.fail()}),a},o.prototype._transaction=function(e){var n=this;return this.processTransaction(e,function(e,t,r){return n.sqldb.transaction(e,t,r)})},o.prototype.transaction=function(e){var n=this;return this.databaseOpen.then(function(){return n._transaction(e)})},o.prototype.changeVersion=function(e,n){var t=this;return this.processTransaction(n,function(n,r,o){return t.sqldb.changeVersion(t.sqldb.version,e,n,r,o)})},o.prototype.openDatabase=function(n){var r=this;return null==n&&(n={}),e.withContext("open SQL database",function(){r.sqldb=v.openDatabase(t,"","",1048576)})},o.prototype.sql=function(t,o,i){return e.withContext("execute SQL statement: "+o,function(){var e;return e=new r,t.executeSql(o,i,n.bind(function(n,t){e.complete(g(t))}),n.bind(function(t,r){n.reportError(r),e.fail()})),e})},o.prototype.listTables=function(e){var n=this;return h("listTables",function(){return n.sql(e,'SELECT * FROM sqlite_master\n WHERE type="table" AND\n name NOT LIKE "!_%" ESCAPE "!" AND\n name NOT LIKE "sqlite!_%" ESCAPE "!"')},function(e){var n;return function(){var t,r,o;for(o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(n.name);return o}().sort()})},o.prototype.dropTable=function(e,n){var t=this;return h("dropTable "+n,function(){return t.sql(e,"DROP TABLE "+n)})},o.prototype.dropAllTables=function(e){var n=this;return h("dropAllTables",function(){return n.listTables(e)},function(t){var o;return r.join(function(){var n,r,i;for(i=[],n=0,r=t.length;r>n;n++)o=t[n],i.push(this.dropTable(e,o));return i}.call(n))},function(){})},o.prototype.eraseDatabase=function(){var e=this;return h("eraseDatabase",function(){return e.openDatabase(),e.changeVersion("",function(n){return e.dropAllTables(n)})})},o.prototype.createTables=function(e){var n=this;return h("createTables",function(){return r.join([n.sql(e,"CREATE TABLE windows (\n windowId TEXT PRIMARY KEY NOT NULL,\n updateId INTEGER NOT NULL\n)"),n.sql(e,"CREATE TABLE agentWindow (\n singleton INTEGER PRIMARY KEY NOT NULL,\n windowId TEXT NOT NULL\n)"),n.sql(e,"CREATE TABLE docs (\n connection TEXT NOT NULL,\n collectionName TEXT NOT NULL,\n docId TEXT NOT NULL,\n doc TEXT NOT NULL,\n PRIMARY KEY (connection, collectionName, docId)\n)"),n.sql(e,"CREATE TABLE stubDocs (\n connection TEXT NOT NULL,\n methodId TEXT NOT NULL,\n collectionName TEXT NOT NULL,\n docId TEXT NOT NULL,\n PRIMARY KEY (connection, methodId, collectionName, docId)\n)"),n.sql(e,"CREATE TABLE queuedMethods (\n connection TEXT NOT NULL,\n methodId TEXT NOT NULL,\n method TEXT NOT NULL,\n PRIMARY KEY (connection, methodId)\n)"),n.sql(e,"CREATE TABLE windowSubscriptions (\n windowId TEXT NOT NULL,\n connection TEXT NOT NULL,\n subscription TEXT NOT NULL,\n PRIMARY KEY (windowId, connection, subscription)\n)"),n.sql(e,"CREATE TABLE subscriptions (\n connection TEXT NOT NULL,\n subscription TEXT NOT NULL,\n serverReady INTEGER NOT NULL,\n status TEXT NOT NULL,\n error TEXT NOT NULL,\n loaded INTEGER NOT NULL,\n PRIMARY KEY (connection, subscription)\n)"),n.sql(e,"CREATE TABLE methodsHoldingUpSubscriptions (\n connection TEXT NOT NULL,\n subscription TEXT NOT NULL,\n methodId TEXT NOT NULL,\n PRIMARY KEY (connection, subscription, methodId)\n)"),n.sql(e,"CREATE TABLE updates (\n id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n theUpdate TEXT NOT NULL\n)")])})},o.prototype.initializeNewDatabase=function(){var e=this;return h("initializeNewDatabase",function(){return e.changeVersion(i,function(n){return e.createTables(n)})})},o.prototype.resetDatabase=function(){var e=this;return h("resetDatabase",function(){return e.eraseDatabase()},function(){return e.initializeNewDatabase()})},o.prototype.upgradeDatabaseIfNeeded=function(){var e=this;return h("upgradeDatabaseIfNeeded",function(){return e.sqldb.version===i?r.completed():e.resetDatabase()})},o.prototype.open=function(){var e=this;return h("open",function(){return e.openDatabase(),e.upgradeDatabaseIfNeeded().into(e.databaseOpen),e.databaseOpen})},o.prototype.ensureWindow=function(e,n){var t=this;return h("ensureWindow",function(){return t.highestUpdateId(e)},function(r){return t.sql(e,"INSERT OR IGNORE INTO windows (windowId, updateId)\n VALUES (?, ?)",[n,r])})},o.prototype.readAllWindowIds=function(e){var n=this;return h("readKnownWindowIds",function(){return n.sql(e,"SELECT windowId FROM windows UNION\nSELECT windowId FROM windowSubscriptions UNION\nSELECT windowId FROM agentWindow")},function(e){var n,t,r,o;for(o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(n.windowId);return o})},o.prototype.deleteWindows=function(e,n){var t=this;return h("deleteWindows",function(){return t.sql(e,"DELETE FROM windows\n WHERE windowId IN ("+m(n)+")",n)},function(){return t.sql(e,"DELETE FROM windowSubscriptions\n WHERE windowId IN ("+m(n)+")",n)},function(){return t.sql(e,"DELETE FROM agentWindow\n WHERE windowId IN ("+m(n)+")",n)})},o.prototype.readAgentWindow=function(e){var t=this;return h("readAgentWindow",function(){return t.sql(e,"SELECT windowId FROM agentWindow")},function(e){return 0===e.length?null:1===e.length?e[0].windowId:(n.reportError("agentWindow table does not contain a singleton row"),r.failed())})},o.prototype.writeAgentWindow=function(e,n){var t=this;return h("writeAgentWindow",function(){return t.sql(e,"INSERT OR REPLACE INTO agentWindow\n (singleton, windowId) VALUES (0, ?)",[n])})},o.prototype.writeDoc=function(e,n,t,r){var o=this;return h("writeDoc",function(){return o.sql(e,"INSERT OR REPLACE INTO docs\n (connection, collectionName, docId, doc)\n VALUES (?, ?, ?, ?)",[n,t,r._id,c.stringify(r)])})},o.prototype.readDocs=function(e,n){var t=this;return h("readDocs",function(){return t.sql(e,"SELECT collectionName, doc FROM docs WHERE connection=?",[n])},function(e){var n,t,r,o,i;for(t={},o=0,i=e.length;i>o;o++)r=e[o],n=c.parse(r.doc),s._ensure(t,r.collectionName)[n._id]=n;return t})},o.prototype.readDocIdsOfCollection=function(e,n,t){var r=this;return h("readDocIdsOfCollection",function(){return r.sql(e,"SELECT docId FROM docs\n WHERE connection = ? AND\n collectionName = ?",[n,t])},function(e){return l.map(e,function(e){return e.docId})})},o.prototype.deleteDoc=function(e,n,t,r){var o=this;return h("deleteDoc",function(){return o.sql(e,"DELETE FROM docs\n WHERE connection=? AND\n collectionName=? AND\n docID=?",[n,t,r])})},o.prototype.addDocumentWrittenByStub=function(e,n,t,r,o){var i=this;return h("addDocumentWrittenByStub",function(){return i.sql(e,"INSERT INTO stubDocs\n (connection, methodId, collectionName, docId)\n VALUES (?, ?, ?, ?)",[n,t,r,o])})},o.prototype.isDocumentWrittenByAnyStub=function(e,n,t,r){var o=this;return h("isDocumentWrittenByAnyStub",function(){return o.sql(e,"SELECT 1 FROM stubDocs\n WHERE connection=? AND\n collectionName=? AND\n docID=?\n LIMIT 1",[n,t,r])},function(e){return e.length>0})},o.prototype.readDocsWrittenByStub=function(e,n,t){var r=this;return h("readDocsWrittenByStub",function(){return r.sql(e,"SELECT collectionName, docId FROM stubDocs\n WHERE connection=? AND\n methodId=?",[n,t])})},o.prototype.removeDocumentsWrittenByStub=function(e,n,t){var r=this;return h("removeDocumentsWrittenByStub",function(){return r.sql(e,"DELETE FROM stubDocs\n WHERE connection=? AND\n methodId=?",[n,t])})},o.prototype.readMethodsWithDocsWritten=function(e,n){var t=this;return h("readMethodsWithDocsWritten",function(){return t.sql(e,"SELECT DISTINCT methodId FROM stubDocs\n WHERE connection=?\n ORDER BY methodId",[n])},function(e){var n;return function(){var t,r,o;for(o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(n.methodId);return o}()})},o.prototype.addQueuedMethod=function(e,n,t,r,o){var i=this;return h("addQueuedMethod",function(){var a;return a=d({name:r,args:o}),i.sql(e,"INSERT INTO queuedMethods\n (connection, methodId, method)\n VALUES (?, ?, ?)",[n,t,a])})},o.prototype.readQueuedMethods=function(e){var n=this;return h("readQueuedMethods",function(){return n.sql(e,"SELECT connection, methodId, method FROM queuedMethods")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.method),t=u.name,n=u.args,r.push({connection:o.connection,methodId:o.methodId,name:t,args:n});return r})},o.prototype.removeQueuedMethod=function(e,n,t){var r=this;return h("removedQueuedMethod",function(){return r.sql(e,"DELETE FROM queuedMethods\n WHERE connection=? AND\n methodId=?",[n,t])})},o.prototype.addWindowSubscription=function(e,n,t,r,o){var i=this;return h("addWindowSubscription",function(){var a;return a=d({name:r,args:o}),i.sql(e,"INSERT OR IGNORE INTO windowSubscriptions\n (windowId, connection, subscription)\n VALUES (?, ?, ?)",[n,t,a])})},o.prototype.setWindowSubscriptions=function(e,n,t,o){var i=this;return h("setWindowSubscriptions",function(){return i.sql(e,"DELETE FROM windowSubscriptions\n WHERE windowId = ? AND connection = ?",[n,t])},function(){return r.map(o,function(r){var o;return o=d({name:r[0],args:r.slice(1)}),i.sql(e,"INSERT INTO windowSubscriptions\n (windowId, connection, subscription)\n VALUES (?, ?, ?)",[n,t,o])})})},o.prototype._testReadWindowSubscriptions=function(e){var n=this;return h("_testReadWindowSubscriptions",function(){return n.sql(e,"SELECT windowId, connection, subscription\n FROM windowSubscriptions\n ORDER BY windowId, connection, subscription")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({windowId:o.windowId,connection:o.connection,name:t,args:n});return r})},o.prototype.readMergedSubscriptions=function(e){var n=this;return h("readMergedSubscriptions",function(){return n.sql(e,"SELECT DISTINCT connection, subscription\n FROM windowSubscriptions\n ORDER BY connection, subscription")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({connection:o.connection,name:t,args:n});
return r})},o.prototype.removeWindowSubscription=function(e,n,t,r,o){var i=this;return h("removeWindowSubscription",function(){var a;return a=d({name:r,args:o}),i.sql(e,"DELETE FROM windowSubscriptions\n WHERE windowId=? AND\n connection=? AND\n subscription=?",[n,t,a])})},o.prototype.ensureSubscription=function(e,n,t,r){var o=this;return h("ensureSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"INSERT OR IGNORE INTO subscriptions\n (connection, subscription, serverReady, loaded, status, error)\n VALUES (?, ?, 0, 0, 'subscribing', '')",[n,i])})},o.prototype.initializeSubscriptions=function(e){var n=this;return h("initializeSubscriptions",function(){return n.sql(e,"UPDATE subscriptions\n SET serverReady = 0,\n status = 'unsubscribed',\n error = ''")})},o.prototype.removeSubscription=function(e,n,t,r){var o=this;return h("removeSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"DELETE FROM subscriptions\n WHERE connection = ? AND\n subscription = ?",[n,i])})},o.prototype.cleanSubscriptions=function(e){var n=this;return h("cleanSubscriptions",function(){return r.join([n.readMergedSubscriptions(e),n.readSubscriptions(e)])},function(t){var o,i,u,s,c,l,f,d,p,h,v,_,m;for(u=t[0],c=t[1],l=[],d=0,h=c.length;h>d;d++)_=c[d],i=_.connection,s=_.name,o=_.args,a(u,{connection:i,name:s,args:o})||l.push({connection:i,name:s,args:o});for(f=[],p=0,v=l.length;v>p;p++)m=l[p],i=m.connection,s=m.name,o=m.args,f.push(n.removeSubscription(e,i,s,o));return r.join(f).then(function(){return l})})},o.prototype._loadSubscription=function(e){var n,t,r,o;return o=c.parse(e.subscription),t=o.name,n=o.args,r={connection:e.connection,name:t,args:n,serverReady:1===e.serverReady,status:e.status,loaded:1===e.loaded},""!==e.error&&(r.error=c.parse(e.error)),r},o.prototype.readSubscription=function(e,n,t,r){var o=this;return h("readSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"SELECT connection, subscription, serverReady, status,\n error, loaded\n FROM subscriptions\n WHERE connection=? AND subscription=?",[n,i])},function(e){return 0===e.length?null:o._loadSubscription(e[0])})},o.prototype.readSubscriptions=function(e){var n=this;return h("readSubscriptions",function(){return n.sql(e,"SELECT connection, subscription, serverReady, status,\n error, loaded\n FROM subscriptions\n ORDER BY connection, subscription")},function(e){return l.map(e,n._loadSubscription)})},o.prototype.haveSubscription=function(e,n,t,r){var o=this;return h("haveSubscription",function(){var i;return i=d({name:t,args:r}),o.sql(e,"SELECT 1 FROM subscriptions\n WHERE connection=? AND\n subscription=?",[n,i])},function(e){return e.length>0})},o.prototype.setSubscriptionServerReady=function(e,n,t,r){var o=this;return h("setSubscriptionServerReady",function(){var i;return i=d({name:t,args:r}),o.sql(e,"UPDATE subscriptions SET serverReady = 1\n WHERE connection=? AND\n subscription=?",[n,i])})},o.prototype.setSubscriptionStatus=function(e,n,t,r,o){var i=this;return h("setSubscriptionStatus",function(){var a;return a=d({name:t,args:r}),i.sql(e,"UPDATE subscriptions SET status=?\n WHERE connection=? AND\n subscription=?",[o,n,a])})},o.prototype.setSubscriptionReady=function(e,n,t,r){var o=this;return h("setSubscriptionReady",function(){var i;return i=d({name:t,args:r}),o.sql(e,"UPDATE subscriptions SET status = 'ready', loaded = 1\n WHERE connection = ? AND subscription = ?",[n,i])})},o.prototype.setSubscriptionError=function(e,n,t,r,o){var i=this;return h("setSubscriptionError",function(){var a;return a=d({name:t,args:r}),i.sql(e,"UPDATE subscriptions\n SET serverReady = 0, status = 'error', error = ?, loaded = 0\n WHERE connection = ? AND\n subscription = ?",[c.stringify(o),n,a])})},o.prototype.setSubscriptionLoaded=function(e,n,t,r){var o=this;return h("setSubscriptionLoaded",function(){var i;return i=d({name:t,args:r}),o.sql(e,"UPDATE subscriptions SET loaded = 1\n WHERE connection=? AND\n subscription=?",[n,i])})},o.prototype._testReadMethodsHoldingUpSubscriptions=function(e){var n=this;return h("_testReadMethodsHoldingUpSubscriptions",function(){return n.sql(e,"SELECT connection, subscription, methodId\n FROM methodsHoldingUpSubscriptions\n ORDER BY connection, subscription, methodId")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({connection:o.connection,name:t,args:n,methodId:o.methodId});return r})},o.prototype.readSubscriptionsHeldUp=function(e){var n=this;return h("readSubscriptionsHeldUp",function(){return n.sql(e,"SELECT DISTINCT connection, subscription\n FROM methodsHoldingUpSubscriptions\n ORDER BY connection, subscription")},function(e){var n,t,r,o,i,a,u;for(r=[],i=0,a=e.length;a>i;i++)o=e[i],u=c.parse(o.subscription),t=u.name,n=u.args,r.push({connection:o.connection,name:t,args:n});return r})},o.prototype.addSubscriptionWaitingOnMethods=function(e,n,t,o,i){var a=this;return h("addSubscriptionWaitingOnMethods",function(){var u,s,c,l,f,p;for(s=d({name:t,args:o}),c=[],l=function(t){return c.push(a.sql(e,"INSERT OR IGNORE INTO methodsHoldingUpSubscriptions\n (connection, subscription, methodId)\n VALUES (?, ?, ?)",[n,s,t]))},f=0,p=i.length;p>f;f++)u=i[f],l(u);return r.join(c)})},o.prototype.removeMethodHoldingUpSubscriptions=function(e,n){var t=this;return h("removeMethodHoldingUpSubscriptions",function(){return t.sql(e,"DELETE FROM methodsHoldingUpSubscriptions\n WHERE methodId=?",[n])})},o.prototype.addUpdate=function(e,n){var t=this;return h("addUpdate",function(){var r;return r=c.stringify(n),t.sql(e,"INSERT INTO updates (theUpdate) VALUES (?)",[r])})},o.prototype._loadUpdates=function(e){var n,t,r,o;for(n=[],r=0,o=e.length;o>r;r++)t=e[r],n.push({id:t.id,update:c.parse(t.theUpdate)});return n},o.prototype._testReadUpdates=function(e){var n=this;return h("_testReadUpdates",function(){return n.sql(e,"SELECT id, theUpdate FROM updates ORDER BY id")},function(e){return n._loadUpdates(e)})},o.prototype.highestUpdateId=function(e){var n=this;return h("highestUpdateId",function(){return n.sql(e,"SELECT MAX(id) AS id FROM updates")},function(e){var n;return null!=(n=e[0].id)?n:0})},o.prototype.writeWindowUpdateIndex=function(e,n,t){var r=this;return h("writeWindowUpdateIndex",function(){return r.sql(e,"UPDATE windows SET updateId = ?\n WHERE windowId = ?",[t,n])})},o.prototype.initializeWindowUpdateIndex=function(e,n){var t=this;return h("initializeWindowUpdateIndex",function(){return t.highestUpdateId(e)},function(r){return t.writeWindowUpdateIndex(e,n,r)})},o.prototype._testReadWindows=function(e){var n=this;return h("_testReadWindows",function(){return n.sql(e,"SELECT windowId, updateId FROM windows\n ORDER BY windowId")})},o.prototype.removeUpdatesProcessedByAllWindows=function(e){var n=this;return h("removeUpdatesProcessedByAllWindows",function(){return n.sql(e,"SELECT MIN(updateId) AS minUpdateId FROM windows")},function(t){var r,o,i;return r=null!=(o=null!=(i=t[0])?i.minUpdateId:void 0)?o:0,n.sql(e,"DELETE FROM updates WHERE id <= ?",[r])})},o.prototype.pullUpdatesForWindow=function(e,n){var t,r=this;return t=null,h("pullUpdatesForWindow",function(){return r.sql(e,"SELECT updateId FROM windows WHERE windowId=?",[n])},function(n){var t,o,i;return t=null!=(o=null!=(i=n[0])?i.updateId:void 0)?o:0,r.sql(e,"SELECT theUpdate FROM updates WHERE id > ?",[t])},function(o){var i;return t=function(){var e,n,t,r;for(t=this._loadUpdates(o),r=[],e=0,n=t.length;n>e;e++)i=t[e],r.push(i.update);return r}.call(r),r.initializeWindowUpdateIndex(e,n)},function(){return t})},o}(),y=new f,o._SQLStore=f,o._database=y,o._databaseName=t,o._databaseVersion=i,o.resetDatabase=function(){return y.resetDatabase()},s.startup(function(){!o._disableStartupForTesting&&o.supported&&y.open()}))}.call(this),function(){u="object"==typeof u?u:{};var a,c,d,p,h,v,_,m,g,y,b,w,E,k,S;o.supported&&(v=o._database,o._windows={},o._windows.windowsAreDead=S=new t,g=function(){return+new Date},o.isWebWorker?(_=function(e){var n,t,r;for(t=0,r=e.length;r>t;t++)n=e[t],WebWorker.windowIsDead(n);S(e)},p=!1,m=null,w={},WebWorker.addMessageHandler("goodbye",function(e,n){_([n.windowId])}),WebWorker.addMessageHandler("pong",function(e,n){null!=w&&delete w[n.windowId]}),d=function(){return _(l.keys(w)),p=!1,w=null},c=function(){return e.withContext("window check",function(){p||null!=m&&g()-m<9e3||(p=!0,v.transaction(function(e){return v.readAllWindowIds(e)}).then(function(e){var n,t,r,o,i,a,u,c,l,f;for(w={},l=WebWorker.windowIds,r=0,a=l.length;a>r;r++)t=l[r],w[t]=!0;for(o=0,u=e.length;u>o;o++)t=e[o],w[t]=!0;for(m=g(),f=WebWorker.ports,i=0,c=f.length;c>i;i++)n=f[i],n.postMessage({msg:"ping"});s.setTimeout(d,4e3)}))})},s.startup(function(){return c(),s.setInterval(c,1e4)})):(o._windows.thisWindowId=E=f.id(),o._windows.nowAgent=y=new t,w=null,m=null,p=!1,_=function(n){return e.withContext("deadWindows",function(){return v.transaction(function(e){return v.readAgentWindow(e).then(function(t){return null==t||l.contains(n,t)?a(e):r.completed()})}).then(function(){return S(n)})})},h=!1,o._windows.currentlyTheAgent=function(){return h},a=function(t){return e.withContext("becomeTheAgentWindow",function(){return h=!0,n.defer(function(){return y()}),v.writeAgentWindow(t,E)})},b=function(){return e.withContext("startupCheck",function(){return v.transaction(function(e){return v.readAgentWindow(e).then(function(n){var t;return null==n?a(e):(t=localStorage.getItem("/awwx/offline-data/agentWindowClosed"),t===n?a(e):void 0)}).then(function(){localStorage.removeItem("/awwx/offline-data/agentWindowClosed")})})})},c=function(){return e.withContext("window check",function(){return p?void 0:(p=!0,v.transaction(function(e){return v.readAllWindowIds(e)}).then(function(e){var n,t,o;if(!(null!=m&&g()-m<9e3)){for(w={},t=0,o=e.length;o>t;t++)n=e[t],n!==E&&(w[n]=!0);return i("ping"),r.delay(4e3).then(function(){return e})}}).then(function(){return _(l.keys(w))}).then(function(){return p=!1}))})},s.startup(function(){return e.withContext("windows startup",function(){return o._disableStartupForTesting?void 0:o._usingSharedWebWorker?v.transaction(function(e){return v.ensureWindow(e,E)}):(i.listen("ping",function(){return e.withContext("listen ping",function(){i("pong",E)})}),i.listen("pong",function(n){return e.withContext("listen pong",function(){null!=w&&delete w[n]})}),i.listen("goodbye",function(e){return _([e])}),v.transaction(function(e){return v.ensureWindow(e,E)}).then(function(){return b()}).then(function(){return c(),s.setInterval(c,1e4)}),void 0)})}),k=function(){return e.withContext("unload",function(){o._usingSharedWebWorker?o._sharedWebWorker.post({msg:"goodbye",windowId:E}):(h&&localStorage.setItem("/awwx/offline-data/agentWindowClosed",E),i("goodbye",E))})},null!=window.addEventListener&&window.addEventListener("unload",k,!1)))}.call(this),function(){u="object"==typeof u?u:{},o._subscriptionStatus=function(e){var n;return n={status:e.status,loaded:e.loaded},null!=e.error&&(n.error=e.error),n}}.call(this),function(){u="object"==typeof u?u:{};var t,f,p,h,v,_,m,g,y,b,w,E,k,S,O,T,I,C,R,N,A,D,M,x,j,U,P=[].slice;o.supported&&(w=o._database,o._test||(o._test={}),o.isWebWorker||(U=o._windows,I=U.nowAgent,A=U.thisWindowId),x=o._windows.windowsAreDead,o._messageAgent=function(){var e,t;if(t=arguments[0],e=2<=arguments.length?P.call(arguments,1):[],o.isWebWorker)throw new Error("oops, messaging agent from agent");o._usingSharedWebWorker?o._sharedWebWorker.post({msg:t,args:e}):o._windows.currentlyTheAgent()?n.defer(function(){return"function"==typeof E[t]?E[t].apply(E,e):void 0}):i.apply(null,[t].concat(P.call(e)))},o.isWebWorker?(WebWorker.addMessageHandler("update",function(e){var n,t,r,o;for(o=WebWorker.ports,t=0,r=o.length;r>t;t++)n=o[t],n!==e&&n.postMessage({msg:"update"})}),p=function(e,n){return WebWorker.addMessageHandler(e,function(){n()})},g=function(){var e,n,t,r;for(r=WebWorker.ports,n=0,t=r.length;t>n;n++)e=r[n],e.postMessage({msg:"update"})}):(E={},p=function(e,n){E[e]=n,i.listen(e,n)},g=function(){i.includingSelf("update")}),h=function(e,n,t){return null!=n&&(n.madeUpdate=!0),w.addUpdate(e,t)},_=function(e,n,t){return h(e,n,{update:"subscriptionStatus",subscription:{connection:t.connection,name:t.name,args:t.args},status:o._subscriptionStatus(t)})},m=function(e,n,t,r,o){return w.readSubscription(e,t,r,o).then(function(t){return _(e,n,t)})},D=function(n,t){return e.withContext("updateSubscriptionsReady",function(){return r.join([w.readSubscriptions(n),w.readSubscriptionsHeldUp(n)]).then(function(e){var o,i,u,s,c,l,f,d,p,h,v;for(f=e[0],d=e[1],s=[],p=0,h=f.length;h>p;p++)v=f[p],i=v.connection,u=v.name,o=v.args,c=v.serverReady,l=v.status,c&&"subscribing"===l&&!a(d,{connection:i,name:u,args:o})&&s.push({connection:i,name:u,args:o});return r.map(s,function(e){var r,o,i;return o=e.connection,i=e.name,r=e.args,w.setSubscriptionReady(n,o,i,r).then(function(){return m(n,t,o,i,r)})})})})},o._test.updateSubscriptionsReady=D,O=function(e){return{name:e.name,args:e.args}},v=o.isWebWorker?function(e){return w.transaction(e)}:function(e){return w.transaction(function(n){return w.readAgentWindow(n).then(function(t){return t===A?e(n):r.failed()})})},this.connectionAgents={},f=function(){function e(e,n){if(this.connectionName=e,this.meteorConnection=n,null!=connectionAgents[this.connectionName])throw new Error("a ConnectionAgent has already been constructed for this connection name: "+this.connectionName);connectionAgents[this.connectionName]=this,this.methodHandlers={},this.collectionAgents={},this.methodsSent={},this.meteorSubscriptionHandles={},this._nMeteorSubscriptionsReady=0,this._deletedRemovedDocs=!1}return e.prototype.deleteRemovedDocuments=function(e){return this._deletedRemovedDocs?r.completed():(this._deletedRemovedDocs=!0,this._eachCollectionAgent(function(n){return n.deleteDocumentsGoneFromServer(e)}))},e.prototype.checkIfReadyToDeleteDocs=function(e){return this.allMeteorSubscriptionsReady()?this.deleteRemovedDocuments(e):void 0},e.prototype._alreadyHaveMeteorSubscription=function(e){return!!this.meteorSubscriptionHandles[d(e)]},e.prototype.allMeteorSubscriptionsReady=function(){return this._nMeteorSubscriptionsReady===l.size(this.meteorSubscriptionHandles)},e.prototype._eachCollectionAgent=function(e){var n,t,o,i;o=[],i=this.collectionAgents;for(t in i)n=i[t],o.push(e(n));return r.join(o)},e.prototype.instantiateCollectionAgent=function(e){var n;(n=this.collectionAgents)[e]||(n[e]=new t(this,e,new s.Collection(e)))},e.prototype.instantiateCollectionAgents=function(e){var n,t,r;for(t=0,r=e.length;r>t;t++)n=e[t],this.instantiateCollectionAgent(n)},e.prototype.meteorSubscriptionReady=function(e){var n=this;return this.instantiateCollectionAgents(l.keys(this.meteorConnection._updatesForUnknownStores)),v(function(t){return w.setSubscriptionServerReady(t,n.connectionName,e.name,e.args).then(function(){return m(t,null,n.connectionName,e.name,e.args)}).then(function(){return D(t,null)}).then(function(){return++n._nMeteorSubscriptionsReady,n.checkIfReadyToDeleteDocs(t)}).then(function(){return g()})})},e.prototype.currentSubscriptions=function(){return l.map(l.keys(this.meteorSubscriptionHandles),c.parse)},e.prototype.oldSubscriptions=function(e){return l.reject(this.currentSubscriptions(),function(n){return a(e,n)})},e.prototype.newSubscriptions=function(e){var n=this;return l.reject(e,function(e){return n._alreadyHaveMeteorSubscription(e)})},e.prototype.stopOldSubscriptions=function(e,n,t){var o,i,a,u,s,c;for(a=[],c=this.oldSubscriptions(t),u=0,s=c.length;s>u;u++)i=c[u],o=d(i),this.meteorSubscriptionHandles[o].stop(),delete this.meteorSubscriptionHandles[o],n.madeUpdate=!0,a.push(w.addUpdate(e,{update:"subscriptionStatus",subscription:{connection:this.connectionName,name:i.name,args:i.args},status:{status:"unsubscribed",loaded:!1}}));return r.join(a)},e.prototype.subscriptionError=function(e,n){var t=this;w.transaction(function(r){return w.setSubscriptionError(r,t.connectionName,e.name,e.args,n).then(function(){return m(r,null,t.connectionName,e.name,e.args)})}).then(function(){return g()})},e.prototype.startNewSubscription=function(e){var n,t,r,o=this;this._deletedRemovedDocs=!1,r=e.name,n=e.args,t=s.subscribe.apply(s,[r].concat(P.call(n),[{onError:function(n){o.subscriptionError(e,n)},onReady:function(){o.meteorSubscriptionReady(e)}}])),this.meteorSubscriptionHandles[d(e)]=t},e.prototype.startNewSubscriptions=function(e,n,t){var o=this;return r.map(this.newSubscriptions(t),function(t){return o.startNewSubscription(t),w.ensureSubscription(e,o.connectionName,t.name,t.args).then(function(){return w.setSubscriptionStatus(e,o.connectionName,t.name,t.args,"subscribing")}).then(function(){return m(e,n,o.connectionName,t.name,t.args)})})},e.prototype.subscribeToSubscriptions=function(e,n,t){return t=l.map(t,O),r.join([this.stopOldSubscriptions(e,n,t),this.startNewSubscriptions(e,n,t)])},e.prototype.checkIfDocumentNowFree=function(e,n,t){return this.collectionAgents[n].updateDocFromServerIfFree(e,t)},e.prototype.methodCompleted=function(e){var n,t=this;n=null,v(function(o){return w.removeQueuedMethod(o,t.connectionName,e).then(function(){return w.readDocsWrittenByStub(o,this.connectionName,e)}).then(function(r){return n=r,w.removeDocumentsWrittenByStub(o,t.connectionName,e)}).then(function(){var e,i,a,u,s,c;for(a=[],u=0,s=n.length;s>u;u++)c=n[u],e=c.collectionName,i=c.docId,a.push(t.checkIfDocumentNowFree(o,e,i));return r.join(a)}).then(function(){return w.removeMethodHoldingUpSubscriptions(o,e)}).then(function(){return D(o,null)})}).then(function(){return g()})},e.prototype.sendQueuedMethod=function(e,n,t){var r=this;this.methodsSent[e]||(this.methodsSent[e]=!0,s.call("/awwx/offline-data/apply",e,n,t,function(t){t&&s._debug("offline method error",n,t),r.methodCompleted(e)}))},e}(),T=function(e){var n;return n="/"===e?s.default_connection:s.connect(e),new f(e,n)},b=function(e){return connectionAgents[e]||(connectionAgents[e]=T(e))},R=function(e){return w.readQueuedMethods(e).then(function(e){var n,t,r,o,i,a,u;for(i=0,a=e.length;a>i;i++)u=e[i],t=u.connection,r=u.methodId,o=u.name,n=u.args,b(t).sendQueuedMethod(r,o,n)})},C=function(){return v(function(e){return R(e)})},N=function(e,n){return w.readMergedSubscriptions(e).then(function(t){var o,i,a,u,s,c;for(s=0,c=t.length;c>s;s++)a=t[s],b(a.connection);u=[];for(i in connectionAgents)o=connectionAgents[i],u.push(o.subscribeToSubscriptions(e,n,l.filter(t,function(e){return e.connection===i})));r.join(u).then(function(){n.madeUpdate&&g()})})},t=function(){function e(e,n,t){this.connectionAgent=e,this.collectionName=n,this.serverCollection=t,this.connectionName=this.connectionAgent.connectionName,this.watchServer()}return e.prototype.offlineDocumentsNotInServerCollection=function(e){var n=this;return w.readDocIdsOfCollection(e,this.connectionName,this.collectionName).then(function(e){return l.reject(e,function(e){return n.serverCollection.findOne(e)})})},e.prototype.deleteDocUnlessWrittenByStub=function(e,n){var t=this;return w.isDocumentWrittenByAnyStub(e,this.connectionName,this.collectionName,n).then(function(r){return r?void 0:w.deleteDoc(e,t.connectionName,t.collectionName,n).then(function(){return t.addDocumentUpdate(e,n,null)})})},e.prototype.deleteDocumentsGoneFromServer=function(e){var n=this;return this.offlineDocumentsNotInServerCollection(e).then(function(t){var o,i,a,u;for(i=[],a=0,u=t.length;u>a;a++)o=t[a],i.push(n.deleteDocUnlessWrittenByStub(e,o));return r.join(i)})},e.prototype.addDocumentUpdate=function(e,n,t){return w.addUpdate(e,{update:"documentUpdated",connectionName:this.connectionName,collectionName:this.collectionName,docId:n,doc:t})},e.prototype.updateDocIfFree=function(e,n,t){var r=this;return w.isDocumentWrittenByAnyStub(e,this.connectionName,this.collectionName,n).then(function(o){return o?void 0:(null!=t?w.writeDoc(e,r.connectionName,r.collectionName,t):w.deleteDoc(e,r.connectionName,r.collectionName,n)).then(function(){return r.addDocumentUpdate(e,n,t)})})},e.prototype.updateDocFromServerIfFree=function(e,n){return this.updateDocIfFree(e,n,this.serverCollection.findOne(n))},e.prototype.serverDocUpdated=function(e,n){var t=this;v(function(r){return t.updateDocIfFree(r,e,n)}).then(function(){return g()})},e.prototype.watchServer=function(){var e=this;this.serverCollection.find().observe({added:function(n){return e.serverDocUpdated(n._id,n)},changed:function(n){return e.serverDocUpdated(n._id,n)},removed:function(n){return e.serverDocUpdated(n._id,null)}})},e}(),j=function(e){var n;return n={madeUpdate:!1},w.transaction(function(t){return e(t,n)}).then(function(){n.madeUpdate&&g()})},M=function(){j(function(e,n){return N(e,n)})},S=new r,y=function(e,n){return w.cleanSubscriptions(e).then(function(t){return r.map(t,function(t){return n.madeUpdate=!0,w.addUpdate(e,{update:"subscriptionStatus",subscription:t,status:{status:"unsubscribed",loaded:!1}})})})},k=function(){j(function(e,n){return y(e,n).then(function(){return w.initializeSubscriptions(e)}).then(function(){return w.readSubscriptions(e)}).then(function(t){return r.map(t,function(t){return _(e,n,t)})}).then(function(){return R(e)})}).then(function(){return S.complete()})},x.listen(function(e){S.then(function(){var n;n={madeUpdate:!1},v(function(t){return w.deleteWindows(t,e).then(function(){return y(t,n)}).then(function(){return N(t,n)})}).then(function(){return n.madeUpdate?g():void 0})})}),s.startup(function(){(o.isWebWorker||!o._usingSharedWebWorker)&&(p("windowSubscriptionsUpdated",function(){M()}),p("newQueuedMethod",function(){C()}),o.isWebWorker?k():I.listen(k))}))}.call(this),"undefined"==typeof Package&&(Package={}),Package["offline-common"]={Context:e,Errors:n,Fanout:t,Result:r,Offline:o,broadcast:i,contains:a}}(),_=Package.underscore._,Meteor=Package.meteor.Meteor,Deps=Package.deps.Deps,JSON=Package.json.JSON,EJSON=Package.ejson.EJSON,Reload=Package.reload.Reload,check=Package.check.check,Match=Package.check.Match,Random=Package.random.Random,DDP=Package.livedata.DDP,OrderedDict=Package["ordered-dict"].OrderedDict,LocalCollection=Package.minimongo.LocalCollection,stringify=Package["canonical-stringify"].stringify,Context=Package["offline-common"].Context,Errors=Package["offline-common"].Errors,Result=Package["offline-common"].Result,Offline=Package["offline-common"].Offline,broadcast=Package["offline-common"].broadcast}();