var theObj;
if(document.all){
if(typeof obj=="string"){
return document.all(obj);
}else{
return obj.style;
}
}
if(document.getElementById){
if(typeof obj=="string"){
return document.getElementById(obj);
}else{
return obj.style;
}
}
return null;
} // function gObj
function isInteger(value) {
if ((undefined === value) || (null === value)) {
return false;
}
return value % 1 == 0;
} // function is_Integer
function showquickmsg(inStr, isError){
if (isError) inStr = "<font color=red>" + inStr + "</font>";
gObj("coutput").innerHTML = inStr;
} // function showquickmsg
function bodycompcalc() {
showquickmsg("validating...",true);
weight_lbs = gObj("cpound").value;
start_bf_pct = gObj("cbeforebfpct").value;
start_sm_pct = gObj("cbeforesmpct").value;
end_bf_pct = gObj("cendbfpct").value;
end_sm_pct = gObj("cendsmpct").value;
if ( (!isInteger(weight_lbs)) || (weight_lbs < 1) || (weight_lbs > 999) ) {
showquickmsg("weight must be an integer between 1 and 999",true);
return;
} // weight_lbs fails validation.
if ( (!isInteger(start_bf_pct)) || (start_bf_pct < 1) || (start_bf_pct > 100) ) {
showquickmsg("Starting Body Fat Percentage must be an integer between 1 and 100",true);
return;
} // start_bf_pct fails validation
if ( (!isInteger(start_sm_pct)) || (start_sm_pct < 1) || (start_sm_pct > 100) ) {
showquickmsg("Starting Skeletal Muscle Percentage must be an integer between 1 and 100",true);
return;
} // start_sm_pct fails validation.
if ( (!isInteger(end_bf_pct)) || (end_bf_pct < 1) || (end_bf_pct > 100) ) {
showquickmsg("Ending Body Fat Percentage must be an integer between 1 and 100",true);
return;
} // end_bf_pct fails validation.
if ( (!isInteger(end_sm_pct)) || (end_sm_pct < 1) || (end_sm_pct > 100) ) {
showquickmsg("Ending Skeletal Muscle Percentage must be an integer between 1 and 100",true);
return;
} // end_sm_pct fails validation.
showquickmsg("calculating...",true);
weight_kg = weight_lbs * 0.453592;
RMR_start_bf = weight_kg * ( start_bf_pct / 100 ) * 4.5;
RMR_start_sm = weight_kg * ( start_sm_pct / 100 ) * 13.0;
RMR_end_bf = weight_kg * ( end_bf_pct / 100 ) * 4.5;
RMR_end_sm = weight_kg * ( end_sm_pct / 100 ) * 13.0;
deltaBodyfat = end_bf_pct - start_bf_pct;
deltaSkeletalMuscle = end_sm_pct - start_sm_pct;
NetCaloricDiff = Math.round((RMR_end_bf + RMR_end_sm) - (RMR_start_bf + RMR_start_sm));
var outMsg = "A change of " + deltaBodyfat.toString();
outMsg += "% to body fat and " + deltaSkeletalMuscle.toString() ;
outMsg += "% to skeletal muscle changes caloric requirements by ";
outMsg += NetCaloricDiff.toString() + " calories/day.";
showquickmsg( outMsg , false);
} // function bodycompcalc
Comments