function checkField2(elem){


	if ( elem.value=='' ){
		elem.style.borderColor="red";
		return false;	
	}
	else {
		elem.style.borderColor="green";
		return true;
	}
}

function checkEmail2(elem){


	if ( elem.value==''){
		
		elem.style.borderColor="red";
		
		return false;
	}else{
		var re = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;
		if(!re.test(elem.value)){
			elem.style.borderColor="red";
		
			return false;
		}else{
			elem.style.borderColor="green";
		
			return true;
		}
	}
}
function checkEmail(elem){
	if ( elem.value==''){
		
		elem.style.borderColor="red";
		document.getElementById("label_"+elem.name).style.color = "red";


		return false;
	}else{
		var re = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;
		if(!re.test(elem.value)){
			elem.style.borderColor="red";
		document.getElementById("label_"+elem.name).style.color = "red";

			return false;
		}else{
			elem.style.borderColor="green";
		document.getElementById("label_"+elem.name).style.color = "black";

			return true;
		}
	}
}

function checkRouge(elem){

		elem.style.borderColor="red";
		document.getElementById("label_"+elem.name).style.color = "red";
		
}


function checkField(elem){

	if ( elem.value=='' ){
		elem.style.borderColor="red";
				
		document.getElementById("label_"+elem.name).style.color = "red";
		return false;	
	}
	else {
		elem.style.borderColor="green";
		document.getElementById("label_"+elem.name).style.color = "black";

		return true;
	}
}
function checkEgals(emailconfirm,email){
	if( email.value!=emailconfirm.value || email.value =='' || !checkEmail(email)){
		 emailconfirm.style.borderColor="red";
		 email.style.borderColor="red";
		document.getElementById("label_"+ email.name).style.color = "red";
		document.getElementById("label_"+ emailconfirm.name).style.color = "red";
		return false;
	}
	 else{
		emailconfirm.style.borderColor="green";
		email.style.borderColor="green";
		document.getElementById("label_"+ email.name).style.color = "black";
		document.getElementById("label_"+ emailconfirm.name).style.color = "black";

		return true;

	}

}

function checkDate(elem){
	var re = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
		if(!re.test(elem.value)){
			elem.style.borderColor="red";
		document.getElementById("label_"+elem.name).style.color = "red";
			return false;
		}else{
			elem.style.borderColor="green";
		document.getElementById("label_"+elem.name).style.color = "black";
			return true;
		}
}



function checkPhone(elem){
	var re = /^[0-9]{10}$/;
		if(!re.test(elem.value)){
			elem.style.borderColor="red";
		document.getElementById("label_"+elem.name).style.color = "red";
			return false;
		}else{
			elem.style.borderColor="green";
		document.getElementById("label_"+elem.name).style.color = "black";
			return true;
		}
}
function checkNumerique(elem)	{
	var re = /^[0-9]{5}$/;
	if(!re.test(elem.value)){
		elem.style.borderColor="red";
		document.getElementById("label_"+elem.name).style.color = "red";

		return false;
	}else{
		elem.style.borderColor="green";
		document.getElementById("label_"+elem.name).style.color = "black";

		return true;
	}
}


function checkHeuresSouhaitees2(elem) {
	
	//alert(elem);
	if(document.candidature_spontanee.contratP2[0].checked) {
		elem.style.borderColor="";
		elem.value="";
		document.getElementById("label_"+elem.name).style.color = "";
		return false;
	}
	else {
		return checkNumerique(elem);
	}
	
}


function checkHeuresSouhaitees(elem) {
	
	var re = /^[0-9]{2}$/;
	if(document.candidature_spontanee.contratP2[1].checked && re.test(elem.value)) {
		elem.style.borderColor="green";
		document.getElementById("label_"+elem.name).style.color = "black";
		return true;
	}
	else if(document.candidature_spontanee.contratP2[0].checked) {
		elem.value ="";
		return false;
	}
	else {
		return checkNumerique(elem);
	}
	
}

function checkAlpha(elem)	{
	var re = /^[A-Za-z]+$/;
	if(!re.test(email)){
		elem.style.borderColor="red";
		document.getElementById("label_"+elem.name).style.color = "red";

	}else{
		elem.style.borderColor="green";
		document.getElementById("label_"+elem.name).style.color = "black";

	}
}

