/* jQuery Tree Multiselect v1.14.5 | (c) Patrick Tsai et al. | MIT Licensed */
!function(a){function b(b){var c={allowBatchSelection:!0,sortable:!1,collapsible:!0,freeze:!1,hideSidePanel:!1,sectionDelimiter:"/",showSectionOnSelected:!0,startCollapsed:!1};return a.extend({},c,b)}function c(b,c,e){function f(b,c){for(var d=g,e=0;e<b.length;++e){var f=b[e];if(d[f]||(d[f]=[]),d=d[f],e==b.length-1){d.push(c);break}f=b[e+1];for(var h=null,i=0;i<d.length;++i){var j=d[i];if(j.constructor!=r&&a.isPlainObject(j)&&j[f]&&"undefined"!=typeof j[f]){h=j;break}}if(h)d=h;else{var k=d.push({});d=d[k-1]}}}var g={};a(b).find("> option").each(function(){var b=a(this).attr("data-section").split(e.sectionDelimiter),c=a(this).val(),d=a(this).text(),g=a(this).attr("data-description"),h=a(this).attr("data-index"),i=new r(c,d,g,h);f(b,i)}),d.call(c,g)}function d(b){function c(b){var c=document.createElement("div");c.className="section";var d=document.createElement("div");return d.className="title",d.innerHTML=b,a(c).append(d),a(this).append(c),c}function e(b){var c=b.text,d=b.value,e=b.description,f=b.index,g=document.createElement("div");g.className="item",a(g).text(c||d).attr({"data-value":d,"data-description":e,"data-index":f}),a(this).append(g)}if(b.constructor==r)e.call(this,b);else if(a.isArray(b))for(var f=0;f<b.length;++f)d.call(this,b[f]);else if("object"==typeof b){for(var g in b)if(b.hasOwnProperty(g)){var h=c.call(this,g);d.call(h,b[g])}}else e.call(this,b)}function e(b){var c=a("<span class='description'>?</span>"),d=a(b).find("div.item[data-description!=''][data-description]");c.prependTo(d),a("div.item > span.description").unbind().mouseenter(function(){var b=a(this).parent(),c=b.attr("data-description"),d=document.createElement("div");d.className="temp-description-popup",d.innerHTML=c,d.style.position="absolute",b.append(d)}).mouseleave(function(){a("div.temp-description-popup").remove()})}function f(b,c){var d=a("<input />",{type:"checkbox"});c.freeze&&d.attr("disabled","disabled");var e=null;e=c.allowBatchSelection?a(b).find("div.title, div.item"):a(b).find("div.item"),d.prependTo(e),a(b).find("input[type=checkbox]").click(function(a){a.stopPropagation()})}function g(b,c){var d=a(b).val();if(d){var e=a(c).find("div.item").filter(function(){var b=a(this);return-1!==d.indexOf(b.attr("data-value"))});a(e).find("> input[type=checkbox]").prop("checked",!0)}}function h(b){var c=a(b).find("div.title > input[type=checkbox]");c.change(function(){var b=a(this).closest("div.section"),c=b.find("input[type=checkbox]"),d=a(this).is(":checked");c.prop("checked",d)})}function i(b){var c=a(b).find("input[type=checkbox]");c.change(function(){if(!a(this).is(":checked")){var c=a(this).parentsUntil(b,"div.section");c.find("> div.title > input[type=checkbox]").prop("checked",!1)}})}function j(b){function c(){var c=a(b).find("div.section");c.each(function(){var b=a(this),c=b.find("div.item"),d=c.filter(function(){var b=a(this).find("> input[type=checkbox]");return!b.is(":checked")});if(0===d.length){var e=a(this).find("> div.title > input[type=checkbox]");e.prop("checked",!0)}})}o(b,c)}function k(b){function c(){var c=a(b).find("div.section");c.each(function(){var b=a(this),c=b.find("div.item"),d=c.filter(function(){var b=a(this);return b.find("> input[type=checkbox]").prop("checked")}).length,e=a(this).find("> div.title > input[type=checkbox]"),f=0!==d&&d!==c.length;e.prop("indeterminate",f)})}o(b,c)}function l(b,c){var d="-",e="+",f=a(b).find("div.title"),g=document.createElement("span");g.className="collapse-section",c.startCollapsed?(a(g).text(e),f.siblings().toggle()):a(g).text(d),f.prepend(g),a("span.collapse-section").unbind().click(function(b){b.stopPropagation();var c=a(this).text();a(this).text(c==d?e:d);var f=a(this).parent();f.siblings().toggle()}),f.click(function(){a(this).find("> span.collapse-section").trigger("click")})}function m(b,c,d,e){function f(b){var d=b.text,f=b.value,g=b.sectionName,h=document.createElement("div");h.className="item",h.innerHTML=d,e.showSectionOnSelected&&a(h).append("<span class='section-name'>"+g+"</span>"),e.freeze||a(h).prepend("<span class='remove-selected'>×</span>"),a(h).attr("data-value",f).appendTo(c)}function g(d){var e=[];a(c).find("div.item").each(function(){e.push(a(this).attr("data-value"))});var g=d.filter(function(a){return-1==e.indexOf(a.value)});g.forEach(function(a){f(a)}),n(b,c)}function h(b){var d=[];b.forEach(function(a){d.push(a.value)}),a(c).find("div.item").each(function(){var b=a(this).attr("data-value");-1==d.indexOf(b)&&a(this).remove()})}function i(){var b=a(d),e=[];a(c).find("div.item").each(function(){e.push(a(this).attr("data-value"))}),b.val(e),a(d).html(a(d).find("option").sort(function(b,c){var d=e.indexOf(a(b).attr("value")),f=e.indexOf(a(c).attr("value"));return d>f?1:f>d?-1:0}))}function j(){var d=a(b).find("div.item").has("> input[type=checkbox]:checked"),f=[];if(d.each(function(c){var d=p(this),g=a(this).attr("data-value"),h=a(this).attr("data-index");a(this).attr("data-index",void 0);var i=a.map(a(this).parentsUntil(b,"div.section").get().reverse(),function(b){return p(a(b).find("> div.title"))}).join(e.sectionDelimiter);f.push({text:d,value:g,index:h,sectionName:i})}),f.sort(function(a,b){var c=parseInt(a.index),d=parseInt(b.index);return c>d?1:d>c?-1:0}),g(f),h(f),i(),e.sortable&&!e.freeze){var j=a(c);j.sortable({update:function(a,b){i()}})}}o(b,j)}function n(b,c){a(c).find("span.remove-selected").unbind().click(function(){var c=a(this).parent().attr("data-value"),d=a(b).find("div.item[data-value='"+c+"']"),e=d.find("> input[type=checkbox]");e.prop("checked",!1),e.trigger("change")})}function o(b,c){var d=a(b).find("input[type=checkbox]");d.change(function(){c()}),c()}function p(b){return a(b).clone().children().remove().end().text()}a.fn.treeMultiselect=function(d){var o=b(d);return this.each(function(){var b=a(this);b.attr("multiple","").css("display","none");var d=new q;d.build(b,o.hideSidePanel);var p=d.selections;c(b,p,o),e(p,o),f(p,o),g(b,p,o),o.allowBatchSelection&&(h(p,o),i(p,o),j(p,o),k(p,o)),o.collapsible&&l(p,o);var r=d.selected;m(p,r,b,o),n(p,r,o)}),this};var q=function(){};q.prototype.build=function(b,c){var d=document.createElement("div");d.className="tree-multiselect",a(b).after(d);var e=document.createElement("div");e.className="selections",c&&(e.className+=" no-border"),a(d).append(e);var f=document.createElement("div");f.className="selected",c||a(d).append(f),this.tree=d,this.selections=e,this.selected=f};var r=function(a,b,c,d){this.value=a,this.text=b,this.description=c,this.index=d}}(jQuery);