if(jQuery){(function(a){a.extend(a.fn,{multiSelect:function(c,d){if(!c){var c={}}if(c.selectAll==undefined){c.selectAll=true}if(c.selectAllText==undefined){c.selectAllText="Select All"}if(c.noneSelected==undefined){c.noneSelected="Select options"}if(c.oneOrMoreSelected==undefined){c.oneOrMoreSelected="% selected"}if(c.deselectAll==undefined){c.deselectAll=false}var b=[];if(c.selectedOptions){c.selectedOptions=c.selectedOptions.substr(0,c.selectedOptions.length-1);b=c.selectedOptions.split(",")}a(this).each(function(){var f=a(this);var g='<input type="text" readonly="readonly" class="multiSelect" value="" style="cursor: default;" />';g+='<div class="multiSelectOptions" style="position: absolute; z-index: 99999; display: none;">';if(c.selectAll){g+='<label class="selectAll"><input type="checkbox" class="checkbox selectAll" />'+c.selectAllText+"</label>"}a(f).find("OPTION").each(function(){if(a(this).val()!=""){g+='<label><input type="checkbox" class="checkbox event_data" id="'+a(this).val()+'" name="'+a(f).attr("name")+'" value="'+a(this).val()+'"';if(!c.deselectAll&&a(this).isInArray(b,a(this).val())){g+=' checked="checked"'}g+=" />"+a(this).html()+"</label>"}});g+="</div>";a(f).after(g);a(f).next(".multiSelect").mouseover(function(){a(this).addClass("hover")}).mouseout(function(){a(this).removeClass("hover");a(this).removeClass("active")}).click(function(){if(a(this).hasClass("active")){a(this).multiSelectOptionsHide()}else{a(this).multiSelectOptionsShow()}return false}).focus(function(){a(this).addClass("focus")}).blur(function(){a(this).removeClass("focus")});if(c.selectAll){var e=true;a(f).next(".multiSelect").next(".multiSelectOptions").find("INPUT:checkbox").not(".selectAll").each(function(){if(!a(this).attr("checked")){e=false}});if(e){a(f).next(".multiSelect").next(".multiSelectOptions").find("INPUT.selectAll").attr("checked",true).parent().addClass("checked")}}a(f).next(".multiSelect").next(".multiSelectOptions").find("INPUT.selectAll").click(function(){if(a(this).attr("checked")==true){a(this).parent().parent().find("INPUT:checkbox").attr("checked",true).parent().addClass("checked")}else{a(this).parent().parent().find("INPUT:checkbox").attr("checked",false).parent().removeClass("checked")}});a(f).next(".multiSelect").next(".multiSelectOptions").find("INPUT:checkbox").click(function(){a(this).parent().parent().multiSelectUpdateSelected(c);a(this).parent().parent().find("LABEL").removeClass("checked").find("INPUT:checked").parent().addClass("checked");a(this).parent().parent().prev(".multiSelect").focus();if(!a(this).attr("checked")){a(this).parent().parent().find("INPUT:checkbox.selectAll").attr("checked",false).parent().removeClass("checked")}if(d){d(a(this))}});a(f).next(".multiSelect").next(".multiSelectOptions").each(function(){a(this).multiSelectUpdateSelected(c);a(this).find("INPUT:checked").parent().addClass("checked")});a(f).next(".multiSelect").next(".multiSelectOptions").find("LABEL").mouseover(function(){a(this).parent().find("LABEL").removeClass("hover");a(this).addClass("hover")}).mouseout(function(){a(this).parent().find("LABEL").removeClass("hover")});a(f).next(".multiSelect").keydown(function(h){if(a(this).next(".multiSelectOptions").is(":visible")){if(h.keyCode==9){a(this).addClass("focus").trigger("click");a(this).focus().next(":input").focus();return true}if(h.keyCode==27||h.keyCode==37||h.keyCode==39){a(this).addClass("focus").trigger("click")}if(h.keyCode==40){if(!a(this).next(".multiSelectOptions").find("LABEL").hasClass("hover")){a(this).next(".multiSelectOptions").find("LABEL:first").addClass("hover")}else{a(this).next(".multiSelectOptions").find("LABEL.hover").removeClass("hover").next("LABEL").addClass("hover");if(!a(this).next(".multiSelectOptions").find("LABEL").hasClass("hover")){a(this).next(".multiSelectOptions").find("LABEL:first").addClass("hover")}}a(this).multiSelectAdjustViewport(a(this));return false}if(h.keyCode==38){if(!a(this).next(".multiSelectOptions").find("LABEL").hasClass("hover")){a(this).next(".multiSelectOptions").find("LABEL:first").addClass("hover")}else{a(this).next(".multiSelectOptions").find("LABEL.hover").removeClass("hover").prev("LABEL").addClass("hover");if(!a(this).next(".multiSelectOptions").find("LABEL").hasClass("hover")){a(this).next(".multiSelectOptions").find("LABEL:last").addClass("hover")}}a(this).multiSelectAdjustViewport(a(this));return false}if(h.keyCode==13||h.keyCode==32){if(a(this).next(".multiSelectOptions").find("LABEL.hover INPUT:checkbox").hasClass("selectAll")){if(a(this).next(".multiSelectOptions").find("LABEL.hover INPUT:checkbox").attr("checked")){a(this).next(".multiSelectOptions").find("INPUT:checkbox").attr("checked",false).parent().removeClass("checked")}else{a(this).next(".multiSelectOptions").find("INPUT:checkbox").attr("checked",true).parent().addClass("checked")}a(this).next(".multiSelectOptions").multiSelectUpdateSelected(c);if(d){d(a(this))}return false}if(a(this).next(".multiSelectOptions").find("LABEL.hover INPUT:checkbox").attr("checked")){a(this).next(".multiSelectOptions").find("LABEL.hover INPUT:checkbox").attr("checked",false);a(this).next(".multiSelectOptions").multiSelectUpdateSelected(c);a(this).next(".multiSelectOptions").find("LABEL").removeClass("checked").find("INPUT:checked").parent().addClass("checked");a(this).next(".multiSelectOptions").find("INPUT:checkbox.selectAll").attr("checked",false).parent().removeClass("checked");if(d){d(a(this))}}else{a(this).next(".multiSelectOptions").find("LABEL.hover INPUT:checkbox").attr("checked",true);a(this).next(".multiSelectOptions").multiSelectUpdateSelected(c);a(this).next(".multiSelectOptions").find("LABEL").removeClass("checked").find("INPUT:checked").parent().addClass("checked");if(d){d(a(this))}}}return false}else{if(h.keyCode==38||h.keyCode==40||h.keyCode==13||h.keyCode==32){a(this).removeClass("focus").trigger("click");a(this).next(".multiSelectOptions").find("LABEL:first").addClass("hover");return false}if(h.keyCode==9){a(this).focus().next(":input").focus();return true}}if(h.keyCode==13){return false}});a(f).remove()})},isInArray:function(c,b){for(i=0;i<c.length;i++){if(c[i]==b){return true}}return false},multiSelectOptionsHide:function(){a(this).removeClass("active").next(".multiSelectOptions").hide()},multiSelectOptionsShow:function(){a(".multiSelect").multiSelectOptionsHide();a(this).next(".multiSelectOptions").find("LABEL").removeClass("hover");a(this).addClass("active").next(".multiSelectOptions").show();var b=a(this).position();a(this).next(".multiSelectOptions").css({top:b.top+a(this).outerHeight()+"px"});a(this).next(".multiSelectOptions").css({left:b.left+"px"});multiSelectCurrent=a(this);var c="";a(this).next(".multiSelectOptions").hover(function(){clearTimeout(c)},function(){c=setTimeout('jQuery(multiSelectCurrent).multiSelectOptionsHide(); $(multiSelectCurrent).unbind("hover");',250)})},multiSelectUpdateSelected:function(e){var b=0,c="";a(this).find("INPUT:checkbox:checked").not(".selectAll").each(function(){b++});if(b==0){a(this).prev("INPUT.multiSelect").val(e.noneSelected)}else{if(e.oneOrMoreSelected=="*"){var d="";a(this).find("INPUT:checkbox:checked").each(function(){if(a(this).parent().text()!=e.selectAllText){d=d+a(this).parent().text()+", "}});d=d.substr(0,d.length-2);a(this).prev("INPUT.multiSelect").val(d)}else{a(this).prev("INPUT.multiSelect").val(e.oneOrMoreSelected.replace("%",b))}}},multiSelectAdjustViewport:function(g){var f=0;var e=0,b=0;a(g).next(".multiSelectOptions").find("LABEL").each(function(){if(a(this).hasClass("hover")){e=f;b=a(this).outerHeight();return}f+=a(this).outerHeight()});var d=a(g).next(".multiSelectOptions").scrollTop();var c=a(g).next(".multiSelectOptions").height();a(g).next(".multiSelectOptions").scrollTop(e-((c/2)-(b/2)))}})})(jQuery)};
