/**********************************************************************
 * iNavigate.js  iNavigate 3.1 			           Aug 15, 2001
 *
 * Explorer style dynamic menu structure for MS IE 4.0+ and Netscape 6.0+.
 * 
 * FREE EDITION
 * You may use this code on public or private web sites only if this
 * copyright statement appears intact and you publicly display a link 
 * to http://www.cirkadia.com.
 * 
 * This code is provided "as is" without warranty of any kind.
 * Cirkadia further disclaims all implied warranties including fitness 
 * for any particular purpose. The entire risk arising out of the use 
 * or performace of this code remains with you.
 * 
 * Contact productinfo@cirkadia.com for any other usage.
 * 
 * SERVER, ENTERPRISE & PRODUCT EDITION
 * Your rights to use and deploy iNavigate are in accordance with the type 
 * of license that you purchased and are subject to the complete license statement 
 * which may be found in the accompanying license.txt file, please read this carefully.
 *
 * Copyright © 1998-2001  Cirkadia Ltd.  All rights reserved.
 * 
 * http://www.cirkadia.com
 * 
 **********************************************************************/ 


/**********************************************************************
 *
 * Browser Class & Object
 *
 **********************************************************************/ 

function Browser()
{
    this.IE4plus = false;
    this.Gecko   = false;
    this.Opera   = false;
    this.Mozilla = false;
    this.Mac     = false;   
    this.Version = 0;

    var sVersion = "";
    
    if (navigator.userAgent.indexOf('Opera') != -1)
    {
        this.Opera = true;
    }
    else if (navigator.userAgent.indexOf('Gecko') != -1)
    {
        this.Gecko = true;

        if (navigator.userAgent.indexOf('Netscape6') == -1)
        {
            this.Mozilla = true;
        }

        sVersion = navigator.appVersion;

    }
    else if (document.all)
    {
        this.IE4plus = true;

        sVersion = navigator.appVersion.substring(navigator.appVersion.indexOf('MSIE ') + 5);
    }

    this.Version = Math.floor(parseFloat(sVersion) * 10) / 10;

    this.Mac = navigator.appVersion.indexOf('Macintosh') != -1 ? true : false

    this.DisplayShow = 'block';
    this.DisplayHide = 'none';

    if (this.IE4plus)
    {
        this.DisplayShow = '';
        this.DisplayHide = 'none';
    }
}

var oBrowser = new Browser();

/**********************************************************************
 *
 * iNavigate Class & Object
 *
 **********************************************************************/

function iNavigate()
{
    this.Frames            = false;
    this.GroupName         = '';
    this.HomePage          = 'index.htm';
    this.InitiallyOpen     = false;
    this.PreserveState     = true;
    this.ConvertParent     = false;
    this.MatchQueryString  = false;
    this.PageSearch        = new PageSearch();

    this.NodeBlankName     = /Blank/i;
    this.NodeMinusName     = 'Minus';
    this.NodePlusName      = 'Plus';

    this.NodePlusTitle     = 'Open Menu';
    this.NodeMinusTitle    = 'Close Menu';

    this.Pointer           = new Image();
    this.Pointer.src       = 'iNavigate/graphics/pointer.gif';

    this.BlankPointer      = new Image();
    this.BlankPointer.src  = 'iNavigate/graphics/blank.gif';

    this._oCurrentMenuItem ;
    this._nCurrentMenuNo   ;

    this._FrameWindow      ;
}

iNavigate.prototype.BeforeLoad        = iNavigate_BeforeLoad;
iNavigate.prototype.AfterLoad         = iNavigate_AfterLoad;
iNavigate.prototype.CloseAll          = iNavigate_CloseAll;
iNavigate.prototype.OpenAll           = iNavigate_OpenAll;
iNavigate.prototype.Locate            = iNavigate_Locate;
iNavigate.prototype.LocateFrame       = iNavigate_LocateFrame;
iNavigate.prototype.MoveNext          = iNavigate_MoveNext;
iNavigate.prototype.MovePrevious      = iNavigate_MovePrevious;
iNavigate.prototype.PrepareFrame      = iNavigate_PrepareFrame;

