//
//                  Calendario vers. 2.0
//
//            (c)2002-2004 by Maurizio Mauri
//
//               mailto: M.Mauri@itaer.it
//

// Immagini
var img = new Array('images/gennaio.jpg', 'images/febbraio.jpg', 'images/marzo.jpg',
               'images/aprile.jpg', 'images/maggio.jpg', 'images/giugno.jpg',
               'images/luglio.jpg', 'images/agosto.jpg', 'images/settembre.jpg',
               'images/ottobre.jpg', 'images/novembre.jpg', 'images/dicembre.jpg');

labs = new Array("multimediale", "meteo", "biblio", "nav", "aero",
	"scienze", "radar", "edf", "matem", "inglese", "disegno",
	"cic", "elettro", "fisica");

// colori
var backtable = '#90C0FF';
var calendback = '#EEC68E';
var lines = '#404040';
var bright = '#000000';
var festa = '#FD9139';
var bgvacanza = "#F9E9D1"; // "#F0F0FF";
var bgright = "#00D642";


// dimensioni dell'immagine
var xwidth = 321;
var xheight = 180;
var browser = document.layers ? 0 : document.all ? 1 : 2;

// classi
document.write('<style type="text/css">\n<!--');
document.write('.cal { font: italic 11px/16px Arial, Helvetica, sans-serif; color: #996633;}');
document.write('.num { font-family: Arial, Helvetica, sans-serif; font-size: 14px; text-decoration:none; text-align:right; padding:2px;}');
document.write('.numlinked { font: bold 14px Arial, Helvetica, sans-serif; text-decoration:none; color: #FF6600}');
document.write('.caltitolo { font: normal 20px Verdana, Arial, Helvetica, sans-serif; letter-spacing: 4px; text-decoration: none}');
document.write('.calw {text-align: center; font: bold 12px "trebuchet MS", Arial, Helvetica, sans-serif; letter-spacing: 4px; width:100%}');
document.write('#calx {background-color: transparent}');
document.write('#calz {width: 100%; border-color: #666666 #666666 #DDDDDD #666666; border-style: solid; border-width: 2px 2px 0px 2px; background-color: #F0F0F0; color: #808000}');
document.write('#calb {width: 100%; border-color: #666666 #666666 #666666 #666666; border-style: solid; border-width: 0px 2px 2px 2px; background-color: #E0E0E0; color: #808000}');
document.write('#cala {width: 100%; border-color: #FFBB88; border-style: solid; border-width: 0px 0px 2px 0px; color: #FF0000}');
document.write('.calhead {font: italic 13px Arial, Helvetica, sans-serif; color: #999900; text-align: center;}');
document.write('.numero {font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #000000; text-align: right;}');
document.write('.numero a {font-weight: bold; color: #FF3300; text-decoration: none; display: block; padding: 3px;}');
document.write('.numero a:hover {text-decoration: none; display: block; background-color: #FFFF00;}');
document.write('.numero span {text-decoration: none; display: block; padding: 3px;}');
document.write('.annox {font: bold 20px Verdana, Arial, Helvetica, sans-serif; letter-spacing: 4px; color: #FF0000;}');
document.write('.mesex {font: bold 12px Arial, Helvetica, sans-serif; letter-spacing: 4px; color: #808000;}');
document.write('-->\n</style>');

var xr = random_pages();
creaCalwin();

menuxh = new Array("tabx", "tabx",
    0, "Settembre", labs[xr[0]] + ".htm" + "?mese=9", "SETTEMBRE",
    1, "Ottobre", labs[xr[1]] + ".htm" + "?mese=10", "OTTOBRE",
    2, "Novembre", labs[xr[2]] + ".htm" + "?mese=11", "NOVEMBRE",
    3, "Dicembre", labs[xr[3]] + ".htm" + "?mese=12", "DICEMBRE",
    4, "Gennaio", labs[xr[4]] + ".htm" + "?mese=1", "GENNAIO",
    5, "Febbraio", labs[xr[5]] + ".htm" + "?mese=2", "FEBBRAIO",
    6, "Marzo", labs[xr[6]] + ".htm" + "?mese=3", "MARZO",
    7, "Aprile", labs[xr[7]] + ".htm" + "?mese=4", "APRILE",
    8, "Maggio", labs[xr[8]] + ".htm" + "?mese=5", "MAGGIO",
    9, "Giugno", labs[xr[9]] + ".htm" + "?mese=6", "GIUGNO"
    );


