=1)return e[1];return"resolve"===this.opts.width?(c=this.opts.element.css("width"),c.indexOf("%")>0?c:0===this.opts.element.outerWidth(!1)?"auto":this.opts.element.outerWidth(!1)+"px"):null}return a.isFunction(this.opts.width)?this.opts.width():this.opts.width}var d=c.call(this);null!==d&&this.container.css("width",d)}}),B=y(A,{createContainer:function(){var b=a(document.createElement("div")).attr({"class":"select2-container"}).html([""," ×","
","","",""].join(""));return b},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(a.Event("open"))},close:function(){this.opened()&&(this.parent.close.apply(this,arguments),this.focusser.removeAttr("disabled"),l(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 a,b=this.container,c=this.dropdown,d=!1;this.selection=a=b.find(".select2-choice"),this.focusser=b.find(".select2-focusser"),this.search.bind("keydown",this.bind(function(a){if(this.enabled){if(a.which===z.PAGE_UP||a.which===z.PAGE_DOWN)return void m(a);switch(a.which){case z.UP:case z.DOWN:return this.moveHighlight(a.which===z.UP?-1:1),void m(a);case z.TAB:case z.ENTER:return this.selectHighlighted(),void m(a);case z.ESC:return this.cancel(a),void m(a)}}})),this.focusser.bind("keydown",this.bind(function(a){if(this.enabled&&a.which!==z.TAB&&!z.isControl(a)&&!z.isFunctionKey(a)&&a.which!==z.ESC)return this.opts.openOnEnter===!1&&a.which===z.ENTER?void m(a):a.which==z.DOWN||a.which==z.UP||a.which==z.ENTER&&this.opts.openOnEnter?(this.open(),void m(a)):a.which==z.DELETE||a.which==z.BACKSPACE?(this.opts.allowClear&&this.clear(),void m(a)):void 0})),g(this.focusser),this.focusser.bind("keyup-change input",this.bind(function(a){this.opened()||(this.open(),this.search.val(this.focusser.val()),this.focusser.val(""),m(a))})),a.delegate("abbr","mousedown",this.bind(function(a){this.enabled&&(this.clear(),n(a),this.close(),this.triggerChange(),this.selection.focus())})),a.bind("mousedown",this.bind(function(a){d=!0,this.opened()?this.close():this.enabled&&this.open(),m(a),d=!1})),c.bind("mousedown",this.bind(function(){this.search.focus()})),a.bind("focus",this.bind(function(a){m(a)})),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.setPlaceholder()},clear:function(){var a=this.selection.data("select2-data");this.opts.element.val(""),this.selection.find("span").empty(),this.selection.removeData("select2-data"),this.setPlaceholder(),this.opts.element.trigger({type:"removed",val:this.id(a),choice:a}),this.triggerChange({removed:a})},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(c){c!==b&&null!==c&&(a.updateSelection(c),a.close(),a.setPlaceholder())})}},prepareOpts:function(){var b=this.parent.prepareOpts.apply(this,arguments);return"select"===b.element.get(0).tagName.toLowerCase()?b.initSelection=function(b,c){var d=b.find(":selected");a.isFunction(c)&&c({id:d.attr("value")||d.text(),text:d.text(),element:d})}:"data"in b&&(b.initSelection=b.initSelection||function(c,e){var f=c.val();b.query({matcher:function(a,c,e){return d(f,b.id(e))},callback:a.isFunction(e)?function(a){e(a.results.length?a.results[0]:null)}:a.noop})}),b},setPlaceholder:function(){var a=this.getPlaceholder();if(""===this.opts.element.val()&&a!==b){if(this.select&&""!==this.select.find("option:first").text())return;this.selection.find("span").html(this.opts.escapeMarkup(a)),this.selection.addClass("select2-default"),this.selection.find("abbr").hide()}},postprocessResults:function(b,c){var e=0,f=this,g=!0;this.findHighlightableChoices().each2(function(a,b){
-if(d(f.id(b.data("select2-data")),f.opts.element.val()))return e=a,!1}),this.highlight(e),c===!0&&(g=this.showSearchInput=w(b.results)>=this.opts.minimumResultsForSearch,this.dropdown.find(".select2-search")[g?"removeClass":"addClass"]("select2-search-hidden"),a(this.dropdown,this.container)[g?"addClass":"removeClass"]("select2-with-searchbox"))},onSelect:function(a,b){var c=this.opts.element.val();this.opts.element.val(this.id(a)),this.updateSelection(a),this.opts.element.trigger({type:"selected",val:this.id(a),choice:a}),this.close(),b&&b.noFocus||this.selection.focus(),d(c,this.id(a))||this.triggerChange()},updateSelection:function(a){var c,d=this.selection.find("span");this.selection.data("select2-data",a),d.empty(),c=this.opts.formatSelection(a,d),c!==b&&d.append(this.opts.escapeMarkup(c)),this.selection.removeClass("select2-default"),this.opts.allowClear&&this.getPlaceholder()!==b&&this.selection.find("abbr").show()},val:function(){var a,c=!1,d=null,e=this;if(0===arguments.length)return this.opts.element.val();if(a=arguments[0],arguments.length>1&&(c=arguments[1]),this.select)this.select.val(a).find(":selected").each2(function(a,b){return d={id:b.attr("value")||b.text(),text:b.text()},!1}),this.updateSelection(d),this.setPlaceholder(),c&&this.triggerChange();else{if(this.opts.initSelection===b)throw new Error("cannot call val() if initSelection() is not defined");if(!a&&0!==a)return this.clear(),void(c&&this.triggerChange());this.opts.element.val(a),this.opts.initSelection(this.opts.element,function(a){e.opts.element.val(a?e.id(a):""),e.updateSelection(a),e.setPlaceholder(),c&&e.triggerChange()})}},clearSearch:function(){this.search.val(""),this.focusser.val("")},data:function(a){var c;return 0===arguments.length?(c=this.selection.data("select2-data"),c==b&&(c=null),c):void(a&&""!==a?(this.opts.element.val(a?this.id(a):""),this.updateSelection(a)):this.clear())}}),C=y(A,{createContainer:function(){var b=a(document.createElement("div")).attr({"class":"select2-container select2-container-multi"}).html([" ",""].join(""));return b},prepareOpts:function(){var b=this.parent.prepareOpts.apply(this,arguments);return"select"===b.element.get(0).tagName.toLowerCase()?b.initSelection=function(a,b){var c=[];a.find(":selected").each2(function(a,b){c.push({id:b.attr("value")||b.text(),text:b.text(),element:b[0]})}),b(c)}:"data"in b&&(b.initSelection=b.initSelection||function(c,f){var g=e(c.val(),b.separator);b.query({matcher:function(c,e,f){return a.grep(g,function(a){return d(a,b.id(f))}).length},callback:a.isFunction(f)?function(a){f(a.results)}:a.noop})}),b},initContainer:function(){var b,c=".select2-choices";this.searchContainer=this.container.find(".select2-search-field"),this.selection=b=this.container.find(c),this.search.bind("input paste",this.bind(function(){this.enabled&&(this.opened()||this.open())})),this.search.bind("keydown",this.bind(function(a){if(this.enabled){if(a.which===z.BACKSPACE&&""===this.search.val()){this.close();var c,d=b.find(".select2-search-choice-focus");if(d.length>0)return this.unselect(d.first()),this.search.width(10),void m(a);c=b.find(".select2-search-choice:not(.select2-locked)"),c.length>0&&c.last().addClass("select2-search-choice-focus")}else b.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");if(this.opened())switch(a.which){case z.UP:case z.DOWN:return this.moveHighlight(a.which===z.UP?-1:1),void m(a);case z.ENTER:case z.TAB:return this.selectHighlighted(),void m(a);case z.ESC:return this.cancel(a),void m(a)}if(a.which!==z.TAB&&!z.isControl(a)&&!z.isFunctionKey(a)&&a.which!==z.BACKSPACE&&a.which!==z.ESC){if(a.which===z.ENTER){if(this.opts.openOnEnter===!1)return;if(a.altKey||a.ctrlKey||a.shiftKey||a.metaKey)return}this.open(),a.which!==z.PAGE_UP&&a.which!==z.PAGE_DOWN||m(a)}}})),this.search.bind("keyup",this.bind(this.resizeSearch)),this.search.bind("blur",this.bind(function(a){this.container.removeClass("select2-container-active"),this.search.removeClass("select2-focused"),this.opened()||this.clearSearch(),a.stopImmediatePropagation()})),this.container.delegate(c,"mousedown",this.bind(function(b){this.enabled&&(a(b.target).closest(".select2-search-choice").length>0||(this.clearPlaceholder(),this.open(),this.focusSearch(),b.preventDefault()))})),this.container.delegate(c,"focus",this.bind(function(){this.enabled&&(this.container.addClass("select2-container-active"),this.dropdown.addClass("select2-drop-active"),this.clearPlaceholder())})),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(c){c!==b&&null!==c&&(a.updateSelection(c),a.close(),a.clearSearch())})}},clearSearch:function(){var a=this.getPlaceholder();a!==b&&0===this.getVal().length&&this.search.hasClass("select2-focused")===!1?(this.search.val(a).addClass("select2-default"),this.resizeSearch()):this.search.val("").width(10)},clearPlaceholder:function(){this.search.hasClass("select2-default")&&this.search.val("").removeClass("select2-default")},opening:function(){this.parent.opening.apply(this,arguments),this.clearPlaceholder(),this.resizeSearch(),this.focusSearch(),this.opts.element.trigger(a.Event("open"))},close:function(){this.opened()&&this.parent.close.apply(this,arguments)},focus:function(){this.close(),this.search.focus(),this.opts.element.triggerHandler("focus")},isFocused:function(){return this.search.hasClass("select2-focused")},updateSelection:function(b){var d=[],e=[],f=this;a(b).each(function(){c(f.id(this),d)<0&&(d.push(f.id(this)),e.push(this))}),b=e,this.selection.find(".select2-search-choice").remove(),a(b).each(function(){f.addSelectedChoice(this)}),f.postprocessResults()},tokenize:function(){var a=this.search.val();a=this.opts.tokenizer(a,this.data(),this.bind(this.onSelect),this.opts),null!=a&&a!=b&&(this.search.val(a),a.length>0&&this.open())},onSelect:function(a,b){this.addSelectedChoice(a),this.opts.element.trigger({type:"selected",val:this.id(a),choice:a}),!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.val().length>=this.getMaximumSelectionSize()&&this.updateResults(!0),this.positionDropdown()):(this.close(),this.search.width(10)),this.triggerChange({added:a}),b&&b.noFocus||this.focusSearch()},cancel:function(){this.close(),this.focusSearch()},addSelectedChoice:function(c){var d,e=!c.locked,f=a(" ×"),g=a(""),h=e?f:g,i=this.id(c),j=this.getVal();d=this.opts.formatSelection(c,h.find("div")),d!=b&&h.find("div").replaceWith(""+this.opts.escapeMarkup(d)+"
"),e&&h.find(".select2-search-choice-close").bind("mousedown",m).bind("click dblclick",this.bind(function(b){this.enabled&&(a(b.target).closest(".select2-search-choice").fadeOut("fast",this.bind(function(){this.unselect(a(b.target)),this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus"),this.close(),this.focusSearch()})).dequeue(),m(b))})).bind("focus",this.bind(function(){this.enabled&&(this.container.addClass("select2-container-active"),this.dropdown.addClass("select2-drop-active"))})),h.data("select2-data",c),h.insertBefore(this.searchContainer),j.push(i),this.setVal(j)},unselect:function(a){var b,d,e=this.getVal();if(a=a.closest(".select2-search-choice"),0===a.length)throw"Invalid argument: "+a+". Must be .select2-search-choice";b=a.data("select2-data"),b&&(d=c(this.id(b),e),d>=0&&(e.splice(d,1),this.setVal(e),this.select&&this.postprocessResults()),a.remove(),this.opts.element.trigger({type:"removed",val:this.id(b),choice:b}),this.triggerChange({removed:b}))},postprocessResults:function(){var a=this.getVal(),b=this.results.find(".select2-result"),d=this.results.find(".select2-result-with-children"),e=this;b.each2(function(b,d){var f=e.id(d.data("select2-data"));c(f,a)>=0&&(d.addClass("select2-selected"),d.find(".select2-result-selectable").addClass("select2-selected"))}),d.each2(function(a,b){b.is(".select2-result-selectable")||0!==b.find(".select2-result-selectable:not(.select2-selected)").length||b.addClass("select2-selected")}),this.highlight()==-1&&e.highlight(0)},resizeSearch:function(){var a,b,c,d,e,g=f(this.search);a=o(this.search)+10,b=this.search.offset().left,c=this.selection.width(),d=this.selection.offset().left,e=c-(b-d)-g,e1&&(d=arguments[1]),!c&&0!==c)return this.opts.element.val(""),this.updateSelection([]),this.clearSearch(),void(d&&this.triggerChange());if(this.setVal(c),this.select)this.opts.initSelection(this.select,this.bind(this.updateSelection)),d&&this.triggerChange();else{if(this.opts.initSelection===b)throw new Error("val() cannot be called if initSelection() is not defined");this.opts.initSelection(this.opts.element,function(b){var c=a(b).map(e.id);e.setVal(c),e.updateSelection(b),e.clearSearch(),d&&e.triggerChange()})}this.clearSearch()},onSortStart:function(){if(this.select)throw new Error("Sorting of elements is not supported when attached to