/* 	
	------------------------------------------------------------------------------
	/framework/classes/js/exttreeview.js
	
	Verbeterde xmlrequest-treeview
	
  ------------------------------------------------------------------------------
*/

// TreeView main class
// ------------------------------------------------------------------------------
function ExtTreeView(_id) {

	// standard properties
	this.id = _id;	
	
	this.containerDataSource = "";
	
	this.dataParams = null;
	this.dataBind = ExtTreeView_dataBind;
	
	this.onclick = "";
	this.ondrop = "";
	this.onmove = "";
	this.ondatabind = null;
	
	// meestal willen we niet dat de root getoond wordt?
	this.showRoot = false;
	this.rootName = "";
	this.rootDisplayName = "";
	this.rootContainerId = 0;
	
	// voor bij meerdere apps op de pagina
	this.appName = "";
	this.appType = "";
	
	this.getContainer = ExtTreeView_getContainer;
	this.getRootContainer = ExtTreeView_getRootContainer;
	
	// houdt bij welke container geselecteerd is
	this.selectedContainer = null;
	
	this.childContainers = new Array();
}




function ExtTreeView_dataBind() {

	// altijd 1 ExtTreeViewContainer aanmaken!
	this.startContainer = new ExtTreeViewContainer();
	this.startContainer.dataParams = this.dataParams;
	this.startContainer.dataSource = this.containerDataSource;
	this.startContainer.parentContainer = 0;
	this.startContainer.containerType = "TreeViewRoot";
	this.startContainer.containerId = this.rootContainerId;
	this.startContainer.name = this.rootName;
	this.startContainer.displayName = this.rootDisplayName; // als dit op "" staat, wordt de root niet getoond
	this.startContainer.treeViewId = this.id;
	this.startContainer.treeView = this; // om terug te kunnen
	this.startContainer.appName = this.appName;
	this.startContainer.appType = this.appType;
	this.startContainer.ondatabind = this.ondatabind;
	
	
	debug.write("ExtTreeView is starting databind...");
	
	this.startContainer.render();
	this.startContainer.dataBind(true); // databind & expand
	
}


function ExtTreeView_getContainer(id) {
	return this.childContainers[id];		
}

function ExtTreeView_getRootContainer() {
	return this.startContainer;
}


















