function filldropdown(target,show,value){
		$("#"+target).removeOption(/./);
		$("#"+target).addOption("","Bezig met laden...");
		$("#"+target).ajaxAddOption("/js/fill_select.php",{show: show, criteria: value}, false, function(){
			$("#"+target).attr("disabled", false);
		});
}

function review_options(){
	$(".cat-optie").hide();
	if ($("input[name='branche[]']:checked").length > 0){
		$("input[name='branche[]']:checked").each(function(){
			$(".cat-"+this.value).show();
		});
	}else{
		$(".cat-optie").show();
	}
}

function removeReact(id){
	$.get("/js/remove_react.php", { id: id }, function(){
		$("#react"+id).remove();
		$("#reactvacnr"+id).remove();
		$("#reactpkproj"+id).remove();
	});
}

var sbopen = 0;
var donotclose = 0;
function init_multiple_selects(){
		$(".selectbox").each(function(){
		var objectid = this.id;
		var objectname = this.name;
		var objtitle = this.title;
		var selcount = 0;
		$(this).after('<div class="selectboxselector" id="sbs_'+objectid+'"><span>'+selcount+'</span> '+this.title+'</div><br style="clear:both;" /><ul id="ms_'+objectid+'" class="selectboxlist"></ul>');
		$(this).children().each(function(i){
			if (this.label){
				$("#ms_"+objectid).append('<li><input type="checkbox" name="'+objectname+'[]" id="ms_'+objectid+'-'+i+'" value="'+this.title+'"'+((this.disabled)?' checked="checked"':'')+' /><label for="ms_'+objectid+'-'+i+'">&nbsp;<strong>'+this.label+'</strong></label></li>');
				if(this.disabled) selcount++;
				$(this).children().each(function(ii){
					$("#ms_"+objectid).append('<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="'+objectname+'[]" id="ms_'+objectid+'-'+i+''+ii+'" class="ms_'+objectid+'-'+i+'" value="'+this.value+'" '+((this.selected)?'checked="checked"':'')+' /><label for="ms_'+objectid+'-'+i+''+ii+'">'+this.text+'</label></li>');
					if(this.selected) selcount++;
				});
			}else{
				if(this.selected) selcount++;
				$("#ms_"+objectid).append('<li><input type="checkbox" name="'+objectname+'[]" id="ms_'+objectid+'-'+i+'" value="'+this.value+'" '+((this.selected)?'checked="checked"':'')+' /><label for="ms_'+objectid+'-'+i+'">'+this.text+'</label></li>');
			}
		});
		if (selcount<1) selcount = "Geen";
		$("#sbs_"+objectid+" span").html(selcount);
		$("#sbs_"+objectid).click(function(){
			var objwidth = $(this).width();
			//var selcount = $("input[name='"+objectname+"[]'][class*='ms_']:checked").length;
			var selcount = $("input[name='"+objectname+"[]']:checked").length;
			if (selcount<1) selcount = "Geen";
			$("#sbs_"+objectid+" span").html(selcount);
			$("#sbs_"+objectid).css({width:(objwidth)+'px'});
			$("#ms_"+objectid).css({minWidth:(objwidth+24)+'px'});
				if ($("#ms_"+objectid).height()>200){
					$("#ms_"+objectid).css({height:'200px'});
				}
				if ($("#ms_"+objectid).width()<$(this).width()){
					$("#footer").html($("#ms_"+objectid).width()+"<"+$(this).width());
					$("#ms_"+objectid).css({width:$(this).width()+24+'px'});
				}
			if (sbopen!=1){
				$("#ms_"+objectid).slideDown("fast",function(){
					sbopen = 1;
				});
			}
		});
		$("#ms_"+objectid+" input").click(function(){
			if (this.checked){
				$(this).parent().css({'background-color':'#FFFF7F'});
				$("."+this.id).attr("checked",1).parent().css({'background-color':'#FFFF7F'});
			}else{
				$(this).parent().css({'background-color':'#fff'});
				$("."+this.id).attr("checked",0).parent().css({'background-color':'#fff'});
				$("#"+$(this).attr("class")).attr("checked",0).parent().css({'background-color':'#fff'});
			}
			//var selcount = $("input[name='"+objectname+"[]'][class*='ms_']:checked").length;
			var selcount = $("input[name='"+objectname+"[]']:checked").length;
			if (selcount<1) selcount = "Geen";
			$("#sbs_"+objectid+" span").html(selcount);
		});
		$("#ms_"+objectid).mouseover(function(){
		  donotclose = 1;
	    }).mouseout(function(){
	      donotclose = 0;
	    });
		//remove the original <select>
		$(this).remove();
	});
	$("body").click(function(){
		if (sbopen==1 && donotclose!=1){
			$(".selectboxlist").slideUp("fast",function(){
				sbopen = 0;
			});
		}
	});
}



$(document).ready(function(){
	init_multiple_selects();
	$("label").click(function(){
		var forid = $(this).attr('for');
		if($("#"+forid).attr('checked')){
			$(this).css("font-weight","bold");
		}else{
			$(this).css("font-weight","normal");
		}
	});
	
	$(".tools-hit-area").hover(
      function () {
	  	$(this).find(".tools-holder").show();
      }, 
      function () {
	  	$(this).find(".tools-holder").hide();
      }
    );
});
