//*************************************************************************
function PopupWindow2 (PopURL, PopName, PopWidth, PopHeight)
{
  NewWindow = window.open(PopURL, PopName, "width=" + PopWidth + ",height=" + PopHeight + ",status=no,toolbar=no,location=no,scrollbars=no,resizable=no,titlebar=no");
  if (!((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.substring(0, 3) < "3")))
  {
    NewWindow.focus();
  }
}

//*************************************************************************
/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2003 by Sharon Paine
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

var menuSharesFunds = {
  timer: null,
  activeMenuID: null,
  offX: 5,   // horizontal offset
  offY: 2,   // vertical offset
  //itemCode is either a SecurityID or a FundID
  //itemLocation is either an ExchangeID (for securities) or a CountryID (for Funds)
  show: function(itemCode,itemLocation, itemType, blnWatchList, e) {

  var myDiv
  // Shares Menu
  if (itemType == 1)
    {
    id = "menuShares";
    var WatchSharesRow = document.getElementById("menuSharesRow1");
    if (!blnWatchList)
       {
       WatchSharesRow.style.display="none";
       }
    else
       {
       WatchSharesRow.style.display="";
       }


    //<% If IsBlank(Session("intSubscriberID")) Then %><img src=\"/images/home/padlock.gif\" align=\"absmiddle\" width=\"12\" height=\"15\" border=\"0\"><% End If %>&nbsp;

    myDiv= document.getElementById('menuSharesCell01');
    myDiv.innerHTML = "<a href=\"javascript: PopupWindow2('/my_watchlist/PopupAdd.asp?ItemType=1&SecurityID=" + itemCode + "&ExchangeID=" + itemLocation + "', '_blank', 400, 150)\">Add to My Watchlist</a>"
    myDiv= document.getElementById('menuSharesCell02');
    myDiv.innerHTML = "<a href=\"/company_profile/summary/default.asp?SecurityID=" + itemCode + "&ExchangeID=" + itemLocation + "\" target=\"_blank\">Company Profile</a>"
    //myDiv= document.getElementById('menuSharesCell03');
    //myDiv.innerHTML = "&nbsp;<a href=\"javascript: PopupWindow('http://www.bourseinvestor.com/Cobrands/IS/pages/default.asp?asxcode=" + itemCode + "&siteid=is', '_blank', 676, 700)\">Prices and Charts</a>"
    myDiv= document.getElementById('menuSharesCell04');
    myDiv.innerHTML = "<a href=\"/company_profile/consensus/default.asp?section=4&SecurityID=" + itemCode + "&ExchangeID=" + itemLocation + "\" target=\"_blank\">Broker Consensus</a>"
    myDiv= document.getElementById('menuSharesCell05');
    myDiv.innerHTML = "<a href=\"/company_profile/announcements/default.asp?section=5&SecurityID=" + itemCode + "&ExchangeID=" + itemLocation + "\" target=\"_blank\">Company Announcements</a>"
    }
  // Funds Menu
  if (itemType == 2)
    {
    id = "menuFunds";
    var WatchFundsRow = document.getElementById("menuFundsRow1");
    if (!blnWatchList)
       {
       WatchFundsRow.style.display="none";
       }
    else
       {
       WatchFundsRow.style.display="";
       }


    myDiv= document.getElementById('menuFundsCell01');
    myDiv.innerHTML = "<a href=\"javascript: PopupWindow2('/my_watchlist/PopupAdd.asp?ItemType=2&ItemCode=" + itemCode + "', '_blank', 400, 150)\">Add to My Watchlist</a>"
    myDiv= document.getElementById('menuFundsCell02');
    myDiv.innerHTML = "<a href=\"/funds/profile.asp?FundID=" + itemCode + "\" target=\"_blank\">Fund Profile</a>"
    }



  var mnu = document.getElementById? document.getElementById(id): null;
  if (!mnu) return;
  this.activeMenuID = id;
  if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
  if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
  viewport.getAll();
  this.position(mnu,e);
  },

  hide: function() {
    this.clearTimer();
    if (this.activeMenuID && document.getElementById)
      this.timer = setTimeout("document.getElementById('"+menuSharesFunds.activeMenuID+"').style.visibility = 'hidden'", 200);
  },

  position: function(mnu, e) {
    var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
    var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;

    if ( x + mnu.offsetWidth + this.offX > viewport.width + viewport.scrollX )
      x = x - mnu.offsetWidth - this.offX;
    else x = x + this.offX;

    if ( y + mnu.offsetHeight + this.offY > viewport.height + viewport.scrollY )
      y = ( y - mnu.offsetHeight - this.offY > viewport.scrollY )? y - mnu.offsetHeight - this.offY : viewport.height + viewport.scrollY - mnu.offsetHeight;
    else y = y + this.offY;

    mnu.style.left = x + "px"; mnu.style.top = y + "px";
    this.timer = setTimeout("document.getElementById('" + menuSharesFunds.activeMenuID + "').style.visibility = 'visible'", 400);
  },

  mouseoutCheck: function(e) {
    e = e? e: window.event;
    // is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
    var mnu = document.getElementById(menuSharesFunds.activeMenuID);
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !menuSharesFunds.contained(toEl, mnu) ) menuSharesFunds.hide();
  },

  // returns true of oNode is contained by oCont (container)
  contained: function(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode = oNode.parentNode )
      if ( oNode == oCont ) return true;
    return false;
  },

  clearTimer: function() {
    if (menuSharesFunds.timer) clearTimeout(menuSharesFunds.timer);
  }

}
//*************************************************************************
function hideShow(id)
{
  var el=document.getElementById(id);
  if(el.style.display!="none")
    {
    el.style.display="none";
    }
  else
    {
    el.style.display="";
    }
}
