$(document).ready(function(){
	$("#betaSignupForm").submit(function(){
		$("#betaSignup").attr("disabled", "disabled");

		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var emailToVal = $("#beta_email").val();
		if(emailToVal == '') {
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {
			hasError = true;
		}

		if(hasError == false) {
			$.ajax({
				type: "POST",
				data: {
					txType: 'betaInvite',
					email: emailToVal
				},
				cache: false,
				dataType: 'html',
				url: '/ajaxincs/beta_request.php',
				timeout: 2000,
				error: function() {
					alert('Whoops! Looks like there was a problem with your submission, try it again in a few seconds.');
				},
				success: function(data) {
					var successText = 'Thanks!  We\'ll send an email to <b>' + emailToVal + '</b> as soon as we are ready for you!';
			        $("#betaSignupContent").html( successText );
			        $("#betaSignupEmailContent").slideUp('fast');
			        $("#betaSignupSubmitButton").slideUp('fast');
			        $("#betaSignupContent").slideDown('slow');
				}
			});
		} else {
			alert("Please enter a valid email address");
			$("#betaSignup").removeAttr("disabled");
		}
		
		return false;
	});
});
