/*=======================================================================*\
|| ###################################################################### ||
|| # 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,["error_adding_infraction","error_adding_warning","error_reversing_infraction","error_sending_private_message","give_infraction_ginfraction","infraction_added","infraction_reversed","please_check_the_box_to_reverse_infraction","please_specify_reason_to_reverse_infraction","received_infraction","received_warning","warning_added"]);vBulletin.infraction=vBulletin.infraction||{};(function(E){var D=E("#infractions-tab");vBulletin.infraction.infractUser=function(K,F){var L=E(this);if(L.data("ajaxstarted")){return false}var J=L.hasClass("js-infraction-received"),H,G,I;if(J){H="received_infraction_form";G="received_infraction";I="receive-infraction-dialog"}else{H="give_infraction_form";G="give_infraction_ginfraction";I="give-infraction-dialog"}L.data("ajaxstarted",true);vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/render/"+H,data:{userid:L.data("userid"),nodeid:L.closest(".js-post-controls").data("node-id")||L.data("nodeid"),userInfraction:L.data("userinfraction")},error_phrase:"error_x",complete:function(){L.data("ajaxstarted",null)},success:function(M){if(E("."+I).length){E("."+I).replaceWith(M)}else{E(M).appendTo(document.body).hide()}var N=E("."+I);N.dialog({title:vBulletin.phrase.get(G),autoOpen:true,modal:true,resizable:false,closeOnEscape:false,showCloseButton:false,width:N.hasClass("error-infraction-dialog")?500:(J?600:700),dialogClass:"dialog-container infraction-dialog-container dialog-box",close:function(){var O=E(".js-editor",this);if(O.length&&vBulletin.ckeditor.editorExists(O)){vBulletin.ckeditor.destroyEditor(O)}E(this).dialog("destroy").remove()},open:function(){var R=this;if(!J){var V=E(".infraction-send-pm",R);vBulletin.ajaxForm.apply(E(R),[{dataType:"json",error_phrase:"error_adding_infraction",success:function(Z,X,d,f){console.log("Infraction result:");console.dir(Z);var e=(Z.infractionNodeid&&!Z.infractionNodeid.errors),b=(Z.pmNodeid?1:0),c=(Z.pmNodeid&&!Z.pmNodeid.errors),a="",Y="warning";if(e&&(!b||c)){a=Z.isWarning?"warning_added":"infraction_added";Y=""}else{if(e&&b&&!c){a="error_sending_private_message"}else{a=Z.isWarning?"error_adding_warning":"error_adding_infraction"}}openAlertDialog({title:vBulletin.phrase.get("give_infraction_ginfraction"),message:vBulletin.phrase.get(a),iconType:Y});if(e){if(typeof F=="function"){F.apply(L.get(0),[Z])}E(R).dialog("close")}},beforeSerialize:function(X){},beforeSubmit:function(b,Z,h){var g=E(".infraction-level-control option:selected",Z).val();if(g=="0"){if(E.trim(E(".custom-reason",Z).val())==""){T(E(".infraction-level",R));openAlertDialog({title:vBulletin.phrase.get("give_infraction_ginfraction"),message:vBulletin.phrase.get("please_specify_custom_reason"),iconType:"warning",onAfterClose:function(){E(".custom-reason",Z).focus()}});return false}var f=Number(E(".custom-points",Z).val());if(isNaN(f)||f<=0){T(E(".infraction-level",R));openAlertDialog({title:vBulletin.phrase.get("give_infraction_ginfraction"),message:vBulletin.phrase.get("please_specify_custom_points"),iconType:"warning",onAfterClose:function(){E(".custom-points",Z).focus()}});return false}var d=E(".custom-period option:selected",Z).val(),X=Number(E(".custom-expires",Z).val());if(d!="N"&&(isNaN(X)||X<=0)){T(E(".infraction-level",R));openAlertDialog({title:vBulletin.phrase.get("give_infraction_ginfraction"),message:vBulletin.phrase.get("please_specify_custom_expires"),iconType:"warning",onAfterClose:function(){E(".custom-expires",Z).focus()}});return false}}var Y=E(".infraction-ban-reason .ban-reason",R);if(Y.is(":visible")&&!E.trim(Y.val())){T(E(".infraction-ban",R));E(".ban-reason-desc",R).removeClass("h-hide");Y.focus();E(".dialog-content",R).scrollTop(0).scrollTop(E(".infraction-ban-reason",R).position().top);return false}var a=Number(V.data("required"));if(a){var e=false,c=E(".js-editor",Z);if(vBulletin.ckeditor.editorExists(c)){c=vBulletin.ckeditor.getEditor(c);if(!E.trim(c.getData())){e=true}}else{if(!E.trim(c.val())){e=true}}if(e){openAlertDialog({title:vBulletin.phrase.get("give_infraction_ginfraction"),message:vBulletin.phrase.get("please_specify_infraction_pm"),iconType:"warning",onAfterClose:function(){T(V);c.focus()}});return false}}}}]);var Q=function(X){if(X){P.removeClass("h-hide").find("input, select").prop("disabled",false).end().find(".selectBox").removeClass("selectBox-disabled")}else{P.addClass("h-hide").find("input, select").prop("disabled",true).end().find(".selectBox").addClass("selectBox-disabled")}};E(".infraction-level-control",R).on("change",function(b,a,Z){var d=E(this.options[this.selectedIndex]),Z=Z&&Z.length==1?Z:E(this).closest(".infraction-level").find(".infraction-warning-control input");if(!a){if(d.data("allow-warning")){Z.prop("disabled",false).val(this.value).parent().removeClass("h-hide");Q(false)}else{Z.prop("disabled",true).parent().addClass("h-hide");if(this.value=="0"){Q(true);E(".textbox",P).first().focus()}}}var c=0,X=0;if(!Z.prop("checked")&&this.value!="0"){c=Number(d.data("points"))||0;X=1}else{if(this.value=="0"){c=Number(E(".custom-infraction-info .custom-points",R).val())||0;X=1}}var Y=E(".infraction-dashboard-stats").data();if(S(Number(Y.points)+c,Number(Y.infractions)+X)){U(true)}else{U(false)}O()});E(".infraction-warning-control input",R).on("click",function(){(this.checked)?U(false):E(".infraction-level-control",R).trigger("change",[true,this])});E(".custom-points",R).on("change",function(){E(".infraction-level-control",R).trigger("change",[true])});var P=E(".custom-infraction-info",R).removeClass("h-hide");E("select",R).selectBox();P.addClass("h-hide");E(".js-content-entry-panel, .js-editor",V).data("callback",function(){O()});vBulletin.ckeditor.initEditorComponents(V,true);E(".toggle-button",R).on("click",function(b){var Z=E(this),X=Z.closest(".blockrow-head"),a=X.next(".blockrow-body");if(Z.hasClass("expand")){a.show();X.removeClass("collapsed");O()}else{a.hide();X.addClass("collapsed");O()}Z.toggleClass("collapse expand");var Y=Z.attr("title");Z.attr("title",Z.data("toggle-title")).data("toggle-title",Y);return false});var T=function(X){E(".toggle-button.expand",X).trigger("click")};var S=function(Y,X){if(Y==0&&X==0){return false}var Z=false;E(".infraction-ban-list tbody tr",R).each(function(a,b){var c=E(this).data();if((c&&Number(c.points)&&Y>=Number(c.points))||(c&&Number(c.infractions)&&X>=Number(c.infractions))){Z=true;return false}});return Z};var U=function(X){var Y=E(".infraction-ban-reason",R);if(X){Y.removeClass("h-hide");T(E(".infraction-ban",R))}else{Y.addClass("h-hide")}};var W=E(".dialog-content",R),O=function(){if(!W[0]){W[0]=R}W[(W[0].scrollHeight>parseFloat(W.css("max-height")))?"addClass":"removeClass"]("has-scrollbar")};O();E(".infraction-level-control",R).trigger("change")}else{vBulletin.ajaxForm.apply(E(".infraction-reverse-form",R),[{dataType:"json",error_phrase:"error_reversing_infraction",success:function(Y,Z,a,X){openAlertDialog({title:vBulletin.phrase.get("reverse_this_infraction"),message:vBulletin.phrase.get("infraction_reversed")});if(typeof F=="function"){F.apply(L.get(0),[Y])}E(R).dialog("close")},beforeSerialize:function(X){},beforeSubmit:function(Z,Y,X){if(!E(".infraction-nodeid",Y).is(":checked")){openAlertDialog({title:vBulletin.phrase.get("reverse_this_infraction"),message:vBulletin.phrase.get("please_check_the_box_to_reverse_infraction"),iconType:"warning",onAfterClose:function(){E(".infraction-nodeid",Y).focus()}});return false}else{if(!E.trim(E(".infraction-reason",Y).val())){openAlertDialog({title:vBulletin.phrase.get("reverse_this_infraction"),message:vBulletin.phrase.get("please_specify_reason_to_reverse_infraction"),iconType:"warning",onAfterClose:function(){E(".infraction-reason",Y).focus()}});return false}}return true}}]);E(".reverse-infraction",R).on("click",function(){E(".infraction-reverse-form",R).submit()})}E(".close-infraction",R).on("click",function(){E(R).dialog("close")});E(".ckeditor-bare-box.ckeditor-load-on-focus",R).on("focus",function(){vBulletin.ckeditor.initEditor(this.id,{complete:function(X){O()},error:function(X){E("#"+X).prop("disabled",false).removeClass("ckeditor-load-on-focus")}})})}})}})};vBulletin.infraction.loadUserInfractions=function(F){E.post(vBulletin.getAjaxBaseurl()+"/ajax/render/user_infractions",{userid:F.userid,pagenum:F.pageNumber},function(G,L,K){F.container.html(G);if(E(".pagenav-form",D).length){var H=new vBulletin.pagination({context:D,tabParamAsQueryString:false,allowHistory:D.find(".conversation-toolbar-wrapper").data("allow-history")==1,onPageChanged:function(M,N){vBulletin.infraction.loadUserInfractions({container:D,userid:D.data("userid"),pageNumber:M,replaceState:true})}})}if(typeof F.callback=="function"){F.callback(G)}if(F.pushState||F.replaceState){var J=vBulletin.makePaginatedUrl(location.href,F.pageNumber);if(!A){B=D.find(".conversation-toolbar-wrapper").data("allow-history")=="1";A=new vBulletin.history.instance(B)}if(A.isEnabled()){var I={from:"infraction_filter",page:F.pageNumber,tab:D.data("url-path")?D.data("url-path"):"#"+D.attr("id")};A[F.pushState?"pushState":"setDefaultState"](I,document.title,J)}}},"json")};var A,B;vBulletin.infraction.setHistoryStateChange=function(){if(!A){B=D.find(".conversation-toolbar-wrapper").data("allow-history")=="1";A=new vBulletin.history.instance(B)}if(A.isEnabled()){A.setStateChange(function(J){var I=A.getState();if(I.data.from=="infraction_filter"){A.log(I.data,I.title,I.url);var F=D.closest(".ui-tabs"),H=F.find(".ui-tabs-nav > li").filter('li:has(a[href*="#{0}"])'.format(D.attr("id")));if(H.hasClass("ui-tabs-selected")){vBulletin.infraction.loadUserInfractions({container:D,userid:D.data("userid"),pageNumber:I.data.page,pushState:false})}else{var G=H.index();vBulletin.selectTabByIndex.call(F,G)}}},"infraction_filter")}};vBulletin.infraction.markInfractions=function(){var F,G,H;E(".infractions-list .list-item").each(function(){H=E(this);G=H.data("nodeId");F=vBulletin.cookie.fetchBbarrayCookie("discussion_view",G);if(F){H.addClass("read")}})};E(document).off("click",".js-post-control__infraction").on("click",".js-post-control__infraction",function(F){vBulletin.infraction.infractUser.apply(this,[F,function(H){var J=E(this),G=J.find(".b-icon"),I=J.hasClass("js-infraction-received");G.removeClass("b-icon__tickets--neutral b-icon__tickets--warned b-icon__tickets--infracted");if(I){J.removeClass("js-infraction-received").attr("title",vBulletin.phrase.get("give_infraction_ginfraction"));G.addClass("b-icon__tickets--neutral")}else{J.addClass("js-infraction-received");if(H.isWarning){J.attr("title",vBulletin.phrase.get("received_warning"));G.addClass("b-icon__tickets--warned")}else{J.attr("title",vBulletin.phrase.get("received_infraction"));G.addClass("b-icon__tickets--infracted")}}}])});D.off("click",".infractionCtrl").on("click",".infractionCtrl",function(F){vBulletin.infraction.infractUser.apply(this,[F,function(G){vBulletin.infraction.loadUserInfractions({container:D,userid:E(this).data("userid"),pageNumber:1,pushState:Number(E('.pagenav-form input[name="page"]',D).val())!=1})}])});D.on("click",".view-infraction",function(F){vBulletin.infraction.infractUser.apply(this,[F,function(G){var H=Number(E('.pagenav-form input[name="page"]',D).val())||1;vBulletin.infraction.loadUserInfractions({container:D,userid:E(this).data("userid"),pageNumber:H,pushState:H!=1})}])});E(document).off("click","#privateMessageContainer .action-buttons .view-infraction").on("click","#privateMessageContainer .action-buttons .view-infraction",function(F){vBulletin.infraction.infractUser.apply(this,[F,function(G){}])});E(".infraction-delete").off("click").on("click",function(H){$button=E(this);var F,G=false;if($button.parents("#pmFloatingBarContent").hasClass("infractions-paginator")){F=getSelectedMessages()}else{F=[E("#privateMessageContainer .js-conversation-starter").data("nodeId")];G=true}if(F.length>0){openConfirmDialog({title:vBulletin.phrase.get("messages_header"),message:vBulletin.phrase.get("are_you_sure_delete_infractions"),iconType:"warning",onClickYes:function(){vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/api/node/deleteNodes",data:{nodeids:F,hard:0},success:function(I){if(G){location.href=E("#pmBtnBackToInfractions").prop("href")}else{location.reload()}}})}})}});E(".infraction-mark_as_read").off("click").on("click",function(I){var H=this;var G=getSelectedMessages();if(G.length>0){if(pageData.threadmarking=="0"||pageData.userid=="0"){for(var F in G){vBulletin.cookie.setBbarrayCookie("discussion_view",G[F],Math.round(new Date().getTime()/1000));E("[data-node-id={0}]".format(G[F]),".infractions-list").addClass("read").find(".privateMessageActionCheck").attr("checked",false)}}else{vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/api/node/markReadMultiple",data:{nodeids:G},success:function(J){E(J).each(function(){E("[data-node-id={0}]".format(this),".infractions-list").addClass("read").find(".privateMessageActionCheck").attr("checked",false);var K=E("[data-node-id={0}]".format(this),".infractions-list");K.addClass("read");K.find(".privateMessageActionCheck").attr("checked",false)})}})}}});E(".infraction-mark_as_unread").off("click").on("click",function(I){var H=this;var G=getSelectedMessages();console.log(G);if(G.length>0){if(pageData.threadmarking=="0"||pageData.userid=="0"){for(var F in G){vBulletin.cookie.unsetBbarrayCookie("discussion_view",G[F]);E("[data-node-id={0}]".format(G[F]),".infractions-list").removeClass("read").find(".privateMessageActionCheck").attr("checked",false)}}else{vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/api/node/markUnreadMultiple",data:{nodeids:G},success:function(J){E(J).each(function(){E("[data-node-id={0}]".format(this),".infractions-list").removeClass("read").find(".privateMessageActionCheck").attr("checked",false)})}})}}});E(document).ready(function(){if(E(".infractions-list").length>0){if(pageData.threadmarking=="0"||pageData.userid=="0"){vBulletin.infraction.markInfractions()}}if(E("#pmBtnBackToInfractions").length>0){var F=E("#privateMessageContainer .conversation-list .b-post--infraction").data("nodeId");if(pageData.threadmarking=="0"||pageData.userid=="0"){vBulletin.cookie.setBbarrayCookie("discussion_view",F,Math.round(new Date().getTime()/1000))}else{vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/api/node/markRead",data:{nodeid:F}})}}});E("#infractionFilters").trigger("reset").find(".filter-options input").off("click").on("click",function(F){infractionsFilter.apply(this)});E(document).off("click","#privatemessagePaging .infractionsPrev").on("click","#privatemessagePaging .infractionsPrev",function(G){G.preventDefault();var F=E(this).closest("#privatemessagePaging").find(':input[type=hidden][name="prev-page"]').val();C(E(this),F)});E(document).off("click","#privatemessagePaging .infractionsNext").on("click","#privatemessagePaging .infractionsNext",function(G){G.preventDefault();var F=E(this).closest("#privatemessagePaging").find(':input[type=hidden][name="next-page"]').val();C(E(this),F)});E(document).off("keypress","#privatemessagePaging .infractionsPageTo").on("keypress","#privatemessagePaging .infractionsPageTo",function(G){if(G.keyCode==13){G.preventDefault();var H=E(this);var F=parseInt(H.val(),10);if(isNaN(F)){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("please_enter_a_valid_page_number"),iconType:"error"});return false}C(H,F)}});function C(F,I,N){if(!F){F=E("#private-message-toolbar .infractions-paginator .infractionsPageTo");if(F.length==0){return false}}if(!N){N=0}var K=F.closest(".infractions-paginator");var M=E("#privateMessageContainer .main-pane .pending-posts-container");var H=K.find("#maxPageNum").filter(":input[type=hidden]").val();var J=parseInt(K.find(":input[type=hidden][name=pagenum]").val(),10);var L=parseInt(K.find(":input[type=hidden][name=per-page]").val(),10);I=parseInt(I,10);if(isNaN(I)||isNaN(H)||isNaN(J)){return false}if((I<1)||(I>H)){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("please_enter_a_valid_page_number"),iconType:"error"});return false}else{if((I==J)&&!N){return false}}var G={setCurrentPage:I,setPerPage:L,getPagingInfo:N,options:{}};E("#infractionFilters input:checked").each(function(){G.options[this.name]=this.value});if(G.options.time){G.options.time={from:G.options.time}}E.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/render/privatemessage_infraction_main",type:"POST",data:G,dataType:"json",success:function(Q){M.html(Q);if(E(".infractions-list").length>0){if(pageData.threadmarking=="0"||pageData.userid=="0"){vBulletin.infraction.markInfractions()}}var P=0;var O=0;if(I<H){if(I>1){O=I+1;P=I-1}else{O=I+1}}else{P=I-1}K.find(":input[type=hidden][name=pagenum]").val(I);K.find(":input[type=hidden][name=next-page]").val(O);K.find(":input[type=hidden][name=prev-page]").val(P);if(O){K.find(".infractionsNext").removeClass("h-disabled")}else{K.find(".infractionsNext").addClass("h-disabled")}if(P){K.find(".infractionsPrev").removeClass("h-disabled")}else{K.find(".infractionsPrev").addClass("h-disabled")}K.find(".infractionsPageTo").val(I);if(N){var R=E("#privateMessageContainer .main-pane .pending-posts-container .pending-posts-pageinfo");K.find("#maxPageNum").filter(":input[type=hidden]").val(parseInt(R.find(".totalpages").val(),10));K.find(".infractionsPageCount").text(parseInt(R.find(".totalpages").val(),10));E(".folder-list .folder-item.pending-posts .count",$pmWidget).text(parseInt(R.find(".totalcount").val(),10))}},error:function(){openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("unable_to_contact_server_please_try_again"),iconType:"error"})}})}infractionsFilter=function(G){$paginateButton=E("#private-message-toolbar .infractions-paginator .infractionsPageTo");if($paginateButton.length){C($paginateButton,1,true);return }var F={};E(this).closest(".filter-options-list").find("input:checked").each(function(){F[this.name]=E(this).val()});if(F.time){F.time={from:F.time}}E(this).attr("checked","checked");F.page=1;F.perpage=pmPerPage;var H={options:F};E.ajax({url:vBulletin.getAjaxBaseurl()+"/ajax/render/privatemessage_infraction_main",type:"POST",dataType:"json",data:H,success:function(I){E("#privateMessageContainer .pending-posts-container").html(I);pmPageNum=1;if(E(".infractions-list").length>0){if(pageData.threadmarking=="0"||pageData.userid=="0"){vBulletin.infraction.markInfractions()}}}})};E(document).ready(function(){if(E("#infractionBtnReply").length){vBulletin.conversation.replyWithQuotes.getPostReplyButtonSelector=function(){return"#infractionBtnReply"}}})})(jQuery);