function do_go(theForm) {
	var error = 0;
	if (theForm.country.value == "") {
		error++;
	}
	if (theForm.language.value == "") {
		error++;
	}
	if (error) {
		alert(lbl_general_choose_country);
	} else {
		theForm.action = "/" + theForm.country.value + "/" + theForm.language.value + "/";
		theForm.submit();
	}
}

function toggleTaalkeuze() {
	divTaalkeuze = document.getElementById("taalkeuze");
	lnkTaalkeuze = document.getElementById("linkTaalkeuze");
	if(divTaalkeuze && lnkTaalkeuze) {	
		lnkTaalkeuze.onclick = function() {
			divTaalkeuze.style.visibility="visible";
			return false;
		}
		lnkCloseTaalkeuze = document.getElementById("closeTaalkeuze");
		if(lnkCloseTaalkeuze) {
			lnkCloseTaalkeuze.onclick = function() {
				divTaalkeuze.style.visibility="hidden";
				return false;
			}
		}
	}
	lnkGoTaalkeuze = document.getElementById("linkgo");
	if(lnkGoTaalkeuze) {
		lnkGoTaalkeuze.onclick = function() {
			do_go(document.startform);
			return false;
		}
	}
}

function do_countriechange(theForm) {
	while (theForm.language.options.length > 1) {
		theForm.language.options[(theForm.language.options.length - 1)] = null;
	}
	theForm.language.style.display = "none";
	
	if (theForm.country.value == "fr") {
		theForm.language.options[0]= new Option(lbl_language_fr, "fr", true, true);
	}
	if (theForm.country.value == "gb") {
		theForm.language.options[0]= new Option(lbl_language_en, "en", true, true);
	}
	if (theForm.country.value == "it") {
		theForm.language.options[0]= new Option(lbl_language_it, "it", true, true);
	}
	if (theForm.country.value == "es") {
		theForm.language.options[0]= new Option(lbl_language_es, "es", true, true);
	}
	if (theForm.country.value == "ch") {
		theForm.language.options[0]= new Option('language', "", true, true);
		theForm.language.options[1]= new Option(lbl_language_de, "de", true, false);
		theForm.language.options[2]= new Option(lbl_language_fr, "fr", true, false);
		theForm.language.style.display = "inline";
	}
	if (theForm.country.value == "cn") {
		theForm.language.options[0]= new Option('language', "", true, true);
		theForm.language.options[1]= new Option(lbl_language_cn, "cn", true, false);
		theForm.language.options[2]= new Option(lbl_language_en, "en", true, false);
		theForm.language.style.display = "inline";
	}
	if (theForm.country.value == "nl") {
		theForm.language.options[0]= new Option(lbl_language_nl, "nl", true, true);
	}
	if (theForm.country.value == "pl") {
		theForm.language.options[0]= new Option(lbl_language_pl, "pl", true, true);
	}
	if (theForm.country.value == "ru") {
		theForm.language.options[0]= new Option(lbl_language_ru, "ru", true, true);
	}
	if (theForm.country.value == "ca") {
		theForm.language.options[0]= new Option('language', "", true, true);
		theForm.language.options[1]= new Option(lbl_language_fr, "fr", true, false);
		theForm.language.options[2]= new Option(lbl_language_en, "en", true, false);
		theForm.language.style.display = "inline";
	}
	if (theForm.country.value == "be") {
		theForm.language.options[0]= new Option('language', "", true, true);
		theForm.language.options[1]= new Option(lbl_language_fr, "fr", true, false);
		theForm.language.options[2]= new Option(lbl_language_nl, "nl", true, false);
		theForm.language.style.display = "inline";
	}
	if (theForm.country.value == "us") {
		theForm.language.options[0]= new Option(lbl_language_en, "en", true, true);
	}
	if (theForm.country.value == "in") {
		theForm.language.options[0]= new Option(lbl_language_en, "en", true, true);
	}
	if (theForm.country.value == "my") {
		theForm.language.options[0]= new Option(lbl_language_en, "en", true, true);
	}
	if (theForm.country.value == "de") {
		theForm.language.options[0]= new Option(lbl_language_en, "de", true, true);
	}
	if (theForm.country.value == "mx") {
		theForm.language.options[0]= new Option(lbl_language_en, "es", true, true);
	}
}

function validateAndSubmitForm(theForm) {
	$('#' + theForm).validate({ignore: ":hidden"});
	if ($('#' + theForm).valid()) {
		//return true;
		$('#' + theForm).submit();
	} else {
		alert(lbl_general_fill_out_required);
		return false;
	}
}

