// JavaScript Document var version = '1.1'; function countdown(elementString, dateString, mode, name) { // date in format "December 25, 2005 00:00:00 GMT-500" ///////////////////////////////////////// // usage: // countdown(str element, str date [, int mode [, str name]]) // element is the element that will contain the countdown // date is the countdown (or countup) date in this standard form: // December 25, 2005 00:00:00 GMT-500 ///// // Modes: // 0 (default): Time until My Birthday - 06:33:00 11/25/05: 6 hours, 28 minutes, and 36 seconds. // 1: My Birthday - 06:33:00 11/25/05: 6 hours, 28 minutes, and 36 seconds. // 2: 6 hours, 28 minutes, and 36 seconds. // 3: 6 hours, 28 minutes, and 36 seconds if (mode == null) mode = 0; if (name == null) name = '0'; var clock = document.getElementById(elementString); var eventdate = new Date(dateString); // in format "January 1, 2005 00:00:00 GMT" now = new Date(); nowtime = now.getTime(); // now in milliseconds eventtime = eventdate.getTime(); // event in milliseconds var eventhour = eventdate.getHours(); var eventminute = eventdate.getMinutes(); var eventsecond = eventdate.getSeconds(); var eventmonth = eventdate.getMonth()+1; var eventday = eventdate.getDate(); var eventyear = eventdate.getFullYear(); timeleft = Math.round((eventtime-nowtime) / 1000); // timeleft in seconds var passed = 0; if (timeleft < 0) { // if event has passed timeleft = Math.abs(timeleft); passed = 1; } if (timeleft != 0) { // Let's get a whole bunch of values years = Math.floor(timeleft/31556926); months = Math.floor((timeleft%31556926)/2629744); days = Math.floor(((timeleft%31556926)%2629744)/86400); hours = Math.floor((((timeleft%31556926)%2629744)%86400)/3600); minutes = Math.floor(((((timeleft%31556926)%2629744)%86400)%3600)/60); seconds = Math.floor(((((timeleft%31556926)%2629744)%86400)%3600)%60); } // Now lets build a response to print var togo = ''; // set up our variable if (mode == 0) { togo += 'Time '; if (passed != 1) { togo += 'until '; } else { togo += 'since '; } } if ((mode != 2) && (mode != 3)) { togo += ''; if (name != '0') togo += name + ' - '; if ((eventhour + eventminute + eventsecond) != 0) { togo += eventhour + ':' + eventminute; if (eventsecond != 0) togo += ':' + eventsecond; togo += ' on '; } togo += eventmonth + '/' + eventday; if (eventyear != now.getFullYear()) togo += '/' + eventyear; togo += ': '; } if (timeleft != 0) { if (years > 0) { togo += years + ' ann'; if (years > 1) togo +='i'; if (years < 2) togo +='o'; if (months > 0) togo += ','; if ((minutes!=0)||(seconds!=0)||(hours!=0)||(days!=0)||(months!=0)) togo += ' '; } if (months > 0) { togo += months + ' mes'; if (months > 1) togo +='i' ; if (months < 2) togo +='e' ; if (days > 0) togo += ','; if ((minutes!=0)||(seconds!=0)||(hours!=0)||(days!=0)) togo += ' '; } if (days > 0) { togo += days + ' giorn'; if (days > 1) togo +='i'; if (days < 2) togo +='o'; if (hours > 0) togo += ','; if ((minutes!=0)||(seconds!=0)||(hours!=0)) togo += ' '; } if (hours > 0) { togo += hours + ' or'; if (hours > 1) togo +='e'; if (hours < 2) togo +='a'; if (minutes > 0) togo += ','; if ((minutes!=0)||(seconds!=0)) togo += ' '; } if (minutes > 0) { togo += minutes + ' minut'; if (minutes > 1) togo +='i'; if (minutes < 2) togo +='o'; if (seconds > 0) togo += ','; if (seconds != 0) togo += ' '; } if (seconds > 0) { togo += seconds + ' second'; if (seconds > 1) togo +='i' ; if (seconds < 2) togo +='o' ; } var expld = togo.split(', '); // EXAMPLE: // 0 => 5 years // 1 => 5 months // 2 => 5 days // 3 => 5 hours // 4 => 5 minutes // 5 => 5 seconds var exlast = expld.length-1; var todo = ''; var i; for (i=0 ; i