
function IsNumeric(strString)
//  check for valid numeric strings	
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}


function calculateBMI() {
  height = document.getElementById('bmi_height').value;
  weight = document.getElementById('bmi_weight').value;
  
  if (!IsNumeric(height) || !IsNumeric(weight))
  {
    alert("Zadejte platné hodnoty!")
    return false;
  }
  
  bmi = (weight / ((height/100)*(height/100)));
  bmi = Math.round(bmi * 100) / 100;
  
  alert("Váš BMI je " + bmi + ".");
  return false;
}
