function getPos( elem )
{
	var pos = { 'r':0, 'l':0, 't':0, 'b':0 };
	var tmp = elem;
	
	do {
		pos.l += tmp.offsetLeft;
		tmp = tmp.offsetParent;
	} while( tmp !== null );
	pos.r = pos.l + elem.offsetWidth;
	
	tmp=elem;
	do {
		pos.t += tmp.offsetTop;
		tmp = tmp.offsetParent;
	} while( tmp !== null );
	pos.b = pos.t + elem.offsetHeight;
	
	return pos;
};

function ajax( fichier )
{
	if( window.XMLHttpRequest ) // FIREFOX
		var xhr_object = new XMLHttpRequest();
	else if( window.ActiveXObject ) // IE
		var xhr_object = new ActiveXObject( "Microsoft.XMLHTTP" );
	else
		return false;

	xhr_object.open( "GET", fichier, false );
	xhr_object.send( null );

	if( xhr_object.readyState == 4 )
		return xhr_object.responseText;
	else
		return false;
}

function writediv( texte, id )
{
    document.getElementById( id ).innerHTML = texte;
}

function visible( id )
{
	if( document.getElementById( id ).nodeName == "TR" )
		document.getElementById( id ).style.display = "table-row";
	else
		document.getElementById( id ).style.display = "block";
}

function infoBullesSite( id_bulle, id, lang )
{
	var id_link = 'infoLink_' + id_bulle;

	if( id_bulle.indexOf( '-' ) > -1 )
		id_bulle = id_bulle.substr( 0, id_bulle.indexOf( '-' ) );

	if( document.getElementById( id ).innerHTML == '' )
	{
		var info = ajax( 'accessSup.php?page=infoBulle&lang=' + lang + '&id=' + id_bulle );
		writediv( info, id );
	}

	visible( id );

	var vPos, hPos;
	if( window.innerHeight )
	{
		vPos = window.innerHeight + window.pageYOffset;
		hPos = window.innerWidth;
	}
	else
	{
		vPos = document.body.clientHeight + document.body.scrollTop;
		hPos = document.body.clientWidth;
	}

	var vSpace = vPos - getPos( document.getElementById( id_link ) ).t - document.getElementById( id ).offsetHeight;
	if( vSpace >= 0 )
		document.getElementById( id ).style.top = getPos( document.getElementById( id_link ) ).t;
	else
		document.getElementById( id ).style.top = getPos( document.getElementById( id_link ) ).t + vSpace - 10;
	var hSpace = hPos - getPos( document.getElementById( id_link ) ).r - document.getElementById( id ).offsetWidth;
	if( hSpace >= 5 )
		document.getElementById( id ).style.left = getPos( document.getElementById( id_link ) ).r + 5;
	else
		document.getElementById( id ).style.left = getPos( document.getElementById( id_link ) ).l - document.getElementById( id ).offsetWidth - 5;
}

function removeBulle( id )
{
	document.getElementById( id ).style.display = "none";
}
