function XmlDocument(){}XmlDocument.create=function(C,E){C=C||"foo";E=E||"";try{var H;if(document.implementation&&document.implementation.createDocument){H=document.implementation.createDocument(E,C,null);var F=navigator.userAgent.toLowerCase();if(/mozilla/.test(F)&&!/(compatible|webkit)/.test(F)){var G=new DOMParser();var B="";if(E!==""){xmlns=' "'+E+'"'}H=G.parseFromString("<"+C+B+"></"+C+">","text/xml")}else{H=document.implementation.createDocument(E,C,null)}if(H.readyState===null){H.readyState=1;H.addEventListener("load",function(){H.readyState=4;if(typeof H.onreadystatechange==="function"){H.onreadystatechange()}},false)}}else{if(window.ActiveXObject){H=new ActiveXObject(XmlDocument.getPrefix()+".DomDocument")}}if(!H.documentElement||H.documentElement.tagName!==C||(H.documentElement.namespaceURI&&H.documentElement.namespaceURI!==E)){try{if(E!==""){H.appendChild(H.createElement(C)).setAttribute("xmlns",E)}else{H.appendChild(H.createElement(C))}}catch(A){H=document.implementation.createDocument(E,C,null);if(H.documentElement===null){H.appendChild(H.createElement(C))}if(E!==""&&H.documentElement.getAttribute("xmlns")!==E){H.documentElement.setAttribute("xmlns",E)}}}return H}catch(D){}throw new Error("Your browser does not support XmlDocument objects"+D)};XmlDocument.getPrefix=function(){if(XmlDocument.prefix){return XmlDocument.prefix}var A=["MSXML2","Microsoft","MSXML","MSXML3"];var D;for(var C=0;C<A.length;C++){try{D=new ActiveXObject(A[C]+".DomDocument");XmlDocument.prefix=A[C];return XmlDocument.prefix}catch(B){}}throw new Error("Could not find an installed XML parser")};if(typeof (Document)!=="undefined"&&window.DOMParser){if(typeof (Document.prototype)==="undefined"){Document.prototype=0}Document.prototype.loadXML=function(B){var C=(new DOMParser()).parseFromString(B,"text/xml");while(this.hasChildNodes()){this.removeChild(this.lastChild)}for(var A=0;A<C.childNodes.length;A++){this.appendChild(this.importNode(C.childNodes[A],true))}}}if(window.XMLSerializer&&window.Node&&Node.prototype&&Node.prototype.__defineGetter__){XMLDocument.prototype.__defineGetter__("xml",function(){return(new XMLSerializer()).serializeToString(this)});Document.prototype.__defineGetter__("xml",function(){return(new XMLSerializer()).serializeToString(this)});Node.prototype.__defineGetter__("xml",function(){return(new XMLSerializer()).serializeToString(this)})}function getXmlDoc(A){var B=navigator.userAgent.toLowerCase();if(/mozilla/.test(B)&&!/(compatible|webkit)/.test(B)){var C=new DOMParser();return C.parseFromString(A.responseText,"text/xml")}else{return A.responseXML}}var JSJACJID_FORBIDDEN=[];function JSJaCJIDInvalidException(A){this.message=A;this.name="JSJaCJIDInvalidException"}function JSJaCJID(A){this._node="";this._domain="";this._resource="";if(typeof (A)==="string"){if(A.indexOf("@")!==-1){this.setNode(A.substring(0,A.indexOf("@")));A=A.substring(A.indexOf("@")+1)}if(A.indexOf("/")!==-1){this.setResource(A.substring(A.indexOf("/")+1));A=A.substring(0,A.indexOf("/"))}this.setDomain(A)}else{this.setNode(A.node);this.setDomain(A.domain);this.setResource(A.resource)}}JSJaCJID.prototype.getNode=function(){return this._node};JSJaCJID.prototype.getDomain=function(){return this._domain};JSJaCJID.prototype.getResource=function(){return this._resource};JSJaCJID.prototype.setNode=function(A){JSJaCJID._checkNodeName(A);this._node=A||"";return this};JSJaCJID.prototype.setDomain=function(A){if(!A||A===""){throw new JSJaCJIDInvalidException("domain name missing")}JSJaCJID._checkNodeName(A);this._domain=A;return this};JSJaCJID.prototype.setResource=function(A){this._resource=A||"";return this};JSJaCJID.prototype.toString=function(){var A="";if(this.getNode()&&this.getNode()!==""){A=this.getNode()+"@"}A+=this.getDomain();if(this.getResource()&&this.getResource()!==""){A+="/"+this.getResource()}return A};JSJaCJID.prototype.clone=function(){return new JSJaCJID(this.toString())};JSJaCJID._checkNodeName=function(A){if(!A||A===""){return }for(var B=0;B<JSJACJID_FORBIDDEN.length;B++){if(A.indexOf(JSJACJID_FORBIDDEN[B])!==-1){throw new JSJaCJIDInvalidException("forbidden char in nodename: "+JSJACJID_FORBIDDEN[B])}}};var JSJaCBuilder={buildNode:function(E,B){var C,D=arguments[4];if(arguments[2]){if(JSJaCBuilder._isStringOrNumber(arguments[2])||(arguments[2] instanceof Array)){C=this._createElement(E,B,D);JSJaCBuilder._children(E,C,arguments[2])}else{D=arguments[2].xmlns||D;C=this._createElement(E,B,D);for(var A in arguments[2]){if(arguments[2].hasOwnProperty(A)&&A!=="xmlns"){C.setAttribute(A,arguments[2][A])}}}}else{C=this._createElement(E,B,D)}if(arguments[3]){JSJaCBuilder._children(E,C,arguments[3],D)}return C},_createElement:function(E,A,D){try{if(D){return E.createElementNS(D,A)}}catch(B){}var C=E.createElement(A);if(D){C.setAttribute("xmlns",D)}return C},_text:function(A,B){return A.createTextNode(B)},_children:function(G,A,C,D){if(typeof C==="object"){for(var B in C){if(C.hasOwnProperty(B)){var F=C[B];if(typeof F==="object"){if(F instanceof Array){var E=JSJaCBuilder.buildNode(G,F[0],F[1],F[2],D);A.appendChild(E)}else{A.appendChild(F)}}else{if(JSJaCBuilder._isStringOrNumber(F)){A.appendChild(JSJaCBuilder._text(G,F))}}}}}else{if(JSJaCBuilder._isStringOrNumber(C)){A.appendChild(JSJaCBuilder._text(G,C))}}},_attributes:function(A){var B=[];for(var C in A){if(A.hasOwnProperty(C)){B.push(C+'="'+A[C].toString().htmlEnc()+'"')}}return B.join(" ")},_isStringOrNumber:function(A){return(typeof A==="string"||typeof A==="number")}};var JSJACPACKET_USE_XMLNS=true;function JSJaCPacket(A){this.name=A;if(typeof (JSJACPACKET_USE_XMLNS)!=="undefined"&&JSJACPACKET_USE_XMLNS){this.doc=XmlDocument.create(A,"jabber:client")}else{this.doc=XmlDocument.create(A,"")}}JSJaCPacket.prototype.getDoc=function(){return this.doc};JSJaCPacket.prototype.getNode=function(){if(this.getDoc()&&this.getDoc().documentElement){return this.getDoc().documentElement}return null};JSJaCPacket.prototype.setTo=function(A){if(!A||A===""){this.getNode().removeAttribute("to")}else{if(typeof (A)==="string"){this.getNode().setAttribute("to",A)}else{this.getNode().setAttribute("to",A.toString())}}return this};JSJaCPacket.prototype.setFrom=function(A){if(!A||A===""){this.getNode().removeAttribute("from")}else{if(typeof (A)==="string"){this.getNode().setAttribute("from",A)}else{this.getNode().setAttribute("from",A.toString())}}return this};JSJaCPacket.prototype.setID=function(A){if(!A||A===""){this.getNode().removeAttribute("id")}else{this.getNode().setAttribute("id",A)}return this};JSJaCPacket.prototype.setType=function(A){if(!A||A===""){this.getNode().removeAttribute("type")}else{this.getNode().setAttribute("type",A)}return this};JSJaCPacket.prototype.getTo=function(){return this.getNode().getAttribute("to")};JSJaCPacket.prototype.getFrom=function(){return this.getNode().getAttribute("from")};JSJaCPacket.prototype.getToJID=function(){return new JSJaCJID(this.getTo())};JSJaCPacket.prototype.getFromJID=function(){return new JSJaCJID(this.getFrom())};JSJaCPacket.prototype.getID=function(){return this.getNode().getAttribute("id")};JSJaCPacket.prototype.getType=function(){return this.getNode().getAttribute("type")};JSJaCPacket.prototype.getChild=function(B,D){if(!this.getNode()){return null}B=B||"*";D=D||"*";if(this.getNode().getElementsByTagNameNS){return this.getNode().getElementsByTagNameNS(D,B).item(0)}var A=this.getNode().getElementsByTagName(B);if(D!=="*"){for(var C=0;C<A.length;C++){if(A.item(C).namespaceURI===D){return A.item(C)}}}else{return A.item(0)}return null};JSJaCPacket.prototype.getChildVal=function(B,D){var E=this.getChild(B,D);var A="";if(E&&E.hasChildNodes()){for(var C=0;C<E.childNodes.length;C++){if(E.childNodes.item(C).nodeValue){A+=E.childNodes.item(C).nodeValue}}}return A};JSJaCPacket.prototype.clone=function(){return JSJaCPacket.wrapNode(this.getNode())};JSJaCPacket.prototype.isError=function(){return(this.getType()==="error")};JSJaCPacket.prototype.errorReply=function(A){var B=this.clone();B.setTo(this.getFrom());B.setFrom();B.setType("error");B.appendNode("error",{code:A.code,type:A.type},[[A.cond]]);return B};JSJaCPacket.prototype.xml=typeof XMLSerializer!=="undefined"?function(){var A=(new XMLSerializer()).serializeToString(this.getNode());if(typeof (A)==="undefined"){A=(new XMLSerializer()).serializeToString(this.doc)}return A}:function(){return this.getDoc().xml};JSJaCPacket.prototype._getAttribute=function(A){return this.getNode().getAttribute(A)};JSJaCPacket.prototype._replaceNode=function(A){for(var C=0;C<A.attributes.length;C++){if(A.attributes.item(C).nodeName!=="xmlns"){this.getNode().setAttribute(A.attributes.item(C).nodeName,A.attributes.item(C).nodeValue)}}for(var B=0;B<A.childNodes.length;B++){if(this.getDoc().importNode){this.getNode().appendChild(this.getDoc().importNode(A.childNodes.item(B),true))}else{this.getNode().appendChild(A.childNodes.item(B).cloneNode(true))}}};JSJaCPacket.prototype._setChildNode=function(F,B){var A=this.getChild(F);var D=this.getDoc().createTextNode(B);if(A){try{A.replaceChild(D,A.firstChild)}catch(E){}}else{try{A=this.getDoc().createElementNS(this.getNode().namespaceURI,F)}catch(C){A=this.getDoc().createElement(F)}this.getNode().appendChild(A);A.appendChild(D)}return A};JSJaCPacket.prototype.buildNode=function(A){return JSJaCBuilder.buildNode(this.getDoc(),A,arguments[1],arguments[2])};JSJaCPacket.prototype.appendNode=function(A){if(typeof A==="object"){return this.getNode().appendChild(A)}else{return this.getNode().appendChild(this.buildNode(A,arguments[1],arguments[2],null,this.getNode().namespaceURI))}};function JSJaCPresence(){this.base=JSJaCPacket;this.base("presence")}JSJaCPresence.prototype=new JSJaCPacket();JSJaCPresence.prototype.setStatus=function(A){this._setChildNode("status",A);return this};JSJaCPresence.prototype.setShow=function(A){if(A==="chat"||A==="away"||A==="xa"||A==="dnd"||A==="idle"){this._setChildNode("show",A)}return this};JSJaCPresence.prototype.getStatus=function(){return this.getChildVal("status")};JSJaCPresence.prototype.getShow=function(){return this.getChildVal("show")};function JSJaCIQ(){this.base=JSJaCPacket;this.base("iq")}JSJaCIQ.prototype=new JSJaCPacket();JSJaCIQ.prototype.setIQ=function(C,A,B){if(C){this.setTo(C)}if(A){this.setType(A)}if(B){this.setID(B)}return this};JSJaCIQ.prototype.setQuery=function(C){var A;try{A=this.getDoc().createElementNS(C,"query")}catch(B){A=this.getDoc().createElement("query")}if(A&&A.getAttribute("xmlns")!==C){A.setAttribute("xmlns",C)}this.getNode().appendChild(A);return A};JSJaCIQ.prototype.getQuery=function(){return this.getNode().getElementsByTagName("query").item(0)};function JSJaCMessage(){this.base=JSJaCPacket;this.base("message")}JSJaCMessage.prototype=new JSJaCPacket();JSJaCMessage.prototype.getBody=function(){return this.getChildVal("body")};JSJaCPacket.wrapNode=function(B){var A;switch(B.nodeName.toLowerCase()){case"presence":A=new JSJaCPresence();break;case"message":A=new JSJaCMessage();break;case"iq":A=new JSJaCIQ();break;default:return null}A._replaceNode(B);return A};ComCore.JabberCookieStore=Class.create({initialize:function(){},getSessionsObject:function(){return this._getCookie("jabber")},_getCookie:function(D){var E=document.cookie.split(";");var B="";for(var C=0,A=E.length;C<A;C++){var F=E[C];while(F.charAt(0)===" "){F=F.substring(1,F.length)}if(F.indexOf(D)===0){B=unescape(F)}}if(B.length===0){return{}}return B.evalJSON()},writeSessionsObject:function(E){var D=$H(E).collect(function(F){return{key:F.key,value:F.value}});D=D.sortBy(function(F){return F.value.timestamp}).reverse();var B={};var A=0;D.each(function(F){if(A++<=3){B[F.key]=F.value}});if(B){var C=Object.toJSON(B);this._writeCookie("jabber",C)}},writeJabberStatus:function(A){this._writeCookie("chatStatus",Object.toJSON({s:A}))},updatePeopleCount:function(B){var A=new Date();A.setTime(A.getTime()+(10*24*60*60*1000));this._writeCookie("chatPeopleCount",B,A)},getPeopleCount:function(){return parseInt(this._getCookie("chatPeopleCount"),10)},getJabberStatus:function(){var A=this._getCookie("chatStatus");return A.s},writeCurrentState:function(C){var A=Object.toJSON(C);var B=new Date();B.setTime(B.getTime()+(6*60*60*1000));this._writeCookie("state",A,B)},writeRoster:function(C){var A=Object.toJSON(C);var B=new Date();B.setTime(B.getTime()+(6*60*60*1000));this._writeCookie("roster",A,B)},getRoster:function(){return this._getCookie("roster")},getCurrentState:function(){return this._getCookie("state")},_writeCookie:function(A,C,B){if(B===undefined){B=new Date();B.setTime(B.getTime()+(60*10*1000))}document.cookie=A+"="+escape(C)+"; expires="+B.toGMTString()+"; path=/"},_eoo:true});if(!ComCore.Jabber){ComCore.Jabber={}}function stanza_error(C,B,A){this.code=C;this.type=B;this.cond=A;return{code:C,type:B,cond:A}}function ERR_FEATURE_NOT_IMPLEMENTED(){var A=new JSJaCIQ();return A.errorReply(stanza_error("501","cancel","feature-not-implemented"))}ComCore.Jabber.Connection=function(B,A){this.initialize=function(D,C){this.connectionParams=D;this.setupConnection(D,C);this.cookieExpire=1000*60;this.archiveCallbacks={}};this.setupConnection=function(E,C){this.roster={};this.controller=C;this.resources={};this.isRosterLoaded=false;this.connection=null;this.username=E.username.toLowerCase();this.firstName=E.firstName;this.isQuitting=false;try{this.connection=document.getElementById("remoteFrame").contentWindow.boot();this.connection.userDetails=this.controller.getUserDetails();this.connection.username=E.username.toLowerCase();this.connection.signature=E.signature;this.connection.hash=E.hash;this.connection.userID=E.userID;this.connection.distro=E.distro;this.connection.registerHandler("onConnect",this._onConnect.bind(this));this.connection.registerHandler("onInvalidSID",this._onInvalidSID.bind(this));window.onbeforeunload=this._quit.bind(this)}catch(D){debug(D);window.setTimeout((function(){this.setupConnection(E,C)}).bind(this),1000)}};this.getSession=function(H){var E=new ComCore.JabberCookieStore();var I=E.getSessionsObject();try{for(var D in I){if(I[D]){var G=I[D];var C=(new Date().getTime()-G.timestamp)>this.cookieExpire;if((G.in_use===false)&&G.sid&&G.resource&&(G.sid!=="null")&&!C){G.in_use=true;G.timestamp=new Date().getTime();I[D]=G;E.writeSessionsObject(I);this.connection.username=G.username.toLowerCase();this.connection.resource=G.resource;this.connection.hash=G.hash;this.connection.signature=G.signature;this.connection.userID=G.uid;this.connection.sid=G.sid;this.connection.revive();return }}}}catch(F){debug("Error in getSession: "+F)}this.connection.username=H.username.toLowerCase();this.connection.signature=H.signature;this.connection.hash=H.hash;this.connection.userID=H.userID;this.connection.resource="netlog_webclient_"+(new Date()).getTime()+"-"+Math.floor(Math.random()*10000)+"-"+this.connection.userID;this.connection.connect()};this.sendTypingNotification=function(E,C){var D=this.connection.username+"@chat.netlog.com";var F=C+"@chat.netlog.com";var G={xml:function(){return"<message from='"+D+"' to='"+F+"' type='chat'><"+E+" xmlns='http://jabber.org/protocol/chatstates' /></message>"}};this.connection.addPacketToQueue(G)};this.sendMessage=function(D,C,I){try{var E=this.connection.username+"@chat.netlog.com";var F=D+"@chat.netlog.com";var H=this.createMessage({recipient:F,body:C},false,I);this.connection.addPacketToQueue(H);if(!I){H=this.createMessage({recipient:E,body:C,receiver:D},true,I);this.connection.addPacketToQueue(H);C=C.replace(/&amp;/ig,"&");this.notify("onMessageReceived",{username:E,message:C,chat:D})}}catch(G){debug("Error in sendMessage(): "+G.message)}};this.createMessage=function(D,C,F){var E={xml:function(){var G='<message to="'+D.recipient+'"><body>'+D.body+"</body>";if(C===true){G+="<chat>"+D.receiver+"</chat>"}if(F!==undefined){G+="<payload>"+F+"</payload>"}G+="</message>";return G}};return E};this.setStatus=function(C,D){var E=new JSJaCPresence();E.setShow(C);if(D){E.setStatus(D)}this.connection.addPacketToQueue(E)};this.requestArchive=function(D,E){this.archiveCallbacks[D.to]=(function(F){this.parseArchiveXML(F,E)}).bind(this);var C={xml:function(){return'<iq from="'+D.from+'@chat.netlog.com" to="'+D.to+'@chat.netlog.com" type="get"><chat xmlns="netlog-messageArchive"/></iq>'}};this.connection.addPacketToQueue(C)};this.parseArchiveXML=function(G,I){var C=G.getChild();if(C.childNodes.length===0){I([]);return }var D=[];for(var F=0,H=C.childNodes.length;F<H;F++){var E=C.childNodes[F];D.push(this._createMessage(E))}I(D)};this._createMessage=function(D){var C=D.getElementsByTagName("body")[0];if(C.childNodes.length===0){return{}}var F=C.firstChild.nodeValue;if(!F){return{}}var G=D.getElementsByTagName("delay")[0].getAttribute("stamp");function E(I){var J=I.split("T");var L=J[0].split("-");var H=J[1].split(":");var K=L[1]-1;if(K<0){K=11}return new Date(L[0],K,L[2],H[0],H[1],H[2])}return{body:F,date:E(G),username:D.getAttribute("from").replace("@chat.netlog.com","").split("/")[0]}};this._onMessage=function(J){debug("_onMessage");debug(J);if(J.isError()){return }var K=this.connection.username+"@chat.netlog.com/"+this.connection.resource;var G=J.getFromJID().getNode()+"@"+J.getFromJID().getDomain()+"/"+J.getFromJID().getResource();if(K===G){debug("skipping a message I've sent");return }var F=J.getFromJID().getNode();var I=J.getBody();var M=J.getChild("x");var N=parseInt(J.getNode().getAttribute("userID"),10);var O=J.getChild("payload");if((O!==null)&&O.childNodes&&O.childNodes[0]){this.controller.games.challengeReceived(O.childNodes[0].nodeValue.toString(),F);return }if((J.getChild().tagName==="composing")||(J.getChild().tagName==="active")||(J.getChild().getAttribute("xmlns")==="jabber:x:event")){var H=J.getChild().tagName;if((H!=="composing")&&(H!=="active")){H=J.getChild().getChild().tagName}this.notify("onChatStateNotification",F,H)}if(!I.blank()){if(F==="netlog"){var C=J.getNode();var L=C.getAttribute("link");var E=C.getAttribute("image");var D='<img src="'+E+'" alt="image" class=\'avatar\' style="width: 40px; height: 30px;" />';ComCore.bubbleManager.showBubble(L,D,I,ComCore.bubbleManager.showBubbleTime);this.notify("onBubbleReceived",L,E,D,I);return }var P=J.getChildVal("chat")||"";if((P!==F)&&(P.length>0)){this.notify("onMessageReceived",{username:F,message:I,chat:P})}else{this.notify("onMessageReceived",{username:F,message:I,userID:N})}}};this.sendSecondPresence=function(){var C=new JSJaCPresence();C.getNode().setAttribute("getAll","true");this.connection.addPacketToQueue(C,null)};this._onPresence=function(D){var C=this.getPresenceStatus(D);if(C&&C.username&&C.userstatus){this.notify("onUserStatusChanged",C)}};this.sendIdle=function(C){var D=new JSJaCPresence();D.setShow("idle");this.connection.addPacketToQueue(D)};this.sendActive=function(C){C=C||"online";var D=new JSJaCPresence();D.setShow("chat");D.setStatus(C);D.getNode().setAttribute("restoreFromIdle","true");this.connection.addPacketToQueue(D)};this.getPresenceStatus=function(K){var C;var O=K.getFromJID();var F=O.getNode();var J=O.getResource();var L=this.connection.username+"@chat.netlog.com/"+this.connection.resource;var G=O.getNode()+"@"+O.getDomain()+"/"+O.getResource();var D=K.getChild();if(L===G){debug("skipping a presence I've sent");return }if(!K.getType()&&!K.getShow()&&(F===this.connection.username)&&(K.getNode().getAttribute("getAll")==="false")){return undefined}if(!C){var N=K.getShow();var H=K.getStatus();var E={online:{show:"chat"},busy:{show:"dnd"},away:{show:"away"},idle:{show:"idle"},invisible:{show:"xa"}};var M;for(var P in E){if(E.hasOwnProperty(P)){M=E[P];if(N===M.show){if(M.status){if(H===M.status){C=(M.status===H?P:false)}}else{C=P}}}}}if(!C){C="online"}if(C==="idle"){C="away"}var I={userstatus:C,username:F};if(K&&K.getNode().getAttribute("onlineFriends")){I.onlineFriendCounter=parseInt(K.getNode().getAttribute("onlineFriends"),10)}if(K&&K.getNode().getAttribute("type")&&(K.getNode().getAttribute("type")==="unavailable")){I.userstatus="invisible"}if(D&&(D.tagName.toLowerCase()==="user")){I.user={};["username","avatarUrl","firstname","shout","distro"].each(function(Q){I.user[Q]=unescape(D.getAttribute(Q))});I.user.status=I.userstatus;I.user.name=I.user.username}return I};this._onInvalidSID=function(D){var C={hash:this.connection.hash,signature:this.connection.signature,username:this.connection.username,userID:this.connection.userID};this.getSession(C)};this._onIQ=function(K){var E=K.getType();var M=K.getID();var I=K.getChild();var C=K.getFrom();var J;if(E==="get"){this.connection.addPacketToQueue(ERR_FEATURE_NOT_IMPLEMENTED())}else{if(E==="error"){debug("An iq error occured");this.connection.connected=false;this.connection.connectErrors++;this.connection.lastError=new Date().getTime();return false}else{if(E==="set"){var G;if(M==="game_challenge"){G=I.getAttribute("json");J=I.getAttribute("from").match(/(.*)\@(.*)/);this.controller.games.challengeReceived(G,J[1]);return }if(M==="nudge"){G=I.childNodes[0].nodeValue;J=I.getAttribute("from").match(/(.*)\@(.*)/);if(G){this.controller.nudgeReceived(G,J[1])}}if(C){J=C.match(/([a-z]+)\@(.*)/);if(J&&J[1]&&(J[1]==="netlog")){var N=I;var F=parseInt(N.getAttribute("messages"),10);var H=parseInt(N.getAttribute("friendships"),10);var L=parseInt(N.getAttribute("notifications"),10);this.notify("onNewCounters",{messages:F,friendships:H,notifications:L})}}}else{if(E==="result"){if(M==="get_roster"){this._onRosterLoaded(K)}if(I&&(I.getAttribute("xmlns")==="netlog-messageArchive")){var D=C.replace("@chat.netlog.com","");if(D&&this.archiveCallbacks[D]){this.archiveCallbacks[D](K)}}}else{debug("An unknow IQ occured: "+E)}}}}return false};this._onConnect=function(){this.notify("onConnect");window.chatStatus="onConnect";this.connection.registerHandler("message",this._onMessage.bind(this));this.connection.registerHandler("presence",this._onPresence.bind(this));this.connection.registerHandler("iq",this._onIQ.bind(this));this.connection.registerHandler("onDisconnect",this._onDisconnect.bind(this));this.connection.registerHandler("onError",this._onError.bind(this));this.connection.registerHandler("onReconnect",this._onReconnect.bind(this));this.connection.registerHandler("onReceiveOnlinePeopleCount",this.onReceiveOnlinePeopleCount.bind(this));this.connection.registerHandler("onProcess",this._onProcess.bind(this))};this._onProcess=function(C){this.notify("onProcess",C)};this.onReceiveOnlinePeopleCount=function(C){this.notify("onReceiveOnlinePeopleCount",C)};this._onReconnect=function(){this.notify("onReconnect")};this._onDisconnect=function(){this.notify("onDisconnect")};this._onError=function(C){debug("_onError()");if(this.connection.connected){this.connection.disconnect()}};this.getRoster=function(){return this.roster};this.isRosterLoaded=function(){return this.isRosterLoaded};this._onRosterLoaded=function(D){if(this.rosterTimeout){window.clearTimeout(this.rosterTimeout)}var I={"":"online",chat:"online",dnd:"busy",away:"away",xa:"invisible",idle:"away"};var K=D.getQuery().childNodes;for(var N=0,O=K.length;N<O;N++){var R=K[N];var Q="invisible";var L="";var E=ComCore.Configuration.get("photoStaticURL")+"/p/tt/000/000/0.jpg";var G=R.getAttribute("jid").substr(0,R.getAttribute("jid").indexOf("@"));var T=R.getAttribute("name");var C=R.getAttribute("presence");var F=R.getElementsByTagName("presence");var M=parseInt(R.getAttribute("userID"),10);var P=R.getAttribute("distro")||ComCore.Configuration.get("language");var S=R.getElementsByTagName("lastShout");var H=R.getElementsByTagName("avatarUrl");if((S.length>0)&&(S[0].childNodes.length>0)){L=S[0].childNodes[0].nodeValue}if((H.length>0)&&(H[0].childNodes.length>0)){E=H[0].childNodes[0].nodeValue}if(C!==null){if(I[C]){Q=I[C]}else{Q="busy"}}else{if(F&&F.length>0){var J=this.getPresenceStatus(JSJaCPacket.wrapNode(F[0]));Q=J.userstatus}}this.roster[G]={username:G,name:T,userID:M,shout:L,avatarUrl:E,status:Q,distro:P}}this.isRosterLoaded=true;this.notify("onRosterLoaded")};this.loadRoster=function(E){E=(E===undefined)?false:E;this.rosterTimeout=window.setTimeout((function(){if(this.controller&&this.controller.logging&&(this.controller.logging.state==="START")){this.controller.logging.addCustom("QUEUE "+this.connection._outQueue.join(",")+" | AJAX REQ COUNT: "+this.connection.getAjaxCount()+" | AJAX DATA: "+this.connection.currentPostData)}this.controller.onlineFriends.displayRosterError()}).bind(this),10000);var D=E===false?' small="true"':"";var C={xml:function(){return'<iq type="get" id="get_roster"'+D+'><query xmlns="jabber:iq:roster"/></iq>'}};this.connection.addPacketToQueue(C)};this.sendCustomMessage=function(D,C,E){this.sendMessage(D,C,E)};this.sendNudge=function(C,D){this.sendCustomIQ("nudge",D,C)};this.sendCustomIQ=function(D,F,H){var E=F+"@chat.netlog.com";var G=this.connection.username+"@chat.netlog.com";var C={xml:function(){return'<iq to="'+E+'" type="set" id="'+D+'"><payload xmlns="http://chat.netlog.com/xmlns/customiq" from="'+G+'">'+H+"</payload></iq>"}};this.connection.addPacketToQueue(C)};this._quit=function(){if(this.isQuitting===true){return }if(this.controller.logging&&(this.controller.logging.state==="START")){this.controller.logging.sendInvalid()}var D=this.connection.connected;window.clearInterval(this.connection.poller);this.notify("onQuit");this.connection.terminated=true;this.isQuitting=true;try{var C=new ComCore.JabberCookieStore();var F=C.getSessionsObject();if(F[this.connection.resource]){F[this.connection.resource].in_use=false;F[this.connection.resource].timestamp=new Date().getTime()}else{if(this.connection.sid&&this.connection.resource){F[this.connection.resource]={in_use:false,sid:this.connection.sid,resource:this.connection.resource,hash:this.connection.hash,timestamp:new Date().getTime(),signature:this.connection.signature,username:this.connection.username.toLowerCase(),uid:this.connection.userID}}}if((D===true)&&this.connection.sid){C.writeSessionsObject(F)}}catch(E){debug("Could not write cookie: "+E)}};this.initialize(B,A)};ComCore.Events.extend(ComCore.Jabber.Connection);if(!ComCore.Chat){ComCore.Chat={}}ComCore.Chat.Constants={TAB_WIDTH:142,WINDOW_WIDTH:254,CHAT_STATE_NOTIFICATION_RECEIVED_TIMEOUT:30000,CHAT_STATE_TYPING_TIMEOUT:7000,COOKIE_OBSERVE_INTERVAL:2000,SCROLL_DURATION:0.2,CHAT_STATUSSES:["Everyone","Friends","Busy","Away","Invisible"],MAX_COOKIE_ELEMENTS:20,REFRESH_EVERYONE_INTERVAL:30000,SHOW_BUBBLE_TIME:5000,IDLE_TIMEOUT:300000,ACTIVE_BLINK_TIMEOUT:3000};function log(A,B,E){var C=$("logContainer");if(C&&(ComCore.Chat.Settings.debug!==undefined)){var F=new Element("div",{"class":"txt"});var D=new Element("li");if(B!==undefined){F.insert(new Element("span",{"class":"type"+B}).update(B+": "))}D.insert(new Element("span",{"class":"timestamp"}).update(new Date().toString()));D.insert(F.insert(ComCore.Chat.FormatText.stripHTML(A)));C.insert(D)}if(E===undefined){debug(A)}}String.prototype.ucFirst=function(){return this.substr(0,1).toUpperCase()+this.substr(1,this.length)};String.prototype.trim=function(){var A=this.toString();A=A.replace(/^\s+/,"");A=A.replace(/\s+$/,"");return A};ComCore.Chat.Helper={array_merge:function(){var D=[];for(var C=0,A=arguments.length;C<A;C++){for(var B=0,E=arguments[C].length;B<E;B++){D=D.concat(arguments[C][B])}}return D},parseDate:function(A){var E=A.split(" ");var C=E[0].split("-");var B=E[1].split(":");var D=C[1]-1;if(D<0){D=11}return new Date(C[0],D,C[2],B[0],B[1],B[2])},getImagePathId:function(B){var A=B.split("/");return parseInt(A[A.length-1].replace(".jpg",""),10)},getWindowPosition:function(){var A=parseInt($("chatTabsList").getStyle("right").replace("px",""),10);var B=Math.abs(Math.round(A/ComCore.Chat.Constants.TAB_WIDTH));var D=Math.floor($("chatTabsContainer").clientWidth/141);var C=(B+(D-1));return{left:C,right:B}},str_pad:function(B,G,F,C){var E="",D;var A=function(I,H){var J="";while(J.length<H){J+=I}J=J.substr(0,H);return J};B+="";if(C!=="STR_PAD_LEFT"&&C!=="STR_PAD_RIGHT"&&C!=="STR_PAD_BOTH"){C="STR_PAD_RIGHT"}if((D=G-B.length)>0){if(C==="STR_PAD_LEFT"){B=A(F,D)+B}else{if(C==="STR_PAD_RIGHT"){B=B+A(F,D)}else{if(C==="STR_PAD_BOTH"){E=A(F,Math.ceil(D/2));B=E+B+E;B=B.substr(0,G)}}}}return B},buildImagePath:function(D,B){var C=ComCore.Chat.Helper.str_pad(D,9,0,"STR_PAD_LEFT");var A=ComCore.Configuration.get("photoStaticURL");if(B!==undefined){A="http://"+B+".netlogstatic.com"}return A+"/p/tt/"+C.substr(0,3)+"/"+C.substr(3,3)+"/"+D+".jpg"},getMsgFormatted:function(C,B){for(var A in B){if(B.hasOwnProperty(A)){C=C.replace(new RegExp("\\%"+A+"%","gi"),B[A])}}return C},getTranslation:function(A,B){return ComCore.Chat.Helper.getMsgFormatted(ComCore.Chat.Messages[A],B)},sortByName:function(A){return ComCore.Chat.Helper.cleanName(A.firstname.toLowerCase())},cleanName:function(A){return A.replace(/[\xC0-\xC6]/g,"A").replace(/[\xE0-\xE6]/g,"a").replace(/[\xC8-\xCB]/g,"E").replace(/[\xE8-\xEB]/g,"e").replace(/[\xCC-\xCF]/g,"I").replace(/[\xEC-\xEF]/g,"i").replace(/[\xD2-\xD6]/g,"O").replace(/[\xF2-\xF6]/g,"o").replace(/[\xD9-\xDC]/g,"U").replace(/[\xF9-\xFC]/g,"u").replace(/[\xD1]/g,"N").replace(/[\xF1]/g,"n")},sortList:function(G){var D;var B={online:[],invisible:[],away:[],busy:[]};var F=ComCore.Chat.WelcomeMessage.name;if(G.length===0){return }G=G.sortBy(ComCore.Chat.Helper.sortByName);for(var E=0,A=G.length;E<A;E++){D=G[E];if(D.status&&(D.username!==F)){if(B[D.status]){B[D.status].push(D)}else{log("something went wrong"+D.status)}}}var C=ComCore.Chat.Helper.array_merge(B.online||[],B.busy||[],B.away||[],B.invisible||[]);return C}};ComCore.Chat.Button=Class.create({initialize:function(B,A){this.button=$(B);this.isBlinking=false;if((A===undefined)||(A===true)){this.button.observe("click",this._onClick.bind(this));this.observe("onChange",this._render.bind(this))}this.active=false},_onClick:function(A){A.stop();this.setActive(!this.isActive());this.notify("onClick")},_render:function(){this.button[this.isActive()?"addClassName":"removeClassName"]("active")},setLabel:function(A){this.button.down(".chatTabLabel").update(ComCore.Chat.FormatText.shorten(A,8));return this},getLabel:function(){return this.button.down(".chatTabLabel").innerHTML},setActive:function(A){if(A!==this.active){this.active=A;this.notify("onChange")}return this},isActive:function(){return this.active},show:function(){this.button.show();return this},hide:function(){this.button.hide();return this},visible:function(){return this.button.visible()},getType:function(){return"BUTTON"},getID:function(){return this.button.id},blink:function(){this.button.toggleClassName("blink")},setBlinking:function(B,A){if((A!==false)&&(B===true)){this.notify("onBlink")}if(B===true){if(this.isBlinking===false){this.blinkIntervalID=window.setInterval((function(){this.blink()}).bind(this),250);if(this.isActive()){window.setTimeout((function(){this.setBlinking(false)}).bind(this),ComCore.Chat.Constants.ACTIVE_BLINK_TIMEOUT)}this.isBlinking=true}}else{window.clearInterval(this.blinkIntervalID);this.button.removeClassName("blink");this.isBlinking=false}return this},_eoo:true});ComCore.Events.extend(ComCore.Chat.Button);ComCore.Chat.ChatStatusButton=Class.create({initialize:function(A,B){this.button=B;this.button.observe("click",this._togglechatStatusWindow.bind(this));this.controller=A;this.controller.userStatus.observe("onUserStatusChanged",this._onUserStatusChanged.bind(this))},_togglechatStatusWindow:function(A){A.stop();this.notify("onToggleUserWindow")},setLoading:function(A){this.button[A?"addClassName":"removeClassName"]("loading");return this},setStatus:function(){var D=this.controller.userStatus.jabberStatus;var E=ComCore.Chat.Constants.CHAT_STATUSSES;var B=5;var C;var A=this.button.down("img");while(B--){C=E[B];A[D.toLowerCase()===C.toLowerCase()?"addClassName":"removeClassName"]("iconStatus"+C)}return this},_onUserStatusChanged:function(){this.setStatus()},_eoo:true});ComCore.Events.extend(ComCore.Chat.ChatStatusButton);ComCore.Chat.ConversationButton=Class.create(ComCore.Chat.Button,{initialize:function($super,B,A,C){this.user=B;this.controller=A;this.isFriend=(this.user.nofriend===undefined);if(C!==undefined){$super(C)}else{$super(this._create(this.user.username))}this.unreadCount=this.button.down(".chatTabUnreadCount");this.setLabel((this.isFriend===true)?this.user.firstname:this.user.username);this.setStatus(this.user.status)},onChatStateNotification:function(D){var B=this.controller.onlineFriends.get(this.user.username);if(B&&B.element&&B.element.getElement()){var C=B.element.getElement().down("img.iconStatus");var A=this.button.down("img.chatTabStatus");if(D==="composing"){if(C){C.className="icon iconStatus "+D}A.className="icon chatTabStatus "+D;window.setTimeout(this.onChatStateNotification.bind(this,"active"),ComCore.Chat.Constants.CHAT_STATE_NOTIFICATION_RECEIVED_TIMEOUT)}else{if(C){C.className="icon iconStatus iconStatus"+(B.nofriend===undefined?this.user.status.ucFirst():"Everyone")}A.removeClassName("composing");this.user=this.controller.onlineFriends.users.get(this.user.username);this.setStatus(this.user.status)}}},showButton:function(A){this.controller.scrollController.requestAction((function(){this.show().setActive(true)}).bind(this))},_create:function(B){var A=$("chatTab").cloneNode(true);A.addClassName("conversation");if(this.isFriend!==true){A.addClassName("nofriend")}A.id="chatTab_"+B;var C=ComCore.Chat.Helper.getTranslation("conversationButtonTitle",{username:this.user.name});A.title=C.trim();$("chatTabsList").insert(A);return A.id},_onClick:function($super,A){A.stop();if(A.element().hasClassName("chatTabClose")){this.notify("onClose",this.user.username)}else{$super(A)}},resetUnreadCount:function(){this.unreadCount.update(0).hide();return this},updateUnreadCount:function(){log("updateUnreadCount");var A=this.getUnreadCount()+1;if(A>99){A="99+"}this.unreadCount.update(A).show();return this},getUnreadCount:function(){return parseInt(this.unreadCount.innerHTML,10)},setStatus:function(D){if(this.isFriend===false){this.button.down("img.chatTabStatus").className="icon chatTabStatus iconStatusEveryone";return this}var E=["Online","Busy","Away","Invisible"];if(this.user.nofriend!==undefined){D="Everyone";E.push("Everyone")}var B=E.length;var C;var A=this.button.down("img.chatTabStatus");while(B--){C=E[B];A[(D.toLowerCase()===C.toLowerCase())?"addClassName":"removeClassName"]("iconStatus"+C)}return this},getID:function(){return this.user.username},_eoo:true});ComCore.Chat.Window=Class.create({initialize:function(C,B,A){this.window=$(C);this.button=B;this.close=this.window.down(".chatTabClose");this.minimize=this.window.down(".minimize");if((A===undefined)||(A===true)){this.window.observe("click",this._onClick.bindAsEventListener(this))}},_onClick:function(C){C.stop();var B=C.findElement("a");if(!B){return }if(B===this.close){this._onClose()}else{if(B===this.minimize){this._onMinimize()}else{var A=B.getAttribute("href").replace(/\u200b|<wbr(.*)>/g,"").replace(/%E2%80%8B/g,"");if(B.getAttribute("target")==="_blank"){window.open(A)}else{window.location=A}}}},_onClose:function(){},_onMinimize:function(){this.button.setActive(false)},setTitle:function(A){this.window.down(".title").update(A);return this},getTitle:function(){return this.window.down(".title").innerHTML},closeWindow:function(){this.button.setActive(false);this.window.hide()},setActive:function(A){this.window[A===true?"addClassName":"removeClassName"]("open")},isVisible:function(){var B=this.button.button.previousSiblings().length-1;var D=ComCore.Chat.Helper.getWindowPosition();var C=D.left;var A=D.right;if((B<=C)&&(B>=A)){return true}return false},openWindow:function(){this.setActive(true);this.button.setActive(true);this.window.show()},calculatePosition:function(){return((this.button.button.cumulativeOffset()[0]-this.window.getWidth())+this.button.button.getWidth()-4)},setPosition:function(){this.window.setStyle({left:this.calculatePosition()+"px"})},show:function(){this.setActive(true);this.setPosition();this.window.show();return this},hide:function(){this.window.hide();return this},toggle:function(){if(this.positionSet===undefined){this.setPosition();this.positionSet=true}this.window.toggle();return this},_eoo:true});ComCore.Events.extend(ComCore.Chat.Window);ComCore.Chat.chatStatusWindow=Class.create({initialize:function(A,B){this.controller=A;this.chatStatusButton=B;this.window=$("chatStatusWindow");this.chatStatusButton.observe("onToggleUserWindow",this._toggleWindow.bind(this));ComCore.Chat.UserStatus.observe("onUserStatusChanged",this._statusChange.bind(this));this.window.observe("click",this._onContentClick.bind(this))},_statusChange:function(){this.setStatus(this.controller.userStatus.jabberStatus)},_toggleWindow:function(A){this.window.toggle()},_onContentClick:function(A){var B=A.findElement("li");A.stop();var D=B.getAttribute("id").replace("chatStatus_","");var C=this.controller.userStatus.statusMapping[D];$$("#chatStatusWindow li").invoke("removeClassName","chatStatusCurrent");B.addClassName("chatStatusCurrent");this.controller.userStatus.set(C,true,D);this.hide()},setStatus:function(B){var A=this.window.down("#chatStatus_"+B);if(A){this.window.select("li").invoke("removeClassName","chatStatusCurrent");A.addClassName("chatStatusCurrent")}},hide:function(){this.window.hide()},show:function(){this.window.show()},_eoo:true});ComCore.Chat.State=Class.create({cookieStore:new ComCore.JabberCookieStore(),initialize:function(A){this.controller=A},getState:function(){var A=this.cookieStore.getCurrentState();return(A!==undefined)?A.w:undefined},writeState:function(A){this.cookieStore.writeCurrentState(A)},writeRoster:function(B,A){this.cookieStore.writeRoster({roster:B,time:new Date().getTime()})},getLastUpdateRoster:function(){var A=this.cookieStore.getRoster();if(A&&A.time){return A.time}},getRoster:function(){var A=this.cookieStore.getRoster();if(A){return A}return false},updateRoster:function(F){function C(G){var H={u:escape(G.username),s:G.status,f:escape(G.firstname),a:ComCore.Chat.Helper.getImagePathId(G.avatarUrl),id:G.userID};if(G.shout){H.t=escape(ComCore.Chat.FormatText.shortenShout(G.shout))}return H}if((F===undefined)||((F.constructor===Array)&&(F.length===0))){return }F=ComCore.Chat.Helper.sortList(F);var E=F.findAll(function(G){return((G.status!==undefined)&&(G.status!=="invisible")&&(G.nofriend===undefined)&&(G.username!==ComCore.Chat.WelcomeMessage.name))});var B=0;E=E.collect(function(G){if(B++<7){return C(G)}});if(!E){E=[]}if(E.length<7){var D=7-E.length;var A=F.findAll(function(G){return((G.status==="invisible")&&(G.nofriend===undefined))});A=A.collect(function(G){return C(G)});if(A.length>0){A=A.eachSlice(D).first();E=ComCore.Chat.Helper.array_merge(E,A)}}this.writeRoster(E,F)},updateJabberStatus:function(A){this.cookieStore.writeJabberStatus(A)},getJabberStatus:function(){return this.cookieStore.getJabberStatus()},updateState:function(){var K=this.controller.onlineFriends.users.values();if(!K){this.writeState([]);return }var R=[];var Q=$$("#chatConversationWindows div.open");var G=0;if(Q&&Q.length>0){var E=Q.first().getAttribute("id").replace("conversationWindow_","");var H=this.controller.conversationWindow(E);if(H){G=((H.button.button.cumulativeOffset()[0]-H.window.getWidth())+H.button.button.getWidth()-4);if(H.window.visible()){G+=4}}}var A=this.controller.conversations.values();var S,I,C,O,T,J;for(var L=0,M=A.length;L<M;L++){S=A[L];I=S.b;C=S.w;if(I&&(C.window.hasClassName("open"))){O=S.c.user.status;T=this.controller.onlineFriends.get(S.c.user.username);J=I.getUnreadCount();if(C){R.push({username:T.username,friend:(T.nofriend===undefined),firstname:T.firstname,state:C.window.visible(),position:L,status:O,m:J,id:T.userID,a:ComCore.Chat.Helper.getImagePathId(T.avatarUrl)})}}if(L>ComCore.Chat.Constants.MAX_COOKIE_ELEMENTS){break}}var F=parseInt($("chatTabsList").getStyle("right").replace("px",""),10);var N=(F!==0)?F:0;var D=K.findAll(function(U){return((U.status!=="invisible")&&(U.status!=="offline")&&(U.nofriend===undefined))});var P=(D!==undefined)?D.length:0;var B={w:R,p:G,o:Math.round($("chatTabsContainer").clientWidth/ComCore.Chat.Constants.TAB_WIDTH),f:N};this.updateOnlinePeopleCountCookie();this.writeState(B)},updateOnlinePeopleCountCookie:function(){var A=$("hudButtonChatCount").innerHTML.match(/\((\d*)\)/);var B=(A.length===2)?~~A[1]:0;this.cookieStore.updatePeopleCount(B)}});ComCore.Chat.ConversationWindow=Class.create(ComCore.Chat.Window,{initialize:function($super,D,C,B,F){this.conversation=D;this.smileysLoaded=false;this.isFriend=(this.conversation.user.nofriend===undefined);if(F!==undefined){$super(F,C)}else{$super(this._create(this.conversation.user),C)}this.objectStash=$H();this.user=this.conversation.user;this.controller=B;this.status=this.controller.userStatus.status;this.form=this.window.down("form");this.form.observe("submit",this.onSendMessage.bindAsEventListener(this));this.input=this.form.down("input");this.input.setAttribute("id","chatinput_"+this.conversation.user.userID);this.input.observe("keyup",this.onKeyUp.bind(this));this.input.observe("keydown",this.onKeyDown.bind(this));this.hasFocus=false;this.input.observe("click",this.onInputFocus.bind(this));this.input.observe("focus",this.onInputFocus.bind(this));this.input.observe("blur",this.onInputBlur.bind(this));if((ComCore.Chat.Settings.yamli===true)&&(typeof (window.Yamli)!=="undefined")){var E=new ComCore.Yamli(this.input.getAttribute("id"));E.yamlify(true)}var A=this.window.select("dt.newDay").last();if(A){this.dayFromLastMessage=this.getDayFormat(ComCore.Chat.Helper.parseDate(A.getAttribute("rel")))}else{this.dayFromLastMessage=new Date().getDay()}this.usernameFromLastMessage=this.user.username;if(this.isFriend===false){this.abuseButton=this.getObject(".chatAbuse");this.abuseButton.observe("click",this._sendAbuse.bind(this))}this.smileyButton=this.window.down(".chatSmilies");this.smileyButton.observe("click",this._handleSmilies.bind(this));this.offlineWarning=this.window.down(".conversationOfflineWarning");ComCore.Chat.UserStatus.observe("onUserStatusChanged",this._statusChange.bind(this));this.changeStatusLink=this.offlineWarning.down("a");this.changeStatusLink.observe("click",this.onChangeStatus.bind(this));this.addAsFriendLink=this.window.down(".chatAddAsFriend");this.addAsFriendLink.setAttribute("href","/friends/add/userid="+this.conversation.user.userID);this.addAsFriendLink.setAttribute("rel",this.conversation.user.userID);this.addAsFriendLink[(this.isFriend===false)?"show":"hide"]();this.addAsFriendLink.observe("click",this.onAddFriend.bind(this));this.messageHistory=[];this.messageHistoryPosition=0;this.clearArchiveLink=this.window.down(".clearArchive");this.clearArchiveLink.observe("click",this.onClearArchive.bind(this));this.getObject(".conversationContent").observe("click",this.focusConversationWindow.bind(this));this.controller.onlineFriends.observe("onUserStatusChanged",this.onUserStatusChanged.bind(this));this.conversation.observe("onMessageAdded",this.onMessageAdded.bind(this));if(this.user.status&&(this.user.status==="invisible")){this.showOfflineNotice()}if(this.controller.userStatus.status==="invisible"){this.showofflineWarning()}window.setTimeout((function(){this.hideLoading()}).bind(this),10000);this.typingState="ACTIVE"},focusConversationWindow:function(A){if($(this.form).visible()){this.input.focus()}},clearArchive:function(){this.usernameFromLastMessage="";this.dayFromLastMessage=new Date().getDay();this.getObject(".conversation").innerHTML="";[this.clearArchiveLink,this.window.down("img.iconTrash")].invoke("addClassName","disabled")},onClearArchive:function(A){if(this.clearArchiveLink.hasClassName("disabled")){return }A.stop();if(confirm(ComCore.Chat.Messages.clearArchiveConfirm)===true){this.clearArchive();var B=new Ajax.Request(ComCore.Page.buildAjaxURL("chatbar","clearArchive"),{method:"post",parameters:{userid:this.user.userID,csrftoken_cleararchive:ComCore.CSRF.getToken("clearArchive")}})}},onInputFocus:function(A){this.hasFocus=true;this.button.resetUnreadCount();this.button.setBlinking(false);this.controller.windowTitle.onWindowFocus()},onInputBlur:function(A){this.hasFocus=false},onAddFriend:function(A){A.stop();ComCore.Dialog.initialize();ComCore.Dialog.options.width=750;if((this.conversation.user.userID===undefined)||isNaN(this.conversation.user.userID)){ComCore.Dialog.postContent(ComCore.Page.buildAjaxURL("friends","addFriend"),"nick="+escape(this.conversation.user.username))}else{ComCore.Dialog.postContent(ComCore.Page.buildAjaxURL("friends","addFriend"),"userid="+this.conversation.user.userID)}},onChatStateNotification:function(A){this.button.onChatStateNotification(A)},onKeyDown:function(A){var B=A.keyCode||A.which;var C=false;switch(B){case Event.KEY_UP:this.messageHistoryPosition--;C=true;break;case Event.KEY_DOWN:this.messageHistoryPosition++;C=true;break}if(C===true){A.stop();if(this.messageHistoryPosition<0){this.messageHistoryPosition=0}if(this.messageHistoryPosition>this.messageHistory.length){this.messageHistoryPosition=this.messageHistory.length}this.input.value=this.messageHistory[this.messageHistoryPosition]||""}},onKeyUp:function(A){A.stop();this.onInputFocus();var C=false;var B=A.keyCode||A.which;switch(B){case Event.KEY_DOWN:case Event.KEY_UP:C=true;break}if(C===true){this.typingState="ACTIVE";return }var D=this.input.value;if(D.length>0){this.startTyping();if(this.typingTimeout!==undefined){window.clearTimeout(this.typingTimeout)}this.typingTimeout=window.setTimeout(this.stopTyping.bind(this),ComCore.Chat.Constants.CHAT_STATE_TYPING_TIMEOUT)}else{this.stopTyping()}},startTyping:function(){if(this.typingState==="ACTIVE"){this.typingState="COMPOSING";this.controller.connection.sendTypingNotification("composing",this.user.username)}},stopTyping:function(){if(this.typingState==="COMPOSING"){this.typingState="ACTIVE";this.controller.connection.sendTypingNotification("active",this.user.username)}},getObject:function(B){var A=this.objectStash.get(B);if(!A){A=this.window.down(B);this.objectStash.set(A)}return A},onChangeStatus:function(A){A.stop();this.closeWindow();this.controller.onlineFriendsButton.setActive(true);this.controller.chatStatusWindow.show()},onReceiveArchive:function(){var A=this.conversation.user;var B=this.controller.onlineFriends.get(A.username);B.isArchiveLoaded=A.isArchiveLoaded=true;this.conversation.messages.each(function(C){if((C.body.gameName===undefined)&&(C.username.toLowerCase()===this.controller.connection.username.toLowerCase())){this.messageHistory.push(C.body);this.messageHistoryPosition=this.messageHistory.length;log("add msg "+C.body)}},this);if(A.pendingMessages){A.pendingMessages.each(function(C){this.controller.onMessageReceived(C)},this);A.pendingMessages=[]}if(this.archiveCallback){this.archiveCallback()}if(this.conversation.messages.length>0){[this.clearArchiveLink,this.window.down("img.iconTrash")].invoke("removeClassName","disabled")}this.hideLoading()},showofflineWarning:function(){if(this.controller.userStatus.status!=="online"){this.controller.userStatus.set("online",true,ComCore.Chat.Settings.chatPrivacy.toLowerCase());this.controller.showBubble("STATUS_CHANGED",this.user)}},hideofflineWarning:function(){if(!((this.controller.userStatus.jabberStatus==="friends")&&(this.isFriend===false))){this.form.show()}this.offlineWarning.hide();this.getObject(".conversationContent").scrollTop=this.getObject(".conversationContent").scrollHeight},_checkinvisible:function(){if(this.status==="invisible"){this.showofflineWarning()}else{this.hideofflineWarning()}},_statusChange:function(A){this.status=this.controller.userStatus.status},prepareSmilies:function(){this.getObject(".chatSmiliesList").observe("click",this._smileyClick.bind(this))},_smileyClick:function(B){B.stop();var C=Event.findElement(B,"a");if(!C){return }var A=C.parentNode;this.hideSmilies();if((ComCore.Login.isPremium()===false)&&(A.hasClassName("chatSmileypremium"))){ComCore.Chat.Smilies.premiumTeaser();return false}this.input.value+=C.title;if($(this.form).visible()){this.input.focus()}},_sendAbuse:function(B){if(this.abuseButton.hasClassName("disabled")){return }B.stop();if(confirm(ComCore.Chat.Helper.getTranslation("chatReportAbuse",{user:this.conversation.user.firstname}))){var A=new Element("input",{type:"hidden",name:"chatConversation"});var C=Object.toJSON(this.conversation.messages);A.value=C;this.form.insert(A);this.form.action="/"+escape(this.conversation.user.username)+"/abuse";this.form.submit()}},_handleSmilies:function(A){A.stop();var B=this.getObject(".chatSmiliesBox");this[B.visible()?"hideSmilies":"showSmilies"]()},hideSmilies:function(){this.animateSmilies(false)},showSmilies:function(){if(this.smileysLoaded===false){this.attachSmilies();this.prepareSmilies();this.smileysLoaded=true}this.animateSmilies(true)},animateSmilies:function(B){var E=B?0:100;var A=B?100:0;var C=this.getObject(".chatSmiliesBox");if(typeof (Effect)!=="undefined"){var D=new Effect.Tween(C,E,A,{duration:0.3,afterFinish:function(){if(A===0){C.hide()}}},function(F){C.show();C.setStyle({height:F+"px"})})}else{C[B===true?"show":"hide"]()}},hide:function($super){this.window.hide();this.button.setActive(false);$super();this.controller.state.updateState()},onUserStatusChanged:function(B,A){if(B===this.conversation.user.username){if(A==="invisible"){this.showOfflineNotice()}else{this.hideOfflineNotice()}}},showDisconnectedNotification:function(){this.getObject(".conversationDisconnected").show()},hideDisconnectedNotification:function(){this.getObject(".conversationDisconnected").hide()},addNotification:function(B){var A=this.getDateString(new Date());this.getObject(".conversation").insert('<dd><span class="chatTimestamp">'+A+'</span><br /><div class="info">'+B+"</div></dd>");this.getObject(".conversationContent").scrollTop=this.getObject(".conversationContent").scrollHeight},showLoading:function(){this.window.down(".conversationLoading").show();window.setTimeout((function(){this.hideLoading()}).bind(this),10000)},hideLoading:function(){var A=this.window.down(".conversationLoading");if(A){A.hide()}},attachSmilies:function(A){var B=ComCore.Chat.Settings.smilies;var C=[];$H(B).each(function(D){if(D.value.d===true){C.push("<li class='chatSmiley"+((D.value.t==="f")?"free":"premium")+"'><a href='#' title='"+D.key+"'><img src='"+ComCore.Configuration.get("staticURL")+"/s/i/smilies/"+D.value.i+"' alt='"+D.key+"'>")}});this.getObject(".chatSmiliesList").innerHTML=C.join("")},_create:function(B){var A=$("conversationWindow").cloneNode(true);A.addClassName("conversation");A.setAttribute("id","conversationWindow_"+B.username);if(B.shout&&B.shout.length>0){A.down(".chatShout").update(B.shout)}if(B.avatarUrl){A.down(".titleBar .avatar").setAttribute("src",B.avatarUrl)}if((B.shout===undefined)||(B.shout.length===0)){A.down(".chatShout").hide()}if((this.isFriend!==true)&&(A.down(".titleBar .chatAbuse"))){A.down(".titleBar .chatAbuse").show()}A.down(".titleBar a.chatUserLink").setAttribute("href","/"+escape(B.username));A.down(".titleBar .title").update(ComCore.Chat.FormatText.wordWrap((B.nofriend===undefined)?B.firstname:B.username,10));$("chatConversationWindows").insert(A);return A.getAttribute("id")},getDayFormat:function(B){var A=B.getDate();var C=B.getMonth()+1;if(A<10){A="0"+A}if(C<10){C="0"+C}return A+"/"+C},getDateString:function(B){var A=B.getHours();if(A<10){A="0"+A}var C=B.getMinutes();if(C<10){C="0"+C}return A+":"+C},onMessageAdded:function(H){if(this.abuseButton){this.abuseButton.removeClassName("disabled")}[this.clearArchiveLink,this.window.down("img.iconTrash")].invoke("removeClassName","disabled");this.button.onChatStateNotification("active");var L=H.message;var D=H.fromArchive;var G=H.type;var K=H.chat;if(G==="game"){L.body=this.controller.games.createBody(L)}else{if(G==="challengeSent"){L.body=this.controller.games.createChallengeSentBody(L,K)}else{if(L.username.toLowerCase()!==this.controller.connection.username.toLowerCase()){L.body=ComCore.Chat.FormatText.process(L.body,this)}else{L.body=ComCore.Chat.FormatText.process(L.body,this)}}}var E=this.controller.onlineFriends.users.get(L.username);var C=L.username;var F=(E&&(E.firstname!==undefined))?E.firstname:L.username;if(L.username.toLowerCase()===this.controller.connection.username.toLowerCase()){F=this.controller.connection.firstName}if(L.date===undefined){L.date=new Date()}var A=this.getDayFormat(L.date);if(this.dayFromLastMessage!==A){this.getObject(".conversation").insert('<dt class="newDay">'+A+"</dt>");this.dayFromLastMessage=A;this.getObject(".conversation").insert("<dt>"+F+"</dt>");this.usernameFromLastMessage=C}if(this.usernameFromLastMessage.toLowerCase()!==C.toLowerCase()){this.getObject(".conversation").insert("<dt>"+F+"</dt>");this.usernameFromLastMessage=C}var B=this.getDateString(L.date);var I=(G!==undefined)?'<dd class="gameChallengeBody">':"<dd>";this.getObject(".conversation").insert(I+'<span class="chatTimestamp">'+B+'</span><span class="chatMessage">'+L.body+"</span></dd>");this.doScroll();if(G==="game"){var J=this.window.select("div.gameImage img").last();if(J){J.observe("load",this.doScroll.bind(this))}}if(((!this.button.isActive())||(this.controller.windowTitle.hasFocus===false))&&(this.controller.connection.username!==L.username)&&(D!==true)){log("new update");this.button.updateUnreadCount()}},doScroll:function(){this.getObject(".conversationContent").scrollTop=this.getObject(".conversationContent").scrollHeight},onSendMessage:function(C){C.stop();var B=this.input.value;this.input.value="";if(B.length===0){return }if(B.length>ComCore.Chat.Settings.maximumCharsAllowedPerMessage){this.addError(ComCore.Chat.Messages.messageTooLong);return }this.messageHistory.push(B);this.messageHistoryPosition=this.messageHistory.length;this.notify("onSendMessage",this.conversation.user.username,B);try{$(document).fire("comcore:chat_conversations_sendmessage",{from_userid:ComCore.Login.getUserID(),to_userid:this.conversation.user.userID})}catch(A){log(A)}},addError:function(A){this.getObject(".conversation").insert('<dd class="chatError">'+A+"</dd>");this.doScroll()},showOfflineNotice:function(){var B=ComCore.Chat.Helper.getTranslation("contactOffline",{contact:this.conversation.user.firstname});var A=this.getObject(".conversationOfflineNotice");A.update(B);A.show();this.button.onChatStateNotification("active")},hideOfflineNotice:function(){this.getObject(".conversationOfflineNotice").hide()},show:function($super){this.button.setBlinking(false);this.button.resetUnreadCount();$super();this.doScroll();if($(this.form).visible()){this.input.focus()}this._checkinvisible();this.controller.state.updateState()},_onClose:function(){this.notify("onClose",this.conversation.user.username)},_eoo:true});ComCore.Chat.Conversation=Class.create({initialize:function(A){this.user=A;this.messages=[]},addMessage:function(D){var G=D.username;var F=D.message;var H=D.fromArchive;var E=D.type;var B=D.chat;var C=D.date||new Date();var A={username:G,body:F,date:C};this.messages.push(A);if(H!==true){this.notify("onMessageAdded",{message:A,fromArchive:false,type:E,chat:B})}},_eoo:true});ComCore.Events.extend(ComCore.Chat.Conversation);ComCore.Chat.OnlineFriendsElement=Class.create({parentUL:false,title:false,friendElement:null,initialize:function(A){this.user=A;this.html=this._createElement(A)},_setFriendElement:function(){this.friendElement=$("onlineFriend_"+this.user.username)},getHTML:function(){return this.html},_createElement:function(A){var B="";if(A.shout){B=ComCore.Chat.FormatText.removeHTML(A.shout)}var C=ComCore.Chat.Helper.getTranslation("conversationButtonTitle",{username:A.name});return'<li onclick="ComCore.Chat.controller.onlineFriendsWindow.onClick(this); return false;" class="'+A.status+'" id="onlineFriend_'+A.username+'"><a href="javascript://" class="clearfix"><img class="avatar" src="'+A.avatarUrl+'" alt="" /><img class="icon iconStatus iconStatus'+A.status.ucFirst()+'" src="'+ComCore.Configuration.get("staticURL")+'/s/i/common/blank.gif" alt="" /><strong class="name">'+ComCore.Chat.FormatText.wordWrap(A.firstname,20)+'</strong><br /><span class="unreadMessages" style="display: none">0</span><small class="shout">'+B+"</small></a></li>"},getElement:function(){if(this.friendElement===null){this._setFriendElement()}return this.friendElement},_eoo:true});ComCore.Chat.OnlineEveryoneElement=Class.create(ComCore.Chat.OnlineFriendsElement,{initialize:function(A){this.user=A;this.html=this._createElement(A)},_createElement:function(B){var D="";if(B.shout){D=ComCore.Chat.FormatText.removeHTML(B.shout)}var G=ComCore.Chat.Helper.getTranslation("conversationButtonTitle",{username:B.name});var E="";if(B.gender&&B.age&&B.region){var A=B.gender;var F='<img class="icon icon'+A.toLowerCase().ucFirst()+'" src="'+ComCore.Configuration.get("staticURL")+'/s/i/common/blank.gif" alt="" />';var C=$A([F,B.age,B.region]);E=C.compact().join("-")}return'<li onclick="ComCore.Chat.controller.onlineFriendsWindow.onClick(this); return false;" class="iconStatusEveryone" id="onlineFriend_'+B.username+'"><a href="javascript://" class="clearfix"><img class="avatar" src="'+B.avatarUrl+'" alt="" /><img class="icon iconStatus iconStatusEveryone" src="'+ComCore.Configuration.get("staticURL")+'/s/i/common/blank.gif" alt="" /><strong class="name">'+ComCore.Chat.FormatText.wordWrap(B.username,20)+'</strong><br /><span class="asl">'+E+'</span><span class="unreadMessages" style="display: none">0</span><small class="shout">'+D+"</small></a></li>"},_eoo:true});ComCore.Chat.SearchController=Class.create({initialize:function(A){this.friendsWindow=A;this.searchInput=this.friendsWindow.searchInput;this.searchResetIcon=this.friendsWindow.searchResetIcon;this.resetVars();this.searchInput.observe("keyup",this.onSearch.bind(this));this.searchInput.observe("click",this.onInputClick.bind(this));this.searchResetIcon.observe("click",this.onResetSearch.bind(this))},onInputClick:function(A){A.stop()},resetVars:function(){this.searchResults=[];this.currentResult=null;this.currentPosition=0},onSearch:function(H){var C=this.friendsWindow.controller.onlineFriends;if(!!C.fullRosterLoaded===false){C.load(this.onSearch.bind(this,H),true)}var I=H.keyCode||H.which;if(I===Event.KEY_ESC){this.onResetSearch(H);return }if(I===Event.KEY_DOWN||I===Event.KEY_UP){this.handleArrows(I===Event.KEY_UP);H.stop();return }if(I===Event.KEY_RETURN){this.selectElement();return }var A=this.searchInput.getValue().trim();if(A.length>0){this.currentPosition=0;var F=this.friendsWindow.onlineFriends.search(A);var B=[];for(var D=0,G=F.length;D<G;D++){B.push(this.friendsWindow.onlineFriends.get(F[D]))}var E=$$("#chatListRoster li");E.invoke("hide");if(B.length>0){B=B.sortBy(ComCore.Chat.Helper.sortByName);this.searchResults=B.collect(function(J){return J.element.getElement()});this.searchResults.invoke("show");this.searchResults=E.reject(function(J){return !J.visible()});this.currentResult=this.searchResults.first();if(this.currentResult){this.clearHighlights();this.currentResult.down("a").addClassName("highlight")}}this.friendsWindow.window.down(".search").addClassName("active")}else{this.onResetSearch(H)}},selectElement:function(){this.currentResult=this.searchResults[this.currentPosition];if(this.currentResult){var A=this.currentResult.id.replace(/onlineFriend_/,"").toLowerCase();this.resetSearch();this.friendsWindow.closeWindow();this.friendsWindow.notify("onStartChat",A,true)}},handleArrows:function(A){this.currentResult=this.searchResults[this.currentPosition];if(this.currentResult){this.currentPosition+=A?-1:1;if(this.currentPosition>=this.searchResults.length){this.currentPosition=0}if(this.currentPosition<0){this.currentPosition=this.searchResults.length-1}this.currentResult=this.searchResults[this.currentPosition];if(this.currentResult){this.clearHighlights();this.currentResult.down("a").addClassName("highlight")}}},clearHighlights:function(){$$("#chatListRoster li a.highlight").invoke("removeClassName","highlight")},onResetSearch:function(A){A.stop();this.resetSearch()},resetSearch:function(){this.clearHighlights();this.resetVars();this.friendsWindow.window.down(".search").removeClassName("active");$$("#chatListRoster li").invoke("show");this.searchInput.value="";this.searchInput.focus()},_eoo:true});ComCore.Chat.OnlineFriendsWindowHeader=Class.create({initialize:function(A){this.controller=A;this.windowHeader=$("chatListHeader");this.shoutInputField=$("chatShoutFormInput");this.chatShoutChange=$("chatShoutChange");this.chatShoutSave=$("chatShoutSave");this.chatShoutForm=$("chatShoutForm");this.chatShout=$("chatShout");this.myShout=this.chatShout.down("span");this.shout=this.myShout.innerHTML.trim();this.shoutError=$("chatShoutError");this.shoutErrorMsg=this.shoutError.down(".chatShoutErrorMsg");this.closeShout=$("chatShoutCancel");this.closeShout.observe("click",this._closeShout.bind(this));this.shoutInputField.observe("click",function(B){B.stop()});this.shoutInputField.observe("keypress",this._handleKeypress.bind(this));this._attachEvents()},_closeShout:function(A){A.stop();this.closeShoutF()},closeShoutF:function(){this.chatShoutForm.hide();this.chatShout.show()},_handleKeypress:function(A){if(this.shoutInputField.value.length>140){this.shoutInputField.value=this.shoutInputField.value.substring(0,140)}},_attachEvents:function(){this.chatShoutChange.observe("click",this._toggleShout.bind(this));this.chatShoutSave.observe("click",this._toggleShout.bind(this))},_toggleShout:function(B){var A=Event.element(B);B.stop();if(A===this.chatShoutSave){this._saveShout()}else{this.toggleView();this.shoutInputField.focus()}},toggleView:function(){this.chatShout.toggle();this.chatShoutForm.toggle()},_saveShout:function(){var A=this.shoutInputField.value.trim();A=ComCore.Chat.FormatText.stripHTML(A);this.sendNewShout(A)},sendNewShout:function(B){this.newShout=B;var C=$("chatShoutLoading");this.shoutTimeout=window.setTimeout((function(){C.hide();this.closeShoutF();this.myShout.update(ComCore.Chat.FormatText.wordWrap(this.shout));this.shoutInputField.value=""}).bind(this),8000);C.show();var A=new Ajax.Request(ComCore.Page.buildAjaxURL(null,"addShout"),{method:"post",parameters:{shout:B,logs:1,type:"BOTH","short":1,csrftoken_addShout:ComCore.CSRF.getToken("addShout")},onSuccess:this._onShoutSuccess.bind(this)})},_onShoutSuccess:function(B,A){this.closeShoutF();window.clearTimeout(this.shoutTimeout);$("chatShoutLoading").hide();if(A.actionState!=="shoutSuccess"){this._handleError(A.actionState)}else{this.shout=ComCore.Chat.FormatText.stripHTML(this.newShout)}this.myShout.update(ComCore.Chat.FormatText.wordWrap(this.shout));this.shoutInputField.value=""},_handleError:function(C){var A=$(C);if(!A){A=$("shoutFailure")}var B=A.innerHTML.trim();this.chatShoutForm.hide();this.chatShout.hide();this.shoutError.show();this.shoutErrorMsg.update(B);window.setTimeout((function(){this.chatShoutForm.show();this.shoutError.hide()}).bind(this),5000)},_eoo:true});ComCore.Chat.OnlineFriendsWindow=Class.create(ComCore.Chat.Window,{initialize:function($super,B,C,A){$super("chatList",C,false);this.controller=A;this.onlineFriends=B;this.button=C;this.hasTracked=false;this.chatTab=$("chatTabFriends");this.chatList=$("chatListRoster");this.onlineFriends.observe("onUserStatusChanged",this.onUserStatusChanged.bind(this));this.onlineFriends.observe("onLoaded",this.onLoaded.bind(this));this.searchInput=this.window.down(".search input");this.searchResetIcon=this.window.down(".search .reset");this.searchController=new ComCore.Chat.SearchController(this);this.minimize=this.window.down(".minimize");this.minimize.observe("click",this.onMinimize.bind(this));this.chatTab.observe("scroll",this.onScrollEvent.bind(this))},onScrollEvent:function(C){var A=(this.chatTab.scrollTop+this.chatTab.getHeight());var B=this.chatList.getHeight();if((Math.abs(A-B)<60)&&(!!this.onlineFriends.fullRosterLoaded===false)&&(this.onlineFriends.isLoadingRoster===false)){log("req roster");this.onlineFriends.load(undefined,true)}},onMinimize:function(A){this.button.setActive(false)},onClick:function(A){A=$(A);var B=ComCore.Chat.controller.onlineFriendsWindow;if(A){if(!A.hasClassName("chatStatus")){var C=A.id.replace(/onlineFriend_/,"").toLowerCase();B.closeWindow();B.notify("onStartChat",C,true)}else{B.notify("onStatusChange",A)}}},onLoaded:function(){var I=[];var B=this.onlineFriends.users.values().reject(function(K){return(K.nofriend&&(K.nofriend===true))});var G=ComCore.Chat.Helper.sortList(B);var C,D;for(var E=0,F=G.length;E<F;E++){D=G[E];if((D.username===ComCore.Chat.WelcomeMessage.name)||(D.nofriend!==undefined)){continue}C=this.addNewOnlineFriend(D);I.push(C.getHTML())}var A=$("chatListRoster");A.innerHTML=I.join("");if(!this.hasTracked&&this.controller.logging){this.controller.logging.endLog();this.hasTracked=true}if(this.onlineFriends.rosterCallback!==null){try{this.onlineFriends.rosterCallback(this.onlineFriends.getRosterDetails())}catch(H){log("Error callback");log(H)}}try{$(document).fire("comcore:chat_contactlist_updatelist",{tab:"friends",contacts_count:G.length})}catch(J){log(J)}},addNewOnlineFriend:function(A){var B=new ComCore.Chat.OnlineFriendsElement(A);A.element=B;A.friendElement=null;return B},search:function(F,C,D){var E=F.length,B=-1,A;while(E-B>1){if(F[A=E+B>>1]<C){B=A}else{E=A}}return F[E]!==C?D?E:-1:E},addFirstContactInStatusList:function(J,F,E){var C=null;var B=["online","busy","away","invisible"];var H=B.indexOf(E);H=(H<0)?0:H;var A=function(L){return(L.down("strong.name").innerHTML.toLowerCase()===F.firstname.toLowerCase())};for(var G=H;G>=0;G--){var K=$$("#"+J+" li."+B[G]).reject(A);if(K.length>0){C=K.last();break}}var D=F.element.getElement();if(C===null){var I=$(J);I.insert({top:D})}else{C.insert({after:D})}},highlightNewUserStatus:function(A,F){function E(I){I.style.cssText=""}var H={online:["#96CB00","#ACD733"],away:["#DC0D0D","#C60000"],busy:["#F69825","#FFDC81"],invisible:["#3B3B3B","#616161"]};var G=H[F][0];var D=H[F][1];var B=A.element.getElement();if(typeof (Effect)!=="undefined"){var C=new Effect.Highlight(B,{startcolor:G,endcolor:D,afterFinish:E.bind(this,B)})}},updateContactList:function(E,D,B){if(D.element.getElement()===null){return }var F=$$("#"+E+" li."+B).reject(function(J){return(J.down("strong.name").innerHTML.toLowerCase()===D.firstname.toLowerCase())});if(F.length===0){this.addFirstContactInStatusList(E,D,B);this.updateOnlineStatus(D,B);return }var C=F.collect(function(J){return ComCore.Chat.Helper.cleanName(J.down("strong.name").innerHTML.toLowerCase())});var G=this.search(C,ComCore.Chat.Helper.cleanName(D.firstname.toLowerCase()),true);var A=D.element.getElement();if(!A){return }if(G===0){var I=F.first();I.insert({before:A});this.updateOnlineStatus(D,B);return }var H=F[G-1];if(H){H.insert({after:A})}this.updateOnlineStatus(D,B)},updateOnlineStatus:function(A,F){if((A.nofriend!==undefined)&&(A.nofriend===true)){return }var B=A.element.getElement();if(B===null){return }var G=["online","busy","away","invisible"];var C=4;var E;var D=B.down("img.icon");while(C--){E=G[C];D[F===E?"addClassName":"removeClassName"]("iconStatus"+E.ucFirst())}this.highlightNewUserStatus(A,F)},onUserStatusChanged:function(D,B){var A=this.onlineFriends.get(D);if(A.element&&(A.nofriend===undefined)){this.updateContactList("chatListRoster",A,B);var C=A.element.getElement();if(C){$A(["online","busy","away","invisible"]).each(function(E){C[B===E?"addClassName":"removeClassName"](E)})}}},show:function($super){$super();this.button.setActive(true);this.searchInput.focus()},toggle:function($super){$super();if(this.window.visible()){this.searchInput.focus()}},hide:function($super){this.button.setActive(false);$super()},_eoo:true});ComCore.Events.extend(ComCore.Chat.OnlineFriendsWindow);ComCore.Chat.FormatText={process:function(B,A){B=this.stripHTML(B);B=this.parseEmails(B);B=this.parseURLs(B);B=this.wordWrap(B,34);B=this.addSmilies(B,A);return B},processOwner:function(B,A){B=this.parseEmails(B);B=this.parseURLs(B);B=this.wordWrap(B,34);B=this.addSmilies(B,A);return B},removeHTML:function(A){return A.replace(/(<([^>]+)>)/ig,"")},shorten:function(B,A){A=(A===undefined)?10:A;return(B.length>A)?(B.substr(0,A)+"..."):B},parseEmails:function(B){var A=/([a-zA-Z0-9_.\-]*)@([a-zA-Z0-9_.\-]*)\.(.*)/;return B.gsub(A,function(C){if(C.length===4){return'<a href="/messages/send/receiver='+escape(C[0])+'">'+C[0]+"</a>"}})},parseURLs:function(A){var B=/(http:\/\/)+([\w\-]+\.)?[\w\-]+(\/[\w\- .\/?%&=]*)?(\.[a-zA-Z]{2,})+(\S*)?/;return A.gsub(B,function(D){var C=D[0];var F=D[0];var E=/([a-z]{2,3})+\.netlog.com\/(.*)$/gi;if(F.indexOf("http")===-1){F="http://"+F}if(E.test(F)===true){return'<a href="'+F+'">'+C+"</a>"}else{return'<a href="/out/url='+F+'" target="_blank">'+C+"</a>"}})},stripHTML:function(A){return A.replace(/&/ig,"&amp;").replace(/</ig,"&lt;").replace(/>/ig,"&gt;")},wordWrap:function(K,J){if(/a href/.test(K)===true){return K}if(!J){J=30}var N=new RegExp("\\S{"+J+"}","g");var A=0;var I=K;var E=[];var G=K.match(N);var B=false;if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)){var C=parseInt(RegExp.$1,10);if(C<=6){B=true}}if(G){for(var D=0,H=G.length;D<H;D++){var F=G[D];var L=A+I.indexOf(F);var M=K.substring(A,L);if(M){E.push(M)}if(B===false){E.push(F+"&#8203;")}else{E.push(F+"<wbr/>")}A=L+F.length;I=K.substring(A)}}if(I){E.push(I)}return E.join("")},addSmilies:function(D,A){function C(F){var E=new Image();E.src=F;E.onload=function(){A.getObject(".conversationContent").scrollTop=A.getObject(".conversationContent").scrollHeight};return E}var B=function(F){var E=C(ComCore.Configuration.get("staticURL")+"/s/i/smilies/"+ComCore.Chat.Settings.smilies[F].i);return'<img class="smiley" src="'+E.src+'" />'};D=D.replace(ComCore.Chat.Settings.freeSmiliesRegex,B);D=D.replace(ComCore.Chat.Settings.premiumSmiliesRegex,B);return D},shortenShout:function(C,F){var G="";var B=false;var I=false;var A=0;if(F===undefined){F=50}for(var D=0,E=C.length;D<E;D++){if(C.substr(D,1)==="<"){B=true}if(C.substr(D,1)===">"){var H=I;if(I===true){B=false;H=false}if(I===false){H=true}I=H}if(A>=F){G+="...";break}G+=C.substr(D,1);if(B===false){A++}}return G}};ComCore.Chat.Smilies={smilies:{},premiumTeaser:function(){ComCore.Dialog.initialize();ComCore.Dialog.options.width=630;ComCore.Dialog.getContent("/profile/settings/account/view=super&type=FUN")}};ComCore.Chat.OnlineFriends=Class.create({initialize:function(A){this.users=$H();this.controller=A;this.connection=A.connection;this.rosterLoaded=false;this.fullRosterLoaded=false;this.connectionLoaded=false;this.rosterCallback=null;this.isLoadingRoster=false;this.rosterNumberLoadingAttemptsAllowed=1;this.rosterAttempts=0;this.onlineFriendsCounter=0;this.connection.observe("onUserStatusChanged",this.onUserStatusChanged.bind(this));this.connection.observe("onRosterLoaded",this.onLoaded.bind(this))},addUserToRoster:function(C,A){this.add(C,A);var B=this.controller.onlineFriendsWindow.addNewOnlineFriend(A);$("chatListRoster").insert(B.getHTML());this.controller.onlineFriendsWindow.updateContactList("chatListRoster",A,A.status)},onUserStatusChanged:function(D){var C=D.username;var B=D.userstatus;var E=D.onlineFriendCounter;var A;if(E&&!isNaN(E)&&(this.isLoaded()===false)){this.controller.updateOnlinePeopleCount(E)}else{A=this.users.get(C);if(!A&&(D.user)){A=D.user;this.addUserToRoster(C,A)}}if((C===this.connection.username)&&(this.controller.userStatus.status!==B)){if(B==="idle"){return }this.controller.userStatus.set(B,false,(B.toLowerCase()==="online")?ComCore.Chat.Settings.chatPrivacy.toLowerCase():B);return }A=this.users.get(C);if(A&&(A.nofriend===undefined)){if(A.status!==B){A.status=B;this.notify("onUserStatusChanged",C,B)}}},load:function(C,B){if(C){this.rosterCallback=C}this.isLoadingRoster=true;var A=(B===undefined)?false:B;if(ComCore.Chat.Settings.smallRoster===false){A=true}this.fullRosterLoaded|=A;log("loadRoster("+A+")");this.connection.loadRoster(A)},getRosterDetails:function(){return this.users.values().reject(function(A){return(A.distro!==ComCore.Configuration.get("language"))}).collect(function(A){return{thumbnailUrl:A.avatarUrl,firstname:A.firstname,name:A.name,userID:A.userID,presence:A.status,nickname:A.username}})},displayRosterError:function(A){if(this.controller.logging){this.controller.logging.sendRosterError(A)}if(this.rosterAttempts<this.rosterNumberLoadingAttemptsAllowed){this.rosterAttempts++;this.load()}else{$$("#chatListRoster li").invoke("remove");$("loadingFriends").hide();$("loadingError").show();this.rosterAttempts=0}},cleanUser:function(A){function B(C){if(C&&(C.length>15)){return C.substr(0,15)+"..."}else{return C}}A.name=B(A.name);A.firstname=B(A.firstname);if(!A.avatarUrl){A.avatarUrl=ComCore.Configuration.get("photoStaticURL")+"/p/tt/000/000/0.jpg"}},displayNoFriends:function(){$$("#chatListRoster li").invoke("remove");$("loadingFriends").hide();$("noChatFriends").show();try{$(document).fire("comcore:chat_contactlist_updatelist",{tab:"friends",contacts_count:0})}catch(A){log(A)}},onLoaded:function(){var A=this.connection.getRoster();this.isLoadingRoster=false;this.controller.connection.isRosterLoaded=true;this.rosterLoaded=true;if($H(A).values().length===0){this.displayNoFriends();return }$("loadingError").hide();$H(A).each(function(B){this.add(B.key,B.value)},this);$("loadingFriends").hide();if(this.controller.messageQueue.length>0){this.controller.messageQueue.each(function(C){this.controller.onStartChat(C.username);var B=this.controller.conversationWindow(C.username);B.openWindow();if(B.hasFocus!==true){ComCore.Chat.SoundManager.beep()}this.controller.onMessageReceived({username:C.username,message:C.body,type:C.type,chat:C.chat,playSound:C.playSound})},this)}this.notify("onLoaded");this.controller.updateOnlinePeopleCountFromRoster()},updateUserStatus:function(D,C){var A=this.users.get(D);if(A.status===C){return }A.status=C;var B=this.controller.conversationButton(D);if(B!==false){B.setStatus(C)}},isLoaded:function(){return this.rosterLoaded},search:function(B){var A=$A();this.users.values().each(function(C){if(C&&(C.nofriend===undefined)&&C.username&&C.name&&(C.name.toLowerCase().indexOf(B.toLowerCase())>-1||C.username.toLowerCase().indexOf(B.toLowerCase())>-1)){A.push(C.username)}});return A},add:function(D,C){D=D.toLowerCase();var B=C.name.split(" ");C.firstname=B[0].substr(0,1).toUpperCase()+B[0].substr(1).toLowerCase();this.cleanUser(C);var A=this.get(D);if(A){C=$H(A).merge(C).toObject()}this.users.set(D,C)},get:function(A){return this.users.get(A.toLowerCase())},getAll:function(){return this.users},_eoo:true});ComCore.Events.extend(ComCore.Chat.OnlineFriends);ComCore.Chat.UserStatus=Class.create({statusMapping:{everyone:"online",friends:"online",busy:"busy",away:"away",invisible:"invisible"},jabberStatusMapping:{online:{show:"chat"},busy:{show:"dnd"},away:{show:"away"},invisible:{show:"xa"}},initialize:function(A,B){this.previousStatus=B;this.controller=A;this.connection=A.connection;if(B){this.status=B;this.jabberStatus=this.controller.connectionParams.jabberStatus}},getPrivacyStatus:function(){if(this.privacyStatus===undefined){this.privacyStatus=$H(this.statusMapping).find((function(A){return(A.value===this.status)}).bind(this)).key}return this.privacyStatus},setStatus:function(C,D){var A=this.jabberStatusMapping[C].show;var B=this.jabberStatusMapping[C].status?this.jabberStatusMapping[C].status:false;this.connection.setStatus(A,B);if(D!==undefined){this.connection.observe("onProcess",this.onProcess.bind(this,D))}},onProcess:function(B,A){},set:function(D,A,F,E){this.jabberStatus=F;var C;$A($H(this.statusMapping).keys()).each(function(H){this.controller.onlineFriendsButton.img[this.jabberStatus===H?"addClassName":"removeClassName"]("iconChat"+H.ucFirst())},this);if(A===undefined){A=true}if(A!==false){C=function(){this.setStatus(this.status,E);if((F!=="invisible")&&(this.controller.pendingMessages.length>0)){this.controller.emptyPendingMessages(F)}this.notify("onUserStatusChanged",this.status)}.bind(this)}this.status=D;var G={status:F.toUpperCase()};var B=new Ajax.Request(ComCore.Page.buildAjaxURL("contactlist","setChatbarStatus"),{method:"post",parameters:G,onSuccess:function(I,H){if(A!==false){C()}if(H.success===false){log("Error setting user status!")}}})},get:function(){return this.status},_eoo:true});ComCore.Events.extend(ComCore.Chat.UserStatus);ComCore.Chat.Archive=Class.create({initialize:function(B,C,A){this.connection=B.connection;this.controller=B;this.user=C;this.window=A;this.displayArchive()},displayArchive:function(){var B={from:this.connection.connection.username,to:this.user.username};var C={userid:this.user.userID};var A=new Ajax.Request("/ajax/chatbar/view=getArchive",{method:"post",parameters:C,onSuccess:this._receiveArchive.bind(this)})},_receiveArchive:function(D){var B=D.responseJSON.messages;if(D.responseJSON.success===false){return }if($A(B).length>0){this.window.dayFromLastMessage=new Date().getDay();this.window.getObject(".conversation").childElements().invoke("remove")}var C,A;$A(B).each(function(J){C=ComCore.Chat.Helper.parseDate(J.datetime);var H={body:J.message,username:J.sender_nickname,date:C};A={message:H,fromArchive:true};if(J.isGame!==undefined){var I={gameName:J.gameName,gameThumbnail:ComCore.Configuration.get("staticURL")+J.gameAvatar,gameUrl:J.gameURL};log("parse game archive");this.controller.conversation(this.user.username).addMessage({username:H.username,message:I,playSound:false,type:"game",fromArchive:true});this.window.onMessageAdded({message:{body:I,username:J.sender_nickname,date:C},fromArchive:true,type:"game"})}else{this.controller.conversation(this.user.username).addMessage({username:H.username,message:H.body,fromArchive:true,date:C});this.window.onMessageAdded(A)}},this);if(this.user.status==="invisible"){this.window.showOfflineNotice()}var E=this.controller.state.getState();if((E!==undefined)&&(E.constructor===Array)){var G=this.user.username;var F=E.find(function(H){return(H.username===G)});if(F&&F.m&&(F.m>0)){this.window.button.setBlinking(true)}}this.window.onReceiveArchive()},_eoo:true});ComCore.Chat.OnlineFriendsButton=Class.create(ComCore.Chat.Button,{initialize:function($super,A){this.img=$(A).down("img");$super(A)},_eoo:true});ComCore.Chat.SoundManager={beep:function(){if(ComCore.Chat.Settings.soundEnabled===true){var A=parseInt(ComCore.Chat.Settings.soundType,10);if(A===0){return }Sound.play(ComCore.Configuration.get("staticURL")+"/s/i/hud/sounds/"+A+".swf")}}};ComCore.Chat.ScrollController=Class.create({initialize:function(A){this.controller=A;this.conversationButtons=$("chatTabsList");this.chatTabsContainer=$("chatTabsContainer");this.busyScrolling=false;this.attachScrollers();this.controller.observe("onCloseConversation",this.onDelete.bind(this));this.controller.observe("onOpenHiddenWindow",this.onOpenHiddenWindow.bind(this));ComCore.Chat.Button.observe("onBlink",this.handleBlink.bind(this))},handleBlink:function(E){var A=ComCore.Chat.Helper.getWindowPosition();var C=E.button.previousSiblings().length-1;var D=A.left;var B=A.right;if(C>D){this.scrollLeftButton.addNewMessage()}if(C<B){this.scrollRightButton.addNewMessage()}},onOpenHiddenWindow:function(F){var C=this.controller.conversationButton(F.username);var E=C.button.previousSiblings().length-1;var G=this.calculateScrollAmounts();var I=G.right;var A=Math.floor(this.chatTabsContainer.clientWidth/140);var D=G.right+A-1;var B;var H=(function(){C.show().setActive(true)}).bind(this);if(E>D){B=(E-D);this.doScroll((-ComCore.Chat.Constants.TAB_WIDTH*B),[H])}if(E<I){B=I-E;this.doScroll((ComCore.Chat.Constants.TAB_WIDTH*B),[H])}},attachScrollers:function(){this.updateScrollWidth();this.scrollLeftButton=new ComCore.Chat.ScrollButton(this,"LEFT");this.scrollRightButton=new ComCore.Chat.ScrollButton(this,"RIGHT")},updateScrollWidth:function(){var B=this.controller.chatBar.getWidth()-$("hudButtonsLeft").getWidth()-$("hudButtonsRight").getWidth()-50;var D=Math.floor(B/ComCore.Chat.Constants.TAB_WIDTH);var A=D*ComCore.Chat.Constants.TAB_WIDTH;var C=A>B?B:A;$("chatTabsContainer").setStyle({width:C+"px"});this.conversationButtonsRoom=Math.floor(B/ComCore.Chat.Constants.TAB_WIDTH)},getConversations:function(){return $$("#chatTabsList li.conversation")},showScrollButtonsIfNecessary:function(){if(this.getConversations().length>this.conversationButtonsRoom){this.scrollLeftButton.show();this.scrollRightButton.show()}else{this.scrollLeftButton.hide();this.scrollRightButton.hide()}},scrollRight:function(A){this.doScroll(ComCore.Chat.Constants.TAB_WIDTH,A)},scrollLeft:function(A){this.doScroll(-ComCore.Chat.Constants.TAB_WIDTH,A)},requestAction:function(B){var C=this.getConversations().length;if(C>this.conversationButtonsRoom){var A=this.calculateScrollAmounts();this.doScroll(-(A.left*ComCore.Chat.Constants.TAB_WIDTH),[B])}else{B()}},doScroll:function(A,B){this.controller.hideConversations();this.currentPosition=parseInt(this.conversationButtons.getStyle("right").replace("px",""),10);ComCore.Chat.ScrollEffect.create(this.conversationButtons,this.currentPosition,(this.currentPosition+A),(function(){this.updateScrollers();B.each(function(C){C()});this.busyScrolling=false}).bind(this))},calculateScrollAmounts:function(){var A;if(this.conversationButtons.getStyle("right")){A=parseInt(this.conversationButtons.getStyle("right").replace("px",""),10)}else{A=0}var B=Math.abs(Math.round(A/140));var D=Math.floor(this.chatTabsContainer.clientWidth/140);var C=(this.getConversations().length-(B+D));return{left:C,right:B}},onDelete:function(B){var A=this.calculateScrollAmounts();var C=[];B.remove();if(A.right>0){this.scrollRight(C)}else{if((A.left-1)>0){this.scrollLeft(C)}}this.updateScrollers()},updateScrollers:function(){var A=this.calculateScrollAmounts();if(A.left>=0){this.scrollLeftButton.updatePageNumber(A.left)}if(A.right>=0){this.scrollRightButton.updatePageNumber(A.right)}this.showScrollButtonsIfNecessary()},_eoo:true});ComCore.Chat.ScrollButton=Class.create(ComCore.Chat.Button,{initialize:function($super,D,C){var A=(C==="LEFT")?"chatScrollLeft":"chatScrollRight";$super(A,false);var B=$(A);this.scrollController=D;this.enabled=false;this.pageNumber=0;this.element=B;this.pageElement=B.down("span");this.conversationButtons=$("chatTabsList");this.type=C;this.element.observe("click",this._buttonClick.bind(this))},addNewMessage:function(){this.setBlinking(true,false)},checkCanStopBlinking:function(){var J=true;var H,A;var G=$("chatTabsList");function I(K){return K.down("small.chatTabUnreadCount").visible()}var C=ComCore.Chat.Helper.getWindowPosition();if(this.type==="LEFT"){var E=($$("#hud li.conversation").length-(C.left+C.right));H=G.childElements();for(var D=E;D>0;D--){A=G.childElements()[H.length-D];if(A&&I(A)){J=false;break}}}else{H=G.select("li.conversation");for(var B=0,F=C.right;B<F;B++){A=H[B];if(A&&I(A)){J=false;break}}}if(J===true){this.setBlinking(false,false)}},_buttonClick:function(C){var B=[];if(this.isBlinking===true){B.push(this.checkCanStopBlinking.bind(this))}if(this.enabled&&(this.scrollController.busyScrolling===false)){this.scrollController.busyScrolling=true;var A=$H(this.scrollController.controller.conversations).values().find(function(D){return(D.b.isActive()===true)});if(A){B.push((function(){if(A.w.isVisible()){A.w.openWindow()}}).bind(this))}if(this.type==="RIGHT"){this.scrollController.scrollRight(B)}else{this.scrollController.scrollLeft(B)}}},updatePageNumber:function(A){this.pageNumber=A;this.pageElement.update(A);if((this.pageNumber===0)&&(this.enabled)){this.disable()}if((this.pageNumber>0)&&(!this.enabled)){this.enable()}},getType:function(){return this.type},enable:function(){this.enabled=true;this.element.removeClassName("disabled")},disable:function(){this.enabled=false;this.element.addClassName("disabled")},_eoo:true});ComCore.Chat.ScrollEffect={create:function(B,E,C,D){if(typeof (Effect)!=="undefined"){var A=new Effect.Tween(B,E,C,{afterFinish:function(){D()},duration:ComCore.Chat.Constants.SCROLL_DURATION},function(F){B.setStyle({right:F+"px"})})}else{if(D){D()}}}};ComCore.Chat.WelcomeConversationWindow=Class.create(ComCore.Chat.ConversationWindow,{initialize:function($super,C,B,A){$super(C,B,A);this.form.hide()},onSendMessage:function(){return },_eoo:true});ComCore.Chat.WelcomeMessage={name:"Netlog",sentWelcome:false,openWindow:true,start:function(A,E){if(E!==undefined){ComCore.Chat.WelcomeMessage.openWindow=E}if(this.sentWelcome===false){this.controller=A;var B={username:this.name,firstname:this.name,name:this.name,status:"online",avatarUrl:ComCore.Configuration.get("staticURL")+"/s/i/misc/thumb/thumb_netlog.png"};this.controller.onlineFriends.add(this.name,B);var D=new ComCore.Chat.Conversation(B);var C=new ComCore.Chat.ConversationButton(B,this.controller);this.window=new ComCore.Chat.WelcomeConversationWindow(D,C,this.controller);this.controller.conversations.set(this.name,{c:D,b:C,w:this.window});this.controller.onStartChat(this.name);if(!ComCore.Chat.WelcomeMessage.openWindow){this.window.closeWindow()}this.addMessage();this.sentWelcome=true}},addMessage:function(){var A=ComCore.Chat.Messages.chatWelcomeMessage;var B={body:A,username:this.name,date:new Date()};this.window.onMessageAdded({message:B,fromArchive:false})}};ComCore.Chat.PrivacyCheck=Class.create({initialize:function(A){this.controller=A},canSendMessage:function(C){var B=this.controller.userStatus.getPrivacyStatus();if(B==="everyone"){return true}if((B==="friends")||(B==="busy")){var A=this.controller.onlineFriends.get(C);return((A!==undefined)&&(A!==null))}return false},_eoo:true});ComCore.Chat.ChatbarOptions=Class.create({initialize:function(){this.shoutButton=$("hudButtonShouts").down("a");if(this.shoutButton){this.shoutButton.observe("click",this.showShoutDialog.bind(this))}this.shortcutsButton=$("hudButtonShortcuts");if(this.shortcutsButton){this.shortcutsButton.down("a").observe("click",this.toggleShortcuts.bind(this))}this.hudButtonModerateButtons=$("hudButtonModerateButtons");if(this.hudButtonModerateButtons){this.hudButtonModerateButtons.down("a").observe("click",this.toggleModerateButtons.bind(this))}if(this.shortcutsButton||this.hudButtonModerateButtons){$("hudButtonsLeft").observe("click",this.onOptionsClick.bind(this))}this.minimizeButton=$("hudButtonMinimize").down("a.hudMinimizeButton");this.maximizeButton=$("hudButtonMaximize").down("a.hudMaximizeButton");if(this.minimizeButton&&this.maximizeButton){[this.minimizeButton,this.maximizeButton].each(function(A){A.observe("click",this.onMinimize.bind(this))},this)}},onMinimize:function(A){A.stop();var B=$("hud");if(!B.hasClassName("minimized")){var C=ComCore.Chat.controller.connection.connection;C.stopPoller();C.abortRequest()}B[B.hasClassName("minimized")?"removeClassName":"addClassName"]("minimized");B.setStyle({bottom:""});B.removeClassName("dock");var D=new Ajax.Request(ComCore.Page.buildAjaxURL("chatbar","saveMinimize"),{method:"post",parameters:{keepMinimized:B.hasClassName("minimized")?"YES":"NO"}})},onMaximize:function(A){A.stop();var B=$("hud");B.removeClassName("dock");this.onMinimize(A)},onOptionsClick:function(A){if(!A.findElement("li.hudButtonContextMenu")){this.hideShortcuts();this.hideModerateButtons()}},showShoutDialog:function(B){B.stop();var A="";if(typeof (ComCore.Profile)!=="undefined"){A=ComCore.Profile.getNickname()||""}ComCore.Dialog.initialize();ComCore.Dialog.getContent(ComCore.Page.buildAjaxURL(null,"showShoutsDialog&reply="+A))},toggleModerateButtons:function(A){if($("hudModerateButtons").visible()){this.hideModerateButtons()}else{this.showModerateButtons()}A.stop()},hideModerateButtons:function(){if(!this.hudButtonModerateButtons){return }$("hudModerateButtons").hide();this.hudButtonModerateButtons.down(".hudTooltip").show()},showModerateButtons:function(){this.hideShortcuts();if(!this.hudButtonModerateButtons){return }$("hudModerateButtons").toggle();this.hudButtonModerateButtons.down(".hudTooltip").toggle()},toggleShortcuts:function(A){if($("hudShortcuts").visible()){this.hideShortcuts()}else{this.showShortcuts()}A.stop()},hideShortcuts:function(){if(!this.shortcutsButton){return }$("hudShortcuts").hide();this.shortcutsButton.down(".hudTooltip").show()},showShortcuts:function(){this.hideModerateButtons();if(!this.shortcutsButton){return }$("hudShortcuts").toggle();this.shortcutsButton.down(".hudTooltip").toggle()},_eoo:true});ComCore.Chat.Logging=Class.create({initialize:function(A){this.state=null;this.controller=A;this.logInfo=$A();this.isLogging=false;this.userID=ComCore.Login.getUserID();this.trackingID=parseInt(new Date().getMilliseconds()+parseInt(this.userID,10)+Math.round(Math.random()*1000000),10)},startLog:function(){if(this.state!==null){return false}this.state="START";this.isLogging=true;this.sendStart()},sendRosterError:function(B){if(B!==undefined){this.logInfo.push("EMPTY ROSTER")}else{this.logInfo.push("ROSTER TIMEOUT")}this.isLogging=false;var A=this.logInfo.toJSON();this.sendReport("INVALID",A)},endLog:function(){if(this.state!=="START"){return }this.state="STOP";this.logInfo.push("END: "+new Date().getTime().toString());this.isLogging=false;var A=this.logInfo.toJSON();this.sendReport("STOP",A)},addResponse:function(A,B){if(B&&B.xml()){this.logInfo.push("RESPONSE: ("+A+")"+B.xml().toString())}else{this.logInfo.push("RESPONSE: ("+A+")")}},addRequest:function(A){this.logInfo.push("REQUEST: "+A.toString())},getMetaInfo:function(){var A=window.location.href.split("/");var B=A[4];var C=A[5];return{module:B,submodule:C}},sendStart:function(){this.sendReport("START","")},sendInvalid:function(){this.sendReport("INVALID","")},addCustom:function(A){this.logInfo.push(A)},sendReport:function(D,B){var A=new Image();var F=this.getMetaInfo();var C=$H({module:F.module,submodule:F.submodule,type:D,userID:this.userID,trackID:this.trackingID});if(B&&B.length>0){C.set("information",escape(B))}var G=C.toQueryString();var E=new Ajax.Request("/ajax/chatbar/view=saveLogging",{method:"post",parameters:G})},_eoo:true});ComCore.Chat.Controller=Class.create({initialize:function(A){this.connectionParams=A;this.connection=new ComCore.Jabber.Connection(A,this);this.connection.controller=this;this.connection.observe("onMessageReceived",this.onMessageReceived.bind(this));this.connection.observe("onDisconnect",this.onDisconnect.bind(this));this.connection.observe("onReconnect",this.onReconnect.bind(this));this.connection.observe("onConnect",this.onConnect.bind(this));this.connection.observe("onQuit",this.onQuit.bind(this));this.connection.observe("onNewCounters",this.onNewCounters.bind(this));this.connection.observe("onChatStateNotification",this.onChatStateNotification.bind(this));this.connection.observe("onReceiveOnlinePeopleCount",this.updateOnlinePeopleCount.bind(this));if(window.chatStatus&&(window.chatStatus==="onConnect")){this.onConnect()}this.chatBar=$("hud");this.messageQueue=[];this.windowTitle=new ComCore.Chat.WindowTitle();this.loggedClick=false;this.idle=false;ComCore.Chat.Button.observe("onChange",this.onButtonChanged.bind(this));ComCore.Chat.Button.observe("onClose",this.onCloseConversation.bind(this));ComCore.Chat.Window.observe("onClose",this.onCloseConversation.bind(this));ComCore.Chat.Window.observe("onSendMessage",this.onSendMessage.bind(this));this.onlineFriends=new ComCore.Chat.OnlineFriends(this);this.onlineFriendsButton=new ComCore.Chat.OnlineFriendsButton("hudButtonChatLink");this.onlineFriendsWindow=new ComCore.Chat.OnlineFriendsWindow(this.onlineFriends,this.onlineFriendsButton,this);this.onlineFriendsWindow.observe("onStartChat",this.onStartChat.bind(this));this.onlineFriends.observe("onLoaded",this.onLoaded.bind(this));this.onlineFriends.observe("onUserStatusChanged",this.onUserStatusChanged.bind(this));this.idleNotifier=new ComCore.Chat.IdleNotifier();this.chatBarOptions=new ComCore.Chat.ChatbarOptions(this);this.userStatus=new ComCore.Chat.UserStatus(this,this.connection.connectionParams.userStatus);this.state=new ComCore.Chat.State(this);this.conversations=$H();this.chatStatusButton=new ComCore.Chat.ChatStatusButton(this,$("chatStatusButton"));this.chatStatusWindow=new ComCore.Chat.chatStatusWindow(this,this.chatStatusButton);this.scrollController=new ComCore.Chat.ScrollController(this);this.onlineFriendsHeader=new ComCore.Chat.OnlineFriendsWindowHeader(this);this.privacyCheck=new ComCore.Chat.PrivacyCheck(this);this.menuController=new ComCore.Chat.MenuController(this);this.settingsController=new ComCore.Chat.SettingsController(this);this.bubbleFloodContainer={};var B=$$("#accountActions a.logout");if(B&&(B.length>0)){B.first().observe("click",this.onLogout.bind(this))}if(ComCore.Chat.Settings.nudgesEnabled===true){this.nudgeController=new ComCore.Chat.NudgeController(this)}this.restorePreviousSession();ComCore.Chat.UserStatus.observe("onUserStatusChanged",this._statusChange.bind(this));this.debugButton=$("hudDebugButton");if(this.debugButton){this.debugButton.observe("click",this.onToggleDebug.bind(this))}this.games=new ComCore.Chat.Games(this);this.pendingMessages=[];this.observeMainWindow();try{if(ComCore.Chat.trackingEnabled&&(ComCore.Chat.trackingEnabled===true)){this.logging=new ComCore.Chat.Logging(this)}}catch(C){}},onLogout:function(A){},onToggleDebug:function(A){A.stop();$("logContainer").toggle()},getUserDetails:function(){return{username:this.connectionParams.username.toLowerCase(),avatar:$$("#chatListHeaderLeft img.myAvatar")[0].getAttribute("src"),distro:ComCore.Configuration.get("language"),firstname:this.connectionParams.firstName,shout:escape($$("#chatShout span")[0].innerHTML)}},nudgeReceived:function(A,B){if(this.nudgeController){this.nudgeController.nudgeReceived(A,B)}},updateOnlinePeopleCount:function(A){if(A<=0){$("hudButtonChatCount").hide();return false}$("hudButtonChatCount").update("("+A+")").show()},updateOnlinePeopleCountFromRoster:function(){var A=this.onlineFriends.users.values().findAll(function(B){return((B.status!=="invisible")&&(B.nofriend===undefined))}).length;this.updateOnlinePeopleCount(A)},onChatStateNotification:function(C,B){var A=this.conversationWindow(C);if(A&&(A.button.visible()===true)){A.onChatStateNotification(B)}},onNewCounters:function(B){var A=$H();A.set("messages",$("hudButtonInbox").down("span.hudCounter"));A.set("notifications",$("hudButtonNotifications").down("span.hudCounter"));A.each(function(D){if(B[D.key]){var E=$(D.value);if(E&&(parseInt(B[D.key],10)!==parseInt($(D.value).innerHTML,10))){if(parseInt(B[D.key],10)<=0){E.hide()}else{if(parseInt(B[D.key],10)>99){E.down(".count").update("99+")}else{E.down(".count").update(B[D.key])}E.show();if(typeof (Effect)!=="undefined"){var C=new Effect.Pulsate(E)}}}}})},onLoaded:function(){var A=$$("#chatTabsList li.conversation");A.each(function(E){var F=E.getAttribute("id").replace("chatTab_","");var D=this.conversationButton(F);var C=this.onlineFriends.get(F);if(D&&C){D.setStatus(C.status);var B=this.conversationWindow(F);if(B){B.onUserStatusChanged(F,C.status)}}},this)},onQuit:function(A){this.state.updateRoster(this.onlineFriends.users.values());this.state.updateState();this.state.updateJabberStatus(this.userStatus.status)},emptyPendingMessages:function(B){var A;if(B==="everyone"){A=this.pendingMessages;this.pendingMessages=[]}else{A=this.pendingMessages.find(function(C){return(C.isFriend===true)});this.pendingMessages=this.pendingMessages.reject(function(C){return(C.isFriend===true)})}A.each(function(C){this.onMessageReceived({username:C.username,message:C.message})},this)},hideConversations:function(){this.conversations.values().each(function(A){A.w.closeWindow()})},disableChat:function(){$$("#hud div.conversation").invoke("hide");$$("#hud li.conversation").invoke("hide");this.userStatus.set("invisible",true,"invisible",function(){window.location="/login/action=logout"})},observeMainWindow:function(){var A=document;Event.observe(A.onresize?A:window,"resize",this.fixOpenWindows.bind(this));A.observe("click",this.onDocumentClick.bind(this));A.observe("state:idle",this.onStateIdle.bind(this)).observe("state:active",this.onStateActive.bind(this))},onStateIdle:function(){if(this.idle===false){this.userStatus.previousStatus=this.userStatus.status;this.userStatus.status="idle";this.connection.sendIdle(ComCore.Chat.Constants.IDLE_TIMEOUT);this.idle=true;log("you are now idle")}},onStateActive:function(){if(this.idle===true){log("active again");var A=(this.userStatus.previousStatus!=="idle")?this.userStatus.previousStatus:"online";this.connection.sendActive(A);this.userStatus.status=A;this.idle=false}},_statusChange:function(B){var A=B.jabberStatus;this.chatStatusWindow.setStatus(A)},onDocumentClick:function(A){if(!A.findElement("#hud")){this.onlineFriendsWindow.hide()}},fixOpenWindows:function(){this.onlineFriendsWindow.setPosition();$H(this.conversations).values().each(function(E){if(E.w){E.w.setPosition();E.w.window.style.left=(parseInt(E.w.window.style.left.replace("px",""),10)+4)+"px"}});var B=this.chatBar.getWidth()-$("hudButtonsLeft").getWidth()-$("hudButtonsRight").getWidth()-50;var D=Math.floor(B/ComCore.Chat.Constants.TAB_WIDTH);var A=D*ComCore.Chat.Constants.TAB_WIDTH;var C=A>B?B:A;$("chatTabsContainer").setStyle({width:C+"px"});this.scrollController.updateScrollers()},onReconnect:function(){$("disconnectedWarning").hide();this.userStatus.set("online",true,"everyone");this.showReconnectToAllWindows()},onDisconnect:function(){$("disconnectedWarning").show();$("loadingFriends").hide();this.showDisconnectToAllWindows();log("controller received disconnect")},showReconnectToAllWindows:function(){this.conversations.values().each(function(B){var A=B.w;if(A){A.hideDisconnectedNotification()}})},showDisconnectToAllWindows:function(){this.conversations.values().each(function(B){var A=B.w;if(A){A.showDisconnectedNotification()}})},restorePreviousSession:function(){this.restoreRoster();this.restoreWindows()},restoreRoster:function(){var A=this.state.getRoster();if(A){var F=A.roster;if(F&&(F.constructor===Array)&&(F.length>0)){$("loadingFriends").hide();var D=ComCore.Configuration.get("photoStaticURL")+"/p/tt/000/000/0.jpg";F.each(function(K){var J=unescape(K.u);var I=(K.f!==undefined)?unescape(K.f):unescape(K.u);var H=(K.t!==undefined)?unescape(unescape(K.t)):"";var G=(K.a!==undefined)?ComCore.Chat.Helper.buildImagePath(K.a):D;this.onlineFriends.users.set(unescape(K.u),{username:J,status:K.s,firstname:I,name:I,shout:H,avatarUrl:G,userID:K.id})},this);var E=this.onlineFriends.users.values().reject(function(G){return(G.nofriend&&(G.nofriend===true))});E=ComCore.Chat.Helper.sortList(E);var B=[];E.each(function(G){var H=this.onlineFriendsWindow.addNewOnlineFriend(G);B.push(H.getHTML())},this);var C=$("chatListRoster");C.innerHTML=B.join("")}}},restoreWindows:function(){var A=$$("#chatTabsList li.conversation");if(A.length>0){A.each(function(D){var L=D.down("a");var G=L.className.toLowerCase()||"invisible";var M=parseInt(L.getAttribute("id").replace("chatuser_",""),10);var F=D.getAttribute("id").replace("chatTab_","");var C=$("conversationWindow_"+F);var I=D.down("span.chatTabLabel").innerHTML;if(!C){return }var E=C.down("div.chatShout").innerHTML;var N=C.down("img.avatar").getAttribute("src");var H=this.onlineFriends.get(F);var B=C.getAttribute("rel");if(B===undefined){B=F}if(H===undefined){H={nofriend:C.hasClassName("nofriend")?true:undefined,name:B,status:G,isArchiveLoaded:true,avatarUrl:N,username:F,shout:E,firstname:I,userID:M};this.onlineFriends.add(F,H)}H.isArchiveLoaded=true;var J={button:D,window:C};this.createConversation(F,J,true);var K=this.conversationButton(F);if(K){K.setStatus(G)}C=this.conversationWindow(F);K.show();if(D.hasClassName("active")){K.active=true}},this)}},onConnect:function(){$("hudButtonChatList").onclick=null;var A=$("hudButtonChatLoading");if(A.visible()){A.hide();this.onlineFriendsWindow.show();this.loggedClick=true;if(this.onlineFriends.isLoaded()===false){this.onlineFriends.load()}}if(ComCore.Chat.Settings.sendWelcomeMessage===true){ComCore.Chat.Settings.sendWelcomeMessage=false;ComCore.Chat.WelcomeMessage.start(this)}},onUserStatusChanged:function(D,C){if(C==="online"){if(this.onlineFriends.isLoaded()===false){this.onlineFriends.load((function(){this.onUserStatusChanged(D,C)}).bind(this));return }var A=this.onlineFriends.get(D);this.showBubble("ONLINEFRIEND",A)}var B=this.conversationButton(D);if(B!==false){B.setStatus(C)}},showBubble:function(D,C){if(ComCore.bubbleManager&&C){var B;var F=this.bubbleFloodContainer[C];if((F!==undefined)&&(F[D]!==undefined)){if((new Date().getTime()-F[D])<20000){return }}if(F===undefined){this.bubbleFloodContainer[C]={}}this.bubbleFloodContainer[C][D]=new Date().getTime();if(D==="ONLINEFRIEND"){var E=(function(H,G){G.stop();if(H){this.onStartChat(H.username)}}).bind(this,C);if(this.onlineFriendsWindow.window.visible()===false){B=ComCore.Chat.Helper.getTranslation("onlineFriend",{name:C.firstname});var A=(C.avatarUrl!==undefined)?'<img class="avatar" src="'+C.avatarUrl+'" />':"0";ComCore.bubbleManager.showBubble("/"+escape(C.username),A,B,ComCore.Chat.Constants.SHOW_BUBBLE_TIME,E)}}else{if(D==="STATUS_CHANGED"){B=ComCore.Chat.Helper.getTranslation("statusChanged");ComCore.bubbleManager.showBubble("#","0",B,ComCore.Chat.Constants.SHOW_BUBBLE_TIME)}else{if(D==="STATUS_CHANGED_TO_EVERYONE"){B=ComCore.Chat.Helper.getTranslation("statusChangedToEveryone");ComCore.bubbleManager.showBubble("#","0",B,ComCore.Chat.Constants.SHOW_BUBBLE_TIME)}}}}},onCloseConversation:function(C,D){this.hideConversations();var B=this.conversationButton(D).button;var A=this.conversationWindow(D);if(A){A.setActive(false);A.hide()}this.notify("onCloseConversation",B)},onButtonChanged:function(B){if(B===this.chatStatusButton){this.chatStatusWindow.toggle();var D=this.conversations.keys().first();if(D){this.conversationWindow(D).hide()}if(B.isActive()){this.onlineFriendsButton.setActive(false)}}else{if(B===this.onlineFriendsButton){if(!this.loggedClick&&this.logging&&(this.onlineFriendsWindow.hasTracked!==true)){this.logging.startLog();this.loggedClick=true}this.onlineFriendsWindow.toggle();if(B.isActive()){this.hideConversations();if(this.onlineFriends.isLoaded()===false){this.onlineFriends.load()}try{$(document).fire("comcore:chat_open")}catch(C){log(C)}}}else{if(B.getType()!=="BUTTON"){}else{var A=this.conversationWindow(B.getID());if(A&&B.isActive()){this.onlineFriendsWindow.hide();this.conversations.values().each(function(E){E.b.setActive(E.b===B)});A.show()}else{if(A){A.hide()}}}}}},conversation:function(A){return this.conversations.get(A).c},conversationWindow:function(A){if(this.conversations.get(A)!==undefined){return this.conversations.get(A).w}return false},conversationButton:function(A){if(this.conversations.get(A)!==undefined){return this.conversations.get(A).b}return false},createConversation:function(D,E,K){if(K===undefined){K=false}var F=this.onlineFriends.get(D);if(F.element===undefined){var B;if(F.nofriend===undefined){B=new ComCore.Chat.OnlineFriendsElement(F)}else{B=new ComCore.Chat.OnlineEveryoneElement(F)}F.element=B}var C,J;if(!this.conversations.get(D)){J=new ComCore.Chat.Conversation(F);C=new ComCore.Chat.ConversationButton(F,this,(E!==undefined)?E.button:undefined);var A=new ComCore.Chat.ConversationWindow(J,C,this,(E!==undefined)?E.window:undefined);if((F.archiveLoading!==true)&&(K===false)){var H=new ComCore.Chat.Archive(this,F,A);F.archiveLoading=true}this.conversations.set(D,{c:J,b:C,w:A})}else{C=this.conversationButton(D)}var I=$("chatTabsList");var G=(parseInt(I.getStyle("width").replace("px",""),10)+150)+"px";I.setStyle({width:G});this.scrollController.updateScrollers();return J},onSendMessage:function(A,F,D){if(D==="/dragon"){ComCore.EasterEggs.showDragon();return }if(ComCore.Chat.Settings.nudgesEnabled===true){var E=D.match(/^\/nudge(.*)/i);if(E&&(E.length>0)){var C=E[1].trim();if(C.length===0){A.addNotification("nudges: "+$H(ComCore.Chat.NudgeController.nudges).keys().invoke("toLowerCase").join(", "))}else{this.nudgeController.sendNudge(C,F)}return }}var B=this.onlineFriends.get(F);if(B&&(this.userStatus.jabberStatus!=="everyone")&&(B.nofriend&&(B.nofriend===true))){this.userStatus.set("online",true,"everyone");this.showBubble("STATUS_CHANGED_TO_EVERYONE",B)}D=ComCore.Chat.FormatText.stripHTML(D);this.connection.sendMessage(F,D)},logStartConversation:function(A){if(A.username){var D={to:A.username};var C=new Ajax.Request(ComCore.Page.buildAjaxURL("chatbar","logConversation"),{parameters:D})}try{$(document).fire("comcore:chat_conversations_startnew",{from_userid:ComCore.Login.getUserID(),to_userid:A.userID})}catch(B){log(B)}},onStartChat:function(D){var B=this.onlineFriends.get(D);if(!B){B={nofriend:true,name:D,status:"online",username:D,avatarUrl:ComCore.Configuration.get("photoStaticURL")+"/p/tt/000/000/0.jpg"};this.onlineFriends.add(D,B)}if(B){if(this.onlineFriends.isLoaded()===false){this.onlineFriends.load()}if(!this.conversations.get(D)){this.logStartConversation(B);this.createConversation(D)}var C=this.conversationButton(D);if(!$(C.button).descendantOf("chatTabsList")){this.regenerateChatEnvironment(B);this.conversationButton(D).showButton(D);return }var A=this.conversationWindow(D);if(A.isVisible()){if(C.button===$("chatTabsList").lastChild){C.showButton(D)}else{C.show().setActive(true)}}else{this.notify("onOpenHiddenWindow",B)}}},isFriend:function(B){var A=this.onlineFriends.users.keys().find(function(C){return(C===B)});return(A!==undefined)},onMessageReceived:function(I){if(this.chatBar.hasClassName("minimized")){this.chatBar.removeClassName("minimized")}var D=I.username;var K=I.message;var J=I.chat;var B=I.playSound;var H=I.type;var F,C,A;F=this.onlineFriends.get(D);if(this.onlineFriends.isLoaded()===false){if(J===undefined){F=(J!==undefined)?J:D;this.onlineFriends.load(this.onMessageReceived.bind(this,I));return }else{if(this.conversations.get(J)){this.onlineFriends.load()}else{this.onlineFriends.load(this.onMessageReceived.bind(this,I));return }}}if(H!==undefined){F=this.onlineFriends.get((J!==undefined)?J:D);if(F&&(F.isArchiveLoaded!==true)){this.createConversation(F.username);A=this.conversationWindow(F.username);A.archiveCallback=this.onMessageReceived.bind(this,I);return false}}var E=true;if(J!==undefined){if(this.conversations.get(J)===undefined){if(this.onlineFriends.get(J)!==undefined){this.createConversation(J)}else{E=false}}if(E){C=this.conversationButton(J);if(C){C.show().setActive(true)}this.conversation(J).addMessage({username:ComCore.TopLogin.getNickname(),message:K,fromArchive:false,type:H,chat:J})}}else{log("onMessageReceived("+D+", "+K+")");if(!F){F={nofriend:true,name:D,firstname:D,status:"online",username:D,avatarUrl:ComCore.Configuration.get("photoStaticURL")+"/p/tt/000/000/0.jpg"};if(I.userid&&(I.userid>0)){F.userID=I.userid}this.onlineFriends.add(D,F);this.createConversation(D)}if(F){if((F.nofriend!==undefined)&&(this.userStatus.jabberStatus==="friends")){return }this.windowTitle.poll(F);if(!this.conversations.get(D)){this.createConversation(D)}C=this.conversationButton(D).button;if(!$(C).descendantOf("chatTabsList")){this.regenerateChatEnvironment(F)}this.conversation(D).addMessage({username:D,message:K,fromArchive:false,type:H});A=this.conversationWindow(D);A.hideOfflineNotice();if((A&&!$(A.window).visible())||(B===true)||(this.windowTitle.hasFocus===false)){ComCore.Chat.SoundManager.beep()}C=this.conversationButton(D);C.setStatus(F.status).show();C.setBlinking(true);try{$(document).fire("comcore:chat_conversations_receivemessage",{from_userid:F.userID,to_userid:ComCore.Login.getUserID()})}catch(G){log(G)}}}this.state.updateState()},regenerateChatEnvironment:function(A){var C=this.conversations.get(A.username);var B=new ComCore.Chat.ConversationButton(A,this);C.b=B;this.conversationWindow(A.username).button=B},startNew:function(E,D){if(this.onlineFriends.isLoaded()===false){ComCore.LoadingIndicator.show();this.onlineFriends.load((function(){this.startNew(E,D)}).bind(this));return }ComCore.LoadingIndicator.hide();var A=$H({nofriend:true,gender:"",age:"",region:"",status:"online",avatarUrl:ComCore.Configuration.get("photoStaticURL")+"/p/tt/000/000/0.jpg",name:E});D=$H(A).merge(D).toObject();if(D.mainphotoid&&!isNaN(D.mainphotoid)){D.avatarUrl=ComCore.Chat.Helper.buildImagePath(D.mainphotoid,D.distro)}var B=this.onlineFriends.get(E.toLowerCase());if(B===undefined){B={name:D.firstname,status:D.status,username:E.toLowerCase(),avatarUrl:D.avatarUrl,userID:D.userID};if(D.nofriend&&(D.nofriend===true)){B.nofriend=true}this.onlineFriends.add(E,B);var C=new ComCore.Chat.OnlineEveryoneElement(B);B.element=C;$("chatListEveryone").insert(B.element.html);this.onlineFriendsWindow.updateContactList("chatListEveryone",B,B.status)}this.onStartChat(B.username)},_eoo:true});ComCore.Chat.MenuController=Class.create({initialize:function(A){this.controller=A;this.menu=$("chatMenuTabs");this.tabs=this.menu.select("a");this.views=[$("chatTabFriends"),$("chatTabEveryone"),$("chatTabSettings")];this.menu.observe("click",this.onMenuClick.bind(this));this.searchFunctions=[$("chatSearchFriends"),$("chatSearchEveryone")];this.everyoneController=new ComCore.Chat.EveryoneController(this)},onMenuClick:function(A){A.stop();var C=(A.element().tagName.toLowerCase()==="a")?A.element():A.element().down("a.menuTab")||A.element().up("a.menuTab");var B=C.getAttribute("id").replace("chatMenuItem","");this.tabs.invoke("removeClassName","selected");C.addClassName("selected");this.controller.chatStatusWindow.hide();this.views.each(function(E){E[(E.getAttribute("id")===("chatTab"+B))?"show":"hide"]()});this.searchFunctions.each(function(E){E[(E.getAttribute("id")===("chatSearch"+B))?"show":"hide"]()});if(B==="Everyone"){this.notify("onEveryoneClick")}else{$("chatRefreshEveryone").hide()}try{$(document).fire("comcore:chat_contactlist_switchtab",{tab:B.toLowerCase()})}catch(D){log(D)}},_eoo:true});ComCore.Events.extend(ComCore.Chat.MenuController);ComCore.Chat.SettingsController=Class.create({initialize:function(A){$("chatSound").observe("change",this.onChatSoundChange.bind(this));$("privacySettings").observe("change",this.saveChatSettings.bind(this));if($("displaySettings")){$("displaySettings").observe("change",this.saveChatSettings.bind(this))}$("disableChatBar").observe("click",this.saveChatSettings.bind(this));$("chatDeleteAllHistory").observe("click",this.onDeleteAllHistory.bind(this));this.controller=A;this.controller.userStatus.observe("onUserStatusChanged",this.changeStatus.bind(this))},onDeleteAllHistory:function(A){A.stop();var D=ComCore.Chat.Helper.getTranslation("clearAllArchives");if(confirm(D)===true){$("savingLoading").show();var C={csrftoken_clearallarchives:ComCore.CSRF.getToken("clearAllArchives")};var B=new Ajax.Request(ComCore.Page.buildAjaxURL("chatbar","clearAllArchives"),{method:"post",parameters:C,onSuccess:this.onDeleteAllHistoryDone.bind(this)})}},onDeleteAllHistoryDone:function(B){if(B.responseJSON.success===true){this.onSaveChatSettingsDone();var A;this.controller.conversations.each(function(C){A=C.value.w;if(A){A.clearArchive()}})}},changeStatus:function(A){if(A!=="invisible"){$("disableChatBar").checked=true}else{$("disableChatBar").checked=false}if((this.controller.userStatus.jabberStatus==="everyone")||(this.controller.userStatus.jabberStatus==="friends")){$("privacySettings").select("option").each(function(B){B.selected=(B.value===this.controller.userStatus.jabberStatus)},this)}},saveChatSettings:function(){var C=$("disableChatBar");$("savingLoading").show();if(C.checked===false){this.controller.userStatus.set("invisible",true,"invisible")}else{if(this.controller.userStatus.status!=="online"){this.controller.userStatus.set("online",true,ComCore.Chat.Settings.chatPrivacy.toLowerCase())}}var H=C.checked?"ACTIVE":"DISABLED";var B=($("privacySettings").selectedIndex===1)?"EVERYONE":"FRIENDS";var F="MINIMIZABLE";if($("displaySettings")){F=($("displaySettings").selectedIndex===0)?"VISIBLE":($("displaySettings").selectedIndex===1?"MINIMIZABLE":"AUTOHIDE")}var A=$("chatSound");var E=A.options[A.selectedIndex].value;if(this.controller.userStatus.status==="online"){this.controller.userStatus.set("online",true,B.toLowerCase())}if(F==="MINIMIZABLE"){$("hudButtonMinimize").show();$("hudButtonMaximize").show();stopAutoHideChat()}else{$("hudButtonMinimize").hide();$("hudButtonMaximize").hide();if(F==="AUTOHIDE"){startAutoHideChat()}else{stopAutoHideChat()}}var G="chatActive="+H+"&privacy="+B+"&display="+F+"&sound="+E+"&"+ComCore.CSRF.getParam("saveSettings");var D=new Ajax.Request(ComCore.Page.buildAjaxURL("chatbar","saveSettings"),{method:"post",parameters:G,onSuccess:this.onSaveChatSettingsDone.bind(this)})},onSaveChatSettingsDone:function(A){$("savingLoading").hide();var B=$("savingSuccess");B.show();window.setTimeout(function(){B.hide()},3000)},onChatSoundChange:function(A){A.stop();var C=$("chatSound");var B=parseInt(C.options[C.selectedIndex].value,10);if(B!==0){Sound.play(ComCore.Configuration.get("staticURL")+"/s/i/hud/sounds/"+B+".swf")}ComCore.Chat.Settings.soundType=B;this.saveChatSettings()},_eoo:true});ComCore.Chat.EveryoneController=Class.create({initialize:function(A){this.ajaxLoaded=this.ajaxLoading=false;this.menuController=A;this.menuController.observe("onEveryoneClick",this.onShowView.bind(this));$("chatRefreshEveryone").observe("click",this.onRefreshEveryoneView.bind(this))},onRefreshEveryoneView:function(A){A.stop();this.ajaxLoaded=false;this.loadEveryoneContent()},onShowView:function(A){this.lastFetch=new Date().getTime();$("chatRefreshEveryone").show();if(((this.ajaxLoaded===false)&&(this.ajaxLoading===false))||((new Date().getTime()-this.lastFetch)>ComCore.Chat.Constants.REFRESH_EVERYONE_INTERVAL)){this.loadEveryoneContent()}},loadEveryoneContent:function(){$("chatTabEveryone").down(".hudLoading").show();var A=new Ajax.Request("/ajax/chatbar/view=getEveryone",{method:"GET",onCreate:(function(){this.ajaxLoading=true}).bind(this),onSuccess:this.onReceiveEveryoneList.bind(this)})},onReceiveEveryoneList:function(E){$("chatTabEveryone").down(".hudLoading").hide();this.ajaxLoading=true;var B=E.responseJSON;var G=[];var J=[];for(var F=0,H=B.length;F<H;F++){var A=B[F];if(A){A.nickname=A.nickname.toLowerCase();var D={nofriend:true,age:A.age,region:A.region,gender:A.gender,name:A.firstname,status:"online",username:A.nickname,avatarUrl:A.picture,userID:(parseInt(A.userid,10)||0)};var I=this.menuController.controller.onlineFriends.get(D.username);if(I===undefined){this.menuController.controller.onlineFriends.add(D.username,D);D=this.menuController.controller.onlineFriends.get(D.username)}else{D=I}var C=new ComCore.Chat.OnlineEveryoneElement(D);D.element=C;J.push(D)}}var L=this.menuController.controller.onlineFriends.users.values().findAll(function(M){return(M.nofriend&&(M.nofriend===true)&&M.element)});J.each(function(M){G.push(M.element.html)});$("chatListEveryone").innerHTML="";$("chatListEveryone").innerHTML=G.join("");try{$(document).fire("comcore:chat_contactlist_updatelist",{tab:"everyone",contacts_count:B.length})}catch(K){log(K)}},_eoo:true});ComCore.Events.extend(ComCore.Chat.EveryoneController);ComCore.Chat.Games=Class.create({initialize:function(A){this.controller=A},getRoster:function(A){if(this.controller.onlineFriends.rosterLoaded===false){this.controller.onlineFriends.load(this.getRoster.bind(this,A))}else{var B=this.controller.onlineFriends.getRosterDetails();A(B)}},createChallenge:function(C){if(this.controller.onlineFriends.isLoaded()===false){var D=(function(F){this.createChallenge(C)}).bind(this);this.controller.onlineFriends.load(D);return }var B=this.controller.onlineFriends.users.values().find(function(F){return(F.userID===C.netlogid)});var E=escape(Object.toJSON(C));if(B){var A=ComCore.Chat.Helper.getTranslation("gameChallengeArchive",{sender:this.controller.connection.username,game:C.gameName,url:C.gameUrl});this.controller.connection.sendCustomMessage(B.username,A,E)}else{log("Could not find user!")}},challengeReceived:function(C,E){var A=unescape(C);var D=null;try{D=A.evalJSON()}catch(B){log(B)}if((D!==null)&&(D.gameName!==undefined)){this.displayChallenge(D,E)}},createBody:function(E){var A=E.body;var G=ComCore.Chat.Helper.getTranslation("gameChallengeString",{sender:E.username,game:A.gameName});var J=ComCore.Chat.Helper.getTranslation("gameChallengeLink");var D=new Element("img",{src:A.gameThumbnail});var H=$("gameChallengeClone").cloneNode(true);var C=H.down(".gameImage");var F=H.down(".gameDescription");var B=((/play\/((.*)+)/i).test(window.location.href)===true)?"_blank":"_self";var I=new Element("a",{href:A.gameUrl,target:B}).update(J);C.insert(D);F.insert(G);F.insert(new Element("br"));F.insert(I);return H.innerHTML},createChallengeSentBody:function(G,C){var A=unescape(G.body).evalJSON();var D=ComCore.Chat.Helper.getTranslation("gameChallengeSent",{receiver:C,game:A.gameName});var B=new Element("img",{src:A.gameThumbnail});var H=$("gameChallengeClone").cloneNode(true);var F=H.down(".gameImage");var E=H.down(".gameDescription");F.insert(B);E.insert(D);return H.innerHTML},displayChallenge:function(A,B){this.controller.onMessageReceived({username:B,message:A,playSound:false,type:"game"})},_eoo:true});ComCore.Chat.WindowTitle=Class.create({initialize:function(){this.setFocusEvents();this.originalTitle=document.title;this.hasFocus=true;this.newMessages=0;this.isScrolling=false},poll:function(A){if(!this.hasFocus){if(this.isScrolling===false){var B=ComCore.Chat.Helper.getTranslation("newChatMessageReceived",{username:A.name});this.scrollTitle(B)}}},scrollTitle:function(A){if(this.scrollTimeout){window.clearTimeout(this.scrollTimeout)}A=A.substring(1,A.length)+A.substring(0,1);document.title=A;this.isScrolling=true;this.scrollTimeout=window.setTimeout((function(){this.scrollTitle(A)}).bind(this),600)},setFocusEvents:function(){this.active_element=document.activeElement;var A=document;if(Prototype.Browser.IE){A.observe("onfocusout",this.onWindowBlur.bind(this));A.observe("onfocusin",this.onWindowFocus.bind(this))}else{window.onblur=this.onWindowBlur.bind(this);window.onfocus=this.onWindowFocus.bind(this);A.onblur=window.onblur.bind(this);A.focus=window.onfocus.bind(this)}},onWindowFocus:function(B){var A=document;if(this.scrollTimeout){window.clearTimeout(this.scrollTimeout);this.isScrolling=false}if(A.title!==this.originalTitle){A.title=this.originalTitle}this.hasFocus=true;this.notify("onWindowFocus")},onWindowBlur:function(A){this.hasFocus=false;if(this.active_element!==document.activeElement){this.active_element=document.activeElement}},_eoo:true});ComCore.Events.extend(ComCore.Chat.WindowTitle);ComCore.Events.extend(ComCore.Chat.Controller);ComCore.Chat.IdleNotifier=Class.create({_events:[[window,"scroll"],[window,"resize"],[document,"mousemove"],[document,"keydown"]],_timer:null,_idleTime:null,initialize:function(){this.initObservers();this.setTimer()},initObservers:function(){this._events.each((function(A){Event.observe(A[0],A[1],this.onInterrupt.bind(this))}).bind(this))},onInterrupt:function(){document.fire("state:active",{idleTime:(new Date()-this._idleTime)});this.setTimer()},setTimer:function(){window.clearTimeout(this._timer);this._idleTime=new Date();this._timer=window.setTimeout(function(){document.fire("state:idle")},ComCore.Chat.Constants.IDLE_TIMEOUT)},_eoo:true});ComCore.Chat.NudgeController=Class.create({initialize:function(A){this.nudges=ComCore.Chat.NudgeController.nudges;this.floodCheck=[];this.controller=A;this.pendingNudges=[];this.isNudgeVisible=false;this.controller.windowTitle.observe("onWindowFocus",this.emptyQueue.bind(this))},emptyQueue:function(){if(this.pendingNudges.length>3){this.pendingNudges=this.pendingNudges.slice(0,3)}if(this.pendingNudges.length>0){var A=this.pendingNudges.shift();this.nudgeReceived(A[0],A[1])}},sendNudge:function(A,B){if(this.nudges[A.toUpperCase()]){log("sending nudge");this.controller.connection.sendNudge(this.nudges[A.toUpperCase()].cmd,B)}},nudgeReceived:function(D,G){if(this.nudges[D.toUpperCase()]===undefined){log("Received unknown nudge");return }if(this.isNudgeVisible===true){this.pendingNudges.push([D,G]);return }if(this.controller.windowTitle.hasFocus===false){this.controller.windowTitle.scrollTitle("You received a nudge from "+G+" ");this.pendingNudges.push([D,G]);return false}var F=this.floodCheck.any(function(H){return(((new Date().getTime()-H.timestamp)<30000)&&(H.username===G))});if(F===true){return }this.floodCheck.push({timestamp:new Date().getTime(),username:G});if(!this.controller.conversations.get(G)){this.controller.createConversation(G)}var C=this.controller.conversationWindow(G);this.controller.onStartChat(G);if(C){C.addNotification("You received a nudge!")}var B=this.nudges[D.toUpperCase()].ttl;log("received a nudge!!");var E=new Element("embed",{id:"currentNudge",src:ComCore.Configuration.get("staticURL")+"/s/f/chat/"+D+".swf",wmode:"transparent",loop:"false",style:"width: 100%; height: 90%; position:absolute; top:0px; left:0px; z-index: 99999"});var A=$("currentNudge");if(A){A.remove()}window.setTimeout((function(){$("currentNudge").remove();this.isNudgeVisible=false;this.emptyQueue()}).bind(this),(B*1000));document.body.insert(E)},_eoo:true});ComCore.Chat.NudgeController.nudges={FART:{cmd:"fart",ttl:10},BUNNY:{cmd:"bunny",ttl:10},CRY:{cmd:"cry",ttl:5},CUPID:{cmd:"cupid",ttl:7},KISS:{cmd:"kiss",ttl:7},PANIC:{cmd:"panic",ttl:12},PENGUIN:{cmd:"penguin",ttl:14},SEXY:{cmd:"sexy",ttl:10},AMADEUS:{cmd:"amadeus",ttl:5}};