/*------------------------------------------------------------------
Bibliotheque Javascript : ControlValid.js
--------------------------------------------------------------------
Description :
	Bibliotheque contenant des fonctions qui affectent les formats
	et masques de controle de validation des champs d'un formulaire.
	Lors de la validation ou de l'envoi du formulaire, les champs
	sont controlés pour assurer la cohérence du formulaire.

Evolution à venir :  multilinguisme
--------------------------------------------------------------------
Function Publics :

- obligatoires(objet_form, nom_du_champ_1, nom_en_clair, nom_du_champ_2, nom_en_clair,......)
- txtareataille(objet_form, nom_du_champ_1, nom_en_clair, taille_1, nom_du_champ_2, nom_en_clair,......)
- obligatoiresList(objet_form, nom_du_champ_1, nom_en_clair, valeur_nulle, nom_du_champ_2, nom_en_clair, valeur_nulle,......)
- obligatoiresRadioButton(objet_form, nom_du_groupe, nom_en_clair, nombre_de_radio);
- obligatoiresCheckBox(objet_form, nom_en_clair, identifiant_groupe, nom_du_champ_1, nom_du_champ_2, ...)
- numeriques(objet_form, nom_du_champ_1, nom_en_clair, nom_du_champ_2, nom_en_clair,......)
- majuscules(objet_form, nom_du_champ_1, nom_du_champ_2, ......)
- formats(objet_form, nom_du_champ_1, nom_en_clair, format, nom_du_champ_2, nom_en_clair, format, ......)
- verifierIdentifiant(objet_form, nom_du_champ_1, nom_en_clair, nom_du_champ_2, nom_en_clair, ......)
- formatIdentifiant(objet_form, nom_du_champ_1, nom_en_clair, format, nom_du_champ_2, nom_en_clair, format, ......)
- checkAll(objet_form)
- RAZ(nom_du_champ_1, nom_du_champ_2, ......)
--------------------------------------------------------------------
Exemple Page HTML fonctionnel

	<html></head>
	<script src="tmp/ControlValid.js"></script>
	<script Language="Javascript">
	function initChamps() {
		// Initialise les propriétés des champs
		// On doit juste appeler la bonne fonction, passer la form et
		// les noms de tous les champs suivi du nom 'en clair'
		obligatoires(document.form1, "txfReq1", "Champ 1", "txfReq2", "Champ 2");
		numeriques(document.form1, "txfNum", "Champ montant");
		majuscules(document.form1, "txfMaj1", "txfMaj2");
		obligatoiresList(document.form1, "List1", "List items", "nulle");

		// pour celle-la, il ya 1 seul nom de champ, 1 seul nom en clair, puis du nombre de Radios
		obligatoiresRadioButton(document.form1, "rbGroupA", "Zone Radios A", 3);
		obligatoiresRadioButton(document.form1, "rbGroupB", "Zone Radios B", 4);

		// pour celle-la, c'est 'nom en clair', puis un identificateur de groupe, puis les noms de toutes les CheckBox
		obligatoiresCheckBox(document.form1, "Boite a cocher A", "idGroupe1", "chk1A", "chk2A", "chk3A", "chk4A");
		obligatoiresCheckBox(document.form1, "Boite a cocher B", "idGroupe2", "chk1B", "chk2B");

		// Ici, c'est spécial, juste après chaque champ on doit passer son format
		formats(document.form1, "txfFormat", "Champ formaté", "XX/AA/9999");
		formatIdentifiant(document.form1, "txfFormatIdentifiant", "Champ formaté", "AAAA-XA99AX");
	}
	</script></head>

	<body onLoad="initChamps()">
	<form name="form1" action="tmp/test.htm" onSubmit="return checkAll(this)">
		 Ces deux champs sont obligatoires<br>
		<input type="text" name="txfReq1" size="20">
		<input type="text" name="txfReq2" size="20">
	  <p>
		Celui-ci est num&eacute;rique<br>
		<input type="text" name="txfNum" size="20">
	  <p>
		Celui-ci a le format suivant : XX/AA/9999<br>
		<input type="text" name="txfFormat" size="10" maxlength="10">
	  <p>
		Ces deux champs sont en majuscules<br>
		<input type="text" name="txfMaj1" size="20" value="Celui-ci">
		<input type="text" name="txfMaj2" size="20" value="Et celui-ci">
	  <p>
 	  	<INPUT type="checkbox" name="chk1A" value="1">1A
	  	<INPUT type="checkbox" name="chk2A" value="2">2A
	  	<INPUT type="checkbox" name="chk3A" value="3">3A
	  	<INPUT type="checkbox" name="chk4A" value="4">4A
	  <p>
 	  	<INPUT type="checkbox" name="chk1B" value="1">1B
	  	<INPUT type="checkbox" name="chk2B" value="2">2B
	  <p>
	  	<INPUT type="radio" name="rbGroupA" value="1">1A
	  	<INPUT type="radio" name="rbGroupA" value="2">2A
	  	<INPUT type="radio" name="rbGroupA" value="3">3A
	  <p>
	  	<INPUT type="radio" name="rbGroupB" value="1">1B
	  	<INPUT type="radio" name="rbGroupB" value="2">2B
	  	<INPUT type="radio" name="rbGroupB" value="3">3B
	  	<INPUT type="radio" name="rbGroupB" value="4">4B
	  <p>
	    <SELECT NAME="List1" size="3">
	    	<OPTION value="1">item 1</OPTION>
	    	<OPTION value="nulle">item 2</OPTION>
	    	<OPTION value="3">item 3</OPTION>
	    	<OPTION value="nulle">item 4</OPTION>
	    </SELECT>
	  <p>
		<input type="submit" value="Verif + Submit Formulaire si OK">
		<input type="button" value="Verif simple" name="btnCheck" onClick="checkAll(document.form1)">
	</form></body></html>
-------------------------------------------------------------------*/
MsgErrTxtOblig="\n\nCe champ est obligatoire !";
MsgErrListOblig="\n\nCette liste est obligatoire !";
MsgErrTxtNumber="\n\nCe champ doit être un nombre !";
MsgErrTxtFormat1="\n\nCe champ a le format suivant : "
MsgErrTxtFormat2="\n\nRappel :\nX = Caractère quelconque\nA = Lettre\n9 = Chiffre";
MsgErrTxtFormat3="\nLes années sont comprises entre 1980 et 3000";
MsgErrRbOblig="\n\nUn choix de ce groupe doit être sélectionné !";
MsgErrChkOblig="\n\nUne case à cocher de ce groupe doit être sélectionnée !";
/*
MsgErrTxtOblig="\n\nThis field is mandatory !";
MsgErrListOblig="\n\nThis list is mandatory !";
MsgErrTxtNumber="\n\nThis field must be a number !";
MsgErrTxtFormat1="\n\nThis field has the following format : "
MsgErrTxtFormat2="\n\nRappel :\nX = Caractère quelconque\nA = Lettre\n9 = Chiffre";
MsgErrRbOblig="\n\nA choice of this group must be selected !";
MsgErrChkOblig="\n\nA Checkbox of this group must be selected !";
*/

