 
   var TreeImgPath = 'images/'; // Path to images for the tree
   var TreeLastURL='';
   var TreeShowNumbers = true;	 //Show or hide the tree numbers
   var TreeBackColor = "#FFFFFF"; // background color of the HTML table the tree resides in
   var TreeNormalColor = "#000000";   // color of unselected nodes
   var TreeCurrentColor = "#507FC7"; // color of selected node
   var TreeTitleColor = "#507FC7";
   var TreeLevel = 0;
   var TreeTextSizes = new Array(1, 0.8, 0.7, 0.9, 0.8);	 
   var TreeFontTitle = "Helvetica,Arial";  // font type of tree nodes
   var TreeFontLines = "Helvetica,Arial";  // font type of tree nodes
   var TreeLastIndex=0;  // Last tree node selected array index

  // Preload our tree images

    var imgMinus = new Image();		 imgMinus.src = TreeImgPath + 'ArrowDown.jpg';
   var imgPlus = new Image();			 imgPlus.src = TreeImgPath + 'ArrowRight.jpg';
   var imgLeaf = new Image();		 imgLeaf.src = TreeImgPath + 'ArrowLeaf.gif';

  // You'll want to implement your owner browser checking functions.  This example is
  // far from adequate for production use.

   var fIsIE=true;
    if  (navigator.appName.toUpperCase() == 'NETSCAPE')  {fIsIE=false;}
	  

