<!-- Begin Calendar

/* VARIABLES FOR FORMATTING
NOTE: You can format the 'BORDER', 'BGCOLOR', 'FONT', 'BORDERCOLOR', 'ETC.'
      tags to customize your iso calendar's look. */

var cal_style = '"color: #0000ff; font-size: 8pt; font-family:verdana; letter-spacing: -1pt;"';  // calendar style parameters
var hlight_style = '"background-color: #ffffff; color:#ff0000; font-weight: bold; border: solid #0000ff; border-width:1;"';  // highlighted cell style parameters
var cal_bgcolor = '#FFFFFF';        // calendar background color
var nr_week_bgcolor = '#00d000';    // number week background color
var wday_bgcolor = '#c0c0c0';       // weekday background color
var bars_bgcolor = '#C1D6EC';       // background color of top & bottom bars
var cell_size = 20;                 // size of each cell
var bars_height = 22;               // top & bottom height bars


//  SET ARRAYS
var day_of_week = new Array('Lu','Ma','Me','Gi','Ve','Sa','Do');
var month_of_year = new Array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');

//  DECLARE AND INITIALIZE GLOBAL VARIABLES
var Calendar = new Date();
var year = Calendar.getYear();	      // Returns year
if ( year < 1000 ) { year += 1900; }  // Correction for 2 digit year format
var month = Calendar.getMonth();      // Returns month (0-11)
var today = Calendar.getDate();       // Returns day (1-31)
var weekday = Calendar.getDay();      // Returns weekday (0-6)

var nowepoc = Date.UTC(year,month,today+1,0,0,0);    // getting current day from epoc, millisec 

// CONVERTING FOR ISO (european) FORMAT
weekday = weekday-1
if (weekday < 0) { weekday = 6; }
// END CONVERTING FOR ISO (european) FORMAT

var num_OF_cols = 8;                 // number of table's columns
var DAYS_OF_WEEK = num_OF_cols - 1;  // days of week
var DAYS_OF_MONTH = 31;              // max number of days in a month
var cal;                             // Used for printing
var flag=0;


Calendar.setDate(1);    // Start the calendar day at '1'
Calendar.setMonth(month);    // Start the calendar month at now


 // GETTING ISO FORMAT WEEK INFO

	unomese = Date.UTC(year,month,2,0,0,0);    // getting first day of current month - epoc, millisec
	unogen = Date.UTC(year,0,1,0,0,0);         // getting first day of january current year - epoc, millisec

	var unogennaio = new Date();
	unogennaio.setYear(year);
	unogennaio.setMonth(0);
	unogennaio.setDate(1);
	gsett1gennaio = unogennaio.getDay();       // getting weekday of january firstday current year

var startfirstweek = 0;
var numyeardays = (nowepoc-unogen)/86400000;   // getting today number of days since january firstday 
var numdays1mnth = (unomese-unogen)/86400000;  // getting number of days from month firstday since january firstday 
var nOfWk = 0;
var nOWeeks = 0;  // variabile non pił usata per incongruenze, ma esistente nelle versioni precedenti

 // OFFSET WEEKDAY FOR ISO FORMAT
if ( gsett1gennaio == 1 ) {startfirstweek = 7;}
if ( gsett1gennaio == 0 ) {startfirstweek = 1;}
if ( gsett1gennaio == 6 ) {startfirstweek = 2;}
if ( gsett1gennaio == 5 ) {startfirstweek = 3;}
if ( gsett1gennaio == 4 ) {startfirstweek = 4;}
if ( gsett1gennaio == 3 ) {startfirstweek = 5;}
if ( gsett1gennaio == 2 ) {startfirstweek = 6;}


// nr. weeks at begining of month 
if ( gsett1gennaio > 4 || gsett1gennaio == 0 && month == 0) { nOfWk = ""; } else { nOfWk =  1; }

var nOfWkOffset = ((numdays1mnth-startfirstweek + 7) /7) - Math.floor((numdays1mnth-startfirstweek + 7) /7);

if (month != 0) {

if (nOfWkOffset == 0 || gsett1gennaio > 4)

{ nOfWk = Math.floor((numdays1mnth-startfirstweek + 7) /7); } else {

nOfWk = Math.floor((numdays1mnth-startfirstweek + 7) /7) + 1; }

}    // nr. weeks at begining of month but january


// routine to calculate the actual week number (day by day)
var nOWeeksOffset = ((numyeardays-startfirstweek + 7) /7) - Math.floor((numyeardays-startfirstweek + 7) /7);

// variable to check if the division has no modulous (only on sunday, number multiple of 7)


if (gsett1gennaio < 5) {

if (nOWeeksOffset == 0) 

{ nOWeeks = Math.floor((numyeardays-startfirstweek + 7) / 7) ; } else {

 nOWeeks = Math.floor((numyeardays-startfirstweek + 7) / 7) + 1 ; } }

// case of year started on day minor than thursday (gsett1gennaio < 5)


if (gsett1gennaio > 4) {

if (nOWeeksOffset == 0)

{ nOWeeks = Math.floor((numyeardays-startfirstweek + 7) / 7) - 1 ; } else {

 nOWeeks = Math.floor((numyeardays-startfirstweek + 7) / 7); } }

// case of year started on day greater than thursday (gsett1gennaio > 4)

// END GETTING ISO FORMAT WEEK INFO

 // OTHER VARIABLES

