function surligne(champ, erreur) {
	if (erreur) {
		champ.style.backgroundColor = "#fba";
		document.getElementById('verif_contact').style.display = "block";
	}
	else {
		champ.style.backgroundColor = "";
		document.getElementById('verif_contact').style.display = "";
	}
}

function verifnom_contact (champ) {
	var regex = /^[a-zA-Z-\s]{2,25}$/;
	if (!regex.test(champ.value)) {
		surligne (champ, true);
		return false;
	}
	else {
		surligne (champ, false);
		return true;
	}
}
		
					
function verifmail_contact (champ) {
	var regex = /^[a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/;
	if (!regex.test(champ.value)) {
		surligne (champ, true);
		return false;
	}
	else {
		surligne (champ, false);
		return true;
	}
}

function veriftel_contact (champ) {
	var regex = /^(0[1-8])(?:[ _.-]?(\d{2})){4}$/;
	if (!regex.test(champ.value)) {
		surligne (champ, true);
		return false;
	}
	else {
		surligne (champ, false);
		return true;
	}
}

function verifdpt_contact (champ) {
	var regex = /^[0-9]{1,3}$/;
	if (!regex.test(champ.value)) {
		surligne (champ, true);
		return false;
	}
	else {
		surligne (champ, false);
		return true;
	}
}


function veriform_contact (f) {
	var nomOk = verifnom_contact (f.nom_contact);
	var prenomOk = verifnom_contact (f.prenom_contact);
	var mailOk = verifmail_contact (f.mail_contact);
	var telOk = veriftel_contact (f.tel_contact);
	var dptOk = verifdpt_contact (f.dpt_contact);
	
	if (nomOk && prenomOk && mailOk && telOk && dptOk)
		return true;
	else {
		document.getElementById('verif_contact').style.display = "block";
		return false;
	}
}