function ExtTreeViewContainer() {

	
	this.dataSource = "";					// eigen datasource
	this.dataParams = "";				// extra dataparams
	this.parentContainer = null;			// locatie van de container
	this.containerType = "";				// type van de container (b.v. CategoryID, PageID, ...    ==> combinatie van id + type is uniek
	this.containerId = 0;					// id van het containerType (b.v. 23, {22333-F...}, ...   ==> combinatie van id + type is uniek
	this.name = "";							// korte naam
	this.displayName = "";					// weergavenaam
	this.treeViewId = 0;					// id van de treeview zelf (tvPages b.v.)
	this.treeView = null;					// object treeview
	this.childContainers = null;			// array met de childContainers
	this.dataBound = false;					// property om te weten of de databind() al gelopen heeft
	this.selected = false;				// 
	this.subContainerStatus = "unknown"; // unknown, yes, no
	this.id = ""
	this.ondatabind = null;
	
	// voor bij meerdere apps op de pagina
	this.appName = "";
	this.appType = "";
	
	// html-componenten
	this.divContainerId 			= ""; //  C_tvPages_PageID_28
	this.divTitleId     			= ""; //  T_tvPages_PageID_28 
	this.imgCollapsedId				= ""; // TC_tvPages_PageID_28
	this.imgExpandedId				= ""; // TE_tvPages_PageID_28
	this.imgType							= ""; // TY_tvPages_PageID_28
	this.divTitleTextId				= ""; // TT_tvPages_PageID_28
	this.imgBusyId					= ""; // TB_tvPages_PageID_28
	this.divChildContainersId     	= ""; // CC_tvPages_PageID_28
	this.divMoveId					= ""; //  M_tvPages_PageID_28
	
	this.containerElement 		= null;	
	this.divTitle     			= null;
	this.imgCollapsed			= null;
	this.imgExpanded			= null;
	this.imgType					= null; // File/Folder/...
	this.divTitleText			= null;
	this.imgBusy				= null;
	this.divChildContainers     = null; 
	this.divMove				= null;
	
	// functies
	this.render = ExtTreeViewContainer_render;
	this.dataBind = ExtTreeViewContainer_dataBind;
	this.destroy = ExtTreeViewContainer_destroy;
	
	this.addClickEvents = ExtTreeViewContainer_addClickEvents;
	this.addEvent = ExtTreeViewContainer_addEvent;
	
	this.expand = ExtTreeViewContainer_expand;
	this.isExpanded = ExtTreeViewContainer_isExpanded;
	this.collapse = ExtTreeViewContainer_collapse;
	this.toggle = ExtTreeViewContainer_toggle;
	this.showBusy = ExtTreeViewContainer_showBusy;
	this.hideBusy = ExtTreeViewContainer_hideBusy;
	
	this.select = ExtTreeViewContainer_select;
	this.unselect = ExtTreeViewContainer_unselect;
	
	this.show = ExtTreeViewContainer_show;
	this.hide = ExtTreeViewContainer_hide;
	
	this.showChildMoveElements = ExtTreeViewContainer_showChildMoveElements;
	this.showMoveElement = ExtTreeViewContainer_showMoveElement;
	
	this.hideChildMoveElements = ExtTreeViewContainer_hideChildMoveElements;
	this.hideMoveElement = ExtTreeViewContainer_hideMoveElement;
	
	
	
	
	
}

function ExtTreeViewContainer_select() {
	// unselect previous
	if (this.treeView.selectedContainer) {
		this.treeView.selectedContainer.unselect();
		
	}
	this.treeView.selectedContainer = this;		
	this.selected = true;
	this.divTitle.className = "fw_exttreeview_title_selected";	
	
}


function ExtTreeViewContainer_unselect() {
	if (this.divTitle) {
		this.divTitle.className = "fw_exttreeview_title";
		this.treeView.selectedContainer = null;
		this.selected = false;
	}
	
}


function ExtTreeViewContainer_show() {
	this.divContainer.style.display = "block";
}

function ExtTreeViewContainer_hide() {
	this.divContainer.style.display = "none";	
}

function ExtTreeViewContainer_showBusy() {
	if (this.imgBusy)
		this.imgBusy.style.display = "block";
}

function ExtTreeViewContainer_hideBusy() {
	if (this.imgBusy)
		this.imgBusy.style.display = "none";	
}


function ExtTreeViewContainer_toggle() {
	if (this.isExpanded()) {
		this.collapse();
	}
	else {
		this.expand();	
	}
	
}

function ExtTreeViewContainer_showChildMoveElements() {
	if (this.childContainers && this.childContainers.length > 0) {
		//alert("zou moeten gaan");
		for (i=0; i<this.childContainers.length; i++) {
			this.childContainers[i].showMoveElement();	
		}
	}
	else {
		//alert("er is niks");	
	}
	
}
function ExtTreeViewContainer_hideChildMoveElements() {
	if (this.childContainers && this.childContainers.length > 0) {
		for (i=0; i<this.childContainers.length; i++) {
			this.childContainers[i].hideMoveElement();	
		}
	}
}
function ExtTreeViewContainer_showMoveElement() {
	//alert("showing move element for " + this.id);
	if (this.divMove) {
		//alert("really showing move element for " + this.id);
		this.divMove.style.display = "block";
	}
	
}
function ExtTreeViewContainer_hideMoveElement() {
	if (this.divMove) {
		this.divMove.style.display = "none";	
	}
	
}



