var Feet,Result,Result1,Inches,Lbs,Cms,Kgs,Pinch,Peet,Metres,BMI
var clockID=0
function UpdateClock()
{
if (clockID)
{clearTimeout(clockID);
clockID = 0;}

var tDate = new Date();
var dayofweek = tDate.getDay();
if (dayofweek==0){dayofweek="Sunday"}
if (dayofweek==1){dayofweek="Monday"}
if (dayofweek==2){dayofweek="Tuesday"}
if (dayofweek==3){dayofweek="Wednesday"}
if (dayofweek==4){dayofweek="Thursday"}
if (dayofweek==5){dayofweek="Friday"}
if (dayofweek==6){dayofweek="Saturday"}

var Day=tDate.getDate()

var Mth=tDate.getMonth()+1
if (Mth==1){Mth="January"}
if (Mth==2){Mth="February"}
if (Mth==3){Mth="March"}
if (Mth==4){Mth="April"}
if (Mth==5){Mth="May"}
if (Mth==6){Mth="June"}
if (Mth==7){Mth="July"}
if (Mth==8){Mth="August"}
if (Mth==9){Mth="September"}
if (Mth==10){Mth="October"}
if (Mth==11){Mth="November"}
if (Mth==12){Mth="December"}

var Yr=tDate.getFullYear()

var H=tDate.getHours();
if (H>11)
{var AMPM="PM";}
else
{var AMPM="AM";}

if (H>12)
{H=H-12;}

if (H<10)
{H="0"+H;}

var M=tDate.getMinutes()
if (M<10)
{M="0"+M;}

var S=tDate.getSeconds()
if (S<10)
{S="0"+S;}

theDate.innerHTML=dayofweek+", "+Mth+" "+Day+", "+Yr+" ---"+H+":"+M+":"+S+" "+AMPM;
clockID = setTimeout("UpdateClock()",1000);
}

function StartClock() {
clockID = setTimeout("UpdateClock()",500);
}

function KillClock() {
if (clockID)
 {clearTimeout(clockID);
 clockID = 0;}
}

function FeetConvert()
{
Result=document.ABC.ft.value*30.48;
Result+=document.ABC.ins.value*2.54;
document.ABC.heightcms.value=round2(Result,2);
}

function InchConvert()
{
Peet=document.ABC.ft.value;
Pinch=document.ABC.ins.value;

if (Pinch >= 12)
	{FtInsConvert(Pinch);}
else
	{Feet=Peet*30.48;
	Inches=Pinch*2.54;
	Result=+Inches+Feet;
	document.ABC.heightcms.value=round2(Result,2);}
	}

function FtInsConvert(Inches)
{
Inches=Pinch%12;
Feet=+Peet+parseInt(Pinch/12);
document.ABC.ft.value=Feet;
document.ABC.ins.value=round2(Inches,1);
Result=(Feet*30.48)+(Inches*2.54);
document.ABC.heightcms.value=round2(Result,2);
}

function CmsConvert()
{
Cms=document.ABC.heightcms.value;
Feet=parseInt(Cms/30.48);
Inches=(Cms % 30.48)/2.54;
document.ABC.ft.value=round2(Feet,2);
document.ABC.ins.value=round2(Inches,1);
}

function ECmsConvert()
{
Cms=document.ABC.ecms.value*0.45359;
document.ABC.eins.value=round2(Cms,2);
document.ABC.wins.value="XXXX";
document.ABC.wcms.value="XXXX";
}

function EInchConvert()
{
Ins=document.ABC.eins.value*2.54;
document.ABC.ecms.value=round2(Ins,2);
document.ABC.wins.value="XXXX";
document.ABC.wcms.value="XXXX";
}

function WCmsConvert()
{
Cms=document.ABC.wcms.value*0.45359;
document.ABC.wins.value=round2(Cms,2);
document.ABC.eins.value="XXXX";
document.ABC.ecms.value="XXXX";
}

function WInchConvert()
{
Ins=document.ABC.wins.value*2.54;
document.ABC.wcms.value=round2(Ins,2);
document.ABC.eins.value="XXXX";
document.ABC.ecms.value="XXXX";
}

function LbsConvert()
{
Kgs=document.ABC.lbs.value*0.45359;
document.ABC.kgs.value=round2(Kgs,2);
}

function KgsConvert()
{
Lbs=document.ABC.kgs.value*2.2;
document.ABC.lbs.value=round2(Lbs,2);
}

function round2(nbr,digits){
		nbr=nbr.toString()
		if (nbr.indexOf(".")==-1){
			int_part=nbr
			decimal_part=""
			}
		else{
			int_part=nbr.substring(0,nbr.indexOf("."))
			decimal_part=nbr.substring(1+nbr.indexOf("."),2+nbr.indexOf(".")+digits)
			}
		while(decimal_part.length<digits+1)
			decimal_part+="0"
		if (Number(decimal_part.charAt(decimal_part.length-1)<5))
			decimal_part=decimal_part.substring(0,digits)
		else{
			decimal_part=(Number(decimal_part)+10).toString()
			if (decimal_part.length>digits+1){
				int_part=(Number(int_part)+1).toString()
				decimal_part=decimal_part.substring(1,digits+1)
				}
			decimal_part=decimal_part.substring(0,digits)
			}
		if (int_part=="")
			int_part=0;
		if (Number(digits)>0)
			return int_part+"."+decimal_part
		else
			return int_part
		}

function Tape1()
{
	if (document.ABC.Tape[0].checked=true)
		{document.ABC.Tape[1].checked=false;

		document.ABC.ft.value="";
		document.ABC.ins.value="";
		document.ABC.eins.value="";
		document.ABC.wins.value="";
		document.ABC.lbs.value="";

		document.ABC.heightcms.value="XXXX";
		document.ABC.ecms.value="XXXX";
		document.ABC.wcms.value="XXXX";
		document.ABC.kgs.value="XXXX";

		document.ABC.ft.focus();}
}

function Tape2()
{
	if	(document.ABC.Tape[1].checked=true)
		{document.ABC.Tape[0].checked=false;

		document.ABC.heightcms.value="";
		document.ABC.ecms.value="";
		document.ABC.wcms.value="";
		document.ABC.kgs.value="";

		document.ABC.ft.value="XXXX";
		document.ABC.ins.value="XXXX";
		document.ABC.eins.value="XXXX";
		document.ABC.wins.value="XXXX";
		document.ABC.lbs.value="XXXX";

		document.ABC.heightcms.focus();}
}

function ValidateInput()
{		
		if (document.ABC.ft.value.length<1)
			{alert("Please enter your height in feet");
			document.ABC.ft.focus();
			return false;}

		else if (document.ABC.heightcms.value.length<1)
			{alert("Please enter your height in cms");
			document.ABC.heightcms.focus();
			return false;}

		else if (document.ABC.eins.value.length<1)
			{alert("Please enter your elbow width in ins");
			document.ABC.eins.focus();
			return false;}

		else if (document.ABC.ecms.value.length<1)
			{alert("Please enter your elbow width in cms");
			document.ABC.ecms.focus();
			return false;}


		else if (document.ABC.lbs.value.length<1)
			{alert("Please enter your weight in lbs");
			document.ABC.lbs.focus();
			return false;}


		else if (document.ABC.kgs.value.length<1)
			{alert("Please enter your weight in kgs");
			document.ABC.kgs.focus();
			return false;}

		else
		{return true;}
}

