/*
OUVERTURE DU BLOCK DIV - SUITE A CLIQUE SUR + 
ET FERMETURE DU BLOCK +
*/
function ouvrir_1div(id)
{
	Element.show(id);
}
/*
FERMETURE DU BLOCK -
*/
function fermer_1div(id)
{

	Element.hide(id);
}

function toggle_div(id1, id2, id3)
{
	Element.hide(id1);
	Element.hide(id2);
	Element.show(id3);
}
/*
INITIALISATION DES BLOCK DIV
*/
function init()
{
	Element.show('box1');
	Element.show('box3');
	Element.show('box5');
	Element.hide('box2');
	Element.hide('box4');
	Element.hide('box6');
}
/*
OUVERTURE DU BLOCK DIV - SUITE A CLIQUE SUR + 
ET FERMETURE DU BLOCK +
*/
function ouvrir_div(id,id2)
{
	Element.show(id);
	Element.hide(id2);
}
/*
FERMETURE DU BLOCK -
*/
function fermer_div(id,id2)
{
	Element.show(id2);
	Element.hide(id);
}
function ouvrirformulairespon(spon)
{
	
	ms.open();
	$('spon').value=spon;	
}
/*
FERMETURE DU BLOCK -
*/
function modifiecontenu(i,ref,id,spon)
{
	if((ref!="") & (id!=""))
	{
		eval('m'+i+'.close();');
		ma.open();
		$('refoffre').value=ref;
		$('idoffre').value=id;
		$('spon').value=spon;
	}
	else
	{
		alert("cette annonce n est pas visible");
	}
}
/*
	Verification du formulaire de candidature
	Attention la meme fonciton est appellé que l'on soit 
	en spontanee ou en reponse offre
*/
function verifupload()
{
	var exit =false;
	var exit1 = false;
	var exit2 = false;
	
	exit = verif_input('nomcandidat','texte',true);
	if(exit ==false) exit = verif_input('prenomcandidat','texte',true);
	if(exit ==false) exit = verif_input('emailcandidat','email',true);
	
	/*
		On ne test ce cas que si on est ds une candidature spontanee
	*/
	
	if(exit ==false)
	{
		
		if(document.getElementById('typeposte'))
		{
				exit1 = verif_select('typeposte',false);
		}
		if(document.getElementById('autreposte') )
		{
			exit2 = verif_input('autreposte','texte',false);
		}
		/*
		Divers test pour determiner si les deux listes poste et autre poste sont bien remplis
		*/
		
		if(document.getElementById('autreposte'))
		{
			
			if(document.getElementById('autreposte').style.display == "")
			{
				if((document.getElementById('typeposte').options[document.getElementById('typeposte').selectedIndex].value  == 0 
					|| document.getElementById('typeposte').options[document.getElementById('typeposte').selectedIndex].value  == -1) 
					 & exit2==true)
				{
					exit = true;
					verif_input('autreposte','texte',true);
				}
			}
			else
			{
				if(exit1 == true)
				{
					exit = true;
					verif_select('typeposte',true);
				}
			}
		}
		else
		{
		
			if(exit1 == true)
			{
				exit = true;
				verif_select('typeposte',true);
			}
		}
		
	}
	if(exit ==false) exit = verif_input('fichiercv','texte',true);
	if(exit ==false) exit = verif_input('fichierlettre','texte',true);
	if(exit ==false) document.getElementById('uplaod').submit();
}

/*
	FONCTION AJAX POUR LES LISTE DEROULANTES DES PAYS REGION ...
	nomselect nom de la lsite deroulante
	parm2 id a mettre a jour 
*/
function getSelect(initurl,nomselect,parm2)
{
	if(document.getElementById(nomselect).options[document.getElementById(nomselect).selectedIndex].value!=0)
	{
		
		
		document.getElementById('spinner').style.display = "";
		var url = "";
		url = initurl+'?recherche='+parm2+'&id='+document.getElementById(nomselect).options[document.getElementById(nomselect).selectedIndex].value;

		var opt = {
			// Use POST
			method: 'get',
			// Handle successful response
			onSuccess: function() {
			   document.getElementById(parm2).style.display = "";
			   document.getElementById(parm2+"td").style.display = "";
			   document.getElementById('spinner').style.display = "none";
				}
		}
		new Ajax.Updater($(parm2),url,opt);
		
		
	}
	else
	{
		if(nomselect == 'pays')
		{
				var url = "";
				url = initurl+'?recherche=pays&id=0';
		
				var opt = {
					// Use POST
					method: 'get',
					// Handle successful response
					onSuccess: function() {
					   document.getElementById('pays').style.display = "";
					   document.getElementById('paystd').style.display = "";
					   document.getElementById('spinner').style.display = "none";
					}
				}
				new Ajax.Updater($('pays'),url,opt);
		}
	}

}
/*
	Sprecifique pour les postes 
	Si on saisi un nouveau type de poste on remet a zero la liste deroulante
*/
function init_select()
{
	if(document.getElementById('autreposte').value != "")
	{
		document.getElementById('typeposte').selectedIndex = 0;
		document.getElementById('typeposte').options[document.getElementById('typeposte').selectedIndex].value = 0;
	}
}
/*
	Sprecifique pour les postes 
	Remet a zero la zone autre poste si on selectionne
	un element de la liste
*/
function init_input()
{

	if(document.getElementById('typeposte') && document.getElementById('autreposte'))
	{
		if(document.getElementById('typeposte').options[document.getElementById('typeposte').selectedIndex].value  != -1)
		{
			document.getElementById('autreposte').style.display = "none";
			document.getElementById('tdautre').style.display = "none";
			document.getElementById('errorautreposte').style.display = "none";
			document.getElementById('errortypeposte').style.display = "none";
			
			
		}
		else
		{
			document.getElementById('autreposte').style.display = "";
			document.getElementById('tdautre').style.display = "";
			document.getElementById('errorautreposte').style.display = "none";
			document.getElementById('errortypeposte').style.display = "none";
		}
	}
}

