function enableStep2()
{
	$("#step_2").css({
		opacity: 1.0
	});
	$("#step_2 legend").css({
		opacity: 1.0 // For dumb Internet Explorer
	});
	$("#step_2 input, #step_2 textarea, #step_2 select").each(function(){
		this.disabled = false;
	});	
}

function disableStep2()
{
	$("#step_2").css({ opacity: 0.3 });
	$("#step_2 input, #step_2 textarea, #step_2 select").each(function(){
		this.disabled = true;
	});
}

function enableStep3()
{
	$("#step_3").css({
		opacity: 1.0
	});
	$("#step_3 legend").css({
		opacity: 1.0 // For dumb Internet Explorer
	});
	$("#step_3 input, #step_3 textarea, #step_3 select").each(function(){
		this.disabled = false;
	});		
}

function disableStep3()
{
	$("#step_3").css({ opacity: 0.3 });
	$("#step_3 input, #step_3 textarea, #step_3 select").each(function(){
		this.disabled = true;
	});		
}

$(function(){	
	// Reset form elements back to default values
	$("#submit_button").attr("disabled",true);
	$("#website_referred").val('Address of Website');
	$("#website_referred").attr("disabled",true);
	$("#tradeshow").val('Name of Tradeshow');
	$("#tradeshow").attr("disabled",true);
	$("#publication_name").val('Publication');
	$("#publication_name").attr("disabled",true);
	$("#other").attr("disabled",true);
	$("#step_1 input[type=radio]").each(function(){
		this.checked = false;
	});
	
	// Disable steps 2 and 3
	disableStep2();
	disableStep3();	
	
	$("input[@name='HearAbout']").change(function(){
		var elem = $("input[@name='HearAbout']:checked");
		$("#website_referred").attr("disabled",true);
		$("#tradeshow").attr("disabled",true);
		$("#publication_name").attr("disabled",true);
		$("#other").attr("disabled",true);
		disableStep2();
		switch(elem.val())
		{
			case 'Another Website':
				$("#website_referred").attr("disabled",false);
				break;
			case 'Tradeshow':
				$("#tradeshow").attr("disabled",false);
				break;
			case 'Print Ad':
				$("#publication_name").attr("disabled",false);
				break;
			case 'Other':
				$("#other").attr("disabled",false);
				break;
		}
		if (elem != null)
			enableStep2();
	});
	
	$("#i_am").change(function() {
		var step1_complete = false;
		
		if ($("#i_am option:selected").val() != "")
		{
			step1_complete = true;
		}
		
		if (step1_complete)
		{
			enableStep2();
		}
		else
		{
			disableStep2();
		}
	});
	
	$("#name,#phone,#email").change(function() {
		var step2_complete = false;
		
		if ($("#name").val() != "" && $("#phone").val() != "" && $("#email").val() != "")
		{
			step2_complete = true;
		}
		
		if (step2_complete)
		{
			enableStep3();
		}
		else
		{
			disableStep3();
		}
	});
	
	$("#next_button_2").click(function() {
		$("#name").change();
	});
	
	$("#security_code,#interested_in").change(function() {
		var step3_complete = false;
	
		if($("#security_code").val() != "" && $("#interested_in option:selected").val() != "")
		{
			step3_complete = true;
		}
		
		if (step3_complete)
		{
			$("#submit_button").attr("disabled",false);		
		}
		else
		{
			$("#submit_button").attr("disabled",true);		
		}
	});
	
	$("#security_code").keypress(function() {
		var step3_complete = false;
	
		if($("#security_code").val() != "" && $("#interested_in option:selected").val() != "")
		{
			step3_complete = true;
		}
		
		if (step3_complete)
		{
			$("#submit_button").attr("disabled",false);		
		}
		else
		{
			$("#submit_button").attr("disabled",true);		
		}
	});
});