<!-- Original:  James P. Dildine (jpd@wlsmail.com) -->
<!-- Web Site:  http://www.mste.uiuc.edu/dildine -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

//////////////////////////////////////////////////////////////////////
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

/////////////////////////////////////////////////////////////////////////
function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function


function solveBAC(form) {
var ounces = eval(form.ounces.value);
var percent = eval(form.percent.value);
var weight = eval(form.weight.value);
var hours = eval(form.hours.value);
var dbgMsg = "Initial dbgMsg value";

dbgMsg = getSelectedRadioValue(form.gender);

////////////////////////////////////////////////////////////////////////////
var locGender = getSelectedRadioValue(form.gender);

if (locGender == "Male")
{
  var result = (ounces * percent * 0.075 / weight) - (hours * 0.015);
  dbgMsg = "locGender = " + locGender;
}

else if (locGender == "Female")
{
  var result = (ounces * percent * 0.075 / weight * 75/66) - (hours * 0.015);
  dbgMsg = "locGender = " + locGender;
}

else
 {dbgMsg = "Error in gender eval - locGender = " + locGender;}

////////////////////////////////////////////////////////////////////////////
if (result < 0.02)
{message = "There is a negligible amount of alcohol in your system. ";
 message = message + "You are not legally intoxicated, but be careful and keep the rubber-side down!";
 result = "-- neglible amount --";
}

else if (result == "NaN")
{message = "Please try again.";}

else if (result >= 0.35)
{message = "Dude, you're probably dead, even if you don't get on your bike!";}

else if (result >= 0.16 && result < 0.35)
{message = "You're probably tossing your cookies and can't even find";
message = message + "your bike. If you do - DON'T GET ON!";}

else if (result >= 0.10 && result < 0.16)
{message = "NOT COOL - All states consider this BAC seriously intoxicated. ";
 message = message + "Please do not ride your bike under ANY circumstance, ";
 message = message + "and wipe the drool off of your face!";}

else if (result >= 0.08 && result < 0.10)
{message = "You would be considered intoxicated at .08% and arrested for DUI in 45 states. ";
 message = message + "You should not ride your bike at all once you've reached this point. ";
 message = message + "About 2,500 motorcyclists that are killed and about 50,000 ";
 message = message + "that are seriously injured in crashes per year, involved drinking and riding";}

else if(result < 0.08 && result >= 0.02)
{message = "You are legally intoxicated at .08%. You should not ride your bike. ";
 message = message + "40% - 45% of all fatal motorcycle crashes involve the use of alcohol";}

else
{message = "You should not end up here!";}

form.message.value = message;
form.bacamount.value = result + " %";
form.dbgMsg.value = dbgMsg;
}

