////////////////////////////////////////////////////////////////////
// Ideal Weight calculation script.
// Copyright 2002-2005 ShurikSoft.com, All rights reserved.
// http://www.shuriksoft.com
////////////////////////////////////////////////////////////////////
// To use this script linkback to  http://ideal.shuriksoft.com  
// is necessary 

    sex="male"; s1="male"; s0="female"; 
    function validate(){
               if (inputform.height.value==""){
                 alert("Warning! Please Input your height"); return 1;
               }
               if (inputform.howold.value==""){
                 alert("Warning! Please Input your age"); return 1;
               }
               if (inputform.massa.value==""){
                 alert("Warning! Please Input your weight"); return 1;
               }
               if ((parseInt(inputform.height.value)>=250)||(parseInt(inputform.height.value)<=90)){
                 alert("Warning! wrong height value."); return 1;
               }     
               if (parseInt(inputform.howold.value)<=5){
                 alert("Warning! wrong age value."); return 1;
               }     
               if (parseInt(inputform.howold.value)>=70){
                 alert("Warning! wrong age value"); return 1;
               } 
               if (parseInt(inputform.massa.value)<=10){
                 alert("Warning! wrong weight value."); return 1;
               }       
               if (parseInt(inputform.massa.value)>=150){
                 alert("Warning! wrong weight value."); return 1;
               }     
               return 0;
    }
    function calculate(){
     var ideal,fat,compact,v;
     if(validate()==0)
       { if(sex==s1) {ideal=(parseInt(inputform.height.value)*3-450+parseInt(inputform.howold.value))*0.25+45;
                       fat =((parseInt(inputform.massa.value)-ideal)/parseInt(inputform.massa.value))*100+15; }
         if(sex==s0) {ideal=(parseInt(inputform.height.value)*3-450+parseInt(inputform.howold.value))*0.225+40.4;
                       fat =((parseInt(inputform.massa.value)-ideal)/parseInt(inputform.massa.value))*100+22; }
        compact=8.9*fat+11*(100-fat);
        v=parseInt(inputform.massa.value)/compact;
        inputform.res.value=ideal;
        inputform.res_fat.value=Math.ceil(fat);
        inputform.res_p.value=Math.ceil(compact);
        inputform.res_v.value=v;
       }
     }
//End 
