<!--
// DBUS! Deutschland - Enterprise Information Portal By Busskamp And Scholwin
// Source Code By Dirk Busskamp And Web Design By Sabine Busskamp
// Copyright 2000 - 2010 DBUS! Deutschland
// http://www.dbus.de
// mailto:info@dbus.de

dbusfxTreeConfig.loadingText = "Loading...";
dbusfxTreeConfig.loadErrorTextTemplate = "Error loading \"%1%\"";
dbusfxTreeConfig.emptyErrorTextTemplate = "Error \"%1%\" does not contain any tree items";

function dbusfxLoadTree(sText, sXmlSrc, sAction, sBehavior, sIcon, sOpenIcon) {
this.dbusfxTree = dbusfxTree;
this.dbusfxTree(sText, sAction, sBehavior, sIcon, sOpenIcon);
this.src = sXmlSrc;
this.loading = false;
this.loaded = false;
this.errorText = "";
if (this.open) {
_startLoadXmlTree(this.src, this);
}
else {
this._loadingItem = new dbusfxTreeItem(dbusfxTreeConfig.loadingText);
this.add(this._loadingItem);
}
}

dbusfxLoadTree.prototype = new dbusfxTree;
dbusfxLoadTree.prototype._dbusfxtree_expand = dbusfxTree.prototype.expand;
dbusfxLoadTree.prototype.expand = function() {
if (!this.loaded && !this.loading) {
_startLoadXmlTree(this.src, this);
}
this._dbusfxtree_expand();
}

function dbusfxLoadTreeItem(sText, sXmlSrc, sAction, eParent, sIcon, sOpenIcon) {
this.dbusfxTreeItem = dbusfxTreeItem;
this.dbusfxTreeItem(sText, sAction, eParent, sIcon, sOpenIcon);
this.src = sXmlSrc;
this.loading = false;
this.loaded = false;
this.errorText = "";
if (this.open) {
_startLoadXmlTree(this.src, this);
}
else {
this._loadingItem = new dbusfxTreeItem(dbusfxTreeConfig.loadingText);
this.add(this._loadingItem);
}
}

dbusfxLoadTreeItem.prototype = new dbusfxTreeItem;
dbusfxLoadTreeItem.prototype._dbusfxtreeitem_expand = dbusfxTreeItem.prototype.expand;
dbusfxLoadTreeItem.prototype.expand = function() {
if (!this.loaded && !this.loading) {
_startLoadXmlTree(this.src, this);
}
this._dbusfxtreeitem_expand();
}

function _startLoadXmlTree(sSrc, jsNode) {
if (jsNode.loading || jsNode.loaded) {
return;
}
jsNode.loading = true;
if ((window.location.protocol == "http:") ||
(document.implementation && document.implementation.createDocument)) {
var xmlHttp = XmlHttp.create();
xmlHttp.open("GET", sSrc, true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4)
_xmlFileLoaded(xmlHttp.responseXML, jsNode);
};
window.setTimeout(function () {
xmlHttp.send(null);
}, 10);
}
else {
var xmlFile = new ActiveXObject("Microsoft.XMLDOM");
xmlFile.async="true";
xmlFile.onreadystatechange = function () {
if (xmlFile.readyState == 4)
_xmlFileLoaded(xmlFile, jsNode);
};
window.setTimeout(function () {
xmlFile.load(sSrc);
}, 10);
}
}

function _xmlTreeToJsTree(oNode) {
var text = oNode.getAttribute("text");
var action = oNode.getAttribute("action");
var parent = null;
var icon = oNode.getAttribute("icon");
var openIcon = oNode.getAttribute("openIcon");
var src = oNode.getAttribute("src");
var jsNode;
if (src != null && src != "") {
jsNode = new dbusfxLoadTreeItem(text, src, action, parent, icon, openIcon);
}
else {
jsNode = new dbusfxTreeItem(text, action, parent, icon, openIcon);
}
var cs = oNode.childNodes;
var l = cs.length;
for (var i = 0; i < l; i++) {
if (cs[i].tagName == "tree") {
jsNode.add( _xmlTreeToJsTree(cs[i]), true );
}
}
return jsNode;
}

function _xmlFileLoaded(oXmlDoc, jsParentNode) {
if (jsParentNode.loaded) {
return;
}
var bIndent = false;
var bAnyChildren = false;
jsParentNode.loaded = true;
jsParentNode.loading = false;
if( oXmlDoc == null || oXmlDoc.documentElement == null) {
jsParentNode.errorText = parseTemplateString(dbusfxTreeConfig.loadErrorTextTemplate,
jsParentNode.src);
}
else {
var root = oXmlDoc.documentElement;
var cs = root.childNodes;
var l = cs.length;
for (var i = 0; i < l; i++) {
if (cs[i].tagName == "tree") {
bAnyChildren = true;
bIndent = true;
jsParentNode.add( _xmlTreeToJsTree(cs[i]), true);
}
}
if (!bAnyChildren) {
jsParentNode.errorText = parseTemplateString(dbusfxTreeConfig.emptyErrorTextTemplate,
jsParentNode.src);
}
}
if (jsParentNode._loadingItem != null) {
jsParentNode._loadingItem.remove();
bIndent = true;
}
if (bIndent) {
jsParentNode.indent();
}
if (jsParentNode.errorText != "") {
window.status = jsParentNode.errorText;
}
}

function parseTemplateString(sTemplate) {
var args = arguments;
var s = sTemplate;
s = s.replace(/\%\%/g, "%");
for (var i = 1; i < args.length; i++) {
s = s.replace( new RegExp("\%" + i + "\%", "g"), args[i] )
}
return s;
}
//-->
