$(document).ready(function(){

	$("#show_petition").click(function() {
		$("#action_overlay").fadeIn("medium");
	});
	$("#close_overlay").click(function() {
		$("#action_overlay").slideUp("slow");
	});

	$(".taf input[type=submit]").addClass("taf_submit");

	var form = $("#petition_form")
	form.submit(function() {

		$(".notice").hide();
		$(".notice").html('');

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

		var emailAddress = $("#email").val();
		if(emailAddress == '') {
			$(".notice").html('<div class="error">Please enter an email address.</div>');
			hasError = true;
		} else if(!emailReg.test(emailAddress)) {
			$(".notice").html('<div class="error">Please enter a valid email address.</div>');
			hasError = true;
		}
		var zipCode = $("#zip").val();
		if(!zipReg.test(zipCode)) {
			$(".notice").append('<div class="error">Please enter a valid zip code.</div>');
			hasError = true;
		}

		if(hasError) {
			$(".notice").show();
			return false;
		} else {
			form.post();
			alert('posted');
		}
		return false;
	});
});

