<!--
//***************************************************************************
//   Empower Mobility LLC, Essex Junction, Vermont 05452
//   Copyright © 2001-06, All Rights Reserved.
//***************************************************************************
//
// FILE:        emWeb_nav.js
// AUTHOR:      Tom Jaros
// NOTICE:      Copyright Notice
//
//              This software, 'emWeb_nav.js', is provided 'AS-IS' and without any express or 
//              implied warranty.  In no event will the author or Empower Mobility LLC
//              be held liable for any damages arising from the use of this software.
//              
//              This software must not be modified or redistributed without prior written 
//              approval by the author or an authorized agent of Empower Mobility LLC.  All
//              bug fixes or enhancements will be performed by Empower Mobility LLC unless
//              otherwise noted.
//
//              Usage is also subject to the following conditions:
//
//              1. The origin of this software must not be misrepresented; you must not
//                 claim that you wrote the original software. 
//
//              2. This notice may not be removed or altered from any source distribution.
//
//***************************************************************************
var gNavLastObj                 = null,
    gNavSelectedi               = -1,
    gPageSelectedi              = -1,
    gPageSelectedj              = -1;
var gSubNavMenu                 = null;
var gNavSubFloaterOpenTimerID   = -1,
    gNavSubFloaterCloseTimerID  = -1;
//***************************************************************************
// preload
//***************************************************************************
var gSubInvertImage = new Image,
    gInvertImage = new Image;
    
