/******************************************************************************
* gshpHierarchyRuntime.js
*******************************************************************************
Runtime du gestionnaire de hierarchie
*******************************************************************************
*                                                                             *
* Copyright 2006 Isotools				                      *
*                                                                             *
******************************************************************************/
var hierarchyEditor;

//
// ------------------------------------- Global functions
//
function gshpRemapNewOids(map)
{
	if (hierarchyEditor) {
		hierarchyEditor.remapNewOids(map);
	}
}

function gshpHierarchyGetElement(evt) 
{
	if (document.all != null) {
		return window.event.srcElement;
	} else {
		return evt.currentTarget;
	}
}

function gshpHierarchyPlusMinusClick(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.plusMinusClick(evt, element);
}

function gshpHierarchyTitleClick(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.titleClick(evt, element);
	return false;
}

function gshpHierarchyDragStart(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.dragStart(evt, element);
}

function gshpHierarchyDragIt(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.dragIt(evt, element);
}

function gshpHierarchyTitleBlur(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.titleBlur(evt, element);
}

function gshpHierarchyChangeTitle(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.changeTitle(evt, element);
}

function gshpHierarchyDragEnd(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.dragEnd(evt, element);
}

function gshpHierarchyStopEvent(evt)
{
	evt || (evt = window.event);
	var element = gshpHierarchyGetElement(evt);
	hierarchyEditor.stopEvent(evt, element);
}

//
// ------------------------------------- class GshpHierarchyLeaf
//
var hierarchyEditor;
function GshpHierarchyDir(record, showVisibilityStat)
{
	this.oid = parseInt(record[0], 10);
	this.type = 0;
	this.parent = parseInt(record[2], 10);
	if(isNaN(this.parent)) this.parent = null;
	this.srank = parseInt(record[3], 10);
	if(isNaN(this.srank)) this.srank = null;
	this.label = record[4];
	var mask = parseInt(record[5], 10);
	this.isSpecial = (mask & 1) == 0;
	this.isOnlineCreated = (mask & 2) != 0;
	this.childDirs = new Array();
	this.childLeaves =  new Array();
	this.modified = 0;
	this.localCount =  parseInt(record[6], 10);
	if(isNaN(this.localCount)) this.localCount = 0;
	this.localVisibleCount =  parseInt(record[7], 10);
	if(isNaN(this.localVisibleCount)) this.localVisibleCount = 0;
	this._showVisibilityStat = showVisibilityStat;
}
GshpHierarchyDir.prototype.created = 1;
GshpHierarchyDir.prototype.deleted = 2;
GshpHierarchyDir.prototype.modifiedTitle = 4;
GshpHierarchyDir.prototype.modifiedSubdirs = 8;
GshpHierarchyDir.prototype.modifiedLeaves = 16;

GshpHierarchyDir.prototype.plusIcon = "iso_icons/dynlib_plus.gif";
GshpHierarchyDir.prototype.minusIcon = "iso_icons/dynlib_minus.gif";
GshpHierarchyDir.prototype.emptyIcon = "iso_icons/empty.gif";


GshpHierarchyDir.prototype.changeOid = function(newOid)
{
	var oldOid = this.oid;
	this.oid = newOid;
	this.li.id = "I" + this.oid;

	this.modified &= ~this.created;
	for(var i=0;i<this.childDirs.length;i++) {
		var child = this.childDirs[i];
		child.changeParentOid(newOid);
	}
	for(var i=0;i<this.childLeaves.length;i++) {
		var child = this.childLeaves[i];
		child.changeParentOid(newOid);
	}
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode != null) {
		parentNode.changeChildOid(oldOid, newOid);
	}
	if(this == hierarchyEditor.selectedNode) {
		this.select();
	}
	hierarchyEditor.dirOidHasChanged(oldOid, this);
}

GshpHierarchyDir.prototype.changeParentOid = function(newOid)
{
	this.parent = newOid;
}

GshpHierarchyDir.prototype.isSelfOrAncestorSpecial = function()
{
	if(this.isSpecial) return true;
	if(this.parent == null) return false;
	var parentNode = hierarchyEditor.getNode(this.parent);
	if(parentNode == null) return false;
	return parentNode.isSelfOrAncestorSpecial();
}
GshpHierarchyDir.prototype.changeChildOid = function(oldOid, newOid)
{
	for(var i=0;i<this.childDirs.length;i++) {
		if(this.childDirs[i] == oldOid) this.childDirs[i] = newOid;
	}
	
}

GshpHierarchyDir.prototype.edit = function(url) 
{
	url += "?category=" + this.oid;
	window.frames.top.document.location.href = url;
}

GshpHierarchyDir.prototype.showDetail = function(url) 
{
	url += "?category=" + this.oid + "#results";
	window.frames.top.frames.searchFrame.document.location.href = url;
}

GshpHierarchyDir.prototype.addChild = function(node, h)
{
	switch(node.type) {
	case 0: this.childDirs[this.childDirs.length] = node.oid; break;
	default: this.childLeaves[this.childLeaves.length] = node.oid; break;
	}
	return true;
}

GshpHierarchyDir.prototype.getGlobalCount = function()
{
	if(this.globalCount != null) return this.globalCount;
	var n = 0;
	for(var i=0;i<this.childDirs.length;i++) {
		var node = hierarchyEditor.getNode(this.childDirs[i]);
		n += node.getGlobalCount();
	}
	return this.globalCount = n + this.localCount;
}
GshpHierarchyDir.prototype.getGlobalVisibleCount = function()
{
	if(this.globalVisibleCount != null) return this.globalVisibleCount;
	var n = 0;
	for(var i=0;i<this.childDirs.length;i++) {
		var node = hierarchyEditor.getNode(this.childDirs[i]);
		n += node.getGlobalVisibleCount();
	}
	return this.globalVisibleCount = n + this.localVisibleCount;
}

GshpHierarchyDir.prototype.generateChildren = function(h, div, parentOids)
{
	for(var i=0;i<this.childDirs.length;i++) {
		this.addSep(h, div, "d", i);
		var node = h.getNode(this.childDirs[i]);
		node.generate(h, div, parentOids);
	}
	for(var i=0;i<this.childLeaves.length;i++) {
		this.addSep(h, div, "l", i);
		var node = h.getNode(this.childLeaves[i]);
		node.generate(h, div, parentOids);
	}

}


