// JavaScript Document
 /*
tested & OK:
MAC ie5, ns4, ns6
PC ie6, ns4, opera

 IMPORTANT!
si on n'utilise pas de lyrobjs mais qu'on veut se servir de DOM, inclure ça:
<script language="JavaScript" type="text/JavaScript">
DomInit();
</script>

*/
<!--
// *****************************
//util
// *****************************
// pour les browsers qui n'implémentent pas push et pop dans les arrays
function PileObj(anArray)
{
	if (!anArray)
		this.pile = new Array();
	else
		this.pile = anArray;
	this.compteur = this.pile.length - 1;
	
	this.push = PileObjPush;
	this.Push = PileObjPush;
	this.pop = PileObjPop;
	this.Pop = PileObjPop;
	this.Get = PileObjGet;
	this.GetTop = PileObjGetTop;
	this.Set = PileObjSet;
	this.Length = PileObjLength;
	
	return this;
}

function PileObjPush(elem)
{
	this.compteur++;
	this.pile[this.compteur] = elem;
	return this.compteur+1;
}
function PileObjPop()
{
	elem = this.pile[this.compteur];
	this.compteur--;
	return elem;
}
function PileObjGet(index)
{
	return this.pile[index];
}
function PileObjGetTop()
{
	return this.pile[this.compteur];
}
function PileObjSet(index, valeur)
{
	this.pile[index] = valeur;
}
function PileObjLength()
{
	return this.pile.length;
}


// fonction débug
function DisplayNestedArray(theArray)
{
str = "";
for (i=0; i < theArray.length; i++) 
{
	str += "Row"+i+": ";
	for (j=0; j < theArray[i].length; j++) 
		str += theArray[i][j] + ', ';
	str += " \n";
}
alert(str);
}//DisplayNestedArray()
function DisplayArray(theArray)
{
str = "";
for (i=0; i < theArray.length; i++) 
{
	str += i+": "+theArray[i];
	str += " \n";
}
alert(str);
}//DisplayNestedArray()

// ***************************** Browser sniffer
// !! il faut l'activer au moyen de DomInit()
// (ce qui est fait d'office si on creee un lyrobj)
function BrowserCheck()
{
this.version = parseFloat(navigator.appVersion);
this.agent = navigator.userAgent;
this.major = parseInt(this.version);
this.dom = document.getElementById ? true : false ;
this.mac = navigator.userAgent.indexOf("Mac") > -1;
this.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && this.dom) ? true : false ;

this.ie4 = (document.all && !this.dom && !this.opera5) ? true : false ;
this.ie5 = (navigator.appVersion.indexOf("MSIE 5")>-1) && this.dom && !this.opera5;
this.ie6 = (navigator.appVersion.indexOf("MSIE 6")>-1) && this.dom && !this.opera5;
this.ie = this.ie4 || this.ie5 || this.ie6;

this.nsold = (this.agent.indexOf('mozilla') > -1) && (this.agent.indexOf('spoofer') == -1) && (this.agent.indexOf('compatible')== -1) && (this.version <= 4.03);
this.ns4 = (!this.nsold && document.layers && !this.dom) ? true : false ;
this.ns6 = this.dom && parseInt(this.version)>= 5;

this.compatible = this.ie || this.ns4 || this.ns6 || this.opera5;
//alert("version:"+this.version+"  dom:"+this.dom+"  mac:"+this.mac+"  ie:"+this.ie+"  ns4:"+this.ns4+"  ns6:"+this.ns6+"  compatible:"+this.compatible);
return this;
}//BrowserCheck()

// ***************************** DOM 
function DomVars()
{
	if(is.ns4)  
	{
	  doc = "document";
	  sty = "";
	  htm = ".document";
	}
	else if (is.ie)
	{
	  doc = "document.all";
	  sty = ".style";
	  htm = "";
	}
}

function GetLyr (nom)
{
if (is.dom)
	lyr = document.getElementById(nom);
else
	lyr = eval(doc+'["'+ nom + '"]' + sty);
return lyr;
}

function GetMouse(e)
{	// appeler via gestionnaire d'event!
	// retourne la position relative au document (non à la fenetre):
	// tient donc compte du scroll
	if(is.ns4||is.ns6)  
	{
		  xpos = parseInt(e.pageX + window.pageXOffset);  
		  ypos = parseInt(e.pageY + window.pageYOffset);
	}
	else if(is.ie)
	{
		  xpos = event.x + GetHScroll();
		  ypos = event.y + GetVScroll();
		  //alert(xpos+','+ypos);
	}
	else
	{
		  xpos = e.x + GetHScroll();
		  ypos = e.y + GetVScroll();
	}
	var mousepos = new Array(xpos, ypos);
	return mousepos;
}//GetMouse()

