// JavaScript Document
function ClearForm(form){
    form.weight.value = "";
    form.height.value = "";
    form.bmi.value = "";
    form.my_comment.value = "";
}

function bmi(weight, height) {
          bmindx=weight/eval(height*height);
          return bmindx;
}

function checkform(form) {
       if (form.weight.value==null||form.weight.value.length==0 || form.height.value==null||form.height.value.length==0){
            alert("\nFyll i både vikt och längd.");
            return false;
       }
       else if (parseFloat(form.height.value) <=119||
                parseFloat(form.height.value) >=250||
                parseFloat(form.weight.value) <=19||
                parseFloat(form.weight.value) >=500){
                alert("\nYou really know what you are doing? \nFill out the form again. \nWeight in kg and \nheight in cm");
                ClearForm(form);
                return false;
       }
       return true;
}

function computeform(form) {
       if (checkform(form)) {
       yourbmi=Math.round(bmi(form.weight.value, form.height.value/100));
       form.bmi.value=yourbmi;
       if (yourbmi >40) {
          form.my_comment.value="Are you related to Free Willy??";
       }
       else if (yourbmi >30 && yourbmi <=40) {
          form.my_comment.value="Bigger than a whale!";
       }
       else if (yourbmi >27 && yourbmi <=30) {
          form.my_comment.value="You are what you eat!";
       }
       else if (yourbmi >25 && yourbmi <=27) {
          form.my_comment.value="Hey, don´t touch the cookiejars!";
       }
       else if (yourbmi >24 && yourbmi <=25) {
          form.my_comment.value="So you like love handles?";
       }
       else if (yourbmi >23 && yourbmi <=24) {
          form.my_comment.value="Cut down on the donuts!";
       }
       else if (yourbmi >=21 && yourbmi <=23) {
          form.my_comment.value="Looking good, yeah";
       }
       else if (yourbmi >=20 && yourbmi <21) {
          form.my_comment.value="Eat more and enjoy life";
       }
       else if (yourbmi >=18 && yourbmi <20) {
          form.my_comment.value="Grow or die...";
       }
       else if (yourbmi >=16 && yourbmi <18) {
          form.my_comment.value="Okey, still alive?...";
       }
       else if (yourbmi <16) {
          form.my_comment.value="Hey, where did you go?";
       }
       }
       return;
}
