$(document).ready(function() {
	$("#newsletter_submit").click(function() {
		var email = $("input[name='newsletter_email']").val();
		$.ajax({
			type: "GET",
			url: "ajax/newsletter_signup.php",
			data: "email=" + email,
			dataType: "html",
			beforeSend: function() {
				$('#loader').show()
			},
			complete: function(){
				$('#loader').hide()
			},
			success: function(response, textStatus, obj) {
				if (response == 'success') {
					$("#newsletter_form").html(
						"<p style=\"padding-left: 0;\">Thank you! Your email address has been added to our newsletter.</p>"
					);
				}
				else if (response == 'senderror') {
					$("#newsletter_message").html(
						"<p>There has been a problem. Please try again.</p>"
					);
				}
				else if (response == 'invalidemail') {
					$("#newsletter_message").html(
						"<p>Invalid email address.</p>"
					);
				}
				else if (response == 'noemail') {
					$("#newsletter_message").html(
						"<p>Email address empty.</p>"
					);
				}
				else {
					$("#newsletter_message").html(
						"<p>There has been a problem. Please try again.</p>"
					);
				}
			},
			error: function() {
				$("#newsletter_message").html(
					"<p>There has been a problem. Please try again.</p>"
				);
			}
		});
	});
});