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


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dojox.socket"],["require","dojo.cookie"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dojox.socket"]){_4._hasResource["dojox.socket"]=true;_4.provide("dojox.socket");_4.require("dojo.cookie");var _7=window.WebSocket;function _8(_9){if(typeof _9=="string"){_9={url:_9};}return _7?_6.socket.WebSocket(_9,true):_6.socket.LongPoll(_9);};_6.socket=_8;_8.WebSocket=function(_a,_b){var ws=new _7(new _4._Url(document.baseURI.replace(/^http/i,"ws"),_a.url));ws.on=function(_c,_d){ws.addEventListener(_c,_d,true);};var _e;_4.connect(ws,"onopen",function(_f){_e=true;});_4.connect(ws,"onclose",function(_10){if(_e){return;}if(_b){_8.replace(ws,_6.socket.LongPoll(_a),true);}});return ws;};_8.replace=function(_11,_12,_13){_11.send=_4.hitch(_12,"send");_11.close=_4.hitch(_12,"close");if(_13){_14("open");}_4.forEach(["message","close","error"],_14);function _14(_15){(_12.addEventListener||_12.on).call(_12,_15,function(_16){var _17=document.createEvent("MessageEvent");_17.initMessageEvent(_16.type,false,false,_16.data,_16.origin,_16.lastEventId,_16.source);_11.dispatchEvent(_17);},true);};};_8.LongPoll=function(_18){var _19=false,_1a=true,_1b,_1c=[];var _1d={send:function(_1e){var _1f=_4.delegate(_18);_1f.rawBody=_1e;clearTimeout(_1b);var _20=_1a?(_1a=false)||_1d.firstRequest(_1f):_1d.transport(_1f);_1c.push(_20);_20.then(function(_21){_1d.readyState=1;_1c.splice(_4.indexOf(_1c,_20),1);if(!_1c.length){_1b=setTimeout(_29,_18.interval);}if(_21){_23("message",{data:_21},_20);}},function(_22){_1c.splice(_4.indexOf(_1c,_20),1);if(!_19){_23("error",{error:_22},_20);if(!_1c.length){_1d.readyState=3;_23("close",{wasClean:false},_20);}}});return _20;},close:function(){_1d.readyState=2;_19=true;for(var i=0;i<_1c.length;i++){_1c[i].cancel();}_1d.readyState=3;_23("close",{wasClean:true});},transport:_18.transport||_4.xhrPost,args:_18,url:_18.url,readyState:0,CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,dispatchEvent:function(_24){_23(_24.type,_24);},on:function(_25,_26){return _4.connect(this,"on"+_25,_26);},firstRequest:function(_27){var _28=(_27.headers||(_27.headers={}));_28.Pragma="start-long-poll";try{return this.transport(_27);}finally{delete _28.Pragma;}}};function _29(){if(_1d.readyState==0){_23("open",{});}if(!_1c.length){_1d.send();}};function _23(_2a,_2b,_2c){if(_1d["on"+_2a]){var _2d=document.createEvent("HTMLEvents");_2d.initEvent(_2a,false,false);_4.mixin(_2d,_2b);_2d.ioArgs=_2c&&_2c.ioArgs;_1d["on"+_2a](_2d);}};_1d.connect=_1d.on;setTimeout(_29);return _1d;};}}};});