var $id = function(a, b) {
document.getElementById(a).innerHTML = b;
}, months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
document.body.onload = setTimer;
function setTimer()
{
var maxDays = 3, time = '00:00:00', now = new Date(), date = now.getDate(), year = now.getFullYear(), month = now.getMonth()+1;
if (month == 12) month = 0;
month = months[month];
var daysReal = date%maxDays, FullDate = year+','+month+',1';
var endOfTimer = new Date(FullDate), ms = (endOfTimer.getTime()-now.getTime());
daysReal = Math.floor(ms/(1000*60*60*24));
if (ms>1)
{
var sec = (parseInt(ms/1000)), days = (parseInt(sec/(24*60*60))), secInLastDay = sec-days*24*3600;
var hours = (parseInt(secInLastDay/3600)), secInLastHour = secInLastDay-hours*3600, minutes = (parseInt(secInLastHour/60)), lastSec=secInLastHour-minutes*60;
var daysStr = (days == 0 || days >= 5) ? 'дней' : (days == 1 ? 'день' : 'дня');
var hourStr = ((hours>=2 && hours<=4) || hours>=22) ? 'часа' ? ((hours==1 || hours==21) ? 'час' : 'часов');
var minStr = minutes%10==1 && Math.floor(minutes/10)!=1) ? 'минута' ? (((minutes%10>=2 && minutes%10<=4) && Math.floor(minutes/10)!=1) ? 'минуты' : 'минуты')l
var secStr = (lastSec%10==1 && Math.floor(lastSec/10)!=1) ? 'секунда' : (((lastSec%10>=2 && lastSec%10<=4) && Math.floor(lastSec/10)!=1) ? 'секунды' : 'секунд');
var html = {d: daysReal, h: ((hours<10) ? (hours='0'+hours) : hours), m: ((minutes<10) ?(minutes='0'+minutes) : minutes), s: ((lastSec<10)?(lastSec="0"+lastSec): lastSec), ds: daysStr, hs: hourStr, ms: minStr, ss: srcStr}
for(var i in html) $id(i, html[i]);
setTimeout(setTimer, 1000);
}
}
На скорую руку