function getCookieTool(NameOfCookie)
{ if (document.cookie.length > 0) 
{ begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) 
{ begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }  
}
return null; 
}

function getCookie(NameOfCookie)
{ 
if (document.cookie.length > 0) 
{ begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) 
{ begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
var quitcookie = document.cookie.substring(begin, end);
hof(quitcookie); } 
}
return null; 
}

function getCookie2(NameOfCookie)
{ 
if (document.cookie.length > 0) 
{ begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) 
{ begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
quitsave = document.cookie.substring(begin, end);
} 
}
return null; 
}

function hof(quitdate){
	today = new Date()          
	BirthDay = new Date(quitdate)         
	timeold = (today.getTime() - BirthDay.getTime());         
	sectimeold = timeold / 1000;         
	secondsold = Math.floor(sectimeold);         
	msPerDay = 24 * 60 * 60 * 1000 ;         
	timeold = (today.getTime() - BirthDay.getTime());         
	e_daysold = timeold / msPerDay;         
	daysold = Math.floor(e_daysold) + 1;         
	e_hrsold = (e_daysold - daysold)*24;         
	hrsold = Math.floor(e_hrsold);         
	minsold = Math.floor((e_hrsold - hrsold)*60);           
	quitter = daysold	         
}

function fmtCost(value) {
if (quitter != null || quitsave != null){
result="$"+Math.floor(value)+".";
var cents=100*(value-Math.floor(value))+0.5;
result += Math.floor(cents/10);
result += Math.floor(cents%10);
return result;
}
}

function setCookie(NameOfCookie, value, expiredays) 
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + 
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
 
function delCookie (NameOfCookie) 
{
// The function simply checks to see if the cookie is set.
// If so, the expiration date is set to Jan. 1st 1970.

if (getCookieTool(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
location.reload();
}
else{
alert("QuitTrack is already off.");
}
} 

function calcDate(){
	var quitday = document.tracker.quitday.value;
	var quitmo = document.tracker.quitmo.value;
	var quityr = document.tracker.quityr.value;
	var quitter = quitday + "/" + quitmo + "/" + quityr
if (quitday == "" || quitmo == "" || quityr == ""){
alert("You need to fill in all 3 fields.\n\nPlease use this format:\nmm/dd/yyyy.");
return;
}
else{
	setCookie("quitdate",quitter,10000); 
	location.reload();
	}
}

function calcMoney(){
	var quitamount = document.tracker.amount.value;
	var quitcost = document.tracker.cost.value;
	var quitsavings = quitamount * quitcost;
if (!getCookieTool("quitdate")){
	alert("Please set your QuitTrack date first.");
	return;
	}
if (quitamount == "" || quitcost == ""){
	alert("You need to fill in both fields.");
	return;
	}
else{
	setCookie("quitmoney",quitsavings,10000); 
	location.reload();
	}
}

function changeStyle(what){
	if(document.all){
	document.all[what].style.backgroundColor='#eee';
	document.all[what].style.borderColor='#000';
	}
}
function changeBack(what){	
	if(document.all){
	document.all[what].style.backgroundColor='#fff';
	document.all[what].style.borderColor='#999';
	}
}
var quitter = 0
var quitsave = 0
getCookie("quitdate");
getCookie2("quitmoney");