var ThisUrl;
function LogonUser()
{						
	var h=top.location.href;
	var Pt=h.indexOf("AccessDenied.asp") ;
	if (Pt == -1) Pt=h.indexOf("Login.asp") ;
	if (Pt == -1)
		top.location="/Library/Login/Login.asp?" + h ;
	else
	{
		Pt=h.indexOf("?") ;
		top.location="/Library/Login/Login.asp?" + h.substring(Pt+1) ;		
	}
}

Cookies =
{
	save :	function(name,value,days)
	{
		if (days) 
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000))
			var expires = "; expires="+date.toGMTString()
		}
		else expires = ""
		document.cookie = name+"="+value+expires+"; path=/"
	},

	read :	function(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		if (ca) for(var i=0;i<ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},

	erase :	function(name) 
	{
		document.cookie = name+"=; expires=-1; path=/";
	},

	clear :	function() 
	{
		var ca = document.cookie.split(';');
		for(var i=0;i<ca.length;i++)
		{
			var c=ca[i].substring(0, ca[i].indexOf("=")) ;
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			document.cookie = c+"=; expires=-1; path=/";
		}
	}
}

Profile =
{
	defaultValue:function (name)
	{
		switch (name)
		{
			case "css"	: return "Default";	// feuille de style par défaut
			case "pw" 	: return "100" ;	// largeur par défaut de la page (pw=page width)
			case "s3d"	: return "1" ;		// Effets 3D
			case "zf"	: return "1" ;		// Facteur de zoom
			case "ac"	: return "1" ;		// AutoComplete
			default		: return "" ;
		}
	},

	read :	function (name)
	{
		var nameEQ = name + ":";
		var p=Cookies.read("Profile");
		if (p)
		{
			var ca=p.split(',');
			for (var i=0; i<ca.length; i++)
			{
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
		}
		return Profile.defaultValue(name) ;
	},

	save :	function (name, value)
	{
		var nameEQ = name + ":";
		var p=Cookies.read("Profile");
		if (p)
		{
			var ca=p.split(',');
			for (var i=0; i<ca.length; i++)
			{
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0)
				{
					ca[i]=nameEQ + value;
					p=ca.join(",");
					Cookies.save("Profile", p, 365);
					return ;
				}
			}
			Cookies.save("Profile", p+nameEQ+value+",", 365) ;
		}
		else Cookies.save("Profile", nameEQ+value+",", 365) ;
	}
}

/*
function GetCss()
{
	var css;

	if ( Profile.read("dm")=="1")	// nouvelle version
	{
        if ( typeof(CssPrint)== "undefined") css=Profile.read("css"); else css="Print";
//		css = "/Library/Styles/" + css + "/Style.css";
		css = "/Library/NewStyles/" + css + "/Style.asp";
		if ( Profile.read("s3d")!="1" ) css = css + "?flat=1"
		document.write('<link rel="stylesheet" href="' + css + '" type="text/css">') ;
	}
	else
	{
	        if ( typeof(CssPrint)== "undefined") css=Cookies.read("css"); else css="Print";
		if (css==null || css=="") css="Default" ;
	        if (css=="Grey")
			document.write('<link rel="stylesheet" href="/Library/Styles/Grey/Style.asp" type="text/css">') ;
		else
			document.write('<link rel="stylesheet" href="/Library/Styles/'+css+'/Style.css" type="text/css">') ;
	}
}

function SetCss(Name)
{
	Cookies.save("css",Name,365)
	location = location;
}
//GetCss() ;
*/