function ExtTreeViewContainer_expand() {
	debug.write("ExtTreeViewContainer_expand: " + this.divChildContainers + " - " + this.dataBound + " - " + this.childContainers);
	if (this.divChildContainers) {
		if (this.dataBound == false) {
			this.dataBind(true);	
		}
		else {
			if (this.childContainers && this.childContainers.length > 0) {
				this.divChildContainers.style.display = "block";	
				this.imgCollapsed.style.display = "none";
				this.imgExpanded.style.display = "block";
			}
			else {
				this.collapse();	
			}
		}
	}
	else {
		this.dataBind(true);	
	}
	
}

function ExtTreeViewContainer_collapse() {
	if (this.containerType != "TreeViewRoot" && this.divChildContainers) {
		this.divChildContainers.style.display = "none";	
		this.imgCollapsed.style.display = "block";
		this.imgExpanded.style.display = "none";
	}
}


function ExtTreeViewContainer_isExpanded() {
	if (this.divChildContainers.style.display == "block") {
		return true;	
	}
	else {
		return false;	
	}
}

function ExtTreeViewContainer_destroy() {
	if (this.divTitleText && this.divTitleText.parentNode)
		this.divTitleText.parentNode.removeChild(this.divTitleText);
	if (this.imgBusy && this.imgBusy.parentNode)
		this.imgBusy.parentNode.removeChild(this.imgBusy);
	if (this.imgCollapsed && this.imgCollapsed.parentNode)
		this.imgCollapsed.parentNode.removeChild(this.imgCollapsed);
	if (this.imgExpanded && this.imgExpanded.parentNode)
		this.imgExpanded.parentNode.removeChild(this.imgExpanded);
	if (this.imgType && this.imgType.parentNode)
		this.imgType.parentNode.removeChild(this.imgType);
	if (this.divTitle && this.divTitle.parentNode)
		this.divTitle.parentNode.removeChild(this.divTitle);
	if (this.divChildContainers && this.divChildContainers.parentNode)
		this.divChildContainers.parentNode.removeChild(this.divChildContainers);
	if (this.divMove && this.divMove.parentNode)
		this.divMove.parentNode.removeChild(this.divMove);
	if (this.divContainer && this.divContainer.parentNode)
		this.divContainer.parentNode.removeChild(this.divContainer);
	
	this.divTitleText = null;
	this.imgBusy = null;
	this.imgCollapsed = null;
	this.imgExpanded = null;
	this.imgType = null;
	this.divTitle = null;
	this.divChildContainers = null;
	this.divMove = null;
	this.divContainer = null;
}


