/*
Displays today's date as a late Roman would have written it.
Copyright (C) 2002 JPD, 25 Jan 2002.
Ack:
- Paul Lewis for description of the Roman Calendar (http://www.wilkiecollins.demon.co.uk/roman/calhis.htm)
- Dougie Lawson, The JavaScript Source http://javascript.internet.com for the "Roman" & "Init" functions.
*/

function Init()
{
 this.length = Init.arguments.length;
 for ( var i = 0; i < this.length; i++ ) this[ i + 1 ] = Init.arguments[ i ];
}

function Roman(number)
{
if (number < 1) { alert(number+" is too small\nMinumum value is 1"); number = 1; }
if (number > 5999) { alert(number+" is too big\nMaximum value is 5999"); number = 5999; }
var roman_unit = new Init("","I","II","III","IV","V","VI","VII","VIII","IX");
var roman_tens = new Init("","X","XX","XXX","XL","L","LX","LXX","LXXX","XC");
var roman_hund = new Init("","C","CC","CCC","CD","D","DC","DCC","DCCC","CM");
var roman_thou = new Init("","M","MM","MMM","MMMM","MMMMM");

var v = 0; var w = 0; var x = 0; var y = 0;
v = ((number - (number % 1000)) / 1000) + 1;
number = (number % 1000);
w = ((number - (number % 100)) / 100) + 1;
number = (number % 100);
x = ((number - (number % 10)) / 10) + 1;
y = (number % 10) + 1;
return (" " + roman_thou[v] + roman_hund[w] + roman_tens[x] + roman_unit[y]);
}

function ShowRomanDate(year,ilmonth,date)
{
  var months= new Init("IAN. ","FEB. ","MART. ","APR. ","MAI. ","IVN. ","IVL. ","AVG. ","SEPT. ","OCT. ","NOV. ","DEC. ","IAN. ")
  var LeapYear=0;			// flag...
  if (year%4 == 0) LeapYear=1;		// ...set to 1 if leap year...
  if (year%100 == 0) LeapYear=0;   	// ...but not if a century year...
  if (year%400 == 0) LeapYear=1;   	// ...but set if div by 400.

  // Set up month length (ignore leap year for now):
  var monlength=31;
  if ((ilmonth==9)||(ilmonth==4)||(ilmonth==6)||(ilmonth==11)) monlength=30;
  if (ilmonth==2) monlength=28;

  var slmonth=months[ilmonth];
  var daystr="";
  var kalends=1;
  var nones=5;
  var ides=13;
  var nextyear=0;

  if ((ilmonth==3)||(ilmonth==5)||(ilmonth==7)||(ilmonth==10))		//nones and ides different in these months
    {
     var nones=7;
     var ides=15;
    }

  // Start working out the date string:
  if (date>ides)	// Start at end of month, after the ides.
    {
     if ((ilmonth==2) && (date>25) && (LeapYear==1)) monlength=29;   // Only affects dates >25 in a Leapyear Feb
     daystr="A.D. " + Roman(monlength-date+2);		//AD=ante diem; counting down to Kalends of next month, inclusive.
     if (date==monlength) daystr="PRID. ";
     if (ilmonth==12) nextyear = 1;	// Looks ahead to Kalends of Jan in the following year, so add one to year ...
     daystr+= " KAL. " + months[ilmonth +1];	//...before the kalends of the next month
    }

  else if (date>nones)		// Next, second quarter of month between nones and ides.
    {
     daystr="A.D. " + Roman(ides-date+1) + " ";
     if (date==(ides-1)) daystr="PRID. ";
     if (date==ides) daystr="";
     daystr+= "ID. " + months[ilmonth];
    }

  else if (date>kalends)	// Next, first quarter of month between kalends and nones.
    {
     daystr="A.D. " + Roman(nones-date+1) + " ";
     if (date==(nones-1)) daystr="PRID. ";
     if (date==nones) daystr="";
     daystr+= "NON. " + months[ilmonth];
    }
  else if (date==kalends)	//Finally, Kalends (first of month).
    {
     daystr="KAL. " + months[ilmonth];
    }

  // Fiddle: Bizarrely, they counted the 25th Feb in Leapyear as "24th again".
  if ((date==25) && (ilmonth==2) && (LeapYear==1)) daystr="A.D. BIS VI KAL. MART.";

  // Rome founded in 753BC (AVC=Ab Urbe Condita).
  daystr += " " + Roman(year+753+nextyear) + " AVC.";

  document.write(daystr);
}
//-------------------------------------------------------------------
/*
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>

15/3/2002: Amended by JPD to reduce size of calendar, remove time, highlight today more effectively,
	correct bug in leapYear function, and update HTML.
*/


function leapYear(year)
{
var leap=0;
if (year % 4 == 0) leap=1;  	// basic rule
if (year % 100 == 0) leap=0;  	// but not if a century year
if (year % 400 == 0) leap=1;  	// but is if a tercentury year

if (leap==1) return true;
  else
 {return false}
}

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 year = now.getYear()
if (year < 1000) year+=1900
var month = now.getMonth()

//year=2003
//month=1

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) {
// create basic table structure

var text = "" // initialize accumulative variable to empty string
text += '<div align="center">'
text += '<table class="caltable" cellspacing="4px">'   // table settings
text += '<th colspan="7" class="calth">' // create table header cell
// set font for table header:
text += '<p class="calp">'
text += monthname + ' ' + year
text += '<\/p>' // close table header's font settings
text += '<\/th>' // close header cell

// variables to hold constant settings
var openCol = '<td class="caltd"> '
var closeCol = '<\/td>'

// create array of abbreviated day names
var weekDay = new Array(7)
weekDay[0] = "Sun"
weekDay[1] = "Mon"
weekDay[2] = "Tue"
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>'
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>'
  for (var col = 1; col <= 7; ++col) {
    if (digit > lastdate) break
    if (curCell < firstday) {
      text += '<td class="caltd">&nbsp;<\/td>';
      curCell++
    }
    else {
      text += '<td class="caltd'
      if (digit == date) { // current cell represents today's date, so change foregnd & backgnd colour
        text += 'today'
      }
      text += '">' + digit + '<\/td>'
      digit++
    }
  }  //end for col
  text += '<\/tr>'
}  // end for row


// close all basic table tags
text += '<\/table>'
text += '<\/div>'

// print accumulative HTML string
document.write(text)
}

