function dd(list){
var listElementStyle=document.getElementById(list).style;
if (listElementStyle.display=="none"){
listElementStyle.display="block";}
else {
listElementStyle.display="none";
}
}

function display_in_id(to, from) {
	document.getElementById(to).innerHTML = document.getElementById(from).innerHTML;
}

function toggle_top12list(item) {
	display_in_id('top12list_items', item);	
}

/* begin tab swap */
unselectedTabImage = "images/tabn.gif";

Array.prototype.search = function (el) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == el) {
			return i;
		}
	}
	return -1;
}

function change_tag_background (id, src) {

	/* Set the chosen tab's backgroundImage property */
	document.getElementById(id).style.backgroundImage = "url(" + src + ")";
	document.getElementById(id).blur();

	/* Set the other tabs' backgroundImage properties */
	var tabs = new Array('tab1', 'tab2', 'tab3');
	var position = tabs.search(id);

	for (var i = 0; i < tabs.length; i++) {
		if (i != position) {
			document.getElementById(tabs[i]).style.backgroundImage = "url(" + unselectedTabImage + ")";
		}
	}

}
/* end tab swap */

/* Rotating image BEGIN */

var item=new Array()
item[0]="<a href='/health/health-food.html'><img src='images/health.jpg' border='0' /></a>"
item[1]="<a href='/cancer/skin-cancer-symptoms.html'><img src='images/checkup.jpg' border='0' /></a>"
item[2]="<a href='/medical-information/blood-pressure-exercise.html'><img src='images/exercise.jpg' border='0' /></a>"
item[3]="<a href='/mc-back-pain.html'><img src='images/back.jpg' border='0' /></a>"
var current=0
var timeout;

var ns6=document.getElementById&&!document.all

function changeImage(delay_next) {
	document.getElementById("div1").innerHTML=item[current];
	if(delay_next > 0) {
		timeout = setTimeout("changeItem()",delay_next);
	}
}

function changeItem() {
	if (current==3) {
		current=0;
	} else {
		current++;
	}
	changeImage(5000);
}

function itemForward() {
	clearTimeout(timeout);
	document.getElementById("div1").innerHTML=item[current];
	if (current==3) {
		current=0;
	} else {
		current++;
	}
	changeImage(10000);
}

function itemBackwards() {
	clearTimeout(timeout);
	if (current==0) {
		current=3;
	} else {
		current--;
	}
	changeImage(10000);
}

function itemPause() {
	clearTimeout(timeout);
}

function preloadImages() {
	if (document.images) {
		pic1= new Image(531,232);
		pic1.src="images/health.jpg";
		
		pic2= new Image(531,232);
		pic2.src="images/checkup.jpg";
		
		pic3= new Image(531,232);
		pic3.src="images/exercise.jpg";
		
		pic4= new Image(531,232);
		pic4.src="images/back.jpg";
	}
}
/* Rotating image END */


/* ///////////////////////////////////////////////////////////////////////// */
/* BEGIN HEALTH TOOLS */
/* ///////////////////////////////////////////////////////////////////////// */ 

/* BEGIN BMI CALC */
function get_bmi(thebutton) {
	var theform = thebutton.form;
	var height_feet = theform.height_feet.value * 1;
	var height_inches = theform.height_inches.value * 1;
	var height = height_feet * 12 + height_inches;
	var weight = theform.weight.value;
	var the_result = (weight * 703) / (height * height);
	the_result = the_result.toFixed(1);
	
	if (height_feet == "") {
		alert ('Please enter your height in feet and inches');
	} else if (height_inches =="") {
		alert ('Please enter your height in feet and inches');
	} else if (weight == "") {
		alert ('Please enter your weight');
	} else {
		document.getElementById('bmi').innerHTML = the_result;
	}
	return false;
}
/* END BMI CALC */

/* BEGIN METRIC BMI CALC */
function get_metric_bmi(thebutton) {
	var theform = thebutton.form;
	var metric_height = theform.metric_height.value;
	var metric_weight = theform.metric_weight.value;
	var the_metric_result = metric_weight / ((metric_height/100) * (metric_height/100));
	the_metric_result = the_metric_result.toFixed(1);
	
	if (metric_height == "") {
		alert ('Please enter your height');
	} else if (metric_weight == "") {
		alert ('Please enter your weight');
	} else {
		document.getElementById('bmi').innerHTML = the_metric_result;
	}
	return false;
}
/* END METRIC BMI CALC */

