$(document).ready(function(){  
	var checkBoxFax;
	var checkBoxPost;
	var inputFax;
	var inputAdresse;
	var inputPlz;
	var inputCity;
	var isValid;
	
	$("#password").hide();
	$("#passwordRepeat").hide();
	$("#passwordInformation").hide();
	$("label:contains('Passwort')").append("<span>*</span>");
	$("label:contains('Wiederholung')").append("<span>*</span>");	
	

	$(".tx-srfeuserregister-pi1-submit").click(function(){
		isValid = true;
		
		checkBoxFax 	= $("#tx-srfeuserregister-pi1-send_fax:checked").val();
		checkBoxPost 	= $("#tx-srfeuserregister-pi1-send_post:checked").val();
		
		inputFax 		= $("#tx-srfeuserregister-pi1-fax").val();
		inputAdresse 	= $("#tx-srfeuserregister-pi1-address").val();
		inputPlz 		= $("#tx-srfeuserregister-pi1-zip").val();
		inputCity 		= $("#tx-srfeuserregister-pi1-city").val();
		
		//Lšsche Erros fals vorhanden
		$(".tx-srfeuserregister-pi1-error").remove();
		
		//PrŸft ob eine Fax Nummer eingetragen wurde
		if(checkBoxFax == "on") {
			if(inputFax == "") {
				$("#tx-srfeuserregister-pi1-fax").parent().before("<div class='tx-srfeuserregister-pi1-error'>Bitte geben Sie Ihre Faxnummer ein!</div>");
				isValid = false;
			}
		}
		
		//PrŸft ob die Anschrift eingegeben wurde
		if(checkBoxPost == "on"){
			if(inputAdresse == "") {
				$("#tx-srfeuserregister-pi1-address").parent().before("<div class='tx-srfeuserregister-pi1-error'>Bitte geben Sie Ihre Adresse ein!</div>");
				isValid = false;
			}
			if(inputPlz == "") {
				$("#tx-srfeuserregister-pi1-zip").parent().before("<div class='tx-srfeuserregister-pi1-error'>Bitte geben Sie Ihre PLZ ein!</div>");
				isValid = false;
			}
			if(inputCity == "") {
				$("#tx-srfeuserregister-pi1-city").parent().before("<div class='tx-srfeuserregister-pi1-error'>Bitte geben Sie Ihren Ort ein!</div>");
				isValid = false;
			}
		}
		
		return isValid;
	});
	
	/*
	 * Stern zum Input Field HinzufŸgen bei Fax verschicken
	 */
	$("#tx-srfeuserregister-pi1-send_fax").click(function(){
		checkBoxFax 	= $("#tx-srfeuserregister-pi1-send_fax:checked").val();
		
		if(checkBoxFax == "on") {
			$("label:contains('Fax')").append("<span>*</span>");
		}else{
			$("label:contains('Fax') span").remove();
		}
	});
	
	/*
	 * Stern zum Input Field HinzufŸgen bei Post verschicken
	 */
	$("#tx-srfeuserregister-pi1-send_post").click(function(){
		checkBoxPost 	= $("#tx-srfeuserregister-pi1-send_post:checked").val();
		
		//Frage die Checkbox ab
		if(checkBoxPost == "on") {
			$("label:contains('Hausnr')").append("<span>*</span>");
			$("label:contains('PLZ')").append("<span>*</span>");
			$("label:contains('Ort')").append("<span>*</span>");
		}else{
			$("label:contains('Hausnr') span").remove();
			$("label:contains('PLZ') span").remove();
			$("label:contains('Ort') span").remove();
		}
	});

	/*
	* Passwort Feld einblenden ausblenden abhŠngig von der Checkbox
	*/
	$("#chosePassword").click(function(){
		var choseCheckbox = $("#chosePassword:checked").val();
		if(choseCheckbox === "1") {
			$("#password").fadeIn("normal");
			$("#passwordRepeat").fadeIn("normal");
			$("#passwordInformation").fadeIn("normal");
		}else{
			$("#password").fadeOut("normal");
			$("#passwordRepeat").fadeOut("normal");
			$("#passwordInformation").fadeOut("normal");
		}
	});
});
