<!--
var nodeTag = 'DIV';
var textTag = 'SPAN';
function TreeViewController(treeView) {
  this.view = treeView;
  this.selectionColor = treeView.getAttribute(TAG_ATTRIBUTE.NJ_SELECTED_NODE_COLOR);
  this.expandAction = treeView.getAttribute(TAG_ATTRIBUTE.NJ_EXPAND_ACTION);
  this.collapseAction = treeView.getAttribute(TAG_ATTRIBUTE.NJ_COLLAPSE_ACTION);
  this.selectAction = treeView.getAttribute(TAG_ATTRIBUTE.NJ_SELECT_ACTION);
  this.selectedFolderImage = treeView.getAttribute(TAG_ATTRIBUTE.NJ_SELECTED_FOLDER_IMAGE);
  if (isNullString(this.selectedFolderImage)) {
		this.selectedFolderImage = 'images/nj_openfolder.gif';
  }
  this.defaultFolderImage = treeView.getAttribute(TAG_ATTRIBUTE.NJ_DEFAULT_FOLDER_IMAGE);
  if (isNullString(this.defaultFolderImage)) {
		this.defaultFolderImage = 'images/nj_folder.gif';
  }
  this.defaultNodeImage = treeView.getAttribute(TAG_ATTRIBUTE.NJ_DEFAULT_NODE_IMAGE);
  if (isNullString(this.defaultNodeImage)) {
		this.defaultNodeImage = 'images/nj_defaultnode.gif';
  }
  this.selectionNodes = new Array();
  this.shiftSize = 16;
	this.treeId = null;
	var _spanTag = getParentTag(treeView, 'SPAN', null);
	if (_spanTag != null) {
		this.treeId = _spanTag.id;
	}
  //if (!this.view.style.backgroundColor) {
  //  this.view.style.backgroundColor = '#ffffff';
  //}
  this.root = null;
  for (var i=0; i<treeView.childNodes.length; i++) {
    var t = treeView.childNodes.item(i);
    if (checkTag(t, 'SPAN')) {
    	for (var j=0; j<t.childNodes.length; j++) {
    		var t2 = t.childNodes[j];
    		if (checkTag(t2, nodeTag)) {
		      this.root = t2;
  		    break;
  		  }
			}
		}
    if (this.root != null) break;
  } 
  this.initTreeNode(this.root, 0);
  this.initTreeNodeSelection(this.root, 0);
}
TreeViewController.prototype.initTreeNode = function (element, depth) {
  if (checkTag(element,nodeTag)) {
    if (depth==0) {
      element.style.left = '2px';
    } else {
      element.style.left = this.shiftSize + 'px';
    }
    for (var i=0; i<element.childNodes.length; i++) {
      if (this.initTreeNode(element.childNodes.item(i), depth+1)) {
        element._hasChild = true;
      }
    }
    if (TAG_ATTRIBUTE.getBooleanAttribute(element, '_initialized') != true) {
      element.treeViewController = this;
      element._initialized = true;
      element.style.whitespace = 'nowrap';
      element.style.position = 'relative';
      var icon = document.createElement('IMG');
      icon.style.position = 'relative';
      setCSSFloat(icon);
      if (element.getAttribute(TAG_ATTRIBUTE.NJ_SELECTABLE) != 'false') {
        icon.onmousedown = this.treeNodeMouseDown;
      }
      element.insertBefore(icon, element.firstChild);
      element._iconImage = icon;
      this.setIconImage(element);
      var toggle = document.createElement('IMG');
      toggle.style.position = 'relative';
      setCSSFloat(toggle);
      toggle.onmousedown = this.toggleMouseDown;
      element.insertBefore(toggle, icon);
      element._toggleImage = toggle;
      if (TAG_ATTRIBUTE.getBooleanAttribute(element, TAG_ATTRIBUTE.NJ_EXPAND) == true) {
        this.expand(element);
      } else {
        this.collapse(element, true);
      }
    } 
    return true;
  } else if (checkTag(element,textTag)) {
  	if (element.getAttribute(TAG_ATTRIBUTE.NJ_HASH) == null) {
    	for (var i=0; i<element.childNodes.length; i++) {
      	return this.initTreeNode(element.childNodes.item(i), depth);
    	}
  	} else {
	    //element.style.backgroundColor = this.view.style.backgroundColor;
      var _div = element.parentNode;
      if (_div.getAttribute(TAG_ATTRIBUTE.NJ_SELECTABLE) != 'false') {
        element.onmousedown = this.treeNodeMouseDown;
        element.onmouseover = this.treeNodeMouseOver;
        element.onmouseout  = this.treeNodeMouseOut;
      }
    	element.parentNode._textNode = element;
    }
  }
  return false;
}
TreeViewController.prototype.initTreeNodeSelection = function (element, depth) {
  for (var i=0; i<element.childNodes.length; i++) {
    if (checkTag(element,textTag)) {
      var _selected = TAG_ATTRIBUTE.getBooleanAttribute(element, TAG_ATTRIBUTE.NJ_SELECTED);
      if (_selected == true) {
        this.changeSelection(element.parentNode, true);
        return;
      }
    }
    var _child = element.childNodes[i];
    if (checkTag(_child,textTag) || checkTag(_child,nodeTag)) {
      this.initTreeNodeSelection(_child, depth++);
    }
  }
}
TreeViewController.prototype.setIconImage  = function (element) {
  if (isNotNullString(element.getAttribute(TAG_ATTRIBUTE.NJ_ICON))) {
    element._iconImage.src = element.getAttribute(TAG_ATTRIBUTE.NJ_ICON);
  } else if (element._hasChild) {
    if (TAG_ATTRIBUTE.getBooleanAttribute(element, TAG_ATTRIBUTE.NJ_SELECTED) == true) {
      element._iconImage.src = this.selectedFolderImage;
    } else {
      element._iconImage.src = this.defaultFolderImage;
    } 
  } else {
    element._iconImage.src = this.defaultNodeImage;
  }
}
TreeViewController.prototype.expand  = function (element) {
  if (!element._hasChild) {
    //element._toggleImage.src = 'images/nj_null12x13.gif';
    element._toggleImage.src = 'images/nj_null10x16.gif';
  } else {
    element.setAttribute(TAG_ATTRIBUTE.NJ_EXPAND, true);
    element._toggleImage.src = 'images/nj_collapse.gif';
    for (var i=0; i<element.childNodes.length; i++) {
      var _span = element.childNodes.item(i);
      if (checkTag(_span,'SPAN')) {
      	for (var j=0; j<_span.childNodes.length; j++) {
      		var _div = _span.childNodes[j];
	      	if (checkTag(_div,nodeTag)) {
        		_div.style.display ='block';
        	}
        }
      }
    }
    this.setRootWidth(this.view.style.width, -4);
    if (Browser.isMSIE()) {
      this.checkSize(this.root);
    }
  }
}
TreeViewController.prototype.setRootWidth = function (rootWidth, offset) {
	var _w = 0;
	if (isNotNullString(rootWidth)) {
		try {
			_w = parseInt(rootWidth.substring(0,rootWidth.length-2)) + offset;
		} catch (e) {
		}
	}
	this.root.style.width = _w + 'px';
}
TreeViewController.prototype.checkSize = function (element) {
  if (element._textNode && element.style.display!='none') {
    var width = parseFloat(this.root.style.width);
    var required = element._textNode.offsetLeft + element._textNode.offsetWidth + 2;
    if (isNaN(width)  || width < required) {
      this.root.style.width = required + 'px';
    }
    for (var i=0; i<element.childNodes.length; i++) {
    	var _span = element.childNodes[i];
			if (_span.tagName == 'SPAN') {
				var _childDiv = _span.firstChild;
				if (_childDiv != null && _childDiv.tagName == 'DIV') {
	  	    this.checkSize(_childDiv);
	  	  }
	    }
    }
  }
}
TreeViewController.prototype.collapse = function (element, onInit) {
  if (!element._hasChild) {
    element._toggleImage.src = 'images/nj_null10x16.gif';
  } else {
    element.setAttribute(TAG_ATTRIBUTE.NJ_EXPAND, false);
    element._toggleImage.src = 'images/nj_expand.gif';
    for (var i=0; i<element.childNodes.length; i++) {
      var _span = element.childNodes.item(i);
      if (checkTag(_span,'SPAN')) {
      	for (var j=0; j<_span.childNodes.length; j++) {
      		var _div = _span.childNodes[j];
	      	if (checkTag(_div,nodeTag)) {
        		_div.style.display ='none';
        	}
        }
      }
    }
    if (!onInit) {
      this.setRootWidth(this.view.style.width, -4);
      if (Browser.isMSIE()) {
        this.checkSize(this.root);
      }
    }
  }
}
TreeViewController.prototype.toggleMouseDown = function (event) {
  var src = stopPropagation(event);
  if (checkTag(src,'IMG') || checkTag(src, textTag)) {
		//src = getParentTag(src, 'DIV', 'nj:tree');
    src = src.parentNode;
    if (checkTag(src, textTag)) {
    	src = src.parentNode;
    }
  }
  if (!src._hasChild) return false;
	var _treeViewController = src.treeViewController;
  var _expand = TAG_ATTRIBUTE.getBooleanAttribute(src, TAG_ATTRIBUTE.NJ_EXPAND);
  if (_expand == true) {
    _treeViewController.collapse(src,false);
    _expand = false;
  } else {
    _treeViewController.expand(src);
    _expand = true;
  }
	var _action;
	if (_expand) {
		_action = _treeViewController.expandAction;
	} else {
		_action = _treeViewController.collapseAction;
	}
	if (isNullString(_action)) _action = 'Ajax:';
	var _spanNode = getChildTag(src, 'SPAN', null, false);
	if (_spanNode != null) {
		var _nodeHash = _spanNode.getAttribute(TAG_ATTRIBUTE.NJ_HASH);
		if (isNotNullString(_nodeHash)) {
			var _inf;
			if (_expand) {
				_inf = 'tre:expand:' + _treeViewController.treeId + '::' + _nodeHash;
			} else {
				_inf = 'tre:collapse:' + _treeViewController.treeId + '::' + _nodeHash;
			}
  		doNinjavaSubmit(_spanNode, _action, false, false, null, _inf);
  	}
	}
  return false;
}
TreeViewController.prototype.treeNodeMouseOver = function (event) {  
  this.style.cursor = 'pointer';
  this.style.textDecoration = 'underline';
  this._oldColor = this.style.color;
  this.style.color = '#0000ff'; 
}
TreeViewController.prototype.treeNodeMouseOut = function (event) {
  this.style.cursor = 'auto';
  this.style.textDecoration = 'none';
  this.style.color = 
  this._oldColor;
}
TreeViewController.prototype.treeNodeMouseDown = function (event) {
  var shift;
  if (window.event) {
    shift = (window.event.shiftKey);
  } else {
    shift = (event.shiftKey);
  }
  var src = stopPropagation(event);
  if (checkTag(src,'IMG') || checkTag(src, textTag)) {
    src = src.parentNode;
    if (checkTag(src, textTag)) {
    	src = src.parentNode;
    }
  }
  var _treeViewController = src.treeViewController;
  _treeViewController.changeSelection(src, shift);
  var _action = _treeViewController.selectAction;
	if (isNullString(_action)) _action = 'Ajax:';
	var _spanNode = getChildTag(src, 'SPAN', null, false);
	var _selectedHash = _spanNode.getAttribute(TAG_ATTRIBUTE.NJ_HASH);
	var _nodeHashes = _selectedHash;
	var _selectionNodes = _treeViewController.selectionNodes;
	if (_selectionNodes.length > 1) {
  	for (var i=0; i<_selectionNodes.length; i++) {
  		var _selectionNode = _selectionNodes[i];
  		var _childHash = getChildTag(_selectionNode, 'SPAN', null, false).getAttribute(TAG_ATTRIBUTE.NJ_HASH);
  		if (_childHash != _selectedHash) {
  			_nodeHashes += ',' + _childHash;
			}
		}
	}
	var _inf = "tre:select:" + _treeViewController.treeId + '::' + _nodeHashes;
	doNinjavaSubmit(_spanNode, _action, false, false, null, _inf);
  return false;
}
TreeViewController.prototype.changeSelection = function (element, multi) {
  if (!multi) {  
    for (var i=0; i<this.selectionNodes.length; i++) {
      this.selectionNodes[i].setAttribute(TAG_ATTRIBUTE.NJ_SELECTED, false);
      //this.changeNodeColor(this.selectionNodes[i], this.view.style.backgroundColor);
      this.changeNodeColor(this.selectionNodes[i], '');
      this.setIconImage(this.selectionNodes[i]);
    }
    while (this.selectionNodes.length>0 ) {
      this.selectionNodes.pop(this.selectionNodes[0]);
    }
  }
  element.setAttribute(TAG_ATTRIBUTE.NJ_SELECTED, true);
  this.changeNodeColor(element, this.selectionColor);
  this.selectionNodes.push(element);
  this.setIconImage(element);
//------------------------------------------------------------
//------------------------------------------------------------
}
TreeViewController.prototype.changeNodeColor = function (element, color) {
  for (var i=0; i<element.childNodes.length; i++) {
    var child = element.childNodes.item(i);
    if (checkTag(child , textTag)) {
      child.style.backgroundColor = color;
      return;
    }
  }
}
function checkTag(element, tagname) {
  return (element.nodeType == 1 && element.tagName.toUpperCase() == tagname);
}
function stopPropagation(event) {
  var srcElement; 
  if (window.event) {
    srcElement = window.event.srcElement;
    window.event.cancelBubble = true;
  } else {
    srcElement = event.target;
    event.stopPropagation(); 
  }
  return srcElement;
}
function setCSSFloat(element) {
  if (Browser.isMSIE()) {
    element.style.styleFloat = 'left';
  } else {
    element.style.cssFloat = 'left';
  }
}
function initTrees(parent) {
	if (parent == null || parent.childNodes.length == 0) return;
	if (parent.tagName == 'SELECT') return;
	for (var i=0; i<parent.childNodes.length; i++) {
		var _child = parent.childNodes[i];
		if (_child.tagName == nodeTag && TAG_ATTRIBUTE.getNjType(_child) == 'nj:treeNode') {
			var _treeDiv = null;
			var _depth = 0;
			var _div = parent.parentNode;
			while (_div != null) {
				if (_div.tagName != 'DIV') {
					break;
				}
				if (TAG_ATTRIBUTE.getNjType(_div) == 'nj:tree') {
					_treeDiv = _div;
					break;
				}
				_div = _div.parentNode;
				if (_div != null) _div = _div.parentNode;
				_depth++;
			}
			if (_treeDiv != null) {
				var _root = getChildTag(_treeDiv, 'DIV', 'nj:treeNode', false);
				_root.treeViewController.initTreeNode(_child, _depth);
				_root.treeViewController.initTreeNodeSelection(_child, _depth);
			}
			return;
		}
	}
	initTreesInternal(parent);
}
function initTreesInternal(parent) {
	if (parent.tagName == 'SELECT') return;
	for (var i=0; i<parent.childNodes.length; i++) {
		var _child = parent.childNodes[i];
		if (_child.tagName == nodeTag && TAG_ATTRIBUTE.getNjType(_child) == 'nj:tree') {
			initTree(_child);
		}
		initTreesInternal(_child);
	}
}
function initTree(element) {
  var treeView = new TreeViewController(element);
}
function getTreeId(element) {
	var _treeDiv = getParentTag(element, 'DIV', 'nj:tree');
	if (_treeDiv == null) return null;
	var _parentSpan = _treeDiv.parentNode;
	if (_parentSpan == null || _parentSpan.tagName != 'SPAN') return null;
	return _parentSpan.id;
}
//-->

