/************************************************************ InfoBule ***************************************************************/

/*******************
* infobulles
* Ben, 23/07/2005
*******************/

// espacement entre le curseur et l'infobulle
//cursor_padding = 5;
cursor_padding_x = 10;//180
cursor_padding_y = 10;

// gestion des navigateurs (IE, MOZ, NS)
nav = navigator.appName;

ie = document.all;
ns = document.layers;
fi = document.getElementById && !document.all;

if(!ie && !ns && !fi){
	alert("navigateur "+nav+" incompatible !");	
}

if(!ie){
	document.captureEvents(Event.MOUSEMOVE); 	
}
_bubbleActive = false;
document.onmousemove = get_mouse;
//alert(navigator.appName);
/*
// recupere les coordonnees de la souris
// les affecte au style de la div infobulle
function get_mouse(e){
	if(ie){
		x = event.x;
		y = event.y;
		window.status = x;
	}else{
		x = e.pageX;
		y = e.pageY;
	}	
	
	bubble = document.getElementById("infobulle");
	bubble.style.left = x + cursor_padding_x;
	bubble.style.top = y + cursor_padding_y;
	
}*/

function get_mouse(e){ // works on IE6,FF,Moz,Opera7
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e){ 
    if (e.pageX || e.pageY){ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
    }else if (e.clientX || e.clientY){ // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
    }
	bubble = document.getElementById("infobulle");
    elex = mousex + cursor_padding_x;
    eley = mousey + cursor_padding_y;	
	if(_bubbleActive){
	  if(eley<176){
		if (document.body){
			var screenWidth = (document.body.clientWidth);
			var screenHeight = (document.body.clientHeight);
		} else {
			var screenWidth = (window.innerWidth);
			var screenHeight = (window.innerHeight);
		}
	    bubble.style.position = "absolute";
		maxLeft = screenWidth-280;
	    bubble.style.left = elex>maxLeft?maxLeft.toString(10) + 'px':(elex).toString(10) + 'px';
	    bubble.style.top  = (eley).toString(10) + 'px';
	  }else{
	    bubble.style.position = "absolute";
		bubble.style.display = "none";
		bubble.style.visibility = "hidden";
		bubble.style.left = 200 + 'px';
	    bubble.style.top  = 176 + 'px';
	  }
    }
  }
}


// affiche la bubble
function showBubble(title,text){
	_bubbleActive = true;
	bubble.style.visibility = "visible";
    bubble.style.display = "block";
	

//	title = unescape(title);
//	text = unescape(text);

if(navigator.appName.toLowerCase()=="opera"){
	title = Utf8.decode(title);
	text = Utf8.decode(text);
}
	var reg=new RegExp("(&apos;)", "g");
//	alert(text+' --- '+text.replace(reg,"'"));
	text = "<span>"+title.replace(reg,"'")+"</span><br/>"+text.replace(reg,"'");
	bubble.innerHTML = text;

	// déconseillé pas aux normes

/*	longueur_bubble = bubble.firstChild.length;
	bubble.firstChild.replaceData(0, longueur_bubble, text); 
*/
	
}

// cache la bubble
function killBubble(){
	_bubbleActive = true;
	bubble.style.visibility = "hidden";
        bubble.style.display = "none";
}

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

var Utf8 = {

	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}