/*
	Author:		Robert Hashemian (http://www.hashemian.com/)
	Modified by:	Munsifali Rashid (http://www.munit.co.uk/)
*/

function test()
{
    alert("testing");
}

function countdown(obj)
{
	this.obj		        = obj;
	this.MinutesDiv		    = "minutes";
	this.SecondsDiv         = "seconds";
	this.BackColor		    = "white";
	this.ForeColor		    = "black";
	this.TargetDate		    = new Date("12/31/2020 5:00 AM");
	this.CountDownComplete  = "";    //Blank if no completion date. Enter date if 
	this.CountActive	    = true;
	
	this.DisplayStr;

	this.Calcage		= cd_Calcage;
	this.CountBack		= cd_CountBack;
	this.Setup		    = cd_Setup;
	this.ZeroReached    = cd_ZeroReached;
}

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)
{
  //this.MinutesDisplayStr = this.DisplayFormat.replace(/%%D%%/g,	this.Calcage(secs,86400,100000));
  //this.SecondsDisplayStr = this.DisplayStr.replace(/%%H%%/g,		this.Calcage(secs,3600,24));

  if (this.CountActive)
  {
    if (secs < 0)
    {
        this.ZeroReached();
    }
    else
    {
        document.getElementById(this.MinutesDiv).innerHTML = this.Calcage(secs,60,60);
        document.getElementById(this.SecondsDiv).innerHTML = this.Calcage(secs,1,60);
        setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990);
    }
  }
}
function cd_Setup()
{
	var dthen	= this.TargetDate;
  	var dnow	= new Date();
	var ddiff		= new Date(dthen-dnow);
	var gsecs		= Math.floor(ddiff.valueOf()/1000);
	this.CountBack(gsecs);
}
function cd_ZeroReached()
{
    // Event of count down reaching zero
    // To be modified as needed
    this.CountActive = false;
    window.location = "joinnow.html";
}