function writeContent (content, windowRef) {
	windowRef.document.open();
	windowRef.document.write (content);
	windowRef.document.close();
	return;
}

function composeTreeHead () {
	var s = "";
	s += "<HEAD>\n";
	s += "<TITLE>IRS Topic Selection Tree</TITLE>\n";
	s += "</HEAD>\n";
	return s;
}

function composeTreeFull (dataRoot) {
	var s = "<HTML>\n";
	s += composeTreeHead ();
	s += "<BODY background=\"../images/cSelectBG.gif\">\n";
	s += "<TABLE  border=\"0\" cell spacing=\"0\" cellpadding=\"0\" bordercolor=\"#CC6633\" width=\"100%\" summary=\"layout table\">\n";
	s += composeTreeBody (dataRoot,"",0,"");
	s += "</TABLE>\n";
	s += "</BODY>\n";
	s += "</HTML>\n";
	return s;
}

function composeTreeBody (treeData, nowIndent, nowDepth, nowPosition) {
	var s = "";
	
	// Omit display / rendering, if it is the root
	if (nowDepth > 0) {
		
		if (nowDepth <= 1) {
			s += "<TR><TD width=\"20%\"><a name=\"top\"></a>&nbsp;</TD><TD>\n";
		} else if (nowDepth == 2) {
			s += "<TR><TD width=\"20%\">&nbsp;</TD><TD>\n";
		} else if (nowDepth == 3) {
			s += "<TR><TD width=\"20%\">&nbsp;</TD><TD>\n";
		} else {
			s += "<TR><TD width=\"20%\">&nbsp;</TD><TD>\n";
		}
		
		// Use the indent
		
		s += nowIndent;
		
		// Compose the +/-/n icon
		//Concatenate nowPosition with 'img' to an id to allow focus to remain on the anchor.

		if (treeData.length > 0) {				
			s += "<A href='javascript:parent.frames[\"logo\"].";
			s += "expandOrCollapse(\"" + nowPosition + "\"); onclick=document.links(\""+nowPosition+"img\").focus();' id=\""+ nowPosition +"img\">";
			
		 	if (treeData.isExpanded) {
				s += "<img alt=\"Click to collapse menu for " + treeData.fullName + "\" border=\"0\" src=\"../images/minus_sign.gif\">";
			} 
			else {
				s += "<img alt=\"Click to expand menu for " + treeData.fullName + "\" border=\"0\" src=\"../images/plus_sign.gif\">";
			}
		s += "</A>";
		}
		
		s += "&nbsp;";
		
		
		// Compose the file/folder/any icon and the Names
		

		if (treeData.type.toLowerCase() == "file") {

			s += "<A style=\"font-size: 10pt; font-family: Arial, Helvetica, sans-serif; color: black; text-decoration: none;\" href='javascript:parent.frames[\"logo\"].";
			s += "show(\"" + nowPosition + "\")'>";

		} 
		
		else {

			s += "<A style=\"font-size: 10pt; font-family: Arial, Helvetica, sans-serif; color: black; text-decoration: none;\" href='javascript:parent.frames[\"logo\"]."
			s += "show1(\"" + nowPosition + "\"); onclick=document.links(\""+nowPosition+"\").focus();' id=\""+ nowPosition +"\">";
		}

		s += "<IMG border=\"0\" src=\"";
		if (treeData.type.toLowerCase() == "folder") {
			if (treeData.isExpanded) {
				if (treeData.isShowing) {
					s += "../images/folder_open_now.gif";
				} else {
					s += "../images/folder_open.gif";
				}
			} else {
				if (treeData.isShowing) {
					s += "../images/folder_now.gif";
				} else {
					s += "../images/folder.gif";
				}
			}
		} else if (treeData.type.toLowerCase() == "file") {
			if (treeData.isShowing) {
				s += "../images/file_now.gif";
			} else {
				s += "../images/file.gif";
			}
		} else {
			s += "../images/any.gif";
		}
		s += "\" ";
		s += "alt=\"\" ";
		s += ">"; 
		s += "&nbsp;";
		if (treeData.isShowing) { s += "<B>"; }
		s += treeData.fullName;
		if (treeData.isShowing) { s += "</B>"; }
		s += "</A>\n";
		s += "</TD></TR>\n";
	}
	if (treeData.isExpanded) {
		for ( var i = 0; i < treeData.length; i++ ) {
			//alert (s);
			if (nowDepth == 0) {
				s += composeTreeBody (treeData[i], 
					(nowIndent + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"), 
					(nowDepth + 1), 
					(i));
			} else {
				s += composeTreeBody (treeData[i], 
					(nowIndent + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"), 
					(nowDepth + 1),
					(nowPosition + "," + i));
			}
		}
	}
	return s;
}

