/*** Calendar Widget ***
*** dynamically builds and populates a small calendar
*
* Copyright (c) 2012
* Randy Webster (http://www.techraw.com/)
* All Rights Reserved.
*
* This notice MUST stay intact for legal use.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version. View the license at http://www.gnu.org/licenses
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
//-- MAKE CUSTOMIZATION CHANGES HERE --
//table border type, set to: (none | dotted | dashed | solid | double | groove | ridge | inset | outset)
var border = "solid";
//table border size, must be numeric
var border_size = 2;
//table border color in hex or color name
var border_color = "black";
//the font type
var font = "Tahoma";
//the font size
var font_size = "7";
//the font color in hex or color name
var font_color = "lime";
//day border color in hex or color name, for no border set color to match background color
var day_border = "#555555";
//the background color in hex or color name, use the word transparent for no background color
var bg_color = "transparent";
//today's highlight color in hex or color name
var today_color = "#3F3F3F";
//the font color for holidays in hex or color name
var holiday_color = "#D1D1D1";
//-- MAKE NO CHANGES PAST THIS POINT --
main();
function main() {
var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var date = new Date();
var today = date.getDate();
var month = date.getMonth();
var year = (date.getYear() < 2000) ? date.getYear() + 1900 : date.getYear();
//create css properties
document.write("");
//create the hosting table
document.write("
");
document.write("");
//create the calendar table
document.write("");
document.write("");
document.write(monthNames[month] + " " + year);
document.write(" | ");
create(today, month, year); //create the calendar
document.write(" |
");
}
function getHoliday(weekday, today, month) {
//determine if holiday and return name
var ymonth = month + 1;
var date = ymonth + "/" + today;
if ((today > 7) && (today <= 14) && (weekday == 0) && (ymonth == 5)) {
return "Mother's Day";
}
else if ((today > 24) && (today <= 31) && (weekday == 1) && (ymonth == 5)) {
return "Memorial Day";
}
else if ((today > 14) && (today <= 21) && (weekday == 0) && (ymonth == 6)) {
return "Father's Day";
}
else if ((today > 0) && (today <= 7) && (weekday == 1) && (ymonth == 9)) {
return "Labor Day";
}
else if ((today > 21) && (today <= 28) && (weekday == 4) && (ymonth == 11)) {
return "Thanksgiving Day";
}
else if (date == "1/1") {
return "New Year's Day";
}
else if (date == "2/14") {
return "Valentine's Day";
}
else if (date == "7/4") {
return "Independence Day";
}
else if (date == "10/31") {
return "Halloween";
}
else if (date == "11/11") {
return "Veteran's Day";
}
else if (date == "12/25") {
return "Xmas Day";
}
else if (date == "12/31") {
return "New Year's Eve";
}
else {
return "";
}
}
function getDays(month, year) {
//return the number of days for the month
var days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if (month == 1) { //is february
if (isLeapYear(year)) {
return 29;
}
else {
return days[month];
}
}
else {
return days[month];
}
}
function isLeapYear(year) {
//check for leap year
if (((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0)) {
return true;
}
else {
return false;
}
}
function setValue(weekday, today, month, value) {
var holiday = (weekday > -1) ? getHoliday(weekday, value, month) : "";
var bgColor = (value == today) ? today_color : bg_color;
var fontColor = (holiday == "") ? font_color : holiday_color;
var title = (holiday == "") ? "" : "title='" + holiday + "'";
//create the table cell for the date
document.write("");
document.write("" + value + " | ");
}
function create(today, month, year)
{
var dayNames = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var first = new Date (year, month, 1).getDay();
var days = getDays(month, year) + first;
var grid = 0;
//create the days table
document.write("");
document.write("");
//write day names
for (var i = 0; i < 7; i++) {
if (i % 7 == 0) {
document.write("
");
document.write("");
}
setValue(-1, today, month, dayNames[i]);
}
//insert blank days up to first
for (var i = 0; i < first; i++) {
if (i % 7 == 0) {
document.write("
");
document.write("");
grid++;
}
setValue(-1, today, month, " ");
}
//write date values
for (var i = first; i < days; i++) {
if (i % 7 == 0) {
document.write("
");
document.write("");
grid++;
}
setValue(i % 7, today, month, (i - first) + 1);
}
//insert remaining blank days
for (var i = days; i < (grid * 7); i++) {
if (i % 7 == 0) {
document.write("
");
}
setValue(-1, today, month, " ");
}
document.write("
");
}