/* Gestion de l'image de fond  */
function SetCookie (name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.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=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function test(){

//alert(document.cookie);


	if (document.cookie.indexOf("sial=") == -1){
	m = parseInt((Math.random()*7)+1);
img = "/en/2006/00_images/Bandeau_Fille/0"+m+".jpg";
		SetCookie("sial",m);
		new getObj("CadreCentre").obj.style.backgroundImage ="url("+img+")";
	}
	else  {
		nb=document.cookie.substring(document.cookie.indexOf('sial=')+5,document.cookie.indexOf('sial=')+6);
		bandeau="/en/2006/00_images/Bandeau_Fille/0"+nb+".jpg";
		new getObj("CadreCentre").obj.style.backgroundImage ="url("+bandeau+")";
	}
}

/*   */


var tabMenu =[];
var tabTBX =[];
var tabStc = new Array();
var tID='';
var locat = top.document.location.href;
var obSelect;

function cm(id,nom,lien,targe){
	//alert(id);
	this['ob'+id] = new menu(id,nom,lien,targe,'Menu');
}

function csm(id,nom,lien,targe){
	//alert(id);
	this['ob'+id] = new menu(id,nom,lien,targe,'TBX');
}

function menu(id,nom,lien,targe,type){
	this.id = id;
	this.nom = nom;
	this.lien = lien;
	
	if(targe)
		this.targe = "target="+targe;
	else
		this.targe = "";
	this.tabId = this.id.split("_");
	this.type=type;
	this.picto=id;
	
	eval('tab'+type+'['+eval('tab'+type+'.length')+']=this');
}

function traiteUrl(url){
	//alert(url);
	if(url=="") return false;
	else{
		if(url.indexOf(".htm")!=-1 ) {
			url = url.substring(0,url.lastIndexOf("_"));
		}
		if(locat.indexOf(url)==-1 || url=="#") return false;
		else return true;
	}
}

function initMenu(){
	obSelect = getLien('Menu');
	writeNavLeft();
	obSelect = getLien('TBX');
	writeTBX();
}

function getLien(type){
	lienReturn='';
	for(i=0;i<eval('tab'+type).length;i++){
		if(traiteUrl(eval('tab'+type+'[i].lien')) && eval('tab'+type+'[i].targe!="target=_blank"')){ 
			lienReturn = eval('tab'+type+'[i]');
		}
	}
	
	if(lienReturn!='') return(lienReturn);
	else return false;
}



function writeNavLeft(){
	ch='';
	
	if(obSelect==false){
		var adresse = document.location.href; 
		if (adresse.indexOf('news') != -1)
			ch='<img src="/en/2006/g_outils/images/newsletter.jpg" width="156" height="455">';
		if (adresse.indexOf('sialdor') != -1)
			ch='<img src="/en/2006/i_sial_dor/images/sialdor.jpg" width="156" height="234">';
	}
	else{
		//alert(obSelect);
		i=1;
		
		allumNav(obSelect.tabId[0]);
		
		obj = this['ob'+obSelect.tabId[0]];
		ch+='<img src="/en/2006/00_images/Nav_G/'+obj.nom+'">'; //nivo 1 nom image
		while(this['ob'+obSelect.tabId[0]+'_'+i]){
			obj = this['ob'+obSelect.tabId[0]+'_'+i];
			
			if(i==obSelect.tabId[1])
				ch+='<a href="'+obj.lien+'" '+obj.targe+' class="NavGon">'+obj.nom+'</a>';
			else
				ch+='<a href="'+obj.lien+'" '+obj.targe+' class="NavGoff">'+obj.nom+'</a>';

	
			ch+='<div id="PtnavH"><img src="/00_images/pix.gif"></div>';
			i++;
		}
	}
	
	x = new getObj("navG");
	x.obj.innerHTML=ch;

}

function writeTBX(){
	ch='';
	ch+='<div><img src="/00_images/pix.gif" height="5"></div>';

	i=1;
	
	//obj = this['ob'+obSelect.tabId[0]];
	//ch+='<img src="/en/2006/00_images/Nav_G/'+obj.nom+'">'; //nivo 1 nom image
	while(this['obTBX'+i]){
		obj = this['obTBX'+i];
		ch+='<div style="height:11px; width:13px; float:left"><img src="/00_images/picto/'+obj.picto+'.gif" class="picto" height=11></div>';
		
		if(obSelect && 'TBX'+i==obSelect.tabId[0]){
			
			if (obSelect.tabId[0] == 'TBX3') ch+='<a href="'+obj.lien+'" '+obj.targe+' class="navTBXoff">'+obj.nom+'</a>';
			else ch+='<a href="'+obj.lien+'" '+obj.targe+' class="navTBXon">'+obj.nom+'</a>';
		}
		else{
			ch+='<a href="'+obj.lien+'" '+obj.targe+' class="navTBXoff">'+obj.nom+'</a>';
		}
		//ch+='</div>';
		ch+='<div id="separateur" style="clear:both; border-top:1px solid #ffffff;"><img src="/00_images/pix.gif"></div>';
	i++
	}
	
	x = new getObj("navTBX");
	x.obj.innerHTML=ch;

}

function allumNav(id){
	document.images['btn'+id].src = '/en/2006/00_images/Nav_H/btn'+id+'_1.gif';
}
