var displayCSS	= isIE?"block":"table";
var cursorCSS	= isIE?"hand":"pointer";


function ExpandHide_old(iid,bid) {
  if (document.getElementById(iid)!=null && document.getElementById(bid)!=null) {
    var icon = document.getElementById(iid);
    var tableBlock = document.getElementById(bid);
    var isExpand = (icon.src.indexOf("expand")>-1)?true:false;
    icon.src = isExpand?"/images/hide_icon.gif":"/images/expand_icon.gif";
    tableBlock.style.display = isExpand?displayCSS:"none";
  }
}

function ExpandHide(iid,bid) {
  var expandIcon = arguments.length > 2 ? arguments[2] : "/images/expand_icon.gif";
  var hideIcon = arguments.length > 3 ? arguments[3] : "/images/hide_icon.gif";

  if (document.getElementById(iid)!=null && document.getElementById(bid)!=null) {
    var icon = document.getElementById(iid);
    var tableBlock = document.getElementById(bid);
    var isExpand = (icon.src.indexOf("expand")>-1)?true:false;
    icon.src = isExpand?hideIcon:expandIcon;
    tableBlock.style.display = isExpand?displayCSS:"none";
  }
}


function getTagAtt(node, att, t, f) {
  var ff = (f == undefined || f == null) ? "" : f;
  var tt = (t == undefined || t == null) ? "$$$" : t;

  return (node != undefined && node != null) ? ((att == undefined || att == null) ? node.firstChild.nodeValue : (node.getAttribute(att)!=null?((node.getAttribute(att)!=""?tt.replace('$$$', node.getAttribute(att)):ff)):ff)) : "";		// direct to get firstchild value
//  return (node != undefined && node != null) ? (node.getAttribute(att)!=null?((node.getAttribute(att)!=""?tt.replace('$$$', node.getAttribute(att)):ff)):ff) : "";		// inherit
//  return (node != undefined && node != null) ? (node.getAttribute(att)!=null?(tt.replace('$$$', node.getAttribute(att))):ff) : "";		// simple
}

function getNodeAtts(node) {
  var att = "";

  if (node.childNodes.length>0)
    for (var n=0; n<node.childNodes.length; n++)
      if (node.childNodes[n].nodeName!="#text")	// checking for firefox
	att+=" "+ node.childNodes[n].nodeName + "=\"" + getTagAtt(node.childNodes[n], "value") + "\"";
  return att;
}

function genTriLeveltable(x) {
  var rootNodes = (isIE)?x[0].childNodes.length:Math.round((x[0].childNodes.length - 1)/2);

  divStyle += getTagAtt(x[0].getElementsByTagName("config")[0], "width", " width: $$$");
  tableStyle += getTagAtt(x[0].getElementsByTagName("config")[0], "width", " width: $$$ ") + getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("style")[0], "table");
  headStyle += getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("style")[0], "head");
  var tdStyle = getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("style")[0], "td");

  document.write ("<div id=\"dataTable\"><center>");

  for (var i=0; i<rootNodes-1; i++) {
    gt = x[0].getElementsByTagName(groupTag)[i];

    document.write (getTagAtt(gt, "jump", "<a name=\"$$$\"></a>", "")  + "<div style=\""+divStyle+" margin-bottom:20px;\">");
    document.write ("<table cellspacing=\"0\" cellpadding=\"5\" style=\""+tableStyle+"\">");
    if (getTagAtt(gt, "always") != "true") document.write ("<tr height=\"40\" style=\"" + headStyle + "Cursor:" + cursorCSS + ";\" onmouseover=\"this.style.backgroundColor='#c0ddda'\" onmouseout=\"this.style.backgroundColor='#afd0ca'\" onclick=\"javascript:ExpandHide('"+imgName+i+"','"+TblName+i+"')\">");
    else document.write ("<tr height=\"40\" style=\""+headStyle+"\">");
    document.write ("<td width=\"30\" align=\"center\">" + (getTagAtt(gt, "always") != "true" ? "<img src=\"/images/expand_icon.gif\" id=\"" +imgName+i+ "\">":(getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("emptyICON")[0], "src", "<img src=\"$$$\">"))) + "</td>");
    document.write ("<td width=\"900\">" + getTagAtt(gt, "title") + getTagAtt(gt, "subtitle", "<br>$$$") + "</td>");
