// JavaScript Document

function submitForm() {
	$(function() {
		$(".button").click(function() {
			// process form	
			
			var fname = $("input#first_name").val();
			var lname = $("input#last_name").val();
			var email = $("input#email1").val();
			var phone = $("input#phone_home").val();
			var age = $("input#age").val();
			var gender = $("input#gender").val();
			var address= $("input#primary_address_street").val();
			var city = $("input#primary_address_city").val();
			var state = $("select#primary_address_state").val();
			var zip = $("input#primary_address_postalcode").val();
			var church = $("input#church").val();
			var leader = $("input#leader").val();
			var rm1 = $("input#roommate1").val();
			var rm2 = $("input#roommate2").val();
			var rm3 = $("input#roommate3").val();
			var comments = $("textarea#description").val();

			var dataString = 'first_name='+ fname + '&last_name=' + lname + '&email1=' + email + '&phone_home=' + phone + '&age=' + age + '&gender=' + gender + '&primary_address_street=' + address + '&primary_address_city=' + city + '&primary_address_state=' + state + '&primary_address_postalcode=' + zip + '&church=' + church + '&leader=' + leader + '&roommate1=' + rm1 + '&roommate2=' + rm2 + '&roommate3=' + rm3 + '&description=' + comments;
			//alert (dataString); return false;
			
			$.ajax({
				type: "POST",
				url: "scripts/register.php",
				data: dataString,
				success: function() {
					$('#reg_form').html("<div id='empty'></div>");
					$("#step2").fadeIn(1500); 
					/*$('#message').html("<h2>Registration Form Submitted</h2>")
					.append("<p><strong>Step 2:</strong> Complete the registration process by purchasing your pass below.</p>")
					.hide()
					.fadeIn(1500);*/
				},
				error: function(request,error) {
					$('#reg_form').html("<div id='error'></div>");
					if (error = "timeout") {
					 $("#error").append("The request timed out, please resubmit");
					}
					else {
					 $("#error").append("ERROR: " + error);
					}
				}
			 });
			return false;
		});
	});
}
