var dragstarted;
var AfianTreeConfig = {
	rootIcon        : 'images/tree/foldericon.gif',
	openRootIcon    : 'images/tree/openfoldericon.gif',
	folderIcon      : 'images/tree/foldericon.gif',
	openFolderIcon  : 'images/tree/openfoldericon.gif',
	fileIcon        : 'images/tree/file.gif',
	iIcon           : 'images/tree/i.gif',
	lIcon           : 'images/tree/l.gif',
	lMinusIcon      : 'images/tree/lminus.gif',
	lPlusIcon       : 'images/tree/lplus.gif',
	tIcon           : 'images/tree/t.gif',
	tMinusIcon      : 'images/tree/tminus.gif',
	tPlusIcon       : 'images/tree/tplus.gif',
	blankIcon       : 'images/tree/blank.gif',
	defaultText     : 'Tree Item',
	defaultAction   : 'javascript:void(0);',
	defaultBehavior : 'explorer',
	loadingText		: AfianMessages['Loading...'],
	reloadingText	: AfianMessages['Reloading...']
};

var selectedPath;

var AfianTreeHandler = {
	idCounter : 0,
	idPrefix  : "afian_tree_",
	all       : new Array,
	all2       : new Array,
	behavior  : null,
	selected  : null,
	onSelect  : null,
	getId     : function() { return this.idPrefix + this.idCounter++; },
	toggle    : function (oItem) { this.all[oItem.id.replace('-plus','')].toggle(); },
	idtoggle    : function (id) { this.all[id].toggle(); },
	reload    : function (oItem) {
		this.all[oItem.id.replace('-icon','')].reload();
	},
	dropdrag	:  function (oItem) {
		this.all[oItem.id.replace('-anchor','')].dropdrag();
	},
	mouseover	:  function (oItem) {
		this.all[oItem.id.replace('-anchor','')].mouseover();
	},
	mouseout	:  function (oItem) {
		this.all[oItem.id.replace('-anchor','')].mouseout();
	},
	select     : function (oItem) { this.all[oItem.id.replace('-anchor','')].select(); },
	blur      : function (oItem) { this.all[oItem.id.replace('-anchor','')].blur(); },
	rootOnClick	: function() {},
	insertHTMLBeforeEnd	:	function (oElement, sHTML) {
		if (oElement.insertAdjacentHTML != null) {
			oElement.insertAdjacentHTML("BeforeEnd", sHTML)
			return;
		}
		var df;
		var r = oElement.ownerDocument.createRange();
		r.selectNodeContents(oElement);
		r.collapse(false);
		df = r.createContextualFragment(sHTML);
		oElement.appendChild(df);
	}
};



function AfianTreeAbstractNode(sText, sAction) {
	this.childNodes  = [];
	this.id     = AfianTreeHandler.getId();
	this.text   = sText || AfianTreeConfig.defaultText;
	this.action = sAction || AfianTreeConfig.defaultAction;
	this._last  = false;
	this.all2index = AfianTreeHandler.all2.length;
	AfianTreeHandler.all[this.id] = this;
	AfianTreeHandler.all2[this.all2index] = this;
}


AfianTreeAbstractNode.prototype.add = function (node, bNoIdent) {
	node.parentNode = this;
	this.childNodes[this.childNodes.length] = node;
	var root = this;
	if (this.childNodes.length >= 2) {
		this.childNodes[this.childNodes.length - 2]._last = false;
	}
	while (root.parentNode) { root = root.parentNode; }
	if (root.rendered) {
		if (this.childNodes.length >= 2) {
			getById(this.childNodes[this.childNodes.length - 2].id + '-plus').src = ((this.childNodes[this.childNodes.length -2].folder)?((this.childNodes[this.childNodes.length -2].open)?AfianTreeConfig.tMinusIcon:AfianTreeConfig.tPlusIcon):AfianTreeConfig.tIcon);
			this.childNodes[this.childNodes.length - 2].plusIcon = AfianTreeConfig.tPlusIcon;
			this.childNodes[this.childNodes.length - 2].minusIcon = AfianTreeConfig.tMinusIcon;
			this.childNodes[this.childNodes.length - 2]._last = false;
		}
		this._last = true;
		var foo = this;
		while (foo.parentNode) {
			for (var i = 0; i < foo.parentNode.childNodes.length; i++) {
				if (foo.id == foo.parentNode.childNodes[i].id) { break; }
			}
			if (i == foo.parentNode.childNodes.length - 1) { foo.parentNode._last = true; }
			else { foo.parentNode._last = false; }
			foo = foo.parentNode;
		}
		AfianTreeHandler.insertHTMLBeforeEnd(getById(this.id + '-cont'), node.toString());
		if ((!this.folder) && (!this.openIcon)) {
			this.icon = AfianTreeConfig.folderIcon;
			this.openIcon = AfianTreeConfig.openFolderIcon;
		}
		if (!this.folder) { this.folder = true; this.collapse(true); }
		if (!bNoIdent) { this.indent(); }
	}
	return node;
}

