/*
    ------------------------------------------------------------
    menu.js                                        build up menu 
    CopyRight (c) TFM Productions (Prosan, http://www.prosan.org)

    var tm_Menu = new Menu("<titel>");
    ------------------------------------------------------------
*/


function Menu(menuName) {
    this.menu       = new Array();
    this.menuParm   = new Array();
    this.menuName   = menuName;
    this.getMenu();
    this.createMenuArray();
    this.activateTriggers();
}

Menu.prototype = {
    xmlReceived     :2,
    xmlMenuArr      :false,
    menu            :false,
    menuParm        :false,
    ajaxMenu        :false,
    xmlMenuParmArr  :false,
    ajaxMenuParm    :false,
    AdjustPosition  :false,
    menuBuilt       :false,
    Regel           :"",
    dhtml           :false,
    DU_TimeOut      :false,

    // httpRequest ----------------------------------------
    getMenu:function() {
        if(!this.ajaxMenu) this.ajaxMenu = new httpRequest();
        var self = this;
        this.ajaxMenu.callback = function() { self.fillMenu(); }
        this.ajaxMenu.requestType = "POST";
        this.ajaxMenu.makeRequest("../../book/xmlreq/qrymenu.php", "menu=" + this.menuName);
        if(!this.ajaxMenuParm) this.ajaxMenuParm = new httpRequest();
        var self = this;
        this.ajaxMenuParm.callback = function() { self.fillMenuParm(); }
        this.ajaxMenuParm.requestType = "POST";
        this.ajaxMenuParm.makeRequest("../../book/xmlreq/qrymenuparm.php", "menu=" + this.menuName);
    },

    // Callback from getList ----------------------------------------
    fillMenu:function(httprequest) {

        var xmldoc;

        if(xmldoc = this.ajaxMenu.xmlResponse()) {
            var xmlroot = xmldoc.documentElement;
            this.xmlMenuArr = xmlroot.getElementsByTagName("MenuItem");
            this.xmlReceived--;
        }
    },
    
    // Callback from getList ----------------------------------------
    fillMenuParm:function(httprequest) {

        var xmldoc;

        if(xmldoc = this.ajaxMenuParm.xmlResponse()) {
            var xmlroot = xmldoc.documentElement;
            this.xmlMenuParmArr = xmlroot.getElementsByTagName("MenuParameter");
            this.xmlReceived--;
        }
    },
    
    createMenuArray:function() {
        if(this.xmlReceived) {
            var self = this;
            setTimeout(function() { self.createMenuArray(); }, 100);
        } else {
            for(var x=0; x < this.xmlMenuArr.length; x++) {
                this.menu[x] = new menuItem(this.xmlMenuArr[x], this.menuLayout);
            }
            for(var x=0; x < this.xmlMenuParmArr.length; x++) {
                this.menuParm[x] = new menuParm(this.xmlMenuParmArr[x], this.menuParmLayout);
            }
            this.buildMenu(0);
        }
    },

    activateTriggers:function() {
        var self = this;
        if(!this.menuBuilt) {
            setTimeout(function() { self.activateTriggers(); }, 400);
        } else {
            this.dhtml = new dhtmlApi();
            try {
                document.getElementById("DIV_" + this.menuName).innerHTML = this.Regel;
                this.addTriggers();
            } catch(e) {
                setTimeout(function() { self.activateTriggers(); }, 800);
            }
        }
    },

    buildMenu:function(Level) {

        var C_Vertical   = 0;
        var C_Horizontal = 1;
        var C_Relative   = 2;

        var C_TextLength = 2;
        var C_Fixed      = 1;
        var C_Calculated = 0;
        var NrSep        = 0;
        var NrCells      = 0;

        var isIE = (document.all)?1:0;
        var mp   = this.menuParm[(Level)?1:0];
        var mp1  = this.menuParm[1];

        // alert(this.menu.length);
        for(var x in this.menu) {
            // alert(this.menu[x].display());
            if(this.menu[x].MenuID == Level) {
                NrCells++;
                if(this.menu[x].Separator != 0) NrSep++;
            }
        }

        var CellHeight = mp.Height + isIE * (2 * mp.Border + mp.Padding_top + mp.Padding_bottom);         // Totale celhoogte
        var Y_Offset = mp.Height + 2 * mp.Border + mp.Padding_top + mp.Padding_bottom;
        var Position = "absolute";
        if(!Level) {                                                // Hoofdmenu
            if(mp.Orientation & C_Horizontal == C_Vertical) {
                var Hoogte = CellHeight * NrCells + NrSep;
                var Breedte = mp.Width + isIE * (2 * mp.Border + mp.Padding_left + mp.Padding_right);
            } else {
                var Hoogte  = mp.MenuHoogte + isIE * (2 * mp.Border + mp.Padding_top + mp.Padding_bottom);
                var Breedte = mp.MenuBreedte + isIE * (2 * mp.Border + mp.Padding_left + mp.Padding_right);
            }
            this.Regel +=
                "<Div Name=" + this.menuName + " id=" + this.menuName +
                " style='white-space:nowrap;z-index:" + mp.Z_Index +
                ";position:" + ((mp.Orientation & C_Relative)?"relative":"absolute") +
                ";top:" + mp.Y_Pos + "px" +
                ";left:" + mp.X_Pos + "px" +
                ";height:" + Hoogte + "px" + 
                ";width:" + Breedte + "px" +
                ";padding-left:" + mp.Padding_left + "px" +
                ";padding-right:" + mp.Padding_right + "px" +
                ";padding-bottom:" + mp.Padding_bottom + "px" +
                ";padding-top:" + mp.Padding_top + "px" +
                ";cursor:pointer" +
                ";background-color:" + mp.BGColor +
                ";background-image:" + ((mp.BGImage == "")?"url(null)":"url(" + mp.BGImage + ")") +
                ";border:" + mp.Border + "px solid" +
                ";border-color: " + mp.BorderColorBottom + " " +
                                        mp.BorderColorLeft + " " +
                                        mp.BorderColorTop + " " +
                                        mp.BorderColorRight +
                ";visibility:visible'>\n";
        }

        /* Dimensies bepalen */

        var CellWidth = 0;
        var X_Offset  = 0;
        if(mp.Orientation & C_Horizontal == C_Horizontal) {
            switch(mp.Text_Position) {
                case C_Calculated:
                    CellWidth = Math.floor((mp.Width - (NrSep * 2)) / NrCells);
                    break;
                case C_Fixed:
                    CellWidth = mp.Width + isIE * 2 * (mp.Border + mp.Padding_right + mp.Padding_left);
                    X_Offset = mp.Width + 2 * (mp.Border + mp.Padding_right + mp.Padding_left);
                    break;
                case C_TextLength:
                    break;
            }
        } else {
            CellWidth = mp.Width + isIE * 2 * (mp.Border + mp.Padding_right + mp.Padding_left);
        }

        var Seps   = 0;
        var CellNo = 0;
        var Hor    = 0;
        var Offset = 0;

        for(var x=0; x<this.menu.length; x++) {
            if(this.menu[x].MenuID==Level) {
                var Vert = (mp.Orientation & C_Horizontal == C_Horizontal)?0:(CellNo * (Y_Offset) + Seps);
                if(mp.Text_Position == C_TextLength) {
                    Hor+=Offset;
                    Offset = Number(this.menu[x].Breedte);
                } else {
                    Hor  = (mp.Orientation & C_Horizontal == C_Horizontal)?(X_Offset * CellNo + Seps * 2):0;
                }

                this.Regel += "<Div Name=" + this.menuName + "_" + x + " id=" + this.menuName + "_" + x +
                    " style='white-space:nowrap;z-index:" + (mp.Z_Index + 1 + Level) +
                    ";position:absolute" +
                    ";top:" + Vert + "px" +
                    ";left:" + Hor + "px" +
                    ";height:" + CellHeight + "px" + 
                    ";width:" + ((CellWidth)?CellWidth:Offset) + "px" +
                    ";cursor:pointer" +
                    ";background-image:" + ((mp.BGImage == "")?"url(null)":"url(" + mp.BGImage + ")") +
                    ";background-color:" + mp.BGColor +
                    ";color:" + mp.FGColor +
                    ";padding-left:" + mp.Padding_left + "px" +
                    ";padding-right:" + mp.Padding_right + "px" +
                    ";padding-bottom:" + mp.Padding_bottom + "px" +
                    ";padding-top:" + mp.Padding_top + "px" +
                    ";font-family:" + mp.Font +
                    ";font-size:" + mp.FontSize + "pt" +
                    ";font-weight:" + mp.FontWeight + 
                    ";text-align:" + ((!Level && (mp.Orientation & C_Horizontal) && !mp.Text_Align)?"center":"left") +
                    ";border: " + mp.Border + "px solid" +
                    ";border-color: " + mp.BorderColorTop + " " +
                                        mp.BorderColorRight + " " +
                                        mp.BorderColorBottom + " " +
                                        mp.BorderColorLeft +
                    ";visibility:inherit'>" +
                    "<SPAN id=" + this.menuName + "_" + x +
                        " style='left:" + mp.Text_X + "px" +
                        ";top:" + mp.Text_Y + "px" +
                        ";height:" + (CellHeight - mp.Text_Y) + "px" + 
                        ";width:" + ((CellWidth)?(CellWidth-mp.Text_X):Offset) + "px" +
                        ";text-align:" + ((!Level && (mp.Orientation & C_Horizontal) && !mp.Text_Align)?"center":"left") +
                        ";position:absolute'>" + this.menu[x].Text + "</SPAN>\n";

                    if((mp.Orientation & C_Horizontal) == C_Vertical && this.menu[x].Submenu != 0) {
                        this.Regel += "\n<div id=" + this.menuName + "_" + x + "_a" + " name=" + this.menuName + "_" + x + "_a" +
                            " style='top:" + Math.floor((mp1.Height - 15) /2) + "px" +
                            ";left:" + (CellWidth - 15) + "px" +
                            ";position:absolute" +
                            ";z-index:99" +
                            ";width:15px" +
                            ";height:15px" +
                            ";visibility:inherit'><img ID=" + x + "_a src=" + mp.SubMenuImage + " border=0></Div>\n";
                    }

                if(this.menu[x].Submenu != 0) {
                    var subTop = 0;
                    var subLeft = 0;
                    var subHeight = (this.menu[x].Submenu) * (mp1.Height + mp1.Padding_top + mp1.Padding_bottom + mp1.Border * 2) + 1;
                    var subWidth = mp1.Width + mp1.Padding_left + mp1.Padding_right + mp1.Border * 2 + 1;
                    for(var e in this.menu) {
                        if(this.menu[e].MenuID == this.menu[x].ID && this.menu[e].Separator) subHeight++;
                    }
                    if(mp.Orientation & C_Horizontal == C_Horizontal) {  // Hoofdmenu is horizontaal
                        subTop = CellHeight + 2 * mp.Border + mp.Padding_top + mp.Padding_bottom;
                        subLeft = mp1.X_Pos;
                    } else {                        // Hoofdmenu is verticaal
                        subTop = mp1.Y_Pos;
                        subLeft = CellWidth;
                    }
                    this.Regel +=
                        "<Div Name=" + this.menuName + "_" + x + "_s" +
                        " id=" + this.menuName + "_" + x + "_s" +
                        " style='white-space:nowrap;z-index:" + (mp.Z_Index * Level) +
                        ";position:absolute" +
                        ";top:" + subTop + "px" +
                        ";left:" + subLeft + "px" +
                        ";height:" + subHeight + "px" + 
                        ";width:" + subWidth + "px" +
                        ";cursor:pointer" +
                        ";background-color:" + mp1.ContainerColor +
                        ";border:0px solid" +
                        ";border-color: " + mp.BorderColorTop + " " +
                                            mp.BorderColorRight + " " +
                                            mp.BorderColorBottom + " " +
                                            mp.BorderColorLeft +
                        ";visibility:hidden'>\n";
                    this.buildMenu(this.menu[x].ID);
                }

                this.Regel += "</DIV>\n";

                if(this.menu[x].Separator != 0) {
                    var Shor = Hor;
                    var Svert = Vert;
                    if(mp.Orientation & C_Horizontal == C_Horizontal) {
                        Shor += (CellWidth + Offset);
                        Seps  += 2;
                        this.Regel += "<Div name=" + this.menuName + "_" + x + "_d" +
                            " id=" + this.menuName + "_" + x + "_d" +
                            " style='white-space:nowrap;z-index:" + (mp.Z_Index + 1) +
                            ";position:absolute" +
                            ";top:" + (Svert + 4) + "px" +
                            ";left:" + Shor + "px" +
                            ";height:" + (mp.Height - 6) + "px" +
                            ";width:1px" +
                            ";background-color:" + mp.Sep_Color +
                            ";color:" + mp.FGColor +
                            ";padding-left:" + mp.Padding_left + "px" +
                            ";padding-right:" + mp.Padding_right + "px" +
                            ";padding-bottom:" + mp.Padding_bottom + "px" +
                            ";padding-top:" + mp.Padding_top + "px" +
                            ";border:0px solid" +
                            ";font-family:" + mp.Font +
                            ";font-size:" + mp.FontSize + "pt;text-align:center" +
                            ";font-weight:normal" +
                            ";visibility:inherit'></DIV>\n";
                        Hor+= 2;
                    } else
                        Seps++ ;
                }
                CellNo++;
            }
        }
        this.Regel += "</DIV>\n";

        this.menuBuilt = true;
    },

    addTriggers:function() {

        for(var x=0; x < this.menu.length; x++) {

            if(this.menu[x].Routine != "" || this.menu[x].Submenu != 0) {
                var thisObj = document.getElementById(this.menuName + "_" + x);
                if(thisObj) {
                    var self = this;
                    thisObj.onmouseover = function(evt) { self.MouseOver(evt); }
                    thisObj.onmouseout  = function(evt) { self.MouseOut(evt); }
                    thisObj.onmouseup   = function(evt) { self.Activate(evt); }
                }
            }
        }
    },

    Activate:function(evt) {

        var parms = "";
        evt = (evt)?evt:((event)?event:null);
        if(evt) {
            var Elem = (evt.target)?evt.target:((evt.srcElement)?evt.srcElement:null);
            if(Elem) {
                var mi = Elem.id.split("_");
                var x = Number(mi[mi.length - 1]);

                if(this.menu[x].Routine2) {
                    var Type = this.menu[x].Routine2.split(":");
                    if(Type[0].match(/javascript/i)) {
                        open(this.menu[x].Routine2 + "(\"" + this.menu[x].Parms2.replace(/,/g, "\",\"") + "\")", "_self");
                    } else {
                        if(this.menu[x].Parms2 != "") {
                            parms2 = "?" + this.menu[x].Parms2;
                         } 
                       open(this.menu[x].Routine2 + parms2, "_self");
                    }
                }

                if(this.menu[x].Routine) {
                    var Type = this.menu[x].Routine.split(":");
                    if(Type[0].match(/javascript/i)) {
                        open(this.menu[x].Routine + "(\"" + this.menu[x].Parms.replace(/,/g, "\",\"") + "\")", "_self");
                    } else {
                        if(this.menu[x].Parms != "") { parms = "?" + this.menu[x].Parms; } 
                        if(this.menu[x].Target) {
                            open(this.menu[x].Routine + parms, this.menu[x].Target);
                        } else {
                            open(this.menu[x].Routine + parms, "_self");
                        }
                    }
                }
            }
            evt.cancelBubble = true;
        }
    },

    MouseOver:function(evt) {
        
        evt = (evt)?evt:((event)?event:null);
        if(evt) {
            var Elem = (evt.target)?evt.target:((evt.srcElement)?evt.srcElement:null);
            if(Elem) {
                if(this.DU_TimeOut)
                    clearTimeout(this.DU_TimeOut);
                var mi = Elem.id.split("_");
                var x = Number(mi[mi.length - 1]);
                if(Elem.tagName == "SPAN")
                    Elem = document.getElementById(this.menu[x].Name + "_" + x);
                if(!isNaN(x)) {
                    var item = this.menuParm[((!this.menu[x].MenuID)?0:1)];  // check
                    this.dhtml.setBGColor(Elem, item.MO_BGColor);
                    this.dhtml.setFGColor(Elem, item.MO_FGColor);
                    this.dhtml.setBGImage(Elem, item.MO_BGImage);

                    var Style = this.dhtml.getObject(Elem);
                    for(var v in this.menu) {
                        if(this.menu[v].Submenu !=0 &&
                            v != x &&
                            this.menu[v].MenuID == this.menu[x].MenuID &&
                            this.menu[v].Visible == true) {

                            this.chkChild(this.menu[v].ID);
                            this.dhtml.hide(this.menuName + "_" + v + "_s");
                            this.menu[v].Visible = false;
                        }
                    }
                    if(this.menu[x].Submenu != 0) {
                        this.dhtml.show(Elem.id + "_s");
                        this.menu[x].Visible = true;
                    }
                }
            }
            evt.cancelBubble = true;
        }
    },

    MouseOut:function(evt) {
        
        var TargetId = "";
        var TargetTagName;

        evt = (evt)?evt:((event)?event:null);
        if(evt) {
            var Elem = (evt.target)?evt.target:((evt.srcElement)?evt.srcElement:null);
            if(Elem) {

                var Target = (evt.relatedTarget)?evt.relatedTarget:((evt.toElement)?evt.toElement:null);
                if(Target) {
                    try {
                        TargetId      = Target.id;
                        TargetTagName = Target.tagName;
                    } catch(e) {}
                }

                if(Elem.id != TargetId) {
                    var mi = Elem.id.split("_");
                    var x = Number(mi[mi.length - 1]);
                    if(Elem.tagName == "SPAN")
                        Elem = document.getElementById(this.menu[x].Name + "_" + x);
                    if(!isNaN(x)) {
                        var item = this.menuParm[((!this.menu[x].MenuID)?0:1)];  // check
                        this.dhtml.setBGColor(Elem, item.BGColor);
                        this.dhtml.setFGColor(Elem, item.FGColor);
                        this.dhtml.setBGImage(Elem, item.BGImage);
                    }

                    if(TargetId.substr(0,mi[0].length) != mi[0]) {
                        var self = this;
                        this.DU_TimeOut = setTimeout(function() { self.chkChild(0) }, this.menuParm[0].Delay);
                    }
                }
            }
            evt.cancelBubble = true;
        }
    },

    chkChild:function(MenuId) {

        for(var x in this.menu) {
            if(this.menu[x].MenuID == MenuId && this.menu[x].Submenu != 0 && this.menu[x].Visible == true) {
                this.dhtml.hide(this.menuName + "_" + x + "_s");
                this.menu[x].Visible = false;
                this.chkChild(this.menu[x].ID);
            }
        }
    },

    AdjustDivPos:function(evt) {
        
        var x=0, y=0, tempEl;

        var divObj = this.dhtml.getRawObject("DIV_" + this.menuName)

        if (document.layers) {
            x = divObj.x;
            y = divObj.y;
        } else {
            x = divObj.offsetLeft;
            y = divObj.offsetTop;
            tempEl = divObj.offsetParent;
            while (tempEl != null) {
                x += tempEl.offsetLeft;
                y += tempEl.offsetTop;
                tempEl = tempEl.offsetParent;
            }
        }

        divObj = this.dhtml.getObject(this.menuName)
        divObj.left         = x +  "px";
        divObj.top          = y + "px";
        divObj.visibility   = "visible";
    },

    printMenu:function(Target) {
        var tekst = "";
        for(var x = 0; x < this.menu.length; x++) {
            tekst += this.menu[x].display();
        }
        document.getElementById(Target).value = tekst;
    }
}

