/*------------------------------------------------------------------------------------ This file that calculates which day of the year it is on on the date the file is accessed. It then compares that day to the date of the reenactment, to see whether it's before, during, or after the reenactment. Finally, it displays the appropriate message in the status bar of the page. ------------------------------------------------------------------------------------*/ function getLeapYearDays(y) /*------------------------------------------- Receives: a year (for example, from Date.getYear() ). Returns: 28 or 29, depending on whether it's leap year or not. ---------------------------------------------*/ { if (y/100 == 0) { if (y/400 == 0) { return (29); } else { return (28); } } else { if (y/4 == 0) { return (29); } else { return (28); } } } function returnDayOfTheYear(theDate) /*------------------------------------------- Receives: a Date object. Returns: the number of the day of the year. (I.e., January 1 is Day 1, December 31 is Day 365, etc.) Calls: getLeapYearDays . ---------------------------------------------*/ { strBreak = "
"; var daysInMonth = new Array(12); daysInMonth[0] = 31; //January daysInMonth[1] = getLeapYearDays(theDate.getYear()); daysInMonth[2] = 31; //March daysInMonth[3] = 30; //April daysInMonth[4] = 31; //May daysInMonth[5] = 30; //June daysInMonth[6] = 31; //July daysInMonth[7] = 31; // August daysInMonth[8] = 30; // September daysInMonth[9] = 31; // October daysInMonth[10] = 30; // November daysInMonth[11] = 31; // December theMonth = theDate.getMonth(); if (theMonth == 0) // If it's January { julianDate = theDate.getDate(); return julianDate; } else { var dayCount = theDate.getDate(); // Date of the present month. // Now add up the days in the previous months. for (x = 0; x < theMonth; x++) { dayCount = dayCount + daysInMonth[x]; } return dayCount; } } // Figure out what day of the year it is: toDay = new Date(); var thisDate = returnDayOfTheYear(toDay); //A number between 1 and 365, inclusive. // Set up the dates of the reenactment: thatDay = new Date(); thatDay.setFullYear(2006, 4, 28); var firstDayOfEvent = returnDayOfTheYear(thatDay); //A number between 1 and 365, inclusive. var endOfEvent = firstDayOfEvent + 2; //---Output of the status bar var strPadding = " "; var str1= strPadding + (firstDayOfEvent - thisDate) + " days to go until the Battle of Spokane Falls! Click '2006 EVENTS' for details. " ; var str2= strPadding + "Hurry over to Riverside State Park this weekend for the Battle of Spokane Falls! Click '2006 EVENTS' for schedule. " var str3= strPadding + "Hope you enjoyed the 2007 Battle of Spokane Falls. We're looking forward to seeing you at our other events this summer. Click our 'Events' page for details. " //------------------------------- // Which message shall we display in the status bar? // That depends on whether the event is over, active, or still to come: if (firstDayOfEvent > thisDate) { strMessage = str1; } else { if (thisDate <= endOfEvent ) { strMessage = str2; } else // Event is over. { strMessage = str3; } } L = strMessage.length; var start = 0; function showTicker() { status = strMessage.substring(start, L-1); // Maybe this should be L instead of L-1, // but for the time being I've just added an extra // space at the end of each string. start++; if (start == L) { start = 0; } var t = setTimeout("showTicker()", 200); } showTicker();