
// When the DOM is ready...
$(function(){
		   
	$('.legend').corner('10px');
	$('.fieldset').corner('10px');

	
	// 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();
	$("#smsbundel_wrap").hide();
	$("#special_accommodations_wrap").hide();
	
	// Reset form elements back to default values
	/*$("#submit_button").attr("disabled",true);*/
	$("#belminuten").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_one = "not complete";
	$.stepTwoComplete_two = "not complete"; 
		
	// When a dropdown selection is made
	$("#belminuten").change(function() {
	$.stepTwoComplete_one = "complete";
	
	$.get('ajax/getSms/?min='+$(this).val(), function(data) {
	  if(data=='error')
	  {
		$('#ajaxError').html('<span>Er is geen sms bundel beschikbaar!<ol><li>Selecteer belminuten opnieuw</li><li>Of selecteer "Alles weergeven"</li></ol></span>');  
		$('#smsbundel').html('<option value="alles" name="sms-bundel">Helaas geen resultaat</option>');
	  }else{
	  $('#ajaxError span').hide();	  
	  $('#smsbundel').html(data);
	  }
});

	
		$("#step_1")
			$("#step_1").animate({
				paddingBottom: "120px"
			})
			.css({
				"background-image": "url(public/images/check.png)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_2").css({
				opacity: 1.0
			});
			$("#step_2 legend").css({
				opacity: 1.0 // For dumb Internet Explorer
			});
			
	});
	

	
	function stepTwoTest() {
		if (($.stepTwoComplete_one == "complete") && ($.stepTwoComplete_two == "complete")) {
			$("#step_2")
			.animate({
				paddingBottom: "120px"
			})
			.css({
				"background-image": "url(public/images/check.png)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_3").css({
				opacity: 1.0
			});
			$("#step_3 legend").css({
				opacity: 1.0 // For dumb Internet Explorer
			});
		}
	};
	
	$("#step_2 input[name=sms]").click(function(){
		
		if ($("#company_name_toggle_on:checked").val() == 'on') {
			$("#smsbundel_wrap").slideDown();
		} else {
			$.stepTwoComplete_two = "complete"; 
			stepTwoTest();
		};
		
	});
	
	$("#smsbundel").change(function(){
		$.stepTwoComplete_two = "complete"; 
		stepTwoTest();
	});
	
	$("#go").click(function(){
		if (this.checked && $("#belminuten option:selected").text() != 'Please Choose'
		  	&& $.stepTwoComplete_one == 'complete' && $.stepTwoComplete_two == 'complete') {
				$("#submit_button").attr("disabled",false);
			} else {
				$("#submit_button").attr("disabled",true);
		}
	});
	
});