
$(function(){
	if($('#emstaForm').length > 0)
	{
		var isValid = false;
		
		$('#registration_form_error').hide();
		
		// load the common transaction fields section to the registration form
		$('#common_transaction_fields').load('pages/shared/common_transaction_fields.html');
		
		// load the Contact Info section to the registration forms
		$('.contact_info_reg_section').load('pages/shared/contact_info_reg_section.html');
		
		// load the Reservation Payment section to the registration forms
		$('.registration_fee_section').load('pages/shared/registration_fee.html');
		
		// Intercept the submit buttons click event
		$('#registration_submit').click(function(){
			
			// Update the cost of the class to include seating reservation
			//if($('#reserve_seat_payment').is(':checked')) {
				$.post('application/formmail.php', $('#emstaForm').serialize(), function(data){
					if(data.indexOf('Form Submission Error') > 0) {
						$('#registration_form_container').hide();
						$('#registration_form_error').html(data);
						$('#registration_form_error').show();
						isValid = false;
					}else {
						isValid = true;
					}
				});
			//}else {
			//	isValid = true;
			//	$('#emstaForm').attr('action','application/formmail.php');
			//}
			
			if(isValid) {
				$(this).val('Please Wait...');
				$('#emstaForm').submit();
			}else {
				$(this).val('Submit');
				return false;
			}
		});
	}
});
