﻿function countdown_clock()
{
	document.write('<div style="padding-right:0px;padding-top:4px;padding-left:10px;width: 412px;height:58px; background-image:url(http://supernatural-spn.net/1234335345321.jpg);background-position: right;background-repeat: no-repeat; background-color:black; color: white;text-align:left" id="countdown"></div>');
	//Countdown to next monday	
	//countdown(year, month, day, hour, minute);
	//cOUNTDOWN To any given date
	countdown(2010, 01, 21, 21, 00);
}
         
function countdown(year, month, day, hour, minute)
{
	Today = new Date();
	Todays_Year = Today.getFullYear();
	Todays_Month = Today.getMonth() + 1;                  

	//Convert both today's date and the target date into miliseconds.                           
	Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
	Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 

	Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  

	//Find their difference, and convert that into seconds.                  
	Time_Left = Math.round((Target_Date - Todays_Date) / 1000);

	if ( Time_Left < 0 )
		Time_Left = 0;

	//More datailed.
	days = Math.floor(Time_Left / (60 * 60 * 24));
	Time_Left %= (60 * 60 * 24);
	hours = Math.floor(Time_Left / (60 * 60));
	Time_Left %= (60 * 60);
	minutes = Math.floor(Time_Left / 60);
	Time_Left %= 60;
	seconds = Time_Left;

	obj = document.getElementById('countdown');
	obj.innerHTML = '<font style="font-family:Arial;font-size:10pt"><b>5.11 Сэм, прервись  ';
	obj.innerHTML += '<br><font style="font-family:Verdana;font-size:10pt"><b>' + days + '</b> ' + rus_counts(days, 'день', 'дня', 'дней') + ' </font>';
	obj.innerHTML += '<font style="font-family:Verdana;font-size:10pt"><b>' + hours + '</b> ' + rus_counts(hours, 'час', 'часа', 'часов') + ' </font>';
	obj.innerHTML += '<font style="font-family:Verdana;font-size:10pt"><b>' + minutes + '</b> ' + rus_counts(minutes, 'минута', 'минуты', 'минут') + ' и </font>';
	obj.innerHTML += '<font style="font-family:Verdana;font-size:10pt"><b>' + seconds + '</b> ' + rus_counts(seconds, 'секунда', 'секунды', 'секунд') + '</font>';  

	//Recursive call, keeps the clock ticking.
	setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ');', 1000);
}

function rus_counts( number, one, twotofour, fivetoten )
{
	numstr = '|' + number;
	len = numstr.length;

	if ( len > 3 )
		lasttwo = numstr.substring((numstr.length-2), numstr.length);
	else if( len == 3 )
		lasttwo = number;
	else
		lasttwo = 0;

	if ( lasttwo >= 11 && lasttwo <= 20 )
		return fivetoten;

	lastdigit = numstr.substring(numstr.length-1, numstr.length);

	if ( lastdigit == 0 )
		return fivetoten;
	else if( lastdigit == 1 )
		return one;
	else if ( lastdigit < 5 )
		return twotofour;
	else
		return fivetoten;
}