// ------ Non cambiare ----------
var mesi = new Array('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno',
               'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');

var days = new Array('Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa', 'Do');
var dd = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

var today = new Date();
var anno = today.getFullYear();
var mese = today.getMonth();
var currday = today.getDate();
var cellwidth = Math.floor(xwidth / 7);
xwidth = cellwidth * 7;
var xmese = 0;
var aboutx = false;
var isOn = false;
var thisPath = "../";
var vacanza = new Array("-090814", "091001-091002", "091122-100006",
		"100510-100731");
var note = new Array(
		"090801", "Collegio Docenti<br>Riunione dipartimenti", null,
		"090802", "Prove di recupero", null,
		"090803", "Prove di recupero", null,
		"090804", "Scrutini", null,
		"090805", "Scrutini", null,
		"090807", "Riunione dipartimenti", null,
		"090808", "Esami integrativi", null,
		"090809", "Riunione dipartimenti", null,
		"090814", "Collegio docenti", null,
		"090815", "Inizio attivit&agrave; didattiche", null,
		"090823", "Classi 1<sup>e</sup> e 3<sup>e</sup>: consigli di classe con le famiglie", null,
		"090824", "Classi 1<sup>e</sup> e 3<sup>e</sup>: consigli di classe con le famiglie", null,
		"090825", "Classi 1<sup>e</sup> e 3<sup>e</sup>: consigli di classe con le famiglie", null,
		"090830", "Termine ultimo consegna, via e-mail, dei progetti", null,
		"090901", "Consigli di classe 2-4-5", null,
		"090902", "Consigli di classe 2-4-5", null,
		"000913", "Collegio dei docenti", null,
		"090922", "Elezioni rappresentanti studenti e genitori", null,
		"091009", "Consigli di classe", "../comunic/cdc1109.htm",
		"091010", "Consigli di classe", "../comunic/cdc1109.htm",
		"091011", "Consigli di classe", "../comunic/cdc1109.htm",
		"091012", "Consigli di classe", "../comunic/cdc1109.htm",
		"091013", "Consigli di classe", "../comunic/cdc1109.htm",
		"091015", "Elezione rappresentanti genitori e alunni al c.d.c", null,
		"091016", "Elezione rappresentanti genitori e alunni al c.d.c", null,
		"091030", "Settimana di recupero e potenziamento", null,
		"091109", "Ricevimento pomeridiano genitori", "../comunic/ricev.htm",
		"091111", "Ricevimento pomeridiano genitori", "../comunic/ricev.htm",
		"091112", "Open Day", null,
		"091117", "Classi 5: simulazione 3a prova", null,
		"100028", "Scrutini 1&deg; periodo", null,
		"100029", "Scrutini 1&deg; periodo", null,
		"100101", "Scrutini 1&deg; periodo", null,
		"100102", "Scrutini 1&deg; periodo", null,
		"100103", "Scrutini 1&deg; periodo", null,
		"100104", "Scrutini 1&deg; periodo", null,
		"100105", "Scrutini 1&deg; periodo", null,
		"100116", "Incontro D.S. - responsabili dip.", null,
		"100117", "Riunione interdipartimentale", null,
		"100119", "Collegio Docenti", null,
		"100127", "Consegna al D.S. relazione intermedia sui progetti", null,
		"100209", "Riunione responsabili dipartimenti", null,
		"100210", "Riunione dipartimenti", null,
		"100212", "Simulazione prova italiano classi 5<sup>e</sup>", null,
		"100214", "PI day (la festa del PI greco)", "http://www.piday.org",
		"100222", "Consigli di classe", null,
		"100223", "Consigli di classe", null,
		"100224", "Consigli di classe", null,
		"100225", "Consigli di classe", null,
		"100226", "Consigli di classe", null,
		"100227", "Consigli di classe", null,
		"100315", "Simulazione terza prova 5<sup>e</sup> classi", null,
		"100320", "Ricevimento pomeridiano genitori", null,
		"100322", "Ricevimento pomeridiano genitori", null,
		"100330", "Termine dei progetti, sportelli e corsi di recupero", null,
		"100403", "Consigli di classe", null,
		"100404", "Consigli di classe", null,
		"100405", "Consigli di classe", null,
		"100406", "Consigli di classe", null,
		"100407", "Consigli di classe", null,
		"100410", "Consigli di classe", null,
		"100414", "Consegna in segreteria proposte di nuova adozione - Classi 5<sup>e</sup>: consegna documento 15 maggio", null,
		"100415", "Consegna dichiarazione attivitą svolte", null,
		"100419", "Collegio dei Docenti", null,
		"100507", "Scrutini finali classi quinte", null,
		"100508", "Scrutini finali classi quinte", null,
		"100509", "Scrutini finali classi triennio", null,
		"100510", "Scrutini finali classi triennio", null,
		"100511", "Scrutini finali classi triennio", null,
		"100514", "Scrutini finali classi biennio", null,
		"100515", "Scrutini finali classi biennio", null,
		"100516", "Scrutini finali classi biennio", null,
		"100518", "Collegio Docenti", null
		);

