/*
 =======================================================================*\
|| ###################################################################### ||
|| # vBulletin 6.2.3
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2026 MH Sub I, LLC dba vBulletin. 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.precache(["error","pmchat_close_button_label","pmchat_idle_disconnected_message","pmchat_idle_disconnected_title","pmchat_reconnect_button_label"],["pmchat_enabled","pmchat_header_polling_interval","pmchat_chat_polling_idle_timeout","pmchat_chat_polling_min_interval","pmchat_chat_polling_max_interval"]);
(function(b,na,V){function ha(g){g=g.hasOwnProperty("messageid")?"?messageid="+encodeURIComponent(g.messageid):"?aboutNodeid="+encodeURIComponent(g.aboutNodeid)+"&toUserid="+encodeURIComponent(g.toUserid);return""==g?"#":oa+g}function ia(g){var u;g=g.hasOwnProperty("url")?g.url:ha(g);"#"!=g&&((u=window.open(g,"_blank","width=600,height=700,resizable=yes,scrollbars=yes,status=yes"))&&!u.closed&&"undefined"!=typeof u.closed||window.open(g+queryString))}function pa(){function g(l){var f=l[Object.keys(l)[0]];
f=f&&f.orderListForJs||[];var n=f.length,y=!1,F={};if(0<n)L.find(".js-pmchat__submenu__ephemeral").remove();else return!1;for(var z=0;z<n;z++){var v=f[z];if(l.hasOwnProperty(v)){var p=l[v];var r=W.clone(!0);var t=r.find(".js-pmchat__submenu__link"),O="js-pmchat__messagefinder__"+v;r.removeClass("h-hide-imp");t.attr("data-starter",v).prop("title",p.previewtext).attr("href",ha({messageid:v}));r.find(".js-pmchat__submenu__title").html(p.title);0==p.msgread&&r.addClass("b-comp-menu-dropdown__content-item--unread");
r.addClass(O);r.insertBefore(q);(r=0<M&&(!w.hasOwnProperty(v)||w[v].publishdate!=p.publishdate||w[v].userid!=p.userid)&&0==p.msgread&&p.userid!=pageData.userid)&&(y=!0);F[v]={publishdate:p.publishdate,userid:p.userid,title:p.title,previewtext:p.previewtext,findmehelper:O,isNew:r}}}w=F;M=D;y&&u()}function u(){console.log("New Messages found in polling! Notifying user");if(B.find(".js-comp-menu-dropdown").hasClass("b-comp-menu-dropdown--open")){var l=[];for(f in w)w.hasOwnProperty(f)&&w[f].isNew&&l.push("."+
w[f].findmehelper);if(0<l.length){var f=l.join(", ");var n=b(f),y=setInterval(function(){n.toggleClass("b-comp-menu-dropdown__content-item--unread-alert")},100);setTimeout(function(){clearInterval(y);n.removeClass("b-comp-menu-dropdown__content-item--unread-alert")},3E3)}}else B.find(".js-comp-menu-dropdown").addClass("b-comp-menu-dropdown--alert")}function X(){k+=60;k>=x&&G()}function G(){clearTimeout(Y);k>=x?console.log("Header polling stopped due to idle timeout. (idle time: "+k+"s)"):Y=setTimeout(P,
1E3*H)}function P(){G();console.log("Polled for header data!"+Date.now());Z()}function Q(l,f,n){l.length&&(l.text()!=f&&(l.text(f),l.toggleClass("h-hide-imp",0>=f)),n&&l.parents().eq(1).toggleClass("h-hide-imp",0>=f))}function Z(l){K?"function"==typeof l&&I&&I.always(l):(K=!0,N.removeClass("h-hide-imp"),vBulletin.loadingIndicator.suppressNextAjaxIndicator(),I=vBulletin.AJAX({call:"/chat/loadheaderdata",success:function(f){var n=f.headerCounts;Q(aa,n.messages);Q(R,n.totalcount);ba.each(function(){var y=
b(this),F=y.data("folderid")||0;Q(y,n.details&&n.details[F]&&n.details[F].count||0,!0)});b.isEmptyObject(f.messages)||g(f.messages)},api_error:vBulletin.ajaxtools.logApiError,error:vBulletin.ajaxtools.logAjaxError,complete:[function(){K=!1;N.addClass("h-hide-imp");D=Date.now()},l]}))}var B=b(".js-pmchat__dropdown"),aa=B.find(".js-pmchat__messages-count"),R=b(".notifications-count").not(".js-pmchat__messages-count").not("[data-folderid]"),ba=b(".notifications-count[data-folderid]").not(".js-pmchat__messages-count"),
L=B.find(".js-pmchat__dropdown-submenu"),W=L.find(".js-pmchat__dropdown__single-pm-template").removeClass("js-pmchat__dropdown__single-pm-template"),q=L.find(".js-pmchat__insert-marker"),N=b(".js-pmchat__dropdown-submenu").find(".js-pmchat__submenu__loading-icon");B.find(".js-pmchat__header-data");var H=V.get("pmchat_header_polling_interval")||30,k=0,x=vBulletin.options.get("pmchat_chat_polling_idle_timeout")||300,D=0,w={},M=0,K=!1,I=null,ca=b.debounce(100,function(){"function"==typeof vBulletin.CompMenuDropdown.updateMenuFormat&&
vBulletin.CompMenuDropdown.updateMenuFormat()});L.off("click").on("click",".js-pmchat__submenu__link",function(){var l={},f=b(this).attr("href");"#"!=f?l.url=f:l.messageid=b(this).data("starter");ia(l);b(this).parent().removeClass("b-comp-menu-dropdown__content-item--unread");return!1});b(".js-pmchat-reload-header").on("click",function(l){B.find(".js-comp-menu-dropdown").removeClass("b-comp-menu-dropdown--alert");k=0;Date.now()-D<1E3*H?console.log("PM Load aborted: less than "+H+" seconds since last load."):
(G(),Z(ca))});(function(){console.log("Idle detection enabled");setInterval(X,6E4);b(document).on("click keypress scroll",function(l){k=0})})();var Y=setTimeout(P,1E3*H)}function qa(){function g(){var e=b(".js-pmchat__insert-marker").offset().top,a=b(".js-pm-content-entry-container"),d=a.outerHeight();a="fixed"==a.css("position");var c=b(window).outerHeight();(!a||e>c-d)&&vBulletin.animateScrollTop(e)}function u(e){if(n)console.log("Nothing to load, awaiting first message.");else if(E.messagesLoading)console.log("loadNewMessages() rejected: Still awaiting messages from a previous call.");
else{console.log("loadNewMessages() executing.");var a=[];H.find(".js-pmchat__post-wrapper").each(function(d,c){d=parseInt(b(c).data("publishdate")||0,10);var h=parseInt(b(c).data("nodeid")||0,10);d>I&&(I=d,ca=h);0<h&&a.push(h);I>d&&b(c).removeClass("js-pmchat__post-wrapper")});E.messagesLoading=!0;vBulletin.loadingIndicator.suppressNextAjaxIndicator();vBulletin.AJAX({call:"/chat/loadnewmessages",data:{parentid:D,newreplyid:e,lastpublishdate:I,lastnodeid:ca,loadednodes:a},success:function(d){S=(S+
1)%10;d.html&&""!==d.html?(T[S]=1,U=Date.now(),console.log("loadNewMessages(): Inserting new messages."),b(d.html).insertBefore(Y),g()):(T[S]=-1,console.log("loadNewMessages(): No new messages."))},error:function(d){console.log("loadNewMessages(): Error loading new PMs. Ajax result:");console.log(d)},complete:function(d){window.vBulletin.loadingIndicator.hide();E.messagesLoading=!1;E.queued&&(E.queued=!1,window.vBulletin.loadingIndicator.show(),setTimeout(u,0));X(!0)}})}}function X(e){clearTimeout(F);
var a=Date.now(),d=a-U,c=a-y,h=0<T[S],m=T.reduce(function(A,C){return A+C})/10;0<U?h?(t>v&&(t=v),--t,U>z&&(z=U)):t-=1*m:t+=1;t<p?t=p:t>r&&(t=r);y=a;da&&(da=!1,z=a);h=(a-z)/1E3;console.log("Idle time: "+h+"s. (timeout: "+O+"s)");h>=O?(console.log("Polling for messages stopped due to idle timeout. Idle start time: "+z+" time now: "+a),Q(),z=a):(F=setTimeout(G,1E3*t),e?console.log(Date()+" "+`Poll timer was reset from loadNewMssages().  Last poll was ${y}. Next poll is in ${t} seconds. `+"Time since last poll: "+
c/1E3+"s, since last hit: "+d/1E3+"s."):console.log(Date()+" "+`Polling for messages complete. Last poll was ${y}. Next poll is in ${t} seconds. `+"Time since last poll: "+c/1E3+"s, since last hit: "+d/1E3+"s."))}function G(){X();u()}function P(){z=Date.now();t=v;G()}function Q(){f&&f.dialog("instance")||(f=na.dialogtools.openConfirmDialogSimple({title:"pmchat_idle_disconnected_title",message:"pmchat_idle_disconnected_message",width:"50%",yesPhrase:"pmchat_reconnect_button_label",noPhrase:"pmchat_close_button_label",
onClickYes:P,onClickNo:()=>window.close()}))}function Z(e){e?(ra.remove(),ja.remove(),k.attr("data-message-type","pm-reply"),History.replaceState({},K,pageData.baseurl_pmchat+"?messageid="+e),aa(e)):console.log("Missing nodeid for loadParticipants()")}function B(){sa.trigger("event-js-element-resize")}function aa(e,a){vBulletin.AJAX({call:"/chat/loadparticipants",data:{nodeid:e},success:function(d){let c=b(".js-pmchat__participants-insert-marker"),h=b(".js-pmchat__participant");d.participants_html&&
""!=d.participants_html&&c.length&&(h.remove(),c.prepend(d.participants_html),ea.trigger("event-js-content-change"));N.hasClass("h-hide")&&(N.removeClass("h-hide"),ka.trigger("click"),fa.removeClass("h-hide"));d.phrase&&""!=d.phrase&&(b(".js-participants-count-phrase").text(d.phrase),b(".js-participants-count-phrase--title").prop("title",d.phrase));d.title&&""!=d.title&&b(document).find("title").html(d.title);if(a&&a.success&&"function"==typeof a.success)return a.success.apply(this,[d])},complete:function(d,
c,h){if(a&&a.complete&&"function"==typeof a.complete)return a.complete.apply(this,[d,c,h])},error:function(d,c,h){console.log("/ajax/chat/loadparticipants failed!");console.log("----------------");console.log("jqXHR:");console.dir(d);console.log("text status:");console.dir(c);console.log("error thrown:");console.dir(h);console.log("----------------")}})}function R(e){var a=b(this).attr("href");a.startsWith("#")||(e.preventDefault(),(e=window.open(a,"_blank"))&&!e.closed&&"undefined"!=typeof e.closed||
window.open(a))}function ba(e){fa.animate({height:"toggle"},{duration:"fast",start:function(){ea.trigger("event-js-element-resize-start")},progress:function(a,d,c){B()},complete:function(){B()}});e.preventDefault();la.length&&la.toggleClass("fa-caret-down fa-caret-up")}function L(){var e=function(m){var A=0<ea.height();if(m.data&&m.data.command)switch(m.data.command){case "open":J.removeClass("h-hide");break;case "close":J.addClass("h-hide");break;default:A?J.toggleClass("h-hide"):J.removeClass("h-hide")}else J.toggleClass("h-hide");
A?B():ba(m);m.preventDefault()},a={},d=b(".js-participants-add-recipients-input"),c=new vBulletin_Autocomplete(d,{apiClass:"user",afterAdd:function(m,A,C){"undefined"!=typeof C&&"undefined"!=typeof C.id&&C.id&&(a[A]=C.id)},delimiter:" ; "}),h=function(m){c.clearElements();m.data?m.data.command="close":m.data={command:"close"};e(m)};console.log({addRecipientsAutoComplete:c});ma.off("click").on("click",{command:"toggle"},e);J.find(".js-add-recipients-cancel").off("click").on("click",{command:"close"},
h);J.find(".js-add-recipients-submit").off("click").on("click",function(m){var A=c.getInputField(),C=A.val();C&&(A.val(""),c.addElement(C,C));A=c.getValues();vBulletin.AJAX({call:"/ajax/api/content_privatemessage/addPMRecipientsByUsernames",data:{pmid:D,usernames:A,usernamesToIds:a},success:function(ua){aa(D,{success:function(){h(m);E.messagesLoading?E.queued=!0:u()},complete:function(){window.vBulletin.loadingIndicator.hide()}})}})})}function W(e){function a(){if("fixed"==c.css("position")){h.removeClass("h-hide");
var m=c.outerHeight()-30;h.css("height",m+"px")}else h.addClass("h-hide")}var d=e+"-replacement",c=b("."+e),h=b("."+d);0==h.length&&(h=b("<div />").addClass(d).insertAfter(c));b(a);b(document).off("click",a).on("click",a);vBulletin.Responsive.Debounce.registerCallback(a);CKEDITOR.on("instanceReady",function(m){a();m.editor.on("focus",function(){setTimeout(function(){a()},0)})});c.on("event-js-element-resize",a)}var q=b(".js-pmchat__container"),N=b(".js-pmchat__participants"),H=q.find(".js-pmchat__thread-container"),
k=q.find("form"),x=q.find(".js-pmchat__data");q=parseInt(x.data("pmchannelid"),10);var D=parseInt(x.data("parentid"),10),w=parseInt(x.data("pm_messageid"),10),M=parseInt(x.data("to_userid"),10),K=x.data("pm_title"),I=0,ca=0,Y=b(".js-pmchat__insert-marker"),l=H.find(".js-pmchat__thread-placeholder"),f,n=!1;q!=D&&0<w||(n=!0);var y=0,F,z=Date.now(),v,p=V.get("pmchat_chat_polling_min_interval")||1,r=V.get("pmchat_chat_polling_max_interval")||30;r<p&&(q=r,r=p,p=q);var t=v=(10*p+1*r)/11;var O=vBulletin.options.get("pmchat_chat_polling_idle_timeout")||
300,U=0,S=9,T=[];for(q=0;10>q;++q)T[q]=0;var E={messagesLoading:!1,queued:!1},da=!1,sa=b(".js-pmchat__header"),ka=b(".js-participants-collapser-ui"),la=b(".js-participants-toggle-arrow"),fa=b(".js-participants-collapsible"),ea=fa.find(".js-vbscroller-wrapper"),ma=b(".js-participants-show-add-recipients-ui"),J=b(".js-participants-add-recipients-wrapper"),ra=k.find(".js-wrapper-contententry_title"),ja=k.find(".js-wrapper-contententry__msgRecipients");new vBulletin_Autocomplete(b(".privatemessage_author"),
{apiClass:"user",delimiter:" ; "});b(".js-pm-content-entry-container .js-pmchat-submit").off("click").on("click",function(e){function a(c,h,m){b("<input>").attr({type:"hidden",name:h,value:m}).appendTo(c)}var d=b(this);d.prop("disabled",!0);z=Date.now();n?(0==k.find('input[name="msgRecipients"]').length&&M?(console.log({msg:"sentto input added with prefill:",to_userid:M}),a(k,"sentto[]",M)):console.log({msg:'User editable input[name="msgRecipients"] was found. Prefilled sentto skipped.'}),0==k.find('input[name="title"]').length?
(console.log({msg:"title input added with prefill:",pm_title:K}),a(k,"title",K)):console.log({msg:'User editable input[name="title"] was found. Prefilled title skipped.'})):(e=k.find('input[name="respondto"]'),0<e.length?e.val(w):a(k,"respondto",w),0==k.find('input[name="msgtype"]').length&&a(k,"msgtype","message"));n&&l.addClass("h-hide");vBulletin.loadingIndicator.show();vBulletin.AJAX({call:"/create-content/private-message",data:k.serialize(),success:function(c){c.nodeId&&(c=parseInt(c.nodeId,
10),n&&(k.find('input[name="parentid"]').val(c),x.data("parentid",c),x.data("pm_messageid",c),x.attr("data-parentid",c),x.attr("data-pm_messageid",c),D=w=c,n=!1,Z(c)),console.log("==================NEW MESSAGE POSTED, LOADING NEW MESSAGES!"),E.messagesLoading?E.queued=!0:u(c),vBulletin.contentEntryBox.resetForm(k,!1,function(){var h=k.attr("ck-editorid")||b(".js-editor",k).attr("id");h=vBulletin.ckeditor.getEditor(h);vBulletin.hv.reset();h.focus()}))},api_error:vBulletin.hv.resetOnError,complete:function(c){vBulletin.loadingIndicator.hide();
d.prop("disabled",!1)}});return!1});q="a:not('.js-pmchat-ignoreanchor')";var ta=`.js-namecard-html ${q}`;V.get("usenamecard")&&(q+=":not([data-vbnamecard])",b("body").on("click",ta,R));H.on("click",q,R);N.on("click",q,R);b("body").on("click","a.js-pmchat-ignoreanchor",function(e){e.preventDefault()});ka.off("click").on("click",ba);0<ma.length&&0<J.length&&L();b(".js-pm-content-entry-container .js-button").enable();g();G();(function(){b(document).on("click keypress scroll",function(a){da=!0});var e=
k.attr("ck-editorid")||b(".js-editor",k).attr("id");b("#"+e).on("afterInit",function(){var a=vBulletin.ckeditor.getEditor(e);a.on("contentDom",function(){function d(){da=!0}var c=a.editable();null!=c&&(c.attachListener(c,"keypress",d),c.attachListener(c,"click",d),c.attachListener(c,"focus",d))})})})();window.setTimeout(function(){var e=k.attr("ck-editorid")||b(".js-editor",k).attr("id");b("#"+e).on("afterInit",function(){var a=vBulletin.ckeditor.getEditor(e);if(a){console.log("Setting predefined starter PM text: "+
x.data("pm_textprefill"));var d=x.data("pm_textprefill");d&&(d+="&nbsp;");a.setData(d,function(){vBulletin.ckeditor.fixTableFunctionality.call(vBulletin.ckeditor,{},a);var c=ja.find(".autocompleteHelper");0<c.length?c.trigger("focus"):a.focus();d&&(c=a.createRange(),c.moveToPosition(c.root,CKEDITOR.POSITION_BEFORE_END),a.getSelection().selectRanges([c]));g()})}else console.log("Editor not found, cannot set predefined starter PM text")})},0);W("js-pm-content-entry-container");W("js-pmchat__header");
vBulletin.ready("pushnotification").then(e=>{e=new BroadcastChannel("vb_push_privatemessage");b(e).on("message",a=>{a=a.originalEvent;const d=a.data||{};a.origin==location.origin&&w==(d.starter||0)&&(f&&f.dialog("instance")?(P(),f.dialog("close")):G())})});(function(){var e=b("#debug-information");if(1==e.length){function a(){b("body").is(".l-xsmall")?e.appendTo("body"):e.insertBefore(".js-pm-content-entry-container")}a();vBulletin.Responsive.Debounce.registerCallback(a)}})()}var oa=pageData.baseurl_pmchat;
(function(){b(function(){b("body").off("click",".js-pmchat-link").on("click",".js-pmchat-link",function(u){u.preventDefault();u={url:b(this).attr("href")};ia(u);return!1});var g=b(".js-pmchat__dropdown");0<g.length?g.attr("data-initialized")?console.log("PM Dropdown already initialized. Skipping re-init."):(console.log("Initializing PM Dropdown!"),g.attr("data-initialized",!0),pa()):console.log("PM Dropdown not detected, skipping init.");g=b(".js-pmchat__container");0<g.length?g.attr("data-initialized")?
console.log("PM Chat window already initialized. Skipping re-init."):(console.log("Initializing PM Chat window!"),g.attr("data-initialized",!0),qa()):console.log("PM Chat window not detected, skipping init.")})})()})(jQuery,vBulletin,vBulletin.options);
