//********** 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_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,4}$", "");
	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_nb(champ) {
   var syntaxe_nb = new RegExp("^[0-9.()+ ]*$", "");
   if(!syntaxe_nb.test(champ.value)) {
		alert("Erreur de syntaxe dans le nombre d'heures !");
		return false;
	}
	return true;
}

function verif_cp(champ) {
	var syntaxe_cp = new RegExp("^[0-9]*$", "");
	if(!syntaxe_cp.test(champ.value)) {
		alert("Erreur de syntaxe dans le code postal !");
		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);
}