// percorso per tornare all'indice
function setPath(path) {
  thisPath = path;
}

function formatnumber(x) {
var frm = "00" + x;
return frm.substring(frm.length - 2);
}

function isVacanza(anno, mese, giorno) {
var key = formatnumber(anno % 100) + formatnumber(mese) + formatnumber(giorno);
for (var i = 0; i < vacanza.length; i++) {
  var dx = vacanza[i];
  var init, end;
  var idx = dx.indexOf("-");
  if (idx == 0)
    init = "000000";
  else
    init = dx.substring(0, 6);
  if (idx < 0)
    end = init;
  else
    end = dx.substring(idx + 1);

  if (key < init)
    return false;
  if (key >= init && key <= end)
    return true;
}
  return false;
}


function cercanota0(giorno, mese, anno) {
  var nota = "" + giorno;
  var key = formatnumber(anno % 100) + formatnumber(mese) + formatnumber(giorno);
  for (var i = 0; i < note.length; i += 3) {
    if (key == note[i]) {
      if (note[i + 2] != null) {
      	 var mx = thisPath;
      	 if (note[i + 2].substr(0, 4) == "http")
      	 	mx = "";
      	 nota = '<a href="' + mx + note[i + 2] + '" class="numlinked" target="blank">' + nota + '</a>';
      }
      break;
    }
  }
  return nota;
}

function writeCalDiv(id, txt) {
	var x;
	if (document.getElementById) {
		x = document.getElementById(id);
	}
	else if (document.all) {
		x = document.all[id];
	}
	if (txt != null)
		x.innerHTML = txt;
	return x;
}

function creaCalwin() {
	document.write('<div id="calcont" style="position: absolute; border: 1px solid; width: 340px; height: 250px; display:none;" onClick="nascondi(this)">');
	document.write('<div id="calhead" align="center" style="background:blue; padding: 4px; font-family: Georgia, \'Times New Roman\', Times, serif; font-size: 14px; font-weight: bold; font-variant: small-caps; letter-spacing: 2px; color:#FFFFCC">&nbsp;</div>');
	document.write('<div id="calwin" align="center" style="overflow:auto; background:cornsilk; padding: 4px; font: bold 15px Arial, Helvetica, sans-serif; color:#FFFFCC; height:80%;">&nbsp;</div>');
	document.write('<div id="calfoot" align="center" style="background:khaki; font-size: 12px"><i><strong>Cliccare sulla finestra per chiudere</strong></i></div></div>');
}

function win_Cal(nnote) {
	var mx = note[nnote];
	if (note[nnote + 1] != null)
		mx = '<a href="' + thisPath + note[nnote + 1] + '" class="numero" style="color: blue;" target="blank">' + mx + '</a>';
	var tx = "Calendario";

	var wx = 340;
	var wy = 200;

	var dx = '<table width="100%" border="0" style="height:100%;font: bold 15px Arial, Helvetica, sans-serif;"><tr><td height="100%" align="center" bgcolor="cornsilk">' + mx + '</td></tr></table>';
	var z = writeCalDiv("calhead", tx);

	var x = writeCalDiv("calwin", dx);
	var y = writeCalDiv("calcont", null);

	y.style.left = (document.body.clientWidth - wx) / 2 + document.body.scrollLeft;
	y.style.top = (document.body.clientHeight - 250) / 2 + document.body.scrollTop;

	y.style.display = "block";
	y.style.height = wy;
}


