//LANCEMENT DES FONCTIONS
function init(){
	loadFontSize(); 
}

// Affiche/vide la "value" des "input text" sur un Focus //////////////////
function focus_input(ident)		{ ident.value = ""; }
function blur_input(ident,val)	{ if (ident.value == "") ident.value=val; }

//////////////////////////////////
// EXPAND/COLLAPSE inc_menu_rub
//////////////////////////////////
function expand_all(obj,type) {
	// type = expand
	if (type == 'expand') {
		var newClass = 'expand_moins';
		var newStyle = 'block';
	// type = collapse
	} else {
		var newClass = 'expand_plus';
		var newStyle = 'none';
	}
	// Si obj = ALL : Toutes les listes arbo de la page
	if (obj == 'all') {
		if (document.all)	var root = document.all;
		else				var root = document.getElementsByTagName("*");
		for (var i=0; i<root.length; i++){
			if (root[i].className == 'parent_root') {
				if (document.all)	var newroot = root[i].all;
				else				var newroot = root[i].getElementsByTagName("*");
				root[i+1].style.display = 'block';
				for (var y=0; y<newroot.length; y++) {
					if (newroot[y].tagName == "LI" && newroot[y].className !="child_root") 	newroot[y].style.display = newStyle;
					if (newroot[y].tagName == "UL") 										newroot[y].style.display = newStyle;
					if (newroot[y].tagName == "SPAN" && newroot[y].className !="hide")		newroot[y].className = newClass;
				}
			}
		}
	// Sinon uniquement La liste arbo dont l'ID = obj
	} else {
		var root = document.getElementById(obj);
		var parent = document.getElementById('expand_'+obj);
		root.style.display = newStyle;
		parent.className = newClass;
		root = root.getElementsByTagName("*");
		for (var i=0; i<root.length; i++){
			if (root[i].tagName == "LI") 	root[i].style.display = newStyle;
			if (root[i].tagName == "UL") 	root[i].style.display = newStyle;
			if (root[i].tagName == "SPAN")	root[i].className = newClass;
		}
	}
	// Affiche tjs le bouton à la racine
	for (var i=0; i<root.length; i++){
		if (root[i].className == 'child_root') {
			root[i+1].style.display = 'block';
		}			
	}
}
function expand(obj) {
	var root = document.getElementById(obj);
	var parent = document.getElementById('expand_'+obj);
	if (root.style.display != 'block') {
		parent.className = 'expand_moins';
		var newStyle = 'block';
	} else {
		parent.className = 'expand_plus';
		var newStyle = 'none';
	}
	root.style.display = newStyle;
	for (var i=0; i<root.childNodes.length; i++) {
		if (root.childNodes[i].nodeName == "LI") root.childNodes[i].style.display = newStyle;
	}
}

////////////
// FONT SIZE
////////////////////////////////////////////////////////////////
var fsBase			= 11;
var fsMax			= 16;
var fsMin 			= 9;
function fsTag()	{ return document.getElementById('content'); }

// affectation FONT-SIZE to fsTag
function loadFontSize() {
	if (readCook('cookie_font')) fsTag().style.fontSize = readCook('cookie_font')+'px'; 
	else fsTag().style.fontSize = fsBase+'px'; 
}
// reduire
function reduire() {
	var fsPx = fsTag().style.fontSize;	
	var fsSize = fsPx.substring(0,2);
	var fsSize = parseInt(fsSize)-1;
	if(fsSize < fsMin) {
		alert('Taille minimum');
		return;
	}
	fsTag().style.fontSize = fsSize+'px';
	setCook('cookie_font',fsSize);
}
// augmenter
function augmenter() {
	var fsPx = fsTag().style.fontSize;	
	var fsSize = fsPx.substring(0,2);
	var fsSize = parseInt(fsSize)+1;
	if(fsSize >= fsMax) {
		alert('Taille maximale');
		return;
	}
	fsTag().style.fontSize = fsSize+'px';
	setCook('cookie_font',fsSize);
}
// normal
function normal() {
	fsTag().style.fontSize = fsBase+'px';
	setCook('cookie_font',fsBase);
}
// GESTION DU COOKIE
function setCook(nom,valeur) {
	document.cookie = escape(nom) + "=" + escape(valeur) + "; path=/";	
}		
function getCook(nom) {
	deb=document.cookie.indexOf(nom+"=");
	if(deb>=0) {
		deb=nom.length+1;
		fin=document.cookie.indexOf(";",deb)
		if(fin<0) fin=document.cookie.length;
		return unescape(document.cookie.substring(deb,fin));
	}
	return "";	
}
function readCook(nom) {
	var arg = nom+"=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null; 
}
function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr)); 
}		  			
	   