/* fonction pour la gestion des tips de commentaire dans les arbres */
/* ---------------------------------------------------------------- */
/* 26-jul-2007 LDT : version initiale */

/* utilisation :
	objet déclencheur : onMouseOver="javascript:showNote('p-com1-c02',event)"
                        onMouseOut="javascript:hideNote('p-com1-c02')"

	objet ouvert : 		onMouseOver="javascript:keepShowingNote('p-com1-c02')"
						onMouseOut="javascript:hideNote('p-com1-c02')"
						
*/


function open_window(url) {
	mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=700');
	if (mywin.focus) {
		mywin.focus()
	}
//	mywin.document.write("<html><body>chargement en cours...</body></html>");
//	mywin.document.location=url;
}

function getObject( obj ) {
	if ( document.getElementById ) {
	  obj = document.getElementById( obj );
	} else if ( document.all ) {
	  obj = document.all.item( obj );
	} else {
	  obj = null;
	}
	return obj;
}

function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	else return null;
}

/* affiche un div à gauche de la souris, toujours visible dans la fenêtre */
function showNote(refid, event){
	var theDiv = getObject(refid);
	if (theDiv) {
		/* ne pas mettre en fin de prob car pb d'affichage avec IE (pas de bordure aux tableaux au 1er affichage) */
		theDiv.style.visibility = 'visible' ;
		/* increase because of wrong computation of width by browser */
		if (!theDiv.widthAlreadyComputed) {
			theDiv.style.width = (theDiv.offsetWidth + 20)+'px';
		}
		
		var y = mouseY(event)
		var divHeight=theDiv.offsetHeight ? theDiv.offsetHeight : theDiv.style.height;
		
		var clientHeight = window.innerHeight ? window.innerHeight -5 : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		var clientWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
		var scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		var scrollLeft = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
		
		/* if div too hight increase width */
		if (divHeight * 1.1 > clientHeight ) {
			theDiv.style.width=Math.round((theDiv.offsetWidth * 1.2 * divHeight) / clientHeight)+'px';
			divHeight=theDiv.offsetHeight;
		}
		/* compute top : suivant la position du clic (haut ou bas de la fenêtre) */
		y=y-Math.round((divHeight*(y-scrollTop)/clientHeight));
		theDiv.style.top = y+'px' ;
		
		var divWidth=theDiv.offsetWidth ? theDiv.offsetWidth : theDiv.style.width;
		var newDivWidth=divWidth;

		/* try to check the inner element width */
		if (!theDiv.widthAlreadyComputed) {
		
			var tables=theDiv.getElementsByTagName('table');
			if (tables.length > 0) {
				for(var i=0; i < tables.length ;i++) {
					var tableWidth=tables[i].offsetWidth ? tables[i].offsetWidth + tables[i].offsetLeft + 10 : tables[i].style.width;
					if (tableWidth > divWidth) newDivWidth=tableWidth;
				}
			}
			if (newDivWidth > divWidth + 10 ) {
				theDiv.style.width = newDivWidth+'px';
				divWidth = newDivWidth;
			}
			
			theDiv.widthAlreadyComputed=true;
		}
		/* if the div is too large */
		if (divWidth + 20 > clientWidth) {
			theDiv.style.width = (clientWidth - 20)+'px';
			theDiv.style.top = (scrollTop + 10) + 'px';
		}
		
		var left = mouseX(event)-divWidth-10;
		if ((left - scrollLeft) < 0 ) left=scrollLeft;
		theDiv.style.left=(left - (theDiv.offsetParent ? theDiv.offsetParent.offsetLeft : 0 ))+'px';
		
		theDiv.countShow=1;
	}
}

function hideNote(refid){
	var theDiv = getObject(refid);
	if (theDiv) {
		theDiv.countShow=theDiv.countShow-1;
		setTimeout('tryHideNote(\''+refid+'\')',300);
	}
}

function tryHideNote(refid) {
	var theDiv = getObject(refid);
	if (theDiv && theDiv.countShow==0) {
		theDiv.style.visibility='hidden';
	}
}

function keepShowingNote(refid){
	var theDiv = getObject(refid);
	if (theDiv) {
		theDiv.countShow=theDiv.countShow+1;
	}
}


/* definition de fonctions si inexistantes */
			
if(!document.getElementById) document.getElementById=function (id) {
	return eval("document.all."+id);
}
if(!document.getElementsByName) document.getElementsByName=function (name) {
	var el=document.all,result=new Array(),j=0;
	for(var i=0;i < el.length;i++) 
	 { if (el[i].name.toLowerCase()==name.toLowerCase()) { result[j++]=el[i];}
	 }
	return result;
}
if(!document.getElementsByTagName) document.getElementsByTagName=function (tagName) {
	var el=document.all,result=new Array(),j=0;
	for(var i=0;i < el.length;i++) if(el[i].tagName.toLowerCase()==tagName.toLowerCase()) {result[j++]=el[i];}
	return result;
}