function cercanotaX(giorno, mese, anno, tolink) {
	var key = formatnumber(anno % 100) + formatnumber(mese) + formatnumber(giorno);

	for (var i = 0; i < note.length; i += 3) {
		if (key == note[i]) {
			nota = '<a href="javascript:win_Cal(' + (i + 1) + ')">' + tolink + '</a>';
			return nota;
		}
	}
	return "<span>" + giorno + "</span>";
}


function cercanota(giorno, mese, anno) {
  var nota = "&nbsp;";
  var key = formatnumber(anno % 100) + formatnumber(mese) + formatnumber(giorno);
  for (var i = 0; i < note.length; i += 3) {
    if (key == note[i]) {
      nota = note[i + 1];
      if (note[i + 2] != null) {
      	 var mx = thisPath;
      	 if (note[i + 2].substr(0, 4) == "http")
      	 	mx = "";
      	 nota = '<a href="' + note[i + 2] + '" class="cal" target="blank">' + note[i + 1] + '</a>';
      }
      break;
    }
  }
  return nota;
}

function comparedate(d1, d2) {
   if (d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth() && d1.getDate() == d2.getDate()) 
      return true;
   return false;
}

function pasqua(aa) {
   var xx = new Array(22, 22, 23, 23, 24, 24);
   var yy = new Array(2, 2, 3, 4, 5, 5);
   var a = aa % 19;
   var b = aa % 4;
   var c = aa % 7;

   var i = Math.floor(aa / 100) - 15;
   var x = xx[i], y = yy[i];
   var d = (19*a + x) % 30;
   var e = (2*b + 4*c + 6 * d + y) % 7;

   var p = 22 + d + e;

   var m = 300;
   if (p > 31) {
      m = 400;
      p = p - 31;
   }
   return m + p;
}


function isfesta(d) {
   var feste = new Array(0, 101, 106, 425, 501, 602, 815, 1101, 1208, 1225, 1226);

   if (d.getDay() == 0)
      return true;

   var pp = pasqua(d.getFullYear()) + 1;     // Pasquetta
      if (pp % 100 > 31)
         pp = 401;

   feste[0] = pp;
   for (var i = 0; i < feste.length; i++)
      if (Math.floor(feste[i] / 100) == d.getMonth() + 1) {
         var gg = feste[i] % 100;
         if (gg == d.getDate())
            return true;
      }

   return false;
}

function calendarMini(mese, anno, path) {
	xwidth = 189;
	cellwidth = 27;
	setPath(path);
	return calendar(mese, anno);
}


function calendarX(mese, anno, path) {
	setPath(path);
return calendar(mese, anno);
}

function calendar(mese, anno) {
   var dx = 2 - (new Date(anno, mese, 1)).getDay();
   if (dx == 2)
      dx = -5;

   var daysInMonth = dd[mese];

   if (mese == 1) {
      if (anno % 4 == 0 && anno % 100 != 0  || anno % 400 == 0)
         daysInMonth++;
   }

	var tx = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr align="center">';
	tx += '<td width="50%" valign="bottom" class="mesex"><span style="border: 1px solid black; border-bottom:none; display:block; padding:2px">' + mesi[mese] + '</span></td>';
	tx += '<td width="50%" class="annox" style="border-bottom: 1px solid black;">' + anno + '</td></tr></table>';
	tx += '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF" style="border: 1px solid black; border-top:none">';
    tx += '<tr align="center" class="calhead">';
	for (var i = 0; i < 7; i++)
		tx += '<td width="14%" bgcolor="#E0E0E0">' + days[i] + '</td>';
	tx += '</tr>';
	for (var j = 0; j < 6; j++) {
		if (dx > daysInMonth)
			break;

      for (var i = 0; i < 7; i++) {
         var bgstring = "";
         var fgcol = lines;
         var fgstring = '&nbsp;';

         if (dx > 0 && dx <= daysInMonth) {
			var ddx = new Date(anno, mese, dx);
          	if (isfesta(ddx)) {
               bgstring = ' bgcolor="' + festa + '"';
            } else if (isVacanza(anno, mese, dx)) {
	       		bgstring = ' bgcolor="' + bgvacanza + '"';
	    	} else
				bgstring = ' bgcolor="' + calendback + '"';
			
			if (comparedate(ddx, today)) {
               testo = '<strong style="border:dotted 1px black; padding:0px 3px 0px 3px;display:block;background-color: #CCCC33;">' + dx + '</strong>';
            } else
             	testo = dx;
            var fgstring = cercanotaX(dx, mese, anno, testo);
        	tx += '<td class="numero"' + bgstring + '>';
	    	tx += fgstring;
	    	tx += '</td>\n';
         } else {
         	tx += '<td class="numero"><span>&nbsp;</span></td>';
         }
         dx++;
      }
      tx += '</tr>\n';
   }
   tx += '</table>';
   return tx;
}