/* BEGIN BMI SWAPS - TABS */
function display_in_id(to, from) {
	document.getElementById(to).innerHTML = document.getElementById(from).innerHTML;
}

function toggle_bmi(item) {
	display_in_id('bmi_items', item);	
}

/* Tab Swap */
unselectedTabImage = "/images/tabn.gif";

Array.prototype.search = function (el) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == el) {
			return i;
		}
	}
	return -1;
}

function change_tab_bg (id, src) {

	/* Set the chosen tab's backgroundImage property */
	document.getElementById(id).style.backgroundImage = "url(" + src + ")";
	document.getElementById(id).blur();

	/* Set the other tabs' backgroundImage properties */
	var tabs = new Array('tab1', 'tab2');
	var position = tabs.search(id);

	for (var i = 0; i < tabs.length; i++) {
		if (i != position) {
			document.getElementById(tabs[i]).style.backgroundImage = "url(" + unselectedTabImage + ")";
		}
	}

}
/* END BMI SWAPS - TABS */

/* BEGIN HEART RATE CALC */
function get_heart_rate(thebutton) {
	var theform = thebutton.form;
	var age = theform.age.value * 1;
	var rhr = theform.rhr.value * 1;
	var heart_rate_low = ((206.9 - (0.67 * age)) - rhr) * 0.65 + rhr;
	var heart_rate_high = ((206.9 - (0.67 * age)) - rhr) * 0.85 + rhr;
	
	if (age <= 0) {
		alert ('Please enter your age');
	} else if (rhr <= 0) {
		alert ('Please enter beats per minute');
	} else {
		var max_heart_rate = 220 - age;
		var heart_rate_range = Math.round(heart_rate_low) + ' - ' + Math.round(heart_rate_high);
		document.getElementById('rate').innerHTML = heart_rate_range;
		document.getElementById('max').innerHTML = max_heart_rate;
	}
	return false;
}
/* END HEART RATE CALC */

/* BEGIN HEALTHY WEIGHT CHECKER */
function get_healthy_weight(thebutton) {
	var theform = thebutton.form;
	var sex = get_selected_from_radio_group(theform.sex);
	var height_feet = theform.height_feet.value * 1;
	var height_inches = theform.height_inches.value * 1;
	var height = height_feet * 12 + height_inches;
	var frame = get_selected_from_radio_group(theform.frame);
	
	if (height == "" || height < 58 || height > 82) {
		alert ('Please Enter a Height Between 4\'10" and 6\'10"');
	} else {	
		var ideal_weight = 0;
		if (sex == 'Male' && frame == 'Small') {
			if (height > 58 && height < 73) {
				ideal_weight = (height - 58) * 3 + 117;
			} else if (height > 73) {
				ideal_weight = (height - 58) * 4 + 117;
			} else {
				ideal_weight = 117;
			}
		} else if (sex == 'Male' && frame == 'Medium') {
			if (height > 58 && height < 73) {
				ideal_weight = (height - 58) * 3 + 124;
			} else if (height > 73) {
				ideal_weight = (height - 58) * 4.5 + 117;
			} else {
				ideal_weight = 124;
			}
		} else if (sex == 'Male' && frame == 'Large') {
			if (height > 58 && height < 73) {
				ideal_weight = (height - 58) * 3 + 132;
			} else if (height > 73) {
				ideal_weight = (height - 58) * 5 + 117;
			} else {
				ideal_weight = 132;
			}
		} else if (sex == 'Female' && frame == 'Small') {
			if (height > 58 && height < 73) {
				ideal_weight = (height - 58) * 3 + 102;
			} else if (height > 73) {
				ideal_weight = (height - 58) * 4 + 102;
			} else {
				ideal_weight = 102;
			}
		} else if (sex == 'Female' && frame == 'Medium') {
			if (height > 58 && height < 73) {
				ideal_weight = (height - 58) * 3 + 113;
			} else if (height > 73) {
				ideal_weight = (height - 58) * 4.5 + 102;
			} else {
				ideal_weight = 113;
			}
		} else if (sex == 'Female' && frame == 'Large') {
			if (height > 58 && height < 73) {
				ideal_weight = (height - 58) * 3 + 124;
			} else if (height > 73) {
				ideal_weight = (height - 58) * 5 + 102;
			} else {
				ideal_weight = 124;
			}
		}
		document.getElementById('max_weight').innerHTML = Math.round(ideal_weight);
	}
	return false;
}

