/*
Copyright 1996 - Tomer and Yehuda Shiran
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>

Event function added by Dexxaboy, www.dexxaboy.com
*/

setCal()

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] = "Jan"
ar[1] = "Feb"
ar[2] = "March"
ar[3] = "April"
ar[4] = "May"
ar[5] = "June"
ar[6] = "July"
ar[7] = "Aug"
ar[8] = "Sep"
ar[9] = "Oct"
ar[10] = "Nov"
ar[11] = "Dec"

// return name of specified month (parameter)
return ar[month]
}

function setCal() {
// standard time attributes
var now = new Date()
var year = now.getYear()
if (year < 1000)
year+=1900
var month = now.getMonth()
var monthName = getMonthName(month)
var date = now.getDate()
now = 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 = 1 // height of the table's header cell
var border = 0 // 3D height of table's border
var cellspacing = "0" // width of table's border
var headerColor = "FFFFFF" // color of table's header
var headerSize = "2" // size of tables header font
var colWidth = "4" // width of columns in table
var dayCellHeight = "2" // height of cells containing days of the week
var dayColor = "" // color of font representing week days
var cellHeight = "5" // height of cells representing dates in the calendar
var todayColor = "FFAB0D" // color specifying today's date in the calendar

// create basic table structure
var text = "" // initialize accumulative variable to empty string
text += '<CENTER>'
text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
text += '<TH  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   WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
openCol += '<FONT SIZE="' + headerSize + '" COLOR="' + dayColor + '">'
var closeCol = '</FONT></TD>'

// create array of abbreviated day names
var weekDay = new Array(7)
weekDay[0] = "S"
weekDay[1] = "M"
weekDay[2] = "T"
weekDay[3] = "W"
weekDay[4] = "T"
weekDay[5] = "F"
weekDay[6] = "S"

// 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

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></TD>';
curCell++
} else {
if (digit == date) { // current cell represent today's date
text += '<TD HEIGHT=' + cellHeight + ' valign="top">'
text += '<FONT COLOR="' + todayColor + '" SIZE="2"><b>'
text += digit
text += '</b></FONT><BR>'
text += '</FONT>'
text += '</TD>'
} else
text += '<div id=calevents><TD HEIGHT=' + cellHeight + '>' + digit + '</TD>'
digit++
}
}
text += '</TR>'
}

// close all basic table tags
text += '</div>'
text += '</TABLE>'
text += '</CENTER></FONT>'

// print accumulative HTML string
document.write(text)
document.write("<table align='right'><td id='clock'></td></table>") 
}

//Calendar End

var the_timeout;
function writetime()
{

now = new Date();
var hrs = now.getHours();
var mins = now.getMinutes();
var secs = now.getSeconds();
mins = fixtime(mins);
secs = fixtime(secs);
var dn = "AM";

var day = now.getDay();
var mday = now.getDate();
var month = now.getMonth();
var year = now.getFullYear();

var DaysOfWeek = new Array(7);
DaysOfWeek[0] = "Sunday";
DaysOfWeek[1] = "Monday";
DaysOfWeek[2] = "Tuesday";
DaysOfWeek[3] = "Wednesday";
DaysOfWeek[4] = "Thursday";
DaysOfWeek[5] = "Friday";
DaysOfWeek[6] = "Saturday";

var MonthsOfYear = new Array(12);
MonthsOfYear[0] = "January";
MonthsOfYear[1] = "February";
MonthsOfYear[2] = "March";
MonthsOfYear[3] = "April";
MonthsOfYear[4] = "May";
MonthsOfYear[5] = "June";
MonthsOfYear[6] = "July";
MonthsOfYear[7] = "August";
MonthsOfYear[8] = "September";
MonthsOfYear[9] = "October";
MonthsOfYear[10] = "November";
MonthsOfYear[11] = "December";


if (hrs > 12) { dn = "PM"; hrs = hrs - 12; }
if (hrs == 0) { hrs = 12; }

var clock = hrs+ ":" +mins+ ":" +secs+ " " +dn;
document.getElementById('clock').innerHTML = clock;

the_timeout = setTimeout('writetime();',1000);
}
writetime();
function fixtime(num)
{
if (num < 10 )
{num = "0" + num;}
return num;
}

// Clock End


//Events Start
function event(date,msg,color){

var range = document.body.createTextRange(); 
range.moveToElementText(document.getElementById("calevents"));

if(range.findText(date)){
range.pasteHTML('<font color='+color+' onclick=\'alert("'+msg+'")\' style=\'cursor:hand\'>'+date+'</font>');
range.collapse(false);
}}

// event("11","Veterans Day (US)","Color");