AfianTreeAbstractNode.prototype.toggle = function() {
	if (this.folder) {
		if (this.open) { this.collapse(); }
		else { this.expand(); }
}	}

AfianTreeAbstractNode.prototype.select = function() {
	if ((AfianTreeHandler.selected) && (AfianTreeHandler.selected != this) && (AfianTreeHandler.all[AfianTreeHandler.selected.id] != undefined)) { AfianTreeHandler.selected.deSelect();
	}
	AfianTreeHandler.selected = this;
	if ((this.openIcon)) {
		getById(this.id + '-icon').src = this.openIcon; 
	}
	getById(this.id + '-anchor').className = 'tree-item-fulltitle-selected';
	if (AfianTreeHandler.onSelect) { AfianTreeHandler.onSelect(this); }
}

AfianTreeAbstractNode.prototype.deSelect = function() {
	getById(this.id + '-anchor').className = 'tree-item-fulltitle';
	if ((this.openIcon)) {
		getById(this.id + '-icon').src = this.icon; 
	}
	AfianTreeHandler.selected = null;
}


AfianTreeAbstractNode.prototype.doExpand = function() {
/*	if (AfianTreeHandler.behavior == 'classic') { getById(this.id + '-icon').src = this.openIcon; }*/
	if (this.childNodes.length) {  getById(this.id + '-cont').style.display = 'block'; }
	this.open = true;
}

AfianTreeAbstractNode.prototype.doCollapse = function() {
	/*if (AfianTreeHandler.behavior == 'classic') { getById(this.id + '-icon').src = this.icon; }*/
	if (this.childNodes.length) { getById(this.id + '-cont').style.display = 'none'; }
	this.open = false;
}

AfianTreeAbstractNode.prototype.expandAll = function() {
	this.expandChildren();
	if ((this.folder) && (!this.open)) { this.expand(); }
}

AfianTreeAbstractNode.prototype.expandChildren = function() {
	for (var i = 0; i < this.childNodes.length; i++) {
		this.childNodes[i].expandAll();
} }

AfianTreeAbstractNode.prototype.collapseAll = function() {
	this.collapseChildren();
	if ((this.folder) && (this.open)) { this.collapse(true); }
}

AfianTreeAbstractNode.prototype.collapseChildren = function() {
	for (var i = 0; i < this.childNodes.length; i++) {
		this.childNodes[i].collapseAll();
} }

AfianTreeAbstractNode.prototype.indent = function(lvl, del, last, level, nodesLeft) {
	if (lvl == null) { lvl = -2; }
	var state = 0;
	for (var i = this.childNodes.length - 1; i >= 0 ; i--) {
		state = this.childNodes[i].indent(lvl + 1, del, last, level);
		if (state) { return; }
	}
	if (del) {
		if ((level >= this._level) && (getById(this.id + '-plus'))) {
			if (this.folder) {
				getById(this.id + '-plus').src = (this.open)?AfianTreeConfig.lMinusIcon:AfianTreeConfig.lPlusIcon;
				this.plusIcon = AfianTreeConfig.lPlusIcon;
				this.minusIcon = AfianTreeConfig.lMinusIcon;
			}
			else if (nodesLeft) { getById(this.id + '-plus').src = AfianTreeConfig.lIcon; }
			return 1;
	}	}
	var foo = getById(this.id + '-indent-' + lvl);
	if (foo) {
		if ((foo._last) || ((del) && (last))) { foo.src =  AfianTreeConfig.blankIcon; }
		else { foo.src =  AfianTreeConfig.iIcon; }
	}
	return 0;
}

