forked from jaystack/jaydata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datajs-1.0.3.min.js
13 lines (13 loc) · 57.4 KB
/
datajs-1.0.3.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
// Copyright (c) Microsoft. All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
(function(b,a){if(!b.datajs)b.datajs={};if(!b.OData)b.OData={};var db=b.datajs,c=b.OData,Ac="b",eb="c",Y="entry",fb="f",yb="p",xc="s",je="u",Hc="n",hb="c",Ud="d",Db="i",zb="p",Bc="n",w=function(b){return b!==null&&b!==a},vd=function(b,d){var a,c;for(a=0,c=b.length;a<c;a++)if(b[a]===d)return true;return false},B=function(b,c){return b!==a?b:c},e=function(a){if(arguments.length===1){b.setTimeout(a,0);return}var c=Array.prototype.slice.call(arguments,1);b.setTimeout(function(){a.apply(this,c)},0)},Sb=function(a,c){if(!a)return null;if(x(a)){var b,e,d;for(b=0,e=a.length;b<e;b++){d=Sb(a[b],c);if(d)return d}return null}else return a.dataServices?Sb(a.dataServices.schema,c):c(a)},Gc=function(a){return a.__edmType==="Edm.DateTimeOffset"||!a.__edmType&&a.__offset},wc=function(a,b){if(a===0)a="";else a="."+f(a.toString(),3);if(b>0){if(a==="")a=".000";a+=f(b.toString(),4)}return a},Cb=function(a){if(typeof a==="string")return a;var e=Gc(a),c=nc(a.__offset);if(e&&c!=="Z"){a=new Date(a.valueOf());var b=dd(c),i=a.getUTCHours()+b.d*b.h,h=a.getMinutes()+b.d*b.m;a.setUTCHours(i,h)}else if(!e)c="";var d=a.getUTCFullYear(),j=a.getUTCMonth()+1,g="";if(d<=0){d=-(d-1);g="-"}var k=wc(a.getUTCMilliseconds(),a.__ns);return g+f(d,4)+"-"+f(j,2)+"-"+f(a.getUTCDate(),2)+"T"+f(a.getUTCHours(),2)+":"+f(a.getUTCMinutes(),2)+":"+f(a.getUTCSeconds(),2)+k+c},Sc=function(e){var a=e.ms,h="";if(a<0){h="-";a=-a}var g=Math.floor(a/8.64e7);a-=8.64e7*g;var d=Math.floor(a/3.6e6);a-=3.6e6*d;var b=Math.floor(a/6e4);a-=6e4*b;var c=Math.floor(a/1e3);a-=c*1e3;return h+"P"+f(g,2)+"DT"+f(d,2)+"H"+f(b,2)+"M"+f(c,2)+wc(a,e.ns)+"S"},f=function(c,d,b){var a=c.toString(10);while(a.length<d)if(b)a+="0";else a="0"+a;return a},nc=function(a){return!a||a==="Z"||a==="+00:00"||a==="-00:00"?"Z":a},Ve=function(b,g,c,f,d,e){return d.request(b,function(d){try{d.headers&&Lb(d.headers);d.data===a&&f.read(d,e)}catch(h){if(h.request===a)h.request=b;if(h.response===a)h.response=d;c(h);return}g(d.data,d)},c)},x=function(a){return Object.prototype.toString.call(a)==="[object Array]"},zd=function(a){return Object.prototype.toString.call(a)==="[object Date]"},Qb=function(b,d){if(b){var a,c;for(a=0,c=b.length;a<c;a++)if(b[a].name===d)return b[a]}return null},pc=function(a,b,c){return a?Sb(b,function(b){return pe(a,b,c)}):null},Ib=function(b,a){return pc(b,a,"complexType")},J=function(b,a){return pc(b,a,"entityType")},Le=function(b,a){return a.indexOf(b)===0&&a.charAt(b.length)==="."?a.substr(b.length+1):null},pe=function(g,c,f){if(c){var d=Le(c["namespace"],g),b=c[f];if(d&&b){var a,e;for(a=0,e=b.length;a<e;a++)if(b[a].name===d)return b[a]}}return null},Ye={accept:"Accept","content-type":"Content-Type",dataserviceversion:"DataServiceVersion",maxdataserviceversion:"MaxDataServiceVersion"},Lb=function(a){for(var b in a){var d=b.toLowerCase(),c=Ye[d];if(c&&b!==c){var e=a[b];delete a[b];a[c]=e}}},Mb=function(b,c){return b!==a?b:c},d=function(a){return parseInt(a,10)},qf=/^([+-])?P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)(?:\.(\d+))?S)?)?/,cd=function(g){var b=qf.exec(g);if(b===null)throw{message:"Invalid duration value."};var l=b[2]||"0",j=b[3]||"0",m=d(b[4]||0),k=d(b[5]||0),h=d(b[6]||0),i=parseFloat(b[7]||0);if(l!=="0"||j!=="0")throw{message:"Unsupported duration value."};var a=b[8],c=0;if(!a)a=0;else{if(a.length>7)throw{message:"Cannot parse duration value to given precision."};c=f(a.substring(3),4,true);a=f(a.substring(0,3),3,true);a=d(a);c=d(c)}a+=i*1e3+h*6e4+k*3.6e6+m*8.64e7;if(b[1]==="-")a=-a;var e={ms:a,__edmType:"Edm.Time"};if(c)e.ns=c;return e},dd=function(a){var b=a.substring(0,1);b=b==="+"?1:-1;var e=d(a.substring(1)),c=d(a.substring(a.indexOf(":")+1));return{d:b,h:e,m:c}},K=function(b){switch(typeof b){case"object":return!b?Hc:x(b)||x(b.results)?fb:b.__metadata&&b.__metadata.uri!==a?Y:x(b.EntitySets)?xc:x(b.__batchRequests)?Ac:zd(b)?yb:eb;case"string":case"number":case"boolean":return yb}return je},Yc=function(b,c,d){if(!b.method)b.method="GET";if(!b.headers)b.headers={};else Lb(b.headers);if(b.headers.Accept===a)b.headers.Accept=c.accept;w(b.data)&&b.body===a&&c.write(b,d);if(!w(b.headers.MaxDataServiceVersion))b.headers.MaxDataServiceVersion=c.maxDataServiceVersion||"1.0"},Se=function(a){switch(K(a)){case eb:return a.__deferred&&a.__deferred.uri?Ud:hb;case fb:case Y:return Db;case yb:return zb}return Bc},kb=function(a){throw a;},td=function(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")},Hf=/^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#:]+)?(\?[^#]*)?(#.*)?/,ld=["scheme","authority","path","query","fragment"],Vb=function(e){var b={isAbsolute:false};if(e){var c=Hf.exec(e);if(c){var a,d;for(a=0,d=ld.length;a<d;a++)if(c[a+1])b[ld[a]]=c[a+1]}if(b.scheme)b.isAbsolute=true}return b},Vc=function(a){return"".concat(a.scheme||"",a.authority||"",a.path||"",a.query||"",a.fragment||"")},xe=/^\/{0,2}(?:([^@]*)@)?([^:]+)(?::{1}(\d+))?/,Ce=/%[0-9A-F]{2}/ig,Ae=function(c){var b=Vb(c),e=b.scheme,d=b.authority;if(e){b.scheme=e.toLowerCase();if(d){var a=xe.exec(d);if(a)b.authority="//"+(a[1]?a[1]+"@":"")+a[2].toLowerCase()+(a[3]?":"+a[3]:"")}}c=Vc(b);return c.replace(Ce,function(a){return a.toLowerCase()})},q=function(e,f){if(!f)return e;var a=Vb(e);if(a.isAbsolute)return e;var c=Vb(f),b={},d;if(a.authority){b.authority=a.authority;d=a.path;b.query=a.query}else{if(!a.path){d=c.path;b.query=a.query||c.query}else{if(a.path.charAt(0)==="/")d=a.path;else d=ce(a.path,c.path);b.query=a.query}b.authority=c.authority}b.path=qe(d);b.scheme=c.scheme;b.fragment=a.fragment;return Vc(b)},ce=function(d,b){var a="/",c;if(b){c=b.lastIndexOf("/");a=b.substring(0,c);if(a.charAt(a.length-1)!=="/")a=a+"/"}return a+d},qe=function(a){var b="",d="",c;while(a)if(a.indexOf("..")===0||a.indexOf(".")===0)a=a.replace(/^\.\.?\/?/g,"");else if(a.indexOf("/..")===0){a=a.replace(/^\/\..\/?/g,"/");c=b.lastIndexOf("/");if(c===-1)b="";else b=b.substring(0,c)}else if(a.indexOf("/.")===0)a=a.replace(/^\/\.\/?/g,"/");else{d=a;c=a.indexOf("/",1);if(c!==-1)d=a.substring(0,c);b=b+d;a=a.replace(d,"")}return b},tb=0,nf=function(a){return a.method&&a.method!=="GET"?false:true},df=function(f){var a=b.document.createElement("IFRAME");a.style.display="none";var c=f.replace(/&/g,"&").replace(/"/g,""").replace(/\</g,"<"),e='<html><head><script type="text/javascript" src="'+c+'"><\/script></head><body></body></html>',d=b.document.getElementsByTagName("BODY")[0];d.appendChild(a);Dc(a,e);return a},ae=function(){if(b.XMLHttpRequest)return new b.XMLHttpRequest;var a;if(b.ActiveXObject)try{return new b.ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(d){try{return new b.ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(c){a=c}}else a={message:"XMLHttpRequest not supported"};throw a;},We=function(a){return a.indexOf("http://")===0||a.indexOf("https://")===0||a.indexOf("file://")===0},tf=function(c){if(!We(c))return true;var a=b.location,d=a.protocol+"//"+a.host+"/";return c.indexOf(d)===0},Te=function(c,d){try{delete b[c]}catch(e){b[c]=a;if(d===tb-1)tb-=1}},Tb=function(a){if(a){Dc(a,"");a.parentNode.removeChild(a)}return null},ke=function(f,e){var b=f.getAllResponseHeaders().split(/\r?\n/),a,d;for(a=0,d=b.length;a<d;a++)if(b[a]){var c=b[a].split(": ");e[c[0]]=c[1]}},Dc=function(b,c){var a=b.contentWindow?b.contentWindow.document:b.contentDocument.document;a.open();a.write(c);a.close()};c.defaultHttpClient={callbackParameterName:"$callback",formatQueryString:"$format=json",enableJsonpCallback:false,request:function(c,m,j){var o={},a=null,g=false,f;o.abort=function(){f=Tb(f);if(g)return;g=true;if(a){a.abort();a=null}j({message:"Request aborted"})};var k=function(){f=Tb(f);if(!g){g=true;a=null;j({message:"Request timed out"})}},h,d=c.requestUri,r=B(c.enableJsonpCallback,this.enableJsonpCallback),q=B(c.callbackParameterName,this.callbackParameterName),s=B(c.formatQueryString,this.formatQueryString);if(!r||tf(d)){a=ae();a.onreadystatechange=function(){if(g||a===null||a.readyState!==4)return;var e=a.statusText,b=a.status;if(b===1223){b=204;e="No Content"}var h=[];ke(a,h);var f={requestUri:d,statusCode:b,statusText:e,headers:h,body:a.responseText};g=true;a=null;if(b>=200&&b<=299)m(f);else j({message:"HTTP request failed",request:c,response:f})};a.open(c.method||"GET",d,true,c.user,c.password);if(c.headers)for(h in c.headers)a.setRequestHeader(h,c.headers[h]);if(c.timeoutMS){a.timeout=c.timeoutMS;a.ontimeout=k}a.send(c.body)}else{if(!nf(c))throw{message:"Request is not local and cannot be done through JSONP."};var p=tb;tb+=1;var v=p.toString(),t=false,l;h="handleJSONP_"+v;b[h]=function(a){f=Tb(f);if(!g){t=true;b.clearTimeout(l);Te(h,p);if(b.ActiveXObject&&!b.DOMParser)a=b.JSON.parse(b.JSON.stringify(a));e(m,{body:a,statusCode:200,headers:{"Content-Type":"application/json"}})}};var u=c.timeoutMS?c.timeoutMS:1.2e5;l=b.setTimeout(k,u);var i=q+"=parent."+h;if(this.formatQueryString)i+="&"+s;var n=d.indexOf("?");if(n===-1)d=d+"?"+i;else if(n===d.length-1)d=d+i;else d=d+"&"+i;f=df(d)}return o}};var C="2.0",F=function(f){if(!f)return null;var b=f.split(";"),d={},a,e;for(a=1,e=b.length;a<e;a++){var c=b[a].split("=");d[td(c[0])]=c[1]}return{mediaType:td(b[0]),properties:d}},he=function(b){if(!b)return a;var d=b.mediaType,c;for(c in b.properties)d+=";"+c+"="+b.properties[c];return d},kc=function(c,b,a,d){return{contentType:c,dataServiceVersion:b,metadata:a?a.metadata:null,context:a,handler:d}},Kb=function(b,c,d){if(!b)return;var a=b.headers;if(!a[c])a[c]=d},Nf=function(a,b){if(!a.dataServiceVersion)a.dataServiceVersion=b},ac=function(c,d){var b=c.headers;return b&&b[d]||a},Tc=function(a){return F(ac(a,"Content-Type"))},Df=/^\s?(\d+\.\d+);?.*$/,mc=function(c){var b=ac(c,"DataServiceVersion");if(b){var a=Df.exec(b);if(a&&a.length)return a[1]}},Wc=function(a,b){return a.accept.indexOf(b.mediaType)>=0},pf=function(c,g,b,h){if(!b||!b.headers)return false;var e=Tc(b),i=mc(b)||"",f=b.body;if(!w(f))return false;if(Wc(c,e)){var d=kc(e,i,h,c);d.response=b;b.data=g(c,f,d);return b.data!==a}return false},ef=function(d,f,b,g){if(!b||!b.headers)return false;var e=Tc(b),h=mc(b);if(!e||Wc(d,e)){var c=kc(e,h,g,d);c.request=b;b.body=f(d,b.data,c);if(b.body!==a){Kb(b,"DataServiceVersion",c.dataServiceVersion||"1.0");Kb(b,"Content-Type",he(c.contentType));Kb(b,"MaxDataServiceVersion",d.maxDataServiceVersion);return true}}return false},P=function(c,b,d,a){return{accept:d,maxDataServiceVersion:a,read:function(a,b){return pf(this,c,a,b)},write:function(c,a){return ef(this,b,c,a)}}},Cf=function(b,a){return a},bf=function(c,b){return w(b)?b.toString():a};c.textHandler=P(Cf,bf,"text/plain",C);var pb="application/xml",Ad="http://",ub=Ad+"www.w3.org/",R=Ad+"schemas.microsoft.com/ado/",sb=R+"2007/08/dataservices",Q=ub+"2000/xmlns/",vb=ub+"XML/1998/namespace",yd=R+"2007/06/edmx",Mf=R+"2008/09/edm",Jf=R+"2006/04/edm",Kf=R+"2007/05/edm",Lf=R+"2009/11/edm",g=ub+"2005/Atom",cb=ub+"2007/app",v=sb,j=sb+"/metadata",Gb=sb+"/related/",pd=sb+"/scheme",Dd=function(a){var b=/(^\s)|(\s$)/;return b.test(a)},lf=function(c,f){var g="<c>"+f+"</c>",d=qb(g,null),e=c.ownerDocument,b=d.domNode;if("importNode"in e)b=e.importNode(d.domNode,true);var a=b.firstChild;while(a){c.appendChild(a);a=a.nextSibling}},lb=function(c,b,a){try{c.setProperty(b,a)}catch(d){}},Mc=function(){var c,a;if(b.ActiveXObject)try{a=new ActiveXObject("Msxml2.DOMDocument.6.0");a.async=false;return a}catch(e){try{a=new ActiveXObject("Msxml2.DOMDocument.3.0");a.async=false;lb(a,"ProhibitDTD",true);lb(a,"MaxElementDepth",256);lb(a,"AllowDocumentFunction",false);lb(a,"AllowXsltScript",false);return a}catch(d){c=d}}else{if(b.DOMParser)return new b.DOMParser;c={message:"XML DOM parser not supported"}}throw c;},cc=function(a){return{name:a.localName,"namespace":a.nsURI,value:a.domNode.value}},jc=function(a){var b={name:a.localName,"namespace":a.nsURI,value:Uc(a.domNode),attributes:[],children:[]};L(a,function(a){a.nsURI!==Q&&b.attributes.push(cc(a))});l(a,function(a){b.children.push(jc(a))});return b},ff=function(a){var b=/^\s*$/;return a===null||b.test(a)},Hd=function(a){while(a!==null&&a.nodeType===1){var b=ob(a,"space",vb);if(b==="preserve")return true;else if(b==="default")break;else a=a.parentNode}return false},Uc=function(f){var c=null,b=f.firstChild,h=f.ownerDocument.preserveWhiteSpace===false,d;while(b){if(b.nodeType===3||b.nodeType===4){var g=b.nodeValue,e=h||!ff(g);if(!e){if(d===a)d=Hd(f);e=d}if(e)if(!c)c=g;else c+=g}b=b.nextSibling}return c},s=function(b,d,e){var c;if(b.getElementsByTagNameNS){c=b.getElementsByTagNameNS(d,e);if(c.length!==0)return c[0]}else{var a=b.firstChild;while(a){if(a.nodeType===1&&md(a)===e&&a.namespaceURI===d)return a;a=a.nextSibling}}return null},Md=function(b,f){var d="http://www.mozilla.org/newlayout/xml/parsererror.xml",a=u(b,"");if(a.localName==="parsererror"&&a.nsURI===d){var h=Uc(b),c=s(a,d,"sourcetext"),g=c?c.nodeValue:"";throw{message:h,errorXmlText:f,srcText:g};}var e="http://www.w3.org/1999/xhtml";if(a.localName==="h3"&&a.nsURI==e||s(b,e,"h3"))throw{message:n(b),errorXmlText:f,srcText:""};},fc=function(c,d,e){var b=c.ownerDocument,a;if(b.createAttributeNS)a=b.createAttributeNS(Q,d);else a=b.createNode(2,d,Q);a.nodeValue=e;c.setAttributeNode(a)},Eb=function(a,b){if(Dd(b)){var d=yc(a,"space",vb,"xml");d.value="preserve"}var c=a.ownerDocument.createTextNode(b);a.appendChild(c)},L=function(f,e){var b,c=f.domNode,a,d;for(a=0,d=c.attributes.length;a<d;a++){b=c.attributes.item(a);e(u(b))}},M=function(b,a,c){return ob(b.domNode,a,c)},Ee=function(d,b,c){var a=d.attributes;return a.getNamedItemNS?a.getNamedItemNS(c,b):a.getQualifiedItem(b,c)},l=function(c,d){var a=c.domNode.firstChild,b;while(a!==null){if(a.nodeType===1){b=q(Ub(a),c.baseURI);d(u(a,b))}a=a.nextSibling}},Qc=function(c){var a=c.domNode.firstChild,b;while(a!==null){if(a.nodeType===1){b=q(Ub(a),c.baseURI);return u(a,b)}a=a.nextSibling}return null},n=function(e){var c=e.text;if(c!==a)return c;c="";var b=e.firstChild;if(b)do{if(b.nodeType===3||b.nodeType===4)c+=b.nodeValue;var d=b.firstChild;if(!d)while(b!==e){d=b.nextSibling;if(d){b=d;break}else b=b.parentNode}else b=d}while(b!==e);return c},md=function(a){return a.localName?a.localName:a.baseName},ad=function(d,c){var a;if(b.ActiveXObject){a=Mc();a.documentElement=a.createNode(1,d,c)}else if(b.document.implementation&&b.document.implementation.createDocument)a=b.document.implementation.createDocument(c,d,null);return u(a.documentElement)},yc=function(d,c,g,f){var e=d.ownerDocument,b;c=f?f+":"+c:c;if(e.createAttributeNS){b=e.createAttributeNS(g,c);d.setAttributeNodeNS(b)}else{b=e.createNode(2,c,g||a);d.setAttributeNode(b)}return b},Fe=function(f,b,g,e){var d=f.ownerDocument,c;b=e?e+":"+b:b;if(d.createElementNS)c=d.createElementNS(g,b);else c=d.createNode(1,b,g||a);f.appendChild(c);return c},k=function(d,g,e,f){var c=d.domNode.ownerDocument,b;if(c.createElementNS)b=c.createElementNS(e,g);else b=c.createNode(1,g,e||a);f&&Eb(b,f);d.domNode.appendChild(b);return u(b)},t=function(c,g,e,f){var d=c.domNode.ownerDocument,b;if(d.createAttributeNS){b=d.createAttributeNS(e,g);b.value=f;c.domNode.setAttributeNodeNS(b)}else{b=d.createNode(2,g,e||a);b.value=f;c.domNode.setAttributeNode(b)}return u(b)},X=function(b,a){return a?a+":"+b:b},qb=function(d,c){var a=Ff(d),b=q(Ub(a),c);return u(a,b)},nd=function(a){var b=a.domNode.ownerDocument;return Kc(b)},ge=function(d){var b=d.childNodes,a,e=b.length;if(e===0)return"";var c=d.ownerDocument.createDocumentFragment();for(a=0;a<e;a++)c.appendChild(b[a].cloneNode(true));return Kc(c)},Kc=function(c){var d=c.xml;if(d!==a)return d;if(b.XMLSerializer){var e=new b.XMLSerializer;return e.serializeToString(c)}throw{message:"XML serialization unsupported"};},ob=function(a,b,c){if(a.getAttributeNS)return a.getAttributeNS(c||null,b);var d=a.attributes.getQualifiedItem(b,c);return d?d.value:null},Ub=function(a){return ob(a,"base",vb)},Ff=function(b){var a=Mc();if(a.parseFromString){a=a.parseFromString(b,"text/xml");Md(a.documentElement,b)}else{a.loadXML(b);if(a.parseError.errorCode!==0)throw{message:a.parseError.reason,errorXmlText:b,srcText:a.parseError.srcText};}return a.documentElement},u=function(a,d){var b=a.namespaceURI,c=a.nodeName;if(!b)if(a.nodeType===2&&(c==="xmlns"||c.indexOf("xmlns:",0)===0))b=Q;else b=null;return{baseURI:d,domNode:a,localName:md(a),nsURI:b}},ee=function(b){if(b.nsURI===v)switch(b.localName){case"links":return Bf(b);case"uri":return xd(b)}return a},Bf=function(b){var a=[];l(b,function(b){if(b.localName==="uri"&&b.nsURI===v){var c=xd(b);a.push(c)}});return{results:a}},xd=function(a){return{uri:n(a.domNode)}},Yd=function(a){if(K(a)===eb&&!a.__metadata&&a.hasOwnProperty("uri"))return If(a)},If=function(a){var b=ze(null,"uri",v);a.uri&&Eb(b.domNode,a.uri);return b},ze=function(a,c,b){return a?k(a,c,b):ad(c,b)},Ef=function(c,b){if(b){var a=qb(b);if(a)return ee(a)}},cf=function(g,f,b){var e=b.contentType=b.contentType||F(pb),c=a;if(e&&e.mediaType===pb){var d=Yd(f);if(d)c=nd(d)}return c};c.xmlHandler=P(Ef,cf,pb,C);var Lc=["application/atom+xml","application/atomsvc+xml","application/xml"],bd=Lc[0],zf=X("inline","m"),af=X("properties","m"),Wd=X("type","m"),Vd=X("null","m"),Td=[g,cb,vb,Q],Nd={SyndicationAuthorEmail:"author/email",SyndicationAuthorName:"author/name",SyndicationAuthorUri:"author/uri",SyndicationContributorEmail:"contributor/email",SyndicationContributorName:"contributor/name",SyndicationContributorUri:"contributor/uri",SyndicationPublished:"published",SyndicationRights:"rights",SyndicationSummary:"summary",SyndicationTitle:"title",SyndicationUpdated:"updated"},nb=function(a){return!vd(Td,a)},S=function(a){return a},Af=function(a){return a==="true"},Ke=/^(-?\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(.*)$/,dc=function(o,j){var a=Ke.exec(o),g=a?nc(a[8]):null;if(!a||!j&&g!=="Z")throw{message:"Invalid date/time value"};var i=d(a[1]);if(i<=0)i++;var b=a[7],e=0;if(!b)b=0;else{if(b.length>7)throw{message:"Cannot parse date/time value to given precision."};e=f(b.substring(3),4,true);b=f(b.substring(0,3),3,true);b=d(b);e=d(e)}var m=d(a[4]),l=d(a[5]),n=d(a[6]);if(g!=="Z"){var h=dd(g),k=-h.d;m+=h.h*k;l+=h.m*k}var c=new Date;c.setUTCFullYear(i,d(a[2])-1,d(a[3]));c.setUTCHours(m,l,n,b);if(isNaN(c.valueOf()))throw{message:"Invalid date/time value"};if(j){c.__edmType="Edm.DateTimeOffset";c.__offset=g}if(e)c.__ns=e;return c},Ze=function(a){return dc(a,false)},ie=function(a){return dc(a,true)},lc={"Edm.Boolean":Af,"Edm.Binary":S,"Edm.DateTime":Ze,"Edm.DateTimeOffset":ie,"Edm.Time":cd,"Edm.Decimal":S,"Edm.Guid":S,"Edm.String":S,"Edm.Byte":d,"Edm.Double":parseFloat,"Edm.Single":parseFloat,"Edm.Int16":d,"Edm.Int32":d,"Edm.Int64":S,"Edm.SByte":d},m=function(a){return a.toString()},Pd={"Edm.Binary":m,"Edm.Boolean":m,"Edm.Byte":m,"Edm.DateTime":Cb,"Edm.DateTimeOffset":Cb,"Edm.Decimal":m,"Edm.Double":m,"Edm.Guid":m,"Edm.Int16":m,"Edm.Int32":m,"Edm.Int64":m,"Edm.SByte":m,"Edm.Single":m,"Edm.String":m,"Edm.Time":Sc},Nb=function(b){return b&&lc[b]!==a},Zb=function(a,b){if(a!==null&&b){var c=lc[b];if(c)a=c(a)}return a},bc=function(a,b){if(a!==null&&b){if(zd(a))b=Gc(a)?"Edm.DateTimeOffset":"Edm.DateTime";var c=Pd[b];if(c)a=c(a)}return a},Ic=function(a,b){if(a.nsURI===g)switch(a.localName){case"feed":return jf(a,b);case"entry":return ed(a,b)}if(a.nsURI===cb&&a.localName==="service")return Od(a)},jf=function(c,e){var a={},b={results:[],__metadata:a};a.feed_extensions=T(c);l(c,function(c){switch(c.nsURI){case g:switch(c.localName){case"id":a.uri=q(n(c.domNode),c.baseURI);a.uri_extensions=T(c);break;case"title":a.title=n(c.domNode);a.title_extensions=T(c);break;case"entry":var h=ed(c,e);b.results.push(h);break;case"link":De(c,b)}return;case j:if(c.localName==="count"){b.__count=d(n(c.domNode));return}}var f=V(c);a.feed_extensions.push(f)});return b},De=function(d,c){var a=jd(d),b=c.__metadata;switch(a.rel){case"next":c.__next=a.href;b.next_extensions=a.extensions;break;case"self":b.self=a.href;b.self_extensions=a.extensions}},jd=function(b){var a={extensions:[]},c;L(b,function(d){if(!d.nsURI)switch(d.localName){case"href":a.href=q(d.domNode.nodeValue,b.baseURI);return;case"type":case"rel":a[d.localName]=d.domNode.nodeValue;return}if(nb(d.nsURI)){c=U(d);a.extensions.push(c)}});if(!a.href)throw{error:"href attribute missing on link element",element:b};return a},V=function(a){var b={name:a.localName,namespaceURI:a.nsURI,attributes:T(a),children:[]};l(a,function(c){var a=V(c);b.children.push(a)});if(b.children.length===0){var c=n(a.domNode);if(c)b.value=c}return b},T=function(b){var a=[];L(b,function(b){if(nb(b.nsURI)){var c=U(b);a.push(c)}});return a},U=function(a){return{name:a.localName,namespaceURI:a.nsURI,value:a.domNode.nodeValue}},oc=function(d,b){if(d.indexOf("/")===-1)return b[d];else{var e=d.split("/"),c,f;for(c=0,f=e.length;c<f;c++){if(b===null)return a;b=b[e[c]];if(b===a)return b}return b}},fe=function(g,b,k,h){var d;if(g.indexOf("/")===-1){b[g]=k;d=g}else{var f=g.split("/"),c,l;for(c=0,l=f.length-1;c<l;c++){var e=b[f[c]];if(e===a){e={};b[f[c]]=e}else if(e===null)return;b=e}d=f[c];b[d]=k}if(h){var j=b.__metadata=b.__metadata||{},i=j.properties=j.properties||{},m=i[d]=i[d]||{};m.type=h}},hc=function(a){return Nd[a]||a},He=function(f,h,b,g){var d=h.split("/"),c,e;for(c=0,e=d.length;c<e;c++)if(d[c].charAt(0)==="@")return ob(b,d[c].substring(1),f);else{b=s(b,f,d[c]);if(!b)return a}return g?ge(b):n(b)},Me=function(e,h,k,j,f,g){var a=j,d=k.split("/"),b,i;for(b=0,i=d.length;b<i;b++){var c;if(d[b].charAt(0)==="@"){c=Ee(a,d[b].substring(1),e);if(!c)c=yc(a,d[b].substring(1),e,h)}else{c=s(a,e,d[b]);if(!c)c=Fe(a,d[b],e,h)}a=c}if(a.nodeType===2)a.value=g;else{f&&a.setAttribute("type",f);if(f==="xhtml")lf(a,g);else Eb(a,g)}},Pe=function(d){if(d.childNodes.length)return false;var c=d.attributes,e=c.length;if(e===0)return true;for(var b=0;b<e;b++){var a=c[b].nodeName;if(a!=="xmlns"&&a.indexOf("xmlns:")!==0&&a!=="m:type")return false}return true},we=function(i,m){var b=s(i.domNode,j,"properties");if(!b){var h=s(i.domNode,g,"content");if(h)b=s(h,j,"properties")}if(b){var a=b,e=m.split("/"),d,l;for(d=0,l=e.length-1;d<l;d++){a=s(a,v,e[d]);if(!a)return}var f=s(a,v,e[d]);f&&a.removeChild(f);var c=a;while(c!==b&&Pe(c)){var k=c.parentNode;k.removeChild(c);c=k}}},Yb=function(a,e,d,l,j,b,n){var f=a["FC_TargetPath"+b],h=hc(f),k=f!==h?g:a["FC_NsUri"+b],i=a["FC_KeepInContent"+b]==="true"?true:false,m=a["FC_ContentKind"+b],o=a["FC_NsPrefix"+b]||null,c=oc(e,l);if(!w(c))return;if(!i){n.dataServiceVersion="2.0";we(d,e)}c=bc(c,j);Me(k,o,h,d.domNode,m,c)},Xb=function(b,h,k,f,e,c){if(b["FC_KeepInContent"+c]==="true")return;if(oc(h,f)===null)return;var i=b["FC_TargetPath"+c],j=hc(i),l=i!==j?g:b["FC_NsUri"+c],m=b["FC_ContentKind"+c]==="xhtml",d=He(l,j,k.domNode,m);if(d===a)return;d=Zb(d,e);fe(h,f,d,e)},Fb=function(g,b,j){var h=j.split("/"),c,i;while(b){var d=b;for(c=0,i=h.length;c<i;c++){var f=d.property;if(!f)break;var e=Qb(f,h[c]);if(!e)break;var a=e.type;if(!a||Nb(a))return a||null;d=Ib(a,g);if(!d)return null}b=J(b.baseType,g)}return null},Sd=function(l,h,d){if(!d||d.length===0)return;var j=h.__metadata.type;while(j){var a=J(j,d);if(!a)return;var c,b=a.FC_SourcePath;if(b){c=Fb(d,a,b);Xb(a,b,l,h,c,"")}var i=a.property;if(i){var g,n;for(g=0,n=i.length;g<n;g++){var e=i[g],k=0,f="";while(e["FC_TargetPath"+f]){b=e.name;c=e.type;var m=e["FC_SourcePath"+f];if(m){b+="/"+m;c=Fb(d,a,b)}Xb(e,b,l,h,c,f);k++;f="_"+k}}}j=a.baseType}},ed=function(c,d){var a={},b={__metadata:a},e=M(c,"etag",j);if(e)a.etag=e;l(c,function(c){if(c.nsURI===g)switch(c.localName){case"id":a.uri=q(n(c.domNode),c.baseURI);a.uri_extensions=T(c);break;case"category":ve(c,b,a);break;case"content":de(c,b);break;case"link":ue(c,b,d)}c.nsURI===j&&c.localName==="properties"&&wb(c,b,a)});Sd(c,b,d);return b},ve=function(c,e,a){var d=M(c,"scheme"),f=M(c,"term");if(d===pd){if(e.__metadata.type)throw{message:"Invalid AtomPub document: multiple category elements defining the entry type were encounterd withing an entry",element:c};a.type=f;a.type_extensions=[];var b;L(c,function(c){if(!c.nsURI){if(c.localName!=="scheme"&&c.localName!=="term"){b=U(c);a.type_extensions.push(b)}}else if(nb(c.nsURI)){b=U(c);a.type_extensions.push(b)}})}},de=function(a,d){var c=M(a,"src"),e=M(a,"type"),b=d.__metadata;if(c){if(!e)throw{message:"Invalid AtomPub document: content element must specify the type attribute if the src attribute is also specified",element:a};b.media_src=q(c,a.baseURI);b.content_type=e}l(a,function(e){if(c)throw{message:"Invalid AtomPub document: content element must not have child elements if the src attribute is specified",element:a};e.nsURI===j&&e.localName==="properties"&&wb(e,d,b)})},Id=function(b,e,c){c.edit_media=b.href;c.edit_media_extensions=[];var a,d;for(a=0,d=b.extensions.length;a<d;a++)if(b.extensions[a].namespaceURI===j&&b.extensions[a].name==="etag")c.media_etag=b.extensions[a].value;else c.edit_media_extensions.push(b.extensions[a])},ue=function(d,c,e){var a=jd(d),b=c.__metadata;switch(a.rel){case"self":b.self=a.href;b.self_link_extensions=a.extensions;break;case"edit":b.edit=a.href;b.edit_link_extensions=a.extensions;break;case"edit-media":Id(a,c,b);break;default:a.rel.indexOf(Gb)===0&&Gd(d,a,c,e)}},Gd=function(f,d,c,g){var e=d.rel.substring(Gb.length),b=a;l(f,function(a){if(a.nsURI===j&&a.localName==="inline"){var c=Qc(a);if(c)b=Ic(c,g);else b=null}});if(b===a)b={__deferred:{uri:d.href}};c[e]=b;c.__metadata.properties=c.__metadata.properties||{};c.__metadata.properties[e]={extensions:d.extensions}},wb=function(b,c,a){l(b,function(b){if(b.nsURI===v){a.properties=a.properties||{};Xd(b,c,a.properties)}})},Xd=function(b,h,g){var e=null,c="Edm.String",d=[];L(b,function(a){if(a.nsURI===j)switch(a.localName){case"null":e=a.domNode.nodeValue;return;case"type":c=a.domNode.nodeValue;return}if(nb(a.nsURI)){var b=U(a);d.push(b)}});var a=null,f={type:c,extensions:d};if(e!=="true"){a=n(b.domNode);if(Nb(c))a=Zb(a,c);else if(Qc(b)){a={__metadata:{type:c}};wb(b,a,f)}}h[b.localName]=a;g[b.localName]=f},Od=function(b){var a={workspaces:[],extensions:[]};l(b,function(c){if(c.nsURI===cb&&c.localName==="workspace"){var e=Cd(c);a.workspaces.push(e)}else{var d=V(b);a.extensions.push(d)}});if(a.workspaces.length===0)throw{message:"Invalid AtomPub service document: No workspace element found.",element:b};return a},Cd=function(b){var a={collections:[],extensions:[]};l(b,function(c){if(c.nsURI===g){if(c.localName==="title"){if(b.title)throw{message:"Invalid AtomPub service document: workspace has more than one child title element",element:c};a.title=n(c.domNode)}}else if(c.nsURI===cb){if(c.localName==="collection"){var d=Bd(c,a);a.collections.push(d)}}else{var e=V(b);a.extensions.push(e)}});a.title=a.title||"";return a},Bd=function(b){var a={href:M(b,"href"),extensions:[]};if(!a.href)throw{message:"Invalid AtomPub service document: collection has no href attribute",element:b};a.href=q(a.href,b.baseURI);l(b,function(c){if(c.nsURI===g){if(c.localName==="title"){if(a.title)throw{message:"Invalid AtomPub service document: collection has more than one child title element",element:c};a.title=n(c.domNode)}}else if(c.nsURI!==cb){var d=V(b);a.extensions.push(d)}});if(!a.title)throw{message:"Invalid AtomPub service document: collection has no title element",element:b};return a},ye=function(b,c){var a,d=K(b);switch(d){case fb:a=fd(null,b,c);break;case Y:case eb:a=Rb(null,b,c)}return a},gd=function(b,c){if(b)return k(b,c,g);var a=ad(c,g);fc(a.domNode,"xmlns:d",v);fc(a.domNode,"xmlns:m",j);return a},fd=function(g,c,f){var d=gd(g,"feed"),b=x(c)?c:c.results;if(b){var a,e;for(a=0,e=b.length;a<e;a++)Rb(d,b[a],f)}return d},Rb=function(i,b,d){var a=gd(i,"entry"),h=k(a,"author",g);k(h,"name",g);k(a,"title",g);var c=k(a,"content",g);t(c,"type",null,"application/xml");var f=k(c,af,j),e=b.__metadata?b.__metadata.properties:null;Qd(a,b.__metadata);ec(a,f,b,e,d);Zd(a,b,d);return a},Zd=function(l,e,i){if(!e.__metadata)return;var h=i.metadata,a=J(e.__metadata.type,h);while(a){var k,c=a.FC_SourcePath;if(c){k=Fb(h,a,c);Yb(a,c,l,e,k,"",i)}var g=a.property;if(g){var f,m;for(f=0,m=g.length;f<m;f++){var b=g[f],j=0,d="";while(b["FC_TargetPath"+d]){c=b.name;if(b["FC_SourcePath"+d])c+="/"+b["FC_SourcePath"+d];Yb(b,c,l,e,b.type,d,i);j++;d="_"+j}}}a=J(a.baseType,h)}},Qd=function(b,a){if(a){a.etag&&t(b,"etag",j,a.etag);a.uri&&k(b,"id",g,a.uri);if(a.type){var c=k(b,"category",g);t(c,"term",null,a.type);t(c,"scheme",null,pd)}}},re=function(b,c,d){var a=k(b,"link",g);t(a,"rel",null,d);t(a,"href",null,c);return a},ec=function(l,k,h,i,f){var d,g,c,b,j=f.metadata,e;for(d in h)if(d!=="__metadata"){g=h[d];c=Se(g);b=i?i[d]:null;if(!b){if(e===a)if(h.__metadata)e=J(h.__metadata.type,j);if(e){b=Qb(e.property,d);if(!b)b=Qb(e.navigationProperty,d)}}if(c===Bc){c=zb;if(b&&!Nb(b.type))if(b.relationship)c=Db;else if(Ib(b.type,f.metadata))c=hb}if(c===zb||c===hb)Rd(k,d,c,g,b,f);else Ed(l,c,d,g,f)}},Rd=function(g,l,i,c,b,h){var f=X(l,"d"),d=b&&b.type,a;if(i===hb){a=k(g,f,v);var e;if(b)e=b.properties;if(c===null)h.dataServiceVersion="2.0";ec(null,a,c,e,h)}else a=k(g,f,v,bc(c,d||"Edm.String"));c===null&&t(a,Vd,j,"true");d&&t(a,Wd,j,d)},Ed=function(i,l,m,b,h){var d,c,a,e=l===Db;if(e){d=b&&b.__metadata?b.__metadata.uri:"";a=K(b);switch(a){case Y:c=Rb;break;case fb:a="feed";c=fd;break;case Hc:a=Y;c=null;break;default:throw{message:"Invalid payload for inline navigation property: "+a};}}else d=b.__deferred.uri;var n=q(m,Gb),f=re(i,d,n);if(e){var g=k(f,zf,j);t(f,"type",null,"application/atom+xml;type="+a);c&&c(g,b,h)}},sf=function(d,b,c){if(b){var a=qb(b);if(a)return Ic(a,c.metadata)}},Ne=function(g,f,b){var d=b.contentType=b.contentType||F(bd),c=a;if(d&&d.mediaType===bd){var e=ye(f,b);c=nd(e)}return c};c.atomHandler=P(sf,Ne,Lc.join(","),C);var o={elements:{Association:{attributes:["Name"],elements:["End*","ReferentialConstraint"]},AssociationSet:{attributes:["Name","Association"],elements:["End*"]},CollectionType:{attributes:["ElementType","Nullable","DefaultValue","MaxLength","FixedLength","Precision","Scale","Unicode","Collation"]},ComplexType:{attributes:["Name","BaseType","Abstract"],elements:["Property*"]},DefiningExpression:{text:true},Dependent:{attributes:["Role"],elements:["PropertyRef*"]},Documentation:{text:true},End:{attributes:["Type","Role","Multiplicity","EntitySet"],elements:["OnDelete"]},EntityContainer:{attributes:["Name","Extends"],elements:["EntitySet*","AssociationSet*","FunctionImport*"]},EntitySet:{attributes:["Name","EntityType"]},EntityType:{attributes:["Name","BaseType","Abstract","OpenType"],elements:["Key","Property*","NavigationProperty*"]},Function:{attributes:["Name","ReturnType"],elements:["Parameter*","DefiningExpression","ReturnType"]},FunctionImport:{attributes:["Name","ReturnType","EntitySet"],elements:["Parameter*"]},Key:{elements:["PropertyRef*"]},NavigationProperty:{attributes:["Name","Relationship","ToRole","FromRole"]},OnDelete:{attributes:["Action"]},Parameter:{attributes:["Name","Type","Mode","MaxLength","Precision","Scale"]},Principal:{attributes:["Role"],elements:["PropertyRef*"]},Property:{attributes:["Name","Type","Nullable","DefaultValue","MaxLength","FixedLength","Precision","Scale","Unicode","Collation","ConcurrencyMode"]},PropertyRef:{attributes:["Name"]},ReferenceType:{attributes:["Type"]},ReferentialConstraint:{elements:["Principal","Dependent"]},ReturnType:{attributes:["ReturnType"],elements:["CollectionType","ReferenceType","RowType"]},RowType:{elements:["Property*"]},Schema:{attributes:["Namespace","Alias"],elements:["Using*","EntityContainer*","EntityType*","Association*","ComplexType*","Function*"]},TypeRef:{attributes:["Type","Nullable","DefaultValue","MaxLength","FixedLength","Precision","Scale","Unicode","Collation"]},Using:{attributes:["Namespace","Alias"]}}},gc=["m:FC_ContentKind","m:FC_KeepInContent","m:FC_NsPrefix","m:FC_NsUri","m:FC_SourcePath","m:FC_TargetPath"];o.elements.Property.attributes=o.elements.Property.attributes.concat(gc);o.elements.EntityType.attributes=o.elements.EntityType.attributes.concat(gc);o.elements.Edmx={attributes:["Version"],elements:["DataServices"],ns:yd};o.elements.DataServices={elements:["Schema*"],ns:yd};o.elements.EntityContainer.attributes.push("m:IsDefaultEntityContainer");o.elements.Property.attributes.push("m:MimeType");o.elements.FunctionImport.attributes.push("m:HttpMethod");o.elements.EntityType.attributes.push("m:HasStream");o.elements.DataServices.attributes=["m:DataServiceVersion","m:MaxDataServiceVersion"];var sd=function(a){if(!a)return a;if(a.length>1){var b=a.substr(0,2);return b===b.toUpperCase()?a:a.charAt(0).toLowerCase()+a.substr(1)}return a.charAt(0).toLowerCase()},Oe=function(g,e){if(e==="Documentation")return{isArray:true,propertyName:"documentation"};var c=g.elements;if(!c)return null;var b,f;for(b=0,f=c.length;b<f;b++){var a=c[b],d=false;if(a.charAt(a.length-1)==="*"){d=true;a=a.substr(0,a.length-1)}if(e===a){var h=sd(a);return{isArray:d,propertyName:h}}}return null},Jd=/^(m:FC_.*)_[0-9]+$/,Xc=function(a){return a===Mf||a===Jf||a===Kf||a===Lf},xb=function(a){if(!a.domNode)a=u(a,"");var f=a.localName,c=o.elements[f];if(!c)return null;if(c.ns){if(a.nsURI!==c.ns)return null}else if(!Xc(a.nsURI))return null;var b={},d=[],e=c.attributes||[];L(a,function(c){var l=c.domNode,g=c.localName,f=c.nsURI,k=l.value;if(f===Q)return;var a=null,h=false;if(Xc(f)||f===null)a="";else if(f===j)a="m:";if(a!==null){a+=g;var i=Jd.exec(a);if(i)a=i[1];if(vd(e,a)){h=true;b[sd(g)]=k}}!h&&d.push(cc(c))});l(a,function(e){var a=Oe(c,e.localName);if(a)if(a.isArray){var f=b[a.propertyName];if(!f){f=[];b[a.propertyName]=f}f.push(xb(e))}else b[a.propertyName]=xb(e);else d.push(jc(e))});if(c.text)b.text=n(a);if(d.length)b.extensions=d;return b},Re=function(d,b){var c=qb(b);return xb(c)||a};c.metadataHandler=P(Re,null,pb,C);var Ob=["application/json","application/json;odata=verbose"],Xe=F(Ob[0]),be=F(Ob[1]),Ld=function(d,g){var b={collections:[]},a,e;for(a=0,e=d.EntitySets.length;a<e;a++){var c=d.EntitySets[a],f={title:c,href:q(c,g)};b.collections.push(f)}return{workspaces:[b]}},uf=/^\/Date\((-?\d+)(\+|-)?(\d+)?\)\/$/,Je=function(a){var b;if(a<0){b="-";a=-a}else b="+";var c=Math.floor(a/60);a=a-60*c;return b+f(c,2)+":"+f(a,2)},vc=function(e){var b=e&&uf.exec(e);if(b){var a=new Date(d(b[1]));if(b[2]){var c=d(b[3]);if(b[2]==="-")c=-c;var f=a.getUTCMinutes();a.setUTCMinutes(f-c);a.__edmType="Edm.DateTimeOffset";a.__offset=Je(c)}if(!isNaN(a.valueOf()))return a}},Jc=function(b,f){if(b&&typeof b==="object")for(var d in b){var e=b[d],c=Jc(e,f);c=f(d,c);if(c!==e)if(e===a)delete b[d];else b[d]=c}return b},Gf=function(b,a){return a("",Jc(b,a))},vf=function(h,e,d){var f=d.metadata,g=B(d.context?d.context.recognizeDates:a,h.recognizeDates),c=typeof e==="string"?b.JSON.parse(e):e;c=Gf(c,function(m,a){if(a&&typeof a==="object"){var i=a.__metadata&&a.__metadata.type,j=J(i,f)||Ib(i,f);if(j){var h=j.property;if(h){var d,l;for(d=0,l=h.length;d<l;d++){var c=h[d],e=c.name,b=a[e];if(c.type==="Edm.DateTime"||c.type==="Edm.DateTimeOffset"){if(b){b=vc(b);if(!b)throw{message:"Invalid date/time value"};a[e]=b}}else if(c.type==="Edm.Time")a[e]=cd(b)}}}else if(g)for(var k in a){b=a[k];if(typeof b==="string")a[k]=vc(b)||b}}return a}).d;c=Kd(c,d.dataServiceVersion);c=te(c,d.response.requestUri);return c},Qe=function(i,g,c){var d=a,e=c.contentType=c.contentType||be;if(e&&e.mediaType===Xe.mediaType){var h=g,f=Date.prototype.toJSON;try{Date.prototype.toJSON=function(){return Cb(this)};d=b.JSON.stringify(h,gf)}finally{Date.prototype.toJSON=f}}return d},gf=function(b,a){return a&&a.__edmType==="Edm.Time"?Sc(a):a},te=function(a,b){return K(a)===xc?Ld(a,b):a},Kd=function(b,a){if(a&&a.lastIndexOf(";")===a.length-1)a=a.substr(0,a.length-1);if(!a)if(x(b))a="1.0";if(a==="1.0")if(x(b))b={results:b};return b};c.jsonHandler=P(vf,Qe,Ob.join(","),C);c.jsonHandler.recognizeDates=false;var bb="multipart/mixed",me=/^HTTP\/1\.\d (\d{3}) (.*)$/i,le=/^([^()<>@,;:\\"\/[\]?={} \t]+)\s?:\s?(.*)/,Wb=function(){return Math.floor((1+Math.random())*65536).toString(16).substr(1)},Rc=function(a){return a+Wb()+"-"+Wb()+"-"+Wb()},qd=function(a){return a.handler.partHandler},Nc=function(b){var a=b.boundaries;return a[a.length-1]},mf=function(d,c,a){var b=a.contentType.properties.boundary;return{__batchResponses:ud(c,{boundaries:[b],handlerContext:a})}},Ge=function(d,c,a){var b=a.contentType=a.contentType||F(bb);if(b.mediaType===bb)return xf(c,a)},ud=function(b,a){var e="--"+Nc(a);rb(b,a,e);O(b,a);var f=[],h;while(h!=="--"&&a.position<b.length){var i=rd(b,a),d=F(i["Content-Type"]);if(d&&d.mediaType===bb){a.boundaries.push(d.properties.boundary);try{var g=ud(b,a)}catch(j){j.response=kd(b,a,e);g=[j]}f.push({__changeResponses:g});a.boundaries.pop();rb(b,a,"--"+Nc(a))}else{if(!d||d.mediaType!=="application/http")throw{message:"invalid MIME part type "};O(b,a);var c=kd(b,a,e);try{if(c.statusCode>=200&&c.statusCode<=299)qd(a.handlerContext).read(c,a.handlerContext);else c={message:"HTTP request failed",response:c}}catch(j){c=j}f.push(c)}h=b.substr(a.position,2);O(b,a)}return f},rd=function(f,b){var c={},a,d,e;do{e=b.position;d=O(f,b);a=le.exec(d);if(a!==null)c[a[1]]=a[2];else b.position=e}while(d&&a);Lb(c);return c},kd=function(b,a,g){var h=a.position,c=me.exec(O(b,a)),d,e,f;if(c){d=c[1];e=c[2];f=rd(b,a);O(b,a)}else a.position=h;return{statusCode:d,statusText:e,headers:f,body:rb(b,a,"\r\n"+g)}},O=function(b,a){return rb(b,a,"\r\n")},rb=function(c,b,d){var e=b.position||0,a=c.length;if(d){a=c.indexOf(d,e);if(a===-1)return null;b.position=a+d.length}else b.position=a;return c.substring(e,a)},xf=function(f,e){var g=K(f);if(g!==Ac)throw{message:'Serialization of batches of type "'+g+'" is not supported'};var b=Rc("batch_"),d=f.__batchRequests,c="",a,h;for(a=0,h=d.length;a<h;a++)c+=gb(b,false)+Zc(d[a],e);c+=gb(b,true);var i=e.contentType.properties;i.boundary=b;return c},gb=function(b,c){var a="\r\n--"+b;if(c)a+="--";return a+"\r\n"},Zc=function(f,e,h){var d=f.__changeRequests,a;if(x(d)){if(h)throw{message:"Not Supported: change set nested in other change set"};var c=Rc("changeset_");a="Content-Type: "+bb+"; boundary="+c+"\r\n";var b,g;for(b=0,g=d.length;b<g;b++)a+=gb(c,false)+Zc(d[b],e,true);a+=gb(c,true)}else{a="Content-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\n";Yc(f,qd(e),{metadata:e.metadata});a+=kf(f)}return a},kf=function(a){var b=(a.method?a.method:"GET")+" "+a.requestUri+" HTTP/1.1\r\n";for(var c in a.headers)if(a.headers[c])b=b+c+": "+a.headers[c]+"\r\n";b+="\r\n";if(a.body)b+=a.body;return b};c.batchHandler=P(mf,Ge,bb,C);var wd=[c.jsonHandler,c.atomHandler,c.xmlHandler,c.textHandler],Oc=function(d,c,e){var a,b;for(a=0,b=wd.length;a<b&&!wd[a][d](c,e);a++);if(a===b)throw{message:"no handler for data"};};c.defaultSuccess=function(a){b.alert(b.JSON.stringify(a))};c.defaultError=kb;c.defaultHandler={read:function(a,b){a&&w(a.body)&&a.headers["Content-Type"]&&Oc("read",a,b)},write:function(b,a){Oc("write",b,a)},maxDataServiceVersion:C,accept:"application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1"};c.defaultMetadata=[];c.read=function(a,g,h,f,d,e){var b;if(a instanceof String||typeof a==="string")b={requestUri:a};else b=a;return c.request(b,g,h,f,d,e)};c.request=function(a,g,d,b,e,f){if(!g)g=c.defaultSuccess;if(!d)d=c.defaultError;if(!b)b=c.defaultHandler;if(!e)e=c.defaultHttpClient;if(!f)f=c.defaultMetadata;a.recognizeDates=B(a.recognizeDates,c.jsonHandler.recognizeDates);a.callbackParameterName=B(a.callbackParameterName,c.defaultHttpClient.callbackParameterName);a.formatQueryString=B(a.formatQueryString,c.defaultHttpClient.formatQueryString);a.enableJsonpCallback=B(a.enableJsonpCallback,c.defaultHttpClient.enableJsonpCallback);var h={metadata:f,recognizeDates:a.recognizeDates,callbackParameterName:a.callbackParameterName,formatQueryString:a.formatQueryString,enableJsonpCallback:a.enableJsonpCallback};try{Yc(a,b,h);return Ve(a,g,d,b,e,h)}catch(i){d(i)}};c.batchHandler.partHandler=c.defaultHandler;var p=b.localStorage,ne=function(){var a={v:this.valueOf(),t:"[object Date]"};for(var b in this)a[b]=this[b];return a},oe=function(d,a){if(a&&a.t==="[object Date]"){var c=new Date(a.v);for(var b in a)if(b!=="t"&&b!=="v")c[b]=a[b];a=c}return a},jb=function(a,b){return a.name+"#!#"+b},tc=function(a,b){return b.replace(a.name+"#!#","")},h=function(a){this.name=a};h.create=function(a){if(h.isSupported())return new h(a);throw{message:"Web Storage not supported by the browser"};};h.isSupported=function(){return!!p};h.prototype.add=function(b,f,c,a){a=a||this.defaultError;var d=this;this.contains(b,function(g){if(!g)d.addOrUpdate(b,f,c,a);else e(a,{message:"key already exists",key:b})},a)};h.prototype.addOrUpdate=function(g,f,j,c){c=c||this.defaultError;if(g instanceof Array)c({message:"Array of keys not supported"});else{var i=jb(this,g),h=Date.prototype.toJSON;try{var d=f;if(d!==a){Date.prototype.toJSON=ne;d=b.JSON.stringify(f)}p.setItem(i,d);e(j,g,f)}catch(k){if(k.code===22||k.number===2147942414)e(c,{name:"QUOTA_EXCEEDED_ERR",error:k});else e(c,k)}finally{Date.prototype.toJSON=h}}};h.prototype.clear=function(f,b){b=b||this.defaultError;try{var d=0,c=p.length;while(c>0&&d<c){var a=p.key(d),g=tc(this,a);if(a!==g){p.removeItem(a);c=p.length}else d++}e(f)}catch(h){e(b,h)}};h.prototype.close=function(){};h.prototype.contains=function(f,c,a){a=a||this.defaultError;try{var b=jb(this,f),d=p.getItem(b);e(c,d!==null)}catch(g){e(a,g)}};h.prototype.defaultError=kb;h.prototype.getAllKeys=function(h,b){b=b||this.defaultError;var d=[],a,g;try{for(a=0,g=p.length;a<g;a++){var c=p.key(a),f=tc(this,c);c!==f&&d.push(f)}e(h,d)}catch(i){e(b,i)}};h.prototype.mechanism="dom";h.prototype.read=function(f,h,d){d=d||this.defaultError;if(f instanceof Array)d({message:"Array of keys not supported"});else try{var g=jb(this,f),c=p.getItem(g);if(c!==null&&c!=="undefined")c=b.JSON.parse(c,oe);else c=a;e(h,f,c)}catch(i){e(d,i)}};h.prototype.remove=function(b,d,a){a=a||this.defaultError;if(b instanceof Array)a({message:"Batches not supported"});else try{var c=jb(this,b);p.removeItem(c);e(d)}catch(f){e(a,f)}};h.prototype.update=function(b,f,c,a){a=a||this.defaultError;var d=this;this.contains(b,function(g){if(g)d.addOrUpdate(b,f,c,a);else e(a,{message:"key not found",key:b})},a)};var id=b.mozIndexedDB,A=b.IDBTransaction,od=b.IDBKeyRange,r=function(b,a){return function(c){if(c.code===11)c={name:"QUOTA_EXCEEDED_ERR",error:c};if(b)b(c);else a&&a(c)}},z=function(c,e,d,h){var b=c.name,a=c.db,f=r(h,c.defaultError);if(a)d(a.transaction(b,e));else{var g=id.open("_datajs_"+b);g.onsuccess=function(h){a=c.db=h.target.result;if(!a.objectStoreNames.contains(b)){var g=a.setVersion("1.0");g.onsuccess=function(){a.createObjectStore(b,null,false);d(a.transaction(b,e))};g.onerror=f;g.onblocked=f}else d(a.transaction(b,e))};g.onerror=r(h,this.defaultError)}},i=function(a){this.name=a};i.create=function(a){if(i.isSupported())return new i(a);throw{message:"IndexedDB is not supported on this browser"};};i.isSupported=function(){return!!id};i.prototype.add=function(c,d,e,f){var h=this.name,g=this.defaultError,b=[],a=[];if(c instanceof Array){b=c;a=d}else{b=[c];a=[d]}z(this,A.READ_WRITE,function(j){j.onabort=r(f,g);j.oncomplete=function(){if(c instanceof Array)e(b,a);else e(c,d)};for(var i=0;i<b.length&&i<a.length;i++)j.objectStore(h).add(a[i],b[i])},f)};i.prototype.addOrUpdate=function(c,d,e,f){var h=this.name,g=this.defaultError,b=[],a=[];if(c instanceof Array){b=c;a=d}else{b=[c];a=[d]}z(this,A.READ_WRITE,function(j){j.onabort=r(f,g);j.oncomplete=function(){if(c instanceof Array)e(b,a);else e(c,d)};for(var i=0;i<b.length&&i<a.length;i++)j.objectStore(h).put(a[i],b[i])},f)};i.prototype.clear=function(c,a){var d=this.name,b=this.defaultError;z(this,A.READ_WRITE,function(e){e.onerror=r(a,b);e.oncomplete=function(){c()};e.objectStore(d).clear()},a)};i.prototype.close=function(){if(this.db){this.db.close();this.db=null}};i.prototype.contains=function(f,d,b){var e=this.name,c=this.defaultError;z(this,A.READ_ONLY,function(g){var h=g.objectStore(e).openCursor(od.only(f));g.oncomplete=function(){d(h.result!==a)};g.onerror=r(b,c)},b)};i.prototype.defaultError=kb;i.prototype.getAllKeys=function(c,a){var d=this.name,b=this.defaultError;z(this,A.READ_ONLY,function(e){var g=[];e.oncomplete=function(){c(g)};var f=e.objectStore(d).openCursor();f.onerror=r(a,b);f.onsuccess=function(b){var a=b.target.result;if(a){g.push(a.key);a["continue"].call(a)}}},a)};i.prototype.mechanism="indexeddb";i.prototype.read=function(b,c,d){var f=this.name,e=this.defaultError,a=b instanceof Array?b:[b];z(this,A.READ_WRITE,function(g){var h=[];g.onerror=r(d,e);g.oncomplete=function(){if(b instanceof Array)c(a,h);else c(a[0],h[0])};for(var i=0;i<a.length;i++){var j=g.objectStore(f),k=j["get"].call(j,a[i]);k.onsuccess=function(a){h.push(a.target.result)}}},d)};i.prototype.remove=function(a,e,b){var f=this.name,d=this.defaultError,c=a instanceof Array?a:[a];z(this,A.READ_WRITE,function(a){a.onerror=r(b,d);a.oncomplete=function(){e()};for(var g=0;g<c.length;g++){var h=a.objectStore(f);h["delete"].call(h,c[g])}},b)};i.prototype.update=function(c,d,e,f){var h=this.name,g=this.defaultError,a=[],b=[];if(c instanceof Array){a=c;b=d}else{a=[c];b=[d]}z(this,A.READ_WRITE,function(j){j.onabort=r(f,g);j.oncomplete=function(){if(c instanceof Array)e(a,b);else e(c,d)};for(var i=0;i<a.length&&i<b.length;i++){var k=j.objectStore(h).openCursor(od.only(a[i]));k.pair={key:a[i],value:b[i]};k.onsuccess=function(b){var a=b.target.result;if(a)a.update(b.target.pair.value);else j.abort()}}},f)};var G=function(h){var g=[],c=[],b={};this.name=h;var d=function(a){return a||this.defaultError},f=function(c,d){var b;if(c instanceof Array)b="Array of keys not supported";if(c===a||c===null)b="Invalid key";if(b){e(d,{message:b});return false}return true};this.add=function(c,g,e,a){a=d(a);if(f(c,a))if(!b.hasOwnProperty(c))this.addOrUpdate(c,g,e,a);else a({message:"key already exists",key:c})};this.addOrUpdate=function(i,k,l,j){j=d(j);if(f(i,j)){var h=b[i];if(h===a)if(g.length>0)h=g.splice(0,1);else h=c.length;c[h]=k;b[i]=h;e(l,i,k)}};this.clear=function(a){c=[];b={};g=[];e(a)};this.contains=function(d,c){var a=b.hasOwnProperty(d);e(c,a)};this.getAllKeys=function(c){var a=[];for(var d in b)a.push(d);e(c,a)};this.read=function(g,h,a){a=d(a);if(f(g,a)){var i=b[g];e(h,g,c[i])}};this.remove=function(j,k,i){i=d(i);if(f(j,i)){var h=b[j];if(h!==a){if(h===c.length-1)c.pop();else{c[h]=a;g.push(h)}delete b[j];if(c.length===0)g=[]}e(k)}};this.update=function(c,g,e,a){a=d(a);if(f(c,a))if(b.hasOwnProperty(c))this.addOrUpdate(c,g,e,a);else a({message:"key not found",key:c})}};G.create=function(a){return new G(a)};G.isSupported=function(){return true};G.prototype.close=function(){};G.prototype.defaultError=kb;G.prototype.mechanism="memory";var wf={indexeddb:i,dom:h,memory:G};db.defaultStoreMechanism="best";db.createStore=function(c,a){if(!a)a=db.defaultStoreMechanism;if(a==="best")a=h.isSupported()?"dom":"memory";var b=wf[a];if(b)return b.create(c);throw{message:"Failed to create store",name:c,mechanism:a};};var of=function(a,c,b){return function(){a[c].apply(a,arguments);return b}},N=function(){this._arguments=a;this._done=a;this._fail=a;this._resolved=false;this._rejected=false};N.prototype={then:function(a,b){if(a)if(!this._done)this._done=[a];else this._done.push(a);if(b)if(!this._fail)this._fail=[b];else this._fail.push(b);if(this._resolved)this.resolve.apply(this,this._arguments);else this._rejected&&this.reject.apply(this,this._arguments);return this},resolve:function(){if(this._done){var b,c;for(b=0,c=this._done.length;b<c;b++)this._done[b].apply(null,arguments);this._done=a;this._resolved=false;this._arguments=a}else{this._resolved=true;this._arguments=arguments}},reject:function(){if(this._fail){var b,c;for(b=0,c=this._fail.length;b<c;b++)this._fail[b].apply(null,arguments);this._fail=a;this._rejected=false;this._arguments=a}else{this._rejected=true;this._arguments=arguments}},promise:function(){var a={};a.then=of(this,"then",a);return a}};var mb=function(){return b.jQuery&&b.jQuery.Deferred?new b.jQuery.Deferred:new N},se=function(a,b){var c=a.indexOf("?")>=0?"&":"?";return a+c+b},Ue=function(a,d){var b=a.indexOf("?"),c="";if(b>=0){c=a.substr(b);a=a.substr(0,b)}if(a[a.length-1]!=="/")a+="/";return a+d+c},zc=function(b,a){return{method:"GET",requestUri:b,user:a.user,password:a.password,enableJsonpCallback:a.enableJsonpCallback,callbackParameterName:a.callbackParameterName,formatQueryString:a.formatQueryString}},Of=function(d,c){var e=-1,b=d.indexOf("?");if(b!==-1){var a=d.indexOf("?"+c+"=",b);if(a===-1)a=d.indexOf("&"+c+"=",b);if(a!==-1)e=a+c.length+2}return e},hf=function(e,a,c,d){return rc(e,a,[],c,d)},rc=function(i,b,d,f,g){var h=zc(i,b),e=c.request(h,function(a){var c=a.__next,h=a.results;d=d.concat(h);if(c)e=rc(c,b,d,f,g);else f(d)},g,a,b.httpClient,b.metadata);return{abort:function(){e.abort()}}},Be=function(f){var b=this,e=f.source;b.identifier=Ae(encodeURI(decodeURI(e)));b.options=f;b.count=function(h,g){var f=b.options;return c.request(zc(Ue(e,"$count"),f),function(b){var a=d(b.toString());if(isNaN(a))g({message:"Count is NaN",count:a});else h(a)},g,a,f.httpClient,f.metadata)};b.read=function(g,d,c,f){var a="$skip="+g+"&$top="+d;return hf(se(e,a),b.options,c,f)};return b},rf=function(a,b){var c=Ie(a,b);if(c){var d=c.i-b.i,e=d+(a.c-a.d.length);a.d=a.d.concat(b.d.slice(d,e))}},Ie=function(a,b){var f=a.i+a.c,g=b.i+b.c,c=a.i>b.i?a.i:b.i,d=f<g?f:g,e;if(d>=c)e={i:c,c:d-c};return e},Fc=function(b,c){if(b===a||typeof b!=="number")throw{message:"'"+c+"' must be a number."};if(isNaN(b)||b<0||!isFinite(b))throw{message:"'"+c+"' must be greater than or equal to zero."};},Fd=function(b,c){if(b!==a){if(typeof b!=="number")throw{message:"'"+c+"' must be a number."};if(isNaN(b)||b<=0||!isFinite(b))throw{message:"'"+c+"' must be greater than zero."};}},ic=function(b,c){if(b!==a&&(typeof b!=="number"||isNaN(b)||!isFinite(b)))throw{message:"'"+c+"' must be a number."};},Pb=function(b,d){var a,c;for(a=0,c=b.length;a<c;a++)if(b[a]===d){b.splice(a,1);return true}return false},H=function(a,b){for(var c in b)a[c]=b[c];return a},hd=function(a){var b=0,d=typeof a;if(d==="object"&&a)for(var c in a)b+=c.length*2+hd(a[c]);else if(d==="string")b=a.length*2;else b=8;return b},sc=function(a,c,b){a=Math.floor(a/b)*b;c=Math.ceil((c+1)/b)*b;return{i:a,c:c-a}},ib="destroy",E="idle",Ec="init",Jb="read",Bb="prefetch",Hb="write",W="cancel",y="end",Ab="error",D="start",qc="wait",uc="clear",ab="done",Z="local",Pc="save",Cc="source",I=function(c,i,g,k,j,l,h){var d,e,a=this;a.p=i;a.i=k;a.c=j;a.d=l;a.s=D;a.canceled=false;a.pending=h;a.oncomplete=null;a.cancel=function(){if(!g)return;var c=a.s;if(c!==Ab&&c!==y&&c!==W){a.canceled=true;b(W,d)}};a.complete=function(){b(y,d)};a.error=function(c){!a.canceled&&b(Ab,c)};a.run=function(b){e=b;a.transition(a.s,d)};a.wait=function(a){b(qc,a)};var f=function(d,e,f){switch(d){case D:e!==Ec&&c(a,d,e,f);break;case qc:c(a,d,e,f);break;case W:c(a,d,e,f);a.fireCanceled();b(y);break;case Ab:c(a,d,e,f);a.canceled=true;a.fireRejected(f);b(y);break;case y:if(a.oncomplete)a.oncomplete(a);!a.canceled&&a.fireResolved();c(a,d,e,f);break;default:c(a,d,e,f)}},b=function(b,c){a.s=b;d=c;f(b,e,c)};a.transition=b;return a};I.prototype.fireResolved=function(){var a=this.p;if(a){this.p=null;a.resolve(this.d)}};I.prototype.fireRejected=function(b){var a=this.p;if(a){this.p=null;a.reject(b)}};I.prototype.fireCanceled=function(){this.fireRejected({canceled:true,message:"Operation canceled"})};var yf=function(j){var z=Ec,p={counts:0,netReads:0,prefetches:0,cacheReads:0},k=[],s=[],n=[],u=0,m=false,t=Mb(j.cacheSize,1048576),l=0,i=0,r=0,v=t===0,c=Mb(j.pageSize,50),C=Mb(j.prefetchSize,c),P="1.0",g,A=0,o=j.source;if(typeof o==="string")o=new Be(j);o.options=j;var q=db.createStore(j.name,j.mechanism),f=this;f.onidle=j.idle;f.stats=p;f.count=function(){if(g)throw g;var a=mb(),c=false;if(m){e(function(){a.resolve(l)});return a.promise()}var b=o.count(function(c){b=null;p.counts++;a.resolve(c)},function(d){b=null;a.reject(H(d,{canceled:c}))});return H(a.promise(),{cancel:function(){if(b){c=true;b.abort();b=null}}})};f.clear=function(){if(g)throw g;if(k.length===0){var a=mb(),b=new I(S,a,false);B(b,k);return a.promise()}return k[0].p};f.filterForward=function(c,b,a){return Q(c,b,a,false)};f.filterBack=function(c,b,a){return Q(c,b,a,true)};f.readRange=function(c,b){Fc(c,"index");Fc(b,"count");if(g)throw g;var a=mb(),d=new I(U,a,true,c,b,[],0);B(d,s);return H(a.promise(),{cancel:function(){d.cancel()}})};f.ToObservable=f.toObservable=function(){if(!b.Rx||!b.Rx.Observable)throw{message:"Rx library not available - include rx.js"};if(g)throw g;return b.Rx.Observable.CreateWithDisposable(function(d){var a=false,b=0,g=function(b){!a&&d.OnError(b)},e=function(i){if(!a){var h,j;for(h=0,j=i.length;h<j;h++)d.OnNext(i[h]);if(i.length<c)d.OnCompleted();else{b+=c;f.readRange(b,c).then(e,g)}}};f.readRange(b,c).then(e,g);return{Dispose:function(){a=true}}})};var x=function(a){return function(d){g={message:a,error:d};var b,c;for(b=0,c=s.length;b<c;b++)s[b].fireRejected(g);for(b=0,c=k.length;b<c;b++)k[b].fireRejected(g);s=k=null}},h=function(c){if(c!==z){z=c;var b=k.concat(s,n),a,d;for(a=0,d=b.length;a<d;a++)b[a].run(z)}},M=function(){var a=new N;q.clear(function(){u=0;m=false;l=0;i=0;r=0;v=t===0;p={counts:0,netReads:0,prefetches:0,cacheReads:0};f.stats=p;q.close();a.resolve()},function(b){a.reject(b)});return a},T=function(a){var b=Pb(k,a);if(!b){b=Pb(s,a);!b&&Pb(n,a)}A--;h(E)},V=function(d){var a=new N,e=false,b=o.read(d,c,function(b){var c={i:d,c:b.length,d:b};a.resolve(c)},function(b){a.reject(b)});return H(a,{cancel:function(){if(b){b.abort();e=true;b=null}}})},Q=function(a,b,p,e){a=d(a);b=d(b);if(isNaN(a))throw{message:"'index' must be a valid number.",index:a};if(isNaN(b))throw{message:"'count' must be a valid number.",count:b};if(g)throw g;a=Math.max(a,0);var j=mb(),h=[],l=false,k=null,m=function(a,d){if(!l)if(b>=0&&h.length>=b)j.resolve(h);else k=f.readRange(a,d).then(function(g){for(var f=0,l=g.length;f<l&&(b<0||h.length<b);f++){var i=e?l-f-1:f,n=g[i];if(p(n)){var k={index:a+i,item:n};e?h.unshift(k):h.push(k)}}if(!e&&g.length<d||e&&a<=0)j.resolve(h);else{var o=e?Math.max(a-c,0):a+d;m(o,c)}},function(a){j.reject(a)})},i=sc(a,a,c),o=e?i.i:a,n=e?a-i.i+1:i.i+i.c-a;m(o,n);return H(j.promise(),{cancel:function(){k&&k.cancel();l=true}})},O=function(){f.onidle&&A===0&&f.onidle()},X=function(a){if(m||C===0||v)return;if(n.length===0||n[0]&&n[0].c!==-1){var b=new I(R,null,true,a,C,null,C);B(b,n)}},B=function(a,b){a.oncomplete=T;b.push(a);A++;a.run(z)},Y=function(e){var c=false,b=H(new N,{cancel:function(){c=true}}),d=J(b,"Read page from store failure");q.contains(e,function(f){if(c)return;if(f){q.read(e,function(e,d){!c&&b.resolve(d!==a,d)},d);return}b.resolve(false)},d);return b},bb=function(g,a){var f=false,b=H(new N,{cancel:function(){f=true}}),d=J(b,"Save page to store failure"),c=function(){b.resolve(true)};if(a.c>0){var e=hd(a);v=t>=0&&t<u+e;if(!v)q.addOrUpdate(g,a,function(){L(a,e);F(c,d)},d);else c()}else{L(a,0);F(c,d)}return b},F=function(b,d){var a={actualCacheSize:u,allDataLocal:m,cacheSize:t,collectionCount:l,highestSavedPage:i,highestSavedPageSize:r,pageSize:c,sourceId:o.identifier,version:P};q.addOrUpdate("__settings",a,b,d)},J=function(a){return function(){a.resolve(false)}},L=function(d,e){var a=d.c,b=d.i;if(a===0){if(i===b-c)l=i+r}else{i=Math.max(i,b);if(i===b)r=a;u+=e;if(a<c&&!l)l=b+a}if(!m&&l===i+r)m=true},K=function(d,b,e,a){var c=d.canceled&&b!==y;if(c)if(b===W)a&&a.cancel&&a.cancel();return c},S=function(a,b,c){var d=a.transition;if(c!==ib){h(ib);return true}switch(b){case D:d(uc);break;case y:O();break;case uc:M().then(function(){a.complete()});a.wait();break;default:return false}return true},R=function(a,f,b,e){if(!K(a,f,b,e)){var g=a.transition;if(b!==Bb){if(b===ib)f!==W&&a.cancel();else b===E&&h(Bb);return true}switch(f){case D:n[0]===a&&g(Z,a.i);break;case ab:var d=a.pending;if(d>0)d-=Math.min(d,e.c);if(m||d===0||e.c<c||v)a.complete();else{a.pending=d;g(Z,e.i+c)}break;default:return G(a,f,b,e,true)}}return true},U=function(a,e,b,d){if(!K(a,e,b,d)){var f=a.transition;if(b!==Jb&&e!==D){if(b===ib)e!==D&&a.cancel();else b!==Hb&&h(Jb);return true}switch(e){case D:if(b===E||b===Bb){h(Jb);if(a.c>0){var g=sc(a.i,a.c,c);f(Z,g.i)}else f(ab,a)}break;case ab:rf(a,d);var i=a.d.length;if(a.c===i||d.c<c){p.cacheReads++;X(d.i+d.c);a.complete()}else f(Z,d.i+c);break;default:return G(a,e,b,d,false)}}return true},G=function(a,e,g,c,f){var i=a.error,d=a.transition,j=a.wait,b;switch(e){case y:O();break;case Z:b=Y(c).then(function(b,e){if(!a.canceled)if(b)d(ab,e);else d(Cc,c)});break;case Cc:b=V(c).then(function(b){if(!a.canceled){if(f)p.prefetches++;else p.netReads++;d(Pc,b)}},i);break;case Pc:if(g!==Hb){h(Hb);b=bb(c.i,c).then(function(b){if(!a.canceled){if(!b&&f)a.pending=0;d(ab,c)}h(E)})}break;default:return false}if(b)if(a.canceled)b.cancel();else a.s===e&&j(b);return true};q.read("__settings",function(d,a){if(w(a)){var b=a.version;if(!b||b.indexOf("1.")!==0){x("Unsupported cache store version "+b)();return}if(c!==a.pageSize||o.identifier!==a.sourceId)M().then(function(){h(E)},x("Unable to clear store during initialization"));else{u=a.actualCacheSize;m=a.allDataLocal;t=a.cacheSize;l=a.collectionCount;i=a.highestSavedPage;r=a.highestSavedPageSize;P=b;h(E)}}else F(function(){h(E)},x("Unable to write settings during initialization."))},x("Unable to read settings from store."));return f};db.createDataCache=function(a){Fd(a.pageSize,"pageSize");ic(a.cacheSize,"cacheSize");ic(a.prefetchSize,"prefetchSize");if(!w(a.name))throw{message:"Undefined or null name",options:a};if(!w(a.source))throw{message:"Undefined source",options:a};return new yf(a)}})(this)