var OutputWin = window.open("","OutputWin","left=0,top=0,screenX=0,screenY=0,height=700,width=340,scrollbars=1,resizable=1");
OutputWin.document.body.innerHTML = "";
OutputWin.focus();

var NodeTypes = new Array("Element","Attribute","Text","CDATA","Entity Reference","Entity","Processing Instruction","Comment","Document","Document Type","Document Fragment","Notation");
var ELEMENT_NODE = 1; 
var ATTRIBUTE_NODE = 2; 
var TEXT_NODE = 3; 
var CDATA_SECTION_NODE = 4; 
var ENTITY_REFERENCE_NODE = 5;
var ENTITY_NODE = 6;
var PROCESSING_INSTRUCTION_NODE = 7;
var COMMENT_NODE = 8;
var DOCUMENT_NODE = 9;
var DOCUMENT_TYPE_NODE = 10;
var DOCUMENT_FRAGMENT_NODE = 11;
var NOTATION_NODE = 12;

function Traverse(ELEM)
{
	OutputWin.document.write("<div style='clear:both;border:1px solid black; padding:5px;font-size:8pt;font-family:Verdana'><ol>");
	for (var i=0; i<ELEM.childNodes.length; i++)
	{
		OutputWin.document.write("<li>" + NodeTypes[ELEM.childNodes[i].nodeType-1] + ": " + ELEM.childNodes[i].nodeName + ShowAtts(ELEM.childNodes[i]) + "</li>");
		if (ELEM.childNodes[i].hasChildNodes()) Traverse(ELEM.childNodes[i]);
	}
	OutputWin.document.write("</ol></div>");
}

function ShowAtts(ELEM)
{
	var retStr = "";
	if (ELEM.attributes && ELEM.attributes.length > 0)
	{
			retStr += "<ol>";
			for (var i=0; i < ELEM.attributes.length; i++)
			{
				retStr += "<li>@" + ELEM.attributes[i].name + "</li>";
			}
			retStr += "</ol>";
	}
	return retStr;
}

function RemoveTextNodes(NODE,RECURSIVE)
{
	var ChildNode;
	for (var i=NODE.childNodes.length-1; i>=0; i--)
	{
		ChildNode = NODE.childNodes[i];
		if (ChildNode.nodeType == 3)
		{
			NODE.removeChild(ChildNode);
		}
		else if (RECURSIVE && ChildNode.hasChildNodes())
		{
			RemoveTextNodes(ChildNode,true);
		}
	}
}

function ShowDom(ELEM,REMOVETEXT)
{
	if (REMOVETEXT) RemoveTextNodes(ELEM,true);
	Traverse(ELEM);
}