function menuItem(xmlArray, recLayout) {
    this.ID             = Number(xmlGetElement(xmlArray, "ID"));
    this.Name           = xmlGetElement(xmlArray, "MenuNaam");
    this.MenuID         = Number(xmlGetElement(xmlArray, "MenuID"));
    this.Seq            = Number(xmlGetElement(xmlArray, "VolgNr"));
    this.Text           = xmlGetElement(xmlArray, "Tekst");
    this.Image          = xmlGetElement(xmlArray, "Image");
    this.Routine        = xmlGetElement(xmlArray, "Routine");
    this.Routine2       = xmlGetElement(xmlArray, "Routine2");
    this.Target         = xmlGetElement(xmlArray, "Target");
    this.Parms          = xmlGetElement(xmlArray, "Parms");
    this.Parms2         = xmlGetElement(xmlArray, "Parms2");
    this.Authorisatie   = xmlGetElement(xmlArray, "Authorisatie");
    this.Shortcut       = xmlGetElement(xmlArray, "Shortcut");
    this.NoAuthState    = xmlGetElement(xmlArray, "NoAuthState");
    this.Breedte        = xmlGetElement(xmlArray, "Breedte");
    this.Separator      = Number(xmlGetElement(xmlArray, "Sep"));
    this.Submenu        = Number(xmlGetElement(xmlArray, "SubMenu"));
    this.DIVName        = "";
    this.Visible        = false;
    return this;
}

