/*=======================================================================*\
|| ###################################################################### ||
|| # 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   # ||
|| ###################################################################### ||
\*========================================================================*/
vBulletin=vBulletin||{};vBulletin.createAjaxTools=function(G,A){var F={};var C=function(K){return'<textarea style="border:1px solid #999;margin-top:10px;height:120px;width:100%;">'+K+"</textarea>"};var J=function(O){var K=[];for(var M=0;M<O.length;M++){var L=($.isArray(O[M])?O[M][0]:O[M]),N=vBulletin.phrase.get(O[M]);if(L!=N){N+=" ("+L+")"}K.push(N)}return K};var E=function(M){for(var K=0;K<M.length;K++){var L=M[K];if($.isArray(L)&&L[0]=="exception_trace"){M.splice(K,1);return L[1]}}return""};var B=function(K,L){return(function(N,Q,P){var M="";if(typeof N.status!="undefined"){M+=" "+N.status}if(Q!=null){M+=" "+Q}if(typeof P!="undefined"){M+=" "+P}var O=vBulletin.phrase.get(K.error_phrase)+"<br /><br />"+vBulletin.phrase.get("error_information_x",M);console.log(L+" Error callback: "+K.url);F.logAjaxError(N,Q,P);openAlertDialog({title:vBulletin.phrase.get(K.title_phrase),message:O,iconType:"error",onAfterClose:K.after_error,})})};var H=function(N,O,M,L,R,P){var T=N.errors;if(!T){T=[N.error]}if(O.api_error){var S=O.api_error.apply(L,[T,N,O]);if(!S){return }}var K=function(U){P.data=P.data.replace(/securitytoken=[^&]*(&|$)/,"securitytoken="+U.newtoken+"$1");$.ajax(P)};if(A!=0){if(F.hasError(T,["inlinemodauth_required",])){D("inlinemod_auth",K,A,"cplogin");return }if(N.userid==0&&F.hasError(T,[/^humanverify_/,"no_create_permissions","session_timed_out_login","not_logged_no_permission","no_permission","no_delete_permissions","no_featured_permissions",])){var Q=function(){D("login",K,A,(O.cpaction?"cplogin":""))};if(!I(K,Q,A)){Q()}return }}F.showApiError(T,N,O)};F.hasError=function(Q,L){if(!$.isArray(Q)){return false}var K=L;if(!$.isArray(K)){K=[L]}for(var N=0;N<Q.length;N++){var O=Q[N];if($.isArray(O)){O=O[0]}for(var M=0;M<K.length;M++){var P=K[M];if($.type(P)=="regexp"){if(P.test(O)){return true}}else{if(P==O){return true}}}}return false};F.logApiError=function(K){console.dir(J(K))};F.showApiError=function(O,M,L){var N=E(O),K=J(O);if($("#debug-information").length==1){if(N){K.push(C(N))}K.push(C(JSON.stringify(M)))}K="<ul>\n<li>"+K.join("</li>\n<li>")+"</li>\n</ul>";openAlertDialog({title:vBulletin.phrase.get(L.title_phrase),message:K,iconType:"error",onAfterClose:L.after_error})};F.logAjaxError=function(K,M,L){console.dir({textStatus:M,jqXHRStatus:K.status,errorThrown:L})};F.ajax=function(L){var K={type:"POST",dataType:"json",title_phrase:"error",error_phrase:"error",api_error:false,after_error:null,element:null};$.extend(true,K,L);if(!K.url){K.url=G+K.call;K.call=""}if(!K.error){K.error=B(K,"ajax")}var M=this;K.success=function(N,O,P){if(!N){if(!L.emptyResponse){vBulletin.error(K.title_phrase,"invalid_server_response_please_try_again",K.after_error)}else{L.emptyResponse.apply(this,arguments)}}else{if(N&&(N.errors||N.error)){H(N,K,L,M,F.ajax,this)}else{if(L.success){L.success.apply(this,arguments)}}}};$.ajax(K)};F.ajaxForm=function(L){var K={dataType:"json",title_phrase:"error",error_phrase:"error",after_error:null,element:null,};$.extend(K,L);if(!K.error){K.error=B(K,"ajaxForm")}K.beforeSubmit=function(Q,N,P){if(L.beforeSubmit){if(L.beforeSubmit.apply(this,arguments)===false){return false}}var O=$("button, .b-button",N);O.prop("disabled",true);N.one("ajaxComplete",function(){O.prop("disabled",false)});return true};var M=this;K.success=function(O,P,Q,N){if(!O){if(!K.emptyResponse){vBulletin.error(K.title_phrase,"invalid_server_response_please_try_again",K.after_error)}else{K.emptyResponse.apply(this,arguments)}}else{if(O&&(O.errors||O.error)){H(O,K,L,M,F.ajaxForm,this)}else{if(L.success){L.success.apply(this,arguments)}}}};this.ajaxForm(K)};var I=function(M,L,K){if(typeof (vBfb)!="undefined"&&vBfb.isFbLogin()){vBfb.makeAuthEvent(function(N){F.ajax({call:"/auth/login-external",data:{provider:"facebook",auth:N.accessToken,userid:K},success:function(O){vBulletin.doReplaceSecurityToken(O.newtoken);return M(O)},api_error:L})})();return true}return false};var D=function(Q,P,N,L){var M,K;var O=openConfirmDialog({title:vBulletin.phrase.get(Q),message:vBulletin.phrase.get("loading")+"...",width:400,dialogClass:"loading",buttonLabel:{yesLabel:vBulletin.phrase.get("login"),noLabel:vBulletin.phrase.get("cancel")},onClickYesWithAjax:true,onClickYes:function(){K.text("").addClass("h-hide");F.ajax({call:"/auth/ajax-login",data:M.serializeArray(),success:function(R){vBulletin.doReplaceSecurityToken(R.newtoken);O.dialog("close");return P(R)},api_error:function(R){K.html(vBulletin.phrase.get(R[0])).removeClass("h-hide");K.find("a").attr("target","_blank")},title_phrase:Q})},});F.ajax({call:"/auth/login-dialog",data:{logintype:L,userid:N,isAjaxTemplateRender:true,},success:function(R){O.removeClass("loading");$(".dialog-content .message",O).html(R);O.dialog("option","position",{of:window});M=O.find(".js-login-form");K=$(".js-error-box",M);$('[type="text"], [type="password"]',O).on("keydown",function(S){if(S.which==13){S.preventDefault();$("#btnConfirmDialogYes",O).click()}});$("input",O).first().focus()},api_error:F.showApiError,title_phrase:Q,error_phrase:"error_loading_delete_form",after_error:function(){O.dialog("close")}})};F.library={};F.library.inlineMod=function(K){D("inlinemod_auth",K,A,"cplogin")};return F};