var IsMenu;
var IsForFolders;
var loaded; 
var x = "1"; 
var isback;

function $(id) { return document.getElementById(id); }
    
function isBackButtonUsed(){
 return isBack;
}

function MultiCheck(e,obj) {
    var allCbs = obj.parentNode.parentNode.parentNode.getElementsByTagName("input");
    for (var i = 0; i < allCbs.length; i++){
        allCbs[i].checked =  obj.checked;
    }    
    return true;
}
    
function CheckForBackButton(){
    var _a1 = $('ctl00_inpCheckBackBtn');
    if (_a1 != null)
    {
    isBack = (x != _a1.value);
    if (isBack) {
        _a1.value=3;
        _a1.defaultValue=3;
    }
    else {
        _a1.value=2;
        _a1.defaultValue=2;    
     }
     }
}

function getClientsTimeZone()
{
	//getting remote timezone
	var today = new Date();
	var TDM = document.getElementById('ctl00_ContentPlaceHolder1_TimeDiffInMins')
	if(TDM != null)
	{
	    TDM.value = -(today.getTimezoneOffset());
	}
}
		
function Hide(divId)			
{			 
	if (divId != null)
	{				
		var div = document.getElementById(divId);									
		if (div != null)
		{
		    div.style.visibility = "hidden";
		    div.style.position = "absolute";												
		}
	}
}


function ShowHelpBox(helpDivId)
{		
	var divArray = document.getElementsByTagName("div");
	for (var i =0; i < divArray.length; i++)
	{
		if (divArray[i].id != null && divArray[i].id.indexOf("helpBox_") > -1)
		{
			divArray[i].style.visibility = "hidden";
		}				
	}

	var helpDiv = document.getElementById(helpDivId);									
	if (helpDiv.style.visibility.toLowerCase() == "hidden") 
	{					
		var helpDiv = document.getElementById(helpDivId);				
		helpDiv.style.visibility = "visible";
		var temp = "Hide('"+ helpDivId + "')";
		setTimeout(temp,5000);
	} 						
}
															
function ShowNews()
{
	document.getElementById('ctl00_ContentPlaceHolder1_news').style.position = "relative";			
	document.getElementById('ctl00_ContentPlaceHolder1_news').style.visibility = "visible";								
}

function SetCookiesNJS()
{
	if (document.getElementById('ctl00$ICJ') != null)	
	{
	    document.getElementById('ctl00$ICJ').value = "true";			
	}
}					

function CheckEnableMenuActions(menuItemIds,parentId)
{    
        var tasks = 0;
        var allCBs = $("ctl00_ContentPlaceHolder1_"+parentId).getElementsByTagName("input");
        var areSomeChecked = false;
        for (var i =0; i < allCBs.length; i++)
        {
            if (allCBs[i].id != null && allCBs[i].id != ""
             && allCBs[i].type == "checkbox" && allCBs[i].checked)
            {
                areSomeChecked = true;
                tasks = allCBs[i].id.substr(allCBs[i].id.lastIndexOf("_")+1);
             }            
        }

        for (var i =0; i < menuItemIds.length; i++)
        {
            var menuItemObj = $("ctl00_"+menuItemIds[i]);
            if (menuItemObj == null) 
                menuItemObj = $("ctl00_ContentPlaceHolder1_"+menuItemIds[i]);
                if (menuItemObj != null)  
                {
                    menuItemObj.disabled = !areSomeChecked;
                    if (!areSomeChecked)
                    {
                        menuItemObj.style.color = "lightgrey";
                    }
                    else
                    {
                        if((menuItemIds[i].indexOf("hypMenuRemoveTeachers")) > -1)
                            if(tasks > 0)
                                menuItemObj.href = menuItemObj.href.replace("Are you sure you want to remove the selected teacher/s?", "The selected teacher/s have set some tasks that are not yet handed in. By continuing, you will also remove all associated tasks.");
                            else
                                menuItemObj.href = menuItemObj.href.replace("The selected teacher/s have set some tasks that are not yet handed in. By continuing, you will also remove all associated tasks.","Are you sure you want to remove the selected teacher/s?");
                        menuItemObj.style.color = "";    
                    }
                }
        }
        
}


function ConfirmMenuItem(menuItemId,message)
{
    var menuItem = $(menuItemId);
    if (menuItem == null)
        menuItem = $("ctl00_"+menuItemId);
    if (menuItem == null)
        menuItem = $("ctl00_ContentPlaceHolder1_"+menuItemId);
        
    if (menuItem != null && menuItem.disabled == false)
    {    
        if (message == null) message = "Are you sure?";
        return confirm(message);
    }
    else
      return false;
}

function ConfirmRemoveResource()
{
	return confirm("Are you sure you want to remove this resource?");
}	
			
function ConfirmDeleteList()
{
	return confirm("Are you sure you want to delete this folder?");			
}					
//flag to indicate whether the page has loaded yet
var loaded = false;

//picture array which corresponds to the <a> options i.e 0,1,2 see bottom of page
var pictureArray = ["OriginalImage","MediumImage","ThumbnailImage"];
//var reset = false;
		
		
function CheckSelectedApplication(source, args)
{
	args.IsValid = (args.Value != "NOVALUE");
}
		
function PreviewSelectedImageFile(fileUploadObject)
{
    
	var TargetObject = document.getElementById("ctl00_ContentPlaceHolder1_imgPreview");	
	if (fileUploadObject.value != "" && fileUploadObject.value != null)
	{	
	    if (TargetObject.src != null)
	    {																					
		    TargetObject.src = "file://"+fileUploadObject.value;		    						
		}
	}

}	

function MakeImageVisible()
{	
	var TargetObject = document.getElementById("ctl00_ContentPlaceHolder1_imgPreview");	
	if (TargetObject != null)		
	{
	    TargetObject.style.visibility = "visible";			

	 }
}


function MakeImageHidden()
{	
	var TargetObject = document.getElementById("ctl00_ContentPlaceHolder1_imgPreview");
	TargetObject.style.visibility = "hidden"			
}
			


		
		
function FocusButton(btnId)
{
	currentButt = btnId;
}
	
function FindParent(node,nodeName)
{
	var parentCell = node.parentNode;
	while(parentCell.nodeName.toUpperCase() != nodeName)
	{
	    parentCell = parentCell.parentNode; 
	}	
	
	return parentCell;
}	
	
