

var countdownstart;
var epochtimemilliseconds = GetCookie();
var nowdate = new Date();
var nowtime = nowdate.getTime();
var redirect_url = "http://www.topsecretcarsecret.com/indxtmsup.php";
var daystoexp = "7";

if (epochtimemilliseconds > 0)
{
	milliseconds_elapsed = nowtime - epochtimemilliseconds;
	if (milliseconds_elapsed >= (86400000 * daystoexp)) //86400 seconds in 1 day, times 1000 milliseconds/second
	{
		location.replace(redirect_url);
	}
	else { countdownstart = Math.round(((86400000 * daystoexp) - milliseconds_elapsed)/1000); }
}
else
{
	countdownstart = 86400 * daystoexp;
	WriteCookie("etmindx", nowtime);
}

function WriteCookie(name,value) 
{
	var exp = '';
	var cookieExpiration = 365; // days
	var today = nowdate;
	var expdate = nowtime + (cookieExpiration * 24 * 60 * 60 * 1000);
	today.setTime(expdate);
	exp = '; expires=' + today.toGMTString();
	document.cookie = name + "=" + value + '; path=/;domain=topsecretcarsecret.com' + exp;
}

function GetCookie()
{
	var cookiecontent;
	if(document.cookie.length > 0) 
	{
		var cookiename = 'etmindx=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
		if(cookiebegin > -1) 
  		{
      			cookiebegin += 8;
      			cookieend = document.cookie.indexOf(";",cookiebegin);
      			if(cookieend < cookiebegin) 
      			{ 
      				cookieend = document.cookie.length; 
			}
			cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
		else { cookiecontent = 0; }
	}
	else { cookiecontent = 0; }
	return cookiecontent;
}


var _countDowncontainer=0;
var _currentSeconds=0;

function ActivateCountDown(strContainerID, initialValue) { _countDowncontainer = document.getElementById(strContainerID);

if (!_countDowncontainer) {
alert("count down error: container does not exist: "+strContainerID+"\nmake sure html element with this ID exists");
return;
}

SetCountdownText(initialValue); window.setTimeout("CountDownTick()", 1000); }

function CountDownTick() {
if (_currentSeconds <= 0) {
location.replace(redirect_url); //alert("your time has expired!");
return;
}

SetCountdownText(_currentSeconds-1);
window.setTimeout("CountDownTick()", 1000);
}

function SetCountdownText(seconds) {
//store:
if (seconds < 1) { location.replace(redirect_url); } _currentSeconds = seconds;

//get minutes:
var minutes=parseInt(seconds/60);

//shrink:
seconds = (seconds%60);

//get hours:
var hours=parseInt(minutes/60);

//shrink:
minutes = (minutes%60);

//get days
var days = parseInt(hours/24);
var hoursremainder = parseInt(((hours/24)%2)*24) + 1;

//build text:
var strText = AddZero(days) + " <span style='color:#c00000'>days</span> | " + AddZero(hoursremainder) + " <span style='color:#c00000'>hours</span> | " + AddZero(minutes) + " <span style='color:#c00000'>minutes</span> | " + AddZero(seconds) + " <span style='color:#c00000'>seconds remaining</span>";

//apply:
_countDowncontainer.innerHTML = strText;
}

function AddZero(num) {
return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}


function WindowLoad(event) { ActivateCountDown("CountDownPanel", countdownstart); } 