function ExtTreeViewContainer_render() {
	this.id = this.containerType + "_" + this.containerId; // CategoryID_23, TreeViewRoot_0, PageID_{222B-AB-34545}
	
	this.divContainerId 			= "C_" + this.treeViewId + "_" + this.id   //  C_tvPages_CategoryID_23 -> wrapper voor titel en items
	this.divTitleId     			= "T_" + this.treeViewId + "_" + this.id   //  T_tvPages_CategoryID_23 -> titel (displayname) van de container zelf
	this.imgCollapsedId				= "TC_" + this.treeViewId + "_" + this.id  // TE_tvPages_CategoryID_23 -> als we hierop klikken -> expand()
	this.imgExpandedId				= "TE_" + this.treeViewId + "_" + this.id  // TC_tvPages_CategoryID_23 -> als we hierop klikken -> collapse()
	this.imgTypeId				    = "TY_" + this.treeViewId + "_" + this.id  // TY_tvPages_CategoryID_23 -> icoontje dat aanduidt wat het is
	this.divTitleTextId				= "TT_" + this.treeViewId + "_" + this.id  // TT_tvPages_CategoryID_23 -> bevat de tekst van de titel
	this.imgBusyId					= "TB_" + this.treeViewId + "_" + this.id  // TB_tvPages_CategoryID_23 -> wordt enkel getoond tijdens de databind()
	this.divChildContainersId     	= "CC_" + this.treeViewId + "_" + this.id  // CC_tvPages_CategoryID_23 -> wrapper voor de childContainers
	this.divMoveId			     	= "M_" + this.treeViewId + "_" + this.id   //  M_tvPages_CategoryID_23 -> drop element voor move binnen zelfde parent
		
	
	this.divContainer = document.createElement("div");
	this.divContainer.id = this.divContainerId;
	//this.divContainer.style.marginTop = "2px";
	//this.divContainer.style.marginBottom = "2px";
	this.divContainer.className = "fw_exttreeview_container";
	this.divContainer.style.backgroundColor = "transparent";
	
	
	this.divTitle = document.createElement("div");
	this.divTitle.id = this.divTitleId;
	//this.divTitle.style.display = "block";
	//this.divTitle.style.backgroundColor = "Green";
	this.divTitle.style.clear = "both";
	this.divTitle.style.width = "100%";
	this.divTitle.style.display = "block";
	if(document.all && !window.opera)
		this.divTitle.style.styleFloat = "left";
	else
		this.divTitle.style.cssFloat = "left";
	this.divTitle.className = "fw_exttreeview_title";
	
	this.imgCollapsed = document.createElement("img");
	this.imgCollapsed.id = this.imgCollapsedId;
	this.imgCollapsed.src = layoutroot + "/img/fw_icon_collapsed.gif";
	if(document.all && !window.opera)
		this.imgCollapsed.style.styleFloat = "left";
	else
		this.imgCollapsed.style.cssFloat = "left";
	this.imgCollapsed.style.clear = "left";
	this.imgCollapsed.className = "fw_exttreeview_collapsed";
	
	
	this.imgExpanded = document.createElement("img");
	this.imgExpanded.id = this.imgExpandedId;
	this.imgExpanded.src = layoutroot + "/img/fw_icon_expanded.gif";
	this.imgExpanded.style.display = "none";
	if(document.all && !window.opera)
		this.imgExpanded.style.styleFloat = "left";
	else
		this.imgExpanded.style.cssFloat = "left";
	this.imgExpanded.className = "fw_exttreeview_expanded";
	
	if (this.containerType == "Folder" || this.containerType == "File") {
		this.imgType = document.createElement("img");
		this.imgType.id = this.imgExpandedId;
		this.imgType.src = layoutroot + "/img/fw_icon_" + this.containerType.toLowerCase(this.containerType) + ".png";
		if(document.all && !window.opera)
			this.imgType.style.styleFloat = "left";
		else
			this.imgType.style.cssFloat = "left";
		this.imgType.className = "fw_exttreeview_type";
	}
	
	this.divTitleText = document.createElement("div");
	this.divTitleText.id = this.divTitleTextId;
	this.divTitleText.innerHTML = this.displayName;
	if(document.all && !window.opera)
		this.divTitleText.style.styleFloat = "left";
	else
		this.divTitleText.style.cssFloat = "left";
	this.divTitleText.className = "fw_exttreeview_titletext";		
	//this.divTitleText.style.backgroundColor = "pink";
	
	
	this.imgBusy = document.createElement("img");
	this.imgBusy.id = this.imgBusyId;
	this.imgBusy.src = layoutroot + "/img/fw_icon_busy.gif";
	if(document.all && !window.opera)
		this.imgBusy.style.styleFloat = "right";
	else
		this.imgBusy.style.cssFloat = "right";
	this.imgBusy.style.display = "none";
	this.imgBusy.className = "fw_exttreeview_busy";
	
	
	this.divChildContainers = document.createElement("div");
	this.divChildContainers.id = this.divChildContainersId;
	this.divChildContainers.style.display = "none";
	//this.divChildContainers.style.backgroundColor = "Blue";
	this.divChildContainers.style.marginLeft = "10px";
	
	
	this.divMove = document.createElement("div");
	this.divMove.id = this.divMoveId;
	//this.divMove.style.display = "none";
	//this.divMove.style.marginLeft = "10px";
	this.divMove.className = "fw_exttreeview_move";
	this.divMove.innerHTML = "&nbsp;";
	
	var divParentContainer = null;
	if (this.parentContainer) {
		debug.write("Rendering in " + this.parentContainer.id + " (" + this.parentContainer.displayName + ")");
		divParentContainer = this.parentContainer.divChildContainers;
	}
	else {
		debug.write("Rendering in root-element");	
		var divParentContainer = document.getElementById("F_" + this.treeViewId);
	}
	
	
	if (divParentContainer) {
	 	divParentContainer.appendChild(this.divContainer);
	 	this.divContainer.appendChild(this.divMove);
	 	this.divContainer.appendChild(this.divTitle);
	 	this.divTitle.appendChild(this.imgCollapsed);
	 	this.divTitle.appendChild(this.imgExpanded);
	 	if (this.imgType != null)
	 		this.divTitle.appendChild(this.imgType);
	 	this.divTitle.appendChild(this.divTitleText);
	 	this.divTitle.appendChild(this.imgBusy);
	 	this.divContainer.appendChild(this.divChildContainers);
	 	
	 	divClose = document.createElement("div");
	 	divClose.style.clear = "both";
	 	divParentContainer.appendChild(divClose);
	 	
	 	this.addClickEvents();
	 	
	 	if (this.subContainerStatus == "no") {
	 		this.imgCollapsed.style.visibility = "hidden";
	 		this.imgExpanded.style.visibility = "hidden";
	 	}
	 		
	 	// mezelf ook toevoegen aan de associative array van de treeview -> gemakkelijker en sneller voor de events
	 	this.treeView.childContainers[this.id] = this;
	 	debug.write("childContainer[" + this.id + "] op " + this.containerId + " gezet");
	 	
	 	if (this.treeView.ondrop != "") {
		
	 		new Draggable(this.divTitle, {revert: true, starteffect: ExtTreeViewContainer_startDrop, endeffect: ExtTreeViewContainer_endDrop});
	 		//new Draggable(this.divTitle, {revert: true});
	 		Droppables.add(this.divTitle, {onDrop:ExtTreeViewContainer_handleDrop, hoverclass:'fw_exttreeview_title_dragging'});
	 		Droppables.add(this.divMove, {onDrop:ExtTreeViewContainer_handleMove, hoverclass:'fw_exttreeview_move_dragging'});
	 	}
	 	
	 	if (this.displayName == "") {
	 		this.divTitle.style.display = "none";
	 		this.divChildContainers.style.marginLeft = "0px";
	
	 	}
	 	
	
	}
	else {
		debug.write("Impossible to render()");
		//alert("Impossible to render");
	}
		
	
	
}


