function Coord(x, y){
  this.x = (!x)?0:x;
  this.y = (!y)?0:y;
  
  //this.toString = objToString;
  //this.equals = equalsCoord;
}

function getLayerRef (id, document) {
  if (!document)
    document = window.document;
  if (document.layers) {
    for (var l = 0; l < document.layers.length; l++)
      if (document.layers[l].id == id)
        return document.layers[l];
    for (var l = 0; l < document.layers.length; l++) {
      var result = getLayerRef(id, document.layers[l].document);
      if (result)
        return result;
    }
    return null;
  }
  else if (document.all) {
    return document.all[id];
  }
  else if (document.getElementById) {
    return document.getElementById(id);
  } else {
    return null;
  }
}

function setPosition(objLayer, coords){
  br=navigator.appName;
    
    if (document.layers ) {
      alert(navigator.appName);
      objLayer.top = coords.y;
      objLayer.left = coords.x;
    } else if (window.opera) {
      objLayer.style.top = coords.y;
      objLayer.style.left = coords.x;
    } else if (document.all) {
      objLayer.style.pixelTop = coords.y;
      objLayer.style.pixelLeft = coords.x;
    } else if (document.getElementById) {
      objLayer.style.top = coords.y + 'px'; 
      objLayer.style.left = coords.x + 'px';
    }
}

function setPositionById(id, coords){
	var objLayer = getLayerRef( id, document );
	setPosition( objLayer, coords );
}

function setVisibility(objLayer, visible) {
	if(document.layers){
    objLayer.visibility  = 
        (visible == true) ? 'show' : 'hide';
  } else {
    objLayer.style.visibility = 
        (visible == true) ? 'visible' : 'hidden';
  }
}

function setVisibilityById(id, visible) {
	var objLayer = getLayerRef( id, document );
	alert( objLayer );
	setVisibility( objLayer, visible );
}

function getLayerCoords( objLayer ){
  var coords = new Coord();
  
  if (document.layers) {
    coords.y = objLayer.top;
    coords.x = objLayer.left;
  } else if ( window.opera ) {
    coords.y = objLayer.style.top;
    coords.x = objLayer.style.left;
  } else if (document.all) {
    o = objLayer;
    while(o.offsetParent) {
      coords.y += parseInt(o.offsetTop);
      coords.x += parseInt(o.offsetLeft);
      o = o.offsetParent;
    }
  } else if (document.getElementById) {
    coords.y = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue('top') ); 
    coords.x = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue("left") );
  }
 
  return coords;
}

function getLayerCoordsById( id ){
  var objLayer = getLayerRef(id);
  var coords = new Coord();
  
  if (document.layers) {
    coords.y = objLayer.top;
    coords.x = objLayer.left;
  } else if ( window.opera ) {
    coords.y = objLayer.style.top;
    coords.x = objLayer.style.left;
  } else if (document.all) {
    o = objLayer;
    while(o.offsetParent) {
      coords.y += parseInt(o.offsetTop);
      coords.x += parseInt(o.offsetLeft);
      o = o.offsetParent;
    }
  } else if (document.getElementById) {
    coords.y = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue('top') ); 
    coords.x = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue("left") );
  }
 
  return coords;
}