function verifchamp(id)
{
	if(id.value == "")
	{
		this.style.background='red';
	}
}
/* 
	JAVASCRIPT POUR VERIFIER SELECT AJAX 
	Verification des valeurs envoyées
*/
function verif_select(id,bloquant)
{
	if(document.getElementById(id))
	{

		if(document.getElementById(id).length >0)
		{
			if(document.getElementById(id).options[document.getElementById(id).selectedIndex].value== "0") 
			{
				if(bloquant==true)
				{
					document.getElementById(id).style.background = 'red';
					document.getElementById('error'+id).style.display = '';
				}
				return  true;
			}
			else
			{
				document.getElementById(id).style.background = 'white';
				if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = 'none';
				return false;
				
			}
		}
		else
		{
			if(bloquant==true)
			{
				document.getElementById(id).style.background = 'red';
				if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = '';
			}
			return  true;
		}
	}
	else
	{
		if(bloquant==true & document.getElementById(id))
		{
			document.getElementById(id).style.background = 'red';
			if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = '';
		}
		return  true;
	}
}
function initcouleur(id)
{
	document.getElementById(id).style.background = 'white';
}
function Verif_Date(d){ 
 
	// Cette fonction permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
	// Par Romuald
	
	if (d == "") // si la variable est vide on retourne faux
		return false;
	
	e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
	
	if (!e.test(d)) // On teste l'expression régulière pour valider la forme de la date
		return false; // Si pas bon, retourne faux
	// On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
	j = parseInt(d.split("/")[0], 10); // jour
	m = parseInt(d.split("/")[1], 10); // mois
	a = parseInt(d.split("/")[2], 10); // année
	// Si l'année n'est composée que de 2 chiffres on complète automatiquement
	if (a < 1000) {
		if (a < 89)	a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
		else a+=1900;
	}
	// Définition du dernier jour de février
	// Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
	else fev = 28;
	// Nombre de jours pour chaque mois
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
	// Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
	return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );

 } 
 
function verif_email(s)
{
    if (window.RegExp)
	{
        var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
        var proto   = "(mailto:)?";
        var usr     = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
        var domain  = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
        var reg2str = "^" + proto + "?" + usr + "\@" + domain + "$";
        var reg1    = new RegExp(reg1str);
        var reg2    = new RegExp(reg2str);
        return !reg1.test(s) && reg2.test(s);
    }
	else
	{
        return str.indexOf("@") >= 0;
    }
}
/* 
	JAVASCRIPT POUR VERIFIER CHAMP FORMULAIRE
	Verification des valeurs envoyées
*/
function verif_xinha(value,id,texte)
{
		
	
	if(value  =="")
	{
			if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = '';
			return true;
	}
	else
	{
			if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = 'none';
			return false;
	}
	
	
	
}
/* 
	JAVASCRIPT POUR VERIFIER CHAMP FORMULAIRE
	Verification des valeurs envoyées
*/
function verif_input(id,type,bloquant)
{
	
	
	if(document.getElementById(id).value == "")
	{
		if(bloquant==true) 
		{
			document.getElementById(id).style.background = 'red';
			if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = '';
		
		}
		return true;
	}
	else
	{
		switch(type)
		{
			case 'email':
			  if(verif_email(document.getElementById(id).value)==false)
			  {
				 	if(bloquant==true) 
					{
						document.getElementById(id).style.background = 'red';
						if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = '';
					
					}
				  	return true;
			  }
			  else
			  {
				  document.getElementById(id).style.background = 'white';
				  if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = 'none';
				  return false;
				 
			  }

			break;
			case 'texte':
				 document.getElementById(id).style.background = 'white';
				 if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = 'none';
			 	return false;
			break;
		
			case 'date':
				if(Verif_Date(document.getElementById(id).value)==true)
				{
					 document.getElementById(id).style.background = 'white';
					 if(document.getElementById('error'+id)) document.getElementById('error'+id).style.display = 'none';
					 return false;
				}
				else
				{
				
					if(bloquant==true) 
					{
						document.getElementById(id).style.background = 'red';
						if(document.getElementById('error'+id))document.getElementById('error'+id).style.display = '';
					
					}
					return true;
				}
				break;
		}
	}
}