// 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		
	}

	dayPhone = document.fbForm.txtworkphone
	if (isNaN(dayPhone.value))
	{
		alert("Phone number you have entered is invalid");
		dayPhone.focus()
		return false		
	}

	eveningPhone = document.fbForm.txthomephone
	if (isNaN(eveningPhone.value))
	{
		alert("Phone number you have entered is invalid");
		eveningPhone.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;
}
}

//Detect Browser Type.
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
  is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
  is_major = parseInt(is_minor);
}
var isMinNS4 = ((navigator.appName.indexOf("Netscape") >= 0 || agt.indexOf("gecko") >= 0) && is_major >= 4) ? true : false;
var isMinNS6 = (agt.indexOf("gecko") >=0 && is_major >= 5) ? true : false;
var isMinIE4 = (document.all) ? true : false;
var isMinIE5 = (isMinIE4==1 && is_major >= 5) ? true : false;
var isMinIE6 = (isMinIE4 && is_major >= 6) ? true : false;
var isDOM = (document.getElementById) ? true : false;
var isSafari = (agt.indexOf("safari") != -1) ? true : false
var isOpera = (agt.indexOf("opera") != -1) ? true : false
var isIE = (isMinIE4 || isMinIE5 ||  isMinIE6);
var isNN = (isMinNS4 || isMinNS6 );

/**
 Returns a single named DOM element or null if not found.
 @param elementName String _ID_ of element you want to retrieve
 @return element if found or null.
*/
function get(elementName) {
  var ret = null;
  if (isDOM == 1) {
    if(document.getElementById(elementName)) {
      ret = document.getElementById(elementName);
    }
  }  else if (isMinIE4 == 1) {
    if(document.all(elementName)[0]) {
      ret = document.all(elementName)[0];
    }  else {
      ret = document.all(elementName);
    }
  }
  return ret;
}

//random images script

                function getCookie(c_name)



                {



                if (document.cookie.length>0)



                  {



                  c_start=document.cookie.indexOf(c_name + "=")



                  if (c_start!=-1)



                    {



                    c_start=c_start + c_name.length+1



                    c_end=document.cookie.indexOf(";",c_start)



                    if (c_end==-1) c_end=document.cookie.length



                    return unescape(document.cookie.substring(c_start,c_end))



                    }



                  }



                return null



                }







                function randImagesCookie()



                {



                        if(getCookie('name')==null || getCookie('name')=="NaN")



                        {



                                document.cookie="name"+"="+1;



                        }



                        var cimgnum=getCookie('name');



                        if(cimgnum >= 4) {



                                var simgnum=1;



                        } else {



                                var simgnum=parseInt(cimgnum)+1;



                        }



						



						for(i=1; i<=4; i++)



						{



						



	                        var imagename = "index"+simgnum+"_"+i



	                        document.cookie="name"+"="+simgnum;



							var tmp = eval("get('index"+i+"')")

							

	                        var thePicture=tmp;



    	                    var picPath="images/"+imagename+".jpg";

							if(i==0) {

								thePicture.background=picPath;

							} else {

								thePicture.src=picPath;

							}

							



						}



                }