<!-- ***************** credit & instructions **************** -->
<!-- ******************************************************** -->

<!-- To install: ******************************************** -->
<!-- 1) change the formatting variables for your needs ****** -->
<!-- 2) put this file "fullisocalendar.js" where you like *** -->
<!-- 3) point to it from the script launcher in your doc. *** -->
<!-- ******************************************************** -->

<!-- ******************************************************** -->
<!-- PLEASE KEEP THE FOLLOWING CREDIT, YOU MAY NEED IN FUTURE -->
<!-- ******************************************************** -->
<!-- *** Author: Alberto Leo ******************************** -->
<!-- *** Program: full ISO Calendar ver. 2.1 **************** -->
<!-- *** URL: www.leo-alberto.it **************************** -->
<!-- ******************************************************** -->


<!-- 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: #474848; font-size: 8pt; font-family:verdana; letter-spacing: -1pt;"';  // calendar style parameters
var hlight_style = '"background-color: #FFFFFF; color:#085A18; font-weight: bold; font-size: 10pt; border: solid #f0f0f0; border-width:1;"';  // highlighted cell style parameters
var cal_bgcolor = '#F6F6F6';        // calendar background color
var nr_week_bgcolor = '#FFFFFF';    // weekday background color
var wday_bgcolor = '#FFFFFF';       // weekday background color
var bars_bgcolor = '#f0f0f0';       // background color of top & bottom bars
var cell_size = 20;                 // size of each cell
var bars_height = 25;               // top & bottom height bars
var lang = 0;                       // set language, 0=english, 1=italian, 2=german, 3=french, 4=spanish

//  SET ARRAYS FOR DIVERSE LANGUAGES
var day_of_week = new Array()
day_of_week[0] = new Array('M','T','W','T','F','S','S');
day_of_week[1] = new Array('Lu','Ma','Me','Gi','Ve','Sa','Do');
day_of_week[2] = new Array('Mo','Di','Mi','Do','Fr','Sa','So');
day_of_week[3] = new Array('Lu','Ma','Me','Je','Ve','Sa','Di');
day_of_week[4] = new Array('Lu','Ma','Mi','Ju','Vi','Sá','Do');


var month_of_year = new Array()
month_of_year[0] = new Array
('January','February','March','April','May','June','July','August','September','October','November','December');
month_of_year[1] = new Array
('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');
month_of_year[2] = new Array
('Januar','Februar','Märzì','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
month_of_year[3] = new Array
('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
month_of_year[4] = new Array
('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');

var current_daya = new Array('Day ','Giorno numero ','Tag zahl ','Jour nombre ','Dia número ');
var current_dayb = new Array(' of 365',' dell\'anno',' von das jahr',' de le année',' de los año');
var week = new Array('Wk','Se','Wo','Se','Se');

//  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 = "";  // 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

// 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+' HEIGHT=20 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+' HEIGHT=20 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=#ffffff><TR><TD>';
cal += '<TABLE border=1 bordercolor=#f0f0f0 cellspacing=0 cellpadding=1 style='+cal_style+'>' + TR_start;
cal += '<TD height='+bars_height+' COLSPAN='+ num_OF_cols +' BGCOLOR='+bars_bgcolor+' style="border: solid #f0f0f0; border-width: 0;" align="center"><B>';
cal +=  month_of_year[lang][month] + ' ' + year + '</B>' + TD_end + TR_end;
cal +=  TR_start + TD_start_set + week[lang] + 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[lang][index] + TD_end;

// PRINTS DAY
else
cal += TD_dayw + day_of_week[lang][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; }
// END CONVERTING FOR ISO (european) FORMAT



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="'+cal_style+' border:solid #A4CE3C;border-width:1;" align=center><b>';

// cal += current_daya[lang] + numyeardays + current_dayb[lang];

cal += '</B></TD></TR></TABLE></TD></TR></TABLE>';

//  PRINT CALENDAR
document.write(cal);
