/*
	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,v,K,p,E,m,F,L,A,n,G,M,B,t,C,H){b._xhrObj=C._create;var w=b.config;b.objectToQuery=p.objectToQuery;b.queryToObject=p.queryToObject;b.fieldToObject=m.fieldToObject;b.formToObject=m.toObject;b.formToQuery=m.toQuery;b.formToJson=m.toJson;b._blockAsync=!1;var u=b._contentHandlers=b.contentHandlers=
{text:function(a){return a.responseText},json:function(a){return A.fromJson(a.responseText||null)},"json-comment-filtered":function(a){a=a.responseText;var c=a.indexOf("/*"),g=a.lastIndexOf("*/");if(-1==c||-1==g)throw Error("JSON was not comment filtered");return A.fromJson(a.substring(c+2,g))},javascript:function(a){return b.eval(a.responseText)},xml:function(a){var c=a.responseXML;c&&v("dom-qsa2.1")&&!c.querySelectorAll&&v("dom-parser")&&(c=(new DOMParser).parseFromString(a.responseText,"application/xml"));
if(v("ie")&&(!c||!c.documentElement)){var g=function(h){return"MSXML"+h+".DOMDocument"};g=["Microsoft.XMLDOM",g(6),g(4),g(3),g(2)];G.some(g,function(h){try{var d=new ActiveXObject(h);d.async=!1;d.loadXML(a.responseText);c=d}catch(k){return!1}return!0})}return c},"json-comment-optional":function(a){return a.responseText&&/^[^{\[]*\/\*/.test(a.responseText)?u["json-comment-filtered"](a):u.json(a)}};b._ioSetArgs=function(a,c,g,h){var d={args:a,url:a.url},k=null;if(a.form){k=E.byId(a.form);var l=k.getAttributeNode("action");
d.url=d.url||(l?l.value:b.doc?b.doc.URL:null);k=m.toObject(k)}l={};k&&n.mixin(l,k);a.content&&n.mixin(l,a.content);a.preventCache&&(l["dojo.preventCache"]=(new Date).valueOf());d.query=p.objectToQuery(l);d.handleAs=a.handleAs||"text";var e=new F(function(f){f.canceled=!0;c&&c(f);var q=f.ioArgs.error;q||(q=Error("request cancelled"),q.dojoType="cancel",f.ioArgs.error=q);return q});e.addCallback(g);var x=a.load;x&&n.isFunction(x)&&e.addCallback(function(f){return x.call(a,f,d)});var y=a.error;y&&n.isFunction(y)&&
e.addErrback(function(f){return y.call(a,f,d)});var z=a.handle;z&&n.isFunction(z)&&e.addBoth(function(f){return z.call(a,f,d)});e.addErrback(function(f){return h(f,e)});w.ioPublish&&b.publish&&!1!==d.args.ioPublish&&(e.addCallbacks(function(f){b.publish("/dojo/io/load",[e,f]);return f},function(f){b.publish("/dojo/io/error",[e,f]);return f}),e.addBoth(function(f){b.publish("/dojo/io/done",[e,f]);return f}));e.ioArgs=d;return e};var I=function(a){a=u[a.ioArgs.handleAs](a.ioArgs.xhr);return void 0===
a?null:a},J=function(a,c){return a},D=function(a){0>=r&&(r=0,w.ioPublish&&b.publish&&(!a||a&&!1!==a.ioArgs.args.ioPublish)&&b.publish("/dojo/io/stop"))},r=0;B.after(t,"_onAction",function(){--r});B.after(t,"_onInFlight",D);b._ioCancelAll=t.cancelAll;b._ioNotifyStart=function(a){w.ioPublish&&b.publish&&!1!==a.ioArgs.args.ioPublish&&(r||b.publish("/dojo/io/start"),r+=1,b.publish("/dojo/io/send",[a]))};b._ioWatch=function(a,c,g,h){a.ioArgs.options=a.ioArgs.args;n.mixin(a,{response:a.ioArgs,isValid:function(d){return c(a)},
isReady:function(d){return g(a)},handleResponse:function(d){return h(a)}});t(a);D(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,g){var h=b._ioSetArgs(c,function(e){l&&l.cancel()},I,J),d=h.ioArgs;"postData"in c?d.query=c.postData:"putData"in c?d.query=c.putData:"rawBody"in c?d.query=c.rawBody:(2<arguments.length&&!g||-1==="POST|PUT".indexOf(a.toUpperCase()))&&b._ioAddQueryToUrl(d);var k={method:a,handleAs:"text",
timeout:c.timeout,withCredentials:c.withCredentials,ioArgs:d};"undefined"!==typeof c.headers&&(k.headers=c.headers);"undefined"!==typeof c.contentType&&(k.headers||(k.headers={}),k.headers["Content-Type"]=c.contentType);"undefined"!==typeof d.query&&(k.data=d.query);"undefined"!==typeof c.sync&&(k.sync=c.sync);b._ioNotifyStart(h);try{var l=C(d.url,k,!0)}catch(e){return h.cancel(),h}h.ioArgs.xhr=l.response.xhr;l.then(function(){h.resolve(h)}).otherwise(function(e){d.error=e;e.response&&(e.status=e.response.status,
e.responseText=e.response.text,e.xhr=e.response.xhr);h.reject(e)});return h};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 H.checkStatus(a.status)};b._getText=function(a){var c;b.xhrGet({url:a,sync:!0,load:function(g){c=g}});return c};n.mixin(b.xhr,{_xhrObj:b._xhrObj,fieldToObject:m.fieldToObject,
formToObject:m.toObject,objectToQuery:p.objectToQuery,formToQuery:m.toQuery,formToJson:m.toJson,queryToObject:p.queryToObject,contentHandlers:u,_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});