GshpHierarchyDir.prototype.deleteDir = function()
{
	if(this.open == false) {
		this.plusMinusClick();
	}
	var rank = this.rank;
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode == null) return;
	while(this.childDirs.length) {
		var child = hierarchyEditor.getNode(this.childDirs[0]);
		parentNode.insertChild(child, rank++);
	}
	var rank = 0;
	while(this.childLeaves.length) {
		var child = hierarchyEditor.getNode(this.childLeaves[0]);
		parentNode.insertChild(child, rank++);
	}
	parentNode.removeChild(this);
	parentNode.updateRanks();
	this.li.parentNode.removeChild(this.li.previousSibling);
	this.li.parentNode.removeChild(this.li);
	this.modified |= this.deleted;
}

GshpHierarchyDir.prototype.addSep = function(h, div, type, rank)
{
	var sep = document.createElement("div");
	sep.className = "sep";
	sep.setAttribute("_t" , type);
	sep.setAttribute("_r" , rank);
	sep.innerHTML = String.fromCharCode(160);
	if(div != null) div.appendChild(sep);
	return sep;
}

GshpHierarchyDir.prototype.generate = function(h, div, parentOids)
{
	var full=this.childDirs.length > 0 || this.childLeaves.length > 0;
	var open = this.open = parentOids[this.oid] != null;
	var li = this.li = document.createElement("div");
	if(div != null) {
		div.appendChild(li);
	}
	li.id = "I" + this.oid;
	li.className = "dirRow";
	var a = this.a = document.createElement("a");
	li.appendChild(a);
	var img = document.createElement("img");
	this.img = img;
	img.align='absbottom';
	//img.width = 16;
	//img.height = 16;
	img.style.width = "16px";
	img.style.height = "16px";
	img.border = 0;
	if(full) {
		if(open) {
			img.src = this.minusIcon;
		} else {
			img.src = this.plusIcon;
		}
		a.href = "#";
		a.name = "never";
		a.onclick = gshpHierarchyPlusMinusClick;
	} else {
		img.src = this.emptyIcon;
		this.open = null;
		a.name = "never";
	}
	a.appendChild(img);
	var icon = document.createElement("img");
	icon.src = this.isSelfOrAncestorSpecial() ? "iso_icons/gshp_inactive_section.gif" : "iso_icons/gshp_section.gif";
	icon.align='absbottom';
	li.appendChild(icon);
	var a = this.title = document.createElement("a");
	a.className = "dir" + (this.isSpecial ? " productTitleEmph": "");
	a.href = "#";

	var alt = "";
	if(this.isSpecial) alt = "Rayon inactif\n";
	else if(this.isSelfOrAncestorSpecial()) alt = "Rayon invisble car ancêtre inactif\n";
	li.appendChild(a);

	var count = "";
	if (this._showVisibilityStat == true) {
		var globalCount = this.getGlobalCount();
		var globalVisibleCount = this.getGlobalVisibleCount();
		if(globalVisibleCount != 0 || globalCount !=0) {
			count += globalVisibleCount + "/" + globalCount;
		}
		if(count != "") count = " (" + count + ")";
	}
	a.innerHTML = this.label + count;

	if (this._showVisibilityStat == true) {
		var visibleAlt = "";
		if (this.localCount == 0)
			visibleAlt = "aucun article";
		else {
			switch(this.localVisibleCount) {
				case 0:	visibleAlt = "aucun article visible"; break;
				case 1:	visibleAlt = "1 article visible"; break;
				default : visibleAlt = this.localVisibleCount + " articles visibles"; break;
			}
			visibleAlt += " / ";
			switch(this.localCount) {
				case 1:	visibleAlt += "1 article"; break;
				default : visibleAlt += this.localCount + " articles"; break;
			}
		}
		if (visibleAlt != "") alt += "contient localement " + visibleAlt + "\n";

		visibleAlt = "";
		if (this.globalCount == 0)
			visibleAlt = "aucun article";
		else {
			switch(globalVisibleCount) {
				case 0:	visibleAlt = "aucun article visible"; break;
				case 1:	visibleAlt = "1 article visible"; break;
				default : visibleAlt = globalVisibleCount + " articles visibles"; break;
			}
			visibleAlt += " / ";
			switch(globalCount) {
				case 1:	visibleAlt += "1 article"; break;
				default : visibleAlt += globalCount + " articles"; break;
			}
		}
		if (visibleAlt != "") alt += "contient globalement " + visibleAlt;
	}
	a.title = alt;

	a.onclick = gshpHierarchyTitleClick;
	if(full && open) {
		var ul = document.createElement("ul");
		this.ul = ul;
		li.appendChild(ul);
		this.generateChildren(h, ul, parentOids)
	}
	return li;
}
GshpHierarchyDir.prototype.setRank = function(rank)
{
	this.rank = rank;
	if(this.title) {
		var label = "";
		//label = rank + " ";
		this.title.innerHTML = label + this.label;
		var sep = this.li.previousSibling;
		if(sep != null) {
			sep.setAttribute("_r", "" + rank);
			//sep.innerHTML = "" + rank;
		} 
	}
}

GshpHierarchyDir.prototype.changeTitle = function(title)
{
	if(this.label == title) return;
	this.modified |= this.modifiedTitle;
	this.title.innerHTML = this.label = title;
}

GshpHierarchyDir.prototype.addNewDir = function(dir)
{
	var rank = this.childDirs.length;
	if(!this.open || this.open == null) {
		this.plusMinusClick();
	}
	var pivot = this.ul.childNodes[this.childDirs.length * 2];
	this.childDirs[this.childDirs.length] = dir.oid;
	var sep = this.addSep(hierarchyEditor, this.ul, "d", rank);
	var li = dir.generate(hierarchyEditor, this.ul, {});
	if(pivot == null) {
		this.ul.appendChild(sep);
		this.ul.appendChild(li);
	} else {
		this.ul.insertBefore(sep, pivot);
		this.ul.insertBefore(li, pivot);
	}
	dir.setRank(rank);
	this.modified |= this.modifiedSubdirs;
}

GshpHierarchyDir.prototype.highlightSeparator = function(rank, type)
{
	if(this.ul == null) return;
	var pos = 2 * rank;
	if(type == 1) pos += 2 * this.childDirs.length;
	var element;
	if(pos < this.ul.childNodes.length) {
		element = this.ul.childNodes(pos);
	} else {
		element = this.title;
	}
	hierarchyEditor.highlightTargetElement(element);
}

GshpHierarchyDir.prototype.getTitleElement = function(h, div, parentOids)
{
	return this.title;
}