menuItem.prototype= {
    display:function() {
        return("\nID = " + this.ID + "\n" +
            "Name = " + this.Name + "\n" +
            "MenuID = " + this.MenuID + "\n" +
            "Volgnr = " + this.Seq + "\n" +
            "Text = " + this.Text + "\n" +
            "Image = " + this.Image + "\n" +
            "Routine = " + this.Routine + "\n" +
            "Routine2 = " + this.Routine2 + "\n" +
            "Target = " + this.Target + "\n" +
            "Parms = " + this.Parms + "\n" +
            "Parms2 = " + this.Parms2 + "\n" +
            "Authorisatie = " + this.Authorisatie + "\n" +
            "Shortcut = " + this.Shortcut + "\n" +
            "NoAuthState = " + this.NoAuthState + "\n" +
            "Breedte = " + this.Breedte + "\n" +
            "Separator = " + this.Separator + "\n" +
            "Submenu = " + this.Submenu + "\n" +
            "DIVName = " + this.DIVName + "\n" +
            "Visible = " + this.Visible + "\n");
    }
}

function menuParm(xmlArray, recLayout) {

    this.ID                 = Number(xmlGetElement(xmlArray, "ID"));
    this.Name               = xmlGetElement(xmlArray, "MenuNaam");
    this.Niveau             = Number(xmlGetElement(xmlArray, "Niveau"));
    this.X_Pos              = Number(xmlGetElement(xmlArray, "X_Pos"));
    this.Y_Pos              = Number(xmlGetElement(xmlArray, "Y_Pos"));
    this.Height             = Number(xmlGetElement(xmlArray, "Hoogte"));
    this.Width              = Number(xmlGetElement(xmlArray, "Breedte"));
    this.Font               = xmlGetElement(xmlArray, "Font");
    this.FontSize           = Number(xmlGetElement(xmlArray, "FontSize"));
    this.FGColor            = xmlGetElement(xmlArray, "FGColor");
    this.BGColor            = xmlGetElement(xmlArray, "BGColor");
    this.BGImage            = xmlGetElement(xmlArray, "BGImage");
    this.MO_Font            = xmlGetElement(xmlArray, "MO_Font");
    this.MO_FontSize        = Number(xmlGetElement(xmlArray, "MO_FontSize"));
    this.MO_FGColor         = xmlGetElement(xmlArray, "MO_FGColor");
    this.MO_BGColor         = xmlGetElement(xmlArray, "MO_BGColor");
    this.MO_BGImage         = xmlGetElement(xmlArray, "MO_BGImage");
    this.Padding            = Number(xmlGetElement(xmlArray, "Padding"));
    this.Padding_left       = Number(xmlGetElement(xmlArray, "Padding_left"));
    this.Padding_bottom     = Number(xmlGetElement(xmlArray, "Padding_bottom"));
    this.Padding_right      = Number(xmlGetElement(xmlArray, "Padding_right"));
    this.Padding_top        = Number(xmlGetElement(xmlArray, "Padding_top"));
    this.Z_Index            = Number(xmlGetElement(xmlArray, "Z_Index"));
    this.Delay              = Number(xmlGetElement(xmlArray, "Delay"));
    this.Orientation        = Number(xmlGetElement(xmlArray, "Orientation"));
    this.FontWeight         = xmlGetElement(xmlArray, "FontWeight");
    this.ContainerColor     = xmlGetElement(xmlArray, "ContainerColor");
    this.Border             = Number(xmlGetElement(xmlArray, "Border"));
    this.BorderColorLeft    = xmlGetElement(xmlArray, "BorderColorLeft");
    this.BorderColorRight   = xmlGetElement(xmlArray, "BorderColorRight");
    this.BorderColorTop     = xmlGetElement(xmlArray, "BorderColorTop");
    this.BorderColorBottom  = xmlGetElement(xmlArray, "BorderColorBottom");
    this.Text_Align         = Number(xmlGetElement(xmlArray, "Text_Align"));
    this.Sep_Color          = xmlGetElement(xmlArray, "Sep_Color");
    this.Text_Position      = Number(xmlGetElement(xmlArray, "Text_Position"));
    this.MenuHoogte         = Number(xmlGetElement(xmlArray, "MenuHoogte"));
    this.MenuBreedte        = Number(xmlGetElement(xmlArray, "MenuBreedte"));
    this.SubMenuImage       = xmlGetElement(xmlArray, "SubMenuImage");
    this.Text_X             = xmlGetElement(xmlArray, "Text_X");
    this.Text_Y             = xmlGetElement(xmlArray, "Text_Y");
}

