/*=======================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.1.9 Patch Level 4
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2016 vBulletin Solutions Inc. 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=this.get_config("autoreg")?{scope:"public_profile,email"}:{scope:"public_profile,email,publish_actions,user_about_me,user_birthday,user_location,user_work_history"};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.2",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:{error_external_no_vb_user:function(){window.top.location="register"}}})};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){B(jQuery.inArray(A,C.authResponse.grantedScopes.split(","))>-1)},{scope:A,auth_type:"rerequest",return_scopes:true})};window.vBulletin=window.vBulletin||{};window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["enablefacebookconnect","facebookappid","facebookactive","facebookautoregister","fbfeednewthread","fbfeedpostreply","fbfeedblogentry","fbfeedblogcomment","fbfeednewarticle","fbfeedarticlecomment"]);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"),feed_newthread:window.vBulletin.options.get("fbfeednewthread"),feed_postreply:window.vBulletin.options.get("fbfeedpostreply"),feed_blogentry:window.vBulletin.options.get("fbfeedblogentry"),feed_blogcomment:window.vBulletin.options.get("fbfeedblogcomment"),feed_newarticle:window.vBulletin.options.get("fbfeednewarticle"),feed_articlecomment:window.vBulletin.options.get("fbfeedarticlecomment")});$("#externalLoginProviders").parent().addClass("externalLoginEnabled")}else{$("#lnkFacebookLogin").hide()}})};(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";A.parentNode.insertBefore(B,A)}(document));