function get(e){
	return document.getElementById(e);
}

// Initialisation pour l'inscription newsletter
var clearNL = false;

function clearnewsletter(done){
	if (done == false){
		get('inputnewsletter').value = '';
		done = true;
	}
	return done;
}

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.');
	}
}

function checkForm2(){
	var email = get('email').value.length;
	var nom = get('nom').value.length;
	var parcours = get('parcours').value.length;
	var cv = get('cv').value.length;
	var indice = document.forms['contactform'].elements['typeposte'].options.selectedIndex;
	var typeposte = document.forms['contactform'].elements['typeposte'].options[indice].text.length;
	
	if (email>0 && nom>0 && parcours>0 && cv>0 && typeposte>0){
		get('valid').value = 1;
		document.contactform.submit();
	}else{
		alert('Champs obligatoires : Nom, Email, Parcours, Type de poste recherché, et Cv.');
	}
}

function flash(tag) {
document.write(tag);
} 

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');
}

// Affiche la popup d inscription / desinscription a la NL
function displayPop(type){
	get(type).style.visibility = 'visible';
}

function fermePopUp(page){
window.opener.location = page;
window.close();
}

// Dépace +/- 115px la div "toscroll"
function moveprof(direction,numloc,maxprof){
	var left = get('toscroll').style.left;
	var longueur = left.length - 2; 
	
	if (direction == 'droite'){
		if (numloc < (maxprof - 3)){
			get('toscroll').style.left = parseFloat(left.substring(0,longueur)) - 115 + 'px';
			get('defileprofg').style.visibility = 'visible';
			if (numloc == (maxprof - 4)){
				get('defileprofd').style.visibility = 'hidden';
			}
			return (numloc+1);
		}
	}
	if (direction == 'gauche'){
		if (numloc > 0){
			get('toscroll').style.left = parseFloat(left.substring(0,longueur)) + 115 + 'px';
			get('defileprofd').style.visibility = 'visible';
			if (numloc == 1){
				get('defileprofg').style.visibility = 'hidden';
			}
			return (numloc-1);
		}
	}
	return numloc;
}

// SCROLL PERSO uniquement avec fleches haut bas
var mytime;
var deplacement = false;
var totalheight = -1; 
var boxheight = -1;

// Monte et descend le contenu de disciplines - boite contenante 280px de haut, apparition du scroll si dépassement
function movedisci(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps){
	var letop = get(loc_divtoscroll).style.top;
	var lalongueur = letop.length - 2;
	var topactuel = parseFloat(letop.substring(0,lalongueur));
	clearTimeout(mytime);
	var decale;
	
	if (loc_type == 'bas'){
		decale = loc_total - loc_boxheight + topactuel;
		if (decale > loc_pas){
			decale = loc_pas;
		}
		if (decale > 0){
			get(loc_divtoscroll).style.top = topactuel - decale + 'px';
			get(loc_up).style.visibility = 'visible';
			if ((topactuel-decale) == (loc_boxheight - loc_total)){
				get(loc_down).style.visibility = 'hidden';
			}
			mytime = setTimeout(function(){movedisci(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps);},loc_temps);
		}
	}
	if (loc_type == 'haut'){
		decale = (-(topactuel));
		if (decale > loc_pas){
			decale = loc_pas;
		}
		if (decale > 0){
			get(loc_divtoscroll).style.top = topactuel + decale + 'px';
			get(loc_down).style.visibility = 'visible';
			if ((topactuel+decale) == 0){
				get(loc_up).style.visibility = 'hidden';
			}
			mytime = setTimeout(function(){movedisci(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps);},loc_temps);
		}
	}
}

// Demarrage du scroll, demandé à l'onload
function startminiscroll(){
	try {
		totalheight = get("discitoscroll").offsetHeight; 
		boxheight = get("contenudisci").offsetHeight;
		if (totalheight > boxheight){
			get("bottomarrow").style.visibility = 'visible';
		}
	}
	catch(e){}
}

// Arret du scroll au relachement de la souris
function stopminiscroll(){
	deplacement=false;
	clearTimeout(mytime);
}