function sendMail(items,nomForm) {
	
	var ValidForm = true;
	var tabItem=items.split(',');
	
	for (i=0;i<tabItem.length;i++) {
		if (tabItem[i]=='rechercheP') {
			checkField(document.candidature_spontanee["rechercheP"]);
			if (document.candidature_spontanee[tabItem[i]].selectedIndex==0) {
				ValidForm = false;
			}
		}
		else {
			if(!checkField(document.candidature_spontanee[tabItem[i]])) {
				ValidForm = false;
			}
		}
	}
	if(!checkDate(document.candidature_spontanee["dateP"]))
	ValidForm = false;
	
	
	
	if((!checkHeuresSouhaitees(document.candidature_spontanee["heureP"]) && !document.candidature_spontanee.contratP2[0].checked) || !checkEmail(document.candidature_spontanee["emailP"]) || !checkEgals(document.candidature_spontanee["emailConfP"],document.candidature_spontanee["emailP"]) || !checkNumerique(document.candidature_spontanee["cpP"]) || !checkPhone(document.candidature_spontanee["telP"])) {
		ValidForm = false;
	}
	
	if (!document.candidature_spontanee.dispoP[1].checked && !document.candidature_spontanee.dispoP[0].checked) {
		document.getElementById("label_dispoP").style.color="red";
		ValidForm = false;
	}
	else {
		if (document.candidature_spontanee.dispoP[1].checked && !(document.candidature_spontanee["lundim"].checked || document.candidature_spontanee["mardim"].checked || document.candidature_spontanee["mercredim"].checked || document.candidature_spontanee["jeudim"].checked || document.candidature_spontanee["vendredim"].checked  || document.candidature_spontanee["samedim"].checked || document.candidature_spontanee["lundiapm"].checked || document.candidature_spontanee["mardiapm"].checked || document.candidature_spontanee["mercrediapm"].checked || document.candidature_spontanee["jeudiapm"].checked || document.candidature_spontanee["vendrediapm"].checked  || document.candidature_spontanee["samediapm"].checked   )) {
			document.getElementById("label_dispoP").style.color="red";
			ValidForm = false;
		}
		else {
			document.getElementById("label_dispoP").style.color="#000000";
		}
	}
	
	
	
		
	nom_fichier=document.candidature_spontanee.cvP.value;// on r?cupere le chemin complet du fichier
	nbchar = nom_fichier.length;// on compte le nombre de caractere que compose ce chemin
	extension = nom_fichier.substring(nbchar-4,nbchar); // on r?cupere les 4 derniers caracteres
	extension=extension.toLowerCase(); //on uniforme les caracteres en minuscules au cas ou cela aurait ?t? ?cris en majuscule...
	
	//alert(extension);
	
	if (extension=='.doc' || extension=='docx')  {
		document.candidature_spontanee.cvP.style.borderColor = "green";
	}
	
	else {
		document.candidature_spontanee.cvP.style.borderColor = "red";
		ValidForm = false;
	}
	
	
	
	
	nom_fichier2=document.candidature_spontanee.motivP.value;// on r?cupere le chemin complet du fichier
	nbchar = nom_fichier2.length;// on compte le nombre de caractere que compose ce chemin
	extension2 = nom_fichier2.substring(nbchar-4,nbchar); // on r?cupere les 4 derniers caracteres
	extension2=extension2.toLowerCase(); //on uniforme les caracteres en minuscules au cas ou cela aurait ?t? ?cris en majuscule...
	
	//alert(extension2);
	
	if (extension2=='.doc' || extension2=='docx')  {
		document.candidature_spontanee.motivP.style.borderColor = "green";
	}
	
	else {

		document.candidature_spontanee.motivP.style.borderColor = "red";
		ValidForm = false;
	}
	
	
	
	if(goCapcha('index.php?type=35') == 0)
 	ValidForm = false;
	
	if (ValidForm) {
		document.candidature_spontanee.submit(); 
	}
}




function sendMailBoutique(items,nomForm) {

	var ValidForm = true;
	var tabItem=items.split(',');
		
	for (i=0;i<tabItem.length;i++) {
		if(!checkField(document.candidature_spontanee[tabItem[i]])) {
			ValidForm = false;
		}
	}
	if(!checkEmail(document.candidature_spontanee["emailP"]) || !checkEmail(document.candidature_spontanee["emailConfP"]) || !checkEgals(document.candidature_spontanee["emailConfP"],document.candidature_spontanee["emailP"])) {
		ValidForm = false;
	}

	if(goCapcha('index.php?type=35') == 0)
 	ValidForm = false;
	
	
	if (ValidForm) {
		document.candidature_spontanee.submit(); 
	}
	

	
	
	
}

