
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;

}

function formattedDate(d){
   var day   = d.getDate();
   var month = d.getMonth() + 1;
   var year  = d.getYear();

  if(year < 2000 && year >= 100) {
    year = (year - 100) + 2000;
  }

   return (day<10?"0"+day:day) + "/" + (month<10?"0"+month:month) + "/" + year;
}

function dateLastUpdate(){
   var originalDate = document.lastModified;
   var d = new Date(Date.parse(originalDate));

   return formattedDate(d);
}

