var sg=window.sg||{};sg.classie_select2_helper={match_data:{},staticCommon:null,subjectMisses:[],subjectHits:[],beneficiaryMisses:[],beneficiaryHits:[],select2_helper_type:"classie",init:function(e,t){this.staticCommon=t||$("body").data("static-common");var o=this;e.find(".taxonomy_selector option,optgroup").each((function(){o.match_data[$.trim(this.text)]={matchString:$(this).data("matchstring")}})),this.setupElement(e,this.subjectMisses,this.subjectHits,this.beneficiaryMisses,this.beneficiaryHits)},setMatchData:function(e){this.match_data=e},showBreadcrumb:function(e,t,o,n){void 0===n?$(e).find(".selection_prompt").text("Your selection:"):$(e).find(".selection_prompt").text(n);var s=$(e).find(".selection_status_choice1"),i=$(e).find(".selection_status_choice2");if(s.text(o),i.text(""),""!==o&&-1!==t.indexOf("SUB")){sg.classie_select2_helper.formatBreadcrumb(s,i);var l="<a class ='qTipSelected' url ='/json/universalChoice/"+t+"/tooltip' style='cursor:pointer;'><img class='taxonomy_definition' style='margin-left:0px' src='"+this.staticCommon+"/img/classie_definition_icon.png' width=14/></a>";""===i.text()?s.append(l):i.append(l)}},formatBreadcrumb:function(e,t){if($(e).closest("div")[0].scrollWidth>$(e).closest("div").innerWidth()){var o=$(e).html(),n=o.substr(0,o.lastIndexOf("&gt;")),s=o.substr(o.lastIndexOf("&gt;"));$(e).html(n),$(e).closest("div")[0].scrollWidth>$(e).closest("div").innerWidth()&&n.indexOf("&gt;")>0&&(s=n.substr(n.lastIndexOf("&gt;"))+s,n=n.substr(0,n.lastIndexOf("&gt;")),$(e).html(n)),void 0!==t?$(t).html(s):$(e).append("<div>"+s+"</div>")}},formatSelections:function(){$("div.universalChoiceTreeSelection").each((function(){sg.classie_select2_helper.formatBreadcrumb(this)}))},highlightOption:function(e,t){$(".browse_selection_choice.highlighted .browse_selection_level"+t).each((function(){$(this).parent().parent().removeClass("highlighted")})),$(e).parent().parent().addClass("highlighted")},scrollBrowserLeft:function(e,t,o,n){var s=this;$(e).find(".taxonomy_alt_scroller_wrapper").animate({scrollLeft:t},800),$(e).find(".arrow"+(n-1)).addClass("back"),$(e).find(".arrow"+(n-1)+" img").attr("src",s.staticCommon+"/img/browse_arrow_backward.png"),$(e).find(".arrow"+(n-1)+" img").click((function(){$(e).find(".taxonomy_alt_scroller_wrapper").animate({scrollLeft:o},800),$(e).find(".arrow"+(n-1)).removeClass("back"),$(e).find(".arrow"+(n-1)+" img").attr("src",s.staticCommon+"/img/browse_arrow_forward.png"),$(e).find(".arrow"+(n-1)+" img").off("click")})),$(e).find(".arrow"+n).show()},populateBrowseLevel:function(e,t,o){var n,s=this,i=[],l=0,a=" .taxonomy_selector > option.level"+t,c="Select a category or child-category.";$("#lookup_response_selection_prompt").length&&(c=$("#lookup_response_selection_prompt").val()),void 0!==o&&(a+='[data-parent="'+o+'"]');var r=$(e+a),d=$(e+" .taxonomy_selector").select2("val");$(r).each((function(){(n=this.text).lastIndexOf(">")>0&&(n=n.substr(n.lastIndexOf(">")+2));var e=$(this).hasClass("deprecated-show")?"&nbsp;<span class='sg-field-deprecated'>Archived</span>":"",o=-1!==$.inArray("uc_"+this.id,d);$(this).hasClass("deprecated-hidden")||(i[l++]="<div class='browse_selection_choice"+(o?" selected":"")+"' data-choice='"+this.text+"'><label style='display: inline-block; margin-bottom: 0px;'><input id="+this.id+" class='noDefaultSelection browse_selection_level"+t+"' name='browse_selection_level"+t+"' type='radio' value='"+$(this).attr("value")+"'"+(o&&$(this).hasClass("leaf-node")?" disabled ":"")+">"+n+e+"</label></div>")})),$(e+" .taxonomy_level"+t).html(""),$(e+" .taxonomy_level"+t).append(i),1===t&&($(e).find(".divider").removeClass("back"),$(e).find(".divider img").attr("src",s.staticCommon+"/img/browse_arrow_forward.png"),$(e).find(".arrow1").show(),$(e).find(".arrow2").hide(),$(e).find(".arrow3").hide(),s.showBreadcrumb(e,"","",c),$(e).find(".taxonomy_select_button").prop("disabled",!0),$(e).find(".browse_selection_level1").click((function(){$(e).find(".taxonomy_select_button").prop("disabled",$(this).closest("div").hasClass("selected")),$(e).find(".taxonomy_level2").empty(),s.populateBrowseLevel(e,2,this.id),s.highlightOption(this,1),s.showBreadcrumb(e,this.id,$(this).parent().parent().data("choice"))}))),2===t&&$(e).find(".browse_selection_level2").click((function(){$(e).find(".taxonomy_select_button").prop("disabled",$(this).closest("div").hasClass("selected")),$(e).find(".taxonomy_level3").empty(),s.populateBrowseLevel(e,3,this.id),s.highlightOption(this,2),s.showBreadcrumb(e,this.id,$(this).parent().parent().data("choice")),$(e).find(".taxonomy_level3 input").length>0&&s.scrollBrowserLeft(e,274,0,2)})),3===t&&$(e).find(".browse_selection_level3").click((function(){$(e).find(".taxonomy_select_button").prop("disabled",$(this).closest("div").hasClass("selected")),$(e).find(".taxonomy_level4").empty(),s.populateBrowseLevel(e,4,this.id),s.highlightOption(this,3),s.showBreadcrumb(e,this.id,$(this).parent().parent().data("choice")),$(e).find(".taxonomy_level4 input").length>0&&s.scrollBrowserLeft(e,570,274,3)})),4===t&&$(e).find(".browse_selection_level4").click((function(){$(e).find(".taxonomy_select_button").prop("disabled",$(this).closest("div").hasClass("selected")),s.highlightOption(this,4),s.showBreadcrumb(e,this.id,$(this).parent().parent().data("choice"))}))},openTaxonomyBrowse:function(e){"function"==typeof window.ga&&ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJSUBJ",eventAction:"browse-all-open"});var t="";void 0!==e&&(t=void 0!==e.id?"#"+e.id:"#"+e),$("#select2-drop-mask").click(),$(t+" .taxonomy_alt_selector_wrapper").slideDown(),$(t+" .taxonomy_alt_scroller_wrapper").animate({scrollLeft:1},1),$(t+" .taxonomy_alt_selector_wrapper").blur((function(){$(t+" .taxonomy_alt_selector_wrapper").slideUp()})),this.populateBrowseLevel(t,1),$(t).find(".browse_selection_choice input").prop("checked",!1),$(t).find(".browse_selection_choice").removeClass("highlighted")},closeTaxonomyBrowse:function(e){e.find(".taxonomy_alt_selector_wrapper").slideUp(),e.find(".taxonomy_level1").val([]),e.find(".taxonomy_level2").val([]),e.find(".taxonomy_level3").val([]),e.find(".taxonomy_level4").val([]),e.find(".taxonomy_level2").empty(),e.find(".taxonomy_level3").empty(),e.find(".taxonomy_level4").empty()},setupTaxonmyBrowseClick:function(e){var t;t=setInterval((function(){$(".taxonomy_browse_all").length>0&&(clearInterval(t),$(".taxonomy_browse_all").on("click",(function(){var t=e.attr("id");sg.classie_select2_helper.openTaxonomyBrowse(t)})))}),100)},setupElement:function(e,t,o,n,s){var i,l=$(e);if(l.find(".taxonomy_selector optgroup").length>0){l.find(".taxonomy_selector").select2({dropdownCssClass:"bigdrop",matcher:function(e,t){return sg.classie_select2_helper.matchUserInput(e,t)},formatResult:function(e,t,o,n){return sg.sg_select2_helper.formatSelect2Result(e,t,o,n)},formatSelection:function(e){return sg.classie_select2_helper.formatSelectedItem(e)},maximumSelectionSize:$("#"+e[0].id+"_max_responses").val(),formatNoMatches:function(){return"No matches found."},escapeMarkup:function(e){return e}}),l.find(".select2-input").css("min-width","100px");var a=l.find(".taxonomy_selector").select2("val");a&&1==a.length&&a[0]==l.find(".taxonomy_selector option.no-selection").val()?l.find(".taxonomy_selector optgroup,option").addClass("disabled"):a&&a.length>0&&l.find(".taxonomy_selector .no-selection").addClass("disabled"),l.find(".taxonomy_selector").on("select2-selecting",(function(e){var t=$(".select2-container input.select2-input").val();if("function"==typeof window.ga&&ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJBENEFICIARY",eventAction:"search-all-select",eventLabel:t}),e&&e.choice){var o=l.find(".taxonomy_selector").select2("val");-1!=e.choice.css.indexOf("no-selection")?o&&0!=o.length?e.preventDefault():l.find(".taxonomy_selector optgroup,option").addClass("disabled"):o&&1==o.length&&o[0]==l.find(".taxonomy_selector option.no-selection").val()?e.preventDefault():l.find(".taxonomy_selector .no-selection").addClass("disabled")}})),l.find(".taxonomy_selector").on("change",(function(e){if(e&&e.removed){var t=l.find(".taxonomy_selector").select2("val");-1!=e.removed.css.indexOf("no-selection")?l.find(".taxonomy_selector optgroup,option").removeClass("disabled"):0==t.length&&l.find(".taxonomy_selector option.no-selection").removeClass("disabled")}})),sg.sg_select2_helper.setUpLevelIndent(l),l.find(".select2-container input.select2-input").on("keyup",(function(){var e=$(this).val(),t=$("#select2-drop").find(".select2-no-results");clearTimeout(i),i=setTimeout((function(){"function"==typeof window.ga&&(0===t.length&&""!==$.trim(e)?-1==$.inArray(e,s)&&(s.push(e),ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJBENEFICIARY",eventAction:"search-term-hit",eventLabel:e})):0!==t.length&&""!==$.trim(e)&&-1==$.inArray(e,n)&&(n.push(e),ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJBENEFICIARY",eventAction:"search-term-miss",eventLabel:e})))}),700)}))}else l.find(".taxonomy_selector").length>0&&(l.find(".taxonomy_selector").select2({dropdownCssClass:"bigdrop",matcher:function(e,t){return sg.classie_select2_helper.matchUserInput(e,t)},formatResult:function(e,t,o,n){return sg.sg_select2_helper.formatSelect2Result(e,t,o,n)},formatSelection:function(e){return sg.classie_select2_helper.formatSelectedItem(e)},maximumSelectionSize:$("#"+e[0].id+"_max_responses").val(),minimumInputLength:1,escapeMarkup:function(e){return e},formatInputTooShort:function(){return sg.classie_select2_helper.setupTaxonmyBrowseClick(l),'Type search term(s), or <a class="taxonomy_browse_all" href="javascript:void(0);">Browse All</a>'},formatNoMatches:function(){return sg.classie_select2_helper.setupTaxonmyBrowseClick(l),'<strong>No results.</strong>  Try different search terms, or <a class="taxonomy_browse_all" href="javascript:void(0);" style="font-size:90%">Browse All</a>'}}),l.find(".select2-input").css("min-width","100px"),l.find(".taxonomy_selector").on("select2-selecting",(function(){var e=$(".select2-container input.select2-input").val();"function"==typeof window.ga&&ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJSUBJ",eventAction:"search-all-select",eventLabel:e})})),l.find(".select2-container input.select2-input").on("keyup",(function(){var e=$(this).val(),n=$("#select2-drop").find(".select2-no-results");clearTimeout(i),i=setTimeout((function(){"function"==typeof window.ga&&(0===n.length&&""!==$.trim(e)?-1==$.inArray(e,o)&&(o.push(e),ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJSUBJ",eventAction:"search-term-hit",eventLabel:e})):0!==n.length&&""!==$.trim(e)&&-1==$.inArray(e,t)&&(t.push(e),ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJSUBJ",eventAction:"search-term-miss",eventLabel:e})))}),700)})));sg.sg_select2_helper.setupQtip(l),l.find(".ftEditChoice").change((function(){sg.sg_select2_helper.setupQtip($(this))})),sg.sg_select2_helper.setUpClickExpend(l),sg.sg_select2_helper.setUpDescriptionField(l),l.find(".select2-container").click((function(){sg.classie_select2_helper.closeTaxonomyBrowse(l)})),l.find(".taxonomy_close_button").click((function(){""!==l.find(".selection_status_choice1").text()?function(){var e;(e=void 0===sg.ma.util?$(sg.ma.questionTypes.confirmCloseBrowseAllPopup().content):$(sg.ma.util.confirmCloseBrowseAllPopup().content)).modal();var t=$(".confirm-modal.in").siblings(".modal.in");0!==t.length&&(t.css("z-index","1040"),$(".confirm-modal.in").siblings(".modal-backdrop.in").first().hide()),$(".feConfirmBtn",e).click((function(){sg.classie_select2_helper.closeTaxonomyBrowse(l)})),$(".confirm-modal.in").on("hidden.bs.modal",(function(e){0!==t.length&&($(".confirm-modal").siblings(".modal-backdrop.in").first().show(),t.css("z-index","1050")),$(".confirm-modal").remove()}))}():sg.classie_select2_helper.closeTaxonomyBrowse(l)})),l.find(".taxonomy_select_button").click((function(){"function"==typeof window.ga&&ga("send",{hitType:"event",eventCategory:"CLASSIE-SEARCH-PRJSUBJ",eventAction:"browse-all-select"});var e=l.find(".taxonomy_level1 input:checked").val();l.find(".taxonomy_level2 input:checked").length>0&&(e=l.find(".taxonomy_level2 input:checked").val()),l.find(".taxonomy_level3 input:checked").length>0&&(e=l.find(".taxonomy_level3 input:checked").val()),l.find(".taxonomy_level4 input:checked").length>0&&(e=l.find(".taxonomy_level4 input:checked").val());var t=l.find(".taxonomy_selector").select2("val");t||(t=[]),t=t.concat(e),l.find(".taxonomy_selector").val(t).trigger("change"),sg.classie_select2_helper.closeTaxonomyBrowse(l)}))},matchUserInput:function(e,t){return sg.sg_select2_helper.matchUserInput(e,t,this.match_data)},formatSelectedItem:function(e){return sg.sg_select2_helper.formatSelectedItem(e,this.staticCommon,this.select2_helper_type)}};