// vult divChildContainers op met childItems (als die er zijn)
function ExtTreeViewContainer_dataBind(expandAfterDataBind) {
	
	debug.write("databind for " + this.id + ", this.datasource = " + this.dataSource + ", this.containerID = " + this.containerId);
	var onDataBind = this.ondatabind;
	
	if (this.dataSource != "") {
		
		if (this.dataParams && isArray(this.dataParams)) {
			var params = this.dataParams;
		}
		else {
			var params = new Array();
		}
		// hier moeten we eigenlijk alle gegevens van deze container meegeven
		params["ContainerType"]	= this.containerType;
		params["ParentContainerID"] = this.containerId;
		
		debug.write("Starting xml request for " + this.id, "ExtTreeViewContainer_dataBind");
		oXmlRequest = new XmlRequest();
		if (this.appName != "") {
			oXmlRequest.appName = this.appName;
			oXmlRequest.appType = this.appType;
		}
		oXmlRequest.functionName	= this.dataSource;
		oXmlRequest.params 			= params;	
		oXmlRequest.callingObject   = this;
		oXmlRequest.onsuccess 		= ExtTreeViewContainer_handleXmlResponse;
		oXmlRequest.start();
		this.showBusy();
	}
	
	
	var etvc = this;
	
	
	//var onDataBind = this.ondatabind;
	
	function ExtTreeViewContainer_handleXmlResponse(oXmlResponse) {
		debug.write("Expanding: " + expandAfterDataBind);
		
		//debug.write("Handling xml response for " + etvc.id, "ExtTreeViewContainer_handleXmlResponse");
		if (!etvc)
			return;
			
		debug.write(oXmlResponse.responseText);
		
		if (oXmlResponse.statusCode != "2000") {
			alert(oXmlResponse.responseText);	
		}
		else {
			if (etvc.childContainers) {
				for(i=etvc.childContainers.length-1; i >= 0; i--) {
					//alert("this is " + etvc.id + " destroying my " + i + "st childContainer");
					var childContainer = etvc.childContainers[i];
					//alert("this is " + etvc.id + " destroying childContainer " + i + " (" + childContainer.displayName + ") ");
					childContainer.destroy();
				}
				
				etvc.childContainers.clear();
			}
			else {
				debug.write("creating new childContainers");
				etvc.childContainers = new Array();	
			}
			
			if (oXmlResponse.data.length != 0) {
				
				for(i=0; i<oXmlResponse.data.length; i++) {
					var row = oXmlResponse.data[i];
					// voor elke row die we terugkrijgen maken we een childcontainer, die we alleen maar renderen (niet databinden)
					debug.write("row " + i + ": " + row["ContainerType"] + "-" + row["ContainerID"] + "-" + row["Name"] + "-" + row["DisplayName"]);
					etvc.childContainers[i] = new ExtTreeViewContainer();
					etvc.childContainers[i].dataSource = etvc.dataSource;
					etvc.childContainers[i].parentContainer = etvc;
					etvc.childContainers[i].appName = etvc.appName;
					etvc.childContainers[i].appType = etvc.appType;
					etvc.childContainers[i].containerType = row["ContainerType"];
					etvc.childContainers[i].containerId = row["ContainerID"];
					etvc.childContainers[i].subContainerStatus = row["SubContainerStatus"];
					etvc.childContainers[i].name = row["Name"];
					etvc.childContainers[i].displayName = row["DisplayName"];
					etvc.childContainers[i].treeViewId = etvc.treeViewId;
					etvc.childContainers[i].treeView = etvc.treeView;
					
					etvc.childContainers[i].render();
					
				}
				
			
				etvc.dataBound = true;
			
				if (expandAfterDataBind == true) {
					etvc.expand();	
				}
			}
			else {
				etvc.dataBound = true;
			
				etvc.collapse();	
			}
			
			
			if (onDataBind) {
				debug.write("Executing databind function: " + onDataBind);
				onDataBind(oXmlResponse);
			}
			
				
			etvc.hideBusy();
			
			
			
//			
//			/*if (onDataBind) {
//				debug.write("Executing databind function: " + onDataBind);
//				onDataBind();
//			}
//			*/
		}
		
		
	}
	
	
	
	
}