iNavigate.prototype.menuId            = 'iNavigateMenu';
iNavigate.prototype.menuBodyId        = 'iNavigateMenuBody';
iNavigate.prototype.menuItemId        = 'iNavigateItem';
iNavigate.prototype.menuBoxId         = 'iNavigateMenuBox';
iNavigate.prototype.menuNodeId        = 'iNavigateMenuNode';
iNavigate.prototype.pointerId         = 'iNavigatePointer';

iNavigate.prototype.cookiePrefix      = 'iNavigate_';

iNavigate.prototype.menuNoAttr        = 'menuNo';
iNavigate.prototype.menuNodePathAttr  = 'nodePath';
iNavigate.prototype.menuNodeQueryAttr = 'nodeQuery';
iNavigate.prototype.currentMenuAttr   = 'menuCurrent';

var iNavigate = new iNavigate();

var xMenu;
var xMenuBody;
var xMenuBox;
var xMenuBoxPlusImage;
var xMenuBoxMinusImage;
var xHref;

function iNavigate_BeforeLoad()
{
    if (!oBrowser.IE4plus && !oBrowser.Gecko) return;

    var i;

    //--------------------------------------------------
    // 
    //--------------------------------------------------
    var bFirstTime = GetGroupLoaded();

    var bLoadOpen = bFirstTime ? iNavigate.InitiallyOpen : false;

    if (bFirstTime) SetGroupLoaded();

    //--------------------------------------------------
    // 
    //--------------------------------------------------
    if (!iNavigate.Frames) iNavigate.PageSearch.Initialize(window);

    //--------------------------------------------------
    // close previously closed menus [asap]
    //--------------------------------------------------
    xMenu = GetElements(document, iNavigate.menuId);

    xMenuBody = new Array(xMenu.length);

    for (i=0; i < xMenu.length; i++)
    {
        xMenu[i].setAttribute(iNavigate.menuNoAttr, i);

        xMenuBody[i] = GetFirstElement(xMenu[i], iNavigate.menuBodyId);

        if (xMenuBody[i]) 
        {
            if (bLoadOpen)
            {
                SetMenuCookie(xMenu[i], true);
            }
            else
            {
                if (GetMenuCookie(xMenu[i]) == false)
                {
                    xMenuBody[i].style.display = oBrowser.DisplayHide;
                }
            }
        }
    }
    
    //--------------------------------------------------
    // find the current menu item
    //--------------------------------------------------
    var xItem = GetElements(document, iNavigate.menuItemId);

    xHref = new Array(xItem.length);

    for (i=0; i < xItem.length; i++)
    {
        xHref[i] = xItem[i].href;
    }

    if (!iNavigate.Frames)
    {
        for (i=0; i < xItem.length; i++)
        {
            oItem = xItem[i];
        
            if (iNavigate.PageSearch.MatchesLink(oItem) == true)
            {
                iNavigate._oCurrentMenuItem = oItem;
                iNavigate._nCurrentMenuNo   = i;

                _OpenAncestorNodes(oItem)

                _SetItemPointer(iNavigate._oCurrentMenuItem, iNavigate.Pointer)
    
                break;
            }
        }
    }
    
    //--------------------------------------------------
    // activate menus
    //--------------------------------------------------
    xMenuBox           = new Array(xMenu.length);
    xMenuBoxPlusImage  = new Array(xMenu.length);
    xMenuBoxMinusImage = new Array(xMenu.length);

    for (i=0; i < xMenu.length; i++)
    {
        xMenuBox[i] = GetFirstElement(xMenu[i], iNavigate.menuBoxId);

        xMenuBox[i].setAttribute(iNavigate.menuNoAttr, i);

        xMenuBoxPlusImage[i]      = new Image();
        xMenuBoxPlusImage[i].src  = xMenuBox[i].src.replace(iNavigate.NodeBlankName, iNavigate.NodePlusName);
    
        xMenuBoxMinusImage[i]     = new Image();
        xMenuBoxMinusImage[i].src = xMenuBox[i].src.replace(iNavigate.NodeBlankName, iNavigate.NodeMinusName);
 
        _ActivateMenu(i);
    }
}


