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 = "";
    getNextSiblingByElement(activeMenu).style.display = "none";
  }
  if(ref == activeMenu){
    activeMenu = null;
	setCookie("accordion_active", "", 10);
  } else {
    ref.className = "active";
    getNextSiblingByElement(ref).style.display = "block";
    activeMenu = ref;
	setCookie("accordion_active", getFirstChild(ref, "DIV").innerHTML, 10);
  }
  return false;
}

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

  }
}

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

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;


