
var exer=0;var cals=0.5;$(function(){$('#exer').slider({max:4,min:1,slide:function(event,ui){exer=(parseInt(ui.value));switch(exer){case 1:exer=0;break;case 2:exer=3;break;case 3:exer=5;break;case 4:exer=7;break;}
$('#exerv').html(exer);calculateLoss();}});$('#cals').slider({max:2,min:0.5,step:0.5,slide:function(event,ui){cals=(parseFloat(ui.value));var text='';switch(cals){case 0.5:text='a little';break;case 1:text='some';break;case 1.5:text='quite a lot';break;case 2:text='loads'
break;}
$('#calsv').html(text);calculateLoss();}});$('#female,#male').change(function(){calculateLoss();});$('#stones,#pounds,#age').keyup(function(){calculateLoss();});$('#feet,#inches').click(function(){calculateLoss();});});function calculateLoss(){var stones=parseInt($('#stones').val());var pounds=parseInt($('#pounds').val());var feet=parseInt($('#feet').val());var inches=parseInt($('#inches').val());var age=parseInt($('#age').val());if($('#female').attr('checked')==true){var sex=0;}else{var sex=1;}
if(stones>0){var weight=stones*6350.29318;if(pounds>0){weight=weight+(pounds*453.59237);}
var height=((feet*12)+inches)*2.54;var weightk=weight/1000;if(sex==0){var bmr=655.0955+(9.5634*weightk)+(1.8496*height)-(4.6756*age);}else{var bmr=66.4730+(13.7516*weightk)+(5.0033*height)-(6.7550*age);}
bmr=bmr*1.375;var bgcalspermin=bmr/1440;var fromdb=5.6;var actualcalspermin=(fromdb/68)*(weightk);var remaincalspermin=actualcalspermin-bgcalspermin;if(remaincalspermin<0)remaincalspermin=0;var overexcals=exer*30*remaincalspermin;var totalweightperweek=(overexcals/500)+cals;var maxloss=Math.round(totalweightperweek*8);var maxlossg=(totalweightperweek*8)*453.59237;var bmi185=18.5*((height/100)*(height/100))*1000;if(bmi185>(weight-maxlossg)){maxloss=Math.round((weight-bmi185)/453.59237);}
if(maxloss>0){if(maxloss>14){var st=Math.round((maxloss/14)-0.5);var lb=maxloss-(14*st);var ret=st+"st";if(lb!=0){ret=ret+" "+lb+"lb";}}else{var ret=maxloss+' lb';}
$("#result").html('You could lose '+ret+' in 8 weeks, slide bars to see how much more!');}else{$("#result").html('Your current BMI is low enough that you do not need to lose weight');}}else{$('#result').html('Enter your details to predict your weight loss');}}