/*
	File:		navigator.js
	Created:	January 14, 2003
	Copyright:	Copyright © 2003 Matt McConville
			All rights reserved.

			No part of this site may be reproduced or 
			transmitted in any form or by any means, 
			electronic or mechanical, including but 
			not limited too, photocopying, recording, 
			or by any information and retrieval system 
			without expressed written permission. All 
			rights reserved. Use without expressed 
			written consent is a violation of applicable 
			laws.

	Purpose:	Define the javaScript functions
			that support navigation through the site. 

	
*/


/*
	Function:		displayCopyright()
	Parameters:		n/a
	Returns:		n/a

	Purpose:		Display the copyright tag on the 
				page footer.

*/
function displayCopyright()
{
	document.writeln('Copyright &copy; 2004, Matt McConville&nbsp;&nbsp;');
	return;
}


/*
    Function:		displayDate()
    Parameters:		none
    Returns:		none

    Purpose:		The displayDate() function constructs
				a text string that displays the current
				date (i.e. today's date) in month, day, 
				year format (i.e. "July 4, 2000").

*/
function displayDate()
{
    var today      = new Date();
    var daysOfWeek = new Array(7);
    var months     = new Array(12);
    var dateStr    = new String();


    //
    //  Set the values for the days of week array
    //
    daysOfWeek[0] = 'Sunday';
    daysOfWeek[1] = 'Monday';
    daysOfWeek[2] = 'Tuesday';
    daysOfWeek[3] = 'Wednesday';
    daysOfWeek[4] = 'Thursday';
    daysOfWeek[5] = 'Friday';
    daysOfWeek[6] = 'Saturday';


    //
    //  Set the values for the months array
    //
    months[0]  = 'January';
    months[1]  = 'February';
    months[2]  = 'March';
    months[3]  = 'April';
    months[4]  = 'May';
    months[5]  = 'June';
    months[6]  = 'July';
    months[7]  = 'August';
    months[8]  = 'September';
    months[9]  = 'October';
    months[10] = 'November';
    months[11] = 'December';

   
    //
    //  Assign the day of the week
    //
    dateStr = daysOfWeek[today.getDay()];


    //
    //  Assign the month to the displayed 
    //  date string
    //
    dateStr += ' - ';
    dateStr += months[today.getMonth()];


    //
    //  Add the day of the month to the 
    //  displayed date string
    //
    dateStr += ' ';
    dateStr += today.getDate();


    //
    //  Add the year to the displayed
    //  date string
    //
    dateStr += ', ';
    dateStr += today.getFullYear();


    //
    //  Write the date out to the document
    //
    document.writeln(dateStr);  
}


//
//	Function:		subscriptionRequest();
//	Parameters:		n/a
//	Returns:		true / false
//
//	Purpose:		
//
function subscriptionRequest()
{
	//
	//	Ensure that a valid email address, at least in
	//	format is entered.
	//
	if (! isValidEmail(subscribe.emailAddress.value))
	{
		alert('Please enter a valid email address.');
		subscribe.emailAddress.focus();
		return(false);
	}

      //
	// Clear the value
      //
      subscribe.emailAddress.value = "";
	return(true);
}


//
//    Function:           isEmpty();
//    Parameters:         String value to be validated
//    Returns:            none
//
//	Purpose:		
//
function isEmpty(s)
{
    return ((s == null) || (s.length == 0))
}


//
//	Function:		isValidEmail();
//	Parameters:		pStr - value of the email address input text field
//	Returns:		true / false
//
//	Purpose:		Validates the email address field contains a 
//				non-null string, that contains a "@" and a ".".
//
function isValidEmail(pStr)
{
	var	strLen = pStr.length;
	
	if (isEmpty(pStr))
	{
		return(false);
	}

	if (pStr.indexOf("@", 0) == -1)
	{
		return(false);
	}

	if (pStr.indexOf(".", 0) == -1)
	{
		return(false);
	}

	return(true);
}


/*
	Function:		displayPrevMonth
	Parameters:		pMonth - current month
	Returns:		none

	Purpose:		The displayPrevMonth() function constructs
				a text string that displays 
*/
function displayPrevMonth(pMonth)
{
    var today      = new Date();
    var months     = new Array(12);
    var displayStr = new String();


    //
    //  Set the values for the months array
    //
    months[0]  = 'January';
    months[1]  = 'February';
    months[2]  = 'March';
    months[3]  = 'April';
    months[4]  = 'May';
    months[5]  = 'June';
    months[6]  = 'July';
    months[7]  = 'August';
    months[8]  = 'September';
    months[9]  = 'October';
    months[10] = 'November';
    months[11] = 'December';


    //
    //  Check to see if the passed month is equal
    //  to the current month
    //
    if (pMonth != (today.getMonth() + 1))
    {
	  //
	  //	Construct the anchor tag
        //
        displayStr  = '<a class=\"footerLink\" href=\"';
        displayStr += months[today.getMonth()];
        displayStr += '.html\" ';


        //
        //  Add the mouse on and mouse off styles
        //
        displayStr += 'onMouseOver=\"this.style.color=\'#FFFF00\'\" ';
        displayStr += 'onMouseOut=\"this.style.color=\'#FFFFFF\'\">';

 
        //
	  //  Add the displayed text
        //
        displayStr += '<< ';
    	  displayStr += months[today.getMonth()];


        //
	  //	Close the anchor tag
        //
        displayStr += '</a>';
    }


    //
    //  Check to see if the month is less than three (3)
    //  months forward from the current month, if so
    //  display the month.
    //
    document.writeln(displayStr);
}
