var arrChecks = new Array();

var regNotEmpty        = /[^\s]+/;
var regZipCodeOrEmpty  = /^(2[AB]|\d{2})\d{3}$|^\s*$/;
var regZipCodeNotEmpty = /^(2[AB]|\d{2})\d{3}$/;
var regEmail           = /^\s*(\([+]{0,1}\d+\)|[+]{0,1}\d+)(\s*\d+)+\s*$/;
var regDate            = /^(0{0,1}[1-9]|[1-2][0-9]|3[0-1])\/(0{0,1}[1-9]|1[0-2])\/[0-9]{4}$/;

function checkFields(ndeForm)
{

	// Déclarations
	var bValid = true;
	var ndeFields = ndeForm.elements;
	var ndeField = null;
	var ndeFirstInvalidField = null;
	var intNbFields = ndeFields.length;
	var intPos = 0;
			
	// Parcours des champs du formulaire
	while( intPos < intNbFields )
	{
	
		// Validation du champ courant
		ndeField = ndeFields[intPos++];
		if( !checkField(ndeField) )
		{
		
			bValid = false;
			if( ndeFirstInvalidField === null ) ndeFirstInvalidField = ndeField;
			
		}
		
	}
	
	// Affichage d'un message d'alerte et positionnement du curseur
	if( !bValid )
	{
		window.alert('Le contenu d\'un champ au moins est invalide.');
		ndeFirstInvalidField.focus();
	}

	// Retour du résultat
	return bValid;

}

function checkField(ndeField)
{

	// Recherche d'une expression régulière de validation
	var intNbChecks = arrChecks.length;
	var intPos = 0;
	var arrCurrentCheck = null;
	var rexCheck = null;
	
	while( intPos < intNbChecks )
	{
	
		arrCurrentCheck = arrChecks[intPos];
		if( arrCurrentCheck[0] === ndeField.id )
			{ rexCheck = arrCurrentCheck[1]; break; }
			
		++intPos;
	
	}
	
	// Validation du champ à l'aide de la contrainte trouvée
	if( rexCheck !== null )
	{
	
		// Réinitialisation de l'état du champ
		ndeField.className = ndeField.className.replace(/\s*invalid/g, '');

		// Application de l'expression régulière
		if( ndeField.value.search(rexCheck) < 0 )
		{
		
			// Champ invalide
			ndeField.className += ' invalid';
			return false;
		
		}
		else
		{
		
			// Champ validé
			return true;
			
		}
	
	}
	else
	{
	
		// Pas de contrainte sur le champ
		return true;
		
	}

}