// This script came from Uncle Jim's Web Designs
// www.jdstiles.com

function montharray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
   this[0] = m0;
   this[1] = m1;
   this[2] = m2;
   this[3] = m3;
   this[4] = m4;
   this[5] = m5;
   this[6] = m6;
   this[7] = m7;
   this[8] = m8;
   this[9] = m9;
   this[10] = m10;
   this[11] = m11;
}

function MakeArray(n) {this.length = n; return this;}
  var Days = new MakeArray(7);
  var Months = new MakeArray(12);
  var Roman  = new MakeArray(31); // numeri romani dei giorni
  
  Days[1]="Dominicia"; Days[2]="Lunae"; Days[3]="Martis";   Days[4]="Mercurii";
  Days[5]="Iovis"; Days[6]="Veneris"; Days[7]="Saturni";

  Months[1]="IANVARIVS"; Months[2]="FEBRVARIS"; Months[3]="MARTIVS";   Months[4]="APRILIS"; 
  Months[5]="MAIVS"; Months[6]="IVNIVS"; Months[7]="IVLIVS";   Months[8]="AVGVSTVS"; 
  Months[9]="SEPTEMBER"; Months[10]="OCTOBER"; Months[11]="NOVEMBER"; 
  Months[12]="DECEMBER";

  Roman[1]="I";Roman[2]="II";Roman[3]="III";Roman[4]="IV";Roman[5]="V";Roman[6]="VI";Roman[7]="VII";
  Roman[8]="VIII";Roman[9]="IX";Roman[10]="X";Roman[11]="XI";Roman[12]="XII";Roman[13]="XIII";Roman[14]="XIV";
  Roman[15]="XV";Roman[16]="XVI"; Roman[17]="XVII";Roman[18]="XVIII"; Roman[19]="XIX";Roman[20]="XX";
  Roman[21]="XXI";Roman[22]="XXII"; Roman[23]="XXIII";Roman[24]="XIV"; Roman[25]="XXV";Roman[26]="XXVI";
  Roman[27]="XXVII";Roman[28]="XXVIII"; Roman[29]="XXIX";Roman[30]="XXX"; Roman[31]="XXXI";
  
 
  /** scrittura del giorno della settimana  giorno mese e anno **/
  function getNiceDate(theDate) {
  giornoR = theDate.getDate();
  giornoR = parseIntToRoman(giornoR, 1);
 
  return Days[theDate.getDay()+1] + " " + giornoR + " " +
  Months[theDate.getMonth()+1] + " " + year }
  
    
 function calendar()
{

   today = new Date();
   var thisDay;
 //  var tt,result;
   var monthNames = "GenFebMarAprMagGiuLugAgoSetOttNovDic";
   var monthNames2 = " 1 2 3 4 5 6 7 8 9101112";
   var monthDays = new montharray(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   
   	year = today.getYear();
	year = year % 100;
	year = ((year < 50) ? (2000 + year) : (1900 + year));
	if (((year % 4 == 0) 
	&& !(year % 100 == 0))
	||(year % 400 == 0));
	thisDay = today.getDate(); // ------------ giorno odierno 

	//** funzione di conversione da anno a anno in numero romano */
   year = parseIntToRoman(year, 1); 	
   nDays = monthDays[today.getMonth()];
   firstDay = today;
   firstDay.setDate(1);
   var lastMod = new Date();
   startDay = firstDay.getDay();

   //
   // scrivo i giorni della settimana
   //  
   document.write("<TABLE BORDER=\"5\" CELLPADDING=\"5\">");
   document.write("<TR><TH  id='RM' COLSPAN=7>");
   document.write(getNiceDate(lastMod));
   document.write("<TR><TH id='R'>Lun<TH id='R'>Mar<TH id='R'>Mer<TH id='R'>Iov<TH id='R'>Ven<TH id='R'>Sat<TH id='R'>Dom");
   document.write("<TR>");

   column = 0;
   for (i=1; i<startDay; i++) // i= 0 Domenica i=1 Lunedi
   {

      document.write("<TD>");
      document.write("<CENTER>");
      document.write(" ");
      column++;
   }
  
   for (i=1; i<=nDays; i++)
   {
         document.write("<TD>");
      if (column == 6) // colonna 6 = Domenica
         document.write("<FONT COLOR=\"#FF4B00\">");

      if (column == 5) // colonna 5 = Sabato
         document.write("<FONT COLOR=\"#4B00FF\">");               

      if (i == thisDay)
		document.write("<B><FONT COLOR=\"#00FFCB\">");
        document.write("<CENTER>");
        //document.write(i); // scrivo i numeri del mese i arabo
        document.write(Roman[i]); // scrivo numeri del mese in romano
		document.write("</CENTER>");
      if (i == thisDay)
         document.write("</B>")

      if (column == 7||column == 0||i == thisDay) 
         document.write("</FONT>")
      column++;

      if (column == 7)
      {
         document.write("<TR>");
         column = 0;
      }
   }

   document.write("</TABLE>");
}
