function calc()
{
	var wt = document.form.Weight.value;
	var ht = document.form.ht.value;
	
	var op="pounds"; //document.form.opt1.value;
	
	//SI value
	var h = ht/100;
	var si = Math.round((wt/(h*h))*100)/100;
	//document.form.si.value = si;

	//US value
	var lb = wt*2.2;
	var ic = ht*0.39;
	var us = Math.round((703*(lb/(ic * ic)))*100)/100;
	//document.form.us.value = us;
	
	//UK value
	var uk = Math.round((6.35*si)*100)/100;
	//document.form.uk.value = uk;
	
	//If value is not given for weight
	if(wt=="")
	{
		alert("Enter the value for weight");
		document.form.Weight.focus();
		return false;
	}

	////If weight is less than 10
	//else if(wt<=10)
	//{
	//	document.form.si.value = 0;
	//	document.form.us.value = 0;
	//	document.form.uk.value = 0;
	//	alert("Weight should be greater than 10kgs");
	//}
	
	////If weight is pounds and less than 22lbs
	//else if(op=="pounds" && wt<=22)
	//{
	//	document.form.si.value = 0;
	//	document.form.us.value = 0;
	//	document.form.uk.value = 0;
	//	alert("Weight should be greater than 22lbs");
	//}
	
	////If given height is less than 33cms
	//else if(ht<33)
	//{
	//	document.form.si.value = 0;
	//	document.form.us.value = 0;
	//	document.form.uk.value = 0;
	//	alert("Height should be taller than 33cms");
	//}
	//else if(op=="pounds")
	//{
	//	document.form.si.value=Math.round((si/2.2)*100)/100;
	//	document.form.us.value=Math.round((us/2.2)*100)/100;
	//	document.form.uk.value=Math.round((uk/2.2)*100)/100;
	//}
	si=Math.round((si/2.2)*100)/100;

	var d = "Your category is "
	if(si<15)
	{
		document.form.desc.value= d + "Starvation";
	}
	else if(si>15 && si<=18.5)
	{
		document.form.desc.value= d + "Underweight";
	}
	else if(si>18.5 && si<=25)
	{	
		document.form.desc.value= d + "Normal";	
	}
	else if(si>25 && si<=30)
	{
		document.form.desc.value=d + "Overweight";
	}
	else if(si>30)
	{
		document.form.desc.value=d + "Obese";
	}
	else
	{
		document.form.desc.value="Insufficient Information Please call office.";
	}

}


function conv(aa)//Height conversion
{
	var ft=0, inc=0, ht=0;
	if(aa==1 || aa==2)
	{
		ft = document.form.Height.value;
		inc = document.form.Height1.value;
		var ss = ft*12;
		var tot = ss+parseInt(inc);
       	var val= tot*2.54;
		document.form.ht.value = Math.round(val);
	}

	else{
		ht = document.form.ht.value;
		if(ht!="")
		{
			var cm=Math.round(ht/2.54);
			var div=parseInt(cm/12);
			var md=cm%12;
			document.form.Height.value=div;
			document.form.Height1.value=md;
		}
         }
	
}


function unit()  //Weight conversion
{
	var pp="pounds"; //document.form.opt1.value;
	var ww = document.form.Weight.value;
	
	//Kilogram to pounds
	if(pp=="pounds")	
	{
		document.form.Weight.value = Math.round((ww*2.2)*100)/100;
	}

	//Pounds to kilograms
	else
	{
		document.form.Weight.value=Math.round(ww/2.2);
	}
	document.form.desc.value = "2222";

}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.form.EmailAddress

	if (calc() == false){
		return false
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

	//sleep(10000);
	document.form.submit()
	return true
 }
 
 function sleep(milliSeconds){
	var startTime = new Date().getTime(); // get the current time
	while (new Date().getTime() < startTime + milliSeconds); // hog cpu
 }