GshpHierarchyDir.prototype.insertChild = function(child, rank)
{
	var node = this;
	while(node) {
		if(node == child) return;
		node = hierarchyEditor.getNode(node.parent);
	}
	if(!this.open || this.open == null) {
		this.plusMinusClick();
	}
	var list;
	if(child.type == 0) {
		list = this.childDirs
	} else {
		list = this.childLeaves;
	}
	if(rank == null) {
		rank = list.length;
	}
	var oid = this.oid;
	if(oid == -1) oid = null;
	if(child.parent != oid) {
		var parentNode = hierarchyEditor.getNodeOrRoot(child.parent);
		parentNode.removeChild(child);
		child.parent = this.oid;
		for(var i=list.length- 1;i>=rank;i--) {
			list[i+1] = list[i];
		}
		list[rank] = child.oid;
	} else {
		if(rank > child.rank) {
			rank--; 
		}
		if(rank == child.rank) return;
		if(rank > child.rank) {
			for(var i=child.rank +1;i<=rank;i++) {
				var oid = list[i];
				if(oid == null) alert("too big " + i + " " + list.length);
				list[i-1] = oid;				
			}
			list[rank] = child.oid;
			child.setRank(rank);
		} else {
			for(var i=child.rank-1;i>=rank;i--) {
				var oid = list[i];
				var brother = hierarchyEditor.getNode(oid);
				list[i+1] = oid;				
			}
			list[rank] = child.oid;
		}
	}
	var li = child.li;
	var sep = li.previousSibling;
	var ul = li.parentNode;
	ul.removeChild(li);
	ul.removeChild(sep);
	var pos = 2 * rank;
	if(child.type == 1) pos += 2 * this.childDirs.length;
	if(rank != null && pos < this.ul.childNodes.length) {
		var pivot = this.ul.childNodes(pos);
		this.ul.insertBefore(sep, pivot); 
		this.ul.insertBefore(li, pivot); 
	} else {
		this.ul.appendChild(sep); 
		this.ul.appendChild(li); 
	}
	this.updateRanks();
	if(!child.type) this.modified |= this.modifiedSubdirs;
	else this.modified |= this.modifiedLeaves;
}

GshpHierarchyDir.prototype.updateRanks = function()
{
	var list = this.childDirs
	for(var i=0;i<list.length;i++) {
		var oid = list[i];
		var child = hierarchyEditor.getNode(oid);
		child.setRank(i);
	}
	var list = this.childLeaves;
	for(var i=0;i<list.length;i++) {
		var oid = list[i];
		var child = hierarchyEditor.getNode(oid);
		child.setRank(i);
	}
}

GshpHierarchyDir.prototype.removeChild = function(child, rank)
{
	var list = child.type ? this.childLeaves:this.childDirs;
	var newList = new Array();
	for(var i=0;i<list.length;i++) {
		var oid = list[i];
		if(oid == child.oid) {
			continue;
		}
		newList[newList.length] = oid;
	}
	if(child.type) this.childLeaves = newList;
	else this.childDirs = newList;
	this.updateRanks();
	if(this.childLeaves.length + this.childDirs.length == 0) {
		this.open = null;
		if(this.img != null) {
			this.img.src = this.emptyIcon;
		}
		if(this.ul != null) {
			this.ul.style.display = "none";
		}
	}
	if(!child.type) this.modified |= this.modifiedSubdirs;
	else this.modified |= this.modifiedLeaves;

}
GshpHierarchyDir.prototype.moveUp = function()
{
	var rank = this.rank-1;
	var node = this;
	var parentNode = hierarchyEditor.getNodeOrRoot(node.parent);
	if(node.rank == 0) {
		rank = null;
		while(parentNode.rank == 0) {
			node = parentNode;
			parentNode = hierarchyEditor.getNodeOrRoot(node.parent);
			if(parentNode == null) return;
		}
		parentNode = parentNode.previousSibling();
	}
	if(parentNode != null) {
		parentNode.insertChild(this, rank);
	}
}

GshpHierarchyDir.prototype.moveDown = function()
{
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	//console.innerHTML = this.rank + " " + (parentNode.childLeaves.length - 1);
	if(this.rank < parentNode.childDirs.length - 1) {
		parentNode.insertChild(this, this.rank+2);
	} else {
		var uncleNode = parentNode.nextSibling();
		if(uncleNode) {
			uncleNode.insertChild(this, 0);
		} else {
			var grandParentNode = hierarchyEditor.getNodeOrRoot(parentNode.parent);
			if(grandParentNode == null || grandParentNode == parentNode) return;
			grandParentNode.insertChild(this, 0);
		}
	}
}

GshpHierarchyDir.prototype.moveLeft = function()
{
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode == null) return;
	var grandParentNode = hierarchyEditor.getNodeOrRoot(parentNode.parent);
	if(grandParentNode == null || grandParentNode == parentNode) return;
	grandParentNode.insertChild(this, parentNode.rank + 1);
}

GshpHierarchyDir.prototype.moveRight = function()
{
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode == null) return;
	var nieceNode = hierarchyEditor.getNode(parentNode.childDirs[this.rank - 1]);
	if(nieceNode != null) {
		nieceNode.insertChild(this, null);
		return;
	}
	var dir = hierarchyEditor.newFolder(true);
	dir.insertChild(this, null);

}

GshpHierarchyDir.prototype.plusMinusClick = function()
{
	if(this.open == true) {
		this.open = false;
		this.img.src = this.plusIcon;
		this.ul.style.display = "none";
	} else {
		if(this.open == null) {
			this.a.onclick = gshpHierarchyPlusMinusClick;
		}
		this.open = true;
		this.img.src = this.minusIcon;
		if(this.ul == null) {
			var ul = this.ul = document.createElement("ul");
			this.li.appendChild(ul);
			this.generateChildren(hierarchyEditor, ul, {});
		} else {
			this.ul.style.display = "block";
		}
	}
}
GshpHierarchyDir.prototype.select = function()
{
	if(this.title != null) {
		this.title.className = "dirSelected "  + (this.isSpecial ? " productTitleEmph": "");
		hierarchyEditor.editTitle(this.label);
	}
	this.show();
	var url = hierarchyEditor.getDirLink();
	if(url == null) return;
	var parameterName = hierarchyEditor.getDirParameterName();
	var target = hierarchyEditor.getDirTarget();
	if(url.indexOf("?") > 0) url += "&";
	else url += "?";
	url += parameterName + "=" + this.oid;
	url = fixUrl(url);
	if(target != null) {
		window.open(url, target);
	} else {
		document.location = url;
	}
}