/* DETERMINES SEX BY WHICH RADIO BUTTON CHECKED */
function get_selected_from_radio_group(group) {
	// Call with: value =  get_selected_from_radio_group(theform.groupname)
	for (i = 0; i < group.length; i++) {
		if (group[i].checked) {
			return group[i].value;
		}
	}
	return '';
}
/* END HEALTHY WEIGHT CHECKER */

/* BEGIN BODY FAT PERCENTAGE */
/* MALE */
function get_body_fat_male(thebutton){
	var theform = thebutton.form;
	var weight = theform.weight.value;
	var waist = theform.waist.value;
	
	var body_fat_percentage = 0;
	if (weight == "") {
		alert('Please enter your weight in pounds (lbs.)');
	} else if (waist == "") {
		alert('Please enter your waist measurement in inches.');
	} else {
		body_fat_percentage = ((weight - ((weight * 1.082 + 94.42) - waist * 4.15)) * 100) / weight;
		document.getElementById('body_fat').innerHTML = body_fat_percentage.toFixed(2) + ' %';
	}
	return false;
}
/* FEMALE */
function get_body_fat_female(thebutton){
	var theform = thebutton.form;
	var weight = theform.weight.value;
	var wrist = theform.wrist.value;
	var forearm = theform.forearm.value;
	var waist = theform.waist.value;
	var hip = theform.hip.value;
	
	var body_fat_percentage = 0;
	if (weight == "") {  
		alert('Please enter your weight.');
	} else if (waist == "") {
		alert('Please enter your waist measurement in inches');
	} else if (hip == "") {
		alert('Please enter your hip measurment in inches.');
	} else if (wrist == "") {
		alert('Please enter your wrist size in inches.');
	} else if (forearm == "") {
		alert('Please enter your forearm size in inches.');
	} else {		
		body_fat_percentage = ((weight - ((weight * 0.732 + 8.987) + (wrist / 3.140) - (waist * 0.157) - (hip * 0.249) + (forearm * 0.434))) * 100) / weight;
		document.getElementById('body_fat').innerHTML = body_fat_percentage.toFixed(2) + ' %';
	}
	return false;
}

/* WHERE TO PUT MALE/FEMALE FORMS - (in a div) */
function display_in_id(to, from) {
	document.getElementById(to).innerHTML = document.getElementById(from).innerHTML;
}

function toggle_bodyfat(item) {
	display_in_id('bodyfat_items', item);	
}

/* BEGIN BODY FAT SWAPS - TABS */
function display_in_id(to, from) {
	document.getElementById(to).innerHTML = document.getElementById(from).innerHTML;
}

function toggle_bfat(item) {
	display_in_id('bfat_items', item);	
}

/* Tab Swap */
unselectedTabImage = "/images/tabn.gif";

Array.prototype.search = function (el) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == el) {
			return i;
		}
	}
	return -1;
}

function change_sex_bg (id, src) {

	/* Set the chosen tab's backgroundImage property */
	document.getElementById(id).style.backgroundImage = "url(" + src + ")";
	document.getElementById(id).blur();

	/* Set the other tabs' backgroundImage properties */
	var tabs = new Array('tab3', 'tab4');
	var position = tabs.search(id);

	for (var i = 0; i < tabs.length; i++) {
		if (i != position) {
			document.getElementById(tabs[i]).style.backgroundImage = "url(" + unselectedTabImage + ")";
		}
	}

}
/* END BODY FAT SWAPS - TABS */

/* END BODY FAT PERCENTAGE*/

/* ///////////////////////////////////////////////////////////////////////// */
/* END HEALTH TOOLS */
/* ///////////////////////////////////////////////////////////////////////// */ 