function NextSiblingElement(Element)
{
	var NextSibling = null;
	for(NextSibling = Element.nextSibling;  (NextSibling != null) && (NextSibling.nodeType != 1);  NextSibling = NextSibling.nextSibling)
	{
	}
	return(NextSibling);
}

var SectionHeadingList = [];

function SectionHeadingListOpen()
{
	var SectionHeadingListLength = SectionHeadingList.length;
	for(var SectionHeadingIndex = 0;  SectionHeadingIndex < SectionHeadingListLength;  SectionHeadingIndex++)
	{
		SectionHeadingOpen(SectionHeadingList[SectionHeadingIndex]);
	}
}

function SectionHeadingListClose()
{
	var SectionHeadingListLength = SectionHeadingList.length;
	for(var SectionHeadingIndex = 0;  SectionHeadingIndex < SectionHeadingListLength;  SectionHeadingIndex++)
	{
		SectionHeadingClose(SectionHeadingList[SectionHeadingIndex]);
	}
}

function SectionHeadingOpen(SectionHeading)
{
	var SectionContent = NextSiblingElement(SectionHeading);
	SectionContent.style.display = "block";
	SectionHeading.className = "SectionOpen";
}

function SectionHeadingClose(SectionHeading)
{
	var SectionContent = NextSiblingElement(SectionHeading);
	SectionContent.style.display = "none";
	SectionHeading.className = "SectionClosed";
}

function SectionHeadingToggle(SectionHeading)
{
	var SectionContent = NextSiblingElement(SectionHeading);
	switch(SectionContent.style.display.toLowerCase())
	{
		case "block":
			SectionContent.style.display = "none";
			SectionHeading.className = "SectionClosed";
			break;
//		case "none":
		default:
			SectionContent.style.display = "block";
			SectionHeading.className = "SectionOpen";
			break;
	}
}

function SectionHeadingLinkClick()
{
	SectionHeadingToggle(this.parentNode);
	return(false);
}

function SectionHeadingListToggleCreate(Caption)
{
	var Toggle = window.document.createDocumentFragment();

	var Checkbox = window.document.createElement("INPUT");
	Checkbox.type = "checkbox";
	Checkbox.id = "SectionToggle";
	Checkbox.onclick = SectionHeadingListCheckboxClick;

	Toggle.appendChild(Checkbox);

	var Label = window.document.createElement("LABEL");
	Label.htmlFor = "SectionToggle";
	Label.appendChild(window.document.createTextNode(Caption));

	Toggle.appendChild(Label);

	return(Toggle);
}

function SectionHeadingListCheckboxClick()
{
	if(this.checked)
	{
		SectionHeadingListOpen();
	}
	else
	{
		SectionHeadingListClose();
	}
}

function SectionOutline(DocumentNodeList, HeadingElementTagName)
{
	HeadingElementTagName = HeadingElementTagName.toLowerCase();
	for(var DocumentNode = DocumentNodeList.firstChild;  DocumentNode != null;  DocumentNode = DocumentNode.nextSibling)
	{
		/* Is this a heading element? */
		if((DocumentNode.nodeType == 1) && (DocumentNode.tagName.toLowerCase() == HeadingElementTagName))
		{
			var DocumentNodeChild = DocumentNode.firstChild;
			/* Does the heading element consist of a hyperlink? */
			if((DocumentNodeChild.nodeType == 1) && (DocumentNodeChild.tagName.toLowerCase() == "a") && (DocumentNodeChild.href))
			{
				var DocumentNodeNext = NextSiblingElement(DocumentNode);
				/* Is the following element not a heading element? */
				if((DocumentNodeNext != null) && (DocumentNodeNext.nodeType == 1) && (DocumentNodeNext.tagName.toLowerCase() != HeadingElementTagName))
				{
					DocumentNodeChild.onclick = SectionHeadingLinkClick;
					DocumentNodeNext.style.display = "none";
					DocumentNode.className = "SectionClosed";
					SectionHeadingList.push(DocumentNode);
					DocumentNode = DocumentNodeNext;
				}
				else
				{
					DocumentNode.className = "SectionExtended";
				}
			}
			else
			{
			}
		}
	}
}