function AfianTree(sText, sAction, sBehavior, sIcon, sOpenIcon) {
	this.base = AfianTreeAbstractNode;
	this.base(sText, sAction);
	this.icon      = sIcon || AfianTreeConfig.rootIcon;
	this.openIcon  = sOpenIcon || AfianTreeConfig.openRootIcon;
	this.open  = true;
	this.folder    = true;
	this.rendered  = false;
	this.onSelect  = null;
	if (!AfianTreeHandler.behavior) {  AfianTreeHandler.behavior = sBehavior || AfianTreeConfig.defaultBehavior; }
}

AfianTree.prototype = new AfianTreeAbstractNode;

AfianTree.prototype.setBehavior = function (sBehavior) {
	AfianTreeHandler.behavior =  sBehavior;
};

AfianTree.prototype.getBehavior = function (sBehavior) {
	return AfianTreeHandler.behavior;
};

AfianTree.prototype.getSelected = function() {
	if (AfianTreeHandler.selected) { return AfianTreeHandler.selected; }
	else { return null; }
}

AfianTree.prototype.remove = function() { }
AfianTree.prototype.expand = function() {
	this.doExpand();
}
AfianTree.prototype.collapse = function(b) {
	this.doCollapse();
}
AfianTree.prototype.getFirst = function() {
	return null;
}
AfianTree.prototype.getLast = function() {
	return null;
}
AfianTree.prototype.getNextSibling = function() {
	return null;
}
AfianTree.prototype.getPreviousSibling = function() {
	return null;
}

