
function getData ()
{


   var theForm = getForm();



   if (theForm.unitsRB[0].checked)
   {
      units = US;
   }
   else
   {
      units = METRIC;
   }

   if (theForm.sexRB[0].checked)
   {
      sex = MALE;
   }
   else
   {
      sex = FEMALE;
   }

   if (units == US)
   {
      abdomen = theForm.abdomenTF.value;
      hips = theForm.hipTF.value;
      waist = theForm.waistTF.value;
      iliac = theForm.iliacTF.value;
      height = theForm.heightTF.value;
      weight = theForm.weightTF.value;   
      age = theForm.ageTF.value;  
   } 
   else
   {
      abdomen = theForm.abdomenTF.value;
      hips = theForm.hipTF.value;
      waist = theForm.waistTF.value;
      iliac = theForm.iliacTF.value;
      height = theForm.heightTF.value;
      weight = theForm.weightTF.value;   
      age = theForm.ageTF.value;  
   }  // end METRIC

   exHeartRate = theForm.heartRateTF.value;  
   walkTime = theForm.walkTimeTF.value;  

} 


function displayGlobals ()
{


   var un = "\nunits = " + units;
   var sx = "\nsex = " + sex;
   var ab = "\nabdomen = " + abdomen;
   var hp = "\nhips = " + hips;
   var wst = "\nwaist = " + waist;
   var il = "\niliac = " + iliac;
   var ht = "\nheight = " + height;
   var wt = "\nweight = " + weight;
   var ag = "\nage = " + age;
   var hr = "\nheart rate = " + exHeartRate;
   var wtm = "\nwalk time = " + walkTime;

   confirm ("globals\n\n" + un + sx + ag + wt + ht + hp + wst + il + ab + wtm + hr);

}  //#end displayGlobals

/**
 * testing function to display the results of calculations
 */
function displayResults ()
{
//#top displayResults

   var bfd = doBodyFatDistributionCalc ();
   var bmi = doBodyMassIndexCalc ();
   var bfp = doBodyFatPercentEstCalc ();
   var mou = doMaxOxygenUptakeCalc ();

   document.dataEntryForm.bfdTF.value = bfd;
   document.dataEntryForm.bfpTF.value = bfp;
   document.dataEntryForm.bmiTF.value = bmi;
   document.dataEntryForm.mouTF.value = mou;

}  //#end displayResults

/**
 * display the form name for testing
 */
function displayFormName ()
{
//#top displayFormName

   confirm ("this form name is " + getFormName());

}  //#end displayFormName


//***********************************************
// These funcition get the each piece of data 
// from a given screen and store it in the global
// data.  Units of measure is important, it's 
// default value is US, so if you don't call this
// function before calling all the other "gets"
// everything will be in US units.
//***********************************************

/**
 * get the name of the form calling a function
 */
function getFormName ()
{
//#top getFormName

   return getForm().name;

}  //#end getFormName

/**
 * get the form calling a function
 */
function getForm ()
{
//#top getForm

   return document.forms[0];

}  //#end getForm