function TreeDisplayNode(TreeNumber,currentIsExpanded) 
{

 
  
   var sH = '';
   var TreeNumArray = TreeNumber.split(".");
   var CurrentNodeLevel = TreeNumArray.length-1;
   var scrollY=0;
   var addScroll=true;
   var theHref="";
   var sParentReloadTreeID="noreload";
   var oInputArray = new Array();

  // Before advancing to the next node, let's see if we need to validate the current page in the IFRAME.

   if (ValidateChildForm() == false) 	{  return false; }
 
  
  // Use a JavaScript array for our string concatenation because it will drastically increase speed.

  oInputArray.push("<html>\n<head>\n<title>My Tree Title</title>\n</head>\n<body bgcolor=\"#FFFFFF\">\n<table border=0 cellspacing=1 cellpadding=0>\n");

 // Don't allow the user to select a node while a page is being loaded in the IFRAME.

   try	{ if (GetFormValue("ChildLoaded")!='1') {   return false; }}
   catch (exception) {  }
	
   try
		{
   

         // Set the font sizes based on whether we are using IE or NS.

                if (fIsIE==true) { var mdi=TreeTextSizes[1], sml=TreeTextSizes[2]; }
                else { var mdi=TreeTextSizes[3], sml=TreeTextSizes[4]; }

   // Begin reconstructing the tree

	for (i=0; i<TreeNodes.length; i++) 
		{
		
		thisNumber = TreeNodes[i][0];
		
		//  Are we on the current node?

		var isTreeNumber = (thisNumber == TreeNumber);
		
		if (isTreeNumber) theHref=TreeNodes[i][2];
		
		var thisNumArray = thisNumber.split(".");
		var thisLevel = thisNumArray.length-1;
		var toDisplay = true;

		if (thisLevel > 0)
		{
			for (j=0; j<thisLevel; j++) 
			{
				toDisplay = (j>CurrentNodeLevel)?false:toDisplay && (thisNumArray[j] == TreeNumArray[j]);
			}
		}
		
		thisIsExpanded = toDisplay && (thisNumArray[thisLevel] == TreeNumArray[thisLevel])

		if (currentIsExpanded)
		{
			toDisplay = toDisplay && (thisLevel<=CurrentNodeLevel);
			if (isTreeNumber) thisIsExpanded = false;
		}
		
		if (toDisplay) 
		{
			if (i!=0) 	
			 {
				
				if (addScroll) scrollY+=((thisLevel<2)?mdi:sml)*25;

				if (isTreeNumber) addScroll=false;
				
				var isLeaf = (i==TreeNodes.length-1) || (thisLevel >= TreeNodes[i+1][0].split(".").length-1);
			 
		    		img = (isLeaf)?"ArrowLeaf.gif":(thisIsExpanded)?"ArrowDown.jpg":"ArrowRight.jpg";
				
				 
				  oInputArray.push("<tr>");
				for (k=1; k<=thisLevel; k++) {   oInputArray.push("<td>&nbsp;</td>"); }

               if (isTreeNumber) { TreeLastIndex = i; }
 
         
                oInputArray.push("<td valign=top><a href=#  onclick=\"TreeDisplayNode('" + thisNumber + "'," + thisIsExpanded + ");\"><img src=images/" + img + "  border=0></a></td> <td colspan=" + (nCols-thisLevel) + "><a href=#  onclick=\"TreeDisplayNode('" + thisNumber + "'," + thisIsExpanded + ")\" style=\"font-family: " + TreeFontLines + ";" + ((thisLevel<=TreeLevel)?"font-weight:bold":"") +  "; font-size:" + ((thisLevel<=TreeLevel)?mdi:sml) + "em; color: " + ((isTreeNumber)?TreeCurrentColor:TreeNormalColor) + "; text-decoration:none\">" + ((TreeShowNumbers)?(thisNumber+" "):"") + TreeNodes[i][1] + "</a></td></tr>");

			}
		}
	}

	  oInputArray.push("</table>\n</body></html>");
	  sH = oInputArray.join(' ');
 
  // sH now contains an HTML table representing the contents of the tree that should be visible.  We'll repopulate the DIV layer with our tree.

	document.getElementById("divTree").innerHTML = sH;
   
	    if (theHref != "") 
			 {
			 
		         if (TreeLastURL !="") 
					 {   

                         // If page associated with 100.2 changed the structure of the tree (ParentReload would have been set by the 100_2 IFRAME page), then set
						 // our default.asp page to reload after 100_2 has been submitted.
						 // If we have other tree id's that could alter the structure of the tree, we'd want to include a case for that here as well.

                         if ((TreeNumber == '100.2') && (document.frmSubmit.ParentReload.value == '1')) {  sParentReloadTreeID='100_2'; }				   
     			      
					    //  Before submitting the current IFRAME page to itself, we'll set the tree to an Unloaded state to prevent clicks on nodes before
						//  the IFRAME page has finished loading.

						 if (fIsIE==true) 
						      {  SetChildUnLoaded(); document.ifWorkspace.frmSubmit.NextURL.value=theHref;  document.ifWorkspace.frmSubmit.submit(); }						     
							else
						     {   SetChildUnLoaded(); window.frames['ifWorkspace'].document.frmSubmit.NextURL.value=theHref;  window.frames['ifWorkspace'].document.frmSubmit.submit(); }
		 
		                  //  Do we need to reload the default.asp page because of tree structure change?

						   if (sParentReloadTreeID!="noreload") 
							   {
						
							      // If IE, simply run a TimeOut waiting for the IFRAME page to finish processing, then reload default.asp.  Our ASP code should have
								  // a method to take the querystring value "nexttreeid" and land on a specific tree node when the page loads.

							    	if (CheckIsIE() == true)
									{
								     	WaitForChildLoad();
										document.location.href="default.asp?nexttreeid=" + sParentReloadTreeID;
									}
									else
									{
							            // Netscape is screwy when it comes to page reloads.  The code below is a work around to literally force Netscape
										// to not use what is in memory or disk cache when we reload default.asp.

								        WaitForChildLoad();
										window.location.reload( true );
									    window.location.reload( true );
										var randomnumber=Math.floor(Math.random()*10000)
										document.location.href="default.asp?nexttreeid=" + sParentReloadTreeID + "&ns=" + randomnumber;
									 
									}
								}
					 }
			  }
		 
		}
	catch (exception) 
		{ 
		
 		    if (exception.description == null) { alert("Exception: " + exception.message); }
            else {  alert("Exception: " + exception.description); }
		}
   TreeLastURL = theHref;
}




function WaitForChildLoad()  
{
     // Used to wait until the IFRAME page has finished processing before performing the next task.
	 oTimeOut = window.setTimeout("CheckChildLoaded()","250");
}


