/*  copyright: Multimedia atelier 2002 */
/*     author: Lukas Duffek            */
/*    project: konsigna.cz             */
/*       date: 2002-09-25              */

// class ObjectRef()
function ObjectRef(objId) {
  this.elementRef = null;
  this.styleRef = null;
  this.id = objId;
  this.assigned = false;
  if (this.id != null) {
    this.get(objId);
  }
}

// ObjectRef.get()
ObjectRef.prototype.get = function(objId) {
  if (document.getElementById) {
    this.elementRef = document.getElementById(objId);
    (this.elementRef == null) ? this.styleRef = null : this.styleRef = this.elementRef.style;
  }
  else if (document.all) {
    this.elementRef = document.all[objId];
    (this.elementRef == null) ? this.styleRef = null : this.styleRef = this.elementRef.style;
  }
  else if (document.layers) {
    this.elementRef = document.layers[objId];
    (this.elementRef == null) ? this.styleRef = null : this.styleRef = this.elementRef;
  }
  (this.elementRef == null) ? this.assigned = false : this.assigned = true;
}

// ObjectRef.isVisible()
ObjectRef.prototype.isVisible = function() {
  if (this.styleRef) {
    return ((this.styleRef.visibility != "hidden") && (this.styleRef.display != "none"));
  }
}

// ObjectRef.toggleVisibility()
ObjectRef.prototype.toggleVisibility = function(value) {
  if (this.styleRef == null) return;
  if ((value != null) && ((value == "visible") || (value == "hidden"))) {
    this.styleRef.visibility = value;
  }
  if (value == null) {
    if (this.isVisible()) {
      this.styleRef.visibility = "hidden";
    }
    else {
      this.styleRef.visibility = "visible";
    }  
  }
}

// ObjectRef.toggleDisplay()
ObjectRef.prototype.toggleDisplay = function(value) {
  if (this.styleRef == null) return;
  if (value != null) {
    this.styleRef.display = value;
  }
  if (value == null) {
    if (this.isVisible()) {
      this.styleRef.display = "none";
    }
    else {
      this.styleRef.display = "";
    }  
  }
}

// ObjectRef.findChild()
ObjectRef.prototype.findChild = function(objId) {
  // DOM browsers only
  for (i = 0; i < this.elementRef.children.length; i++) {
    if (this.elementRef.children[i].id == objId) {
      return this.elementRef.children[i];
    }
    else {
      return this.findChild(this.elementRef.children[i]);
    }
  }
}

