﻿function $id(id){return document.getElementById(id)}
function $name(id){return document.getElementsByName(id)}
function showWork(obj)
{   
    var a;   
     for (var i = 0; i < obj.options.length; i++) {        
        if (obj.options[i].selected == true) {        
            a = obj.options[i].value;        
            break;        
        }        
    }             
    if(a>=13)
    {     
      with(document.getElementById ("work").style)
      {
        display='block';        
      }     
      if(document.getElementById ("sex2").checked==true)
      {         
          with(document.getElementById ("Pregnant").style)
          {
            display='';        
          }  
      }
     
    }
    else
    {   
         with(document.getElementById("work").style)
      {
        display='none';
      } 
      document.getElementById ("chkPregnant").checked=false;
       with(document.getElementById ("Pregnant").style)
      {
        display='none';        
      }  
       with(document.getElementById("prgant").style)
      {
        display='none';
      }         
    }
}
function showPrgant(obj)
{
    if(obj.checked==true)
    {
         with(document.getElementById("prgant").style)
      {
        display='block';
      } 
    }else{
           with(document.getElementById("prgant").style)
      {
        display='none';
      } 
    }
}
function selectPrgant(obj)
{
    var selectSex =$id("sex2")
    
    if(selectSex.checked==true)
    { 
          if(returnAge()>=13)
          {
               with(document.getElementById ("Pregnant").style)
              {
                display='';        
              }  
          }
    }
}
function selectPrgantSir(obj)
{
     var selectSex =$id("sex1");
     if(selectSex.checked==true)
     {
         document.getElementById ("chkPregnant").checked=false;
       with(document.getElementById ("Pregnant").style)
      {
        display='none';        
      }  
     }
}