function GetWidth()
{
	if(is.ns4 || is.ns6) 
        return innerWidth;
//	else if(is.ie4 || is.ie5) 
	else if(is.ie) 
        return parseInt(document.body.clientWidth);
	else if (is.dom)
		return window.innerWidth;
}

function GetHeight()
{
	if(is.ns4 || is.ns6) 
		return innerHeight;
	else if(is.ie4 || is.ie5) 
		return parseInt(document.body.clientHeight);
	else if (is.dom)
		return window.innerHeight;
}

function FrameDims()

{
	frame_width = GetWidth();
	frame_height = GetHeight();
}

function GetHScroll()
{
	if(is.ie) 
		return document.body.scrollLeft;
	else if(is.ns4  || is.dom) 
		return window.pageXOffset;
}

function GetVScroll()
{
	if(is.ie) 
		return document.body.scrollTop;
	else if(is.ns4 || is.dom) 
		return window.pageYOffset;
}

// obtenir la position d'un element!
function IE_DOM_GetOffsetLeft(el)
{ // !! ne pas employer directement: marche pas pour ns4!!
	var ol = el.offsetLeft;
	while((el = el.offsetParent) != null)
		ol += el.offsetLeft;
	return ol;
} // !! pour ns4, on ne peut obtenir la position que pour les image: voir GetImageOffset()

function IE_DOM_GetOffsetTop(el)
{	// !! voir ci-dessus
	var ot = el.offsetTop;
	while((el = el.offsetParent) != null)
		ot += el.offsetTop;
	return ot;
}

