//Valide le formulaire
function ValidSubmit() {

	//Teste sur le nom
	if(document.forms[0].nom.value.length == 0) {
		alert("Merci de saisir votre nom");
		document.forms[0].nom.focus();
		return false;
	}
	
	//Teste sur l'email
	if(document.forms[0].email.value.length == 0) {
		alert("Merci de saisir votre adresse email");
		document.forms[0].email.focus();
		return false;
	}
	
	if(!verifEmail()) {
		return false;
	}
	
	//Teste sur le message
	if(document.forms[0].message.value.length == 0) {
		alert("Merci de saisir votre message");
		document.forms[0].message.focus();
		return false;
	}
	
	return true;
}


//Test sur le code postal
function verifCP() {
	if( !isNumeric(document.forms[0].cp.value) || (document.forms[0].cp.value.length != 5)) {
		alert('Merci de renseigner votre code postal.\n');
		document.forms[0].cp.focus();
		return false;		
	}
	return true;
}

//Test sur email
function verifEmail() {
	if( !checkemail(document.forms[0].email.value) ) {
		alert('Votre adresse email est invalide.\nMerci de la corriger.\n');
		document.forms[0].email.focus();
		return false;		
	}
	return true;
}

//Test sur la cnil
function verifCnil() {
	if( document.forms[0].cnil[0].checked == false && document.forms[0].cnil[1].checked == false ) {
		alert('Merci de renseigner votre choix sur la Cnil.')
		return false;		
	}
	return true;
}

//Vérifie si valeur pasée est un mail
function checkemail(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(email))
		return true;
	return false;
}

// Returns true if the string only contains alpha characters (empty string = true)
function isAlpha(txt) {
	return ValidString(txt,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
}

// Returns true if the string only contains numeric characters (empty string = true)
function isNumeric(txt) {
	return ValidString(txt,'0123456789.');
}

// Returns true if the string only contains alpha numeric characters (empty string = true)
function isAlphaNumeric(txt) {
	return ValidString(txt,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
}

function ValidString(ChkString,ValidString) {
	for (i=0; i<ChkString.length; i++) {
		if (ValidString.indexOf(ChkString.substring(i,i+1)) == -1) return false;
	}
	return true;
}