jQuery(function($) {
	$('#buyers_journey').submit(function() {
		$("#post").hide();
					
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var email = $('#email_cta');
		var emailVal = email.val();
		if (!emailVal) {
			$("#post").text('Please enter your email address.');
			hasError = true;
		} else if (!emailReg.test(emailVal)) {
			$("#post").text('Please enter a valid email address.');
			hasError = true;
		}

		if (hasError) {
			$("#btn-submit").css("margin-top", "20px");
			$('#post').show();
			email.focus();
		} else {
			$("#btn-submit").hide();
			$(".ajax-loader").show();
			$(this).marketoPost(function() {
				$(".ajax-loader").hide();
				$("#email_me").hide();
				$("#email_cta").hide();
				$("#post").text('Your copy of the Buyer\'s Journey is on its way. If there\'s anything else we can do for you, please connect with us.').show();
				var date = new Date();
				date.setTime(date.getTime()+(365*24*60*60*1000));
				document.cookie = 'BuyerJourney=1; expires='+date.toGMTString()+'; path=/';
			});
		}

		return false;
	});
});