function sendMailReponseOffre(items,nomForm) {
	var ValidForm = true;
	var tabItem=items.split(',');
		
	for (i=0;i<tabItem.length;i++) {
		if(!checkField(document.reponse_offre[tabItem[i]])) {
			ValidForm = false;
		}
	}
	if(!checkEmail(document.reponse_offre["emailP"]) || !checkEmail(document.reponse_offre["emailConfP"]) || !checkEgals(document.reponse_offre["emailConfP"],document.reponse_offre["emailP"]) || !checkNumerique(document.reponse_offre["cpP"]) || !checkPhone(document.reponse_offre["telP"])) {
		ValidForm = false;
	}
	
	if(goCapcha('index.php?type=35') == 0)
 	ValidForm = false;
	
	if (ValidForm) {
		document.reponse_offre.submit(); 
	}
}

function sendMailContactPresse(items,nomForm) {
	var ValidForm = true;
	var tabItem=items.split(',');
		
	for (i=0;i<tabItem.length;i++) {
		if(!checkField(document.contact_presse[tabItem[i]])) {
			ValidForm = false;
		}
	}
	if(!checkEmail(document.contact_presse["emailP"]) || !checkEgals(document.contact_presse["emailConfP"],document.contact_presse["emailP"])) {
		ValidForm = false;
	}
	
	if(goCapcha('index.php?type=35') == 0)
 	ValidForm = false;
	
	if (ValidForm) {
		document.contact_presse.submit(); 
	}
}




function testOption(items,form)
{

	var tabItem=items.split(',');
		
		options = document[form].themeP.options;
		
		
	for (i=0;i<tabItem.length;i++) {
		
		options[tabItem[i]].style.display="block";
		
	}
	
}




function cacherOption(items,form)
{
	
	
	var tabItem=items.split(',');
	options = document[form].themeP.options;	
	
		//alert(document[form].themeP.selectedIndex);
		
	for (i=0;i<tabItem.length;i++) {		
		options[tabItem[i]].style.display="none";
	}
}



function BackLayer(id, largeur) {	
		// La popUp avec le contenu


		dom = document.getElementById && !document.all;
		// La hauteur du fond transparent
	/*	if (document.documentElement.clientHeight >= document.body.offsetHeight ) {	
		hy = document.documentElement.clientHeight; 
		} else { 
		hy = document.body.offsetHeight; 
		}

		if (hy >= document.getElementById(id).offsetHeight + py + py) {
		hyFinal = hy;
		} else {
		hyFinal = document.getElementById(id).offsetHeight + py + py;
		}
*/		

	 	
		
		
		py = 100;
		px = Math.floor(largeur / 2); 
		document.getElementById(id).style.top = py + 'px'; 
		document.getElementById(id).style.marginLeft = '-'+ px + 'px';	
		document.getElementById(id).style.display = "block";

		
		
		window.scrollTo(0,0);
		
}

function BackLayer(id, largeur, offres , metier) {	
		// La popUp avec le contenu


		dom = document.getElementById && !document.all;
		// La hauteur du fond transparent

	 	
		document.getElementById('link').value = "informations/bhv-recrute/nos-offres-demploi.html?metier"+metier+"&"+offres;
		
		py = 100;
		px = Math.floor(largeur / 2); 
		document.getElementById(id).style.top = py + 'px'; 
		document.getElementById(id).style.marginLeft = '-'+ px + 'px';	
		document.getElementById(id).style.display = "block";

		
		
		window.scrollTo(0,0);
	 	
		


		
		
		
}