GshpHierarchyDir.prototype.show = function()
{
	hierarchyEditor.show(this.li);
}

GshpHierarchyDir.prototype.showRec = function()
{
	if(!this.li) {
		var parent = hierarchyEditor.getNode(this.parent);
		parent.showRec();
		if(parent.open != true) parent.plusMinusClick();
	}
	this.li.scrollIntoView();
}
GshpHierarchyDir.prototype.unselect = function()
{
	if(this.title != null) {
		this.title.className = "dir "  + (this.isSpecial ? " productTitleEmph": "");
		hierarchyEditor.editTitle(null);
	}
}

GshpHierarchyDir.prototype.dragStart = function(event)
{
	if(this.li == null) return;
	var dragElement = document.getElementById("dragElement");
	dragElement.innerHTML = this.li.outerHTML;
	hierarchyEditor.addEvent(document, "mousemove", gshpHierarchyDragIt);
	hierarchyEditor.addEvent(document, "mouseover", gshpHierarchyStopEvent);
	hierarchyEditor.addEvent(document, "mouseup", gshpHierarchyDragEnd);
}

GshpHierarchyDir.prototype.dragEnd = function()
{
	var dragElement = document.getElementById("dragElement");
	dragElement.innerHTML = "";
	var rank;
	var highlightedElement = hierarchyEditor.getHighlightedElement();
	if(highlightedElement != null) {
		rank = parseInt(highlightedElement.getAttribute("_r"));
		if(isNaN(rank)) rank = null;
		this.insertChild(hierarchyEditor.draggedNode, rank);
	} 
	hierarchyEditor.removeEvent(document, "mousemove", gshpHierarchyDragIt);
	hierarchyEditor.removeEvent(document, "mouseover", gshpHierarchyStopEvent);
	hierarchyEditor.removeEvent(document, "mouseup", gshpHierarchyDragEnd);
}

GshpHierarchyDir.prototype.dragIt = function(event, element, posX, posY)
{
	var rank = parseInt(element.getAttribute("_r"), 10);
	var type = element.getAttribute("_t");
	if(this.acceptNode(posX, posY, rank, type,element)) {
		//console.innerHTML = this.oid + " " + type + " " + rank;
	} else {
		//console.innerHTML = "";
		hierarchyEditor.highlightTargetElement(null);
	}
}

GshpHierarchyDir.prototype.acceptNode = function(x, y, rank, type, element)
{
	hierarchyEditor.highlightTargetElement(null);
	//console.innerHTML = "acceptNode dir " + hierarchyEditor.draggedNode.type + " " + this.rank + " " + rank + " " + type + " " + this.label;
	var oid = hierarchyEditor.draggedNode.oid;
	var parent = this;
	while(parent) {
		if(parent.oid == oid) return false;
		parent = hierarchyEditor.getNode(parent.parent);
	}
	switch(type) {
	case "d":
		if(hierarchyEditor.draggedNode.type == 1) return false;
		break;
	case "l":
		if(hierarchyEditor.draggedNode.type == 0) {
			hierarchyEditor.highlightTargetElement(this.ul);
			return true;
		}
		break;
	}
	hierarchyEditor.highlightTargetElement(element);
	return true;
}
GshpHierarchyDir.prototype.previousSibling = function()
{
	if(this.rank == 0) return;
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode == null) return;
	return hierarchyEditor.getNode(parentNode.childDirs[this.rank - 1]);
}
GshpHierarchyDir.prototype.nextSibling = function()
{
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode == null) return;
	return hierarchyEditor.getNode(parentNode.childDirs[this.rank + 1]);
}
GshpHierarchyDir.prototype.dumpChildren = function(list)
{
	var res = "";
	for(var i=0;i<list.length;i++) {
		if(res != "") res += " ";
		var oid = list[i];
		var node = hierarchyEditor.getNodeOrRoot(oid);
		if(node.modified & node.deleted) continue;
		res += oid;
	}
	return res;
}
GshpHierarchyDir.prototype.reportChanges = function()
{
	if(!this.modified) return;
	if((this.modified & this.created) && (this.modified & this.deleted)) return;
	if(this.modified & this.deleted) {
		return "o:" + this.oid + ",a:d";
	}
	if(this.modified & this.created) {
		return "o:" + this.oid + ",a:c,t:" + escape(this.label) + ",d:" + this.dumpChildren(this.childDirs) + ",l:" + this.dumpChildren(this.childDirs);
	}
	var code = "o:" + this.oid + ",a:m";
	if(this.modified & this.modifiedTitle) {
		code += ",t:" + escape(this.label);
	}
	if(this.modified & this.modifiedSubdirs) {
		code += ",d:" + this.dumpChildren(this.childDirs)
	}
	if(this.modified & this.modifiedLeaves) {
		code += ",l:" + this.dumpChildren(this.childLeaves)
	}
	return code;

}

//
// ------------------------------------- class GshpHierarchyLeaf
//
function GshpHierarchyLeaf(record)
{
	this.oid = parseInt(record[0], 10);
	this.type = 1;
	this.parent = parseInt(record[2], 10);
	if(isNaN(this.parent)) this.parent = null;
	this.srank = parseInt(record[3], 10);
	if(isNaN(this.srank)) this.srank = null;
	this.label = record[4];
	var mask = parseInt(record[5], 10);
	this.isSpecial = (mask & 1) == 0;
	return true;
}

GshpHierarchyLeaf.prototype.addChild = function(node)
{
	return false;
}

GshpHierarchyLeaf.prototype.changeParentOid = function(newOid)
{
	this.parent = newOid;
}

GshpHierarchyLeaf.prototype.generate = function(h, div, parentOids)
{
	var li = this.li = document.createElement("div");
	div.appendChild(li);
	li.id = "I" + this.oid; 
	var icon = document.createElement("img");
	icon.src = "iso_icons/gshp_product.gif";
	icon.align='absbottom';
	li.appendChild(icon);
	var a = this.title = document.createElement("a");
	a.className = "leaf" + (( parentOids[this.oid] == null) ? "" : "Selected") + " " + (this.isSpecial ? " productTitleEmph": "");
	a.href = "#";
	a.onclick = gshpHierarchyTitleClick;
	a.innerHTML = this.label;
	li.appendChild(a);
}
GshpHierarchyLeaf.prototype.setRank = function(rank)
{
	this.rank = rank;
	if(this.title) {
		var label = "";
		//label = rank + " ";
		this.title.innerHTML = label + this.label;
		var sep = this.li.previousSibling;
		if(sep != null) {
			sep.setAttribute("_r", "" + rank);
			//sep.innerHTML = "" + rank;
		} 
	}
}

