
/* referenced calendar adapted from  original calendar script Copyright 1996 - Tomer and Yehuda Shiran

Feel free to "steal" this code provided that you leave this notice as is.

Additional examples from the book can be found at http://www.geocities.com/SiliconValley/9000/

For more information contact Tomer or Yehuda Shiran <yshiran@iil.intel.com>*/


setCal()



function getTime() {

// initialize time-related variables with current time settings

var now = new Date()

var then = new Date()

var hour = now.getHours()

var minute = now.getMinutes()

now = null

then = null

var ampm = "" 



// validate hour values and set value of ampm

if (hour >= 12) {

hour -= 12

ampm = "PM"

} else

ampm = "AM"

hour = (hour == 0) ? 12 : hour



// add zero digit to a one digit minute

if (minute < 10)

minute = "0" + minute // do not parse this number!



// return time string

return hour + ":" + minute + " " + ampm

}



function leapYear(year) {

if (year % 4 == 0) // basic rule

return true // is leap year

/* else */ // else not needed when statement is "return"

return false // is not leap year

}




function getDays(month, year) {

// create array to hold number of days in each month

var ar = new Array(12)

ar[0] = 31 // January

ar[1] = (leapYear(year)) ? 29 : 28 // February

ar[2] = 31 // March

ar[3] = 30 // April

ar[4] = 31 // May

ar[5] = 30 // June

ar[6] = 31 // July

ar[7] = 31 // August

ar[8] = 30 // September

ar[9] = 31 // October

ar[10] = 30 // November

ar[11] = 31 // December



// return number of days in the specified month (parameter)

return ar[month]

}



function getMonthName(month) {

// create array to hold name of each month

var ar = new Array(12)

ar[0] = "January"

ar[1] = "February"

ar[2] = "March"

ar[3] = "April"

ar[4] = "May"

ar[5] = "June"

ar[6] = "July"

ar[7] = "August"

ar[8] = "September"

ar[9] = "October"

ar[10] = "November"

ar[11] = "December"



// return name of specified month (parameter)

return ar[month]

}


function setCal() {

// standard time attributes

var now = new Date()

var thenyear = new Date("September 1, 2000")

var year = thenyear.getYear()

var month = thenyear.getMonth()

if (year < 1000)

year+=1900


var monthName = getMonthName(month)

var date = now.getDate()

var month = thenyear.getMonth()

var lastyear = year -1

thenyear = null




// create instance of first day of month, and extract the day on which it occurs

var firstDayInstance = new Date(year, month, 1)

var firstDay = firstDayInstance.getDay()

firstDayInstance = null



// number of days in current month

var days = getDays(month, year)



// call function to draw calendar

drawCal(firstDay + 1, days, date, monthName, year)


}



