if(!Function.prototype.bind){Function.prototype.bind=function(a){var b=this;return function(){return b.apply(a,arguments)}}}if(!Function.prototype.prependArg){Function.prototype.prependArg=function(c){var d=this;return function(){var a=[c];for(var b=0;b<arguments.length;b++)a.push(arguments[b]);return d.apply(this,a)}}}if(!Array.prototype.indexOf){Array.prototype.indexOf=function(a){var b=this.length;var c=Number(arguments[1])||0;c=(c<0)?Math.ceil(c):Math.floor(c);if(c<0)c+=b;for(;c<b;c++){if(c in this&&this[c]===a)return c}return-1}}function $build(a,b){return new Strophe.Builder(a,b)}function $msg(a){return new Strophe.Builder("message",a)}function $iq(a){return new Strophe.Builder("iq",a)}function $pres(a){return new Strophe.Builder("presence",a)}Strophe={NS:{HTTPBIND:"http://jabber.org/protocol/httpbind",BOSH:"urn:xmpp:xbosh",CLIENT:"jabber:client",AUTH:"jabber:iq:auth",ROSTER:"jabber:iq:roster",PROFILE:"jabber:iq:profile",DISCO_INFO:"http://jabber.org/protocol/disco#info",DISCO_ITEMS:"http://jabber.org/protocol/disco#items",MUC:"http://jabber.org/protocol/muc",SASL:"urn:ietf:params:xml:ns:xmpp-sasl",STREAM:"http://etherx.jabber.org/streams",BIND:"urn:ietf:params:xml:ns:xmpp-bind",SESSION:"urn:ietf:params:xml:ns:xmpp-session",VERSION:"jabber:iq:version",STANZAS:"urn:ietf:params:xml:ns:xmpp-stanzas"},addNamespace:function(a,b){Strophe.NS[a]=b},Status:{ERROR:0,CONNECTING:1,CONNFAIL:2,AUTHENTICATING:3,AUTHFAIL:4,CONNECTED:5,DISCONNECTED:6,DISCONNECTING:7},LogLevel:{DEBUG:0,INFO:1,WARN:2,ERROR:3,FATAL:4},ElementType:{NORMAL:1,TEXT:3},TIMEOUT:70,SECONDARY_TIMEOUT:7,forEachChild:function(a,b,c){var d,f;for(d=0;d<a.childNodes.length;d++){f=a.childNodes[d];if(f.nodeType==Strophe.ElementType.NORMAL&&(!b||this.isTagEqual(f,b))){c(f)}}},isTagEqual:function(a,b){return a.tagName.toLowerCase()==b.toLowerCase()},xmlElement:function(a){if(!a){return null}var b=null;if(window.ActiveXObject){b=new ActiveXObject("Microsoft.XMLDOM").createElement(a)}else{b=document.createElement(a)}if(b.tagName!=a)b.setAttribute("_h",a);var c,d;for(c=1;c<arguments.length;c++){if(!arguments[c]){continue}if(typeof(arguments[c])=="string"||typeof(arguments[c])=="number"){b.appendChild(Strophe.xmlTextNode(arguments[c]))}else if(typeof(arguments[c])=="object"&&typeof(arguments[c]['sort'])=="function"){for(d=0;d<arguments[c].length;d++){if(typeof(arguments[c][d])=="object"&&typeof(arguments[c][d]['sort'])=="function"){b.setAttribute(arguments[c][d][0],arguments[c][d][1])}}}}return b},xmlescape:function(a){a=a.replace(/\&/g,"&amp;");a=a.replace(/</g,"&lt;");a=a.replace(/>/g,"&gt;");return a},xmlTextNode:function(a){a=Strophe.xmlescape(a);if(window.ActiveXObject){return new ActiveXObject("Microsoft.XMLDOM").createTextNode(a)}else{return document.createTextNode(a)}},getText:function(a){if(!a)return null;var b="";if(a.childNodes.length===0&&a.nodeType==Strophe.ElementType.TEXT){b+=a.nodeValue}for(var c=0;c<a.childNodes.length;c++){if(a.childNodes[c].nodeType==Strophe.ElementType.TEXT){b+=a.childNodes[c].nodeValue}}return b},copyElement:function(a){var b,c;if(a.nodeType==Strophe.ElementType.NORMAL){c=Strophe.xmlElement(a.tagName);for(b=0;b<a.attributes.length;b++){c.setAttribute(a.attributes[b].nodeName.toLowerCase(),a.attributes[b].value)}for(b=0;b<a.childNodes.length;b++){c.appendChild(Strophe.copyElement(a.childNodes[b]))}}else if(a.nodeType==Strophe.ElementType.TEXT){c=Strophe.xmlTextNode(a.nodeValue)}return c},escapeJid:function(a){var b=a.split("@");if(b.length==1)return a;var c=b.splice(b.length-1,1)[0];b=b.join("@").replace(/^\s+|\s+$/g,'').replace(/\\/g,"\\5c").replace(/ /g,"\\20").replace(/\"/g,"\\22").replace(/\&/g,"\\26").replace(/\'/g,"\\27").replace(/\//g,"\\2f").replace(/:/g,"\\3a").replace(/</g,"\\3c").replace(/>/g,"\\3e").replace(/@/g,"\\40");return[b,c].join("@")},unescapeJid:function(a){return a.replace(/\\20/g," ").replace(/\\22/g,'"').replace(/\\26/g,"&").replace(/\\27/g,"'").replace(/\\2f/g,"/").replace(/\\3a/g,":").replace(/\\3c/g,"<").replace(/\\3e/g,">").replace(/\\40/g,"@").replace(/\\5c/g,"\\")},getNodeFromJid:function(a){if(a.indexOf("@")<0)return null;return Strophe.escapeJid(a).split("@")[0]},getDomainFromJid:function(a){var b=Strophe.escapeJid(Strophe.getBareJidFromJid(a));if(b.indexOf("@")<0)return b;else return b.split("@")[1]},getResourceFromJid:function(a){var b=Strophe.escapeJid(a).split("/");if(b.length<2)return null;return b[1]},getBareJidFromJid:function(a){return this.escapeJid(a).split("/")[0]},log:function(a,b){return},debug:function(a){this.log(this.LogLevel.DEBUG,a)},info:function(a){this.log(this.LogLevel.INFO,a)},warn:function(a){this.log(this.LogLevel.WARN,a)},error:function(a){this.log(this.LogLevel.ERROR,a)},fatal:function(a){this.log(this.LogLevel.FATAL,a)},serialize:function(a){var b;if(!a)return null;if(typeof(a["tree"])==="function"){a=a.tree()}var c=a.nodeName;var d,f;if(a.getAttribute("_h")){c=a.getAttribute("_h")}b="<"+c;for(d=0;d<a.attributes.length;d++){if(a.attributes[d].nodeName!="_h"){b+=" "+a.attributes[d].nodeName.toLowerCase()+"='"+a.attributes[d].value.replace("'","&#39;").replace("&","&#x26;")+"'"}}if(a.childNodes.length>0){b+=">";for(d=0;d<a.childNodes.length;d++){f=a.childNodes[d];if(f.nodeType==Strophe.ElementType.NORMAL){b+=Strophe.serialize(f)}else if(f.nodeType==Strophe.ElementType.TEXT){b+=f.nodeValue}}b+="</"+c+">"}else{b+="/>"}return b},_s:0,_a:{},addConnectionPlugin:function(a,b){Strophe._a[a]=b}};Strophe.Builder=function(a,b){if(a=="presence"||a=="message"||a=="iq"){if(b&&!b.xmlns)b.xmlns=Strophe.NS.CLIENT;else if(!b)b={xmlns:Strophe.NS.CLIENT}}this.nodeTree=this._n(a,b);this.node=this.nodeTree};Strophe.Builder.prototype={tree:function(){return this.nodeTree},toString:function(){return Strophe.serialize(this.nodeTree)},up:function(){this.node=this.node.parentNode;return this},attrs:function(a){for(var b in a)this.node.setAttribute(b,a[b]);return this},c:function(a,b){var c=this._n(a,b);this.node.appendChild(c);this.node=c;return this},cnode:function(a){this.node.appendChild(a);this.node=a;return this},t:function(a){var b=Strophe.xmlTextNode(a);this.node.appendChild(b);return this},_n:function(a,b){var c=Strophe.xmlElement(a);for(var d in b)c.setAttribute(d,b[d]);return c}};Strophe.Handler=function(a,b,c,d,f,g){this.handler=a;this.ns=b;this.name=c;this.type=d;this.id=f;this.from=g;this.user=true};Strophe.Handler.prototype={isMatch:function(b){var c,d;c=false;if(!this.ns){c=true}else{var f=this;Strophe.forEachChild(b,null,function(a){if(a.getAttribute("xmlns")==f.ns)c=true});c=c||b.getAttribute("xmlns")==this.ns}if(c&&(!this.name||Strophe.isTagEqual(b,this.name))&&(!this.type||b.getAttribute("type")==this.type)&&(!this.id||b.getAttribute("id")==this.id)&&(!this.from||b.getAttribute("from")==this.from)){return true}return false},run:function(a){var b=null;try{b=this.handler(a)}catch(e){if(e.sourceURL){Strophe.fatal("error: "+this.handler+" "+e.sourceURL+":"+e.line+" - "+e.name+": "+e.message)}else if(e.fileName){if(typeof(console)!="undefined"){console.trace();console.error(this.handler," - error - ",e,e.message)}Strophe.fatal("error: "+this.handler+" "+e.fileName+":"+e.lineNumber+" - "+e.name+": "+e.message)}else{Strophe.fatal("error: "+this.handler)}throw e;}return b},toString:function(){return"{Handler: "+this.handler+"("+this.name+","+this.id+","+this.ns+")}"}};Strophe.TimedHandler=function(a,b){this.period=a;this.handler=b;this.lastCalled=new Date().getTime();this.user=true};Strophe.TimedHandler.prototype={run:function(){this.lastCalled=new Date().getTime();return this.handler()},reset:function(){this.lastCalled=new Date().getTime()},toString:function(){return"{TimedHandler: "+this.handler+"("+this.period+")}"}};Strophe.Request=function(b,c,d,f){this.id=++Strophe._s;this.xmlData=b;this.data=Strophe.serialize(b);this.origFunc=c;this.func=c;this.rid=d;this.date=NaN;this.sends=f||0;this.abort=false;this.dead=null;this.age=function(){if(!this.date)return 0;var a=new Date();return(a-this.date)/1000};this.timeDead=function(){if(!this.dead)return 0;var a=new Date();return(a-this.dead)/1000};this.xhr=this._t()};Strophe.Request.prototype={getResponse:function(){var a=null;if(this.xhr.responseXML&&this.xhr.responseXML.documentElement){a=this.xhr.responseXML.documentElement;if(a.tagName=="parsererror"){Strophe.error("invalid response received");Strophe.error("responseText: "+this.xhr.responseText);Strophe.error("responseXML: "+Strophe.serialize(this.xhr.responseXML));throw"parsererror";}}else if(this.xhr.responseText){Strophe.error("invalid response received");Strophe.error("responseText: "+this.xhr.responseText);Strophe.error("responseXML: "+Strophe.serialize(this.xhr.responseXML))}return a},_t:function(){var a=null;if(window.XMLHttpRequest){a=new XMLHttpRequest();if(a.overrideMimeType){a.overrideMimeType("text/xml")}}else if(window.ActiveXObject){a=new ActiveXObject("Microsoft.XMLHTTP")}a.onreadystatechange=this.func.prependArg(this);return a}};Strophe.Connection=function(a){this.service=a;this.jid="";this.rid=Math.floor(Math.random()*4294967295);this.sid=null;this.streamId=null;this.do_session=false;this.do_bind=false;this.timedHandlers=[];this.handlers=[];this.removeTimeds=[];this.removeHandlers=[];this.addTimeds=[];this.addHandlers=[];this._8=null;this._i=null;this.authenticated=false;this.disconnecting=false;this.connected=false;this.errors=0;this.paused=false;this.window=5;this._4=[];this._0=[];this._j=Math.round(Math.random()*10000);this._6=null;this._5=null;this._7=null;this._8=setTimeout(this._b.bind(this),100);for(var b in Strophe._a){ptype=Strophe._a[b];var c=function(){};c.prototype=ptype;this[b]=new c();this[b].init(this)}};Strophe.Connection.prototype={reset:function(){this.rid=Math.floor(Math.random()*4294967295);this.sid=null;this.streamId=null;this.do_session=false;this.do_bind=false;this.timedHandlers=[];this.handlers=[];this.removeTimeds=[];this.removeHandlers=[];this.addTimeds=[];this.addHandlers=[];this.authenticated=false;this.disconnecting=false;this.connected=false;this.errors=0;this._0=[];this._j=Math.round(Math.random()*10000)},pause:function(){this.paused=true},resume:function(){this.paused=false},getUniqueId:function(a){if(typeof(a)=="string"||typeof(a)=="number"){return++this._j+":"+a}else{return++this._j+""}},connect:function(a,b,c,d,f,g){this.jid=a;this.pass=b;this.connect_callback=c;this.disconnecting=false;this.connected=false;this.authenticated=false;this.errors=0;if(!d)d=60;if(!f)f=1;if(g)this.window=g;this.domain=Strophe.getDomainFromJid(this.jid);var h=this._c().attrs({to:this.domain,"xml:lang":"en",wait:d,hold:f,window:this.window,content:"text/xml; charset=utf-8",ver:"1.6","xmpp:version":"1.0","xmlns:xmpp":Strophe.NS.BOSH});this._1(Strophe.Status.CONNECTING,null);this._0.push(new Strophe.Request(h.tree(),this._d.bind(this).prependArg(this._k.bind(this)),h.tree().getAttribute("rid")));this._3()},attach:function(a,b,c,d){this.jid=a;this.sid=b;this.rid=c;this.connect_callback=d;this.domain=Strophe.getDomainFromJid(this.jid);this.authenticated=true;this.connected=true},xmlInput:function(a){return},xmlOutput:function(a){return},rawInput:function(a){return},rawOutput:function(a){return},send:function(a){if(a===null){return}if(typeof(a["sort"])==="function"){for(var b=0;b<a.length;b++){this._l(a[b])}}else if(typeof(a["tree"])==="function"){this._l(a.tree())}else{this._l(a)}this._3();clearTimeout(this._8);this._8=setTimeout(this._b.bind(this),100)},sendIQ:function(c,d,f,g){var h=null,m=null;var j=this;if(typeof(c["tree"])==="function"){c=c.tree()}var i=c.getAttribute('id');if(!i){i=this.getUniqueId("sendIQ");c.setAttribute("id",i)}var m=this.addHandler(function(a){if(h){j.deleteTimedHandler(h)}var b=a.getAttribute('type');if(b==='result'){if(d){d(a)}}else if(b==='error'){if(f){f(a)}}else{throw{name:"StropheError",message:"Got bad IQ type of "+b}}},null,'iq',null,i);if(g){h=this.addTimedHandler(g,function(){j.deleteHandler(m);if(f){f(null)}return false})}this.send(c);return i},_l:function(a){if(a===null||!a["tagName"]||!a["childNodes"]){throw{name:"StropheError",message:"Cannot queue non-DOMElement."}}this._4.push(a)},_u:function(){this._4.push("restart");this._3();clearTimeout(this._8);this._8=setTimeout(this._b.bind(this),100)},addTimedHandler:function(a,b){var c=new Strophe.TimedHandler(a,b);this.addTimeds.push(c);return c},deleteTimedHandler:function(a){this.removeTimeds.push(a)},addHandler:function(a,b,c,d,f,g){var h=new Strophe.Handler(a,b,c,d,f,g);this.addHandlers.push(h);return h},deleteHandler:function(a){this.removeHandlers.push(a)},disconnect:function(a){this._1(Strophe.Status.DISCONNECTING,a);Strophe.info("Disconnect was called because: "+a);if(this.connected){this._i=this._v(3000,this._m.bind(this));this._o()}},_1:function(a,b){for(var c in Strophe._a){var d=this[c];if(d.statusChanged){try{d.statusChanged(a,b)}catch(err){Strophe.error(""+c+" plugin caused an exception changing status: "+err)}}}if(this.connect_callback){try{this.connect_callback(a,b)}catch(err){Strophe.error("User connection callback caused an exception: "+err)}}},_c:function(){var a=$build('body',{rid:this.rid++,xmlns:Strophe.NS.HTTPBIND});if(this.sid!==null){a.attrs({sid:this.sid})}return a},_w:function(a){Strophe.debug("removing request");var b;for(b=this._0.length-1;b>=0;b--){if(a==this._0[b]){this._0.splice(b,1)}}a.xhr.onreadystatechange=function(){};this._3()},_x:function(a){var b=this._0[a];if(b.dead===null){b.dead=new Date()}this._e(a)},_e:function(a){var b=this._0[a];var c=-1;try{if(b.xhr.readyState==4){c=b.xhr.status}}catch(e){Strophe.error("caught an error in _0["+a+"], reqStatus: "+c)}if(typeof(c)=="undefined"){c=-1}var d=new Date();var f=b.age();var g=(!isNaN(f)&&f>Strophe.TIMEOUT);var h=(b.dead!==null&&b.timeDead()>Strophe.SECONDARY_TIMEOUT);var m=(b.xhr.readyState==4&&(c<1||c>=500));var j;if(g||h||m){if(h){Strophe.error("Request "+this._0[a].id+" timed out (secondary), restarting")}b.abort=true;b.xhr.abort();j=b;this._0[a]=new Strophe.Request(b.xmlData,b.origFunc,b.rid,b.sends);b=this._0[a]}if(b.xhr.readyState===0){Strophe.debug("request id "+b.id+"."+b.sends+" posting");b.date=new Date();try{b.xhr.open("POST",this.service,true)}catch(e){Strophe.error("XHR open failed.");if(!this.connected){this._1(Strophe.Status.CONNFAIL,"bad-service")}this.disconnect();return}var i=function(){b.xhr.send(b.data)};if(b.sends>1){var n=Math.pow(b.sends,3)*1000;setTimeout(i,n)}else{i()}b.sends++;this.xmlOutput(b.xmlData);this.rawOutput(b.data)}else{Strophe.debug("_3: "+(a===0?"first":"second")+" request has readyState of "+b.xhr.readyState)}},_3:function(){if(!this._0){Strophe.debug("_3 called with undefined requests")}else{Strophe.debug("_3 called with "+this._0.length+" requests")}if(!this._0||this._0.length===0){return}if(this._0.length>0){this._e(0)}if(this._0.length>1&&Math.abs(this._0[0].rid-this._0[1].rid)<this.window-1){this._e(1)}},_d:function(a,b){Strophe.debug("request id "+b.id+"."+b.sends+" state changed to "+b.xhr.readyState);if(b.abort){b.abort=false;return}var c;if(b.xhr.readyState==4){c=0;try{c=b.xhr.status}catch(e){}if(typeof(c)=="undefined"){c=0}if(this.disconnecting){if(c>=400){this._p(c);return}}var d=(this._0[0]==b);var f=(this._0[1]==b);if((c>0&&c<500)||b.sends>5){this._w(b);Strophe.debug("request id "+b.id+" should now be removed")}if(c==200){if(f||(d&&this._0.length>0&&this._0[0].age()>Strophe.SECONDARY_TIMEOUT)){this._x(0)}Strophe.debug("request id "+b.id+"."+b.sends+" got 200");a(b);this.errors=0}else{Strophe.error("request id "+b.id+"."+b.sends+" error "+c+" happened");if(c===0||(c>=400&&c<600)||c>=12000){this._p(c);if(c>=400&&c<500){this._1(Strophe.Status.DISCONNECTING,null);this._f()}}}if(!((c>0&&c<10000)||b.sends>5)){this._3()}}},_p:function(a){this.errors++;Strophe.warn("request errored, status: "+a+", number of errors: "+this.errors);if(this.errors>4){this._m()}},_f:function(){Strophe.info("_f was called");this.authenticated=false;this.disconnecting=false;this.sid=null;this.streamId=null;this.rid=Math.floor(Math.random()*4294967295);if(this.connected){this._1(Strophe.Status.DISCONNECTED,null);this.connected=false}this.handlers=[];this.timedHandlers=[];this.removeTimeds=[];this.removeHandlers=[];this.addTimeds=[];this.addHandlers=[]},_q:function(f){try{var g=f.getResponse()}catch(e){if(e!="parsererror")throw e;this.disconnect("strophe-parsererror")}if(g===null)return;this.xmlInput(g);this.rawInput(Strophe.serialize(g));var h,m;while(this.removeHandlers.length>0){m=this.removeHandlers.pop();h=this.handlers.indexOf(m);if(h>=0)this.handlers.splice(h,1)}while(this.addHandlers.length>0){this.handlers.push(this.addHandlers.pop())}if(this.disconnecting&&this._0.length==0){this.deleteTimedHandler(this._i);this._i=null;this._f();return}var j=g.getAttribute("type");var i,n;if(j!==null&&j=="terminate"){i=g.getAttribute("condition");n=g.getElementsByTagName("conflict");if(i!==null){if(i=="remote-stream-error"&&n.length>0){i="conflict"}this._1(Strophe.Status.CONNFAIL,i)}else{this._1(Strophe.Status.CONNFAIL,"unknown")}this.disconnect();return}var k=this;Strophe.forEachChild(g,null,function(a){var b,c;c=k.handlers;k.handlers=[];for(b=0;b<c.length;b++){var d=c[b];if(d.isMatch(a)&&(k.authenticated||!d.user)){if(d.run(a)){k.handlers.push(d)}}else{k.handlers.push(d)}}})},_o:function(){Strophe.info("_o was called");var a=this._c().attrs({type:"terminate"});var b,c;if(this.authenticated){a.c('presence',{xmlns:Strophe.NS.CLIENT,type:'unavailable'})}this.disconnecting=true;var d=new Strophe.Request(a.tree(),this._d.bind(this).prependArg(this._q.bind(this)),a.tree().getAttribute("rid"));var f;while(this._0.length>0){f=this._0.pop();f.xhr.abort();f.abort=true}this._0.push(d);this._3()},_k:function(a){Strophe.info("_k was called");this.connected=true;var b=a.getResponse();if(!b)return;this.xmlInput(b);this.rawInput(Strophe.serialize(b));var c=b.getAttribute("type");var d,f;if(c!==null&&c=="terminate"){d=b.getAttribute("condition");f=b.getElementsByTagName("conflict");if(d!==null){if(d=="remote-stream-error"&&f.length>0){d="conflict"}this._1(Strophe.Status.CONNFAIL,d)}else{this._1(Strophe.Status.CONNFAIL,"unknown")}return}if(!this.sid){this.sid=b.getAttribute("sid")}if(!this.stream_id){this.stream_id=b.getAttribute("authid")}var g=false;var h=false;var m=false;var j=b.getElementsByTagName("mechanism");var i,n,k,l;if(j.length>0){for(i=0;i<j.length;i++){n=Strophe.getText(j[i]);if(n=='DIGEST-MD5'){h=true}else if(n=='PLAIN'){g=true}else if(n=='ANONYMOUS'){m=true}}}else{var o=this._c();this._0.push(new Strophe.Request(o.tree(),this._d.bind(this).prependArg(this._k.bind(this)),o.tree().getAttribute("rid")));this._3();return}if(Strophe.getNodeFromJid(this.jid)===null&&m){this._1(Strophe.Status.AUTHENTICATING,null);this._6=this._2(this._g.bind(this),null,"success",null,null);this._5=this._2(this._9.bind(this),null,"failure",null,null);this.send($build("auth",{xmlns:Strophe.NS.SASL,mechanism:"ANONYMOUS"}).tree())}else if(Strophe.getNodeFromJid(this.jid)===null){this._1(Strophe.Status.CONNFAIL,'x-strophe-bad-non-anon-jid');this.disconnect()}else if(h){this._1(Strophe.Status.AUTHENTICATING,null);this._7=this._2(this._y.bind(this),null,"challenge",null,null);this._5=this._2(this._9.bind(this),null,"failure",null,null);this.send($build("auth",{xmlns:Strophe.NS.SASL,mechanism:"DIGEST-MD5"}).tree())}else if(g){k=Strophe.escapeJid(Strophe.getBareJidFromJid(this.jid));k=k+"\u0000";k=k+Strophe.getNodeFromJid(this.jid);k=k+"\u0000";k=k+this.pass;this._1(Strophe.Status.AUTHENTICATING,null);this._6=this._2(this._g.bind(this),null,"success",null,null);this._5=this._2(this._9.bind(this),null,"failure",null,null);l=encode64(k);this.send($build("auth",{xmlns:Strophe.NS.SASL,mechanism:"PLAIN"}).t(l).tree())}else{this._1(Strophe.Status.AUTHENTICATING,null);this._2(this._z.bind(this),null,null,null,"_A");this.send($iq({type:"get",to:this.domain,id:"_A"}).c("query",{xmlns:Strophe.NS.AUTH}).c("username",{}).t(Strophe.getNodeFromJid(this.jid)).tree())}},_y:function(a){var b=/([a-z]+)=("[^"]+"|[^,"]+)(?:,|$)/;var c=decode64(Strophe.getText(a));var d=hex_md5(Math.random()*1234567890);var f="";var g=null;var h="";var m="";var j;this.deleteHandler(this._5);while(c.match(b)){j=c.match(b);c=c.replace(j[0],"");j[2]=j[2].replace(/^"(.+)"$/,"$1");switch(j[1]){case"realm":f=j[2];break;case"nonce":h=j[2];break;case"qop":m=j[2];break;case"host":g=j[2];break}}var i="xmpp/"+this.domain;if(g!==null){i=i+"/"+g}var n=str_md5(Strophe.getNodeFromJid(this.jid)+":"+f+":"+this.pass)+":"+h+":"+d;var k='AUTHENTICATE:'+i;var l="";l+='username="'+Strophe.getNodeFromJid(this.jid)+'",';l+='realm="'+f+'",';l+='nonce="'+h+'",';l+='cnonce="'+d+'",';l+='nc="00000001",';l+='qop="auth",';l+='digest-uri="'+i+'",';l+='response="'+hex_md5(hex_md5(n)+":"+h+":00000001:"+d+":auth:"+hex_md5(k))+'",';l+='charset="utf-8"';this._7=this._2(this._B.bind(this),null,"challenge",null,null);this._6=this._2(this._g.bind(this),null,"success",null,null);this._5=this._2(this._9.bind(this),null,"failure",null,null);this.send($build('response',{xmlns:Strophe.NS.SASL}).t(encode64(l)).tree());return false},_B:function(a){this.deleteHandler(this._6);this.deleteHandler(this._5);this._6=this._2(this._g.bind(this),null,"success",null,null);this._5=this._2(this._9.bind(this),null,"failure",null,null);this.send($build('response',{xmlns:Strophe.NS.SASL}).tree());return false},_z:function(a){var b=false;var c,d;if(a.getAttribute("type")=="result"){c=a.childNodes[0];if(c){d=c.getElementsByTagName("digest")[0];if(d){b=true}}}var f=$iq({type:"set",id:"_C"}).c('query',{xmlns:Strophe.NS.AUTH}).c('username',{}).t(Strophe.getNodeFromJid(this.jid));if(b){f.up().c("digest",{}).t(hex_sha1(this.stream_id+this.pass))}else{f.up().c('password',{}).t(this.pass)}if(!Strophe.getResourceFromJid(this.jid)){this.jid=Strophe.getBareJidFromJid(this.jid)+'/strophe'}f.up().c('resource',{}).t(Strophe.getResourceFromJid(this.jid));this._2(this._D.bind(this),null,null,null,"_C");this.send(f.tree());return false},_g:function(a){Strophe.info("SASL authentication succeeded.");this.deleteHandler(this._5);this._5=null;if(this._7){this.deleteHandler(this._7);this._7=null}this._2(this._E.bind(this),null,"stream:features",null,null);this._u();return false},_E:function(a){var b,c;for(b=0;b<a.childNodes.length;b++){c=a.childNodes[b];if(c.nodeName=='bind'){this.do_bind=true}if(c.nodeName=='session'){this.do_session=true}}if(!this.do_bind){this._1(Strophe.Status.AUTHFAIL,null);return false}else{this._2(this._F.bind(this),null,null,null,"_r");var d=Strophe.getResourceFromJid(this.jid);if(d)this.send($iq({type:"set",id:"_r"}).c('bind',{xmlns:Strophe.NS.BIND}).c('resource',{}).t(d).tree());else this.send($iq({type:"set",id:"_r"}).c('bind',{xmlns:Strophe.NS.BIND}).tree())}return false},_F:function(a){if(a.getAttribute("type")=="error"){Strophe.info("SASL binding failed.");this._1(Strophe.Status.AUTHFAIL,null);return false}var b=a.getElementsByTagName("bind");var c;if(b.length>0){c=b[0].getElementsByTagName("jid");if(c.length>0){this.jid=Strophe.getText(c[0]);if(this.do_session){this._2(this._G.bind(this),null,null,null,"_H");this.send($iq({type:"set",id:"_H"}).c('session',{xmlns:Strophe.NS.SESSION}).tree())}}}else{Strophe.info("SASL binding failed.");this._1(Strophe.Status.AUTHFAIL,null);return false}},_G:function(a){if(a.getAttribute("type")=="result"){this.authenticated=true;this._1(Strophe.Status.CONNECTED,null)}else if(a.getAttribute("type")=="error"){Strophe.info("Session creation failed.");this._1(Strophe.Status.AUTHFAIL,null);return false}return false},_9:function(a){if(this._6){this.deleteHandler(this._6);this._6=null}if(this._7){this.deleteHandler(this._7);this._7=null}this._1(Strophe.Status.AUTHFAIL,null);return false},_D:function(a){if(a.getAttribute("type")=="result"){this.authenticated=true;this._1(Strophe.Status.CONNECTED,null)}else if(a.getAttribute("type")=="error"){this._1(Strophe.Status.AUTHFAIL,null);this.disconnect()}return false},_v:function(a,b){var c=new Strophe.TimedHandler(a,b);c.user=false;this.addTimeds.push(c);return c},_2:function(a,b,c,d,f){var g=new Strophe.Handler(a,b,c,d,f);g.user=false;this.addHandlers.push(g);return g},_m:function(){Strophe.info("_m was called");var a;while(this._0.length>0){a=this._0.pop();a.xhr.abort();a.abort=true}this._f();return false},_b:function(){var a,b,c,d;while(this.removeTimeds.length>0){b=this.removeTimeds.pop();a=this.timedHandlers.indexOf(b);if(a>=0)this.timedHandlers.splice(a,1)}while(this.addTimeds.length>0){this.timedHandlers.push(this.addTimeds.pop())}var f=new Date().getTime();d=[];for(a=0;a<this.timedHandlers.length;a++){b=this.timedHandlers[a];if(this.authenticated||!b.user){c=b.lastCalled+b.period;if(c-f<=0){if(b.run()){d.push(b)}}else{d.push(b)}}}this.timedHandlers=d;var g,h;if(this.authenticated&&this._0.length===0&&this._4.length===0&&!this.disconnecting){Strophe.info("no requests during idle cycle, sending blank request");this._4.push(null)}if(this._0.length<2&&this._4.length>0&&!this.paused){g=this._c();for(a=0;a<this._4.length;a++){if(this._4[a]!==null){if(this._4[a]==="restart"){g.attrs({to:this.domain,"xml:lang":"en","xmpp:restart":"true","xmlns:xmpp":Strophe.NS.BOSH})}else{g.cnode(this._4[a]).up()}}}delete this._4;this._4=[];this._0.push(new Strophe.Request(g.tree(),this._d.bind(this).prependArg(this._q.bind(this)),g.tree().getAttribute("rid")));this._e(this._0.length-1)}if(this._0.length>0){h=this._0[0].age();if(this._0[0].dead!==null){if(this._0[0].timeDead()>Strophe.SECONDARY_TIMEOUT){this._3()}}if(h>Strophe.TIMEOUT){Strophe.warn("Request "+this._0[0].id+" timed out, over "+Strophe.TIMEOUT+" seconds since last activity");this._3()}}clearTimeout(this._8);this._8=setTimeout(this._b.bind(this),100)}};
