    var undefined;
    String.prototype.equals = function (item) {
        return (this == item);
    }

    function TreeItem(parent, data, after) {
        this.parent = null;
        this.data = data;
        this.children = new Array();

        if (parent != null) {
            parent.add(this, after);
        }
    }

    /**
     *  Adds to the end of the items children collection
     */
    TreeItem.prototype.add = function(item, after) {
        item.parent = this;
        
        if (after == null) {
            this.children[this.children.length] = item;
        }
        else {
            var index = 0;
            for (var i=0; i < this.children.length; i++) {
                if (this.children[i] == after) {
                    index = i + 1;
                    break;
                }
            }
            
            this.children.splice(index, 0, item);
        }
    }

    TreeItem.prototype.remove = function(item) {
        var index = -1;
        for (var i=0; i < this.children.length; i++) {
            if (this.children[i] == item) {
                index = i;
                break;
            }
        }

        if (index != -1) {
            this.children.splice(index,1);
        }
    }
    
    TreeItem.prototype.equals = function (item) {
        if(this.data.label == item.data.label && this.data.value == item.data.value && this.data.type == item.data.type){
        	return true;
        }else{
	        return false;
	    }
    }
    
    TreeItem.prototype.getNextChild =  function(currentChildItem) {
    	
    	if(currentChildItem == null && this.children.length > 0){
    		return this.children[0];
    	}
    
        for (var i = 0; i < this.children.length - 1; i++) {
            if (this.children[i].equals(currentChildItem)) return this.children[i+1];
        }

        return null;
    
    }
    
    TreeItem.prototype.getNextSibling =  function() {
    
	    var siblings = this.parent.children;
    
        for (var i = 0; i < siblings.length - 1; i++) {
            if (siblings[i].equals(this)) return siblings[i+1];
        }

        return null;
    }

    TreeItem.prototype._find = function (item, itemToFind) {
        if (item != null && item.equals(itemToFind)) return item;

        for (var i = 0; i < item.children.length; i++) {
            if (item.children[i].equals(itemToFind)) return item.children[i];

            var x = item.children[i].find(itemToFind);
            if (x != null) return x;
        }

        return null;
    }

    TreeItem.prototype.find = function(itemToFind) {
        return this._find(this, itemToFind);
    }
    
    TreeItem.prototype.moveUp = function() {
        var siblings = this.parent.children;
        for (var i=1; i < siblings.length; i++) {
            if (siblings[i] == this) {
                var temp1 = siblings[i];
                var temp2 = siblings[i-1];
                siblings[i] = temp2;
                siblings[i-1] = temp1;
                break;
            }
        }
    }

    TreeItem.prototype.moveDown = function() {
        var siblings = this.parent.children;
        for (var i=0; i < siblings.length - 1; i++) {
            if (siblings[i] == this) {
                var temp1 = siblings[i];
                var temp2 = siblings[i+1];
                siblings[i] = temp2;
                siblings[i+1] = temp1;
                break;
            }
        }
    }
    
/*    TreeItem.prototype.depthFirst = function(f) {
        var item = this;
        var m = f;
        
        if (arguments.length == 2) {
            item = arguments[1];
        }

//        f(item);
alert(item);
        
        for (var i=0; i < item.children.length; i++) {
            depthFirst(m, item.children[i]);
//            f(item.children[i]);
alert(item.children[i]);
        }
    }
*/

function showProps(obj) {
	var result = " ";
	for(var i in obj) {
		result += i + " = " + obj[i] + "<BR>"
	}
	return result
}

function showIt(docObj) {
	var newWin = window.open("","", config="width=500,height=500,left=150,scrollbars=1")
	newWin.document.write("<B>Properties: </b><BR><BR>")
	newWin.document.write(showProps(docObj))
}