function MontreLayer(id, largeur) {	
		// La popUp avec le contenu

		dom = document.getElementById && !document.all;
		// La hauteur du fond transparent
	/*	if (document.documentElement.clientHeight >= document.body.offsetHeight ) {	
		hy = document.documentElement.clientHeight; 
		} else { 
		hy = document.body.offsetHeight; 
		}

		if (hy >= document.getElementById(id).offsetHeight + py + py) {
		hyFinal = hy;
		} else {
		hyFinal = document.getElementById(id).offsetHeight + py + py;
		}
*/		
		//document.getElementById('fondForm').style.display = "block";

	 	
		
		
		py = 100;
		px = Math.floor(largeur / 2); 
		document.getElementById(id).style.top = py + 'px'; 
		//document.getElementById(id).style.marginLeft = '-'+ px + 'px';	
		document.getElementById(id).style.display = "block";
		
		//voirSelect('hidden','sujetP');
		//voirSelect('hidden','themeP');
		
		
		window.scrollTo(0,0);
		
}



function MontreLayer_presse(id, largeur) {	
		// La popUp avec le contenu

		dom = document.getElementById && !document.all;
		// La hauteur du fond transparent
	/*	if (document.documentElement.clientHeight >= document.body.offsetHeight ) {	
		hy = document.documentElement.clientHeight; 
		} else { 
		hy = document.body.offsetHeight; 
		}

		if (hy >= document.getElementById(id).offsetHeight + py + py) {
		hyFinal = hy;
		} else {
		hyFinal = document.getElementById(id).offsetHeight + py + py;
		}
*/		
		//document.getElementById('fondForm').style.display = "block";

	 	
		
		
		py = 100;
		px = 250; 
		document.getElementById(id).style.top = py + 'px'; 
		document.getElementById(id).style.marginLeft = '-'+ px + 'px';	
		document.getElementById(id).style.display = "block";
		
		//voirSelect('hidden','sujetP');
		//voirSelect('hidden','themeP');
		
		
		window.scrollTo(0,0);
		
}


function MontreLayer2(id, largeur) {	
		// La popUp avec le contenu

		dom = document.getElementById && !document.all;
		// La hauteur du fond transparent
	/*	if (document.documentElement.clientHeight >= document.body.offsetHeight ) {	
		hy = document.documentElement.clientHeight; 
		} else { 
		hy = document.body.offsetHeight; 
		}

		if (hy >= document.getElementById(id).offsetHeight + py + py) {
		hyFinal = hy;
		} else {
		hyFinal = document.getElementById(id).offsetHeight + py + py;
		}
*/		
		//document.getElementById('fondForm').style.display = "block";

	 	
		
		
		py = 100;
		px = Math.floor(largeur / 2); 
		document.getElementById(id).style.top = py + 'px'; 
		document.getElementById(id).style.marginLeft = '-'+ px + 'px';	
		document.getElementById(id).style.display = "block";
		
		//voirSelect('hidden','sujetP');
		//voirSelect('hidden','themeP');
		
		
		window.scrollTo(0,0);
		
}

function cacheCenterPopUp_tipafriend(id) {
    // La popUp avec le contenu
    document.getElementById(id).style.display = "none";
    // Le fond transparent

    
}


var receiveReq = getXmlHttpRequestObject();

function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}





//Initiate the AJAX request
function makeRequest(url, param) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   receiveReq.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq.onreadystatechange = updatePage; 

   //Add HTTP headers to the request
   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   //Make the request
   receiveReq.send(param);
 }   
}





//Called every time our XmlHttpRequest objects state changes
function updatePage() {
 //Check if our response is ready
 if (receiveReq.readyState == 4) {
   //Set the content of the DIV element with the response text
 //  document.getElementById('result').innerHTML = receiveReq.responseText;
   
//alert(receiveReq.responseText);
//Get a reference to CAPTCHA image
 //  img = document.getElementById('imgCaptcha'); 
   //Change the image
  // img.src = 'create_image.php?' + Math.random();
 }
}



//Called every time when form is perfomed
function getParam(theForm,varLink) {
 //Set the URL
 var url = varLink;
 //Set up the parameters of our AJAX call
 var postStr = theForm.captchaP.name + "=" + encodeURIComponent( theForm.captchaP.value );
 //Call the function that initiate the AJAX request
 makeRequest(url, postStr);
}



