function $(attrName,value)
{
    return GLOBAL["HTMLDOC"].$(attrName,value)
}
function DOMDocument(rootDOMNode)
{
    //System required variables
    var type = "DOMDocument";
    this.type = "DOMDocument"
    this.LUT = new ALUT();
    
    //Class Instance Vars
    this.registered = new Array();
    this.getNodeById = getNodeById;
    this.registerNode = registerNode;
    this.getNodesByClassName = getNodesByClassName;
    this.getNodesByTagName = getNodesByTagName;
    this.removeNode = removeNode;
    this.getNodesByAttribute = $;
    this.$ = $;
    this.finalize = finalize;
    this.nodeCount = 0
    this.getGeneralEvent = getGeneralEvent;
    this.initialize = initialize;
    //this.addInnerHTML = initialize; //FRAMEWORK FUNCTION - DO NOT USE
    this.root = rootDOMNode
   
    //load the html that is already coded
    //only from the given document root
    //allows for either nodes with style defined inline
    //or nodes with style defined in a style sheet referenced
    //by an id or class name, does not allow mixed forms of styleing
    function initialize(parentNode,nodeChildren)
    {
        //------------------------------------------------------------
        //DO NOT CHANGE OR MODIFY THIS FUNCTION, took hours to get working
        //-----------------------------------------------------------
        //make a direct copy of the nodeChildren array, since it is passed by ref
        //the array gets changed when the framework adds more nodes
        
        if(nodeChildren && nodeChildren.length == 0)
            return
        var temp = nodeChildren;
        nodeChildren = new Array();
        for(var i = 0; i < temp.length; i++)
        {
            nodeChildren[i] = temp[i];
        }
        //recursive function
        //parentNode DOMNode, children Array(HTMLNode dom nodes)
        var total = nodeChildren.length
        var children = new Array()
        for(var i = 0; i < total; i++)
        {
            children.push(nodeChildren[i]);
        }
        
        for(var i = 0; i < total; i++)
        if(children[i].tagName )
        {
            //RETARDED IE PROBLEM
                //fix: only access className member once
                //original: used children[i].className or child.className, after acess
                // the variable was overwritten
                //it turns out, the childNodes array is not an array but part of the DOM tree
                //which behaves like an array, a copy is made so it does not grow and duplicates
                //are created... the className problem's cause is still unknown but the fix works
            var child = children[i]
            var cname = child.className
            var id = child.getAttribute("id")
            
            //alert(child_style.backgroundColor)
            var node = new DOMNode(child,parentNode);
            //alert(children[i].getAttribute("class"))
            if(cname && cname != "" && cname != "undefined")
            {   
                node.createAttribute("class",cname)
            }
            if(id && id != "" && id != "undefined")
            {
                node.createAttribute("id",id)
            }
            //copy in the attributes
           /*for(var i = 0; i < child.attributes.length; i++)
            {
                if(child.attributes[i].name == "style" || child.attributes[i].name == "id" ||
                   child.attributes[i].name == "class" || child.attributes[i].name == "className" ||
                   child.attributes[i].name.toLowerCase().indexOf("on") != -1 || child.attributes[i].name == "MapID" ||
                   child.attributes[i].name == "mapid")
                    continue;
                alert(child.attributes[i].name)
                node.createAttribute(child.attributes[i].name,child.attributes[i].value);
            }*/
           
            
            this.registerNode(node)
            this.initialize(node,child.childNodes)
        }
        
    }
    
    function getNodeCount()
    {
        return this.registered.length
    }
    
    function registerNode(newNode)
    {
        var i = this.registered.length;
        this.nodeCount = this.nodeCount
        newNode.createAttribute("MapID","mid_"+String(i));
        this.registered.push(newNode);
        this.LUT.addNode(newNode);
    }
    
    function getNodeById(idValue)
    {
        return this.$("id",idValue)
    }
    
    function getNodesByClassName(classNameValue)
    {
        return this.$("class",classNameValue);
    }
    
    function getNodesByTagName(tagName)
    {
        return this.$("tagName",tagName);
    }
    
    
    function $(Attribute_Name,Attribute_Value)
    {
        return this.LUT.getNodes(Attribute_Name,Attribute_Value);
    }
    
    function getGeneralEvent(Event_Name,obj)
    {
        if(obj.getAttribute("MapID"))
        {
            //alert(obj.getAttribute("MapID"));
            var MID = parseInt(obj.getAttribute("MapID").split("_")[1]);
            if(MID == null){return;}
            var node = this.registered[MID];
            obj[Event_Name] = function(e)
            {
                if(node[Event_Name] != null)
                {
                    node[Event_Name](e);
                }
            }
        }
    }
    function removeNode(node)
    {
        node.parent.HTMLNode.removeChild(node.HTMLNode)
    }
    function finalize()
    {
        //setup Nodes for all events, if they are undefined, it will not be called
        var all = document.body.getElementsByTagName("*");
        for(var i = 0; i < all.length; i++)
        {
            this.getGeneralEvent("onclick",all[i])
            this.getGeneralEvent("onmouseout",all[i])
            this.getGeneralEvent("onmouseover",all[i])
            this.getGeneralEvent("onmousedown",all[i])
            this.getGeneralEvent("onmouseup",all[i])
            this.getGeneralEvent("onmousemove",all[i])
            this.getGeneralEvent("onerror",all[i])
            this.getGeneralEvent("onload",all[i])
            //all[i].onscroll = this.getGeneralEvent("onscroll",all[i])
        }
    }
}

var DOMDOCUMENT = new DOMDocument(null);
