


// Create the tree
function addRootNode(prefix, nodeInfo, rootName, activeNode, activeNodeCmd, dataMode, editable, icon_base, node_params, path) {
	var nodeValues = nodeInfo.split("|");
	if (editable != 0) {
		document.write("<img src=\"" + icon_base + "\" align=absmiddle alt=\"Root\" />");
		addCheckBox(nodeValues[0], nodeValues[2], nodeValues[3], nodeValues[4], activeNode, activeNodeCmd, dataMode);
		addEditIcons(prefix, nodeValues[0], nodeValues[2], activeNode, activeNodeCmd, node_params, path);
		if (nodeValues[5] == "X") {
		}
		else {
			document.write("<a href=\"" + getNodeUrl(prefix, nodeValues[0], nodeValues[5], node_params, path, dataMode) + "\" " + nodeValues[6] + " onmouseover=\"window.status='" + nodeValues[1] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		}
		if (activeNode == nodeValues[0]) {
			document.write("<font style=\"BACKGROUND-COLOR: #222288\" color=#ffffff>");
		}
		//document.write("&nbsp;");
		if (nodeValues[7] != "") {
			document.write("<img src=\"" + nodeValues[7] + "\" border=0>");
		}
		document.write(nodeValues[1]);
		//document.write("&nbsp;");
		if (activeNode == nodeValues[0]) {
			document.write("</font>");
		}
		if (nodeValues[5] == "X") {
		}
		else {
			document.write("</a>");
		}
		document.write("<br>");

	} else {
		document.write("<img src=\"" + icon_base + "\" align=absmiddle alt=\"Root\" />&nbsp;" + rootName + "&nbsp;<br>");
	}
}

function getNodeUrl(prefix, node_id, url, node_params, path, dataMode) {
	if (url == "#") {
		if (dataMode == 1) {
			return "javascript:nu" + prefix + "(" + node_id + ",11,'" + node_params + "','" + path + "')";//urlPrefix + "&" + urlNodeKey + "=" + node_id + "&" + urlNodeKey + "cmd=11&rnd=" + Math.random();	// Modify One Node
		}
		else {
			return "javascript:nu" + prefix + "(" + node_id + ",3,'" + node_params + "','" + path + "')";//urlPrefix + "&" + urlNodeKey + "=" + node_id + "&" + urlNodeKey + "cmd=3&rnd=" + Math.random();	// Modify One Node
		}
	}
	else {
		return url;
	}
}

// Adds a new node in the tree
function writeLinesIcons(icon_line, icon_empty)
{
	// Write out line & empty icons
	for (g=0; g<recursedNodes.length; g++) {
		if (recursedNodes[g] == 1) document.write("<img src=\"" + icon_line + "\" align=absmiddle>");
		else document.write("<img src=\"" + icon_empty + "\" align=absmiddle>");
	}
}


function addNode(node_id, node_name, node_url, target_str, node_img_src, prefix, activeNode, activeNodeCmd, node_params, path, dataMode, text_font)
{

	// Start link
	if (node_url == "X") {
	}
	else {
		document.write("<a href=\"" + getNodeUrl(prefix, node_id, node_url, node_params, path, dataMode) + "\" " + target_str + " onmouseover=\"window.status='" + node_name + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
	}
	if (activeNode == node_id) {
		document.write("<font style=\"BACKGROUND-COLOR: #222288\" color=#ffffff>");
	}

	// Write out node name
        if (node_img_src != "") {
	  document.write("<img src=\"" + node_img_src + "\" border=0>");
        }
	document.write("&nbsp;");
	document.write("<font color=#"+text_font+">");
	document.write(node_name);
	document.write("</font>");
	//document.write("&nbsp;");

	if (activeNode == node_id) {
		document.write("</font>");
	}

	// End link
	if (node_url == "X") {
	}
	else {
		document.write("</a>");
	}

	//document.write("<br>");

}

function doMouseOver(name, i, actCmdID) {
  if (document.images) {
    document.images[name].src=node_act3[i].src;
  }
  window.status=status_str[actCmdID];
  return true;
}

function doMouseOut(name, src) {
  if (document.images) {
    document.images[name].src=src;
  }
  window.status=' ';
  return true;
}

function addCheckBox(node_id, mask, checked, valuePrefix, activeNode, activeNodeCmd, dataMode)
{

  if ((mask & 0x50) != 0) {	// MODIFY_MULTIPLE_MASK | DELETE_MULTIPLE_MASK
    if (dataMode == 2) {
      TreeBaseCheckBoxCallBack(valuePrefix + node_id, checked);
    }
    else {
      document.write("<input type=checkbox name=" + QeBatchNodeName + " value=" + node_id);
      if (checked != 0) {
        document.write(" checked ");
      }
      document.write(">");
    }
  }
}

function addEditIcons(prefix, node_id, mask, activeNode, activeNodeCmd, node_params, path)
{

  var img_addm_src = node_act1[0].src;
  var img_add_src = node_act1[1].src;
  var img_del_src = node_act1[2].src;
  var img_up_src = node_act1[3].src;
  var img_down_src = node_act1[4].src;
  var img_cmd_src = node_act1[5].src;
  var img_hide_src = node_act1[6].src;
  if (activeNode == node_id) {
    if (activeNodeCmd == 2) {
      img_addm_src = node_act2[0].src;
    }
    else if (activeNodeCmd == 1) {
      img_add_src = node_act2[1].src;
    }
    else if (activeNodeCmd == 5) {
      img_del_src = node_act2[2].src;
    }
    else if (activeNodeCmd == 7) {
      img_up_src = node_act2[3].src;
    }
    else if (activeNodeCmd == 8) {
      img_down_src = node_act2[4].src;
    }
    else if (activeNodeCmd == 13) {
      img_hide_src = node_act2[6].src;
    }
    else if (activeNodeCmd == 14) {
      img_cmd_src = node_act2[5].src;
    }
  }

//  public final static int EXPAND_MASK = 0x1;
//  public final static int ADD_MASK = 0x2;
//  public final static int ADD_MULTIPLE_MASK = 0x4;
//  public final static int MODIFY_MASK = 0x8;
//  public final static int MODIFY_MULTIPLE_MASK = 0x10;
//  public final static int DELETE_MASK = 0x20;
//  public final static int DELETE_MULTIPLE_MASK = 0x40;
//  public final static int MOVE_UP_MASK = 0x80;
//  public final static int MOVE_DOWN_MASK = 0x100;
//  public final static int ALLOW_SHOW_NODE_NUMBER_MASK = 0x200;
//  public final static int HIDE_MASK = 0x400;
//  public final static int SETUP_MASK = 0x800;


  if ((mask & 0x4) != 0) {
    document.write("<a href=\"javascript:nu" + prefix + "(" + node_id + ",2,'" + node_params + "','" + path + "')\" onmouseover=\"return doMouseOver('node_addm" + node_id + "',0,2);\" onmouseout=\"return doMouseOut('node_addm" + node_id + "', '" + img_addm_src + "');\">");
    document.write('<img name=node_addm' + node_id + ' src=\"' + img_addm_src + '\" align=absMiddle alt=\"' + status_str[2] + '\"></a>');
  }
  if ((mask & 0x2) != 0) {
    document.write("<a href=\"javascript:nu" + prefix + "(" + node_id + ",1,'" + node_params + "','" + path + "')\" onmouseover=\"return doMouseOver('node_add" + node_id + "',1,1);\" onmouseout=\"return doMouseOut('node_add" + node_id + "', '" + img_add_src + "');\">");
    document.write('<img name=node_add' + node_id + ' src=\"' + img_add_src + '\" align=absMiddle alt=\"' + status_str[1] + '\"></a>');
  }
  if ((mask & 0x20) != 0) {
    document.write("<a href=\"javascript:nu" + prefix + "(" + node_id + ",5,'" + node_params + "','" + path + "')\" onmouseover=\"return doMouseOver('node_del" + node_id + "',2,5);\" onmouseout=\"return doMouseOut('node_del" + node_id + "', '" + img_del_src + "');\">");
    document.write('<img name=node_del' + node_id + ' src=\"' + img_del_src + '\" align=absMiddle alt=\"' + status_str[5] + '\"></a>');
  }
  if ((mask & 0x80) != 0) {
    document.write("<a href=\"javascript:nu" + prefix + "(" + node_id + ",7,'" + node_params + "','" + path + "')\" onmouseover=\"return doMouseOver('node_up" + node_id + "',3,7);\" onmouseout=\"return doMouseOut('node_up" + node_id + "', '" + img_up_src + "');\">");
    document.write('<img name=node_up' + node_id + ' src=\"' + img_up_src + '\" align=absMiddle alt=\"' + status_str[7] + '\"></a>');
  }
  if ((mask & 0x100) != 0) {
    document.write("<a href=\"javascript:nu" + prefix + "(" + node_id + ",8,'" + node_params + "','" + path + "')\" onmouseover=\"return doMouseOver('node_down" + node_id + "',4,8);\" onmouseout=\"return doMouseOut('node_down" + node_id + "', '" + img_down_src + "');\">");
    document.write('<img name=node_down' + node_id + ' src=\"' + img_down_src + '\" align=absMiddle alt=\"' + status_str[8] + '\"></a>');
  }
  if ((mask & 0x400) != 0) {
    document.write("<a href=\"javascript:nu" + prefix + "(" + node_id + ",13,'" + node_params + "','" + path + "')\" onmouseover=\"return doMouseOver('node_hide" + node_id + "',6,13);\" onmouseout=\"return doMouseOut('node_hide" + node_id + "', '" + img_hide_src + "');\">");
    document.write('<img name=node_hide' + node_id + ' src=\"' + img_hide_src + '\" align=absMiddle alt=\"' + status_str[13] + '\"></a>');
  }
  if ((mask & 0x800) != 0) {
    document.write("<a href=\"javascript:nu" + prefix + "(" + node_id + ",14,'" + node_params + "','" + path + "')\" onmouseover=\"return doMouseOver('node_cmd" + node_id + "',5,14);\" onmouseout=\"return doMouseOut('node_cmd" + node_id + "', '" + img_cmd_src + "');\">");
    document.write('<img name=node_cmd' + node_id + ' src=\"' + img_cmd_src + '\" align=absMiddle alt=\"' + status_str[14] + '\"></a>');
  }

}

// Opens or closes a node
function oc(node, bottom, prefix, icons, hide_flag) {
	var theDiv = document.getElementById("div" + prefix + "_" + node);
	var theJoin = document.getElementById("join" + prefix + "_" + node);
	var theIcon = document.getElementById("icon" + prefix + "_" + node);

	if (theDiv.style.display == 'none') {
		if (bottom==1) theJoin.src = icons[3].src;
		else theJoin.src = icons[2].src;
		if (hide_flag==1) theIcon.src = icons[7].src;
		else theIcon.src = icons[5].src;
		theDiv.style.display = '';
	} else {
		if (bottom==1) theJoin.src = icons[1].src;
		else theJoin.src = icons[0].src;
		if (hide_flag==1) theIcon.src = icons[6].src;
		else theIcon.src = icons[4].src;
		theDiv.style.display = 'none';
	}
}

// Push and pop not implemented in IE(crap!    donīt know about NS though)
if(!Array.prototype.push) {
	function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
	Array.prototype.push = array_push;
}

if(!Array.prototype.pop) {
	function array_pop(){
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
	Array.prototype.pop = array_pop;
}


function addNode2(ctrl_id, tree_id, parent_id, node_id, node_flag, expand_flag, hide_flag, last_sibling, node_name, node_url, node_params, target_str, data_mode, node_img_src, value_prefix, active_node_id, active_node_cmd, flag, checked, br_flag, text_font)
{
    var node_path2 = "";

    writeLinesIcons(eval("icon_line" + ctrl_id), eval("icon_empty" + ctrl_id));
    var js_oc = "";
    if (node_flag != 0) {
      if (last_sibling != 0) {
        js_oc = "javascript:oc(" + node_id + ",1," + tree_id + ",icons" + ctrl_id + "," + hide_flag + ")";
        document.write("<a href=\"" + js_oc + "\"><img id=\"join" + tree_id + "_" + node_id + "\" src=\"");
        if ((expand_flag != 0) && (node_flag != 0)) document.write(eval("icons" + ctrl_id)[3].src);
        else document.write(eval("icons" + ctrl_id)[1].src);
        document.write("\" border=0 align=absbottom alt=\"Open/Close node\">");
      }
      else {
        js_oc = "javascript:oc(" + node_id + ",0," + tree_id + ",icons" + ctrl_id + "," + hide_flag + ")";
        document.write("<a href=\"" + js_oc + "\"><img id=\"join" + tree_id + "_" + node_id + "\" src=\"");
        if ((expand_flag != 0) && (node_flag != 0)) document.write(eval("icons" + ctrl_id)[2].src);
        else document.write(eval("icons" + ctrl_id)[0].src);
        document.write("\" border=0 align=absbottom alt=\"Open/Close node\">");
      }
      document.write("<img id=\"icon" + tree_id + "_" + node_id + "\" src=\"");
      if ((expand_flag != 0) && (node_flag != 0)) {
      	if (hide_flag==1) document.write(eval("icons" + ctrl_id)[7].src);
      	else document.write(eval("icons" + ctrl_id)[5].src);
      }
      else {
      	if (hide_flag==1) document.write(eval("icons" + ctrl_id)[6].src);
      	else document.write(eval("icons" + ctrl_id)[4].src);
      }
      document.write("\" border=0 align=absbottom alt=\"Folder\"></a>");
    }
    else {
      document.write("<img src=\"");
      if (last_sibling != 0) document.write(eval("icon_join_bottom" + ctrl_id));
      else document.write(eval("icon_join" + ctrl_id));
      document.write("\" border=0 align=absbottom>");

      // Start link
      if (node_url != "X") {
        if (node_url == "#") {
          if (data_mode == 1) {
            document.write("<a href=\"javascript:nu" + tree_id + "(" + node_id + ",11,'" + node_params + "','" + node_path2 + "')\" onmouseover=\"window.status='" + node_name + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
          }
          else {
            document.write("<a href=\"javascript:nu" + tree_id + "(" + node_id + ",3,'" + node_params + "','" + node_path2 + "')\" onmouseover=\"window.status='" + node_name + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
          }
        }
        else {
          document.write("<a href=\"" + node_url + "\" " + target_str + " onmouseover=\"window.status='" + node_name + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
        }
      }
      document.write("<img id=\"icon" + tree_id + "_" + node_id + "\" src=\"");

      if (hide_flag == 0) {
        if (node_id == active_node_id) {
          document.write(eval("icon_page_active" + ctrl_id));
        }
        else {
          document.write(eval("icon_page" + ctrl_id));
        }
      }
      else {
        if (node_id == active_node_id) {
          document.write(eval("icon_pagehide_active" + ctrl_id));
        }
        else {
          document.write(eval("icon_pagehide" + ctrl_id));
        }
      }

      document.write("\" border=0 align=absbottom alt=\"Page\">");
      // End link
      if (node_url != "X") {
        document.write("</a>");
      }
    }

    addCheckBox(node_id, flag, checked, value_prefix, active_node_id, active_node_cmd, data_mode);

    addEditIcons(tree_id, node_id, flag, active_node_id, active_node_cmd, node_params, node_path2);

/*
    var img_addm_src = node_act1[0].src;
    var img_add_src = node_act1[1].src;
    var img_del_src = node_act1[2].src;
    var img_up_src = node_act1[3].src;
    var img_down_src = node_act1[4].src;
    if (active_node_id == node_id) {
      if (active_node_cmd == 2) {
        img_addm_src = node_act2[0].src;
      }
      else if (active_node_cmd == 1) {
        img_add_src = node_act2[1].src;
      }
      else if (active_node_cmd == 5) {
        img_del_src = node_act2[2].src;
      }
      else if (active_node_cmd == 7) {
        img_up_src = node_act2[3].src;
      }
      else if (active_node_cmd == 8) {
        img_down_src = node_act2[4].src;
      }
    }

    if ((flag & 0x4) != 0) {
      document.write("<a href=\"javascript:nu" + tree_id + "(" + node_id + ",2,'" + node_params + "','" + node_path2 + "')\" onmouseover=\"return doMouseOver('node_addm" + node_id + "',0,2);\" onmouseout=\"return doMouseOut('node_addm" + node_id + "', '" + img_addm_src + "');\">");
      document.write("<img name=node_addm" + node_id + " src=\"" + img_addm_src + "\" align=absbottom alt=\"" + status_str[2] + "\"></a>");
    }
    if ((flag & 0x2) != 0) {
      document.write("<a href=\"javascript:nu" + tree_id + "(" + node_id + ",1,'" + node_params + "','" + node_path2 + "')\" onmouseover=\"return doMouseOver('node_add" + node_id + "',1,1);\" onmouseout=\"return doMouseOut('node_add" + node_id + "', '" + img_add_src + "');\">");
      document.write("<img name=node_add" + node_id + " src=\"" + img_add_src + "\" align=absbottom alt=\"" + status_str[1] + "\"></a>");
    }
    if ((flag & 0x20) != 0) {
      document.write("<a href=\"javascript:nu" + tree_id + "(" + node_id + ",5,'" + node_params + "','" + node_path2 + "')\" onmouseover=\"return doMouseOver('node_del" + node_id + "',2,5);\" onmouseout=\"return doMouseOut('node_del" + node_id + "', '" + img_del_src + "');\">");
      document.write("<img name=node_del" + node_id + " src=\"" + img_del_src + "\" align=absbottom alt=\"" + status_str[5] + "\"></a>");
    }
    if ((flag & 0x80) != 0) {
      document.write("<a href=\"javascript:nu" + tree_id + "(" + node_id + ",7,'" + node_params + "','" + node_path2 + "')\" onmouseover=\"return doMouseOver('node_up" + node_id + "',3,7);\" onmouseout=\"return doMouseOut('node_up" + node_id + "', '" + img_up_src + "');\">");
      document.write("<img name=node_up" + node_id + " src=\"" + img_up_src + "\" align=absbottom alt=\"" + status_str[7] + "\"></a>");
    }
    if ((flag & 0x100) != 0) {
      document.write("<a href=\"javascript:nu" + tree_id + "(" + node_id + ",8,'" + node_params + "','" + node_path2 + "')\" onmouseover=\"return doMouseOver('node_down" + node_id + "',4,8);\" onmouseout=\"return doMouseOut('node_down" + node_id + "', '" + img_down_src + "');\">");
      document.write("<img name=node_down" + node_id + " src=\"" + img_down_src + "\" align=absbottom alt=\"" + status_str[8] + "\"></a>");
    }
*/


    if ((node_url == "X") && (js_oc != "")) {
      addNode(node_id, node_name, js_oc, "", node_img_src, tree_id, active_node_id, active_node_cmd, node_params, node_path2, data_mode, text_font);
    }
    else {
      addNode(node_id, node_name, node_url, target_str, node_img_src, tree_id, active_node_id, active_node_cmd, node_params, node_path2, data_mode, text_font);
    }

    if (br_flag != 0) {
      document.write('<br>');
    }

}


