// Routine CountDown ( giorni ore minuti secondi mancanti a: ) 
//                                  Campi esterni richiesti sono: dateFuture e outest { non tra () }

// Author: ricocheting.com
// For: public release (freeware)
// Date: 4/24/2003 (update: 5/15/2009)
// Description: displays the amount of time until the "dateFuture" entered below.

// NOTE: the month entered must be one less than current month. 
//            ie; 0=January, 11=December
// NOTE: the hour is in 24 hour format. 0=12am, 15=3pm etc
// format: dateFuture = new Date(year,month-1,day,hour,min,sec)
// example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm

// dateFuture = new Date(2010,3,03,24,0,00);

// TESTING: comment out the line below to print out
//          the "dateFuture" for testing purposes
// document.write(dateFuture +"<br />");

// LAYOUT FORMAT
// If you want to change the size, font, or color; you can edit the last line
// of your generated code and add a style="" property like:
// <div id="countbox" style="font:14pt Arial; color:#FF0000;">&nbsp;</div>
// Oppure per formattare il testo, nel CSS inserire un "#countbox"
// con le caratteristiche che si vogliono ottenere.

// nothing beyond this point
function GetCount()
{
// controllo se esiste conteggio da fare

if (outest!="")
  {
   
// grab current date
   dateNow = new Date();
// calc milliseconds between dates
   amount = dateFuture.getTime() - dateNow.getTime();
   delete dateNow;

// time is already past
   if(amount < 0)
     {
      outend="";
      outend = outest + "Conteggio terminato!!!";
      document.getElementById('countbox').innerHTML=outend;
     }
// date is still good
   else
       {
        days=0;hours=0;mins=0;secs=0;out="";
	out = out + outest
// kill the "milliseconds" so just secs
// (Math.floor arrotonda sempre all'intero inferiore)
	amount = Math.floor(amount/1000);
// days
	days=Math.floor(amount/86400);
// resto della divisione intera cioe' il resto della divisione amount/days
	amount=amount%86400;
// hours
	hours=Math.floor(amount/3600);
		amount=amount%3600;
// minutes
	mins=Math.floor(amount/60);
	amount=amount%60;
// seconds
	secs=Math.floor(amount);

	if(days != 0){out += days +" giorn"+((days!=1)?"i":"o")+", ";}
	if(days != 0 || hours != 0){out += hours +" or"+((hours!=1)?"e":"a")+", ";}
	if(days != 0 || hours != 0 || mins != 0){out += mins +" minut"
                                                                            +((mins!=1)?"i":"o")+", ";}

	out += secs +" second"+((secs!=1)?"i":"o");

// stampa su video campo out formattato secondo un #countbox
	document.getElementById('countbox').innerHTML=out;

	setTimeout("GetCount()", 1000);
	}
  }
}

// call when everything has loaded (Non funziona con testo scorrevole attivo)
// window.onload=GetCount;