function CheckChildLoaded()
{
    try
	  {		 
	     if (GetFormValue("ChildLoaded")==1) { window.clearTimeout(oTimeOut); return true; }
	     else                                                      {  return false; }  
      }
	 catch (exception)  { alert("CheckChildLoaded: " + exception.description); return false; }
}



function GetNextTreeID()
{

 //  Many times, we'll want our IFRAME page to take us forward and backward through the tree.
 //  This function looks are the current tree node and advances to the next item in our tree array.

       var lCurIndex=0;
	   var sNextTreeID="0";
	   var currentArray;
	   var TreeNumArray;

	   lCurIndex = TreeLastIndex + 1;

	   for (lCurIndex = TreeLastIndex + 1;lCurIndex<TreeNodes.length;lCurIndex++)
     	{ 
		  
           currentArray = new String(TreeNodes[lCurIndex]);
           TreeNumArray = currentArray.split(",");
 
		   sNextTreeID = TreeNumArray[0];
		   lCurIndex = TreeNodes.length + 1;
		   return TreeDisplayNode(sNextTreeID,false);
	 
		}

		lCurIndex += TreeLastIndex + 1;
		
		if (lCurIndex < TreeNodes.length){ lCurIndex = 0; }
        
	    currentArray = new String(TreeNodes[lCurIndex]);
        TreeNumArray = currentArray.split(",");
        sNextTreeID = TreeNumArray[0];	 
		return TreeDisplayNode(sNextTreeID,false);
}
 

function GetPrevTreeID()
{

//  Many times, we'll want our IFRAME page to take us forward and backward through the tree.
 //  This function looks are the current tree node and advances to the previous item in our tree array.

       var lCurIndex=0;
	   var sNextTreeID="0";
	   var currentArray;
	   var TreeNumArray;

    if (TreeLastIndex == 0) { return true;} 

	lCurIndex = TreeLastIndex - 1;
 
    currentArray = new String(TreeNodes[lCurIndex]);
    TreeNumArray = currentArray.split(",");
    sNextTreeID = TreeNumArray[0];	 
    return TreeDisplayNode(sNextTreeID,false);
}


// Called in the IFRAME pages to tell default.asp that our IFRAME page has loaded.

function SetChildLoaded()      {  SetFormValue("ChildLoaded","1"); }

// Called via default.asp just before processing an IFRAME page.  

function SetChildUnLoaded() {  SetFormValue("ChildLoaded","0"); }

// Called in the IFRAME page if it recognized a change in tree structure and a
// need to reload default.asp

function SetParentReload()   { SetFormValue("ParentReload","1"); }



 
function GetFormValue(sFieldName)
{
  if (fIsIE == true) { return parent.frmSubmit[sFieldName].value; }
  else  { return document.frmSubmit[sFieldName].value; }
}

 function SetFormValue(sFieldName,sVal)
{
  if (fIsIE == true) { parent.frmSubmit[sFieldName].value = sVal; }
  else  { document.frmSubmit[sFieldName].value = sVal; }
}

  
//-----------------------------------------------------------------  Tree Validate Form Definitions ----------------------------------------------------------------



// ValidateChildForm() is a master function that calls ValidateForm() in IFRAME pages wherever designated.
// In our example, we only need to run ValidateForm() in the page p100_3.asp.  This allows us to prevent
// users from advancing to the next node after having entered invalid data.


function ValidateChildForm()
{

    var sCurTreeID='';
	var fValidate=false;
	
   try
	{

	     if (fIsIE==true)  { sCurTreeID = document.ifWorkspace.frmSubmit.CurTreeID.value; }
         else { sCurTreeID = window.frames['ifWorkspace'].document.frmSubmit.CurTreeID.value; }

	  switch (sCurTreeID)
          { 
		        case 'stop'    :  return false; break;
                case '100_3' :  fValidate = true;  break;               
                default:    break;    				                            
          }

	  if (fValidate == true)
		{
           if (fIsIE==true)  { return document.ifWorkspace.ValidateForm(); }
            else { return window.frames['ifWorkspace'].ValidateForm(); }
		}
         
	}
  catch (exception){ } 

	return true;

}
