/* Copyright (c) 2006-2009 Romain Bezut
   Programme sous Licence GPL (voir le fichier LICENSE) */
/* Contient les bases de tout script AJAX */

var direction = true;
var opacity = 0;

function getHTTPObject(){
  var xmlhttp = false;

/* Pour IE */
/*@cc_on
  @if (@_jscript_version >= 5)
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e) {
  try
  {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (E) {
    xmlhttp = false;
  }
  }
  @else
    xmlhttp = false;
  @end @*/
  /* on essaie de creer l'objet si ce n'est pas deja fait */
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    }
    catch (e){
      xmlhttp = false;
    }
  }

  return xmlhttp;
}

function ajaxRpl(url, id)
{
  var xmlhttp = getHTTPObject();

  if (!xmlhttp)
    return false;

  xmlhttp.open("GET", url, true);
  xmlhttp.send(null);

  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById(id).innerHTML = xmlhttp.responseText;
      if (id == 'viewprofil') {
        direction = true;
        opacity = 0;
        showProfil();
      }
    }
  }

  return true;
}

function showProfil()
{
  // Showing...
  if (direction && opacity < 16) {
    if (opacity == 0) {
      document.getElementById('viewprofil').style.display = "block";
      document.getElementById('viewprofil').style.top = document.documentElement.scrollTop + 20 + 'px';
    }

    opacity++;
    document.getElementById('viewprofil').style.opacity = opacity / 18;

    if (opacity >= 16)
      direction = false;
    else
      window.setTimeout(showProfil, 20);
  }
  else if(!direction && opacity > 0) {
    opacity -= 2;
    document.getElementById('viewprofil').style.opacity = opacity / 16;

    if (opacity <= 0) {
      direction = true;
      document.getElementById('viewprofil').style.display = "none";
      document.getElementById('viewprofil').innerHTML = '';
    }
    else
      window.setTimeout(showProfil, 20);
  }

  return false;
}
