//**********************************************************
// SCREEN javascript for fitness pages
// These functions change radio buttons on the screen
// to the proper units of measure when units is choosen.
// JOANNE: 
// These functions get the data from certain radio 
// buttons on the screens.  If you change the
// the names of these radio buttons in your html, this 
// code will need to be changed too.  Not too hard, if a
// radio button was call inchRB for example, look in 
// this file for "inchRB" and change it to your new name.
// INCLUDES: 
// Any screens with units or sex need this javascript.
// This file uses constants.js and conversions.js so they
// must come before this file in the include list.
//**********************************************************

/**
 * When units is choosen on the Body Fat Est Percent
 * Screen, change all the units of measure radio buttons
 * to the appropriate choice.
 */
function updateBodyFatPercentEstUnitsChanged ()
{ 
//#top updateBodyFatPercentEstUnitsChanged

   var theForm = getForm ();

   // if US
   if (theForm.unitsRB[US].checked)
   {
      if (!theForm.weightRB[POUNDS].checked)
      {
         theForm.weightRB[POUNDS].checked = true;  
         if (theForm.weightTF.value != "")
         {
            weight = theForm.weightTF.value;
            theForm.weightTF.value = kilosToPoundsRounded (weight, 1);
         }
      }  // end if weight, pounds selected

      if (!theForm.heightRB[INCHES].checked)
      {
         theForm.heightRB[INCHES].checked = true;  
         if (theForm.heightTF.value != "")
         {
            height = theForm.heightTF.value;
            theForm.heightTF.value = cmToInchesRounded (height, 1);
         }
      }  // end if height, inches selected

      if (!theForm.hipsRB[INCHES].checked)
      {
         theForm.hipsRB[INCHES].checked = true; 
         if (theForm.hipsTF.value != "")
         {
            hips = theForm.hipsTF.value;
            theForm.hipsTF.value = cmToInchesRounded (hips, 1);
         }
      }  // end if hips, inches selected

      if (!theForm.iliacRB[INCHES].checked)
      {
         theForm.iliacRB[INCHES].checked = true; 
         if (theForm.iliacTF.value != "")
         {
            iliac = theForm.iliacTF.value;
            theForm.iliacTF.value = cmToInchesRounded (iliac, 1);
         } 
      }  // end if iliac, inches selected
      
      if (!theForm.abdomenRB[INCHES].checked)
      {
         theForm.abdomenRB[INCHES].checked = true; 
         if (theForm.abdomenTF.value != "") 
         {
            abdomen = theForm.abdomenTF.value;
	    theForm.abdomenTF.value = cmToInchesRounded (abdomen, 1);
         }
      }  // end if abdomen, inches selected

   }  // end if US
   else
   {
      if (!theForm.weightRB[KILOS].checked)
      { 
         theForm.weightRB[KILOS].checked = true;  
         if (theForm.weightTF.value != "")
         {
            weight = poundsToKilos (theForm.weightTF.value);
            theForm.weightTF.value = roundFloat (weight, 1);
         }
      }

      if (!theForm.heightRB[CM].checked)
      {
         theForm.heightRB[CM].checked = true;
         if (theForm.heightTF.value != "")
         {
            theForm.heightTF.value = inchesToCmRounded (theForm.heightTF.value, 1);
         }
      }

      if (!theForm.hipsRB[CM].checked)
      {
         theForm.hipsRB[CM].checked = true;  
         if (theForm.hipsTF.value != "")
            theForm.hipsTF.value = inchesToCmRounded (theForm.hipsTF.value, 1);
      }

      if (!theForm.iliacRB[CM].checked)
      {
        theForm.iliacRB[CM].checked = true;
        if (theForm.iliacTF.value != "")
           theForm.iliacTF.value = inchesToCmRounded (theForm.iliacTF.value, 1);
      }

      if (!theForm.abdomenRB[CM].checked)
      {
        theForm.abdomenRB[CM].checked = true;
         if (theForm.abdomenTF.value != "")
           theForm.abdomenTF.value = inchesToCmRounded (theForm.abdomenTF.value, 1);
      }

   }  // end else METRIC

}  //#end updateBodyFatPercentEstUnitsChanged

/**
 * NOT USED ANYMORE
 * When units is choosen on the Body Fat Est Percent
 * Screen, change all the units of measure radio buttons
 * to the appropriate choice.
 *
 * @param aButton
 */
function cantUpdateBodyFatPercentEstUnits (aButton)
{ 
//#top cantUpdateBodyFatPercentEstUnits

   var theForm = getForm ();

   // if US
   if (aButton[US].checked)
   {
      // put it back to METRIC
      aButton[METRIC].checked = true;
   }  // end if US
   else
   {
      // put it back to US
      aButton[US].checked = true;
   }  // end else METRIC
   
   confirm ("All units of measure must be either US or METRIC.  \nIf you would like to change them, check the appropriate units button");
}  //#end cantUpdateBodyFatPercentEstUnits

/**
 * When units is choosen on the Body Fat Est Percent
 * Screen, change all the units of measure radio buttons
 * to the appropriate choice.
 */