gSubInvertImage.src = './images/web_cell_invert.gif';
gInvertImage.src = './images/web_subcell.gif';
//***************************************************************************
function WebGenerateID(i, m, j)
{
    var s;

    s = String(i);
    if (j != -1)
    {
        s = s + m + String(j);
    }

    return(s);
}
//***************************************************************************
function WebToggleFont(mode)
{
    var style;
    
    style = document.body.style;
    
    switch (mode)
    {
        case 0:
            style.fontSize = "8.5pt";
            style.lineHeight = 1.5;
            break;
        case 1:
            style.fontSize = "9.0pt";
            style.lineHeight = 1.5;
            break;
        case 2:
            style.fontSize = "9.5pt";
            style.lineHeight = 1.5;
            break;
        case 3:
            style.fontSize = "10.0pt";
            style.lineHeight = 1.5;            
            break;
    }
}
//***************************************************************************
function WebScriptInit()
{
    var obj;

    WebToggleFont(1);
    
    WebNavFill();

    obj = WebToolsGetObject("web_nav");
    if (obj != null)
    {
        var i, j, k, u;

        i = 0;
        j = 0;
        k = 0;

        u = String(location);
        
        k = u.indexOf("url=");
        if (k != -1)
        {
            var obj;
        
            obj = WebToolsGetObject("web_content_center_hidden");
            if (obj != null)
            {
                obj.src = u.substr(k+4);
            }               
        }
        else        
        {
            k = u.indexOf("cat=");
            if (k != -1)
            {
                i = u.charAt(k+4);
            }
    
            k = u.indexOf("page=");
            if (k != -1)
            {
                j = u.charAt(k+5);
            }
            
            if ((j == '-') || (k == -1))
            {
                WebSubNav(i, -1);
            }
            else
            {
                WebSubNav(i, j);
            }
        }
    }
}
//***************************************************************************
function WebNavFill()
{
    var obj;

    obj = WebToolsGetObject("web_nav");
    if (obj != null)
    {
        var i, s;

        s = "<table width='100%' cellpadding='0' cellspacing='0'><tr>";

        for (i = 0; i < gNav_Labels.length; i++)
        {
            s += "<td valign='middle'><div class='web_Nav_Cell' ";
            s += "onclick='javascript:WebSubNavFill(this, " + String(i) + ", true);' ";
            s += "onmouseover='javascript:WebNavFloat(this, " + String(i) + ", 1);' ";
            s += "onmouseout='javascript:WebNavFloat(this, " + String(i) + ", 2);' ";
            s += ">" + gNav_Labels[i] + "</div></td>";
        }

        s += "</tr></table>";

        obj.innerHTML = s;
    }
}
//***************************************************************************
function WebNavReset()
{
    if (gNavLastObj != null)
    {
        gNavSelectedi = -1;
        WebNavFloat(gNavLastObj, -2, 2);
    }
}
//***************************************************************************
function WebNavFloat(navObj, i, m)
{
    switch(m)
    {
        case 1:
            WebNavReset();
            navObj.style.cursor = "pointer";
            navObj.style.background = "transparent url(./images/web_cell_invert.gif) repeat-x top center";
            navObj.style.color = "#FFFFFF";
            
            if ((i >= 0) && (i != gNavSelectedi))
            {
                gNavLastObj = navObj;
                
                if (gSubNavMenu == null)
                {
                    WebSubNavFloatSetOpenTimer();
                }
                else
                {
                    WebSubNavFill(navObj, i, false);
                }

                gNavSelectedi = i;
            }
            break;
        case 2:
            WebSubNavFloatClearOpenTimer();
            if (((i >= 0) && (gSubNav_Labels[i].length == 0)) || (i != gNavSelectedi))
            {
                gNavLastObj = null;
                navObj.style.cursor = "default";
                navObj.style.background = "transparent";
                navObj.style.color = "#FFFFFF";
            }
            else if (gSubNavMenu == null)
            {
                WebNavReset();                
            }
            else
            {   
                WebSubNavFloatSetCloseTimer();
            }
            break;
    }
}
//***************************************************************************
function WebSubNavFill(navObj, i, bClick)
{
    gSubNavMenu = WebToolsGetObject("web_subnav");
    if (gSubNavMenu == null)
    {
        // not right
    }
    else if (bClick)
    {
        gSubNavMenu = null;
        
        if (gSubNav_Labels[i].length == 1)
        {
            open(gSubNav_Labels[i][0], "", "menubar=1,resizable=1,location=1,status=1,scrollbars=1,toolbar=1");
        }
        else
        {
            WebSubNav(i, -1);
        }
    }
    else
    {
        var objStyle;

        WebSubNavFloatClearCloseTimer();
        objStyle = gSubNavMenu.style;
        objStyle.visibility = "hidden";

        if (gSubNav_Labels[i].length < 2)
        {
            gSubNavMenu = null;   
        }
        else
        {
            var j, s, absX, absH1, absH2;

            s = "<table cellspacing='0' cellpadding='0'>";

            for (j = 0; j < gSubNav_Labels[i].length; j++)
            {
                s += "<tr><td align='center'";
                
                if ((j + 1) < gSubNav_Labels[i].length)
                {
                    s += "class='web_SubNav_Cell' ";
                }
                else
                {
                    s += "class='web_SubNav_LastCell' ";
                }

                s += "onclick='javascript:WebSubNav(" + String(i) + ", " + String(j) + ");' ";
                s += "onmouseover='javascript:WebSubNavFloat(this, " + String(j) + ", 1);' ";
                s += "onmouseout='javascript:WebSubNavFloat(this, " + String(j) + ", 2);'>";
                s += gSubNav_Labels[i][j] + "</td></tr>";
            }

            s += "</table>";

            gSubNavMenu.innerHTML = s;
                
            absX = WebToolsGetRealLeft(navObj);
            absH1 = absX + (navObj.offsetWidth / 2);
            absH2 = absX + (obj.offsetWidth / 2);

            WebToolsMoveLayerTo(obj, absX - (absH2 - absH1), WebToolsGetRealBottom(navObj));
            objStyle.visibility = "visible";
        }
    }
}
//***************************************************************************
function WebSubNavFloatClearOpenTimer()
{
    if (gNavSubFloaterOpenTimerID != -1)
    {
        clearTimeout(gNavSubFloaterOpenTimerID);
        gNavSubFloaterOpenTimerID = -1;
    }
}
//***************************************************************************
function WebSubNavFloatSetOpenTimer()
{
    WebSubNavFloatClearCloseTimer();
    WebSubNavFloatClearOpenTimer();
    gNavSubFloaterOpenTimerID = setTimeout("WebSubFloatOpen()", 400);
}
//***************************************************************************
function WebSubNavFloatClearCloseTimer()
{
    if (gNavSubFloaterCloseTimerID != -1)
    {
        clearTimeout(gNavSubFloaterCloseTimerID);
        gNavSubFloaterCloseTimerID = -1;
    }
}
//***************************************************************
function WebSubNavFloatSetCloseTimer()
{
    WebSubNavFloatClearCloseTimer();
    gNavSubFloaterCloseTimerID = setTimeout("WebSubFloatClose()", 1000);
}
//***************************************************************************
function WebSubFloatOpen()
{
    WebSubNavFill(gNavLastObj, gNavSelectedi, false);
}
//***************************************************************************
function WebSubFloatClose()
{
    obj = WebToolsGetObject("web_subnav");
    if (obj != null)
    {
        gSubNavMenu = null;
        obj.style.visibility = "hidden";
        WebNavReset();
    }
}
//***************************************************************************
function WebSubNavFloat(subNavObj, i, m)
{
    switch(m)
    {
        case 1:
            WebSubNavFloatClearCloseTimer();
            subNavObj.style.cursor = "pointer";
            subNavObj.style.color = "#0000EE";
            subNavObj.style.background = "transparent url(./images/web_subcell.gif) repeat-x top center";
            break;
        case 2:
            WebSubNavFloatSetCloseTimer();
            subNavObj.style.cursor = "default";
            subNavObj.style.color = "#333366";
            subNavObj.style.background = "transparent";
            break;
    }
}
//***************************************************************************
function WebSubNav(i, j)
{
    var obj;

    WebSubFloatClose();

    obj = WebToolsGetObject("web_content_center_hidden");
    if (obj != null)
    {
        obj.src = "p_" + WebGenerateID(i, "_", j) + ".html";
    }
}
//***************************************************************************
function WebSubPageInit()
{
    var u, i, j, k, s, obj1, obj2;

    i = -1;
    j = -1;
    
    u = String(location);
    
    if (u.indexOf(".html") == -1)
    {
        // skip --- this could be a CGI reloading
    }
    else if (u.indexOf("p_") == -1)
    {
        // skip --- this could be a blog archive or other embedded page needing view
    }
    else
    {
        k = u.indexOf("_");
        if (k != -1)
        {
            i = u.charAt(k+1);
            u = u.slice(k+1);
        }
    
        k = u.indexOf("_");
        if (k != -1)
        {
            j = u.charAt(k+1);
        }
    }
    
    if (i != -1)
    {
        obj1 = parent.WebToolsGetObject("web_font");
        if (obj1 == null)
        {
            // skip   
        }
        else
        {
            s = "<table width='100%' cellpadding='4' cellspacing='0'><tr valign='top'><td align='right'>";
            s += "<a href='javascript:WebToggleFont(0);'>A</a>&nbsp;&nbsp;";
            s += "<a href='javascript:WebToggleFont(1);'><big>A</big></a>&nbsp;&nbsp;";
            s += "<a href='javascript:WebToggleFont(2);'><big><big>A</big></big></a>&nbsp;&nbsp;";
            s += "<a href='javascript:WebToggleFont(3);'><big><big><big>A</big></big></big></a>&nbsp;&nbsp;";
            s += "</td></tr></table>";
            
            obj1.innerHTML = s;
        }
    }
            
    if (i != -1)
    {
        obj1 = parent.WebToolsGetObject("web_main_title");
        if (obj1 == null)
        {
            // boo
        }
        else if (i == -1)
        {
            // something bad --- leave as is   
        }
        else if ((j == -1) || (gSubNav_Labels[i][j] == null))
        {
            obj1.innerHTML = gNav_Labels[i];
        }
        else
        {
            obj1.innerHTML = gNav_Labels[i] + " &middot; " + gSubNav_Labels[i][j];
        }
    }        

    obj1 = parent.WebToolsGetObject("web_content");
    if (obj1 == null)
    {
        s = gsCompanyURL + "/index.html?";
        if (i == -1)
        {
            s += "url=" + u; 
        }
        else
        {
            s += "cat=" + String(i);
        
            if (j != -1)
            {
                s += "&page=" + String(j);    
            }    
        }
       
        location = s;
    }
    else
    {
        obj1.innerHTML = document.body.innerHTML + "<br><br><br>";
    }

    if (i != -1)
    {
        obj1 = parent.WebToolsGetObject("web_sendfriend");
        if (obj1 != null)
        {
            obj1.href = "mailto:?subject=Check out " + gsCompanyName + "!&body=" + gsCompanyURL + "%3Fcat%3D" + WebGenerateID(i, "%26page%3D", j);
        }
        
        parent.gPageSelectedi = i;
        parent.gPageSelectedj = j;
    }
}
//***************************************************************************
function WebSubPageSubNav(i, j, k)
{
    parent.WebSubNav(i, j);
    parent.gNavSelectedk = k;
}
//***************************************************************************
function WebOpenLegal()
{
    var win = 0;

    win = open("legal.html",
               "LegalWindow",
               "toolbar=no,location=no,directories=no,status=no,menubar=no," +
               "scrollbars=no,resizable=no,copyhistory=no,"+
               "top=10,left=10,width=690,height=600");

    if (win)
    {
        win.focus();
    }
}
//***************************************************************************
var gRawLink = null;
//***************************************************************************
function WebOpenRawLink(s, w, h, b, r)
{
    if (gRawLink == null)
    {
        // skip first instance
    } 
    else if (gRawLink.closed == false)
    {
        gRawLink.close();   
    }
    
    gRawLink = open(s,
                    "RawLink",
                    "toolbar=no,location=no,directories=no,status=yes,menubar=no," +
                    "scrollbars=" + b + " ,resizable=" + r + ",copyhistory=no,"+
                    "top=10,left=10,width=" + String(w) + ",height=" + String(h));

    if (gRawLink)
    {
        gRawLink.focus();
    }
}
//***************************************************************************
var gPopup = null;
//***************************************************************************
function WebOpenPopup(s)
{
    if (gPopup == null)
    {
        // skip first instance
    } 
    else if (gPopup.closed == false)
    {
        gPopup.close();   
    }
    
    gPopup = open("p_" + WebGenerateID(parent.gPageSelectedi, "_", parent.gPageSelectedj) + "_" + String(s) + ".html",
                  "Popup",
                  "toolbar=no,location=no,directories=no,status=yes,menubar=no," +
                  "scrollbars=0,resizable=no,copyhistory=no,"+
                  "top=10,left=10,width=700,height=" + String(screen.height * .60));

    if (gPopup)
    {
        gPopup.focus();
    }
}
//***************************************************************************
function WebSubPageBranch(s)
{
    open(s, "SubPageBranch", "");
}
//***************************************************************************
function WebScriptInitPopup()
{
    var obj;

    obj = WebToolsGetObject("web_closefooter");
    if (obj != null)
    {
        obj.innerHTML = "<a class='web_a_nav' href='javascript:WebCloseCurrentWindow();'>Close</a><br><br>";
    }
}
//***************************************************************************
function WebCloseCurrentWindow()
{
    close();
}
//***************************************************************************
-->