function getXhr(){
  var xhr = null; 
	if(window.XMLHttpRequest)       // Pour Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){  // Pour Internet Explorer 
	   try { 
     xhr = new ActiveXObject("Msxml2.XMLHTTP"); } 
     catch (e) { 
      xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	else { // XMLHttpRequest non support� par le navigateur utilis�
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
  return xhr;
}

/* M�thode qui sera appel�e sur le click du select prenom */
var LINK="";
var ETAT=0;



/*
function goThemP(link,idPage){
	// ce IF permet de ne pas bloquer le select "SURNOM" lorsqu'on a effectué un choix sur chaque select
	var xhr = getXhr();
  	// On défini ce qu'on va faire quand on aura la réponse à l'aide d'une fonction 'anonyme'
  	xhr.onreadystatechange = function(){
  		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
  		if(xhr.readyState == 4 && xhr.status == 200){
  			leselect = xhr.responseText;
  			// On se sert de innerHTML pour rajouter les options a la liste
  			document.getElementById('AjaxTheme').innerHTML = leselect;
  		}
	}
	// Ici on envoi la requete en post au fichier "http1.php"
  	xhr.open("POST",link,true);
  	// ne pas oublier le header pour le post
  	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	// enfin, on post les arguments, ici l'id de l'auteur
  	sel = document.getElementById('sujetP');
  	id_prenom = sel.options[sel.selectedIndex].value;
  	xhr.send("SujetP="+id_prenom+"&Id="+idPage);
}
*/
/*function goThemP(idsujet){

	//document.getElementById('themeP').innerHTML=document.getElementById('theme_sujet_'+idsujet).innerHTML;
	
	var tab = document.getElementById('theme_sujet_'+idsujet).innerHTML.split('||');
	
	for(var i=0; i < tab.length; i++) {
			if(tab[i] != '') {
			document.getElementById('themeP').options[i] = new Option(tab[i],tab[i]);
			}
		}
	
	
	
}*/




function goCapcha(link){
  // ce IF permet de ne pas bloquer le select "SURNOM" lorsqu'on a effectu� un choix sur chaque select
    LINK=link;
 
//alert(LINK);
var elem = document.getElementById('captchaP');
	var xhr = getXhr();
  	// On d�fini ce qu'on va faire quand on aura la r�ponse � l'aide d'une fonction 'anonyme'
  	xhr.onreadystatechange = function(){
  		// On ne fait quelque chose que si on a tout re�u et que le serveur est ok
  		if(xhr.readyState == 4 && xhr.status == 200){
  			var leselect = xhr.responseText;
			var resultat= leselect.split('<');
			var res2 = resultat[0].split('&');
			
			var borde=res2[1];	
			var lab=res2[0];
  			// On se sert de innerHTML pour rajouter les options a la liste
  		//	document.getElementById('AjaxTheme').innerHTML = leselect;
				if(borde.indexOf('green') != -1)
					ETAT=1;
				else
					ETAT=0;
					
					
					elem.style.borderColor=borde;
					if(lab.indexOf('black') != -1)
					document.getElementById("label_captchaP").style.color = "black";
					else
					document.getElementById("label_captchaP").style.color = "red";

	
			

  		}
}

   	// Ici on envoi la requete en post au fichier "http1.php"
  	// ne pas oublier le header pour le post
  	// enfin, on post les arguments, ici l'id de l'auteur
  	  xhr.open("POST",link,false);  	
  	
  	sel = document.getElementById('captchaP');
  	capchaNum = sel.value;
  	 xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	xhr.send("capchaNum="+capchaNum);
  	
  	
  	  	var leselect = xhr.responseText;
			var resultat= leselect.split('<');
			var res2 = resultat[0].split('&');
			
			var borde=res2[1];	
			var lab=res2[0];
  			// On se sert de innerHTML pour rajouter les options a la liste
  		//	document.getElementById('AjaxTheme').innerHTML = leselect;
				if(borde.indexOf('green') != -1)
					ETAT=1;
				else
					ETAT=0;
					
					
					elem.style.borderColor=borde;
					if(lab.indexOf('black') != -1)
					document.getElementById("label_captchaP").style.color = "black";
					else
					document.getElementById("label_captchaP").style.color = "red";

  	
  	return ETAT;
  	

}


function societe(isSociete){
	if(isSociete){
		document.getElementById('label_nomP').innerHTML='Soci&eacute;t&eacute;* :';
		document.getElementById('label_prenomP').innerHTML='Nom du contact* :';
	}
	else{
		document.getElementById('label_nomP').innerHTML='Nom* :';
		document.getElementById('label_prenomP').innerHTML='Pr&eacute;nom* :';
	}
}

function miseEnPageMSG(msgArea){
document.getElementById('text').value=msgArea.replace(/\n/g, "<br/>");
}



