
/*
@file general.js
@author Stuart Perkins
@version $Id$ 1.0
@copyright loigirardin.net 2007
*/

function chk(){
	return true;
}
function jmcp(V){
	n1 = document.getElementById('nomA');
	p1 = document.getElementById('prenomA');
	e1 = document.getElementById('emailA');
	n2 = document.getElementById('nomB');
	p2 = document.getElementById('prenomB');
	e2 = document.getElementById('emailB');
	if( V == true ){
		n2.value = n1.value;
		p2.value = p1.value;
		e2.value = e1.value;
	}else{
		n2.value = "";
		p2.value = "";
		e2.value = "";
	}
}
function send(F){
	var obj = document.getElementById(F);
	if(F=='sendEmail' || F=='cbkn' || F=='cbkl' || F=='crdv' || F == 'cetude'){
		chkForm(F);
	}else{
		if(chk()==true)obj.submit();
	}
}

function ValidateForm( fid ){
	var F, N, M, T;
	var err, e, result;
	this.F = fid;
	this.err = false;
	this.e = 0;
	this.result = "";
	this.GetByID = function(ID){
		if(document.getElementById){
			return document.getElementById(ID);
		}else if(document.all){
	    return document.all[ID];
		}
	};
	this.HL = function(C){
		GetByID(C).style.borderColor = "#FF9B00";
		GetByID(C).style.backgroundColor = "#FFE4BB";
	};
	this.chkNom = function(){
		this.N = GetByID(this.F).nom.value;
		this.err = false;
		if(this.N.length>=2){
			this.err = regNom();
		}else{
			this.err = true;
		}
		return( !this.err );
	};
	this.chkPrenom = function(){
		this.N = GetByID(this.F).prenom.value;
		this.err = false;
		if(this.N.length>=3){
			this.err = regNom();
		}else{
			this.err = true;
		}
		return( !this.err );
	};
	this.chkEmail = function(){
		this.M = GetByID(this.F).email.value;
		if(this.M.length>8){
			this.err = !regEmail();
		}else{
			this.err = true;
		}
		return( !this.err );
	};
	this.chkTel = function(){
		this.T = GetByID(this.F).Telperso.value;
		if(this.T.length>8){
			this.err = !regTel();
		}else{
			this.err = true;
		}
		return( !this.err );
	};
	this.chkTelFx = function(){
		this.T = GetByID(this.F).Telfixe.value;
		if(this.T.length>8){
			this.err = !regTel();
		}else{
			this.err = true;
		}
		return( !this.err );
	};
	this.chkTelMb = function(){
		this.T = GetByID(this.F).Telgsm.value;
		if(this.T.length>8){
			this.err = !regTel();
		}else{
			this.err = true;
		}
		return( !this.err );
	};
	this.chkCP = function(){
		this.Z = GetByID(this.F).cp.value;
		if(this.Z.length<5)this.err = true;
		return( !this.err );
	};
	this.chkSjt = function(){
		this.Z = GetByID(this.F).subject.value;
		if(this.Z.length<5)this.err = true;
		return( !this.err );
	};
	this.chkMsg = function(){
		this.Z = GetByID(this.F).message.value;
		if(this.Z.length<10)this.err = true;
		return( !this.err );
	};
	this.regNom = function(){
		return(this.N.search(/^\w+((-\w+)|(\.\w+))*[0-9]+$/)!=-1);
	};
	this.regEmail = function(){
		return(this.M.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/)!=-1);
	};
	this.regTel = function(){
		return(this.T.search(/^\w+((-\w+)|(\.\w+))*[0-9]+$/)!=-1);
	};
	if(this.F=='sendEmail'){
		if( !chkNom() ){this.e++;HL('nom');}
		if( !chkEmail() ){this.e++;HL('email');}
		if( !chkCP() ){this.e++;HL('cp');}
		if( !chkSjt() ){this.e++;HL('subject');}
		if( !chkMsg() ){this.e++;HL('message');}
	}else if(this.F=='cbkn' || this.F=='cbkl'){
		if( !chkNom() ){this.e++;HL('nom');}
		if( !chkTel() ){this.e++;HL('Telperso');}
		if( !chkCP() ){this.e++;HL('cp');}
	}else if( this.F == 'crdv' ){
		if( !chkNom() ){this.e++;HL('nom');}
		if( !chkTel() ){this.e++;HL('Telperso');}
		if( !chkCP() ){this.e++;HL('cp');}
		if( !chkEmail() ){this.e++;HL('email');}
	}else if( this.F == 'cetude' ){
		if( !chkNom() ){this.e++;HL('nom');}
		if( !chkPrenom() ){this.e++;HL('prenom');}
		if( !chkTelFx() ){this.e++;HL('Telfixe');}
		if( !chkTelMb() ){this.e++;HL('Telgsm');}
		if( !chkCP() ){this.e++;HL('cp');}
		if( !chkEmail() ){this.e++;HL('email');}
	}
	if( !this.e ){
		this.result = GetByID(this.F).submit();
	}else{
		this.result = alert("veuillez verifier votre saisi.");
	}
	return this.result;
}
function chkForm( fid ){
	chkRes = ValidateForm( fid );
	eval( chkRes );
}