function OnBodyKeyPress(Event){}
		
		function CNPNC(anchor,eovent)
		{
			Navigating = false;
			var ieX = eovent.keyCode;
			var nsX = eovent.which;
			var keyPressed;										
			if (ieX != "")
			{
				keyPressed = String.fromCharCode(ieX);
			}
			else
			{
				keyPressed = String.fromCharCode(nsX);
			}		
			var tableCell = anchor.parentNode.parentNode;
			var subTable = tableCell.parentNode.parentNode.parentNode;	
			var div = tableCell.firstChild;		
			var tableRow = tableCell.parentNode;
			var parentTable = FindParent(subTable,"TABLE");
			var parentParentTable = FindParent(parentTable,"TABLE");
		
			UnselectRows(subTable);																		
			div.style.backgroundColor ='#ebebeb';					
					
			if (keyPressed == "\r" || ieX == 13 ||nsX == 13)
			{
				if (navigator.userAgent.toLowerCase().indexOf("gecko") < 0)
				{				
					anchor.click();
				}
			}																		
			else if (keyPressed == "6")
			{
				if (tableRow.firstChild.firstChild.id == "")
				{
					tableRow.firstChild.firstChild.style.backgroundColor='#ebebeb';
				}
				else
				{
					tableRow.style.backgroundColor='#ebebeb';			
				}
			}
			else if (keyPressed == "4")
			{													
				if (subTable.style.visibility.toUpperCase()== "VISIBLE")
				{		
					div.style.backgroundColor='';										
					CloseMenu(FindParent(subTable,"TABLE"));
						
					FindParent(subTable,"TD").previousSibling.firstChild.firstChild.focus();												

				}						
			}		
			else if (keyPressed == "8")
			{																						
				if (tableRow.previousSibling != null && (tableRow.previousSibling.rowIndex != 0 || tableRow.previousSibling.rowIndex == 0 && parentTable.id == ""))
				{			
								
					div.style.backgroundColor='';							
															
					if (tableRow.previousSibling.firstChild.nextSibling != null)
					{																			
						if (tableRow.previousSibling.firstChild.nextSibling.firstChild.firstChild.nodeValue == null )								 				
						{
							tableRow.previousSibling.firstChild.firstChild.firstChild.focus();	
						}
						else
						{
							tableRow.previousSibling.firstChild.firstChild.focus();						
						}
						
						tableRow.previousSibling.firstChild.style.backgroundColor='#ebebeb';											
					}
					else
					{
						tableRow.previousSibling.firstChild.firstChild.lastChild.focus();	
						tableRow.previousSibling.firstChild.firstChild.style.backgroundColor='#ebebeb';						
					
					}
				}
				else
				{			
					if (parentTable.id == "" && subTable.id != TreeListControlTable && TreeListControlTable != null)
					{						
						div.style.backgroundColor='';						
						var tableAbove = document.getElementById(TreeListControlTable);
						SelectRow(tableAbove,tableAbove.rows.length-1);
						
					}
					else if (parentTable.id == "" && subTable.id != TreeListControlTableInherited  )
					{
						div.style.backgroundColor='';						
						var tableAbove = document.getElementById(TreeListControlTableInherited);
						SelectRow(tableAbove,tableAbove.rows.length-1);										
					}
					else
					{
						div.style.backgroundColor ='#ebebeb';	
					}
				}							
			}
			else if (keyPressed == "2")
			{		
																
				var numRows = tableCell.parentNode.parentNode.parentNode.rows.length;
				
				if (tableRow.nextSibling != null)
				{	
					//UnselectRows(parentTable,tableRow.nextSibling);			
					div.style.backgroundColor='';
																
					if (tableRow.nextSibling.firstChild.nextSibling != null)
					{
						if (tableRow.nextSibling.firstChild.nextSibling.firstChild.firstChild.nodeValue == null )								 				
						{
							tableRow.nextSibling.firstChild.firstChild.firstChild.focus();	
						}
						else
						{
							tableRow.nextSibling.firstChild.nextSibling.firstChild.focus();						
						}					
	
						tableRow.nextSibling.firstChild.style.backgroundColor='#ebebeb';												
					}
					else					
					{								   								
						tableRow.nextSibling.firstChild.firstChild.lastChild.focus();	
						tableRow.nextSibling.firstChild.firstChild.style.backgroundColor='#ebebeb';										
					}
				}
				else
				{						   	   
					if (parentTable.id == "" && subTable.id != TreeListControlTableInherited && TreeListControlTableInherited != null)
					{
					    
						div.style.backgroundColor='';						
						var tableBelow = document.getElementById(TreeListControlTableInherited);
						SelectRow(tableBelow,0);
					}	
					else if (parentTable.id == "" && subTable.id != TreeListControlTable)
					{					    
						div.style.backgroundColor='';						
						var tableBelow = document.getElementById(TreeListControl);
						SelectRow(tableBelow,0);
					}	
					else
					{						    						
						div.style.backgroundColor ='#ebebeb';
					}
				}								
			}
			else
			{
				div.style.backgroundColor ='#ebebeb';
			}			
											
		}
		
		
		

		function CNPN(tableCellId,subTableCellId,subTableId,event)
		{	
			AccessMode = true;
			Navigating = false;
			var ieX = event.keyCode;
			var nsX = event.which;
			var keyPressed;									
		
			if (ieX != "")
			{
				keyPressed = String.fromCharCode(ieX);
			}
			else
			{
				keyPressed = String.fromCharCode(nsX);
			}						

			var subTable = document.getElementById(subTableId);
						
						
			var subTableCell = document.getElementById(subTableCellId);				
			var tableRow = subTableCell.parentNode;
			var parentTable = FindParent(subTable,"TABLE");
			var parentParentTable = FindParent(parentTable,"TABLE");

			UnselectRows(subTable);	
			tableRow.style.backgroundColor='#ebebeb';											

			if (keyPressed == "\r" || ieX == 13 ||nsX == 13)
			{
				if (subTableCell.previousSibling != null)
				{	
					if (navigator.userAgent.toLowerCase().indexOf("gecko") < 0)
					{								
						subTableCell.previousSibling.firstChild.click();
					}
				}
			}				
			else if (keyPressed == "6")
			{				
					
				if (subTable.style.visibility.toUpperCase()== "HIDDEN")
				{																	
					NodeClicked(tableCellId,subTableCellId,subTableId,"keyPress");
					
					if (subTable.firstChild.firstChild.nextSibling.firstChild.nextSibling != null)
					{						
						subTable.firstChild.firstChild.nextSibling.firstChild.firstChild.firstChild.focus();
						subTable.firstChild.firstChild.nextSibling.firstChild.style.backgroundColor='#ebebeb';						
					}
					else
					{						
						subTable.firstChild.firstChild.nextSibling.firstChild.firstChild.lastChild.focus();
						subTable.firstChild.firstChild.nextSibling.firstChild.firstChild.style.backgroundColor='#ebebeb';										
					}					
				}
			}
			else if (keyPressed == "4")
			{																					
				if (subTable.style.visibility.toUpperCase()== "VISIBLE")
				{			
					tableRow.style.backgroundColor='';					
					NodeClicked(tableCellId,subTableCellId,subTableId,"keyPress");
				}		
				else
				{
			
					if (parentParentTable.id != "")//not main table
					{
					    
						CloseMenu(parentParentTable);
						if (FindParent(parentTable,"TD").previousSibling.firstChild.id == "")
						{
							FindParent(parentTable,"TD").previousSibling.firstChild.firstChild.focus();
						}
						else
						{
							parentTable.parentNode.previousSibling.firstChild.focus();							
						}
					}																				
				}				
			}
			else if (keyPressed == "8")
			{			
				
				CloseMenu(parentTable);						
						
				if (tableRow.previousSibling != null  && ((tableRow.previousSibling.rowIndex != 0)
				 ||  (tableRow.previousSibling.rowIndex == 0 && parentParentTable.id == "")) )
				{		
				
					UnselectRows(parentTable,tableRow.previousSibling);					
					tableRow.style.backgroundColor='';					
					if (tableRow.previousSibling.firstChild.nextSibling != null)
					{										 				
					
						if (tableRow.previousSibling.firstChild.nextSibling.firstChild.firstChild.nodeValue == null )								 				
						{
							tableRow.previousSibling.firstChild.firstChild.firstChild.focus();	
						}
						else
						{
							tableRow.previousSibling.firstChild.nextSibling.firstChild.focus();						
						}					

						tableRow.previousSibling.firstChild.style.backgroundColor='#ebebeb';							
					}
					else
					{
						tableRow.previousSibling.firstChild.firstChild.lastChild.focus();	
						tableRow.previousSibling.firstChild.style.backgroundColor='#ebebeb';						
					}
				}
				else
				{
				    var otherTable;
				    
					if (parentTable.id != TreeListControlTable && TreeListControlTable != null)
					{
					   otherTable = document.getElementById(TreeListControlTable);
					}
					
					if (parentTable.id != TreeListControlTableInherited && TreeListControlTable != null)
					{
					   otherTable = document.getElementById(TreeListControlTableInherited);					
					}
					
					if (otherTable)
					{					
						tableRow.style.backgroundColor='';						
						
						
						if (otherTable.rows.length == 0)
						{
							otherTable.style.backgroundColor='#ebebeb';							
						}
						else
						{
							SelectRow(otherTable,otherTable.rows.length-1);
						}
					}
				
				}
			}
			else if (keyPressed == "2")
			{
			
				CloseMenu(parentTable);
														
				var numRows = subTableCell.parentNode.parentNode.parentNode.rows.length;
				
				if (tableRow.nextSibling != null)
				{				
					UnselectRows(parentTable,tableRow.nextSibling);				
					tableRow.style.backgroundColor='';					
					if (tableRow.nextSibling.firstChild.nextSibling != null)
					{	
						if (tableRow.nextSibling.firstChild.nextSibling.firstChild.firstChild.nodeValue == null )								 				
						{
							tableRow.nextSibling.firstChild.firstChild.firstChild.focus();	
						}
						else
						{
							tableRow.nextSibling.firstChild.nextSibling.firstChild.focus();						
						}					
											
						tableRow.nextSibling.firstChild.style.backgroundColor='#ebebeb';												
					}
					else
					{
						tableRow.nextSibling.firstChild.firstChild.lastChild.focus();	
						tableRow.nextSibling.firstChild.firstChild.style.backgroundColor='#ebebeb';												
					}
				}
				else
				{
					if (parentTable.id != TreeListControlTableInherited && TreeListControlTableInherited != null)
					{
						tableRow.style.backgroundColor='';						
						var otherTable = document.getElementById(TreeListControlTableInherited);
						SelectRow(otherTable,0);
					}	
					else if (parentTable.id != TreeListControlTable && TreeListControlTable != null)
					{
						tableRow.style.backgroundColor='';						
						var otherTable = document.getElementById(TreeListControlTable);
						SelectRow(otherTable,0);
					}
											
				}
			}
			else
			{
				tableRow.style.backgroundColor='#ebebeb';	
			}			
		}
			

		function UnselectRows(topTable,row)				    
		{		
			if (topTable != null)
			{		
				for(var i=0; i < topTable.rows.length; i++)
				{							    		
					var tr = topTable.rows[i];
										
						if (tr.cells.length > 1)
						{						    
							if (tr.cells.length > 1
							        && tr.cells[1].firstChild != null
							        && tr.cells[1].firstChild.firstChild != null
							        && tr.cells[1].firstChild.firstChild.firstChild != null 
							        && tr.cells[1].firstChild.firstChild.firstChild.style != null  
							        && tr.cells[1].firstChild.firstChild.firstChild.style.visibility == "visible")
							{
								continue;
							}
						}
					
					var cell = tr.cells[0];
					
					if (tr.cells.length > 1) 
					{												   											
						ChangeBorderColorBack(cell);
						tr.getElementsByTagName('a')[0].style.color = '';								
					}
																															
					if (tr != row)
					{						    
						cell.style.backgroundColor = "";																					
					
						if (tr.cells[0].id == "")//if there is no span for blob image then its a div
						{										 	
							if (navigator.userAgent.toLowerCase().indexOf("gecko") == -1)
							{
								tr.cells[0].blur();
								tr.cells[0].style.color = "";
							}
						}
						else
						{
							///tr.style.backgroundColor = "";
							if (navigator.userAgent.toLowerCase().indexOf("gecko") == -1)
							{			
							    if (tr.cells[1].firstChild != null)			
							    {
								    tr.cells[1].firstChild.blur();																
								    if (tr.cells[1].firstChild.firstChild != null 
								    && tr.cells[1].firstChild.firstChild.firstChild != null)
								        tr.cells[1].firstChild.firstChild.firstChild.style.color = "";
								}
							}
						}
					}
				}			
			}			
		}
		
				
		function SelectHighlightedRow(topTable)
		{
			if (topTable != null)
			{
				for(var i=0; i < topTable.rows.length; i++)
				{
					var tr = topTable.rows[i];
					
					if (tr.firstChild.firstChild.id == "")//if there is no span for blob image then its a div
					{
						if (tr.firstChild.firstChild.style.backgroundColor != "")
						{
							tr.firstChild.firstChild.focus();					
						}					
					}
					else
					{
						if (tr.style.backgroundColor != "")
						{
							tr.firstChild.nextSibling.firstChild.focus();						
						}
					}
				}
			}				
		}
		
		function SelectRow(topTable,index)
		{
			if (topTable != null)
			{
				if (topTable.rows.length > index)
				{
					var tableRow = topTable.rows[index];
                    tableRow.cells[0].style.backgroundColor = "#eeeeee";
					tableRow.cells[0].firstChild.firstChild.focus();										
				}
			}	
		}
		
			
        var currentButt ="ctl00_ContentPlaceHolder1_btnSubmit"; //default
		
		function FormSubmit(Event)
		{			
		    //netscape and ie use properties of determining key press
			var ieX = Event.keyCode;
			var nsX = Event.which;

			var keyPressed;									
		
			if (ieX != "")
			{
				keyPressed = String.fromCharCode(ieX);
			}
			else
			{
				keyPressed = String.fromCharCode(nsX);
			}
			
			var topTable = document.getElementById(TreeListControlTable);
			
			var topTableInherited, topTableInherited2;

			if (TreeListControlTableInherited != null)			
				topTableInherited = document.getElementById(TreeListControlTableInherited);
			
			if (TreeListControlTableInherited2 != null)
			    topTableInherited2 = document.getElementById(TreeListControlTableInherited2);
						
			if (ieX == 27 || nsX == 27)
			{			    				
				if (topTable != null)					
					CloseMenu(topTable);	
				if (topTableInherited != null)	{
				    SelectHighlightedRow(topTableInherited);				
					CloseMenu(topTableInherited);														
			    }						
				if (topTableInherited2 != null)	{
				    SelectHighlightedRow(topTableInherited2);				
					CloseMenu(topTableInherited2);														
			    }									    
			}
											
			if ( (ieX == 27 || nsX == 27) && (Event.shiftKey || (Event.modifiers & Event.SHIFT_MASK) == Event.SHIFT_MASK))
			{							   
				if (topTableInherited != null  && (topTableInherited.getElementsByTagName("a")[0].disabled != true && topTableInherited.getElementsByTagName("a")[0].href != ""))
				{				
					SelectRow(topTableInherited,0);
				}
				if (topTableInherited2 != null  && (topTableInherited2.getElementsByTagName("a")[0].disabled != true && topTableInherited2.getElementsByTagName("a")[0].href != ""))
				{				
					SelectRow(topTableInherited2,0);
				}				
				else  if (topTable != null  && (topTable.getElementsByTagName("a")[0].disabled != true))
				{				    
					SelectRow(topTable,0);
				}					
			}										

			if (keyPressed == "\r" || ieX == 13 ||nsX == 13)
			{					    									        
				if (document.title.toLowerCase().indexOf("edit resource details") > -1 
				    || document.title.toLowerCase().indexOf("email folder") > -1
				    || currentButt == "saveNode")
				{
					return false;
				}
																					
			    var mainButton = null;			    
			    mainButton = document.getElementById(currentButt);
			    	    						     			    			   
			    if (mainButton == null)
			    {	
					mainButton = document.getElementById("UserSearch1_btnSubmit");
					
					if (mainButton == null)
					{										
						mainButton = document.getElementById("ucSearchControl_"+currentButt);			
					}
				}											
				
				if (mainButton != null)
				{		
					mainButton.focus();
																										
					if (navigator.userAgent.toLowerCase().indexOf("gecko") > -1	||(navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.platform.toLowerCase().indexOf("macppc") > -1))				  
					{
						mainButton.click();							
					}					
				}
				else							
				{
					var currentButt2 = document.getElementById("btnSubmit2");
					var currentButt3 = document.getElementById("btnAgree");

					if (currentButt3 != null) 
					{
						currentButt3.focus();
						currentButt3.click();
						return false;
						Event.returnValue = false;												
					}
					
					if (currentButt2 != null) 
					{
						currentButt2.focus();
						currentButt2.click();		
						return false;						
					}
										
					if (currentButt != "hs_btnSearch")
					{					    
						Event.returnValue = false;						
						return true;
					}									
				}
			}
			
		}
		
								
		function ProtectInputBoxes(obj)
		{

			//inputScreenShotObj = document.getElementById("uploadedScreenshotFile");	
			inputResourceFile = document.getElementById("uploadedResourceFile");					
			
			if (obj.selectedIndex == 1) 
			{				
				//inputScreenShotObj.disabled = false;
				inputResourceFile.disabled = false;
				document.getElementById("btnUpload").disabled = false;									
			}		
			else if (obj.selectedIndex == 2) 
			{	
				//inputScreenShotObj.disabled = "disabled";
				inputResourceFile.disabled = false;	
				document.getElementById("btnUpload").disabled = false;								
			}
			else
			{
				//inputScreenShotObj.disabled = true;
				inputResourceFile.disabled = true;	
				document.getElementById("btnUpload").disabled = true;		
			}
		}
							
		function SetFormModeAsReset()
		{
				reset = true;
		}
				
	    function DisplayError(errorMessage)
		{										
				var summary = document.getElementById("ValidationSummary");
				var ul = document.createElement("ul");
				var li = document.createElement("li");
				var textNode = document.createTextNode(errorMessage);
				ul.appendChild(li);
				li.appendChild(textNode);
				summary.appendChild(ul);		
				summary.style.visibility = "visible";		
		}


		function AutoActivateTree(categoryControlId,parentTableId)
		{		
		   	   
			IsMenu = false;											
			var tableCell = document.getElementById(categoryControlId+"_LINECELL");			
			//build up and add the heirarchical id to the childTable name			
			var childTableId = categoryControlId.split("-")[1];	
			
		    
			var childTable = document.getElementById(hierarchicalId+childTableId);
			var topTable = document.getElementById(parentTableId);			
			if (childTable != null) 
			{
				childTable = childTable.parentNode.parentNode.parentNode.parentNode;				
			}

			//get a handle to the correct table as written out by the user control			
			var tableArray = new Array();
			var index = 0;
			var parentTableFirstCell = tableCell;
			
			if (tableCell != null)
			{			
				parentTableFirstCell = tableCell.parentNode.parentNode.parentNode.rows[0].firstChild.nextSibling;
			}									
									
			//loop round in reverse form child table to upper most table opening tables and setting the + sign to -
			while (childTable != null)
			{										
				if (childTable == topTable)
				{									
					break;
				}
				else
				{																
					tableArray[index] = childTable;					
					var cell = childTable.parentNode.previousSibling;															
					OpenBranch(cell);
					childTable = childTable.parentNode.parentNode.parentNode.parentNode;		
				}
				index++;							
			}	
					
			for (var i = (tableArray.length -1); i >= 0; i--)
			{		
			    						
				MakeNodeVisible(tableArray[i]);								
			}
					
			IsMenu = true;					
		}


		function OpenBranch(cell)
		{
			
			if (cell != null)
			{
				var secondCell = cell.nextSibling;										
				var subtable = secondCell.firstChild;
				NodeClicked(cell.id,secondCell.id,subtable.id,"event");							
			}
		}


		function CheckEventHandler(checkBox)
		{		  
		  if (checkBox.checked)
		  {			
			checkBox.nextSibling.style.color = "Red";		  
			var allLabels = document.getElementsByTagName("label");		 
		  }	
		  else
		  {
			checkBox.nextSibling.style.color = "black";			
		  }
		}


		function GetCategories()
		{											
			var allCategoriesString = "";
			var TopTable =  document.getElementById(TreeListControlEditableTable);	
			var inputBoxArray = TopTable.getElementsByTagName("input");
									
			for (var i =0; i < inputBoxArray.length; i++)
			{		
				if (inputBoxArray[i].type.toLowerCase() == "checkbox")
				{									
					allCategoriesString = allCategoriesString + inputBoxArray[i].id+",";
				}				
			} 
			
			document.getElementById(CategoriesTextBox).value = allCategoriesString;		
		}
		
		var inEditMode = false;		
	
		function DisplayError(e)
		{
			alert("We are sorry an unexpected error has occurred.\n"+e);
			throw e;		
		}
	
		//check if InternetExplorer on mac osx
		function IsOnMac()
		{
			var result = false;
			if (navigator.platform.toLowerCase().indexOf("mac") > -1)		
			{
				result = true;
			}
			return result;
		}
	
			
		//defunct				
		function AddJavaScriptCapability(link)		
		{
			link.href = link.href+"&js=true";		
		}		
		
																
		var timeOutIds = new Array(175);
		var running = false;
		
				
		//stops any timeout commands for a particular menu level
		function ClearTimeOuts(level)
		{			
			if (level == null) return;
			for (var i = 0; i < timeOutIds.length; i++)
			{			
				if (timeOutIds[i] != null && (level == 42 || level == timeOutIds[i].level || timeOutIds[i].level == 42))
				{	   
					clearTimeout(timeOutIds[i].id);
					timeOutIds[i] = null;
					return;
				}
			}																
		}
		
		function ClearTimeOutsAllAbove(level)
		{			
			if (level == null) return;		
			for (var i = 0; i < timeOutIds.length; i++)
			{			
				if (timeOutIds[i] != null && (timeOutIds[i].level <= level || level == 42 || level == timeOutIds[i].level || timeOutIds[i].level == 42))
				{	   
					clearTimeout(timeOutIds[i].id);
					timeOutIds[i] = null;
					return;
				}
			}																			
		}
		
		
		function ClearTimeOutBelow(level)
		{			
			if (level == null) return;		
			for (var i = 0; i < timeOutIds.length; i++)
			{			
				if (timeOutIds[i] != null && (timeOutIds[i].level >= level || level == 42 || level == timeOutIds[i].level || timeOutIds[i].level == 42))
				{	   
					clearTimeout(timeOutIds[i].id);
					timeOutIds[i] = null;
					return;
				}
			}																			
		}		

		