function updateBodyFatDistUnitsChanged ()
{ 
//#top updateBodyFatDistUnitsChanged

   var theForm = getForm ();

   // if US
   if (theForm.unitsRB[US].checked)
   {
      if (!theForm.hipsRB[INCHES].checked)
      {
         theForm.hipsRB[INCHES].checked = true;  
         if (theForm.hipsTF.value != "")
            theForm.hipsTF.value = theForm.hipsTF.value / 2.54;
      }

      if (!theForm.waistRB[INCHES].checked)
      {
         theForm.waistRB[INCHES].checked = true;  
         if (theForm.waistTF.value != "")
            theForm.waistTF.value = theForm.waistTF.value / 2.54;
      }

   }  // end if US
   else
   {
      if (!theForm.hipsRB[CM].checked)
      {
         theForm.hipsRB[CM].checked = true;  
         if (theForm.hipsTF.value != "")
            theForm.hipsTF.value = theForm.hipsTF.value * 2.54;
      }

      if (!theForm.waistRB[CM].checked)
      {
         theForm.waistRB[CM].checked = true;  
         if (theForm.waistTF.value != "")
            theForm.waistTF.value = theForm.waistTF.value * 2.54;
      }

   }  // end else METRIC

}  //#end updateBodyFatDistUnitsChanged

/**
 * When units is choosen on the Body Mass Index
 * Screen, change all the units of measure radio buttons
 * to the appropriate choice.
 */
function updateBodyMassIndexUnitsChanged ()
{ 
//#top updateBodyMassIndexUnitsChanged

   var theForm = getForm ();

   // if US
   if (theForm.unitsRB[US].checked)
   {
      if (!theForm.weightRB[POUNDS].checked)
      {
         theForm.weightRB[POUNDS].checked = true;  
         if (theForm.weightTF.value != "")
            theForm.weightTF.value = theForm.weightTF.value * 2.2;
      }

      if (!theForm.heightRB[INCHES].checked)
      {
         theForm.heightRB[INCHES].checked = true;  
         if (theForm.heightTF.value != "")
            theForm.heightTF.value = theForm.heightTF.value / 2.54;
      }

   }  // end if US
   else
   {
      if (!theForm.weightRB[CM].checked)
      {
         theForm.weightRB[CM].checked = true;  
         if (theForm.weightTF.value != "")
            theForm.weightTF.value = theForm.weightTF.value / 2.2;
      }

      if (!theForm.heightRB[CM].checked)
      {
         theForm.heightRB[CM].checked = true;  
         if (theForm.heightTF.value != "")
            theForm.heightTF.value = theForm.heightTF.value * 2.54;
      }

   }  // end else METRIC

}  //#end updateBodyMassIndexUnitsChanged

/**
 * When units is choosen on the Maximal Oxygen Uptake
 * Screen, change all the units of measure radio buttons
 * to the appropriate choice.
 */
function updateMaxOxygenUptakeUnitsChanged ()
{ 
//#top updateMaxOxygenUptakeUnitsChanged

   var theForm = getForm ();

   // if US
   if (theForm.unitsRB[US].checked)
   {
      if (!theForm.weightRB[POUNDS].checked)
      {
         theForm.weightRB[POUNDS].checked = true;  
         if (theForm.weightTF.value != "")
            theForm.weightTF.value = theForm.weightTF.value * 2.2;
      }

   }  // end if US
   else
   {
      if (!theForm.weightRB[CM].checked)
      {
         theForm.weightRB[CM].checked = true;  
         if (theForm.weightTF.value != "")
            theForm.weightTF.value = theForm.weightTF.value / 2.2;
      }

   }  // end else METRIC

}  //#end updateMaxOxygenUptakeUnitsChanged

/** 
 * clear the values on the Body Mass Index screen
 */
function clearBodyMassIndexScreen ()
{
//#top clearBodyMassIndexScreen

   var theForm = getForm ();

   theForm.weightTF.value = "";
   theForm.heightTF.value = "";

   theForm.bmiTF.value = "";

} //#end clearBodyMassIndexScreen

/** 
 * clear the values on the Body Fat Distribution screen
 */
function clearBodyFatDistScreen ()
{
//#top clearBodyFatDistScreen

   var theForm = getForm ();

   theForm.hipsTF.value = "";
   theForm.waistTF.value = "";

   theForm.bfdTF.value = "";

} //#end clearBodyFatDistScreen

/** 
 * clear the values on the Body Fat Percent Est screen
 */
function clearBodyFatPercentEstScreen ()
{
//#top clearBodyFatPercentEstScreen

   var theForm = getForm ();

   theForm.hipsTF.value = "";
   theForm.abdomenTF.value = "";
   theForm.ageTF.value = "";
   theForm.iliacTF.value = "";
   theForm.heightTF.value = "";
   theForm.weightTF.value = "";

   theForm.bfpTF.value = "";
} //#end clearBodyFatPercentEstScreen

/** 
 * clear the values on the Maximal Oxygen
 * Uptake screen
 */
function clearMaxOxygenUptakeScreen ()
{
//#top clearMaxOxygenUptakeScreen

   var theForm = getForm ();

   theForm.weightTF.value = "";
   theForm.ageTF.value = "";
   theForm.walkTimeTF.value = "";
   theForm.exHeartRateTF.value = "";

   theForm.mouTF.value = "";

} //#end clearMaxOxygenUptakeScreen

/** 
 * clear the values on the Target Heart Rate
 * screen
 */
function clearTargetHeartRateScreen ()
{
//#top clearTargetHeartRateScreen

   var theForm = getForm ();

   theForm.ageTF.value = "";

   theForm.thrlTF.value = "";
   theForm.thrhTF.value = "";

} //#end clearTargetHeartRateScreen