//Validation Newsletter
$(document).ready(function() {
	var validator = $("#infolettre").bind("invalid-form.validate", function() {
		
	}).validate({
		rules: {
			courriel: {
				required: true,
				email: true,
				remote: "../library/inc/check_emails.php"
			}
		},
		messages: {
			courriel: {
				required: "Please enter you email address",
				email: "Invalid email address",
				remote: jQuery.format("{0} is already registered")
			}
   		},
   		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				target: "#newsletterForm",
				success: function() {
					$("#newsletterForm").html("<div id=\"message\"></div>");
					$("#message").html("<h5>Your email has been registered!</h5>")
					//.append("<p>Vous recevrez des nouvelles de Jouvence sous peu.</p>")
					.hide()
					.fadeIn(1500, function() {
					  $("#message");
					});
				  }
			});
		}

	});
	
});

$(document).ready(function() {
						   
	$.validator.addMethod('phone', function (value) {
	return /^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/.test(value);
	}, 'Please enter a valid phone number.');
	
	var validator = $("#contactForm").bind("invalid-form.validate", function() {
		
	}).validate({
		rules: {
			name: "required",
			courriel: {
				required: "#parcourriel:checked",
				email: true
			}
		},
		messages: {
			lastname: "Please enter your last name",
			firstname: "Please enter your first name",
			communication: "Please choose an option",
			phone: {
				required: "Phone number required",
				phone: "Please enter a valid phone number"
			},
			courriel: {
				required: "Please enter a email adress",
				email: "Email adress invalid"
			}
   		},
   		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				target: "#informationForm",
				success: function() {
					$("#informationForm").html("<div id=\"message\"></div>");
					$("#message").html("<h5>Your information requestion has been sent.<br />You will be contacted by a member of our team real soon...</h5><p>See you soon at Jouvence!</p>")
					.hide()
					.fadeIn(1500, function() {
					  $("#message");
					});
				  }
			});
		}

	});
	
});
