
// sous ie5 undefined n'est pas defini 
if (typeof(undefined)=='undefined') var undefined="undefined";


//***************************
function objet_adresse(id_objet) 
{
if (document.getElementById) 
	return(document.getElementById(id_objet));
if(document.all) 
	return(document.all(id_objet));

return null;
}	

//***************************
function objet_position (objet) 
{
	var obj;
	var coords = {x: -1, y: -1};

	obj=objet;

	if (obj == null) 
		return coords

	if (document.layers) 
	{
		coords.x=obj.x;
		coords.y=obj.y;
	    return coords;
	}
	if(obj.offsetLeft!=undefined) 
	{
		coords.x=0;
		coords.y=0;
	    while (obj)
	    {
			coords.x += obj.offsetLeft;
			coords.y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	    return coords;
	}
	return coords;
}


//***************************
function ancre_index(id_ancre) 
{
var i;

for (i=0; i<document.anchors.length; i++) 
	{
	if (document.anchors[i].name==id_ancre) 
		return(i);
	}
return(-1);
}	

//***************************
function ancre_adresse(id_ancre) 
{
var i;
var ancre=null;

for (i=0; i<document.anchors.length; i++) 
	{
	ancre=document.anchors[i];
	if (ancre.name==id_ancre) 
		return(ancre);
	}
return(null);
}	

//***************************
function ancre_position(id_ancre, index_ancre) 
{
var ancre;
var coords = {x: -1, y: -1 };

if (index_ancre ==null || index_ancre>0)
	ancre=ancre_adresse(id_ancre);	
else
	ancre=document.anchors[index_ancre];

if (ancre == null) 
	{
	// désactivation du message :
	//alert(id_ancre + " : ancre non trouvée");
	return coords
	}
coords=objet_position(ancre);
return coords
}

//***************************
function ancre_position_dans_fenetre(id_ancre) 
{
var coords = {x: -1, y: -1 };
var x=0;
var y=0;

var coords=ancre_position(id_ancre);

if (document.getElementById) 
	{
	if (isNaN(window.screenX)) 
		{
		coords.x+=window.screenLeft-document.body.scrollLeft;
		coords.y+=window.screenTop-document.body.scrollTop;
		}
	else 
		{
		coords.x+=window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		coords.y+=window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	return coords;
	}
	
if (ie4) 
	{
	coords.x+=window.screenLeft-document.body.scrollLeft;
	coords.y+=window.screenTop-document.body.scrollTop;
	return coords;
	}
if (ns4) 
	{
	coords.x+=window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
	coords.y+=window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
	return coords;
	}
return coords;
}


//***************************
function fenetre_position()
{
var coords = {x: -1, y: -1, l:-1, h:-1};

if (ns4 || ns6 || ns7)
	{ 
	coords.x = window.pageXOffset;
	coords.y = window.pageYOffset;
	coords.l = window.innerWidth; 	
	coords.h = window.innerHeight;
	}	
else	
	{
	coords.x = document.body.scrollLeft;
	coords.y = document.body.scrollTop;
	coords.l = document.body.clientWidth;	
	coords.h = document.body.clientHeight;	
	}
return coords;
}


//***************************
function fenetre_positionner(x, y)
{

/*
if (ns4 || ns6 || ns7)
	{
	if (x>0) window.pageXOffset=x;
	if (y>0) window.pageYOffset=y;
	}
else
	{
	if (x>0) document.body.scrollLeft=x;
	if (y>0) document.body.scrollTop=y;
	}
*/


if (ns4 || ns6 || ns7)
	{
	if (x<0) x=window.pageXOffset;
	if (y<0) y=window.pageYOffset;
	}
else
	{
	if (x<0) x=document.body.scrollLeft;
	if (y<0) y=document.body.scrollTop;
	}

window.scrollTo(x, y);
}


function document_hauteur() 
{
 if (ie4) 
     return document.body.scrollHeight;
if (ns4 || ns6 || ns7)
       return document.height;
if (ns6)
       return innerHeight;
return 0;
}


//***************************
function fenetre_positionner_selon_ancre(nom_ancre, y_decal) 
{
var y_ancre, y_fen;

y_ancre=ancre_position(nom_ancre).y;

//alert(y_ancre);	
if (ns4 || ns6 || ns7)
	{ 
	y_decal+=20;
	location.href='#R' + id_rubrique;
	y_fen=fenetre_position().y;

//	alert (y_fen +"-"+y_ancre+"=" +(y_fen-y_ancre) +"<"+y_decal);
	if(Math.abs(y_fen-y_ancre)<y_decal)
		window.scrollBy(0, -y_decal);
	}
else
	{	
//	alert ("y_ancre:"+y_ancre+" hdoc:" +document_hauteur()+ " y_decal=" + y_decal);
	if (document_hauteur()-y_ancre>y_decal)
			y_ancre-=y_decal;
	fenetre_positionner(-1, y_ancre);
	}
}	


//***********************
// positionne un layer par rapport à une ancre
// x_l, y_l : decalage en x,y par rapport à l'ancre
function repositionner_layer(nom_layer, x_l, y_l, nom_ancre)
{
var	x_ancre=0, y_ancre=0 ;

if (nom_ancre)
	{
	x_ancre=ancre_position(nom_ancre).x;
	y_ancre=ancre_position(nom_ancre).y;
	}

if (x_ancre<0) x_ancre=0;
if (y_ancre<0) y_ancre=0;

//pour netscape
if (ns4)
	{
	x_ancre += 2  ;
	y_ancre += 2 ;
	}	
//pour netscape
if (ns6 || ns7)
	{
	x_ancre += 2  ;
	y_ancre -= 28 ;
	}	

layer_positionner(nom_layer, x_ancre + x_l, y_ancre + y_l) ;		

return  ;
}