// Affiche la photo zoom
function showZoom(source,w,h){
	get('zoomW').style.width = w - 31 + 'px';
	get('zoomH').style.height = h - 31 + 'px';
	get('zoomimg').src = source;
	get('zoomimg').style.height = h + 'px';
	get('zoomimg').style.width = w + 'px';
	get('opacity').style.visibility = 'visible';
}

function closeZoom(){
	get('zoomimg').src = 'images/spacer.gif';
	get('opacity').style.visibility = 'hidden';
}

function movetarif(direction,numlocc,maxtarif){
	var left = get('toscroll').style.left;
	var longueur = left.length - 2; 
	if (direction == 'droite'){
		if (numlocc < (maxtarif-1)){
			get('toscroll').style.left = parseFloat(left.substring(0,longueur)) - 526 + 'px';
			get('defiletarifg').style.visibility = 'visible';
			if (numlocc == (maxtarif-2)){
				get('defiletarifd').style.visibility = 'hidden';
			}
			return (numlocc+1);
		}
	}
	if (direction == 'gauche'){
		if (numlocc > 0){
			get('toscroll').style.left = parseFloat(left.substring(0,longueur)) + 526 + 'px';
			get('defiletarifd').style.visibility = 'visible';
			if (numlocc == 1){
				get('defiletarifg').style.visibility = 'hidden';
			}
			return (numlocc-1);
		}
	}
	return numlocc;
}

function moveagenda(direction,numloccc,maxagenda){
	var left = get('toscroll').style.left;
	var longueur = left.length - 2; 
	if (direction == 'droite'){
		if (numloccc < (maxagenda-1)){
			get('toscroll').style.left = parseFloat(left.substring(0,longueur)) - 625 + 'px';
			get('prev').style.visibility = 'visible';
			if (numloccc == (maxagenda-2)){
				get('next').style.visibility = 'hidden';
			}
			return (numloccc+1);
		}
	}
	if (direction == 'gauche'){
		if (numloccc > 0){
			get('toscroll').style.left = parseFloat(left.substring(0,longueur)) + 625 + 'px';
			get('next').style.visibility = 'visible';
			if (numloccc == 1){
				get('prev').style.visibility = 'hidden';
			}
			return (numloccc-1);
		}
	}
	return numloccc;
}
var dyn=0;
var planningmode = 0;
// Activation et desactivation des checkboxes du planning
function majcheck(dyn,planningmode){
	try{
		// Par ANNEE
		if (planningmode == 'y'){
			// Pour chaque minicase, (annee#mois#jour#disci#type)
			for (var i=0;i<dyn.length;i++){
				var tmp = new Array();
				var tmp = dyn[i].split('#');
				var disc = tmp[3];
				var type = tmp[4];
				
				// Nécéssite de cocher la discipline X
				if (get('d'+disc).checked == true){
					if ((type == 'cours')
						|| ((get('showstages').checked == true) && (type == 'stage'))
						|| ((get('showevents').checked == true) && (type == 'event'))) {
						get(dyn[i]).style.color = '#c02c80';
					}else{
						get(dyn[i]).style.color = '#666';
					}
				}else{
					get(dyn[i]).style.color = '#666';
				}
			}
		}
		// Par MOIS
		if (planningmode == 'm'){
			// Pour chaque minicase, (annee#mois#jour#disci#type)
			for (var i=0;i<dyn.length;i++){
				var tmp = new Array();
				var tmp = dyn[i].split('#');
				var disc = tmp[3];
				var type = tmp[4];
				
				// Nécéssite de cocher la discipline X
				if (get('d'+disc).checked == true){
					if ((type == 'cours')
						|| ((get('showstages').checked == true) && (type == 'stage'))
						|| ((get('showevents').checked == true) && (type == 'event'))) {
						get(dyn[i]).style.display = 'block';
					}else{
						get(dyn[i]).style.display = 'none';
					}
				}else{
					get(dyn[i]).style.display = 'none';
				}
			}
		}
	}
	catch(e){
		alert('Error : majcheck');
	}
}

