﻿/****************************************/
/*	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()
{
	this.BaseHref=top.location.href.substring(0,top.location.href.lastIndexOf("/",top.location.href.length)+1,top.location.href.length);	
}
Application.prototype.RefreshMenus=top.Application_RefreshMenus;

Application.prototype.GetResolution=top.Application_GetResolution;
function Application_GetResolution()
{
    return screen.width+"*"+screen.height;
}

Application.prototype.GetNodeCourant=Application_GetNodeCourant;
function Application_GetNodeCourant()
{
    var i=0;

	for(i=0;i<_Root.Liste.length;i++)
	{ 
		if(_Root.Liste[i].IsCourant)
		{
		    return i;
		}
	}
    return -1;
}

Application.prototype.GetWindowsHeight=Application_GetWindowsHeight;
function Application_GetWindowsHeight()
{
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number')
    {windowHeight=window.innerHeight;}
    else
    {
        if (document.documentElement&&document.documentElement.clientHeight)
        {windowHeight = document.documentElement.clientHeight;}
        else
        {
            if (document.body&&document.body.clientHeight)
            {windowHeight=document.body.clientHeight;}
        }
    }
    return windowHeight;
        
	/*var h=screen.availHeight-moins;
	top.document.getElementById("frame_contenu").style.height="75%";*/
}	


Application.prototype.AutoFitFrameContenu=Application_AutoFitFrameContenu;
function Application_AutoFitFrameContenu(frameObj,mAdjust)
{ 
    if ((frameObj.contentDocument && (frameObj.contentDocument.body.offsetHeight||frameObj.contentDocument.documentElement.offsetHeight))||frameObj.Document && frameObj.Document.body.scrollHeight)
    {
        var contentHeight=window.opera? frameObj.contentDocument.documentElement.offsetHeight : frameObj.contentDocument? frameObj.contentDocument.body.offsetHeight+mAdjust : frameObj.Document.body.scrollHeight;
        var contentWidth=window.opera? collectWidth(frameObj.contentDocument) : frameObj.contentDocument? frameObj.contentDocument.documentElement.offsetWidth : frameObj.Document.body.scrollWidth;
        var frameWidth=frameObj.offsetWidth;        
        
        if(!window.opera) {frameObj.style.overflow='visible';}        
        frameObj.height = (frameWidth<contentWidth? contentHeight+mAdjust : contentHeight+mAdjust)+"px";
        if (window.opera && (frameWidth>=contentWidth)) {frameObj.contentDocument.body.style.overflow='hidden';}       
        if ((navigator.userAgent.indexOf("Firefox")>-1) && (frameWidth>=contentWidth)) {frameObj.contentDocument.body.style.overflow='hidden';}
    }    
//    if (navigator.userAgent.indexOf("Firefox")>-1)
//    {
//        if(parseInt(frameObj.height)<450)
//        {top.document.getElementById("MasterMenu").style.height="480px";top.document.getElementById("MasterPage").style.height="650px";}
//        else
//        {top.document.getElementById("MasterMenu").style.height=(parseInt(frameObj.height))+"px";top.document.getElementById("MasterPage").style.height=(parseInt(frameObj.height)+160)+"px";}    
//        top.document.getElementById("MasterContent").style.height=top.document.getElementById("MasterPage").style.height;
//    }
}


Application.prototype.Start=Application_Start;
function Application_Start()
{
	var tb=this.GetQueryStringFromUrl(top.location.href);
	if(tb["p"])
	{
	    if (tb["p"]=="plan")
	    {top.document.getElementById("frame_contenu").src="mods/opplugplansite/index.htm";}
	    else if (tb["p"]=="recherche")
	    {
	        document.getElementById("TxtRecherche").value=tb["keys"];
	        top.document.getElementById("frame_contenu").src="mods/opplugjsengine/index.htm";
	    }
	    else
	    {top.document.getElementById("frame_contenu").src="pages/"+tb["p"];}
	}
	else
	{
	    top.document.getElementById("frame_contenu").src=_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 true;}
	else
	{
		if (url.indexOf(this.UrlDecode(this.BaseHref))>-1)
		{return true;}
		else
		{return false;}
	}
}

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();
var pageRedirect="";
var LoadEnabled=true;