function xmlGetElement(xmlRecord, Item) {
    if(Item) {
        var Element = xmlRecord.getElementsByTagName(Item).item(0);
        if(Element.firstChild == null) {
            return "";
        } else {
            return Element.firstChild.nodeValue;
        }
    } else return "";
}

function dhtmlApi() {
    this.init(false);
}

dhtmlApi.prototype = {
    isCSS   :false,
    isW3C   :false,
    isIE4   :false,
    isNN4   :false,
    isIE6CSS:false,

    init:function (Show) {
        if (document.images) {
            this.isCSS = (document.body && document.body.style) ? true : false;
            this.isW3C = (this.isCSS && document.getElementById) ? true : false;
            this.isIE4 = (this.isCSS && document.all) ? true : false;
            this.isNN4 = (document.layers) ? true : false;
            this.isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;

            if(Show == true) {
                alert("isCSS = " + this.isCSS +
                    "\nisW3C = " + this.isW3C +
                    "\nisIE4 = " + this.isIE4 +
                    "\nisNN4 = " + this.isNN4 +
                    "\nisIE6CSS = " + this.isIE6CSS);
            }
        }
    },

    //  -------------------------------------------------------------------------------
    // Seek nested NN4 layer from string name
    //  -------------------------------------------------------------------------------
    seekLayer:function(doc, name) {
        var theObj;
        for (var i = 0; i < doc.layers.length; i++) {
            if (doc.layers[i].name == name) {
                theObj = doc.layers[i];
                break;
            }
            // dive into nested layers if necessary
            if (doc.layers[i].document.layers.length > 0) {
                theObj = this.seekLayer(document.layers[i].document, name);
            }
        }
        return theObj;
    },

    //  -------------------------------------------------------------------------------
    // Convert object name string or object reference into a valid element object reference
    //  -------------------------------------------------------------------------------
    getRawObject:function (obj) {
        var theObj;
        if (typeof obj == "string") {
            if (this.isW3C) {
                theObj = document.getElementById(obj);
            } else if (this.isIE4) {
                theObj = document.all(obj);
            } else if (this.isNN4) {
                theObj = seekLayer(document, obj);
            }
        } else {
            // pass through object reference
            theObj = obj;
        }
        return theObj;
    },

    // Convert object name string or object reference
    // into a valid style (or NN4 layer) reference
    getObject:function (obj) {
        var theObj = this.getRawObject(obj);
        if (theObj && this.isCSS) {
            theObj = theObj.style;
        }
        return theObj;
    },

    // Set the backgroundImage of an object
    setBGImage:function (obj, Image) {
        if(Image == "") return;
        var theObj = this.getObject(obj);
        if (theObj) {
            if (this.isNN4) {
                theObj.background = "url(" + Image + ")";
            } else if (this.isCSS) {
                theObj.background = "url(" + Image + ")";
            }
        }
    },

    // Set the background color of an object
    setBGColor:function (obj, color) {
        var theObj = this.getObject(obj);
        if (theObj) {
            if (this.isNN4) {
                theObj.bgColor = color;
            } else if (this.isCSS) {
                theObj.backgroundColor = color;
            }
        }
    },

    // Set the Foreground color of an object
    setFGColor:function (obj, color) {
        var theObj = this.getObject(obj);
        if (theObj) {
            if (this.isNN4) {
                theObj.color = color;
            } else if (this.isCSS) {
                theObj.color = color;
            }
        }
    },

    // Set the visibility of an object to visible
    show:function (obj) {
        var theObj = this.getObject(obj);
        if (theObj) {
            theObj.visibility = "visible";
        }
    },

    // Set the visibility of an object to hidden
    hide:function (obj) {
        var theObj = this.getObject(obj);
        if (theObj) {
            theObj.visibility = "hidden";
        }
    }
}