function iNavigate_PrepareFrame(oWindow)
{
    iNavigate.PageSearch = new PageSearch();

    iNavigate._FrameWindow = oWindow;
}


function iNavigate_LocateFrame()
{
    if (!oBrowser.IE4plus && !oBrowser.Gecko) return;

    //--------------------------------------------------
    // clear pointer from previous menu item
    //--------------------------------------------------
    _SetItemPointer(iNavigate._oCurrentMenuItem, iNavigate.BlankPointer)

    //--------------------------------------------------
    // 
    //--------------------------------------------------
    iNavigate.PageSearch.Initialize(iNavigate._FrameWindow);

    //--------------------------------------------------
    // find the current menu item
    //--------------------------------------------------
    var xItem = GetElements(document, iNavigate.menuItemId);

    for (i=0; i < xItem.length; i++)
    {
        oItem = xItem[i];
        oMenuBox  = xMenuBox[i];
        oMenuBody = xMenuBody[i];
    
        if (iNavigate.PageSearch.MatchesLink(oItem) == true)
        {
            iNavigate._oCurrentMenuItem = oItem;
            iNavigate._nCurrentMenuNo   = i;

            _OpenAncestorNodes(oItem)

            _SetItemPointer(iNavigate._oCurrentMenuItem, iNavigate.Pointer)

            break;
        }
    }

    //--------------------------------------------------
    // set menu box graphics
    //--------------------------------------------------
    for (i=0; i < xMenu.length; i++)
    {
        _SetMenuBox(i)
    }
}


function _OpenAncestorNodes(oItem)
{
    //--------------------------------------------------
    // open up all ancestor menus
    //--------------------------------------------------
    while (oItem)
    {
        if (oBrowser.Gecko)   oItem = oItem.parentNode;
        if (oBrowser.IE4plus) oItem = oItem.parentElement;

        if (oItem)
        {
            if (oItem.id == iNavigate.menuId)
            {
                break; //current link must be a 'node' link - so don't open it
            }
            else if (oItem.id == iNavigate.menuBodyId)
            {
                oItem.style.display = oBrowser.DisplayShow;
                break;
            }
        }
    }

    while (oItem)
    {
        if (oBrowser.Gecko)   oItem = oItem.parentNode;
        if (oBrowser.IE4plus) oItem = oItem.parentElement;

        if (oItem)
        {
            if (oItem.id == iNavigate.menuId)
            {
                SetMenuCookie(oItem, true);

                oItem.setAttribute(iNavigate.currentMenuAttr, '1');
            }
            else if (oItem.id == iNavigate.menuBodyId)
            {
                oItem.style.display = oBrowser.DisplayShow;
            }
        }
    }
}


function _SetItemPointer(oItem, oPointer)
{
    //--------------------------------------------------
    // set pointer on current menu item
    //--------------------------------------------------
    if (oItem)
    {
        if (oBrowser.IE4plus) 
        {
            oImagePointer = GetFirstElement(oItem.parentElement.parentElement.parentElement, iNavigate.pointerId);
        }
        else if (oBrowser.Gecko)
        {
            oImagePointer = GetFirstElement(oItem.parentNode.parentNode.parentNode, iNavigate.pointerId);
        }
    
        if (oImagePointer) oImagePointer.src = oPointer.src;
    }
}


function _SetMenuBox(nMenu)
{
    if (xMenuBody[nMenu])
    {
        if (GetMenuCookie(xMenu[nMenu]) == true)
        {
            xMenuBox[nMenu].src   = xMenuBoxMinusImage[nMenu].src;
            xMenuBox[nMenu].title = iNavigate.NodeMinusTitle;
        }
        else
        {
            xMenuBox[nMenu].src   = xMenuBoxPlusImage[nMenu].src;
            xMenuBox[nMenu].title = iNavigate.NodePlusTitle;
        }
    }
}


