/*=======================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.4.2
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2018 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   # ||
|| ###################################################################### ||
\*========================================================================*/
window.vBulletin=window.vBulletin||{};window.vBulletin.phrase=window.vBulletin.phrase||{};window.vBulletin.phrase.precache=window.vBulletin.phrase.precache||[];window.vBulletin.phrase.precache=$.merge(window.vBulletin.phrase.precache,["follow","following","following_pending"]);window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,[]);(function(){vBulletin.subscribe={};var B=function(I){var L=$(I);if(L.hasClass("isSubscribed")||L.hasClass("is-pending")){return true}var N=parseInt(L.attr("data-node-id"),10),M={},J="";if(L.hasClass("is-topic")){J="/ajax/api/follow/add";M.follow_item=N;M.type="follow_contents";D(L,J,M)}else{var K={};K.channelid=N;K.recipient=parseInt(L.attr("data-owner-id"),10);if(L.hasClass("is-blog-channel")){K.requestType="member"}else{if(L.hasClass("is-sg-channel")){K.requestType="sg_subscriber"}else{K.requestType="subscriber"}}D(L,"/ajax/api/node/requestChannel",K)}};var G=function(I,J){I.children(".js-button__text-primary").text(vBulletin.phrase.get(J))};var A=function(K,L,J,I){G(K,L);K.addClass((J||"")+" b-button--special").removeClass((I||"")+" b-button--secondary")};var H=function(K,L,J,I){G(K,L);K.addClass((J||"")+" b-button--secondary").removeClass((I||"")+" b-button--special")};var D=function(J,I,K){vBulletin.AJAX({call:I,data:K,success:function(L){if(!isNaN(L)&&L>=1){if(L==1){A(J,"following","isSubscribed")}else{A(J,"following_pending","is-pending")}}else{vBulletin.error("follow","follow_error")}},title_phrase:"follow",error_phrase:"follow_error"})};var F=function(I){var K=$(I),L=parseInt(K.attr("data-node-id"),10),J=parseInt(K.attr("data-owner-id"),10);vBulletin.AJAX({call:"/ajax/api/node/requestChannel",data:({channelid:L,recipient:J,requestType:"sg_member"}),success:function(M){if(M===true){A(K,"joined","has-joined");if(K.hasClass("join-to-post-btn")||K.hasClass("js-refresh")){window.location.reload()}}else{if(!isNaN(M)){A(K,"following_pending","is-pending")}}},title_phrase:"join",error_phrase:"join_error"})};var C=function(I){var J=$(I),K=parseInt($(I).attr("data-node-id"),10);vBulletin.AJAX({call:"/ajax/api/blog/leaveChannel",data:{channelId:K},success:function(L){if(L===true){if(J.hasClass("js-button--follow")){G(J,"follow");J.addClass("b-button--special").removeClass("isSubscribed b-button--unfollow")}else{G(J,"join");J.removeClass("has-joined b-button--special")}location.reload()}else{vBulletin.error("leave","invalid_server_response_please_try_again")}},title_phrase:"leave",error_phrase:"invalid_server_response_please_try_again"})};var E=function(I){var J=$(I),K=$(I).attr("data-node-id");vBulletin.AJAX({call:"/ajax/api/follow/delete",data:{follow_item:K,type:"follow_contents"},success:function(L){if(L==1){H(J,"follow","","isSubscribed b-button--unfollow")}else{vBulletin.error("follow","unfollow_error")}},title_phrase:"follow",error_phrase:"unfollow_error"})};vBulletin.subscribe.removeUnsubscribeOptions=function(M,J){var L=$(M).parents(".unsubscribe-overlay"),N=parseInt(L.attr("data-node-id"),10),K=$(L).children(".unsubscribe-options"),I=[];if(typeof N!="number"){return false}var O="li :checkbox[name=unsubscribeItems]";if(!(($(K).find("li #"+N+"-unsubscribeAll:checkbox:checked")).length===1)){O+=":checked"}$.each($(K).find(O),function(P,S){var Q=$(S).attr("data-type"),R=parseInt($(S).attr("data-item-id"),10);if(R&&typeof R=="number"){I.push({type:Q,itemId:R})}});if(I.length>0){vBulletin.AJAX({call:"/ajax/api/follow/unsubscribeItems",data:{unsubscribeItems:I},success:function(P){if(P===true){$(L).dialog("close").remove();J.updatePageNumber(1).applyFilters(false)}},title_phrase:"profile_guser",error_phrase:"unable_to_contact_server_please_try_again"})}else{vBulletin.error("profile_guser","unsubscribe_overlay_error")}};vBulletin.subscribe.updateSubscribeButton=function(J){if(typeof J!="undefined"){var I=$(".js-button--follow").filter(function(){return $(this).data("node-id")==pageData.nodeid&&pageData.nodeid!=pageData.channelid});switch(J){case 0:H(I,"follow","","isSubscribed b-button--unfollow");break;case 1:H(I,"following","isSubscribed");break;case 2:H(I,"following_pending","is-pending");break}}};$(".js-button--follow").on("click",function(I){if(!$(this).hasClass("isSubscribed")){B(this)}else{if($(this).hasClass("b-button--unfollow")){if($(this).hasClass("is-blog-channel")){C(this)}else{E(this)}}}});$(".js-button--follow").on("mouseover",function(I){var J=$(this);if(J.hasClass("isSubscribed")&&!J.hasClass("is-owner")){H(J,"following_remove","b-button--unfollow")}});$(".js-button--follow").on("mouseout",function(I){var J=$(this);if(J.hasClass("b-button--unfollow")){A(J,"following","","b-button--unfollow")}});$(".join-to-post-btn").on("click",function(I){if(!$(this).hasClass("has-joined")&&!$(this).hasClass("is-pending")){F(this)}});$(".join-btn").on("click",function(I){if(!$(this).hasClass("has-joined")&&!$(this).hasClass("is-pending")){F(this)}else{if($(this).hasClass("leave-btn")&&!$(this).hasClass("is-owner")){C(this)}}});$(".join-btn").on("mouseover",function(I){var J=$(this);if(J.hasClass("has-joined")&&!J.hasClass("is-owner")){H(J,"leave","leave-btn")}});$(".join-btn").on("mouseout",function(I){var J=$(this);if(J.hasClass("leave-btn")&&!J.hasClass("is-owner")){A(J,"joined","","leave-btn")}})})();