/*=======================================================================*\
|| ###################################################################### ||
|| # 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(A){window.vBulletin=window.vBulletin||{};var B=[".registration-widget"];if(!vBulletin.pageHasSelectors(B)){return false}window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=A.merge(window.vBulletin.options.precache,["usecoppa","checkcoppa","webmasteremail","reqbirthday","regrequirepaidsub"]);window.vBulletin.phrase=window.vBulletin.phrase||{};window.vBulletin.phrase.precache=window.vBulletin.phrase.precache||[];window.vBulletin.phrase.precache=A.merge(window.vBulletin.phrase.precache,["close","email_addresses_must_match","error","invalid_email_address","password_must_be_at_least_four_chars","passwords_must_match","please_enter_a_username","please_enter_your_email_address","please_enter_your_parent_or_guardians_email_address","please_select_a_day","please_select_a_month","please_select_a_year","register_not_agreed","registration_coppa_fail","registration_start_failed","site_terms_and_rules","site_terms_and_rules_title","registeremail","moderateuser","registration_complete","paid_subscriptions","paid_subscription_required"]);A(document).ready(function(){var L=parseInt(window.vBulletin.options.get("usecoppa")),I=false,E=false,J=false,D=parseInt(window.vBulletin.options.get("reqbirthday")),Q=parseInt(window.vBulletin.options.get("regrequirepaidsub")),N,F,P,M;function K(){A("#frmRegister").trigger("reset");setTimeout(vBulletin.hv.reset,0);if(L||D){var X=A.cookie(pageData.cookie_prefix+"coppaage");var U,R,S,W=false;if(L&&X&&parseInt(window.vBulletin.options.get("checkcoppa"))){var V=X.split("-",3);if(V.length==3){U=parseInt(V[0]);R=parseInt(V[1]);S=parseInt(V[2]);if(U!=0&&R!=0&&S!=0){W=true;A("#regMonth").val(U);A("#regDay").val(R);A("#regYear").val(S)}H(U,R,S,W,true)}}else{A(".signup-content").removeClass("h-hide")}A("#regMonth, #regDay, #regYear").off("change").on("change",function(){U=A("#regMonth").val();R=A("#regDay").val();S=A("#regYear").val();H(U,R,S,W)})}else{A(".signup-content").removeClass("h-hide")}A(".registration-widget select").selectBox();A("#regDataUsername").off("keydown blur").on("keydown",function(Y){if(Y.keyCode==13){A(this).triggerHandler("blur")}return true}).on("blur",function(){if(A.trim(this.value)==""){return true}E=true;var Y=this;A.ajax({url:vBulletin.getAjaxBaseurl()+"/registration/checkusername",type:"POST",data:{username:A.trim(Y.value)},dataType:"json",contentType:"application/x-www-form-urlencoded; charset=UTF-8",success:function(Z){if(Z&&Z.errors){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get(Z.errors[0]),iconType:"warning",onAfterClose:function(){Y.value="";Y.select();Y.focus()}})}else{if(J){A("#frmRegister").submit()}}},complete:function(){E=false}})});A("#viewTerms").off("click").on("click",function(){console.log(window.vBulletin.options.get("webmasteremail"));openAlertDialog({title:vBulletin.phrase.get("site_terms_and_rules_title"),message:vBulletin.phrase.get("site_terms_and_rules",window.vBulletin.options.get("webmasteremail"),pageData.baseurl),buttonLabel:vBulletin.phrase.get("close"),width:600,maxHeight:400});return false});var T=A(".paidsubscription_row");if(T.length>0){A("select.cost",T).change(function(){var d=A(this).closest(".newsubscription_row"),b=A(this).find("option:selected").first(),a=A(this).closest(".subscriptions_list"),Z=A(".order_confirm",T),c=A(".payment-form",T),Y=A.parseJSON(d.attr("data-allowedapis"));N=d.attr("data-id");F=b.attr("data-subid");M=b.attr("data-currency");A('<tr class="confirm_data"><td>'+b.attr("data-subtitle")+"</td><td>"+b.attr("data-duration")+"</td><td>"+b.attr("data-value")+"</td></tr>").appendTo(A(".order_confirm_table",Z));a.addClass("h-hide");Z.off("click",".remove_subscription").on("click",".remove_subscription",function(){A(".confirm_data",Z).remove();A("input.paymentapi",Z).closest("label").removeClass("h-hide");A(".subscriptions-order",Z).prop("disabled",false);A("select.cost",a).selectBox("value","");Z.addClass("h-hide");a.removeClass("h-hide");N=0;return false});Z.off("click","input.paymentapi").on("click","input.paymentapi",function(){P=A("input.paymentapi:checked",Z).val()});A("input.paymentapi",Z).each(function(){var e=A(this).attr("data-currency").split(",");if(A.inArray(M,e)==-1||A.inArray(A(this).val(),Y)==-1){A(this).closest("label").addClass("h-hide")}});Z.removeClass("h-hide")})}}function H(U,R,T,V,S){S=S||false;if(U!=0&&R!=0&&T!=0){if(V){A(".birth-date-wrapper").addClass("h-hide")}A.ajax({url:vBulletin.getAjaxBaseurl()+"/registration/iscoppa",type:"POST",data:{month:U,day:R,year:T},dataType:"json",success:function(W){if(W&&typeof (W.needcoppa)!="undefined"){I=W.needcoppa!=0;if(W.needcoppa==2){if(!V){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("registration_coppa_fail"),iconType:"error"});A(".birth-date-wrapper").addClass("h-hide")}A(".signup-content").addClass("h-hide");A(".coppafail_notice").removeClass("h-hide");return }else{if((W.needcoppa==1)||(!S)){A(".birth-date-wrapper").addClass("h-hide");A("#regContent").removeClass("h-hide");A("#frmRegister .action-buttons").removeClass("h-hide");A(".signup-content").removeClass("h-hide")}else{A(".birth-date-wrapper").removeClass("h-hide");A(".signup-content").removeClass("h-hide");A(".registration-widget select").selectBox()}}}A(".coppa")[I?"removeClass":"addClass"]("h-hide-imp")},error:function(){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("registration_start_failed"),iconType:"error"})}})}}K();function G(R,S){if(R){openAlertDialog({title:vBulletin.phrase.get("error"),message:R,iconType:"warning",onAfterClose:function(){S.focus()}});return false}return true}function O(){var R="",S;if(L){if(A("#regMonth").val()==0){R=vBulletin.phrase.get("please_select_a_month");S=A("#regMonth").next(".selectBox")}else{if(A("#regDay").val()==0){R=vBulletin.phrase.get("please_select_a_day");S=A("#regDay").next(".selectBox")}else{if(A("#regYear").val()==0){R=vBulletin.phrase.get("please_select_a_year");S=A("#regYear").next(".selectBox")}}}if(!G(R,S)){return false}}if(A.trim(A("#regDataUsername").val())==""){R=vBulletin.phrase.get("please_enter_a_username");S=A("#regDataUsername")}else{if(A("#regDataPassword").val()==""||A("#regDataPassword").val().length<4){R=vBulletin.phrase.get("password_must_be_at_least_four_chars");S=A("#regDataPassword")}else{if(A("#regDataPassword").val()!=A("#regDataConfirmpassword").val()){R=vBulletin.phrase.get("passwords_must_match");S=A("#regDataConfirmpassword")}else{if(A.trim(A("#regDataEmail").val())==""){R=vBulletin.phrase.get("please_enter_your_email_address");S=A("#regDataEmail")}else{if(!isValidEmailAddress(A("#regDataEmail").val())){R=vBulletin.phrase.get("invalid_email_address");S=A("#regDataEmail")}else{if(A("#regDataEmail").val()!=A("#regDataEmailConfirm").val()){R=vBulletin.phrase.get("email_addresses_must_match");S=A("#regDataEmailConfirm")}else{if(I){if(A.trim(A("#parentGuardianEmail").val())==""){R=vBulletin.phrase.get("please_enter_your_parent_or_guardians_email_address");S=A("#parentGuardianEmail")}else{if(!isValidEmailAddress(A("#parentGuardianEmail").val())){R=vBulletin.phrase.get("invalid_email_address");S=A("#parentGuardianEmail")}}}}}}}}}if(!G(R,S)){return false}if(!A("#cbApproveTerms").is(":checked")){R=vBulletin.phrase.get("register_not_agreed");S=A("#cbApproveTerms")}if(Q&&!N){R=vBulletin.phrase.get("paid_subscription_required");S=A(".cost")}if(N&&!P){R=vBulletin.phrase.get("please_select_a_payment_method");S=A("input.paymentapi").first()}return G(R,S)}function C(){var R=this;console.log("Paid Subscriptions Data: subscriptionid: "+N+"; subscriptionsubid: "+F+"; paymentapiclass: "+P+"; currency: "+M);if(!O()){J=false;return false}A(".action-buttons button",R).prop("disabled",true);A.ajax({url:vBulletin.getAjaxBaseurl()+"/registration/registration",data:A(R).serializeArray(),type:"POST",dataType:"json",success:function(T){if(T&&T.response&&T.response.errors){var W=[];for(var S in T.response.errors){if(T.response.errors[S][0]!="exception_trace"){W.push(vBulletin.phrase.get(T.response.errors[S]))}}openAlertDialog({title:vBulletin.phrase.get("error"),message:W.join("<br />"),iconType:"warning",onAfterClose:function(){vBulletin.hv.reset(true)}})}else{if(T&&T.response&&T.response.usecoppa){location.replace(T.response.urlPath)}else{if(T&&T.response){var U=function(){var X=T.response.msg_params;X.unshift(T.response.msg);openAlertDialog({title:vBulletin.phrase.get("registration_gregister"),message:vBulletin.phrase.get.apply(vBulletin.phrase,X),onAfterClose:function(){if(T.response.urlPath){location.replace(T.response.urlPath)}else{A(".signup-success").removeClass("h-hide");A(".signup-content").addClass("h-hide")}}})};if(!N){U()}else{var V=openConfirmDialog({title:vBulletin.phrase.get("paid_subscriptions"),message:vBulletin.phrase.get("loading")+"...",width:500,dialogClass:"paidsubscription-dialog loading",buttonLabel:{yesLabel:vBulletin.phrase.get("order"),noLabel:vBulletin.phrase.get("cancel")},primaryButton:"yes",onClickYesWithAjax:true,onClickYes:function(){A(this).closest(".paidsubscription-dialog").find("form").submit()},onClickNo:function(){if(Q){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("paid_subscription_required"),iconType:"warning",onAfterClose:function(){V.dialog("open")}})}else{U()}}});A.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/api/paidsubscription/placeorder",data:{subscriptionid:N,subscriptionsubid:F,paymentapiclass:P,currency:M},type:"POST",dataType:"json",complete:function(){A("body").css("cursor","auto")},success:function(X){if(X&&!X.error){A(".paidsubscription-dialog").removeClass("loading");A(".dialog-content .message",V).html(X);A('.dialog-content .message input[type="submit"], .dialog-content .message .js-subscription__cancel',V).hide();V.dialog("option","position","center")}},error:function(Z,Y,X){console.log("Unable to fetch payment api form! error:"+X);openAlertDialog({title:"Error",message:"Error fetching payment form.",iconType:"error"})}})}}}}},error:function(S){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("registration_start_failed"),iconType:"error"})},complete:function(){A(".action-buttons button",R).prop("disabled",false);J=false}})}A("#frmRegister").off("submit.usersignup").on("submit.usersignup",function(){J=true;var R=this;setTimeout(function(){if(E){J=false;return }C.apply(R)},10);return false});A("#regBtnReset").off("click").on("click",function(R){vBulletin.hv.reset();setTimeout(function(){A(".registration-widget select").selectBox("refresh");A("#regMonth").next(".selectBox").focus()},50)})})})(jQuery);