
function init() {
	// on recupere chaque champ a verifier
	var commentaire_titre 			= document.getElementById('commentaire_titre');
	var commentaire_email			= document.getElementById('commentaire_email');
	var commentaire_commentaires	= document.getElementById('commentaire_commentaires');
	var commentaire_prenom			= document.getElementById('commentaire_prenom');
	var commentaire_nom			= document.getElementById('commentaire_nom');

	// initialise l'appel aux fonctions pour chaque champ
	// il y a des diff&eacute;rences de traitement DOM entre IE et Firefox, notamment pour l'affectation d'&eacute;venement
	// pour IE
	if (window.attachEvent) {
		commentaire_email.onchange 		  = function() { verifEmail(commentaire_email); };
		commentaire_titre.onkeyup  	 	 = function() { verifTitreNonVide(commentaire_titre); };
		commentaire_commentaires.onkeyup = function() { verifCommentairesNonVide(commentaire_commentaires); };
		commentaire_prenom.onkeyup		  = function() { verifPrenomNonVide(commentaire_prenom); };
		commentaire_nom.onkeyup		  = function() { verifNomNonVide(commentaire_nom); };
	}
	// pour Firefox
	else {
		commentaire_email.setAttribute('onKeyUp'			, 'verifEmail(commentaire_email)');
		commentaire_titre.setAttribute('onKeyUp'			, 'verifTitreNonVide(commentaire_titre)');
		commentaire_commentaires.setAttribute('onKeyUp'	, 'verifCommentairesNonVide(commentaire_commentaires)');
		commentaire_prenom.setAttribute('onKeyUp'		, 'verifPrenomNonVide(commentaire_prenom)');
		commentaire_nom.setAttribute('onKeyUp'		, 'verifNomNonVide(commentaire_nom)');
		}
}

function verifEmail(email) {
	adresse = email.value;
	email_alert_ok = document.getElementById('email_alert_ok');
	email_alert_nok = document.getElementById('email_alert_nok');
	// suppression du texte existant
	while(email_alert_ok.firstChild != null) {
		email_alert_ok.removeChild(email_alert_ok.firstChild);
	}
	while(email_alert_nok.firstChild != null) {
		email_alert_nok.removeChild(email_alert_nok.firstChild);
	}
	// creation du message suivant le cas
	if (!checkEmail(adresse)) {
		var texte = document.createTextNode("Le format de l'adresse email entr&eacute;e ne semble pas correct");
		email_alert_nok.appendChild(texte);
	} 
	else {
		imageok(email_alert_ok);
	}
}
function checkEmail(email) {
	var arobase = email.indexOf("@");
	var point = email.lastIndexOf(".");
	if((arobase < 2) || (point + 3 > email.length) || (point < arobase+3)) {
		return false;
	}
	return true;
}
function verifCommentairesNonVide(arg){
	tmp = arg.value;
	lieu_alert_ok = document.getElementById('commentaires_alert_ok');//spanalert.value;
	lieu_alert_nok = document.getElementById('commentaires_alert_nok');//spanalert.value;
	
	var chaine_vide = '';
	// suppression du texte existant
	while(lieu_alert_nok.firstChild != null) {
		lieu_alert_nok.removeChild(lieu_alert_nok.firstChild);
	}
	while(lieu_alert_ok.firstChild != null) {
		lieu_alert_ok.removeChild(lieu_alert_ok.firstChild);
	}
	// creation du message suivant le cas
	if(tmp == chaine_vide) {
		var texte = document.createTextNode("Le message ne peut pas &ecirc;tre vide.");
		lieu_alert_nok.appendChild(texte);
	}
	else {
		imageok(lieu_alert_ok);
	}
}
function verifTitreNonVide(arg){
	tmp = arg.value;
	lieu_alert_ok = document.getElementById('titre_alert_ok');//spanalert.value;
	lieu_alert_nok = document.getElementById('titre_alert_nok');//spanalert.value;
	
	var chaine_vide = '';
	// suppression du texte existant
	while(lieu_alert_nok.firstChild != null) {
		lieu_alert_nok.removeChild(lieu_alert_nok.firstChild);
	}
	while(lieu_alert_ok.firstChild != null) {
		lieu_alert_ok.removeChild(lieu_alert_ok.firstChild);
	}
	// creation du message suivant le cas
	if(tmp == chaine_vide) {
		var texte = document.createTextNode("Veuillez indiquer le titre de votre commentaire");
		lieu_alert_nok.appendChild(texte);
	}
	else {
		imageok(lieu_alert_ok);
	}

}
function verifNomNonVide(arg){
	tmp = arg.value;
	lieu_alert_ok = document.getElementById('nom_alert_ok');//spanalert.value;
	lieu_alert_nok = document.getElementById('nom_alert_nok');//spanalert.value;
	
	var chaine_vide = '';
	// suppression du texte existant
	while(lieu_alert_nok.firstChild != null) {
		lieu_alert_nok.removeChild(lieu_alert_nok.firstChild);
	}
	while(lieu_alert_ok.firstChild != null) {
		lieu_alert_ok.removeChild(lieu_alert_ok.firstChild);
	}
	// creation du message suivant le cas
	if(tmp == chaine_vide) {
		var texte = document.createTextNode("Ce champ ne doit pas &ecirc;tre vide");
		lieu_alert_nok.appendChild(texte);
	}
	else {
		imageok(lieu_alert_ok);
	}
}
function verifPrenomNonVide(arg){
	tmp = arg.value;
	lieu_alert_ok = document.getElementById('prenom_alert_ok');//spanalert.value;
	lieu_alert_nok = document.getElementById('prenom_alert_nok');//spanalert.value;
	
	var chaine_vide = '';
	// suppression du texte existant
	while(lieu_alert_nok.firstChild != null) {
		lieu_alert_nok.removeChild(lieu_alert_nok.firstChild);
	}
	while(lieu_alert_ok.firstChild != null) {
		lieu_alert_ok.removeChild(lieu_alert_ok.firstChild);
	}
	// creation du message suivant le cas
	if(tmp == chaine_vide) {
		var texte = document.createTextNode("Ce champ ne doit pas &ecirc;tre vide");
		lieu_alert_nok.appendChild(texte);
	}
	else {
		imageok(lieu_alert_ok);
	}
}
function verifNomNonVide(arg){
	tmp = arg.value;
	lieu_alert_ok = document.getElementById('nom_alert_ok');//spanalert.value;
	
	var chaine_vide = '';
	// suppression du texte existant
	while(lieu_alert_ok.firstChild != null) {
		lieu_alert_ok.removeChild(lieu_alert_ok.firstChild);
	}
	imageok(lieu_alert_ok);
}
function imageok(element)
{
		var image = document.createElement("img");
		var source = document.createAttribute("src");
     	source.nodeValue = "../includes/img/icones/icone_ok.png";
		var taille = document.createAttribute("width");
     	taille.nodeValue = "24";
		image.setAttributeNode(source);
		image.setAttributeNode(taille);
		element.appendChild(image);
}