﻿$('input[type="text"]').focus(function() {
	if (this.value == this.defaultValue){ 
		this.value = '';
	}
	if(this.value != this.defaultValue){
		this.select();
	}
});
$('input[type="text"]').blur(function() {
	if ($.trim(this.value) == ''){
		this.value = (this.defaultValue ? this.defaultValue : '');
	}
});
$("form.control").submit(function(){
	var msg="";
	$(this).find("input.notEmpty").each(function(){
		if(this.value==this.defaultValue || this.value==""){
			msg+="Le champ "+this.name+" doit être renseigné<br/>";
			$(this).focus();
		}
	});
	$(this).find("input.number").each(function(){
		if(!parseInt(this.value)){
			msg+="Le champ "+this.name+" doit être un nombre entier<br/>";
		}
	});
	
	$(this).find("input.email").each(function(){
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this.value))){
			msg+="Le champ "+this.name+" doit être un email<br/>";
			$(this).focus();
		}
	});
	if(msg==""){
		$.post("nous_contacter.php?js=1", $("form.control>input, form.control>textarea"),
		function(data){
		
			$("#msgCont").html(data);
		
		}, "html");
	}else{
		$("#msg").html("<strong>Le formulaire ne peut être envoyé :</strong><br/><br/>"+msg);
	}
	return false
});
