// JavaScript Document
jQuery(document).ready(function() {
	
$("#submitted-side").hide();
$("#thank-you-side").hide();

var emailPat = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

// convert text area multiline into single line separated by "; "
function killNewline(string) {
	while (string.indexOf("\n") > 0) {
		string = string.replace(/\n/, "; ");
	}
	return string;
}

$("#email-submit").click(function() {
	
    $("#submitted-side").show();
	$.ajax({	 // need ajax for ie to execute .show
	 success:   function () {
	   $("#submitted-side").show();
		}
	});
	
	// getting field values
	var news_email = $("#news-email").val();
	
	// the email address is NOT valid
	if(!emailPat.test(news_email)) {
		$("#submitted-side").hide();
		alert("The email address is not valid");
		$("#news-email").focus();
		$.ajax({	 // need ajax for ie to execute .show
		 success:   function () {
		   $("#submitted-side").hide();
			}
		});
		return false;
	
	} else {
		
		$.ajax({
			type: 	"POST",
			url: 	"php/padgettNews.php",
			data: 	"&email=" + news_email, 
			success: function () {
				$("#submitted-side").hide();
				$("#thank-you-side").show("slow");
				
				// clear form and hide message
				setTimeout(function() {
					$("#submitted-side").hide();
					$("#thank-you-side").hide();
					$("#news-email").val("");
				}, 10000);
				
			},
			async: false
		});
		
	}
	
}); // end newsletter email submit function
	
}); //end $ function
