/*
 * typeahead.js 0.10.5
 * https://github.com/twitter/typeahead.js
 * Copyright 2013-2014 Twitter, Inc. and other contributors; Licensed MIT
 */
(function(B){var Q=function(){return{isMsie:function(){return/(msie|trident)/i.test(navigator.userAgent)?navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2]:false;
},isBlankString:function(U){return !U||/^\s*$/.test(U);
},escapeRegExChars:function(U){return U.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");
},isString:function(U){return typeof U==="string";
},isNumber:function(U){return typeof U==="number";
},isArray:B.isArray,isFunction:B.isFunction,isObject:B.isPlainObject,isUndefined:function(U){return typeof U==="undefined";
},toStr:function T(U){return Q.isUndefined(U)||U===null?"":U+"";
},bind:B.proxy,each:function(W,U){B.each(W,V);
function V(X,Y){return U(Y,X);
}},map:B.map,filter:B.grep,every:function(V,W){var U=true;
if(!V){return U;
}B.each(V,function(X,Y){if(!(U=W.call(null,Y,X,V))){return false;
}});
return !!U;
},some:function(V,W){var U=false;
if(!V){return U;
}B.each(V,function(X,Y){if(U=W.call(null,Y,X,V)){return false;
}});
return !!U;
},mixin:B.extend,getUniqueId:function(){var U=0;
return function(){return U++;
};
}(),templatify:function S(V){return B.isFunction(V)?V:U;
function U(){return String(V);
}},defer:function(U){setTimeout(U,0);
},debounce:function(W,Y,V){var X,U;
return function(){var c=this,b=arguments,a,Z;
a=function(){X=null;
if(!V){U=W.apply(c,b);
}};
Z=V&&!X;
clearTimeout(X);
X=setTimeout(a,Y);
if(Z){U=W.apply(c,b);
}return U;
};
},throttle:function(Z,b){var X,W,a,U,Y,V;
Y=0;
V=function(){Y=new Date();
a=null;
U=Z.apply(X,W);
};
return function(){var c=new Date(),d=b-(c-Y);
X=this;
W=arguments;
if(d<=0){clearTimeout(a);
a=null;
Y=c;
U=Z.apply(X,W);
}else{if(!a){a=setTimeout(V,d);
}}return U;
};
},noop:function(){}};
}();
var L="0.10.5";
var N=function(){return{nonword:S,whitespace:T,obj:{nonword:U(S),whitespace:U(T)}};
function T(V){V=Q.toStr(V);
return V?V.split(/\s+/):[];
}function S(V){V=Q.toStr(V);
return V?V.split(/\W+/):[];
}function U(W){return function V(){var X=[].slice.call(arguments,0);
return function Y(a){var Z=[];
Q.each(X,function(b){Z=Z.concat(W(Q.toStr(a[b])));
});
return Z;
};
};
}}();
var D=function(){function T(a){this.maxSize=Q.isNumber(a)?a:100;
this.reset();
if(this.maxSize<=0){this.set=this.get=B.noop;
}}Q.mixin(T.prototype,{set:function Z(a,d){var c=this.list.tail,b;
if(this.size>=this.maxSize){this.list.remove(c);
delete this.hash[c.key];
}if(b=this.hash[a]){b.val=d;
this.list.moveToFront(b);
}else{b=new U(a,d);
this.list.add(b);
this.hash[a]=b;
this.size++;
}},get:function V(a){var b=this.hash[a];
if(b){this.list.moveToFront(b);
return b.val;
}},reset:function X(){this.size=0;
this.hash={};
this.list=new W();
}});
function W(){this.head=this.tail=null;
}Q.mixin(W.prototype,{add:function Y(a){if(this.head){a.next=this.head;
this.head.prev=a;
}this.head=a;
this.tail=this.tail||a;
},remove:function S(a){a.prev?a.prev.next=a.next:this.head=a.next;
a.next?a.next.prev=a.prev:this.tail=a.prev;
},moveToFront:function(a){this.remove(a);
this.add(a);
}});
function U(a,b){this.key=a;
this.val=b;
this.prev=this.next=null;
}return T;
}();
var O=function(){var S,T;
try{S=window.localStorage;
S.setItem("~~~","!");
S.removeItem("~~~");
}catch(X){S=null;
}function V(Z){this.prefix=["__",Z,"__"].join("");
this.ttlKey="__ttl__";
this.keyMatcher=new RegExp("^"+Q.escapeRegExChars(this.prefix));
}if(S&&window.JSON){T={_prefix:function(Z){return this.prefix+Z;
},_ttlKey:function(Z){return this._prefix(Z)+this.ttlKey;
},get:function(Z){if(this.isExpired(Z)){this.remove(Z);
}return Y(S.getItem(this._prefix(Z)));
},set:function(a,b,Z){if(Q.isNumber(Z)){S.setItem(this._ttlKey(a),W(U()+Z));
}else{S.removeItem(this._ttlKey(a));
}return S.setItem(this._prefix(a),W(b));
},remove:function(Z){S.removeItem(this._ttlKey(Z));
S.removeItem(this._prefix(Z));
return this;
},clear:function(){var b,a,c=[],Z=S.length;
for(b=0;
b<Z;
b++){if((a=S.key(b)).match(this.keyMatcher)){c.push(a.replace(this.keyMatcher,""));
}}for(b=c.length;
b--;
){this.remove(c[b]);
}return this;
},isExpired:function(a){var Z=Y(S.getItem(this._ttlKey(a)));
return Q.isNumber(Z)&&U()>Z?true:false;
}};
}else{T={get:Q.noop,set:Q.noop,remove:Q.noop,clear:Q.noop,isExpired:Q.noop};
}Q.mixin(V.prototype,T);
return V;
function U(){return new Date().getTime();
}function W(Z){return JSON.stringify(Q.isUndefined(Z)?null:Z);
}function Y(Z){return JSON.parse(Z);
}}();
var P=function(){var U=0,W={},S=6,V=new D(10);
function Z(a){a=a||{};
this.cancelled=false;
this.lastUrl=null;
this._send=a.transport?X(a.transport):B.ajax;
this._get=a.rateLimiter?a.rateLimiter(this._get):this._get;
this._cache=a.cache===false?new D(0):V;
}Z.setMaxPendingRequests=function T(a){S=a;
};
Z.resetCache=function Y(){V.reset();
};
Q.mixin(Z.prototype,{_get:function(e,h,b){var g=this,f;
if(this.cancelled||e!==this.lastUrl){return ;
}if(f=W[e]){f.done(d).fail(c);
}else{if(U<S){U++;
W[e]=this._send(e,h).done(d).fail(c).always(a);
}else{this.onDeckRequestArgs=[].slice.call(arguments,0);
}}function d(i){b&&b(null,i);
g._cache.set(e,i);
}function c(){b&&b(true);
}function a(){U--;
delete W[e];
if(g.onDeckRequestArgs){g._get.apply(g,g.onDeckRequestArgs);
g.onDeckRequestArgs=null;
}}},get:function(b,d,a){var c;
if(Q.isFunction(d)){a=d;
d={};
}this.cancelled=false;
this.lastUrl=b;
if(c=this._cache.get(b)){Q.defer(function(){a&&a(null,c);
});
}else{this._get(b,d,a);
}return !!c;
},cancel:function(){this.cancelled=true;
}});
return Z;
function X(a){return function b(d,g){var c=B.Deferred();
a(d,g,f,e);
return c;
function f(h){Q.defer(function(){c.resolve(h);
});
}function e(h){Q.defer(function(){c.reject(h);
});
}};
}}();
var I=function(){function S(b){b=b||{};
if(!b.datumTokenizer||!b.queryTokenizer){B.error("datumTokenizer and queryTokenizer are both required");
}this.datumTokenizer=b.datumTokenizer;
this.queryTokenizer=b.queryTokenizer;
this.reset();
}Q.mixin(S.prototype,{bootstrap:function U(b){this.datums=b.datums;
this.trie=b.trie;
},add:function(c){var b=this;
c=Q.isArray(c)?c:[c];
Q.each(c,function(d){var f,e;
f=b.datums.push(d)-1;
e=W(b.datumTokenizer(d));
Q.each(e,function(g){var j,i,h;
j=b.trie;
i=g.split("");
while(h=i.shift()){j=j.children[h]||(j.children[h]=Z());
j.ids.push(f);
}});
});
},get:function T(d){var b=this,e,c;
e=W(this.queryTokenizer(d));
Q.each(e,function(f){var j,i,h,g;
if(c&&c.length===0){return false;
}j=b.trie;
i=f.split("");
while(j&&(h=i.shift())){j=j.children[h];
}if(j&&i.length===0){g=j.ids.slice(0);
c=c?X(c,g):g;
}else{c=[];
return false;
}});
return c?Q.map(V(c),function(f){return b.datums[f];
}):[];
},reset:function Y(){this.datums=[];
this.trie=Z();
},serialize:function a(){return{datums:this.datums,trie:this.trie};
}});
return S;
function W(b){b=Q.filter(b,function(c){return !!c;
});
b=Q.map(b,function(c){return c.toLowerCase();
});
return b;
}function Z(){return{ids:[],children:{}};
}function V(f){var c={},e=[];
for(var d=0,b=f.length;
d<b;
d++){if(!c[f[d]]){c[f[d]]=true;
e.push(f[d]);
}}return e;
}function X(g,e){var c=0,f=0,i=[];
g=g.sort(h);
e=e.sort(h);
var d=g.length,b=e.length;
while(c<d&&f<b){if(g[c]<e[f]){c++;
}else{if(g[c]>e[f]){f++;
}else{i.push(g[c]);
c++;
f++;
}}}return i;
function h(k,j){return k-j;
}}}();
var F=function(){return{local:U,prefetch:S,remote:T};
function U(V){return V.local||null;
}function S(X){var W,V;
V={url:null,thumbprint:"",ttl:24*60*60*1000,filter:null,ajax:{}};
if(W=X.prefetch||null){W=Q.isString(W)?{url:W}:W;
W=Q.mixin(V,W);
W.thumbprint=L+W.thumbprint;
W.ajax.type=W.ajax.type||"GET";
W.ajax.dataType=W.ajax.dataType||"json";
!W.url&&B.error("prefetch requires url to be set");
}return W;
}function T(Z){var X,Y;
Y={url:null,cache:true,wildcard:"%QUERY",replace:null,rateLimitBy:"debounce",rateLimitWait:300,send:null,filter:null,ajax:{}};
if(X=Z.remote||null){X=Q.isString(X)?{url:X}:X;
X=Q.mixin(Y,X);
X.rateLimiter=/^throttle$/i.test(X.rateLimitBy)?W(X.rateLimitWait):V(X.rateLimitWait);
X.ajax.type=X.ajax.type||"GET";
X.ajax.dataType=X.ajax.dataType||"json";
delete X.rateLimitBy;
delete X.rateLimitWait;
!X.url&&B.error("remote requires url to be set");
}return X;
function V(a){return function(b){return Q.debounce(b,a);
};
}function W(a){return function(b){return Q.throttle(b,a);
};
}}}();
(function(d){var S,Y;
S=d.Bloodhound;
Y={data:"data",protocol:"protocol",thumbprint:"thumbprint"};
d.Bloodhound=U;
function U(l){if(!l||!l.local&&!l.prefetch&&!l.remote){B.error("one of local, prefetch, or remote is required");
}this.limit=l.limit||5;
this.sorter=b(l.sorter);
this.dupDetector=l.dupDetector||a;
this.local=F.local(l);
this.prefetch=F.prefetch(l);
this.remote=F.remote(l);
this.cacheKey=this.prefetch?this.prefetch.cacheKey||this.prefetch.url:null;
this.index=new I({datumTokenizer:l.datumTokenizer,queryTokenizer:l.queryTokenizer});
this.storage=this.cacheKey?new O(this.cacheKey):null;
}U.noConflict=function k(){d.Bloodhound=S;
return U;
};
U.tokenizers=N;
Q.mixin(U.prototype,{_loadPrefetch:function V(q){var m=this,p,l;
if(p=this._readFromStorage(q.thumbprint)){this.index.bootstrap(p);
l=B.Deferred().resolve();
}else{l=B.ajax(q.url,q.ajax).done(n);
}return l;
function n(o){m.clear();
m.add(q.filter?q.filter(o):o);
m._saveToStorage(m.index.serialize(),q.thumbprint,q.ttl);
}},_getFromRemote:function X(q,l){var p=this,n,o;
if(!this.transport){return ;
}q=q||"";
o=encodeURIComponent(q);
n=this.remote.replace?this.remote.replace(this.remote.url,q):this.remote.url.replace(this.remote.wildcard,o);
return this.transport.get(n,this.remote.ajax,m);
function m(r,s){r?l([]):l(p.remote.filter?p.remote.filter(s):s);
}},_cancelLastRemoteRequest:function j(){this.transport&&this.transport.cancel();
},_saveToStorage:function e(n,m,l){if(this.storage){this.storage.set(Y.data,n,l);
this.storage.set(Y.protocol,location.protocol,l);
this.storage.set(Y.thumbprint,m,l);
}},_readFromStorage:function i(m){var l={},n;
if(this.storage){l.data=this.storage.get(Y.data);
l.protocol=this.storage.get(Y.protocol);
l.thumbprint=this.storage.get(Y.thumbprint);
}n=l.thumbprint!==m||l.protocol!==location.protocol;
return l.data&&!n?l.data:null;
},_initialize:function T(){var o=this,n=this.local,l;
l=this.prefetch?this._loadPrefetch(this.prefetch):B.Deferred().resolve();
n&&l.done(m);
this.transport=this.remote?new P(this.remote):null;
return this.initPromise=l.promise();
function m(){o.add(Q.isFunction(n)?n():n);
}},initialize:function T(l){return !this.initPromise||l?this._initialize():this.initPromise;
},add:function Z(l){this.index.add(l);
},get:function g(p,l){var n=this,o=[],m=false;
o=this.index.get(p);
o=this.sorter(o).slice(0,this.limit);
o.length<this.limit?m=this._getFromRemote(p,q):this._cancelLastRemoteRequest();
if(!m){(o.length>0||!this.transport)&&l&&l(o);
}function q(s){var r=o.slice(0);
Q.each(s,function(u){var t;
t=Q.some(r,function(v){return n.dupDetector(u,v);
});
!t&&r.push(u);
return r.length<n.limit;
});
l&&l(n.sorter(r));
}},clear:function c(){this.index.reset();
},clearPrefetchCache:function W(){this.storage&&this.storage.clear();
},clearRemoteCache:function f(){this.transport&&P.resetCache();
},ttAdapter:function h(){return Q.bind(this.get,this);
}});
return U;
function b(m){return Q.isFunction(m)?l:n;
function l(o){return o.sort(m);
}function n(o){return o;
}}function a(){return false;
}})(this);
var H=function(){return{wrapper:'<span class="twitter-typeahead"></span>',dropdown:'<span class="tt-dropdown-menu"></span>',dataset:'<div class="tt-dataset-%CLASS%"></div>',suggestions:'<span class="tt-suggestions"></span>',suggestion:'<div class="tt-suggestion"></div>'};
}();
var G=function(){var S={wrapper:{position:"relative",display:"inline-block"},hint:{position:"absolute",top:"0",left:"0",borderColor:"transparent",boxShadow:"none",opacity:"1"},input:{position:"relative",verticalAlign:"top",backgroundColor:"transparent"},inputWithNoHint:{position:"relative",verticalAlign:"top"},dropdown:{position:"absolute",top:"100%",left:"0",zIndex:"100",display:"none"},suggestions:{display:"block"},suggestion:{whiteSpace:"nowrap",cursor:"pointer"},suggestionChild:{whiteSpace:"normal"},ltr:{left:"0",right:"auto"},rtl:{left:"auto",right:" 0"}};
if(Q.isMsie()){Q.mixin(S.input,{backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"});
}if(Q.isMsie()&&Q.isMsie()<=7){Q.mixin(S.input,{marginTop:"-1px"});
}return S;
}();
var A=function(){var T="typeahead:";
function S(U){if(!U||!U.el){B.error("EventBus initialized without el");
}this.$el=B(U.el);
}Q.mixin(S.prototype,{trigger:function(V){var U=[].slice.call(arguments,1);
this.$el.trigger(T+V,U);
}});
return S;
}();
var E=function(){var U=/\s+/,Y=S();
return{onSync:Z,onAsync:T,off:V,trigger:W};
function a(g,e,c,d){var f;
if(!c){return this;
}e=e.split(U);
c=d?b(c,d):c;
this._callbacks=this._callbacks||{};
while(f=e.shift()){this._callbacks[f]=this._callbacks[f]||{sync:[],async:[]};
this._callbacks[f][g].push(c);
}return this;
}function T(e,c,d){return a.call(this,"async",e,c,d);
}function Z(e,c,d){return a.call(this,"sync",e,c,d);
}function V(c){var d;
if(!this._callbacks){return this;
}c=c.split(U);
while(d=c.shift()){delete this._callbacks[d];
}return this;
}function W(d){var e,f,c,g,h;
if(!this._callbacks){return this;
}d=d.split(U);
c=[].slice.call(arguments,1);
while((e=d.shift())&&(f=this._callbacks[e])){g=X(f.sync,this,[e].concat(c));
h=X(f.async,this,[e].concat(c));
g()&&Y(h);
}return this;
}function X(f,e,d){return c;
function c(){var j;
for(var h=0,g=f.length;
!j&&h<g;
h+=1){j=f[h].apply(e,d)===false;
}return !j;
}}function S(){var d;
if(window.setImmediate){d=function e(f){setImmediate(function(){f();
});
};
}else{d=function c(f){setTimeout(function(){f();
},0);
};
}return d;
}function b(d,c){return d.bind?d.bind(c):function(){d.apply(c,[].slice.call(arguments,0));
};
}}();
var C=function(V){var U={node:null,pattern:null,tagName:"strong",className:null,wordsOnly:false,caseSensitive:false};
return function T(Z){var W;
Z=Q.mixin({},U,Z);
if(!Z.node||!Z.pattern){return ;
}Z.pattern=Q.isArray(Z.pattern)?Z.pattern:[Z.pattern];
W=S(Z.pattern,Z.caseSensitive,Z.wordsOnly);
X(Z.node,Y);
function Y(d){var b,a,c;
if(b=W.exec(d.data)){c=V.createElement(Z.tagName);
Z.className&&(c.className=Z.className);
a=d.splitText(b.index);
a.splitText(b[0].length);
c.appendChild(a.cloneNode(true));
d.parentNode.replaceChild(c,a);
}return !!b;
}function X(d,e){var b,c=3;
for(var a=0;
a<d.childNodes.length;
a++){b=d.childNodes[a];
if(b.nodeType===c){a+=e(b)?1:0;
}else{X(b,e);
}}}};
function S(Z,X,c){var b=[],a;
for(var Y=0,W=Z.length;
Y<W;
Y++){b.push(Q.escapeRegExChars(Z[Y]));
}a=c?"\\b("+b.join("|")+")\\b":"("+b.join("|")+")";
return X?new RegExp(a):new RegExp(a,"i");
}}(window.document);
var K=function(){var o;
o={9:"tab",27:"esc",37:"left",39:"right",13:"enter",38:"up",40:"down"};
function l(x){var v=this,w,s,u,t;
x=x||{};
if(!x.input){B.error("input is missing");
}w=Q.bind(this._onBlur,this);
s=Q.bind(this._onFocus,this);
u=Q.bind(this._onKeydown,this);
t=Q.bind(this._onInput,this);
this.$hint=B(x.hint);
this.$input=B(x.input).on("blur.tt",w).on("focus.tt",s).on("keydown.tt",u);
if(this.$hint.length===0){this.setHint=this.getHint=this.clearHint=this.clearHintIfInvalid=Q.noop;
}if(!Q.isMsie()){this.$input.on("input.tt",t);
}else{this.$input.on("keydown.tt keypress.tt cut.tt paste.tt",function(y){if(o[y.which||y.keyCode]){return ;
}Q.defer(Q.bind(v._onInput,v,y));
});
}this.query=this.$input.val();
this.$overflowHelper=e(this.$input);
}l.normalizeQuery=function(s){return(s||"").replace(/^\s*/g,"").replace(/\s{2,}/g," ");
};
Q.mixin(l.prototype,E,{_onBlur:function c(){this.resetInputValue();
this.trigger("blurred");
},_onFocus:function W(){this.trigger("focused");
},_onKeydown:function q(s){var t=o[s.which||s.keyCode];
this._managePreventDefault(t,s);
if(t&&this._shouldTrigger(t,s)){this.trigger(t+"Keyed",s);
}},_onInput:function T(){this._checkInputValue();
},_managePreventDefault:function Y(w,v){var u,t,s;
switch(w){case"tab":t=this.getHint();
s=this.getInputValue();
u=t&&t!==s&&!f(v);
break;
case"up":case"down":u=!f(v);
break;
default:u=false;
}u&&v.preventDefault();
},_shouldTrigger:function r(u,t){var s;
switch(u){case"tab":s=!f(t);
break;
default:s=true;
}return s;
},_checkInputValue:function Z(){var s,t,u;
s=this.getInputValue();
t=b(s,this.query);
u=t?this.query.length!==s.length:false;
this.query=s;
if(!t){this.trigger("queryChanged",this.query);
}else{if(u){this.trigger("whitespaceChanged",this.query);
}}},focus:function h(){this.$input.focus();
},blur:function m(){this.$input.blur();
},getQuery:function j(){return this.query;
},setQuery:function i(s){this.query=s;
},getInputValue:function X(){return this.$input.val();
},setInputValue:function a(t,s){this.$input.val(t);
s?this.clearHint():this._checkInputValue();
},resetInputValue:function V(){this.setInputValue(this.query,true);
},getHint:function U(){return this.$hint.val();
},setHint:function n(s){this.$hint.val(s);
},clearHint:function d(){this.setHint("");
},clearHintIfInvalid:function S(){var v,u,s,t;
v=this.getInputValue();
u=this.getHint();
s=v!==u&&u.indexOf(v)===0;
t=v!==""&&s&&!this.hasOverflow();
!t&&this.clearHint();
},getLanguageDirection:function g(){return(this.$input.css("direction")||"ltr").toLowerCase();
},hasOverflow:function k(){var s=this.$input.width()-2;
this.$overflowHelper.text(this.getInputValue());
return this.$overflowHelper.width()>=s;
},isCursorAtEnd:function(){var t,u,s;
t=this.$input.val().length;
u=this.$input[0].selectionStart;
if(Q.isNumber(u)){return u===t;
}else{if(document.selection){s=document.selection.createRange();
s.moveStart("character",-t);
return t===s.text.length;
}}return true;
},destroy:function p(){this.$hint.off(".tt");
this.$input.off(".tt");
this.$hint=this.$input=this.$overflowHelper=null;
}});
return l;
function e(s){return B('<pre aria-hidden="true"></pre>').css({position:"absolute",visibility:"hidden",whiteSpace:"pre",fontFamily:s.css("font-family"),fontSize:s.css("font-size"),fontStyle:s.css("font-style"),fontVariant:s.css("font-variant"),fontWeight:s.css("font-weight"),wordSpacing:s.css("word-spacing"),letterSpacing:s.css("letter-spacing"),textIndent:s.css("text-indent"),textRendering:s.css("text-rendering"),textTransform:s.css("text-transform")}).insertAfter(s);
}function b(t,s){return l.normalizeQuery(t)===l.normalizeQuery(s);
}function f(s){return s.altKey||s.ctrlKey||s.metaKey||s.shiftKey;
}}();
var R=function(){var T="ttDataset",h="ttValue",b="ttDatum";
function S(i){i=i||{};
i.templates=i.templates||{};
if(!i.source){B.error("missing source");
}if(i.name&&!V(i.name)){B.error("invalid dataset name: "+i.name);
}this.query=null;
this.highlight=!!i.highlight;
this.name=i.name||Q.getUniqueId();
this.source=i.source;
this.displayFn=W(i.display||i.displayKey);
this.templates=X(i.templates,this.displayFn);
this.$el=B(H.dataset.replace("%CLASS%",this.name));
}S.extractDatasetName=function f(i){return B(i).data(T);
};
S.extractValue=function c(i){return B(i).data(h);
};
S.extractDatum=function c(i){return B(i).data(b);
};
Q.mixin(S.prototype,E,{_render:function U(o,i){if(!this.$el){return ;
}var n=this,k;
this.$el.empty();
k=i&&i.length;
if(!k&&this.templates.empty){this.$el.html(j()).prepend(n.templates.header?m():null).append(n.templates.footer?l():null);
}else{if(k){this.$el.html(p()).prepend(n.templates.header?m():null).append(n.templates.footer?l():null);
}}this.trigger("rendered");
function j(){return n.templates.empty({query:o,isEmpty:true});
}function p(){var r,q;
r=B(H.suggestions).css(G.suggestions);
q=Q.map(i,s);
r.append.apply(r,q);
n.highlight&&C({className:"tt-highlight",node:r[0],pattern:o});
return r;
function s(t){var u;
u=B(H.suggestion).append(n.templates.suggestion(t)).data(T,n.name).data(h,n.displayFn(t)).data(b,t);
u.children().each(function(){B(this).css(G.suggestionChild);
});
return u;
}}function m(){return n.templates.header({query:o,isEmpty:!k});
}function l(){return n.templates.footer({query:o,isEmpty:!k});
}},getRoot:function d(){return this.$el;
},update:function Y(k){var j=this;
this.query=k;
this.canceled=false;
this.source(k,i);
function i(l){if(!j.canceled&&k===j.query){j._render(k,l);
}}},cancel:function g(){this.canceled=true;
},clear:function a(){this.cancel();
this.$el.empty();
this.trigger("rendered");
},isEmpty:function Z(){return this.$el.is(":empty");
},destroy:function e(){this.$el=null;
}});
return S;
function W(i){i=i||"value";
return Q.isFunction(i)?i:j;
function j(k){return k[i];
}}function X(j,k){return{empty:j.empty&&Q.templatify(j.empty),header:j.header&&Q.templatify(j.header),footer:j.footer&&Q.templatify(j.footer),suggestion:j.suggestion||i};
function i(l){return"<p>"+k(l)+"</p>";
}}function V(i){return/^[_a-zA-Z0-9-]+$/.test(i);
}}();
var M=function(){function l(u){var s=this,q,t,r;
u=u||{};
if(!u.menu){B.error("menu is required");
}this.isOpen=false;
this.isEmpty=true;
this.datasets=Q.map(u.datasets,c);
q=Q.bind(this._onSuggestionClick,this);
t=Q.bind(this._onSuggestionMouseEnter,this);
r=Q.bind(this._onSuggestionMouseLeave,this);
this.$menu=B(u.menu).on("click.tt",".tt-suggestion",q).on("mouseenter.tt",".tt-suggestion",t).on("mouseleave.tt",".tt-suggestion",r);
Q.each(this.datasets,function(v){s.$menu.append(v.getRoot());
v.onSync("rendered",s._onRendered,s);
});
}Q.mixin(l.prototype,E,{_onSuggestionClick:function k(q){this.trigger("suggestionClicked",B(q.currentTarget));
},_onSuggestionMouseEnter:function S(q){this._removeCursor();
this._setCursor(B(q.currentTarget),true);
},_onSuggestionMouseLeave:function f(){this._removeCursor();
},_onRendered:function Y(){this.isEmpty=Q.every(this.datasets,q);
this.isEmpty?this._hide():this.isOpen&&this._show();
this.trigger("datasetRendered");
function q(r){return r.isEmpty();
}},_hide:function(){this.$menu.hide();
},_show:function(){this.$menu.css("display","block");
},_getSuggestions:function X(){return this.$menu.find(".tt-suggestion");
},_getCursor:function V(){return this.$menu.find(".tt-cursor").first();
},_setCursor:function n(r,q){r.first().addClass("tt-cursor");
!q&&this.trigger("cursorMoved");
},_removeCursor:function U(){this._getCursor().removeClass("tt-cursor");
},_moveCursor:function T(q){var s,r,u,t;
if(!this.isOpen){return ;
}r=this._getCursor();
s=this._getSuggestions();
this._removeCursor();
u=s.index(r)+q;
u=(u+1)%(s.length+1)-1;
if(u===-1){this.trigger("cursorRemoved");
return ;
}else{if(u<-1){u=s.length-1;
}}this._setCursor(t=s.eq(u));
this._ensureVisible(t);
},_ensureVisible:function j(t){var q,s,r,u;
q=t.position().top;
s=q+t.outerHeight(true);
r=this.$menu.scrollTop();
u=this.$menu.height()+parseInt(this.$menu.css("paddingTop"),10)+parseInt(this.$menu.css("paddingBottom"),10);
if(q<0){this.$menu.scrollTop(r+q);
}else{if(u<s){this.$menu.scrollTop(r+(s-u));
}}},close:function g(){if(this.isOpen){this.isOpen=false;
this._removeCursor();
this._hide();
this.trigger("closed");
}},open:function e(){if(!this.isOpen){this.isOpen=true;
!this.isEmpty&&this._show();
this.trigger("opened");
}},setLanguageDirection:function o(q){this.$menu.css(q==="ltr"?G.ltr:G.rtl);
},moveCursorUp:function Z(){this._moveCursor(-1);
},moveCursorDown:function p(){this._moveCursor(+1);
},getDatumForSuggestion:function b(r){var q=null;
if(r.length){q={raw:R.extractDatum(r),value:R.extractValue(r),datasetName:R.extractDatasetName(r)};
}return q;
},getDatumForCursor:function W(){return this.getDatumForSuggestion(this._getCursor().first());
},getDatumForTopSuggestion:function i(){return this.getDatumForSuggestion(this._getSuggestions().first());
},update:function a(q){Q.each(this.datasets,r);
function r(s){s.update(q);
}},empty:function d(){Q.each(this.datasets,q);
this.isEmpty=true;
function q(r){r.clear();
}},isVisible:function h(){return this.isOpen&&!this.isEmpty;
},destroy:function m(){this.$menu.off(".tt");
this.$menu=null;
Q.each(this.datasets,q);
function q(r){r.destroy();
}}});
return l;
function c(q){return new R(q);
}}();
var J=function(){var t="ttAttrs";
function d(z){var y,AA,x;
z=z||{};
if(!z.input){B.error("missing input");
}this.isActivated=false;
this.autoselect=!!z.autoselect;
this.minLength=Q.isNumber(z.minLength)?z.minLength:1;
this.$node=n(z.input,z.withHint);
y=this.$node.find(".tt-dropdown-menu");
AA=this.$node.find(".tt-input");
x=this.$node.find(".tt-hint");
AA.on("blur.tt",function(AC){var AE,AD,AB;
AE=document.activeElement;
AD=y.is(AE);
AB=y.has(AE).length>0;
if(Q.isMsie()&&(AD||AB)){AC.preventDefault();
AC.stopImmediatePropagation();
Q.defer(function(){AA.focus();
});
}});
y.on("mousedown.tt",function(AB){AB.preventDefault();
});
this.eventBus=z.eventBus||new A({el:AA});
this.dropdown=new M({menu:y,datasets:z.datasets}).onSync("suggestionClicked",this._onSuggestionClicked,this).onSync("cursorMoved",this._onCursorMoved,this).onSync("cursorRemoved",this._onCursorRemoved,this).onSync("opened",this._onOpened,this).onSync("closed",this._onClosed,this).onAsync("datasetRendered",this._onDatasetRendered,this);
this.input=new K({input:AA,hint:x}).onSync("focused",this._onFocused,this).onSync("blurred",this._onBlurred,this).onSync("enterKeyed",this._onEnterKeyed,this).onSync("tabKeyed",this._onTabKeyed,this).onSync("escKeyed",this._onEscKeyed,this).onSync("upKeyed",this._onUpKeyed,this).onSync("downKeyed",this._onDownKeyed,this).onSync("leftKeyed",this._onLeftKeyed,this).onSync("rightKeyed",this._onRightKeyed,this).onSync("queryChanged",this._onQueryChanged,this).onSync("whitespaceChanged",this._onWhitespaceChanged,this);
this._setLanguageDirection();
}Q.mixin(d.prototype,{_onSuggestionClicked:function U(z,y){var x;
if(x=this.dropdown.getDatumForSuggestion(y)){this._select(x);
}},_onCursorMoved:function o(){var x=this.dropdown.getDatumForCursor();
this.input.setInputValue(x.value,true);
this.eventBus.trigger("cursorchanged",x.raw,x.datasetName);
},_onCursorRemoved:function X(){this.input.resetInputValue();
this._updateHint();
},_onDatasetRendered:function j(){this._updateHint();
},_onOpened:function V(){this._updateHint();
this.eventBus.trigger("opened");
},_onClosed:function a(){this.input.clearHint();
this.eventBus.trigger("closed");
},_onFocused:function l(){this.isActivated=true;
this.dropdown.open();
},_onBlurred:function m(){this.isActivated=false;
this.dropdown.empty();
this.dropdown.close();
},_onEnterKeyed:function h(y,x){var z,AA;
z=this.dropdown.getDatumForCursor();
AA=this.dropdown.getDatumForTopSuggestion();
if(z){this._select(z);
x.preventDefault();
}else{if(this.autoselect&&AA){this._select(AA);
x.preventDefault();
}}},_onTabKeyed:function w(z,y){var x;
if(x=this.dropdown.getDatumForCursor()){this._select(x);
y.preventDefault();
}else{this._autocomplete(true);
}},_onEscKeyed:function r(){this.dropdown.close();
this.input.resetInputValue();
},_onUpKeyed:function T(){var x=this.input.getQuery();
this.dropdown.isEmpty&&x.length>=this.minLength?this.dropdown.update(x):this.dropdown.moveCursorUp();
this.dropdown.open();
},_onDownKeyed:function Y(){var x=this.input.getQuery();
this.dropdown.isEmpty&&x.length>=this.minLength?this.dropdown.update(x):this.dropdown.moveCursorDown();
this.dropdown.open();
},_onLeftKeyed:function v(){this.dir==="rtl"&&this._autocomplete();
},_onRightKeyed:function i(){this.dir==="ltr"&&this._autocomplete();
},_onQueryChanged:function f(y,x){this.input.clearHintIfInvalid();
x.length>=this.minLength?this.dropdown.update(x):this.dropdown.empty();
this.dropdown.open();
this._setLanguageDirection();
},_onWhitespaceChanged:function s(){this._updateHint();
this.dropdown.open();
},_setLanguageDirection:function q(){var x;
if(this.dir!==(x=this.input.getLanguageDirection())){this.dir=x;
this.$node.css("direction",x);
this.dropdown.setLanguageDirection(x);
}},_updateHint:function k(){var y,AC,AB,AA,x,z;
y=this.dropdown.getDatumForTopSuggestion();
if(y&&this.dropdown.isVisible()&&!this.input.hasOverflow()){AC=this.input.getInputValue();
AB=K.normalizeQuery(AC);
AA=Q.escapeRegExChars(AB);
x=new RegExp("^(?:"+AA+")(.+$)","i");
z=x.exec(y.value);
z?this.input.setHint(AC+z[1]):this.input.clearHint();
}else{this.input.clearHint();
}},_autocomplete:function u(z){var AB,AA,x,y;
AB=this.input.getHint();
AA=this.input.getQuery();
x=z||this.input.isCursorAtEnd();
if(AB&&AA!==AB&&x){y=this.dropdown.getDatumForTopSuggestion();
y&&this.input.setInputValue(y.value);
this.eventBus.trigger("autocompleted",y.raw,y.datasetName);
}},_select:function g(x){this.input.setQuery(x.value);
this.input.setInputValue(x.value,true);
this._setLanguageDirection();
this.eventBus.trigger("selected",x.raw,x.datasetName);
this.dropdown.close();
Q.defer(Q.bind(this.dropdown.empty,this.dropdown));
},open:function c(){this.dropdown.open();
},close:function e(){this.dropdown.close();
},setVal:function S(x){x=Q.toStr(x);
if(this.isActivated){this.input.setInputValue(x);
}else{this.input.setQuery(x);
this.input.setInputValue(x,true);
}this._setLanguageDirection();
},getVal:function b(){return this.input.getQuery();
},destroy:function p(){this.input.destroy();
this.dropdown.destroy();
W(this.$node);
this.$node=null;
}});
return d;
function n(x,AC){var AD,z,AB,y;
AD=B(x);
z=B(H.wrapper).css(G.wrapper);
AB=B(H.dropdown).css(G.dropdown);
y=AD.clone().css(G.hint).css(Z(AD));
y.val("").removeData().addClass("tt-hint").removeAttr("id name placeholder required").prop("readonly",true).attr({autocomplete:"off",spellcheck:"false",tabindex:-1});
AD.data(t,{dir:AD.attr("dir"),autocomplete:AD.attr("autocomplete"),spellcheck:AD.attr("spellcheck"),style:AD.attr("style")});
AD.addClass("tt-input").attr({autocomplete:"off",spellcheck:false}).css(AC?G.input:G.inputWithNoHint);
try{!AD.attr("dir")&&AD.attr("dir","auto");
}catch(AA){}return AD.wrap(z).parent().prepend(AC?y:null).append(AB);
}function Z(x){return{backgroundAttachment:x.css("background-attachment"),backgroundClip:x.css("background-clip"),backgroundColor:x.css("background-color"),backgroundImage:x.css("background-image"),backgroundOrigin:x.css("background-origin"),backgroundPosition:x.css("background-position"),backgroundRepeat:x.css("background-repeat"),backgroundSize:x.css("background-size")};
}function W(x){var y=x.find(".tt-input");
Q.each(y.data(t),function(AA,z){Q.isUndefined(AA)?y.removeAttr(z):y.attr(z,AA);
});
y.detach().removeData(t).removeClass("tt-input").insertAfter(x);
x.remove();
}}();
(function(){var U,S,V;
U=B.fn.typeahead;
S="ttTypeahead";
V={initialize:function W(d,c){c=Q.isArray(c)?c:[].slice.call(arguments,1);
d=d||{};
return this.each(b);
function b(){var g=B(this),e,f;
Q.each(c,function(h){h.highlight=!!d.highlight;
});
f=new J({input:g,eventBus:e=new A({el:g}),withHint:Q.isUndefined(d.hint)?true:!!d.hint,minLength:d.minLength,autoselect:d.autoselect,datasets:c});
g.data(S,f);
}},open:function X(){return this.each(b);
function b(){var d=B(this),c;
if(c=d.data(S)){c.open();
}}},close:function a(){return this.each(b);
function b(){var d=B(this),c;
if(c=d.data(S)){c.close();
}}},val:function T(b){return !arguments.length?d(this.first()):this.each(c);
function c(){var f=B(this),e;
if(e=f.data(S)){e.setVal(b);
}}function d(g){var f,e;
if(f=g.data(S)){e=f.getVal();
}return e;
}},destroy:function Z(){return this.each(b);
function b(){var d=B(this),c;
if(c=d.data(S)){c.destroy();
d.removeData(S);
}}}};
B.fn.typeahead=function(c){var b;
if(V[c]&&c!=="initialize"){b=this.filter(function(){return !!B(this).data(S);
});
return V[c].apply(b,[].slice.call(arguments,1));
}else{return V.initialize.apply(this,arguments);
}};
B.fn.typeahead.noConflict=function Y(){B.fn.typeahead=U;
return this;
};
})();
})(window.jQuery);




