var activeId = null;
var activeEl = null;
var allowed_browser = setAllowedBrowser();

function setAllowedBrowser() {
  allowed_browser = false; // set initial value.
  information = getBrowserInfo();

  switch(information[1]){
  case "Netscape" : 
    version = information[2].substr(0,3);
    if (version >= 5)
      allowed_browser = true;
    break;
  case "Microsoft Internet Explorer":
    version = information[2].substr(22,3);
    if (version >= 5.5)
      allowed_browser = true;
    break;
  case "Opera":
    version = information[2].substr(0,3);
    if (version >= 7.2)
      allowed_browser = true;
    break;
  default: allowed_browser = false;
  }

  return allowed_browser;
}


function getBrowserInfo() {
  code = navigator.appCodeName;
  app = navigator.appName;
  ver = navigator.appVersion;
  agent = navigator.userAgent;
  return [code, app, ver, agent];
}


function dropDown(event, targetId) {
  var callerObj = document.getElementById(targetId);
  if(allowed_browser){
    setActiveMenu(callerObj, targetId);
    activateMenu();
  }
}

function setActiveMenu(el, id) {
  if(el != null && id) {
    if(activeEl != null && typeof activeEl == "object") {
      resetPreviousActiveMenu();
      deactivateMenu();
    }
    activeId = id;
    activeEl = el;
  }
  else {
    deactivateMenu();
  }
}

function resetPreviousActiveMenu() {
  if(activeEl != null && typeof activeEl == "object") {
    activeEl.className = activeEl.className.replace("Active","");
  }
}

function activateMenu() {
  if(activeEl != null && typeof activeEl == "object") {
    if(activeEl.getElementsByTagName("ul").length >= 1) {
      activeEl.className = activeEl.className + "Active";
      activateChildren();
    }
  }
}

function deactivateMenu() {
  resetPreviousActiveMenu();
  deactivateChildren();
  activeEl = null;
  activeId = null;
}

function activateChildren() {
  creche = document.getElementById(activeId + "-creche");
  if(creche != null && typeof creche == "object") {
    creche.style.left = activeEl.offsetLeft + "px";
    creche.style.top = activeEl.offsetHeight + "px";
    creche.style.visibility = "visible";
  }
}

function deactivateChildren() {
  creche = document.getElementById(activeId + "-creche");
  if(creche != null && typeof creche == "object") {
    creche.style.visibility = "hidden";
  }
}

function closeDropDown(obj) {
  if(allowed_browser){
    if(activeEl != null && typeof activeEl == "object") {
      deactivateMenu();
    }
  }
}

