/*1306808390,169776065*/

if (window.CavalryLogger) { CavalryLogger.start_js(["h4GIG"]); }

var ChannelRebuildReasons={Unknown:0,AsyncError:1,TooLong:2,Refresh:3,RefreshDelay:4,UIRestart:5,NeedSeq:6,PrevFailed:7,IFrameLoadGiveUp:8,IFrameLoadRetry:9,IFrameLoadRetryWorked:10,PageTransitionRetry:11,IFrameLoadMaxSubdomain:12,NoChannelInfo:13,NoChannelHost:14,ChannelUnknown:100,ChannelNoCUser:101,ChannelInvalidCUser:102,ChannelInvalidChanstr:103,ChannelChDistribTimeout:104,ChannelGetChannelOther:105,ChannelNodeShutdown:106,ChannelTermination:107,ChannelUserMismatch:108,ChannelUserMismatchShady:109,ChannelBadXs:110,ChannelSeqNeg:111,ChannelSeqTooBig:112,ChannelSeqTooSmall:113,ChannelUnexpectedJoin:114,ChannelInvalidXsCookie:115,ChannelRelocate:116,ChannelWrongPartition:117};
var CrossDocument={};(function(){CrossDocument.setListener=function(eventHandler){if(window.postMessage){if(window.addEventListener){window.addEventListener('message',eventHandler,false);}else window.onmessage=eventHandler;}else if(document.postMessage)document.addEventListener('message',eventHandler,false);};CrossDocument.mkPostMessage=function(targetWindow,targetDocument,msgHandler){if(window.postMessage){if("object"==typeof window.postMessage){return function(message,origin){targetWindow.postMessage(message,origin);};}else return bind(targetWindow,targetWindow.postMessage);}else if(document.postMessage){return bind(targetDocument,targetDocument.postMessage);}else return bind(targetWindow,msgHandler);};CrossDocument.targetOrigin=function(parent){if(window.postMessage||document.postMessage){var parentLoc=parent.location;var parentHost=parentLoc.hostname;if(parentHost=='facebook.com'||parentHost.substring(parentHost.length-13)=='.facebook.com')return parentLoc.protocol+'//'+parentLoc.host;}else return null;};var _handleMessage=function(msgCallback,msgStr){if(!msgStr||msgStr.charAt(0)!='{')return;var msg=eval('('+msgStr+')');return msgCallback(msg);};CrossDocument.mkEventHandler=function(msgCallback){return function(event){event=event||window.event;var domain=(event.domain||event.origin);if(domain.substring(domain.length-13)!='.facebook.com'&&domain.substring(domain.length-15)!='://facebook.com'&&domain!='facebook.com')return;return _handleMessage(msgCallback,event.data);};};CrossDocument.mkMessageHandler=function(msgCallback){return function(msgStr){return _handleMessage(msgCallback,msgStr);};};})();
function ChannelManager(b,e,d,a,c){this.user=e;this.iframeLoadMaxRetries=1;this.iframeLoadMaxSubdomain=6;this.expectResponseTimeout=5000;this.retryInterval=d;this.channelConfig=a;this._init(b,c);}ChannelManager.CONN_LOG_INTERVAL=10000;ChannelManager.prototype={_init:function(c,d){this.channelManagerId=rand32();this.config={};this.channel={};this.isActionRequest=true;this.isReady=false;this.isRebuilding=false;this.iframeIsLoaded=false;this.iframeEverLoaded=false;this.iframeCheckFailedCount=0;this.shouldClearSubdomain=false;this.subframe=c;Event.listen(this.subframe,'load',this._iframeLoadCheck.bind(this));this.postMessage=null;var a=presenceCookieManager.getSubCookie('ch');if(d){this.iframeSubdomain=null;}else{this.iframeSubdomain=0;if(a&&a.sub){for(var b=0;b<a.sub.length;b++)if(!a.sub[b]){this.iframeSubdomain=b;break;}if(b==a.sub.length)if(b==this.iframeLoadMaxSubdomain&&URI().isSecure()){this.iframeSubdomain=null;this._sendDummyReconnect(ChannelRebuildReasons.IFrameLoadMaxSubdomain);}else this.iframeSubdomain=a.sub.length;}}this.handleIframeEvent=CrossDocument.mkEventHandler(this._handleIframeMessage.bind(this));this.handleIframeMessage=CrossDocument.mkMessageHandler(this._handleIframeMessage.bind(this));CrossDocument.setListener(this.handleIframeEvent.bind(this));presenceCookieManager.register('ch',this._getCookieInfo.bind(this));if(typeof window.onpageshow!='undefined'){Event.listen(window,'pagehide',this._onUnload.bind(this));Event.listen(window,'pageshow',this.rebuild.bind(this,ChannelRebuildReasons.Refresh));}else onunloadRegister(this._onUnload.bind(this));this._connLogger=EagleEye.createLogger('channel-connectivity',this.getConfig('CONNECTIVITY_SAMPLING',.01));this._connTime=Env.start;this._connT=2000;this._connectivity={};(this._connSample=this._connSample.bind(this))();(this._connLog=this._connLog.bind(this))();},_connSample:function(){var a=new Date(),b=this._connState||'idle';t=a-this._connTime;this._connAdd(b,t);this._connTime=a;setTimeout(this._connSample,1000*(1+Math.random()));},_connAdd:function(a,b){this._connectivity[a]=(this._connectivity[a]||0)+b;},_connLog:function(){this._connLogger(this._connectivity);this._connectivity={};this._connT=Math.min(60000,2*this._connT);setTimeout(this._connLog,this._connT);},sendIframeMessage:function(b){if(!this.postMessage)return;var c=JSON.stringify(b);try{this.postMessage(c,this.targetOrigin);}catch(a){presence.error('channel: iframe msg error: '+'message "'+c+'" and error '+a.toString());}},_handleIframeMessage:function(g){var f=this.channel.currentSeq;if('seq' in g){this.channel.currentSeq=g.seq;presence.doSync();}switch(g.t){case 'init':this._connState=null;this.iframeLoaded();break;case 'log':window.chatErrorLog&&window.chatErrorLog.log(g.msg);break;case 'shutdown':if(window.loaded){presence.error('channel:refresh_'+g.reason);this.rebuild(g.reason);this.channel.shutdownHandler(true);}break;case 'connectivity':delete g.t;if('state' in g){this._connState=g.state;delete g.state;}for(var e in g)this._connAdd(e,g[e]);break;case 'fullReload':presence.error('channel:fullReload');presenceCookieManager.clear();Arbiter.inform('channel/invalid_history');break;case 'msg':var a=this.channel;var h=g.ms;var i=a.currentSeq-h.length;for(var d=0;d<h.length;d++,i++)if(i>=f){var b=h[d];try{a.msgHandler(a.name,b);}catch(c){presence.error('channel: error while handling '+b.type+' - '+c.toString());}}break;}},_onUnload:function(){this.shouldClearSubdomain=true;presenceCookieManager.setCheckUserCookie(true);presence.doSync(true);},addChannel:function(a,d,b,f,e,c){if(this.channel.name){presence.error("channel: addChannel called twice");return;}this.channel={name:a,currentSeq:d,msgHandler:b,startHandler:f,shutdownHandler:e,restartHandler:c};presence.doSync();},_getCookieInfo:function(){var b={};if(this.config.host){b.h=this.config.host;if(this.config.port)b.p=this.config.port;if(null!==this.iframeSubdomain){var a=presenceCookieManager.getSubCookie('ch');var e=(a&&a.sub)?a.sub:[];var d=e.length;if(this.shouldClearSubdomain){e[this.iframeSubdomain]=0;}else{e[this.iframeSubdomain]=1;for(var c=d;c<=this.iframeSubdomain;c++)if(!e[c])e[c]=0;}b.sub=e;}b[this.channel.name]=this.channel.currentSeq;}b.ri=this.retryInterval;return b;},getConfig:function(c,b){var a=this.channelConfig;return a&&(c in a)?a[c]:b;},stop:function(){this.stopped=true;this.setReady(false);},setReady:function(a){this.isReady=a;var b={type:'isReady',isReady:a,isActionRequest:this.isActionRequest};if(a&&this.isActionRequest)this.isActionRequest=false;if(a){b.channelName=this.channel.name;b.currentSeq=this.channel.currentSeq;b.channelManagerId=this.channelManagerId;b.channelConfig=this.channelConfig;}this.sendIframeMessage(b);},setActionRequest:function(a){this.sendIframeMessage({type:'isActionRequest',isActionRequest:a});},expectResponse:function(){this.sendIframeMessage({type:'expectResponse',newTimeout:this.expectResponseTimeout});},_iframeUrl:function(a,c,b){var d;if(null===this.iframeSubdomain){d='';}else{d=this.iframeSubdomain;d+=URI().isSecure()?'-':'.';}return new URI().setDomain(d+a+'.facebook.com').setPort(c).setPath(b).setSecure(URI().isSecure()).toString();},iframeLoad:function(a,c){this.isReady=c;this.iframeIsLoaded=false;this.config=a;var e=this._iframeUrl(a.host,a.port,a.path);clearTimeout(this._checkTimer);this._checkTimer=this._iframeCheck.bind(this).defer(this.getConfig('IFRAME_LOAD_TIMEOUT',30000));var d=null;if(!ua.ie()||ua.ie()<8)try{d=this.subframe.contentDocument;}catch(b){}if(d){try{d.location.replace(e);}catch(b){presence.error('channel: error setting location: '+b.toString());}}else if(this.subframe.contentWindow){this.subframe.src=e;}else if(this.subframe.document){this.subframe.src=e;}else presence.error('channel: error setting subframe url');presence.debug('channel: done with iframeLoad, subframe sent to '+e);},_iframeLoadCheck:function(){try{this.subframe.contentWindow.document.body.innerHTML;}catch(a){presence.error('channel:iframe load check error:(check #'+this.iframeCheckFailedCount+'):'+a);}},iframeLoaded:function(){if(!this.iframeIsLoaded){this.iframeIsLoaded=true;this.postMessage=CrossDocument.mkPostMessage(this.subframe.contentWindow,this.subframe.contentDocument,this.subframe.contentWindow.channelUplink.handleParentMessage);this.targetOrigin="*";this.setReady(this.isReady);if(this.iframeCheckFailedCount){this.channel.restartHandler(false);this._sendDummyReconnect(ChannelRebuildReasons.IFrameLoadRetryWorked);}else this.channel.startHandler();this.iframeCheckFailedCount=0;this.iframeEverLoaded=true;}},_diagnoseIframeError:function(b){function a(j){var k={},l=new Date();var h=j=='channel'?b.host:b.host2;var g=function(m){if(!k.result){k.t=new Date()-l;k.result=m?'contact':'error';e();}};k.toString=function(){return 'NAME STATUS (t=TIME)'.replace('NAME',j).replace('STATUS',k.result||'timeout').replace('TIME',Math.round(k.t/1000));};var i=new Image();i.onload=g.bind(null,true);i.onerror=g.bind(null,false);i.src=new URI().setDomain(h+'.facebook.com').setPort(b.port).setPath('/iping').setSecure(URI().isSecure());return k;}function e(g){if(g||(c.result&&d.result))presence.error('channel:iframe_failed:'+c+', '+d);}var f=e.bind(null,true).defer(120000);var c=a('channel'),d=a('alias');},_iframeCheck:function(){delete this._checkTimer;if(!this.iframeIsLoaded){this.iframeCheckFailedCount++;var a=this.config;this.config={};presenceCookieManager.store();if(this.iframeCheckFailedCount<=this.iframeLoadMaxRetries){this.rebuild(ChannelRebuildReasons.IFrameLoadRetry);}else{this.channel.shutdownHandler();this._sendDummyReconnect(ChannelRebuildReasons.IFrameLoadGiveUp);this._diagnoseIframeError(a);}}else this.retryInterval=0;},_sendDummyReconnect:function(b){var a=new AsyncRequest().setURI('/ajax/presence/reconnect.php').setData({reason:b,iframe_loaded:this.iframeEverLoaded}).setOption('suppressErrorHandlerWarning',true).setOption('retries',1).setMethod('GET').setReadOnly(true).setAllowCrossPageTransition(true);a.specifiesWriteRequiredParams()&&a.send();},_rebuildResponse:function(c){var b=c.getPayload();var a=b.user_channel;presence.debug('got rebuild response with channel '+a+', seq '+b.seq+', host '+b.host+', port '+b.port);this.channel.currentSeq=b.seq;this.isRebuilding=false;if(b.path!=this.config.path||b.host!=this.config.host){this.iframeLoad(b,true);}else this.setReady(true);presenceCookieManager.store();if(typeof chatOptions!='undefined')chatOptions.setVisibility(b.visibility);this.channel.restartHandler(true);},_retryRebuild:function(c,a){var d=this.getConfig('MAX_RETRY_INTERVAL',60000);var e=this.getConfig('MIN_RETRY_INTERVAL',10000);if(a){this.retryInterval=d;}else if(this.retryInterval==0){this.retryInterval=e;}else this.retryInterval=Math.min(d,this.retryInterval*2);var b=this.retryInterval*(.75+Math.random()*.5);presence.warn('channel: retry: manager trying again in '+(b*.001)+' secs');setTimeout(this._rebuildSend.bind(this,c),this.retryInterval);},_rebuildError:function(a,b){this.channel.shutdownHandler(true);presence.error('channel: got rebuild error: '+b.getErrorDescription());if(presence.checkMaintenanceError(b)){presence.warn('channel: manager not trying again');}else if(presence.checkLoginError(b)){if(presence.inPopoutWindow){this._retryRebuild(ChannelRebuildReasons.PrevFailed,true);}else presence.warn('channel: manager not trying again');}else this._retryRebuild(ChannelRebuildReasons.PrevFailed,false);},_rebuildTransportError:function(a,b){this.channel.shutdownHandler(true);presence.error('channel: got rebuild transport error: '+b.getErrorDescription());this._retryRebuild(a,false);},_rebuildSend:function(b){if(!presence.hasUserCookie(true))return;if(typeof b!='number')b=ChannelRebuildReasons.Unknown;presence.debug('channel: sending rebuild');var a=new AsyncRequest().setURI('/ajax/presence/reconnect.php').setData({reason:b,iframe_loaded:this.iframeEverLoaded}).setHandler(this._rebuildResponse.bind(this)).setErrorHandler(this._rebuildError.bind(this,b)).setTransportErrorHandler(this._rebuildTransportError.bind(this,b)).setOption('suppressErrorAlerts',true).setOption('retries',1).setMethod('GET').setReadOnly(true).setAllowCrossPageTransition(true);return a.specifiesWriteRequiredParams()&&a.send();},rebuild:function(a){presenceCookieManager.setCheckUserCookie(false);if(this.stopped)return;if(this.isRebuilding){presence.debug('channel: rebuild called, but already rebuilding');return;}this.setReady(false);this.isRebuilding=true;presence.debug('channel: rebuilding');if(a==ChannelRebuildReasons.RefreshDelay)this.retryInterval=this.channelConfig.MAX_RETRY_INTERVAL;setTimeout(this._rebuildSend.bind(this,a),this.retryInterval);}};
function TinyPresence(g,c,b,a,e,d,f){this.user=g;this.name=c;this.firstName=b;this.alias=a;this.sitevars=f;this.popoutURL=env_get('www_base')+'presence/popout.php';this.updateServerTime(e);this.pageLoadTime=this.getTime();this._init(d);}TinyPresence.prototype={cookiePollTime:2000,popoutHeartbeatTime:1000,popoutHeartbeatAllowance:4000,popoutHeartbeatFirstAllowance:15000,shutdownDelay:5000,restartDelay:3000,_init:function(a){this.stateStorers=[];this.stateLoaders=[];this._syncTimeout=null;this.windowID=rand32()+1;this.cookiePoller=null;this.heartbeat=null;this.stateUpdateTime=0;this.loaded=false;this.isShutdown=false;this.isShuttingDown=false;this.isRestarting=false;this.isPermaShutdown=false;this.shutdownTime=0;this.justPoppedOut=false;this.syncPaused=0;this.poppedOut=a;this.inPopoutWindow=a;presenceCookieManager.register('state',this._getCookieData.bind(this));Arbiter.subscribe("page_transition",this.checkRebuild.bind(this));this.load();},updateServerTime:function(a){this.timeSkew=new Date().getTime()-a;},getTime:function(){return new Date().getTime()-this.timeSkew;},debug:function(a){},warn:function(a){this.logError("13003:warning:"+a);},error:function(a){this.logError("13002:error:"+a);},logError:function(a){window.EagleEye&&EagleEye.log('realtime-error',{data:a});},load:function(){var b=presenceCookieManager.getSubCookie('state');if(!b){this.debug('presence: got null state cookie, loading with current state');this._load(this._getCookieData());return;}try{this._load(b);}catch(a){this.error('presence: got load exception: '+a.toString());this._load(this._getCookieData());}},_load:function(b){this.syncPaused++;this.stateUpdateTime=verifyNumber(b.ut);this.popoutTime=verifyNumber(b.pt);this.poppedOut=!!b.p;if(this.poppedOut){if(this.inPopoutWindow)if(!this.heartbeat)this.heartbeat=setInterval(this._popoutHeartbeat.bind(this),this.popoutHeartbeatTime);}else if(this.inPopoutWindow){if(!this.loaded){this.poppedOut=true;this.doSync();}}else this.justPoppedOut=true;if(!this.inPopoutWindow&&!this.cookiePoller)this.cookiePoller=setInterval(this._pollCookie.bind(this),this.cookiePollTime);this.state=b;for(var a=0;a<this.stateLoaders.length;a++)this.stateLoaders[a](b);this.syncPaused--;this._loaded();},_loaded:function(){this.loaded=true;},_pollCookie:function(){var e=presenceCookieManager.getSubCookie('state');if(!e)return;var d=this.popoutTime;if(e.ut>this.stateUpdateTime){this.load(e);return;}if(this.poppedOut&&!this.inPopoutWindow){var a=verifyNumber(e.pt);var b=new Date().getTime()-a;var c=this.popoutHeartbeatTime+this.popoutHeartbeatAllowance;if(this.justPoppedOut)if(a==d){c+=this.popoutHeartbeatFirstAllowance;}else this.justPoppedOut=false;this.popoutTime=a;if(b>c){this.poppedOut=false;this.doSync();}}},_popoutHeartbeat:function(){this._pollCookie();if(this.poppedOut)presenceCookieManager.store();},_getCookieData:function(){var b={p:this.poppedOut?1:0,ut:this.stateUpdateTime,pt:this.inPopoutWindow?new Date().getTime():this.popoutTime};for(var a=0;a<this.stateStorers.length;a++)b=this.stateStorers[a](b);this.state=b;return this.state;},doSync:function(a){if(this.syncPaused)return;if(a){this._doSync();}else if(!this._syncTimeout)this._syncTimeout=this._doSync.bind(this).defer();},_doSync:function(){clearTimeout(this._syncTimeout);this._syncTimeout=null;this.stateUpdateTime=new Date().getTime();presenceCookieManager.store();this._load(this.state);},pauseSync:function(){this.syncPaused++;},resumeSync:function(){this.syncPaused--;this.doSync();},handleMsg:function(a,b){this._handleMsg.bind(this,a,b).defer();},_handleMsg:function(a,b){if(typeof b=='string'){if(b=='shutdown'){this.connectionShutdown();}else if(b=='restart')if(this.isShutdown)this.restart();return;}if(this.isShutdown)return false;if(!b.type)return;Arbiter.inform(PresenceMessage.getArbiterMessageType(b.type),{sender:this,channel:a,obj:b});},checkRebuild:function(){if(this.isShutdown&&!this.isPermaShutdown)channelManager.rebuild(ChannelRebuildReasons.PageTransitionRetry);},getErrorDescription:function(a){var c=a.getError();var b=a.getErrorDescription();if(!b)b=_tx("Se ha producido un error.");if(c==1357001)b=_tx("Se ha superado el tiempo de espera de la sesi\u00f3n. Por favor, vuelve a iniciar sesi\u00f3n.");return b;},checkLoginError:function(a){var b=a.getError();if(b==1357001||b==1357004||b==1348009){this.loginShutdown();return true;}return false;},checkMaintenanceError:function(a){if(a.getError()==1356007){this.maintenanceShutdown();return true;}return false;},permaShutdown:function(){this.isPermaShutdown=true;var a=_tx("Facebook {Chat} est\u00e1 experimentando problemas t\u00e9cnicos.",{Chat:_tx("Chat")});this.shutdown(false,a,"perma_shutdown");},loginShutdown:function(){var a=_tx("Se ha superado el tiempo de espera de la sesi\u00f3n. Por favor, vuelve a iniciar sesi\u00f3n.");this.shutdown(false,a,"login_shutdown");},connectionShutdown:function(b){var a=_tx("No se ha podido conectar con Facebook {Chat} en este momento.",{Chat:_tx("Chat")});this.shutdown(b,a,"connection_shutdown");},maintenanceShutdown:function(){var a=_tx("El {Chat} de Facebook est\u00e1 parado en este momento por razones de mantenimieto.",{Chat:_tx("Chat")});this.shutdown(false,a,"maintenance_shutdown");channelManager.stop();},versionShutdown:function(){var a=_tx("Por favor, refresca esta p\u00e1gina para obtener la \u00faltima versi\u00f3n de Facebook {Chat}.",{Chat:_tx("Chat")});this.shutdown(false,a,"version_shutdown");channelManager.stop();},shutdown:function(d,c,a){this.isRestarting=false;this.isShuttingDown=true;var b=new Date().getTime();this.shutdownTime=b;if(!d){this._shutdown(c,0,a);}else setTimeout(this._shutdown.bind(this,c,b,a),this.shutdownDelay);},_shutdown:function(b,c,a){if(!this.isShuttingDown&&c==this.shutdownTime)return;if(c&&this.isShutdown)return;if(typeof b!='string'||!b)b=_tx("Facebook {Chat} est\u00e1 experimentando problemas t\u00e9cnicos.",{Chat:_tx("Chat")});if(typeof a!='string'||!a)a="undefined";this.warn("presence:displaying_shutdown:"+a);if(this.isShutdown)return;this.logError("13001:shutdown:presence:"+a);this.isShutdown=true;Arbiter.inform(PresenceMessage.SHUTDOWN,{sender:this});},restart:function(a){this.isShuttingDown=false;this.isRestarting=true;if(!a){this._restart(0);}else this._restart.bind(this,this.shutdownTime).defer(this.restartDelay);},_restart:function(a){if(!this.isRestarting||(a&&a!=this.shutdownTime))return;this.debug("presence: restarting");this.isShutdown=false;this.load();Arbiter.inform(PresenceMessage.RESTARTED,{sender:this});},start:function(){Arbiter.inform(PresenceMessage.STARTED,{sender:this});},registerStateStorer:function(a){this.stateStorers.push(a);},registerStateLoader:function(a){this.stateLoaders.push(a);},hasUserCookie:function(a){var b=this.user==getCookie('c_user');if(!b&&a)this.permaShutdown();return b;}};
function Presence(g,c,b,a,e,d,f){this.parent.construct(this,g,c,b,a,e,d,f);}Presence.extend('TinyPresence');Presence.prototype={minWidth:100,minHeight:100,defWidth:900,defHeight:650,defX:30,defY:30,_init:function(b){if(!b){this.holder=$('fbDockChat');}else this.holder=document.body;this.parent._init(b);this.popoutWidth=this.defWidth;this.popoutHeight=this.defHeight;this.popoutClicked=false;this.popinClicked=false;if(this.inPopoutWindow){Util.fallbackErrorHandler=null;onbeforeunloadRegister(this.popin.bind(this,false));onunloadRegister(this.popin.bind(this,false));}if(this.inPopoutWindow){Event.listen(window,'resize',this._windowOnResize.bind(this));Event.listen(window,'keypress',this._documentKeyPress.bind(this));}var c=ua.safari();this.isSafari2=(c&&c<500);this.isOpera=(ua.opera()>0);var a=ua.firefox();this.isFF2=(a&&a<3);this.isWindows=ua.windows();if(this.inPopoutWindow){this._windowOnResize.bind(this).defer();setTimeout(this._windowOnResize.bind(this),3000);}},_load:function(a){this.parent._load(a);if(this.poppedOut){if(!this.inPopoutWindow)CSS.addClass(this.holder,'popped_out');}else{if(this.inPopoutWindow)if(this.loaded)if(!this.popinClicked)window.close();CSS.removeClass(this.holder,'popped_out');}if(this.inPopoutWindow){this._handleResize.bind(this,0,0).defer();setTimeout(this._handleResize.bind(this,0,0),100);}this.parent._loaded();},_loaded:bagofholding,_handleMsg:function(a,b){this.parent._handleMsg(a,b);if(typeof b=='string'||!b.type)return;if(this.isShutdown)return false;if(b.type=='app_msg')if(b.event_name=='beep_event'){Bootloader.loadComponents('beeper',function(){Beeper.ensureInitialized();LiveMessageReceiver.route(b);});}else LiveMessageReceiver.route(b);},popout:function(){if(this.inPopoutWindow||this.poppedOut){this.popin(true);return;}if(this.popoutClicked)return;this.popoutClicked=true;var a=window.open(this.popoutURL,"fbChatWindow","status=0,toolbar=0,location=0,menubar=0,"+"directories=0,resizable=1,scrollbars=0,"+"width="+this.popoutWidth+",height="+this.popoutHeight+","+"left="+this.defX+",top="+this.defY);CSS.removeClass(this.holder,'popped_out');this.poppedOut=true;this.justPoppedOut=true;this.popoutTime=(new Date()).getTime();this.doSync();this.popoutClicked=false;},popin:function(a){if(typeof a=='undefined')a=true;if(this.inPopoutWindow){if(this.popinClicked)return;this.popinClicked=true;}this.poppedOut=false;this.doSync();if(this.inPopoutWindow&&a)window.close();},_windowOnResize:function(){if(!this.inPopoutWindow)return;this.contentResized={};var a=Vector2.getViewportDimensions();this._handleResize(a.x-this.virtPopoutWidth,a.y-this.virtPopoutHeight);if(this.inPopoutWindow)this.popoutHeight=a.y;},_handleResize:function(b,c){var a=this.loaded?100:10;if(this.handleResizeTimer)clearTimeout(this.handleResizeTimer);this.handleResizeTimer=setTimeout(function(){this.virtPopoutWidth+=b;this.virtPopoutHeight+=c;this.popoutWidth=Math.max(this.virtPopoutWidth,this.minWidth);this.popoutHeight=Math.max(this.virtPopoutHeight,this.minHeight);Arbiter.inform(PresenceMessage.WINDOW_RESIZED,{sender:this});},a);},_documentKeyPress:function(a){if(!this.inPopoutWindow)return;a=$E(a);var b=a?a.keyCode:-1;if(b==KEYS.ESC)Event.kill(a);},renderLink:function(b,c,a){return '<a href="'+b+'"'+(this.inPopoutWindow?' target="_blank"':'')+(a?a:'')+'>'+c+'</a>';},_shutdown:function(c,d,b){this.parent._shutdown(c,d,b);if((!this.isShuttingDown&&d===this.shutdownTime)||(d&&this.isShutdown))return;if(!this.inPopoutWindow){if(Chat.isOnline())CSS.addClass(this.holder,'presence_error');var a=$('fbChatErrorNub');TooltipLink.setTooltipText(DOM.find(a,'a.fbNubButton'),c);}else{if(this.shutdownErrorDialog)this.shutdownErrorDialog.hide();this.shutdownErrorDialog=ErrorDialog.show(_tx("Error del chat de Facebook"),c);}},_restart:function(a){this.parent._restart(a);if(!this.isRestarting||(a&&a!=this.shutdownTime))return;if(!this.inPopoutWindow){CSS.removeClass(this.holder,'presence_error');}else if(this.shutdownErrorDialog)this.shutdownErrorDialog.hide();},isOnline:function(){return this.state&&this.state.vis;}};function getFirstName(c){var d=c.split(" ");var b=d[0];var a=b.length;if(typeof d[1]!='undefined'&&(a==1||(a==2&&b.indexOf('.')!=-1)||(a==3&&b.toLowerCase()=='the')))b+=' '+d[1];return b;}
function LiveMessageReceiver(a){this.eventName=a;this.subs=null;this.handler=bagofholding;this.shutdownHandler=null;this.restartHandler=null;this.registered=false;this.appId=1;}LiveMessageReceiver.prototype.setAppId=function(a){this.appId=a;return this;};LiveMessageReceiver.prototype.setHandler=function(a){this.handler=a;this._dirty();return this;};LiveMessageReceiver.prototype.setRestartHandler=function(a){this.restartHandler=a.shield();this._dirty();return this;};LiveMessageReceiver.prototype.setShutdownHandler=function(a){this.shutdownHandler=a.shield();this._dirty();return this;};LiveMessageReceiver.prototype._dirty=function(){if(this.registered){this.unregister();this.register();}};LiveMessageReceiver.prototype.register=function(){var b=function(d,c){return this.handler(c);}.bind(this);var a=PresenceMessage.getAppMessageType(this.appId,this.eventName);this.subs={};this.subs.main=Arbiter.subscribe(a,b);if(this.shutdownHandler)this.subs.shut=Arbiter.subscribe(PresenceMessage.SHUTDOWN,this.shutdownHandler);if(this.restartHandler)this.subs.restart=Arbiter.subscribe(PresenceMessage.RESTARTED,this.restartHandler);this.registered=true;return this;};LiveMessageReceiver.prototype.unregister=function(){if(!this.subs)return this;for(var a in this.subs)if(this.subs[a])Arbiter.unsubscribe(this.subs[a]);this.subs=null;this.registered=false;return this;};LiveMessageReceiver.route=function(b){var a=function(c){var d=PresenceMessage.getAppMessageType(b.app_id,b.event_name);Arbiter.inform(d,c,Arbiter.BEHAVIOR_PERSISTENT);};if(b.hasCapture){new AsyncRequest().setHandler(function(c){a(c.getPayload());}).setAllowCrossPageTransition(true).handleResponse(b.response);}else a(b.response);};
function BuddyListDataSource(a){this.parent.construct(this,copy_properties(a,{maxResults:a.maxResults||Infinity,persistOnRefresh:a.persistOnRefresh||true}));}BuddyListDataSource.extend('DataSource');BuddyListDataSource.prototype={init:function(){this.parent.init();OrderedFriendsList.subscribe('initialized',function(){var a=Arbiter.subscribe(['buddylist/initialized','buddylist/availability-changed'],this._update.shield(this));if(!this.persistOnRefresh)onleaveRegister(function(){Arbiter.unsubscribe(a);});}.bind(this));},bootstrap:function(){this.parent.bootstrap();if(this.showOfflineUsers)OrderedFriendsList.subscribe('initialized',function(){ChatUserInfoManager.fetchAll();this.inform('activity',{activity:true});var a=ChatUserInfoManager.subscribe('updated',function(){this.inform('activity',{activity:false});this._update();}.bind(this));if(!this.persistOnRefresh)onleaveRegister(function(){ChatUserInfoManager.unsubscribe(a);});}.bind(this));},_update:function(){var d=this.value;var b=this.flatValue;this.dirty();var c=keys(ChatUserInfos);c.sort(OrderedFriendsList.compare);var a=[];c.forEach(function(f){if(f==Env.user)return;var e=AvailableList.get(f);if(!this.showOfflineUsers&&e===AvailableList.OFFLINE)return;var g=ChatUserInfos[f];a.push({uid:f,text:g.name,photo:g.thumbSrc,availability:e});}.bind(this));if(a.length)this.addEntries(a);if(d){this.respond(d,this.buildUids(b),true);this.value=d;this.flatValue=b;}},refreshData:function(){AvailableList.update();},setMaxResults:function(a){this.maxResults=this.numResults=a;if(this.value)this.respond(this.value,this.buildUids(this.flatValue),true);}};
add_properties('TypeaheadRenderers',{buddylist:function(b,d){var f=htmlize(b.text),e=b.photo,c=[];if(e)c=['<img src="',e,'" alt="" />'];var a='offline';switch(b.availability){case AvailableList.ACTIVE:a='active';break;case AvailableList.IDLE:a='idle';break;}return ['<li class="clearfix ',a,'">',c.join(''),'<span class="text">'+f+'</span>','<i class="'+a+'">','</i>','</li>'];}});
add_properties('TypeaheadBehaviors',{chatBuddyList:function(c){var a=c.getElement();var b=c.getView().getElement();c.subscribe('focus',function(){c.getData().refreshData();});c.subscribe('respond',function(d,e){if(e.value&&!e.results.length){var f=$N('div',{className:'noResults'},_tx("Este amigo no se encuentra en el chat."));DOM.setContent(b,f);}CSS.show(b);CSS.addClass(a,'respond');});c.subscribe('reset',function(){CSS.hide(b);CSS.removeClass(a,'respond');});c.subscribe('select',function(d,e){Chat.openTab(e.selected.uid,e.selected.text);});c.subscribe('highlight',function(d,f){if(f.index>=0){var i=c.getView().getItems()[f.index];if(i){var h=Rect(i);var e=i.offsetParent;var g=h.boundWithin(Rect(e)).getPositionVector();h.getPositionVector().sub(g).scrollElementBy(e);}}});}});
var ChatOnlineFriends=window.ChatOnlineFriends||{chatFriends:{},chatStatuses:['chatOnline','chatIdle','chatOffline'],_subscribe:function(event,a){this._tokens.push(Arbiter.subscribe(event,a));},clickHandler:function(event){var c=event.getTarget();var b=Parent.byClass(c,'uiListItem');if(b){var a=this.chatFriends[b.id];if(Chat.isOnline()){Chat.openTab(a.user_id,a.name,'friend');}else goURI(a.uri);return false;}},onunload:function(){this._tokens.forEach(function(a){Arbiter.unsubscribe(a);});},_setStatus:function(a,b){if(CSS.hasClass(a,b))return;this.chatStatuses.forEach(function(c){CSS.conditionClass(a,c,c==b);});},initTypeahead:function(b,a){b.subscribe('reset',function(){CSS.show(a);});b.subscribe('query',function(c,d){if(d.value){CSS.hide(a);}else CSS.show(a);});},init:function(d,e,a,c,b){this._initShared(d,e,a,b);this._facepile=c.firstChild;this._faceFutures&&this._hideAllFaces();this._faceFutures=[];OrderedFriendsList.subscribe('initialized',function(){this._orderedFriends=OrderedFriendsList.getList();this._hashedFriends=Object.from(this._orderedFriends);this._subscribe(['buddylist/initialized','buddylist/availability-changed'],this.update.shield(this));}.bind(this));Event.listen(c,'click',this.clickHandlerClientRendering.bind(this));AvailableList.update();},_initShared:function(c,d,a,b){this.maxElements=c;this._faceTmpl=b;this._tokens=[];onleaveRegister(this.onunload.bind(this));this.initTypeahead(d,DOM.find(a,'div.fbFriendsOnlineFacepile'));},update:function(){var g=ge('chatFriendsOnline');if(g)CSS.conditionClass(g,'isOffline',!Chat.isOnline());if(!Chat.isOnline()||!AvailableList.isReady())return;AvailableList.getAvailableIDs().forEach(function(h){if(!this._hashedFriends[h]){this._orderedFriends.push(h);this._hashedFriends[h]=true;}}.bind(this));var b=0;for(var e=0;e<this._orderedFriends.length;e++){var d=this._orderedFriends[e];var a=AvailableList.get(d);var c=this._faceFutures[e];var f=b<this.maxElements;if(a&&f){if(!c){c=this._makeFace(e);this._faceFutures[e]=c;}b++;}this._updateFace(c,f,this._mapChatStatus(a));}},_mapChatStatus:function(a){switch(a){case AvailableList.OFFLINE:return 'chatOffline';case AvailableList.IDLE:return 'chatIdle';case AvailableList.ACTIVE:return 'chatOnline';}},_updateFace:function(b,c,a){b&&b(function(d){this._setStatus(d,a);CSS.conditionShow(d,c);}.bind(this));},_makeFace:function(c){var d=null;var a=null;var b=this._orderedFriends[c];ChatUserInfoManager.get(b,function(j){a=this._faceTmpl.render();DataStore.set(a,'friendID',b);var i=XHPTemplate.getNode(a,'img');var k=i.cloneNode(false);k.setAttribute('src',j.thumbSrc);DOM.replace(i,k);var e=XHPTemplate.getNode(a,'anchor');TooltipLink.setTooltipText(e,j.name);d&&d(a);var f=false;for(var h=c+1;h<this._orderedFriends.length&&!f;h++){var g=this._faceFutures[h];var l=g&&g();if(l){this._facepile.insertBefore(a,l);f=true;}}if(!f)this._facepile.appendChild(a);}.bind(this));return function faceFuture(e){if(e)if(a){e(a);}else d=e;return a;};},clickHandlerClientRendering:function(event){var c=event.getTarget();var a=Parent.byClass(c,'uiFacepileItem');if(a){var b=DataStore.get(a,'friendID');if(b&&Chat.isOnline()){ChatUserInfoManager.get(b,function(d){Chat.openTab(b,d.name,'friend');});return false;}}},_hideAllFaces:function(){this._faceFutures.forEach(function(a){a&&a(function(b){DOM.remove(b);});});}};
