var cd = 0;
var header;
function countdown(id,number,header,function_this,time) {
	
	hms = number;
	number = parseInt(number-1);
	var years = parseInt(Math.floor(hms/(86400*30*12)));
	hms = hms - years*86400*30*12;
	var months = parseInt(Math.floor(hms/(86400*30)));
	hms = hms - (months * 86400*30);
	var days = parseInt(Math.floor(hms / 86400));
	var hours = parseInt(Math.floor((hms-(days*86400))/3600));
	var mins = parseInt(Math.floor((hms-(days*86400)-(hours*3600))/60));
	var secs = parseInt(Math.floor(hms-(days*86400)-(hours*3600)-(mins*60)));
	var extra = ''; var extra_two = '';
	if(function_this == 'city_timer'){ extra = '<b>'; extra_two = '</b>';}
	if (hours != 0) {
		$("#" + id).html(extra+sprintf("%02d:%02d:%02d", hours, mins, secs)+extra_two);
		}
		else{
		$("#" + id).html(extra+sprintf("%02d:%02d", mins, secs)+extra_two);
		}
	if((mins == 0) && (secs == 0) && (hours == 0)) {
	if(header != '')
	{
  		window.location = header;
	}
	
	if(function_this == 'energy')
	{
		energy(time);
	}
	
 	} else {
 		cd = setTimeout("countdown('"+id+"','"+number+"','"+header+"','"+function_this+"','"+time+"')",1000);
 	}
}

function main_countdown(id,number) {
	
	hms = number;
	number = parseInt(number-1);
	var days = parseInt(Math.floor(hms / 86400));
	var hours = parseInt(Math.floor((hms-(days*86400))/3600));
	var mins = parseInt(Math.floor((hms-(days*86400)-(hours*3600))/60));
	var secs = parseInt(Math.floor(hms-(days*86400)-(hours*3600)-(mins*60)));
	
	if(days > 1){ $("#" + id).html(sprintf("%02d дни %02d:%02d:%02d", days, hours, mins, secs)); }
	if(days == 1){ $("#" + id).html(sprintf("%02d ден %02d:%02d:%02d", days, hours, mins, secs)); }
	if(days == 0){ $("#" + id).html(sprintf("%02d:%02d:%02d", hours, mins, secs)); }
	
	if((days == 0) && (mins == 0) && (secs == 0) && (hours == 0)) {
		
 	} else {
 		cd = setTimeout("main_countdown('"+id+"','"+number+"')",1000);
 	}
}
