<!-- Begin

function CostCalc(form) {
var monthcost = 0;
var yearcost = 0;
var decadecost = 0;
if (form.howmany.value==null||form.howmany.value.length==0){		// check to see that the quantity field has been filled in
alert("Please enter how many cigarettes you smoke in a day.");
return false;
}
else
if (form.packcost.value==null||form.packcost.value.length==0){		// check to see that the cost field has been filled in
alert("Please enter how much you pay for a pack of 20 cigarettes.");
return false;
}
else
//	validate the values entered in both boxes
var checknum = new Array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
var checkproper = new Array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".");
var valmess = new Array ("please enter appropriate values for both quantity and cost", "please enter a proper cost", "please enter a correct value for the quantity smoked.  Do not include any decimal place") 
var howmany = form.howmany.value;
var good = 0;							// counter to see how many of the entered characters are valid
var out = 0;							// flag to determine the output message, if any, after data validation 
var a = howmany.length;
var packcost =  form.packcost.value;
var b = packcost.length;
for (var i=0; i<a; i++) {
	var chr = howmany.charAt(i);
	for (var j=0; j<10; j++) {
		var cur = checknum[j];
		if (chr==cur) good = good + 1;
				}
	if (good == a) out = out + 1;		// adds flag if quantity has been entered correctly
	}
var good = 0
for (var i=0; i<b; i++) {
var chr = packcost.charAt(i);
	for (var j=0; j<11; j++) {
		var cur = checkproper[j];
		if (chr==cur) good = good + 1;
				}
	if (good == b) out = out + 2;		// adds flag if cost has been entered correctly
	}
if (out != 3) {
	alert(valmess[out]);		// outputs an error message if either of the values are invalid 	
	return;						// intended to cease the function rather than do the calculation and get NaN output
	}
howmany = form.howmany.value;
packcost = form.packcost.value;
var v1 = packcost * 1;					// converts text from a form into a number
var v2 = v1.toFixed(2);
form.packcost.value = v2; 
v1 = howmany * packcost * 30.5 / 20;
var v2 = v1.toFixed(2);
form.monthcost.value = v2;
v1 = howmany * packcost * 365 / 20;
var v2 = v1.toFixed(2);
form.yearcost.value = v2;
v1 = v2 * 10;
var v2 = v1.toFixed(2);
form.decadecost.value = v2;
}

// End -->