function drawCal(firstDay, lastDate, date, monthName, year) {

// constant table settings

var headerHeight = 30 // height of the table's header cell

var border = 1 // 3D height of table's border

var cellspacing = 1 // width of table's border

var headerColor = "ffffff" // color of table's header

var headerSize = "+1" // size of tables header font

var textSize = "-1" // size of tables text font

var colWidth = 35 // width of columns in table

var dayCellHeight = 10 // height of cells containing days of the week

var dayColor = "darkblue" // color of font representing week days

var cellHeight = 10 // height of cells representing dates in the calendar

var todayColor = "red" // color specifying today's date in the calendar

var timeColor = "purple" // color of font representing current time



// create basic table structure

var text = "" // initialize accumulative variable to empty string

text += '<CENTER>'

text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings

text += '<TH bgColor="blue" COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell

text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header

text += monthName + ' ' + year 



text += '</FONT>' // close table header's font settings

text += '</TH>' // close header cell




// variables to hold constant settings

var openCol = '<TD bgColor=#00ff00 WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'

openCol += '<FONT COLOR="' + dayColor + '">'

var closeCol = '</FONT></TD>'

var digit = 1

var opentoon = '<a href="'

var midtoon = '.htm">'

var closetoon = '</a>'


// create array of abbreviated day names

var weekDay = new Array(7)

weekDay[0] = "Sun"

weekDay[1] = "Mon"

weekDay[2] = "Tues"

weekDay[3] = "Wed"

weekDay[4] = "Thu"

weekDay[5] = "Fri"

weekDay[6] = "Sat"



// create first row of table to set column width and specify week day

text += '<TR ALIGN="center" VALIGN="center">'

for (var dayNum = 0; dayNum < 7; ++dayNum) {

text += openCol + weekDay[dayNum] + closeCol 

}

text += '</TR>'




// declaration and initialization of two variables to help with tables

var digit = 1

var curCell = 1


var myrefmo = monthName
{if(monthName == "January")
refmo = '0' + 1;
if(monthName == "February")
refmo = '0' + 2;
if(monthName == "March")
refmo = '0' + 3;
if(monthName =="April")
refmo = '0' + 4;
if(monthName == "May")
refmo = '0' + 5;
if(monthName == "June")
refmo = '0' + 6;
if(monthName == "July")
refmo = '0' + 7;
if(monthName == "August")
refmo = '0' + 8;
if(monthName == "September")
refmo = '0' + 9;
if(monthName == "October")
refmo = 10;
if(monthName == "November")
refmo = 11;
if(monthName == "December")
refmo = 12;

}

var lastmo = monthName
{if(monthName == "January")
lastmo = "December";
if(monthName == "February")
lastmo = "January";
if(monthName == "March")
lastmo = "February";
if(monthName == "April")
lastmo = "March";
if(monthName == "May")
lastmo = "April";
if(monthName == "June")
lastmo = "May";
if(monthName == "July")
lastmo = "June";
if(monthName == "August")
lastmo = "July";
if(monthName == "September")
lastmo = "August";
if(monthName == "October")
lastmo = "September";
if(monthName == "November")
lastmo = "October";
if(monthName == "December")
lastmo = "November";

}


var nextmo = monthName
{if(monthName == "January")
nextmo = "February";
if(monthName == "February")
nextmo = "March";
if(monthName == "March")
nextmo = "April";
if(monthName == "April")
nextmo = "May";
if(monthName == "May")
nextmo = "June";
if(monthName == "June")
nextmo = "July";
if(monthName == "July")
nextmo = "August";
if(monthName == "August")
nextmo = "September";
if(monthName == "September")
nextmo = "October";
if(monthName == "October")
nextmo = "November";
if(monthName == "November")
nextmo = "December";
if(monthName == "December")
nextmo = "January";

}

if(monthName == "January")
var lastyear = year -1;
else
var lastyear = year;


if(monthName == "December")
var nextyear = year +1;
else
var nextyear = year;



for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {

text += '<TR ALIGN="right" VALIGN="top">'

for (var col = 1; col <= 7; ++col) {

if (digit > lastDate)

break

if (curCell < firstDay)  {

text += '<TD bgcolor= #b0b0b0></TD>';

curCell++

} else {

var digit1 = digit 

{if (digit <= 9)

digit1 = '0'+ digit

if (digit >= 10)

digit1 = digit

}


if  (col == 6 || col == 7 || col == 1 || digit< 07){ // current cell represent today's date

text += '<TD bgcolor= #d0d0d0 HEIGHT=' + cellHeight + '>'

text += '<FONT COLOR="' + todayColor + '"+ Font Size = -1>'

text += +digit+'<br>'

text += '</FONT><BR>'

text += '</FONT>'

text += '</TD>'



} else

text += '<TD HEIGHT=' + cellHeight + '><b><font size =-1>'+opentoon + year + refmo + digit1+ midtoon + digit + closetoon+'</b></TD>'

digit++

}

}



}

// close all basic table tags


text += '</TABLE>'
text += '<TABLE BORDER=' + "0" + ' CELLSPACING=' + cellspacing + '>'
text += '</TR>'
text += '<TR ALIGN="right" VALIGN="top">'
text += '<TD width = 100><b><font size =+1>Prev. Month</b></TD>';
text += '<TD width = 25>&nbsp;</TD>';
text += '<TD width = 25>&nbsp;</TD>';
text += '<TD width = 25>&nbsp;&nbsp;</TD>';
text += '<TD width - 25>&nbsp;</TD>';
text += '<TD width = 25>&nbsp;</TD>';
text += '<TD width = 100><b><font size =+1>'+ opentoon + nextyear +"_"+ nextmo + midtoon+ "Next Month" + closetoon +'</b></TD>';

text += '</TR>'
text += '</TABLE>'

text += '</CENTER>'



// print accumulative HTML string

document.write(text) 

}





