
// Suppression du message par champ
//jQuery.validator.messages.required = "";

//$().ready(function() {
//function activeForm() {

	/*$("#contactForm").validate();
	alert( $("#contactForm") );*/

	// validate the comment form when it is submitted
	$("#contactForm").validate({
		invalidHandler: function(e, validator) {
			
			
			var errors = validator.numberOfInvalids();
			if (errors) {
				//var message = errors == 1
				//? 'Il vous reste 1 champ &agrave; saisir.'
				//: 'Il vous reste ' + errors + ' champs &agrave; saisir.';
				var message = 'Veuillez renseigner tous les champs requis.'
				$("div.errorMessage span").html(message);
				$("div.errorMessage").show();
			} else {
				$("div.errorMessage").hide();
			}
		},
		
		validHandler: function(e, validator) {
			$("div.errorMessage").hide();
		},
		
		messages: {},
		
		submitHandler: function(form) { 
			//$("input.valid").css.display = 'none';
			
			$("div.errorMessage").hide();
			
			var dataString = 
						'civilite=' + 		$("input[name='civilite']:checked").val()+
						'&nom='+ 			$("input#nom").val() + 
						'&prenom=' + 		$("input#prenom").val() + 
						'&societe=' + 		$("input#societe").val()+
						'&fonction=' + 		$("input#fonction").val()+
						'&telephone=' + 	$("input#telephone").val()+
						'&email=' + 		$("input#email").val()+
						'&message=' + 		$("textarea#message").val()+
						'&ajax=true';
			
			$.ajax({
				url: 'index.php',
				data: dataString,
				dataType: 'json',
				type: 'post',
				success: 'ajaxSuccess'
			});
			
			$("#form2").html('<p style="margin:20px 10px 0 15px;">Votre demande de contact a bien &eacute;t&eacute; pris en compte.</p>');
		},
		
		ajaxSuccess: function (j) {
			
			alert('123');
			
			//$("div.errorMessage span").html(j.msg);
			//$("div.errorMessage").show();
			
			//alert("submitted 2! : "+ j.msg); 
		},
				
		
		ajaxStart: function() {
			alert('123');
			//loader.show();
		},
		
		ajaxStop: function() {
			//loader.hide();
		},
		
		ajaxError: function(a, b, e) {
			throw e;
		}
		
	});
	
	
	
	
	// validate the comment form when it is submitted
	$("#connexion").validate({
		invalidHandler: function(e, validator) {
			
			
			var errors = validator.numberOfInvalids();
			if (errors) {
				//var message = errors == 1
				//? 'Il vous reste 1 champ &agrave; saisir.'
				//: 'Il vous reste ' + errors + ' champs &agrave; saisir.';
				var message = 'Veuillez renseigner tous les champs requis.'
				$("div.errorMessage span").html(message);
				$("div.errorMessage").show();
			} else {
				$("div.errorMessage").hide();
			}
		},
		
		validHandler: function(e, validator) {
			$("div.errorMessage").hide();
		},
		
		messages: {},
		
		submitHandler: function(form) { 
			//$("input.valid").css.display = 'none';
			$("div.errorMessage").hide();
			
			var dataString = 
						'&identifiant='+ 	$("input#identifiant").val() + 
						'&mdp='+ 			$("input#mdp").val() + 
						'&ajax=true';

			$.ajax({
				url: 'schema.php',
				data: dataString,
				dataType: 'json',
				type: 'post',
				success: 'ajaxSuccess'
			});
			
			$("#form2").html('<p style="margin:20px 10px 0 15px;">Votre demande de contact a bien &eacute;t&eacute; pris en compte.</p>');
		},
		
		ajaxSuccess: function (j) {
			
			alert('123');
			
			//$("div.errorMessage span").html(j.msg);
			//$("div.errorMessage").show();
			
			//alert("submitted 2! : "+ j.msg); 
		},
				
		
		ajaxStart: function() {
			alert('123');
			//loader.show();
		},
		
		ajaxStop: function() {
			//loader.hide();
		},
		
		ajaxError: function(a, b, e) {
			throw e;
		}
		
	});
	/*
	$("#contactForm").ajaxSuccess(function() { 
		alert("Thank you for your comment!"); 
	}); */
	
	/*
	// show a simple loading indicator
		var loader = jQuery('<div id="loader"><img src="images/loading.gif" alt="loading..." /></div>')
			.css({position: "relative", top: "1em", left: "25em"})
			.appendTo("body")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		
		var v = jQuery("#form").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});
		
		jQuery("#reset").click(function() {
			v.resetForm();
		});
	
	
	
	alert('hello');*/
//}
//});