var Ccounter = 0;
var Mcounter = 1;
var firstNode = 0;
var lastNode = 0;

function openTree(caption)
{
	document.write('<font face="Tahoma,Arial,Helvetica,Sans Serif" size="2">');
	document.write('<div style="margin-left:0; display:;">');
	document.write('<table cellpadding=0 cellspacing=0><tr>');
	document.write('<td valign=top><img src = "Products/Tree/ftv2plastnode.gif" ID=MI-1 onClick="expandCollapseClick();">');
	document.write('<img src = "/Products/Tree/folderc2.gif"></td>');
	document.write('<td valign=top><span ID=MT-1><font size="-1"><b>');
	document.write(caption);
	document.write('</a></b></font></span></td>');
	document.writeln('</tr></table>');
}

function closeTree()
{
	document.writeln ('</DIV>\n</FONT>');
}

// This function handles to onClick event for expanding/closing
// nodes of the tree.
function expandCollapseClick ()
{
	var parentID;
	var child;
	var parentImage;

	parentID = window.event.srcElement.id;

	if (parentID.charAt (0) == 'M')
	{
		child = document.all ('C' + parentID.substr (2));
		parentImage = document.all ('MI' + parentID.substr (2));
		if (child.style.display == 'none') // hidden
		{
			child.style.display = '';
			/* use last minus sign when appropiate */
			if(parentID == 'MI-1' || parentID == 'MI-' + Mcounter)
				parentImage.src = '/Products/Tree/ftv2mlastnode.gif';
			else
				parentImage.src = '/Products/Tree/ftv2mnode.gif';
		}
		else
		{
			child.style.display = 'none';
			if(parentID == 'MI-1' || parentID == 'MI-' + Mcounter)
				parentImage.src = '/Products/Tree/ftv2plastnode.gif';
			else
				parentImage.src = '/Products/Tree/ftv2pnode.gif';
		}
	}
}

// This function gets called from a script tag at the bottom of
// your html to expand the menu upon page opening.
function expandMenu(cat)
{
	var parentID;
	var child;
	var parentImage;

	// Get First level desired to expand. You want to specify
	// Top level (MI-1) when calling this function.
	parentID = cat.substr(0);

	if (parentID.charAt(0) == 'M')
	{
		child = document.all ('C' + parentID.substr (2));
		parentImage = document.all ('MI' + parentID.substr (2));
		if (child.style.display == 'none') // hidden
		{
			child.style.display = '';
			/* use last minus sign when appropiate */
			if(parentID == 'MI-1' || parentID == 'MI-' + Mcounter)
				parentImage.src = '/Products/Tree/ftv2mlastnode.gif';
			else
				parentImage.src = '/Products/Tree/ftv2mnode.gif';
		}
		else
		{
			child.style.display = 'none';
			if(parentID == 'MI-1' || parentID == 'MI-' + Mcounter)
				parentImage.src = '/Products/Tree/ftv2plastnode.gif';
			else
				parentImage.src = '/Products/Tree/ftv2pnode.gif';
		}
	}
}

// This function creates the link.
function makeLink (category, urlDir, target)
{
	var categoryToDisplay, targetstr;

	if (category.length > 12)
	{
		categoryToDisplay = category.substring (0, 50);
	}
	else
	{
		categoryToDisplay = category;
	}

	if (urlDir != "") // Test to see if target is empty, if not empty add the target attribute to href tag
	{

		HTMLstr='<font size="-1"><A HREF="' + urlDir + '" TITLE="Open &#145;' + category + '&#146;." class="Corp3"';
		targetstr = target + ""; // Explicitely change target to string
		HTMLstr += 'target="' + target +'">' + categoryToDisplay + '</A></font>';
	}
	else // else leave tag alone.
	{
		HTMLstr = '<font size="-1"><A ID=MI-' + Mcounter + ' onClick="expandCollapseClick()">' + categoryToDisplay + '</A></font>';
	}
	return HTMLstr;
}

// This function creates the end nodes under any given category.
function makeNode (name, URLpath, target)
{
	++lastNode; // increment to track last node of node division.
	document.writeln ('<table CELLPADDING=0 CELLSPACING=0><tr><td valign=top><img ID=img1-' + lastNode + ' src = "/Products/Tree/ftv2vertline.gif"><img ID=img2-' + lastNode + ' src = "/Products/Tree/ftv2node.gif"><IMG src = "/Products/Tree/doc.gif"></td><td valign=top>' + makeLink(name, URLpath, target) + '</td></tr></table>');
}

// This function creates the category.
function makeCategory (name, URLpath, target)
{
	Mcounter++;
	document.writeln ('<table CELLPADDING=0 CELLSPACING=0><tr><td valign=top><IMG src = "/Products/Tree/ftv2pnode.gif" ID=MI-' + Mcounter + '  onClick=expandCollapseClick()><IMG src = "/Products/Tree/folderc2.gif"></td><td valign=top><SPAN ID=MT-' + Mcounter + '>' + makeLink (name, URLpath, target) + '</SPAN></td></tr></table>');
}

// This function creates the opening div tag for hiding and
// showing with the expandCollapseClick function.
function openDiv ()
{
	Ccounter++;
	document.writeln ('<DIV ID=C-' + Ccounter + ' STYLE="margin-left:15; display:None;">');
}
function openNodeDiv ()
{
	firstNode = lastNode + 1; // remember first node of node division.
	++Ccounter;
	document.writeln ('<DIV ID=C-' + Ccounter + ' STYLE="margin-left:0; display:None;">');
}

// This function closes the div tag.
function closeDiv ()
{
	var image;

	document.writeln ('</DIV>');

	image = document.all('MI-' + Mcounter);
	image.src = '/Products/Tree/ftv2plastnode.gif';

	// blank last catagory's node's first image(vertical line).
	for(i = firstNode; i <= lastNode; ++i)
	{
		image = document.all('img1-' + i);
		image.src = '/Products/Tree/ftv2blank.gif';
	}
}
function closeNodeDiv ()
{
	var image;

	document.writeln('</DIV>');

	image = document.all('img2-' + lastNode);
	image.src = '/Products/Tree/ftv2lastnode.gif';
}

// This command calls the function created in the head of your
// document. If you do not want users to see your directory
// structure, you will need to put that function here. I moved
// it outside this file and into the head of the html file
// to manipulate the tree using ASP.
// showDirectoryTree();