GshpHierarchyLeaf.prototype.changeTitle = function(title)
{
}

GshpHierarchyLeaf.prototype.getTitleElement = function(h, div, parentOids)
{
	return this.title;
}

GshpHierarchyLeaf.prototype.select = function()
{
	this.title.className = "leafSelected "  + (this.isSpecial ? " productTitleEmph": "");
	hierarchyEditor.editTitle(null);
	this.show();
	var url = hierarchyEditor.getLeafLink();
	if(url == null) return;
	var parameterName = hierarchyEditor.getLeafParameterName();
	var target = hierarchyEditor.getLeafTarget();
	if(url.indexOf("?") > 0) url += "&";
	else url += "?";
	url += parameterName + "=" + this.oid;
	url = fixUrl(url);
	if(target != null) {
		window.open(url, target);
	} else {
		document.location = url;
	}

}

GshpHierarchyLeaf.prototype.show = function()
{
	hierarchyEditor.show(this.li);
}

GshpHierarchyLeaf.prototype.unselect = function()
{
	this.title.className = "leaf "  + (this.isSpecial ? " productTitleEmph": "");
	hierarchyEditor.editTitle(null);
}
GshpHierarchyLeaf.prototype.dragStart = GshpHierarchyDir.prototype.dragStart;
GshpHierarchyLeaf.prototype.dragIt = GshpHierarchyDir.prototype.dragIt;
GshpHierarchyLeaf.prototype.dragEnd = GshpHierarchyDir.prototype.dragEnd;

GshpHierarchyLeaf.prototype.acceptNode = function(x, y, rank, type)
{
	hierarchyEditor.highlightTargetElement(null);
	//console.innerHTML = "acceptNode leaf " + hierarchyEditor.draggedNode.type + " " + this.rank + " " + this.label;
	if(hierarchyEditor.draggedNode.type == 0) {
		//if(this.rank > 0) return false;
		var parentNode = hierarchyEditor.getNode(this.parent);
		if(parentNode == null) return false;
		//console.innerHTML = "higlight 0 1";
		hierarchyEditor.highlightTargetElement(parentNode.li);
		return true;
	}
	var position = hierarchyEditor.getAbsolutePos(this.li);
	var rank = this.rank;
	if(2 * y > 2 * position.y + position.h) {
		rank++;
	}
	var parentNode = hierarchyEditor.getNode(this.parent);
	if(parentNode == null) return false;
	parentNode.highlightSeparator(rank, 1);
	return true;
}

GshpHierarchyLeaf.prototype.insertChild = function(child, rank)
{
	var parentNode = hierarchyEditor.getNode(this.parent);
	if(child.type == 0) rank = null;
	parentNode.insertChild(child, rank);
}

GshpHierarchyLeaf.prototype.moveUp = function()
{
	var rank = this.rank-1;
	var node = this;
	var parentNode = hierarchyEditor.getNodeOrRoot(node.parent);
	if(node.rank == 0) {
		if(parentNode.childDirs.length > 0) {
			var nieceNode = hierarchyEditor.getNode(parentNode.childDirs[parentNode.childDirs.length - 1]);
			if(nieceNode != null) {
				nieceNode.insertChild(this, null);
			}
		}
		rank = null;
		while(parentNode.rank == 0) {
			node = parentNode;
			parentNode = hierarchyEditor.getNode(node.parent);
			if(parentNode == null) return;
		}
		parentNode = parentNode.previousSibling();
	}
	if(parentNode != null) {
		parentNode.insertChild(this, rank);
	}
}

GshpHierarchyLeaf.prototype.moveDown = function()
{
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	//console.innerHTML = this.rank + " " + (parentNode.childLeaves.length - 1);
	if(this.rank < parentNode.childLeaves.length - 1) {
		parentNode.insertChild(this, this.rank+2);
	} else {
		var uncleNode = parentNode.nextSibling();
		if(uncleNode) {
			uncleNode.insertChild(this, 0);
		} else {
			var grandParentNode = hierarchyEditor.getNodeOrRoot(parentNode.parent);
			if(grandParentNode == null) return;
			grandParentNode.insertChild(this, 0);
		}
	}
}

GshpHierarchyLeaf.prototype.moveLeft = function()
{
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode == null) return;
	var grandParentNode = hierarchyEditor.getNodeOrRoot(parentNode.parent);
	if(grandParentNode == null) return;
	grandParentNode.insertChild(this, 0);
}

GshpHierarchyLeaf.prototype.moveRight = function()
{
	var parentNode = hierarchyEditor.getNodeOrRoot(this.parent);
	if(parentNode == null) return;
	var nieceNode = hierarchyEditor.getNode(parentNode.childDirs[parentNode.childDirs.length - 1]);
	if(nieceNode != null) {
		nieceNode.insertChild(this, null);
		return;
	}
	var dir = hierarchyEditor.newFolder();
	dir.insertChild(this, null);

}

//
// ------------------------------------- class GshpHierarchyEditor
//
function GshpHierarchyEditor(isMultiple, showVisibilityStat)
{
	hierarchyEditor = this;
	this.msg = "";
	this._nodes = new Object();
	var root = this._root = new GshpHierarchyDir(new Array("-1", "0", "", "", "Root", "1"), showVisibilityStat);
	root.open = true;
	this.newOid = -2;
	this._hiddenFrameName = null;
	this._enableTitleBlur = true;
	this._enableChangeTitle = true;
	this._showVisibilityStat = showVisibilityStat;
	var dropTarget = new GshpHierarchyEditorDropTarget(isMultiple);
	window.sdsDragAndDropManager.addTarget(dropTarget, document);
}

GshpHierarchyEditor.prototype.addData = function(data)
{
	for(var i=0;i<data.length;i++) {
		var record = data[i].split("|");
		switch(record[1]) {
		case "0":
			var dir = new GshpHierarchyDir(record, this._showVisibilityStat);
			this._nodes[dir.oid] = dir;
			//this.addMsg("dir " + dir.oid + " " + dir.label);
			break;
		case "1":
			var leaf = new GshpHierarchyLeaf(record);
			//this.addMsg("leaf " + leaf.oid + " " + leaf.label);
			this._nodes[leaf.oid] = leaf;
		}
	}
}

