﻿<!-- Hide script from older browsers

function getObj(el){
	if (document.layers) {
		obj = document.layers[el]
	} else if (document.all) {
		obj = document.all(el)
	} else if (document.getElementById) {
		obj = document.getElementById(el)
	}
	return obj;
}

function showhide(a,el){
	obj=getObj(el)
	obj.style.display=a
	return
}


function mSystem (val) {
	if (val=="eng"){
		showhide("block","weightp")
		showhide("block","heighte")

		showhide("none","weightk")
		showhide("none","heightm")

		obj=getObj("heng")
		obj.checked=true
		
		obj=getObj("weight")
		w=obj.value;
		if (w>0) obj.value=w*2.2

		cent=parseFloat(getElement("centimeters")*1);
			fobj=getObj("feet")
			iobj=getObj("inches")
		
			num=(cent/2.54)/12
				tmp=num.toString()
				swap=tmp.split(".")
					fobj.value=swap[0]
					iobj.value=parseInt(swap[1].substr(0,1))+2

		
	}

	if (val=="met"){
		showhide("none","weightp")
		showhide("none","heighte")	

		showhide("block","weightk")
		showhide("block","heightm")
		
		obj=getObj("hmet")
		obj.checked=true

		obj=getObj("weight")
		w=obj.value;
		if (w>0) obj.value=w/2.2

		ft=parseInt(getElement("feet")*1);
		inch=parseInt(getElement("inches")*1);
		
		cobj=getObj("centimeters")
		cent=cobj.value;
			swap=(ft*12+inch)*2.54
				cobj.value=swap

	}
}

function getElement(elname){
	var output="";
	var test="";

	tobj = new Object();
	tobj = eval("document.cic." + elname);

	if (tobj.type=="text"){
		test+="item : "+elname+" ("+tobj.value+")\n";
		output=tobj.value;
	} else if (tobj.type=="select-one") {
		sel=tobj.selectedIndex;
		test+="item : "+elname+" ("+tobj.options[sel].value+")\n";
		output=tobj.options[sel].value;
	} else {
		len=tobj.length
		if (len>0) {
			output=new Array();
			cnt=0;
			for (x=0; x<len; x++){
				if (tobj[x].checked) {
					test+="item : "+elname+"("+x+") ("+tobj[x].value+")\n";
					tmp=tobj[x].value
					output[cnt]=tmp
					cnt++;
				}
			}
		}
	}
	return output
}


function calCalc () {
	getVals()
}


function XXcalCalc () {
weight = document.cic.weight.value;
w = document.cic.w.value;
h = document.cic.h.value;
feet = document.cic.feet.value;
inches = document.cic.inches.value;
centimeters = document.cic.centimeters.value;
years = document.cic.years.value;
g = document.cic.g.value;
//alert (getVals());
alert (weight);
}

function heightSystem () {
alert ("Something's happening on change!");
}


function roundResult(num){
	dec=100;
	return Math.round(num*dec)/dec
}

function getVals(){

var obj = new Array()
obj[0] = "weight"			//your weight
obj[1] = "w"				//lbs or kilos //p or k//radio

obj[2] = "mtype"	//height in metric or english
obj[3] = "centimeters"	//your height in cm
obj[4] = "feet"			//your feet
obj[5] = "inches"			//your inches 

obj[6] = "years"			//your age

obj[7] = "g"				//your gender

obj[8] = "e"				//excersize
value = "test";


// HEIGHT
height=-1;
mtype=getElement(obj[2]);

if (mtype=="met") {
	//alert(parseInt(getElement(obj[3])*1))
	height=parseInt(getElement(obj[3])*1);
}
if (mtype=="eng") {
	ft=parseInt(getElement(obj[4])*1);
	inch=parseInt(getElement(obj[5])*1);
	height=(ft*12+inch)*2.54	
}

// WEIGHT
weight=parseInt(getElement(obj[0])*1);
if (mtype=="eng") weight=parseInt(weight/2.2)

// AGE
age=parseInt(getElement(obj[6])*1);

// GENDER
gen=getElement(obj[7]);
	// Equate gender offset
	var offset=0;
	if (gen=="f") offset=-161
	if (gen=="m") offset=5

// excersize
excer=getElement(obj[8])*1;

//Men:
//5 + 10 (weight in kilos) +6.25 (height in cm) - 5 (age)

//Women:
//-161 +10 (weight in kilos) +6.25 (height in cm) - 5 (age) 

tmp=(offset+(10*weight)+(6.25*height)-(5*age))*excer
result=roundResult(tmp)

obj=getObj("result")
obj.value=result


/*
test="offset: "+offset+"\n"
test+="weight: "+weight+"\n"
test+="height: "+height+"\n"
test+="age: "+age+"\n"
test+="----------------\n"
test+=result+"\n"

alert(test)
*/

}


// End hiding script from older browsers -->