
// ----- Popup Control ----

function displaymenu(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function showchild(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["menu_position"] == "y") ? p.offsetHeight -1 : 0;
  var left = (c["menu_position"] == "x") ? p.offsetWidth + 2 : 0;
  var cposition = c["menu_changeposition"]
  for (; p; p = p.offsetParent)
  {
  
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  //c.style.left       = left+'px';
  c.style.left       = (left + cposition) +'px';
  c.style.visibility = "visible";
}

// ----- Show -----

function showmenu()
{
  var p = document.getElementById(this["menu_parent"]);
  var c = document.getElementById(this["menu_child" ]);

  showchild(p.id, c.id);

  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----

function hidemenu()
{
  var c = document.getElementById(this["menu_child"]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 50);
}

// ----- Click -----

function menuclick()
{
  var p = document.getElementById(this["menu_parent"]);
  var c = document.getElementById(this["menu_child" ]);

  if (c.style.visibility != "visible")
       showchild(p.id, c.id);
  else c.style.visibility = "hidden";

  return false;
}

// ----- Attach -----

// PARAMETERS:
// parent   - id of visible html element
// child    - id of invisible html element that will be dropdowned
// showtype - "click" = you should click the parent to show/hide the child
//            "hover" = you should place the mouse over the parent to show
//                      the child
// position - "x" = the child is displayed to the right of the parent
//            "y" = the child is displayed below the parent
// cursor   - Omit to use default cursor or check any CSS manual for possible
//            values of this field

function drawmenu(parent, child, showtype, position, cursor, loc)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);
  var moveleft = 0
  
  
  if(loc ==7){
	if (window.ActiveXObject){
		moveleft = -38
	}
	else{
		moveleft = -44
	}
  }
  

  p["menu_parent"]     = p.id;
  c["menu_parent"]     = p.id;
  p["menu_child"]      = c.id;
  c["menu_child"]      = c.id;
  p["menu_position"]   = position;
  c["menu_position"]   = position;
  c["menu_changeposition"] = moveleft

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = menuclick;
      p.onmouseout  = hidemenu;
      c.onmouseover = showmenu;
      c.onmouseout  = hidemenu;
      break;
    case "hover":
      p.onmouseover = showmenu;
      p.onmouseout  = hidemenu;
      c.onmouseover = showmenu;
      c.onmouseout  = hidemenu;
      break;
  }
}
