(function(e){"use strict";if(typeof define==="function"&&define.amd){define(["jquery"],e)}else{e(jQuery)}})(function(e){"use strict";function r(t,n){var i=function(){},s=this,o={autoSelectFirst:false,appendTo:document.body,serviceUrl:null,lookup:null,onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},formatResult:r.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:false,onSearchStart:i,onSearchComplete:i,onSearchError:i,containerClass:"autocomplete-suggestions",tabDisabled:false,dataType:"text",currentRequest:null,triggerSelectOnValidInput:true,preventBadQueries:true,lookupFilter:function(e,t,n){return e.value.toLowerCase().indexOf(n)!==-1},paramName:"query",transformResult:function(t){return typeof t==="string"?e.parseJSON(t):t},showNoSuggestionNotice:false,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:false};s.element=t;s.el=e(t);s.suggestions=[];s.badQueries=[];s.selectedIndex=-1;s.currentValue=s.element.value;s.intervalId=0;s.cachedResponse={};s.onChangeInterval=null;s.onChange=null;s.isLocal=false;s.suggestionsContainer=null;s.noSuggestionsContainer=null;s.options=e.extend({},o,n);s.classes={selected:"autocomplete-selected",suggestion:"autocomplete-suggestion"};s.hint=null;s.hintValue="";s.selection=null;s.initialize();s.setOptions(n)}var t=function(){return{escapeRegExChars:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},createNode:function(e){var t=document.createElement("div");t.className=e;t.style.position="absolute";t.style.display="none";return t}}}(),n={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40};r.utils=t;e.Autocomplete=r;r.formatResult=function(e,n){var r="("+t.escapeRegExChars(n)+")";return e.value.replace(new RegExp(r,"gi"),"$1")};r.prototype={killerFn:null,initialize:function(){var t=this,n="."+t.classes.suggestion,i=t.classes.selected,s=t.options,o,u;t.element.setAttribute("autocomplete","off");t.killerFn=function(n){if(e(n.target).closest("."+t.options.containerClass).length===0){t.killSuggestions();t.disableKillerFn()}};t.noSuggestionsContainer=e('
').html(this.options.noSuggestionNotice).get(0);t.suggestionsContainer=r.utils.createNode(s.containerClass);o=e(t.suggestionsContainer);o.appendTo(s.appendTo);if(s.width!=="auto"){o.width(s.width)}o.on("mouseover.autocomplete",n,function(){t.activate(e(this).data("index"))});o.on("mouseout.autocomplete",function(){t.selectedIndex=-1;o.children("."+i).removeClass(i)});o.on("click.autocomplete",n,function(){t.select(e(this).data("index"))});t.fixPositionCapture=function(){if(t.visible){t.fixPosition()}};e(window).on("resize.autocomplete",t.fixPositionCapture);t.el.on("keydown.autocomplete",function(e){t.onKeyPress(e)});t.el.on("keyup.autocomplete",function(e){t.onKeyUp(e)});t.el.on("blur.autocomplete",function(){t.onBlur()});t.el.on("focus.autocomplete",function(){t.onFocus()});t.el.on("change.autocomplete",function(e){t.onKeyUp(e)})},onFocus:function(){var e=this;e.fixPosition();if(e.options.minChars<=e.el.val().length){e.onValueChange()}},onBlur:function(){this.enableKillerFn()},setOptions:function(t){var n=this,r=n.options;e.extend(r,t);n.isLocal=e.isArray(r.lookup);if(n.isLocal){r.lookup=n.verifySuggestionsFormat(r.lookup)}r.orientation=n.validateOrientation(r.orientation,"bottom");e(n.suggestionsContainer).css({"max-height":r.maxHeight+"px",width:r.width+"px","z-index":r.zIndex})},clearCache:function(){this.cachedResponse={};this.badQueries=[]},clear:function(){this.clearCache();this.currentValue="";this.suggestions=[]},disable:function(){var e=this;e.disabled=true;if(e.currentRequest){e.currentRequest.abort()}},enable:function(){this.disabled=false},fixPosition:function(){var t=this,n=e(t.suggestionsContainer),r=n.parent().get(0);if(r!==document.body&&!t.options.forceFixPosition)return;var i=t.options.orientation,s=n.outerHeight(),o=t.el.outerHeight(),u=t.el.offset(),a={top:u.top,left:u.left};if(i=="auto"){var f=e(window).height(),l=e(window).scrollTop(),c=-l+u.top-s,h=l+f-(u.top+o+s);if(Math.max(c,h)===c)i="top";else i="bottom"}if(i==="top")a.top+=-s;else a.top+=o;if(r!==document.body){var p=n.css("opacity"),d;if(!t.visible)n.css("opacity",0).show();d=n.offsetParent().offset();a.top-=d.top;a.left-=d.left;if(!t.visible)n.css("opacity",p).hide()}if(t.options.width==="auto"){a.width=t.el.outerWidth()-2+"px"}n.css(a)},enableKillerFn:function(){var t=this;e(document).on("click.autocomplete",t.killerFn)},disableKillerFn:function(){var t=this;e(document).off("click.autocomplete",t.killerFn)},killSuggestions:function(){var e=this;e.stopKillSuggestions();e.intervalId=window.setInterval(function(){e.hide();e.stopKillSuggestions()},50)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var e=this,t=e.el.val().length,n=e.element.selectionStart,r;if(typeof n==="number"){return n===t}if(document.selection){r=document.selection.createRange();r.moveStart("character",-t);return t===r.text.length}return true},onKeyPress:function(e){var t=this;if(!t.disabled&&!t.visible&&e.which===n.DOWN&&t.currentValue){t.suggest();return}if(t.disabled||!t.visible){return}switch(e.which){case n.ESC:t.el.val(t.currentValue);t.hide();break;case n.RIGHT:if(t.hint&&t.options.onHint&&t.isCursorAtEnd()){t.selectHint();break}return;case n.TAB:if(t.hint&&t.options.onHint){t.selectHint();return};case n.RETURN:if(t.selectedIndex===-1){t.hide();return}t.select(t.selectedIndex);if(e.which===n.TAB&&t.options.tabDisabled===false){return}break;case n.UP:t.moveUp();break;case n.DOWN:t.moveDown();break;default:return}e.stopImmediatePropagation();e.preventDefault()},onKeyUp:function(e){var t=this;if(t.disabled){return}switch(e.which){case n.UP:case n.DOWN:return}clearInterval(t.onChangeInterval);if(t.currentValue!==t.el.val()){t.findBestHint();if(t.options.deferRequestBy>0){t.onChangeInterval=setInterval(function(){t.onValueChange()},t.options.deferRequestBy)}else{t.onValueChange()}}},onValueChange:function(){var t=this,n=t.options,r=t.el.val(),i=t.getQuery(r),s;if(t.selection){t.selection=null;(n.onInvalidateSelection||e.noop).call(t.element)}clearInterval(t.onChangeInterval);t.currentValue=r;t.selectedIndex=-1;if(n.triggerSelectOnValidInput){s=t.findSuggestionIndex(i);if(s!==-1){t.select(s);return}}if(i.length