function ExtTreeViewContainer_addClickEvents() {
	this.addEvent(this.divTitle, ExtTreeViewContainer_handleEvent, "click");
}



function ExtTreeViewContainer_addEvent(element, handler, eventType) {
	//alert("adding event to " + this.divTitle);
	element.onclick = handler;
	return;
	
	//W3C
	if(element.addEventListener) {
		//alert('W3C event added');
		element.addEventListener(eventType, handler, false);
	}

	//Microsoft
	else if(element.attachEvent){
		//alert("MS event added");
		element.attachEvent(eventType, handler);
	}
}

function ExtTreeViewContainer_getContainerById(id) {
	var ar = id.split("_");
	if (ar.length >=4) {
		var frameworkElementId = ar[1]; // de treeview zelf dus
		var frameworkElement = eval(frameworkElementId);
		//alert('Het event (type = ' + ev.type + ') is opgetreden op ' +frameworkElement.id);

		if (frameworkElement) {
			//alert("1");
			extTreeViewContainerId = ar[2] + "_" + ar[3];
			// als de containerId underscores bevatte:
			if (ar.length > 4) {
				for(i=4; i<ar.length; i++) {
					extTreeViewContainerId += "_" + ar[i];
				}
			}
			
			//alert("We gaan nu het element zoeken: " + extTreeViewContainerId);
			return frameworkElement.getContainer(extTreeViewContainerId);
		}
		else {
			//alert("2");
			return null;	
		}
	}
		
}
function ExtTreeViewContainer_startDrop(draggableElement) {
	new Effect.Opacity(draggableElement.id, {duration:0.5, from:1.0, to:0.7});
	var etvc = ExtTreeViewContainer_getContainerById(draggableElement.id);
	//alert("drop started: " + etvc.id);
	etvc.collapse();
	
	// nu moeten we de move-div's van de parent van deze etvc ook activeren
	if (etvc.parentContainer) {
		etvc.parentContainer.showChildMoveElements();	
	}
	// maar mezelf heeft dat geen zin
	etvc.hideMoveElement();
	
}

