var rmail=/^[a-zA-Z0-9][a-zA-Z0-9\-_\.]*[a-zA-Z0-9]@[0-9a-zA-Z\-\.]{1,}[0-9a-zA-Z](\.[a-zA-Z]{2,7}){1,2}$/g;
var rdate = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/g;

Event.observe(window, "load", init);

function init(e)
{
	if($("FormRecherche"))
	{
		Event.observe($("FormRecherche"), "submit", verifFormRecherche);
	}
	
	if($("FormContact"))
	{
		Event.observe($("FormContact"), "submit", verifFormContact);
	}
	
	if($("FormRecrutement"))
	{
		Event.observe($("FormRecrutement"), "submit", verifFormRecrutement);
	}
	
	if($("FormFormation"))
	{
		Event.observe($("FormFormation"), "submit", verifFormFormation);
	}
}

function verifFormRecherche(e)
{

	var recherche = document.getElementById("mot");	
	if (recherche.value == '' || recherche.value.length <= 2)
	{
		recherche.focus();
		alert("Votre recherche n'est pas assez pertinente, veuillez préciser votre recherche.");
		Event.stop(e);
	}
}

function verifFormContact(e)
{
	var nom = document.getElementById("contact[nom_contact]");
	var prenom = document.getElementById("contact[prenom_contact]");
	var societe = document.getElementById("contact[societe_contact]");;
	var email = document.getElementById("contact[email_contact]");
		
	
	if (nom.value == '')
	{
		nom.focus();
		alert("Le champ nom est obligatoire.");
		Event.stop(e);
	}
	if (prenom.value == '')
	{
		prenom.focus();
		alert("Le champ prénom est obligatoire.");
		Event.stop(e);
	}
	if (societe.value == '')
	{
		societe.focus();
		alert("Le champ société est obligatoire.");
		Event.stop(e);
	}
	if (email.value == '')
	{
		email.focus();
		alert("Le champ email est obligatoire.");
		Event.stop(e);
	}
	email_value = email.value;
	if (!email_value.match(rmail))
	{
		email.focus();
		alert("Le champ email n'est pas valide.");
		Event.stop(e);
	}
}

function verifFormFormation(e)
{
	var nom = document.getElementById("formation[nom_inscription]");
	var prenom = document.getElementById("formation[prenom_inscription]");
	var societe = document.getElementById("formation[societe_inscription]");;
	var email = document.getElementById("formation[email_inscription]");
		
	
	if (nom.value == '')
	{
		nom.focus();
		alert("Le champ nom est obligatoire.");
		Event.stop(e);
	}
	if (prenom.value == '')
	{
		prenom.focus();
		alert("Le champ prénom est obligatoire.");
		Event.stop(e);
	}
	if (societe.value == '')
	{
		societe.focus();
		alert("Le champ date société est obligatoire.");
		Event.stop(e);
	}
	if (email.value == '')
	{
		email.focus();
		alert("Le champ email est obligatoire.");
		Event.stop(e);
	}
	email_value = email.value;
	if (!email_value.match(rmail))
	{
		email.focus();
		alert("Le champ email n'est pas valide.");
		Event.stop(e);
	}
}


function verifFormRecrutement(e)
{	
	var nom = document.getElementById("recrutement[nom_recrutement_reponse]");
	var prenom = document.getElementById("recrutement[prenom_recrutement_reponse]");
	var email = document.getElementById("recrutement[email_recrutement_reponse]");
	var tel = document.getElementById("recrutement[tel_recrutement_reponse]");
	var cv = document.getElementById("recrutement[cv_recrutement_reponse]");
	var lm = document.getElementById("recrutement[lm_recrutement_reponse]");
		
	
	if (nom.value == '')
	{
		nom.focus();
		alert("Le champ nom est obligatoire.");
		Event.stop(e);
	}
	if (prenom.value == '')
	{
		prenom.focus();
		alert("Le champ prénom est obligatoire.");
		Event.stop(e);
	}
	if (email.value == '')
	{
		email.focus();
		alert("Le champ email est obligatoire.");
		Event.stop(e);
	}
	email_value = email.value;
	if (!email_value.match(rmail))
	{
		email.focus();
		alert("Le champ email n'est pas valide.");
		Event.stop(e);
	}
	if (tel.value == '')
	{
		tel.focus();
		alert("Le champ téléphone est obligatoire.");
		Event.stop(e);
	}
	if (cv.value == '')
	{
		cv.focus();
		alert("Le champ CV est obligatoire.");
		Event.stop(e);
	}
	if (lm.value == '')
	{
		lm.focus();
		alert("Le champ LM est obligatoire.");
		Event.stop(e);
	}
}
