$(document).ready(function(){
	$("#info").validate({
		onkeyup: false,
		onfocusout: false,
		errorContainer: "#errors",
		errorLabelContainer: "#errors ul",
		wrapper: "li",
		
		rules: {
			name: "required",
			email: {	
				required: true,
       			email: true
			},
			bericht: "required"
		},
		
		messages: {
			name: "Er is geen naam opgegeven",
			email: "Er is geen geldig emailadres opgegeven",
			bericht: "Er is geen bericht ingevuld"
		},
		
		highlight: function(element, errorClass) {
			$(element).attr("style", "border-color:#ff0000;");
 		},
		
		unhighlight: function(element, errorClass) {
			$(element).attr("style", "");
 		}
	});


	$("#info #btn").click(function() { 
		if($("#info").valid()){
			var naam, email, telefoon, bericht;
			naam = $("#name").val();
			email = $("#email").val();
			telefoon = $("#st").val();
			bericht = $("#bericht").val();
			data = "sender=contactformulier&naam=" + naam +"&email=" + email + "&telefoon=" + telefoon + "&bericht=" + bericht;
			
			$.ajax({
				//this is the php file that processes the data and send mail  
				url: "../php/mailer.php",   
				
				//GET method is used  
				type: "POST",  
				   
				//pass the data           
				data: data,       
						  
				//Do not cache the page  
				cache: false,  
				 
				//success  
				success: function (html) {                
					if(html != "")
						alert(html);
						
					$("#info, #instructie").fadeOut('slow', function() { 
						$("#succes").fadeIn();
					});
				}
			});
		}
	});
});