GshpHierarchyEditor.prototype.sortData = function()
{
	var root = this._root;
	for(var oid in this._nodes) {
		var node = this._nodes[oid];
		var parent = this._nodes[node.parent];
		if(parent == null || !parent.addChild(node, this)) {
			root.addChild(node, this);
		}
	}
	this.sortChildren(root);
	for(var oid in this._nodes) {
		var node = this._nodes[oid];
		this.sortChildren(node);
	}
	this.flushMsg();
}

GshpHierarchyEditor.prototype.sortChildren = function(node)
{
	if(node.type != 0) return;
	var list = node.childDirs;
	node.childDirs = list.sort(this.compareNode);
	for(var i=0;i<list.length;i++) {
		var child = this.getNode(list[i]);
		if(child != null) child.setRank(i);
	}
	var list = node.childLeaves
	node.childLeaves = list.sort(this.compareNode);
	for(var i=0;i<list.length;i++) {
		var child = this.getNode(list[i]);
		if(child != null) child.setRank(i);
	}
	//this.addMsg("sort " + node.oid + " " + node.childDirs.length + " " + list.length);
}

GshpHierarchyEditor.prototype.compareNode = function(oid1, oid2)
{
	var n1 = hierarchyEditor.getNode(oid1);
	var n2 = hierarchyEditor.getNode(oid2);
	var r1 = n1.srank;
	var r2 = n2.srank;
	if(r1 != null) {
		if(r2 != null) {
			if(r1 < r2) return -1;
			if(r2 > r1) return 1;
			return 0;
		}
		return -1;
	} else {
		if(r2 != null) return 1;
		if(n1 < n2) return -1;
		if(n2 > n1) return 1;
		return 0;
	}
}

GshpHierarchyEditor.prototype.getNode = function(oid)
{
	return this._nodes[oid];
}

GshpHierarchyEditor.prototype.getNodeOrRoot = function(oid)
{
	var node = this._nodes[oid];
	if(node == null) node = this._root;
	return node;
}


GshpHierarchyEditor.prototype.getParentOids = function(oid)
{
	var parentOids = {};
	var node = this.selectedNode = this.getNode(oid);
	if(node == null) {
		return parentOids;
	}
	while(node) {
		parentOids[node.oid] = 1;
		node = this.getNode(node.parent);
	}
	return parentOids;
}
var console;

GshpHierarchyEditor.prototype.enableTitleBlur = function(status)
{
	this._enableTitleBlur = status;
}
GshpHierarchyEditor.prototype.enableChangeTitle = function(status)
{
	this._enableChangeTitle = status;
}
GshpHierarchyEditor.prototype.enableDrag = function(status)
{
	if(status) {
		this.addEvent(document, "dragstart", gshpHierarchyDragStart);
	} else {
		this.removeEvent(document, "dragstart", gshpHierarchyDragStart);
	}
}

GshpHierarchyEditor.prototype.init = function(leafStartOid, dirStartOid)
{
	this.sortData();
	this.rootDiv = document.getElementById("treeRoot");
	this.titleInput = document.getElementById("titleInput");
	
	if (this._enableTitleBlur)	
		this.addEvent(this.titleInput, "blur", gshpHierarchyTitleBlur);
	if (this._enableChangeTitle)
		this.addEvent(this.titleInput, "keyup", gshpHierarchyChangeTitle);

	console = document.getElementById("console");
	var startOid = leafStartOid ? leafStartOid : dirStartOid;
	var node = this.selectedNode = this.getNode(startOid);
	var parentOids = this.getParentOids(startOid);
	parentOids[this._root.oid] = 1;
	this._root.ul = this.rootDiv;
	this._root.generateChildren(this, this.rootDiv, parentOids);
	this.flushMsg();
}
GshpHierarchyEditor.prototype.addMsg = function(msg)
{
	this.msg += msg + "\n";
}

GshpHierarchyEditor.prototype.flushMsg = function()
{
	if(this.msg != "") {
		alert(this.msg);
		this.msg = "";
	}
}

GshpHierarchyEditor.prototype.stopEvent = function(ev) 
{
	ev || (ev = window.event);
	if (document.all != null) {
		ev.cancelBubble = true;
		ev.returnValue = false;
	} else {
		ev.preventDefault();
		ev.stopPropagation();
	}
	return false;
}

GshpHierarchyEditor.prototype.addEvent = function(el, evname, func)
{
	if (el.attachEvent) { // IE
		el.attachEvent("on" + evname, func);
	} else if (el.addEventListener) { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} else {
		el["on" + evname] = func;
	}
}

GshpHierarchyEditor.prototype.removeEvent = function(el, evname, func)
{
	if (el.detachEvent) { // IE
		el.detachEvent("on" + evname, func);
	} else if (el.removeEventListener) { // Gecko / W3C
		el.removeEventListener(evname, func, true);
	} else {
		el["on" + evname] = null;
	}
}
GshpHierarchyEditor.prototype.getNodeFromHTML = function(element)
{
	while(element != null && element.nodeType == 1) {
		var id = element.id;
		var node = this.getNode(id.substr(1));
		if(node != null) return node;
		element = element.parentNode;
	}
	return this._root;
}

GshpHierarchyEditor.prototype.plusMinusClick = function(event, element)
{
	var node = this.getNodeFromHTML(element);
	if(node == null) return;
	if(node.open != null) node.plusMinusClick();
	this.stopEvent(event);
}

GshpHierarchyEditor.prototype.titleClick = function(event, element)
{
	var node = this.getNodeFromHTML(element);
	if(node == null) return;
	if(this.selectedNode != null) {
		this.selectedNode.unselect();
	}
	this.selectedNode = node;
	node.select();
	this.stopEvent(event);
}

GshpHierarchyEditor.prototype.moveLeft = function()
{
	if(this.selectedNode != null) {
		this.selectedNode.moveLeft();
		this.selectedNode.show();
		this.commitAndNavigate();
	}
	return false;
}

GshpHierarchyEditor.prototype.moveRight = function()
{
	if(this.selectedNode != null) {
		this.selectedNode.moveRight();
		this.selectedNode.show();
		this.commitAndNavigate();
	}
	return false;
}

GshpHierarchyEditor.prototype.moveUp = function()
{
	if(this.selectedNode != null) {
		this.selectedNode.moveUp();
		this.selectedNode.show();
		this.commitAndNavigate();
	}
	return false;
}

GshpHierarchyEditor.prototype.moveDown = function()
{
	if(this.selectedNode != null) {
		this.selectedNode.moveDown();
		this.selectedNode.show();
		this.commitAndNavigate();
	}
	return false;
}

