﻿// JScript File

var xmlDoc;  
// load xml file
function loadXML(xmlFile) 
{ 
    try //Internet Explorer
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    catch(e)
    {
        try //Firefox, Mozilla, Opera, etc.
        {
            xmlDoc = document.implementation.createDocument("","",null);
        }
        catch(e)
        {
            alert(e.message);
            return;
        }
    }        

    xmlDoc.async=false; 
    xmlDoc.onreadystatechange=verify; 
    xmlDoc.load(xmlFile); 
    menu=xmlDoc.documentElement; 
} 
// verify loaded xml file ready to use
function verify() 
{  
    if (xmlDoc.readyState != 4) 
    {  
        return false;  
    } 
    return true;
}

var menuHTML = "";
var first = false;
// method created a unorder list of menu items from an XML file
// by recursing through the file and creating <ul> and <li> tags
// from information within the xml file
function createMenuItem(nodes, first, className)
{       
    var index = 0;  // local varable for looping
    var childNode;  //  local arable for single node
    if ( first == true)
    {
        //if first add inital <ul> entry 
        menuHTML += "<ul class=\"" + className +  "\" id=\"nav\" >\n"
    }
    // loop though nodes child nodes processing each completly before continuing onward.
    for (index=0; index < nodes.childNodes.length; index++)
    {                
        childNode = nodes.childNodes[index];
        // for firefox - only process element tags
        if ( childNode.nodeType == 1)
        {
            // create inital <li> for menu option
            menuHTML += "<li><a ";
            if ( childNode.getAttribute("url") != null && childNode.getAttribute("url").length > 0)
            {
                menuHTML += "href=\"" + childNode.getAttribute("url") + "\"";
            }
            else if(childNode.getAttribute("sideMenuID") != null && childNode.getAttribute("sideMenuID").length > 0)
            {
                menuHTML +=  " onclick=\"showMenu2('" + childNode.getAttribute("sideMenuID") + "');\"";
            }
            menuHTML += " >";
            menuHTML += childNode.getAttribute("title");
            menuHTML += "</a>";
            //alert(menuHTML);
            if (childNode.hasChildNodes())
            {
                // if node has childern start new unordered list and call method recusively 
                menuHTML += "\n<ul>";
                createMenuItem(childNode, false, className);
                menuHTML += "</ul>\n";
            }
            // close <li>
            menuHTML += "</li>\n";            
        }
    }
        
    if ( first == true)
    {
        //if first add closing </ul> entry 
        menuHTML += "</ul>\n"
    }
}