//    document.write ("<td width=\"20\">" + (getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("top")[0], "name") != "" ? "<span class=\"download\"><a href=\"#top\"><img src=\"/images/top_icon.gif\" border=\"0\" alt=\"" + getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("top")[0], "name") + "\"></a></span>" : "") + "</td>");
    document.write ("<td width=\"20\">" + (getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("top")[0], "name", "<a href=\"#top\"><img src=\"/images/top_icon.gif\" border=\"0\" alt=\"$$$\"></a>", getTagAtt(x[0].getElementsByTagName("config")[0].getElementsByTagName("top")[0], "title", "<a href=\"#top\"><img src=\"/images/top_icon.gif\" border=\"0\" alt=\"$$$\"></a>"))) + "</td>");
    document.write ("</tr>");
    document.write ("</table>");

    partNodes = (isIE)?gt.childNodes.length:Math.round((gt.childNodes.length - 1)/2);

    if (partNodes > 0) {
      document.write ("<table cellspacing=\"0\" cellpadding=\"0\" style=\""+tableStyle+" margin-top:10px; display: " + (getTagAtt(gt, "always") != "true" ? "none" : displayCSS) + "\" id=\""+TblName+i+"\">");
	for (var j=0; j<partNodes; j++) {

	  dt = gt.getElementsByTagName(childTag)[j];
	  if (getTagAtt(dt, "title")!="") {
	    document.write ("<tr height=\"40\" valign=\"middle\" style=\"" + subheadStyle + "\">");
	    document.write ("<td style=\"" + getTagAtt(dt, "padding") + getTagAtt(dt, "style") + "\"><a name=\"" + getTagAtt(gt, "jump") + j + "\"></a>" + getTagAtt(dt, "title") + getTagAtt(dt, "subtitle", "<br>$$$") + "</td>");
	    document.write ("</tr>");
	  }

	  itemNodes = (isIE)?dt.childNodes.length:Math.round((dt.childNodes.length - 1)/2);
	  for (var k=0; k<itemNodes; k++) {
	    ct = dt.getElementsByTagName("item")[k];
	    document.write ("<tr onmouseover=\"this.style.backgroundColor='#d4eeeb'\" onmouseout=\"this.style.backgroundColor='#e3f6f4'\">");
	    document.write ("<td style=\"" + getTagAtt(ct, "padding", "$$$", getTagAtt(dt, "padding")) + getTagAtt(dt, "style") + "\">");
	    document.write ("<a name=\"" + getTagAtt(gt, "jump") + j + "_" + k + "\"></a>");
	    document.write ("<span style=\"padding-top: 8px; padding-bottom: 8px; float: left; " + getTagAtt(ct, "style", "$$$", DefaultSpanStyle1) + "\">");
	    document.write (getTagAtt(ct, "url", "<a href=\"$$$\"" + getTagAtt(ct, "boxname", " boxname=\"$$$\"") + getTagAtt(ct, "rev", " rev=\"$$$\"") + ">") + getTagAtt(ct, "title") + getTagAtt(ct, "url", "</a>") + getTagAtt(ct, "desc", "<div style=\"padding-top: 5; \">$$$</div>"));
	    document.write ("</span>");

	    detailNodes = (isIE)?ct.childNodes.length:Math.round((ct.childNodes.length - 1)/2);
	    for (var m=0; m<detailNodes; m++) {

	      ddt = ct.getElementsByTagName("link")[m];
	      var att = getNodeAtts(ddt);

	      document.write ("<span style=\""+ getTagAtt(ddt, "icon","","padding-top: 8px; ") +"float: left; " + getTagAtt(ddt, "style", "$$$", DefaultSpanStyle2) + "\">");

	      var tmpURL = getTagAtt(ddt, "url", "$$$", getTagAtt(ct, "url"));
	      document.write ((tmpURL!=""?"<a href=\"" + tmpURL + "\"" + att + ">":""));
//	      document.write (getTagAtt(ddt, "icon", "<img src=\"$$$\" border=\"0\" style=\"vertical-align:middle;\">" + getTagAtt(ddt, "name")));
	      document.write (getTagAtt(ddt, "icon", "<img src=\"$$$\" border=\"0\" style=\"vertical-align:middle;\">"));
	      document.write (getTagAtt(ddt, "name"));
	      document.write ((tmpURL!=""?"</a>":""));
	      document.write ("</span>");
	    }

	    document.write ("</td>");
	    document.write ("</tr>");

	    if (k<itemNodes-1) document.write ("<tr height=\"1\"><td style=\""+lineStyle+"\" ></td></tr>");
	  }
	}
      document.write ("</table>");
    }
    document.write ("</div>");
  }
  document.write ("</center></div>");
}
