function nodeHasChildren () {

  if (this.children.length > 0) {
    return true;
  }

  return false;
}

function nodeGetChildren () {
  return this.children;
}

function nodeRender () {

  var out = "";
  var level = "";
  var children = "";
  var display = "";
  var j, c, i;
  var start, ende;
  
  if (this.level != -1 ){


    if (this.level != 0) {
      level = "<img src=\"/images/spacer.gif\" width=\"" + (this.level * 10 ) + "\" height=\"15\">";
    }

    if (this.hasChildren()) {
      level += "<a href=\"javascript:m.toggle(" + this.id + ");\">";
      if (this.expanded) {
	var img = "/images/dminus.gif";
      } else {
	var img = "/images/dplus.gif";
      }

      level += "<img src=\"" + img + "\" width=\"12\" height=\"9\" border=\"0\" name=\"img" + this.id + "\">";
      level += "<\/a>";
    } else {
      level += "<img src=\"/images/spacer.gif\" width=\"15\" height=\"15\">";
    }
   
    //display = this.name + "[-" + this.id + "-] (" +this.level +")<br>";
    display = this.properties.eval ("<a href=\"%url\" class=\"sitemap\">%name</a><div style=\"margin-left: " + ((this.level * 10) + 15) + "px;\" class=\"sitemaptext\">%desc</div>"); 
  }

  if (this.hasChildren() && this.expanded) {
    c = this.getChildren();


    for (i = 0; i < c.length; i++) {     
      children += c[i].render();
    }    
  }

  /*if (is.ns && is.v < 5) {
    out = "<layer id=\"" + this.id + "\">" + level + display + "<layer id=\"" + this.id +"_CHILDREN\">" + children + "</layer></layer>";
  } else {
  out = "*/

  out = level + display + children;

  return out;
}

function nodeToString () {

  var out = "";

  out += "[Node id = " + this.id + " name = " + this.name + " level = " + this.level;

  if (this.parentid != null) {
    out += " parent = " + this.parentid;
  } else {
    out += " parent = null";
  }

  out += "]";
  
  return out;

}

function nodeAdd (entry) {
  
  if (this.container != null) {
    this.container.cache [String(entry.id)] = entry;
  }
  
  if (this.container != null && entry.container == null) {
    entry.container = this.container;
  }

  entry.parentid = this.id;
  entry.level = this.level + 1;
  entry.copyToProps();
  this.children[this.children.length] = entry;

}

function nodeCopyToProps () {

  this.properties.set ("id", this.id);
  this.properties.set ("name", this.name);
  this.properties.set ("level", this.level);
}

function node (id, name) {

  this.id = id;
  this.name = name;
  this.icon = null;
  this.level = -1;
  this.parentid = null;
  this.container = null;
  this.expanded = true;
  this.children = new Array();
  this.properties = new properties();
  this.copyToProps = nodeCopyToProps;
  this.hasChildren = nodeHasChildren;
  this.getChildren = nodeGetChildren;
  this.render = nodeRender;
  this.toString = nodeToString;
  this.add = nodeAdd;

  this.copyToProps ();

  if (arguments.length > 2) {
    var i;
    
    for (i = 2; i < arguments.length; i++) {      
      if (arguments[i].length && arguments[i].length == 2) {
	if (typeof (arguments[i][0]) == 'string') {
	  this.properties.set (arguments[i][0], arguments[i][1]);
	}
      }
    }
  }
    
}