/*------------------------------------------------------------------
Fonction :		RAZ
--------------------------------------------------------------------
Nature :		public
Arguments :		Nom du champ 1
					+ Nom du champ 2
					+ ...
Resultat :		aucun
Description :	met à vide la valeur des champs spécifiés
-------------------------------------------------------------------*/
function RAZ() {
	for (var i=0; i<RAZ.arguments.length; i++) {
		RAZ.arguments[i].value = "";
	}
}

/*------------------------------------------------------------------
Fonction :		obligatoires
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ 1
					+ Libellé du champ 1
					+ ...
Resultat :		aucun
Description :	Positionne l'attribut obligatoire à true
				pour tous les champs spécifiés
-------------------------------------------------------------------*/
function obligatoires(form) {
	for (var i=1; i<obligatoires.arguments.length; i++) {
		form[obligatoires.arguments[i]].obligatoire = true;
		form[obligatoires.arguments[i]].nomLong = setSpecialEncoding(obligatoires.arguments[++i]);
	}
}

/*------------------------------------------------------------------
Fonction :		setSpecialEncoding
--------------------------------------------------------------------
Nature : 		public
Arguments : 	txtDepart = Texte à formater
Résultat : 		texte formaté
Description : 	Remplace tous les codes HTML des caractères spéciaux,
				notamment les '&eacute;', '&eagrave;', '&agrave;' ou
				bien encore les '&ccedil;', par le caractère brut
				correspondant
--------------------------------------------------------------------*/
function setSpecialEncoding(txtDepart) {
	// tableau à étendre en fonction des besoins...
	tableauCodes = new Array("&eacute;", "é",
							 "&egrave;", "è",
							 "&aacute;", "á",
							 "&agrave;", "à",
							 "&ccedil;", "ç");
	txtRetour = txtDepart;
	
	for (var i=0; i<tableauCodes.length; i=i+2) {
		txtRetour = txtRetour.replace(tableauCodes[i], tableauCodes[i+1]);
	}	
	
	return txtRetour;
}

