<!--
/*
	Fonctions javascript Utilitaires :
	
	Update_Droplist(hidden_ref,droplist1,droplist2,message) 
	-> Mettre à jour un droplist associé sans avoir à rafraichir la page.
	
	ploadImg_accueil()
	-> Liste des images en préchargement ONLOAD pour la fonction MM_preloadImages()
	
	browser_detect()
	-> Détection de browser
	
	open_window(mypage, myname, w, h, scroll)
	-> Ouverture d'une fenêtre en popup
	
	telechargement(mypage, myname, w, h, scroll)
	-> Ouverture d'une fenêtre popup pour le téléchargement
	
	MM_preloadImages()
	-> Préload d'image
	
	MM_swapImgRestore()
	-> Restore d'images après rollover
	
	MM_findObj(n, d)
	-> Recherche d'object
	
	MM_swapImage()
	-> Rollover d'images


*/

//Mettre à jour un droplist associé sans avoir à rafraichir la page.
//Méhode similaire à AJAX
function Update_Droplist(hidden_ref,droplist1,droplist2,message,message2,droplist3) {

	
	//OBJECT
	obj_droplist1 = eval("document.theform." + droplist1);
	obj_droplist2 = eval("document.theform." + droplist2);
	
	//Valeur sélectionné dans le droplist
	drop_value = obj_droplist1.value;
	
	if(drop_value == "null" || drop_value == ""){
	
		//Efface le drop list 2
		obj_droplist2.options.length = 0;
		obj_droplist2.style.display = "none";
		
		//Si l'objet existe, c'est qu'un 3e droplist doit être effacer
		//lors du rafraichissement du 1er.
		if(droplist3 != "NULL"){
			obj_droplist3 = eval("document.theform." + droplist3);	
			obj_droplist3.options.length = 0;
			obj_droplist3.style.display = "none";
		}
	
	} else {
	
		//Récupérer les informations Onchange
		//------------------------------------------------
		
		//Path du champ hidden text
		path_text = "document.theform.text_" + hidden_ref + drop_value + ".value"; 
		path_object_text = "document.theform.text_" + hidden_ref + drop_value; 
		//Path du champ hidden id
		path_id = "document.theform.id_" + hidden_ref + drop_value + ".value"; 
		path_object_id = "document.theform.id_"+ hidden_ref  + drop_value; 
		
		
		//Si l'objet existe, c'est qu'un 3e droplist doit être effacer
		//lors du rafraichissement du 1er.
		if(droplist3 != "NULL"){
			obj_droplist3 = eval("document.theform." + droplist3);	
			obj_droplist3.options.length = 0;
			obj_droplist3.style.display = "none";
		}
		
		//Si les object Hidden existe pour l'élément
		if(eval(path_object_text && path_object_id)){
		
			//Valeur texte du hidden field correspondant au drop list 2
			hidden_text = eval(path_text);
			//Valeur ID du hidden field correspondant au drop list 2
			hidden_id = eval(path_id);
			
			//Split des valeurs textes dans un tableau
			split_text = hidden_text.split("¤");
			//Split des valeurs ID dans un tableau
			split_id = hidden_id.split("¤");
			//------------------------------------------------
				
			//Mise à jour du second droplist
			//------------------------------------------------
			
			//Efface le droplist 2
			obj_droplist2.options.length = 0;
			
			//Créé le nombre d'option nécessaire dans le droplist 2
			obj_droplist2.options.length = split_id.length + 1;
			
			//Ajout de l'option message à valeur NULL si sous élément
			if(split_id.length > 0){
				obj_droplist2.options[0].text = message;
				obj_droplist2.options[0].value = "null";
			}
	
			for (i = 0; i < split_id.length; i++) {
				obj_droplist2.options[i+1].text = split_text[i];
				obj_droplist2.options[i+1].value = split_id[i];
			}
			obj_droplist2.style.display = "block";
			
		} else {
			
			//Efface le droplist 2
			obj_droplist2.options.length = 1;
			obj_droplist2.options[0].text = message2;
			obj_droplist2.options[0].value = "aucun";
			obj_droplist2.style.display = "block";
		}	
		//------------------------------------------------
		
	}
	
		
 }


