// Pre-load images
var background = new Image(); background.src = appBase + '/public/images/public_background.png';
var header = new Image(); header.src = appBase + '/public/images/header_bg.png';
var homeOn = new Image(); homeOn.src = appBase + '/public/images/menu/home_on.png';
var homeOff = new Image(); homeOff.src = appBase + '/public/images/menu/home_off.png';
var homeHover = new Image(); homeHover.src = appBase + '/public/images/menu/home_hover.png';
var easyOn = new Image(); easyOn.src = appBase + '/public/images/menu/easy_on.png';
var easyOff = new Image(); easyOff.src = appBase + '/public/images/menu/easy_off.png';
var easyHover = new Image(); easyHover.src = appBase + '/public/images/menu/easy_hover.png';
var signupOn = new Image(); signupOn.src = appBase + '/public/images/menu/signup_on.png';
var signupOff = new Image(); signupOff.src = appBase + '/public/images/menu/signup_off.png';
var signupHover = new Image(); signupHover.src = appBase + '/public/images/menu/signup_hover.png';
var contactOn = new Image(); contactOn.src = appBase + '/public/images/menu/contact_on.png';
var contactOff = new Image(); contactOff.src = appBase + '/public/images/menu/contact_off.png';
var contactHover = new Image(); contactHover.src = appBase + '/public/images/menu/contact_hover.png';

var fsInlinePlayer = null;

function ClickButton(id) {
    var item = document.getElementById(id);
    if (document.all)
        item.click();
    else {
        var evt = item.ownerDocument.createEvent("MouseEvents");
        evt.initMouseEvent("click", true, true, item.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        item.dispatchEvent(evt);
    }
}

function buildHomeFlash()
{
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="760" height="541" id="fsInlinePlayer" align="middle">');
        document.write('<param name="allowScriptAccess" value="always" />');
        document.write('<param name="movie" value="public/content/OnAndOn.swf" />');
        document.write('<param name="quality" value="high" />');
        document.write('<param name="wmode" value="transparent" />');
        document.write('<param name="bgcolor" value="#ffffff" />');
        document.write('</object>');
    }
    else
        document.write('<embed src="public/content/OnAndOn.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="760" height="541" id="fsInlinePlayer" name="fsInlinePlayer" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');

    fsInlinePlayer = document.getElementById('fsInlinePlayer');
}

function showLogin()
{
    // Call the event for the page
    if (window.onLoginDialog != null)
        onLoginDialog();

    // Disable the error message
    if (document.getElementById('loginHideThisBox') != null)
        document.getElementById('loginHideThisBox').style.display = 'none';
    
    // Disable the scroll bars
    document.body.style.height = '100%';
    if (navigator.appName != 'Netscape')
        document.body.style.overflow = 'hidden';
    
    // Cover the document
    document.getElementById('coverSheet').style.display = 'inline';

    // Hide the current username/password
    document.getElementById('username').value = document.getElementById('username').getAttribute('cookieValue');
    document.getElementById('password').value = '';

    // Show the login box
    document.getElementById('loginHolder').style.display = 'inline';
    
    // Finalize the box
    setupLoginBox();
}

function onEnterKey(e, forceLogin)
{
    if (forceLogin == true || e.keyCode == 13 )
    {
        submitLogin();
        return false;
    }
}

function submitLogin()
{
    document.getElementById('loginForm').submit();
}

function setupLoginBox()
{
    // Call the event for the page
    if (window.onLoginDialog != null)
        onLoginDialog();

    // Change the iframe height
    if (document.getElementById('loginFrameHolder') != null)
        document.getElementById('loginFrameHolder').style.height = document.getElementById('lgnBox').offsetHeight + 'px';
    
    // Focus on the user name
    if (document.getElementById('username').value == '')
        document.getElementById('username').focus();
    else
        document.getElementById('password').focus();
}

function cancelLogin()
{
    // Hide the login box
    document.getElementById('loginHolder').style.display = 'none';

    // Cover the document
    document.getElementById('coverSheet').style.display = 'none';

    // Disable the scroll bars
    document.body.style.height = '';
    if (navigator.appName != 'Netscape')
        document.body.style.overflow = 'auto';
}

function openBrWindow(theURL,Name,popW,popH,scroll,resizable)
{
    // Replace a beginning ~ in the URL
    if (theURL.substring(0,1) == '~')
        theURL = appBasePath + theURL.substring(1);

    if (resizable != '0' && resizable != 'no')
        resizable = '1';

    // Find the window dimensions
    var w, h, x, y;
    if (document.all)
    {
        /* the following is only available after onLoad */
        w = document.documentElement.offsetWidth;
        h = document.documentElement.offsetHeight;
        x = window.screenLeft;
        y = window.screenTop - 70;
    }
    else if (document.layers)
    {
        w = window.innerWidth;
        h = window.innerHeight;
        x = window.screenX;
        y = window.screenY;
    }
    else
    {
        w = window.outerWidth;
        h = window.outerHeight;
        x = window.screenX;
        y = window.screenY;
    }

    var leftPos = ((w-popW)/2)+x, topPos = ((h-popH)/2)+y;

    if (topPos < 0)
        topPos = 0;

    // begin new popup code
    winProp = 'width='+popW+',height='+popH+',left='+leftPos+',top='+topPos+',scrollbars='+scroll+',resizable='+resizable;
    Win = window.open(theURL, Name, winProp)

    if (parseInt(navigator.appVersion) >= 4){
        Win.window.focus();
    }
}

function wStatus(item)
{
    window.status = item.getAttribute('title');
    return true;
}

function clearStatus() { window.status = ''; }
