$(document).ready(function(){
 	
 	 			
 	$("#main1 a").click(function() {
 		$("#main2").fadeIn("slow");
 		$("#main2 > div").hide();
		$("#main2 ."+ this.className).fadeIn("slow");
        $("#nav1").fadeIn("slow");
 		$("#nav1 a.home").css({'color' : '#ffff33'});
	});
	
	$("#main2").click(function() {
 		$("#main2").fadeOut("slow");
 		$("#main2 > div2").hide();
 		
	});
		
	$("#nav1 a").click(function() {
		if (this.className == "home") {
			$("#main2, #main3").fadeOut("slow");
			
		};
	});
    
    $("#info img").click(function() {
 		$("#info").fadeOut("slow");
 		
	});

	$("form").submit(function(){
		var params = {};
		var inputok = true;
		$("form .fehler").css("color","#000000");
		
		$("form input.must").each(function(i){
			$("form td." + this.name).css("color","#000000");
			if (this.value == "") {
				$("form td." + this.name).css("color","#ff0000");
				inputok = false;
			};
			
			if (this.name == "email"){
				$("form td.email").css("color","#000000");
				var name = this.value.indexOf("@");
				var domain = this.value.lastIndexOf(".")-name-1;
				var land = this.value.length-name-domain-2;
				
				if (name < 2 || domain < 2 || land < 2 || land > 4) {
				 	$("form td.email").css("color","#ff0000");
				 	inputok = false;
				 };
			};
		});
		var anzahl=0;
		$("form input.anzmust").each(function(){
			anzahl += this.value;
		});
		if (anzahl == 0) {
			inputok = false;
			$("form td.anz_fehler").css("color","#ff0000");
		};
		
		if (!inputok) {
			$("form .fehler").css("color","#ff0000");
			return false;
		};
		$("form :input").each(function(i){
			if (this.name != "cancel" && this.name != "senden") {
				params[this.name] = this.value;
			};
		});
		$.post("send.anmeldung.php", params);
		$("#main3 .anmeldung").hide();
		$("#main3 .antwort").show();
		$("form")[0].reset();
		
		return false;
	});	
	
	$("form input.anz").change(function(){
		$("form td.anz_fehler").css("color","#000000");
		if (isNaN(this.value)){
			this.value = "";
		};
		var kosten = 0;
		$("form input.anz").each(function(){
			if (this.name == "adults") { kosten += this.value*20 ;};
			if (this.name == "studenten" || this.name == "nacht") { kosten += this.value*15 ;};
			if (this.name == "essen_samstag" || this.name == "essen_sonntag") { kosten += this.value*12 ;};
		});
		$("form input[name='kosten']").val(kosten);
		
	});
	
 });
