		/*

			JavaScript Blood Alcohol Calculator		

			RaiderSoft Custom Web Development

			Copyright (c) 2004, RaiderSoft. All Rights Reserved.

			http://www.raidersoft.com/

		*/

		function calculateBAC(f)

		{

			var weight = parseFloat(f.weight.value);

			var time = parseFloat(f.time.value);

			var type = parseFloat(f.type.value);

			var amount = parseFloat(f.amount.value);

			var burnoff = 0;

			var peak_bac = 0;

			var total_alcohol = 0;

			var rho = 0;

			var bac = 0;



			// Show error alert message if weight is not entered

			if(isNaN(weight))

			{

				f.result.value = "";

				alert("Please enter your weight.");

			}



			// Calculate RHO factor, total alcohol, peak BAC, 

			// and burnoff to determine current B.A.C.

			else

			{

				if(f.gender.value == 'm') rho = .13; else rho = .115;

				

				total_alcohol = amount * (type / 100.0);			

				peak_bac = total_alcohol / (rho * weight);								

				burnoff = 0.015 * time;			

				bac = peak_bac - burnoff;



				// Burnoff can give us negative numbers

				// Don't print negative BAC's.

				if(bac < 0) bac = 0.0;

				

				// Display Result

				//f.result.value = bac.toFixed(3);

				

				bac_str = bac.toString();

				bac_truncated = bac_str.substring(0,6);

				

				f.result.value = bac_truncated + "%";

				//f.result.value = bac;

			}

			return false;

		}