/*------------------------------------------------------------------
Fonction :		txtareataille
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du textarea 1
					+ Libellé du textarea 1
					+ Nombre de caractères max du textarea 1
					+ ...
Resultat :		aucun
Description :	Permet de définir le nombre de caractères maximum pour un textarea
-------------------------------------------------------------------*/
function txtareataille(form) {
	for (var i=1; i<txtareataille.arguments.length; i++) {
		form[txtareataille.arguments[i]].txtarea = true;
		form[txtareataille.arguments[i]].nomLong = txtareataille.arguments[i+1];
		form[txtareataille.arguments[i]].taille = txtareataille.arguments[i+2];
		i = i+2;
	}
}

/*------------------------------------------------------------------
Fonction :		obligatoiresList
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ 1
					+ Libellé du champ 1
					+ ...
Resultat :		aucun
Description :	Positionne l'attribut obligatoire à true
				pour toutes les listes spécifiées
-------------------------------------------------------------------*/
function obligatoiresList(form) {
	for (var i=1; i<obligatoiresList.arguments.length; i++) {
		form[obligatoiresList.arguments[i]].obligatoireList = true;
		form[obligatoiresList.arguments[i]].nomLong = obligatoiresList.arguments[i+1];
		form[obligatoiresList.arguments[i]].nullValue = obligatoiresList.arguments[i+2];
		i=i+2;
	}
}

/*------------------------------------------------------------------
Fonction :		obligatoiresRadioButton
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ
					+ Libellé du champ
					+ Nombre de radios
Resultat :		aucun
Description :	Positionne l'attribut obligatoire à true
				pour le groupe de RadioButton spécifié
-------------------------------------------------------------------*/
function obligatoiresRadioButton(form) {
	form[obligatoiresRadioButton.arguments[1]].obligatoireRB = true;
	form[obligatoiresRadioButton.arguments[1]].name = obligatoiresRadioButton.arguments[1];
	form[obligatoiresRadioButton.arguments[1]].nomLong = obligatoiresRadioButton.arguments[2];
	form[obligatoiresRadioButton.arguments[1]].numberRB = obligatoiresRadioButton.arguments[3];
}

/*------------------------------------------------------------------
Fonction :		obligatoiresCheckBox
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Libellé du groupe de chexkBox
					+ Identificateur unique du groupe
					+ Nom du champ 1
					+ Nom du champ 2
					+ ...
Resultat :		aucun
Description :	Positionne l'attribut obligatoire à true
				pour tous les champs spécifiés
-------------------------------------------------------------------*/
function obligatoiresCheckBox(form) {
	for (var i=3; i<obligatoiresCheckBox.arguments.length; i++) {
		form[obligatoiresCheckBox.arguments[i]].obligatoireCKB = true;
		form[obligatoiresCheckBox.arguments[i]].nomLong = obligatoiresCheckBox.arguments[1];
		form[obligatoiresCheckBox.arguments[i]].groupe = obligatoiresCheckBox.arguments[2];
	}
}

/*------------------------------------------------------------------
Fonction :		numeriques
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ 1
					+ Libellé du champ 1
					+ ...
Resultat :		aucun
Description :	Positionne l'attribut numérique à true
				pour tous les champs spécifiés
-------------------------------------------------------------------*/
function numeriques(form) {
	for (var i=1; i<numeriques.arguments.length; i++) {
		form[numeriques.arguments[i]].numerique = true;
		form[numeriques.arguments[i]].nomLong = numeriques.arguments[++i];
	}
}

