(function(){var g,a,h,e,f,c={}.hasOwnProperty,d=function(l,j){for(var i in j){if(c.call(j,i)){l[i]=j[i]}}function k(){this.constructor=l}k.prototype=j.prototype;l.prototype=new k();l.__super__=j.prototype;return l};g=jQuery;e=(function(){function i(){this.options_index=0;this.parsed=[]}i.prototype.add_node=function(j){if(j.nodeName.toUpperCase()==="OPTGROUP"){return this.add_group(j)}else{return this.add_option(j)}};i.prototype.add_group=function(p){var o,l,n,k,m,j;o=this.parsed.length;this.parsed.push({array_index:o,group:true,label:this.escapeExpression(p.label),title:p.title?p.title:void 0,children:0,disabled:p.disabled,classes:p.className});m=p.childNodes;j=[];for(n=0,k=m.length;n<k;n++){l=m[n];j.push(this.add_option(l,o,p.disabled))}return j};i.prototype.add_option=function(k,l,j){if(k.nodeName.toUpperCase()==="OPTION"){if(k.text!==""){if(l!=null){this.parsed[l].children+=1}this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:k.value,text:k.text,html:k.innerHTML,title:k.title?k.title:void 0,selected:k.selected,disabled:j===true?j:k.disabled,group_array_index:l,group_label:l!=null?this.parsed[l].label:null,classes:k.className,style:k.style.cssText})}else{this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:true})}return this.options_index+=1}};i.prototype.escapeExpression=function(l){var k,j;if((l==null)||l===false){return""}if(!/[\&\<\>\"\'\`]/.test(l)){return l}k={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"};j=/&(?!\w+;)|[\<\>\"\'\`]/g;return l.replace(j,function(m){return k[m]||"&amp;"})};return i})();e.select_to_array=function(i){var n,m,l,j,k;m=new e();k=i.childNodes;for(l=0,j=k.length;l<j;l++){n=k[l];m.add_node(n)}return m.parsed};var b=/^[\d#\*\+pe\?][\d#\*pe\?]{0,}$/;a=(function(){function i(j,k){this.form_field=j;this.options=k!=null?k:{};this.is_multiple=this.form_field.multiple;this.set_default_text();this.set_default_values();this.setup();this.set_up_html();this.register_observers();this.on_ready()}i.prototype.set_default_values=function(){var j=this;this.click_test_action=function(k){return j.test_active_click(k)};this.activate_action=function(k){return j.activate_field(k)};this.active_field=false;this.mouse_on_container=false;this.results_showing=false;this.result_highlighted=null;this.allow_single_deselect=(this.options.allow_single_deselect!=null)&&(this.form_field.options[0]!=null)&&this.form_field.options[0].text===""?this.options.allow_single_deselect:false;this.disable_search_threshold=this.options.disable_search_threshold||0;this.disable_search=this.options.disable_search||false;this.enable_split_word_search=this.options.enable_split_word_search!=null?this.options.enable_split_word_search:true;this.group_search=this.options.group_search!=null?this.options.group_search:true;this.search_contains=this.options.search_contains||false;this.single_backstroke_delete=this.options.single_backstroke_delete!=null?this.options.single_backstroke_delete:true;this.max_selected_options=this.options.max_selected_options||Infinity;this.inherit_select_classes=this.options.inherit_select_classes||false;this.display_selected_options=this.options.display_selected_options!=null?this.options.display_selected_options:true;this.display_disabled_options=this.options.display_disabled_options!=null?this.options.display_disabled_options:true;this.include_group_label_in_selected=this.options.include_group_label_in_selected||false;this.max_shown_results=this.options.max_shown_results||Number.POSITIVE_INFINITY;return this.case_sensitive_search=this.options.case_sensitive_search||false};i.prototype.set_default_text=function(){if(this.form_field.getAttribute("data-placeholder")){this.default_text=this.form_field.getAttribute("data-placeholder")}else{if(this.is_multiple){this.default_text=this.options.placeholder_text_multiple||this.options.placeholder_text||i.default_multiple_text}else{this.default_text=this.options.placeholder_text_single||this.options.placeholder_text||i.default_single_text}}return this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||i.default_no_result_text};i.prototype.choice_label=function(j){if(this.include_group_label_in_selected&&(j.group_label!=null)){return"<b class='group-name'>"+j.group_label+"</b>"+j.html}else{return j.html}};i.prototype.mouse_enter=function(){return this.mouse_on_container=true};i.prototype.mouse_leave=function(){return this.mouse_on_container=false};i.prototype.input_focus=function(j){var k=this;if(this.is_multiple){if(!this.active_field){return setTimeout((function(){return k.container_mousedown()}),50)}}else{if(!this.active_field){return this.activate_field()}}};i.prototype.input_blur=function(j){var k=this;if(!this.mouse_on_container){this.active_field=false;if(this.max_selected_options>this.choices_count()&&b.test(this.search_field.val())){this.result_clear_highlight();this.result_select(j)}return setTimeout((function(){return k.blur_test()}),100)}};i.prototype.results_option_build=function(k){var l,o,p,q,n,j,m;l="";q=0;m=this.results_data;for(n=0,j=m.length;n<j;n++){o=m[n];p="";if(o.group){p=this.result_add_group(o)}else{p=this.result_add_option(o)}if(p!==""){q++;l+=p}if(k!=null?k.first:void 0){if(o.selected&&this.is_multiple){this.choice_build(o)}else{if(o.selected&&!this.is_multiple){this.single_set_selected_text(this.choice_label(o))}}}if(q>=this.max_shown_results){break}}return l};i.prototype.result_add_option=function(l){var k,j;if(!l.search_match){return""}if(!this.include_option_in_results(l)){return""}k=[];if(!l.disabled&&!(l.selected&&this.is_multiple)){k.push("active-result")}if(l.disabled&&!(l.selected&&this.is_multiple)){k.push("disabled-result")}if(l.selected){k.push("result-selected")}if(l.group_array_index!=null){k.push("group-option")}if(l.classes!==""){k.push(l.classes)}j=document.createElement("li");j.className=k.join(" ");j.style.cssText=l.style;j.setAttribute("data-option-array-index",l.array_index);j.innerHTML=l.search_text;if(l.title){j.title=l.title}return this.outerHTML(j)};i.prototype.result_add_group=function(l){var k,j;if(!(l.search_match||l.group_match)){return""}if(!(l.active_options>0)){return""}k=[];k.push("group-result");if(l.classes){k.push(l.classes)}j=document.createElement("li");j.className=k.join(" ");j.innerHTML=l.search_text;if(l.title){j.title=l.title}return this.outerHTML(j)};i.prototype.results_update_field=function(){this.set_default_text();if(!this.is_multiple){this.results_reset_cleanup()}this.result_clear_highlight();this.results_build();if(this.results_showing){return this.winnow_results()}};i.prototype.reset_single_select_options=function(){var j,n,l,m,k;m=this.results_data;k=[];for(n=0,l=m.length;n<l;n++){j=m[n];if(j.selected){k.push(j.selected=false)}else{k.push(void 0)}}return k};i.prototype.results_toggle=function(){if(this.results_showing){return this.results_hide()}else{return this.results_show()}};i.prototype.results_search=function(j){if(this.results_showing){return this.winnow_results()}else{return this.results_show()}};i.prototype.winnow_results=function(){var u,o,r,n,j,t,p,s,k,l,q,m;this.no_results_clear();n=0;t=this.get_search_text();u=t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");k=new RegExp(u,"i");r=this.get_search_regex(u);m=this.results_data;for(l=0,q=m.length;l<q;l++){o=m[l];o.search_match=false;j=null;if(this.include_option_in_results(o)){if(o.group){o.group_match=false;o.active_options=0}if((o.group_array_index!=null)&&this.results_data[o.group_array_index]){j=this.results_data[o.group_array_index];if(j.active_options===0&&j.search_match){n+=1}j.active_options+=1}o.search_text=o.group?o.label:o.html;if(!(o.group&&!this.group_search)){o.search_match=this.search_string_match(o.search_text,r);if(o.search_match&&!o.group){n+=1}if(o.search_match){if(t.length){p=o.search_text.search(k);s=o.search_text.substr(0,p+t.length)+"</em>"+o.search_text.substr(p+t.length);o.search_text=s.substr(0,p)+"<em>"+s.substr(p)}if(j!=null){j.group_match=true}}else{if((o.group_array_index!=null)&&this.results_data[o.group_array_index].search_match){o.search_match=true}}}}}this.result_clear_highlight();if(n<1&&t.length){this.update_results_content("");return this.no_results(t)}else{this.update_results_content(this.results_option_build());return this.winnow_results_set_highlight()}};i.prototype.get_search_regex=function(k){var j,l;j=this.search_contains?"":"^";l=this.case_sensitive_search?"":"i";return new RegExp(j+k,l)};i.prototype.search_string_match=function(o,l){var k,n,m,j;if(l.test(o)){return true}else{if(this.enable_split_word_search&&(o.indexOf(" ")>=0||o.indexOf("[")===0)){n=o.replace(/\[|\]/g,"").split(" ");if(n.length){for(m=0,j=n.length;m<j;m++){k=n[m];if(l.test(k)){return true}}}}}};i.prototype.choices_count=function(){var k,m,j,l;if(this.selected_option_count!=null){return this.selected_option_count}this.selected_option_count=0;l=this.form_field.options;for(m=0,j=l.length;m<j;m++){k=l[m];if(k.selected){this.selected_option_count+=1}}return this.selected_option_count};i.prototype.choices_click=function(j){j.preventDefault();if(!(this.results_showing||this.is_disabled)){return this.results_show()}};i.prototype.keyup_checker=function(j){var m,l;m=(l=j.which)!=null?l:j.keyCode;this.search_field_scale();switch(m){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0){return this.keydown_backstroke()}else{if(!this.pending_backstroke){this.result_clear_highlight();return this.results_search()}}break;case 13:j.preventDefault();var k=this.search_field.val();if(this.results_showing&&this.result_highlight){return this.result_select(j)}else{if(this.results_showing&&!this.result_highlight&&b.test(k)){return this.result_select(j,true)}else{if(this.results_showing&&!this.result_highlight&&!b.test(k)){this.generate_invalid_number_note()}else{if(!this.result_highlight&&b.test(k)){return this.result_select(j)}}}}break;case 27:if(this.results_showing){this.results_hide()}return true;case 59:case 186:j.preventDefault();var k=this.search_field.val();k=this.search_field.val().length<3?k:k.substring(0,k.length-1);this.search_field.val(k);if(this.results_showing&&this.result_highlight){return this.result_select(j)}else{if(this.results_showing&&!this.result_highlight&&b.test(k)){return this.result_select(j)}else{if(this.results_showing&&!this.result_highlight&&!b.test(k)){this.generate_invalid_number_note()}else{if(!this.result_highlight&&b.test(k)){return this.result_select(j)}}}}break;case 9:case 38:case 40:case 16:case 91:case 17:case 18:break;default:return this.results_search()}};i.clearInvalidNoteTimer=null;i.prototype.generate_invalid_number_note=function(){if(this.clearInvalidNoteTimer){window.clearTimeout(this.clearInvalidNoteTimer);this.clearInvalidNoteTimer=null}g("#searchNumberInvalidWord").hide().remove();g('<i class="colorRed" id="searchNumberInvalidWord" data-trans="phone_number_invalid"></i>').appendTo(".no-results");g(".no-results").translate();this.clearInvalidNoteTimer=addTimeout(function(){g("#searchNumberInvalidWord").hide().remove()},3000)};i.prototype.clipboard_event_checker=function(j){var k=this;return setTimeout((function(){return k.results_search()}),50)};i.prototype.container_width=function(){if(this.options.width!=null){return this.options.width}else{return""+this.form_field.offsetWidth+"px"}};i.prototype.include_option_in_results=function(j){if(this.is_multiple&&(!this.display_selected_options&&j.selected)){return false}if(!this.display_disabled_options&&j.disabled){return false}if(j.empty){return false}return true};i.prototype.search_results_touchstart=function(j){this.touch_started=true;return this.search_results_mouseover(j)};i.prototype.search_results_touchmove=function(j){this.touch_started=false;return this.search_results_mouseout(j)};i.prototype.search_results_touchend=function(j){if(this.touch_started){return this.search_results_mouseup(j)}};i.prototype.outerHTML=function(k){var j;if(k.outerHTML){return k.outerHTML}j=document.createElement("div");j.appendChild(k);return j.innerHTML};i.browser_is_supported=function(){if("Microsoft Internet Explorer"===window.navigator.appName){return document.documentMode>=8}if(/iP(od|hone)/i.test(window.navigator.userAgent)||/IEMobile/i.test(window.navigator.userAgent)||/Windows Phone/i.test(window.navigator.userAgent)||/BlackBerry/i.test(window.navigator.userAgent)||/BB10/i.test(window.navigator.userAgent)||/Android.*Mobile/i.test(window.navigator.userAgent)){return false}return true};i.default_multiple_text=g.i18n.prop("select_some_options");i.default_single_text=g.i18n.prop("select_an_option");i.default_no_result_text=g.i18n.prop("sms_chat_input_confirm");return i})();g.fn.extend({chosen:function(i){if(!a.browser_is_supported()){}return this.each(function(k){var l,j;l=g(this);j=l.data("chosen");if(i==="destroy"){if(j instanceof h){j.destroy()}return}if(!(j instanceof h)){l.data("chosen",new h(this,i))}})}});h=(function(i){d(j,i);function j(){f=j.__super__.constructor.apply(this,arguments);return f}j.prototype.setup=function(){this.form_field_jq=g(this.form_field);this.current_selectedIndex=this.form_field.selectedIndex;return this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")};j.prototype.set_up_html=function(){var k,l;k=["chosen-container"];k.push("chosen-container-"+(this.is_multiple?"multi":"single"));if(this.inherit_select_classes&&this.form_field.className){k.push(this.form_field.className)}if(this.is_rtl){k.push("chosen-rtl")}l={"class":k.join(" "),style:"width: "+(this.container_width())+";",title:this.form_field.title};if(this.form_field.id.length){l.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"}this.container=g("<div />",l);if(this.is_multiple){this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" id="chosen-search-field-input" maxlength="40" data-trans="select_some_options" value="'+g.i18n.prop("select_some_options")+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>')}else{this.container.html('<a class="chosen-single chosen-default"><span>'+g.i18n.prop("select_some_options")+'</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>')}this.form_field_jq.hide().after(this.container);this.dropdown=this.container.find("div.chosen-drop").first();this.search_field=this.container.find("input").first();this.search_results=this.container.find("ul.chosen-results").first();this.search_field_scale();this.search_no_results=this.container.find("li.no-results").first();if(this.is_multiple){this.search_choices=this.container.find("ul.chosen-choices").first();this.search_container=this.container.find("li.search-field").first()}else{this.search_container=this.container.find("div.chosen-search").first();this.selected_item=this.container.find(".chosen-single").first()}this.results_build();this.set_tab_index();return this.set_label_behavior()};j.prototype.on_ready=function(){return this.form_field_jq.trigger("chosen:ready",{chosen:this})};j.prototype.register_observers=function(){var k=this;this.container.bind("touchstart.chosen",function(l){k.container_mousedown(l);return l.preventDefault()});this.container.bind("touchend.chosen",function(l){k.container_mouseup(l);return l.preventDefault()});this.container.bind("mousedown.chosen",function(l){k.container_mousedown(l)});this.container.bind("mouseup.chosen",function(l){k.container_mouseup(l)});this.container.bind("mouseenter.chosen",function(l){k.mouse_enter(l)});this.container.bind("mouseleave.chosen",function(l){k.mouse_leave(l)});this.search_results.bind("mouseup.chosen",function(l){k.search_results_mouseup(l)});this.search_results.bind("mouseover.chosen",function(l){k.search_results_mouseover(l)});this.search_results.bind("mouseout.chosen",function(l){k.search_results_mouseout(l)});this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(l){k.search_results_mousewheel(l)});this.search_results.bind("touchstart.chosen",function(l){k.search_results_touchstart(l)});this.search_results.bind("touchmove.chosen",function(l){k.search_results_touchmove(l)});this.search_results.bind("touchend.chosen",function(l){k.search_results_touchend(l)});this.form_field_jq.bind("chosen:updated.chosen",function(l){k.results_update_field(l)});this.form_field_jq.bind("chosen:activate.chosen",function(l){k.activate_field(l)});this.form_field_jq.bind("chosen:open.chosen",function(l){k.container_mousedown(l)});this.form_field_jq.bind("chosen:close.chosen",function(l){k.input_blur(l)});this.search_field.bind("blur.chosen",function(l){k.input_blur(l)});this.search_field.bind("keyup.chosen",function(l){k.keyup_checker(l)});this.search_field.bind("keydown.chosen",function(l){k.keydown_checker(l)});this.search_field.bind("focus.chosen",function(l){k.input_focus(l)});this.search_field.bind("cut.chosen",function(l){k.clipboard_event_checker(l)});this.search_field.bind("paste.chosen",function(l){k.clipboard_event_checker(l)});if(this.is_multiple){return this.search_choices.bind("click.chosen",function(l){k.choices_click(l)})}else{return this.container.bind("click.chosen",function(l){l.preventDefault()})}};j.prototype.destroy=function(){g(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action);if(this.search_field[0].tabIndex){this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex}this.container.remove();this.form_field_jq.removeData("chosen");return this.form_field_jq.show()};j.prototype.search_field_disabled=function(){this.is_disabled=this.form_field_jq[0].disabled;if(this.is_disabled){this.container.addClass("chosen-disabled");this.search_field[0].disabled=true;if(!this.is_multiple){this.selected_item.unbind("focus.chosen",this.activate_action)}return this.close_field()}else{this.container.removeClass("chosen-disabled");this.search_field[0].disabled=false;if(!this.is_multiple){return this.selected_item.bind("focus.chosen",this.activate_action)}}};j.prototype.container_mousedown=function(k){if(!this.is_disabled){if(k&&k.type==="mousedown"&&!this.results_showing){k.preventDefault()}if(!((k!=null)&&(g(k.target)).hasClass("search-choice-close"))){if(!this.active_field){if(this.is_multiple){this.search_field.val("")}g(this.container[0].ownerDocument).bind("click.chosen",this.click_test_action);this.results_show()}else{if(!this.is_multiple&&k&&((g(k.target)[0]===this.selected_item[0])||g(k.target).parents("a.chosen-single").length)){k.preventDefault();this.results_toggle()}}return this.activate_field()}}};j.prototype.container_mouseup=function(k){if(k.target.nodeName==="ABBR"&&!this.is_disabled){return this.results_reset(k)}};j.prototype.search_results_mousewheel=function(k){var l;if(k.originalEvent){l=k.originalEvent.deltaY||-k.originalEvent.wheelDelta||k.originalEvent.detail}if(l!=null){k.preventDefault();if(k.type==="DOMMouseScroll"){l=l*40}return this.search_results.scrollTop(l+this.search_results.scrollTop())}};j.prototype.blur_test=function(k){if(!this.active_field&&this.container.hasClass("chosen-container-active")){return this.close_field()}};j.prototype.close_field=function(){g(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action);this.active_field=false;this.results_hide();this.container.removeClass("chosen-container-active");this.clear_backstroke();this.show_search_field_default();return this.search_field_scale()};j.prototype.activate_field=function(){this.container.addClass("chosen-container-active");this.active_field=true;this.search_field.val(this.search_field.val());return this.search_field.focus()};j.prototype.test_active_click=function(k){var l;l=g(k.target).closest(".chosen-container");if(l.length&&this.container[0]===l[0]){return this.active_field=true}else{return this.close_field()}};j.prototype.results_build=function(){this.parsing=true;this.selected_option_count=null;this.results_data=e.select_to_array(this.form_field);if(this.is_multiple){this.search_choices.find("li.search-choice").remove()}else{if(!this.is_multiple){this.single_set_selected_text();if(this.disable_search||this.form_field.options.length<=this.disable_search_threshold){this.search_field[0].readOnly=true;this.container.addClass("chosen-container-single-nosearch")}else{this.search_field[0].readOnly=false;this.container.removeClass("chosen-container-single-nosearch")}}}this.update_results_content(this.results_option_build({first:true}));this.search_field_disabled();this.show_search_field_default();this.search_field_scale();return this.parsing=false};j.prototype.result_do_highlight=function(l){var p,o,m,n,k;if(l.length){this.result_clear_highlight();this.result_highlight=l;this.result_highlight.addClass("highlighted");m=parseInt(this.search_results.css("maxHeight"),10);k=this.search_results.scrollTop();n=m+k;o=this.result_highlight.position().top+this.search_results.scrollTop();p=o+this.result_highlight.outerHeight();if(p>=n){return this.search_results.scrollTop((p-m)>0?p-m:0)}else{if(o<k){return this.search_results.scrollTop(o)}}}};j.prototype.result_clear_highlight=function(){if(this.result_highlight){this.result_highlight.removeClass("highlighted")}return this.result_highlight=null};j.prototype.results_show=function(){if(this.is_multiple&&this.max_selected_options<=this.choices_count()){this.form_field_jq.trigger("chosen:maxselected",{chosen:this});return false}this.container.addClass("chosen-with-drop");this.results_showing=true;this.search_field.focus();this.search_field.val(this.search_field.val());this.winnow_results();return this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this})};j.prototype.update_results_content=function(k){return this.search_results.html(k)};j.prototype.results_hide=function(){if(this.results_showing){this.result_clear_highlight();this.container.removeClass("chosen-with-drop");this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})}return this.results_showing=false};j.prototype.set_tab_index=function(l){var k;if(this.form_field.tabIndex){k=this.form_field.tabIndex;this.form_field.tabIndex=-1;return this.search_field[0].tabIndex=k}};j.prototype.set_label_behavior=function(){var k=this;this.form_field_label=this.form_field_jq.parents("label");if(!this.form_field_label.length&&this.form_field.id.length){this.form_field_label=g("label[for='"+this.form_field.id+"']")}if(this.form_field_label.length>0){return this.form_field_label.bind("click.chosen",function(l){if(k.is_multiple){return k.container_mousedown(l)}else{return k.activate_field()}})}};j.prototype.show_search_field_default=function(){if(this.is_multiple&&this.choices_count()<1&&!this.active_field){this.search_field.val(g.i18n.prop("select_some_options"));return this.search_field.addClass("default")}else{this.search_field.val("");return this.search_field.removeClass("default")}};j.prototype.search_results_mouseup=function(k){var l;l=g(k.target).hasClass("active-result")?g(k.target):g(k.target).parents(".active-result").first();if(l.length){this.result_highlight=l;this.result_select(k);return this.search_field.focus()}};j.prototype.search_results_mouseover=function(k){var l;l=g(k.target).hasClass("active-result")?g(k.target):g(k.target).parents(".active-result").first();if(l){return this.result_do_highlight(l)}};j.prototype.search_results_mouseout=function(k){if(g(k.target).hasClass("active-result"||g(k.target).parents(".active-result").first())){return this.result_clear_highlight()}};j.prototype.choice_build=function(l){var k,m,n=this;k=g("<li />",{"class":"search-choice"}).html("<span>"+(this.choice_label(l))+"</span>");if(l.disabled){k.addClass("search-choice-disabled")}else{m=g("<a />",{"class":"search-choice-close","data-option-array-index":l.array_index});m.bind("click.chosen",function(o){return n.choice_destroy_link_click(o)});k.append(m)}return this.search_container.before(k)};j.prototype.choice_destroy_link_click=function(k){k.preventDefault();k.stopPropagation();if(!this.is_disabled){return this.choice_destroy(g(k.target))}};j.prototype.choice_destroy=function(k){if(this.result_deselect(k[0].getAttribute("data-option-array-index"))){this.show_search_field_default();if(this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1){this.results_hide()}k.parents("li").first().remove();return this.search_field_scale()}};j.prototype.results_reset=function(){this.reset_single_select_options();this.form_field.options[0].selected=true;this.single_set_selected_text();this.show_search_field_default();this.results_reset_cleanup();this.form_field_jq.trigger("change");if(this.active_field){return this.results_hide()}};j.prototype.results_reset_cleanup=function(){this.current_selectedIndex=this.form_field.selectedIndex;return this.selected_item.find("abbr").remove()};j.prototype.result_select=function(s,p){var m,t;if(this.result_highlight){m=this.result_highlight;this.result_clear_highlight();if(this.is_multiple&&this.max_selected_options<=this.choices_count()){this.form_field_jq.trigger("chosen:maxselected",{chosen:this});return false}if(this.is_multiple){m.removeClass("active-result")}else{this.reset_single_select_options()}m.addClass("result-selected");t=this.results_data[m[0].getAttribute("data-option-array-index")];t.selected=true;this.form_field.options[t.options_index].selected=true;this.selected_option_count=null;if(this.is_multiple){this.choice_build(t)}else{this.single_set_selected_text(this.choice_label(t))}if(!((s.metaKey||s.ctrlKey)&&this.is_multiple)){this.results_hide()}this.show_search_field_default();if(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex){this.form_field_jq.trigger("change",{selected:this.form_field.options[t.options_index].value})}this.current_selectedIndex=this.form_field.selectedIndex;s.preventDefault();return this.search_field_scale()}else{var r=this.search_field.val();var q=false;var k=8;for(var n=0;n<this.form_field.options.length;n++){if(this.form_field.options[n].value==getLastNumber(r,k)){if(this.max_selected_options>this.choices_count()){this.form_field.options[n].selected=true}q=true;break}}if(!q&&this.max_selected_options>this.choices_count()){var o=true;var l=new Option(r,getLastNumber(r,k),false,o);l.source="0";this.form_field.add(l)}this.results_build();this.no_results_clear();return this.search_field_scale()}};j.prototype.single_set_selected_text=function(k){if(k==null){k=this.default_text}if(k===this.default_text){this.selected_item.addClass("chosen-default")}else{this.single_deselect_control_build();this.selected_item.removeClass("chosen-default")}return this.selected_item.find("span").html(k)};j.prototype.result_deselect=function(m){var l,k;l=this.results_data[m];if(!this.form_field.options[l.options_index].disabled){l.selected=false;this.form_field.options[l.options_index].selected=false;this.selected_option_count=null;this.result_clear_highlight();if(this.results_showing){this.winnow_results()}this.form_field_jq.trigger("change",{deselected:this.form_field.options[l.options_index].value});if(this.form_field.options[l.options_index].text.indexOf("/")<0&&this.form_field.options[l.options_index].source=="0"){if(!!window.ActiveXObject||"ActiveXObject" in window){this.form_field.options[l.options_index].removeNode(true)}else{this.form_field.options[l.options_index].remove()}this.results_build()}this.search_field_scale();return true}else{return false}};j.prototype.single_deselect_control_build=function(){if(!this.allow_single_deselect){return}if(!this.selected_item.find("abbr").length){this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>')}return this.selected_item.addClass("chosen-single-with-deselect")};j.prototype.get_search_text=function(){return g("<div/>").text(g.trim(this.search_field.val())).html()};j.prototype.winnow_results_set_highlight=function(){var k,l;l=!this.is_multiple?this.search_results.find(".result-selected.active-result"):[];k=l.length?l.first():this.search_results.find(".active-result").first();if(k!=null){return this.result_do_highlight(k)}};j.prototype.no_results=function(k){var l;l=g('<li class="no-results"><b data-trans="sms_chat_input_confirm">'+this.results_none_found+"</b> <span></span></li>");this.search_results.append(l);g(".no-results").translate();return this.form_field_jq.trigger("chosen:no_results",{chosen:this})};j.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()};j.prototype.keydown_arrow=function(){var k;if(this.results_showing&&this.result_highlight){k=this.result_highlight.nextAll("li.active-result").first();if(k){return this.result_do_highlight(k)}}else{return this.results_show()}};j.prototype.keyup_arrow=function(){var k;if(!this.results_showing&&!this.is_multiple){return this.results_show()}else{if(this.result_highlight){k=this.result_highlight.prevAll("li.active-result");if(k.length){return this.result_do_highlight(k.first())}else{if(this.choices_count()>0){this.results_hide()}return this.result_clear_highlight()}}}};j.prototype.keydown_backstroke=function(){var k;if(this.pending_backstroke){this.choice_destroy(this.pending_backstroke.find("a").first());return this.clear_backstroke()}else{k=this.search_container.siblings("li.search-choice").last();if(k.length&&!k.hasClass("search-choice-disabled")){this.pending_backstroke=k;if(this.single_backstroke_delete){return this.keydown_backstroke()}else{return this.pending_backstroke.addClass("search-choice-focus")}}}};j.prototype.clear_backstroke=function(){if(this.pending_backstroke){this.pending_backstroke.removeClass("search-choice-focus")}return this.pending_backstroke=null};j.prototype.keydown_checker=function(l){var m,k;m=(k=l.which)!=null?k:l.keyCode;this.search_field_scale();if(m!==8&&this.pending_backstroke){this.clear_backstroke()}switch(m){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:if(this.results_showing&&!this.is_multiple){this.result_select(l)}this.mouse_on_container=false;break;case 13:if(this.results_showing){l.preventDefault()}break;case 32:if(this.disable_search){l.preventDefault()}break;case 38:l.preventDefault();this.keyup_arrow();break;case 40:l.preventDefault();this.keydown_arrow();break;case 59:case 186:if(this.search_field.val().length<3){l.preventDefault()}break}};j.prototype.search_field_scale=function(){var k,o,n,l,r,s,q,m,p;if(this.is_multiple){n=0;q=0;r="position:absolute; left: -1000px; top: -1000px; display:none;";s=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(m=0,p=s.length;m<p;m++){l=s[m];r+=l+":"+this.search_field.css(l)+";"}k=g("<div />",{style:r});k.text(this.search_field.val());g("body").append(k);q=k.width()+25;k.remove();o=this.container.outerWidth();if(q>o-10){q=o-10}return this.search_field.css({width:q+"px"})}};j.prototype.generate_random_id=function(){var k;k="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(g("#"+k).length>0){k+=this.generate_random_char()}return k};return j})(a)}).call(this);