function GetImgRef(imgName)
{	// retourne la reference d'une image
 	if(is.dom)
		imgref = document.getElementById(imgName);
	else
		imgref = MM_findObj(imgName);
	return imgref;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function SetImgSize (nom, w,h)
{
img = GetImgRef(nom);
img.width = w;
img.height = h;
}

// change une image (elle doit etre nommee)
function SwapImage(imgName, imgNewUrl) 
{ 
   x=MM_findObj(imgName);
  if ( x != null )
   { 
		x.src=imgNewUrl;
   }
}

// retourne les left et top d'une image (il faut qu'elle soit nommee)
// (pratique pour situer un endroit dans le flot de la page!)
function GetImageOffset(imgName)
{	
	imgref = GetImgRef(imgName);
	var imgcoords = new Array(0,0);
	if (is.ie4 || is.ie5 || is.dom)	// marche aussi pour dom
	{
		imgcoords[0] = IE_DOM_GetOffsetLeft(imgref);
		imgcoords[1] = IE_DOM_GetOffsetTop(imgref);
	}
	else if (is.ns4)
	{
		imgcoords[0] = imgref.x;
		imgcoords[1] = imgref.y;
	}
	return imgcoords;
}

// indispensable!
// initialise le systeme dom
// LyrObj appelle DomInit(), mais ça peut etre fait ad libitum sans inconvenient...
function DomInit()
{
	is = new BrowserCheck();
	isDONE = true;
	DomVars();
	FrameDims();
}

// cette array sert à empiler les pointeurs de fonctions à exécuter lors d'un mouseMoveEvent
MOUSEMOVE_FUNCTS = new PileObj(); // utiliser .push pour ajouter des fonctions
// exécute lors d'un event toutes les fonctions dont les pointeurs sont dans l'array ci-dessus
function TheMouseMove(e)
{
	for(i=0; i<MOUSEMOVE_FUNCTS.Length(); i++)
		MOUSEMOVE_FUNCTS.Get(i)(e);
	return true;
}
// idem pour mouseDownEvent
MOUSEDOWN_FUNCTS = new PileObj(); 
function TheMouseDown(e)
{
	for(i=0; i<MOUSEDOWN_FUNCTS.Length(); i++)
		MOUSEDOWN_FUNCTS.Get(i)(e);
	return true;
}
// idem pour mouseOverEvent
MOUSEOVER_FUNCTS = new PileObj(); 
function TheMouseOver(e)
{
	for(i=0; i<MOUSEOVER_FUNCTS.Length(); i++)
		MOUSEOVER_FUNCTS.Get(i)(e);
	return true;
}
// idem pour mouseOutEvent
MOUSEOUT_FUNCTS = new PileObj(); 
function TheMouseOut(e)
{
	for(i=0; i<MOUSEOUT_FUNCTS.Length(); i++)
		MOUSEOUT_FUNCTS.Get(i)(e);
	return true;
}

// initialise un gestionnaire d'events au niveau du document
function StartEventCapture(eventname)
{
	switch(eventname)
	{
		case 'mousemove':	
			document.onmousemove = TheMouseMove;
			if(is.ns4||is.ns6) 
				document.captureEvents(Event.MOUSEMOVE);
		break;
		case 'mousedown':	
			document.onmousedown = TheMouseDown;
			if(is.ns4||is.ns6) 
				document.captureEvents(Event.MOUSEDOWN);
		break;
		case 'mouseover':	
			document.onmouseover = TheMouseOver;
			if(is.ns4||is.ns6) 
				document.captureEvents(Event.MOUSEMOVER);
		break;
		case 'mousemove':	
			document.onmouseout = TheMouseOut;
			if(is.ns4||is.ns6) 
				document.captureEvents(Event.MOUSEOUT);
		break;
	}
}

//*********************************** end DOM

//************************************************************************************************
// *****************************
// LyrObj
// *****************************
// objet for cross-browser layer manipulation      ! requires a 'is' BrowserCheck object!
// includes methods for moving, resizing, clipping, show/hide,
// and getting information from layers regardless of the browser or platform


// ***************************** lyrobj initialisation (constructor)

// Call this, store the returned object, then use it for whatever layer manipulation

// Arguments:
// * name: the name of the layer, you bet
// * container: the LyrObj (not just name!) of the nesting layer, if it is nested (0 if not)
// - it means that, obviously, you must create the container's LyrObj before its content's -
// * x, y, width, height: to set the layer location and size. 
// (it is adviced to pass values, even if you want to keep the values of an existing layer,
// for some browsers won't tell you the layer dimensions if they've not been explicitly set)
// visiswitch: -1 to hide the layer, +1 to show it, 0 (or not set) to leave it alone

// Note that lyrobjs should only use 'absolute' positionning: 
// I failed to implement a reliable cross-platform 'relative' behavior. Tell me if you succeeded!

function LyrObj (name, container, x, y, width, height, visiswitch)
{
this.type = 'LyrObj';
this.name = name;
DomInit();
this.container = container ? container : "";
if  (is.ie4||is.ie5) {
this.layer = document.all[name];
}
else if (is.dom) {
this.layer = document.getElementById(name);
}
else if (is.ns4) {
nest = (!container) ? "" : "document."+container.name+".";
this.layer = eval(nest+"document."+name);
}
else {
alert:("this browser appears to be incompatible with some code on this page. Strange things may occur (harmless, though). Sorry...");
}
this.style = (is.dom || is.ie4) ? this.layer.style : this.layer ;

this.WriteContent = LyrWriteContent;
this.Left = GetLyrLeft;
this.Top = GetLyrTop;
this.Right = GetLyrRight;
this.Bottom = GetLyrBottom;
this.Width = GetLyrWidth;
this.Height = GetLyrHeight;
this.MoveTo = MoveLyrTo;
this.MoveBy = MoveLyrBy;
this.SizeTo = SizeLyrTo;
this.SizeBy = SizeLyrBy;
this.Show = ShowLyr;
this.Hide = HideLyr;
this.MoveTo(x,y);
this.SizeTo(width, height);
if (visiswitch == 1) {
  this.Show();
}
else if (visiswitch == -1) {
  this.Hide();
}
var isDONE;
if (!isDONE)
	DomInit(); 
//alert("LyrObj()");
return this;
}//LyrObj()

// ***************************** LyrObj layer manip methods
function MoveLyrTo ( x, y){
this.style.left = x;
this.style.top = y;
}
function MoveLyrBy (x, y){
this.style.left = this.Left() + x;    
this.style.top = this.Top() + y;
}
function HideLyr (){
this.style.visibility = "hidden";
}
function ShowLyr (){
this.style.visibility = "visible";
}
function SizeLyrTo (w, h){
	if(is.ns4)
	{
		w = (w>0) ? w : this.Width();
		h = (h>0) ? h : this.Height();
		this.style.resizeTo(w, h);
	}
	else
	{
		if (w>0) this.style.width = w;
		if (h>0) this.style.height = h;
	}
}
function SizeLyrBy (w, h) {
	if ((this.Width() + w) < 0) w = -(this.Width() );
	if ((this.Height() + h) < 0) h = -(this.Height() );
	if(is.ns4)
	{
		this.style.resizeBy(w, h);
	}
	else
	{
	this.style.width = this.Width()+ w;;
	this.style.height = this.Height() + h;
	}
}
function GetLyrLeft() {
return parseInt(this.style.left);
}
function GetLyrTop() {
return parseInt(this.style.top);
}
function GetLyrRight() {
return parseInt(this.style.left) + parseInt(this.Width());
}
function GetLyrBottom() {
return parseInt(this.style.top) + parseInt(this.Height());
}
function GetLyrWidth() {
if(is.ie)
return parseInt(this.style.pixelWidth);
else if (is.ns4)
return parseInt(this.style.clip.width);
else
return parseInt(this.style.width);
}
function GetLyrHeight() {
if(is.ie)
return parseInt(this.style.pixelHeight);
else if (is.ns4)
return parseInt(this.style.clip.height);
else
return parseInt(this.style.height);
}

function LyrWriteContent(str)
{
if (is.ns4)
{
	this.layer.document.write(str);
	this.layer.document.close();
}
else
	this.layer.innerHTML = str;
		if (is.ie )
	{		
		this.style.width = this.layer.offsetWidth;
		this.style.height = this.layer.offsetHeight;
	}
}

// ****END LyrObj
// *****************************
// LyrGroup
// *****************************
// encapsule un groupe de LyrObjs manipules 'comme un seul',
// et de façon transparente: les methodes sont les meme que pour un lyrobj.

// constructeur: on passe juste une array contenant les lyrobjs deja crees
function LyrGroup (lyrobjS)
{
this.type = 'LyrGroup';
this.lyrS = lyrobjS;

this.Left = GetGroupLeft;
this.Top = GetGroupTop;
this.Right = GetGroupRight;
this.Bottom = GetGroupBottom;
this.Width = GetGroupWidth;
this.Height = GetGroupHeight;
this.MoveTo = MoveGroupTo;
this.MoveBy = MoveGroupBy;
this.SizeTo = SizeGroupTo;
this.SizeBy = SizeGroupBy;
this.Show = ShowGroup;
this.Hide = HideGroup;

return this;
}//LyrGroup()

// ***************************** LyrObj layer manip methods
function MoveGroupTo ( x, y)
{
	numlyrs = this.lyrS.length;
	for (i = 0; i<numlyrs; i++)
		this.lyrS[i].MoveTo( x, y);
}
function MoveGroupBy (x, y)
{
	numlyrs = this.lyrS.length;
	for (i = 0; i<numlyrs; i++)
		this.lyrS[i].MoveBy( x, y);
}
function HideGroup()
{
	numlyrs = this.lyrS.length;
	for (i = 0; i<numlyrs; i++)
		this.lyrS[i].Hide();
}
function ShowGroup ()
{
	numlyrs = this.lyrS.length;
	for (i = 0; i<numlyrs; i++)
		this.lyrS[i].Show();
}
function SizeGroupTo (w, h)
{
	numlyrs = this.lyrS.length;
	for (i = 0; i<numlyrs; i++)
		this.lyrS[i].SizeTo(w, h);
}
function SizeGroupBy (w, h) 
{
	numlyrs = this.lyrS.length;
	for (i = 0; i<numlyrs; i++)
		this.lyrS[i].SizeBy(w, h);
}
function GetGroupLeft() 
{
	numlyrs = this.lyrS.length;
	bord= this.lyrS[0].Left();
	for (i = 1; i<numlyrs; i++)
	{
		newbord= this.lyrS[i].Left();
		if (newbord< bord) bord = newbord;
	}
	return bord;
}
function GetGroupRight() 
{
	numlyrs = this.lyrS.length;
	bord = this.lyrS[0].Right();
	for (i = 1; i<numlyrs; i++)
	{
		newbord = this.lyrS[i].Right();
		if (newbord> bord) bord = newbord;
	}
	return bord;
}
function GetGroupTop() 
{
	numlyrs = this.lyrS.length;
	bord = this.lyrS[0].Top();
	for (i = 1; i<numlyrs; i++)
	{
		newbord = this.lyrS[i].Top();
		if (newbord< bord) bord = newbord;
	}
	return bord;
}
function GetGroupBottom() 
{
	numlyrs = this.lyrS.length;
	bord = this.lyrS[0].Bottom();
	for (i = 1; i<numlyrs; i++)
	{
		newbord = this.lyrS[i].Bottom();
		if (newbord> bord) bord = newbord;
	}
	return bord;
}
function GetGroupWidth() 
{
	return (this.Right() - this.Left());
}
function GetGroupHeight() 
{
	return (this.Bottom() - this.Top());
}
// ****END LyrGroup
//-->