function showLayer(layer) {
    layer.style.visibility = "visible";
}

function moveLayerTo(layer, x, y) {
    layer.style.left = x;
    layer.style.top  = y;
}

function moveLayerBy(layer, dx, dy) {
    layer.style.pixelLeft += dx;
    layer.style.pixelTop  += dy;
}

function getLeft(layer) {
    return(layer.style.pixelLeft);
}

function getTop(layer) {
    return(layer.style.pixelTop);
}

function getRight(layer) {
    return(layer.style.pixelLeft + getWidth(layer));
}

function getBottom(layer) {
    return(layer.style.pixelTop + getHeight(layer));
}

function getPageLeft(layer) {
    return(layer.offsetLeft);
}

function getPageTop(layer) {
    return(layer.offsetTop);
}

function getWidth(layer) {
    if (layer.style.pixelWidth)
      return(layer.style.pixelWidth);
    else
      return(layer.clientWidth);
}

function getHeight(layer) {
    if (false && layer.style.pixelHeight)
      return(layer.style.pixelHeight);
    else
      return(layer.clientHeight);
}

function getzIndex(layer) {
    return(layer.style.zIndex);
}

function setzIndex(layer, z) {
    layer.style.zIndex = z;
}

//-----------------------------------------------------------------------------
// Layer clipping.
//-----------------------------------------------------------------------------

function clipLayer(layer, clipleft, cliptop, clipright, clipbottom) {
    layer.style.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

function getClipLeft(layer) {
    var str =  layer.style.clip;
    if (!str)
      return(0);
    var clip = getIEClipValues(layer.style.clip);
    return(clip[3]);
}

function getClipTop(layer) {
    var str =  layer.style.clip;
    if (!str)
      return(0);
    var clip = getIEClipValues(layer.style.clip);
    return(clip[0]);
}

function getClipRight(layer) {
    var str =  layer.style.clip;
    if (!str)
      return(layer.style.pixelWidth);
    var clip = getIEClipValues(layer.style.clip);
    return(clip[1]);
}

function getClipBottom(layer) {
    var str =  layer.style.clip;
    if (!str)
      return(layer.style.pixelHeight);
    var clip = getIEClipValues(layer.style.clip);
    return(clip[2]);
}

function getClipWidth(layer) {
    var str = layer.style.clip;
    if (!str)
      return(layer.style.pixelWidth);
    var clip = getIEClipValues(layer.style.clip);
    return(clip[1] - clip[3]);
}

function getClipHeight(layer) {
    var str =  layer.style.clip;
    if (!str)
      return(layer.style.pixelHeight);
    var clip = getIEClipValues(layer.style.clip);
    return(clip[2] - clip[0]);
}

function getIEClipValues(str) {

  var clip = new Array();
  var i;

  // Parse out the clipping values for IE layers.

  i = str.indexOf("(");
  clip[0] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[1] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[2] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[3] = parseInt(str.substring(i + 1, str.length), 10);
  return(clip);
}

function scrollLayerTo(layer, x, y, bound) {

  var dx = getClipLeft(layer) - x;
  var dy = getClipTop(layer) - y;

  scrollLayerBy(layer, -dx, -dy, bound);
}

function scrollLayerBy(layer, dx, dy, bound) {

  var cl = getClipLeft(layer);
  var ct = getClipTop(layer);
  var cr = getClipRight(layer);
  var cb = getClipBottom(layer);

  if (bound) {
    if (cl + dx < 0)

      dx = -cl;

    else if (cr + dx > getWidth(layer))
      dx = getWidth(layer) - cr;
    if (ct + dy < 0)

      dy = -ct;

    else if (cb + dy > getHeight(layer))
      dy = getHeight(layer) - cb;
  }

  clipLayer(layer, cl + dx, ct + dy, cr + dx, cb + dy);
  moveLayerBy(layer, -dx, -dy);
}

function setBgColor(layer, color) {
    layer.style.backgroundColor = color;
}

function setBgImage(layer, src) {
    layer.style.backgroundImage = "url(" + src + ")";
}

function findLayer(name, doc) {

  var i, layer;

  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name)
      return layer;
    if (layer.document.layers.length > 0) {
      layer = findLayer(name, layer.document);
      if (layer != null)
        return layer;
    }
  }

  return null;
}

//-----------------------------------------------------------------------------
// Window and page properties.
//-----------------------------------------------------------------------------

function getWindowWidth() {
    return(document.body.clientWidth);
}

function getWindowHeight() {
    return(document.body.clientHeight);
}

function getPageWidth() {
    return(document.body.scrollWidth);
}

function getPageHeight() {
    return(document.body.scrollHeight);
}

function getPageScrollX() {
    return(document.body.scrollLeft);
}

function getPageScrollY() {
    return(document.body.scrollTop);
}

function showHint(title, text) {
		var hint_layer, new_content;
		hint_layer = document.all.hint;
		new_content = '<table bgcolor=FFFFFF height=15 border=0 cellpadding=2 cellspacing=1 Style=\'font-size: 9pt\'>';
//		new_content += '<tr><td bgcolor=#3333FF height=10 valign=middle align=center><nobr><b><font color=gold>' + title + "</font>"
//		if (text && text.length > 0) new_content += '</b></nobr></td></tr><tr><td bgcolor=#2E78E3><font color=white><nobr>' + text;
		if (text && text.length > 0) new_content += '<tr><td bgcolor=#2E78E3><font color=white><nobr>' + text;
		new_content += '</nobr></td></tr></table>';
		hint_layer.innerHTML = new_content;
		showLayer(hint_layer);
}

function moveHint() {
		var toX, toY, hint_layer;
		event_x = event.x;
		event_y = event.y;
		hint_layer = document.all.hint;
		toX = (event_x + 13 + getWidth(hint_layer) > getWindowWidth()) ? getPageScrollX() + event_x - getWidth(hint_layer) - 10: getPageScrollX() + event_x + 13;
		toY = (event_y + 13 + getHeight(hint_layer) > getWindowHeight()) ? getPageScrollY() + event_y - getHeight(hint_layer) - 10: getPageScrollY() + event_y + 13;
		moveLayerTo(hint_layer, toX, toY);
}

function hideHint() {
		document.all.hint.style.visibility = 'hidden';
}
