    var childActive = null 
    var menuActive = null
    var lastHighlight = null
    var active = false

    var IsOver=0;

// Finds out if a is an ancestor of b
function contains(a, b)
{
	// we climb through b parents
	// till we find a
 	while(b && (a!=b) && (b!=null))
		b = b.parentNode;
	return a == b;
}


function CheckIsOver(){
  IsOver=0;
  setTimeout("TimedCheckIsOver()",100);
}
function TimedCheckIsOver(){
  if (IsOver==0 && menuActive){
        clearHighlight(menuActive)
        closeMenu(menuActive)
        active = false
        menuActive=null
        choiceActive = null

  }

}

   
    function getReal(el) {
      // Find a table cell element in the parent chain */
      temp = el
      while ((temp!=null) && (temp.tagName!="TABLE") && (temp.className!="root") && (temp.id!="menuBar")) {
        if (temp.tagName=="TD")
          el = temp
        temp = temp.parentElement
      }
      return el
    }

    function raiseMenu(el) {

//      el.style.borderLeft = "2px #EEEEEE solid"
//      el.style.borderTop = "2px #EEEEEE solid"
//      el.style.borderRight = "2px gray solid"
//      el.style.borderBottom = "2px gray solid"
//      el.style.background="#99CC66";
    }

    function clearHighlight(el) {
      if (el==null) return
//      el.style.borderRight = "2px lightgrey solid"
//      el.style.borderBottom = "2px lightgrey solid"
//      el.style.borderTop = "2px lightgrey solid"
//      el.style.borderLeft = "2px lightgrey solid" 
//      el.style.background="#FF9900";
        el.style.color="#e9e3db";
        el.style.backgroundImage='url(images/TopNavBG.gif)';
}

    function sinkMenu(el) {
//      el.style.borderRight = "2px #EEEEEE solid"
//      el.style.borderBottom = "2px #EEEEEE solid"
//      el.style.borderTop = "2px gray solid"
//      el.style.borderLeft = "2px gray solid"
//      el.style.background="#99CC66";
        el.style.color="#d39e10";
        el.style.backgroundImage='url(images/TopNavBGSelected.gif)';
    }

    function menuHandler(menuItem) {
      // Write generic menu handlers here!
      // Returning true collapses the menu. Returning false does not collapse the menu
      return true
    }

    function getOffsetPos(which,el,tagName) {
      var mpos = 0 // el["offset" + which]
      while (el.tagName!=tagName) {
        mpos+=el["offset" + which]
        el = el.offsetParent
      }
      return mpos	
    }

    function getRootTable(el) {
      el = GetParent(el)
      if (el.tagName=="TR") 
        el = GetParent(el)
      return el
    }

    function getElement(el,tagName) {
      while ((el!=null) && (el.tagName!=tagName) )
        el = GetParent(el)
      return el
    }

    function processClick() {
          var evt = window.event || arguments.callee.caller.arguments[0];
          var el;
          if (evt.srcElement) el= evt.srcElement;
          if (evt.toElement) el=evt.toElement;
          if (evt.target) el=evt.target;
    //  var el = getReal(window.event.srcElement)
      if ((getRootTable(el).id=="menuBar") && (active)) {        
        cleanupMenu(menuActive)
        clearHighlight(menuActive)
        active=false
        lastHighlight=null
        doHighlight(el)
      }
      else {
        if ((el.className=="root") || (!menuHandler(el)))         
          doMenuDown(el)
        else {
          if (el._childItem==null) 
            el._childItem = getChildren(el)
          if (el._childItem!=null)  return;
          if ((el.id!="break") && (el.className!="disabled") && (el.className!="disabledhighlight") && (el.className!="clear"))  {
            if (menuHandler(el)) {
              cleanupMenu(menuActive)
              clearHighlight(menuActive)
              active=false
              lastHighlight=null
            }
          }
        }
      }
    }

    function getChildren(el) {
      var tList = [];
      if (el.children && el.children.tags){
         tList = el.children.tags("TABLE");
      } else {
      if (el.getElementsByTagName('TABLE')) tList = el.getElementsByTagName('TABLE');
      }
      var i = 0
      while ((i<tList.length) && (tList[i].tagName!="TABLE"))
        i++
      if (i==tList.length)
        return null
      else
        return tList[i]
    }

    function doMenuDown(el) {
      if (el._childItem==null) 
        el._childItem = getChildren(el)
      if ((el._childItem!=null) && (el.className!="disabled") && (el.className!="disabledhighlight")) {
        // Performance Optimization - Cache child element
        ch = el._childItem
        if (ch.style.display=="block") {
          removeHighlight(ch.active)
          return
        }

        ch.style.display = "block"
        if (el.className=="root") {
          ch.style.top = el.offsetHeight + el.offsetTop + 2
          ch.style.pixelLeft = el.offsetLeft + 1
	  if (ch.style.pixelWidth==0)
            ch.style.pixelWidth = ch.rows[0].offsetWidth+50
          sinkMenu(el)
          active = true
          menuActive = el
        } else {
          childActive = el
          ch.style.pixelTop = getOffsetPos("Top",el,"TABLE") -3 // el.offsetTop + el.offsetParent.offsetTop - 3
          ch.style.pixelLeft = el.offsetLeft + el.offsetWidth;
          if (!window.event){
            var templeft = el.offsetLeft + el.offsetWidth;
            ch.style.left =templeft+'px';
            ch.style.top = getOffsetPos("Top",el,"TABLE") -3
          }
	  if (ch.style.pixelWidth==0)
            ch.style.pixelWidth = ch.offsetWidth+50
        }     
      }
    }
 
    function doHighlight(el) {
     if (typeof GlobalMovePanel != 'undefined' && GlobalMovePanel) { 
        CancelBubble(el);
        return false;
      }

var evt = window.event || arguments.callee.caller.arguments[0];
el = evt.target || evt.toElement;

      el = getReal(el)
      if ("root"==el.className) {
        if ((menuActive!=null) && (menuActive!=el)) {
          clearHighlight(menuActive)
        }
        if (!active) {
          raiseMenu(el)
          doMenuDown(el)
        }          
        else 
          sinkMenu(el)
        if ((active) && (menuActive!=el)) {
          cleanupMenu(menuActive)          
          doMenuDown(el)
        }
        menuActive = el  
        lastHighlight=null
      }
      else {
        if (childActive!=null) {
          if (!contains(childActive,el)) 
            closeMenu(el,childActive)    
        }

        if (("TD"==el.tagName) && ("clear"!=el.className)) {
          var ch = getRootTable(el)         
          if (ch.active!=null) {
            if (ch.active!=el) {
              if (ch.active.className=="disabledhighlight")  
                ch.active.className="disabled"
              else
                ch.active.className=""
              }
            }
          ch.active = el
          lastHighlight = el
          if ((el.className=="disabled") || (el.className=="disabledhighlight") || (el.id=="break")) 
            el.className = "disabledhighlight"
          else {
            if (el.id!="break") {
              el.className = "highlight"
              if (el._childItem==null) 
                el._childItem = getChildren(el)
              if (el._childItem!=null) {
                doMenuDown(el)
              }
            }  
          }
        }
      }
    }

    function removeHighlight(el) {
      if (el!=null)
        if ((el.className=="disabled") || (el.className=="disabledhighlight"))  
          el.className="disabled"
        else
          el.className=""
    }

    function cleanupMenu(el) {

      if (el==null) return
      if (!el.all && el.getElementsByTagName('TABLE')) el.all = el.getElementsByTagName('TABLE');
      for (var i = el.all.length-1; i >=0; i--) {
        var item = el.all[i]
        if (item.tagName=="TABLE"){
           item.style.display = '';
        }
        removeHighlight(item.active)
        item.active=null
      }
    }

    function GetParent(ch){
      return ch.parentNode || ch.parentElement;
    }
    function closeMenu(ch, el) {
      var start = ch
      while (ch.className!="root" && GetParent(ch)!=undefined) {
          ch = ch.parentNode || ch.parentElement ;
          if (((!contains(ch,el)) && (ch.className!="root"))) {
            start=ch
          }
          
      }
      cleanupMenu(start)
    }
 

    function doCheckOut() {
      var evt = window.event || arguments.callee.caller.arguments[0];
      var el;
      if (evt.srcElement) el= evt.srcElement;
      if (evt.toElement) el=evt.toElement;
      if (evt.target) el=evt.target;
      if ((!active) && (menuActive!=null) && (!contains(menuActive,el))) {
        clearHighlight(menuActive)
        menuActive=null
      }
    }

