//OBJET GRAPHE************************************************************************************************
function Graphe()
{
	this.Indice=0;
	this.Liste=new Array();
}
Graphe.prototype.Ajouter=_Graphe_ajouter;
Graphe.prototype.GetIndice=_Graphe_indice;
function _Graphe_indice(o)
{
	var i=0;var j=-1;
	while((i<_Root.Liste.length)&&(j==-1))
	{
		if(this.Liste[i].Id==o){j=i;}
		i++;
	}
	return j;
}
function _Graphe_ajouter(o)
{
	this.Liste[this.Indice]=o;
	this.Indice++;
}


//OBJET NODE***************************************************************************************************
function node(lib,idPath,parent,niv)
{
	this.Id=idPath;
	this.Level=niv;
	this.Pere=parent;
	this.Libelle=lib;
	this.Visible=false;
	this.IsCourant=false;

	if((idPath.indexOf("www.")>-1)||(idPath.indexOf("http")>-1))
	{this.Chemin=idPath;}
	else
	{this.Chemin=top._BaseHref+"pages/"+idPath;}
	
	this.Color="";
	this.Image1="";
	this.Image2="";
	this.Image3="";	
	if(arguments[4])
	{
		var tmp=arguments[4].split(";");
		this.Color=tmp[0];
		this.Image1=tmp[1];
		this.Image2=tmp[2];
		this.Image3=tmp[3];
	}	
	this.Racine=_Root;
	this.Racine.Ajouter(this);
}
node.prototype.IsPere=_Node_IsPere;
node.prototype.IsBaisser=_Node_IsBaisser;
node.prototype.TopParent=_TopParent;
function _Node_IsPere()
{
	var i=0;
	var res=false;
 
	for(i=0;i<this.Racine.Liste.length;i++)
	{ 
		if(this.Racine.Liste[i].Pere==this.Id)
		{res=true;} 
	}
	return (res);
}
function _Node_IsBaisser()
{
	var i=0;
	var res=false;
	for(i=0;i<this.Racine.Liste.length;i++)
	{ 
		if(this.Racine.Liste[i].Pere==this.Id)
		{
			if(this.Racine.Liste[i].Visible==true)
			{res=true;}
		} 
	}
	return (res);
}
function _TopParent()
{
	var i=0;
	var j=0;
	
	for(i=0;i<this.Racine.Liste.length;i++)
	{
		if(this.Racine.Liste[i].Id==this.Id)
		{j=i;}		
	}

	while(j>=0)
	{
		if (this.Racine.Liste[j].Pere=="")
		{
			i=j;
			j=-1;
		}
		j--;
	}

	return i;
}

//VARIABLES GLOBALES******************************************************************************************
var _Root=new Graphe();
var _IsFirstLoad=true;
var _Actualiser=true;
var _SecuriseActive=false;
var _SecurisePageId="";
var chemBase=""+top.location;
var _BaseHref=chemBase.substring(0,chemBase.lastIndexOf("/",chemBase.length)+1,chemBase.length);
var _MyNav=new Navigateur();
var _Precedent = new Array(); //Tableaux des fiches précédentes
var _Suivant = new Array(); //Tableaux des fiches suivantes
var _PrSv=false;
var _QueryString;
		
//FONCTIONS DU NOYAU******************************************************************************************
function LoadWithOtherPage(file)
{
	Load();
	top.frcontenu.location=top._BaseHref+"pages/"+file;
}

function Load()
{
	
	if(_IsFirstLoad)
	{
 		top._Actualiser=true;
		top._IsFirstLoad=false;
		
		var url="";
		if(Load.arguments[0])
		{url=top._BaseHref+"pages/"+Load.arguments[0];}
		else
		{url=_Root.Liste[0].Chemin;}
		
		if(top.IsUrl(url))
		{GoUrl(url);}
		else
		{frcontenu.location=url;}
	}
}

function NomFile(loc)
{nomFile(loc);}
function nomFile(loc)
{	
	var monLoc="";
	var diese=-1,intero=-1;
	monLoc=""+loc;
	diese=monLoc.indexOf("#");
	if (diese>-1)
	{monLoc=monLoc.substring(monLoc.lastIndexOf("/",diese)+1,diese);}
	else
	{monLoc=monLoc.substring(monLoc.lastIndexOf("/",monLoc.length)+1,monLoc.length);}
	intero=monLoc.indexOf("?");
	if (intero>-1)
	{monLoc=monLoc.substring(0,monLoc.lastIndexOf("?"));}
	return monLoc;
}

function Raz()
{
	var i=0;
	for(i=0;i<_Root.Liste.length;i++)
	{ 
		if(_Root.Liste[i].Pere=="")
		{_Root.Liste[i].Visible=false;} 
		else
		{_Root.Liste[i].Visible=false;} 
		_Root.Liste[i].IsCourant=false;
	}
}