//class declaration for TimeOutLevel type
function TimeOutLevel(level,id)
{
	this.level = level;
	this.id = id;			
}
		
		
		
		function AddTimeOut(level,id)
		{		  
			for (var i = 0; i < timeOutIds.length; i++)
			{
				if (timeOutIds[i] == null)
				{ 
					var t = new TimeOutLevel(level,id);
					timeOutIds[i] = t;
					return;
				}			
			}				
			clearTimeout(id);			
		}
		
			var TreeListControlTable;
			var TreeListControlTableInherited;
			var TreeListControlTableInherited2;

			var Navigating = false;
	
	function CloseOwnedCatMenu()
	{
	
		if (TreeListControlTable != null)
		{	
			var ownedMenuControl = document.getElementById(TreeListControlTable);
			if (ownedMenuControl != null )		
			CloseMenu(ownedMenuControl);			
		}			
	}
	
	function CloseInheritedCatMenu()
	{
		if (TreeListControlTableInherited != null)
		{	
			var inheritedMenuControl = document.getElementById(TreeListControlTableInherited);	
			if (inheritedMenuControl != null)		
			{
			    CloseMenu(inheritedMenuControl);							
			}
		}		
		
		if (TreeListControlTableInherited2 != null)
		{	
			var inheritedMenuControl = document.getElementById(TreeListControlTableInherited2);	
			if (inheritedMenuControl != null)		
			CloseMenu(inheritedMenuControl);							
		}	
	}
	
	function WaitAndClosedIfLoaded()
	{
	    try
	    {
	        if (loaded)
	            WaitAndClose();
	    }
	    catch(e){}
	}
	
	function WaitAndClose()
	{
		if (IsUnsupported()) return;
		
		ClearTimeOuts(42);
		Navigating=false;
		AddTimeOut(42,setTimeout('CloseAll()',0));	
	}
	
	function CAAL(obj)
	{

	}
	
	
	function CloseAll()
	{		
		if (loaded)
		{
			Navigating = false;
			CloseOwnedCatMenu();		
			CloseInheritedCatMenu();		
			Navigating = true;

			var table;
			if (TreeListControlTable != null)
			{
				table = document.getElementById(TreeListControlTable);
				UnselectRows(table);			
			}
			
			if (TreeListControlTableInherited != null)
			{
			    
				table = document.getElementById(TreeListControlTableInherited);			
				UnselectRows(table);			
			}
			
			if (TreeListControlTableInherited2 != null)
			{
				table = document.getElementById(TreeListControlTableInherited2);			
				UnselectRows(table);			
			}
		}
			
				
	}

	    function UnselectExpandedMenu(parentTable)
	    {	    
	       
			if (IsMenu == true && parentTable != null)
			{		               								                  
				var allTables = parentTable.getElementsByTagName("table"); //get all tables		
					
					
				for (var i = 0; i < allTables.length; i++) //for each table
				{
					//if a parent node
				    //if (allTables[i].parentNode.parentNode.parentNode.parentNode ==parentTable)
					{				
				        												
					    if (allTables[i].className == "expanded")
					    {					
					        
                            for (var x = 0; x < allTables[i].rows.length; x++)
                            {
                                var row = allTables[i].rows[x];
                                if (row.cells.length > 1) //parentrow
                                {
                                    var table = row.cells[1].getElementsByTagName("table")[0];
                                    if (table != null)
                                    {
				                        table.style.position = "absolute";				
				                        table.style.visibility = "hidden";	                                   
				                    }
                                }
                            
                            }                      
						    UnselectRows(allTables[i]);	 
						    UnselectExpandedMenu(allTables[i]);				   																		
					    }	
					}					 	
				}															
			}		    
	    }
	    
	
		function CloseMenuNotExpanded(id)
		{				    
            var parentTable = document.getElementById(id);
                          
			if (IsMenu == true)
			{	
			    if (parentTable != null)
			    {			
                    for (var x = 0; x < parentTable.rows.length; x++)					                  
                    {
                        var r = parentTable.rows[x];
                        if (r.cells.length > 1)
                        {
                           var node = r.cells[1].firstChild;
                        
                           if (node != null)
                           {                                                                                
                               if (node.nodeName.toLowerCase() == "div")
                               {
                                    node = node.firstChild.firstChild;                                      
                               }
                                                                                                                
                               MakeNodeInvisible(node);                                
                               CloseMenuNotExpanded(node.id);
                           }                           
                                                   
                           r.cells[0].getElementsByTagName("a")[0].style.color = '';
                           RemoveRowHighlight(r); 
                        }                    
                    }
                }                                              																	
			}												
		}	
	
	
	
		//Closes all nodes for a level -- closes the menu
		function CloseMenu(parentTable,subTable)
		{		   
			if (!Navigating && IsMenu == true)
			{					
			    UnselectExpandedMenu(parentTable);
				//RemoveRowHighlight(parentTable.parentNode.parentNode);
				var allTables = parentTable.getElementsByTagName("table"); //get all tables		
					
				for (var i = 0; i < allTables.length; i++) //for each table
				{																				
					//if a parent node
					if (allTables[i].parentNode.parentNode.parentNode.parentNode.parentNode == parentTable 
					    || allTables[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode == parentTable)
					{									
						var signElement = document.getElementById(allTables[i].id+"-SPAN");
						var cell =  document.getElementById(allTables[i].id+"_CELL");
						
						if (signElement != null)
						{								
							var tempSignObject = signElement.firstChild;
							
							if (tempSignObject != null)
							{
							    if (IsMenu == true)
							    {										 
								    tempSignObject.src = "/images/bulletblobf.gif";
							    }
							    else
							    {
							        if (IsForFolders)
								        tempSignObject.src = "/images/bulletblobffolder.png";
                                    else								        
								        tempSignObject.src = "/images/bulletblobfblue.gif";								        
							    }
							}
						}
                            
							CloseMenu(allTables[i]);//MARKED//
							
							CloseTree(allTables[i]);											
					}					 	
				}															
			}
												
		}


			function RemoveBranchLineTable(tableCell)
			{
				var table = document.getElementById("lineTb_"+tableCell.id);

				if (table!=null)
				{	
					var innerTable = table.getElementsByTagName("table")[0];	
																																		
					if (innerTable != null)
					{
						innerTable.style.visibility = "hidden";
						innerTable.style.position = "absolute";						
					}	
					
					table.style.visibility = "hidden";
					table.style.position = "absolute";
					tableCell.removeChild(table);																								
				}						
			}


			var timeoutId;
					


			var isOpen = false;

			function CloseMenuDelayed(parentTableid,rowIndex)
			{			
				var parentTable= document.getElementById(parentTableid);
				
                
				var row = parentTable.rows[rowIndex];				
				Navigating = false;							
				CloseMenu(parentTable);
				UnselectRows(parentTable,row);	
				Navigating = true;
				
			
									
			}
			
				function geckoGetRv()
				{
					
					if (navigator.product != 'Gecko')
					{
						return true;
					}
					
					var rvValue = 0;
					var ua      = navigator.userAgent.toLowerCase();
					var rvStart = ua.indexOf('rv:');
					
					if (rvStart == -1) //"like gecko"
					{
						var rvStart = ua.indexOf('safari/');
						var rv = ua.substring(rvStart+7);
						
						if (parseFloat(rv) < 125.0)
						{
							return false;
						}
						else
						{
							return true;
						}
					
					}
					else
					{
						var rvEnd   = ua.indexOf(')', rvStart);
						var rv      = ua.substring(rvStart+3, rvEnd);
						
						var rvParts = rv.split('.');
						var exp     = 1;

						for (var i = 0; i < rvParts.length; i++)
						{
							var val = parseInt(rvParts[i]);
							rvValue += val / exp;
							exp *= 100;
						}
						
						if (rvValue < 1.07) 
						{
							return false; 
						}
						else
						{
							return true;
						}
					}
				}			
						
			var flyOuts = true;
			
			function OpenMenuDelayed(subTableId,subTableCellId)
			{			    
				if (!geckoGetRv()){return; }
				
				var subTableCell = document.getElementById(subTableCellId);	
				
				var subTable = document.getElementById(subTableId);					
				var parentTable = subTable.parentNode;
				
				//iterating backwards to get the immediate parenttable
				while(parentTable.nodeName.toLowerCase() != "table")
				{
				    parentTable = parentTable.parentNode;				    
				}
				
				Navigating = false;
				
				CloseMenu(parentTable,subTable);				
                
                //checking to see if any of the parent nodes of the subtable are in the
                //expanded section (if it exists)
                var isInExpandedSection = false;
                
                var menuTableControl = subTable;
                
               //iterating backwards checking for expanded section via classname value
                while(menuTableControl.id != TreeListControlTable && menuTableControl.id != TreeListControlTableInherited && menuTableControl.id != TreeListControlTableInherited2)
                {
                    menuTableControl = menuTableControl.parentNode;
                    if (menuTableControl != null && menuTableControl.className != null && menuTableControl.className.toLowerCase() == "expanded")
                    {                        
                        isInExpandedSection = true;
                        break;
                    }
                }
                
			    if (!isInExpandedSection)			    
			    {			      		       
			        UnselectExpandedMenu(document.getElementById(TreeListControlTable));
			        UnselectExpandedMenu(document.getElementById(TreeListControlTableInherited));			        
			        UnselectExpandedMenu(document.getElementById(TreeListControlTableInherited2));			        
			    }										   			    			   						    			    					    													
										
				if (navigator.userAgent.toLowerCase().indexOf("msie") > -1)
				{
					subTableCell.style.position = "relative";	
					subTableCell.style.left = "-30px";																				
				}
				else
				{					
					subTableCell.style.position = "absolute";																						
					subTableCell.style.left = "110px";																													
				}	
								
				subTableCell.style.zIndex = 200000;					
				
				if (subTableCell.firstChild != null && subTableCell.firstChild.nodeName != "DIV")
				{				    
				    var div2 = document.createElement("div");
				    var div = document.createElement("div");	
				    				    			
				    if (navigator.userAgent.toLowerCase().indexOf("msie") == -1)
				    {				    			    			    
				        div.style.top = "-20";
				    }
				    				    
				    div.appendChild(div2);
				    div2.appendChild(subTable);
				    subTableCell.appendChild(div);
				    div2.style.position = "relative";
					div2.style.left = "-2";
				    div2.style.top = "-2";
				    
                    div2.style.backgroundColor = "#C5C5C5";				    

				    div.style.position = "absolute";
				    div.style.backgroundColor = "gray";
				    //div.style.backgroundImageUrl = "images/10Alpha.png";
				    subTable.style.position = "relative";
				    subTable.style.left = "-2";
				    subTable.style.top = "-2";
				    subTable.style.borderLeft = "#A6C3E1 solid 1px";				    
				    
				}
				
		        
							
				Navigating = true;	
				
				if (!IsForFolders)	
				    HighlightRow(subTableCell.previousSibling);
				    
							
				MakeNodeVisible(subTable);
					
				if (!flyOuts)
				    subTableCell.previousSibling.appendChild(subTable);																										
	
				UnselectRows(subTable);
				UnselectRows(parentTable,subTableCell.previousSibling);		
																																								
			}	
			
			function IsUnsupported()
			{
				if (navigator.userAgent.toLowerCase().indexOf("msie") > -1 && IsOnMac() && navigator.userAgent.toLowerCase().indexOf("opera") < 0)
				{
					return true;
				}	
				
				return false;		
			}
			
			var openTableId;
			var AccessMode = false;
			var suppress = false;
			

			
			//interface method
			function NodeClicked(tableCellId,subTableCellId,subTableId,ev,Event)
			{		
				try				
				{ 								    						
						if (inEditMode)//to cater for opera buggy behaviour
						{
							alert("Please finish your edit operation.");
							return;
						}																																													
						var parentTable;		
						
						if (tableCellId != null && tableCellId != "")
						{
							tableCell = document.getElementById(tableCellId);
						}
												
						var subTableCell = document.getElementById(subTableCellId);	
																													
						var subTable = document.getElementById(subTableId);
						
				
						var signObject = document.getElementById(subTableId+"-SPAN");
						
						if (signObject != null)																																															
						   signObject = document.getElementById(subTableId+"-SPAN").firstChild;							
							if (IsMenu 
							|| (subTable.style.visibility.toUpperCase()== "HIDDEN"
							 || subTable.style.visibility == null))
							{									
								parentTable = subTable.parentNode.parentNode.parentNode.parentNode;
																	
								if (IsMenu)
							    {									    
									if (IsUnsupported())
									{
										return;
									}							    							    
							     
									if (ev != null) {//open it with no delay					    
										OpenMenuDelayed(subTable.id,subTableCellId);
										}
									else {												    			
		   					           if (parentTable.nodeName.toLowerCase() == "tbody")
		   					                parentTable = parentTable.parentNode;
   					            													
										var level = subTable.id.split("_").length - 4;
										
										if (parentTable.id == TreeListControlTable || parentTable.id == TreeListControlTableInherited || parentTable.id == TreeListControlTableInherited2) {
											level = 1;
										}
																									
										ClearTimeOuts(level);	
										
										AddTimeOut(level,setTimeout("OpenMenuDelayed('" + subTable.id + "','" + subTableCellId + "')",250));																																											
									}
								}	
								else {											
									SwitchSign(signObject);	
									subTableCell.style.position = "relative";
															
									MakeNodeVisible(subTable);																																
                                    subTableCell.appendChild(subTable);//fixed safari											                           
									OpenTree(subTable);	
                                    AdjustTablePosition(subTable,tableCell);						
								}																	
							}
							else {																		
								if (ev == null) {																									
									if (!IsMenu)
									{																	
										SwitchSign(signObject);																							
										//subTableCell.style.position = "absolute";																	  															
										CloseTree(subTable);									
									}

																											
									if (!IsMenu)
									{
										for (var i =0; i < subTable.rows.length; i++)
										{
											var tableCell = subTable.rows[i].firstChild;
											if (tableCell.style != null)
											{
											    tableCell.style.borderLeftWidth = "";
											    tableCell.style.borderLeftColor = "";
											    tableCell.style.borderLeftStyle = "";
											}											
										}									

										if (navigator.userAgent.toLowerCase().indexOf("gecko") < 0)
										{											
											subTableCell.style.height = "20px";							
										}
										else
										{
											subTableCell.style.height = "19px";							
										}
									}
								}																					
							}																							
				 }
				 catch(e)
				 {
					DisplayError(e);
				 }				   				   				   	
			}
			
								
			function ClickNode(nodeId)
			{
			    if (document.getElementById(nodeId) != null)
			        document.getElementById(nodeId).click();
			}
		
							
			function AdjustTablePosition(subTable,tableC)
			{											
				if (tableC != null && !inEditMode)
				{
					tableC.appendChild(subTable);
			    }
				
				var level = subTable.id.split("_").length - 1;														
			}		
			

			function SwitchSign(signObject)
			{				
			    if (signObject != null)
			    {
				    if (signObject.src.indexOf("bulletblobf") > -1)
				    {
					    if (IsMenu)
					    {
						    signObject.src = "/images/bulletblobb.gif";					
					    }
					    else
					    {
					        if (IsForFolders)
					        {   					            
						        signObject.src = "/images/bulletblobbfolder.png";	
						        ChangeFolderIcons(signObject); 			
						    }
						    else
						        signObject.src = "/images/bulletblobbblue.gif";			
					    }
				    }
				    else
				    {
					    if (IsMenu)
					    {
						    signObject.src = "/images/bulletblobf.gif";						
					    }
					    else
					    {
					        if (IsForFolders)	
					        {						            		        
						        signObject.src = "/images/bulletblobffolder.png";					       
						        ChangeFolderIcons(signObject); 
						    }
						    else
						        signObject.src = "/images/bulletblobfblue.gif";							    
					    }				
				    }
				}
			}

			function OpenTree(table)		
			{																																													
						var x = table.getElementsByTagName("table"); //all child tables																															
						for (var i = 0; i < x.length; i++)						
						{			
							var show = false;									
							var currentTable = x[i];
							var anc = document.getElementById(currentTable.id+"-ANCHOR");																																																			
							//if the table has children i.e hasn't just been created
							if (document.getElementById(currentTable.id+"-SPAN") != null)
							{																						
								var pictureSrc = document.getElementById(currentTable.id+"-SPAN").firstChild.src;																														
								if (pictureSrc.indexOf("bulletblobb") > -1)//may have been visible before
								{																					
									//REVERSE UP THE TREE FOR EACH NODE
									//TABLE AS PARENT NODES SHOULD HAVE BEEN ALREADY MADE VISIBLE 
									//LOGIC...
									//IF ANY PARENT TABLES ARE INVISIBLE DON'T SHOW			
									//IF ALL PARENT TABLES ARE VISIBLE THEN SHOW									
									var parentTable = currentTable.parentNode.parentNode.parentNode.parentNode;												
									while (parentTable != null)
									{							
                                        //PARENT IS VISIBLE SO CARRY ON												
										if (parentTable.style.visibility.toUpperCase() == "VISIBLE")
									    {															        
									       parentTable.style.position = "relative";													                           //check if reached the table user clicked on (passed in)				
										   if (parentTable == table)
										   {
                                                //IF REACHED THE TOP THEN BREAK OUT AND SET FLAG TO TRUE			
											    show = true;	
											    break;							
										   }
										   else //ELSE IF NOT YET REACHED THE TOP CARRY ON
										   {
										      parentTable = parentTable.parentNode.parentNode.parentNode.parentNode;
										   }
										}
										else //IF ANY PARENT ARE NOT VISIBLE THEN DON'T SHOW THE CHILD
										{
										    break; 
										}										
									}
									
									if (show == true) 
									{ 
									    var tableCell = document.getElementById(currentTable.id+"_CELL");
										MakeNodeVisible(currentTable); 
									}	
								}
							}																						
						}															               	               
			}	
																		
			function CloseTree(theTable)
			{		

				
					MakeNodeInvisible(theTable);					

					var x = theTable.getElementsByTagName("table");	
									
					for (var i = 0; i < x.length; i++)
					{						
						MakeNodeInvisible(x[i]);																																																																																																								
					}						
				
			}						
							
			function MakeNodeVisible(table)
			{			
			     //check that not already selected
                 if (document.getElementById(table.id+"_CELL") != null 
                 && document.getElementById(table.id+"_CELL").previousSibling.className.toLowerCase() == "leftareasection")
                 {
                     return;
                 }
			
				if (!IsMenu)
				{
					table.style.position = "relative";													
				}
				else
				{	
				    if (!flyOuts)
				    {				
					    table.style.position = "relative";
					}
					else
					{
					    table.style.position = "relative";
					}
				}
				table.style.visibility = "visible";																						
			}
			
			function MakeNodeInvisible(table)
			{
			     //check not already selected
                 if (document.getElementById(table.id+"_CELL") != null 
                 && document.getElementById(table.id+"_CELL").previousSibling.className.toLowerCase() == "leftareasection")
                 {
                     return;
                 }
                 			
				table.style.position = "absolute";				
				table.style.visibility = "hidden";														
			}							
			
			var currentMenu;
			
			
			//function to check to see if the table passed in is the main menu table. 
			//if it is an another menu is present then close it
			//means that by opening owned menu it closes the inherited menu and vice versa
			function CheckCloseMenu(parentTable)
			{							
			    //if  the main or beginning table
				if (parentTable.id == TreeListControlTable || parentTable.id == TreeListControlTableInherited
				 || parentTable.id == TreeListControlTableInherited2)	
				{									
				    //close the other menu 
					if (currentMenu == null || currentMenu != parentTable.id)
					{																		
						currentMenu = parentTable.id;
																
						if (parentTable.id == TreeListControlTable)
						{									
							if (TreeListControlTableInherited != null)
							{
								parentTable = document.getElementById(TreeListControlTableInherited);								
								Navigating = false								
								CloseMenu(parentTable);
								UnselectRows(parentTable);								
								Navigating = true;
							}
							
							if (TreeListControlTableInherited2 != null)
							{
								parentTable = document.getElementById(TreeListControlTableInherited2);								
								Navigating = false								
								CloseMenu(parentTable);
								UnselectRows(parentTable);								
								Navigating = true;
							}							
														
						}
						
						if (parentTable.id == TreeListControlTableInherited)
						{
							if (TreeListControlTable != null)
							{
								parentTable = document.getElementById(TreeListControlTable);								
							
								Navigating = false;	
								CloseMenu(parentTable);	
								UnselectRows(parentTable);																								
								Navigating = true;
							}	
							
							if (TreeListControlTableInherited2 != null)
							{
								parentTable = document.getElementById(TreeListControlTableInherited2);								
								Navigating = false								
								CloseMenu(parentTable);
								UnselectRows(parentTable);								
								Navigating = true;
							}															
						}
						
						
						if (parentTable.id == TreeListControlTableInherited2)
						{
							if (TreeListControlTable != null)
							{
								parentTable = document.getElementById(TreeListControlTable);								
							
								Navigating = false;	
								CloseMenu(parentTable);	
								UnselectRows(parentTable);																								
								Navigating = true;
							}	
							
							if (TreeListControlTableInherited != null)
							{
								parentTable = document.getElementById(TreeListControlTableInherited);								
								Navigating = false								
								CloseMenu(parentTable);
								UnselectRows(parentTable);								
								Navigating = true;
							}						
						
						}
					}

				}
			}
			
			          						
			function CMC(obj)
			{			
				if (IsUnsupported()) return;
                /*
                var elms = document.forms[0].elements;
				for(i=0;i<elms.length-1;i++)
				{
				    if(elms[i].type == "text");
				        elms[i].blur();
				}																			
				
				var input = document.getElementById("ctl100_ContentPlaceHolder1_cmbSearchText_Input");
				if(input != null)
				    input.blur();
				*/    
				var div;
				
				var subTable = obj.parentNode.parentNode.parentNode.parentNode;		
																																				
				if (subTable.id == null || subTable.id == "")
				{
					subTable = subTable.parentNode;
				}
						
	    		var level = subTable.id.split("_").length - 4;
	    			    				    	
				ClearTimeOuts(level+1);	//clear timeout queues for the level below	
							                        
				      			
				CheckCloseMenu(subTable);					
				
			    if (subTable.className.toLowerCase() == "expanded" || obj.parentNode.parentNode.className.toLowerCase() == "expanded")
			    {            	          		       
			       AddTimeOut(level,setTimeout("CloseMenuNotExpanded('"+TreeListControlTable +"')",250));				       
			       AddTimeOut(level,setTimeout("CloseMenuNotExpanded('"+TreeListControlTableInherited +"')",250));				       
			       AddTimeOut(level,setTimeout("CloseMenuNotExpanded('"+TreeListControlTableInherited2 + "')",250));
			    }
			    else
			    {
			        ClearTimeOuts(level);
			    }				
			    									
				if (obj.parentNode.parentNode.cells)//child row div passed in
				{								   	 														
					div = obj.parentNode;																
					var row  = obj.parentNode.parentNode;										
                    //all level below must close if this is a child	
					AddTimeOut(level+1,setTimeout("CloseMenuDelayed('" + div.parentNode.parentNode.parentNode.id + "','"+row.rowIndex+"')",250));														 
				}
				else//parent row anchor passed in
				{									
					div = obj.parentNode.parentNode;																														
				}							
					
				HighlightRow(div);																									
			}
			
			var selectedAnchorId = "";
			
			function HighlightRow(obj)
			{			
			    
			    var parentBackColor = '#CFDFEE';
			    
			    if (document.styleSheets)
			    {
		    	    if (document.styleSheets[0].cssRules)
				    {
					    rules = document.styleSheets[0].cssRules
				    }
				    else if (document.styleSheets[0].rules)
				    {										
					    rules = document.styleSheets[0].rules;
				    }
				    
				    for (var i = 0; i < rules.length; i++)
				    {				
					    if (rules[i].selectorText.toLowerCase() == ".jscriptclass")
					    {
						    parentBackColor = rules[i].style.backgroundColor;												
					    }					
				    }					    			
			    }			
							
				
				var anchor;
                var isParentNode = false;
                								
				if (obj.parentNode.cells.length == 1)
				{                  			
					obj = obj.firstChild;	
					anchor =  obj.firstChild;													
				}
				else
				{   
				    isParentNode = true;
				    anchor = obj.firstChild.firstChild;
				}
				
                //anchor.style.color = 'red';
                selectedAnchorId = anchor.id;
                
           
				if (obj.className.toLowerCase() == "leftareasection" || obj.className.toLowerCase() == "leftareacurrent" ||
				    obj.parentNode.parentNode.className.toLowerCase() == "leftareasection" ||  obj.parentNode.parentNode.className.toLowerCase() == "leftareacurrent" )
				{				   
				    return;
				}
						
								
			    if (isParentNode)						
			    {			        
				    obj.style.backgroundColor=parentBackColor; 															
				}
				else
				{
				    obj.style.backgroundColor='#F4F7FE';    
                    obj.style.borderTop= '1px #cccccc solid';
                    obj.style.borderBottom =  '1px #cccccc solid';				    				    
				}
			}
			
			function CMB(obj)
			{		
				if (IsUnsupported()) return;			
				
				/*
				var elms = document.forms[0].elements;
				for(i=0;i<elms.length-1;i++)
				{
				    if(elms[i].type == "text");
				        elms[i].blur();
				}
				if($find("ctl00_ContentPlaceHolder1_cmbSearchText") != null)
				    $find("ctl00_ContentPlaceHolder1_cmbSearchText").hideDropDown();

				
                var input = document.getElementById("ctl100_ContentPlaceHolder1_cmbSearchText_Input");
				if(input != null)
				    input.blur();
				*/    
				var obj;
				
				var div;					
					
				var subTable = obj.parentNode.parentNode.parentNode.parentNode.parentNode;               
				var level = subTable.id.split("_").length - 5;
		 										
				if (obj.parentNode.parentNode.cells)//child row div passed in
				{	
					obj = obj.parentNode.parentNode;					
					div = obj.cells[0];																																						
				}
				else//parent row anchor passed in
				{				    
					obj = obj.parentNode.parentNode.parentNode;											
					div = obj.cells[0];					
				}													

                
				if (obj.cells.length > 1)//parent row
				{				    
					if (obj.nodeName.toUpperCase() == "TR" && obj.cells.length > 1 
					    && obj.cells[1].firstChild != null 
					    && obj.cells[1].firstChild.firstChild != null
					    && obj.cells[1].firstChild.firstChild.firstChild != null
					    && obj.cells[1].firstChild.firstChild.firstChild.style != null 
					    && obj.cells[1].firstChild.firstChild.firstChild.style.visibility == "visible")
					{					
						ChangeBorderColorBack(div);										
						return;
					}
				}
            
				ChangeColorBack(div,obj);				
			
				if (IsOnMac() && navigator.userAgent.toLowerCase().indexOf("msie") > -1)
				{
					RemoveRowHighlight(obj);
				}
				else
				{						
					setTimeout("ICMB('" + obj.getElementsByTagName("a")[0].id +  "')",0);							
				}
			}
			
			function ICMB(id)
			{	
				
				var anchor = document.getElementById(id);
				
				//if already selected then don't remove highlight applies to parent row
				var temp = anchor.parentNode.parentNode.style.borderColor;

                
				if (id == selectedAnchorId || anchor.parentNode.style.borderColor == '#CFDFEE'  ||
				anchor.parentNode.parentNode.style.borderColor == '#CFDFEE' || 
					anchor.parentNode.parentNode.style.borderColor == 'rgb(207, 223, 238) rgb(207, 223, 238) rgb(207, 223, 238) rgb(207, 223, 238)')
				{ 
					return;						
				}
				
				
				var row = anchor.parentNode.parentNode;
				if (row.nodeName.toUpperCase() == "TD")
				{
				    row = row.parentNode;
				}

				var table = null;
				
				if (row.cells.length > 1 && row.cells[1].firstChild != null)
				{									
					table = row.cells[1].firstChild.firstChild;
					
				}					
					
				
				if (table == null ||( table.style != null && table.style.visibility != "visible"))
				{
				 
					RemoveRowHighlight(row);
				}			

			}


			function ChangeColorBack(cell,row)
			{
			  
				if (cell.className.toLowerCase() == "leftareasection" || cell.className.toLowerCase() == "leftareacurrent")
				{
				   return
				}			

			    cell.style.backgroundColor = '';	
				//cell.style.borderColor = "";
				//cell.style.color = "";								
										
                										
										    	                													
				row.getElementsByTagName('a')[0].style.color = '';																																		
				
				
				ChangeBorderColorBack(cell);			
			}
	

			function ChangeBorderColorBack(cell)
			{
                cell.style.borderColor = "";
				obj = cell.firstChild.firstChild;
                
                if (obj != null && obj.style != null)
				    obj.style.borderColor = "";							
			
				selectedAnchorId = -1;
			}
			
		
			function RemoveRowHighlight(row)
			{	        
			    
				//if already selected dont remove highlight applies to child row				
				if (row.cells[0].firstChild.id == selectedAnchorId || row.cells[0].firstChild.style.borderColor == '#CFDFEE' || 
				  row.cells[0].firstChild.style.borderColor == 	'rgb(207, 223, 238) rgb(207, 223, 238) rgb(207, 223, 238) rgb(207, 223, 238)') return;

				//GET PARENT CELL										
				var cell = row.cells[0].firstChild;
				cell.style.backgroundColor= '';
				cell.style.borderColor = ""
				cell.style.borderTopColor = "";
				cell.style.borderBottomColor = "";
				row.cells[0].style.backgroundColor = '';
				row.style.backgroundColor = '';	
				
				  
  																																		
			}
			
			var rowArray = new Array(50);