

// fonction Super Check V3.0

// Par Jerome Coquard, 10/03/2000

// Last update : JeC 11/02/2001



// Utilisation :

// |--------------------------------------------------------------------------------------------------------------------------------|

// |<FORM .... NAME="nom_du_formulaire">																							|

// |<SCRIPT>																														|

// |var nom_du_champs1 = "test 1[|test 2|....|test n]";																				|

// |...																																|

// |var nom_du_champsn = ...																										|

// |</SCRIPT>																														|

// |																																|

// |....																															|

// |																																|

// |<INPUT TYPE="BUTTON" ONCLICK="SuperCheck('nom_du_formulaire','nom_du_champs1'[,'nom_du_champs2', ... ,'nom_du_champsn'])"...	|

// |...</FORM>																														|

// |--------------------------------------------------------------------------------------------------------------------------------|



// Tests disponibles :



// obligatoire[:nom_partie]

// numerique

// textuel

// mailformat

// minimum:n

// maximum:n

// nbcaractere:n

// aumoins1:champs1:champ2[:...champsn]:nom_formulaire:nom_partie

// dateformat:format:caractère_de_séparation[:nom_partie]

// si:valeur:fonction[:param1:param2...paramn]

// egal:champ:nom_formulaire

// aunmoins:Minimum:nomFormulaire





// Fonctions des tests :



function obligatoire (Chaine, Champs) {

		warning = arguments[1];

	if (arguments.length == 3) {

		Champs = arguments[2];

	}

	if(Chaine == '') {

		document.images[warning].src="images/warning.gif";

		pb = "Le champ \"" + Champs + "\" est obligatoire.";

		return pb;

	}

	return "no problemo";

}



function egal (Chaine, Champs, Champs2, Formu) {

	var temp = eval("document."+Formu+"."+Champs2+".value");

	if (Chaine != temp) {

		pb = "Le champ " + Champs + " doit être egal au champ " + Champs2 + ".";

		return pb;

	} else {

		return "no problemo";

	}

}







function numerique (Chaine, Champs) {

	warning = arguments[1];

	if(isNaN(Chaine) && Chaine != '') {

		if (arguments.length == 3) {

			Champs = arguments[2];

			}

		document.images[warning].src="images/warning.gif";

		pb = "Le champ \"" + Champs + "\" doit être composé de chiffres.";

		return pb;

	}

	return "no problemo";

}



function textuel (Chaine, Champs) {

	warning = arguments[1];

	if(!isNaN(Chaine) && Chaine != '') {

		if (arguments.length == 3) {

			Champs = arguments[2];

			}

		document.images[warning].src="images/pixel.gif";

		pb = "Le champ " + Champs + " doit être composé de caractères.";

		return pb;

	}

	return "no problemo";

}



function minimum(Chaine, Champs, Limite) {

	if (Chaine.length < Limite) {

		pb = "Le champ " + Champs + " doit comporter au moins " + Limite + " caractères.";

		return pb;

	}

	return "no problemo";

}



function maximum(Chaine, Champs, Limite) {

	if (Chaine.length > Limite) {

		pb = "Le champ " + Champs + " doit comporter au plus " + Limite + " caractères.";

		return pb;

	}

	return "no problemo";

}



function nbcaractere(Chaine, Champs, Limite) {

	warning = arguments[1];

	if (Chaine.length != Limite && Chaine.length != 0) {

		if (arguments.length == 4) {

			Champs = arguments[3];

			}

		document.images[warning].src="images/warning.gif";

		pb = "Le champ \"" + Champs + "\" doit comporter " + Limite + " caractères.";

		return pb;

	}

	return "no problemo";

}



function dateformat(Chaine, Champs, Format, SplitChr) {

	SChaine = Chaine.split(SplitChr);

	SFormat = Format.split(SplitChr);

	if (arguments.length == 5) {

		Champs = arguments[4];

		}

	if (SChaine.length != SFormat.length && Chaine != '') {

		pb = "Le format du champ " + Champs + " n'est pas valide.";

		return pb;

	} else {

		for (var Counter = 0 ; Counter < SChaine.length ; Counter++) {

			if ((SChaine[Counter].length != SFormat[Counter].length || isNaN(SChaine[Counter])) && Chaine != '') {

				pb = "Le format du champ " + Champs + " n'est pas valide.";

				return pb;

			}

		}

		if (((SChaine[0] > 31) || (SChaine[0] < 1) || (SChaine[1] > 12) || (SChaine[1] < 1)) && Chaine != '') {

			pb = "La date du champ " + Champs + " n'est pas correcte.";

			return pb;

		}

	}

	return "no problemo";

}



function mailformat (Chaine, Champs) {

	apos=Chaine.indexOf("@")

	dotpos=Chaine.lastIndexOf(".")

	lastpos=Chaine.length-1

	if (Chaine != '' && (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)) {

		document.images[arguments[1]].src="images/warning.gif";

		pb = "Le champ \"" + Champs + "\" doit avoir le format email.";

		return pb;

	}

	return "no problemo";

}



