function swapImg(imgName,state){eval('document.' + imgName + '.src = ' + imgName + state + '.src');}

dieton = new Image(); dieton.src = "/images/tabs-diet-on.gif";dietoff = new Image(); dietoff.src = "/images/tabs-diet-off.gif";
gymon = new Image(); gymon.src = "/images/tabs-gym-on.gif";gymoff = new Image(); gymoff.src = "/images/tabs-gym-off.gif";
exerciseon = new Image(); exerciseon.src = "/images/tabs-exercise-on.gif";exerciseoff = new Image(); exerciseoff.src = "/images/tabs-exercise-off.gif";
toolson = new Image(); toolson.src = "/images/tabs-tools-on.gif";toolsoff = new Image(); toolsoff.src = "/images/tabs-tools-off.gif";
newsletteron = new Image(); newsletteron.src = "/images/tabs-newsletter-on.gif";newsletteroff = new Image(); newsletteroff.src = "/images/tabs-newsletter-off.gif";

/*******************/
/*   SEARCHBOX    */
/*******************/

function searchboxes(inp,defaultText,isFocus)
{
	if (isFocus==1)
	{
		if (inp.value==defaultText){inp.value='';}
	}
	else
	{
		if (inp.value==''){inp.value=defaultText;}
	}
}

function toggleElm()
{
	a=toggleElm.arguments;
	for(i=0; i<a.length; i++)
	{
		try
		{
			elm=document.getElementById(a[i]);
			if (elm.style.display=='none'){elm.style.display='';}
			else {elm.style.display='none';}
		}catch(e){}
	}
}



function ClearForm (form)

        {

        form.weight.value="";

        form.waist.value="";

        form.bodyfat.value="";

        }



function VerifyForm(form) 

        {

        

        // Holds whether or not the form is correct

        var Correct = true;



        // Check for missing fields

        if (form.weight.value == null || form.weight.value.length == 0 ||

        form.waist.value == null || form.waist.value.length == 0) {

                alert ("\nPlease fill in all of the form elements");

                Correct = false;

     }

        

        // Check that only numbers are in the weight and waist fields

        else {

                // Holds the floats representing the weight and waist

                var TestWeight;

                var TestWaist;



                // Parse the weight and waist values and put in the variables

                TestWeight = parseFloat(form.weight.value);

                TestWaist = parseFloat(form.waist.value);



                // Check to see that TestWeight is a number

                if (isNaN (TestWeight)) {

                        alert("\nMake sure to enter the weight\nas a number.");

                        Correct = false;

                        form.weight.value="";

                }



                // Check to see that TestWaist is a number

                if (isNaN (TestWaist)) {

                        alert("\nMake sure to enter the waist size\nas a number.");

                        Correct = false;

                        form.waist.value="";

                }

        

                // Check that the TestWeight is greater than 0

                if (TestWeight <= 0) {

                        alert("\nCome on.  Enter a real weight.");

                        Correct = false;

                        form.weight.value="";   

                }



                // Check that the TestWaist is greater than 0

                if (TestWaist <= 0) {

                        alert("\nCome on.  Enter a real waist size.");

                        Correct = false;

                        form.waist.value="";    

                }



        }



        // If the inputs are correct, calculate the bodyfat percent

        if (Correct) {

                

                // Holds the bodyfat number and percent

                var BF;

                var BFPercent;



                // Make the male calculations   

                if (form.gender[0].checked) {

                        BF = -98.42 + 4.15*TestWaist - .082*TestWeight;

                }



                // Make the female calculations

                else {

                        BF = -76.76 + (4.15*TestWaist) - (.082*TestWeight);

                }

                

                // Calculate the bodyfat percentage

                BFPercent = BF / TestWeight;

                BFPercent = BFPercent * 100;

                BFPercent = Math.round(BFPercent);



                // Send this number to the screen

                form.bodyfat.value = BFPercent + "%";

        }

}



function FigureBMI()

{

 if (document.bmi.inches.value == null || document.bmi.inches.value == 0 ||

     document.bmi.pounds.value == null || document.bmi.pounds.value == 0)

        {

     alert ("\nPlease fill in all of the form elements");

        }

 else

         {

         meters = document.bmi.inches.value*0.0254;

         kilograms = document.bmi.pounds.value*0.4535924;  

         Square      = meters * meters;

         document.bmi.calcval.value = Math.round(kilograms/Square);

         }

}



function MM_openBrWindow(theURL,winName,features) 

{ 

  window.open(theURL,winName,features);

}



function myCon() 

{

  var FromVal, ToVal, FromName, ToName, val1, val2, Factor;



  val1 = document.MainForm.amount.value;

  val2 = val1

  val1 = parseFloat(val1);

  if (isNaN(val1)) val1 = 1;

  document.MainForm.amount.value = val1;

  

  FromVal = document.MainForm.from[document.MainForm.from.selectedIndex].value;

  ToVal = document.MainForm.to[document.MainForm.to.selectedIndex].value;

  FromName = document.MainForm.from.options[document.MainForm.from.selectedIndex].text;

  ToName = document.MainForm.to.options[document.MainForm.to.selectedIndex].text;



  Factor = eval("(" + FromVal + ")/(" + ToVal + ")");

  val1 *= Factor;

  val1 = Math.round(val1 *10000000)/10000000;

  

  document.MainForm.answer.value = val2 + " " + FromName + " = " + val1 + " " + ToName;

}





