$(function(){if(window.Select2){window.Select2["class"].multi.prototype.clearSearch=function(){var n=this.getPlaceholder(),t=this.getMaxSearchWidth(),i=this.getVal().length>0;n&&(this.search.addClass("select2-default"),i?this.search.val("").width(10):(this.search.val(n),this.search.width(t>0?t:this.container.css("width"))))},window.Select2["class"].multi.prototype._initContainer=window.Select2["class"].multi.prototype.initContainer,window.Select2["class"].multi.prototype.initContainer=function(){this.search.on("keydown",this.bind(function(n){var t;if(this.isInterfaceEnabled()){var i=this.selection.find(".select2-search-choice-focus"),r=i.prev(".select2-search-choice:not(.select2-locked)"),u=i.next(".select2-search-choice:not(.select2-locked)");if(i.length&&(n.shiftKey||n.which==8||n.which==9||n.which==37||n.which==39||n.which==46)){t=i;switch(n.which){case 9:t=n.shiftKey?r.length?r:null:u.length?u:null;break;case 46:this.unselect(i.first()),t=r.length?r:u}(n.shiftKey||t)&&(n.preventDefault(),n.stopImmediatePropagation()),this.selectChoice(t);return}if(this.opened())switch(n.which){case 13:this.selectHighlighted(),this.close(),n.preventDefault(),n.stopImmediatePropagation();return;case 9:this.selectHighlighted(),this.close();break;case 27:this.cancel(n),n.preventDefault(),n.stopImmediatePropagation();return}if(!n.shiftKey&&n.which==9){this.selectChoice(this.selection.find(".select2-search-choice:not(.select2-locked)").first()),n.preventDefault(),n.stopImmediatePropagation();return}}}));this._initContainer()},window.Select2["class"].multi.prototype.addSelectedChoice=function(n){var e=!n.locked,s=$("<li class='select2-search-choice'>    <div><\/div>    <a href='#' onclick='return false;' class='select2-search-choice-close' tabindex='-1'><span class='glyphicon glyphicon-remove-sign'><\/span><\/a><\/li>"),h=$("<li class='select2-search-choice select2-locked'><div><\/div><\/li>"),t=e?s:h,c=this.id(n),o=this.getVal(),u,f,r,i;if(u=this.opts.formatSelection(n,t.find("div"),this.opts.escapeMarkup),u!=undefined&&t.find("div").replaceWith($("<div><\/div>").html(u)),f=this.opts.formatSelectionCssClass(n,t.find("div")),f!=undefined&&t.addClass(f),r=!1,this.opts.insertIntoId?(i=$(this.opts.insertIntoId),i&&i.length>0&&ko.utils.arrayFilter(i[0].childNodes,function(t){return t.childNodes[1].innerText===n.text||t.innerText===n.text}).length>0&&(r=!0)):(i=$(this.searchContainer).parent().parent().select2("data"),i&&ko.utils.arrayFilter(i,function(t){return t.text===n.text}).length>0&&(r=!0)),!r){if(e)t.find(".select2-search-choice-close").on("mousedown",this.bind(function(n){n.preventDefault(),n.stopPropagation()})).on("click dblclick",this.bind(function(n){this.isInterfaceEnabled()&&($(n.target).closest(".select2-search-choice").fadeOut("fast",this.bind(function(){this.unselect($(n.target)),this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus"),this.close(),this.focusSearch()})).dequeue(),n.preventDefault(),n.stopPropagation())})).on("focus",this.bind(function(){this.isInterfaceEnabled()&&(this.container.addClass("select2-container-active"),this.dropdown.addClass("select2-drop-active"))}));t.data("select2-data",n),this.opts.insertBefore?t.insertBefore(this.searchContainer):this.opts.insertIntoId?($(this.opts.insertIntoId).append(t),(this.opts.animateInsert==null||this.opts.animateInsert)&&$(this.opts.insertIntoId).animate({scrollTop:$(this.opts.insertIntoId)[0].scrollHeight},700)):$(this.searchContainer).parent().append(t),o.push(c),this.setVal(o)}};function n(n,i){for(var r=0,u=i.length;r<u;r=r+1)if(t(n,i[r]))return r;return-1}function t(n,t){return n===t?!0:n===undefined||t===undefined?!1:n===null||t===null?!1:n.constructor===String?n+""==t+"":t.constructor===String?t+""==n+"":!1}window.Select2["class"].multi.prototype.updateSelection=function(t){var r=[],u=[],i=this;$(t).each(function(){n(i.id(this),r)<0&&(r.push(i.id(this)),u.push(this))}),t=u,this.opts.insertIntoId?$(this.opts.insertIntoId).find(".select2-search-choice").remove():this.selection.find(".select2-search-choice").remove(),$(t).each(function(){i.addSelectedChoice(this)}),i.postprocessResults()},window.Select2["class"].single.prototype.createContainer=function(){return $(document.createElement("div")).attr({"class":"select2-container"}).html("<a href='javascript:void(0)' class='select2-choice' tabindex='-1'>   <span class='select2-chosen'>&#160;<\/span><abbr class='select2-search-choice-close glyphicon glyphicon-remove-sign'><\/abbr>   <span class='select2-arrow' role='presentation'><b role='presentation'><\/b><\/span><\/a><label for='' class='select2-offscreen'><\/label><input class='select2-focusser select2-offscreen' type='text' aria-haspopup='true' role='button' /><div class='select2-drop select2-display-none'>   <div class='select2-search'>       <label for='' class='select2-offscreen'><\/label>       <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input' role='combobox' aria-expanded='true'       aria-autocomplete='list' />   <\/div>   <ul class='select2-results' role='listbox'>   <\/ul><\/div>")}}})