//---------------------------------
// Validation des numéros de téléphones
//---------------------------------
function check_form_telephone (champ){
	
	//window.alert("bob "+champ);
	// Initialisation des variables
	var contenu = document.getElementById( "formcontact_"+champ ).value;
	
	var form = document.getElementById( "formcontact_"+champ );
	var zone = document.getElementById( "zone_"+champ );
	var image_validation = document.getElementById( "img_"+champ );
	
	if (contenu.search(/^[0-9-.+ ]*$/) != -1 && contenu != ""){
		// Formulaire valide
		//document.getElementById( 'formcontact_utilisateur_telephone' ).style.background-image = url('/skins/img/formulaire/form_valide.gif');
		//form.style.background = '#A8C1E9 url( "/img/formulaire/form_valide.gif" ) no-repeat right center';
		form.style.background = '#FFF';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_valide.gif';
	} else {
		form.style.background = '#FCC';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_invalide.gif';
	}
}
//---------------------------------
// Validation de champ Alpha
//---------------------------------
function check_form_alpha (champ){

	//window.alert("bob "+champ);
	// Initialisation des variables
	var contenu = document.getElementById( "formcontact_"+champ ).value;
	
	var form = document.getElementById( "formcontact_"+champ );
	var zone = document.getElementById( "zone_"+champ );
	var image_validation = document.getElementById( "img_"+champ );
	
	if (contenu.search(/^[a-zA-Z- éèçà]*$/) != -1
		&& contenu != ""
		&& contenu.length >= 2 ){
			
		// Formulaire valide
		form.style.background = '#FFF'; 
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_valide.gif';
	} else {
		form.style.background = '#FCC';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_invalide.gif';
	}
}

//---------------------------------
// Validation de champ Alpha et num
//---------------------------------
function check_form_alpha_num (champ){

	//window.alert("bob "+champ);
	// Initialisation des variables
	var contenu = document.getElementById( "formcontact_"+champ ).value;
	
	var form = document.getElementById( "formcontact_"+champ );
	var zone = document.getElementById( "zone_"+champ );
	var image_validation = document.getElementById( "img_"+champ );
	
	if (contenu.search(/^[\'éèàça-zA-Z- 0-9]*$/) != -1
		&& contenu != ""
		&& contenu.length >= 2 ){
			
		// Formulaire valide
		form.style.background = '#FFF';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_valide.gif';
	} else {
		form.style.background = '#FCC';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_invalide.gif';
	}
}

//---------------------------------
// Validation d'une adresse mail
//---------------------------------
function check_form_email (champ){
	
	// Initialisation des variables
	var contenu = document.getElementById( "formcontact_"+champ ).value;
	
	var form = document.getElementById( "formcontact_"+champ );
	var zone = document.getElementById( "zone_"+champ );
	var image_validation = document.getElementById( "img_"+champ );
	
//  nouveau test sur email
//	if (contenu.search(/^[éèça-zA-Z- 0-9@.]*$/) != -1
	if (contenu.search(/^.+@.+\..+$/) != -1
		&& contenu != ""
		&& contenu.length >= 2 ){
			
		// Formulaire valide
		form.style.background = '#FFF';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_valide.gif';
	} else {
		form.style.background = '#FCC';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_invalide.gif';
	}
}

//---------------------------------
// Validation de champ date
//---------------------------------
function check_form_date (champ){

	// Initialisation des variables
	var contenu = document.getElementById( "formcontact_"+champ ).value;
	
	var form = document.getElementById( "formcontact_"+champ );
	var zone = document.getElementById( "zone_"+champ );
	var image_validation = document.getElementById( "img_"+champ );
	
	if (contenu.match(/^(\d{1,2}\/){2}\d{4}$/)){
		// Formulaire valide
		form.style.background = '#FFF';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_valide.gif';
	} else {
		form.style.background = '#FCC';
		form.style.color='#111111';
		image_validation.src = '/img/formulaire/form_invalide.gif';
	}
}
//---------------------------------
// Vide le champ lors d'un clic
//---------------------------------
function clear_form (champ, defaut){

	if (document.getElementById( champ ).value == defaut){
		document.getElementById( champ ).value = "";
	} else if (document.getElementById( champ ).value.length==0){
		document.getElementById( champ ).value = defaut;
	}

}

//---------------------------------
// Validation du form recherche (Department)
//---------------------------------

//idHidden -> id de la div caché

function check_form_dep(idHidden, idInput) {
	if (document.getElementById(idInput).value == 0) {
			document.getElementById(idHidden).style.display = 'block';
		return false;
	}
	return true;
}

function check_form_dep2(idInput) {
	if (document.getElementById(idInput).value == 0) {
			alert('Veuillez chosir un département');
		return false;
	}
	return true;
}