// JavaScript Document
//----------------------------------------------------------------------------------
// SCRIPTS DE GESTION DE COOKIES
// Attention: Ne pas modifier ces fonctions
// La personnalisation se fait dans les scripts d'appel de ces fonctions
//----------------------------------------------------------------------------------
function EcrireCookie(nom, valeur)
{
   var argv=EcrireCookie.arguments;
   var argc=EcrireCookie.arguments.length;
   var expires=(argc > 2) ? argv[2] : null;
   var path=(argc > 3) ? argv[3] : null;
   var domain=(argc > 4) ? argv[4] : null;
   var secure=(argc > 5) ? argv[5] : false;
   document.cookie=nom+"="+escape(valeur)+
      ((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
      ((path==null) ? "" : ("; path="+path))+
      ((domain==null) ? "" : ("; domain="+domain))+
      ((secure==true) ? "; secure" : "");
}

function SupprimeCookie(nom) { 
     var expire = new Date (); 
     expire.setTime (expire.getTime() - (24 * 60 * 60 * 1000)); 
     document.cookie = name + "=; expires=" + expire.toGMTString(); 
}

function getCookieVal(offset)
{
   var endstr=document.cookie.indexOf (";", offset);
   if (endstr==-1) endstr=document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(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 voirCookies() {
	xmenu=LireCookie("alpiMenuCAUE40");
	alert(xmenu);
}
//-- FONCTION INITALISATION MENU SELON CLICK INTERNAUTE
// xxthemes => variable déclaré dans la page
function initMenu() {
	xmenu=LireCookie("alpiMenuCAUE40");
	xtheme=LireCookie("alpiMenuCAUE40Theme");
	//alert("xxtheme="+xxthemes+"xtheme="+xtheme+"\nxmenu="+xmenu) ;
	if (xxthemes!=xtheme) {
		SupprimeCookie("alpiMenuCAUE40") ;
	}
	if (xmenu!=null) {
		//voirCookies() ;
		montreSubInit(xmenu) ;
	}
}
window.onload = initMenu ;
//----------------------------------------------------------------------------------
// 
// FIN SCRIPTS COOKIES AU CHOCO ;)
// 
//----------------------------------------------------------------------------------
function montre(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=nbreMenu; i++) {
			if (document.getElementById('smenu'+i))
			{document.getElementById('smenu'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
}

function montreSub(id) {
	var d = document.getElementById(id);
	if (d) {
		d.style.display='block';
		affecte(id) ;
		}
}

function montreSub2(id) {
	var d = document.getElementById(id);
	if (d) {d.style.display='block';}
}

function montreSubInit(liste) {
	var tabSub = liste.split(".") ;
	var sep = "." ;
	var end = "0" ;
	var tmpSub = tabSub[0]+sep ;
	var tmpSub2 = "" ;
	
	for (i=1;i<tabSub.length-1;i++) {
		if (tmpSub2!="") {
			tmpSub2 = tmpSub2+tabSub[i]+sep ;
		} else {
			tmpSub2 = tmpSub+tabSub[i]+sep ;
		}
		montreSub2(tmpSub2+end) ;
		//document.write(tmpSub2+"<br />") ;
		//document.write(tmpSub2+end+"<br />") ;
	}
}

function affecte(idMenu) {
	//document.fMenu.arbo.value = idMenu ;
	//---- Ecrire le cookie, valide 1 mois
	date=new Date;
	date.setMonth(date.getMonth()+1);
	EcrireCookie("alpiMenuCAUE40", idMenu, date);
}

function memoThemeMenu(idthemes) {
	date=new Date;
	date.setMonth(date.getMonth()+1);
	EcrireCookie("alpiMenuCAUE40Theme", idthemes, date);
}

function rollOverMenuDiv(id, nowClass, foreverClass) {
	identity = document.getElementById(id);
		if (nowClass!=foreverClass) {
				identity.className = foreverClass ;
			} else {
				identity.className = foreverClass+"Hover" ;
			}
}