/*
   base.js
	Copyright (c) 2002-2006 Conejo Systems.  All Rights Reserved.
*/

// A_onmouseover
function A_onmouseover()
{
    /* in the browser status bar: display the value of the A element's title attribute
        (if it exists), or else just display its inner HTML */
    if( this.title && (this.title.length > 0))
        window.status = this.title;
    else
        window.status = "";         /* (suppress display of the link target) */

    /* this function returns true to block default handling of the
        window.status value in onmouseover and onmouseout events */
    return true;
}

// A_onmouseout
function A_onmouseout()
{
    window.status = "";

    /* this function returns true to block default handling of the
        window.status value in onmouseover and onmouseout events */
    return true;
}

// doMailTo
function doMailTo( sDest )
{
	// try to frustrate crawlers that harvest email addresses ...
	var	cEl = String.fromCharCode( 0x6C );
	var	cAt = String.fromCharCode( 0x40 );
	var cExt = String.fromCharCode( 0x2E, 0x63, 0x6F, 0x6D );

    // build the basic mailto string (see RFC 2368)
    var sCmd = unescape( "mai" + cEl + "to:" + sDest + cAt + "conejosystems" + cExt );

    // use the specified subject if possible; otherwise create one
    var sSubject = (arguments.length >= 2) ?
                    arguments[1] :
                    "BWOP contact";
    sCmd += "?subject=" + escape( sSubject );

    // append browser info if the third argument is true
    if( (arguments.length == 3) && arguments[2] )
    {
        var sCRLF = "\r\n";
        var sBody = sCRLF + sCRLF + sCRLF + "--------" +
                sCRLF + "Troubleshooting information:" +
                sCRLF + "  userAgent:   " + self.navigator.userAgent +
                sCRLF + "  platform:    " + self.navigator.platform +
                sCRLF + "  javaEnabled: " + self.navigator.javaEnabled() +
                sCRLF + "--------";

        sCmd += "&body=" + escape( sBody );
    }

    // some browser magic to invoke the user's email application
	top.location.href = sCmd;

    return false;
}

// getDOMFrame
function getDOMFrame( sFrame )
{
    var oFrameset = self;
    var oFrame = oFrameset.frames[sFrame];
    while( (oFrame == null) && (top != oFrameset) )
    {
        oFrameset = oFrameset.parent;
        oFrame = oFrameset.frames[sFrame];
    }

    return oFrame;
}

// getDOMElementsByTag
function getDOMElementsByTag( sFrame, sTag )
{
    if( document.getElementsByTagName )
	    return getDOMFrame(sFrame).document.getElementsByTagName( sTag );

    // at this point we're running in some decrepit browser like NN4
    alert( "This is an old web browser that does not fully support javascript" );
}

// getDOMElementById
function getDOMElementById( sFrame, sID )
{
    if( document.getElementById )
        return getDOMFrame(sFrame).document.getElementById( sID );

    // at this point we're running in some decrepit browser like NN4
    alert( "This is an old web browser that does not fully support javascript" );
}

// addEventListeners
function addEventListeners( sFrame )
{
    // traverse the list of links (A elements) in the content frame
    var aA = getDOMElementsByTag( sFrame, "a" );
    for( var i=0; i<aA.length; i++ )
    {
        // add onmouseover and onmouseout events to the link
	    aA[i].onmouseover = A_onmouseover;
	    aA[i].onmouseout = A_onmouseout;

        /* ensure the element has a title attribute that browsers
            can display when the user hovers */
        if( (aA[i].title == null) || (aA[i].title == "") )
        {
            // try to get title text from a contained IMG element
            var oImgAlt = aA[i].firstChild.alt;
            if( (oImgAlt != null) && (oImgAlt != "") )
                aA[i].title = oImgAlt;
            else    // (just settle for whatever text lies inside the A element)
                aA[i].title = aA[i].innerHTML;
        }
    }
}

// showPageTitle
function showPageTitle()
{
    var aTitle = getDOMElementsByTag( "frameContent", "title" );
    top.document.title = aTitle[0].innerHTML;
}

// showPageTimestamp
function showPageTimestamp()
{
    // get the timestamp from the current content page
    var oE = getDOMElementById( "frameContent", "timestamp" );
    if( oE == null )
        return;
    var s = oE.innerHTML;
    
    // insert a BR element and suppress the trailing dot
    s = s.replace( " at ", "<br/>at " );
    s = s.replace( "UTC.", "UTC" );
    
    // update the displayed timestamp
    oE = getDOMElementById( "frameBottom", "frameBottomTimestamp" );
    if( oE == null )
        return;
    oE.innerHTML = s;
}

/* body_load

   Note:
    Opera v8 is buggy:  the event that calls this function does not fire
    if you use the browser's Back button to (re)load the page.

    Unlike IE and Moz, where the BODY this object is a javascript window object,
    in Opera the BODY this is an HTML DOM HTMLBodyElement, so figuring out which
    frame the body is in means traversing the HTML DOM tree. Thus, for simplicity,
    this function takes the containing frame name as a parameter.
*/
function body_load( sFrame )
{
    switch( sFrame )
    {
        case "frameContent":
            showPageTitle();
            showPageTimestamp();
            break;
            
        case "frameBottom":
            showPageTimestamp();
            break;
            
        default:
            break;
    }

    addEventListeners( sFrame );
}