function Account()
{
  if( CheckValue()==true)
  {
    var weight=$id("txtWeight").value;
    var inta =$id("txtStand").value;
    var stand=inta/100;
    var a=(weight*0.01)/(stand*stand);
    a=a*100;
    var Bmi=$id("txtBMI");
    Bmi.value=a.toFixed(2);
    if(returnSex()==1)
    {
        if(Number(a.toFixed(2)) <= 18)
        {
         $id("txtMessage").value="偏瘦!";         
        }
        else if(Number(a.toFixed(2)) >= 18 && Number(a.toFixed(2)) < 25)
        {
            $id("txtMessage").value="正常体重!";            
        }
        else if(Number(a.toFixed(2)) >= 25 && Number(a.toFixed(2)) < 30)
        {
            $id("txtMessage").value="超重!";            
        }        
        else if(Number(a.toFixed(2)) >= 30 && Number(a.toFixed(2)) < 35)
        {
            $id("txtMessage").value="轻度肥胖!";            
        }
        else if(Number(a.toFixed(2)) >= 35 &&Number(a.toFixed(2)) < 40)
        {
            $id("txtMessage").value="中度肥胖!";            
        }
        else if(Number(a.toFixed(2)) >= 40)
        {
            $id("txtMessage").value="重度肥胖!";            
        }
         var a=returnAge();
         var b=returnWork();
        mans(a,b);
    }
    else if(returnSex()==2)
    {
        if(Number(a.toFixed(2)) <= 18)
        {
         $id("txtMessage").value="偏瘦!";         
        }
        else if(Number(a.toFixed(2)) >= 18 && Number(a.toFixed(2)) < 25)
        {
            $id("txtMessage").value="正常体重!";            
        }
        else if(Number(a.toFixed(2)) >= 25 && Number(a.toFixed(2)) < 30)
        {
            $id("txtMessage").value="超重!";            
        }        
        else if(Number(a.toFixed(2)) >= 30 && Number(a.toFixed(2)) < 35)
        {
            $id("txtMessage").value="轻度肥胖!";            
        }
        else if(Number(a.toFixed(2)) >= 35 &&Number(a.toFixed(2)) < 40)
        {
            $id("txtMessage").value="中度肥胖!";            
        }
        else if(Number(a.toFixed(2)) >= 40)
        {
            $id("txtMessage").value="重度肥胖!";            
        }
        if($id("chkPregnant").checked==false)
        {
            var a=returnAge();//年龄
            var b=returnWork();//劳动强度
            womans(a,b);
        }
        else
        {
             $id("txtMessage").value="";
            var b = returnPregnant();
            pregnantss(b);
        }
        
    }
  }
}
function pregnatss()
{
            var b = returnPregnant();
            pregnantss(b);
}
function pregnantss(b)
{
   
    if(b==1)
    {
        SetTxts("2300","70","0","800","1.5","1.7","15","100","14","800","700","2500","2200","400","15","11.5","50","0","0");
    }
    else if(b==2)
    {
        SetTxts("2300","80","0","900","1.5","1.7","15","130","14","1000","700","2500","2200","400","25","16.5","50","0","0");
    }
    else if(b==3)
    {
        SetTxts("2300","85","0","900","1.5","1.7","15","130","14","1200","700","2500","2200","400","35","16.5","50","0","0");
    }
    
}
function mans(a,b)
{
   
    if(a==1)
    {
        SetTxts("1100","35","0","500","0.6","0.6","6","60","4","600","450","1000","650","100","12","9","20","0.8","0");   
    }
    else if(a==2)
    {
        SetTxts("1200","40","30~35","500","0.6","0.6","6","60","4","600","450","1000","650","100","12","9","20","0.8","0");
    }
    else if(a==3)
    {
        SetTxts("1350","45","30~35","500","0.6","0.6","6","60","4","600","450","1000","650","100","12","9","20","0.8","0");
    }
     else if(a==4)
    {
        SetTxts("1450","50","30~35","600","0.7","0.7","7","70","5","800","500","1500","900","150","12","12","25","1","0");
    }
    else if(a==5)
    {
        SetTxts("1600","55","30~35","600","0.7","0.7","7","70","5","800","500","1500","900","150","12","12","25","1","0");
    }
     else if(a==6)
    {
         SetTxts("1700","55","30~35","600","0.7","0.7","7","70","5","800","500","1500","900","150","12","12","25","1","0");
    }
    else if(a==7)
    {
        SetTxts("1800","60","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==8)
    {
        SetTxts("1900","65","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==9)
    {
        SetTxts("2000","65","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==10)
    {
        SetTxts("2100","70","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==11)
    {
        SetTxts("2400","75","25~30","700","1.2","1.2","12","90","10","1000","1000","1500","1200","350","16","18","45","1.8","0");
    }
     else if(a==12)
    {
        SetTxts("2900","85","25~30","800","1.5","1.5","15","100","14","1000","1000","2000","1800","350","20","19","50","2","0");
    }
    else if(a==13&&b==1)
    {
        SetTxts("2400","75","20~30","800","1.4","1.4","14","100","14","800","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==14&&b==1)
    {
       SetTxts("2300","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==15&&b==1)
    {
        SetTxts("1900","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==16&&b==1)
    {
       SetTxts("1900","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==17&&b==1)
    {
       SetTxts("1900","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
       else if(a==13&&b==2)
    {
        SetTxts("2700","80","20~30","800","1.4","1.4","14","100","14","800","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==14&&b==2)
    {
       SetTxts("2600","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==15&&b==2)
    {
        SetTxts("2200","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==16&&b==2)
    {
       SetTxts("2100","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==17&&b==2)
    {
       SetTxts("2100","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==13&&b==3)
    {
        SetTxts("3200","90","20~30","800","1.4","1.4","14","100","14","800","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==14&&b==3)
    {
       SetTxts("3100","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==15&&b==3)
    {
        SetTxts("2200","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==16&&b==3)
    {
       SetTxts("2100","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
      else if(a==17&&b==3)
    {
       SetTxts("2100","75","20~30","800","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","15","50","2","3.5");
    }
}
function SetTxts(sub1,sub2,sub3,sub4,sub5,sub6,sub7,sub8,sub9,sub10,sub11,sub12,sub13,sub14,sub15,sub16,sub17,sub18,sub19)
{
         $id("kcal").value = sub1;
         $id("lblDanBaiZhi").value = sub2;
         $id("lblZhiFang").value = sub3;
         $id("lblWeiShenSua").value = sub4;
         $id("lblLiuAnSu").value = sub5;
         $id("lblHeHuangSu").value = sub6;
         $id("lblNiKeSuan").value= sub7;
         $id("lblWeiShenSuc").value = sub8;
         $id("lblWeiShenSue").value = sub9;
         $id("lblGai").value= sub10;
         $id("lblLing").value = sub11;
         $id("lblJia").value = sub12;
         $id("lblNa").value = sub13;
         $id("lblMei").value = sub14;
         $id("lblTie").value = sub15;
         $id("lblXin").value= sub16;
         $id("lblXi").value= sub17;
         $id("lblTong").value= sub18;
         $id("lblMeng").value = sub19;
}
function womans(a,b)
{
    
    if(a==1)
    {
        SetTxts("1050","35","0","500","0.6","0.6","6","60","4","600","450","1000","650","100","12","9","20","0.8","0");   
    }
    else if(a==2)
    {
        SetTxts("1150","40","30~35","500","0.6","0.6","6","60","4","600","450","1000","650","100","12","9","20","0.8","0");
    }
    else if(a==3)
    {
        SetTxts("1300","45","30~35","500","0.6","0.6","6","60","4","600","450","1000","650","100","12","9","20","0.8","0");
    }
     else if(a==4)
    {
        SetTxts("1400","50","30~35","600","0.7","0.7","7","70","5","800","500","1500","900","150","12","12","25","1","0");
    }
    else if(a==5)
    {
        SetTxts("1500","55","30~35","600","0.7","0.7","7","70","5","800","500","1500","900","150","12","12","25","1","0");
    }
     else if(a==6)
    {
         SetTxts("1600","55","30~35","600","0.7","0.7","7","70","5","800","500","1500","900","150","12","12","25","1","0");
    }
    else if(a==7)
    {
        SetTxts("1700","60","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==8)
    {
        SetTxts("1800","65","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==9)
    {
        SetTxts("1900","65","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==10)
    {
        SetTxts("2000","65","25~30","700","0.9","1","9","80","7","800","700","1500","1000","250","12","13.5","35","1.2","0");
    }
     else if(a==11)
    {
        SetTxts("2200","75","25~30","700","1.2","1.2","12","90","10","1000","1000","1500","1200","350","18","15","45","1.8","0");
    }
     else if(a==12)
    {
        SetTxts("2400","80","25~30","700","1.2","1.2","12","100","14","1000","1000","2000","1800","350","25","15.5","50","2","0");
    }
    else if(a==13&&b==1)
    {
        SetTxts("2100","65","20~30","700","1.3","1.2","13","100","14","800","700","2000","2200","350","20","11.5","50","2","3.5");
    }
      else if(a==14&&b==1)
    {
       SetTxts("1900","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==15&&b==1)
    {
        SetTxts("1800","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==16&&b==1)
    {
       SetTxts("1700","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==17&&b==1)
    {
      SetTxts("1700","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
       else if(a==13&&b==2)
    {
       SetTxts("2300","70","20~30","700","1.3","1.2","13","100","14","800","700","2000","2200","350","20","11.5","50","2","3.5");
    }
      else if(a==14&&b==2)
    {
      SetTxts("2000","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==15&&b==2)
    {
       SetTxts("2000","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==16&&b==2)
    {
        SetTxts("1900","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==17&&b==2)
    {
        SetTxts("1900","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==13&&b==3)
    {
         SetTxts("2700","80","20~30","700","1.3","1.2","13","100","14","800","700","2000","2200","350","20","11.5","50","2","3.5");
    }
      else if(a==14&&b==3)
    {
       SetTxts("2200","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==15&&b==3)
    {
        SetTxts("2200","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==16&&b==3)
    {
       SetTxts("2200","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
      else if(a==17&&b==3)
    {
        SetTxts("2200","65","20~30","700","1.3","1.4","13","100","14","1000","700","2000","2200","350","15","11.5","50","2","3.5");
    }
}
function isDigit(s)

{

var patrn=/^\d+(\.\d+)?$/;

if (!patrn.exec(s))
{

return false
}

return true

}
function CheckValue()
{
    var txtmsg= $id("lblMessage");
     if($id("txtStand").value=="")
     {
       txtmsg.value="请您输入身高";
       return false;
     }
        if($id("txtWeight").value=="")
     {
       txtmsg.value="请您输入体重";
       return false;
     }
     if(isDigit($id("txtStand").value)==false)
     {
       txtmsg.value="身高必须为数字";
       return false;
     }
        if(isDigit($id("txtWeight").value)==false)
     {
       txtmsg.value="体重必须为数字";
       return false;
     }
                    
     if(returnAge()==0)
     {
       txtmsg.value="请您选择年龄";
       return false;
     }
    
     if(returnSex()==0)
     {
        txtmsg.value="请您选择性别";
       return false;
     }
     txtmsg.value="";
     return true;
}

function returnSex()
{
     var b=0;
     var sexs=$name("sex");
     for(var j=0;j<sexs.length;j++)
     {
        if(sexs[j].checked==true)
        {
            b=sexs[j].value;
            break;
        }
     }
     return b;
}
function returnAge()
{
    var a=0;
      var selectAge = $id("age");
     for (var i = 0; i < selectAge.options.length; i++) {        
                if (selectAge.options[i].selected == true) {        
                    a = selectAge.options[i].value;        
                    break;        
                }        
            }
            return a;
}
function returnWork()
{
    var b=0;
     var works=$name("rdwork1");
     for(var j=0;j<works.length;j++)
     {
        if(works[j].checked==true)
        {
            b=works[j].value;
            break;
        }
     }
     return b;
}
function returnPregnant()
{
    var b=0;
     var Pregnant=$name("rdprgant1");
     for(var j=0;j<Pregnant.length;j++)
     {
        if(Pregnant[j].checked==true)
        {
            b=Pregnant[j].value;
            break;
        }
     }
     return b;
}