
function init() {
	// on recupere chaque champ a verifier
	var contact_coiffeur_prenom			= document.getElementById('contact_coiffeur_prenom');
	var contact_coiffeur_nom			= document.getElementById('contact_coiffeur_nom');
//	var contact_coiffeur_tel_fixe		= document.getElementById('contact_coiffeur_tel_fixe');
//	var contact_coiffeur_tel_mobile		= document.getElementById('contact_coiffeur_tel_mobile');
	var contact_coiffeur_ville			= document.getElementById('contact_coiffeur_ville');
	var contact_coiffeur_email			= document.getElementById('contact_coiffeur_email');
	var contact_coiffeur_titre 			= document.getElementById('contact_coiffeur_titre');

	// 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) {
		contact_coiffeur_prenom.onkeyup		 = function() { verifPrenomNonVide(contact_coiffeur_prenom); };
		contact_coiffeur_nom.onkeyup		 = function() { verifNomNonVide(contact_coiffeur_nom); };
//		contact_coiffeur_tel_fixe.onkeyup	 = function() { verifNomNonVide(contact_coiffeur_tel_fixe); };
//		contact_coiffeur_tel_mobile.onkeyup	 = function() { verifNomNonVide(contact_coiffeur_tel_mobile); };
		contact_coiffeur_ville.onkeyup		 = function() { verifVilleNonVide(contact_coiffeur_ville); };
		contact_coiffeur_email.onchange 	 = function() { verifEmail(contact_coiffeur_email); };
		contact_coiffeur_titre.onkeyup  	 = function() { verifTitreNonVide(contact_coiffeur_titre); };
	}
	// pour Firefox
	else {
		contact_coiffeur_prenom.setAttribute('onKeyUp'		, 'verifPrenomNonVide(contact_coiffeur_prenom)');
		contact_coiffeur_nom.setAttribute('onKeyUp'			, 'verifNomNonVide(contact_coiffeur_nom)');
//		contact_coiffeur_tel_fixe.setAttribute('onKeyUp'	, 'verifPrenomNonVide(contact_coiffeur_tel_fixe)');
//		contact_coiffeur_tel_mobile.setAttribute('onKeyUp'	, 'verifNomNonVide(contact_coiffeur_tel_mobile)');
		contact_coiffeur_ville.setAttribute('onKeyUp'		, 'verifVilleNonVide(contact_coiffeur_ville)');
		contact_coiffeur_email.setAttribute('onKeyUp'		, 'verifEmail(contact_coiffeur_email)');
		contact_coiffeur_titre.setAttribute('onKeyUp'		, 'verifTitreNonVide(contact_coiffeur_titre)');
		}
}

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 verifVilleNonVide(arg){
	tmp = arg.value;
	lieu_alert_ok = document.getElementById('ville_alert_ok');//spanalert.value;
	lieu_alert_nok = document.getElementById('ville_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 la ville o&ugrave; vous souhaitez &ecirc;tre coiff&eacute;(e).");
		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 contact_coiffeur");
		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);
}


function verifCP(cp) {
	var XHR = new XHRConnection();
	XHR.appendData("cp", cp.value);
	XHR.sendAndLoad("verifCP.php", "POST", afficheDispo);
}
function afficheDispo(obj) {
	lieu_alert_ok = document.getElementById('cp_alert_ok');
	lieu_alert_nok = document.getElementById('cp_alert_nok');
	
	// suppression du texte existant
	while(lieu_alert_ok.firstChild != null) {
		lieu_alert_ok.removeChild(lieu_alert_ok.firstChild);
	}
	while(lieu_alert_nok.firstChild != null) {
		lieu_alert_nok.removeChild(lieu_alert_nok.firstChild);
	}
	
	// Construction des noeuds
	var tabResult = obj.responseXML.getElementsByTagName('resultat');
	var resultat = tabResult.item(0);
	var dispo = resultat.getAttribute('dispo');
	
	// creation du message suivant le cas
	if (dispo == "true") {
		//var texte = document.createTextNode("Le nom d'utilisateur est disponible");
		//lieu_alert_ok.appendChild(texte);
		imageok(lieu_alert_ok);
	} 
	else {
		if (dispo == "false") {
			var texte = document.createTextNode("Le nom d'utilisateur n'est pas disponible");
			lieu_alert_nok.appendChild(texte);
		}
	}	
//	imageok(lieu_alert_ok);
}