GshpHierarchyEditor.prototype.newFolder = function(forceParent)
{
	var node = this.selectedNode;
	if(node != null) {
		if(node.type || forceParent == true) {
			node = this.getNodeOrRoot(node.parent);
		}
		var title = "titre";
		var oid = this.newOid--;
		var rank = node.childDirs.length;
		var record = new Array(oid, 0, node.oid, rank, title, 3);
		var dir = new GshpHierarchyDir(record, this._showVisibilityStat);
		dir.modified |= dir.created;
		this._nodes[oid] = dir;
		node.addNewDir(dir);
		if(this.selectedNode != null) {
			this.selectedNode.unselect();
		}
		this.selectedNode = dir;
		dir.select();
		this.showTitle(dir);
		//this.commitAndNavigate();
		return dir;
	}
	
}
GshpHierarchyEditor.prototype.showTitle = function(dir)
{
	var title = dir.title;
	var titleInput = this.titleInput;
	titleInput.style.display = "inline";
	var titlePos = this.getAbsolutePos(title);
	titleInput.style.left = (2 + titlePos.x) + "px";
	titleInput.style.top = (titlePos.y - 2) + "px";
	titleInput.focus();
	if(document.all) {
		var range = this.titleInput.createTextRange();
		range.select();
	}
}

GshpHierarchyEditor.prototype.titleBlur = function(event, element)
{
	var titleInput = this.titleInput;
	titleInput.style.display = "none";
	this.commitAndNavigate();
}

GshpHierarchyEditor.prototype.deleteFolder = function()
{
	var node = this.selectedNode;
	var parentNode = this.getNodeOrRoot(node.parent);
	if(parentNode == null || node == null || node.type != 0 || node == this._root) return;
	if(!node.isOnlineCreated) {
		alert(objThesaurus.translate("gshpNoHierarchyDeletion")); 
		return;
	}
	if(!confirm(objThesaurus.translate("gshpQstHierarchyDeletion"))) return;
	var selectionNode = parentNode;
	if(node.rank > 0) {
		selectionNode = this.getNode(parentNode.childDirs[node.rank-1]);
	}
	node.unselect();
	node.deleteDir();
	selectionNode.select();
	this.selectedNode = selectionNode;
	this.commitAndNavigate();
	return false;
}
GshpHierarchyEditor.prototype.removeNode = function(node)
{
	this._nodes[node.oid] = null;
}

GshpHierarchyEditor.prototype.changeTitle = function(evt, element)
{
	var value = this.titleInput.value;
	if(this.selectedNode != null) {
		this.selectedNode.changeTitle(value);
	}
	if(evt.keyCode == 13) {
		this.titleInput.blur();
	}
}

GshpHierarchyEditor.prototype.editTitle = function(value)
{
	if(this.titleInput == null) return;
	if(value == null) {
		this.titleInput.disabled = true;
		this.titleInput.value = "";
		this.titleInput.style.backgroundColor = "#E0E0E0";
	} else {
		this.titleInput.disabled = false;
		this.titleInput.value = value;
		this.titleInput.style.backgroundColor = "#FFFFFF";
	}
}

GshpHierarchyEditor.prototype.show = function(element)
{
	if(element == null) return;
	if(this.dragging) return;
	var pos1 = this.getAbsolutePos(this.rootDiv);
	var pos2 = this.getAbsolutePos(element);
	if(pos1.y > pos2.y) {
		this.rootDiv.scrollTop = this.rootDiv.scrollTop  + pos2.y - pos1.y; 
	} else if(pos2.y + pos2.h > pos1.y + pos1.h) {
		var delta = pos2.y + pos2.h  - pos1.y - pos1.h + 5;
		if(delta > pos2.y - pos1.y) delta = pos2.y - pos1.y;
		this.rootDiv.scrollTop = this.rootDiv.scrollTop + delta;
	}
}

GshpHierarchyEditor.prototype.dragStart = function(event, element)
{
	//if(element.tagName == "IMG") return;
	var node = this.getNodeFromHTML(element);
	if(element == node.img) return;
	if(node.oid == -1) return;
	if(this.dragging) return;
	this.dragging = true;
	this.draggedNode = node;
	if(node == null) return;
	//if(node != this._root) 
		this.titleClick(event, element);
	node.dragStart(event);
	this.dragIt(event, element);
	//this.stopEvent(event);
}



GshpHierarchyEditor.prototype.dragIt = function(event, element)
{
	var node = this.getNodeFromHTML(element);
	if(node == null) return;
	var posX;
	var posY;
	if (document.all != null) {
		posY = window.event.clientY + document.body.scrollTop;
		posX = window.event.clientX + document.body.scrollLeft;
	} else {
		posX = event.pageX;
		posY = event.pageY;
	}
	var position = this.getAbsolutePos(this.rootDiv);
	if(position.y + this.rootDiv.scrollTop > posY) {
		if(this.rootDiv.scrollTop > 0) {
			this.rootDiv.scrollTop--;
		}
	} else if(position.y + position.h < posY) {
		if(this.rootDiv.scrollTop < this.rootDiv.scrollHeight - position.h + 4) {
			this.rootDiv.scrollTop++;
		}
	}
	var dragElement = document.getElementById("dragElement");
	dragElement.style.left = posX + 10;
	dragElement.style.top = posY + 10;
	node.dragIt(event, element, posX, posY);
	this.stopEvent(event);
}

GshpHierarchyEditor.prototype.dragEnd = function(event, element)
{
	this.dragging = false;
	var node = this.getNodeFromHTML(element);
	if(node == null) return;
	node.dragEnd();
	this.stopEvent(event);
	this.highlightTargetElement(null);
	this.draggedNode.show();
	this.draggedNode = null;
	this.commitAndNavigate();
}


GshpHierarchyEditor.prototype.getHighlightedElement = function()
{
	return this.highlightedElement;
}
GshpHierarchyEditor.prototype.highlightTargetElement = function(element)
{
	if(this.highlightedElement != null) {
		this.highlightedElement.className = this.highlightedElement.className.replace(" highlighted", "");
		this.highlightedElement = null;
	}
	if(element == null) return;
	var type = element.getAttribute("_t");
	if(type == null) {
		var node = this.getNodeFromHTML(element);
		if(node != null) {
			element = node.getTitleElement();
		}
	} 
	if(element == null) return;
	this.highlightedElement = element;
	var className = element.className;
	if(className == null) className = "";
	element.className = className + " highlighted";
} 
GshpHierarchyEditor.prototype.getAllChanges = function()
{
	var res = "";
	var dirs = new Array();
	for(var oid in this._nodes) {
		var node = this._nodes[oid];
		if(node == null) continue;
		if(node.type != 0) continue;
		dirs[dirs.length] = parseInt(oid, 10);
	}
	dirs = dirs.sort();
	for(var i=0;i<dirs.length;i++) {
		var oid = "" + dirs[i];
		var node = this._nodes[oid];
		if(node.type != 0) continue;
		var str = node.reportChanges();
		if(str == null) continue;
		if(res != "") res += "\n";
		res += str;
	}
	var str = this._root.reportChanges();
	if(str != null) {
		if(res != "") res += "\n";
		res += str;
	}
	return res;
}

