function estPresent(obj, nom, taille, type) { 
	return maFonction(obj, nom, taille, type, true);
}

function estValide(obj, nom, taille, type) {
	return maFonction(obj, nom, taille, type, false);
}

function maFonction(obj, nom, taille, type, presence) { 
	if(type=="mdp" && document.formulaire.passwd.value!=obj.value)
		{   alert("Vous devez inscrire 2 fois le m\352me mot de passe");
			obj.focus();
			obj.select();
			return false;
		}
	
	if(type=="coche" && obj.checked == false)
		{   alert("Vous devez accepter " + nom );
			obj.focus();
			obj.select();
			return false;
		}
		
	if(type=="select" && obj.value == "")
		{   alert("Vous devez s\351lectionner " + nom );
			obj.focus();
			return false;
		}

	if(type=="verifmail" && document.formulaire.login.value!=obj.value)
		{   alert("Vous devez inscrire 2 fois le m\352me mail !");
			obj.focus();
			obj.select();
			return false;
		}
	if (presence && obj.value == "" && taille!=-1) {
		alert("Vous devez pr\351ciser le champ '" + nom + "'.");
		obj.focus();
		if(type!="date_liste" && type!="enum") obj.select();
		return false;
	}
	
	if (taille != 0 && obj.value.length < taille) {
		alert("Le champ '" + nom + "' est trop court.\nMinimum " + taille + " caracteres.");
		obj.focus();
		obj.select();
		return false;		
	}
	if (obj.value != "" && type == "int") {
		temp = parseInt(obj.value);
		if (isNaN(temp)) {
			alert("Le champ '" + nom + "' n'est pas un nombre entier.");
			obj.focus();
			obj.select();
			return false;
		}
		obj.value = temp
	}
   else if (obj.value != "" && type == "intPositif") {
		temp = parseInt(obj.value);
		if (isNaN(temp)) {
			alert("Le champ '" + nom + "' n'est pas un nombre entier.");
			obj.focus();
			obj.select();
			return false;
		}
		else if (temp <= 0) {
			alert("Le champ '" + nom + "' doit &ecirc;tre un nombre entier POSITIF.");
			obj.focus();
			obj.select();
			return false;
			}
		obj.value = temp
	}
	else if (obj.value != "" && (type == "decimal" || type == "euro")) {
		var temp = replaceString(",", ".", obj.value);
		var ipReg = new RegExp("^[0-9]*[\.]?[0-9]+$");
		if (!ipReg.test(temp)) {
			alert("Le champ '" + nom + "' n'est pas un nombre decimal.");
			obj.focus();
			obj.select();
			return false;
		}
		else if(type == "euro" && temp==0)
			{
				alert("La case '" + nom + "' ne peut etre nulle.");
				obj.focus();
				obj.select();
				return false;
			}
		obj.value = temp			
	}
	else if (obj.value != "" && type == "floatPositif") {
		var temp = replaceString(",", ".", obj.value);
		temp = parseFloat(temp);
		if (isNaN(temp)) {
			alert("Le champ '" + nom + "' n'est pas un nombre d\351cimal.");
			obj.focus();
			obj.select();
			return false;
		}
		else if (temp < 0) {
			alert("Le champ '" + nom + "' n'est pas un nombre d\351cimal POSITIF.");
			obj.focus();
			obj.select();
			return false;
		}
		obj.value = temp
	}
	else if (obj.value != "" && type == "mail") {
		var i = obj.value.indexOf("@",1);
		var j = obj.value.indexOf(".", i + 3);
		if ((i == -1) || (j == -1) || (j + 3 > obj.value.length)) {
			alert("Le champ '" + nom + "' n'est pas un mail valide.");
			obj.focus();
			obj.select();
			return false;			
		}		
	}
	else if (obj.value != "" && type == "tel") {
		var ipReg = new RegExp("^([0-9][-., ]?){10}$");
		if (!ipReg.test(obj.value)) {
			alert("Le champ '" + nom + "' n'est pas un num\351ro valide.");
			obj.focus();
			obj.select();
			return false;			
		}		
	}
	else if (obj.value != "" && type == "url") {
		var i = obj.value.indexOf(".",0);
		
		if (i == -1) {
			alert("Le champ '" + nom + "' n'est pas une url valide.");
			obj.focus();
			obj.select();
			return false;			
		}		
	}
	else if (obj.value != "" && type == "date") {
		var ok = true;
		if ((obj.value.length != 10) || (obj.value.substring(2,3) != "/") || (obj.value.substring(5,6) != "/")) ok = false;
		var i = obj.value.substring(0,2);
		if ((i < 1) || (i >31)) ok = false;
		i = obj.value.substring(3,5);
		if ((i < 1) || (i >12)) ok = false;	
		i = obj.value.substring(6,10);
		if ((i < 1900) || (i >2100)) ok = false;		
		if (!ok) {
			alert("Le champ '" + nom + "' n'est pas une date valide.\nFormat : jj/mm/aaaa.");
			obj.focus();
			obj.select();
			return false;			
		}
	}	
	else if (obj.value != "" && type == "SIREN") {
		var ipReg = new RegExp("^([0-9]){9}$");
		if (!ipReg.test(obj.value)) {
			alert("Le champ '" + nom + "' n'est pas un num\351ro valide.");
			obj.focus();
			obj.select();
			return false;			
		}		
	}
	return true;
}

function replaceString(oldS, newS, fullS) {
 // Remplace oldS avec newS dans la chaine fullS
    for (var i=0; i<fullS.length; i++) {
       if (fullS.substring(i,i+oldS.length) == oldS) {
          fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
       }
    }
    return fullS
}

function limite(champ,taille) 
{ 
 if(champ.value.length > taille) { 
	alert ('TROP de caractere'); 
	// ici on bloque la taille, sinon il ajoute le caractere quand meme. 
	champ.value = champ.value.substr(0, taille); 
	} 
} 

