/*=======================================================================*\
|| ###################################################################### ||
|| # 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   # ||
|| ###################################################################### ||
\*========================================================================*/
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,["aim","email_addresses_must_match","google_talk_im","icq","passwords_must_match","please_add_signature","signature","signature_saved","skype","usersetting_signatures_link","usersetting_signature_errorsaving","yahoo_im","end_subscription","end_subscription_confirm","cancel"]);window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["ctMaxChars"]);(function(C){window.vBulletin=window.vBulletin||{};var D=[".profile-settings-widget"];if(!vBulletin.pageHasSelectors(D)){return false}var A="usersettings";vBulletin.usersettings=vBulletin.usersettings||{};vBulletin.usersettings.signature;vBulletin.usersettings.updatePreview=function(E){C.ajax({url:vBulletin.getAjaxBaseurl()+"/profile/previewSignature",type:"POST",data:{signature:E},dataType:"json",success:function(F){if(F){if(F.errors){openAlertDialog({title:vBulletin.phrase.get("usersetting_signatures_link"),message:vBulletin.phrase.get("usersetting_signature_errorsaving")+": "+vBulletin.phrase.get(F.errors[0]),iconType:"error"});C(".list-item[data-node-id="+nodeid+"] .voteCtrl").removeClass("h-disabled")}else{C(".js-signature__preview").html(F).slideDown()}}},complete:function(){C("body").css("cursor","default")}})};var B;vBulletin.usersettings.init=function(){C(".js-signature__edit").off("click").on("click",function(E){E.preventDefault();C("#editSignatureDialog").dialog({title:vBulletin.phrase.get("usersetting_signatures_link"),autoOpen:false,modal:true,resizable:false,closeOnEscape:false,showCloseButton:false,width:500,dialogClass:"signature-dialog-container dialog-container dialog-box",create:function(){var F=C(this),G=C(".js-editor",F);vBulletin.ckeditor.initEditor(G,{success:function(I){var H=vBulletin.ckeditor.getEditor(I);H.setData(G.prev(".js-editor-parsed-text").html(),function(){H.resetDirty()});F.on("dialogopen",function(){H.setData(C(".js-signature__preview").html(),function(){H.resetDirty()})})},error:function(){G.val(G.prev(".js-editor-parsed-text").html().replace(/<br\s*[\/]?>/gi,"\n")).data("orig-value",G.val());F.on("dialogopen",function(){G.val(C(".js-signature__preview").html().replace(/<br\s*[\/]?>/gi,"\n")).data("orig-value",G.val())})},hideLoadingDialog:true});C(".js-signature__cancel",F).off("click").on("click",function(H){var I=vBulletin.ckeditor.editorExists(G)?vBulletin.ckeditor.getEditor(G).checkDirty():G.val()!=G.data("orig-value");if(I){openConfirmDialog({title:vBulletin.phrase.get("cancel_edit"),message:vBulletin.phrase.get("all_changes_made_will_be_lost_would_you_like_to_continue"),iconType:"warning",onClickYes:function(){F.dialog("close")}})}else{F.dialog("close")}});C(".js-signature__submit",F).off("click").on("click",function(J){J.preventDefault();var H=vBulletin.ckeditor.editorExists(G)?vBulletin.ckeditor.getEditor(G).getData():G.val();if(!C.trim(H)){openAlertDialog({title:vBulletin.phrase.get("signature"),message:vBulletin.phrase.get("please_add_signature"),iconType:"warning",onAfterClose:function(){vBulletin.ckeditor.editorExists(G)?vBulletin.ckeditor.getEditor(G).focus():G.focus()}});return false}var I=[];C('input[name|="filedataids[]"]',F).each(function(){I.push(C(this).val())});C.ajax({url:this.form.action,type:this.form.method,data:{signature:H,filedataids:I},dataType:"json",success:function(K){if(K){if(K.errors){openAlertDialog({title:vBulletin.phrase.get("signature"),message:vBulletin.phrase.get("error_saving_signature")+": "+vBulletin.phrase.get(K.errors[0]),iconType:"error"})}else{C(".js-signature__preview").html(K);openAlertDialog({title:vBulletin.phrase.get("signature"),message:vBulletin.phrase.get("signature_saved")});F.dialog("close")}}},complete:function(){C("body").css("cursor","default")}});return false})}}).dialog("open");return false})};C(document).ready(function(){C(".js-user-settings form").trigger("reset");vBulletin.usersettings.init();C(".b-form-select__select").selectBox();var K=window.vBulletin.options.get("ctMaxChars");C(".js-user-settings__reset").off("click").on("click",resetFormFields);setSelectedOption(C(".js-birth__month"),C("#bd_month"));C(".js-birth__month").selectBox().change(function(){C("#bd_day").val(C(".js-birth__day option:selected").val());updateDaySelectBox(C(".js-birth__day"),C(".js-birth__month").val())});C(".js-birth__year").off("blur").on("blur",function(){C("#bd_day").val(C(".js-birth__day option:selected").val());updateDaySelectBox(C(".js-birth__day"),C(".js-birth__month").val())});C("#profileSettings_form").ajaxForm({dataType:"json",beforeSubmit:function(W,V,U){if(C(".js-user_title").length&&(C(".js-user_title").val().length>K)){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("please_enter_user_title_with_at_least_x_characters",K),iconType:"warning"});return false}return true},success:function(W,X,Y,V){if(W&&W.response&&W.response.errors){var Z=[];for(var U in W.response.errors){if(W.response.errors[U][0]!="exception_trace"&&W.response.errors[U][0]!="errormsg"){Z.push(vBulletin.phrase.get(W.response.errors[U]))}}openAlertDialog({title:vBulletin.phrase.get("error"),message:Z.join("<br />"),iconType:"warning"})}else{window.location.reload(true)}}});createDaySelectBox(C(".js-birth__day"));var P=C(".js-user-settings .b-tabbed-pane__tabs").data("allow-history")==1,L=vBulletin.history.instance(P),R=C(".js-module-top-anchor").attr("id");if(L.isEnabled()){var G=L.getState();if(!G||C.isEmptyObject(G.data)){var O=location.pathname.match(/\/(profile|account|privacy|notifications|subscriptions)\/?$/),Q=(O&&O[1])||"profile",T={from:"tabs",tab:Q};L.setDefaultState(T,document.title,location.href)}L.setStateChange(function(Y){var X=L.getState();if(X.data.from=="tabs"){L.log(X.data,X.title,X.url);var W=B.tabbedPane("getSelectedTab"),V="#"+X.data.tab+"Tab";if(W.children("a").prop("hash")!=V){var U=B.tabbedPane("findTabAnchorByHash",V).data("bypassPushState",true);B.tabbedPane("selectTab",U)}}},"tabs")}B=C(".b-tabbed-pane").tabbedPane({isResponsive:true,callback:function(X,U){if(L.isEnabled()){if(!X.data("bypassPushState")){var V={from:"tabs",tab:X.data("url-path")},W=vBulletin.makeTabUrl(location.href,V.tab,false);L.pushState(V,document.title,W)}}C("select.b-form-select__select").selectBox();X.data("bypassPushState",null)}});if(!L.isEnabled()){B.on("selectTab",function(V,U){location.href=vBulletin.makeTabUrl(location.href,C(U).data("url-path"),false,R);return false})}var I={aim:vBulletin.phrase.get("aim"),google:vBulletin.phrase.get("google_talk_im"),skype:vBulletin.phrase.get("skype"),yahoo:vBulletin.phrase.get("yahoo_im"),icq:vBulletin.phrase.get("icq")};var N=Object.keys(I).length;var E=function(U){var V=0;U.find(".selectBox.js-im").each(function(){var W=C(this).width();if(W>V){V=W}});return V};var H=function(V,U){V.find(".selectBox.js-im").each(function(){var W=C(this);W.width(U);W.find(".selectBox-label").css("width","auto")})};C(document).off("change",".selectBox.js-im").on("change",".selectBox.js-im",function(){$screenNamesContainer=C(this).closest(".js-screen-name__container");var U=E($screenNameContainer);updateProviders($screenNamesContainer,I);H($screenNameContainer,U)});setIMSelectedOption(C("select.js-im"),I);var F="b-icon b-icon__x-circle--light h-margin-horiz-l h-margin-top-xs h-left js-screen-name__remove";C(".js-screen-name__new").off("click").on("click",function(Y){Y.preventDefault();var W=C(this);var Z=C(this).parents(".js-screen-names").find(".js-screen-name__container");var U=Z.find(".js-screen-name").length;var X=E(Z);if(U<N){var V='<div class="h-margin-bottom-xs h-clearfix js-screen-name">';V+='<input type="text" name="user_screennames[]" class="js-user_screenname h-left b-form-input__input h-margin-right-l h-margin-bottom-s" value="" />';V+='<select name="user_im_providers[]" class="js-im--'+U+' js-im b-form-select__select h-left" data-orig-value-class="js-im--'+U+'">';V+=getAvailableIMs(Z,I);V+="</select>";V+='<div class="'+F+'"></div></div>';Z.append(V);Z.find(".js-im--"+U).selectBox();Z.find(".js-user_screenname:last").focus();if(Z.find(".js-screen-name").length>=N){W.hide()}updateProviders(Z,I);H(Z,X)}});C(".js-screen-names").each(function(){$container=C(this);var U=E($container);H($container,U);if($container.find(".selectBox.js-im").length>=N){$container.find(".js-screen-name__new").hide()}});C(document).off("click",".js-screen-name__remove").on("click",".js-screen-name__remove",function(){var V=C(this).parents(".js-screen-name");var X=C(this).closest(".js-screen-names");var W=E(X);var U=V.siblings(".js-screen-name").length;if(U<1){V.find(".js-user_screenname").val("")}else{V.find("select.js-im").selectBox("destroy");V.remove()}updateProviders(X,I);H(X,W);X.find(".js-screen-name__new").show()});C("#new_useremail").off("focus."+A).on("focus."+A,function(U){U.preventDefault();C("#new_email_container").addClass("isActive").slideDown("3000")});C("#user_newpass").off("focus."+A).on("focus."+A,function(U){U.preventDefault();C("#new_pass_container").addClass("isActive").slideDown("3000")});C("#settingsErrorClose").off("click").on("click",function(){C("#settingsErrorDialog").dialog("close")});C("#accountSettings_form").ajaxForm({dataType:"json",beforeSubmit:function(W,U,V){return J()},success:function(W,X,Y,V){if(W&&W.response&&W.response.errors){var Z=[];for(var U in W.response.errors){if(W.response.errors[U][0]!="exception_trace"&&W.response.errors[U][0]!="errormsg"){Z.push(vBulletin.phrase.get(W.response.errors[U]))}}openAlertDialog({title:vBulletin.phrase.get("error"),message:Z.join("<br />"),iconType:"warning"})}else{window.location.reload(true)}}});var J=function(){var U=C("#user_newpass"),b=C("#user_newpass2"),c=U.val(),a=b.val();if(c||a){var Y=C("#user_currentpass");if(Y.val()==""){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("enter_current_password"),iconType:"error",onAfterClose:function(){Y[0].focus()}});return false}if(c!=a){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("passwords_must_match"),iconType:"error",onAfterClose:function(){U[0].focus()}});return false}}else{U.removeAttr("name");b.removeAttr("name")}var Z=C("#new_useremail"),V=C("#new_useremail2"),W=Z.val(),X=V.val();if(W||X){var Y=C("#user_currentpass");if(Y.val()==""){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("enter_current_password"),iconType:"error",onAfterClose:function(){Y[0].focus()}});return false}if(W!=X){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("email_addresses_must_match"),iconType:"error",onAfterClose:function(){Z[0].focus()}});return false}if(!isValidEmailAddress(Z.val())){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("invalid_email_address"),iconType:"error",onAfterClose:function(){Z[0].focus()}});return false}}else{Z.removeAttr("name");V.removeAttr("name")}return true};C("#accountSettings_form input:checkbox[name=enable_pm]").off("change").on("change",function(){if(C(this).prop("checked")){C("#pm_controls :input").prop("disabled",false)}else{C("#pm_controls :input").prop("disabled",true)}});S();function S(){var V=C("#ignorelist_container").val();var U=new vBulletin_Autocomplete(C("#ignorelist_container"),{apiClass:"user",minLength:C("#minuserlength").val(),maxItems:C("#maxitems").val()});if(V){V=V.split(",");C.each(V,function(W,X){X=C.trim(X);U.addElement(X)})}}C("#follower_request").off("change").on("change",function(){if(C(this).attr("checked")=="checked"){C("#general_followrequest").attr("checked",true)}});C("#general_followrequest").off("change").on("change",function(){if(!C(this).prop("checked")){C("#follower_request").prop("checked",false)}});var M=C("#subscriptionsTab");if(M.length>0){C(".js-subscription-cost",M).change(function(){var c=C(this).closest(".js-newsubscription_row"),W=C(this).find("option:selected").first(),Y=W.attr("data-currency"),Z=c.attr("data-id"),V=W.attr("data-subid"),a=C(this).closest(".js-subscriptions_list"),X=C(".js-order_confirm",M),b=C(".js-payment-form",M),U=C.parseJSON(c.attr("data-allowedapis"));C(this).selectBox("value","");C('<tr class="confirm_data"><td>'+W.attr("data-subtitle")+"</td><td>"+W.attr("data-duration")+"</td><td>"+W.attr("data-value")+"</td></tr>").appendTo(C(".js-order_confirm_table",X));a.addClass("h-hide");X.off("click",".js-subscription__remove").on("click",".js-subscription__remove",function(){C(".confirm_data",X).remove();C(".js-paymentapi",X).closest("label").removeClass("h-hide");C(".js-subscriptions-order",X).prop("disabled",false);C(".js-subscription-cost",a).selectBox("value","");X.addClass("h-hide");a.removeClass("h-hide");return false});X.off("click",".js-paymentapi").on("click",".js-paymentapi",function(){C(".js-subscriptions-order",X).prop("disabled",false)});C(".js-paymentapi",X).each(function(){var d=C(this).attr("data-currency").split(",");if(C.inArray(Y,d)==-1||C.inArray(C(this).val(),U)==-1){C(this).closest("label").addClass("h-hide")}});X.off("click",".js-subscriptions-order").on("click",".js-subscriptions-order",function(){C(".js-subscriptions-order",X).prop("disabled",true);C("body").css("cursor","wait");C.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/api/paidsubscription/placeorder",data:{subscriptionid:Z,subscriptionsubid:V,paymentapiclass:C(".js-paymentapi:checked",X).val(),currency:Y},type:"POST",dataType:"json",complete:function(){C("body").css("cursor","auto")},success:function(d){if(d&&!d.error){b.html(d);X.addClass("h-hide");a.addClass("h-hide");b.off("click",".js-subscription__cancel").on("click",".js-subscription__cancel",function(){b.html("").addClass("h-hide");C(".js-subscription__remove",X).click();return false});b.removeClass("h-hide")}},error:function(f,e,d){console.log("Unable to fetch payment api form! error:"+d);openAlertDialog({title:"Error",message:"Error fetching payment form.",iconType:"error"})}})});X.removeClass("h-hide")});C(".js-subscription__end",M).click(function(){var U=C(this).attr("data-id"),V=C(this).closest("tr"),W=C(this).closest("table");openConfirmDialog({title:vBulletin.phrase.get("end_subscription"),message:vBulletin.phrase.get("end_subscription_confirm"),iconType:"warning",buttonLabel:{yesLabel:vBulletin.phrase.get("end_subscription"),noLabel:vBulletin.phrase.get("cancel")},onClickYes:function(){C("body").css("cursor","wait");C.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/api/paidsubscription/endsubcription",data:{subscriptionid:U},type:"POST",dataType:"json",complete:function(){C("body").css("cursor","auto")},success:function(X){if(X&&!X.error){V.remove();if(W.find("tr").length<=1){W.closest(".current_subscriptions").remove()}}},error:function(Z,Y,X){console.log("Unable to end subscription! error:"+X);openAlertDialog({title:"Error",message:"Error ending subscription.",iconType:"error"})}})}});return false})}});createDaySelectBox=function(E){var G="";var I=C(".js-birth__month").val();var H=C("#bd_year").val();var J=new Date(H,I,0);if(C("#bd_day").val()==""||C("#bd_day").val()==null){G+="<option name='day' value='' selected='selected'></option>"}for(var F=1;F<=J.getDate();F++){F=(F<10)?("0"+F):F;if(F==C("#bd_day").val()){G+="<option name='day' value='"+F+"' selected='selected'>"+F+"</option>"}else{G+="<option name='day' value='"+F+"'>"+F+"</option>"}}E.html(G);E.selectBox("destroy").selectBox()};updateDaySelectBox=function(E,I){var H=(C(".js-birth__year").val()!="")?C(".js-birth__year").val():0;var J=new Date(H,I,0);J=J.getDate();var G="";for(var F=1;F<=J;F++){F=(F<10)?("0"+F):F;G+="<option name='day' value='"+F+"'>"+F+"</option>"}updateSelectBox(E,G)};updateSelectBox=function(E,F,H){F=(F)?F:E.html();var G=E.attr("class").split(" ");E.selectBox("destroy");E.removeData("selectBoxControl");E.removeData("selectBoxSettings");E.html(F);if(C("#"+G[0]).val()!=undefined){E.val(C("#"+G[0]).val())}E.selectBox()};setSelectedOption=function(F,E){F.val(E.val())};setIMSelectedOption=function(E,G){var F="";C.each(E,function(K,I){var J=C(I).data("orig-value-class");F=C(I).parent().children(":input[type=hidden]."+J).val();C(I).val(F)});var H="";C.each(E,function(J,I){$screenNameContainer=C(E).closest(".js-screen-name__container");H=C(I).closest(".js-screen-name").find("select.js-im option:selected");C.each(C(H),function(K,L){if(C(I).val()!=C(L).val()){C(I).find("option[value= "+C(L).val()+"]").remove()}});updateProviders($screenNameContainer,G)})};getAvailableIMs=function(F,G){var E="";C.each(G,function(H,I){if(F.find("select.js-im option:selected[value= "+H+"]").length==0){E+="<option name='im_provider' value='"+H+"'> "+I+"</option>"}});return E};updateImSelectBox=function(E,F){E.selectBox("destroy");E.removeData("selectBoxControl");E.removeData("selectBoxSettings");E.html(F);E.selectBox()};updateProviders=function(F,E){F.find("select.js-im").each(function(I,G){var J=C(G).val();var H="";C.each(E,function(K,L){if(F.find("select.js-im option:selected[value= "+K+"]").length==0){H+="<option name='im_provider' value='"+K+"'>"+L+"</option>"}else{if(K==J){H+="<option name='im_provider' value='"+K+"' selected='selected'>"+L+"</option>"}}});updateImSelectBox(C(G),H)})};resetFormFields=function(){var E=C(this.form);setTimeout(function(){C("input",E).trigger("change");C("select.b-form-select__select",E).each(function(){updateSelectBox(C(this))})},100)}})(jQuery);