function _ActivateMenu(nMenu)
{
    var oLink;
    var oSpan;
    var oMenuNode;

    oMenu     = xMenu[nMenu];
    oMenuBox  = xMenuBox[nMenu];
    oMenuBody = xMenuBody[nMenu];

    if (oMenuBody)
    {
        //--------------------------------------------------
        // store top level link
        //--------------------------------------------------
        oLink = GetFirstElement(oMenu, iNavigate.menuItemId);

        oSpan = oLink;

        while (oSpan.tagName != 'SPAN')
        {
            if (oBrowser.Gecko)   oSpan = oSpan.parentNode;
            if (oBrowser.IE4plus) oSpan = oSpan.parentElement;
        }

        if (oSpan.id == iNavigate.menuNodeId) 
        {
            oMenu.setAttribute(iNavigate.menuNodePathAttr, NormalizePathName(oLink.pathname));
            oMenu.setAttribute(iNavigate.menuNodeQueryAttr, NormalizeQueryString(oLink.search));
        }

        //--------------------------------------------------
        // bind event handlers
        //--------------------------------------------------
        oMenuNode = GetFirstElement(oMenu, iNavigate.menuNodeId)

        if (oBrowser.IE4plus)
        {
            oMenuBox.onclick  = iNavigate_MenuBoxClick;
            oMenuNode.onclick = iNavigate_MenuNodeClick;
            oMenuBody.onclick = iNavigate_CancelEventPropagation
            
        }            
        else if (oBrowser.Gecko)
        {
            oMenuBox.addEventListener('click',  iNavigate_MenuBoxClick, false);
            oMenuNode.addEventListener('click', iNavigate_MenuNodeClick, false);
            oMenuBody.addEventListener('click', iNavigate_CancelEventPropagation, false);
        }

        //--------------------------------------------------
        // set cursor
        //--------------------------------------------------
        if (oBrowser.IE4plus) 
        {
            oMenuBox.style.cursor = 'hand';
        }

        //--------------------------------------------------
        // set menu box graphics
        //--------------------------------------------------
        if (!oBrowser.Mozilla) _SetMenuBox(nMenu)
    }
}


function iNavigate_AfterLoad()
{
    if (!oBrowser.IE4plus && !oBrowser.Gecko) return;

    //--------------------------------------------------
    // Mozilla 0.9 work-around - set menu box graphics now 
    //--------------------------------------------------
    if (oBrowser.Mozilla)
    {
        for (i=0; i < xMenu.length; i++)
        {
            _SetMenuBox(i)
        }
    }

    if (!iNavigate.Frames)
    {
        //--------------------------------------------------
        // convert target item link to text and add emphasis
        //--------------------------------------------------
        if (!iNavigate.PageSearch._bIsLocation && iNavigate.ConvertParent == false) return;
    
        if (iNavigate._oCurrentMenuItem )
        {
            if (oBrowser.IE4plus)
            {
                // we do this here for IE4 compatibility, in IE5+ we could do it earlier
    
                if (oBrowser.Mac && (oBrowser.Version <= 5.0)) 
                {
                    //IE 5.0 Mac work-around - do nothing!
                }
                else
                {
                    iNavigate._oCurrentMenuItem.outerHTML = '<em class=iNavigateCurrentPage>' + iNavigate._oCurrentMenuItem.innerHTML + '</em>';
                }
            }
    
            else if (oBrowser.Gecko)
            {
                oElement = document.createElement('EM');
    
                oElement.setAttribute('class', 'iNavigateCurrentPage');
    
                var oNode = iNavigate._oCurrentMenuItem.firstChild;
    
                while (oNode)  
                {
                    oElement.appendChild(oNode.cloneNode(true));
    
                    oNode = oNode.nextSibling;
                }
        
                iNavigate._oCurrentMenuItem.parentNode.replaceChild(oElement, iNavigate._oCurrentMenuItem);
            }
        }
    }
}