/**
 * Get the units of measure entered by the user
 * and store it in the global variable "units".
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getUnits (aForm)
{
//#top getUnits

   if (aForm.unitsRB[0].checked)
   {
      units = US;
   }
   else
   {
      units = METRIC;
   }
  
}  //#end getUnits

/**
 * Get the sex entered by the user and store
 * it in the global variable "sex".
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getSex (aForm)
{
//#top getSex

   if (aForm.sexRB[0].checked)
   {
      sex = MALE;
   }
   else
   {
      sex = FEMALE;
   }

}  //#end getSex

/**
 * Get the abdomen measurement entered by the user,
 * validate the value and if its appropriate,
 * store it in the global variable "abdomen",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getAbdomen (aForm)
{
//#top getAbdomen

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   // if it's not a number, send user an error message
   if (isNaN (theForm.abdomenTF.value))
   {
      alert (MESSAGE27);
      validData = false;
      theForm.abdomenTF.focus();
   }
   else
   {
      if (theForm.abdomenRB[US].checked)
      {
         temp = inchesToCm (theForm.abdomenTF.value);
      }  // end US
      else
      {
         temp = theForm.abdomenTF.value;
      }  // end METRIC

      // verify that the abdomen is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE7);
         validData = false;
         theForm.abdomenTF.focus();
      }  // end no abdomen entered 
      else if ( (temp < MIN_ABDOMEN) || (temp > MAX_ABDOMEN) )
      {
         validData = confirm (MESSAGE16 + MESSAGE21);
      }
   
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to abdomen 
      abdomen = temp;
   }  // end else

   return validData;

}  //#end getAbdomen

/**
 * Get the hip measurement entered by the user,
 * validate the value and if its appropriate,
 * store it in the global variable "hips",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getHips (aForm)
{
//#top getHips

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   // if it's not a number, send user an error message
   if (isNaN (theForm.hipsTF.value))
   {
      alert (MESSAGE22);
      validData = false;
      theForm.hipsTF.focus();
   }
   else
   {
      if (theForm.hipsRB[US].checked)
      {
         temp = inchesToCm (theForm.hipsTF.value);
      }  // end US
      else
      {
         temp = theForm.hipsTF.value;
      }  // end METRIC

      // verify that the hips is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE2);
         validData = false;
         theForm.hipsTF.focus();
      }  // end no hips entered 
      else if ( (temp < MIN_HIPS) || (temp > MAX_HIPS) )
      {
         validData = confirm (MESSAGE11 + MESSAGE21);
      }
   
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to hips 
      hips = temp;
   }  // end else

   return validData;

}  //#end getHips

/**
 * Get the waist measurement entered by the user,
 * validate the value and if its appropriate,
 * store it in the global variable "waist",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getWaist (aForm)
{
//#top getWaist

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   // if it's not a number, send user an error message
   if (isNaN (theForm.waistTF.value))
   {
      alert (MESSAGE23);
      validData = false;
      theForm.waistTF.focus();
   }
   else
   {
      if (theForm.waistRB[US].checked)
      {
         temp = inchesToCm (theForm.waistTF.value);
      }
      else
      { 
         temp = theForm.waistTF.value;
      }  // end METRIC
 
      // verify that the waist is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE3);
         validData = false;
         theForm.waistTF.focus();
      }  // end no waist entered 
      else if ( (temp < MIN_WAIST) || (temp > MAX_WAIST) )
      {
         validData = confirm (MESSAGE12 + MESSAGE21);
      }
   
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to waist
      waist = temp;
   }  // end else

   return validData;

}  //#end getWaist

/**
 * Get the iliac measurement entered by the user,
 * validate the value and if its appropriate,
 * store it in the global variable "iliac",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getIliac (aForm)
{
//#top getIliac

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   // if it's not a number, send user an error message
   if (isNaN (theForm.iliacTF.value))
   {
      alert (MESSAGE24);
      validData = false;
      theForm.iliacTF.focus();
   }
   else
   {
      if (theForm.iliacRB[US].checked)
      {
         temp = inchesToCm (theForm.iliacTF.value);
      }  // end US
      else
      {  
         temp = theForm.iliacTF.value;
      }

      // verify that the iliac is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE4);
         validData = false;
         theForm.iliacTF.focus();
      }  // end no iliac entered 
      else if ( (temp < MIN_ILIAC) || (temp > MAX_ILIAC) )
      {
         validData = confirm (MESSAGE13 + MESSAGE21);
      }
   
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to iliac
      iliac = temp;
   } // end else

   return validData;

}  //#end getIliac

/**
 * Get the height measurement entered by the user,
 * validate the value and if its appropriate,
 * store it in the global variable "height",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getHeight (aForm)
{
//#top getHeight

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   // if it's not a number, send user an error message
   if (isNaN (theForm.heightTF.value))
   {
      alert (MESSAGE25);
      validData = false;
      theForm.heightTF.focus();
   }
   else
   {
      if (theForm.heightRB[US].checked)
      {
         temp = inchesToCm (theForm.heightTF.value);
      }  // end US
      else
      { 
         temp = theForm.heightTF.value;
      }  // end METRIC

      // verify that the height is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE5);
         validData = false;
         theForm.heightTF.focus();
      }  // end no height entered 
      else if ( (temp < MIN_HEIGHT) || (temp > MAX_HEIGHT) )
      {
         validData = confirm (MESSAGE14 + MESSAGE21);
      }
   
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to height
      height = temp;
   }  // end else

   return validData;

}  //#end getHeight

/**
 * Get the weight measurement entered by the user,
 * validate the value and if its appropriate,
 * store it in the global variable "weight",
 * store a 0 if it's invalid
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getWeight (aForm)
{
//#top getWeight

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   // if it's not a number, send user an error message
   if (isNaN (theForm.weightTF.value))
   {
      alert (MESSAGE26);
      validData = false;
      theForm.weightTF.focus();
   }
   else
   {
      // get the weight from the screen and store it in KILOS
      if (theForm.weightRB[US].checked)
      {
         temp = poundsToKilos (theForm.weightTF.value);  
      }
      else
      {
         temp = theForm.weightTF.value; 
      }  // end METRIC

      // verify that the weight is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE6);
         validData = false;
         theForm.weightTF.focus();
      }  // end no weight entered 
      else if ( (temp < MIN_WEIGHT) || (temp > MAX_WEIGHT) )
      {
         validData = confirm (MESSAGE15 + MESSAGE21);
      }
   
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to weight
      weight = temp;
   }  // end else

   return validData;

}  //#end getWeight

/**
 * Get the age entered by the user, validate
 * the value and if its appropriate, store
 * it in the global variable "age",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getAge (aForm)
{
//#top getAge

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   temp = theForm.ageTF.value;  

   // if it's not a number, send user an error message
   if (isNaN (temp))
   {
      alert (MESSAGE28);
      validData = false;
      theForm.ageTF.focus();
   }
   else
   {
      // verify that the age is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE8);
         validData = false;
         theForm.ageTF.focus();
      }  // end no age entered 
      else if ( (temp < MIN_AGE) || (temp > MAX_AGE) )
      {
         validData = confirm (MESSAGE17 + MESSAGE21);
      }
   
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to age
      age = temp;
   }  // end else
   
   return validData;

}  //#end getAge

/**
 * Get the exercise heart rate entered by the user,
 * validate the value and if its appropriate,
 * store it in the global variable "exHeartRate",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getExHeartRate (aForm)
{
//#top getExHeartRate

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   temp = theForm.heartRateTF.value; 

   // if it's not a number, send user an error message
   if (isNaN (temp))
   {
      alert (MESSAGE29);
      validData = false;
      theForm.heartRateTF.focus();
   }
   else
   {
      // verify that the age is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE9);
         validData = false;
         theForm.heartRateTF.focus();
      }  // end no heart rate entered 
      else if ( (temp < MIN_HEART_RATE) || (temp > MAX_HEART_RATE) )
      {
         validData = confirm (MESSAGE18 + MESSAGE21);
      }
    
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to heart rate
      exHeartRate = temp;
   }  // end else

   return validData;

}  //#end getExHeartRate

/**
 * Get the one mile walk time rate entered by the 
 * user, validate the value and if its appropriate,
 * store it in the global variable "walkTime",
 * otherwise store a 0
 *
 * @param aForm the name of the form that units
 * is being retrieved from
 */
