//Copyright © [Year(s)] Nokia Corporation and/or its subsidiary(-ies).

Fp.Ajax={Method:{POST:"POST",GET:"GET"},ExResponse:{JSON:"json",TEXT:"text"},JsonParse:(function(){var e="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)",j='(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))',i='(?:"'+j+'*")',d=new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|"+e+"|"+i+")","g"),k=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),g={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},c=new String(""),a="\\",f={"{":Object,"[":Array},b=Object.hasOwnProperty;function h(l,m,n){return m?g[m]:String.fromCharCode(parseInt(n,16));}return function(t,q){var o=t.match(d),v,u=o[0],l;if("{"===u){v={};}else{if("["===u){v=[];}else{throw new Error(u);}}var s,w,m,p=[v];for(m=1,l=o.length;m<l;++m){u=o[m];switch(u.charCodeAt(0)){default:w=p[0];w[s||w.length]=+(u);s=undefined;break;case 34:u=u.substring(1,u.length-1);if(u.indexOf(a)!==-1){u=u.replace(k,h);}w=p[0];if(!s){if(w instanceof Array){s=w.length;}else{s=u||c;break;}}w[s]=u;s=undefined;break;case 91:w=p[0];p.unshift(w[s||w.length]=[]);s=undefined;break;case 93:p.shift();break;case 102:w=p[0];w[s||w.length]=false;s=undefined;break;case 110:w=p[0];w[s||w.length]=null;s=undefined;break;case 116:w=p[0];w[s||w.length]=true;s=undefined;break;case 123:w=p[0];p.unshift(w[s||w.length]={});s=undefined;break;case 125:p.shift();break;}}if(p.length){throw new Error();}if(q){var r=function(B,A){var C=B[A],n=null,y,x,z;if(C&&typeof C==="object"){for(y in C){if(b.call(C,y)&&C!==B){x=r(C,y);if(x!==undefined){C[y]=x;}else{if(!n){n=[];}n.push(y);}}}if(n){for(z=n.length;--z>=0;){delete C[n[z]];}}}return q.call(B,A,C);};v=r({"":v},"");}return v;};})(),JsonToString:function(e){var d=typeof(e);if(d!="object"||e===null){if(d=="string"){e='"'+e+'"';}return String(e);}else{var f,b,c=[],a=(e&&e.constructor==Array);for(f in e){b=e[f];d=typeof(b);if(d=="string"){b='"'+b+'"';}else{if(d=="object"&&b!==null){b=Fp.Ajax.JsonToString(b);}}c.push((a?"":'"'+f+'":')+String(b));}return(a?"[":"{")+String(c)+(a?"]":"}");}}};Fp.Ajax.Request=function(b){var a=this;this.xhr=new XMLHttpRequest();this.xhr.onreadystatechange=function(){a._onLoad.call(a);};this.xhr.onerror=function(){if(a.timeoutRef){clearTimeout(a.timeoutRef);}a._onError.call(a);};this._open(b);};Fp.Ajax.Request.prototype.setHeader=function(a,b){this.xhr.setRequestHeader(a,b);};Fp.Ajax.Request.prototype.send=function(b){this.xhr.send(b);if(this.timeout){var a=this;this.timeoutRef=setTimeout(function(){a.xhr.abort();a.onTimeout();},this.timeout*1000);}};Fp.Ajax.Request.prototype.sendJson=function(a){this.xhr.send(Fp.Ajax.JsonToString(a));};Fp.Ajax.Request.prototype.sendJSON=Fp.Ajax.Request.prototype.sendJson;Fp.Ajax.Request.prototype._onLoad=function(){if(this.xhr.readyState==4){if(this.timeoutRef){clearTimeout(this.timeoutRef);}if(this.xhr.status>=200&&this.xhr.status<300){if(this.exRespType==Fp.Ajax.ExResponse.JSON){try{this.onSuccess(this.xhr.status,Fp.Ajax.JsonParse(this.xhr.responseText));}catch(a){this.onFailure(this.xhr.status,this.xhr.responseText);}}else{this.onSuccess(this.xhr.status,this.xhr.responseText);}}else{this.onFailure(this.xhr.status,this.xhr.responseText);}}};Fp.Ajax.Request.prototype._onError=function(){this.onFailure(this.xhr.status,this.xhr.responseText);};Fp.Ajax.Request.prototype._open=function(a){this.onSuccess=a.onSuccess||function(){};this.onFailure=a.onFailure||function(){};this.onTimeout=a.onTimeout||function(){};this.exRespType=a.exresp||Fp.Ajax.ExResponse.TEXT;this.timeout=a.timeout||0;if(a.url){this.xhr.open(a.method||"GET",a.url,a.async||true);this.setHeader("Content-Type","application/json");this.setHeader("Accept","application/json");this.setHeader("Accept-Language",a.lang||"en-gb");if(Fp.uuid){this.setHeader("X-Ovi-UUID",Fp.uuid);}}};