!function(n){"use strict";var t=function(i,r,u){u&&(u.stopPropagation(),u.preventDefault()),this.$element=n(i),this.$newElement=null,this.button=null,this.options=n.extend({},n.fn.selectpicker.defaults,this.$element.data(),typeof r=="object"&&r),this.options.title==null&&(this.options.title=this.$element.attr("title")),this.val=t.prototype.val,this.render=t.prototype.render,this.refresh=t.prototype.refresh,this.selectAll=t.prototype.selectAll,this.deselectAll=t.prototype.deselectAll,this.init()};t.prototype={constructor:t,init:function(){var i,r;this.options.container?this.$element.css("visibility","hidden"):this.$element.hide(),this.multiple=this.$element.prop("multiple"),i=this.$element.attr("id"),this.$newElement=this.createView(),this.$element.after(this.$newElement),this.options.container&&this.selectPosition(),this.button=this.$newElement.find("> button"),i!==undefined&&(r=this,this.button.attr("data-id",i),n('label[for="'+i+'"]').click(function(){r.button.focus()})),this.$element.attr("class")&&this.$newElement.addClass(this.$element.attr("class").replace(/selectpicker/gi,"")),this.multiple&&this.$newElement.addClass("show-tick"),this.button.addClass(this.options.style),this.checkDisabled(),this.checkTabIndex(),this.clickListener(),this.render(),this.setSize()},createDropdown:function(){var t="<div class='btn-group bootstrap-select'><button type='button' class='btn dropdown-toggle' data-toggle='dropdown'><div class='filter-option pull-left'><\/div>&nbsp;<div class='caret'><\/div><\/button><ul class='dropdown-menu' role='menu'><\/ul><\/div>";return n(t)},createView:function(){var n=this.createDropdown(),t=this.createLi();return n.find("ul").append(t),n},reloadLi:function(){this.destroyLi();var n=this.createLi();this.$newElement.find("ul").append(n)},destroyLi:function(){this.$newElement.find("li").remove()},createLi:function(){var i=this,t=[],r="";return this.$element.find("option").each(function(){var u=n(this),e=u.attr("class")||"",f=u.html(),h=u.data("subtext")!==undefined?'<small class="muted">'+u.data("subtext")+"<\/small>":"",o=u.data("icon")!==undefined?'<i class="'+u.data("icon")+'"><\/i> ':"";if(o!==""&&(u.is(":disabled")||u.parent().is(":disabled"))&&(o="<span>"+o+"<\/span>"),f=o+'<span class="text">'+f+h+"<\/span>",i.options.hideDisabled&&(u.is(":disabled")||u.parent().is(":disabled")))t.push('<a style="min-height: 0; padding: 0"><\/a>');else if(u.parent().is("optgroup")&&u.data("divider")!=!0)if(u.index()==0){var s=u.parent().attr("label"),c=u.parent().data("subtext")!==undefined?'<small class="muted">'+u.parent().data("subtext")+"<\/small>":"",l=u.parent().data("icon")?'<i class="'+u.parent().data("icon")+'"><\/i> ':"";s=l+'<span class="text">'+s+c+"<\/span>",u[0].index!=0?t.push('<div class="div-contain"><div class="divider"><\/div><\/div><dt>'+s+"<\/dt>"+i.createA(f,"opt "+e)):t.push("<dt>"+s+"<\/dt>"+i.createA(f,"opt "+e))}else t.push(i.createA(f,"opt "+e));else u.data("divider")==!0?t.push('<div class="div-contain"><div class="divider"><\/div><\/div>'):n(this).data("hidden")==!0?t.push(""):t.push(i.createA(f,e))}),n.each(t,function(n,t){r+="<li rel="+n+">"+t+"<\/li>"}),this.multiple||this.$element.find("option:selected").length!=0||i.options.title||this.$element.find("option").eq(0).prop("selected",!0).attr("selected","selected"),n(r)},createA:function(n,t){return'<a tabindex="0" class="'+t+'">'+n+'<i class="icon-ok check-mark"><\/i><\/a>'},render:function(){var t=this,i,r,f,o,e,u;this.$element.find("option").each(function(i){t.setDisabled(i,n(this).is(":disabled")||n(this).parent().is(":disabled")),t.setSelected(i,n(this).is(":selected"))}),i=this.$element.find("option:selected").map(function(){var u;return u=t.options.showSubtext&&n(this).attr("data-subtext")&&!t.multiple?' <small class="muted">'+n(this).data("subtext")+"<\/small>":"",n(this).attr("title")!=undefined?n(this).attr("title"):n(this).text()+u}).toArray(),r=this.multiple?i.join(", "):i[0],t.multiple&&t.options.selectedTextFormat.indexOf("count")>-1&&(f=t.options.selectedTextFormat.split(">"),o=this.options.hideDisabled?":not([disabled])":"",(f.length>1&&i.length>f[1]||f.length==1&&i.length>=2)&&(r=t.options.countSelectedText.replace("{0}",i.length).replace("{1}",this.$element.find('option:not([data-divider="true"]):not([data-hidden="true"])'+o).length))),r||(r=t.options.title!=undefined?t.options.title:t.options.noneSelectedText),e=this.options.showSubtext&&this.$element.find("option:selected").attr("data-subtext")?' <small class="muted">'+this.$element.find("option:selected").data("subtext")+"<\/small>":"",u=this.$element.find("option:selected").data("icon")||"",u.length&&(u='<i class="'+u+'"><\/i> '),t.$newElement.find(".filter-option").html(u+r+e)},setSize:function(){var r,s,h,u;this.options.container&&this.$newElement.toggle(this.$element.parent().is(":visible"));var c=this,t=this.$newElement.find(".dropdown-menu"),y=t.find("li > a"),f=this.$newElement.addClass("open").find(".dropdown-menu li > a").outerHeight();this.$newElement.removeClass("open");var l=t.find("li .divider").outerHeight(!0),a=this.$newElement.offset().top,v=this.$newElement.outerHeight(),e=parseInt(t.css("padding-top"))+parseInt(t.css("padding-bottom"))+parseInt(t.css("border-top-width"))+parseInt(t.css("border-bottom-width")),o=this.options.hideDisabled?":not(.disabled)":"",i;this.options.size=="auto"?(r=function(){var o=a-n(window).scrollTop(),s=window.innerHeight,r=e+parseInt(t.css("margin-top"))+parseInt(t.css("margin-bottom"))+2,h=s-o-v-r,u;i=h,c.$newElement.hasClass("dropup")&&(i=o-r),u=t.find("li").length+t.find("dt").length>3?f*3+r-2:0,t.css({"max-height":i+"px","overflow-y":"auto","min-height":u+"px"})},r(),n(window).resize(r),n(window).scroll(r)):this.options.size&&this.options.size!="auto"&&t.find("li"+o).length>this.options.size&&(s=t.find("li"+o+" > *").filter(":not(.div-contain)").slice(0,this.options.size).last().parent().index(),h=t.find("li").slice(0,s+1).find(".div-contain").length,i=f*this.options.size+h*l+e,t.css({"max-height":i+"px","overflow-y":"auto"})),this.options.width=="auto"?(this.$newElement.find(".dropdown-menu").css("min-width","0"),u=this.$newElement.find(".dropdown-menu").css("width"),this.$newElement.css("width",u),this.options.container&&this.$element.css("width",u)):this.options.width?this.options.container?(this.$element.css("width",this.options.width),this.$newElement.width(this.$element.outerWidth())):this.$newElement.css("width",this.options.width):this.options.container&&this.$newElement.width(this.$element.outerWidth())},selectPosition:function(){var t=n(this.options.container).offset(),i=this.$element.offset(),r,u;t&&i&&(r=i.top-t.top,u=i.left-t.left,this.$newElement.appendTo(this.options.container),this.$newElement.css({position:"absolute",top:r+"px",left:u+"px"}))},refresh:function(){this.reloadLi(),this.render(),this.setSize(),this.checkDisabled(),this.options.container&&this.selectPosition()},setSelected:function(n,t){t?this.$newElement.find("li").eq(n).addClass("selected"):this.$newElement.find("li").eq(n).removeClass("selected")},setDisabled:function(n,t){t?this.$newElement.find("li").eq(n).addClass("disabled").find("a").attr("href","#").attr("tabindex",-1):this.$newElement.find("li").eq(n).removeClass("disabled").find("a").removeAttr("href").attr("tabindex",0)},isDisabled:function(){return this.$element.is(":disabled")||this.$element.attr("readonly")},checkDisabled:function(){this.isDisabled()?(this.button.addClass("disabled"),this.button.click(function(n){n.preventDefault()}),this.button.attr("tabindex","-1")):!this.isDisabled()&&this.button.hasClass("disabled")&&(this.button.removeClass("disabled"),this.button.click(function(){return!0}),this.button.removeAttr("tabindex"))},checkTabIndex:function(){if(this.$element.is("[tabindex]")){var n=this.$element.attr("tabindex");this.button.attr("tabindex",n)}},clickListener:function(){var t=this;n("body").on("touchstart.dropdown",".dropdown-menu",function(n){n.stopPropagation()});this.$newElement.on("click","li a",function(i){var r=n(this).parent().index(),f=n(this).parent(),e=f.parents(".bootstrap-select"),o=t.$element.val(),u;t.multiple&&i.stopPropagation(),i.preventDefault(),t.$element.not(":disabled")&&!n(this).parent().hasClass("disabled")&&(t.multiple?(u=t.$element.find("option").eq(r).prop("selected"),u?t.$element.find("option").eq(r).prop("selected",!1):t.$element.find("option").eq(r).prop("selected",!0)):(t.$element.find("option").prop("selected",!1),t.$element.find("option").eq(r).prop("selected",!0)),e.find("button").focus(),o!=t.$element.val()&&t.$element.trigger("change"),t.render())});this.$newElement.on("click","li.disabled a, li dt, li .div-contain",function(t){t.preventDefault(),t.stopPropagation();var i=n(this).parent().parents(".bootstrap-select");i.find("button").focus()});this.$element.on("change",function(){t.render()})},val:function(n){return n!=undefined?(this.$element.val(n),this.$element.trigger("change"),this.$element):this.$element.val()},selectAll:function(){this.$element.find("option").prop("selected",!0).attr("selected","selected"),this.render()},deselectAll:function(){this.$element.find("option").prop("selected",!1).removeAttr("selected"),this.render()},keydown:function(t){var v,r,o,i,f,s,h,c,l,a,e,u,y;(v=n(this),o=v.parent(),r=n("[role=menu] li:not(.divider):visible a",o),r.length)&&(/(38|40)/.test(t.keyCode)?(i=r.index(r.filter(":focus")),s=r.parent(":not(.disabled)").first().index(),h=r.parent(":not(.disabled)").last().index(),f=r.eq(i).parent().nextAll(":not(.disabled)").eq(0).index(),c=r.eq(i).parent().prevAll(":not(.disabled)").eq(0).index(),l=r.eq(f).parent().prevAll(":not(.disabled)").eq(0).index(),t.keyCode==38&&(i!=l&&i>c&&(i=c),i<s&&(i=s)),t.keyCode==40&&(i!=l&&i<f&&(i=f),i>h&&(i=h)),r.eq(i).focus()):(a={48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9"},e=[],r.each(function(){n(this).parent().is(":not(.disabled)")&&n.trim(n(this).text().toLowerCase()).substring(0,1)==a[t.keyCode]&&e.push(n(this).parent().index())}),u=n(document).data("keycount"),u++,n(document).data("keycount",u),y=n.trim(n(":focus").text().toLowerCase()).substring(0,1),y!=a[t.keyCode]?(u=1,n(document).data("keycount",u)):u>=e.length&&n(document).data("keycount",0),r.eq(e[u-1]).focus()),/(13)/.test(t.keyCode)&&(n(":focus").click(),o.addClass("open"),n(document).data("keycount",0)))},hide:function(){this.$newElement.hide()},show:function(){this.$newElement.show()}},n.fn.selectpicker=function(i,r){var f=arguments,u,e=this.each(function(){var h,s;if(n(this).is("select")){var c=n(this),e=c.data("selectpicker"),o=typeof i=="object"&&i;if(e){if(o)for(h in o)e.options[h]=o[h]}else c.data("selectpicker",e=new t(this,o,r));typeof i=="string"&&(s=i,e[s]instanceof Function?([].shift.apply(f),u=e[s].apply(e,f)):u=e.options[s])}});return u!=undefined?u:e},n.fn.selectpicker.defaults={style:null,size:"auto",title:null,selectedTextFormat:"values",noneSelectedText:"Nothing selected",countSelectedText:"{0} of {1} selected",width:null,container:!1,hideDisabled:!1,showSubtext:!1};n(document).data("keycount",0).on("keydown","[data-toggle=dropdown], [role=menu]",t.prototype.keydown)}(window.jQuery)