var currentsection = 0;
/*
0 : homepage
1 : presentation
1_1 :
1_2 :
1_3 :
1_3_1 :
1_3_2 :
1_3_3 :
2 : applications
2_1 :
2_1_1 :
2_1_2 :
2_1_3 :
2_1_4 :
2_1_5 :
2_1_6 :
3 : actualites
4 : espace_client
4_1 :
4_2 :
4_2_1 :
4_2_2 :
4_3 :
4_4 :
4_5 :
4_6 :
4_7 :
4_8 :
4_9 :
4_9_1 :
4_9_2 :
4_9_3 :
4_9_4 :
4_10 :
4_11 :
4_12 :
5 : outil
*/
function popup(url,name,width,height,resizable,other) {
    window.open(url, name, 'width='+width+',height='+height+',resizable='+resizable+other).focus();
}

function toggle(node) {
	// if (section == currentsection) return;
	var ul = node;
	do {
		ul = ul.nextSibling;
	} while(ul && ul.nodeName.toLowerCase() != 'ul');
	if(!ul) return;
	if(ul.style.display != "block") {
		ul.style.display = "block";
	} else {
		ul.style.display = "none";
	}
	var ancestor = node;
	do {
		ancestor = ancestor.parentNode;
	} while(ancestor && ancestor.nodeName.toLowerCase() != 'ul');
	/*if(!ancestor) return;
	var sublists = ancestor.getElementsByTagName('ul');
	for(var i=0, len=sublists.length; i<len; ++i) {
		if(sublists[i] != ul) {
			sublists[i].style.display = "none";
		}
	}*/
}

/* getVPadding : retourne la valeur des paddings verticaux d'un bloc*/
function getVPadding(obj) {
	if (!obj) return 0;
	var pad = parseInt(getStyle(obj,"padding-top"))+parseInt(getStyle(obj,"padding-bottom"));
	if (isNaN(pad)) pad = 0;
	return pad;
}

/* fonction qui permet de récupérer le style précis d'un élément (même si le style est appliqué en CSS) */
function getStyle(oElm, strCssRule){
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle){
		try{
			strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
		} catch(e) {
			return "";
		}
    }
    else if(oElm.currentStyle){
        try{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
	            return p1.toUpperCase();
	        });
	        strValue = oElm.currentStyle[strCssRule];
		} catch(e) {
			return "";
		}
    }
    return strValue;
}
/*fin des fonctions*/


function showhide(bloc){
	with (document.getElementById(bloc).style) {
		if (display == 'none'){
			try {
				display = 'table';
			} catch(e) {
				display = 'block';
			}
		}
		else{
			  display = 'none';
		}
	}
	fixColumns();
}
var ifrlayer = {
	make:function(obj) {
		if(!obj) return; obj = (typeof(obj)=="string") ? document.getElementById(obj) : obj; if(!obj) return;
		if((document.getElementsByTagName("select").length>0 || document.getElementsByTagName("embed").length>0 || document.getElementsByTagName("object").length>0) && document.all && document.getElementById && !window.opera) {
			if(obj.parentNode && !obj.iframelayer) var ifr = obj.parentNode.insertBefore(document.createElement("iframe"), obj);
			else return;
			if(obj.currentStyle.zIndex != "" && parseInt(obj.currentStyle.zIndex)>1 ) {
				ifr.style.zIndex = parseInt(obj.currentStyle.zIndex)-1;
			}
			ifr.src = "javascript:false";
			with(ifr.style) {
				filter = "alpha(opacity=0)";
				position = "absolute";
				width =  obj.offsetWidth+"px";
				height =  obj.offsetHeight+"px";
			}
			obj.iframelayer = ifr;
			ifrlayer.move(obj)
		}
	},
	kill:function(obj) {
		if(!obj) return; obj = (typeof(obj)=="string") ? document.getElementById(obj) : obj; if (!obj) return;
		var ifr = obj.iframelayer;
		if(ifr && ifr.parentNode) {
			ifr.parentNode.removeChild(ifr);
			obj.iframelayer = null
		}
	},
	move:function(obj) {
		if(!obj || !obj.iframelayer) return;
		with(obj.iframelayer.style) {
			top = obj.offsetTop+"px";
			left =  obj.offsetLeft+"px"
		}
	}
}