function CancelBubble(e){
   if (window.event){
     window.event.cancelBubble=true;
     event.returnValue=false;
     event.cancelBubble = true;
     event.keyCode = 0;
   } else {
     e.preventDefault();
     e.stopPropagation();
   }
}
    function processKey(e) {
      evt = (window.event)? window.event : e;
      if (active) {
        switch (evt.keyCode) {
         case 13: lastHighlight.click(); break;
         case 39:  // right
           if ((lastHighlight==null) || (lastHighlight._childItem==null)) {
             var idx = menuActive.cellIndex
//             if (idx==menuActive.offsetParent.cells.length-2)
             if (idx==getElement(menuActive,"TR").cells.length-2)
               idx = 0
             else
               idx++
             newItem = getElement(menuActive,"TR").cells[idx]
           } else
           {
             newItem = lastHighlight._childItem.rows[0].cells[0]
           }
           if (newItem!=null)doHighlight(newItem)
           break; 
         case 37: //left
           if ((lastHighlight==null) || (getElement(getRootTable(lastHighlight),"TR").id=="menuBar")) {
             var idx = menuActive.cellIndex
             if (idx==0)
               idx = getElement(menuActive,"TR").cells.length-2
             else
               idx--
             newItem = getElement(menuActive,"TR").cells[idx]
           } else
           {
             newItem = getElement(lastHighlight,"TR")
             while (newItem.tagName!="TD")
               newItem = newItem.parentElement
           }
           doHighlight(newItem)
           break; 
         case 40: // down
            if (lastHighlight==null) {
              itemCell = menuActive._childItem
              curCell=0
              curRow = 0
            }
            else {
              itemCell = getRootTable(lastHighlight)
              if (lastHighlight.cellIndex==getElement(lastHighlight,"TR").cells.length-1) {
                curCell = 0
                curRow = getElement(lastHighlight,"TR").rowIndex+1
                if (getElement(lastHighlight,"TR").rowIndex==itemCell.rows.length-1)
                  curRow = 0
              } else {
                curCell = lastHighlight.cellIndex+1
                curRow = getElement(lastHighlight,"TR").rowIndex
              }
            }
            doHighlight(itemCell.rows[curRow].cells[curCell])
            CancelBubble(evt);
            break;
         case 38: // up
            if (lastHighlight==null) {
              itemCell = menuActive._childItem
              curRow = itemCell.rows.length-1
              curCell= itemCell.rows[curRow].cells.length-1

            }
            else {
              itemCell = getRootTable(lastHighlight)
              if (lastHighlight.cellIndex==0) {
                curRow = getElement(lastHighlight,"TR").rowIndex-1
                if (curRow==-1)
                  curRow = itemCell.rows.length-1
                curCell= itemCell.rows[curRow].cells.length-1

              } else {
                curCell = lastHighlight.cellIndex - 1
                curRow = getElement(lastHighlight,"TR").rowIndex
              }
            }
            doHighlight(itemCell.rows[curRow].cells[curCell])
            break;
           if (lastHighlight==null) {
              curCell = menuActive._childItem
              curRow = curCell.rows.length-1
            }
            else {
              curCell = getRootTable(lastHighlight)
              if (getElement(lastHighlight,"TR").rowIndex==0)
                curRow = curCell.rows.length-1
              else
                curRow = getElement(lastHighlight,"TR").rowIndex-1
            }
            doHighlight(curCell.rows[curRow].cells[0])
            break;
            CancelBubble(evt)
        }
      }
    }

function ViewMarketReport(MarketQuarter){
  RecordObjectAction('ResearchReport','Open');
  if (!MarketQuarter) SubmitComRequest(CompInfoURL+'&InPanel=1','Retrieving The Market Research Report')
  if (MarketQuarter) SubmitComRequest(CompInfoURL+'&InPanel=1&Quarter='+MarketQuarter,'Retrieving The Market Research Report')
  //drillpanel('panelCompInfo'); 
  //window.open(CompInfoURL, "MarketResearch");


}
function IsIE(){
  if (navigator.userAgent.indexOf('MSIE')> -1) return true;
  return false;
}