// Toggle voir tous / voir aucun
function togglecheck(alldisc){
	try{
		// Si la case TOUS est cochée
		if (get('allcheck').checked){
			// Pour chaque discipline, on coche.
			for (var i=0;i<alldisc.length;i++){
				get('d'+alldisc[i]).checked = 'checked';
			}
		}else{
			// Sinon, on décoche tout
			for (var i=0;i<alldisc.length;i++){
				get('d'+alldisc[i]).checked = false;
			}
		}
	}
	catch(e){
		alert('Error : togglecheck');
	}
}
function movesemainier(direction,nu,maxsem){
	var left = get('semainier').style.left;
	var longueur = left.length - 2; 
	if (direction == 'droite'){
		if (nu < (maxsem-1)){
			get('semainier').style.left = parseFloat(left.substring(0,longueur)) - 250 + 'px';
			get('prev').style.visibility = 'visible';
			if (nu == (maxsem-2)){
				get('next').style.visibility = 'hidden';
			}
			return (nu+1);
		}
	}
	if (direction == 'gauche'){
		if (nu > 0){
			get('semainier').style.left = parseFloat(left.substring(0,longueur)) + 250 + 'px';
			get('next').style.visibility = 'visible';
			if (nu == 1){
				get('prev').style.visibility = 'hidden';
			}
			return (nu-1);
		}
	}
	return nu;
}

// Affichage popup absolute pour le détail d'un cours / stage / event
function showDetail(){
	get('onClic').style.visibility = 'visible';
}

function majPhoto(psource,pwidth,pheight){
	get('thephoto').style.visibility = 'hidden';
	get('thephoto').innerHTML = '<img src = "'+psource+'" width = "'+pwidth+'" height = "'+pheight+'" alt = "" title = "" style = "border:2px solid black;" onload = "get(\'thephoto\').style.visibility = \'visible\';"/>';
}

function bordurePhoto(numerophoto,nbphoto){
	for(var i=0;i<nbphoto;i++){		
		get('miniature'+i).style.borderTop = '1px solid white';
		get('miniature'+i).style.borderRight = '1px solid #999';
		get('miniature'+i).style.borderLeft = '1px solid #aaa';
		get('miniature'+i).style.borderBottom = '1px solid #666';
	}
	get('miniature'+numerophoto).style.border = '1px solid #c02c80';
}

function movephoto(direction,photo,maxphoto){
	var left = get('galerie_barrephoto').style.left;
	var longueur = left.length - 2; 
	if (direction == 'droite'){
		if (photo < (maxphoto-1)){
			get('galerie_barrephoto').style.left = parseFloat(left.substring(0,longueur)) - 73 + 'px';
			get('prev').style.visibility = 'visible';
			if (photo == (maxphoto-8)){
				get('next').style.visibility = 'hidden';
			}
			return (photo+1);
		}
	}
	if (direction == 'gauche'){
		if (photo > 0){
			get('galerie_barrephoto').style.left = parseFloat(left.substring(0,longueur)) + 73 + 'px';
			get('next').style.visibility = 'visible';
			if (photo == 1){
				get('prev').style.visibility = 'hidden';
			}
			return (photo-1);
		}
	}
	return photo;
}

function majVideo(vsource,vtype,serv){
	try{
		if (vtype == 'youtube'){
			get('thephoto').innerHTML = '<object width="445" height="320"><param name="movie" value="'+vsource+'&hl=fr&fs=1&rel=0&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+vsource+'&hl=fr&fs=1&rel=0&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="320"></embed></object>';
		}
		if (vtype == 'dailymotion'){
			get('thephoto').innerHTML = '<object width="445" height="320"><param name="movie" value="'+vsource+'&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="'+vsource+'&related=0" type="application/x-shockwave-flash" width="445" height="320" allowFullScreen="true" allowScriptAccess="always"></embed></object>';
		}
		if (vtype == 'swf'){
			get('thephoto').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="500" height="330"><param name="movie" value="'+vsource+'"/><param name="quality" value="high"/><embed src="'+vsource+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="500" height="330"></embed></object></div>';
		}
		if (vtype == 'flv'){
			get('thephoto').innerHTML = '<object width="445" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="player.swf" name="movie"/><param value="link='+serv+vsource+'" name="FlashVars"/><param value="high" name="quality"/><embed width="445" height="300" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" flashvars="link='+serv+vsource+'" src="player.swf"/></object>';
		}
		if (vtype == '?'){
			alert('Format de vidéo inconnu.');
		}
	}
	catch(e){
		
	}
}
