 /*
  	Author:		Robert Hashemian (http://www.hashemian.com/)
  	Modified by:	Munsifali Rashid (http://www.munit.co.uk/)
  	Modified by:	Tilesh Khatri
	Modified by:	Jose Sousa
	Modified by:	Pedro Cipriano
  */
  
  function StartCountDown(myDiv,myCurrentDate)
  {
	var i=0;
	var localsecs = ((new Date()).getTime())/1000;
	var deltasecs = Number(myCurrentDate);
    if (deltasecs != NaN) {
		CountBack(myDiv,deltasecs,localsecs);
	} else {
		document.write("Error!");
	}
  }
  
  function Calcage(secs, num1, num2)
  {
    s = ((Math.floor(secs/num1))%num2).toString();
    if (s.length < 2) 
    {	
      s = "0" + s;
    }
    return (s);
  }
  
  function CountBack(myDiv, dsecs, lsecs)
  {
    var DisplayStr;
	var secs = dsecs+lsecs-((new Date()).getTime())/1000;
	var DisplayFormat = "%%D%% Dias %%H%%:%%M%%:%%S%%";
	if (secs < 86400)
	{	
		DisplayFormat = "%%H%%:%%M%%:%%S%%";
		if (secs < 3600)
		{
			DisplayFormat = "%%M%%:%%S%%";
			if (secs < 60)
			{
				DisplayFormat = "%%S%% segundos";
			}
		}
	}
	DisplayStr = DisplayFormat.replace(/%%D%%/g,Calcage(secs,86400,100000));
	DisplayStr = DisplayStr.replace(/%%H%%/g,Calcage(secs,3600,24));
	DisplayStr = DisplayStr.replace(/%%M%%/g,Calcage(secs,60,60));
	DisplayStr = DisplayStr.replace(/%%S%%/g,Calcage(secs,1,60));
	if (secs>0)	{
		document.getElementById(myDiv).innerHTML = DisplayStr;
		setTimeout("CountBack('" + myDiv + "'," + dsecs + "," + lsecs + ")",990)
    } else {
		window.location.href=window.location.href;	  
	}
  }
  