function calc_hr()

{

 level = document.form1.level.value;

 val = 220-document.form1.age.value;

 

 if (document.form1.level[0].checked)

 {

  val1 = val * .4;

  val2 = val * .5;

 }

 

 if (document.form1.level[1].checked)

 {

  val1 = val * .5;

  val2 = val * .6;

 }

 

 if (document.form1.level[2].checked)

 {

  val1 = val * .6;

  val2 = val * .8;

 }



 if (document.form1.level[3].checked)

 {

  val1 = val * .7;

  val2 = val * .9;

 }

                                                

 document.form1.target1.value = Math.round(val1);

 document.form1.target2.value = Math.round(val2);

}



function computeBMR(form)

{

 form.BMRMale.value = Math.round(66.473 + ((form.weight.value / 2.2 ) * 13.751) + (5.0033 * form.height.value * 2.54) - (6.55 * form.age.value));

 form.BMRFemale.value = Math.round(665.51 + ((form.weight.value / 2.2 ) * 9.463) + (1.8496 * form.height.value * 2.54) - (4.6756 * form.age.value));

}



function clearBMR(form)

{

 form.age.value = "";

 form.weight.value = "";

 form.height.value = "";

 form.BMRMale.value = "";

 form.BMRFemale.value = "";

}



function Owt() 

{

 var pounds=document.form.pounds.value;

 var feet=document.form.feet.value;

 var inches=document.form.inches.value;

 var waist=document.form.waist.value;

 var Correct = true;

 

 if (document.form.pounds.value == null || document.form.pounds.value.length == 0)

         {

                 alert ("\nPlease enter your weight");

                Correct = false;

        }

 if (document.form.feet.value == null || document.form.feet.value.length == 0 || 

     document.form.inches.value == null || document.form.inches.value.lenght == 0)

        {

                 alert ("\nPlease enter height - both feet and inches");

                Correct = false;

        }

 if (document.form.waist.value == null || document.form.waist.value.length == 0)

         {         

                 alert ("\nPlease enter waist measurement");

                Correct = false;

        }         

         

 if (Correct)

         {

         if(document.form.gender[0].checked) 

             factor=98.42; 

         else factor=76.76;



         TotalInches = eval(feet*12) + eval(inches);

         Meters      = TotalInches/39.36;

         Square      = Meters * Meters;



         bfp=((4.15*waist)-factor-0.082*pounds)/pounds;



         if(document.form.gender[0].checked) 

                 bmiweight=Square*23*2.2;

         else 

                 bmiweight=Square*24*2.2;



         if(document.form.activity[1].checked) 

                 bmiweight=bmiweight-2; 

         else if(document.form.activity[2].checked) 

                 bmiweight=bmiweight-5;

         else 

                 bmiweight=bmiweight;



         if(document.form.age[0].checked)

                 bmiweight=bmiweight-5; 

         else if(document.form.age[1].checked) 

                 bmiweight=bmiweight; 

         else bmiweight=bmiweight+5;



         if(document.form.faddiet[0].checked) 

                 bmiweight=bmiweight+5; 

         else bmiweight=bmiweight;



         if(document.form.gender[0].checked)

                {

                 document.form.goalweight.value=Math.round(bmiweight);

                 document.form.overweight.value=Math.round(pounds-bmiweight);

                 document.form.excessfat.value=Math.round(pounds*(bfp-0.08));

                }

         else

                {

                 document.form.goalweight.value=Math.round(bmiweight);


                 
                 if ( Math.round(pounds-bmiweight) > 0 ) {
                        document.form.overweight.value=Math.round(pounds-bmiweight);
                        document.form.excessfat.value=Math.round(pounds*(bfp-0.13));
                        }

                 else {
                        document.form.overweight.value=0;
                        document.form.excessfat.value=0;
                        }

                }

        }

}



function ClearOwtForm()

{

         document.form.pounds.value="";

         document.form.feet.value="";

         document.form.inches.value="";

         document.form.waist.value="";

         document.form.goalweight.value="";

         document.form.overweight.value="";

         document.form.excessfat.value="";

}



function CalcCalForm()

{

        if (form.mins.value == null || form.mins.value.length == 0 ||

        form.weight.value == null || form.weight.value.length == 0)

                {

         alert ("\nPlease fill in all of the form elements");

                }

    else

                {        

                 factor = document.form.exercise[document.form.exercise.selectedIndex].value;

                 form.total.value = Math.round(factor * form.weight.value * form.mins.value);

                }

}



function ClearCalForm(form)

{

        form.mins.value="";

        form.weight.value="";

}



