// To open a popup window
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// Newsletter Subscription Form
function Newsletter() {
  	mailid = document.newsMail.email
	if (mailid.value == '')
	{
		alert("Please enter E-mail Id");
		mailid.focus()
		return false
	}
	else if (mailid.value.indexOf("@")==-1 || mailid.value.indexOf(".")==-1){
		alert("Invalid E-mail ID")
		mailid.focus()	   
		return false
	}
}

// Feedback form validation
function Feedback() {

	firstName = document.fbForm.txtFirstname
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your first name");
		firstName.focus()
		return false		
	}

	lastName = document.fbForm.txtlastname
	if (lastName.value == "" || !isNaN(lastName.value))
	{
		alert("Please enter your last name");
		lastName.focus()
		return false		
	}

	mailid = document.fbForm.txtemail
	if (mailid.value == '')
	{
		alert("Please enter E-mail Id");
		mailid.focus()
		return false
	}
	else if (mailid.value.indexOf("@")==-1 || mailid.value.indexOf(".")==-1){
		alert("Invalid E-mail ID")
		mailid.focus()	   
		return false
	}

	age = document.fbForm.cmbAgeRange
	if (age.options(age.selectedIndex).value == "")
	{
		alert("Please select your age group");
		age.focus()
		return false		
	}	

	sportsAct = document.fbForm.txtsports
	if (sportsAct.value != "" && !isNaN(sportsAct.value))
	{
		alert("Please enter Sports Activities");
		sportsAct.focus()
		return false		
	}

	comments = document.fbForm.txtComments
	if (comments.value == "" || !isNaN(comments.value))
	{
		alert("Please add your comments");
		comments.focus()
		return false		
	}	
}

// Appointments form validation
function Appointment()
{
if (document.frmAppointment.txtFirstName.value=="" || !isNaN(document.frmAppointment.txtFirstName.value))
	{
	alert('Enter FirstName');
	document.frmAppointment.txtFirstName.focus();
	return false;
	}
if (document.frmAppointment.txtSurname.value=="" || !isNaN(document.frmAppointment.txtSurname.value))
	{
	alert('Enter Surname');
	document.frmAppointment.txtSurname.focus();
	return false;
	}
if (document.frmAppointment.txtHomePhoneNumber.value=="" || isNaN(document.frmAppointment.txtHomePhoneNumber.value))
	{
	alert('Enter Home Phone No.');
	document.frmAppointment.txtHomePhoneNumber.focus();
	return false;
	}
if (document.frmAppointment.txtBusinessPhoneNumber.value!="" && isNaN(document.frmAppointment.txtBusinessPhoneNumber.value))
	{
	alert('Enter a valid Business Phone Number');
	document.frmAppointment.txtBusinessPhoneNumber.focus();
	return false;
	}
	
if (document.frmAppointment.txtMobileNumber.value!="" && isNaN(document.frmAppointment.txtMobileNumber.value))
	{
	alert('Mobile number you have entered is invalid');
	document.frmAppointment.txtMobileNumber.focus();
	return false;
	}
	
if (document.frmAppointment.txtEmailAddress.value=="")
	{
	alert('Enter Email Address');
	document.frmAppointment.txtEmailAddress.focus();
	return false;
	}
	else if (document.frmAppointment.txtEmailAddress.value.indexOf("@")==-1 || document.frmAppointment.txtEmailAddress.value.indexOf(".")==-1){
		alert("Invalid E-mail ID")
		document.frmAppointment.txtEmailAddress.focus()	   
		return false
	}	
}

// BMI Calculator
function converttometers(ht)
{
    return (ht/100);
}
function calculatebmi(ht,wt)
{
return (wt/Math.pow(ht,2));
}
function btnCalcbmi()
{
if (document.frmbmi.txtheight.value != '')
{
	var ht=converttometers(document.frmbmi.txtheight.value);
	var wt=document.frmbmi.txtweight.value;
	var bmi=Math.round(calculatebmi(ht,wt));
	document.frmbmi.txtbmi.value=parseInt(bmi);
	
	if (parseInt(bmi) <19) 
document.frmbmi.comment.value = "Underweight";
if (parseInt(bmi) >=19 && parseInt(bmi) <=25) 
document.frmbmi.comment.value = "Desirable";
if (parseInt(bmi) >=26 && parseInt(bmi) <=29) 
document.frmbmi.comment.value = "Prone to health risks";
if (parseInt(bmi) >=30 && parseInt(bmi) <=40) 
document.frmbmi.comment.value = "Obese";
if (parseInt(bmi) >40) 
document.frmbmi.comment.value = "Extremely obese";
	
}
else 
{
	alert("Please enter your weight and height");
	return false;
}
}


