if(jQuery){(function($){function _1(id,_2){var _3="<label";if(_2.title){_3+=" title=\""+_2.title+"\"";}_3+="><input type=\"checkbox\" name=\""+id+"[]\" value=\""+_2.value+"\"";if(_2.selected){_3+=" checked=\"checked\"";}_3+=" />"+_2.text+"</label>";return _3;};function _4(id,_5,o){var _6="";for(var i=0;i<_5.length;i++){if(_5[i].optgroup){_6+="<label class=\"optGroup\">";if(o.optGroupSelectable){_6+="<input type=\"checkbox\" class=\"optGroup\" />"+_5[i].optgroup;}else{_6+=_5[i].optgroup;}_6+="</label><div class=\"optGroupContainer\">";_6+=_4(id,_5[i].options,o);_6+="</div>";}else{_6+=_1(id,_5[i]);}}return _6;};function _7(_8){var _9=$(this);var _a=_9.next(".multiSelectOptions");var o=_9.data("config");var _b=_9.data("callback");_a.html("");var _c="";if(o.selectAll){_c+="<label class=\"selectAll\"><input type=\"checkbox\" class=\"selectAll\" />"+o.selectAllText+"</label>";}_c+=_4(_9.attr("id"),_8,o);_a.html(_c);var _d=_a.width();var _e=false;if(_a.height()>o.listHeight){_a.css("height",o.listHeight+"px");_e=true;}else{_a.css("height","");}var _f=_e&&(_d==_a.width())?17:0;if((_a.width()+_f)<_9.outerWidth()){_a.css("width",_9.outerWidth()-2+"px");}else{_a.css("width",(_a.width()+_f)+"px");}if($.fn.bgiframe){_9.next(".multiSelectOptions").bgiframe({width:_a.width(),height:_a.height()});}if(o.selectAll){_a.find("INPUT.selectAll").click(function(){_a.find("INPUT:checkbox").attr("checked",$(this).attr("checked")).parent("LABEL").toggleClass("checked",$(this).attr("checked"));});}if(o.optGroupSelectable){_a.addClass("optGroupHasCheckboxes");_a.find("INPUT.optGroup").click(function(){$(this).parent().next().find("INPUT:checkbox").attr("checked",$(this).attr("checked")).parent("LABEL").toggleClass("checked",$(this).attr("checked"));});}_a.find("INPUT:checkbox").click(function(){$(this).parent("LABEL").toggleClass("checked",$(this).attr("checked"));_20.call(_9);_9.focus();if($(this).parent().parent().hasClass("optGroupContainer")){_1c.call(_9,$(this).parent().parent().prev());}if(_b){_b($(this));}});_a.each(function(){$(this).find("INPUT:checked").parent().addClass("checked");});_20.call(_9);if(o.optGroupSelectable){_a.find("LABEL.optGroup").each(function(){_1c.call(_9,$(this));});}_a.find("LABEL:has(INPUT)").hover(function(){$(this).parent().find("LABEL").removeClass("hover");$(this).addClass("hover");},function(){$(this).parent().find("LABEL").removeClass("hover");});_9.keydown(function(e){var _10=$(this).next(".multiSelectOptions");if(_10.css("visibility")!="hidden"){if(e.keyCode==9){$(this).addClass("focus").trigger("click");$(this).focus().next(":input").focus();return true;}if(e.keyCode==27||e.keyCode==37||e.keyCode==39){$(this).addClass("focus").trigger("click");}if(e.keyCode==40||e.keyCode==38){var _11=_10.find("LABEL");var _12=_11.index(_11.filter(".hover"));var _13=-1;if(_12<0){_10.find("LABEL:first").addClass("hover");}else{if(e.keyCode==40&&_12<_11.length-1){_13=_12+1;}else{if(e.keyCode==38&&_12>0){_13=_12-1;}}}if(_13>=0){$(_11.get(_12)).removeClass("hover");$(_11.get(_13)).addClass("hover");_19(_10);}return false;}if(e.keyCode==13||e.keyCode==32){var _14=_10.find("LABEL.hover INPUT:checkbox");_14.attr("checked",!_14.attr("checked")).parent("LABEL").toggleClass("checked",_14.attr("checked"));if(_14.hasClass("selectAll")){_10.find("INPUT:checkbox").attr("checked",_14.attr("checked")).parent("LABEL").addClass("checked").toggleClass("checked",_14.attr("checked"));}_20.call(_9);if(_b){_b($(this));}return false;}if(e.keyCode>=33&&e.keyCode<=126){var _15=_10.find("LABEL:startsWith("+String.fromCharCode(e.keyCode)+")");var _16=_15.index(_15.filter("LABEL.hover"));var _17=_15.filter(function(_18){return _18>_16;});_15=(_17.length>=1?_17:_15).filter("LABEL:first");if(_15.length==1){_10.find("LABEL.hover").removeClass("hover");_15.addClass("hover");_19(_10);}}}else{if(e.keyCode==38||e.keyCode==40||e.keyCode==13||e.keyCode==32){$(this).removeClass("focus").trigger("click");_10.find("LABEL:first").addClass("hover");return false;}if(e.keyCode==9){_10.next(":input").focus();return true;}}if(e.keyCode==13){return false;}});};function _19(_1a){var _1b=_1a.find("LABEL.hover").position().top+_1a.find("LABEL.hover").outerHeight();if(_1b>_1a.innerHeight()){_1a.scrollTop(_1a.scrollTop()+_1b-_1a.innerHeight());}if(_1a.find("LABEL.hover").position().top<0){_1a.scrollTop(_1a.scrollTop()+_1a.find("LABEL.hover").position().top);}};function _1c(_1d){var _1e=$(this);var o=_1e.data("config");if(o.optGroupSelectable){var _1f=true;$(_1d).next().find("INPUT:checkbox").each(function(){if(!$(this).attr("checked")){_1f=false;return false;}});$(_1d).find("INPUT.optGroup").attr("checked",_1f).parent("LABEL").toggleClass("checked",_1f);}};function _20(){var _21=$(this);var _22=_21.next(".multiSelectOptions");var o=_21.data("config");var i=0;var _23=true;var _24="";_22.find("INPUT:checkbox").not(".selectAll, .optGroup").each(function(){if($(this).attr("checked")){i++;_24=_24+$(this).parent().text()+", ";}else{_23=false;}});_24=_24.replace(/\s*\,\s*$/,"");if(i==0){_21.find("span").html(o.noneSelected);}else{if(o.oneOrMoreSelected=="*"){_21.find("span").html(_24);_21.attr("title",_24);}else{_21.find("span").html(o.oneOrMoreSelected.replace("%",i));}}if(o.selectAll){_22.find("INPUT.selectAll").attr("checked",_23).parent("LABEL").toggleClass("checked",_23);}};$.extend($.fn,{multiSelect:function(o,_25){if(!o){o={};}if(o.selectAll==undefined){o.selectAll=true;}if(o.selectAllText==undefined){o.selectAllText="Select All";}if(o.noneSelected==undefined){o.noneSelected="Select options";}if(o.oneOrMoreSelected==undefined){o.oneOrMoreSelected="% selected";}if(o.optGroupSelectable==undefined){o.optGroupSelectable=false;}if(o.listHeight==undefined){o.listHeight=150;}$(this).each(function(){var _26=$(this);var _27="<a href=\"javascript:;\" class=\"multiSelect\"><span></span></a>";_27+="<div class=\"multiSelectOptions\" style=\"position: absolute; z-index: 99999; visibility: hidden;\"></div>";$(_26).after(_27);var _28=$(_26).next(".multiSelect");var _29=_28.next(".multiSelectOptions");_28.find("span").css("width",$(_26).width()+"px");_28.data("config",o);_28.data("callback",_25);var _2a=[];$(_26).children().each(function(){if(this.tagName.toUpperCase()=="OPTGROUP"){var _2b=[];_2a.push({optgroup:$(this).attr("label"),options:_2b});$(this).children("OPTION").each(function(){if($(this).val()!=""){_2b.push({text:$(this).html(),value:$(this).val(),selected:$(this).attr("selected"),title:$(this).attr("title")});}});}else{if(this.tagName.toUpperCase()=="OPTION"){if($(this).val()!=""){_2a.push({text:$(this).html(),value:$(this).val(),selected:$(this).attr("selected"),title:$(this).attr("title")});}}}});$(_26).remove();_28.attr("id",$(_26).attr("id"));_7.call(_28,_2a);_28.hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");}).click(function(){if($(this).hasClass("active")){$(this).multiSelectOptionsHide();}else{$(this).multiSelectOptionsShow();}return false;}).focus(function(){$(this).addClass("focus");}).blur(function(){$(this).removeClass("focus");});$(document).click(function(_2c){if(!($(_2c.target).parents().andSelf().is(".multiSelectOptions"))){_28.multiSelectOptionsHide();}});});},multiSelectOptionsUpdate:function(_2d){_7.call($(this),_2d);},multiSelectOptionsHide:function(){$(this).removeClass("active").removeClass("hover").next(".multiSelectOptions").css("visibility","hidden");},multiSelectOptionsShow:function(){var _2e=$(this);var _2f=_2e.next(".multiSelectOptions");var o=_2e.data("config");$(".multiSelect").multiSelectOptionsHide();_2f.find("LABEL").removeClass("hover");_2e.addClass("active").next(".multiSelectOptions").css("visibility","visible");_2e.focus();_2e.next(".multiSelectOptions").scrollTop(0);var _30=_2e.position();_2e.next(".multiSelectOptions").css({top:_30.top+$(this).outerHeight()+"px"});_2e.next(".multiSelectOptions").css({left:_30.left+"px"});},selectedValuesString:function(){var _31="";$(this).next(".multiSelectOptions").find("INPUT:checkbox:checked").not(".optGroup, .selectAll").each(function(){_31+=$(this).attr("value")+",";});return _31.replace(/\s*\,\s*$/,"");}});$.expr[":"].startsWith=function(el,i,m){var _32=m[3];if(!_32){return false;}return eval("/^[/s]*"+_32+"/i").test($(el).text());};})(jQuery);}
