function $(id)
{
  if (id) // IE !
    return document.getElementById(id);
  return false;
}

function onload_init()
{
  dhtmlHistoryInit(); // XAJAX history
  $('wrapper').onmousedown = boutonEnfonce;
  document.onkeydown = altKeyCheck;
  /*window.document.title = "Test";*/
}

function Loading(id)
{
  if ($(id) && $('loading'))
    $(id).innerHTML = $('loading').innerHTML;
}

function showLoading()
{
  Loading('main_content');
}

function showMenuLoading()
{
  $('login').innerHTML = "";
}

function showWindowLoading()
{
  Loading('wiindow');
}

function getElementsByClassName(classname, node)
{
  if(!node)
    node = document.getElementsByTagName("body")[0];
  var a = [];
  var re = new RegExp('\\b' + classname + '\\b');
  var els = node.getElementsByTagName("*");
  for(var i=0,j=els.length; i<j; i++)
    if(re.test(els[i].className))a.push(els[i]);
  return a;
}

/* Return the size of the screen */
function screen_size()
{
	var windowWidth, windowHeight, pageWidth, pageHeight;

  // Explorer 6 Strict Mode
	if (document.documentElement && document.documentElement.scrollHeight)
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		pageWidth = document.documentElement.scrollWidth;
		pageHeight = document.documentElement.scrollHeight;
	}
	else if (document.body)
	// other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	}
	return ([windowWidth, windowHeight, pageWidth, pageHeight]);
}



function submitComment()
{
  xajax.$('submitButton').disabled = true;
  xajax.$('submitButton').value = "Wait...";
  xajax_comments_submit(xajax.getFormValues("commentform"));
  return (false);
}

function submitLogin()
{
  $('loginButton').disabled = true;
  $('loginButton').value = "Wait...";

  xajax_login($('login_login').value, $('login_password').value);
  return (true);
}

function avatar_zoomInAvatar(obj, avatar, height, width, decX, decY)
{
  if (avatar_zoomIn(obj, obj.src, height, width, obj.offsetLeft - decX, obj.offsetTop - decY))
    $('avatar_zoom').avatar = avatar;
}

function show_image_raytracer(src)
{
  $('player').style.display = 'none';
  show_image(src, 'hide_image_raytracer');
}
function hide_image_raytracer()
{
  $('player').style.display = 'block';
  hide_image();
}

function hide_image_raytracer()
{
  $('player').style.display = 'block';
  hide_image();
}

function avatar_zoomInRaytracer(obj, bigImage, height, width, decX, decY)
{
  var tmp = getAbsolutePos(obj, "thumbs_raytracer");
  var decX = tmp[0] - decX;
  var decY = tmp[1] - decY;
  if (avatar_zoomIn(obj, obj.src, height, width, decX, decY))
    $('avatar_zoom').bigsrc = bigImage;
}

function avatar_zoomIn(obj, pathNewImage, height, width, left, top)
{
  if ($('avatar_zoom').src != pathNewImage)
  {
    $('avatar_zoom').src = pathNewImage;
    $('avatar_zoom').style.display = 'block';
    //$('nelson').innerHTML = obj.offsetTop + ' : ' + obj.offsetLeft;
    //$('nelson').innerHTML = getAbsolutePos(obj, "thumbs_raytracer");
    $('avatar_zoom').style.top = top + "px";
    $('avatar_zoom').style.left = left + "px";
    $('avatar_zoom').style.width = width + "px";
    $('avatar_zoom').style.height = height + "px";
    return (true);
  }
  return (false);
}

function avatar_zoomOut(obj)
{
  obj.style.display = 'none';
  $('avatar_zoom').src = '';
}

function updateResize()
{
	var tmp = screen_size();

  $('overlay').style.width = tmp[2] + 'px';
	$('overlay').style.height = tmp[3] + 'px';

}
