function calculate() {
   	
//input distance and tarrif

	distance = new Number(document.FrontPage_Form1.distance.value);

//validate user input

	if (isNaN(distance)) {
		alert ("Please enter the estimated distance of your trip in kilometers");
}


	tarrif = new Number(document.FrontPage_Form1.tarrifddb.value);
	
//check for valid tarrif

if (tarrif == 1) {
		var cost = 1.61 * distance + 3.20;
}
else if (tarrif == 2)  {
		var cost = 2.25 * distance + 3.20;
}
else {
		var cost = "error";
		alert ("Please Enter either 1 or 2 for Tarrif");
}

// Check that the result is a finite number. If so, display the results
    if (!isNaN(cost) && 
        (cost != Number.POSITIVE_INFINITY) &&
        (cost != Number.NEGATIVE_INFINITY)) {
  
    document.FrontPage_Form1.cost.value = "$" + round(cost);
    }
    else {
    document.FrontPage_Form1.cost.value = "error";
    }

}

//round the cost to 2 places
function round(x)  {
	return Math.round(x*100)/100;
}