function CalcDCI()

{

        if (document.form.inches.value == null || document.form.inches.value.length == 0 ||

        document.form.pounds.value == null || document.form.pounds.value.length == 0 ||

        document.form.years.value == null    || document.form.years.value.length == 0) 

                {

                alert ("\nPlease fill in all of the form elements");

                                return;

                }

                                

        var inches=document.form.inches.value;

        var pounds=document.form.pounds.value;

    var years=document.form.years.value;

        var factor=document.form.exercise[document.form.exercise.selectedIndex].value;

        

        // Make the male calculations   

    if (document.form.gender[0].checked)

          {

             weight = 66 + (13.7 * (pounds / 2.2));

                  height = 5 * (inches * 2.54);

                  age = 6.8 * years;

                  document.form.result.value = (Math.round(weight + height - age) * factor);                   

      }



    // Make the female calculations

    else

          {

       weight = 655 + (9.6 * (pounds / 2.2));

           height = 1.7 * (inches * 2.54);

           age = 4.7 * years;

       document.form.result.value = (Math.round(weight + height - age) * factor);                  

          }

                                

}



function ClearDCI()

{

        document.form.inches.value="";

        document.form.pounds.value="";

    document.form.years.value="";

        document.form.result.value="";

}




/*******************/
/*   TABS          */
/*******************/

function initTabs(c)
		{
			var cont = document.getElementById(c);
			var u = cont.getElementsByTagName('UL');
			if(u.length>0)
			{
				u[0].className='tabs';

				hideAllTabsInContainer(cont);
				showTabInContainer(cont,0);
			}
		}

		function hideAllTabsInContainer(c)
		{
			var u = c.getElementsByTagName('UL');
			if(u.length>0)
			{
				var l = u[0].getElementsByTagName('LI');
				if(l.length>0)
				{
					for(var i=0;i<l.length;i++)
					{
						l[i].className='';

						//ADD ROUNDED CORNERS TO FIRST AND LAST LI
						if(i==0)
						{
							for(var a=0; a < l[i].childNodes.length;a++)
							{
								if(l[i].childNodes[a].tagName.toLowerCase()=='a')
								{
									l[i].childNodes[a].className = 'topleft';
									break;
								}
							}
						}

						if(i==(l.length-1))
						{
							for(var a=0; a < l[i].childNodes.length;a++)
							{
								if(l[i].childNodes[a].tagName.toLowerCase()=='a')
								{
									l[i].childNodes[a].className = 'topright';
									break;
								}
							}
						}
					}
				}
			}
			
			var d = c.getElementsByTagName('DIV');
			if(d.length>0)
			{
				for(var i=0;i<d.length;i++)
				{
					if(d[i].className=='tabPage'){d[i].style.display='none';}
				}
			}
		}

		function showTabInContainer(c,ind)
		{
			var u = c.getElementsByTagName('UL');
			if(u.length>0)
			{
				var l = u[0].getElementsByTagName('LI');
				if(l.length>ind)
				{
					l[ind].className='active';
				}
			}
			
			var d = c.getElementsByTagName('DIV');
			if(d.length>0)
			{
				var t = 0;
				var done = false;

				for(var i=0;i<d.length;i++)
				{
					if(d[i].className=='tabPage')
					{
						if(t==ind)
						{
							d[i].style.display='';
							done=true;
							break;
						}
						else{t+=1;}
					}
				}

				if(done==false){d[t-1].style.display='';}
			}
		}
		
		function toggleTab(me,ind)
		{
			var cont = me.parentNode.parentNode.parentNode;
			hideAllTabsInContainer(cont);
			showTabInContainer(cont,ind);
			try{window.focus();}catch(e){}
		}

/* code for table rollovers */

//SWAP CLASS(element object, classname)
function sC(elm,cn)
{
	if(!elm){return;}
	elm.className = cn;
}
//FIND LINK AND GO(event, element object [, target, linkid])
//evt		- the event object, so the function can be exited if the click originates from a genuine A tag
//elm		- the element to be searched for a link
//target	- optional, "_self" by default, ie the same window
//lnkid		- optional, the value of the id attribute within an A element inside the element object
//			  if not specified, the script will attempt to find a the first A element with an href
//			  attribute inside the element object
function fLaG(evt,elm,trgt,lnkid)
{
	if(!elm){return;}

	var et = evt.target || evt.srcElement;
    var tn = et.tagName;
    if(tn.toLowerCase()=='a'){return;}

	var a;
	if(lnkid){a=document.getElementById(lnkid);}
	else
	{
		var l = elm.getElementsByTagName('A');
		if(l)
		{
			for(var i=0;i<l.length;i++)
			{
				if(l[i].href){a = l[i];break;}
			}
		}
	}

	if(a)
	{
		if(a.href)
		{
			var t = "_self";
			if(trgt){t=trgt;}
			else
			{
				if(a.target){t=a.target;}
			}

			window.open(a.href,t);
		}
		else{return;}
	}
	else{return;}
}

