<!--
/******************************************
    Librairie
******************************************/

function open_popup(URL,thewidth,theheight)
{
  	window.open(URL,"CIDEM",'scrollbars=yes,width='+thewidth+',height='+theheight+',top=100,left=100,menubar=no,status=no,toolbars=no,resizable=no,location=no');
}

/**** Gestion des Rollovers ****/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments;

document.MM_sr=new Array;

for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null) {
   	document.MM_sr[j++]=x;
   	if(!x.oSrc) 
   		x.oSrc=x.src;
   		x.src=a[i+2];
   }
}

function MM_swapImage2() { //v3.0
var i,j=0,x,a=MM_swapImage2.arguments;

for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null) {
   		x.src=a[i+2];
   		x.alt = a[i+1];
   }
}

////////////////////////////////////////////////////////////////////

function swap_bg(nom,col){
	if(x=MM_findObj(nom)){
		x.style.backgroundColor = col;
	}
}

function swap_menu(nom_menu,chemin)
	{
		if(nom_menu != menu){
			if(nom_menu != current_menu){
				swap_bg(nom_menu,bgcolor_roll);
				MM_swapImage2(nom_menu,'',chemin+nom_menu+'_roll.gif',1);
			}
			if(menu != current_menu && menu != ""){
				swap_bg(menu,bgcolor_init);
				MM_swapImage2(menu,'',chemin+menu+'.gif',1);
			}
		  show_div('s'+nom_menu);
		  if(menu != ""){
				show_div('s'+menu);
			}
		  menu = nom_menu;
		}
	}

function menu_off(chemin)
	{
		if(menu != ""){
			if(menu != current_menu){
				swap_bg(menu,bgcolor_init);
				MM_swapImage2(menu,'',chemin+menu+'.gif',1);
			}
		  show_div('s'+menu);
		  menu = "";
		}
	}

function show_div(id)
	{
	  if(document.getElementById){
	  	if(document.getElementById(id)){
			  if(document.getElementById(id).style.display == 'none'){
			  	document.getElementById(id).style.display = 'block';
			  	}
				else{
					document.getElementById(id).style.display = 'none';
				}
			}
  	}
	}

////////////////////////////////////////////////////////////////////


function show_h_div(id,height_init,max_height,step)
	{
	  if(document.getElementById){
		  if(document.getElementById(id).style.display == 'none'){
		  	height_init = height_init + ((max_height-height_init)%step);
		  	document.getElementById(id).style.display = 'block';
		  	document.getElementById(id).style.height = height_init+'px';
		  	timer = window.setTimeout("step('"+id+"',"+height_init+","+max_height+","+step+")",1);
		  	}
			else{
				document.getElementById(id).style.display = 'none';
			}
  	}
	}
	
function deroul_h_div(id,height_init,max_height,step)
	{
	  if(document.getElementById){
		  if(document.getElementById(id).offsetHeight < max_height){
	  		height_init = height_init + ((max_height-height_init)%step);
				document.getElementById(id).style.height = height_init+'px';
				document.getElementById(id).style.display = 'block';
				timer = window.setTimeout("step('"+id+"',"+height_init+","+max_height+","+step+")",1);
			}
			else {
				max_height = max_height - ((max_height-height_init)%step);
				document.getElementById(id).style.height = max_height+'px';
				timer = window.setTimeout("step('"+id+"',"+max_height+","+height_init+","+-step+")",1);
			}
  	}
	}

function step(id,height_init,max_height,step)
	{
		if(height_init != max_height){
			height_init = height_init+step;
			document.getElementById(id).style.height = height_init+'px';
			timer = window.setTimeout("step('"+id+"',"+height_init+","+max_height+","+step+")",1);
		}
		else{
			window.clearTimeout(timer);
		}
	}

function set_retour(){
	var affichage='';
	step = window.innerHeight;
	step2 = screen.availHeight-100;
	if(!step || step > step2){
		step = step2;
		}
	h = step - 32;
	win_height = window.document.getElementById('retour').offsetHeight;
	win_height2 = window.document.body.offsetHeight;
	if(!win_height || document.height > win_height){
			win_height = document.height;
		}
	if(win_height > step){
		hauteur=win_height;
		while(hauteur > step){
			affichage = '<tr><td><img src="medias/spacer.gif" width="51" height='+h+' alt=""></td></tr><tr><td><a href="#top"><img src="medias/top.gif" height="32" width="51" border="0" alt=""></a></td></tr>'+affichage;
			hauteur -= step;
			}
		affichage='<table border="0" cellpadding="0" cellspacing="0">'+affichage+'</table>';
		window.document.getElementById('retour').innerHTML=affichage;
		}
	}
	
function replace_HTML(id,txt){
	alert('ok');
	x=MM_findObj(id);
	alert(x.innerHTML);
	x.innerHTML=txt;
	}

/***********************   VERIF FORMULAIRE   **************************/
function check_mail(field_email) {
src = field_email;

s=src.value.replace(/[^A-Za-z0-9\.@-]/g, "");
s=s.replace(/\s|\_/g,"");
src.value=s;
lg=s.length;
at=s.indexOf('@');
pt=s.lastIndexOf('.');
e=(s.length < 10 | s.length >80 | at==-1 | pt==-1 | pt<at | (lg-pt>4) |
(lg-pt<=2) | at<3 | (pt-at<4)) ?true:false;

return (e) ? false : true;
}

