var timerID = null;
var timerRunning = false;

function stopclock()
{
	if(timerRunning)
	clearTimeout(timerID);
	timerRunning = false;
}

function startclock()
{
	stopclock();
	showtime();
}

function showtime()
{
        var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	var day = now.getDate();
	var month = now.getMonth();
	var year = now.getFullYear();
	
	var timeValue = ((day < 10) ? "0" : "") + day + " " + getMonthName(month) + " " + year + " | "
	timeValue += hours + ((minutes < 10) ? ":0" : ":") + minutes
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds
	
	if (document.getElementById('clockDay')) document.getElementById('clockDay').innerHTML = ((day < 10) ? "0" : "") + day;
	if (document.getElementById('clockMonth')) document.getElementById('clockMonth').innerHTML = getMonthName(month);
	if (document.getElementById('clockYear')) document.getElementById('clockYear').innerHTML = year;
	if (document.getElementById('clockHour')) document.getElementById('clockHour').innerHTML = hours;
	if (document.getElementById('clockMinutes')) document.getElementById('clockMinutes').innerHTML = ((minutes < 10) ? "0" : "") + minutes;
	if (document.getElementById('clockSeconds')) document.getElementById('clockSeconds').innerHTML = ((seconds < 10) ? "0" : "") + seconds;
	// you could replace the above with this
	// and have a clock on the status bar:
	// window.status = timeValue;
	timerID = setTimeout("showtime()", 500);
	// alert(timeValue);
	timerRunning = true;
}

function getMonthName(monthNum)
{
    switch (monthNum) {
        case 0 : return 'Января';
        case 1 : return 'Февраля';
        case 2 : return 'Марта';
        case 3 : return 'Апреля';
        case 4 : return 'Мая';
        case 5 : return 'Июня';
        case 6 : return 'Июля';
        case 7 : return 'Августа';
        case 8 : return 'Сентября';
        case 9 : return 'Октября';
        case 10 : return 'Ноября';
        case 11 : return 'Декабря';
    }
}