function getWalkTime (aForm)
{
//#top getWalkTime

   var temp = 0;
   var theForm = getForm ();
   var validData = true;

   temp = theForm.walkTimeTF.value;  

   // if it's not a number, send user an error message
   if (isNaN (temp))
   {
      alert (MESSAGE30);
      validData = false;
      theForm.walkTimeTF.focus();
   }
   else
   {
      // verify that the age is within a valid range
      if (temp <= ABSOLUTE_MIN_VALUE)
      {
         alert (MESSAGE10);
         validData = false;
         theForm.walkTimeTF.focus();
      }  // end no walk time entered 
      else if ( (temp < MIN_WALK_TIME) || (temp > MAX_WALK_TIME) )
      {
         validData = confirm (MESSAGE19 + MESSAGE21);
      }
     
      // if there were no errors or the user verified the data 
      // was accurate, assign temp to walk time
      walkTime = temp;
   }  // end else

   return validData;

}  //#end getWalkTime

//***********************************************
// These funcition get the necessary data from
// a given screen.
//***********************************************

/**
 * Get the necessary data from the Max Oxygen
 * Uptake screen.  It puts the data in the global
 * variables.
 *
 * @param aForm the name of the form that
 * this data is entered on.
 */
function getMaxOxygenUptakeData (aForm)
{
//#top getMaxOxygenUptakeData

   var aForm = getForm ();
   var validData = true;

   getUnits (aForm);
   getSex (aForm);

   validData = getAge (aForm);
   if (validData)
   {
      validData = getWeight (aForm);  
      if (validData)
      {
         validData = getWalkTime (aForm);
         if (validData)
         {
            validData = getExHeartRate (aForm);
         }
      }
   }  // end if

   return validData;

}  //#end getMaxOxygenUptakeData

/**
 * Get the necessary data from the Body Mass
 * Index screen.  It puts the data in the global
 * variables.
 *
 * @param aForm the name of the form that
 * this data is entered on.
 */
function getBodyMassIndexData (aForm)
{
//#top getBodyMassIndexData

   var aForm = getForm ();
   var validData = true;

   getUnits (aForm);

   validData = getWeight (aForm);
   if (validData)
   {
      validData = getHeight (aForm);   
   }

   return validData;

}  //#end getBodyMassIndexData

/**
 * Get the necessary data from the Max Oxygen
 * Uptake screen.  It puts the data in the global
 * variables.
 *
 * @param aForm the name of the form that
 * this data is entered on.
 */
function getBodyFatDistributionData (aForm)
{
//#top getBodyFatDistributionData

   var aForm = getForm ();
   var validData = true;

   validData = getWaist (aForm);
   if (validData)
   {
      validData = getHips (aForm);
   }

   return validData;

}  //#end getBodyFatDistributionData

