﻿/*
Countdown script

Copyright Ludovit Scholtz
ludovit@scholtz.sk
/**/
function setCountDown(from,to,id){
	setTimeout("countDown('"+id+"')",1000);
	if(from > to) return 'Aukcia skončila';
	pocet = to-from;
	ret = formatTime(pocet);
	document.getElementById(id+"_value").innerHTML = pocet;
	document.getElementById(id).innerHTML = ret;
}
function countDown(id){
	setTimeout("countDown('"+id+"')",1000);
	pocet = document.getElementById(id+"_value").innerHTML;
	pocet = pocet - 1;
	document.getElementById(id+"_value").innerHTML = pocet;
	document.getElementById(id).innerHTML = formatTime(pocet);
}
function formatTime(time){
	 if(time <= 0 ) return 'Aukcia skončila';
	sekund = time % 60;
	time =  (time-sekund)/60;
	minut = time % 60;
	time = (time-minut)/60;
	hodin = time % 24;
	dni = (time-hodin)/24;
	
	return getTimeLang('days',dni)+getTimeLang('hours',hodin)+getTimeLang('minutes',minut)+getTimeLang('seconds',sekund);
}
function getTimeLang(what,count){
	if(what == 'days'){
		if(count == 0) return '';
		if(count > 4) return count + ' dní ';
		if(count == 1) return count + ' deň ';
		return count + ' dni ';
	}
	if(what == 'hours'){
		if(count == 0) return '00:';
		if(count > 4) return pad(count,2) + ':';
		if(count == 1) return pad(count,2) + ':';
		return pad(count,2) + ':';
	}
	if(what == 'minutes'){
		if(count == 0) return '00:';
		if(count > 4) return pad(count,2) + ':';
		if(count == 1) return pad(count,2) + ':';
		return pad(count,2) + ':';
	}
	if(what == 'seconds'){
		if(count == 0) return '00';
		if(count > 4) return pad(count,2) + '';
		if(count == 1) return pad(count,2) + '';
		return pad(count,2) + '';
	}
}
function pad(number, length) {
   
    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }

    return str;

}

