var DOM = document.getElementById?1:0;

var activename, activeno;

// show the dropdown menu with dropid

function dropmenu(dropno,dropmenus)
{
if (DOM)    // only for DOM browsers
{
  for (z = 1; z <= dropmenus; z++)
  {

     var dropid = 'drop' + z;
     var active_dropid = 'drop' + dropno;
     var active_main = 'main' + dropno;
     var dropwidth = document.getElementById(active_main).offsetWidth;
     if (dropwidth < 195)
     {
       dropwidth = 195;
     }

     // maxrightpos: max. right position of left border of the dropmenu
     var maxrightpos = document.body.offsetWidth - dropwidth + 8;
     var x = document.getElementById(active_main).offsetLeft;

     // for IE <= 7
     if(window.navigator.userAgent.indexOf("MSIE") >= 0 && window.navigator.userAgent.indexOf("MSIE 8.0") == -1)
     {
       x += 7;
     }

     // for IE 8
     if(window.navigator.userAgent.indexOf("MSIE 8.0") != -1)
     {
       x += -3;
     }

     // for IE 9
     if(window.navigator.userAgent.indexOf("MSIE 9.0") != -1)
     {
       x += -10;
     }

     // for Konqueror, Opera, Gecko
     if(window.navigator.userAgent.indexOf("KHTML")>=0 || window.navigator.userAgent.indexOf("Opera")>=0 || window.navigator.userAgent.indexOf("Gecko")>=0)
     {
       x += -3;
     }

     // x position: max. = maxrightpos, so dropmenu doesn't overlap right window border
     if (x >= maxrightpos)
     {
       x = maxrightpos;
     }
     // min. x position, so dropmenu doesn't overlap left window border
     if (x < 17)
     {
       x = 17;
     }

     if(dropid == active_dropid)
     {
       document.getElementById(active_dropid).style.width = dropwidth + "px";
       document.getElementById(active_dropid).style.left = x + "px";
       document.getElementById(active_dropid).style.visibility = 'visible';
       document.getElementById(active_dropid).onmouseover = clearclose;
       document.getElementById(active_dropid).onmouseout = t_close;
     }

     else
     {
       document.getElementById(dropid).style.visibility = 'hidden';
       // x position = 0px, if browser window size is changed
       document.getElementById(dropid).style.left = "0px";

     }

  }

  activename= 'drop', activeno = dropno;
  clearclose();
}
}
// end dropmenu()

// reset the closing timer
function clearclose()
{
  if(window.timer)
  {
      clearTimeout(timer);
  }
}

// timer for closing dropdown menus
function t_close()
{
  timer = setTimeout("closedrop()", 200);
}

// close dropdown menu
function closedrop()
{
  if(activename != undefined && activeno != undefined)
  {
    var active_dropid = activename + activeno;
    if(DOM)
    {
      document.getElementById(active_dropid).style.visibility = 'hidden';
      // x position = 0px, if browser window size is changed
      document.getElementById(active_dropid).style.left = "0px";
    }
  }
}
