var nav;
var mouseX;
var mouseY;


function getElementsByClass(classn) {
  var ret = new Array();
  var n = document.getElementsByTagName("*").length;
  for(var i=0;i<n;i++) {
    if(document.getElementsByTagName("*").item(i).className == classn) {
      ret.push(document.getElementsByTagName("*").item(i));
    }
  }
  return ret;
}

function scroller_getCoordY() {
  var scrollY;
  if (document.all) {
    if(!document.documentElement.scrollTop) {
      scrollY = document.body.scrollTop;
    }
    else {
      scrollY = document.documentElement.scrollTop;
    }
  }
  else {
    scrollY = window.pageYOffset;
  }
  return scrollY;
}

function scroller_getCoordX() {
  var scrollX;
  if (document.all) {
    if(!document.documentElement.scrollLeft) {
      scrollX = document.body.scrollLeft;
    }
    else {
      scrollX = document.documentElement.scrollLeft;
    }
  }
  else {
    scrollX = window.pageXOffset;
  }
  return scollX;
}

function getWindowHeight() {
  var height;
  if (document.body) {
    height = document.body.clientHeight;
  }
  else {
    height = window.innerHeight;
  }
  return height;
}

function getMouseX(e) {
  var x;
  e = e || window.event;
  if (e.pageX || e.pageY) {
    x = e.pageX;
  }
  else {
    var de = document.documentElement;
    var b = document.body;
    x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
  }
  return x;
}

function getMouseY(e) {
  var y;
  e = e || window.event;
  if (e.pageY) {
    y = e.pageY;
  }
  else {
    var de = document.documentElement;
    var b = document.body;
    y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
  }
  return y;
}

function positionMouse(e) {
  mouseX = getMouseX(e);
  mouseY = getMouseY(e);
}

function oops() {
  alert('Hum, cela n\'a pas bien fonctionné, il vaudrait mieux recommencer.\n\nSi cela ne marche toujours pas, recharge la page !');
}

function askServer(url,method,param,asynchro) {
  var xhr_object;
  if(window.ActiveXObject) {
    // IE
    xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    nav = 'IE';
  }
  else if(window.XMLHttpRequest) {
    // Firefox et autres navigateurs supportant XMLHttpRequest
    xhr_object = new XMLHttpRequest();
    nav = 'FF';
  }
  if(!asynchro) {
    if(method == 'GET') {
      xhr_object.open("GET", url, false);
      xhr_object.send(null);
      if(xhr_object.readyState == 4) {
        var res = xhr_object.responseText;
        return res;
      }
      return -1;
    }
    if(method == 'POST') {
      xhr_object.open("POST",url,false);
      xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   
      xhr_object.send(param);
      if(xhr_object.readyState == 4) {
        var res = xhr_object.responseText;
        return res;
      }
      return -1;
    }
  }
  if(asynchro) {
    if(method == 'GET') {
      xhr_object.open("GET", url, true);
      xhr_object.send(null);
      return xhr_object;
    }
    if(method == 'POST') {
      xhr_object.open("POST",url,true);
      xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   
      xhr_object.send(param);
      return xhr_object;
    }
  }
  return -1;
}

function getCoordX(node) {
  var offset=0;
  while(node){
    offset+=node["offsetLeft"];
    node=node.offsetParent;
  }
  return offset;
}
function getCoordY(node) {
  var offset=0;
  while(node) {
    offset+=node["offsetTop"];
    node=node.offsetParent;
  }
  return offset;
}

function getCurrentCSS(obj,property) {
  if (obj.currentStyle) return obj.currentStyle.getAttribute(property);
  else return window.getComputedStyle(obj,null).getPropertyValue(property);
}

function readCookie(cookie_name) {
  var start, end;
  start = document.cookie.indexOf(cookie_name + "=")
  if(start>=0) {
    start += cookie_name.length + 1;
    end = document.cookie.indexOf(";",start);
    if(end < 0) end = document.cookie.length;
    return unescape(document.cookie.substring(start,end))
  }
  return "";
}
  
function getBodyWidth() {
  var width;
  if(typeof(window.innerWidth) == 'number') {
    width = window.innerWidth;
  } 
  else if(document.documentElement.clientWidth) {
    width = document.documentElement.clientWidth;
  } 
  else if(document.body.clientWidth) {
    width = document.body.clientWidth;
  }
  else {
    width = -1;
  }
  return width;
}
  
function getBodyHeight() {
  var height;
  if(typeof(window.innerHeight) == 'number') {
    height = window.innerHeight;
  } 
  else if(document.documentElement.clientHeight) {
    height = document.documentElement.clientHeight;
  } 
  else if(document.body.clientHeight) {
    height = document.body.clientHeight;
  }
  else {
    height = -1;
  }
  return height;
}