if(!window.Node){
  var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}

function checkNode(node, filter){
  return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}

function getChildren(node, filter){
  var result = new Array();
  var children = node.childNodes;
  for(var i = 0; i < children.length; i++){
    if(checkNode(children[i], filter)) result[result.length] = children[i];
  }
  return result;
}

function getChildrenByElement(node){
  return getChildren(node, "ELEMENT_NODE");
}

function getFirstChild(node, filter){
  var child;
  var children = node.childNodes;
  for(var i = 0; i < children.length; i++){
    child = children[i];
    if(checkNode(child, filter)) return child;
  }
  return null;
}

function getFirstChildByText(node){
  return getFirstChild(node, "TEXT_NODE");
}

function getNextSibling(node, filter){
  for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling){
    if(checkNode(sibling, filter)) return sibling;
  }
  return null;
}
function getNextSiblingByElement(node){
        return getNextSibling(node, "ELEMENT_NODE");
}

// Menu Functions & Properties

var activeMenu = null;

function showMenu() {
        return showMenu2(this);
}

function showMenu2(ref) {
  if(activeMenu){
    activeMenu.className = "";
    var nRef = activeMenu.parentNode;
    if (!checkNode(nRef, "DIV")) nRef = activeMenu;
    getNextSiblingByElement(nRef).style.display = "none";
  }
  if(ref == activeMenu){
    activeMenu = null;
    setCookie("accordion_active", "", 10, "/");
  } else {
    ref.className = "active";
    var nRef = ref.parentNode;
    if (!checkNode(nRef, "DIV")) nRef = ref;
    getNextSiblingByElement(nRef).style.display = "block";
    activeMenu = ref;
    setCookie("accordion_active", ref.innerHTML, 10, "/");
  }
  return false;
}

function initMenu(){
  //chequeo que ya no este iniciado
  var started  = document.getElementById("menuacc").getAttribute('started');
  if (!started) started = document.getElementById("menuacc").started;
  if (started && started == 'true') {
    return;
  }
  document.getElementById("menuacc").started='true';
  document.getElementById("menuacc").setAttribute('started','true');

  var refActiveMenu = getCookie("accordion_active");
  var antActiveMenu = refActiveMenu==null?false:(refActiveMenu==""?false:true);
  var menus, menu, text, a, i, objRef;
  menus = getChildrenByElement(document.getElementById("menuacc"));
  for(i = 0; i < menus.length; i++){
    menu = menus[i];
        if (getFirstChild(menu, "UL") != null) {
                objRef = getFirstChild(menu, "DIV");
                if (objRef == null) objRef = menu;
                a = getFirstChild(objRef, "A");
                if (a == null) {
                        text = getFirstChildByText(objRef);
                        a = document.createElement("a");
                        menu.replaceChild(a, text);
                        a.appendChild(text);
                }
                a.href = "#";
                a.onclick = showMenu;
                a.onfocus = function(){this.blur()};
                if (antActiveMenu && a.innerHTML == refActiveMenu) {
                        showMenu2(a);
                } else {
                        var nRef = a.parentNode;
                        if (!checkNode(nRef, "DIV")) nRef = a;
                        getNextSiblingByElement(nRef).style.display = "none";
                }
        }

  }
}

function setCookie(c_name,value,expiredays, path) {
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=c_name+ "=" +escape(value)+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
        ((path)?";path=" + path : "" );
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

if(document.createElement) window.onload = initMenu;

