﻿  
  var fatW = 28.6;
  var overweightW = 23.8;
  var normalW = 18.6;
  var underweightW = 18.6
  
  var fatM = 30;
  var overweightM = 25;
  var normalM = 20;
  var underweightM = 20;
  
  
  
  
  function calculateBMI()
        {
           var emptySpace = document.getElementById('empty_space');
           var yourBMI = document.getElementById('your_value');
           var weight = document.bmiCalculator.your_weight.value;
           weight = weight.replace(",", ".");
           var length = document.bmiCalculator.your_length.value;
           length = length.replace(",", ".");
           var bmiValue = Math.round((weight / (length/100 * length/100))*100)/100;
           
           var sizeYourValue = Math.round((bmiValue / 70) * 100 *100)/100;
           var sizeEmptySpace = 100 - sizeYourValue;


            //change graph size
            emptySpace.style.height = sizeEmptySpace+"%";
            yourBMI.style.height = sizeYourValue+"%";
            //set correct colour for the graph
            yourBMI.style.color = "Black";
            //man
            if(document.bmiCalculator.man.checked == true)
            {
              if(bmiValue < underweightM) 
               {
                    yourBMI.style.backgroundColor="#82908A";
                    yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>(du behöver gå upp " + ((Math.round((weight - (normalM * (length/100*length/100)))*10)/10) * -1) +" kilo för att nå normalvikt)";
               
               }
            
                else if(bmiValue >= normalM && bmiValue <= overweightM) 
                {
                   yourBMI.style.backgroundColor = "#BFD4D2";
                   yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>Grattis! du har normalvikt";
                }
         
                else if(bmiValue >normalM && bmiValue <= fatM) 
                {
                    yourBMI.style.backgroundColor = "#6D9E9F";
                    yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>(du behöver gå ner " + (Math.round((weight - (overweightM * (length/100*length/100)))*10)/10 +0.1) +" kilo för att nå normalvikt)";
                }
                else
                {
                    yourBMI.style.backgroundColor = "#3A148B";
                    yourBMI.style.color = "White";
                    yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>(du behöver gå ner " + (Math.round((weight - (overweightM * (length/100*length/100)))*10)/10 +0.1) +" kilo för att nå normalvikt)";
                }
            }
            
            else
            {
              if(bmiValue < underweightW) 
               {
                    yourBMI.style.backgroundColor="#82908A";
                    yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>(du behöver gå upp " + ((Math.round((weight - (normalW * (length/100*length/100)))*10)/10) * -1) +" kilo för att nå normalvikt)";
           
               }
            
               else if(bmiValue >= normalM && bmiValue <= overweightM) 
                 {
                   yourBMI.style.backgroundColor = "#BFD4D2";
                   yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>Grattis! du har normalvikt";
             
         
                }
         
                else if(bmiValue >normalW && bmiValue <= fatW) 
                {
                    yourBMI.style.backgroundColor = "#6D9E9F";
                    yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>(du behöver gå ner " + (Math.round((weight - (overweightW * (length/100*length/100)))*10)/10 +0.1) +" kilo för att nå normalvikt)";
        
                }
                else
                {
                    yourBMI.style.backgroundColor = "#3A148B";
                    yourBMI.style.color = "White";
                    yourBMI.innerHTML = "Ditt BMI värde är: " + bmiValue + " <br/>(du behöver gå ner " + (Math.round((weight - (overweightW * (length/100*length/100)))*10)/10 +0.1) +" kilo för att nå normalvikt)";
                   
            
                }
          
            }
            
           
           
        }
        
        function changeToMan()
        {
            document.bmiCalculator.woman.checked=false;
            document.getElementById('fat').innerHTML = "Fetma (>" + fatM +")";
            document.getElementById('overweight').innerHTML = "Övervikt (" + overweightM + "-"+ fatM +")";
            document.getElementById('normal').innerHTML = "Normal (" + normalM + "-" + overweightM + ")";
            document.getElementById('lindsay_lohan').innerHTML = "Undervikt (<" + underweightM +")";
            document.getElementById('fat').style.height = "57.14%";
            document.getElementById('overweight').style.height = "7.14%";
            document.getElementById('normal').style.height = "7.14%";
            document.getElementById('lindsay_lohan').style.height = "28.57%";
            
            document.getElementById('empty_space').style.backgroundColor = "White";
            document.getElementById('your_value').style.backgroundColor = "White";
            document.getElementById('your_value').innerHTML = "Ditt värde: ??";
            document.bmiCalculator.your_weight.value = "";
            document.bmiCalculator.your_length.value ="";
        }
        
        function changeToWoman()
        {
            document.bmiCalculator.man.checked=false;
            document.getElementById('fat').innerHTML = "Fetma (>" + fatW +")";
            document.getElementById('overweight').innerHTML = "Övervikt (" + overweightW + "-"+ fatW +")";
            document.getElementById('normal').innerHTML = "Normal (" + normalW + "-" + overweightW + ")";
            document.getElementById('lindsay_lohan').innerHTML = "Undervikt (<" + underweightW +")";
            document.getElementById('fat').style.height = "59.14%";
            document.getElementById('overweight').style.height = "6.86%";
            document.getElementById('normal').style.height = "7.42%";
            document.getElementById('lindsay_lohan').style.height = "26.57%";
            
            document.getElementById('empty_space').style.backgroundColor = "White";
            document.getElementById('your_value').style.backgroundColor = "White";
            document.getElementById('your_value').innerHTML = "Ditt värde: ??";
            document.bmiCalculator.your_weight.value = "";
            document.bmiCalculator.your_length.value ="";
        }
