

/************************************************************************************************************
Drag and drop folder tree
Copyright (C) 2006  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com


************************************************************************************************************/	

 






		
	var JSTreeObj;
	var treeUlCounter = 0;
	var nodeId = 1;
	//if(!inputObj && this)inputObj = this;
	/* Constructor */
	function JSDragDropTree()
	{
		//var helpers = array('Session', 'Html', 'Form', 'Number', 'Text', 'Resize'/*, 'GoogleMap'*/);
		var idOfTree;
		var imageFolder;
		var folderImage;
		var plusImage;
		var minusImage;
		var maximumDepth;
		var dragNode_source;
		var dragNode_parent;
		var dragNode_sourceNextSib;
		var dragNode_noSiblings;
		var ajaxObjects;
		
		var dragNode_destination;
		var floatingContainer;
		var dragDropTimer;
		var dropTargetIndicator;
		var insertAsSub;
		var indicator_offsetX;
		var indicator_offsetX_sub;
		var indicator_offsetY;
		
		this.imageFolder = 'images/';
		this.folderImage = 'dhtmlgoodies_folder.gif';
		this.plusImage = 'dhtmlgoodies_plus.gif';
		this.minusImage = 'dhtmlgoodies_minus.gif';
		this.maximumDepth = 6;
		
		this.nodeATagIdPrefix = 'nodeATag';
		var messageMaximumDepthReached;
		var filePathRenameItem;
		var filePathDeleteItem;
		var filePathAddItem;
		var filePathMoveItemsToParentItem;
		var filePathBaseBrowseURL;
		var addSubCategoryMenuTitle;
		var Product;
		var deleteBranchMenuTitle;
		var renameBranchMenuTitle;
		var moveItemsToParentMenuTitle;
		var newCategoryPromptMessage;
		var moveItemsToParentPromptMessagePart1;
		var moveItemsToParentPromptMessagePart2;
		var moveItemsToParentPromptMessagePart3;
		var filePathSaveLayoutItem;
		var additionalRenameRequestParameters = {};
		var additionalDeleteRequestParameters = {};
		var additionalAddRequestParameters = {};

		var addAllowed;
		var renameAllowed;
		var productAllowed;//bassam
		var currentlyActiveItem;
		var contextMenu;
		var currentItemToEdit;		// Reference to item currently being edited(example: renamed)
		var helpObj;
		
		this.contextMenu = false;
		this.floatingContainer = document.createElement('UL');
		this.floatingContainer.style.position = 'absolute';
		this.floatingContainer.style.display='none';
		this.floatingContainer.id = 'floatingContainer';
		this.insertAsSub = false;
		document.body.appendChild(this.floatingContainer);
		this.dragDropTimer = -1;
		this.dragNode_noSiblings = false;
		this.currentItemToEdit = false;
		
		if(document.all){
			this.indicator_offsetX = 2;	// Offset position of small black lines indicating where nodes would be dropped.
			this.indicator_offsetX_sub = 4;
			this.indicator_offsetY = 2;
		}else{
			this.indicator_offsetX = 1;	// Offset position of small black lines indicating where nodes would be dropped.
			this.indicator_offsetX_sub = 3;
			this.indicator_offsetY = 2;			
		}
		if(navigator.userAgent.indexOf('Opera')>=0){
			this.indicator_offsetX = 2;	// Offset position of small black lines indicating where nodes would be dropped.
			this.indicator_offsetX_sub = 3;
			this.indicator_offsetY = -7;				
		}

		this.messageMaximumDepthReached = ''; // Use '' if you don't want to display a message 
		
		this.addAllowed = true;
		this.renameAllowed = true;
		this.productAllowed = true;//bassam
		this.deleteAllowed = true;
		this.currentlyActiveItem = false;
		this.filePathRenameItem = 'folderTree_updateItem.php';
		this.filePathDeleteItem = 'folderTree_updateItem.php';
		this.ajaxObjects = new Array();
		this.helpObj = false;
		
		this.RENAME_STATE_BEGIN = 1;
		this.RENAME_STATE_CANCELED = 2;
		this.RENAME_STATE_REQUEST_SENDED = 3;
		this.renameState = null;
	}
	
	
	/* JSDragDropTree class */
	JSDragDropTree.prototype = {
		// {{{ addEvent()
	    /**
	     *
	     *  This function adds an event listener to an element on the page.
	     *
	     *	@param Object whichObject = Reference to HTML element(Which object to assigne the event)
	     *	@param String eventType = Which type of event, example "mousemove" or "mouseup"
	     *	@param functionName = Name of function to execute. 
	     * 
	     * @public
	     */
		 
		 	
		addEvent : function(whichObject,eventType,functionName)
		{ 
		  if(whichObject.attachEvent){ 
		    whichObject['e'+eventType+functionName] = functionName; 
		    whichObject[eventType+functionName] = function(){whichObject['e'+eventType+functionName]( window.event );} 
		    whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName] ); 
		  } else 
		    whichObject.addEventListener(eventType,functionName,false); 	    
		} 
		// }}}	
		,	
		// {{{ removeEvent()
	    /**
	     *
	     *  This function removes an event listener from an element on the page.
	     *
	     *	@param Object whichObject = Reference to HTML element(Which object to assigne the event)
	     *	@param String eventType = Which type of event, example "mousemove" or "mouseup"
	     *	@param functionName = Name of function to execute. 
	     * 
	     * @public
	     */
		 		
		removeEvent : function(whichObject,eventType,functionName)
		{ 
		  if(whichObject.detachEvent){ 
		    whichObject.detachEvent('on'+eventType, whichObject[eventType+functionName]); 
		    whichObject[eventType+functionName] = null; 
		  } else 
		    whichObject.removeEventListener(eventType,functionName,false); 
		} 
		,	
		
		Get_Cookie : function(name) { 
		   var start = document.cookie.indexOf(name+"="); 
		   var len = start+name.length+1; 
		   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
		   if (start == -1) return null; 
		   var end = document.cookie.indexOf(";",len); 
		   if (end == -1) end = document.cookie.length; 
		   return unescape(document.cookie.substring(len,end)); 
		} 
		,
		// This function has been slightly modified
		Set_Cookie : function(name,value,expires,path,domain,secure) { 
			expires = expires * 60*60*24*1000;
			var today = new Date();
			var expires_date = new Date( today.getTime() + (expires) );
		    var cookieString = name + "=" +escape(value) + 
		       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
		       ( (path) ? ";path=" + path : "") + 
		       ( (domain) ? ";domain=" + domain : "") + 
		       ( (secure) ? ";secure" : ""); 
		    document.cookie = cookieString; 
		},
		
		
		expandAll : function()
		{
			var menuItems = document.getElementById(this.idOfTree).getElementsByTagName('LI');
			for(var no=0;no<menuItems.length;no++){
				var subItems = menuItems[no].getElementsByTagName('UL');
				if(subItems.length>0 && subItems[0].style.display!='block'){
					JSTreeObj.showHideNode(false,menuItems[no].id);
				}			
			}
		}	
		,
		collapseAll : function()
		{
			var menuItems = document.getElementById(this.idOfTree).getElementsByTagName('LI');
			for(var no=0;no<menuItems.length;no++){
				var subItems = menuItems[no].getElementsByTagName('UL');
				if(subItems.length>0 && subItems[0].style.display=='block'){
					JSTreeObj.showHideNode(false,menuItems[no].id);
				}			
			}		
		}	
		,
		/*
		Find top pos of a tree node
		*/
		getTopPos : function(obj){
			var top = obj.offsetTop/1;
			while((obj = obj.offsetParent) != null){
				if(obj.tagName!='HTML')top += obj.offsetTop;
			}			
			if(document.all)top = top/1 + 13; else top = top/1 + 4;		
			return top;
		}
		,	
		/*
		Find left pos of a tree node
		*/
		getLeftPos : function(obj){
			var left = obj.offsetLeft/1 + 1;
			while((obj = obj.offsetParent) != null){
				if(obj.tagName!='HTML')left += obj.offsetLeft;
			}
	  			
			if(document.all)left = left/1 - 2;
			return left;
		}	
			
		,
		showHideNode : function(e,inputId)
		{
			if(inputId){
				if(!document.getElementById(inputId))return;
				thisNode = document.getElementById(inputId).getElementsByTagName('IMG')[0]; 
			}else {
				thisNode = this;
				if(this.tagName=='A')thisNode = this.parentNode.getElementsByTagName('IMG')[0];	
			}
			if(thisNode.style.visibility=='hidden')return;		
			var parentNode = thisNode.parentNode;
			inputId = parentNode.id.replace(/[^0-9]/g,'');
			if(thisNode.src.indexOf(JSTreeObj.plusImage)>=0){
				thisNode.src = thisNode.src.replace(JSTreeObj.plusImage,JSTreeObj.minusImage);
				var ul = parentNode.getElementsByTagName('UL')[0];
				ul.style.display='block';
				if(!initExpandedNodes)initExpandedNodes = ',';
				if(initExpandedNodes.indexOf(',' + inputId + ',')<0) initExpandedNodes = initExpandedNodes + inputId + ',';
			}else{
				thisNode.src = thisNode.src.replace(JSTreeObj.minusImage,JSTreeObj.plusImage);
				parentNode.getElementsByTagName('UL')[0].style.display='none';
				initExpandedNodes = initExpandedNodes.replace(',' + inputId,'');
			}	
			JSTreeObj.Set_Cookie('dhtmlgoodies_expandedNodes',initExpandedNodes,500);			
			return false;						
		}
		,
		/* Initialize drag */
		initDrag : function(e)
		{
			if(document.all)e = event;	
			
			var subs = JSTreeObj.floatingContainer.getElementsByTagName('LI');
			if(subs.length>0){
				if(JSTreeObj.dragNode_sourceNextSib){
					JSTreeObj.dragNode_parent.insertBefore(JSTreeObj.dragNode_source,JSTreeObj.dragNode_sourceNextSib);
				}else{
					JSTreeObj.dragNode_parent.appendChild(JSTreeObj.dragNode_source);
				}					
			}
			
			JSTreeObj.dragNode_source = this.parentNode;
			JSTreeObj.dragNode_parent = this.parentNode.parentNode;
			JSTreeObj.dragNode_sourceNextSib = false;

			
			if(JSTreeObj.dragNode_source.nextSibling)JSTreeObj.dragNode_sourceNextSib = JSTreeObj.dragNode_source.nextSibling;
			JSTreeObj.dragNode_destination = false;
			JSTreeObj.dragDropTimer = 0;
			JSTreeObj.timerDrag();
			return false;
		}
		,
		timerDrag : function()
		{	
			if(this.dragDropTimer>=0 && this.dragDropTimer<10){
				this.dragDropTimer = this.dragDropTimer + 1;
				setTimeout('JSTreeObj.timerDrag()',20);
				return;
			}
			if(this.dragDropTimer==10)
			{
				JSTreeObj.floatingContainer.style.display='block';
				JSTreeObj.floatingContainer.appendChild(JSTreeObj.dragNode_source);	
			}
		}
		,
		moveDragableNodes : function(e)
		{
			if(JSTreeObj.dragDropTimer<10)return;
			if(document.all)e = event;
			dragDrop_x = e.clientX/1 + 5 + document.body.scrollLeft;
			dragDrop_y = e.clientY/1 + 5 + document.documentElement.scrollTop;	
					
			JSTreeObj.floatingContainer.style.left = dragDrop_x + 'px';
			JSTreeObj.floatingContainer.style.top = dragDrop_y + 'px';
			
			var thisObj = this;
			if(thisObj.tagName=='A' || thisObj.tagName=='IMG')thisObj = thisObj.parentNode;

			JSTreeObj.dragNode_noSiblings = false;
			var tmpVar = thisObj.getAttribute('noSiblings');
			if(!tmpVar)tmpVar = thisObj.noSiblings;
			if(tmpVar=='true')JSTreeObj.dragNode_noSiblings=true;
					
			if(thisObj && thisObj.id)
			{
				JSTreeObj.dragNode_destination = thisObj;
				var img = thisObj.getElementsByTagName('IMG')[1];
				var tmpObj= JSTreeObj.dropTargetIndicator;
				tmpObj.style.display='block';
				
				var eventSourceObj = this;
				if(JSTreeObj.dragNode_noSiblings && eventSourceObj.tagName=='IMG')eventSourceObj = eventSourceObj.nextSibling;
				
				var tmpImg = tmpObj.getElementsByTagName('IMG')[0];
				if(this.tagName=='A' || JSTreeObj.dragNode_noSiblings){
					tmpImg.src = tmpImg.src.replace('ind1','ind2');	
					JSTreeObj.insertAsSub = true;
					tmpObj.style.left = (JSTreeObj.getLeftPos(eventSourceObj) + JSTreeObj.indicator_offsetX_sub) + 'px';
				}else{
					tmpImg.src = tmpImg.src.replace('ind2','ind1');
					JSTreeObj.insertAsSub = false;
					tmpObj.style.left = (JSTreeObj.getLeftPos(eventSourceObj) + JSTreeObj.indicator_offsetX) + 'px';
				}
				
				
				tmpObj.style.top = (JSTreeObj.getTopPos(thisObj) + JSTreeObj.indicator_offsetY) + 'px';
			}
			
			return false;
			
			
		}
		,
		dropDragableNodes:function()
		{
			if(JSTreeObj.dragDropTimer<10){				
				JSTreeObj.dragDropTimer = -1;
				return;
			}
			
			var showMessage = false;
			if(JSTreeObj.dragNode_destination){	// Check depth
				var countUp = JSTreeObj.dragDropCountLevels(JSTreeObj.dragNode_destination,'up');
				var countDown = JSTreeObj.dragDropCountLevels(JSTreeObj.dragNode_source,'down');
				var countLevels = countUp/1 + countDown/1 + (JSTreeObj.insertAsSub?1:0);		
				
				if(countLevels>JSTreeObj.maximumDepth){
					JSTreeObj.dragNode_destination = false;
					showMessage = true; 	// Used later down in this function
				}
			}
			
			
			if(JSTreeObj.dragNode_destination)
			{
				var child_id=JSTreeObj.dragNode_source.getElementsByTagName('A')[0].id.replace(/[^0-9]/g,'');
				if(JSTreeObj.insertAsSub)
				{
					var parent_id=JSTreeObj.dragNode_destination.getElementsByTagName('A')[0].id.replace(/[^0-9]/g,'');
					var number_of_hops_down=0;
					var uls = JSTreeObj.dragNode_destination.getElementsByTagName('UL');
					if(uls.length>0)
					{
						ul = uls[0];
						ul.style.display='block';
						
						var lis = ul.getElementsByTagName('LI');

						if(lis.length>0)
						{	// Sub elements exists - drop dragable node before the first one
							ul.insertBefore(JSTreeObj.dragNode_source,lis[0]);
						}else {	// No sub exists - use the appendChild method - This line should not be executed unless there's something wrong in the HTML, i.e empty <ul>
							ul.appendChild(JSTreeObj.dragNode_source);	
						}
					}
					else
					{
						var ul = document.createElement('UL');
						ul.style.display='block';
						JSTreeObj.dragNode_destination.appendChild(ul);
						ul.appendChild(JSTreeObj.dragNode_source);
					}
					var img = JSTreeObj.dragNode_destination.getElementsByTagName('IMG')[0];					
					img.style.visibility='visible';
					img.src = img.src.replace(JSTreeObj.plusImage,JSTreeObj.minusImage);					
				}
				else
				{
					var parent_id=JSTreeObj.dragNode_destination.parentNode.parentNode.getElementsByTagName('A')[0].id.replace(/[^0-9]/g,'');
					var number_of_hops_down=1;
					if(JSTreeObj.dragNode_destination.nextSibling)
					{
						var nextSib = JSTreeObj.dragNode_destination.nextSibling;
						nextSib.parentNode.insertBefore(JSTreeObj.dragNode_source,nextSib);
					}
					else
					{
						JSTreeObj.dragNode_destination.parentNode.appendChild(JSTreeObj.dragNode_source);
					}
					var previousSibling=JSTreeObj.dragNode_destination.previousSibling;
					while(previousSibling!=null)
					{
						number_of_hops_down++;
						previousSibling=previousSibling.previousSibling;
					}
				}	
				var ajaxIndex = JSTreeObj.ajaxObjects.length;
				JSTreeObj.ajaxObjects[ajaxIndex] = new sack();
				JSTreeObj.ajaxObjects[ajaxIndex].method = "POST";
				JSTreeObj.ajaxObjects[ajaxIndex].setVar("id", child_id);
				JSTreeObj.ajaxObjects[ajaxIndex].setVar("parent_id", parent_id);
				JSTreeObj.ajaxObjects[ajaxIndex].setVar("down", number_of_hops_down);
				JSTreeObj.__addAdditionalRequestParameters(JSTreeObj.ajaxObjects[ajaxIndex], JSTreeObj.additionalDeleteRequestParameters);
				JSTreeObj.ajaxObjects[ajaxIndex].requestFile = JSTreeObj.filePathSaveLayoutItem;	// Specifying which file to get
				JSTreeObj.ajaxObjects[ajaxIndex].onCompletion = function() { JSTreeObj.__saveLayoutComplete(ajaxIndex); } ;	// Specify function that will be executed after file has been found
				JSTreeObj.ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function
				/* Clear parent object */
				var tmpObj = JSTreeObj.dragNode_parent;
				var lis = tmpObj.getElementsByTagName('LI');
				if(lis.length==0)
				{
					var img = tmpObj.parentNode.getElementsByTagName('IMG')[0];
					img.style.visibility='hidden';	// Hide [+],[-] icon
					tmpObj.parentNode.removeChild(tmpObj);						
				}
			}
			else
			{
				// Putting the item back to it's original location
				
				if(JSTreeObj.dragNode_sourceNextSib)
				{
					JSTreeObj.dragNode_parent.insertBefore(JSTreeObj.dragNode_source,JSTreeObj.dragNode_sourceNextSib);
				}
				else
				{
					JSTreeObj.dragNode_parent.appendChild(JSTreeObj.dragNode_source);
				}			
			}
			JSTreeObj.dropTargetIndicator.style.display='none';
			JSTreeObj.dragDropTimer = -1;
			if(showMessage && JSTreeObj.messageMaximumDepthReached)
			{//alert(this.maximumDepth);
				alert(JSTreeObj.messageMaximumDepthReached);
				return;
			}
		}
		,
		createDropIndicator : function()
		{
			this.dropTargetIndicator = document.createElement('DIV');
			this.dropTargetIndicator.style.position = 'absolute';
			this.dropTargetIndicator.style.display='none';			
			var img = document.createElement('IMG');
			img.src = this.imageFolder + 'dragDrop_ind1.gif';
			img.id = 'dragDropIndicatorImage';
			this.dropTargetIndicator.appendChild(img);
			document.body.appendChild(this.dropTargetIndicator);
			
		}
		,
		dragDropCountLevels : function(obj,direction,stopAtObject){
			var countLevels = 0;
			if(direction=='up'){
				while(obj.parentNode && obj.parentNode!=stopAtObject){
					obj = obj.parentNode;
					if(obj.tagName=='UL')countLevels = countLevels/1 +1;
				}		
				return countLevels;
			}	
			
			if(direction=='down'){ 
				var subObjects = obj.getElementsByTagName('LI');
				for(var no=0;no<subObjects.length;no++){
					countLevels = Math.max(countLevels,JSTreeObj.dragDropCountLevels(subObjects[no],"up",obj));
				}
				return countLevels;
			}	
		}		
		,
		cancelEvent : function()
		{
			return false;	
		}
		,
		cancelSelectionEvent : function()
		{
			
			if(JSTreeObj.dragDropTimer<10)return true;
			return false;	
		}
		,getNodeOrders : function(initObj,saveString)
		{
			
			if(!saveString)var saveString = '';
			if(!initObj){
				initObj = document.getElementById(this.idOfTree);

			}
			var lis = initObj.getElementsByTagName('LI');

			if(lis.length>0){
				var li = lis[0];
				while(li){
					if(li.id){
						if(saveString.length>0)saveString = saveString + ',';
						var numericID = li.id.replace(/[^0-9]/gi,'');
						if(numericID.length==0)numericID='A';
						var numericParentID = li.parentNode.parentNode.id.replace(/[^0-9]/gi,'');
						if(numericID!='0'){
							saveString = saveString + numericID;
							saveString = saveString + '-';
							
							
							if(li.parentNode.id!=this.idOfTree)saveString = saveString + numericParentID; else saveString = saveString + '0';
						}
						var ul = li.getElementsByTagName('UL');
						if(ul.length>0){
							saveString = this.getNodeOrders(ul[0],saveString);	
						}	
					}			
					li = li.nextSibling;
				}
			}

			if(initObj.id == this.idOfTree){
				return saveString;
							
			}
			return saveString;
		}
		,highlightItem : function(inputObj,e)
		{
			if(JSTreeObj.currentlyActiveItem)JSTreeObj.currentlyActiveItem.className = '';
			this.className = 'highlightedNodeItem';
			JSTreeObj.currentlyActiveItem = this;
		}
		,
		removeHighlight : function()
		{
			if(JSTreeObj.currentlyActiveItem)JSTreeObj.currentlyActiveItem.className = '';
			JSTreeObj.currentlyActiveItem = false;
		}
		,
		hasSubNodes : function(obj)
		{
			var subs = obj.getElementsByTagName('LI');
			if(subs.length>0)return true;
			return false;	
		}
		,
		deleteItem : function(obj1,obj2)
		{
			var message = this.deleteBranchMessagePromptPart1 + ' "' + obj2.innerHTML + '"';
			if(this.hasSubNodes(obj2.parentNode)) message = message + ' ' + this.deleteBranchMessagePromptPart2;
			if(confirm(message)){
				this.__deleteItem_step2(obj2.parentNode);	// Sending <LI> tag to the __deleteItem_step2 method	
			}
			
		}
		,
		moveItemsToParentItem : function(obj1,obj2)
		{
			var message = this.moveItemsToParentPromptMessagePart1 + ': ' + obj2.innerHTML;
			if(this.hasSubNodes(obj2.parentNode)) message = message + ' ' + this.moveItemsToParentPromptMessagePart2;
			message+=', ' + this.moveItemsToParentPromptMessagePart3 + ': '+obj2.parentNode.parentNode.parentNode.getElementsByTagName('A')[0].innerHTML;
			if(confirm(message))
			{
				this.__moveItemsToParentItem_step2(obj2.parentNode);	// Sending <LI> tag to the __deleteItem_step2 method
			}
			return;
		}
		,
		  mylightboxopen : function(obj1,obj2) {//bassam
			   
			   //url = "http://localhost/syriacorthodox/2011-12-1/admin/products/index/"+obj2.parentNode.id.replace(/[^0-9]/gi,'');
			   url = "http://localhost/skiespro/2011-11-25/admin/articles/index";
			   alert(url);
	if (current_my_light_box_stack_index == 0) {
		if (typeof(my_light_box_before_opening_the_first_popup) === 'function') {
			my_light_box_before_opening_the_first_popup(url);
		}
	
	}
		
	if (typeof(my_light_box_before_opening_every_popup) === 'function') {
		my_light_box_before_opening_every_popup(url);
	}
	
	if (typeof(my_light_box_before_opening_this_popup) === 'string') {
		eval(my_light_box_before_opening_this_popup);
	}
	
	current_my_light_box_stack_index++;
	//alert(url);
	//eval('oldScrollTop[' + current_my_light_box_stack_index + '] = jQuery(document).scrollTop();');
	jQuery.ajax({
		type: 'POST',
		url: url,
		
		//dataType: 'script',
		success: function(data) {
		 
			//var top = jQuery(document).scrollTop();
			 jQuery('#my_light_box_background_div_' + current_my_light_box_stack_index).css('left', 0);
			 jQuery('#my_light_box_background_div_' + current_my_light_box_stack_index).css('top',0);
			 jQuery('#my_light_box_background_div_' + current_my_light_box_stack_index).css('width', screen.width );
			 jQuery('#my_light_box_background_div_' + current_my_light_box_stack_index).css('height', screen.height);
			 jQuery('#my_light_box_active_div_' + current_my_light_box_stack_index).css('top', top);
			jQuery('#my_light_box_background_div_' + current_my_light_box_stack_index).show();
			jQuery('#my_light_box_active_div_content_' + current_my_light_box_stack_index).empty().html(data);
			jQuery('#my_light_box_active_div_close_' + current_my_light_box_stack_index).show();
			jQuery('#my_light_box_active_div_content_' + current_my_light_box_stack_index).show();
			jQuery('#my_light_box_active_div_' + current_my_light_box_stack_index).css('opacity', 0.01).show();
			jQuery('#my_light_box_active_div_' + current_my_light_box_stack_index).css('left', 0.5 * (screen.width - my_light_box_active_div_width[current_my_light_box_stack_index] - jQuery('#my_light_box_active_div_' + current_my_light_box_stack_index).width()));
			jQuery('#my_light_box_active_div_' + current_my_light_box_stack_index).animate({opacity:1}, 1000, function() {
				if (typeof(my_light_box_after_opening_this_popup) === 'string') {
					//eval(my_light_box_after_opening_this_popup);
				}
				if (typeof(my_light_box_after_opening_every_popup) === 'function') {
					my_light_box_after_opening_every_popup(url);
				}
				if (current_my_light_box_stack_index == 1) {
					if (typeof(my_light_box_after_opening_the_first_popup) === 'function') {
						my_light_box_after_opening_the_first_popup(url);
					}
				}
			});
		}
	});
	if (current_my_light_box_stack_index == 1) {
		jQuery('#listing_items_of_any_type').attr('id', 'listing_items_of_any_type_old');
	}
},
    mylightboxclose: function (my_light_box_before_closing_this_popup, my_light_box_after_closing_this_popup) {
	if (current_my_light_box_stack_index > 0) {
		if (current_my_light_box_stack_index == 1) {
			if (typeof(my_light_box_before_closing_the_last_popup) === 'function') {
				my_light_box_before_closing_the_last_popup();
			}
		}
		if (typeof(my_light_box_before_closing_every_popup) === 'function') {
			my_light_box_before_closing_every_popup();
		}
		if (typeof(my_light_box_before_closing_this_popup) === 'string') {
			eval(my_light_box_before_closing_this_popup);
		}
		CKEditorClean();
		jQuery('#my_light_box_active_div_' + current_my_light_box_stack_index).animate({opacity:0}, 250, function() {
			jQuery('#my_light_box_active_div_close_title_' + current_my_light_box_stack_index).empty().html('').css('width', 'auto');
			jQuery('#my_light_box_active_div_content_' + current_my_light_box_stack_index).empty().html('');
			jQuery('#my_light_box_active_div_close_' + current_my_light_box_stack_index).hide();
			jQuery('#my_light_box_active_div_content_' + current_my_light_box_stack_index).hide();
			jQuery('#my_light_box_background_div_' + current_my_light_box_stack_index).hide();
			jQuery('#my_light_box_active_div_' + current_my_light_box_stack_index).hide();
			//eval('jQuery(document).scrollTop(oldScrollTop[' + current_my_light_box_stack_index + ']);');
			 captcha(); 
			if (current_my_light_box_stack_index == 1) {
				jQuery('#listing_items_of_any_type_old').attr('id', 'listing_items_of_any_type');
			}
			current_my_light_box_stack_index--;
			if (typeof(my_light_box_after_closing_this_popup) === 'string') {
				eval(my_light_box_after_closing_this_popup);
			}
			if (typeof(my_light_box_after_closing_every_popup) === 'function') {
				my_light_box_after_closing_every_popup();
			}
			if (current_my_light_box_stack_index == 0) {
				if (typeof(my_light_box_after_closing_the_last_popup) === 'function') {
					my_light_box_after_closing_the_last_popup();
				}
			}
		});
	}
},
		__refreshDisplay : function(obj)
		{
			if(this.hasSubNodes(obj))return;

			var img = obj.getElementsByTagName('IMG')[0];
			img.style.visibility = 'hidden';
			if(img.src.indexOf(JSTreeObj.minusImage)>=0) img.src = img.src.replace(JSTreeObj.minusImage,JSTreeObj.plusImage);
		}
		,
		__moveItemsToParentItem_step2 : function(obj)
		{
			var branch_id=obj.id.replace(/[^0-9]/gi,'');
			var parent_branch_id=obj.parentNode.parentNode.id.replace(/[^0-9]/gi,'');
			var ajaxIndex = JSTreeObj.ajaxObjects.length;
			JSTreeObj.ajaxObjects[ajaxIndex] = new sack();
			JSTreeObj.ajaxObjects[ajaxIndex].method = "POST";
			JSTreeObj.ajaxObjects[ajaxIndex].setVar("branch_id", branch_id);
			JSTreeObj.ajaxObjects[ajaxIndex].setVar("parent_branch_id", parent_branch_id);
			JSTreeObj.__addAdditionalRequestParameters(JSTreeObj.ajaxObjects[ajaxIndex], JSTreeObj.additionalDeleteRequestParameters);
			JSTreeObj.ajaxObjects[ajaxIndex].requestFile = JSTreeObj.filePathMoveItemsToParentItem;	// Specifying which file to get
			JSTreeObj.ajaxObjects[ajaxIndex].onCompletion = function() { JSTreeObj.__moveItemsToParentComplete(ajaxIndex,obj); } ;	// Specify function that will be executed after file has been found
			JSTreeObj.ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function				
		}
		,
		__deleteItem_step2 : function(obj)
		{

			var saveString = obj.id.replace(/[^0-9]/gi,'');
			
			var lis = obj.getElementsByTagName('LI');
			for(var no=0;no<lis.length;no++){
				saveString = saveString + ',' + lis[no].id.replace(/[^0-9]/gi,'');
			}
			
			// Creating ajax object and send items
			var ajaxIndex = JSTreeObj.ajaxObjects.length;
			JSTreeObj.ajaxObjects[ajaxIndex] = new sack();
			JSTreeObj.ajaxObjects[ajaxIndex].method = "POST";
			JSTreeObj.ajaxObjects[ajaxIndex].setVar("deleteIds", saveString);
			JSTreeObj.__addAdditionalRequestParameters(JSTreeObj.ajaxObjects[ajaxIndex], JSTreeObj.additionalDeleteRequestParameters);
			JSTreeObj.ajaxObjects[ajaxIndex].requestFile = JSTreeObj.filePathDeleteItem;	// Specifying which file to get
			JSTreeObj.ajaxObjects[ajaxIndex].onCompletion = function() { JSTreeObj.__deleteComplete(ajaxIndex,obj); } ;	// Specify function that will be executed after file has been found
			JSTreeObj.ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function				
		}
		,
		__addItem_step2 : function (obj,new_node_name)
			{
			
				var ajaxIndex = JSTreeObj.ajaxObjects.length;
				JSTreeObj.ajaxObjects[ajaxIndex] = new sack();
				JSTreeObj.ajaxObjects[ajaxIndex].method = "POST";
				JSTreeObj.ajaxObjects[ajaxIndex].setVar("new_node_name", new_node_name);
				JSTreeObj.ajaxObjects[ajaxIndex].setVar("parent_id", obj.parentNode.id.replace(/\D/g,''));
				JSTreeObj.__addAdditionalRequestParameters(JSTreeObj.ajaxObjects[ajaxIndex], JSTreeObj.additionalAddRequestParameters);
				JSTreeObj.ajaxObjects[ajaxIndex].requestFile = JSTreeObj.filePathAddItem;	// Specifying which file to get
				//alert(JSTreeObj.ajaxObjects[ajaxIndex].requestFile);
				JSTreeObj.ajaxObjects[ajaxIndex].onCompletion = function() {JSTreeObj.__addComplete(ajaxIndex,obj,new_node_name); } ;	// Specify function that will be executed after file has been found
				JSTreeObj.ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function				
			}
			,
		
		__addComplete : function(ajaxIndex,obj,new_node_name)
		{
		
			//alert(this);
			//if(!inputObj && this)inputObj = this;
				
			var filter=/^[1-9]\d*$/;
			//	if(!filter.test(jQuery.trim(this.ajaxObjects[ajaxIndex].response))){
			if(!filter.test(jQuery.trim(this.ajaxObjects[ajaxIndex].response))){
				
				alert('ERROR WHEN TRYING TO Add NODE: ' + this.ajaxObjects[ajaxIndex].response); 	// Add failed
				return;
			}
			var li = document.createElement('LI');
			var img = document.createElement('IMG');
			img.src = this.imageFolder + this.plusImage;
			img.style.visibility='hidden';
			img.onclick = JSTreeObj.showHideNode;
			li.appendChild(img);
			var folderImg = document.createElement('IMG');
			folderImg.onmousedown = JSTreeObj.initDrag;
			folderImg.onmousemove = JSTreeObj.moveDragableNodes;
			folderImg.src = this.imageFolder + this.folderImage;
			li.appendChild(folderImg);
			var aTag = document.createElement('A');
			aTag.innerHTML = new_node_name;
			aTag.href = '#';
			jQuery(aTag).click(function() {
				hey_tree_do_your_behavior(this);
			});
			aTag.id = this.nodeATagIdPrefix + this.ajaxObjects[ajaxIndex].response;
			aTag.onmousedown = JSTreeObj.initDrag;
			aTag.onmousemove = JSTreeObj.moveDragableNodes;	
			li.appendChild(aTag);
			li.id = 'node_'+this.ajaxObjects[ajaxIndex].response;
			li.setAttribute('noSiblings','false');
			li.setAttribute('noChildren','false');
			li.setAttribute('noDrag','false');
			li.setAttribute('noDelete','false');
			li.setAttribute('noRename','false');
			li.setAttribute('noAdd','false');
			var subItems = obj.parentNode.getElementsByTagName('UL');
			if(subItems.length>0) subItems[0].appendChild(li);
			else
			{
				var ul = document.createElement('UL');
				obj.parentNode.appendChild(ul).appendChild(li);
				obj.parentNode.childNodes[0].style.visibility='visible';
			}
			var menuModel = new DHTMLGoodies_menuModel();
			var i=0;
			if(this.addAllowed)
			{
				i++;
				menuModel.addItem(i,this.addSubCategoryMenuTitle,'','',false,'JSTreeObj.addItem');
				
				
			}
			if(this.productAllowed)//bassam
			{
				//i++;
				//alert('a');
				//menuModel.addItem(i,this.renameBranchMenuTitle,'','',false,'JSTreeObj.renameItem');
				//menuModel.addItem(i,this.Product,'','',false,'JSTreeObj.mylightboxopen("http://localhost/syriacorthodox/2011-12-1/admin/products/index")');
			}
			
			if(this.renameAllowed)
			{
				i++;
				menuModel.addItem(i,this.renameBranchMenuTitle,'','',false,'JSTreeObj.renameItem');
			}
			if(this.deleteAllowed)
			{
				i++;
				menuModel.addItem(i,this.deleteBranchMenuTitle,'','',false,'JSTreeObj.deleteItem');
			}
			if (this.filePathMoveItemsToParentItem.length > 0) {
				i++;
				menuModel.addItem(i,this.moveItemsToParentMenuTitle,'','',false,'JSTreeObj.moveItemsToParentItem');
			}
			
			//menuModel.addItem(i+1,this.Product,'','',false,'JSTreeObj.mylightboxopen("http://localhost/syriacorthodox/2011-12-1/admin/products/index")');
			menuModel.init();
			
			this.contextMenu.attachToElement(aTag,false,menuModel);
			this.addEvent(aTag,'contextmenu',this.highlightItem);
			li.parentNode.parentNode.childNodes[0].style.visibility='visible';
			if(li.parentNode.parentNode.childNodes[0].src.indexOf(JSTreeObj.plusImage)>=0) JSTreeObj.showHideNode(false,li.parentNode.parentNode.id);
		}
		,
		__deleteComplete : function(ajaxIndex,obj)
		{
			if(jQuery.trim(this.ajaxObjects[ajaxIndex].response)!='OK'){
				alert(this.ajaxObjects[ajaxIndex].response); 	// Delete failed
			}else{
				
				var parentRef = obj.parentNode.parentNode;
				obj.parentNode.removeChild(obj);
				this.__refreshDisplay(parentRef);
			}			
			
		}
		,
		__moveItemsToParentComplete : function(ajaxIndex,obj)
		{
			alert(this.ajaxObjects[ajaxIndex].response);
		}
		,
		__saveLayoutComplete : function(ajaxIndex)
		{
			if(this.ajaxObjects[ajaxIndex].response!='OK') alert(this.ajaxObjects[ajaxIndex].response);
		}
		,
		__renameComplete : function(ajaxIndex,obj,old_node_name)
		{
			
			// alert ("k"+this.ajaxObjects[ajaxIndex].response+"k");
			//document.write(this.ajaxObjects[ajaxIndex].response);
			 //var testok =  this.ajaxObjects[ajaxIndex].response.replace("\n", "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n").split(' ').join('');
			//document.write((this.ajaxObjects[ajaxIndex].response);
			// alert(testok.length);   Bassam and Joseph
			
			if(jQuery.trim(this.ajaxObjects[ajaxIndex].response)!='OK'){
				
				alert('ERROR WHEN TRYING TO RENAME NODE: ' + this.ajaxObjects[ajaxIndex].response); 	// Rename failed
				obj.innerHTML=old_node_name;
				obj.previousSibling.value=old_node_name;
			}
		}
		,
		__saveTextBoxChanges : function(e,inputObj)
		{
			if(!inputObj && this)inputObj = this;
			if(document.all)e = event;
			if(e.keyCode && e.keyCode==27){
				JSTreeObj.__cancelRename(e,inputObj);
				return;
			}
			inputObj.style.display='none';
			inputObj.nextSibling.style.visibility='visible';
			if(inputObj.value.length>0){
				while(inputObj.value.substring(0,1)=='_') inputObj.value=inputObj.value.substring(1,inputObj.value.length);
			}
			if(inputObj.value.length>0){
				var old_node_name=inputObj.nextSibling.innerHTML;
				inputObj.nextSibling.innerHTML = inputObj.value;	
				// Send changes to the server.
				if (JSTreeObj.renameState != JSTreeObj.RENAME_STATE_BEGIN) {
					return;
				}
				JSTreeObj.renameState = JSTreeObj.RENAME_STATE_REQUEST_SENDED;

				var ajaxIndex = JSTreeObj.ajaxObjects.length;
				JSTreeObj.ajaxObjects[ajaxIndex] = new sack();
				JSTreeObj.ajaxObjects[ajaxIndex].method = "POST";
				JSTreeObj.ajaxObjects[ajaxIndex].setVar("renameId", inputObj.parentNode.id.replace(/[^0-9]/gi,''));
				JSTreeObj.ajaxObjects[ajaxIndex].setVar("newName", inputObj.value);
				JSTreeObj.__addAdditionalRequestParameters(JSTreeObj.ajaxObjects[ajaxIndex], JSTreeObj.additionalRenameRequestParameters);
				//alert (inputObj);
				JSTreeObj.ajaxObjects[ajaxIndex].requestFile = JSTreeObj.filePathRenameItem;
				//alert(JSTreeObj.additionalAddRequestParameters);	// Specifying which file to get
				JSTreeObj.ajaxObjects[ajaxIndex].onCompletion = function() { JSTreeObj.__renameComplete(ajaxIndex,inputObj.nextSibling,old_node_name); } ;	// Specify function that will be executed after file has been found
				JSTreeObj.ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		
							
				
				
			}
		}
		,
		__cancelRename : function(e,inputObj)
		{
			JSTreeObj.renameState = JSTreeObj.RENAME_STATE_CANCELD;
			if(!inputObj && this)inputObj = this;
			inputObj.value = JSTreeObj.helpObj.innerHTML;
			inputObj.nextSibling.innerHTML = JSTreeObj.helpObj.innerHTML;
			inputObj.style.display = 'none';
			inputObj.nextSibling.style.visibility = 'visible';
		}
		,
		__renameCheckKeyCode : function(e)
		{
			if(document.all)e = event;
			if(e.keyCode==13){	// Enter pressed
				JSTreeObj.__saveTextBoxChanges(false,this);	
			}	
			if(e.keyCode==27){	// ESC pressed
				JSTreeObj.__cancelRename(false,this);
			}
		}
		,
		__createTextBox : function(obj)
		{
			var textBox = document.createElement('INPUT');
			textBox.className = 'folderTreeTextBox';
			textBox.value = obj.innerHTML;
			obj.parentNode.insertBefore(textBox,obj);	
			textBox.id = 'textBox' + obj.parentNode.id.replace(/[^0-9]/gi,'');
			textBox.onblur = this.__saveTextBoxChanges;	
			textBox.onkeydown = this.__renameCheckKeyCode;
			this.__renameEnableTextBox(obj);
		}
		,
		__renameEnableTextBox : function(obj)
		{
			JSTreeObj.renameState = JSTreeObj.RENAME_STATE_BEGIN;
			obj.style.visibility = 'hidden';
			obj.previousSibling.value = obj.innerHTML;
			obj.previousSibling.style.display = 'inline';	
			obj.previousSibling.select();
		}
		,
		renameItem : function(obj1,obj2)
		{//alert(obj2.parentNode.id);
			currentItemToEdit = obj2.parentNode;	// Reference to the <li> tag.
			if(!obj2.previousSibling || obj2.previousSibling.tagName.toLowerCase()!='input'){
				this.__createTextBox(obj2);
			}else{
				this.__renameEnableTextBox(obj2);
			}
			this.helpObj.innerHTML = obj2.innerHTML;

		}
		,
		initTree : function()
		{
			 
			
			JSTreeObj = this;
			JSTreeObj.createDropIndicator();
			document.documentElement.onselectstart = JSTreeObj.cancelSelectionEvent;
			document.documentElement.ondragstart = JSTreeObj.cancelEvent;
			document.documentElement.onmousedown = JSTreeObj.removeHighlight;
			
			/* Creating help object for storage of values */
			this.helpObj = document.createElement('DIV');
			this.helpObj.style.display = 'none';
			document.body.appendChild(this.helpObj);
			
			
			/* Create context menu */
			if(this.deleteAllowed || this.renameAllowed || this.addAllowed || this.productAllowed){
				try{
					/* Creating menu model for the context menu, i.e. the datasource */
					var menuModel = new DHTMLGoodies_menuModel();
					if(this.deleteAllowed && this.renameAllowed && this.addAllowed && this.productAllowed  )
					{
						menuModel.addItem(1,this.addSubCategoryMenuTitle,'','',false,'JSTreeObj.addItem');
						menuModel.addItem(2,this.renameBranchMenuTitle,'','',false,'JSTreeObj.renameItem');
						menuModel.addItem(3,this.deleteBranchMenuTitle,'','',false,'JSTreeObj.deleteItem');
						if (this.filePathMoveItemsToParentItem.length > 0) {
							menuModel.addItem(4,this.moveItemsToParentMenuTitle,'','',false,'JSTreeObj.moveItemsToParentItem');
						}
						
					//menuModel.addItem(5,this.Product,'','',false,'JSTreeObj.mylightboxopen');bassam to add menu tab
					}
					//bassam
					//alert(this.Product);
				//	alert(this.dragNode_source);
				//alert(JSTreeObj.parentNode.id.replace(/\D/g,''));
		//JSTreeObj.dragNode_destination.getElementsByTagName('A')[0].id.replace(/[^0-9]/g,'');
		//addcomplete
					
					menuModel.init();
					
					var menuModelRenameOnly = new DHTMLGoodies_menuModel();
					if(this.renameAllowed)
					{
						menuModelRenameOnly.addItem(1,this.renameBranchMenuTitle,'','',false,'JSTreeObj.renameItem');
					}
					menuModelRenameOnly.init();	
					
					var menuModelDeleteOnly = new DHTMLGoodies_menuModel();
					if(this.deleteAllowed)
					{
						menuModelDeleteOnly.addItem(1,this.deleteBranchMenuTitle,'','',false,'JSTreeObj.deleteItem');
						if (this.filePathMoveItemsToParentItem.length > 0) {
							menuModelDeleteOnly.addItem(2,this.moveItemsToParentMenuTitle,'','',false,'JSTreeObj.moveItemsToParentItem');
						}
					}
					menuModelDeleteOnly.init();	

					var menuModelAddOnly = new DHTMLGoodies_menuModel();
					if(this.addAllowed)
					{
						menuModelAddOnly.addItem(1,this.addSubCategoryMenuTitle,'','',false,'JSTreeObj.addItem');
					}
					menuModelAddOnly.init();	

					var menuModelRenameAndAddOnly = new DHTMLGoodies_menuModel();
					if(this.renameAllowed && this.addAllowed)
					{
						menuModelRenameAndAddOnly.addItem(1,this.addSubCategoryMenuTitle,'','',false,'JSTreeObj.addItem');
						menuModelRenameAndAddOnly.addItem(2,this.renameBranchMenuTitle,'','',false,'JSTreeObj.renameItem');
					}
					menuModelRenameAndAddOnly.init();	

					var menuModelRenameAndDeleteOnly = new DHTMLGoodies_menuModel();
					if(this.renameAllowed && this.deleteAllowed)
					{
						menuModelRenameAndDeleteOnly.addItem(1,this.renameBranchMenuTitle,'','',false,'JSTreeObj.renameItem');
						menuModelRenameAndDeleteOnly.addItem(2,this.deleteBranchMenuTitle,'','',false,'JSTreeObj.deleteItem');
						if (this.filePathMoveItemsToParentItem.length > 0) {
							menuModelRenameAndDeleteOnly.addItem(3,this.moveItemsToParentMenuTitle,'','',false,'JSTreeObj.moveItemsToParentItem');
						}
					}
					menuModelRenameAndDeleteOnly.init();	

					var menuModelAddAndDeleteOnly = new DHTMLGoodies_menuModel();
					if(this.deleteAllowed && this.addAllowed)
					{
						menuModelAddAndDeleteOnly.addItem(1,this.addSubCategoryMenuTitle,'','',false,'JSTreeObj.addItem');
						menuModelAddAndDeleteOnly.addItem(2,this.deleteBranchMenuTitle,'','',false,'JSTreeObj.deleteItem');
						if (this.filePathMoveItemsToParentItem.length > 0) {
							menuModelAddAndDeleteOnly.addItem(3,this.moveItemsToParentMenuTitle,'','',false,'JSTreeObj.moveItemsToParentItem');
						}
					}
					menuModelAddAndDeleteOnly.init();	
					menuModelAddAndDeleteOnly.addItem(3,this.Product,'','',false,'');
					window.refToDragDropTree = this;
					
					this.contextMenu = new DHTMLGoodies_contextMenu();
					this.contextMenu.setWidth(250);
					referenceToDHTMLSuiteContextMenu = this.contextMenu;
				}catch(e){
					
				}
			}

					
			var nodeId = 0;
			var dhtmlgoodies_tree = document.getElementById(this.idOfTree);
			var menuItems = dhtmlgoodies_tree.getElementsByTagName('LI');	// Get an array of all menu items
			for(var no=0;no<menuItems.length;no++){
				// No children var set ?
				var noChildren = false;
				var tmpVar = menuItems[no].getAttribute('noChildren');
				if(!tmpVar)tmpVar = menuItems[no].noChildren;
				if(tmpVar=='true')noChildren=true;
				// No drag var set ?
				var noDrag = false;
				var tmpVar = menuItems[no].getAttribute('noDrag');
				if(!tmpVar)tmpVar = menuItems[no].noDrag;
				if(tmpVar=='true')noDrag=true;
						 
				nodeId++;
				var subItems = menuItems[no].getElementsByTagName('UL');
				var img = document.createElement('IMG');
				img.src = this.imageFolder + this.plusImage;
				img.onclick = JSTreeObj.showHideNode;
				
				if(subItems.length==0)img.style.visibility='hidden';else{
					subItems[0].id = 'tree_ul_' + treeUlCounter;
					treeUlCounter++;
				}
				var aTag = menuItems[no].getElementsByTagName('A')[0];
				aTag.id = this.nodeATagIdPrefix + menuItems[no].id.replace(/[^0-9]/gi,'');
				//aTag.onclick = JSTreeObj.showHideNode;
				if(!noDrag)aTag.onmousedown = JSTreeObj.initDrag;
				if(!noChildren)aTag.onmousemove = JSTreeObj.moveDragableNodes;
				menuItems[no].insertBefore(img,aTag);
				//alert(img);
				//menuItems[no].id = 'dhtmlgoodies_treeNode' + nodeId;
				var folderImg = document.createElement('IMG');
				if(!noDrag)folderImg.onmousedown = JSTreeObj.initDrag;
				folderImg.onmousemove = JSTreeObj.moveDragableNodes;
				if(menuItems[no].className){
					folderImg.src = this.imageFolder + menuItems[no].className;
				}else{
					folderImg.src = this.imageFolder + this.folderImage;
				}
				menuItems[no].insertBefore(folderImg,aTag);
				
				if(this.contextMenu){
					if(!this.deleteAllowed) var noDelete='true';
					else
					{
						var noDelete = menuItems[no].getAttribute('noDelete');
						//alert(noDelete);
						if(noDelete==null) noDelete='false';
					}
					if(!this.renameAllowed) var noRename='true';
					else
					{
						var noRename = menuItems[no].getAttribute('noRename');
						if(noRename==null) noRename='false';
					}
					if(!this.addAllowed) var noAdd='true';
					else
					{
						var noAdd = menuItems[no].getAttribute('noAdd');
						if(noAdd==null) noAdd='false';
					}
					if(noRename=='false' || noDelete=='false' || noAdd=='false')
					{
						if(noDelete == 'false' && noRename == 'false' && noAdd == 'false') {
							//alert('0');
							this.contextMenu.attachToElement(aTag,false,menuModel);
						} else if (noDelete == 'true' && noRename == 'true' && noAdd == 'false') {
							//alert('1');
							this.contextMenu.attachToElement(aTag,false,menuModelAddOnly);
						} else if (noDelete == 'true' && noRename == 'false' && noAdd == 'false') {
							//alert('2');
							this.contextMenu.attachToElement(aTag,false,menuModelRenameAndAddOnly);
						} else if (noDelete == 'false' && noRename == 'true' && noAdd == 'true') {
							//alert('3');
							this.contextMenu.attachToElement(aTag,false,menuModelDeleteOnly);
						} else if (noDelete == 'false' && noRename == 'false' && noAdd == 'true') {
							//alert('4');
							this.contextMenu.attachToElement(aTag,false,menuModelRenameAndDeleteOnly);
						} else if (noDelete == 'true' && noRename == 'false' && noAdd == 'true') {
							//alert('5');
							this.contextMenu.attachToElement(aTag,false,menuModelRenameOnly);
						} else if (noDelete == 'false' && noRename == 'true' && noAdd == 'false') {
							//alert('6');
							this.contextMenu.attachToElement(aTag,false,menuModelAddAndDeleteOnly);
						}
					}
				}
				this.addEvent(aTag,'contextmenu',this.highlightItem);
			}	
			initExpandedNodes = this.Get_Cookie('dhtmlgoodies_expandedNodes');
			if(initExpandedNodes){
				var nodes = initExpandedNodes.split(',');
				for(var no=0;no<nodes.length;no++){
					if(nodes[no])this.showHideNode(false,nodes[no]);	
				}			
			}			
			document.documentElement.onmousemove = JSTreeObj.moveDragableNodes;	
			document.documentElement.onmouseup = JSTreeObj.dropDragableNodes;
		}
		,
		__addAdditionalRequestParameters : function(ajax, parameters)
		{
			for (var parameter in parameters) {
				ajax.setVar(parameter, parameters[parameter]);
			}
		}
		,
		addItem : function(obj1, obj2)
			  {
				if (1 + this.get_the_elem_depth_in_the_tree(obj1, obj2) >= this.maximumDepth) {
					alert(this.messageMaximumDepthReached);
					return;
				}
				var new_node_name=window.prompt(this.newCategoryPromptMessage + ' "' + obj2.innerHTML + '"','');
				if(new_node_name==null) return;
				new_node_name=new_node_name.replace(/^(\s)+/,'').replace(/(\s)+$/,'');
				if(new_node_name.length==0) return;
				this.__addItem_step2(obj2,new_node_name)
			  }
		,
		get_the_elem_depth_in_the_tree : function(obj1, obj2) {
			return - 1 + jQuery(obj2).parents('#tree LI').size();
		}
	}

