Registry.require(["helper","convert"],function(){var r=Registry.get("helper"),s=Registry.get("convert"),p={},v=function(b){var d=r.isLocalImage(b);return b&&4<b.length&&"http"==b.substr(0,4)||d},w={"user-agent":!0,referer:!0,origin:!0,host:!0,"proxy-connection":!0,"accept-encoding":!0,"accept-charset":!0},q=function(b,d,k){void 0===d&&(d={});void 0===k&&(k={});var l=function(a,c){if(d[a])d[a]("function"==typeof c?c():c)},f=function(a,c){d[a]&&(l(a,c),d[a]=null)},m=!(d.onload||d.onreadychange||d.onprogress||
d.onerror||d.ondone||d.ontimeout),e=new XMLHttpRequest,h=function(a){var c="",t=b.url;if(2<e.readyState&&(c=e.getAllResponseHeaders(),4==e.readyState)){c&&(c=c.replace(/TM-finalURL[0-9a-zA-Z]*\: .*[\r\n]{1,2}/,""));var d=e.getResponseHeader("TM-finalURL"+rea.runtime.short_id);d&&(t=d)}c={readyState:e.readyState,responseHeaders:c,finalUrl:t,status:4==e.readyState?e.status:0,statusText:4==e.readyState?e.statusText:""};a&&4==e.readyState?(e.responseType?(c.responseXML=null,c.responseText=null,c.responseType=
e.responseType):(c.responseXML=e.responseXML,c.responseText=e.responseText),c.response=e.response):(c.responseXML=null,c.responseText="",c.response=null);return c},n=function(a){a=h(!0);4==a.readyState&&200!=a.status&&0!=a.status&&0<b.retries?(b.retries--,q(b,d,k)):function(){if(b.convertBinary&&a.response){var c=a.responseType?a.responseType.toLowerCase():"";if("blob"==c){var e,d=new FileReader;d.onload=function(c){a.response=s.arrbuf2str(d.result);e()};d.readAsArrayBuffer(a.response);return{done:function(a){e=
a}}}"arraybuffer"==c?a.response=s.arrbuf2str(a.response):"json"==c&&(a.response=JSON.stringify(a.response))}return{done:function(a){a()}}}().done(function(){if(b.partialSize){var c=b.convertBinary&&a.response?a.response:a.responseText;a.response_types={};["response","responseText","responseXML"].forEach(function(c){a.response_types[c]=!!a[c];delete a[c]});c&&(c.length>b.partialSize?x(c):a.response_data=c)}f("onload",a);4==a.readyState&&f("ondone",a)})},x=function(a){(function(a,b){for(var e=[],d=
0,f=a.length;d<f;d+=b)e.push(a.slice(d,b+d));return e})(a,parseInt(b.partialSize)).forEach(function(a){l("onpartial",{partial:a})})},y=function(){var a=h();4==a.readyState&&200!=a.status&&0!=a.status&&0<b.retries?(b.retries--,q(b,d,k)):(f("onerror",a),f("ondone",a))},u=function(a,c,b){void 0===b&&(b={});try{var d=null,f=null;if(a.lengthComputable||0<a.total)d=a.loaded,f=a.total;else{var g=Number(r.getStringBetweenTags(c.responseHeaders.toLowerCase(),"content-length:","\n").trim()),h=e.responseText?
e.responseText.length:0;0==g&&(g=-1);d=a.loaded||h;f=a.total||g}b.lengthComputable=a.lengthComputable;b.loaded=d;b.done=d;b.position=d;b.total=f;b.totalSize=f}catch(k){}return b},z=function(a){l("onreadychange",function(){var b=h();b.progress=u(a,b);return b})},A=function(a){l("onprogress",function(){var b=h();return u(a,b,b)})},B=function(a){a=h();f("ontimeout");f("ondone",a)};m||(e.onload=n,e.onerror=y,e.ontimeout=B,e.onprogress=A,e.onreadystatechange=z);try{if(!k.internal&&!v(b.url))throw Error("Invalid scheme of url: "+
b.url);e.open(b.method,b.url,!m,b.user,b.password);if(b.headers)for(var g in b.headers)n=g,p.use&&w[g.toLowerCase()]&&(n=p.prefix+g),e.setRequestHeader(n,b.headers[g]);"undefined"!==typeof b.overrideMimeType&&e.overrideMimeType(b.overrideMimeType);"undefined"!==typeof b.responseType&&(e.responseType=b.responseType);"undefined"!==typeof b.timeout&&(e.timeout=b.timeout);"undefined"!==typeof b.data?e.send(b.data):e.send()}catch(C){if(console.error(C.stack),g={responseXML:"",responseText:"",response:null,
readyState:4,responseHeaders:"",status:403,statusText:"Forbidden"},f("onerror",g),f("ondone",g),m)return g}if(m)return h()};Registry.register("xmlhttprequest","0",{run:q,setWebRequest:function(b){p=b}})});