// Liste des images en préchargement ONLOAD pour la fonction MM_preloadImages()
// !! Vérifier que le chemin d'accès soit valide !!
function ploadImg_accueil() {
	MM_preloadImages('img/accueil/bt_propos_over.gif','img/accueil/bt_ress_over.gif','img/accueil/bt_visite_over.gif','img/console/bt_quitter_over.gif','img/accueil/perso_inscrire_over.gif');
}
function ploadImg_carnet() {
	MM_preloadImages('/img/niv2/bt_dec_arts_over.gif','/img/niv2/bt_dec_culture_over.gif','/img/niv2/bt_vie_culturelle_over.gif','/img/niv2/activites/section2/boutonExtrait_o.gif');
}

//Détection de browser
function browser_detect(){
	
	//Detect Firefox 1 +
	//---------------------------------------
	if(navigator.userAgent.indexOf("Firefox")!=-1){
		var versionindex=navigator.userAgent.indexOf("Firefox")+8
		if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
		var Firefox = true;
	}
	//---------------------------------------
	
	//Detect IE5.5+
	//---------------------------------------
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
	}
	
	//NON IE browser will return 0
	if (version>=5.5) {
		var IE = true;
	}
	//---------------------------------------
	
	
	//Detect Netscape 4.7+
	//---------------------------------------
	if (navigator.appName=="Netscape"&&parseFloat(navigator.appVersion)>=4.7){
		var Netscape = true;
	}
	//---------------------------------------
	
	if(Firefox == true || IE == true || Netscape == true ){
		//Browser compatible
		return true;
	} else {
		//Browser incompatible
		return false;	
	}
	
}

 
// Ouverture d'une fenêtre en popup
function open_window(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 20;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable, menubar, directories, '+
			   'status, toolbar, location';
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function open_window_sans_menu (mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 20;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// Ouverture d'une fenêtre popup pour le téléchargement
function telechargement(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 20;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	
	//Fermer la fenêtre enfant
	win.window.close();
	
}

// Préload d'image
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// Restore d'images après rollover
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;
}

// Recherche d'object
function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

// Rollover d'images
function MM_swapImage() { //v3.0

  //On mouse out du bouton du menu de gauche, l'image reprend sa src initiale
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

  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];}
}
//-->

// Ouverture et fermeture des espaces enseignants avec la bonne feuille de style pour l'impression
function fermer_esp_ens(){
		
		//Cacher l'espace enseignant
		fond_gris = document.getElementById("zone_grise_transp");
		fond_gris.style.display = "none";
		
		espace_c_ens = document.getElementById("esp_ens");
		espace_c_ens.style.display = "none";
		
		espace_ens = document.getElementById("esp_ens_contenu");
		espace_ens.style.display = "none";
		
		if(document.getElementById("bt_espace_ens") != null) {
			bt_esp_ens = document.getElementById("bt_espace_ens");
			bt_esp_ens.style.display = "block";
		}
		
		activerImpression();
	}
	
function ouvrir_esp_ens(){
	
	//Montrer l'espace enseignant
	fond_gris = document.getElementById("zone_grise_transp");
	fond_gris.style.display = "block";
	
	espace_c_ens = document.getElementById("esp_ens");
	espace_c_ens.style.display = "block";
	
	espace_ens = document.getElementById("esp_ens_contenu");
	espace_ens.style.display = "block";
	
	if(document.getElementById("bt_espace_ens") != null) {
			bt_esp_ens = document.getElementById("bt_espace_ens");
			bt_esp_ens.style.display = "none";
	}
	
	activerImpressionEns();
}
	
function activerImpressionEns() {
	document.getElementById("impression").setAttribute("href", "/inc/css/impression_ens.css");
}

function activerImpression() {
	document.getElementById("impression").setAttribute("href", "/inc/css/impression.css");
}