GshpHierarchyEditor.prototype.commit = function(id)
{
	var input = window.frames.top.document.getElementById(id);
	var changes = this.getAllChanges();
	input.value = changes;
}

GshpHierarchyEditor.prototype.commitAndNavigate = function()
{
	if(this._hiddenFrameName == null) return;
	var id = "modifications"
	var input = window.frames.top.document.getElementById(id);
	this.commit(id);
	var form = input.form;
	form.target = this._hiddenFrameName;
	form.submit();
}

GshpHierarchyEditor.prototype.getAbsolutePos = function(element)
{
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(element.tagName);
	if (is_div && element.scrollLeft)
		SL = element.scrollLeft;
	if (is_div && element.scrollTop)
		ST = element.scrollTop;
	var r = { x: element.offsetLeft - SL, y: element.offsetTop - ST, w: element.offsetWidth, h:element.offsetHeight};
	if (element.offsetParent) {
		var tmp = this.getAbsolutePos(element.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

GshpHierarchyEditor.prototype.setDirLink = function(dirLink, parameterName, target)
{
	this._dirLink = dirLink;
	this._dirParameterName = parameterName;
	this._dirTarget = target;
}
GshpHierarchyEditor.prototype.getDirLink = function()
{
	return this._dirLink;
}

GshpHierarchyEditor.prototype.getDirParameterName = function()
{
	return this._dirParameterName;
}

GshpHierarchyEditor.prototype.getDirTarget = function()
{
	return this._dirTarget;
}

GshpHierarchyEditor.prototype.setLeafLink = function(leafLink, parameterName, target)
{
	this._leafLink = leafLink;
	this._leafParameterName = parameterName;
	this._leafTarget = target;
}

GshpHierarchyEditor.prototype.getLeafLink = function()
{
	return this._leafLink;
}

GshpHierarchyEditor.prototype.getLeafParameterName = function()
{
	return this._leafParameterName;
}

GshpHierarchyEditor.prototype.getLeafTarget = function()
{
	return this._leafTarget;
}

GshpHierarchyEditor.prototype.setHiddenFrameName = function(hiddenFrameName)
{
	this._hiddenFrameName = hiddenFrameName;
}
GshpHierarchyEditor.prototype.remapNewOids = function(map)
{
	for(var oid in map) {
		var newOid = map[oid];
		var dir = this._nodes[oid];
		dir.changeOid(newOid);
	}
}

GshpHierarchyEditor.prototype.reloadPage = function()
{
	var href = location.href;
	var pos = href.indexOf("#");
	if(pos > 0) href = href.substr(0, pos);
	var pos = href.indexOf("?");
	if(pos > 0) href = href.substr(0, pos);
	href += "?showVisibilityStat=" + this._showVisibilityStat; 
	if(this.selectedNode != null) {
		href += "&"; 
		if(this.selectedNode.type) href += "product=" + this.selectedNode.oid;
		else href += "category=" + this.selectedNode.oid;
	}
	document.location.assign(href);
	return false;
}

GshpHierarchyEditor.prototype.dirOidHasChanged = function(oldOid, dir)
{
	this._nodes[oldOid] = null;
	this._nodes[dir.oid] = dir;
}

GshpHierarchyEditor.prototype.showDir = function(oid)
{
	var dir = this._nodes[oid];
	if(dir == null) return;
	dir.showRec();
	this.highlightTargetElement(dir.li);
}

GshpHierarchyEditor.prototype.selectDir = function(oid)
{
	var dir = this._nodes[oid];
	if(dir == null) return;
	dir.showRec();
	this.highlightTargetElement(dir.li);
	if(this.selectedNode != null) {
		this.selectedNode.unselect();
	}
	this.selectedNode = dir;
	dir.select();
}

GshpHierarchyEditor.prototype.editDirectory = function(url)
{
	var dir = this.selectedNode;
	if(dir == null) return false;
	if(dir.type != 0) return false;
	dir.edit(url);
	return false;
}


GshpHierarchyEditor.prototype.showDetailDirectory = function(url)
{
	var dir = this.selectedNode;
	if(dir == null) return false;
	if(dir.type != 0) return false;
	dir.showDetail(url);
	return false;
}
function GshpHierarchyEditorDropTarget(isMultiple)
{
	SdsAbstractDragAndDropTarget.call(this, null);
	this._isMultiple = isMultiple;
}

GshpHierarchyEditorDropTarget.prototype = new SdsAbstractDragAndDropTarget();

GshpHierarchyEditorDropTarget.prototype.acceptsType = function(type)
{
	return type == "collection:gshp:product";
}


GshpHierarchyEditorDropTarget.prototype.receives = function(dragObject, element)
{
	if(element.ownerDocument != window.frames.top.frames.structureFrame.document) return;
	var dir = hierarchyEditor.getNodeFromHTML(element);
	var type = element.getAttribute("_t");
	if(dir != null && dir.type == 0 && dir.oid > 0) {
		var form = window.frames.top.document.forms.productHierarchyManagerContentForm;
		var category = dir.oid;
		var input = form.modifications;
		var cmd;
		if(this._isMultiple) {
			cmd = "a:s,c:";
		} else {
			cmd = "a:r,c:";
		}
		cmd += category + ",l:" + dragObject.getData();
		input.value = cmd;
		form.category.value = category;
		form.submit();
	}
}

GshpHierarchyEditorDropTarget.prototype.accepts = function(dragObject, element)
{
	if(element.ownerDocument != window.frames.top.frames.structureFrame.document) return;
	var dir = hierarchyEditor.getNodeFromHTML(element);
	if(dir == null || dir.type != 0 || dir.oid <= 0) {
		hierarchyEditor.highlightTargetElement(null);
		this._targetCategory = null;
	} else {
		hierarchyEditor.highlightTargetElement(element);
		this._targetCategory = dir.oid;
	}
}