var info_x=0;
var info_y=0;

var DOM = false;
var DA = false;
if (document.getElementById) {
  DOM = true;
} else if (document.all) {
  DA = true;
}
  
document.onmousemove = mouseMove;

function mouseMove(e){
  if ( ! document.all) {   
    info_x = e.pageX;
    info_y = e.pageY;
  } else {
    info_x = window.event.clientX;
    info_y = window.event.clientY;
  }
}

function showInfo(id) {
  if (! DOM &&  !DA) return;
  if ( id=='' ) return;
  if (DOM) {
    var infobox = document.getElementById(id);
    infobox.style.visibility = 'visible';
  } else if (DA) {
    document.all[id].style.setAttribute('visibility', 'visible');
  }
  positionLayer(id);
}

function positionLayer(id) {
  var width = 200;
  var height = 200;
  
  if (DOM) {
    if (! document.all) {
      width = document.getElementById(id).style.offsetWidth + 10;
      height = document.getElementById(id).style.offsetHeight + 10;
    } else {
      width = document.getElementById(id).clientWidth;
      height = document.getElementById(id).clientHeight;
    }
  } else if (DA) {
    width = document.all[id].clientWidth;
    height = document.all[id].clientHeight;
  }
  
  if ( ! document.all) {
    if ( (info_x + width) > window.innerWidth) {
      info_x -= (width + 3);
    } else {
      info_x += 3;
    }
    if ( (info_y + height) > window.innerHeight) {
      info_y -= (height + 3);
    } 
  } else {
    if ( (info_x + width) > document.body.offsetWidth  ) {
      info_x -= width;
    } else {
      info_x += 3;
    }
    if ( (info_y + height) > document.body.offsetHeight  ) {
      info_y -= height;
    } 
  }
  
  if (DOM) {
    var infobox = document.getElementById(id);
    infobox.style.left=info_x;
    infobox.style.top=info_y;
  } else if (DA) {
    document.all[id].stylesetAttribute('left', info_x);
    document.all[id].style.setAttribute('top', info_y);
  }
  
}

function hideInfo(id) {
  if (! DOM &&  !DA ) return;
  if ( id=='' ) return;
  if (DOM) {
    var infobox = document.getElementById(id);
    infobox.style.visibility = 'hidden';
  } else if (DA) {
    document.all[id].style.setAttribute('visibility', 'hidden');
  }
}
