//>>built
define("dojox/xmpp/bosh",["dijit","dojo","dojox","dojo/require!dojo/io/script,dojo/io/iframe,dojox/xml/parser"],function(l,d,f){d.provide("dojox.xmpp.bosh");d.require("dojo.io.script");d.require("dojo.io.iframe");d.require("dojox.xml.parser");f.xmpp.bosh={transportIframes:[],initialize:function(a){this.transportIframes=[];for(var b=f._scopeName+".xmpp.bosh",c=d.connect(d.getObject(b),"_iframeOnload",this,function(k){0==k&&(a.load(),d.disconnect(c))}),e=0;e<a.iframes;e++){var g="xmpp-transport-"+e,
h=d.byId("xmpp-transport-"+e);h&&(window[g]&&(window[g]=null),window.frames[g]&&(window.frames[g]=null),d.destroy(h));h=d.io.iframe.create("xmpp-transport-"+e,b+"._iframeOnload("+e+");");this.transportIframes.push(h)}},_iframeOnload:function(a){d.io.iframe.doc(d.byId("xmpp-transport-"+a)).write("\x3cscript\x3evar isLoaded\x3dtrue; var rid\x3d0; var transmiting\x3dfalse; function _BOSH_(msg) { transmiting\x3dfalse; parent.dojox.xmpp.bosh.handle(msg, rid); } \x3c/script\x3e")},findOpenIframe:function(){for(var a=
0;a<this.transportIframes.length;a++){var b=this.transportIframes[a],c=b.contentWindow;if(c.isLoaded&&!c.transmiting)return b}return!1},handle:function(a,b){var c=this["rid"+b],e=f.xml.parser.parse(a,"text/xml");e?c.ioArgs.xmppMessage=e:c.errback(Error("Received bad document from server: "+a))},get:function(a){var b=this.findOpenIframe(),c=d.io.iframe.doc(b);a.frameDoc=c;a=this._makeScriptDeferred(a);var e=a.ioArgs;b.contentWindow.rid=e.rid;b.contentWindow.transmiting=!0;d._ioAddQueryToUrl(e);d._ioNotifyStart(a);
d.io.script.attach(e.id,e.url,c);d._ioWatch(a,this._validCheck,this._ioCheck,this._resHandle);return a},remove:function(a,b){d.destroy(d.byId(a,b));this[a]&&delete this[a]},_makeScriptDeferred:function(a){var b=d._ioSetArgs(a,this._deferredCancel,this._deferredOk,this._deferredError),c=b.ioArgs;c.id="rid"+a.rid;c.rid=a.rid;c.canDelete=!0;c.frameDoc=a.frameDoc;return this[c.id]=b},_deferredCancel:function(a){a.canceled=!0;a.ioArgs.canDelete&&f.xmpp.bosh._addDeadScript(a.ioArgs)},_deferredOk:function(a){a=
a.ioArgs;a.canDelete&&f.xmpp.bosh._addDeadScript(a);return a.xmppMessage||a},_deferredError:function(a,b){b.ioArgs.canDelete&&("timeout"==a.dojoType?f.xmpp.bosh.remove(b.ioArgs.id,b.ioArgs.frameDoc):f.xmpp.bosh._addDeadScript(b.ioArgs));return a},_deadScripts:[],_addDeadScript:function(a){f.xmpp.bosh._deadScripts.push({id:a.id,frameDoc:a.frameDoc});a.frameDoc=null},_validCheck:function(a){a=f.xmpp.bosh;var b=a._deadScripts;if(b&&0<b.length){for(var c=0;c<b.length;c++)a.remove(b[c].id,b[c].frameDoc),
b[c].frameDoc=null;f.xmpp.bosh._deadScripts=[]}return!0},_ioCheck:function(a){return a.ioArgs.xmppMessage?!0:!1},_resHandle:function(a){f.xmpp.bosh._ioCheck(a)?a.callback(a):a.errback(Error("inconceivable dojox.xmpp.bosh._resHandle error"))}}});