// Reusable functions:
// ------------------------------------------------------------
// Copyright 2007 Flashpoint Productions.  All rights reserved.

//DATE & TIME
//Format dates and times.  Display the current date and time.
var daysOfWeek = new Array(7);
daysOfWeek[0] = "Sunday";
daysOfWeek[1] = "Monday";
daysOfWeek[2] = "Tuesday";
daysOfWeek[3] = "Wednesday";
daysOfWeek[4] = "Thursday";
daysOfWeek[5] = "Friday";
daysOfWeek[6] = "Saturday";

var monthsOfYear = new Array(12);
monthsOfYear[0] = "January";
monthsOfYear[1] = "February";
monthsOfYear[2] = "March";
monthsOfYear[3] = "April";
monthsOfYear[4] = "May";
monthsOfYear[5] = "June";
monthsOfYear[6] = "July";
monthsOfYear[7] = "August";
monthsOfYear[8] = "September";
monthsOfYear[9] = "October";
monthsOfYear[10] = "November";
monthsOfYear[11] = "December";

//Consider revising this code to pass the Divs in which date and time will be displayed.
//Use setInterval("displayCurrentDateTime()", 1000); on the page to have the time automatically update.
function displayCurrentDateTime() {
	var now = new Date();
	var timeDiv = document.getElementById("time");
	var dateDiv = document.getElementById("date");
	timeDiv.innerHTML = getFullTimeString(new Date(), true);
	timeDiv.style.width = "75px";
	dateDiv.innerHTML = getFullDateString(new Date());
}
function getFullDateString(date) {
    var year = date.getFullYear();
    var numericDate = date.getDate();
    
    var dayOfWeek = daysOfWeek[date.getDay()];
    var monthOfYear = monthsOfYear[date.getMonth()];
    return dayOfWeek + ", " + monthOfYear + " " + padNumberWithZeros(numericDate, 2) + ", " + year;
}
function getFullTimeString(time, displaySeconds) {
	var timeString = "";
	var AMPM = "AM";
	var hours = time.getHours();
	if (hours >= 12) {
		AMPM = "PM";
	}
	if (hours > 12) {
		hours -= 12;
	}
	if (hours == 0) {
		hours = 12;
	}
	var minutes = time.getMinutes().toString();
	
	if (displaySeconds)
	{
		return hours + ":" + padNumberWithZeros(time.getMinutes(), 2) + ":" + padNumberWithZeros(time.getSeconds(), 2) + " " + AMPM;
	} else {
		return hours + ":" + padNumberWithZeros(time.getMinutes(), 2) + " " + AMPM;
	}
}
function padNumberWithZeros(numToPad, length) {
	var strVal = numToPad.toString();
	while (strVal.length < length) {
		strVal = "0" + strVal;
	}
	return strVal;
}

//EMAIL ADDRESSES
//Send e-mail to the specified address.  Use to help prevent SPAM.
function sendEmailTo(address, domainName, domainExtension, subject, cc, bcc, body)
{
	var mailStr = "m" + "a" + "i" + "l" + "t" + "o" + ":" + address + "@" + domainName + "." + domainExtension;
	
	var additions = "";
	if (subject != null)
	{
		additions += "?&subject=" + escape(subject);
	}
	if (cc != null)
	{
		additions += "?&cc=" + cc;
	}
	if (bcc != null)
	{
		additions += "?&bcc=" + bcc;
	}
	if (body != null)
	{
		additions += "?&body=" + escape(body);
	}
	additions = additions.replace("^\?\&", "?"); //Remove the extra ampersand
	
	mailStr += additions; //Add the optional stuff.
	
	window.location.replace(mailStr);
}
//Write an e-mail address to the screen.
function writeEmail(address, domainName, domainExtension)
{
	var mailStr = address + "@" + domainName + "." + domainExtension;
	
	document.write(mailStr);
}