/**
 * Get the necessary data from the Max Oxygen
 * Uptake screen.  It puts the data in the global
 * variables.
 *
 * @param aForm the name of the form that
 * this data is entered on.
 */
function getBodyFatPercentEstData (aForm)
{
//#top getBodyFatPercentEstData

   var aForm = getForm ();
   var validData = true;

   getUnits (aForm);
   getSex (aForm);
   validData = getAbdomen (aForm);
   if (validData) 
   {
      validData = getHips (aForm);
   }

   if (sex == FEMALE)
   {
      if (validData)
      {
         validData = getHeight (aForm);
         if (validData)
         { 
            validData = getAge (aForm);
         }
      }
   }
   else
   {
      if (validData)
      {
         validData = getIliac (aForm);
         if (validData)
         { 
            validData = getWeight (aForm);
         }
      }
   }

   return validData;

}  //#end getBodyFatPercentEstData

/**
 * Get the necessary data from the Target Heart
 * Rate screen.  It puts the data in the global
 * variables.
 */
function getTargetHeartRateData ()
{
//#top getTargetHeartRateData

   var aForm = getForm ();
   var validData = true;

   validData = getAge ();

   return validData;

}  //#end getTargetHeartRateData

//***********************************************
// These funcition get the necessary data from
// a given screen, do the desired calculation,
// and display the results in the appropriate
// text field on the html screen.
//***********************************************

/**
 * Get the Maximal Oxygen Uptake and display it
 * on the Maximal Oxygen Uptake screen.
 *
 * @param aForm the name of the form that
 * this data is entered on and that the results
 * will be displayed on.
 */
function displayMaxOxygenUptake (aForm)
{
//#top displayMaxOxygenUptake

   var calc = 0;
   var validData = true;

   // get the max oxygen uptake data
   validData = getMaxOxygenUptakeData (aForm);

   // if the max oxygen uptake data is valid
   // do the calculation and dispaly the result
   if (validData)
   {
      calc = doMaxOxygenUptakeCalc ();
      aForm.mouTF.value = calc;
   }

}  //#end displayMaxOxygenUptake

/**
 * Get the Body Mass Index and display it
 * on the Body Mass Index screen.
 *
 * @param aForm the name of the form that
 * this data is entered on and that the results
 * will be displayed on.
 */
function displayBodyMassIndex (aForm)
{
//#top displayBodyMassIndex

   var calc = 0;
   var validData = true;

   // get the body mass data
   validData = getBodyMassIndexData (aForm);

   // if the data is valid, do the calculation
   // and display the result
   if (validData)
   {
      calc = doBodyMassIndexCalc ();
      aForm.bmiTF.value = calc;
   }

}  //#end displayBodyMassIndex

/**
 * Get the Body Mass Index and display it
 * on the Body Mass Index screen.
 *
 * @param aForm the name of the form that
 * this data is entered on and that the results
 * will be displayed on.
 */
function displayBodyFatDistribution (aForm)
{
//#top displayBodyFatDistribution

   var calc = 0;
   var validData;

   // get the body fat dist data
   validData = getBodyFatDistributionData (aForm);

   // if the data is valid, do the calculation and
   // display the result
   if (validData)
   {
      calc = doBodyFatDistributionCalc ();
      aForm.bfdTF.value = calc;
   }

}  //#end displayBodyFatDistribution

/**
 * Get the Body Mass Percentage Est and display it
 * on the Body Mass Percentage Est screen.
 *
 * @param aForm the name of the form that
 * this data is entered on and that the results
 * will be displayed on.
 */
function displayBodyFatPercentEst (aForm)
{
//#top displayBodyFatPercentEst

   var calc = 0;

   // get the body fat percent data
   validData = getBodyFatPercentEstData (aForm);

   // if the data is valid, do the calculation
   // and display the results
   if (validData)
   {
      calc = doBodyFatPercentEstCalc ();
      aForm.bfpTF.value = calc;
   }

}  //#end displayBodyFatPercentEst

/**
 * Get the Body Mass Percentage Est and display it
 * on the Body Mass Percentage Est screen.
 *
 * @param aForm the name of the form that
 * this data is entered on and that the results
 * will be displayed on.
 */
function displayTargetHeartRate ()
{
//#top displayTargetHeartRate

   var calc = 0;
   var theForm = getForm ();

   // get the target heart rate data
   validData = getTargetHeartRateData ();

   // if the data is valid, do the calculation
   // and display the results
   if (validData)
   {
      calc = doTargetHeartRateLowCalc ();
      theForm.thrlTF.value = calc;
      calc = doTargetHeartRateHighCalc ();
      theForm.thrhTF.value = calc;
   }

}  //#end displayTargetHeartRate
