	var chosen_instrument 	= false;
	var chosen_location 	= false;
	var chosen_time		= false;
	var chosen_day		= false;
	var formUrl 			= "";
	
	$(document).ready(function() {
		
		getCorrectBackground();
		
		formUrl = $(".btn-inschrijven").attr("href");
		
		// Activate lightbox functionality
		$(".lightbox").fancybox({
			'overlayOpacity': 0.75
		});
		
		controlRightMenu();
		
		if ($(".btn-inschrijven").length > 0)
		{
			$(".btn-inschrijven").addClass("btn-inschrijven-disabled");
		}
		
		controlSubmit();
		
		$("#instrument").change(function(){
			controlSubmit();
		});
				
		$("input[name='_*POST*_locatie']").click(function(){
			controlSubmit();
		});
		
		$("input[name='_*POST*_tijd']").click(function(){
			controlSubmit();
		});

		$("input[name='_*POST*_dag']").click(function(){
			controlSubmit();
		});

	});
	
	function controlRightMenu()
	{
		$(".cursus-right-links li ul").hide();
		
		$(".cursus-right-links a.active").parent("li").parent("ul").show();
		
		$(".cursus-right-links li h5").click(function() {
			$(this).parent().parent().children("li").children("h5").removeClass("active");
			$(".cursus-right-links li ul").slideUp();
			if (!$(this).siblings("ul").is(":visible"))
			{
				$(this).siblings("ul").slideDown();
				$(this).addClass("active");
			}
		});	
	}
	
	function controlSubmit()
	{
		checkInstrument();
		checkLocation();
		checkTime();
		checkDay();
		setSubmit();
	}
	
	function setSubmit()
	{
		/*
		alert(chosen_instrument);
		alert(chosen_location);
		alert(chosen_time);
		alert(chosen_day);
		*/
		if ( chosen_instrument && chosen_location && chosen_time && chosen_day)
		{
			$("a.btn-inschrijven").removeClass("btn-inschrijven-disabled");
			$("a.btn-inschrijven").attr("href", formUrl);
		}
		else
		{
			$(".btn-inschrijven").addClass("btn-inschrijven-disabled");
			$("a.btn-inschrijven").attr("href", "javascript:;");
		}
	}
	
	function checkInstrument()
	{
		if ($("#instrument").length > 0)
		{
			if ($("#instrument")[0].selectedIndex == 0)
				chosen_instrument = false;
			else
				chosen_instrument = true;
		}
		else
			chosen_instrument = true;
	}
	
	function checkLocation()
	{
		var location_checked = new Array();
		if ($("input[name='_*POST*_locatie']").length > 0)
		{
			$("input[name='_*POST*_locatie']").each(function(){
				if ($(this).attr("checked")) location_checked[location_checked.length] = "ja";	
			});
			if (location_checked.length > 0)
				chosen_location = true;
			else
				chosen_location = false;
		}
		else
			chosen_location = true;
	}
	
	function checkTime()
	{
		var time_checked = new Array();
		if ($("input[name='_*POST*_tijd']").length > 0)
		{
			$("input[name='_*POST*_tijd']").each(function(){
				if ($(this).attr("checked")) time_checked[time_checked.length] = "ja";	
			});
			
			if (time_checked.length > 0)
				chosen_time = true;
			else
				chosen_time = false;			
		}
		else
			chosen_time = true;
	}

	function checkDay()
	{
		var day_checked = new Array();
		if ($("input[name='_*POST*_dag']").length > 0)
		{
			$("input[name='_*POST*_dag']").each(function(){
				if ($(this).attr("checked")) day_checked[day_checked.length] = "ja";	
			});
			
			if (day_checked.length > 0)
				chosen_day = true;
			else
				chosen_day = false;			
		}
		else
			chosen_day = true;
	}
	
	function getCorrectBackground() {
		if ($("#cursus-detail-page").length > 0)
		{
			$(".cursus-pagina-btm").addClass("cursus-pagina-btm-wide");
			$(".cursus-pagina-top").addClass("cursus-pagina-top-wide");
		}
	}