﻿$('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[type=checkbox].checked").each(function(){
		if(this.checked==false){
			msg+="La case \"<strong>"+this.name+"</strong>\" doit être cochée<br/>";
			$(this).focus();
		}
	});
	$(this).find("input.notEmpty").each(function(){
		if(this.value==this.defaultValue || this.value==""){
			msg+="Le champ \"<strong>"+this.name+"</strong>\" doit être renseigné<br/>";
			$(this).focus();
		}
	});
	$(this).find("input.number").each(function(){
		if(!parseInt(this.value)){
			msg+="Le champ \"<strong>"+this.name+"</strong>\" doit être un nombre<br/>";
			$(this).focus();
		}
	});
	$(this).find("input.email").each(function(){
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this.value))){
			msg+="Le champ \"<strong>"+this.name+"</strong>\" doit être un email<br/>";
			$(this).focus();
		}
	});
	if(msg==""){
		$("#msg_2").html("");
		$.post("sendmail.php?js=1", $("input"),
		function(data){
			$("#msg_2").html(data);
			$("#bouton_valide").hide();
		}, "html");
	}else{
		$("#msg_2").html("<strong>Le formulaire ne peut être envoyé :</strong><br/><br/>"+msg);
	}
	return false
});