var monthArr= new Array("Janv","Fev","Mars","Avril","Mai","Juin","Juil","Aout","Sept","Oct","Nov","Dec");  //remplissez ici le tableau des mois dans la langue du site,
var actualDate = new Date("07/25/2006"); //veuillez definir ici la date du jour generee par le serveur au format MM/JJ/AAAA


var calendar={
	monthArr: new Array("Janv","Fev","Mars","Avril","Mai","Juin","Juil","Aout","Sept","Oct","Nov","Dec"),
 	initialised:null,
 	selectDay:null,
	selectMonthYear:null,
	minMonth:null,minYear:null,
	maxMonth:null,maxYear:null,
	date:Date,
	tmpDate:Date,
	actualDate:Date,
 	popupcontainer:null,
	popupprev:null,
	popupnext:null,
	popuptitle:null,
	popupbody:null,
	show:function(obj,e) {
		if (!obj) return;
		calendar.init(obj);
		calendar.popupcontainer.style.display = "block";
		if (e) {
			calendar.getMouse(e);

			with(calendar.popupcontainer.style) {
				left = (window.mouseX-calendar.popupcontainer.offsetWidth)+"px";
				top = window.mouseY+10+"px";
			}
		}
		ifrlayer.make(calendar.popupcontainer);
	},
	hide:function() {
		calendar.popupcontainer.style.display = "none";
		ifrlayer.kill(calendar.popupcontainer);
	},
	init:function(obj) {
		calendar.initialised=true;
		if (window.monthArr) calendar.monthArr = monthArr;
		calendar.actualDate = (window.actualDate) ? window.actualDate : new Date();
		var a,i,opt,minval,maxval,x,div;
		while(obj && obj.getElementsByTagName("select").length==0) obj = obj.parentNode;
		calendar.popupcontainer = document.getElementById("calendar");
		if (!calendar.popupcontainer) return;
		if (!obj) return;
		var sel = obj.getElementsByTagName("select");

		if (sel.length<2) return;
		calendar.selectDay = sel[0];
		calendar.selectMonthYear = sel[1];
		calendar.selectMonthYear.onclick = calendar.selectDay.onclick = function() { calendar.hide()}
		opt = calendar.selectMonthYear.getElementsByTagName("option");

		maxval = opt[opt.length-1].value;
		calendar.maxMonth = maxval.split("-")[0]-1;
		calendar.maxYear = maxval.split("-")[1];
		minval = opt[0].value;
		calendar.minMonth = minval.split("-")[0]-1;
		calendar.minYear = minval.split("-")[1];

		x=calendar.popupcontainer;
		div = x.getElementsByTagName("div");
		for (i=0; i<div.length; i++) {
			switch(div[i].className.toLowerCase()) {
				case "entete" :
					a=div[i].getElementsByTagName("a");
					for (var j=0; j<a.length; j++) {
						switch(a[j].className.toLowerCase()) {
							case "arrow-prev" :
								calendar.popupprev = a[j];
								calendar.popupprev.onclick = function() {
									calendar.goMonth(-1);
									return false;
								}
								break;
							case "arrow-next" :
								calendar.popupnext = a[j];
								calendar.popupnext.onclick = function () {
									calendar.goMonth(1);
									return false;
								}
								break;
							case "title" :
								calendar.popuptitle = a[j];
								calendar.popuptitle.onclick= function() {
									return false;
								}
								break;
						}
					}
					break;
				case "corps" :
					calendar.popupbody = div[i].getElementsByTagName("tbody")[0];
					break;
			}
		}
		var day = calendar.selectDay.options[calendar.selectDay.selectedIndex].value;
		day = (parseInt(day)<10) ?"0"+day : day;

		var my = calendar.selectMonthYear.options[calendar.selectMonthYear.selectedIndex].value;
		calendar.date = new Date(my.split("-")[0]+ "/" + day + "/" + my.split("-")[1]);
		calendar.tmpDate = new Date(calendar.date.getTime());

		calendar.generateDates();
	},
	goMonth:function(incr) {
		calendar.tmpDate.setMonth(calendar.tmpDate.getMonth()+incr);
		var d = new Date(calendar.tmpDate.getTime());
		d.setDate(1);
		var max = new Date(calendar.maxMonth+1+"/01/"+calendar.maxYear);
		var min = new Date(calendar.minMonth+1+"/01/"+calendar.minYear);

		if (d.getTime()>max.getTime()) calendar.tmpDate.setMonth(calendar.tmpDate.getMonth()-1);
		if (d.getTime()<min.getTime()) calendar.tmpDate.setMonth(calendar.tmpDate.getMonth()+1);
		calendar.generateDates();
	},
	generateDates:function() {
		x = calendar.popupbody;
		while(x.childNodes.length>0) x.removeChild(x.childNodes[0]);
		var d=new Date(calendar.tmpDate.getTime());
		d.setDate(1);
		var month = d.getMonth();

		var firstdaypassed = false;
		while(d.getMonth()==month) {
			var tr = calendar.popupbody.appendChild(document.createElement("tr"));
			for (var i=0; i<7; i++) {
				var td = tr.appendChild(document.createElement("td"));
				if (i==(d.getDay()-1>=0 ? d.getDay()-1 : 6)) firstdaypassed=true;
				if (firstdaypassed)  {
					if (d.getMonth()==month) {
						td.innerHTML = d.getDate();
						td.className = (d.getTime()<calendar.actualDate.getTime()) ? "past" : "";
						if (d.getTime()==calendar.actualDate.getTime()) td.className="present";
						d.setDate(d.getDate()+1);
					}
					td.onclick = function() {
						calendar.tmpDate.setDate(parseInt(this.innerHTML));
						calendar.selectDay.selectedIndex = calendar.tmpDate.getDate()-1;
						var opt = calendar.selectMonthYear.getElementsByTagName("option")
						for (var i=0; i<opt.length; i++) {
							var strMonth = (calendar.tmpDate.getMonth()<9) ? "0" : "";
							opt[i].selected = (opt[i].value == strMonth+(calendar.tmpDate.getMonth()+1) +"-"+ calendar.tmpDate.getFullYear()) ? "selected" : "";
						}
						calendar.hide();
					}
				}
			}
		}
		calendar.popuptitle.innerHTML = calendar.monthArr[calendar.tmpDate.getMonth()] + " " + calendar.tmpDate.getFullYear();
	},
	/*Generics Methods*/
	getMouse:function(e){
		var x,y; var elt = (navigator.userAgent.indexOf("MSIE 5")!=-1) ? document.getElementsByTagName("body")[0] : document.documentElement;
		if ( document.captureEvents ) {
			x = e.pageX;
			y = e.pageY;
		} else if ( window.event.clientX ) {
			x = window.event.clientX+elt.scrollLeft;
			y = window.event.clientY+elt.scrollTop;
		}
		window.mouseX = x;
		window.mouseY = y;
	}
 }
 
