"+u.formatInputTooShort(w.val(),u.minimumInputLength)+""):b(""),am}if(u.maximumInputLength&&w.val().length>u.maximumInputLength){return T(u.formatInputTooLong,"formatInputTooLong")?b(""+u.formatInputTooLong(w.val(),u.maximumInputLength)+""):b(""),am}u.formatSearching&&0===this.findHighlightableChoices().length&&b(""+u.formatSearching()+""),w.addClass("select2-active"),r=this.tokenize(),r!=am&&null!=r&&w.val(r),this.resultsPage=1,u.query({element:u.element,term:w.val(),page:this.resultsPage,context:null,matcher:u.matcher,callback:this.bind(function(d){var c;return this.opened()?(this.context=d.context===am?null:d.context,this.opts.createSearchChoice&&""!==w.val()&&(c=this.opts.createSearchChoice.call(null,w.val(),d.results),c!==am&&null!==c&&s.id(c)!==am&&null!==s.id(c)&&0===an(d.results).filter(function(){return ac(s.id(this),s.id(c))}).length&&d.results.unshift(c)),0===d.results.length&&T(u.formatNoMatches,"formatNoMatches")?(b(""+u.formatNoMatches(w.val())+""),am):(v.empty(),s.opts.populateResults.call(this,v,d.results,{term:w.val(),page:this.resultsPage,context:null}),d.more===!0&&T(u.formatLoadMore,"formatLoadMore")&&(v.append(""+s.opts.escapeMarkup(u.formatLoadMore(this.resultsPage))+""),window.setTimeout(function(){s.loadMoreIfNeeded()},10)),this.postprocessResults(d,x),l(),this.opts.element.trigger({type:"loaded",data:d}),am)):(this.search.removeClass("select2-active"),am)})})}},cancel:function(){this.close()},blur:function(){this.opts.selectOnBlur&&this.selectHighlighted({noFocus:!0}),this.close(),this.container.removeClass("select2-container-active"),this.search[0]===document.activeElement&&this.search.blur(),this.clearSearch(),this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus")},focusSearch:function(){Q(this.search)},selectHighlighted:function(f){var e=this.highlight(),h=this.results.find(".select2-highlighted"),g=h.closest(".select2-result").data("select2-data");g&&(this.highlight(e),this.onSelect(g,f))},getPlaceholder:function(){return this.opts.element.attr("placeholder")||this.opts.element.attr("data-placeholder")||this.opts.element.data("placeholder")||this.opts.placeholder},initContainerWidth:function(){function b(){var l,k,j,i,h;if("off"===this.opts.width){return null}if("element"===this.opts.width){return 0===this.opts.element.outerWidth(!1)?"auto":this.opts.element.outerWidth(!1)+"px"}if("copy"===this.opts.width||"resolve"===this.opts.width){if(l=this.opts.element.attr("style"),l!==am){for(k=l.split(";"),i=0,h=k.length;h>i;i+=1){if(j=k[i].replace(/\s/g,"").match(/width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/),null!==j&&j.length>=1){return j[1]}}}return"resolve"===this.opts.width?(l=this.opts.element.css("width"),l.indexOf("%")>0?l:0===this.opts.element.outerWidth(!1)?"auto":this.opts.element.outerWidth(!1)+"px"):null}return an.isFunction(this.opts.width)?this.opts.width():this.opts.width}var a=b.call(this);null!==a&&this.container.css("width",a)}}),aj=L(ak,{createContainer:function(){var a=an(document.createElement("div")).attr({"class":"select2-container"}).html([""," ","
","","",""].join(""));return a},disable:function(){this.enabled&&(this.parent.disable.apply(this,arguments),this.focusser.attr("disabled","disabled"))},enable:function(){this.enabled||(this.parent.enable.apply(this,arguments),this.focusser.removeAttr("disabled"))},opening:function(){this.parent.opening.apply(this,arguments),this.focusser.attr("disabled","disabled"),this.opts.element.trigger(an.Event("open"))},close:function(){this.opened()&&(this.parent.close.apply(this,arguments),this.focusser.removeAttr("disabled"),Q(this.focusser))},focus:function(){this.opened()?this.close():(this.focusser.removeAttr("disabled"),this.focusser.focus())},isFocused:function(){return this.container.hasClass("select2-container-active")},cancel:function(){this.parent.cancel.apply(this,arguments),this.focusser.removeAttr("disabled"),this.focusser.focus()},initContainer:function(){var g,c=this.container,b=this.dropdown,a=!1;this.showSearch(this.opts.minimumResultsForSearch>=0),this.selection=g=c.find(".select2-choice"),this.focusser=c.find(".select2-focusser"),this.focusser.attr("id","s2id_autogen"+ah()),an("label[for='"+this.opts.element.attr("id")+"']").attr("for",this.focusser.attr("id")),this.search.bind("keydown",this.bind(function(d){if(this.enabled){if(d.which===al.PAGE_UP||d.which===al.PAGE_DOWN){return O(d),am}switch(d.which){case al.UP:case al.DOWN:return this.moveHighlight(d.which===al.UP?-1:1),O(d),am;case al.TAB:case al.ENTER:return this.selectHighlighted(),O(d),am;case al.ESC:return this.cancel(d),O(d),am}}})),this.search.bind("blur",this.bind(function(){document.activeElement===this.body().get(0)&&window.setTimeout(this.bind(function(){this.search.focus()}),0)})),this.focusser.bind("keydown",this.bind(function(d){return !this.enabled||d.which===al.TAB||al.isControl(d)||al.isFunctionKey(d)||d.which===al.ESC?am:this.opts.openOnEnter===!1&&d.which===al.ENTER?(O(d),am):d.which==al.DOWN||d.which==al.UP||d.which==al.ENTER&&this.opts.openOnEnter?(this.open(),O(d),am):d.which==al.DELETE||d.which==al.BACKSPACE?(this.opts.allowClear&&this.clear(),O(d),am):am})),Z(this.focusser),this.focusser.bind("keyup-change input",this.bind(function(d){this.opened()||(this.open(),this.showSearchInput!==!1&&this.search.val(this.focusser.val()),this.focusser.val(""),O(d))})),g.delegate("abbr","mousedown",this.bind(function(d){this.enabled&&(this.clear(),M(d),this.close(),this.selection.focus())})),g.bind("mousedown",this.bind(function(d){a=!0,this.opened()?this.close():this.enabled&&this.open(),O(d),a=!1})),b.bind("mousedown",this.bind(function(){this.search.focus()})),g.bind("focus",this.bind(function(d){O(d)})),this.focusser.bind("focus",this.bind(function(){this.container.addClass("select2-container-active")})).bind("blur",this.bind(function(){this.opened()||this.container.removeClass("select2-container-active")})),this.search.bind("focus",this.bind(function(){this.container.addClass("select2-container-active")})),this.initContainerWidth(),this.setPlaceholder()},clear:function(d){var c=this.selection.data("select2-data");c&&(this.opts.element.val(""),this.selection.find("span").empty(),this.selection.removeData("select2-data"),this.setPlaceholder(),d!==!1&&(this.opts.element.trigger({type:"removed",val:this.id(c),choice:c}),this.triggerChange({removed:c})))},initSelection:function(){if(""===this.opts.element.val()&&""===this.opts.element.text()){this.close(),this.setPlaceholder()}else{var a=this;this.opts.initSelection.call(null,this.opts.element,function(b){b!==am&&null!==b&&(a.updateSelection(b),a.close(),a.setPlaceholder())})}},prepareOpts:function(){var a=this.parent.prepareOpts.apply(this,arguments);return"select"===a.element.get(0).tagName.toLowerCase()?a.initSelection=function(e,g){var f=e.find(":selected");an.isFunction(g)&&g({id:f.attr("value"),text:f.text(),element:f})}:"data" in a&&(a.initSelection=a.initSelection||function(i,h){var g=i.val(),b=null;a.query({matcher:function(e,k,j){var f=ac(g,a.id(j));return f&&(b=j),f},callback:an.isFunction(h)?function(){h(b)}:an.noop})}),a},getPlaceholder:function(){return this.select&&""!==this.select.find("option").first().text()?am:this.parent.getPlaceholder.apply(this,arguments)},setPlaceholder:function(){var b=this.getPlaceholder();if(""===this.opts.element.val()&&b!==am){if(this.select&&""!==this.select.find("option:first").text()){return}this.selection.find("span").html(this.opts.escapeMarkup(b)),this.selection.addClass("select2-default"),this.selection.find("abbr").hide()}},postprocessResults:function(b,n,m){var l=0,k=this,j=!0;if(this.findHighlightableChoices().each2(function(d,e){return ac(k.id(e.data("select2-data")),k.opts.element.val())?(l=d,!1):am}),m!==!1&&this.highlight(l),n===!0){var i=this.opts.minimumResultsForSearch;j=0>i?!1:P(b.results)>=i,this.showSearch(j)}},showSearch:function(a){this.showSearchInput=a,this.dropdown.find(".select2-search")[a?"removeClass":"addClass"]("select2-search-hidden"),an(this.dropdown,this.container)[a?"addClass":"removeClass"]("select2-with-searchbox")},onSelect:function(e,d){var f=this.opts.element.val();this.opts.element.val(this.id(e)),this.updateSelection(e),this.opts.element.trigger({type:"selected",val:this.id(e),choice:e}),this.close(),d&&d.noFocus||this.selection.focus(),ac(f,this.id(e))||this.triggerChange()},updateSelection:function(b){var e,f=this.selection.find("span");this.selection.data("select2-data",b),f.empty(),e=this.opts.formatSelection(b,f),e!==am&&f.append(this.opts.escapeMarkup(e)),this.selection.removeClass("select2-default"),this.opts.allowClear&&this.getPlaceholder()!==am&&this.selection.find("abbr").show()},val:function(){var b,h=!1,g=null,f=this;if(0===arguments.length){return this.opts.element.val()}if(b=arguments[0],arguments.length>1&&(h=arguments[1]),this.select){this.select.val(b).find(":selected").each2(function(d,c){return g={id:c.attr("value"),text:c.text(),element:c.get(0)},!1}),this.updateSelection(g),this.setPlaceholder(),h&&this.triggerChange()}else{if(this.opts.initSelection===am){throw Error("cannot call val() if initSelection() is not defined")}if(!b&&0!==b){return this.clear(h),h&&this.triggerChange(),am}this.opts.element.val(b),this.opts.initSelection(this.opts.element,function(c){f.opts.element.val(c?f.id(c):""),f.updateSelection(c),f.setPlaceholder(),h&&f.triggerChange()})}},clearSearch:function(){this.search.val(""),this.focusser.val("")},data:function(b){var d;return 0===arguments.length?(d=this.selection.data("select2-data"),d==am&&(d=null),d):(b&&""!==b?(this.opts.element.val(b?this.id(b):""),this.updateSelection(b)):this.clear(),am)}}),ai=L(ak,{createContainer:function(){var a=an(document.createElement("div")).attr({"class":"select2-container select2-container-multi"}).html([" ",""].join(""));return a},prepareOpts:function(){var a=this.parent.prepareOpts.apply(this,arguments);return"select"===a.element.get(0).tagName.toLowerCase()?a.initSelection=function(e,d){var f=[];e.find(":selected").each2(function(g,c){f.push({id:c.attr("value"),text:c.text(),element:c[0]})}),d(f)}:"data" in a&&(a.initSelection=a.initSelection||function(i,h){var g=ab(i.val(),a.separator),b=[];a.query({matcher:function(k,j,f){var e=an.grep(g,function(c){return ac(c,a.id(f))}).length;return e&&b.push(f),e},callback:an.isFunction(h)?function(){h(b)}:an.noop})}),a},initContainer:function(){var a,b=".select2-choices";this.searchContainer=this.container.find(".select2-search-field"),this.selection=a=this.container.find(b),this.search.attr("id","s2id_autogen"+ah()),an("label[for='"+this.opts.element.attr("id")+"']").attr("for",this.search.attr("id")),this.search.bind("input paste",this.bind(function(){this.enabled&&(this.opened()||this.open())})),this.search.bind("keydown",this.bind(function(c){if(this.enabled){if(c.which===al.BACKSPACE&&""===this.search.val()){this.close();var g,e=a.find(".select2-search-choice-focus");if(e.length>0){return this.unselect(e.first()),this.search.width(10),O(c),am}g=a.find(".select2-search-choice:not(.select2-locked)"),g.length>0&&g.last().addClass("select2-search-choice-focus")}else{a.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus")}if(this.opened()){switch(c.which){case al.UP:case al.DOWN:return this.moveHighlight(c.which===al.UP?-1:1),O(c),am;case al.ENTER:case al.TAB:return this.selectHighlighted(),O(c),am;case al.ESC:return this.cancel(c),O(c),am}}if(c.which!==al.TAB&&!al.isControl(c)&&!al.isFunctionKey(c)&&c.which!==al.BACKSPACE&&c.which!==al.ESC){if(c.which===al.ENTER){if(this.opts.openOnEnter===!1){return}if(c.altKey||c.ctrlKey||c.shiftKey||c.metaKey){return}}this.open(),(c.which===al.PAGE_UP||c.which===al.PAGE_DOWN)&&O(c),c.which===al.ENTER&&O(c)}}})),this.search.bind("keyup",this.bind(this.resizeSearch)),this.search.bind("blur",this.bind(function(c){this.container.removeClass("select2-container-active"),this.search.removeClass("select2-focused"),this.opened()||this.clearSearch(),c.stopImmediatePropagation()})),this.container.delegate(b,"mousedown",this.bind(function(c){this.enabled&&(an(c.target).closest(".select2-search-choice").length>0||(this.clearPlaceholder(),this.open(),this.focusSearch(),c.preventDefault()))})),this.container.delegate(b,"focus",this.bind(function(){this.enabled&&(this.container.addClass("select2-container-active"),this.dropdown.addClass("select2-drop-active"),this.clearPlaceholder())})),this.initContainerWidth(),this.clearSearch()},enable:function(){this.enabled||(this.parent.enable.apply(this,arguments),this.search.removeAttr("disabled"))},disable:function(){this.enabled&&(this.parent.disable.apply(this,arguments),this.search.attr("disabled",!0))},initSelection:function(){if(""===this.opts.element.val()&&""===this.opts.element.text()&&(this.updateSelection([]),this.close(),this.clearSearch()),this.select||""!==this.opts.element.val()){var a=this;this.opts.initSelection.call(null,this.opts.element,function(b){b!==am&&null!==b&&(a.updateSelection(b),a.close(),a.clearSearch())})}},clearSearch:function(){var b=this.getPlaceholder();b!==am&&0===this.getVal().length&&this.search.hasClass("select2-focused")===!1?(this.search.val(b).addClass("select2-default"),this.search.width(this.getMaxSearchWidth())):this.search.val("").width(10)},clearPlaceholder:function(){this.search.hasClass("select2-default")&&this.search.val("").removeClass("select2-default")},opening:function(){this.clearPlaceholder(),this.resizeSearch(),this.parent.opening.apply(this,arguments),this.focusSearch(),this.opts.element.trigger(an.Event("open"))},close:function(){this.opened()&&this.parent.close.apply(this,arguments)},focus:function(){this.close(),this.search.focus()},isFocused:function(){return this.search.hasClass("select2-focused")},updateSelection:function(a){var h=[],g=[],f=this;an(a).each(function(){0>ad(f.id(this),h)&&(h.push(f.id(this)),g.push(this))}),a=g,this.selection.find(".select2-search-choice").remove(),an(a).each(function(){f.addSelectedChoice(this)}),f.postprocessResults()},tokenize:function(){var b=this.search.val();b=this.opts.tokenizer(b,this.data(),this.bind(this.onSelect),this.opts),null!=b&&b!=am&&(this.search.val(b),b.length>0&&this.open())},onSelect:function(d,c){this.addSelectedChoice(d),this.opts.element.trigger({type:"selected",val:this.id(d),choice:d}),(this.select||!this.opts.closeOnSelect)&&this.postprocessResults(),this.opts.closeOnSelect?(this.close(),this.search.width(10)):this.countSelectableResults()>0?(this.search.width(10),this.resizeSearch(),this.getMaximumSelectionSize()>0&&this.val().length>=this.getMaximumSelectionSize()&&this.updateResults(!0),this.positionDropdown()):(this.close(),this.search.width(10)),this.triggerChange({added:d}),c&&c.noFocus||this.focusSearch()},cancel:function(){this.close(),this.focusSearch()},addSelectedChoice:function(p){var a,o=!p.locked,n=an(" "),m=an(""),l=o?n:m,k=this.id(p),b=this.getVal();a=this.opts.formatSelection(p,l.find("div")),a!=am&&l.find("div").replaceWith(""+this.opts.escapeMarkup(a)+"
"),o&&l.find(".select2-search-choice-close").bind("mousedown",O).bind("click dblclick",this.bind(function(c){this.enabled&&(an(c.target).closest(".select2-search-choice").fadeOut("fast",this.bind(function(){this.unselect(an(c.target)),this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus"),this.close(),this.focusSearch()})).dequeue(),O(c))})).bind("focus",this.bind(function(){this.enabled&&(this.container.addClass("select2-container-active"),this.dropdown.addClass("select2-drop-active"))})),l.data("select2-data",p),l.insertBefore(this.searchContainer),b.push(k),this.setVal(b)},unselect:function(f){var h,g,e=this.getVal();if(f=f.closest(".select2-search-choice"),0===f.length){throw"Invalid argument: "+f+". Must be .select2-search-choice"}h=f.data("select2-data"),h&&(g=ad(this.id(h),e),g>=0&&(e.splice(g,1),this.setVal(e),this.select&&this.postprocessResults()),f.remove(),this.opts.element.trigger({type:"removed",val:this.id(h),choice:h}),this.triggerChange({removed:h}))},postprocessResults:function(){var f=this.getVal(),e=this.results.find(".select2-result"),h=this.results.find(".select2-result-with-children"),g=this;e.each2(function(a,i){var d=g.id(i.data("select2-data"));ad(d,f)>=0&&(i.addClass("select2-selected"),i.find(".select2-result-selectable").addClass("select2-selected"))}),h.each2(function(d,c){c.is(".select2-result-selectable")||0!==c.find(".select2-result-selectable:not(.select2-selected)").length||c.addClass("select2-selected")}),-1==this.highlight()&&g.highlight(0)},getMaxSearchWidth:function(){return this.selection.width()-aa(this.search)},resizeSearch:function(){var h,g,l,k,j,i=aa(this.search);h=K(this.search)+10,g=this.search.offset().left,l=this.selection.width(),k=this.selection.offset().left,j=l-(g-k)-i,h>j&&(j=l-i),40>j&&(j=l-i),0>=j&&(j=h),this.search.width(j)},getVal:function(){var b;return this.select?(b=this.select.val(),null===b?[]:b):(b=this.opts.element.val(),ab(b,this.opts.separator))},setVal:function(a){var d;this.select?this.select.val(a):(d=[],an(a).each(function(){0>ad(this,d)&&d.push(this)}),this.opts.element.val(0===d.length?"":d.join(this.opts.separator)))},val:function(){var e,b=!1,a=this;if(0===arguments.length){return this.getVal()}if(e=arguments[0],arguments.length>1&&(b=arguments[1]),!e&&0!==e){return this.opts.element.val(""),this.updateSelection([]),this.clearSearch(),b&&this.triggerChange(),am}if(this.setVal(e),this.select){this.opts.initSelection(this.select,this.bind(this.updateSelection)),b&&this.triggerChange()}else{if(this.opts.initSelection===am){throw Error("val() cannot be called if initSelection() is not defined")}this.opts.initSelection(this.opts.element,function(d){var f=an(d).map(a.id);a.setVal(f),a.updateSelection(d),a.clearSearch(),b&&a.triggerChange()})}this.clearSearch()},onSortStart:function(){if(this.select){throw Error("Sorting of elements is not supported when attached to