function iNavigate_OpenAll()
{
    for (i=0; i < xMenu.length; i++)
    {
        oMenu     = xMenu[i];
        oMenuBox  = xMenuBox[i];
        oMenuBody = xMenuBody[i];

        if (oMenuBody)
        {
            SetMenuCookie(oMenu, true);

            oMenuBody.style.display = oBrowser.DisplayShow;

            oMenuBox.src   = xMenuBoxMinusImage[i].src;
            oMenuBox.title = iNavigate.NodeMinusTitle;
        }
    }
}


function iNavigate_CloseAll()
{
    for (i=0; i < xMenu.length; i++)
    {
        oMenu     = xMenu[i];
        oMenuBox  = xMenuBox[i];
        oMenuBody = xMenuBody[i];

        if (oMenuBody)
        {
            SetMenuCookie(oMenu, false);

            oMenuBody.style.display = oBrowser.DisplayHide;

            oMenuBox.src   = xMenuBoxPlusImage[i].src;
            oMenuBox.title = iNavigate.NodePlusTitle;
        }
    }
}


function iNavigate_Locate()
{
    for (i=0; i < xMenu.length; i++)
    {
        oMenu     = xMenu[i];
        oMenuBox  = xMenuBox[i];
        oMenuBody = xMenuBody[i];

        if (oMenuBody)
        {
            if (oMenu.getAttribute(iNavigate.currentMenuAttr) == '1')
            {
                SetMenuCookie(oMenu, true);
    
                oMenuBody.style.display = oBrowser.DisplayShow;
    
                oMenuBox.src   = xMenuBoxMinusImage[i].src;
                oMenuBox.title = iNavigate.NodeMinusTitle;
            }
        }
    }
}


function iNavigate_MoveNext()
{
    var nItem = iNavigate._nCurrentMenuNo;

    nItem++;

    if (nItem >= xHref.length) nItem = 0;

    if (iNavigate.Frames)
    {
        iNavigate._FrameWindow.document.location = xHref[nItem];
    }
    else
    {
        document.location = xHref[nItem];
    }
}


function iNavigate_MovePrevious()
{
    var nItem = iNavigate._nCurrentMenuNo;

    nItem--;

    if (nItem < 0) nItem = xHref.length - 1;

    if (iNavigate.Frames)
    {
        iNavigate._FrameWindow.document.location = xHref[nItem];
    }
    else
    {
        document.location = xHref[nItem];
    }    
}

/**********************************************************************
 *
 * Page Search Class
 *
 **********************************************************************/

function PageSearch()
{
    this._bIsLocation  = false;
    this.page          = arguments[0];
    this.querystring   = arguments[1];
}

PageSearch.prototype.MatchesLink = PageSearch_MatchesLink;
PageSearch.prototype.MatchesURL  = PageSearch_MatchesURL;
PageSearch.prototype.Initialize  = PageSearch_Initialize;


function PageSearch_Initialize(oWindow)
{
    if (!this.page)
    {
        this._bIsLocation = true;

        this.page = NormalizePathName(oWindow.location.pathname, iNavigate.HomePage);        

        if (iNavigate.MatchQueryString == true)
        {
            this.querystring = NormalizeQueryString(oWindow.location.search);
        }
    }
}


function PageSearch_MatchesLink(oLink)
{
    if (!oLink.pathname) return false;

    var sPathName = NormalizePathName(oLink.pathname);

    if (this._bIsLocation)
    {
        if (this.page != sPathName) return false;

        if (this.querystring)
        {
            if (this.querystring != NormalizeQueryString(oLink.search)) return false;
        }
    }
    else
    {
        if (typeof this.page == 'string')
        {
            if (StringEnds(sPathName, this.page.toLowerCase()) == false) return false;
        }
        else
        {
            if (!this.page.test(sPathName)) return false;
        }
    
        if (this.querystring)
        {
            var sQueryString = NormalizeQueryString(oLink.search);
    
            if (typeof this.querystring == 'string')
            {
                if (this.querystring.toLowerCase() != sQueryString) return false;
            }
            else
            {
                if (!this.querystring.test(sQueryString)) return false
            }
        }
    }
    return true;
}


