!function(n){"use strict";var t=function(t,i){var r,u;n.fn.typeahead.defaults;i.scrollBar&&(i.items=100,i.menu='<ul class="typeahead dropdown-menu" style="max-height:220px;overflow:auto;"><\/ul>');r=this;(r.$element=n(t),r.options=n.extend({},n.fn.typeahead.defaults,i),r.$menu=n(r.options.menu).insertAfter(r.$element),r.eventSupported=r.options.eventSupported||r.eventSupported,r.grepper=r.options.grepper||r.grepper,r.highlighter=r.options.highlighter||r.highlighter,r.lookup=r.options.lookup||r.lookup,r.matcher=r.options.matcher||r.matcher,r.render=r.options.render||r.render,r.onSelect=r.options.onSelect||null,r.sorter=r.options.sorter||r.sorter,r.select=r.options.select||r.select,r.source=r.options.source||r.source,r.displayField=r.options.displayField||r.displayField,r.valueField=r.options.valueField||r.valueField,r.autoSelect=r.options.autoSelect||r.autoSelect,r.options.ajax)?(u=r.options.ajax,"string"==typeof u?r.ajax=n.extend({},n.fn.typeahead.defaults.ajax,{url:u}):("string"==typeof u.displayField&&(r.displayField=r.options.displayField=u.displayField),"string"==typeof u.valueField&&(r.valueField=r.options.valueField=u.valueField),r.ajax=n.extend({},n.fn.typeahead.defaults.ajax,u)),r.ajax.url||(r.ajax=null),r.query=""):(r.source=r.options.source,r.ajax=null);r.shown=!1;r.listen()};t.prototype={constructor:t,eventSupported:function(n){var t=n in this.$element;return t||(this.$element.setAttribute(n,"return;"),t="function"==typeof this.$element[n]),t},select:function(){var t=this.$menu.find(".active"),i,n;return t.length&&(i=t.attr("data-value"),n=this.$menu.find(".active a").text(),this.$element.val(this.updater(n)).change(),this.options.onSelect&&this.options.onSelect({value:i,text:n})),this.hide()},updater:function(n){return n},show:function(){var t=n.extend({},this.$element.position(),{height:this.$element[0].offsetHeight}),i;return(this.$menu.css({top:t.top+t.height,left:t.left}),this.options.alignWidth)&&(i=n(this.$element[0]).outerWidth(),this.$menu.css({width:i})),this.$menu.show(),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},ajaxLookup:function(){function i(){this.ajaxToggleLoadClass(!0);this.ajax.xhr&&this.ajax.xhr.abort();var i=this.ajax.preDispatch?this.ajax.preDispatch(t):{query:t};this.ajax.xhr=n.ajax({url:this.ajax.url,data:i,success:n.proxy(this.ajaxSource,this),type:this.ajax.method||"get",dataType:"json",headers:this.ajax.headers||{}});this.ajax.timerId=null}var t=n.trim(this.$element.val());return t===this.query?this:(this.query=t,this.ajax.timerId&&(clearTimeout(this.ajax.timerId),this.ajax.timerId=null),!t||t.length<this.ajax.triggerLength?(this.ajax.xhr&&(this.ajax.xhr.abort(),this.ajax.xhr=null,this.ajaxToggleLoadClass(!1)),this.shown?this.hide():this):(this.ajax.timerId=setTimeout(n.proxy(i,this),this.ajax.timeout),this))},ajaxSource:function(n){this.ajaxToggleLoadClass(!1);var i,t=this;if(t.ajax.xhr)return t.ajax.preProcess&&(n=t.ajax.preProcess(n)),t.ajax.data=n,i=t.grepper(t.ajax.data)||[],i.length?(t.ajax.xhr=null,t.render(i.slice(0,t.options.items)).show()):t.shown?t.hide():t},ajaxToggleLoadClass:function(n){this.ajax.loadingClass&&this.$element.toggleClass(this.ajax.loadingClass,n)},lookup:function(){var t,n=this;return n.ajax?void n.ajaxer():(n.query=n.$element.val(),n.query&&(t=n.grepper(n.source))?(0==t.length&&(t[0]={id:-21,name:"Result not Found"}),n.render(t.slice(0,n.options.items)).show()):n.shown?n.hide():n)},matcher:function(n){return~n.toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(n){if(this.options.ajax)return n;for(var t,i=[],r=[],u=[];t=n.shift();)t.toLowerCase().indexOf(this.query.toLowerCase())?~t.indexOf(this.query)?r.push(t):u.push(t):i.push(t);return i.concat(r,u)},highlighter:function(n){var t=this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&");return n.replace(new RegExp("("+t+")","ig"),function(n,t){return"<strong>"+t+"<\/strong>"})},render:function(t){var r,i=this,u="string"==typeof i.options.displayField;return t=n(t).map(function(t,f){return"object"==typeof f?(r=u?f[i.options.displayField]:i.options.displayField(f),t=n(i.options.item).attr("data-value",f[i.options.valueField])):(r=f,t=n(i.options.item).attr("data-value",f)),t.find("a").html(i.highlighter(r)),t[0]}),i.autoSelect&&t.first().addClass("active"),this.$menu.html(t),this},grepper:function(t){var r,u,i=this,f="string"==typeof i.options.displayField;if(!(f&&t&&t.length))return null;if(t[0].hasOwnProperty(i.options.displayField))r=n.grep(t,function(n){return u=f?n[i.options.displayField]:i.options.displayField(n),i.matcher(u)});else{if("string"!=typeof t[0])return null;r=n.grep(t,function(n){return i.matcher(n)})}return this.sorter(r)},next:function(){var r=this.$menu.find(".active").removeClass("active"),t=r.next(),i;(t.length||(t=n(this.$menu.find("li")[0])),this.options.scrollBar)&&(i=this.$menu.children("li").index(t),i%8==0&&this.$menu.scrollTop(26*i));t.addClass("active")},prev:function(){var r=this.$menu.find(".active").removeClass("active"),n=r.prev();if(n.length||(n=this.$menu.find("li").last()),this.options.scrollBar){var t=this.$menu.children("li"),u=t.length-1,i=t.index(n);(u-i)%8==0&&this.$menu.scrollTop(26*(i-7))}n.addClass("active")},listen:function(){this.$element.on("focus",n.proxy(this.focus,this)).on("blur",n.proxy(this.blur,this)).on("keypress",n.proxy(this.keypress,this)).on("keyup",n.proxy(this.keyup,this));this.eventSupported("keydown")&&this.$element.on("keydown",n.proxy(this.keydown,this));this.$menu.on("click",n.proxy(this.click,this)).on("mouseenter","li",n.proxy(this.mouseenter,this)).on("mouseleave","li",n.proxy(this.mouseleave,this))},move:function(n){if(this.shown){switch(n.keyCode){case 9:case 13:case 27:n.preventDefault();break;case 38:n.preventDefault();this.prev();break;case 40:n.preventDefault();this.next()}n.stopPropagation()}},keydown:function(t){this.suppressKeyPressRepeat=~n.inArray(t.keyCode,[40,38,9,13,27]);this.move(t)},keypress:function(n){this.suppressKeyPressRepeat||this.move(n)},keyup:function(n){switch(n.keyCode){case 40:case 38:case 16:case 17:case 18:break;case 9:case 13:if(!this.shown)return;this.select();break;case 27:if(!this.shown)return;this.hide();break;default:this.ajax?this.ajaxLookup():this.lookup()}n.stopPropagation();n.preventDefault()},focus:function(){this.focused=!0},blur:function(){this.focused=!1},click:function(n){n.stopPropagation();n.preventDefault();this.select();this.$element.focus()},mouseenter:function(t){this.mousedover=!0;this.$menu.find(".active").removeClass("active");n(t.currentTarget).addClass("active")},mouseleave:function(){this.mousedover=!1;!this.focused&&this.shown&&this.hide()},destroy:function(){this.$element.off("focus",n.proxy(this.focus,this)).off("blur",n.proxy(this.blur,this)).off("keypress",n.proxy(this.keypress,this)).off("keyup",n.proxy(this.keyup,this));this.eventSupported("keydown")&&this.$element.off("keydown",n.proxy(this.keydown,this));this.$menu.off("click",n.proxy(this.click,this)).off("mouseenter","li",n.proxy(this.mouseenter,this)).off("mouseleave","li",n.proxy(this.mouseleave,this));this.$element.removeData("typeahead")}};n.fn.typeahead=function(i){return this.each(function(){var u=n(this),r=u.data("typeahead"),f="object"==typeof i&&i;r||u.data("typeahead",r=new t(this,f));"string"==typeof i&&r[i]()})};n.fn.typeahead.defaults={source:[],items:10,scrollBar:!1,alignWidth:!0,menu:'<ul class="typeahead dropdown-menu"><\/ul>',item:'<li><a href="#"><\/a><\/li>',valueField:"id",displayField:"name",autoSelect:!0,onSelect:function(){},ajax:{url:null,timeout:300,method:"get",triggerLength:1,loadingClass:null,preDispatch:null,preProcess:null}};n.fn.typeahead.Constructor=t;n(function(){n("body").on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(t){var i=n(this);i.data("typeahead")||(t.preventDefault(),i.typeahead(i.data()))})})}(window.jQuery)