function calendarvX(mese, anno, path) {
  setPath(path);
  return calendarv(mese, anno);
}

function calendarv(mese, anno) {
   var daysInMonth = dd[mese];

   if (mese == 1) {
      if (anno % 4 == 0 && anno % 100 != 0  || anno % 400 == 0)
         daysInMonth++
   }

   var tx = '<table width="' + xwidth + '" border="0" cellspacing="0" cellpadding="0">';
   tx += '<tr><td nowrap valign="bottom" width="50%"><div id="calz" class="calw">' + mesi[mese] + '</div></td>';
   tx += '<td align="center" class="caltitolo" width="50%"><div id="cala"><b><font color="#FF0000">' + anno + '</font></b></div></td>';
   tx += '</tr><tr align="center"><td colspan="2" nowrap id="calb">';

   tx += '<table width="' + xwidth + '" border="0" cellspacing="1" cellpadding="0" style="border: solid 1px black"><tr><td valign="top">\n';
   tx += '<table width="100%" border="0" cellspacing="1" cellpadding="1">\n';
      
   for (var x = 1; x <= daysInMonth; x++) {
   	var xd = ((new Date(anno, mese, x)).getDay() + 6) % 7;
   	var ddx = new Date(anno, mese, x);
   	var bgstring = "";
   	var fgcol = lines;
        var fgstring = x;
	if (isfesta(ddx)) {
		bgstring = ' bgcolor="' + festa + '"';
    } else if (isVacanza(anno, mese, x)) {
	    bgstring = ' bgcolor="' + bgvacanza + '"';
	    fgcol = "#A0A0A0";
	}
	else {
		bgstring = ' bgcolor="' + calendback + '"';
	}
        if (comparedate(ddx, today)) {
		fgcol = bright;
		fgstring = '<b><u>' + x + '</u></b>\n';
        }
        fgstring = '<font color="' + fgcol + '" class = "num">' + fgstring + '</font>\n';

   	tx += '<tr' + bgstring + ' height="22"><td class="cal" width="1">' + days[xd] + '</td>';
   	tx += '<td class="num" align="right" width="1">' + fgstring + '</td>';
   	tx += '<td class="cal">' + cercanota(x, mese, anno) + '</td>';
   	tx += '</tr>';
   }
   tx += '</table>\n';
   tx += '</td><td bgcolor="' + bgright + '" width="1"><img src="images/bandav.gif"></td</tr></table>\n';
   tx += '</td></tr></table>';
   return tx;
}


function get_month() {
var param = window.location.search;
var d = new Date();
var mese = d.getMonth() + 1;

if (param.length > 0) {
	param = param.substring(1).split("=");
	if (param[0] == "mese")
		mese = param[1];
}
return Number(mese);
}


function random_page() {
var numberofpages = labs.length;
var n;
do {
  n = Math.floor(Math.random() * numberofpages - 0.01);
} while (location.href.indexOf(labs[n]) >= 0);

return labs[n] + ".htm";
}

function random_pages() {
var i, n;

var rnd = new Array();

for (i = 0, n = 0; i < labs.length; i++) {
if (location.href.indexOf(labs[i]) < 0)
	rnd[n++] = i;
}
n = rnd.length - 1;
for (i = 0; i < rnd.length; i++) {
	var m = Math.floor(Math.random() * (n + 1) - 0.01);
	var t = rnd[m];
	rnd[m] = rnd[n];
	rnd[n--] = t;
}
return rnd;
}


function do_mesibuttons() {
	this_month = get_month();
	this_year = 2009;
	if (this_month < 9)
		this_year = 2010;
	month1 = (this_month + 3) % 12;

	makeNewContainer(menuxh, month1);
}

function leftcalendar() {
	document.write('<div style="width:320">');
	document.write(calendarX(this_month - 1, this_year, "../"));
	document.write('</div>');
}

function rightcalendar() {
	document.write(calendarvX(this_month - 1, this_year, "../"));
}