<!--
//***************************************************************************
//   Empower Mobility LLC, Essex Junction, Vermont 05452
//   Copyright © 2001-08, 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;
var gNavLastBackgroundColor		= null;
	gNavLastColor				= null;
//***************************************************************************
// preload
//***************************************************************************
var gSubInvertImage = new Image,
    gInvertImage = new Image;
//***************************************************************************
gSubInvertImage.src = './images/web_cell_invert.gif';
gInvertImage.src = './images/web_subcell.gif';
//***************************************************************************
function WebCloseCurrentWindow()
{
    close();
}
//***************************************************************************
function WebGenerateID(i, m, j)
{
    var s;

    s = String(i);
    if (j != -1)
    {
        s = s + m + String(j);
    }

    return(s);
}
//***************************************************************************
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='top'><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 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 = "#000000";
            
            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 = "#000000";
            }
            else if (gSubNavMenu == null)
            {
                WebNavReset();                
            }
            else
            {   
                WebSubNavFloatSetCloseTimer();
            }
            break;
    }
}
//***************************************************************************
function WebNavReset()
{
    if (gNavLastObj != null)
    {
        gNavSelectedi = -1;
        WebNavFloat(gNavLastObj, -2, 2);
    }
}

//***************************************************************************
function WebOpenLegal()
{
    var win = 0;

    win = open("legal.html",
               "LegalWindow",
               "toolbar=no,location=no,directories=no,status=no,menubar=no," +
               "scrollbars=yes,resizable=no,copyhistory=no,"+
               "top=10,left=10,width=701,height=" + String(screen.height * .70));

    if (win)
    {
        win.focus();
    }
}
//***************************************************************************
function WebOpenPopup(s)
{
    var currentWindow;

    win = open("p_" + WebGenerateID(parent.gPageSelectedi, "_", parent.gPageSelectedj) + "_" + String(s) + ".html",
               "WebPopupWindow",
               "toolbar=no,location=no,directories=no,status=yes,menubar=no," +
               "scrollbars=yes,copyhistory=no,"+
               "top=10,left=10,width=701,height=" + String(screen.height * .70));

    if (win)
    {
        win.focus();
    }
}
//***************************************************************************
function WebOpenRawLink(s)
{
    var currentWindow;

    win = open(s,
               "WebPopupWindow",
               "toolbar=no,location=no,directories=no,status=yes,menubar=no," +
               "scrollbars=yes,copyhistory=no,resizable=yes,"+
               "top=10,left=10,width=701,height=" + String(screen.height * .70));

    if (win)
    {
        win.focus();
    }
}
//***************************************************************************
function WebScriptInit()
{
    var obj, objViewPC, objViewCE;

    objViewPC = WebToolsGetObject("web_view_windowspc");
    objViewCE = WebToolsGetObject("web_view_windowsce");
    
    if ((objViewPC == null) || (objViewCE == null))
    {
        // trouble in paradise
    }
    else if (ieCE != -1)
    {
		// @@@@@ to do!    
	}    
    else
    {
        WebToggleFont(0);
        WebNavFill();
        
        obj = WebToolsGetObject("web_nav");
        if (obj != null)
        {
            var i, j, bNavigate;
    
            i = 0;
            j = -1;
            bNavigate = true;
            
            if (navigator.cookieEnabled == false)
            {
	            // do nothing
            }
            else if (document.cookie != "") 
            {
                var r, dt, rt, offset, u;
                
                i = document.cookie.indexOf("eM_i");
                if (i == -1)
                {
	             	i = 0;
	             	j = -1;
                }
                else
                {
	                i = document.cookie.replace(/^.*eM_i=?([^;]*);?.*$/, '$1');
	                j = document.cookie.replace(/^.*eM_j=?([^;]*);?.*$/, '$1');
	                r = document.cookie.replace(/^.*eM_r=?([^;]*);?.*$/, '$1');
	            
	                WebSetCookiePageIndex(i, j, true);
	                WebSetCookieRefresh(true);
                
	                u = String(location);
	                if ((offset = u.indexOf("url=")) != -1)
	                {
	                    obj = WebToolsGetObject("web_content_center_hidden");
	                    if (obj != null)
	                    {
	                        bNavigate = false;
	                        obj.src = u.substr(offset+4);
	                    }               
	                }
	                else if ((offset = u.indexOf("cat=")) != -1)
	                {
	                    i = u.charAt(offset+4);
	                    if ((offset = u.indexOf("page=")) != -1)
	                    {
	                        j = u.charAt(offset+5);
	                    }
	                    
	                    gPageSelectedi = i;
	                    gPageSelectedj = j;
	                    WebSetCookiePageIndex(gPageSelectedi, gPageSelectedj, false);
	                    bNavigate = false;
	                    location = gsCompanyURL;
	                }
	                else
	                {
	                    // * Get the current time and then compare it to the last time the page was unloaded.
	                    // * Assume that if 5 seconds has past since the page was unloaded, the page is not being refreshed and
	                    //   reset i and j so it's a new page
	                    
	                    dt = new Date();
	                    rt = Number(r);
	                    
	                    if ((rt != NaN) && ((rt + 5000) < dt.getTime()))
	                    {
	                        i = 0;
	                        j = -1;
	                    }
	                }
                }
            }
            
            if (bNavigate == true)
            {
                WebSubNav(i, j);
            }
        }
    }
}
//***************************************************************************
function WebScriptInitPopup()
{
    var obj, objViewPC, objViewCE;

    objViewPC = WebToolsGetObject("web_view_windowspc");
    objViewCE = WebToolsGetObject("web_view_windowsce");
    
    if ((objViewPC == null) || (objViewCE == null))
    {
        // trouble in paradise
    }
    else
    {
        
    }
    
    obj = WebToolsGetObject("web_closefooter");
    if (obj != null)
    {
        obj.innerHTML = "<a class='web_a_nav' href='javascript:WebCloseCurrentWindow();'>Close</a><br><br>";
    }
}
//***************************************************************************
function WebScriptUnInit()
{
    WebSetCookiePageIndex(gPageSelectedi, gPageSelectedj, false);
    WebSetCookieRefresh(false);
}
//***************************************************************************
function WebSetCookiePageIndex(i, j, bReset)
{
    var expires;
    
    if (bReset == true)
    {
        expires = new Date("January 1, 1970");
    }
    else
    {
        expires = new Date();
        expires.setFullYear(expires.getFullYear()+1);
    }
    
    document.cookie = "eM_i=" + String(i) + "; path=/" +  "; expires=" + expires.toGMTString();
    document.cookie = "eM_j=" + String(j) + "; path=/" +  "; expires=" + expires.toGMTString();
}
//***************************************************************************
function WebSetCookieRefresh(bReset)
{
    var expires, r;
    
    if (bReset == true)
    {
        expires = new Date("January 1, 1970");
    }
    else
    {
        expires = new Date();
        r = expires.getTime(); 
        expires.setFullYear(expires.getFullYear()+1);
    }
    
    document.cookie = "eM_r=" + String(r) + "; path=/" +  "; expires=" + expires.toGMTString();
}
//***************************************************************************
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]);
        }
        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' class='web_SubNav_Cell' ";

                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 WebSubNavFloatClearCloseTimer()
{
    if (gNavSubFloaterCloseTimerID != -1)
    {
        clearTimeout(gNavSubFloaterCloseTimerID);
        gNavSubFloaterCloseTimerID = -1;
    }
}
//***************************************************************************
function WebSubNavFloatClearOpenTimer()
{
    if (gNavSubFloaterOpenTimerID != -1)
    {
        clearTimeout(gNavSubFloaterOpenTimerID);
        gNavSubFloaterOpenTimerID = -1;
    }
}
//***************************************************************
function WebSubNavFloatSetCloseTimer()
{
    WebSubNavFloatClearCloseTimer();
    gNavSubFloaterCloseTimerID = setTimeout("WebSubFloatClose()", 1000);
}
//***************************************************************************
function WebSubNavFloatSetOpenTimer()
{
    WebSubNavFloatClearCloseTimer();
    WebSubNavFloatClearOpenTimer();
    gNavSubFloaterOpenTimerID = setTimeout("WebSubFloatOpen()", 0);
}
//***************************************************************************
function WebSubFloatClose()
{
    obj = WebToolsGetObject("web_subnav");
    if (obj != null)
    {
        gSubNavMenu = null;
        obj.style.visibility = "hidden";
        WebNavReset();
    }
}
//***************************************************************************
function WebSubFloatOpen()
{
    WebSubNavFill(gNavLastObj, gNavSelectedi, false);
}
//***************************************************************************
function WebSubNav(i, j)
{
    var obj;

    WebSubFloatClose();

    obj = WebToolsGetObject("web_content_center_hidden");
    if (obj != null)
    {
        obj.src = "p_" + WebGenerateID(i, "_", j) + ".html";
    }
}
//***************************************************************************
function WebSubNavFloat(subNavObj, i, m)
{
	
    switch(m)
    {
        case 1:
            WebSubNavFloatClearCloseTimer();
            subNavObj.style.cursor = "pointer";
            
            gNavLastColor = subNavObj.style.color; 
            gNavLastBackgroundColor = subNavObj.style.backgroundColor; 
            subNavObj.style.color = "#0000EE";
            subNavObj.style.backgroundColor = "#CCCCFF";
            break;
        case 2:
            WebSubNavFloatSetCloseTimer();
            subNavObj.style.cursor = "default";
            subNavObj.style.color = gNavLastColor;
            subNavObj.style.backgroundColor = gNavLastBackgroundColor;
            break;
    }
}
//***************************************************************************
function WebSubPageInit()
{
    var u, 
        i, 
        j, 
        offset, 
        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
    {
        offset = u.indexOf("_");
        if (offset != -1)
        {
            i = u.charAt(offset+1);
            u = u.slice(offset+1);
        }
    
        offset = u.indexOf("_");
        if (offset != -1)
        {
            j = u.charAt(offset+1);
        }
    }
    
    // add the font tweak interface to the parent page
    
    if (i != -1)
    {
        // depending on how the sub page is being loaded, we may not find this ... it's OK.
        
        obj1 = parent.WebToolsGetObject("web_logo");
        if (obj1 != null)
        {
            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;
        }
    }
            
    // add the title to the parent page
    
    if (i != -1)
    {
        obj1 = parent.WebToolsGetObject("web_main_title");
        if (obj1 == null)
        {
            // boo
        }
        else if (i == -1)
        {
            // something bad --- leave as is   
        }
        else if (i >= gNav_Labels.length)
        {
            // this is not your standard page 
            
            obj2 = WebToolsGetObject("web_main_title");
            if (obj2 != null)
            {
                obj1.innerHTML = "&#187;&nbsp;" + obj2.innerHTML;    
            }
        }
        else if ((j == -1) || (gSubNav_Labels[i][j] == null))
        {
            obj1.innerHTML = "&#187;&nbsp;" + gNav_Labels[i];
        }
        else
        {
            obj1.innerHTML = "&#187;&nbsp;" + gNav_Labels[i] + " &middot; " + gSubNav_Labels[i][j];
        }
    }        

    // add the left column content to the parent page, if we find both divisions of course
    
    if (i != -1)
    {
        obj1 = parent.WebToolsGetObject("web_content_left");
        obj2 = WebToolsGetObject("web_content_left_hidden");
        if (obj1 == null)
        {
            // not supposed to happen   
        }
        else if (obj2 == null)
        {
            obj1.innerHTML = "";
        }
        else
        {
            obj1.innerHTML = obj2.innerHTML;   
        }
    }

    // add the center column content to the parent page - if we're subpage we need to load the parent page first.
    
    obj1 = parent.WebToolsGetObject("web_content_center");
    if (obj1 == null)
    {
        s = gsCompanyURL;
        
        if (i == -1)
        {
            s += "/index.html?url=" + u; 
        }
        else
        {
            // remember the sub page for later
            
            WebSetCookiePageIndex(i, j, false);
            WebSetCookieRefresh(true);
        }
        
        // replace the sub page so the back button doesn't show
        
        location.replace(s);
    }
    else
    {   
        s = document.body.innerHTML + "<br><br>";
        s += "<table cellpadding='0' cellspacing='0' width='100%' border='0'>";
        s += "<tr><td align='right'>{<a id='web_sendfriend'><span class='web_SendTo_Friend'>Send this page to a friend</span></a>}</td></tr>";
        s += "</table>";
                
        // set the parent center column with this subpage's text
        
        //parent.document.title = document.title;
        obj1.innerHTML = s;
    }
    
    // add the right column content to the parent page, if we find both divisions of course

    if (i != -1)
    {
        obj1 = parent.WebToolsGetObject("web_content_right");
        obj2 = WebToolsGetObject("web_content_right_hidden");
        if (obj1 == null)
        {
            // not supposed to happen
        }
        else if (obj2 == null)
        {
            obj1.innerHTML = "";
        }
        else
        {
            obj1.innerHTML = obj2.innerHTML;
        }        
    }
    
    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 WebSubPageBranch(s)
{
    open(s, "SubPageBranch", "");
}
//***************************************************************************
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 = "10.0pt";
            style.lineHeight = 1.5;
            break;
        case 3:
            style.fontSize = "11.0pt";
            style.lineHeight = 1.5;            
            break;
    }
}
//***************************************************************************
-->
