var ajaxBM = null;

function buildmenu()
{
  if(ajaxBM != null)
  {
    ajaxBM.doAbort();
  }
  ajaxBM = new Ajax();
  ajaxBM.url="inc/ajaxscripts/buildmenu.php";

  ajaxBM.onSuccess=successHandlerBM;
  ajaxBM.onError=errorHandlerBM;

 doActionBM();
}

function doActionBM()
{
  if(!ajaxBM.aborted)
    ajaxBM.doRequest();
}

function so_clearInnerHTML(obj) {
	while(obj.firstChild) obj.removeChild(obj.firstChild);
}

function copyAttributesBM(source, destination)
{
  var attributes = source.attributes;
  if(attributes != null)
  {
    for (var i = 0; i < attributes.length; i++)
    {
      var attributeName = attributes[i].nodeName;
      destination.setAttribute(attributeName, source.getAttribute(attributeName));
    }
  }
}

function addNodesBM(source, destination)
{
    for (var i = 0; i < source.childNodes.length; i++)
    {
      var oldnode = source.childNodes[i];
      var oldnodeName = oldnode.nodeName;
      var newnode =  null;
      if(oldnodeName == "#text")
      {
        newnode = document.createTextNode(oldnode.nodeValue);
      }
      else
      {
        newnode = document.createElement(oldnodeName);
      }
      copyAttributesBM(oldnode, newnode);
      destination.appendChild(newnode);
      addNodesBM(oldnode, newnode);
    }
}


function successHandlerBM(txt, xml)
{
  var d = document;
  var navigationdiv = d.getElementById('navigationdiv');
  so_clearInnerHTML(navigationdiv);
  var xmlelement = xml.getElementsByTagName('xmlresponse')[0];
  addNodesBM(xmlelement, navigationdiv);
}
  
function errorHandlerBM(msg)
{
  alert("Error: " + msg);
}


