/*
**	Classe de vérification de formulaires
** Developpeur : Vincent DUJOUX
** Date : Décembre 2006
*/

function formCheck(frm){
	this.form = frm;
	this.Champs = new Array();
	this.Message = new Array();
	this.dateToCheck = new Array();
	this.mailToCheck = new Array();
	this.flagResult = false;
	this.tabChamps = new Array();
	this.msg = "";
}

formCheck.prototype.addChamp = function(champ) {
	this.Champs.push(champ.nom);
	this.Message.push(champ.message);
	this.tabChamps.push(champ);
}

formCheck.prototype.isValide = function(){
	this.msg = "";
	var form = document.forms[this.form];
	var test = true;
	for(var i=0; i<this.tabChamps.length; i++){
		//var val = form[this.tabChamps[i].nom].value;
		if(!this.tabChamps[i].isValide(form)){
			test = false;
			this.msg+="- "+this.tabChamps[i].message+"\n";
		}
	}
	this.msg = ((this.msg!="")? "Merci de vérifier les champs suivant :\n\n"+this.msg:"");
	return test;
}

/*
**	Classe de champs
** Developpeur : Vincent DUJOUX
** Date : Décembre 2006
*/

function Champ(nomChamp, messageChamp){
	this.nom = nomChamp;
	this.message = messageChamp;
}

Champ.prototype.isValide = function(form){
	var val=form[this.nom].value;
	return(val!="");
}

/*
**	Classe de champs de type Email
** Developpeur : Vincent DUJOUX
** Date : Décembre 2006
*/
ChampEmail = function(nomChamp, messageChamp){
	this.nom = nomChamp;
	this.message = messageChamp;
}

ChampEmail.prototype = new Champ()

ChampEmail.prototype.isValide = function(form){
	var val=form[this.nom].value;
	return((val.indexOf("@")>=0)&&(val.indexOf(".")>=0));
}

/*
**	Classe de champs de type Date
** Developpeur : Vincent DUJOUX
** Date : Décembre 2006
*/
ChampDate = function(nomChamp, messageChamp){
	this.nom = nomChamp;
	this.message = messageChamp;
}

ChampDate.prototype = new Champ()

ChampDate.prototype.isValide = function(form){
	var val=form[this.nom].value;
	
	var tabDate = val.split("/");
	
	var ddn = true;
	var j=(tabDate[0]);
	var m=(tabDate[1]);
	var a=(tabDate[2]);
	
	var amin=1900; // année mini
	var amax=2020; // année maxi
	if ( ((isNaN(j))||(j<1)||(j>31)) && (ddn==1) ) {
		 ddn=false;
	}
	if ( ((isNaN(m))||(m<1)||(m>12)) && (ddn==1) ) {
		 ddn=false;
	}
	if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ddn==1) ) {
		 ddn=false;
	}
	return ddn;
}

/*
**	Classe de champs de type Code Postal
** Developpeur : Vincent DUJOUX
** Date : Décembre 2006
*/
ChampCodePostal = function(nomChamp, messageChamp){
	this.nom = nomChamp;
	this.message = messageChamp;
}

ChampCodePostal.prototype.isValide = function(form){
	var val=form[this.nom].value;
	return (val>=01000 && val<=99999);
}


/*
**	Classe de champs de type Select
** Developpeur : Vincent DUJOUX
** Date : Décembre 2006
*/
ChampSelect = function(nomChamp, messageChamp){
	this.nom = nomChamp;
	this.message = messageChamp;
}

ChampSelect.prototype.isValide = function(form){
	var val=form[this.nom].options[form[this.nom].selectedIndex].value;
	return (val!="");
}