function ccBM_bmi_calc(lbs, ins)
{
	var f = document.forms.ccBM_bmiForm;
	var w_v = f.w_v.value*1;
	var w_u = f.w_u.options[f.w_u.selectedIndex].value;
	var h_ft = f.h_ft.options[f.h_ft.selectedIndex].value;
	var h_in = f.h_in.options[f.h_in.selectedIndex].value;
	var h_v = f.h_v.value*1;
	var h_u = f.h_u.options[f.h_u.selectedIndex].value;
	var err = '';
	if(!w_v || (w_v<35 || w_v>600)) { err += 'Weight value is missing or invalid.'+"\n"; }
	if(h_v) {
		if(!ccBM_is_n(h_v)) { err += 'Height must be a number.'+"\n"; }
		if(h_ft || f.h_in.selectedIndex>0) { err += 'Please choose only one method for height (ft+in, OR inches/cm).'; }
	} else {
		if(!ccBM_is_n(h_ft) || f.h_in.selectedIndex==0) { err += 'Height value is missing or invalid.'; }
	}
	if(err) { alert(err); return false; }
	if(w_u=='kg') { w_v *= 2.20462262; }
	if(h_v) {
		if(h_u=='cm') { h_v *= 0.393700787; }
	} else {
		h_v = (h_ft*12) + (1*h_in);
	}
	var bmi = Math.round( (w_v/(h_v*h_v))*703*10 )/10;
	var txt = '';
	if(bmi<16.5) { txt = 'severely underweight'; }
	else if(bmi>=16.5 && bmi<18.5) { txt = 'underweight'; }
	else if(bmi>=18.5 && bmi<25) { txt = 'normal</span>'; }
	else if(bmi>=25 && bmi<30) { txt = 'overweight'; }
	else { txt = 'obese'; }
	txt = 'Your bmi is <span style="color:#DC853F;font-weight:bold;">'+bmi+'.</span> You are considered <span style="color:#DC853F;font-weight:bold;">'+txt+'.</span>';
	document.getElementById('ccBM_lyr_bmi').innerHTML = txt;
}

function ccBM_bmi_calc_metric(lbs, ins)
{
	var f = document.forms.ccBM_bmiForm;
	var w_v = f.w_v.value*1;
	var w_u = 'kg';//f.w_u.options[f.w_u.selectedIndex].value;
	var h_ft = '';//f.h_ft.options[f.h_ft.selectedIndex].value;
	var h_in = '';//f.h_in.options[f.h_in.selectedIndex].value;
	var h_v = f.h_v.value*1;
	var h_u = 'cm';
	var err = '';
	if(!w_v || (w_v<35 || w_v>600)) { err += 'Weight value is missing or invalid.'+"\n"; }
	if(h_v) {
		if(!ccBM_is_n(h_v)) { err += 'Height must be a number.'+"\n"; }
		if(h_ft) { err += 'Please choose only one method for height (ft+in, OR inches/cm).'; }
	} else {
		if(!ccBM_is_n(h_ft)) { err += 'Height value is missing or invalid.'; }
	}
	if(err) { alert(err); return false; }
	if(w_u=='kg') { w_v *= 2.20462262; }
	if(h_v) {
		if(h_u=='cm') { h_v *= 0.393700787; }
	} else {
		h_v = (h_ft*12) + (1*h_in);
	}
	var bmi = Math.round( (w_v/(h_v*h_v))*703*10 )/10;
	var txt = '';
	if(bmi<16.5) { txt = 'severely underweight'; }
	else if(bmi>=16.5 && bmi<18.5) { txt = 'underweight'; }
	else if(bmi>=18.5 && bmi<25) { txt = 'normal</span>'; }
	else if(bmi>=25 && bmi<30) { txt = 'overweight'; }
	else { txt = 'obese'; }
	txt = 'Your bmi is <span style="color:#DC853F;font-weight:bold;">'+bmi+'.</span> You are considered <span style="color:#DC853F;font-weight:bold;">'+txt+'.</span>';
	document.getElementById('ccBM_lyr_bmi').innerHTML = txt;
}

function ccBM_bmi_calc_standard(lbs, ins)
{
	var f = document.forms.ccBM_bmiForm;
	var w_v = f.w_v.value*1;
	var w_u = 'lbs';//f.w_u.options[f.w_u.selectedIndex].value;
	var h_ft = f.h_ft.options[f.h_ft.selectedIndex].value;
	var h_in = f.h_in.options[f.h_in.selectedIndex].value;
	var h_v = '';
	var h_u = '';
	var err = '';
	if(!w_v || (w_v<35 || w_v>600)) { err += 'Weight value is missing or invalid.'+"\n"; }
	if(h_v) {
		if(!ccBM_is_n(h_v)) { err += 'Height must be a number.'+"\n"; }
		if(h_ft || f.h_in.selectedIndex>0) { err += 'Please choose only one method for height (ft+in, OR inches/cm).'; }
	} else {
		if(!ccBM_is_n(h_ft) || f.h_in.selectedIndex==0) { err += 'Height value is missing or invalid.'; }
	}
	if(err) { alert(err); return false; }
	if(w_u=='kg') { w_v *= 2.20462262; }
	if(h_v) {
		if(h_u=='cm') { h_v *= 0.393700787; }
	} else {
		h_v = (h_ft*12) + (1*h_in);
	}
	var bmi = Math.round( (w_v/(h_v*h_v))*703*10 )/10;
	var txt = '';
	if(bmi<16.5) { txt = 'severely underweight'; }
	else if(bmi>=16.5 && bmi<18.5) { txt = 'underweight'; }
	else if(bmi>=18.5 && bmi<25) { txt = 'normal</span>'; }
	else if(bmi>=25 && bmi<30) { txt = 'overweight'; }
	else { txt = 'obese'; }
	txt = 'Your bmi is <span style="color:#DC853F;font-weight:bold;">'+bmi+'.</span> You are considered <span style="color:#DC853F;font-weight:bold;">'+txt+'.</span>';
	document.getElementById('ccBM_lyr_bmi').innerHTML = txt;
}



