// Blank lines and comments stripped to reduce size.
// Contact contact@SpiritAndTruth.org for commented source files.
var undefined;
function onLookupLoad()
    {
    lookupX()
    return;
    }
function goLookupUrl( anchor )
    {
    if ( anchor.substring( 0, 5 ) == 'http:' )
        {
        window.location.href = anchor;
        return;
        }
    if ( anchor.substring( 0, 6 ) == 'https:' )
        {
        window.location.href = anchor;
        return;
        }
    if ( anchor.substring( 0, 4 ) == 'www.' )
        {
        window.location.href = anchor;
        return;
        }
    else if ( anchor.substring( 0, 5 ) == 'file:' )
        {
        window.location.href = anchor;
        return;
        }
    else if ( anchor.substring( 0, 4 ) == 'ftp:' )
        {
        window.location.href = anchor;
        return;
        }
    else if ( anchor.substring( 0, 1 ) == '\\' )
        {
        window.location.href = anchor;
        return;
        }
    else if ( anchor.substring( 0, 1 ) == '\.' )
        {
        window.location.href = anchor;
        return;
        }
    }

function lookupX( url )
    {
    // Disabled - causes problems in Konqueror browser under KDE.
    if ( 0 && url == undefined )
        {
        if ( parent.lastUrl ) url = parent.lastUrl
        }
    parent.lastUrl = url
    if ( ! url ) return

    // May be operating without all our frames.
    var pane = window
    if ( window.parent.bible ) 
        {
        pane = window.parent.bible
        if ( window.parent.bible.b ) 
            {
            pane = window.parent.bible.b
            }
        }

    if ( -1 == url.indexOf( 'search.php' ) )
        {

        parts = url.split( '|' )
        left = parts[ 0 ]
        if ( 0 == left.search( /b\d+c\d+/ ) )
            {
            url = left + '.htm'
            if ( 1 <= parts.length )
                {
                if ( 'TOP' == parts[ 1 ] ) url = url + '#_TOP_'
                if ( 'BOT' == parts[ 1 ] ) url = url + '#_BOT_'
                }
            }
        else 
            {
            address = new Address( url )
            if ( address.isValid() )
                {
                var chapter = address.chapter()
                var book = address.book()
                if ( chapter < 10 )
                    {
                    chapter = "00" + chapter;
                    }
                else if ( chapter < 100 )
                    {
                    chapter = "0" + chapter;
                    }
                url = window._bookFiles[ book ]; 
                url += "c" + chapter + ".htm";
                url += "#" + book + '_';
                url += "C" + address.chapter() + "V" + address.verse();
                }
            }
        var translation = readSelection( 'translation' )
        var path = pathFromTitle( translation, true )

        // WordLinks is a special case.
        if ('WordLinks' == translation)
            {

            // Convert bible address into equivalent WordLinks topic.
            var parts = url.split('#')
            var anchor = parts[parts.length - 1]
            anchor = anchor.replace( /C(\d+)V(\d+)/, "$1:$2" )
            path = pathFromTitle( translation, false )
            url = path + '?topic=' + anchor

            // If have a previous translation, use the same in WordLinks.
            if (!wlx.wlx_translationOld || 'WordLinks' == wlx.wlx_translationOld)
                {
                wlx.wlx_translationOld = 'NASB Bible'
                }
            url = path + '?book=' + wlx.wlx_translationOld 
            url += '&topic=' + anchor
            pane = top
            }
        else
            {
            url =  path + url
            }

        }

    //alert( 'lookupX ' + pane.name + ' ' + url)
    if (window.parent.bible) 
        {
            pane.location.replace( url )
        } 
        else 
        {
            pane.location.href = url
        }
    return;
    }

pathFromTitle = function( title, dirOnly )
    {
    var dir = window._paths[ title ]
    if (dirOnly) 
        {
        var parts = dir.split( '/' )
        dir = parts[0]
        for (i = 1 ; i < (parts.length - 1) ; i++)
            {
            dir += '/' + parts[i]
            }
        dir += '/'
        }
    return dir
    }
