var oString;
var maxDepth=4;

var numTab=0
function walkDom(){
	maxDepth=parseInt(document.getElementById("drillDepth").value);
	document.getElementById("iPut").innerHTML=getFile(document.getElementById("drillPath").value);
	oString="<pre>";
	dTree=document.getElementById("iPut");

	oString+="<b> Number of 1st Level Nodes: </b>"+dTree.childNodes.length+"\n";

  	if(dTree.childNodes.length > 0) drillDown(dTree);

	oString+="</pre>";
	document.getElementById("oPut").innerHTML = oString;
	return;
}
function drillDown(oRef){
	maxDepth--;
	numTab++;
	var tabStr="";
	for (i=0;i<numTab;i++){
		tabStr+="\t";
	}
	if (maxDepth <= 0){
		oString+="<b>\n\t\t******Warning Maximum Depth Reached*******\n\n</b>";
		var abLoop=confirm(oRef.nodeName + " MaxDepth Reached - Abort?");
		if (abLoop){
	  		maxDepth++;
	  		numTab--;
			return;
		}
	}
	for (var j=0;j<oRef.childNodes.length;j++){	
		 oString+=tabStr+"<b>Level:</b>"+numTab+"<b> Type: </b>"+oRef.childNodes[j].nodeType + "<b> Name: </b>"+oRef.childNodes[j].nodeName;
		 if(oRef.childNodes[j].nodeType==1 && oRef.childNodes[j].attributes.length>0) drillAttr(oRef.childNodes[j]);
		 if(oRef.childNodes[j].nodeType!=3 && oRef.childNodes[j].nodeValue > "" && oRef.childNodes[j].nodeValue != " ") oString+="<b> Value: </b>"+oRef.childNodes[j].nodeValue;
		 else if(oRef.childNodes[j].nodeValue > "" && oRef.childNodes[j].nodeValue != " ") oString+="<b> Value: </b>"+stripCom(oRef.childNodes[j].nodeValue);
		 if(oRef.childNodes[j].nodeName=="SCRIPT" && oRef.childNodes[j].text > " ") oString+="<b>\n:Script:\n</b>"+oRef.childNodes[j].text;
		 else oString+="\n";
	 	 if(oRef.childNodes[j].childNodes.length>0){
		 	try{
		 		drillDown(oRef.childNodes[j]);
		 	}catch (e){
		 		oString+="<b>\n****"+e.name + "-" + e.message+"****\n</b>";
		 		continue
		 	}
		 }
	}
	numTab--;
	maxDepth++;
	return;
}

function drillAttr(oRef){
	oString+="<b> Attributes: </b>";
	for (i=0;i<oRef.attributes.length;i++){
		if(oRef.attributes[i].nodeValue != null && oRef.attributes[i].nodeValue > " ")
			oString+=oRef.attributes[i].nodeName+" = "+oRef.attributes[i].nodeValue+"; ";
	}
	oString+="\n";
}

function stripCom(oRef){
	return oRef.replace("\!","|");
}
