/*=======================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.5.2
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2019 MH Sub I, LLC dba vBulletin. All Rights Reserved.  # ||
|| # This file may not be redistributed in whole or significant part.   # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html   # ||
|| ###################################################################### ||
\*========================================================================*/
function vB_Facebook(A){this.config=A;this.loginperms={scope:"public_profile,email"};FB.Event.subscribe("auth.statusChange",function(B){if(B.status=="connected"){$(document).trigger("facebookinitialized");FB.Event.unsubscribe("auth.statusChange",arguments.callee)}});FB.init({appId:this.get_config("appid"),version:"v2.8",status:true,cookie:true,xfbml:true});this.register_loginbtns();this.make_visible();$("#lnkFacebookDisconnectSettings").off("click").on("click",this.do_disconnect);$("#lnkFacebookLoginSettings").off("click").on("click",this.makeAuthEvent(this.do_connect))}vB_Facebook.prototype.get_config=function(A){if(typeof (this.config)=="undefined"||typeof (this.config[A])=="undefined"){return false}else{return this.config[A]}};vB_Facebook.prototype.register_loginbtns=function(){var D=this.makeAuthEvent(this.do_login);$("#lnkFacebookLogin").click(D);$("#fb_getconnected").click(D);$("#fb_regloginbtn").click(function(G){G.preventDefault();FB.login(vBfb.reload,vBfb.loginperms)});var B=$("#facebookusername"),E=$("#facebookpassword"),A=$("#facebookassociate"),F=this.makeAuthEvent(this.login_and_associate),C=function(G){if(G.which==13){F(G)}};if(B.length&&E.length&&A.length){A.click($.proxy(function(){F()},this));B.keypress(C);E.keypress(C)}};vB_Facebook.prototype.make_visible=function(){$("#fb_headerbox").removeClass("hidden");$("#fbregbox").removeClass("hidden")};vB_Facebook.prototype.do_login=function(A){vBulletin.AJAX({call:"/auth/loginExternal",data:{provider:"facebook",auth:A.accessToken},success:vBfb.reload,api_error:function(B){if(vBulletin.ajaxtools.hasError(B,"error_external_no_vb_user")){window.top.location="register";return false}return true}})};vB_Facebook.prototype.do_connect=function(A){vBulletin.AJAX({call:"/ajax/api/facebook/connectCurrentUser",data:{accessToken:A.accessToken},success:vBfb.reload})};vB_Facebook.prototype.do_disconnect=function(){vBulletin.AJAX({call:"/ajax/api/facebook/disconnectUser",data:{userid:pageData.userid},success:vBfb.reload})};vB_Facebook.prototype.login_and_associate=function(A){var C=$("#facebookusername").get(0).value;var B=$("#facebookpassword").get(0).value;vBulletin.AJAX({call:"/auth/loginAndAssociate",data:{username:C,vb_login_md5password:hex_md5(str_to_ent(trim(B))),vb_login_md5password_utf:hex_md5(trim(B)),auth:A.accessToken},success:function(D,E,F){window.top.location=D.redirect}})};vB_Facebook.prototype.reload=function(){window.top.location.reload(true)};vB_Facebook.prototype.makeAuthEvent=function(A){return function(C){if(C){C.preventDefault()}var B=FB.getAuthResponse();if(B&&B.accessToken){A(B)}else{FB.login(function(D){if(D.authResponse&&D.authResponse.accessToken){A(D.authResponse)}},vBfb.loginperms)}return false}};vB_Facebook.prototype.register_logout=function(){FB.logout(vBfb.reload)};vB_Facebook.prototype.handle_submit_override=function(){if(typeof (this.onSubmitEvent)=="undefined"||!this.onSubmitEvent||this.onSubmitEvent.call(this.editFormEl)){var A=document.createElement("input");A.setAttribute("type","hidden");A.setAttribute("name",this.btnClicked.name);A.setAttribute("value",this.btnClicked.value);this.editFormEl.appendChild(A);this.editFormEl.submit()}};vB_Facebook.prototype.has_permission=function(A,B){FB.api("/me/permissions/"+A,function(C){B(C&&!C.error&&C.data.length&&C.data[0].status=="granted")})};vB_Facebook.prototype.request_permission=function(A,B){FB.login(function(C){var D=false;if(typeof (C.authResponse.grantedScopes)!="undefined"){D=jQuery.inArray(A,C.authResponse.grantedScopes.split(","))>-1}B(D)},{scope:A,auth_type:"rerequest",return_scopes:true})};vB_Facebook.prototype.isFbLogin=function(){return !!$.cookie("fbsr_"+this.get_config("appid"))};window.vBulletin=window.vBulletin||{};window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["enablefacebookconnect","facebookappid","facebookactive","facebookautoregister"]);window.fbAsyncInit=function(){$(document).ready(function(){if(window.vBulletin.options.get("facebookactive")){vBfb=new vB_Facebook({appid:window.vBulletin.options.get("facebookappid"),connected:0,active:0,autoreg:window.vBulletin.options.get("facebookautoregister")});$(".js-external-login-providers").removeClass("h-hide-imp");$(".js-external-login-provider--facebook").removeClass("h-hide-imp")}else{$(".js-external-login-provider--facebook").addClass("h-hide-imp");if($(".js-external-login-provider:visible").length<1){$(".js-external-login-providers").addClass("h-hide-imp")}}$(document).on("click",".js-fb-share-dialog",function(E){if(window.vBulletin.options.get("facebookactive")){var D=$(this).data("url-not-encoded");FB.ui({method:"share",mobile_iframe:true,href:D,},function(F){})}else{var B=$(this).prop("href"),C="width=573,height=239,resizable=yes,scrollbars=yes,status=yes",A=window.open(B,"_blank",C);if(!A||A.closed||typeof A.closed=="undefined"){return true}}return false});$(document).on("click",".js-twitter-share",function(D){var B=$(this).prop("href"),C="width=548,height=419,resizable=yes,scrollbars=yes,status=yes",A=window.open(B,"_blank",C);if(!A||A.closed||typeof A.closed=="undefined"){return true}return false})})};(function(C){var B,E="facebook-jssdk",A=C.getElementsByTagName("script")[0],D=$("#fb-root").data("facebook-language");if(C.getElementById(E)){return }B=C.createElement("script");B.id=E;B.async=true;B.src="//connect.facebook.net/"+D+"/sdk.js#xfbml=1&version=v2.8";A.parentNode.insertBefore(B,A)}(document));