﻿
Type.registerNamespace("PlainJoeStudios.Web.Controls");PlainJoeStudios.Web.Controls.Facebook=function(args){return this.ctor(args);};PlainJoeStudios.Web.Controls.Facebook.prototype={TermsOfServiceParentClass:"jqTermsOfServiceParent",TermsOfServiceButtonAgreeClass:"jqBtnAgree",TermsOfServiceButtonCancelClass:"jqBtnCancel",_ApiKey:null,_XdReceiver:"/xd_receiver.htm",_arr_fnLoggedInListeners:null,_arr_fnStatusUpdateListeners:null,_arr_fnApiReadyListeners:null,_UserDetails:null,_UserSession:null,_UserFriends:null,_FunctionQueue:null,_bIsApiReady:false,_bIsLoggedIn:false,_bIsLoggedInWebServiceComplete:false,ctor:function(args){var This=this;if(window.g_Facebook){return window.g_Facebook;}
this._FunctionQueue=new PlainJoeStudios.Web.FunctionQueue();this._ApiKey=args.ApiKey;this._arr_fnLoggedInListeners=[];this._arr_fnStatusUpdateListeners=[];this._arr_fnApiReadyListeners=[];$(function(){window.setTimeout(function(){FB_RequireFeatures(["Base","Common","XdComm","Api","Connect","XFBML"],function(){FB.init(This._ApiKey,This._XdReceiver,{ifUserConnected:function(){window.setTimeout(function(){This.OnLoggedIn();},1);},ifUserNotConnected:function(){This.OnLoggedOut();},doNotUseCachedConnectState:true});This._bIsApiReady=true;for(var ii=0;ii<This._arr_fnApiReadyListeners.length;++ii){This._arr_fnApiReadyListeners[ii]();}
This._arr_fnApiReadyListeners=null;This._FunctionQueue.Run();});},1);});window.g_Facebook=This;},IsApiReady:function(){return this._bIsApiReady;},LogOut:function(){this._FunctionQueue.Run(function(){FB.Connect.logout(function(bWasLoggedIn){if(!bWasLoggedIn){window.setTimeout(function(){$PJP.RedirectToSelf();},1000);}});});},GetUser:function(){return this._UserDetails;},GetUserId:function(){if(this._UserDetails!==null){return this._UserDetails.uid||null;}
else{return null;}},GetUserFriends:function(){return this._UserFriends;},AttachListenerApiReady:function(fn){if(typeof(fn)!=="function"){throw new Error("Expected a function object.");}
if(this._bIsApiReady){fn();}
else{this._arr_fnApiReadyListeners.push(fn);}},AttachListenerLoggedIn:function(fn,bWaitForWebServiceComplete){if(typeof(fn)!=="function"){throw new Error("Expected a function object.");}
bWaitForWebServiceComplete=bWaitForWebServiceComplete||false;if(this._bIsLoggedIn&&!bWaitForWebServiceComplete){fn();}
if(this._bIsLoggedInWebServiceComplete){fn();}
this._arr_fnLoggedInListeners.push({"fn":fn,"bWaitForWebServiceComplete":bWaitForWebServiceComplete});},RemoveListenerLoggedIn:function(fn){if(this._arr_fnLoggedInListeners!=null){for(var j=0;j<this._arr_fnLoggedInListeners.length;++j){if(this._arr_fnLoggedInListeners[j].fn===fn){this._arr_fnLoggedInListeners[j]=null;break;}}}},AttachListenerStatusUpdate:function(fn){if(typeof(fn)!=="function"){throw new Error("Expected a function object.");}
this._arr_fnStatusUpdateListeners.push(fn);},RemoveListenerStatusUpdate:function(fn){if(this._arr_fnStatusUpdateListeners!=null){for(var j=0;j<this._arr_fnStatusUpdateListeners.length;++j){if(this._arr_fnStatusUpdateListeners[j]===fn){this._arr_fnStatusUpdateListeners[j]=null;break;}}}},SendStatusUpdate:function(message,oExtraData){var This=this;message=message.replace(/\n|\r/g,' ');var SendStatusUpdate=function(m){FB.Facebook.apiClient.users_setStatus(m,false,true,function(result,exception){for(var k=0;k<This._arr_fnStatusUpdateListeners.length;++k){var fn=This._arr_fnStatusUpdateListeners[k];if(fn!=null){fn(m,oExtraData);}}});};FB.Facebook.apiClient.users_hasAppPermission("status_update",function(result,exception){if(result!=true){FB.Connect.showPermissionDialog("status_update",function(r){if(r){SendStatusUpdate(message);}});}
else{SendStatusUpdate(message);}});},GetPageIdFromUrl:function(strPageUrl,fnCallback){},RetrieveUserProfileAndFireCallbacks:function(iUserId){var This=this;FB.Facebook.apiClient.users_getInfo([iUserId],["name","first_name","last_name","status","locale","current_location","hometown_location","affiliations","pic_square","profile_url"],function(result){if(result!=null&&result.length>0){This._UserDetails=result[0];PlainJoeStudios.Web.Services.Facebook.UserLoggedIn(This._UserDetails,function(r){$PJP.LogUserInFromFacebook(result[0]);This._bIsLoggedInWebServiceComplete=true;for(var j=0;j<This._arr_fnLoggedInListeners.length;++j){var oListener=This._arr_fnLoggedInListeners[j];if(oListener!=null&&oListener.bWaitForWebServiceComplete===true){oListener.fn();}}},function(r){});for(var j=0;j<This._arr_fnLoggedInListeners.length;++j){var oListener=This._arr_fnLoggedInListeners[j];if(oListener!=null&&oListener.bWaitForWebServiceComplete===false){oListener.fn();}}}});},RetrieveUserFriends:function(){var This=this;FB.Facebook.apiClient.friends_get(null,function(result){This._UserFriends=result;});},OnLoggedIn:function(){var This=this;this._bIsLoggedIn=true;var fbSession=FB.Facebook.apiClient.get_session();if(fbSession==null){return;}
var userId=fbSession.uid;var D8ADK=arguments||{};var fnSaveAndContinue=function(){This._UserSession=fbSession;This.RetrieveUserProfileAndFireCallbacks(userId);This.RetrieveUserFriends();};fnSaveAndContinue();},OnLoggedOut:function(){this._bIsLoggedIn=false;if(this._UserDetails){this._UserDetails=null;g_PlainJoePage.RedirectToSelf();}}};