
function buildMenu(menu){

  if (menu == null){
      menu = "menu.xml"
  } 

  // Carregando o arquivo menu.xml
  xmlDoc = loadXmlFile(menu)

  // Gerando html 
  html = "";
  opennedBlock = false;

  vItems = getListOfXmlElements(xmlDoc, "item")

  for (var i = 0; i < vItems.length; i = i + 1){
    
    tipo = getXmlValue(vItems[i], "tipo");
    nome = getXmlValue(vItems[i], "nome");

    if (tipo == "grupo" && opennedBlock) {
      html += "</ul></div>\n";
      opennedBlock = false;
    }
    
    if (tipo == "grupo") {
      
      html += "<div id='sidebartop'>";
      html += nome;
      html += "</div>\n";

    } else {

      if (! opennedBlock) {
        opennedBlock = true;
	html += "<div id='sidebar'><ul class='menu'>\n";
      }

      link = getXmlValue(vItems[i], "link");
      html += "<li class='menu'><a href='" + link + "'>";
      html += nome;
      html += "</a></li>\n";
      
    }

  }

  if (opennedBlock) {
    html += "</ul></div>\n";
  }

  // Exibindo na pagina
  document.getElementById("menu").innerHTML = html;

}
