// Ajuste les dimensions de l'image en fonction du width passé en paramètre
function CheckWidth(img, newWidth)
{
	if ( img.width > newWidth ) img.width = newWidth;
}

// remet le texte par défaut */
function FillCheck(obj, txt)
{
	if (obj.value == "") obj.value = txt;
}

// Reduit / augmente de 1 un input dans un interval [min;max]
function ChangeValue(obj, method, min, max)
{
	if (method == "" || method == null) method = 1;
	if (min == "" || min == null) min = 0;
	if (max == "" || max == null) max = 0;
	
	qtt = document.getElementById(obj)
	
	if (method > 0) 	{ if (max) { if (qtt.value < max) qtt.value++; } else { qtt.value++; } }
	if (method < 0) 	{ if (min) { if (qtt.value > min) qtt.value--; } else { qtt.value--; } }
}

// Vérifie l'innerWidth/Height
function CheckClientWindow()
{
	if (document.body) wWidth = document.body.clientWidth;
	else wWidth = window.innerWidth;
	
	if (wWidth<1022) HideOrShowObj(Array("borderleft", "borderright"), 0);
	else HideOrShowObj(Array("borderleft", "borderright"), 1);
}

// Cache/Montre les objets passés en paramettres
function HideOrShowObj(objs, method)
{
	for( var i=0; i<objs.length; i++ )
	{
		if (!method) document.getElementById(objs[i]).firstChild.style.display = "none";
		else document.getElementById(objs[i]).firstChild.style.display = "block";
	}
}

// Fonctions Quirksmode
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// Redimensionne la hauteur popup en fonction du dernier élément
function HeightResizer(width)
{
	if (document.body) wWidth = document.body.clientWidth;
	else wWidth = window.innerWidth;	
	var lastEl 	= document.createElement("div");
	document.getElementsByTagName("body")[0].appendChild(lastEl);
	lastElY = findPosY(lastEl);
	window.resizeTo(width, parseInt(lastElY)+28);
}



// Infobulle by Nenex
// ------------------
// InitHelp::Initialise la box et les liens avec la classe helpLink
// showHelp::Affiche la bulle d'aide
// 		@param ev: event lors de l'appel (contient les coordonnées de la souris)
// hideHelp::Cache la bulle d'aide

function initHelp()
{
	var i, x, helpBox;
	
	helpBox = document.createElement('div');
	helpBox.className = 'helpBox';
	helpBox.id = 'helpBox';
	document.body.appendChild(helpBox);
	x = document.getElementsByTagName('*');
	for(i=0; i!=x.length; i++)
		if(x[i].className && x[i].className == 'helpLink')
		{
			if(x[i].title == "") continue;
			x[i].px = findPosX(x[i]);
			x[i].py = findPosY(x[i]);
			x[i].titleRef = x[i].title;
			x[i].title = '';
			x[i].onmouseover = showHelp;
			x[i].onmouseout  = hideHelp;
		}
}

function hideHelp()
{
	var helpBox = document.getElementById('helpBox');
	helpBox.style.display = 'none';
}

function showHelp(ev)
{
	var pos = ev || window.event;
	var helpBox = document.getElementById('helpBox');

	helpBox.style.top = this.py + (this.scrollHeight) + 'px';
	helpBox.style.left = this.px + 5 + 'px';
	helpBox.innerHTML = this.titleRef;
		
	if(document.body.scrollWidth - (this.px + 200) < 0)
	{
		helpBox.style.left = this.px - 190 + 'px';
		helpBox.style.top = this.py + this.scrollHeight + 'px';
	}
	
	helpBox.style.display = 'block';
}