function verif() {
	f_form = document.labellisation;
	if (f_form.titre.value == "") {
			alert("veuillez saisir le titre du projet.\n");
			f_form.titre.focus();
			return false;
		}
	if (f_form.resume.value == "") {
			alert("veuillez présenter le projet.\n");
			f_form.resume.focus();
			return false;
		}
	if (f_form.nom_structure.value == "") {
		f_form.type.value = 1;
			if ((f_form.nombre.value == 0) && (f_form.age.value ==0) && (f_form.struct_garante.value =="")) {
				alert("veuillez saisir le nom de la structure.\n");
				f_form.nom_structure.focus();
				return false;
			}
			else if(f_form.nombre.value == 0){
				alert("veuillez saisir le nombre de personne qui compose le groupe.\n");
				f_form.nombre.focus();
				return false;
			}
			else if(f_form.age.value == 0){
				alert("veuillez saisir la tranche d'age du groupe.\n");
				f_form.age.focus();
				return false;
			}
			else if(f_form.struct_garante.value == 0){
				alert("veuillez saisir la structure garante du groupe.\n");
				f_form.struct_garante.focus();
				return false;
			}
		}
	else {
		f_form.type.value = 0;
		 if((f_form.structure[4].checked) && (f_form.type_structure.value == "")){
				alert("veuillez saisir le type de la structure constituée.\n");
				f_form.type_structure.focus();
				return false;
			}
		}
	if (f_form.nom.value == "") {
			alert("veuillez saisir le nom du responsable du projet");
			f_form.nom.focus();
			return false;
		}
	if (f_form.prenom.value == "") {
			alert("veuillez saisir le prénom du responsable du projet");
			f_form.prenom.focus();
			return false;
		}
	if (f_form.adresse.value == "") {
			alert("veuillez saisir l'adresse du responsable du projet");
			f_form.adresse.focus();
			return false;
		}
	if (f_form.tel.value == "") {
			alert("veuillez saisir le numéro de téléphone du responsable du projet");
			f_form.tel.focus();
			return false;
		}
	if (f_form.mail.value == "") {
			alert("veuillez saisir le courriel du responsable du projet");
			f_form.mail.focus();
			return false;
		}
	else {
		if (!check_mail(f_form.mail)) {
			alert("veuillez saisir un courriel valide");
			f_form.mail.focus();
			return false;
			}
		}
	/*if (f_form.acteur.value == "") {
			alert("password vide.\n");
			f_form.acteur.focus();
			return false;
		}
	if (f_form.public.value == "") {
			alert("password vide.\n");
			f_form.public.focus();
			return false;
		}
	if (f_form.resultats.value == "") {
			alert("password vide.\n");
			f_form.resultats.focus();
			return false;
		}
	if (f_form.coherence.value == "") {
			alert("password vide.\n");
			f_form.coherence.focus();
			return false;
		}
	if (f_form.debut.value == "") {
			alert("password vide.\n");
			f_form.debut.focus();
			return false;
		}
	if (f_form.etapes.value == "") {
			alert("password vide.\n");
			f_form.etapes.focus();
			return false;
		}
	if (f_form.fin.value == "") {
			alert("password vide.\n");
			f_form.fin.focus();
			return false;
		}
		if (f_form.recettes.value == "") {
			alert("password vide.\n");
			f_form.recettes.focus();
			return false;
		}
	if (f_form.depenses.value == "") {
			alert("password vide.\n");
			f_form.depenses.focus();
			return false;
		}
	if (f_form.formes.value == "") {
			alert("password vide.\n");
			f_form.formes.focus();
			return false;
		}
	if (f_form.evaluation.value == "") {
			alert("password vide.\n");
			f_form.evaluation.focus();
			return false;
		}
	if (f_form.commentaires.value == "") {
			alert("password vide.\n");
			f_form.commentaires.focus();
			return false;
		}*/
	f_form.submit();
	return true;
	}

/*******************************************************************************************/
// Garder un div (logo) toujours en haut de page ou en bas de page
// PARAMETRAGE DU SCRIPT
var tjs_delai=20;
var tjs_max=20;
var tjs_mode=1; // 0 - calque toujours en haut de page / 1 - calque en bas

var tjs_hauteur=0;
function PrintCalque(left,top,width,height,contenu) {
	tjs_hauteur=height;
	var Z="<DIV id='tomber' style='position:absolute;left:"+left+"px;top:"+top+"px;width:"+width+"px;height:"+height+"px'>"+contenu+"</DIV>";
	document.write(Z);
	setTimeout("Start()",tjs_delai);
}
function Start() {
	MoveLayer("tomber",GetTop("tomber"));
	setTimeout("Start()",tjs_delai);
}
function Debug() {
	var obj=document.body
	var Z="";
	for (var i in obj) {
		Z+=i+"="+obj[i]+"\n";
	}
	alert(Z);
}
function MoveLayer(nom,top) {
	if (document.getElementById) {
		document.getElementById(nom).style.top=top+'px';
	}
}
function GetTop(nom) {
	// Partie 1 : Récupération de la position du calque et de la page
	if (document.getElementById) {
		var pos=parseInt(document.getElementById(nom).style.top);
		var wintop=parseInt(window.pageYOffset);
		var avail=window.innerHeight;
		//alert(pos+'\r\n'+wintop+'\r\n'+avail+'\r\n');
	}
	else{
	alert('oups');
	}

	// Partie 2 : Traitement de la position
	if (tjs_mode==0) { // toujours en haut
		var delta=Math.ceil((pos-wintop)/3);
		if (delta>tjs_max) {delta=tjs_max;}
		if (delta<-1*tjs_max) {delta=-1*tjs_max;}
		var top=pos-delta;
	}
	if (tjs_mode==1) {// toujours en bas
		var delta=Math.ceil((pos-(wintop+avail-tjs_hauteur)));
		if (delta>tjs_max) {delta=tjs_max;}
		if (delta<-1*tjs_max) {delta=-1*tjs_max;}
		var top=pos-delta;
	}
	return top;
}
/******************************************************************************************/

//-->

