events = new Array( ["Y", "1", "1", "2006", "1:00 AM", "12:00 PM", "New Year's Day",""], ["F", "1", "3", "2", "1:00 AM", "12:59 PM", "Martin Luther King Day",""], ["F", "2", "3", "2", "1:00 AM", "12:59 PM", "President's Day",""], ["F", "3", "0", "0", "1:00 AM", "12:59 PM", "Easter",""], ["F", "5", "4", "2", "1:00 AM", "12:59 PM", "Memorial Day",""], ["Y", "7", "4", "2005", "1:00 AM", "12:59 PM", "Independence Day",""], ["F", "9", "1", "2", "1:00 AM", "12:59 PM", "Labor Day",""], ["F", "10", "2", "2", "1:00 AM", "12:59 PM", "Columbus' Day",""], ["Y", "11", "11", "2005", "1:00 AM", "12:59 PM", "Veteran's Day",""], ["F", "11", "4", "5", "1:00 AM", "12:59 PM", "Thanksgiving",""], ["", "9","9","2010","","","","Today is September 09, 2010",""], ["Y", "12", "25", "2005", "1:00 AM", "12:59 PM", "Christmas",""] ); /*************************************************************************************** JavaScript Calendar - Digital Christian Design Heavily Modified by Hans Menzi //Script featured on and available at JavaScript Kit: http://www.javascriptkit.com // Functions changedate(): Moves to next or previous month or year, or current month depending on the button clicked. createCalendar(): Renders the calander into the page with links for each to fill the date form filds above. ***************************************************************************************/ var thisDate = 1; // Tracks current date being written in calendar var wordMonth = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"); var today = new Date(); // Date object to store the current date var todaysDay = today.getDay() + 1; // Stores the current day number 1-7 var todaysDate = today.getDate(); // Stores the current numeric date within the month var todaysMonth = today.getUTCMonth() + 1; // Stores the current month 1-12 var todaysYear = today.getFullYear(); // Stores the current year var monthNum = todaysMonth; // Tracks the current month being displayed var yearNum = todaysYear; // Tracks the current year being displayed var firstDate = new Date(String(monthNum)+"/1/"+String(yearNum)); // Object Storing the first day of the current month var firstDay = firstDate.getUTCDay(); // Tracks the day number 1-7 of the first day of the current month var numbDays = 0; var calendarString = ""; var eastermonth = 0; var easterday = 0; function changedate(buttonpressed) { if (buttonpressed == "prevyr") yearNum--; else if (buttonpressed == "nextyr") yearNum++; else if (buttonpressed == "prevmo") monthNum--; else if (buttonpressed == "nextmo") monthNum++; else if (buttonpressed == "return") { monthNum = todaysMonth; yearNum = todaysYear; } if (monthNum == 0) { monthNum = 12; yearNum--; } else if (monthNum == 13) { monthNum = 1; yearNum++ } numbDays = lastDayInMonth(monthNum,yearNum); firstDate = new Date(yearNum,monthNum-1,1); firstDay = firstDate.getDay()-1; createCalendar(); return; } function easter(year) { // feed in the year it returns the month and day of Easter using two GLOBAL variables: eastermonth and easterday var a = year % 19; var b = Math.floor(year/100); var c = year % 100; var d = Math.floor(b/4); var e = b % 4; var f = Math.floor((b+8) / 25); var g = Math.floor((b-f+1) / 3); var h = (19*a + b - d - g + 15) % 30; var i = Math.floor(c/4); var j = c % 4; var k = (32 + 2*e + 2*i - h - j) % 7; var m = Math.floor((a + 11*h + 22*k) / 451); var month = Math.floor((h + k - 7*m + 114) / 31); var day = ((h + k - 7*m +114) % 31) + 1; eastermonth = month; easterday = day; } function lastDayInMonth(month, year) { var dd = new Date(year, month, 0); return dd.getDate(); } function createCalendar() { calendarString = ''; var daycounter = 0; calendarString += '
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| <\/td>'; } else { if (checkevents(daycounter,monthNum,yearNum,i,x) || ((todaysDay == x) && (todaysDate == daycounter) && (todaysMonth == monthNum))){ if ((todaysDay == x) && (todaysDate == daycounter) && (todaysMonth == monthNum)) { calendarString += ' | ' + daycounter + '<\/a><\/td>'; } else calendarString += ' | ' + daycounter + '<\/a><\/td>'; } else { calendarString += ' | ' + daycounter + '<\/td>';
}
}
daycounter++;
}
calendarString += '<\/tr>';
}
calendarString += '<\/table>';
calendarString += '' + events[i][6] + '\n'; theevent += '' + events[i][7] + ' \n'; dHans.innerHTML = theevent; } } if (events[i][0] == "M") { } if (events[i][0] == "Y") { if ((events[i][2] == day) && (events[i][1] == month)) { theevent += '' + events[i][6] + '\n'; theevent += '' + events[i][7] + ' \n'; dHans.innerHTML = theevent; } } if (events[i][0] == "F") { if ((events[i][1] == 3) && (events[i][2] == 0) && (events[i][3] == 0) ) { if (easterday == day && eastermonth == month) { theevent += '' + events[i][6] + '\n'; theevent += '' + events[i][7] + ' \n'; dHans.innerHTML = theevent; } } else { floater = floatingholiday(year,events[i][1],events[i][2],events[i][3]); if ((month == 5) && (events[i][1] == 5) && (events[i][2] == 4) && (events[i][3] == 2)) { if ((floater + 7 <= 31) && (day == floater + 7)) { theevent += '' + events[i][6] + '\n'; theevent += '' + events[i][7] + ' \n'; dHans.innerHTML = theevent; } else if ((floater + 7 > 31) && (day == floater)) { theevent += '' + events[i][6] + '\n'; theevent += '' + events[i][7] + ' \n'; dHans.innerHTML = theevent; } } else if ((events[i][1] == month) && (floater == day)) { theevent += '' + events[i][6] + '\n'; theevent += '' + events[i][7] + ' \n'; dHans.innerHTML = theevent; } } } } // Now we'll process any One Time events happening on the matching month, day, year: else if ((events[i][2] == day) && (events[i][1] == month) && (events[i][3] == year)) { theevent += '' + events[i][6] + '\n'; theevent += '' + events[i][7] + ' \n'; dHans.innerHTML = theevent; } } if (theevent == ""){ dHans.innerHTML ='No events to show.'; } } function floatingholiday(targetyr,targetmo,cardinaloccurrence,targetday) { // Floating holidays/events of the events.js file uses: // the Month field for the Month (here it becomes the targetmo field) // the Day field as the Cardinal Occurrence (here it becomes the cardinaloccurrence field) // 1=1st, 2=2nd, 3=3rd, 4=4th, 5=5th, 6=6th occurrence of the day listed next // the Year field as the Day of the week the event/holiday falls on (here it becomes the targetday field) // 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thurday, 6=Friday, 7=Saturday // example: "F", "1", "3", "2", = Floating holiday in January on the 3rd Monday of that month. // // In our code below: // targetyr is the active year // targetmo is the active month (1-12) // cardinaloccurrence is the xth occurrence of the targetday (1-6) // targetday is the day of the week the floating holiday is on // 0=Sun; 1=Mon; 2=Tue; 3=Wed; 4=Thu; 5=Fri; 6=Sat // Note: subtract 1 from the targetday field if the info comes from the events.js file // // Note: // If Memorial Day falls on the 22nd, 23rd, or 24th, then we add 7 to the dayofmonth to the result. // // Example: targetyr = 2052; targetmo = 5; cardinaloccurrence = 4; targetday = 1 // This is the same as saying our floating holiday in the year 2052, is during May, on the 4th Monday // var firstdate = new Date(String(targetmo)+"/1/"+String(targetyr)); // Object Storing the first day of the current month. var firstday = firstdate.getUTCDay(); // The first day (0-6) of the target month. var dayofmonth = 0; // zero out our calendar day variable. targetday = targetday - 1; if (targetday >= firstday) { cardinaloccurrence--; // Subtract 1 from cardinal day. dayofmonth = (cardinaloccurrence * 7) + ((targetday - firstday)+1); } else { dayofmonth = (cardinaloccurrence * 7) + ((targetday - firstday)+1); } return dayofmonth; } |