
// informations sur le navigateur
function Common_BrowserInfos()
{ 
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=this.agent.indexOf("Opera 5")>-1;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.Common_currentBrowser=(this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this; 
}

// variable globales
var Common_currentBrowser=new Common_BrowserInfos();
var Common_currentMousePositionX=0;
var Common_currentMousePositionY=0;

// largeur totale de l'écran
function Common_GetScreenWidth()
{
	return screen.width;
}

// hauteur totale de l'écran
function Common_GetScreenHeight()
{
	return screen.height;
}

// récupération des coordonnées (X,Y) d'un élement
function Common_GetElementPosition(el)
{
	var x = y = 0;
	if(el.offsetParent) 
	{
		x = el.offsetLeft;
		y = el.offsetTop;
		while(el = el.offsetParent) 
		{
			x += el.offsetLeft;
			y += el.offsetTop;
		}
	}

	return {'x':x, 'y':y};
}

// mise à jour des variables globales sur les coordonnées de la souris
function Common_UpdateMousePositions(e)
{
	Common_currentMousePositionX = (Common_currentBrowser.ns4||Common_currentBrowser.ns6)? e.pageX: Common_currentBrowser.ie&&Common_currentBrowser.win&&!Common_currentBrowser.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
	Common_currentMousePositionY = (Common_currentBrowser.ns4||Common_currentBrowser.ns6)? e.pageY: Common_currentBrowser.ie&&Common_currentBrowser.win&&!Common_currentBrowser.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
}

// largeur réelle de la partie visible du navigateur
function Common_GetRealClientWidth()
{
	if( Common_currentBrowser.ie ) return document.body.offsetWidth;
	else return document.body.clientWidth;
}

// hauteur réelle de la partie visible du navigateur
function Common_GetRealClientHeight()
{
	if( Common_currentBrowser.ie ) return document.body.offsetHeight;
	else return document.body.clientHeight;
}

// fonction de debug
function Common_Dbg(texte)
{
	window.status = texte;
}

function Common_DbgElt(eltId, texte)
{
	document.getElementById(eltId).innerHTML = texte;
}

function Common_ShowAttachedElement(targetId, anchorId)
{
	var targetElement = document.getElementById(targetId);
	var anchorCoords = Common_GetElementPosition(anchorId);
	
	targetElement.style.visibility = 'visible';
	targetElement.style.top = ((Common_GetRealClientHeight() / 2) - 80) + 'px';
	targetElement.style.left = ((Common_GetRealClientWidth() / 2) - 50) + 'px';
}

function Common_HideAttachedElement(targetId, anchorId)
{
	var targetElement = document.getElementById(targetId);
	
	targetElement.style.visibility = 'hidden';
}

function Common_HtmlEncode(text, output) 
{
	var reg=new RegExp("&", "g");
	
	text = text.replace(reg, '&amp;');
	fromTo = new Array('&AElig;','Æ','&Aacute;','Á','&Acirc;','Â','&Agrave;','À','&Aring;','Å','&Atilde;', 'Ã','&Auml;','Ä','&Ccedil;','Ç','&ETH;','Ð','&Eacute;','É','&Ecirc;','Ê','&Egrave;','È ','&Euml;','Ë','&Iacute;','Í','&Icirc;','Î','&Igrave;','Ì','&Iuml;','Ï','&Ntilde;','Ñ', '&Oacute;','Ó','&Ocirc;','Ô','&Ograve;','Ò','&Oslash;','Ø','&Otilde;','Õ','&Ouml;','Ö','&THORN; ','Þ','&Uacute;','Ú','&Ucirc;','Û','&Ugrave;','Ù','&Uuml;','Ü','&Yacute;','Ý','&aacute;', 'á','&acirc;','â','&aelig;','æ','&agrave;','à','&aring;','å','&atilde;','ã','&auml;','ä ','&brvbar;','¦','&ccedil;','ç','&cent;','¢','&copy;','©','&deg;','°','&eacute;','é', '&ecirc;','ê','&egrave;','è','&eth;','ð','&euml;','ë','&frac12;','½','&frac14;','¼','&frac34; ','¾','&gt;','>','&gt','>','&iacute;','í','&icirc;','î','&iexcl;','¡','&igrave;','ì','&iquest;','¿','&iuml;','ï', '&laquo;','«','&lt;','<','&lt','<','&mdash;','—','&micro;','µ','&middot;','·','&ndash;','–','&not;','¬','&ntilde;','ñ', '&oacute;','ó','&ocirc;','ô','&ograve;','ò','&oslash;','ø','&otilde;','õ','&ouml;','ö','&para;','¶','&plusmn;','±','&pound;',' £','&quot;','\"','&raquo;','»','&reg;','®','&sect;','§','&sup1;','¹','&sup2;','²', '&sup3;','³','&szlig;','ß','&thorn;','þ','&tilde;','˜','&trade;','™','&uacute;','ú','&ucirc; ','û','&ugrave;','ù','&uuml;','ü','&yacute;','ý','&yen;','¥','&yuml;','ÿ');
	
	if (output) 
	{
		fromTo[fromTo.length] = '&amp;';
		fromTo[fromTo.length] = '&';
	}
	
	for (i=0; i < fromTo.length; i=i+2)
		text = text.replace(eval('/' + fromTo[i+1] + '/g'), fromTo[i]);

	return (text);
}