// JavaScript Document

$(document).ready(function() {
	
	$("#join").validate({
		submitHandler: function(form) {
			$.ajax({
				type: "POST",
				url: "ajax_join.php",
				data: $('#join').serialize(),
				dataType: "json",
				success: function(dat) {
					if (dat.status == "ok") {
						$('.error').hide();				
						$('.mailinglist').append("<p><strong>Thank you for registering.</strong><br />You will receive a confirmation email shortly, please follow the instructions to complete the registration.</p>");
						$('.#join div').slideUp('normal');
					}
					else if (dat.status == "exists") {
						$('.error').html("That e-Mail address is already in our mailing list.").show();
					}
					else {
						$('.error').html("Something went wrong...<br />Please refresh the page and try again.").show();
					}
				}
			});	
 		},
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				$("div.error").show();
			} 
			else {
				$("div.error").hide();
			}
		}, 
		messages: { 
			firstname: " <strong>Error!</strong>", 
			lastname: " <strong>Error!</strong>", 
			email: " <strong>Error!</strong>"
		}, 
		errorClass: "noclass"
	});
	
});