/*
	Copyright (c) 2004-2016, The JS Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/

//>>built
define("dojo/_base/xhr","./kernel ./sniff require ../io-query ../dom ../dom-form ./Deferred ./config ./json ./lang ./array ../on ../aspect ../request/watch ../request/xhr ../request/util".split(" "),function(b,k,G,q,z,m,A,B,v,p,C,H,w,r,x,D){b._xhrObj=x._create;var t=b.config;b.objectToQuery=q.objectToQuery;b.queryToObject=q.queryToObject;b.fieldToObject=m.fieldToObject;b.formToObject=m.toObject;b.formToQuery=m.toQuery;b.formToJson=m.toJson;b._blockAsync=!1;k.add("native-xhr2-blob",function(){if(k("native-xhr2")){var a=
new XMLHttpRequest;a.open("GET","/",!0);a.responseType="blob";var b=a.responseType;a.abort();return"blob"===b}});var g=b._contentHandlers=b.contentHandlers={text:function(a){return a.responseText},json:function(a){return v.fromJson(a.responseText||null)},"json-comment-filtered":function(a){B.useCommentedJson||console.warn("Consider using the standard mimetype:application/json. json-commenting can introduce security issues. To decrease the chances of hijacking, use the standard the 'json' handler and prefix your json with: {}\x26\x26\nUse djConfig.useCommentedJson\x3dtrue to turn off this message.");
a=a.responseText;var b=a.indexOf("/*"),h=a.lastIndexOf("*/");if(-1==b||-1==h)throw Error("JSON was not comment filtered");return v.fromJson(a.substring(b+2,h))},javascript:function(a){return b.eval(a.responseText)},xml:function(a){var b=a.responseXML;b&&k("dom-qsa2.1")&&!b.querySelectorAll&&k("dom-parser")&&(b=(new DOMParser).parseFromString(a.responseText,"application/xml"));if(k("ie")&&(!b||!b.documentElement)){var h=function(a){return"MSXML"+a+".DOMDocument"},h=["Microsoft.XMLDOM",h(6),h(4),h(3),
h(2)];C.some(h,function(c){try{var d=new ActiveXObject(c);d.async=!1;d.loadXML(a.responseText);b=d}catch(f){return!1}return!0})}return b},"json-comment-optional":function(a){return a.responseText&&/^[^{\[]*\/\*/.test(a.responseText)?g["json-comment-filtered"](a):g.json(a)}};k("native-xhr2")&&(g.arraybuffer=g.blob=g.document=function(a,b){return"blob"!==b.args.handleAs||k("native-xhr2-blob")?a.response:new Blob([a.response],{type:a.getResponseHeader("Content-Type")})});b._ioSetArgs=function(a,c,h,
k){var d={args:a,url:a.url},f=null;if(a.form){var f=z.byId(a.form),e=f.getAttributeNode("action");d.url=d.url||(e?e.value:b.doc?b.doc.URL:null);f=m.toObject(f)}e=[{}];f&&e.push(f);a.content&&e.push(a.content);a.preventCache&&e.push({"dojo.preventCache":(new Date).valueOf()});d.query=q.objectToQuery(p.mixin.apply(null,e));d.handleAs=a.handleAs||"text";var l=new A(function(a){a.canceled=!0;c&&c(a);var b=a.ioArgs.error;b||(b=Error("request cancelled"),b.dojoType="cancel",a.ioArgs.error=b);return b});
l.addCallback(h);var u=a.load;u&&p.isFunction(u)&&l.addCallback(function(b){return u.call(a,b,d)});var g=a.error;g&&p.isFunction(g)&&l.addErrback(function(b){return g.call(a,b,d)});var n=a.handle;n&&p.isFunction(n)&&l.addBoth(function(b){return n.call(a,b,d)});l.addErrback(function(a){return k(a,l)});t.ioPublish&&b.publish&&!1!==d.args.ioPublish&&(l.addCallbacks(function(a){b.publish("/dojo/io/load",[l,a]);return a},function(a){b.publish("/dojo/io/error",[l,a]);return a}),l.addBoth(function(a){b.publish("/dojo/io/done",
[l,a]);return a}));l.ioArgs=d;return l};var E=function(a){a=g[a.ioArgs.handleAs](a.ioArgs.xhr,a.ioArgs);return void 0===a?null:a},F=function(a,b){b.ioArgs.args.failOk||console.error(a);return a},y=function(a){0>=n&&(n=0,t.ioPublish&&b.publish&&(!a||a&&!1!==a.ioArgs.args.ioPublish)&&b.publish("/dojo/io/stop"))},n=0;w.after(r,"_onAction",function(){--n});w.after(r,"_onInFlight",y);b._ioCancelAll=r.cancelAll;b._ioNotifyStart=function(a){t.ioPublish&&b.publish&&!1!==a.ioArgs.args.ioPublish&&(n||b.publish("/dojo/io/start"),
n+=1,b.publish("/dojo/io/send",[a]))};b._ioWatch=function(a,b,h,k){a.ioArgs.options=a.ioArgs.args;p.mixin(a,{response:a.ioArgs,isValid:function(c){return b(a)},isReady:function(b){return h(a)},handleResponse:function(b){return k(a)}});r(a);y(a)};b._ioAddQueryToUrl=function(a){a.query.length&&(a.url+=(-1==a.url.indexOf("?")?"?":"\x26")+a.query,a.query=null)};b.xhr=function(a,c,h){var g,d=b._ioSetArgs(c,function(a){g&&g.cancel()},E,F),f=d.ioArgs;"postData"in c?f.query=c.postData:"putData"in c?f.query=
c.putData:"rawBody"in c?f.query=c.rawBody:(2<arguments.length&&!h||-1==="POST|PUT".indexOf(a.toUpperCase()))&&b._ioAddQueryToUrl(f);var e;k("native-xhr2")&&(e={arraybuffer:1,blob:1,document:1});e=k("native-xhr2")&&e[c.handleAs]?c.handleAs:"text";"blob"!==e||k("native-xhr2-blob")||(e="arraybuffer");e={method:a,handleAs:e,responseType:c.responseType,timeout:c.timeout,withCredentials:c.withCredentials,ioArgs:f};"undefined"!==typeof c.headers&&(e.headers=c.headers);"undefined"!==typeof c.contentType&&
(e.headers||(e.headers={}),e.headers["Content-Type"]=c.contentType);"undefined"!==typeof f.query&&(e.data=f.query);"undefined"!==typeof c.sync&&(e.sync=c.sync);b._ioNotifyStart(d);try{g=x(f.url,e,!0)}catch(l){return d.cancel(),d}d.ioArgs.xhr=g.response.xhr;g.then(function(){d.resolve(d)}).otherwise(function(a){f.error=a;a.response&&(a.status=a.response.status,a.responseText=a.response.text,a.xhr=a.response.xhr);d.reject(a)});return d};b.xhrGet=function(a){return b.xhr("GET",a)};b.rawXhrPost=b.xhrPost=
function(a){return b.xhr("POST",a,!0)};b.rawXhrPut=b.xhrPut=function(a){return b.xhr("PUT",a,!0)};b.xhrDelete=function(a){return b.xhr("DELETE",a)};b._isDocumentOk=function(a){return D.checkStatus(a.status)};b._getText=function(a){var c;b.xhrGet({url:a,sync:!0,load:function(a){c=a}});return c};p.mixin(b.xhr,{_xhrObj:b._xhrObj,fieldToObject:m.fieldToObject,formToObject:m.toObject,objectToQuery:q.objectToQuery,formToQuery:m.toQuery,formToJson:m.toJson,queryToObject:q.queryToObject,contentHandlers:g,
_ioSetArgs:b._ioSetArgs,_ioCancelAll:b._ioCancelAll,_ioNotifyStart:b._ioNotifyStart,_ioWatch:b._ioWatch,_ioAddQueryToUrl:b._ioAddQueryToUrl,_isDocumentOk:b._isDocumentOk,_getText:b._getText,get:b.xhrGet,post:b.xhrPost,put:b.xhrPut,del:b.xhrDelete});return b.xhr});