/*
Functions to make drop-down menu appear and disappear

    2002-09-18  RG  created
*/


function toggleMenu(menuname,menustate,originObj)
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {

        //remove all spaces from menuItem names (underscores not acceptable in netscape)
        menuname = menuname.replace(/ /g,'');
        //replace all ampersands with 'and'
        menuname = menuname.replace(/&/g,'and');
        //all to lowercase
        menuname = menuname.toLowerCase();

        //loop through array of menus and hide all except current
        for (i = 0;i < aMenu.length; i++)
        {
             tempMenuname = aMenu[i];
             if ((tempMenuname != menuname)&&(document.all[tempMenuname].style.visibility == 'visible'))
             {
                  document.all[tempMenuname].style.visibility = 'hidden';
             }
        }

        if (menustate == 'visible')
        {
            //if cursor is over link set menu to disappear after delay of 1 second
            if (originObj.tagName == 'TD')
            {
                //calculate position of link
                aPosition = calculatePosition (originObj);

                //place menu adjacent to appropriate link
                document.all[menuname].style.left = aPosition[0];
                document.all[menuname].style.top = aPosition[1]+18;
                //window.timerId = window.setTimeout("alterState('" + menuname + "','hidden')", 1000);
            }
            else
            {
                //alert ('over menu');
                //if cursor is over menu, cancel timeout
                window.clearTimeout(window.timerId);
            }

            document.all[menuname].style.visibility = menustate;
        }
        else
        {
            // upon leaving link or menu set menu to disappear after delay of 1 second
            window.clearTimeout(window.timerId);
            window.timerId = window.setTimeout("alterState('" + menuname + "','hidden')", 1000);
        }

    }
}

function calculatePosition (obj)
{
     var myx = 0;
     var myy = 0;
     //loop out
     while(obj != document.body)
     {
        myx += obj.offsetLeft;
        myy += obj.offsetTop;
        obj = obj.offsetParent;
     }
    result = new Array(myx,myy);
    return result;
}

function alterState(menuname,menustate)
{
    document.all[menuname].style.visibility = menustate;
}

function highlightCell(obj)
{
    obj.style.background = "#000000";
    obj.style.color = "#FFFFFF";

    if (obj != null)
    {

        if (obj.all.length != null)
        {
            for (i = 0; i < obj.all.length; i++)
            {
                if (obj.all(i).tagName=="A")
                {
                    obj.all(i).style.background="#000000";
                    obj.all(i).style.color="#FFFFFF";
                    obj.all(i).style.textDecorationunderLine=false;
                }
            }
        }
    }
}

function unhighlightCell(obj)
{
    obj.style.background = "#CCCCCC";
    obj.style.color = "#000000";

    if (obj != null)
    {

        if (obj.all.length != null)
        {
            for (i = 0; i < obj.all.length; i++)
            {
                if (obj.all(i).tagName=="A")
                {
                    obj.all(i).style.background="#CCCCCC";
                    obj.all(i).style.color="#000000";
                }
            }
        }
    }
}

function new_doc_window(url)
{
   var features = 'toolbar=0,'+
                  'location=0,'+
                  'directories=0,'+
                  'status=0,'+
                  'resizable=1,'+
                  'menubar=0,'+
                  'scrollbars=1,'+
                  'width=560,' +
                  'height=320,' +
                  'top=0,'+
                  'left=0';

   window.open(url,"new_doc_window",features);
}