/*------------------------------------------------------------------
Fonction :		majuscules
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ 1
					+ ...
Resultat :		aucun
Description :	Positionne l'événement onblur pour gérer le passage
				en majuscules pour tous les champs spécifiés
-------------------------------------------------------------------*/
function majuscules(form) {
	for (var i=1; i<majuscules.arguments.length; i++) {
		form[majuscules.arguments[i]].onblur = toMaj;
	}
}

/*------------------------------------------------------------------
Fonction :		formats
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ 1
					+ Libellé du champ 1
					+ Format du champ 1
					+ ...
Resultat :		aucun
Description :	Positionne l'attribut format au format spécifié
				pour tous les champs spécifiés
				Le format peut être quelconque, les caractères réservés sont :
					X : qui signifie "n'importe quel caractère"
					A : qui signifie "uniquement une lettre"
					9 : qui signifie "uniquement un chiffre"
-------------------------------------------------------------------*/
function formats(form) {
	for (var i=1; i<formats.arguments.length; i++) {
		var txt = form[formats.arguments[i]];
		txt.nomLong = formats.arguments[++i];
		txt.format = formats.arguments[++i];
	}
}

/*------------------------------------------------------------------
Fonction :		verifierIdentifiant
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ 1
					+ Libellé du champ 1
					+ ...
Resultat :		aucun
Description :	Positionne l'attribut formatIdentifiant au format spécifié (9999-XXXXXXXX)
				pour tous les champs spécifiés
-------------------------------------------------------------------*/
function verifierIdentifiant(form) {
	for (var i=1; i<verifierIdentifiant.arguments.length; i++) {
		var txt = form[verifierIdentifiant.arguments[i]];
		txt.nomIdentifiant = verifierIdentifiant.arguments[++i];
		txt.formatIdentifiant = "9999-XXXXXXXX";
	}
}

/*------------------------------------------------------------------
Fonction :		formatIdentifiant
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
					+ Nom du champ 1
					+ Libellé du champ 1
					+ Format du champ 1
					+ ...
Resultat :		aucun
Description :	Positionne l'attribut formatIdentifiant au format spécifié
				pour tous les champs spécifiés
				Le format commence par "9999-" suivie d'un nombre quelconque de caractères respectant les normes suivantes :
					X : qui signifie "n'importe quel caractère"
					A : qui signifie "uniquement une lettre"
					9 : qui signifie "uniquement un chiffre"
-------------------------------------------------------------------*/
function formatIdentifiant(form) {
	for (var i=1; i<formatIdentifiant.arguments.length; i++) {
		var txt = form[formatIdentifiant.arguments[i]];
		txt.nomIdentifiant = formatIdentifiant.arguments[++i];
		txt.formatIdentifiant = formatIdentifiant.arguments[++i];
	}
}

/*------------------------------------------------------------------
Fonction :		trim
--------------------------------------------------------------------
Nature : 		public
Arguments : 	txtDepart = Valeur d'un texte à formater
Résultat : 		valeur du texte formaté
Description : 	Supprime tous les espaces au début de la chaîne donnée
-------------------------------------------------------------------*/
function trim(txtDepart) {
	i = 0;
	
	for ( ; i < txtDepart.length; i++) {
		if (txtDepart.charAt(i) == ' ') {

		} else {
			break;
		}
	}

	txtRetour = txtDepart.substr(i, txtDepart.length);

	return txtRetour;
}