function aumoins1 (Chaine, Champs) {

	var counterror = 0;

	var evalexe = "";

	for (counter = 2; counter < arguments.length-2; counter++) {

		if (eval("document." + arguments[arguments.length-2] + "." + arguments[counter] + ".length")) {

			truc = "document." + arguments[arguments.length-2] + "." + arguments[counter];

			for (count2 = 0; count2 < eval(truc + ".length"); count2++) {

				if (eval(truc + "[" + count2 + "].checked")) {

					evalexe = eval(truc + "[" + count2 + "].value");

				}

			}

		} else {

			if (eval("document." + arguments[arguments.length-2] + "." + arguments[counter] + ".type") == "checkbox") {

				exe = "document." + arguments[arguments.length-2] + "." + arguments[counter] + ".checked";

				evalexe = eval(exe);

			} else {

				exe = "document." + arguments[arguments.length-2] + "." + arguments[counter] + ".value";

				evalexe = eval(exe);

			}

		}

		if (!evalexe) {

			counterror++;

		}

	}

	if (counterror == ((arguments.length-2)-2)) {

		pb = "Vous devez cocher au moins une case dans la partie " + arguments[arguments.length-1] + ".";

		return pb;

	}

	return "no problemo";

}



function aumoins (Chaine, Champs, Minimum, nomFormulaire) {

	var nbCheck = eval("document." + nomFormulaire + "." + Champs +".length");

	var nbSelected = 0;

	for (i=0; i< nbCheck; i++) {

		if (eval("document." + nomFormulaire + "." + Champs +"["+i+"].checked")) {

			nbSelected++;

		}

	}

	if (nbSelected<Minimum){

		pb = "Vous devez cocher au moins " +Minimum+ " cases dans la partie " + Champs + ".";

		return pb;

	}

	return "no problemo";

}



function si (Chaine, Champs) {

	exe = arguments[3] + "(";

	for(count = 4; count < arguments.length-1; count++) {

		exe = exe + "'" + arguments[count] + "'" + ",";

	}

	exe = exe + "'" + arguments[arguments.length-1] + "'" + ")";

	if (Chaine == arguments[2]) {

		return eval(exe);

	}

	return "no problemo";

}





// Fonction principale :



function SuperCheck (Formu) {
	if (Formu == "coordonne") {
		//document.coordonne.verif.value = 3945112;
		}
	var erreur = "";

	var Root = new Object;

	Root.SubObj = new Array;

	for (var i = 1 ; i < arguments.length ; i++) {

		Root.SubObj[i] = new Object;

		Root.SubObj[i] = arguments[i];

		

		// on met les pixels à la place de flèches rouges

			document.images[arguments[i]].src="images/pixel.gif";

		

		if (eval("document." + Formu + "." + Root.SubObj[i] + ".length")) {

			if (eval("document." + Formu + "." + Root.SubObj[i] + ".options")) {

				vartruc = "document." + Formu + "." + Root.SubObj[i];

				var Str2Chk = eval(vartruc + ".options[" + vartruc + ".selectedIndex].value");

			} else {

				vartruc = "document." + Formu + "." + Root.SubObj[i];

				Str2Chk = "";

				for (c = 0; c < eval(vartruc + ".length"); c++) {

					if (eval(vartruc + "[" + c + "].checked")) {

						Str2Chk = eval(vartruc + "[" + c + "].value");

					}

				}

			}

		} else {

			var Str2Chk = eval("document." + Formu + "." + Root.SubObj[i] + ".value");

		}



		Quotesplit = Str2Chk.split("'");

		Str2Chk = Quotesplit.join("");

		Nsplit = Str2Chk.split("\n");

		Str2Chk = Nsplit.join("");

		Rsplit = Str2Chk.split("\r");

		Str2Chk = Rsplit.join("");



		TabStr = eval(arguments[i]).split('|');

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

			ArgSup = TabStr[j].split(":");

			if (ArgSup.length > 1) {

				execute = ArgSup[0] + "('" + Str2Chk + "', '" + arguments[i] + "', ";

				for (var k = 1 ; k < ArgSup.length ; k++) {

					execute = execute + "'" + ArgSup[k] + "'";

					if (k != (ArgSup.length - 1)) { execute = execute + ", "; }

				}

				execute = execute + ")";

			} else {

				execute = TabStr[j] + "('" + Str2Chk + "', '" + arguments[i] + "')";

			}

			//alert(execute);

			Probleme = eval(execute);

			if(Probleme != "no problemo") {

				erreur = erreur + Probleme + "\n";

			}

		}

	}

	if (erreur != "") {

		erreur = "Vous avez oublié de fournir les informations suivantes:\n\n" + erreur;

		alert(erreur);

	} else {

		eval("document." + Formu + ".submit()");

	}

}
