// // JavaScript Event Calendar // // Version: 1.0 // Date: November 15, 1998 // For information: http://members.aol.com/kevinilsen or kilsen@m-vation.com // // Configurable values are set to defaults here; can override them before calling Calendar( ) from the HTML page var SpecialDay=1; // 1=Sunday, 2=Monday, . . . 7=Saturday var FontSize=5; var ColorBackground="ffffcc"; var ColorSpecialDay = "red"; var ColorToday = "green"; var ColorEvent = "blue"; // Initialize the range of the calendar to Jan - Dec of the current year. Calls to DefineEvent( ) will change this // as needed; it is also possible to explicitly override the range before calling Calendar( ) from the HTML page. var today = new Date(); var FirstMonth=GetFullYear(today) * 100 + 1; var LastMonth=FirstMonth + 11; // Events[] is a SPARSE array; Call DefineEvent( ) to populate it var Events = new Array; // Each event is defined by calling the DefineEvent( ) routine with the following parameters: // // DefineEvent(EventDate, EventDescription, EventLink, Image, Width, Height) // EventDate is a numeric value in the format YYYYMMDD // EvenDescription is a string that can include embedded HTML tags (e.g.,
, , etc.) // EventLink is the URL of the target page if a hyperlink is desired from this event entry // Image is the URL of the image if you want to display an image with this event // Width is the width of the image in pixels // Height is the height of the image in pixels function DefineEvent(EventDate, EventDescription, EventLink, Image, Width, Height) { var tmp; // Build the HTML string for this event: image (optional), link (optional), and description tmp = ""; if (Image != "") tmp = tmp + ''; if (EventLink != "") tmp = tmp + ''; tmp = tmp + EventDescription; if (EventLink != "") tmp = tmp + ''; // If an event already exists for this date, append the new event to it. if (Events[EventDate]) Events[EventDate] += "
" + tmp; else Events[EventDate] = tmp; // Adjust the minimum and maximum month & year to include this date tmp = Math.floor(EventDate / 100); if (tmp < FirstMonth) FirstMonth = tmp; if (tmp > LastMonth) LastMonth = tmp; } // Utility function to populate an array with values function arr() { for (var n=0;n 1) { yearmonth = parseInt(location.search.substring(1,location.search.length)); if ((""+yearmonth).length == 6) { mo = yearmonth % 100; yr = (yearmonth - mo) / 100; } } // Constrain to the range of months with events if (yearmonth < FirstMonth) { mo = FirstMonth % 100; yr = (FirstMonth - mo) / 100; yearmonth = FirstMonth; } if (yearmonth > LastMonth) { mo = LastMonth % 100; yr = (LastMonth - mo) / 100; yearmonth = LastMonth; } // Create a datae object for the first day of the desired month bgn = new Date(months[mo] + " 1," + yr); // Get the day-of-week of the first day, and the # days in the month dayofweek = bgn.getDay(); lastday = NumDaysIn(mo,yr); document.write(""); for (var i=1;i<=7;i++){ document.write(""); } document.write(""); dy = 1; // Special handling for the first week of the month for (var i=1;i<=7;i++) { // If the day is less than the day of the // week determined to be the first day // of the month, print a space in // this cell of the table. if (i <= dayofweek){ document.write(""); } // Otherwise, write date and the event, // if any, in this cell of the table. else { ShowDate(yr,mo,dy,i,curmo,curdy); dy++; } } document.write(""); // Rest of the weeks . . . while (dy <= lastday) { for (var i=1;i<=7;i++) { // If the day is greater than the last // day of the month, print a space in // this cell of the table. if (dy > lastday) { document.write(""); } // Otherwise, write date and the event, // if any, in this cell of the table. else { ShowDate(yr,mo,dy,i,curmo,curdy); dy++; } } document.write(""); } jump = ""; if (yearmonth > FirstMonth) jump += '<-- View '+months[PrevMonth(mo)]+''; if ((yearmonth > FirstMonth) && (yearmonth < LastMonth)) jump += "   |   "; if (yearmonth < LastMonth) jump += 'View '+months[NextMonth(mo)]+' -->'; document.write(""); document.write("
"+months[mo]+" "+yr+"
"+weekdays[i]+"
 
 
"+jump+"
Jump to month:  "); BuildSelectionList(yearmonth, thispage); document.write("
"); } // Display a date in the appropriate color, with events (if there are any) function ShowDate(yr, mo, dy, dayofweek, currentmonth, currentday) { var ind, HighlightEvent, tmp; document.write("

 "; document.write(">"+dy+"

"+tmp+""); } // Remaining routines are utilities used above function NumDaysIn(mo,yr) { if (mo==4 || mo==6 || mo==9 || mo==11) return 30; else if ((mo==2) && LeapYear(yr)) return 29; else if (mo==2) return 28; else return 31; } function LeapYear(yr) { if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0) return true; else return false; } // fixes a Netscape 2 and 3 bug function GetFullYear(d) { // d is a date object var yr; yr = d.getYear(); if (yr < 1000) yr +=1900; return yr; } function PrevMonth(mth) { if (mth == 1) return 12; else return (mth-1); } function NextMonth(mth) { if (mth == 12) return 1; else return (mth+1); } function PrevYearMonth(yrmth) { if ((yrmth % 100) == 1) return ((yrmth-100)+11); else return (yrmth-1); } function NextYearMonth(yrmth) { if ((yrmth % 100) == 12) return ((yrmth-11)+100); else return (yrmth+1); } function JumpTo(calendar, thispage) { var sel, yrmo; sel = calendar.selectedIndex; yrmo = calendar.form.jumpmonth[sel].value; document.location = thispage + "?" + yrmo; } function BuildSelectionList(current,thispage) { var mo, yr, yearmonth; yearmonth = FirstMonth; document.write(""); }