/*
commented on 08/06/11- backup
function purchaseForm()
{
	prodId=document.payPalForm.prodId;
	zones=document.payPalForm.zones;
	quantity=document.payPalForm.quantity;
	grandTotal=document.payPalForm.grandTotal;
	unitPrice=document.payPalForm.amount;
	var prodPrice=0,postagePrice=0;
	
	flag=false;
	
	for(i=0;i<prodId.length;i++)
	{
		if(prodId[i].checked)
		{
			flag=true;
		}
	}
	
	if(!flag)
	{
		alert("Please select a product");
		return false;
	}
	
	if(prodId[0].checked)
	{
		document.payPalForm.item_name.value="The LAP-BAND™ Solution book";
		
		prodPrice=parseFloat(24.95);
		if(zones.options[zones.selectedIndex].value==0)
		{
			alert("Please select a zone")
			zones.focus();
			return false;
		}
		
		postagePrice=zones.options[zones.selectedIndex].value;
		
	} 
	else if(prodId[1].checked)
	{
		document.payPalForm.item_name.value="The LAP-BAND™ Solution book (box with 44 copies)";
		
		prodPrice=parseFloat(12.00)*44;
		postagePrice = 20.00
	}
	else if(prodId[2].checked)
	{
		document.payPalForm.item_name.value="The LAP-BAND™ Solution book (box with 36 copies)";
		
		prodPrice=parseFloat(12.00)*36;
		postagePrice = 20.00
	}
	

	if(quantity.value=="" || quantity.value<=0)
	{
		alert("Quantity cannot be less than 1")
		quantity.focus();
		return false;
	}
	
	calculateTotal()
}

function calculateTotal()
{
	prodId=document.payPalForm.prodId;
	zones=document.payPalForm.zones;
	quantity=document.payPalForm.quantity;
	grandTotal=document.payPalForm.grandTotal;
	unitPrice=document.payPalForm.amount;
	var prodPrice,postagePrice;
	
	if(prodId[0].checked)
	{
		prodPrice=parseFloat(24.95);
		postagePrice=zones.options[zones.selectedIndex].value;
		
	} 
	else if(prodId[1].checked)
	{
		prodPrice=parseFloat(12.00)*44;
		postagePrice = 20.00
	}
	else if(prodId[2].checked)
	{
		prodPrice=parseFloat(12.00)*36;
		postagePrice = 20.00
	}
	
	totalPrice = (parseFloat(prodPrice) * parseInt(quantity.value)) + parseFloat(postagePrice) * parseInt(quantity.value)
	
	grandTotal.value = r2(totalPrice)
	
	unitPrice.value = r2(parseFloat(prodPrice) + parseFloat(postagePrice));
}

function r2(n) { 

  ans = n * 1000 
  ans = Math.round(ans /10) + "" 
  while (ans.length < 3) {ans = "0" + ans} 
  len = ans.length 
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ans 
} 
*/

function purchaseForm()
{
	prodId=document.payPalForm.prodId;

	if(prodId[0].checked)
		zones=document.payPalForm.zones1;
	
	if(prodId[1].checked)
		zones=document.payPalForm.zones2;
		
	quantity=document.payPalForm.quantity;
	grandTotal=document.payPalForm.grandTotal;
	unitPrice=document.payPalForm.amount;
	var prodPrice=0,postagePrice=0;
	
	flag=false;
	
	for(i=0;i<prodId.length;i++)
	{
		if(prodId[i].checked)
		{
			flag=true;
		}
	}
	
	if(!flag)
	{
		alert("Please select a product");
		return false;
	}
	
	if(prodId[0].checked)
	{
		document.payPalForm.item_name.value="The LAP-BAND™ Solution book";
		
		prodPrice=parseFloat(29.95);
		if(zones.options[zones.selectedIndex].value==0)
		{
			alert("Please select a zone")
			zones.focus();
			return false;
		}
		
		postagePrice=zones.options[zones.selectedIndex].value;
		
	} 
	else if(prodId[1].checked)
	{
		document.payPalForm.item_name.value="The LAP-BAND™ Solution book (box with 32 copies)";
		
		prodPrice=parseFloat(15.00)*32;
		if(zones.options[zones.selectedIndex].value==0)
		{
			alert("Please select a zone")
			zones.focus();
			return false;
		}
		
		postagePrice=zones.options[zones.selectedIndex].value;
	}
	

	if(quantity.value=="" || quantity.value<=0)
	{
		alert("Quantity cannot be less than 1")
		quantity.focus();
		return false;
	}
	
	calculateTotal()
}

function calculateTotal()
{
	prodId=document.payPalForm.prodId;
			
	if(prodId[0].checked)
		zones=document.payPalForm.zones1;
	
	if(prodId[1].checked)
		zones=document.payPalForm.zones2;
		
	quantity=document.payPalForm.quantity;
	grandTotal=document.payPalForm.grandTotal;
	unitPrice=document.payPalForm.amount;
	var prodPrice,postagePrice;
	
	if(prodId[0].checked)
	{
		prodPrice=parseFloat(29.95);
		prodPrice=prodPrice+(prodPrice*.1);
		postagePrice=zones.options[zones.selectedIndex].value;
		
	} 
	else if(prodId[1].checked)
	{
		prodPrice=(parseFloat(15.00)*32);
		prodPrice=prodPrice+(prodPrice*.1);
		postagePrice =zones.options[zones.selectedIndex].value;
	}
	
	totalPrice = (parseFloat(prodPrice) * parseInt(quantity.value)) + parseFloat(postagePrice) * parseInt(quantity.value)
	
	grandTotal.value = r2(totalPrice)
	
	unitPrice.value = r2(parseFloat(prodPrice) + parseFloat(postagePrice));
}

function r2(n) { 

  ans = n * 1000 
  ans = Math.round(ans /10) + "" 
  while (ans.length < 3) {ans = "0" + ans} 
  len = ans.length 
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ans 
} 