/*------------------------------------------------------------------
Fonction :		checkAll
--------------------------------------------------------------------
Nature :		public
Arguments :		form = Nom du formulaire concerné
Resultat :		Boolean
Description :	Vérifie tous les champs de la form.
				Retourne true si les champs sont correctements renseignés.
				Affiche une erreur et retourne false sinon.
-------------------------------------------------------------------*/
function checkAll(form) {
	for (var i=0; i<form.elements.length; i++) {
		var txt = form.elements[i];

		if (txt.obligatoire && !checkObligatoire(txt)) {
			return txtError(txt, txt.nomLong + MsgErrTxtOblig)
		}
		if (txt.obligatoireList && !checkObligatoireList(txt)) {
			return txtError(txt, txt.nomLong + MsgErrListOblig)
		}
		if (txt.numerique && !checkNumerique(txt)) {
			return txtError(txt, txt.nomLong + MsgErrTxtNumber)
		}
		if ((txt.format != null) && !checkFormat(txt)) {
			return txtError(txt, txt.nomLong + MsgErrTxtFormat1 + txt.format + MsgErrTxtFormat2)
		}
		if ((txt.formatIdentifiant != null) && !checkFormatIdentifiant(txt)) {
			return txtError(txt, txt.nomIdentifiant + MsgErrTxtFormat1 + txt.formatIdentifiant + MsgErrTxtFormat2 + MsgErrTxtFormat3)
		}
		if (txt.type=="radio" && form[txt.name].obligatoireRB) {
			if (!checkObligatoireRB(form,txt)) {
				return txtError(txt, form[txt.name].nomLong + MsgErrRbOblig)
			}
		}
		if (txt.obligatoireCKB && !checkObligatoireCKB(form, txt.groupe)) {
			return txtError(txt, txt.nomLong + MsgErrChkOblig)
		}
		if (txt.txtarea && !checkTextareataille(txt)) {
			return txtError(txt, txt.nomLong + "\n\nCe champ doit comporter un maximum de " + txt.taille + " caractères");
		}
		

	}
	return true
}

/*------------------------------------------------------------------
Fonction :		checkObligatoire
--------------------------------------------------------------------
Nature :		private
Arguments :		txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si le champ est vide.
-------------------------------------------------------------------*/
function checkObligatoire(txt) {
	if (trim(txt.value).length == 0) {
		return false
	}
	return true
}

/*------------------------------------------------------------------
Fonction :		checkTextareataille
--------------------------------------------------------------------
Nature :		private
Arguments :		txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si le champ possède trop de caractères.
-------------------------------------------------------------------*/
function checkTextareataille(txt) {
	if (txt.value.length > txt.taille) {
		return false
	}
	return true
}


/*------------------------------------------------------------------
Fonction :		checkObligatoireList
--------------------------------------------------------------------
Nature :		private
Arguments :		txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si le champ est vide.
-------------------------------------------------------------------*/
function checkObligatoireList(txt) {
	if (txt.selectedIndex == -1) {
		return false
	}
	if (txt.options[txt.selectedIndex].value == txt.nullValue) {
		return false
	}
	return true
}

/*------------------------------------------------------------------
Fonction :		checkObligatoireRB
--------------------------------------------------------------------
Nature :		private
Arguments :		form = objet formulaire
				txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si aucun Radio n'est sélectionné.
-------------------------------------------------------------------*/
function checkObligatoireRB(form,RdGrp) {
	for (var i=0; i<form[RdGrp.name].numberRB; i++) {
		sRdName = RdGrp.name
		if (form[sRdName][i].checked) {
			return true;
		}
	}
	return false;
}

/*------------------------------------------------------------------
Fonction :		checkObligatoireCKB
--------------------------------------------------------------------
Nature :		private
Arguments :		form = objet formulaire
				txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si aucun Radio n'est sélectionné.
-------------------------------------------------------------------*/
function checkObligatoireCKB(form, sGroupe) {
	for (var i=0; i<form.elements.length; i++) {
		if (form.elements[i].groupe==sGroupe) {
			if (form.elements[i].checked) {
				return true;
			}
		}
	}
	return false;
}

/*------------------------------------------------------------------
Fonction :		checkFormat
--------------------------------------------------------------------
Nature :		private
Arguments :		txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si le champ n'a pas le bon format ou la bonne longueur
-------------------------------------------------------------------*/
function checkFormat(txt) {
	var val = txt.value;

	// S'il est vide, c'est ok
	if (val.length == 0) {
		return true
	}
	// Si la longueur n'est pas bonne, pas la peine d'aller plus loin
	if (val.length != txt.format.length) {
		return false
	}
	// Vérifie chaque caractère en fonction de son format
	for (var i=0; i<val.length; i++) {
		fchar = txt.format.charAt(i);
		vchar = val.charAt(i);
		switch(fchar) {
			case "A" :
				if (!isAlpha(vchar)) {
					return false
				}
				break;
			case "9" :
				if (!isDigit(vchar)) {
					return false
				}
				break;
			case "X" :
				break;
			default :
				if (fchar != vchar) {
					return false
				}
		}
	}
	return true
}