function PageSearch_MatchesURL(sPathName, sQueryString)
{
    if (typeof this.page == 'string')
    {
        if (this.page.toLowerCase() != sPathName) return false;
    }
    else
    {
        if (!this.page.test(sPathName)) return false;
    }

    if (this.querystring)
    {
        if (typeof this.querystring == 'string')
        {
            if (this.querystring.toLowerCase() != sQueryString) return false;
        }
        else
        {
            if (!this.querystring.test(sQueryString)) return false
        }
    }

    return true;
}


/**********************************************************************
 *
 * Event Handlers
 *
 **********************************************************************/ 

function iNavigate_MenuBoxClick(evt)
{
    var oSource;

    if (oBrowser.IE4plus) oSource = window.event.srcElement;
    if (oBrowser.Gecko)   oSource = evt.currentTarget;

    nMenu = oSource.getAttribute(iNavigate.menuNoAttr);

    _MenuToggle(nMenu);
}

function iNavigate_MenuNodeClick(evt)
{
    var oSource;
    var sNodePath;
    var sNodeQuery;

    if (oBrowser.IE4plus) oSource = window.event.srcElement;
    if (oBrowser.Gecko)   oSource = evt.currentTarget;

    while (oSource.id != iNavigate.menuId)
    {
        if (oBrowser.Gecko)   oSource = oSource.parentNode;
        if (oBrowser.IE4plus) oSource = oSource.parentElement;
    }

    if (oSource)
    {
        sNodePath = oSource.getAttribute(iNavigate.menuNodePathAttr);
        sNodeQuery = oSource.getAttribute(iNavigate.menuNodeQueryAttr);

        if (sNodePath)
        {
            if (iNavigate.PageSearch.MatchesURL(sNodePath, sNodeQuery) == false)
            {
                return;
            }
        }

        nMenu = oSource.getAttribute(iNavigate.menuNoAttr);

        _MenuToggle(nMenu);
    }
}

function _MenuToggle(nMenu)
{
    oMenu     = xMenu[nMenu];
    oMenuBox  = xMenuBox[nMenu];
    oMenuBody = xMenuBody[nMenu];

    if (oMenuBody)
    {
        if (oMenuBody.style.display == oBrowser.DisplayHide)
        {
            SetMenuCookie(oMenu, true);

            oMenuBody.style.display = oBrowser.DisplayShow;

            oMenuBox.src   = xMenuBoxMinusImage[nMenu].src;
            oMenuBox.title = iNavigate.NodeMinusTitle;
        }
        else
        {
            SetMenuCookie(oMenu, false);

            oMenuBody.style.display = oBrowser.DisplayHide;
    
            oMenuBox.src   = xMenuBoxPlusImage[nMenu].src;
            oMenuBox.title = iNavigate.NodePlusTitle;
        }
    }
}

function iNavigate_CancelEventPropagation(evt)
{
    if (oBrowser.IE4plus)
    {
        window.event.cancelBubble=true;
    }

    else if (oBrowser.Gecko)
    {
        evt.cancelBubble = true;
    }
}


/**********************************************************************
 *
 * Menu Cookie Functions
 *
 **********************************************************************/ 

function SetMenuCookie(oMenu, bValue)
{
    var sValue = bValue ? '1' : '0';

    if (iNavigate.PreserveState)
    {
        document.cookie = iNavigate.cookiePrefix + iNavigate.GroupName + '_' + oMenu.getAttribute(iNavigate.menuNoAttr) + '=' + sValue + '; path=/';
    }

    oMenu.setAttribute('menuOpen', sValue);
}