function AllDesactivate()
{
	var i=0;
	var fini=false;
	Raz();
	for(i=0;i<_Root.Liste.length;i++)
	{ 
		if(_Root.Liste[i].Pere=="")
		{_Root.Liste[i].Visible=true;}
	}
}

function Show(id)
{show(id);}

function show(id)
{
	var i=0;
	var idCur="";
	var fini=false;

	if(top._SecuriseActive==true)
	{
		top._SecuriseActive=false;
		AllDesactivate();
		idCur=_Root.GetIndice(id);
		_Root.Liste[idCur].IsCourant=true;
		_Root.Liste[idCur].Visible=true;
		ShowOnglet();
		ShowMenu();
	}
	else
	{
		if(top._Actualiser==true)
		{ 
			Raz();
			idCur=id;

			while(!fini)
			{ 						
				for(i=0;i<_Root.Liste.length;i++)
				{ 	
					if(_Root.Liste[i].Id==id)
					{_Root.Liste[i].IsCourant=true;}
					if(_Root.Liste[i].Pere==idCur)
					{_Root.Liste[i].Visible=true;} 
				}
				if(idCur=="")
				{fini=true;}
				else
				{idCur=_Root.Liste[_Root.GetIndice(idCur)].Pere;}
			}
			ShowOnglet();
			ShowMenu();
		}
		else 
		{top._Actualiser=true;}
	}
}



//FONCTIONS PRECEDENT-SUIVANT******************************************************************************************
function Precedent()
{top.frcontenu.history.go(-1);}
function Suivant()
{top.frcontenu.history.go(1);}

 //GESTION LIENS HTTP***********************************************************************************************************************
function IsUrl(url)
{
	if (url.indexOf(top._BaseHref)>-1)
	{return false;}
	else
	{
		if (url.indexOf(top.URLDecode(top._BaseHref))>-1)
		{return false;}
		else
		{return true;}
	}
}

function GoUrl(url)
{
	top.Show(url);	
	top.frcontenu.location=url;
}

function URLDecode(str)
{
var HEXCHARS = "0123456789ABCDEFabcdef"; 
var encoded = str;
var plaintext = "";
var i = 0;

	while (i < encoded.length)
	{
		var ch = encoded.charAt(i);
		if (ch == "+")
		{
			plaintext += " ";
			i++;
		}
		else if (ch == "%")
		{
			if (i < (encoded.length-2) && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 )
			{
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			}
			else
			{
				plaintext += "%[ERROR]";
				i++;
			}
		}
		else
		{
			plaintext += ch;
			i++;
		}
	}
   return plaintext;
}

function Navigateur()
{
	this.Name="";
	this.Version=0;
	this.Resolution=screen.width;
	var agent=navigator.userAgent;
	
	
	if(agent.indexOf('Netscape/7')>-1)
	{this.Name="NS";this.Version=7;}
	if(agent.indexOf('Netscape6/6')>-1)
	{this.Name="NS";this.Version=6;}
	if(agent.indexOf('Mozilla/4')>-1)
	{this.Name="NS";this.Version=4;}
	if(agent.indexOf('Firefox/0.9')>-1)
	{this.Name="Firefox";this.Version=0.9;}
	if(agent.indexOf('Firefox/1')>-1)
	{this.Name="Firefox";this.Version=1;}
	if(agent.indexOf('MSIE 6')>-1)
	{this.Name="IE";this.Version=6;}
	if(agent.indexOf('MSIE 5')>-1)
	{this.Name="IE";this.Version=5;}
	
}


function SeachImage(imgId)
{	
	if (_MyNav.Name == 'ns4')  {return Ns4ImageById(imgId);}
	if (_MyNav.Name == 'ns6')  {return document.getElementById(imgId);}
	if (_MyNav.Name == 'ie4')  {return eval('document.all.'+ imgId);}
	if (_MyNav.Name == 'ie5')  {return document.getElementById(imgId);}
	if (_MyNav.Name == 'ie6')  {return document.getElementById(imgId);}
	return false;
}

function Ns4ImageById(imgId,me)
{
	var foundIt = false;
	var whereAmI = (me) ? me : document;
		
	if (whereAmI.images[imgId])
	{return whereAmI.images[imgId];}
	
	for (var i=0; i<whereAmI.layers.length; i++) 
	{
		if (whereAmI.layers[i].document.images)
		{foundIt = Ns4ImageById(imgId,whereAmI.layers[i].document);}
		if (foundIt)
		{return foundIt;}
	}
	return null;
}

function Redirect(file)
{
	if(top._BaseHref)
	{this.location=top.BaseHref+"pages/"+file;}
	else
	{this.location=file;}
}