Advertisement
mikelieman

eatregularly-bodycomp/bodycomp.js

Oct 8th, 2013
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var theObj;
  2. if(document.all){
  3.       if(typeof obj=="string"){
  4.             return document.all(obj);
  5.       }else{
  6.             return obj.style;
  7.         }
  8.  }
  9.         if(document.getElementById){
  10.                 if(typeof obj=="string"){
  11.                         return document.getElementById(obj);
  12.                 }else{
  13.                         return obj.style;
  14.                 }  
  15.         }
  16.         return null;
  17. } // function gObj
  18.  
  19. function isInteger(value) {
  20.         if ((undefined === value) || (null === value)) {
  21.                 return false;
  22.         }
  23.         return value % 1 == 0;
  24. } // function is_Integer
  25.  
  26. function showquickmsg(inStr, isError){
  27.         if (isError) inStr = "<font color=red>" + inStr + "</font>";
  28.                 gObj("coutput").innerHTML = inStr;
  29. } // function showquickmsg
  30.        
  31. function bodycompcalc() {
  32.  
  33.         showquickmsg("validating...",true);
  34.  
  35.         weight_lbs = gObj("cpound").value;
  36.         start_bf_pct = gObj("cbeforebfpct").value;
  37.         start_sm_pct = gObj("cbeforesmpct").value;
  38.         end_bf_pct = gObj("cendbfpct").value;
  39.         end_sm_pct = gObj("cendsmpct").value;
  40.  
  41.         if ( (!isInteger(weight_lbs)) || (weight_lbs < 1) || (weight_lbs > 999) ) {
  42.                 showquickmsg("weight must be an integer between 1 and 999",true);
  43.                 return;
  44.         } // weight_lbs fails validation.
  45.  
  46.         if ( (!isInteger(start_bf_pct)) || (start_bf_pct < 1) || (start_bf_pct > 100) ) {
  47.                 showquickmsg("Starting Body Fat Percentage must be an integer between 1 and 100",true);
  48.                 return;
  49.         } // start_bf_pct fails validation
  50.  
  51.         if ( (!isInteger(start_sm_pct)) || (start_sm_pct < 1) || (start_sm_pct > 100) ) {
  52.                 showquickmsg("Starting Skeletal Muscle Percentage must be an integer between 1 and 100",true);
  53.                 return;
  54.         } // start_sm_pct fails validation.
  55.  
  56.         if ( (!isInteger(end_bf_pct)) || (end_bf_pct < 1) || (end_bf_pct > 100) ) {
  57.                 showquickmsg("Ending Body Fat Percentage must be an integer between 1 and 100",true);
  58.                 return;
  59.         } // end_bf_pct fails validation.
  60.  
  61.         if ( (!isInteger(end_sm_pct)) || (end_sm_pct < 1) || (end_sm_pct > 100) ) {
  62.                 showquickmsg("Ending Skeletal Muscle Percentage must be an integer between 1 and 100",true);
  63.                 return;
  64.         } // end_sm_pct fails validation.
  65.  
  66.         showquickmsg("calculating...",true);
  67.  
  68.         weight_kg = weight_lbs * 0.453592;
  69.         RMR_start_bf = weight_kg * ( start_bf_pct / 100 )  *  4.5;
  70.         RMR_start_sm = weight_kg * ( start_sm_pct / 100 )  * 13.0;
  71.         RMR_end_bf   = weight_kg * ( end_bf_pct   / 100 )  *  4.5;
  72.         RMR_end_sm   = weight_kg * ( end_sm_pct   / 100 )  * 13.0;
  73.         deltaBodyfat        = end_bf_pct - start_bf_pct;
  74.         deltaSkeletalMuscle = end_sm_pct - start_sm_pct;
  75.         NetCaloricDiff = Math.round((RMR_end_bf + RMR_end_sm) - (RMR_start_bf + RMR_start_sm));
  76.  
  77.         var outMsg = "A change of " + deltaBodyfat.toString();
  78.                 outMsg += "% to body fat and " + deltaSkeletalMuscle.toString() ;
  79.                 outMsg += "% to skeletal muscle changes caloric requirements by ";
  80.                 outMsg += NetCaloricDiff.toString() + " calories/day.";
  81.  
  82.         showquickmsg( outMsg , false);
  83.  
  84. } // function bodycompcalc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement