$(document).ready(function(){
	// Submits the form
	$('#loginForm').submit(function(){
		// Disables the submit button
		$('input[type=submit]',  this).attr('disabled', 'disabled');
	
		// Validates the form
		if ($("#loginForm").valid() == true) {
			// Posts the form to the login processing page
			$.post(
				"/login/process",
				$("#loginForm").serialize(),
				function (data) {
					if (data.type == 'success') {
						// Swaps the form for the PayPal redirect form and submits it
						//$("#viewport").html(data.redirectForm);
						//$('#paypalRedirectForm').submit();
						document.location.href = '/';
					}
					else {
						// Displays the error to the user
						alert(data.message);
					}
				},
				"json"
			);
		}
		
		// Enables the submit button
		$('input[type=submit]',  this).attr('disabled', '');

		// Keeps the form from posting to itself
		return false;
	});
});
