/****************************************/
/*	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.Id=this.Id.toLowerCase();
	this.Level=niv;
	this.Pere=parent;
	if((idPath.indexOf("www.")>-1)||(idPath.indexOf("http")>-1))
	{this.Chemin=idPath;}
	else
	{this.Chemin=_App.BaseHref+"pages/"+idPath;}
	this.Chemin=this.Chemin.toLowerCase();
	this.Libelle=lib;
	this.Visible=false;
	this.IsCourant=false;

	if(arguments[4])
	{this.Protect=true;}
	else
	{this.Protect=false;}

	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;
}


/****************************************/
/*	OBJET APPLICATION					*/
/****************************************/
function Application()
{
	//Url de base du site
	this.BaseHref=top.location.href.substring(0,top.location.href.lastIndexOf("/",top.location.href.length)+1,top.location.href.length);
	
	//Infos sur navigateur
}
Application.prototype.RefreshMenus=top.Application_RefreshMenus;

Application.prototype.AutoFitFrameContenu=Application_AutoFitFrameContenu;
function Application_AutoFitFrameContenu(doc)
{
	top.document.getElementById("frame_contenu").style.height=(doc.body.scrollHeight+10)+"px";
}

Application.prototype.Start=Application_Start;
function Application_Start()
{
	var tb=this.GetQueryStringFromUrl(top.location.href);
	if(tb["aspx"])
	{
		this.PrepareMenusFromId("../_aspx/"+tb["aspx"]+".aspx");
		frame_contenu.location="_aspx/"+tb["aspx"]+".aspx";
	}
	else if(tb["p"])
	{
		frame_contenu.location="pages/"+tb["p"];
	}
	else
	{frame_contenu.location=_Root.Liste[0].Chemin;}
}


Application.prototype.GetFileNameFromUrl=Application_GetFileNameFromUrl; //Nom du fichier dans une url
function Application_GetFileNameFromUrl(url)
{
	var monLoc="";
	var diese=-1;
	monLoc=""+url;
	diese=monLoc.indexOf("#");
	if (diese>-1)
	{return(monLoc.substring(monLoc.lastIndexOf("/",diese)+1,diese));}
	else
	{return(monLoc.substring(monLoc.lastIndexOf("/",monLoc.length)+1,monLoc.length));}
}

Application.prototype.GetQueryStringFromUrl=Application_GetQueryStringFromUrl; //Découpage des paramètres dans une url
function Application_GetQueryStringFromUrl(url)
{
	var pos1=url.indexOf("?");
	var tabs=new Array();
	if(pos1>-1)
	{
		url=url.substring(pos1+1,url.length);
		var separator="";	
		if(url.indexOf("&")>-1)
		{
			separator="&";
		}
		else if(url.indexOf("%26"))
		{
			separator="%26";
		}			
		var tmp=new Array();
		tmp=url.split(separator);
		for(i=0;i<tmp.length;i++)
		{
			var tmp2=new Array();
			tmp2=tmp[i].split("=");
			tabs[tmp2[0]]=tmp2[1];
		}
	}
	return tabs;
}

Application.prototype.IsUrlInCurrentSite=Application_IsUrlInCurrentSite;
function Application_IsUrlInCurrentSite(url)
{
	if (url.indexOf(this.BaseHref)>-1)
	{return false;}
	else
	{
		if (url.indexOf(this.UrlDecode(this.BaseHref))>-1)
		{return false;}
		else
		{return true;}
	}
}

Application.prototype.UrlDecode=Application_UrlDecode;
function Application_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;
}

Application.prototype.RemiseAZero=Application_RemiseAZero;
function Application_RemiseAZero()
{
	var i=0;
	for(i=0;i<_Root.Liste.length;i++)
	{ 
		_Root.Liste[i].Visible=false;
		_Root.Liste[i].IsCourant=false;
	}
}

Application.prototype.PrepareMenusFromId=Application_PrepareMenusFromId;
function Application_PrepareMenusFromId(id)
{
	var i=0;
	var idCur="";
	var fini=false;

	this.RemiseAZero();
	idCur=id.toLowerCase();
	while(!fini)
	{ 
		for(i=0;i<_Root.Liste.length;i++)
		{ 
			if(_Root.Liste[i].Id.toLowerCase()==id.toLowerCase())
			{_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;}
	}
	this.RefreshMenus();
}


/****************************************/
/*	VARIABLES GLOBALES					*/
/****************************************/
var _Root=new Graphe();
var _App=new Application();

