// JavaScript Document
 
function afficher(id) {
	var ele = document.getElementById(id);
	
	if (ele.className == 'cloak' || ele.className == 'cloak2' || ele.className == 'cloak3')
		ele.className = 'un' + ele.className ;
	else
		ele.className = ele.className.substring(2,10);
}

sfHover = function() {
	var root ;
	
	root = document.getElementById("navHaut") ;
	if (root) 
	{
		var sfEls = root.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	
	root = document.getElementById("checklist") ;
	if (root) {
		var sfEls = root.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			if (sfEls[i].className='over') {
				sfEls[i].onmouseover=function() {
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


function changerLangue(langue) {
	
	var ele = document.getElementById('LANGUE');
	if (!ele) return false;
	
	ele.value = langue ;
		
	ele = document.getElementById('changerLangue');
	if (!ele) return false;
	
	ele.submit();
	
	return true;
}

function closeAll() {
	var navRoot = document.getElementById("contribution");		
	if (!navRoot)
		navRoot = document.getElementById("suivrelasituation");	
		
	if (navRoot) 
	{
		var subnodes = navRoot.getElementsByTagName("DIV");
		for (i=0; i<subnodes.length; i++) {
			node = subnodes[i];
			//alert(node.className);
			if (node.nodeName=="DIV" && node.className=="divliste") {				
					node.style.display = 'none' ;
			}
		}
	}
}

function getWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  
  return myWidth;
}

function infobDisp(oo) {
	var o = document.getElementById(oo);
	if(o) {
		closeAll();
		infobCur=o;
		var eleW = 0;
		var eleTop = 0;
		
		var element = document.getElementById('barreDeNavVerticale');
		if (element)
			eleW = element.offsetWidth;
		
		element = document.getElementById('rubriquecentrale');
		if (element)			
		{ 
			elementOffsetParent = element.offsetParent ;
			
			// While there is an offset parent
            while((elementOffsetParent = element.offsetParent) != null)
            {
                eleTop += element.offsetTop;
                element = elementOffsetParent;
            }
		}
		
		var ww = 0;
		//ww = (screen.availWidth-800) / 2 ;
		ww = (getWidth() - 800) / 2;
		o.style.display='inline';
		o.style.visibility='visible';
		o.style.top = (ymouse-eleTop) + 'px';
		o.style.left= (xmouse-eleW-ww) + 'px';
		//trace('xmouse='+xmouse+' & left='+o.style.left+' & ymouse='+ymouse+' & top='+o.style.top);
		//trace('eleW='+eleW+' & ww='+ww);
		//document.onmousemove=infobMove;
	}
}

function infobHide(oo) {
	var o = document.getElementById(oo);
	if(o) {
		o.style.display='none';
		o.style.visibility='hidden';
	}
}

function trace( msg ){
  if( typeof( jsTrace ) != 'undefined' ){
    jsTrace.send( msg );
  }
}

var xmouse = -500;
var ymouse= -500;

function ouEstSouris( e )
{
	
	if (!e) e=event;
	if (e.pageX) {
		xmouse = e.pageX+document.body.scrollLeft;
		ymouse = e.pageY+document.body.scrollTop;
	}
	else
	{
		xmouse = e.clientX+document.body.scrollLeft;
		ymouse = e.clientY+document.body.scrollTop;
	}
	
	//trace('xmouse='+xmouse+' &ymouse='+ymouse);
}


function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	}
	else { // XMLHttpRequest non supporté par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
	return xhr;
}

/**
 * Fonction qui permet l'affichage des évènements ou formations relatives au jour passé en argument.
 * 1) Appel au script distant via un objet XMLHttpRequest (ajax) pour récupérer le code html correspondant 
 * à la liste des évènements (ou formations) du jour passé en argument (timestamp à 12;00:00 du jour)
 * 2) Mise à jour du div caché
 * 3) Affichage du div caché.
 */
function afficherCalendrierJour(tsJour) {
	
	var ele = document.getElementById('listeEventCal');
	if (ele)
		ele.style.display = 'block';
		
	var xhr = getXhr();
	if (!xhr) return false;
	
	xhr.onreadystatechange = function()
	{
		try {
			var ele = null;
			ele = document.getElementById('listeEventCal_zoneaff');
			
			if(xhr.readyState == 4 && xhr.status == 200) {
				ele.innerHTML = xhr.responseText ;
			}
			else {
				/*var pOld = document.getElementById('listeEventCal_zoneaff');
				pOld.innerHTML = '<p align="center">Chargement...</p>';
				var p = document.createElement('p');
				p.setAttribute('align', 'center');
				p.setAttribute('id', 'listeEventCal_zoneaff');
				p.appendChild(document.createTextNode('Chargement..'));
				ele.replaceChild(p, pOld);*/
				
				ele.innerHTML = '<p align="center">Chargement...</p>';
			}
		}
		catch(e) {
			return false;
		}
	}
	
	var myloc = window.location.href;
	var locarray = myloc.split("/");
	delete locarray[(locarray.length-1)];
	var URL_DOMAINE = locarray.join("/");
	var url = URL_DOMAINE + "scripts/calendrier_extractjour.php" ;
	//alert(url);

	//on appelle le fichier reponse.txt
	xhr.open("POST", url , true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send('tsJour='+tsJour);
	
	return false;
	
	//alert('xhr envoyé.');
}



/**
 * Fonction qui permet la miseà jour du calendrier. Typiquement quand l'utilisateur avance ou recule d'un mois.
 * 1) Appel au script distant via un objet XMLHttpRequest (ajax) pour récupérer le code html correspondant 
 * au calendrier des évènements (et formations) de la période passée en argument (Y-m)
 * 2) Mise à jour du calendrier
 */
function updateCalendar(periode) {
	
	var xhr = getXhr();
	if (!xhr) return false;
	
	xhr.onreadystatechange = function()
	{
		try {
			var ele = null;
			ele = document.getElementById('calendrier');
			
			if(xhr.readyState == 4 && xhr.status == 200) {
				ele.innerHTML = xhr.responseText ;
			}
			else {
				/*var pOld = document.getElementById('listeEventCal_zoneaff');
				pOld.innerHTML = '<p align="center">Chargement...</p>';
				var p = document.createElement('p');
				p.setAttribute('align', 'center');
				p.setAttribute('id', 'listeEventCal_zoneaff');
				p.appendChild(document.createTextNode('Chargement..'));
				ele.replaceChild(p, pOld);*/
				
				ele.innerHTML = '<p align="center">Chargement...</p>';
			}
		}
		catch(e) {
			return false;
		}
	}
	
	var myloc = window.location.href;
	var locarray = myloc.split("/");
	delete locarray[(locarray.length-1)];
	var URL_DOMAINE = locarray.join("/");
	var url = URL_DOMAINE + "scripts/calendrier.php" ;
	//alert(url);

	//on appelle le fichier reponse.txt
	xhr.open("POST", url , true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send('periode='+periode);
	
	return false;
	
	//alert('xhr envoyé.');
}

//==============================================================
//Script:     Auto-Sizing Image Popup Window

//Functions:  Use this script to launch a popup window that
//            automatically loads an image and resizes itself
//            to fit neatly around that image. The script also
//            places a title you set in the titlebar of the 
//            popup window. Any number of images can be launched
//            from a single instance of the script.
            
//Browsers:   NS6-7 & IE4 and later
//            [Degrades functionally in NS4]

//Author:     etLux
//==============================================================

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4)
{
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}

var optNNnoScroll='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optNNwithScroll='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIEnoScroll='resizable=yes,scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
var optIEwithScroll='height=100, width=200, top=100, left=100, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=yes, status=yes';

function popupImage(imageURL,imageTitle,scrollbars)
{
	if (isNN)
	{
		if (scrollbars)
			imgWin=window.open('about:blank','',optNNwithScroll);
		else
			imgWin=window.open('about:blank','',optNNnoScroll);
	}
	if (isIE)
	{
		if (scrollbars)
			imgWin=window.open(imageURL, 'test', optIEwithScroll);
		else
			imgWin=window.open(imageURL, 'test', optIEnoScroll);
	}
	with (imgWin.document)
	{
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('if (height>500) height = 500;');
		//writeln('if (window.scrollbars.visible == true) width = width+20 ;');
		writeln('window.resizeTo(width,height);}');
		writeln('if (isNN){');       
		writeln('height = document.images["George"].height;');
		writeln('width = document.images["George"].width;');
		writeln('if (height>500) height = 500;');
		writeln('if (this.scrollbars.visible == true) width = width+20 ;');
		writeln('window.innerWidth=width;');
		writeln('window.innerHeight=height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
		close();		
	}
}

function decryptmail(coded) {
	cipher = "aZbYcXdWeVfUgThSiRjQkPlOmNnMoLpKqJrIsHtGuFvEwDxCyBzA1234567890"
	shift=coded.length
	link=""
	for (i=0; i<coded.length; i++){
		if (cipher.indexOf(coded.charAt(i))==-1){
			ltr=coded.charAt(i)
			link+=(ltr)
		}
		else {     
			ltr = (cipher.indexOf(coded.charAt(i))-shift+cipher.length) % cipher.length
			link+=(cipher.charAt(ltr))
		}				
	}
	window.location="mailto:"+link ;
}

function imprimer(id){
	if(window.open('imprimer.php?media=print&id='+id, 'Imprimer', 'width=560px, height=450px, top='+(screen.availHeight/2-225)+'px, left='+(screen.availWidth/2-280)+'px, scrollbars=yes'))
		return false;
	return true;	
}

function envoyer(id){
	if(window.open('envoyer.php?href='+escape(window.location)+'&id='+id, 'Envoyer', 'width=560px, height=450px, top='+(screen.availHeight/2-225)+'px, left='+(screen.availWidth/2-280)+'px, scrollbars=yes'))
		return false;
	return true;	
}

function ouvrirContacter(){
	if(window.open('contact.php', 'Contacter', 'width=560px, height=500px, top='+(screen.availHeight/2-250)+'px, left='+(screen.availWidth/2-280)+'px, scrollbars=yes'))
		return false;
	return true;	
}

function lancerRecherchePleinTexte(nomForm, idChamp, cut ) {
	var nb;
	if (document.getElementById(cut))
		nb = document.getElementById(cut).value ;
	else
		nb = 1;
	if ( document.getElementById(idChamp).value != '' || nb>0)	
		document.getElementById(nomForm).submit();
	else
		alert('Vous devez saisir au moins un mot clé pour effectuer une recherche.');
}










