// General Calculator

function checkNumber(form)
{
	if(form.age.value=='')
	{
          form.age.value="000000";
          alert (form.notes.value="Please enter your age.")
          form.age.focus();
          form.age.select();
	}
	status=''
    var str = form.age.value;
    for (var i = 0; i < str.length; i++)        
	{
		var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') 
		{
			form.age.value=form.age.value;
			alert (form.notes.value="Please enter only number values");
			form.age.focus();
			form.age.select();
		} 
    }   
	calculateDeath(form)
}

function calculateDeath(form)
{
	var thisAge=form.age.value;
	var additional=365*14;
    form.notes.value="Average life expectancy of a smoker is 63.";
	if (thisAge>63)
	{
		form.untilDeath.value=0;
		overage=(thisAge-63)*365;
		if (thisAge<77)
			moreDays=additional-overage;
		else
			moreDays=0;
		form.added.value=moreDays;
		form.notes.value="You are on borrowed time.  You are now "+overage+" days past your life expectancy.";
		alert("You are on borrowed time.  You are now "+overage+" days past your life expectancy.");
	}
	else if (thisAge<63)
	{
		daysLeft=( (63-thisAge) + 0) *365;
		form.untilDeath.value=daysLeft;
		form.added.value=additional +0;
	}
	else
	{
		form.untilDeath.value=0;
		form.added.value=additional +0;
		form.notes.value="You are on borrowed time.";
		alert("You are now on borrowed time.");
	}
}

function reset(form)
{
	form.age.value="";
	form.untilDeath.value="";
}