﻿function swapBanner(newImagePath)
{
    fld = document.getElementById('ctl00_BannerImage_imgbk');
    if (fld)
        fld.src = newImagePath;
}

function setCopywriteText()
{
    fld = document.getElementById('copywrite');
    if (fld)
        fld.innerHTML = '&copy ' + new Date().getFullYear() + ' The Hawley Company';
    updateMenu();

    var ua = navigator.userAgent.toLowerCase();
    if ((fld) && (ua.indexOf('safari/') != -1))
        toggleDIV('copywrite', 'none');
    
}

function ChangeColor(id, color)
{
    fld = document.getElementById(id);
    if (fld)
    	fld.className = color;
//        fld.style.color = color;
}

function changeItem()  /* is this overload needed in javascript? */
{
    changeItem(null, null, null, null)
}

function changeItem(itemNum, divName, imgPath, scrollToBottom)
{
    for (i = 1; i <= 10; i++)
        toggleDIV('Item' + i.toString(), 'none');
    for (i = 1; i <= 10; i++)
        ChangeColor('Label' + i.toString(), 'Black');

    if ((itemNum != null) && (divName != null))
    {
        toggleDIV(divName, 'block');
        ChangeColor(itemNum, 'silver');
    }
    
    if (imgPath)
        swapBanner(imgPath);

    fld = document.getElementById('divScrollable');
    if ((scrollToBottom) && (fld) && (divName))
        fld.scrollTop = fld.scrollHeight;

}

function toggleDIV(divname, setto)
{	//warning: do not user debug_ within this function
    fld = document.getElementById(divname);

    if (fld == null)
        return;

    var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
    scrl = iebody.scrollTop;
    if (scrl > 0)
        fld.style.pixelTop += scrl;

    if (setto == null)
    {
        if (fld.style.display != 'block')
            setto = 'block';
        else
            setto = 'none';
    }

    fld.style.display = setto;
    return;
}

/* If menu items are changed, added, deleted or have special meaning, this function may have to be changed to reflect the changes. 
For example: although there is no menu item for Immediate Openings, it falls under contacts menu item for display. */
function updateMenu()
{
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

    ChangeColor('mnuHome', 'Black');
    ChangeColor('mnuAbout', 'Black');
    ChangeColor('mnuAdvocacy', 'Black');
    ChangeColor('mnuCareers', 'Black');
    ChangeColor('mnuNewAccount', 'Black');
    ChangeColor('mnuContact', 'Black');
    ChangeColor('mnuVendorLinks', 'Black');
    switch (sPage)
    {
        case 'Default.aspx': ChangeColor('mnuHome', 'Silver'); break;
        case 'About.aspx': ChangeColor('mnuAbout', 'Silver'); break;
        case 'Advocacy.aspx': ChangeColor('mnuAdvocacy', 'Silver'); break;
        case 'Careers.aspx': ChangeColor('mnuCareers', 'Silver'); break;
        case 'Openings.aspx': ChangeColor('mnuCareers', 'Silver'); break;
        case 'NewAccount.aspx': ChangeColor('mnuNewAccount', 'Silver'); break;
        case 'Contact.aspx': ChangeColor('mnuContact', 'Silver'); break;
        case 'Vendors.aspx': ChangeColor('mnuVendorLinks', 'Silver'); break;
        default: ChangeColor('mnuHome', 'Silver'); break;
    }
}