/* ******** actuality functions ***************** */
/* ********************************************** */
 
 
/* $: shortcut for document.getElementById*/
function $(obj) {
	if(typeof obj == "string") {
		return document.getElementById(obj);
	} else {
		return obj;
	}
}

/*
show / hide actuality block And check URL 
each div have to be identified with
init_ and the block number for the list block
all_ and the block number for the total block
ex:
<div id="init_1">exemple text</div>
<div id="all_1">full text</div>

cf. actualites_statique.jsp for more exemples

from home use ?block_id= and the block number#and the block number to open
ex : ?block_id=1#1
*/

bloc={
	show:function(id){
		var b1=$('init_'+id);
		var b2=$('all_'+id);
		b1.className=b1.className.replace(/shown/g,'hidden');
		b2.className=b2.className.replace(/hidden/g,'shown');
	},
	
	hide:function(id){
		var b1=$('init_'+id);
		var b2=$('all_'+id);
		b1.className=b1.className.replace(/hidden/g,'shown');
		b2.className=b2.className.replace(/shown/g,'hidden');
	},
	
	checkUrl:function(){
		var get = getQueryString();
		if (get.length>0){
			for (i=0;i<get.length;i++){
				if (get[i][0] == 'block_id'){
					bloc.show(get[i][1]);
				}
			}
		}
	}
}

function getQueryString(){
	var tab_args=[];
	var temp=[];
	var tab_elts=[];
	var requete=location.search.substring(1);
	var tab_paires=requete.split("&");
	
	for(var i = 0; i < tab_paires.length; i++) {
		temp = tab_paires[i].split("=");
		tab_elts[i] = new Array(temp[0], unescape(temp[1]));
	}
	
	return tab_elts;
}

//Add Events
function addEvent( obj, type, fn ) {
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function init(){
	bloc.checkUrl();
}

addEvent(window,'load',init)

