//initialisation

// Déclaration de var IMAGE VALIDE - NON VALIDE
var src_true = "../template/img/true.png";
var src_false = "../template/img/false.png";


//recherche si le champ est vide
function checkString(entry) {
    for(var i = 0; i < entry.length; i++){
        if (entry.charAt(i) != " ") {
            return true;
        }
    }
    return false;
}
//////////////////////////////////////////////////////////////////

// Recheche si @ email est dans le bon format
function checkEmail(entry){
	var filtre_email = new RegExp ("^[a-zA-Z]((.|-|_)?[a-zA-Z0-9]+)*@[a-zA-Z0-9]((.|-|_)?[a-zA-Z0-9]+)*(.[a-zA-Z]{2,4})$","gi");
		if ( !document.form_inscript.email.value.match(filtre_email))
		{
			return false;
		}
	return true;
}
//////////////////////////////////////////////////////////////////

// vérification si le champs est valide ou non, si oui on change l'image de validité
function notificationChamp(champ, valeur) {
	if (document.getElementById("r"+champ.id) != null ) {
		var monImage = document.getElementById("r"+champ.id).getElementsByTagName("IMG")[0];
		if (valeur) {
			monImage.src = src_true;
			if (monImage.alt != 'non obligatoire')
				{monImage.alt = "valide";}
		} else {
			monImage.src = src_false;
			if (monImage.alt != 'non obligatoire')
				{monImage.alt = "non valide";}
		}
		
		if (verifForm(document.getElementById("formulaire"))) {
			document.getElementById("boutonSubmit").disabled = false;
		} else {
			document.getElementById("boutonSubmit").disabled = true;
		}
	} else {
		alert("r"+champ.id);
	}
}
//////////////////////////////////////////////////////////////////

function verifForm(formulaire) {
	var lesImages = formulaire.getElementsByTagName("img");
	
	for (var i = 0; i < lesImages.length; i++) {
		if (lesImages[i].className == "imageValidation" && (lesImages[i].alt != "valide" && lesImages[i].alt != 'non obligatoire')) {
			return false;
		}
	}
	
	return true;
}
//////////////////////////////////////////////////////////////////


//vérification champs NON VIDE - retourne IMAGE VALIDE ou NON VALIDE
function verifChamp(champ) {
	notificationChamp(champ, checkString(champ.value));
}
//////////////////////////////////////////////////////////////////


//vérification champs MAil retourne IMAGE VALIDE ou NON VALIDE
function verifChampMail(champMail) {
	notificationChamp(champMail, checkEmail(document.form_inscript.email.value));
}
//////////////////////////////////////////////////////////////////


