function toSt2(n) {
  s = "";
  if (n < 10) s += "0";
  return (s + n).toString();
}
function countdown(end_time, premium, element)
{
	now = new Date();
	end = new Date(end_time);
	count = Math.floor(end.getTime() - now.getTime());
	if(count > 0)
	{
		count = Math.floor(count/1000);
		seconds = toSt2(count%60); count = Math.floor(count/60);
		minutes = toSt2(count%60); count = Math.floor(count/60);
		hours = toSt2(count%24); count = Math.floor(count/24);
		if (premium == 1)
		{
			document.getElementById('timer_'+element).innerHTML = 'Noch <B>' + hours + ':' + minutes + ':' + seconds + '</B> verliehen';
		}
		else
		{
			document.getElementById('timer_'+element).innerHTML = 'Noch max. <B>' + hours + ':' + minutes + ':' + seconds + '</B> verliehen';
		}
		setTimeout("countdown("+end_time+", '"+premium+"', '"+element+"')", 500);
	}
	else
	{
		if (premium == 1)
		{
			document.getElementById('timer_'+element).innerHTML = '<A HREF="rent.php?premium=1"><B>Jetzt leihen!</B></A><BR>Für nur 0,50€';
		}
		else
		{
			document.getElementById('timer_'+element).innerHTML = '<A HREF="rent.php"><B>Jetzt leihen!</B></A>';
		}
	}
}