function computeWindowDimension(width, height, flags)
{
	var offsetY = 16;
	var posX = (screen.availWidth - (0 + width - 10)) / 2;
	if (flags.indexOf("toolbar=yes") != -1)
		offsetY += 32;
	if (flags.indexOf("status=yes") != -1)
		offsetY += 16;
	height -= offsetY;
	var posY = ((screen.availHeight - height) / 2) - offsetY;
	if (posX < 0)
		posX = 0;
	if (posY < 0)
		posY = 0;
	return 'width=' + width + ',height=' + height + ',top=' + posY + ',left=' + posX;
}

function openWindow(url, width, height)
{
    var flags = 'status=yes,toolbar=yes,location=no,directories=no,scrollbars=yes,resizable=yes';
	window.open(encodeURI(url.replace(/[#]/g, '%23')), '', computeWindowDimension(width, height, flags) + ',' + flags);
}

function openWindowWithFlags(url, width, height, flags)
{
	window.open(encodeURI(url.replace(/[#]/g, '%23')), '', computeWindowDimension(width, height, flags) + ',' + flags);
}

function openPopup(url, width, height)
{
    var flags = 'status=no,toolbar=no,location=no,directories=no,scrollbars=yes,resizable=yes';
	window.open(encodeURI(url.replace(/[#]/g, '%23')), '', computeWindowDimension(width, height, flags) + ',' + flags);
}

function switchBlock(blockId) 
{
	var Block, Img;
	Block = document.getElementById(blockId);
	Img = document.getElementById(blockId + 'Img');
	if (Block.style.display == 'none')
	{
		Block.style.display = 'inline';
		Img.src = 'fo/images/picto-bas.gif';
	}
	else
	{
		Block.style.display = 'none';
		Img.src = 'fo/images/lltr.gif';
	}	
}

function switchOneBlock(blockId) 
{
	var Block, i;		
	for(i=1; i<5; i++)
	{
		i = i + "";																				
		Block = document.getElementById(i);
		Block.style.display = 'none';			
	}
	
	Block = document.getElementById(blockId);		
	Block.style.display = 'inline';
}

function switchOneBlockWithin(blockId, max) 
{
	var Block, i;		
	for(i=1 ; i<= max ; i++)
	{
		i = i + "";																				
		Block = document.getElementById(i);
		Block.style.display = 'none';			
	}
	
	Block = document.getElementById(blockId);		
	Block.style.display = 'inline';
}

function addOnLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/* Permet d'aller a la page passer en parametre en encodant l'url correctement */
function changeLocation(url)
{
	document.location = url.replace(/[#]/g, '%23');
}

/* primary function to retrieve cookie by name */
function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal(j);
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

/* utility function called by getCookie() */
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) {
    endstr = document.cookie.length;
  }
  return unescape(document.cookie.substring(offset, endstr)).replace(/["]/g,'');
}