var TR_start = '<TR>';
var TR_end = '</TR>';
var highlight_start = '<TD WIDTH='+cell_size+' align="center" style='+hlight_style+'>';
var highlight_end   = '</B></font></TD>';
var TD_start = '<TD WIDTH='+cell_size+' align=CENTER>';
var TD_start_set = '<TD WIDTH='+cell_size+' bgcolor='+nr_week_bgcolor+' align=center>';
var highlight_start_set = '<TD WIDTH='+cell_size+' align="center" style='+hlight_style+'>';
var highlight_set_end   = '</B></FONT></TD>';
var TD_dayw = '<TD WIDTH='+cell_size+' bgcolor='+wday_bgcolor+' align=center>';
var TD_highlight_dayw = '<TD WIDTH='+cell_size+' align="center" style='+hlight_style+'>';
var TD_end = '</TD>';

/* BEGIN CODE FOR CALENDAR
NOTE: some minor changes can be set here 
to customize your calendar's look.*/

cal =  '<TABLE bgcolor='+cal_bgcolor+' BORDER=0 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR=#0000ff><TR><TD>';
cal += '<TABLE border=0 bordercolor=#0000ff cellspacing=0 cellpadding=1 style='+cal_style+'>' + TR_start;
cal += '<TD height='+bars_height+' COLSPAN='+ num_OF_cols +' BGCOLOR='+bars_bgcolor+' style="border: solid #4169ff; border-width: 1;" align="center"><B>';
cal +=  month_of_year[month] + ' ' + year + '</B>' + TD_end + TR_end;
cal +=  TR_start + TD_start_set + 'Se' + TD_end;

//   NOTHING TO EDIT BELOW THIS POINT, BUT YOU CAN EXPERIMENT IF YOU WISH :-)  //

// LOOPS FOR EACH DAY OF WEEK
for(index=0; index < DAYS_OF_WEEK; index++)
{

// BOLD TODAY'S DAY OF WEEK
if(weekday == index)
cal += TD_highlight_dayw + day_of_week[index] + TD_end;

// PRINTS DAY
else
cal += TD_dayw + day_of_week[index] + TD_end;
}

cal += TR_end;

// CONVERTING FOR ISO (european) FORMAT
var giornosett = Calendar.getDay()-1;
if (giornosett < 0) { giornosett = 6; }

var weekdayflag = giornosett;  // set variable to use for filling last row blank cell

   // SETS HEAD OF ROW FOR WEEK STARTING WITH AT LEAST A BLANK GAP AND NUMBER OF WEEK
if ( giornosett != 0 ) { cal += TR_start;

if ( nOWeeks == nOfWk ) {

cal += highlight_start_set + nOfWk + highlight_set_end;  // HIGHLIGHT TODAY'S NUMBER OF WEEKS

} else { cal += TD_start_set + nOfWk + TD_end; }        // PRINTS ORDINARY TODAY'S NUMBER OF WEEKS

} // END IF CONDITION THAT SETS HEAD OF ROW...

// FILL IN BLANK GAPS UNTIL TODAY'S DAY
for(idx=0; idx < giornosett; idx++)
{ cal += TD_start + '&nbsp;' + TD_end; }

// LOOPS FOR EACH DAY IN CALENDAR
for(index=0; index < DAYS_OF_MONTH; index++)
{
if( Calendar.getDate() > index )     // this condition stops writing day number for month shorter of 31 days
{
  // RETURNS THE NEXT DAY TO PRINT
  week_day = giornosett;

  // START NEW ROW FOR FIRST DAY OF WEEK
  if(week_day == 0)
{ cal += TR_start;

if ( nOWeeks == nOfWk ) {

cal += highlight_start_set + nOfWk + highlight_set_end;  // HIGHLIGHT TODAY'S NUMBER OF WEEKS

} else { cal += TD_start_set + nOfWk + TD_end; }        // OR PRINTS ORDINARY TODAY'S NUMBER OF WEEKS

 }  // END IF CONDITION OF NEW ROW FOR FIRST DAY OF WEEK

  // SET VARIABLE INSIDE LOOP FOR INCREMENTING PURPOSES
  var day  = Calendar.getDate();

  // HIGHLIGHT TODAY'S DATE
  if( today == Calendar.getDate() )
{ cal += highlight_start + day + highlight_end + TD_end;
flag++;
  // OR PRINTS ORDINARY DAY
}  else { cal += TD_start + day + TD_end; flag++;}

 }    // end if condition that stops month shorter of 31 days


  // INCREMENTS UNTIL END OF THE MONTH
  Calendar.setDate(Calendar.getDate()+1);


// CONVERTING FOR ISO (european) FORMAT
giornosett = Calendar.getDay()-1;
if (giornosett < 0) { giornosett = 6; }

idx++;
if ( idx > 6 ) { idx = 0; nOfWk++; }

} // end for loop


// FILLING LAST ROW BLANK CELL
var blanks = 7 - ((flag + weekdayflag) % 7);
if ( blanks == 7 ) { blanks = 0; }

for (i=0; i<blanks; i++)
{ cal += TD_start + '&nbsp;' + TD_end; }

cal += '</TR><TR><TD height='+bars_height+' COLSPAN="'+ num_OF_cols +'" BGCOLOR='+bars_bgcolor+' style=" border:solid #0000ff;border-width:1;" align=center><b>' + numyeardays + '° giorno dell\'anno';

cal += '</B></TD></TR></TABLE></TD></TR></TABLE>';

//  PRINT CALENDAR
document.write(cal);

//  End -->
