var chiffre="0123456789"
var nombre = chiffre+"., "
var alpha = "abcdefghijklmnopqrstuvwxyzéèêëôöòîïìàâäûüùç"
var alphanum= alpha+chiffre
var alphanom= alpha+nombre
var alphanom1= alphanom+"- '()€$£%[]{}&=+@?!/°;:*~_’"


function verif_email(dc,facu,min,max,car_vald) {
	// Renvoi une chaine vide si ok, sinon retourne l'erreur
	var unemail = /^((\w+(\-\w+)*)*\.?(\w+(\-\w+)*))+@((\w+(\-\w+)*)*\.(\w+(\-\w+)*))+$/;
	dc = dc.toLowerCase()
	if (dc.length==0) {
		if(!facu) return " obligatoire - taille: "+min+((min!=max)?" à "+max:"")+" caractères"
	}
	else {
		if (dc.length>max) return " trop long - taille maximum: "+max+" caractères"
		if (dc.length<min) return " trop court - taille minimum: "+min+" caractères"
		if (min==max&&dc.length!=min) return " de taille incorrecte - taille: "+max+" caractères"
	}

	if (car_vald=="") return "" // si rien à vérifier renvoi ok

	for (var i=0;i<dc.length;i++) {
		if (car_vald.indexOf(dc.charAt(i))==-1 ) return " mal renseigné - caractère non autorisé: "+dc.charAt(i)
		
	}
	if(!unemail.test(dc)&&dc.length!=0) {return " mal renseigné"} 
	
	return ""
}



function verif_chp(dc,facu,min,max,car_vald) {
	// Renvoi une chaine vide si ok, sinon retourne l'erreur
	dc = dc.toLowerCase()
	if (dc.length==0) {
		if(!facu) return " obligatoire - taille: "+min+((min!=max)?" à "+max:"")+" caractères"
	}
	else {
		if (dc.length>max) return " trop long - taille maximum: "+max+" caractères"
		if (dc.length<min) return " trop court - taille minimum: "+min+" caractères"
		if (min==max&&dc.length!=min) return " de taille incorrecte - taille: "+max+" caractères"
	}

	if (car_vald=="") return "" // si rien à vérifier renvoi ok

	for (var i=0;i<dc.length;i++) {
		if (car_vald.indexOf(dc.charAt(i))==-1 && dc.charAt(i)!="\n" && escape(dc.charAt(i))!="%0D" ) {
			return " mal renseigné - caractère non autorisé: "+dc.charAt(i)
		}
	}
	return ""
}



function getChp(f,c) { return eval("document."+f+".elements['"+c+"']") }

function getChptxt(f,c) { return getChp(f,c).value }

function setChptxt(f,c,t) { return getChp(f,c).value=t }

function enHex(n) {
	var Hex="0123456789abcdef"
	return Hex.charAt((parseInt(n/16)))+Hex.charAt(n%16)
}

function colorconv(c) {
	//converti la couleur de rvb(255,255,255) => #ffffff
	if(c.indexOf("rgb")>-1) {
		c=c.substring(c.indexOf("(")+1,c.length)
		c=c.substring(0,c.length-1)
		var arrText = c.split(", ");
		c="#"
		for (var i=0; i<arrText.length; i++) { c+=enHex(arrText[i]) }
	}

	return c
}

var tab_color=new Array("#ff0006")

function surbr(f,c,etat) {
	var o=getChp(f,c)
	if(etat) {
		for(var i=0; i<tab_color.length; i++) {
			if(colorconv(o.style.borderRightColor)==tab_color[i]) { break; }
		}
		if(i>=tab_color.length-1) i=0
		else i++

		o.style.borderRightColor=tab_color[i]
		o.style.borderBottomColor=tab_color[i]
	}
	else {
		o.style.borderRightColor="#cccccc"
		o.style.borderBottomColor="#cccccc"
	}
}

var timer


function err(s1,s2) { return "- Le champ [ "+s1+" ] est"+s2+"\n" }


function obj_chp(_formu,_nom) {
	//propriete
	this.formu=_formu
	this.nom=_nom
	this.timer=""
	this.ob=getChp(_formu,_nom)
	this.val=""

	//methode
	this.add=addtimer
	this.del=deltimer
	this.txt=gettxt

	this.on=mevon
	this.off=mevoff

}

function addtimer(_timer) { if(this.timer!="") clearInterval(this.timer); this.timer=_timer }
function deltimer() { clearInterval(this.timer); }
function gettxt() { return getChptxt(this.formu,this.nom) }
function mevon() { this.val=this.txt(); this.add( setTimeout("surbr('"+this.formu+"','"+this.nom+"',1)",600) ) }
function mevoff() { this.del(); setTimeout("surbr('"+this.formu+"','"+this.nom+"',0)",500) }
