// CountdownDaysToEvent.js
// This script calculates the number of days until the first date of event.
// Created: 10/29/2005
// Last Modified: 10/22/2008
// Written By: Brian Bahn

function CountdownDaysToEvent(strEventName, datEventBegins, datEventEnds)
	{

	var strEvent = strEventName;
	var datBegin = new Date(datEventBegins);
	var datEnd = new Date(datEventEnds);

	var datToday = new Date();

	var lngTimeDifferenceToBegin = datBegin.getTime() - datToday.getTime();
	var intDaysToEvent = Math.floor(lngTimeDifferenceToBegin / (1000 * 60 * 60 * 24)) + 1;

	var intEventDay = Math.floor((datToday - datBegin) / (1000 * 60 * 60 * 24)) + 1;
	var intEventDuration = Math.floor((datEnd - datBegin) / (1000 * 60 * 60 * 24)) +1;

	var lngTimeDifferenceSinceEnd = datToday.getTime() - datEnd.getTime();
	var intDaysSinceEventEnded = Math.floor(lngTimeDifferenceSinceEnd / (1000 * 60 * 60 * 24));

	// Has event begun?
	if (intDaysToEvent > 1) 
		{
		// Event has not begun - display days to event.
		if (intDaysToEvent > 13) 
			{
			document.write("<b>" + strEvent + "</b> begins in " + Math.floor((intDaysToEvent / 7)) + " weeks!");
			}
		else document.write("<b>" + strEvent + "</b> begins in " + intDaysToEvent + " days!");
		}
	else if (intDaysToEvent == 1) {
		// Event begins tomorrow.
		document.write("<b>" + strEvent + "</b> begins tomorrow!");
		}	
	else if (intDaysToEvent == 0 && intEventDuration == 1) {
		// Event is today only.
		document.write("<b>" + strEvent + "</b> is today!");
		}
	else if (intDaysToEvent == 0) {
		// Today is the first of __ Event days.
		document.write("Today is the first of " + intEventDuration + " <b>" + strEvent + "</b> days!");
		}
	else if (intDaysSinceEventEnded == 0) {
		// Today is the last day of Event.
		document.write("Today is the last day of <b>" + strEvent + "</b> !!!");
		// alert(intEventDuration);
		}
	else if (intDaysSinceEventEnded < 1) {
		// Today is Event day __ of __.
		document.write("Today is <b>" + strEvent + "</b> day " + intEventDay + " of " + Math.floor(intEventDuration));
		// alert(intEventDuration);
		}

	// Has event ended?
	else if (intDaysSinceEventEnded > 1) 
		// Event has ended.
		{
		if (intDaysSinceEventEnded > 13) 
			{
			document.write("Sorry, <b>" + strEvent + "</b> ended " + Math.floor((intDaysSinceEventEnded / 7)) + " weeks ago!");
			}
		else document.write("Sorry, <b>" + strEvent + "</b> ended " + intDaysSinceEventEnded + " days ago!")

		// document.write("Sorry, <b>" + strEvent + "</b> ended " + intDaysSinceEventEnded + " days ago!");
		}
	else if (intDaysSinceEventEnded == 1) 
		// Event ended yesterday.
		{
		document.write("Sorry, <b>" + strEvent + "</b> ended yesterday!");
		}
	}

// End of CountdownDaysToEvent.js
