
// When the DOM is ready...
$(function(){
	
	// Hide stuff with the JavaScript. If JS is disabled, the form will still be useable.
	// NOTE:
	// Sometimes using the .hide(); function isn't as ideal as it uses display: none; 
	// which has problems with some screen readers. Applying a CSS class to kick it off the
	// screen is usually prefered, but since we will be UNhiding these as well, this works.
	$(".name_wrap").hide();
	$("#gemeinde_duellgemeindename").hide();
	$("#gemeinde_duellnichtbekannt").hide();
	
	// Reset form elements back to default values
	$("#submit_button").attr("disabled",true);
	$("#num_attendees").val('Please Choose');
	$("#step_2 input[type=radio]").each(function(){
		this.checked = false;
	});
	$("#rock").each(function(){
		this.checked = false;
	});
	
	// Fade out steps 2 and 3 until ready
	//$("#step_2 :input").attr('disabled', true);
	//$("#step_3 :input").attr('disabled', true);


	//$("#step_2").css({ opacity: 0.3 });
	//$("#step_3").css({ opacity: 0.3 });
	
	$.stepTwoComplete_one = "not complete";
	$.stepTwoComplete_two = "not complete"; 
		
	// When a dropdown selection is made
	
	
	
   //$("#gemeinde_plz_inp").mask("9999");
   //$("#vp_Telefon_inp").mask("+41 (0) 99 999 99 99");
	
	
	
	$("#step_1 :input").blur(function(){
	
		var all_complete = true;
		$("#step_1 :input").each(function(){
			if ($(this).val() == '' ) {
				all_complete = false;
			};
		});
		
		if (all_complete) {
			$("#step_1")
			.animate({
				paddingBottom: "120px"
			})
			.css({
				"background-image": "url(include/register/images/check.png)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_2 :input").removeAttr('disabled');

			$("#step_2").css({
				

				opacity: 1.0
			});
			$("#step_2 legend").css({
				opacity: 1.0 // For dumb Internet Explorer
			});
		};
		
	});	

	
	
	$("#step_2 :input").blur(function(){
	
		var all_complete = true;
		$("#step_2 :input").each(function(){
			if ($(this).val() == '' ) {
				all_complete = false;
			};
		});
		
		if (all_complete) {
			$("#step_2")
			.animate({
				paddingBottom: "120px"
			})
			.css({
				"background-image": "url(include/register/images/check.png)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_3 :input").removeAttr('disabled');
			$("#step_3").css({
				opacity: 1.0
			});
			$("#step_3 legend").css({
				opacity: 1.0 // For dumb Internet Explorer
			});
		};
		
	});
	
	function stepTwoTest() {
		if (($.stepTwoComplete_one == "complete") && ($.stepTwoComplete_two == "complete")) {
			$("#step_2")
			.animate({
				paddingBottom: "0px"
			});
			
			$("#step_3").css({
				opacity: 1.0
			});
			$("#step_3 legend").css({
				opacity: 1.0 // For dumb Internet Explorer
			});
		}
	};
	
	$("#step_2 input[name=company_name_toggle_group]").click(function(){
		$.stepTwoComplete_one = "complete"; 
		if ($("#company_name_toggle_on:checked").val() == 'on') {
			$("#company_name_wrap").slideDown();
		} else {
			$("#company_name_wrap").slideUp();
		};
		stepTwoTest();
	});
	
	$("#step_1 input[name=duelbekannt]").click(function(){
		
		
		if ($("#gemeinde_duellbekannt_on:checked").val() == 'Ja') {
			$("#gemeinde_duellgemeindename").slideDown();
			$("#gemeinde_duellnichtbekannt").slideUp();
			
		} else {
			$("#gemeinde_duellgemeindename").slideUp();
			$("#gemeinde_duellnichtbekannt").slideDown();
			$("#gemeinde_duellgemeindename_inp").val("keine");
		};
		
		
		
		
		
	});
	
	$("#rock").click(function(){
		if (this.checked && $("#num_attendees option:selected").text() != 'Please Choose'
		  	&& $.stepTwoComplete_one == 'complete' && $.stepTwoComplete_two == 'complete') {
				$("#submit_button").attr("disabled",false);
			} else {
				$("#submit_button").attr("disabled",true);
		}
	});
	
	
	
});
