var DIR_IMAGES = "http://www.qmaxtest.com/qmaxnew/images/";
var IMG_PLUS = DIR_IMAGES + "btnPlus.gif";
var IMG_MINUS = DIR_IMAGES + "btnMinus.gif";

var imgPlus = new Image();
imgPlus.src = IMG_PLUS;
var imgMinus = new Image();
imgMinus.src = IMG_MINUS;

var objLocalTree = null;

var INDENT_WIDTH = 18;

function jsTree() {
    this.root = null;           //the root node of the tree
	this.nodes = new Array;     //array for all nodes in the tree
    objLocalTree = this;
}

jsTree.prototype.createRoot = function(strIcon, strText, strURL, strTarget) {    this.root = new jsTreeNode(strIcon, strText, strURL, strTarget);    this.root.id = "root";    this.nodes["root"] = this.root;
    this.root.expanded = true;
    return this.root;
}
jsTree.prototype.buildDOM = function() {
    this.root.addToDOM(document.body);
}

jsTree.prototype.toggleExpand = function(strNodeID) {

    var objNode = this.nodes[strNodeID];

    if (objNode.expanded)
        objNode.collapse();
    else
        objNode.expand();
}

function jsTreeNode(strIcon, strText, strURL, strTarget) {
    this.icon = strIcon;            //the icon to display    
    this.text = strText;            //the text to display
    this.url = strURL;              //the URL to link to
    this.target = strTarget;        //the target for the URL
    this.indent = 0;                //the indent for the node
    this.expanded = false;          //is this node expanded?
    this.childNodes = new Array;    //the collection of child nodes}

jsTreeNode.prototype.addChild = function (strIcon, strText, strURL, strTarget) {

    var objNode = new jsTreeNode(strIcon, strText, strURL, strTarget);
    objNode.id = this.id + "_" + this.childNodes.length;
    objNode.indent = this.indent + 1;
    this.childNodes[this.childNodes.length] = objNode;
    objLocalTree.nodes[objNode.id] = objNode;
    return objNode;
}

jsTreeNode.prototype.addToDOM = function (objDOMParent) {

    if((this.url.length)<=20)
    {		var strHTMLLink = "<a href=\"" + this.url +"\"";		if (this.target)strHTMLLink += " target=\"" + this.target + "\">";    }    else    {
		// the below line is used for mouseover		//var strHTMLLink = "<a href=\"" + this.url + "\" onmouseover=\"" + this.url +"\"";
		var strHTMLLink = "<a href=\"" + this.url + "\"";		if (this.target)strHTMLLink += " target=\"" + this.target + "\">";
    }
    var objNodeDiv = document.createElement("div");

    objDOMParent.appendChild(objNodeDiv);
    
    var d = new jsDocument;
    
    d.writeln("<font face=verdana size=1><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
    
    if (this.indent > 1) {
         d.write("<td class=hd width=\"");
         d.write(this.indent * INDENT_WIDTH);
         d.write("\">&nbsp;</td>");
    }
    
    if (this.indent > 0) {
    
        d.write("<td class=hd width=\"18\" align=\"center\">");
        if (this.childNodes.length > 0) {
            //d.write("<a href=\"javascript:objLocalTree.toggleExpand('");
            //d.write(this.id);
            //d.write("')\" onmouseover=\"javascript:objLocalTree.toggleExpand('this.id')\"><img src=\"");
            d.write("<a href=\"javascript:objLocalTree.toggleExpand('"+this.id+"')\" onmouseover=\"javascript:objLocalTree.toggleExpand('"+this.id+"')\"><img src=\"");            d.write(this.expanded ? imgMinus.src : imgPlus.src);
            d.write("\" border=\"0\" hspace=\"1\" id=\"");
            d.write("imgPM_" + this.id);
            d.write("\" /></a>");
        }
        d.write("</td>");
    }
    // For hide the image the next line must be commented    //d.write("<td class=hd width=\"22\">" +strHTMLLink + "<img hspace=\"1\" src=\"" + this.icon + "\" border=\"0\" align=\"absmiddle\" /></a></td>");
        if(this.text=='Qmax Tester Family')
    {		d.write("<td class=hd nowrap=\"nowrap\"><font size=2><b>" + strHTMLLink + this.text + "</b></font></a></td>");
		d.writeln("</tr></table></font>");
    }
    else{    d.write("<td class=hd nowrap=\"nowrap\"><font size=2>" + strHTMLLink + this.text + "</font></a></td>");
    d.writeln("</tr></table></font>");
    }
    objNodeDiv.innerHTML = d;
    
    var objChildNodesLayer = document.createElement("div");
    objChildNodesLayer.setAttribute("id", "divChildren_" + this.id);
    objChildNodesLayer.style.position = "relative";
    objChildNodesLayer.style.display = (this.expanded ? "block" : "none");
    objNodeDiv.appendChild(objChildNodesLayer);
    
    for (var i=0; i < this.childNodes.length; i++)
        this.childNodes[i].addToDOM(objChildNodesLayer);
}

jsTreeNode.prototype.collapse = function () {
    if (!this.expanded) {
       // throw "Node is already collapsed"        document.write('Node is already collapsed');
    } else {
        this.expanded = false;
		document.images["imgPM_" + this.id].src = imgPlus.src;
        document.getElementById("divChildren_" + this.id).style.display = "none";
    }
}
jsTreeNode.prototype.expand = function () {
	  if (this.expanded) {
        //throw "Node is already expanded"
		document.write('Node is already expanded');
    } else {
        this.expanded = true;
		document.images["imgPM_" + this.id].src = imgMinus.src;
        document.getElementById("divChildren_" + this.id).style.display = "block";
    }
}
function jsDocument() {
	this.text = new Array();		//array to store the string
	this.write = function (str) { this.text[this.text.length] = str; }
	this.writeln = function (str) { this.text[this.text.length] = str + "\n"; }
	this.toString = function () { return this.text.join(""); }
	this.clear = function () { delete this.text; this.text = null; this.text = new Array; }
}