function activateElements(root)
{
    $.each(activateFunctions, function() {
        this(root)
    })
}

$(document).ready(function(){
	function parsePhone(root) {
		var phoneNumber = root.find("#salsa .recipient .phone:first");
		var inputAppend = "<input type='hidden' name='Other_Data_1' value='"+phoneNumber.html()+"'>"
		$("#customFields").append(inputAppend);
	}

	function swapForm(root) {
		var swapForm = root.find("#addressform");
		var newContent = "<p> " + 
	 		"To make sure your message goes to your Ohio State Senator, please enter your 10 digit zip code.<p><p>(If you don't know your 10 digit zip code, you can <a target='_blank' href='http://zip4.usps.com/zip4/welcome.jsp'><strong>look it up on the US Postal Service Website</strong></a>.)<p><a target='_blank' href='http://zip4.usps.com/zip4/welcome.jsp'><img src='http://stampoutguncrime.com/img/zip4lookup.jpg'></a>" + 
		"</p> " + 
		"<div class='formRow'> " + 
			"<label>Full Zip</label> " + 
			"<input id='tempZip2' size='5' maxsize='5' value='false' onkeypress='return event.keyCode!=13'/>-<input id='tempZip42' value='' size='4' maxsize='4' onkeypress='return event.keyCode!=13'/> " + 
		"</div> " + 
		"<p><input type='button' onclick='submitZip2()' id='zipSubmit' value='Submit'/></p>"

		swapForm.html(newContent);
	}

	swapForm($(document));

	$(".submit").click(function(e) {
		parsePhone($(document));
	});

	var form = $("#widget_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 = $("#zipcode").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;
	});
});