function ExtTreeViewContainer_endDrop(draggableElement) {
	new Effect.Opacity(draggableElement.id, {duration:0.5, from:0.7, to:1.0});
	
	var etvc = ExtTreeViewContainer_getContainerById(draggableElement.id);
	
	if (etvc.parentContainer) {
		etvc.parentContainer.hideChildMoveElements();	
	}
	
}

function ExtTreeViewContainer_handleDrop(draggableElement, droppableElement) {
	var etvcDragged = ExtTreeViewContainer_getContainerById(draggableElement.id);
	var etvcDroppedOn = ExtTreeViewContainer_getContainerById(droppableElement.id);
		
	if (etvcDragged && etvcDroppedOn) {
		if (etvcDragged.treeView.ondrop != "") {
			eval(etvcDragged.treeView.ondrop + "(etvcDragged, etvcDroppedOn)");
			etvcDragged.hide();
		}
	}
	
	else {
		alert("Couldn't get id's of dragged or dropped elements!");
	}
}


function ExtTreeViewContainer_handleMove(draggableElement, droppableElement) {
	var etvcDragged = ExtTreeViewContainer_getContainerById(draggableElement.id);
	var etvcMovedOn = ExtTreeViewContainer_getContainerById(droppableElement.id);
		
	if (etvcDragged && etvcMovedOn) {
		if (etvcDragged.treeView.onmove != "") {
			eval(etvcDragged.treeView.onmove + "(etvcDragged, etvcMovedOn)");
			etvcDragged.hide();
		}
	}
	
	else {
		alert("Couldn't get id's of dragged or dropped elements!");
	}
}

function ExtTreeViewContainer_handleEvent(ev) {
	//alert("event");
	
	var targetElement;
	
	// event bij MS
	if (!ev) var ev = window.event;
	
	// target element W3C
	if (ev.target) targetElement = ev.target;
	// target element MS
	else if (ev.srcElement) targetElement = ev.srcElement;
	
	//alert(targetElement.id);
	var etvc = ExtTreeViewContainer_getContainerById(targetElement.id);
		
	if (etvc) {
		if (ev.type == "click") {
			etvc.toggle();
			etvc.select();
			if (etvc.treeView.onclick != "") {
				//eval(etvc.treeView.onclick + "('" + etvc.containerType + "', '" + etvc.containerId + "')");
				eval(etvc.treeView.onclick + "(etvc)");
			}
			
			
		}
	}
	else {
		alert("Couldn't get to the element for the event: " + targetElement.id);
	}
	
}