function GetMenuCookie(oMenu)
{
    var bValue = false;

    bValue = document.cookie.indexOf(iNavigate.cookiePrefix + iNavigate.GroupName + '_' + oMenu.getAttribute(iNavigate.menuNoAttr) + '=1') != -1;

    if (!bValue) 
    {
        if (oMenu.getAttribute('menuOpen') == '1') bValue = true;
    }
    return bValue;
}


function SetGroupLoaded()
{
    document.cookie = iNavigate.cookiePrefix + iNavigate.GroupName + '=1; path=/';
}


function GetGroupLoaded()
{
    var bValue = false;

    bValue = document.cookie.indexOf(iNavigate.cookiePrefix + iNavigate.GroupName + '=1') == -1;

    return bValue;
}


/**********************************************************************
 *
 * URL Utilities
 *
 **********************************************************************/ 

function NormalizePathName(sPathName, sDefault)
{
    var sBuffer;

    //--------------------------------------------------
    // ensure pathname has leading slash
    //--------------------------------------------------
    var nPos = sPathName.indexOf('/');

    if (nPos == 0) 
    {
        sBuffer = sPathName;
    }
    else
    {
        sBuffer = '/' + sPathName;
    }

    //--------------------------------------------------
    // set default if appropriate
    //--------------------------------------------------
    if (sBuffer.length == 1)
    {
        if (sDefault)
        {
            sBuffer = sBuffer + sDefault;
        }
    }

    //--------------------------------------------------
    // replace all back-slash with forward-slash and set lowercase
    //--------------------------------------------------
    return sBuffer.replace(/\\/g, '/').toLowerCase();
}


function NormalizeQueryString(sQueryString)
{
    //--------------------------------------------------
    // remove leading ?
    //--------------------------------------------------
    var sBuffer = sQueryString;

    if (sBuffer.length > 0)
    {
        var nPos = sBuffer.indexOf('?');

        if (nPos == 0) 
        {
            sBuffer = sBuffer.substr(1);
        }
    }

    //--------------------------------------------------
    // set lowercase
    //--------------------------------------------------
    return sBuffer.toLowerCase()
}


/**********************************************************************
 *
 * Cross Browser Utilities
 *
 **********************************************************************/ 

function GetElements(element, id)
{
    var i;
    var elements = new Array();

    if (oBrowser.IE4plus)
    {
        if (element.all[id])
        {
            elements = element.all[id];

            if (!elements.length) elements = [element.all[id]];
        }
    }
    else if (oBrowser.Gecko)
    {
        _GetElementsDOM2(elements, element, id);
    }
    return elements;
}


function _GetElementsDOM2(elements, element, id)
{
    var i;

    for (i=0; i < element.childNodes.length; i++)
    {
        if (element.childNodes[i].id == id)
        {
            elements.push(element.childNodes[i]);
        }

        _GetElementsDOM2(elements, element.childNodes[i], id);
    }
}


function GetFirstElement(element, id)
{
    var i;
    var reply;
    var elements;

    if (oBrowser.IE4plus)
    {
        if (element.all[id])
        {
            elements = element.all[id];

            if (!elements.length) 
            {
                reply = elements;
            }
            else
            {
                reply = elements[0];
            }
        }
    }
    else if (oBrowser.Gecko)
    {
        elements = new Array()

        _GetFirstElementDOM2(elements, element, id);

        reply = elements[0];
    }

    return reply;
}


function _GetFirstElementDOM2(elements, element, id)
{
    var i;

    for (i=0; i < element.childNodes.length; i++)
    {
        if (element.childNodes[i].id == id)
        {
            elements.push(element.childNodes[i]);

            break;
        }

        _GetElementsDOM2(elements, element.childNodes[i], id);

        if (elements.length > 0) break;
    }
}


/**********************************************************************
 *
 * String Utilities
 *
 **********************************************************************/ 

function StringEnds(sString, sEnd)
{
    return (sString.lastIndexOf(sEnd) == sString.length - sEnd.length)

}

