/* ----- Racourci ----- */
function get(e){
	return document.getElementById(e);
}

/* ----- Popup image Zone admin ----- */
function popupCentre(source,largeur,hauteur){
  var x=(screen.width-largeur)/2;
  var y=(screen.height-hauteur)/2;
  window.open(source,'','top='+y+',left='+x+',width='+largeur+',height='+hauteur+',location=no,status=no,scrollbars=no');
}

/* ----- Deplacement d'une div dans une autre horizontalement ----- */
function move(direction,num,max,divid,leftarrowid,rightarrowid,decalage){
	var left = get(divid).style.left;
	var longueur = left.length - 2; 
	if (direction == 'droite'){
		if (num < (max-1)){
			get(divid).style.left = parseFloat(left.substring(0,longueur)) - decalage + 'px';
			get(leftarrowid).style.visibility = 'visible';
			if (num == (max-4)){
				get(rightarrowid).style.visibility = 'hidden';
			}
			return (num+1);
		}
	}
	if (direction == 'gauche'){
		if (num > 0){
			get(divid).style.left = parseFloat(left.substring(0,longueur)) + decalage + 'px';
			get(rightarrowid).style.visibility = 'visible';
			if (num == 1){
				get(leftarrowid).style.visibility = 'hidden';
			}
			return (num-1);
		}
	}
	return num;
}

/* --------------------- DIAPORAMA --------------------- */
function lancetiming(ms){
	try{
		timing(ms,images);
	}
	catch(e){
		// On arrive ici si la page n'est pas celle du diaporama.
	}
}

/* ----- Chargement / affichage image ----- */
function display(current){
	current = current + 1;
	if (current > (images.length - 1)){current = 0;}
	get('diapo').style.visibility = 'hidden';
	get('diapo').innerHTML = '<img src = "'+images[current]+'" width = "'+largeur[current]+'" height = "'+hauteur[current]+'" alt = "" title = "" onload = "this.style.visibility = \'visible\';fade_in(\'agence_left\',0);"/>';
	
	return (current);
}

/* ----- Timing permanent récursif ----- */
var mto;
var t=0;
function timing(ms,tab){
	current = display(current);
	clearTimeout(mto);
	mto = setTimeout(function(){timing(ms,tab);},ms);
}

/* ---- Charge une photo dans une div ----- */
function majPhoto(psource,pwidth,pheight){
	get('thephoto').style.visibility = 'hidden';
	//get('portfolio_zoom').style.background = 'background:url(\'images/portfolio/loading.gif\') no-repeat center center;';
	get('thephoto').innerHTML = '<table cellspacing = "0" width = "100%"><tr><td valign = "middle" align = "center" style = "height:432px;"><img src = "'+psource+'" width = "'+pwidth+'" height = "'+pheight+'" alt = "" title = "" onload = "get(\'thephoto\').style.visibility = \'visible\';fade_in(\'portfolio_zoom\',0);"/></td></tr></table>';
}

/* ----- Deplacement d'une div dans une autre verticalement ----- */
function movev(direction,num,max,divid,leftarrowid,rightarrowid,decalage){
	var top = get(divid).style.top;
	var longueur = top.length - 2; 
	if (direction == 'bas'){
		if (num < (max-1)){
			get(divid).style.top = parseFloat(top.substring(0,longueur)) - decalage + 'px';
			get(leftarrowid).style.visibility = 'visible';
			if (num == (max-6)){
				get(rightarrowid).style.visibility = 'hidden';
			}
			return (num+1);
		}
	}
	if (direction == 'haut'){
		if (num > 0){
			get(divid).style.top = parseFloat(top.substring(0,longueur)) + decalage + 'px';
			get(rightarrowid).style.visibility = 'visible';
			if (num == 1){
				get(leftarrowid).style.visibility = 'hidden';
			}
			return (num-1);
		}
	}
	return num;
}

/* ----- Verifie que les champs obligatoires sont remplis dans le formulaire de contact ----- */
function checkForm(){
	var email = get('email').value.length;
	var nom = get('nom').value.length;
	var prenom = get('prenom').value.length;
	var raison = get('raison').value.length;
	var objet = get('objet').value.length;
	var message = get('message').value.length;
	var destinataire = get('destinataire').value.length;
	
	if (email>0 && nom>0 && prenom>0 && raison>0 && objet>0 && destinataire>0 && message>0){
		get('valid').value = 1;
		document.contactform.submit();
	}else{
		alert('Champs obligatoires : Raison sociale, Nom, Prénom, Email, Objet, Destinataire, et Message.');
	}
}

/* ----- Bascule une fausse checkbox ----- */
function toggleNL(){
	var val = get('andNL').value;
	// Activé => desactivé
	if (val == 1){
		get('thetick').src = 'images/spacer.gif';
		get('andNL').value = 0;
	}
	// Désactivé => activé
	else{
		get('thetick').src = 'images/contact/tick.jpg';
		get('andNL').value = 1;
	}
}

/* ----- Verifie que les champs obligatoires sont remplis dans le formulaire "Espace candidats"  ----- */
function checkFormCandidat(){
	var bu = get('bu').value.length;
	/*var lieu = get('lieu').value.length;*/
	var cv = get('cv').value.length;
	
	if (bu>0 && cv>0){
		get('valid').value = 1;
		document.contactform.submit();
	}else{
		alert('Champs obligatoires : Secteur d’activité et votre CV.');
	}
}

/* ----- Verifie que les champs obligatoires sont remplis dans le formulaire "Recrutement interne"  ----- */
function checkFormInterne(){
	var nom = get('nom').value.length;
	var prenom = get('prenom').value.length;
	var telfixe = get('telfixe').value.length;
	var email = get('email').value.length;
	var cv = get('cv').value.length;
	
	if (nom>0 && prenom>0 &&telfixe>0 && email>0 && cv>0){
		get('valid').value = 1;
		document.contactform.submit();
	}else{
		alert('Champs obligatoires : Nom, prénom, téléphone fixe, email et votre CV.');
	}
}