function ccBM_is_n(n)
{
	if( isNaN(n) || n==null || n.length==0 ) { return false; }
	n=n+"";
	if( n.search(/\s+/)!=-1 ) { return false; }
	return true;
}

function bmi_tool(p)
{
	var c = document.getElementById('cc_calc_cont');
	
	if (p=='metric')
	{
		c.innerHTML = '<form style="margin:0px;padding:0px;" name="ccBM_bmiForm" onsubmit="ccBM_bmi_calc_metric();return false;"><div style="float:left;width:50px;height:20px;margin-top:55px;margin-left:20px;"><a href="#" onclick="bmi_tool(\'standard\');return false;"><img src="http://www.ebariatricsurgery.com/images/bariatricsurgery24.gif" alt="bariatric surgery" border="0"></a></div><div style="float:left;width:50px;height:20px;margin-top:55px;margin-left:35px;"><a href="#" onclick="bmi_tool(\'metric\');return false;"><img src="http://www.ebariatricsurgery.com/images/bariatricsurgery24.gif" alt="bariatric surgery" border="0"></a></div><input type="text" name="h_v" style="margin-top:9px;margin-left:65px;width:48px;font-size:10px;">&nbsp;&nbsp;&nbsp;<span style="font-size:14px;color:#000000">cm</span><input name="w_v" type="text" style="margin-top:10px;margin-left:65px;width:48px;padding:0px;font-size:10px;" >&nbsp;&nbsp;&nbsp;<span style="font-size:14px;color:#000000">kg</span><input type="submit" style="margin-top:8px;margin-left:25px;height:22px;font-size:12px;vertical-align:top;width:120px;padding: 0 0 5px;" value="calculate BMI"><div id="ccBM_lyr_bmi" style="padding-left:8px;padding-top:2px;margin-left:18px;margin-top:6px;width:122px;height:58px;font-size:11px;font-weight:bold;text-align:center;">Your Body Mass Index is ___. You are considered ____.</div></form><div style="width:150px;text-align:right;margin-top:0px;"><a href="http://www.ebariatricsurgery.com" style="font-size:8px;color:#7B7B7B;">ebariatricsurgery.com</a></div>';
	}
	else if (p=='standard')
	{
		c.innerHTML = '<form style="margin:0px;padding:0px;" name="ccBM_bmiForm" onsubmit="ccBM_bmi_calc_standard();return false;"><div style="float:left;width:50px;height:20px;margin-top:55px;margin-left:20px;"><a href="#" onclick="bmi_tool(\'standard\');return false;"><img src="http://www.ebariatricsurgery.com/images/bariatricsurgery24.gif" alt="bariatric surgery" border="0"></a></div><div style="float:left;width:50px;height:20px;margin-top:55px;margin-left:35px;"><a href="#" onclick="bmi_tool(\'metric\');return false;"><img src="http://www.ebariatricsurgery.com/images/bariatricsurgery24.gif" alt="bariatric surgery" border="0"></a></div><select name="h_ft" style="margin-top:10px;margin-left:65px;width:48px;font-size:10px;"><option value=""></option><option value="4">4\'</option><option value="5">5\'</option><option value="6">6\'</option><option value="7">7\'</option></select>&nbsp;<select name="h_in" style="width:48px;font-size:10px;"><option value=""></option><option value="0">0"</option><option value="1">1"</option><option value="2">2"</option><option value="3">3"</option><option value="4">4"</option><option value="5">5"</option><option value="6">6"</option><option value="7">7"</option><option value="8">8"</option><option value="9">9"</option><option value="10">10"</option><option value="11">11"</option><option value="12">12"</option></select><input name="w_v" type="text" style="margin-top:10px;margin-left:65px;width:30px;padding:0px;font-size:10px;" >&nbsp;&nbsp;&nbsp;<span style="font-size:14px;color:#000000">lbs</span><input type="submit" style="margin-top:8px;margin-left:25px;height:22px;font-size:12px;vertical-align:top;width:120px;padding: 0 0 5px;" value="calculate BMI"><div id="ccBM_lyr_bmi" style="padding-left:8px;padding-top:2px;margin-left:18px;margin-top:6px;width:122px;height:58px;font-size:11px;font-weight:bold;text-align:center;">Your Body Mass Index is ___. You are considered ____.</div></form><div style="width:150px;text-align:right;margin-top:0px;"><a href="http://www.ebariatricsurgery.com" style="font-size:8px;color:#7B7B7B;">ebariatricsurgery.com</a></div>';
	}
}
