
// 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();
	$(".num_wrap").hide();
	$(".mag_wrap").hide();
	$(".online_wrap").hide();
	$(".learn_other_wrap").hide();
	$(".radiotv_wrap").hide();
	$(".flyer_wrap").hide();
	$("#question_wrap").hide();
	$("#special_accommodations_wrap").hide();
	$("#extra_info_wrap").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").css({ opacity: 0.3 });
	$("#step_3").css({ opacity: 0.3 });
	
	$.stepTwoComplete = "not complete";
	$.stepThreeComplete = "not complete"; 
		


	function stepOneTest(){
		if(($('#van').attr('checked') 
			|| $('#oak').attr('checked') 
			|| $('#tor').attr('checked') 
			||$('#mon').attr('checked')) 
			&& ($("#num_entry").val().length > 0))
		{
			$("#step_1").animate({ paddingBottom: "90px" })
			.css({
				"background-image": "url(images/check.png)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_2").css({ opacity: 1.0	});
			$("#stp2 #title-wrap").css({ opacity: 1.0 });
			
		} else {
			$("#step_1").animate({ paddingBottom: "0px"	})
			.css({
				"background-image": "",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_2").css({ opacity: 0.3	});
			$("#stp2 #title-wrap").css({ opacity: 0.3 });	
			$("#step_3").css({ opacity: 0.3	});
			$("#stp3 #title-wrap").css({ opacity: 0.3 });
			$("#submit_button").attr("disabled",true);
		}
	}

	

	$("#van").click(function() {
		if($('#van').attr('checked') || $('#oak').attr('checked') || $('#tor').attr('checked') ||$('#mon').attr('checked')){
			$("#num_1_wrap").slideDown();
			stepOneTest();
			stepTwoTest();
		}else{
			stepOneTest();
			stepTwoTest(); 
		}
	});
	$("#mon").click(function() {
		if($('#van').attr('checked') || $('#oak').attr('checked') || $('#tor').attr('checked') ||$('#mon').attr('checked')){
			$("#num_1_wrap").slideDown();
			stepOneTest();
			stepTwoTest();
		}else{
			stepOneTest();
			stepTwoTest(); 
		}
	});
	$("#tor").click(function() {
		if($('#van').attr('checked') || $('#oak').attr('checked') || $('#tor').attr('checked') ||$('#mon').attr('checked')){
			$("#num_1_wrap").slideDown();
			stepOneTest();
			stepTwoTest();
		}else{
			stepOneTest();
			stepTwoTest(); 
		}
	});
	$("#oak").click(function() {
		if($('#van').attr('checked') || $('#oak').attr('checked') || $('#tor').attr('checked') ||$('#mon').attr('checked')){
			$("#num_1_wrap").slideDown();
			stepOneTest();
			stepTwoTest();
		}else{
			stepOneTest();
			stepTwoTest(); 
		}
	});
	
	
	$(".num_input").blur(function(){
		stepOneTest();
		stepTwoTest();
	});
	
	$("#next").click(function(){
		stepOneTest();
			stepTwoTest();
	});
	$("#next2").click(function(){
		stepOneTest();
			stepTwoTest();
	});
	function stepTwoTest() {
		if (($("#first_name").val().length > 0) && ($("#last_name").val().length > 0) && ($("#cemail").val().length > 0)) {
			$("#step_2").animate({
				paddingBottom: "90px"
			})
			.css({
				"background-image": "url(images/check.png)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_3").css({ opacity: 1.0	});
			$("#stp3 #title-wrap").css({ opacity: 1.0 });
			$.stepTwoComplete = "complete"; 
		} else {
			$("#step_2")
			.animate({
				paddingBottom: "15px"
			})
			.css({
				"background-image": "url()",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_3").css({ opacity: 0.3	});
			$("#stp3 #title-wrap").css({ opacity: 0.3 });
			$("#submit_button").attr("disabled",true);
			$.stepTwoComplete = "not complete";
		}
	};
	$("#num_attendees").change(function() {

		$(".name_wrap").slideUp().find("input").removeClass("active_name_field");

        var numAttendees = $("#num_attendees option:selected").text();
                
        for ( i=1; i<=numAttendees; i++ ) {
            $("#attendee_" + i + "_wrap").slideDown().find("input").addClass("active_name_field");
        }
                  
	});
	$("#first_name").blur(function(){ stepTwoTest(); });
	$("#last_name").blur(function(){ stepTwoTest(); });
	$("#email").blur(function(){ 
		stepTwoTest(); 
		//$("#extra_info_wrap").slideDown();
	});
	
	$("#step_3 input[name=question_toggle_group]").click(function(){
		$.stepThreeComplete = "complete";
		if ($("#question_toggle_on:checked").val() == 'on') {
			$("#question_wrap").slideDown();
		} else {
			$("#question_wrap").slideUp();
		};
	});
	
	
	$("#step_3 input[name=question_toggle_group]").click(function(){
		if ($.stepTwoComplete == 'complete' && $.stepThreeComplete == 'complete') {
				$("#submit_button").attr("disabled",false);
			} else {
				$("#submit_button").attr("disabled",true);
		}
	});
	
	$("#mag").click(function() {
		if($('#mag').attr('checked')){
			$("#mag_wrap").slideDown();
		} else {
			$("#mag_wrap").slideUp();	
		}
	});
	
	$("#online").click(function() {
		if($('#online').attr('checked')){
			$("#online_wrap").slideDown();
		} else {
			$("#online_wrap").slideUp();	
		}
	});
	$("#radiotv").click(function() {
		if($('#radiotv').attr('checked')){
			$("#radiotv_wrap").slideDown();
		} else {
			$("#radiotv_wrap").slideUp();	
		}
	});
	$("#learn_other_bx").click(function() {
		if($('#learn_other_bx').attr('checked')){
			$("#learn_other_wrap").slideDown();
		} else {
			$("#learn_other_wrap").slideUp();	
		}
	});
	$("#flyer").click(function() {
		if($('#flyer').attr('checked')){
			$("#flyer_wrap").slideDown();
		} else {
			$("#flyer_wrap").slideUp();	
		}
	});
});