$(document).ready(function() {

	toggleTaalkeuze();
	
	// VALIDATOR
	$.validator.messages.required = "*";
	$.validator.messages.email = "*";
	// Add validation for required fields
	$.validator.addMethod("req", function (value, element){ return jQuery.trim(value).length > 0;}, "*");

	
	// GALLERY
	var current = 1;
	var button = 1;
	var images = $('#slides').children().size(); 
	//width = 358;
	var width = 545;
	
	$('#p1').animate({"left": "0px"}, 400, "swing");
	
	$("#next").click(function() {
		button = current;
		current++
		if (current == (images+1) ) {current = 1}
		animateLeft(current,button)
		return false;
	});
	
	$("#previous").click(function() {
		button = current;
		current--
		if (current == 0 ) {current = images}
		animateRight(current,button)
		return false;
	});
	
	function animateLeft(current,button) {
		$('#p'+current).css("left",width +"px");
		$('#p'+current).animate({"left": "0px"}, 400, "swing");
		$('#p'+button).animate({"left": -width+"px"}, 400, "swing");
	}
	
	function animateRight(current,button) {
		$('#p'+current).css("left",-width+"px");
		$('#p'+current).animate({"left": "0px"}, 400, "swing");
		$('#p'+button).animate({"left": width+"px"}, 400, "swing");
	}

	// SLIDE TOGGLE
	//$("div[id^='chefBlock']").hide();
	//$("#levelBlock").hide();
	//$("#academyBlock").hide();

	$("a[id^='Block']").click(function() {
		$("#includedBlock").hide();
		$(".chefInfoBlock").hide();
		$("#levelBlock").hide();
		$("#academyBlock").hide();
		var $this = $(this);
		var x = $this.attr("id");
		$("#chef" + x).show();
		//return false;
	});
	$("#levelBlockLink").click(function() {
		$("#includedBlock").hide();
		$(".chefInfoBlock").hide();
		$("#levelBlock").hide();
		$("#academyBlock").hide();
		$("#levelBlock").show();
		//return false;
	});
	$("#academyBlockLink").click(function() {
		$("#includedBlock").hide();
		$(".chefInfoBlock").hide();
		$("#levelBlock").hide();
		$("#academyBlock").hide();
		$("#academyBlock").show();
		//return false;
	});
	$("#includedBlockLink").click(function() {
		$("#includedBlock").hide();
		$(".chefInfoBlock").hide();
		$("#levelBlock").hide();
		$("#academyBlock").hide();
		$("#includedBlock").show();
		//return false;
	});


	// FORM
    $("#c_country").change( function () { 
		//alert($("#c_country option:selected").val());
		if ($("#c_country option:selected").val() == "US") {
			$("#state_other").attr("name","state_other");
			$("#state_ca_wrap").hide();
			$("#state_ca").attr("name","state_ca");
			$("#state_us_wrap").show();
			$("#state_us").attr("name","state");
		} else if ($("#c_country option:selected").val() == "CA") {
			$("#state_other").attr("name","state_other");
			$("#state_us_wrap").hide();
			$("#state_us").attr("name","state_us");
			$("#state_ca_wrap").show();		
			$("#state_ca").attr("name","state");
		} else {
			$("#state_ca_wrap").hide();
			$("#state_ca").attr("name","state_ca");
			$("#state_us_wrap").hide();
			$("#state_us").attr("name","state_us");
			$("#state_other").attr("name","state");
			$("#state_other").attr("value","");
		}
    });
    $("#activity").change( function () { 
		if ($("#activity option:selected").val() == "other") {
			$("#activity_other_wrap").show();
		} else {
			$("#activity_other_wrap").hide();
		}
    });
    
 	// Course Type Images
	$('.fotos .thumbImages img').hover(
		function(){
			// mouseover
			var blockID = $(this).parent().parent().parent().attr('id');
			$('#' + blockID + ' .bigImage img').attr('src', this.src)
		},
		function(){
			 // mouseout
		}
	);
	


    $("#calendar #country").change( function () { 
		var language = $("#calendar_language").val();
		var dataString = "course_academy=" + this.value + "&language=" + language;
		$.ajax({ 
			type: "GET",
			url: "/inc/ajax.dhtml",
			data: dataString,
			async: false,
			success: function(html) {
				$("#course_chef").html(html)
			}
		});
    });
 	

});