$(document).ready(function(){
	//standard AJAX mail form submission (requires mail2_plus.php, and captcha)
	//add form name to selector for submit event, the rest will take care of itself!
	$("input[type=submit]").removeAttr("disabled");
	$("#couponf,#contactf").submit(function(e){
		e.preventDefault();
		var form = $(this);
		var btn = $(this).find("input[type=submit]");
		btn.attr("disabled","disabled");
		$.post("includes/mail2_plus.php",form.serialize(),function(data){
			var err = data.split("|");
			if (err[0] == "error") {
				alert(err[1]);
				btn.removeAttr("disabled");
			} else {
				//if a redirect is specified, use that. Else replace the form with a message.
				if (form.find("input[name=redirect]").length && form.find("input[name=redirect]").val() != "") {
					window.location = form.find("input[name=redirect]").val();
				} else {
					form.html("<p class='sent'>Your message has been sent.</p>");
				}
			}
		});
	});
});
