/**
 *
 * Keating Magee
 * http://www.keatingmagee.com/
 *
 * Script Name: scripts.js
 * Script Version: 1.0
 * Script Info: Basic Config/Load Scripts
 *
 */

// Function to preload images.

function preLoad() {
    homeoff = new Image();
    homeoff.src = "/img/nav/about_off.gif";
    aboutoff = new Image();
    aboutoff.src = "/img/nav/about_off.gif";
    childhoodoff = new Image();
    childhoodoff.src = "/img/nav/childhood_off.gif";
    infooff = new Image();
    infooff.src = "/img/nav/info_off.gif";
    issuesoff = new Image();
    issuesoff.src = "/img/nav/issues_off.gif";
    resourcesoff = new Image();
    resourcesoff.src = "/img/nav/resources_off.gif";

    homeon = new Image();
    homeon.src = "/img/nav/home_on.gif";
    abouton = new Image();
    abouton.src = "/img/nav/about_on.gif";
    childhoodon = new Image();
    childhoodon.src = "/img/nav/childhood_on.gif";
    infoon = new Image();
    infoon.src = "/img/nav/info_on.gif";
    issueson = new Image();
    issueson.src = "/img/nav/issues_on.gif";
    resourceson = new Image();
    resourceson.src = "/img/nav/resources_on.gif";
}

// Function to create dynamic pop up window, currently set to center window on screen.

function newWindow(url, name, wid, hgt, scr, res, stat, loc, mnu, tool, x, y) {
    if (screen) {
        widthOfScreen = screen.width;
        heightOfScreen = screen.height;
    }
    if ((x == null) || (y == null)) {
        midX = widthOfScreen / 2;
        midY = heightOfScreen / 2;
        midWid = wid / 2;
        midHgt = hgt / 2;
        x = midX - midWid;
        y = midY - midHgt;
    }
    windowOpts = "width=" + wid + ",height=" + hgt + ",scrollbars=" + scr + ",resizable=" + res + ",status=" + stat + ",location=" + loc + ",menubar=" + mnu + ",toolbar=" + tool + ",left=" + x + ",top=" + y;
    popUpWindow = window.open(url, name, windowOpts);
}

// Function to dynamically write out the flash code to work around the IE flash "white box" issue.

function flashMovie(name, width, height, bgcolor) {
    if (bgcolor == null) {
        bgcolor = '#ffffff';
    }

    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="' + name + '" align="middle">');
    document.write('    <param name="allowScriptAccess" value="sameDomain" />');
    document.write('    <param name="movie" value="' + name + '" />');
    document.write('    <param name="quality" value="high" />');
    document.write('    <param name="bgcolor" value="' + bgcolor + '" />');
    document.write('    <embed src="' + name + '" quality="high" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" name="' + name + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('    </embed>');
    document.write('</object>');
}

// Function to adjust the height of the sidebar for background purposes.

function adjustSideBar(sidebar) {

    // Grab the necessary div elements.
    var content = document.getElementById('content');
    var sidebar = document.getElementById(sidebar);

    if (content.offsetHeight > sidebar.offsetHeight) {
        sidebar.style.minHeight = content.offsetHeight - document.getElementById('sideBar').offsetHeight + 100 + 'px';
    }
    
}

function validateForm(obj) {
    formId = document.getElementById(obj);

    if (formId.name.value.length < 1) {
        alert("Please enter your name.");
        formId.name.focus();
        return false;
    }

    if (!formId.email.value.match(/[a-zA-Z0-9\.\-\_+%]+@[a-zA-Z0-9\-\_\.]+\.[a-zA-Z]{2,4}/)) {
        alert("Please enter a valid email address.");
        formId.email.focus();
        return false;
    }

    return true;

}

window.onload = preLoad;
