/*
  	Author:		Robert Hashemian (http://www.hashemian.com/)
  	Modified by:	Munsifali Rashid (http://www.munit.co.uk/)
  	Modified by:	Tilesh Khatri
  */
function StartCountDown(myDiv, myTargetDate, isShortened)
  {
    var dthen	= new Date(myTargetDate);
    var dnow	= new Date();
	if(dthen - dnow <= 0)
		return;
    ddiff		= new Date(dthen-dnow);
    gsecs		= Math.floor(ddiff.valueOf()/1000);
    CountBack(myDiv,gsecs,isShortened);
  }
  
  function Calcagelong(secs, num1, num2, type)
  {
	var value;
	value = ((Math.floor(secs/num1))%num2);
	
	if(type != 'day' || value > 0)
	{
		if(value == 0 || value > 1) { type += 's'; }
		s = value.toString() + ' ' + type + ' ';
	}
	else
	{ s = ''; }
	
    return (s);
  }
  function Calcage(secs, num1, num2, type)
  {
    return (((Math.floor(secs/num1))%num2).toString()+type+' ');
  }
  
  function CountBack(myDiv, secs, isShortened)
  {
    var DisplayStr;
    var DisplayFormat;
	
	if ( isShortened === undefined ) {
		DisplayFormat = "%%D%% %%H%% : %%M%% : %%S%% remaining";
		DisplayStr = DisplayFormat.replace(/%%D%%/g,	Calcagelong(secs,86400,100000,'day'));
		DisplayStr = DisplayStr.replace(/%%H%%/g,		Calcagelong(secs,3600,24,'hr'));
		DisplayStr = DisplayStr.replace(/%%M%%/g,		Calcagelong(secs,60,60,'min'));
		DisplayStr = DisplayStr.replace(/%%S%%/g,		Calcagelong(secs,1,60,'sec'));
	}
	else {
		DisplayFormat = "%%D%% %%H%% %%M%% %%S%%";
		DisplayStr = DisplayFormat.replace(/%%D%%/g,	Calcage(secs,86400,100000,'d'));
		DisplayStr = DisplayStr.replace(/%%H%%/g,		Calcage(secs,3600,24,'h'));
		DisplayStr = DisplayStr.replace(/%%M%%/g,		Calcage(secs,60,60,'m'));
		DisplayStr = DisplayStr.replace(/%%S%%/g,		Calcage(secs,1,60,'s'));
	}
    
    if(secs > 0)
    {	
      document.getElementById(myDiv).innerHTML = DisplayStr;
      setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ","+isShortened+");", 990);
    }
    else
    {
      document.getElementById(myDiv).innerHTML = "Deal has expired";
    }
  }