/*
Copyright by G & S GmbH - F.Falkner 
Every redistribution permitted.
*/

function TreeDisplayStd(tree,behaviour,renderFunc,path,indentWidth) {
	this.tree = tree;
	this.behaviour = behaviour || "EXPAND_ONE";
	this.renderFunc = renderFunc || alert("RenderFunction is missing!");
	this.path = path || "";
	this.indentWidth = indentWidth || 10;
	this.sel = null;
	this.forum = false;
	this.home = false,
	this.journal = false;
}

TreeDisplayStd.prototype.select = function(ukatnr,selParents,doUnselect) {
	var selNode = this.tree.getNode(ukatnr,"ukatnr");
	var selCat = selNode.userObject;
	if (!selNode) return;
	if (doUnselect)
		this.tree.root.collapse("COLLAPSE_CHILDREN");
	selNode.expand();
	if (selParents && selCat.ordernr.length > 5) {
		var parentNode = selNode;
		while (parentNode.parent) {
			parentNode.parent.expand();
			parentNode = parentNode.parent;
		}
	}
	this.sel = selNode;
}

TreeDisplayStd.prototype.toHtml = function() {
	var h="";

	for (var i=0;i<this.tree.root.childNodes.length;i++)
		h+=this.drawNode(this.tree.root.childNodes[i]);
	return h;
}

TreeDisplayStd.prototype.drawNode = function(node) {
	var cat = node.userObject;
	var nameSpan = (19 - cat.ordernr.length) / 2;
	
	var spacerSpan = 7-nameSpan;
	var spacerHtml="";
	spacerHtml = this.spacerHtml(spacerSpan);
	
	var isSel = false;
	if (node == this.sel)
		isSel = true;
	var h = this.renderFunc(isSel,nameSpan,spacerSpan,node);
	if (node.expanded) {
		for (var i=0;i<node.childNodes.length;i++)
			h+=this.drawNode(node.childNodes[i]);
	}
	if (this.endRenderFunc) {
		h+=this.endRenderFunc(node);
	}
	return h;
}

TreeDisplayStd.prototype.spacerHtml = function(cols) {
	if (cols == 0) return "";
	var w = this.indent*cols;
	return "<td width='"+w+"'><img src='../pics/spacer.gif' width='"+w+"' height=2></td>";
}

TreeDisplayStd.prototype.getParents = function(ukatnr) {
	var retAry = new Array();
	var selNode = this.tree.getNode(ukatnr,"ukatnr");
	if (!selNode) return retAry;
	while (selNode.parent) {
		retAry[retAry.length] = selNode;
		selNode = selNode.parent;
	}
	return retAry;
}
/*
TreeDisplay.prototype.expand = function(ukatnr) {
	var node = this.tree.getNode(ukatnr,"ukatnr");
	node.expand();
	this.redraw();
}

TreeDisplay.prototype.collapse = function(ukatnr) {
	var node = this.tree.getNode(ukatnr,"ukatnr");
	node.collapse();
	this.redraw();
}

TreeDisplay.prototype.detail = function(ukatnr) {
	var node = this.tree.getNode(ukatnr,"ukatnr");
	this.sel = node;
	var cat = node.userObject;
	contentFrame.location.href=cat.script+"?ukatnr="+cat.ukatnr+"&ukatnr="+cat.ukatnr+"&ukatname="+cat.name+"&ausgabescript="+cat.script;
	this.expand(ukatnr);
}*/	