// Xiti
function XitiPageName()
{
	var PageName=location.href ;
	var Pt=PageName.indexOf("/", 10) ;
	if ( Pt == -1 || Pt==PageName.length-1) 
		PageName="Default.asp" ;
	else
		PageName=PageName.substr(Pt+1);

	Pt=PageName.indexOf("?");
	if ( Pt != -1 ) PageName=PageName.substr(0, Pt) ;

	PageName=PageName.replace(/\//g, "_");
	if ( PageName.substr(PageName.length-1) == "_" ) PageName=PageName + "Default.asp";
	PageName=PageName.toLowerCase() ;
	return PageName ;
}

var PageName=XitiPageName();

function MainPage()
{
   return (top.location == self.location) ? ThisUrl : top.frames[2].ThisUrl;
}

function PrintPage()
{
   var h=MainPage();
   if (h.indexOf("?") == -1) h+="?bqPrint=1"; else h+="&bqPrint=1" ;
   window.open(h,'_blank','directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=yes,copyhistory=no');  
}

function EmailPage()
{
   var h=MainPage();
   var title=(top.location == self.location) ? document.title : top.frames[2].document.title;
   h=escape(h);
   title=escape(title);
   h="mailto:?subject=" + title + "&body=%0D%0A" + h
h=h.replace(/\//g, "%2F");
   top.location=h
}

function Bookmark() 
{
   if (window.external)
   {
      var h=MainPage();
      var title=(top.location == self.location) ? document.title : top.frames[2].document.title;
      window.external.AddFavorite(h, title) ;
   }
   else
      alert("L'ajout automatique de signets n'est pas disponible.\nUtilisez les options de votre navigateur pour ajouter cette page à vos favoris.");
}

function CheckFrame()
{
	var h=self.location + "";
	var Pt, Pt2
	var Server, Folder, Page;
	var Type, FrameSet;
    var topLocation="";
    
// Extraie le nom du serveur, le dossier et le chemin de la page en cours
// ----------------------------------------------------------------------
	Pt=h.indexOf("://");
	Pt=h.indexOf("/", Pt+3);
	Pt2=h.indexOf("/", Pt+1);

    Server=h.substring(0, Pt+1);
	Folder=h.substring(Pt+1, Pt2);

	Page=h.substring(Pt2+1, h.length);
	Pt=Page.indexOf("?")
	if (Pt != -1) Page=Page.substring(0, Pt);
	Page=Page.toUpperCase();

// Détermine si la page est une page normale (1) ou un frame du site Bdsp (2)
// --------------------------------------------------------------------------
    Type=1
	switch (Folder.toUpperCase())
	{
		case "COLLOQUES":
		case "EMPLOI":
		case "RE":
		case "TSP2":
		case "TSP3":
		case "WEBS": 
		   if (Page!="" && Page.toUpperCase()!="DEFAULT.ASP") Type=2;
		break;
	   case "":
	      switch (Page)
	      {
				case "NEWS.ASP": Type=2; break;
	      }
	}	

// Détermine si la page est pleine page (0), dans un frameset bdsp(1) ou dans un autre frameset(2)
// -----------------------------------------------------------------------------------------
    try
    {
        topLocation=top.location.toString();
    }
    catch(e) { }
    
    if (topLocation=="" || topLocation == h)
	   FrameSet=0;
	else
	{
		h=topLocation;
		h=h.toUpperCase();
		if (h.substring(0, Server.length) == Server.toUpperCase()) FrameSet=1; else FrameSet=2;
	}

// Affiche la page correctement si nécessaire
// ------------------------------------------
   if (parent.location==top.location)
   {
		if ( Type==2 && (FrameSet==0 || FrameSet==2) )
		{
	//		alert("Folder="+Folder+", Type="+Type+", FrameSet="+FrameSet + "\n\nTop.location=" + Server + Folder + "?Frame=" + self.location) ;
			h=Server + Folder + "/Default.asp";
			if (Page.toUpperCase()!="TOP.ASP") h+="?Frame=" + escape(self.location) ;
			if (document.images) top.location.replace(h); else top.location=h;
			return;
		}
		if (Type==1 && FrameSet==2)
		{
			alert("Server="+Server+", Folder="+Folder+", Type="+Type+", FrameSet="+FrameSet + "\n\nTop.location=" + self.location);
//			if (document.images) top.location.replace(self.location); else top.location=self.location;
			return;
		}
	//   alert("Folder="+Folder+", Type="+Type+", FrameSet="+FrameSet + "\n"+ self.location + "\n\nOK");
	}
}