/*------------------------------------------------------------------
Fonction :		checkFormatIdentifiant
--------------------------------------------------------------------
Nature :		private
Arguments :		txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si le champ n'a pas le bon format ou la bonne longueur
				Le format est de la forme "AAAA-" suivi de (A ou 9 ou X) autant de fois que l'on veut
-------------------------------------------------------------------*/
function checkFormatIdentifiant(txt) {
	var val = txt.value;

	// S'il est vide, c'est ok
	if (val.length == 0) {
		return true
	}
	// Si la longueur n'est pas bonne, pas la peine d'aller plus loin
	if (val.length != txt.formatIdentifiant.length) {
		return false
	}
	// Si l'identifiant ne commence par une année, pas la peine d'aller plus loin
	var indexannee = val.indexOf("-");
	if(indexannee!=4) {
		return false;
	}
	for (var i=0; i<indexannee; i++) {
		fchar = txt.formatIdentifiant.charAt(i);
		if(fchar!="A") {
			return false;
		}
	}
	vannee = val.substring(0, indexannee);
	if(vannee<1980 || vannee >3000) {
		return false;
	}
	// Vérifie chaque caractère en fonction de son format
	for (var i=(indexannee+1); i<val.length; i++) {
		fchar = txt.formatIdentifiant.charAt(i);
		vchar = val.charAt(i);
		switch(fchar) {
			case "A" :
				if (!isAlpha(vchar)) {
					return false
				}
				break;
			case "9" :
				if (!isDigit(vchar)) {
					return false
				}
				break;
			case "X" :
				break;
			default :
				if (fchar != vchar) {
					return false
				}
		}
	}
	return true
}

/*------------------------------------------------------------------
Fonction :		checkNumerique
--------------------------------------------------------------------
Nature :		private
Arguments :		txt = Zone du formulaire concerné
Resultat :		Boolean
Description :	Retourne false si le champ n'est pas un nombre
-------------------------------------------------------------------*/
function checkNumerique(txt) {
	var val = txt.value;

	// Retire le signe s'il est présent
	if (val.charAt(0) == "-" || val.charAt(0) == "+") {
		val = val.slice(1)
	}

	// Retire le point
	val = val.replace(/\./, "");
	// Retire la virgule
	val = val.replace(/\,/, "");
	// Retire tous les espaces
	val = val.replace(" ", "");

	// Verifie chaque caractère
	for (var i=0; i<val.length; i++) {
		if (!isDigit(val.charAt(i)))
		return false
	}
	return true
}

/*------------------------------------------------------------------
Fonction :		txtError
--------------------------------------------------------------------
Nature :		private
Arguments :		txt = Zone du formulaire concerné
				msg = Message d'erreur à afficher
Resultat :		Boolean
Description :	Place le focus sur le champ et affiche l'erreur
-------------------------------------------------------------------*/
function txtError(txt, msg) {
	txt.focus();
	if (txt.type!="select-one" && txt.type!="select-multiple") {
		txt.select();
	}
	alert(msg);
	return false;
}

/*------------------------------------------------------------------
Fonction :		toMaj
--------------------------------------------------------------------
Nature :		private
Arguments :		Aucun
Resultat :		Aucun
Description :	Convertit le contenu en Majuscules
-------------------------------------------------------------------*/
function toMaj() {
	this.value = this.value.toUpperCase();
}

/*------------------------------------------------------------------
Fonction :		isDigit
--------------------------------------------------------------------
Nature :		private
Arguments :		Aucun
Resultat :		Aucun
Description :	Retourne true si le caratère est un chiffre
-------------------------------------------------------------------*/
function isDigit(digit) {
	// Tous les caratères accéptés
	var charOk = "0123456789";
	return !(charOk.indexOf(digit) == -1)
}
/*------------------------------------------------------------------
Fonction :		isAlpha
--------------------------------------------------------------------
Nature :		private
Arguments :		Aucun
Resultat :		Aucun
Description :	Retourne true si le caratère est une lettre
-------------------------------------------------------------------*/
function isAlpha(alpha) {
	// Tous les caratères accéptés
	var charOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	return !(charOk.indexOf(alpha) == -1)
}


