function countdown(obj)
{
	this.obj		= obj;
	this.Div		= "clock";
	this.TargetDate		= "12/31/2020 5:00 AM";
	this.DisplayFormat	= "%%TIME%% %%FORMAT%%";
	this.CountActive	= true;
	
	this.DisplayStr;

	this.Calcage		= cd_Calcage;
	this.CountBack		= cd_CountBack;
	this.Setup		= cd_Setup;
}

function cd_Calcage(secs, num1, num2)
{
  s = ((Math.floor(secs/num1))%num2).toString();
  // Add a leading zero.
  //if (s.length < 2) s = "0" + s;
  return (s);
}
function cd_CountBack(secs)
{

	if (this.Calcage(secs,86400,100000) >= 1)
	{
		if (this.Calcage(secs,86400,100000) == 1)
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"dag");
		else
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"dagar");
			
		this.DisplayStr = this.DisplayStr.replace(/%%TIME%%/g,		this.Calcage(secs,86400,100000));
	}
	else if (this.Calcage(secs,3600,24) >= 1)
	{
		if (this.Calcage(secs,3600,24) == 1)
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"timme");
		else
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"timmar");

		this.DisplayStr = this.DisplayStr.replace(/%%TIME%%/g,		this.Calcage(secs,3600,24));
	}
	else if (this.Calcage(secs,60,60) >= 1)
	{
		if (this.Calcage(secs,60,60) == 1)
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"minut");
		else
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"minuter");
			
		this.DisplayStr = this.DisplayStr.replace(/%%TIME%%/g,		this.Calcage(secs,60,60));
	}
	else if (this.Calcage(secs,1,60) >= 1)
	{
		if (this.Calcage(secs,1,60) == 1)
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"sekund");
		else
			this.DisplayStr = this.DisplayFormat.replace(/%%FORMAT%%/g,	"sekunder");
			
		this.DisplayStr = this.DisplayStr.replace(/%%TIME%%/g,		this.Calcage(secs,1,60));
	}
	else
	{
		this.DisplayStr = "nu!";
	}
  document.getElementById(this.Div).innerHTML = this.DisplayStr;
  if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990);
}


function cd_Setup()
{
	var dthen	= new Date(this.TargetDate);
  	var dnow	= new Date();
	ddiff		= new Date(dthen-dnow);
	gsecs		= Math.floor(ddiff.valueOf()/1000);
	this.CountBack(gsecs);
}

