/*=======================================================================*\
|| ###################################################################### ||
|| # 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   # ||
|| ###################################################################### ||
\*========================================================================*/
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,[]);var vBulletin_Autocomplete=function(V,c){var B=$(V),b=c.apiClass||null,L=c.apiFunction||"getAutocomplete",e=c.delay||500,d=c.minLength||3,Z=c.maxItems||false,F=B.attr("name")||"autocompleteElements",J=c.containerClass||"entry-field",K=c.placeholderText,P=((typeof c.autoFocus!="undefined")?c.autoFocus:false),G=((typeof c.appendTo!="undefined")?c.appendTo:"body"),g=c.delimiter||",",N=[],A=B.parent(".autocomplete-container"),h=A.find(".autocompleteHelper"),a=false,T=false,R=B.siblings(".autocomplete-box"),I=c.beforeAdd||false,H=c.afterAdd||false,E=c.beforeDelete||false,C=c.afterDelete||false,O=this,Y=c.editorContext||null,X=function(){if(A.length==0){B.wrap('<div class="autocomplete-container b-form-input__input" />');A=B.parent(".autocomplete-container");A.addClass(J).on("mousedown",function(n){var i=this;setTimeout(function(){var o=$(".autocompleteHelper:visible",i);if(o.length>0){o[0].focus()}},10);return false})}if(R.length==0){R=$("<div />").addClass("autocomplete-box").insertBefore(B)}if(h.length==0){h=$('<input type="text" name="autocompleteHelper" />').addClass("autocompleteHelper b-form-input__input b-form-input__input--hide-clear-button").attr("placeholder",function(){return K?K:null}).attr("maxlength",function(){return B.attr("maxlength")?B.attr("maxlength"):null}).insertAfter(R)}h.attr("tabindex",B.attr("tabindex")||0);h.off("keydown").on("keydown",function(n){if(n.which==13){var i=$(n.target).val();if(i.length>=d){S(i,true,n)}}});h.off("blur").on("blur",function(i){a=window.setTimeout(function(){if(!T){var n=h.val();if(n.length>=d){S(n,true,i)}}T=false;a=false},200)});h.off("focus").on("focus",function(i){T=a?true:false;return false});var k=["font-family","font-size","font-weight","font-style","color","line-height","height"];var l;for(l=0;l<k.length;++l){A.css(k[l],B.css(k[l]))}var j='<input type="hidden" name="'+F+'"';if(B.attr("id")){j+=' id="'+B.attr("id")+'"'}if(B.attr("class")){j+=' class="'+B.attr("class")+'"'}if(B.attr("data-value")){var m=B.attr("data-value").split(",")}j+=" />";B.replaceWith(j);B=A.find('[name="'+F+'"]');h.autocomplete({autoFocus:P,appendTo:G,delay:e,minLength:d,search:function(i,n){console.log("searching for "+this.value)},source:function(i,n){console.log("getting source for "+i.term);vBulletin.AJAX({url:vBulletin.getAjaxBaseurl()+"/ajax/api/"+b+"/"+L,data:({searchStr:i.term}),success:function(p){console.log("got source for "+i.term+":");if(p&&$.isArray(p.suggestions)){var o=[];$.each(p.suggestions,function(q,r){if(Y&&Y.type=="tags"){o.push({label:r.title,value:pageData.userid})}else{if(typeof r.id!=="undefined"&&r.id){o.push({label:r.title,value:r.value,id:r.id})}else{o.push({label:r.title,value:r.value})}}});n(o)}else{console.log("/ajax/api/"+b+"/"+L+" successful, but response was not an array");openAlertDialog({title:vBulletin.phrase.get("error"),message:vBulletin.phrase.get("invalid_server_response_please_try_again"),iconType:"error"})}},error_phrase:"error_getting_suggestions"})},select:function(n,i){O.addElement(i.item.label,i.item.value,i.item);h.val("");n.preventDefault()},focus:function(n,i){h.val(i.item.label);n.preventDefault()},open:function(q){var o=$(q.target),n=o.autocomplete("instance"),p=n.menu.element,i=parseInt($(".dialog-box").css("z-index"),10);p.css("z-index",i+1)}});R.delegate(".element-x","click",function(q){var o=$(this).closest(".autocomplete");var n=o.find(".element-text").text().toLowerCase();var i=[];var p=false;$(N).each(function(r,s){if(s.label.toLowerCase()==n){p=s}else{i.push(s)}});if(typeof E=="function"){if(!E.call(this,p.label,p.data)){return false}}N=i;o.remove();f();if(typeof C=="function"){C.call(this,p.label,p.data)}});A.off("click").on("click",function(i){if(!$(i.target).hasClass("ui-autocomplete-input")){$(".ui-autocomplete-input",$(this)).focus()}return false});if(m){W.call(this,m)}},M=function(n,m,l){if(n==""){return false}if(typeof I=="function"){if(!I.call(this,n,m)){return false}}var k=true;$(N).each(function(p,q){if(q.label==n){k=false}});if(!k){return false}if(Z){if(N.length>=Z){return false}}var o=$("<div />").addClass("element-x b-icon b-icon__x-circle").text("X");var i=$("<div />").addClass("element-text").text(n);var j=$("<div />").addClass("autocomplete").append(i).append(o).appendTo(R);N.push({label:n,value:m});f();if(typeof H=="function"){H.call(this,n,m,l)}R.show();return true},W=function(l){var j=l.length,k;for(k=0;k<j;++k){M(l[k])}},U=function(i){Q();W(i)},Q=function(){R.html("");h.val("");N=[];f()},f=function(){var i=[];$(N).each(function(j,k){i.push(k.label)});B.val(i.join(g))},D=function(){return d},S=function(k,i,j){if(Y){switch(Y.type){case"tags":Y.context.addTag(k);break;default:break}}else{O.addElement(k,k);h.val("")}if(typeof i!=="undefined"&&typeof j!=="undefined"){j.preventDefault();return false}};X.call(this);this.addElement=function(k,j,i){return M.call(this,k,j,i)};this.addElements=function(i){W.call(this,i)};this.setElements=function(i){U.call(this,i)};this.getElements=function(){return N};this.getLabels=function(){var i=[];$(N).each(function(j,k){i.push(k.label)});return i};this.getValues=function(){var i=[];$(N).each(function(j,k){i.push(k.value)});return i};this.getInputField=function(){return h};this.clearElements=function(){return Q.call(this)};this.countElements=function(){return $(N).length};this.getMinLength=function(){return D()};this.close=function(){h.val("");h.autocomplete("close")}};