function hidelayer(id) {
  if (document.getElementById) {document.getElementById([id]).style.display = "none";}
  else if (document.all) {document.all[id].style.visibility = "hidden";}
  else if (document.layers) {document.layers[id].visibility = "hide";}
}
function showlayer(id) {
  if (document.getElementById) {document.getElementById([id]).style.display = "block";}
  else if (document.all) {document.all[id].style.visibility = "visible";}
  else if (document.layers) {document.layers[id].visibility = "show";}
}

function writetolayer(lay,txt) {
  if (document.getElementById) {
    var newdiv = document.createElement("div");
    newdiv.innerHTML = txt;
    var container = document.getElementById(lay);
    while (container.hasChildNodes()) {
      container.removeChild(container.lastChild);
    }
    container.appendChild(newdiv);
  } else if (document.all) {
    document.all[lay].innerHTML = txt;
  } else if (document.layers) {
    document[lay].document.write(txt);
    document[lay].document.close();
  }
}


function movelayer(id, x, y) {
  var elm = null;
  if (document.getElementById) {
    elm = document.getElementById(id);
  } else if (document.all) {
    elm = document.all[id];
  } else if (document.layers) {
    elm = document.layers[id];
  }

  if (!elm) {
    // browser not supported or element not found
  } else if (elm.style) {
    if (typeof(elm.style.left) == 'number') {
      elm.style.left = x;
      elm.style.top  = y;
    } else {
      elm.style.left = x + 'px';
      elm.style.top  = y + 'px';
    }
  } else if (typeof(elm.left) == 'number') {
    elm.left = x;
    elm.top  = y;
  }
}
















cursorX = 0;
cursorY = 0;

function getViewWidth() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    return window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    return document.body.clientWidth;
  }

  if (document.body && typeof(document.body.clientWidth) == 'number')
    return document.body.clientWidth;
  else
    return window.innerWidth;
}

function getViewHeight() {
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    return window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    return document.body.clientHeight;
  }

  if (document.body && typeof(document.body.clientHeight) == 'number')
    return document.body.clientHeight;
  else
    return window.innerHeight;
}

function random(bound) {
  return Math.floor(Math.random() * bound);
}

function writelayer(contents, name, x, y) {
    if (document.layers) {
      document.writeln('<layer id="' + name + '" left=' + x + ' top=' + y + '>'+contents+'</layer>');
    } else {
      document.writeln('<div id="' + name + '" style="position:absolute;left:' + x + ';top:' + y + ';">'+contents+'</div>');
    }
}

function getViewXOffset() {
  if( typeof( window.pageXOffset ) == 'number' ) {
    //Netscape compliant
    return window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    return document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    return document.documentElement.scrollLeft;
  }

  if (document.body && typeof(document.body.scrollLeft) == 'number')
    return document.body.scrollLeft;
  else
    return window.pageXOffset;
}

function getViewYOffset() {
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    return window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    return document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    return document.documentElement.scrollTop;
  }

  if (document.body && typeof(document.body.scrollTop) == 'number')
    return document.body.scrollTop;
  else
    return window.pageYOffset;
}

var trackmouselayer = null;
var trackXoffset = 10;
var trackYoffset = 10;

function trackmouse(id, x, y) {
  trackmouselayer = id;
  trackXoffset = x;
  trackYoffset = y;
}

function cursorXY(e) {
  if (window.event) {
    cursorX = getViewXOffset() + event.clientX;
    cursorY = getViewYOffset() + event.clientY;
  } else {
    cursorX = e.pageX;
    cursorY = e.pageY;
  }
  if (trackmouselayer != null) movelayer(trackmouselayer, cursorX+trackXoffset, cursorY+trackYoffset);
}

function captureXY() {
  if (document.layers) { // most likely NS4
    window.onMouseMove=cursorXY;
    window.captureEvents(Event.MOUSEMOVE);
  } else {
    document.onmousemove = cursorXY;
  }
}
captureXY();



