
function countdown(obj)
{
	this.obj		= obj;
	this.Div		= "countdown";
	this.BackColor		= "white";
	this.ForeColor		= "black";
	this.TargetDate		= "12/31/2020 5:00 AM";
	this.DisplayFormat	= "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
	this.CountActive	= true;
	
	this.DisplayStr;

	this.Calcage		= cd_Calcage;
	this.CountBack		= cd_CountBack;
	this.Setup		= cd_Setup;
	this.openMessage		= cd_openMessage;
	this.endMessage = cd_endMessage;
	
	//for clock
	this.timeoutID;
	this.closed = false;
	
	//for getting current secs
	this.ReturnCurrent	= cd_ReturnCurrent;
	this.CurrentSecs;
	
}

function cd_Calcage(secs, num1, num2)
{
		
  s =((Math.floor(secs/num1))%num2).toString();
			


  if (s.length < 2) s = "0" + s;
  return (s);
}
function cd_CountBack(secs)
{

 if (this.closed) {

	document.getElementById(this.Div).innerHTML = "Auction Ended";	
    return;
  }

 if(secs <60) {
	this.DisplayFormat = "%%S%%s";
 }
 else if (secs < 3600) {
	 	this.DisplayFormat = "%%M%%:%%S%%";
 }
 else if (secs < 86400) {
 		this.DisplayFormat = "%%H%%:%%M%%:%%S%%";
 }
 else {
	 	this.DisplayFormat = "%%D%%:%%H%%:%%M%%:%%S%%";
 }	
	

  if(secs == 3) {
	this.DisplayFormat = "THREE";

 }  
 else if(secs == 2) {
	this.DisplayFormat = "TWO";

 }  
 else if(secs == 1) {
	this.DisplayFormat = "ONE";

 }  
 else if (secs < 0 && !this.closed) {
    document.getElementById(this.Div).innerHTML = "Hold Bidding";
	this.DisplayFormat = "Hold Bidding";
    return;
  } 
else if (secs == 0) {
    this.DisplayFormat = "ZERO";
 //   return;
 }


  this.DisplayStr = this.DisplayFormat.replace(/%%D%%/g,	this.Calcage(secs,86400,100000));
  this.DisplayStr = this.DisplayStr.replace(/%%H%%/g,		this.Calcage(secs,3600,24));
  this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		this.Calcage(secs,60,60));
  this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		this.Calcage(secs,1,60));
	if (secs < 21 && secs >= 0) {
			
			  this.DisplayStr ='<span style="color: red;">' +  this.DisplayStr + '</span>';
	}

		  document.getElementById(this.Div).innerHTML = this.DisplayStr;		



  if (this.CountActive) {
   	  this.CurrentSecs = secs;
	  this.timeoutID = setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990);
  }
}
function cd_Setup()
{
	if(this.timeoutID != null)
	{
		clearTimeout(this.timeoutID); 	
	}
	var gsecs		= this.TargetDate; <!--ddiff.valueOf()/1000); -->
	
	this.CountBack(gsecs);
}
function cd_endMessage()
{
//	this.TargetDate = 0;
//	this.Setup();
//	this.closed = true;
 this.closed = true;
	document.getElementById(this.Div).innerHTML = "Auction Ended";	
	document.getElementById("bid_button"+this.id).innerHTML = "Bidding Closed";
}
function cd_openMessage()
{
	if(this.timeoutID != null)
	{
		clearTimeout(this.timeoutID); 	
	}
	document.getElementById(this.Div).innerHTML = "Auction Is Open";	
}

function cd_ReturnCurrent()
{
		return (this.CurrentSecs);
}

