var IE = document.all ? true : false;
var timeout;

function visible(obj,isvisible)
{
  if (isvisible)
  {
    if (IE)
      obj.style.visibility = "visible";
    else
      obj.visibility = "show";
  }
  else
  {
    if (IE)
      obj.style.visibility = "hidden";
    else
      obj.visibility = "hide";
  }
}

function GetObjTop(obj)
{
  var parentTop = 0;
  var parent = obj;

  if (IE)
  {
    parentTop += (parent.offsetHeight || 0)

    while (parent) {
      parentTop += (parent.offsetTop || 0 );
      parent = parent.offsetParent;
    }
  }
  else
  {
    parentTop = parent.pageY + parent.document.height;    
  }
  return parentTop;
}

function GetObjLeft(obj)
{
  var parentLeft = 0;
  var parent = obj;

  if (IE)
  {
    while (parent)
    {
      parentLeft += (parent.offsetLeft || 0);
      parent = parent.offsetParent;
    }
  }
  else
  {
    parentLeft = parent.pageX;
  }
  return parentLeft;
}

function show(menuName,owner)
{
  var x = 0;
  var y = 0;
  var objOwner = GetObject(owner);
  var menuObject = GetObject(menuName);

  x = GetObjLeft(objOwner);
  y = GetObjTop(objOwner);

  // adjust the top edge
  var lbottom = y + getObjHeight( menuObject );
  var wbottom = getInsideWindowHeight();
  var wtop    = getWindowTop();  
  /*if ( lbottom > ( wbottom + wtop ))
  {
    y -= ( lbottom - ( wbottom + wtop ) );
	}    
  }*/
  if ( y < wtop )    
    y = wtop;
   
  if ((menuName.indexOf('dropdown2') != -1) || (menuName.indexOf('dropdown3') != -1))
	{	
	y -=(getObjHeight( menuObject ) + 25);	
	}    

  // adjust the left edge
  var lright  = x + getObjWidth( menuObject );
  var wright  = getInsideWindowWidth();
  var wleft   = getWindowLeft();
  if ( lright > ( wright + wleft ) ) 
  {
     x -= lright - ( wright + wleft );
  }
  if ( x < wleft )
    x = wleft;
   moveObjTo(menuObject,x,y);
   hideAll(menuName);
   visible(menuObject,true);
   clearTimeout(timeout);
}

function moveObjTo(obj, x, y)
{
  if (IE)
  {
    if (x >= 0) obj.style.left = x;
    if (y >= 0) obj.style.top = y;
  }
  else
  {
    obj.moveTo(x,y);
  }
}

function GetObject(name)
{
  var obj = null;
  if (IE)
    obj = document.all(name);
  else
    obj = document.layers[name];
  return (obj);
}

function hide(menuName,now)
{
  if (now)
    visible(GetObject(menuName),false);
  else
    timeout = setTimeout("hide('" + menuName + "',true);",50);
}

function hideAll(wantedMenu)
{
  if (IE)
  {
    var eElem, aDivs = document.all.tags("DIV");
    var iDivsLength = aDivs.length;
    for(i=0; i<iDivsLength; i++)
    {
    eElem = aDivs[i];
      if (eElem.id.indexOf('dropdown') != -1)
      {
        if (eElem.id == wantedMenu) continue;
        else
        {
          if (eElem.style.visibility == "visible")
          {
            eElem.style.visibility = "hidden";
          }
        }
      }
    }
  }
  else
  {
    var eElem, doc = document;
    var iLength = doc.layers.length;
    for(i=0; i<iLength; i++) {
      eElem = doc.layers[i];
      if (eElem.id.indexOf('dropdown') != -1)
      {
        if (eElem.id == wantedMenu) continue;
        else
        {
          if (eElem.visibility == "show")
          {
            eElem.visibility = "hide";
          }
        }
      }
    }

  }
}

if (!IE) {
   var origWidth = window.innerWidth
   var origHeight = window.innerHeight
}

// Invoked by <BODY>'s onResize event handler to refresh the page for
// Navigator 4 to assist in getting positioned elements back in place
function restore() {
   if (!IE) {
      if (origWidth != window.innerWidth || origHeight != window.innerHeight) {
         //history.go(0)
        window.location.reload();
      }
   }
}

function getInsideWindowWidth() {
    var width = -1;
    if ( IE )
      width = document.body.clientWidth;
    else
      width = window.innerWidth;
    return( width );
}

function getInsideWindowHeight() {
    var height = -1;
    if ( IE )
      height = document.body.clientHeight;
    else
      height = window.innerHeight;
    return( height );
}

function getWindowLeft() {
    var x = -1;
    if ( IE )
      x = document.body.scrollLeft;
    else
      x = window.pageXOffset;
    return( x );
}

function getWindowTop() {
    var y = -1;
    if ( IE )
      y = document.body.scrollTop;
    else
      y = window.pageYOffset;
    return( y );
}

function getObjHeight( obj ) {
    if ( IE )
      return( IE ? obj.clientHeight : (obj.clip ? obj.clip.height : -1 ) );
    else
		return(obj.clip ? obj.clip.height : -1);    
      //return( 0 );
}

function getObjWidth( obj ) {
    if ( IE )
      return ( IE ? obj.clientWidth  : (obj.clip ? obj.clip.width : -1 ) );
    else
      return( 0 );
}