function setClass(element, className)
{
	element.className=className;

	return true;
}

function setDivPosition(e, divId, divWidth, divHeight, xToAdd, yToAdd)
{
	var screenTop;
	var screenLeft;

	curDiv = document.getElementById(divId);

	// On determine la position de la souris
	mouseY = e.clientY;
	mouseX = e.clientX;

	// On recup?re la taille de l'?cran du navigateur
	// Mozilla (autres pas test?)
	if (window.innerWidth)
	{
		screenWidth = window.innerWidth-20;
		screenHeight = window.innerHeight;
	}
	// IE
	if (document.all != null)
	{
		screenWidth = document.body.clientWidth-20;
		screenHeight = document.body.clientHeight;
	}

	// Selon les scroll, on defini les top, right, bottom et left de la fenetre
	screenTop = 0;
	screenRight = screenWidth;
	screenBottom = screenHeight;
	screenLeft = 0;

	// Si on sors de la fenetre on inverse par rapport ? la souris
	if(divWidth && divWidth != "")
	{
		if(mouseX+divWidth+xToAdd > screenRight)
			finalPosX = mouseX-divWidth-xToAdd;
		else
			finalPosX = mouseX+xToAdd;
	}
	else
		finalPosX = mouseX+xToAdd;
//debug("truc : "+(screenBottom+" - "+(mouseY+divHeight+yToAdd)));
//debug("mouseY : "+mouseY);
	if(divHeight && divHeight != "")
	{
		if(mouseY+divHeight+yToAdd > screenBottom)
			finalPosY = mouseY-divHeight-yToAdd;
		else
			finalPosY = mouseY+yToAdd;
	}
	else
		finalPosY = mouseY+yToAdd;

	//curDiv.style.position = "fixed";
	curDiv.style.top = finalPosY+"px";
	curDiv.style.left = finalPosX+"px";
/*debug(curDiv.style.position);
debug(curDiv.style.top);
debug(curDiv.style.left);*/
}

function showDiv(divId)
{
	document.getElementById(divId).style.display='block';
}

function hideDiv(divId)
{
	document.getElementById(divId).style.display='none';
}

function showClickForMore(divId)
{
	showDiv(divId);
}

function hideClickForMore(divId)
{
	hideDiv(divId);
}

function showClickToFix(divId)
{
	showDiv(divId);
}

function hideClickToFix(divId)
{
	hideDiv(divId);
}

function switchDisplayDiv(obj, objId)
{
	if(!obj || obj == "")
		obj = document.getElementById(objId);
		
	if(obj.style.display == "block")
		obj.style.display = "none";
	else
		obj.style.display = "block";
}



function getCharCode(e, cbf)
{
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which) {
		// netscape
		key = e.which; 
	}
	
	return cbf(key);
}

function insertInTextAreaAtPointer(textarea, repdeb, repfin)
{
  textarea.focus();

  /* IE */
  if(typeof document.selection != 'undefined') 
  {
    /* Insertion du code de formatage */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = repdeb + insText + repfin;
  
    /* Ajustement de la position du curseur */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length + insText.length + repfin.length);
    }
    range.select();
  }
  /* pour navigateurs plus r?cents bas?s sur Gecko*/
  else if(typeof textarea.selectionStart != 'undefined')
  {
    /* Insertion du code de formatage */
    var start = textarea.selectionStart;
    var end = textarea.selectionEnd;
    var insText = textarea.value.substring(start, end);
    textarea.value = textarea.value.substr(0, start) + repdeb + insText + repfin + textarea.value.substr(end);
    /* Ajustement de la position du curseur */
    var pos;
    if (insText.length == 0) {
      pos = start + repdeb.length;
    } else {
      pos = start + repdeb.length + insText.length + repfin.length;
    }
    textarea.selectionStart = pos;
    textarea.selectionEnd = pos;
  }
  /* pour les autres navigateurs */
  else
  {
    /* requ?te de la position d'insertion */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Insertion ? la position (0.." + textarea.value.length + "):", "0");
    }
    if(pos > textarea.value.length) {
      pos = textarea.value.length;
    }
    /* Insertion du code de formatage */
    var insText = prompt("Veuillez entrer le texte ? formater:");
    textarea.value = textarea.value.substr(0, pos) + repdeb + insText + repfin + textarea.value.substr(pos);
  }
}