AfianTree.prototype.toString = function() {
	var str = "<div id=\"" + this.id + "\" class=\"afian-tree-item\">" +
		"<span class=\"tree-item-fulltitle\" onclick=\"" + this.action + "\"><img id=\"" + this.id + "-icon\" class=\"afian-tree-icon\" src=\"" + ((AfianTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"AfianTreeHandler.rootOnClick();\">" +
		"<span class=\"tree-item-title\">" + this.text + "</span></span></div>" +
		"<div id=\"" + this.id + "-cont\" class=\"afian-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
	var sb = [];
	for (var i = 0; i < this.childNodes.length; i++) {
		sb[i] = this.childNodes[i].toString(i, this.childNodes.length);
	}
	this.rendered = true;
	return str + sb.join("") + "</div>";
};


function AfianTreeItem(sText, sAction, eParent, sIcon, sOpenIcon, dynamic) {
	this.base = AfianTreeAbstractNode;
	this.base(sText, sAction);
	this.dynamic = dynamic;
	if (AfianTreeConfig.usePersistence) {
		this.open = (AfianTreeHandler.cookies.getCookie(this.id.substr(18,this.id.length - 18)) == '1')?true:false;
	} else { this.open = false; }
	if (sIcon) { this.icon = sIcon; }
	if (sOpenIcon) { this.openIcon = sOpenIcon; }
	if (eParent) { eParent.add(this); }
}

AfianTreeItem.prototype = new AfianTreeAbstractNode;

AfianTreeItem.prototype.remove = function() {
	var iconSrc = getById(this.id + '-plus').src;
	var parentNode = this.parentNode;
	var prevSibling = this.getPreviousSibling(true);
	var nextSibling = this.getNextSibling(true);
	var folder = this.parentNode.folder;
	var last = ((nextSibling) && (nextSibling.parentNode) && (nextSibling.parentNode.id == parentNode.id))?false:true;
	this._remove();
	if (parentNode.childNodes.length == 0) {
		getById(parentNode.id + '-cont').style.display = 'none';
		parentNode.doCollapse();
		parentNode.folder = false;
		parentNode.open = false;
	}
	if (!nextSibling || last) { parentNode.indent(null, true, last, this._level, parentNode.childNodes.length); }
	if ((prevSibling == parentNode) && !(parentNode.childNodes.length)) {
		prevSibling.folder = false;
		prevSibling.open = false;
		iconSrc = getById(prevSibling.id + '-plus').src;
		iconSrc = iconSrc.replace('minus', '').replace('plus', '');
		getById(prevSibling.id + '-plus').src = iconSrc;
		getById(prevSibling.id + '-icon').src = prevSibling.icon;
	}
	if (getById(prevSibling.id + '-plus')) {
		if (parentNode == prevSibling.parentNode) {
			iconSrc = iconSrc.replace('minus', '').replace('plus', '');
			getById(prevSibling.id + '-plus').src = iconSrc;
}	}	}

AfianTreeItem.prototype._remove = function() {
	for (var i = this.childNodes.length - 1; i >= 0; i--) {
		this.childNodes[i]._remove();
 	}
	for (var i = 0; i < this.parentNode.childNodes.length; i++) {
		if (this == this.parentNode.childNodes[i]) {
			for (var j = i; j < this.parentNode.childNodes.length; j++) {
				this.parentNode.childNodes[j] = this.parentNode.childNodes[j+1];
			}
			this.parentNode.childNodes.length -= 1;
			if (i + 1 == this.parentNode.childNodes.length) { this.parentNode._last = true; }
			break;
	}	}
	AfianTreeHandler.all[this.id] = null;
	delete AfianTreeHandler.all2[this.all2index];
	var tmp = getById(this.id);
	if (tmp) { tmp.parentNode.removeChild(tmp); }
	tmp = getById(this.id + '-cont');
	if (tmp) { tmp.parentNode.removeChild(tmp); }
}

AfianTreeItem.prototype.expand = function() {
	this.doExpand();
	getById(this.id + '-plus').src = this.minusIcon;
}

AfianTreeItem.prototype.collapse = function(b) {
	this.doCollapse();
	getById(this.id + '-plus').src = this.plusIcon;
}

AfianTreeItem.prototype.getFirst = function() {
	return this.childNodes[0];
}

AfianTreeItem.prototype.getLast = function() {
	if (this.childNodes[this.childNodes.length - 1].open) { return this.childNodes[this.childNodes.length - 1].getLast(); }
	else { return this.childNodes[this.childNodes.length - 1]; }
}

AfianTreeItem.prototype.getNextSibling = function() {
	for (var i = 0; i < this.parentNode.childNodes.length; i++) {
		if (this == this.parentNode.childNodes[i]) { break; }
	}
	if (++i == this.parentNode.childNodes.length) { return this.parentNode.getNextSibling(); }
	else { return this.parentNode.childNodes[i]; }
}

AfianTreeItem.prototype.getPreviousSibling = function(b) {
	for (var i = 0; i < this.parentNode.childNodes.length; i++) {
		if (this == this.parentNode.childNodes[i]) { break; }
	}
	if (i == 0) { return this.parentNode; }
	else {
		if ((this.parentNode.childNodes[--i].open) || (b && this.parentNode.childNodes[i].folder)) { return this.parentNode.childNodes[i].getLast(); }
		else { return this.parentNode.childNodes[i]; }
} }


AfianTreeItem.prototype.toString = function (nItem, nItemCount) {
	var foo = this.parentNode;
	var indent = '';
	if (nItem + 1 == nItemCount) { this.parentNode._last = true; }
	var i = 0;
	while (foo.parentNode) {
		foo = foo.parentNode;
		indent = "<img id=\"" + this.id + "-indent-" + i + "\" src=\"" + ((foo._last)?AfianTreeConfig.blankIcon:AfianTreeConfig.iIcon) + "\" alt=\"\" width=\"19\" height=\"16\">" + indent;
		i++;
	}
	this._level = i;
	if (this.childNodes.length) { this.folder = 1; }
	else { this.open = false; }
	if ((this.folder) || (AfianTreeHandler.behavior != 'classic')) {
		if (!this.icon) { this.icon = AfianTreeConfig.folderIcon; }
		if (!this.openIcon) { this.openIcon = AfianTreeConfig.openFolderIcon; }
	}
	else if (!this.icon) { this.icon = AfianTreeConfig.fileIcon; }
	var label = this.text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	var str = "<div id=\"" + this.id + "\" class=\"afian-tree-item\" >" +
		indent +
		"<img id=\"" + this.id + "-plus\" src=\"" + ((this.folder)?((this.open)?((this.parentNode._last)?AfianTreeConfig.lMinusIcon:AfianTreeConfig.tMinusIcon):((this.parentNode._last)?AfianTreeConfig.lPlusIcon:AfianTreeConfig.tPlusIcon)):((this.parentNode._last)?AfianTreeConfig.lIcon:AfianTreeConfig.tIcon)) + "\" onclick=\"AfianTreeHandler.toggle(this);\" width=\"19\" height=\"16\" alt=\"\" onmouseover=\"check4dragTreePlus(this)\" onmouseout=\"cancelCheck4dragTreePlus(this)\">" +
		"<span class=\"tree-item-fulltitle\" onclick=\"" + ((this.action != 'X')?this.action:'javascript:AfianTreeHandler.idtoggle(\''+this.id+'\')') + "\" id=\"" + this.id + "-anchor\" " +
		(this.target ? " target=\"" + this.target + "\"" : "") +
		" onmouseup=\"AfianTreeHandler.dropdrag(this)\" onmouseover=\"AfianTreeHandler.mouseover(this)\" onmouseout=\"AfianTreeHandler.mouseout(this)\"><img id=\"" + this.id + "-icon\" class=\"afian-tree-icon\" src=\"" + ((this.open)?this.openIcon:this.icon) + "\"  width=\"16\" height=\"16\">" +
		"<span class=\"tree-item-title\">" + label + "</span></span></div>" +
		"<div id=\"" + this.id + "-cont\" class=\"afian-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
		/*"+((this.MyFilesItem)?"title=\"Click to browse '"+this.path+"'\"":"")+"*/
	var sb = [];
	for (var i = 0; i < this.childNodes.length; i++) {
		sb[i] = this.childNodes[i].toString(i,this.childNodes.length);
	}
	this.plusIcon = ((this.parentNode._last)?AfianTreeConfig.lPlusIcon:AfianTreeConfig.tPlusIcon);
	this.minusIcon = ((this.parentNode._last)?AfianTreeConfig.lMinusIcon:AfianTreeConfig.tMinusIcon);
	return str + sb.join("") + "</div>";
}



function check4dragTreePlus(item) {
	if (dragstarted) {
		item = AfianTreeHandler.all[item.id.replace('-plus','')];
		if (item.MyFilesItem) {
			if (!item.open) {
				item.toggleTimeOut = window.setTimeout('AfianTreeHandler.idtoggle(\''+item.id+'\')', 500);
			}
		}
	}
}
function cancelCheck4dragTreePlus(item) {
	if (dragstarted) {
		item = AfianTreeHandler.all[item.id.replace('-plus','')];
		if (item.toggleTimeOut) {
			window.clearTimeout(item.toggleTimeOut);
		}
	}
}






function AfianDynTree(sText, sXmlSrc, sAction, sBehavior, sIcon, sOpenIcon) {
	this.AfianTree = AfianTree;
	this.AfianTree(sText, sAction, sBehavior, sIcon, sOpenIcon);
	this.src = sXmlSrc;
	this.loading = false;
	this.loaded = false;
	this.errorText = "";

	if (this.open)
		AfianTreeLoadData(this.src, this);
	else {
		this._loadingItem = new AfianTreeItem(AfianTreeConfig.loadingText);
		this.add(this._loadingItem);
	}
}

AfianDynTree.prototype = new AfianTree;

AfianDynTree.prototype._AfianTree_expand = AfianTree.prototype.expand;
AfianDynTree.prototype.expand = function() {
	if (!this.loaded && !this.loading) {
		AfianTreeLoadData(this.src, this);
	}
	this._AfianTree_expand();
};



function AfianDynTreeItem(sText, sXmlSrc, sAction, eParent, sIcon, sOpenIcon) {
	this.AfianTreeItem = AfianTreeItem;
	this.AfianTreeItem(sText, sAction, eParent, sIcon, sOpenIcon, true);

	this.src = sXmlSrc;
	this.loading = false;
	this.loaded = false;
	this.errorText = "";

	if (this.open)
		AfianTreeLoadData(this.src, this);
	else {
		this._loadingItem = new AfianTreeItem(AfianTreeConfig.loadingText);
		this.add(this._loadingItem);
	}
}

AfianDynTreeItem.prototype = new AfianTreeItem;

AfianDynTreeItem.prototype._AfianTreeitem_expand = AfianTreeItem.prototype.expand;
AfianDynTreeItem.prototype.expand = function() {
	if (!this.loaded && !this.loading) {
		AfianTreeLoadData(this.src, this);
	}
	this._AfianTreeitem_expand();
};


AfianDynTree.prototype.reload =
AfianDynTreeItem.prototype.reload = function () {
	
	if (this.loaded) {
		var open = this.open;
		while (this.childNodes.length > 0)
			this.childNodes[this.childNodes.length - 1].remove();

		this.loaded = false;

		this._loadingItem = new AfianTreeItem(AfianTreeConfig.reloadingText);
		this.add(this._loadingItem);

		 this.expand();
		 
		 
		 if (AfianTreeHandler.selected) {
			selectedPath = AfianTreeHandler.selected.path;
		}

			if (selectedPath) {
			this.onreload = new Function('onreload(\''+addSingleSlashess(selectedPath)+'\')');
			}
		 
		 
	}
	else if (this.open && !this.loading)
		AfianTreeLoadData(this.src, this);
};



function AfianTreeLoadData(sSrc, jsNode) {
	if (jsNode.loading || jsNode.loaded)
		return;
	jsNode.loading = true;
	
	ifrm = newHiddenIframe(jsNode.id+'-tree-iframe')
	ifrm.src = sSrc+'&id='+jsNode.id;
	jsNode.iframe = ifrm;

}


function FolderBrowserLoadTreeItem(oNode) {
	var text = oNode["text"];
	var parent = null;
	var icon = oNode["icon"];
	var openIcon = AfianTreeConfig.openFolderIcon;
	var target = oNode["target"];
	var path = oNode['path'];
	var dynamic = true;
	var action = 'javascript:writePath(\''+addSingleSlashess(path)+'\', \''+addSingleSlashess(text)+'\')';
	var src = 'index.php?folder_browser_data_feeder=1&path='+encodeURIComponent(path);
	var jsNode = new AfianDynTreeItem(text, src, action, parent, icon, openIcon, dynamic);
	jsNode.path = path;
	return jsNode;
}

function MyFilesLoadTreeItem(oNode) {
	var text = oNode["text"];
	var parent = null;
	var icon = oNode["icon"];
	var openIcon = AfianTreeConfig.openFolderIcon;
	var target = oNode["target"];
	var path = oNode['path'];
	var dynamic = true;
	action = 'javascript:OpenTreeFolder(\''+addSingleSlashess(path)+'\', \''+addSingleSlashess(text)+'\')';
		var src = '?file=tree_listing&path='+encodeURIComponent(path);
	var jsNode;
	
	if (src != null && src != "")
		jsNode = new AfianDynTreeItem(text, src, action, parent, icon, openIcon, dynamic);
	else
		jsNode = new AfianTreeItem(text, action, parent, icon, openIcon);

	if (target != "")
		jsNode.target = target;
	jsNode.path = path;
	jsNode.MyFilesItem = true;
	return jsNode;
}


function ListUser(oNode) {
	var text = oNode["text"];
	var parent = null;
	var icon = "images/tree/afn.gif";
	var src = '?listusers=1&sub=treelisting&uid='+oNode['uid'];
	var dynamic = true;
	var action = 'X';
	var jsNode;
	jsNode = new AfianDynTreeItem(text, src, action, parent, icon, icon, dynamic);

	jsNode.path = path;
	return jsNode;
}

function ListSharedFolder(oNode) {
	var text = oNode["text"];
	var parent = null;
	var icon = oNode["icon"];
	var openIcon = oNode["openIcon"];	
	var target = oNode["target"];
	if (oNode['path']) {
		var path = oNode['path'];
	} else {
		var path = '/'+text;
	}
	var src = '?listusers=1&sub=treelisting&uid='+oNode['uid']+'&path='+oNode['uid']+'::'+encodeURIComponent(path);
	var action = 'javascript:openShare(\''+oNode['user']+'\', \''+oNode['uid']+'\', \''+path+'\')';
	var jsNode;
	jsNode = new AfianDynTreeItem(text, src, action, parent, icon, openIcon, true);
	jsNode.path = oNode['user']+'::'+path;
	return jsNode;
}


function AfianTreeDataLoaded(newIcons, jsParentNode, fnc) {
	if (jsParentNode.loaded)
		return;

		if (!fnc) {
			fnc = MyFilesLoadTreeItem;
		}
		
	var bIndent = false;
	var bAnyChildren = false;
	jsParentNode.loaded = true;
	jsParentNode.loading = false;

		cs = newIcons

		var l = cs.length;
		for (var i = 0; i < l; i++) {
				bAnyChildren = true;
				bIndent = true;
				jsParentNode.add(fnc(cs[i]), true);
		}

	if (jsParentNode._loadingItem != null) {
		jsParentNode._loadingItem.remove();
		bIndent = true;
	}

	AfianHandler.iframesContainer.removeChild(jsParentNode.iframe);
	
	
	if (bIndent) {
		jsParentNode.indent();
	}

	if (jsParentNode.errorText != "")
		window.status = jsParentNode.errorText;
	
	
	
	if (jsParentNode.onreload) {
		jsParentNode.onreload();
	}

}




function reloadTreeByPath(path) {
	for (var i = 0 ; i < AfianTreeHandler.all2.length; i++) {
		if (AfianTreeHandler.all2[i] != undefined && AfianTreeHandler.all2[i].path == path) {
			AfianTreeHandler.all2[i].reload();
		return;
		}
	}
}

function onreload(path) {
	toggleTreeByPath(path);
}

function toggleTreeByPath(path) {
	for (var i = 0 ; i < AfianTreeHandler.all2.length; i++) {
		if ((AfianTreeHandler.all2[i] != undefined) && (AfianTreeHandler.all2[i].path == path)) {
		if (AfianTreeHandler.all2[i].folder) {
			if (!AfianTreeHandler.all2[i].open) {
				AfianTreeHandler.all2[i].expand();
			}
		}
			AfianTreeHandler.all2[i].select();
		return;
		}
	}
}



function parseTree(treeitem, str) {
for (var i = 0 ; i < AfianTreeHandler.all2.length; i++) {
	if (AfianTreeHandler.all2[i] != undefined) {
	str += AfianTreeHandler.all2[i].text;
	str += '\r\n';
	}
}
		return str;

}


function OpenTreeFolder(path, text) {
	bp = AfianHandler.activeTab.section;
	//cd(path, (bp != 'myfiles')?true:false, text); //opens in same tab
	cd(path, true, text);
}


/* drag and drop */

AfianTreeAbstractNode.prototype.dropdrag = function () {
	if (dragstarted) {
		if (this.MyFilesItem) {
		MyFilesDropDrag(this.path);
		} else {
			if (this.path == 'trash@afian') {
				MyFilesDel();
			}
		}
				if (this.dragOverHilight) {
					this.mouseout();
				}
	}		
};

AfianTreeAbstractNode.prototype.mouseover = function () {
	thea = getById(this.id+'-anchor');
	if (dragstarted) {
		if (this.MyFilesItem || this.path == 'trash@afian') {
			this.origBgColor = thea.style.backgroundColor;
			thea.style.backgroundColor='#d7d7d7';/*#B3E8FE*/
			thea.style.textDecoration='none';
			this.dragOverHilight = true;
			/*
			getById('dragcontainer').style.border = '1px solid gray';

			if (this.MyFilesItem) {
			AfianBubbleMessage('Move dragged items to \''+this.path+'\'', 10000);
			} else {
			AfianBubbleMessage('Move dragged items to Trash', 10000);
			}
			*/
		}
	} else {
		thea.style.textDecoration='underline';
		thea.style.color='navy';
	}		
};

AfianTreeAbstractNode.prototype.mouseout = function () {
	thea = getById(this.id+'-anchor');
	if (dragstarted) {
		if (this.MyFilesItem || this.path == 'trash@afian') {
			if (this.origBgColor != undefined) {
				thea.style.backgroundColor=this.origBgColor;
				thea.style.textDecoration='';
				this.dragOverHilight = false;
				delete this.origBgColor;
			/*
				getById('dragcontainer').style.border = 'none';
				AfianBubbleMessage('', 0);
			*/
			}
		}
	} else {
	thea.style.textDecoration='none';
	thea.style.color='black';
	}			
};