/////////////////////////////////     Fonnction de vérification de formulaire        ///////////////////////////////////
var verification=true;

function creer() {
	verification=true;
	verificationDeChamp(document.creation.nom, "nom");
	verificationDeChamp(document.creation.prenom, "prenom");
	verificationDeChampMail(document.creation.mail, "mail");
	verificationDeChamp(document.creation.adresse, "adresse");
	verificationDeChamp(document.creation.ville, "ville");
	verificationDeChamp(document.creation.nom, "nom");
	verificationDeChamp(document.creation.cp, "code postale");
	finVerif();
	return verification;
}

function verifMessage() {
	verification=true;
	verificationDeChamp(document.contacte.nom, "nom");
	verificationDeChamp(document.contacte.prenom, "prenom");
	verificationDeChampMail(document.contacte.email, "mail");
	verificationDeChamp(document.contacte.message, "message");
	verificationDeChamp(document.contacte.code, "code");
	finVerif();
	return verification;
}
function verifInfo() {
	verification=true;
	verificationDeChamp(document.nouvInfo.nom, "nom");
	verificationDeChamp(document.nouvInfo.prenom, "prenom");
	verificationDeChampMail(document.nouvInfo.mail, "mail");
	verificationDeChamp(document.nouvInfo.adresse, "message");
	verificationDeChamp(document.nouvInfo.cp, "code");
	verificationDeChamp(document.nouvInfo.ville, "ville");
	verificationDeChamp(document.nouvInfo.pays, "pays");
	verificationDeChamp(document.nouvInfo.tel, "telephone");
	finVerif();
	return verification;
}

function vrerifPass() {
	verification=true;
	pass(document.nouvPass.oldPass, "oldPass");
	verificationDeChamp(document.nouvPass.oldPass, "ensien mot de pass");
	verificationDeChamp(document.nouvPass.pass, "nouveau mot de passe");
	finVerif();
	return verification;
}

/////////////////////////////////     Fonnction de vérification spécifique           ///////////////////////////////////

function bonmail(mailteste){
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	if(reg.test(mailteste)) {
		return(true);
	}
	else {
		return(false);
	}
}

var erreur=false;
var verifFini=false;
function afficheErreur(texte) {
	var p = document.getElementById('erreur');
	if (erreur==false) {
	var pChild = p.childNodes;
		if (erreur==false && pChild[0]!=null) {
			var nbChild = pChild.length;
			for (var i=0; i<nbChild; i++) {
				p.removeChild(pChild[0]);
			}
		}
		var text = document.createTextNode("Champ ");
		p.appendChild(text);
		erreur=true;
		var text = document.createTextNode(texte);
		p.appendChild(text);
	}
	else {
		var text = document.createTextNode(", "+texte);
		p.appendChild(text);
	};
}

function finVerif() {
	if (verification == false) {
		var p = document.getElementById('erreur');
		p.appendChild(document.createTextNode(" incomplete."));
	}
	erreur=false;
	verifFini=true;
}

function ajoutPhoto() {
	var p = document.getElementById("photo");
	var a = document.getElementById("modifPhoto");
	p.removeChild(a);
	
	//<input type="file" name="photo" />
	
	var inp = document.createElement("input");
	inp.setAttribute("type", "file");
	inp.setAttribute("id", "inmpPhoto");
	inp.setAttribute("name", "photo");
	
	p.appendChild(inp);
}
function isset (variable) {
  alert (typeof variable != 'undefined');
}

function verificationDeChamp( leChamp, texte) {
	if (leChamp.value == "" || leChamp.value == leChamp.getAttribute("title")) {
		afficheErreur(texte);
		verification=false;
	}
}
function verificationDeChampMail( leChamp, texte) {
	if (leChamp.value == "" || leChamp.value == leChamp.getAttribute("title")) {
		afficheErreur(texte);
		verification=false;
	}
	else if (bonmail(leChamp.value)==false) {
		afficheErreur(texte);
		verification=false;
	}
}


function pass(pass, balise) {
	verification = false;
	
	var data = "pass=" + pass.value;
	creerRequete();
	requete.open("POST","ajax/pass.php", false);
	requete.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	requete.send(data);	
	repPasse(balise);
}
function repPasse(tag) {
	verification = false;
	var rep = requete.responseText;
	
	var oldPasse = document.getElementsByName(tag);
	var parent = oldPasse[0].parentNode;
	if (rep=="false") {
		var texte = document.createTextNode(" - movais mots de passe - ");
		for (var i=3; i<parent.childNodes.length; i++) {
			parent.removeChild(parent.childNodes[i]);
		}
		parent.appendChild(texte);
	}
	else {
		verification = true;
		for (var i=3; i<parent.childNodes.length; i++) {
			parent.removeChild(parent.childNodes[i]);
		}
	}
}

