//********** LIBRAIRIE DE VERIFICATION DE FORMULAIRE **********//

//**********    Copyright Lapoz pour e-Lixir 2005    **********//



function verif_remplissage(champs) {

   var i = 0, j;

   for(j=0; j<champs.length; j++) {

      if(!champs[j].value && !i) {

	     alert("Vous n'avez pas rempli tous les champs obligatoires !");

		  i = 1;

		  return false;

	  }

   }

	return true;

}



function verif_liste(champ, descriptif) {

	if(champ.options[champ.selectedIndex].value == "") {

		alert("Vous devez indiquer "+descriptif+" !");

		return false;

	}

	return true;

}



function verif_cases(champs, descriptif) {

	var i = 0, j; 

	for(j=0; j<champs.length; j++)

		if(!champs[j].checked)

			i++;

	if(i==champs.length){

		alert("Vous devez cocher au moins "+descriptif+"...");

		return false;

	}

	return true;

}



function verif_mail(champ) {

	var syntaxe_mail = new RegExp("^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\._]*@[\-a-zA-Z0-9\._]+[\.]{1}[a-zA-Z]{2,5}$", "");

	if(!syntaxe_mail.test(champ.value)) {

		alert("Erreur de syntaxe dans l'adresse mail !");

		return false;

	}

	return true;

}



function verif_tel(champ, descriptif) {

   var syntaxe_tel = new RegExp("^[0-9.()+ ]*$", "");

   if(!syntaxe_tel.test(champ.value)) {

		alert("Erreur de syntaxe dans le numéro de "+descriptif+" !");

		return false;

	}

	return true;

}



function verif_cp(champ) {

	var syntaxe_cp = new RegExp("^[0-9]{1}[0-9abAB]{1}[0-9]{3}$", "");

	if(!syntaxe_cp.test(champ.value)) {

		alert("Erreur de syntaxe dans le code postal !");

		return false;

	}

	return true;

}



function verif_login_pwd(champ) {

	var syntaxe_login_pwd = new RegExp("^[a-zA-Z0-9]{6,}$", "");

	if(!syntaxe_login_pwd.test(champ.value)) {

		alert("Le login comme le mot de passe doivent être composés d'au moins 6 caractères alphanumériques !");

		return false;

	}

	return true;

}

function verif_pwd2(pwd1, pwd2) {

	if(pwd1.value != pwd2.value) {

		alert("Les mots de passes ne sont pas identiques !");

		return false;

	}

	return true;

}



function verif_jour(champ) {

	if(isNaN(champ.value) || champ.value > 31 || champ.value < 1) {

		alert("Erreur dans la date !");

		return false;

	}

	return true;

}



function verif_mois(champ) {

	if(isNaN(champ.value) || champ.value > 12 || champ.value < 1) {

		alert("Erreur dans la date !");

		return false;

	}

	return true;

}



function verif_annee(champ) {

	if(isNaN(champ.value) || champ.value < 1 || champ.value > 9999) {

		alert("Erreur dans la date !");

		return false;

	}

	return true;

}



function verif_heure(champ) {

	if(isNaN(champ.value) || champ.value > 23 || champ.value < 0) {

		alert("Erreur dans l'heure !");

		return false;

	}

	return true;

}



function verif_minute(champ) {

	if(isNaN(champ.value) || champ.value > 59 || champ.value < 0) {

		alert("Erreur dans les minutes !");

		return false;

	}

	return true;

}



function verif_float(champ, descriptif) {

	var syntaxe_float = new RegExp("^[0-9.]*$", "");

	if(!syntaxe_float.test(champ.value)) {

		alert(descriptif+" doit être un nombre !");

		return false;

   }

	return true;

}



function verif_url(champ) {

	var syntaxe_url = new RegExp("^https?://*", "");

	if(!syntaxe_url.test(champ.value))

		champ.value = "http://" + champ.value;

}



function verif_tof(champ) {

	var format_tof = new RegExp("(jpg|jpeg)$", "");

	if(!format_tof.test(champ.value)) {

		alert("Vous devez indiquer une photo au format JPEG !");

		return false;

	}

	return true;

}



function majuscules(champ) {

	champ.value = champ.value.toUpperCase();

}



function minuscules(champ) {

	champ.value = champ.value.toLowerCase();

}



function majFirst(champ) {

	var index;

	var tmpStr;

	var tmpChar;

	var preString;

	var postString;

	var strlen;

	

	tmpStr = champ.value.toLowerCase();

	strLen = tmpStr.length;

	

	if (strLen > 0)  {

		for (index = 0; index < strLen; index++)  {

			if (index == 0)  {

				tmpChar = tmpStr.substring(0,1).toUpperCase();

				postString = tmpStr.substring(1,strLen);

				tmpStr = tmpChar + postString;

			}

			else {

				tmpChar = tmpStr.substring(index, index+1);

				if ((tmpChar == " " || tmpChar == "-") && 

					  (tmpStr.substring(index+1, index+3) != "le" && tmpStr.substring(index+1, index+3) != "la" && 

						tmpStr.substring(index+1, index+3) != "du" && tmpStr.substring(index+1, index+3) != "de" && 

						tmpStr.substring(index+1, index+4) != "des" && tmpStr.substring(index+1, index+4) != "rue" && index < (strLen-1)))  {

					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();

					preString = tmpStr.substring(0, index+1);

					postString = tmpStr.substring(index+2,strLen);

					tmpStr = preString + tmpChar + postString;

				}

			}

		}

	}

	champ.value = tmpStr;

}



function majFirstOnly(champ) {

	champ.value = champ.value.substring(0, 1).toUpperCase() + champ.value.substring(1);

}