// 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
	}
}

// Signup form validation
function Signup() {

	describeyou = document.signupForm.cmbDescribeYou
	if (describeyou.options(describeyou.selectedIndex).value == "")
	{
		alert("Please select what describes you best");
		describeyou.focus()
		return false		
	}

	username = document.signupForm.txtUserName
	if (username.value == "" || !isNaN(username.value))
	{
		alert("Please enter your user name");
		username.focus()
		return false		
	}

password = document.signupForm.txtPassword 
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.signupForm.password.value;
var pw2 = document.signupForm.repassword.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password');
password.focus()
return false;
}
// check for minimum length
if (document.signupForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.signupForm.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same password. Please re-enter your password.");
return false;
}
}

	prefix = document.signupForm.cmbPrefix
	if (prefix.options(prefix.selectedIndex).value == "")
	{
		alert("Please select Prefix");
		prefix.focus()
		return false		
	}
	
	firstname = document.signupForm.txtFirstName
	if (firstname.value == "" || !isNaN(firstname.value))
	{
		alert("Please enter your first name");
		firstname.focus()
		return false		
	}
	
	middleinitial = document.signupForm.txtMiddleInitial
	if (middleinitial.value != "" && !isNaN(middleinitial.value))
	{
		alert("Please enter Middle Initials");
		middleinitial.focus()
		return false		
	}	

	lastname = document.signupForm.txtLastName
	if (lastname.value == "" || !isNaN(lastname.value))
	{
		alert("Please enter your Last name");
		lastname.focus()
		return false		
	}

	email = document.signupForm.txtEmail
	if (email.value == '')
	{
		alert("Please enter E-mail Id");
		email.focus()
		return false
	}
	else if (email.value.indexOf("@")==-1 || email.value.indexOf(".")==-1){
		alert("Invalid E-mail ID")
		email.focus()	   
		return false
	}
	
	contact = document.signupForm.txtContactNumber
	if (isNaN(contact.value))
	{
		alert("Contact Number You have entered is wrong");
		contact.focus()
		return false		
	}	

}

// Account infomration form validation
function Account() {

	firstName = document.accountForm.txtFirstName
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your first name");
		firstName.focus()
		return false		
	}
	
	lastName = document.accountForm.txtLastName
	if (lastName.value == "" || !isNaN(lastName.value))
	{
		alert("Please enter your last name");
		lastName.focus()
		return false		
	}
	
	phone = document.accountForm.txtPhone
	if (phone.value == "" || isNaN(phone.value))
	{
		alert("Please enter Phone Number");
		phone.focus()
		return false		
	}	

	email = document.accountForm.txtemail
	if (email.value == '')
	{
		alert("Please enter E-mail Id");
		email.focus()
		return false
	}
	else if (email.value.indexOf("@")==-1 || email.value.indexOf(".")==-1){
		alert("Invalid E-mail ID")
		email.focus()	   
		return false
	}
	
city = document.accountForm.txtCity
	if (city.value == "" || !isNaN(city.value))
	{
		alert("Please enter City Name");
		city.focus()
		return false		
	}
	
state = document.accountForm.txtState
	if (state.value == "" || !isNaN(state.value))
	{
		alert("Please enter State Name");
		state.focus()
		return false		
	}	
	
	zip = document.accountForm.txtZip
	if (zip.value == "" || isNaN(zip.value))
	{
		alert("Please enter Zipcode");
		zip.focus()
		return false		
	}

country = document.accountForm.txtCountry
	if (country.value == "" || !isNaN(country.value))
	{
		alert("Please enter Country Name");
		country.focus()
		return false		
	}	

var stdate = document.accountForm.stdate.value;
var sdate = stdate.split(' ');
sd = sdate[0].split('-')
var d1 = new Date(sd[1],sd[2],sd[0]);
var tdate = new Date()
var today = new Date(tdate.getFullYear(),tdate.getMonth()+1,tdate.getDate())
	
	if(stdate == "")
	{
		alert("Please select your \"Date of Birth\"")
		return false;
	}
	
	gender = document.accountForm.cmbGender
	if (gender.options(gender.selectedIndex).value == "")
	{
		alert("Please select your Gender");
		gender.focus()
		return false		
	}
	
occu = document.accountForm.txtOccupation
	if (occu.value != "" && !isNaN(occu.value))
	{
		alert("Please enter Occupation");
		occu.focus()
		return false		
	}
	
treat = document.accountForm.txtTreatment
	if (treat.value != "" && !isNaN(treat.value))
	{
		alert("Please enter Treatment");
		treat.focus()
		return false		
	}

treatdesc = document.accountForm.txtTreatmentDescription
	if (treatdesc.value != "" && !isNaN(treatdesc.value))
	{
		alert("Please enter Treatment Description");
		treatdesc.focus()
		return false		
	}

}

// Profile form validation
function Profile() {

	firstName = document.profileForm.txtFirstName
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your first name");
		firstName.focus()
		return false		
	}
	
	middleinitial = document.profileForm.txtMiddleInitial
	if (middleinitial.value != "" && !isNaN(middleinitial.value))
	{
		alert("Please enter Middle Initials");
		middleinitial.focus()
		return false		
	}

	lastName = document.profileForm.txtLastName
	if (lastName.value == "" || !isNaN(lastName.value))
	{
		alert("Please enter your last name");
		lastName.focus()
		return false		
	}

var stdate = document.profileForm.stdate.value;
var sdate = stdate.split(' ');
sd = sdate[0].split('-')
var d1 = new Date(sd[1],sd[2],sd[0]);
var tdate = new Date()
var today = new Date(tdate.getFullYear(),tdate.getMonth()+1,tdate.getDate())
	
	if(stdate == "")
	{
		alert("Please select your \"Date of Birth\"")
		return false;
	}
	
	gender = document.profileForm.cmbGender
	if (gender.options(gender.selectedIndex).value == "")
	{
		alert("Please select your Gender");
		gender.focus()
		return false		
	}
	
	phone = document.profileForm.txtPhone
	if (isNaN(phone.value))
	{
		alert("Please enter Phone Number");
		phone.focus()
		return false		
	}
	
occu = document.profileForm.txtOccupation
	if (occu.value != "" && !isNaN(occu.value))
	{
		alert("Please enter Occupation");
		occu.focus()
		return false		
	}
	
treat = document.profileForm.txtTreatment
	if (treat.value != "" && !isNaN(treat.value))
	{
		alert("Please enter Treatment");
		treat.focus()
		return false		
	}

treatdesc = document.profileForm.txtTreatmentDescription
	if (treatdesc.value != "" && !isNaN(treatdesc.value))
	{
		alert("Please enter Treatment Description");
		treatdesc.focus()
		return false		
	}

city = document.profileForm.txtCity
	if (city.value != "" && !isNaN(city.value))
	{
		alert("Please enter City Name");
		city.focus()
		return false		
	}
	
state = document.profileForm.txtState
	if (state.value != "" && !isNaN(state.value))
	{
		alert("Please enter State Name");
		state.focus()
		return false		
	}	
	
	zip = document.profileForm.txtZip
	if (isNaN(zip.value))
	{
		alert("Please enter Zipcode");
		zip.focus()
		return false		
	}

country = document.profileForm.txtCountry
	if (country.value != "" && !isNaN(country.value))
	{
		alert("Please enter Country Name");
		country.focus()
		return false		
	}

}

// Story form validation
function Story() {

	title = document.storyForm.txtTitle
	if (title.value == "" || !isNaN(title.value))
	{
		alert("Please enter your story title");
		title.focus()
		return false		
	}
	
	desc = document.storyForm.txtComments
	if (desc.value == "" || !isNaN(desc.value))
	{
		alert("Please enter your story description");
		desc.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;
}
}

// Medical Professionals form validation
function OnlineOrder() {

	firstName = document.mpform.txtFirstname
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your Name");
		firstName.focus()
		return false		
	}

if (document.mpform.txtproviderno.value=="" || isNaN(document.mpform.txtproviderno.value))
	{
	alert('Please enter Provider No.');
	document.mpform.txtproviderno.focus();
	return false;
	}

	TelePhone = document.mpform.txtTelePhoneNumber
	if (isNaN(TelePhone.value))
	{
		alert("Phone number you have entered is invalid");
		TelePhone.focus()
		return false		
	}
	
	mailid = document.mpform.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
	}
	
if (document.mpform.txtkits.value=="" || isNaN(document.mpform.txtkits.value))
	{
	alert('Please enter No. of Kits');
	document.mpform.txtkits.focus();
	return false;
	}

if (document.mpform.txtkits1.value=="" || isNaN(document.mpform.txtkits1.value))
	{
	alert('Please enter No. of Kits');
	document.mpform.txtkits1.focus();
	return false;
	}
	}
	
	// Patients form validation
function PatientsOnlineOrder() {

	firstName = document.patientform.txtFirstname
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your Name");
		firstName.focus()
		return false		
	}

if (document.patientform.txtdob.value=="")
	{
	alert('Please enter your Date of Birth');
	document.patientform.txtdob.focus();
	return false;
	}
	
	TelePhone = document.patientform.txtTelePhoneNumber
	
	if (isNaN(TelePhone.value))
	{
		alert("Phone number you have entered is invalid");
		TelePhone.focus()
		return false		
	}

	mailid = document.patientform.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
	}
	
if (!document.patientform.ubh.checked && !document.patientform.libt.checked)
	{
	alert('Please select atleast one Breath Test');
	return false;
	}

if (document.patientform.txtdoctor.value=="")
	{
		alert('Please enter Referring Doctor');
		document.patientform.txtdoctor.focus();
		return false;
	}
}
	
// Referrals form validation
function ReferralsOnlineOrder() {

	firstName = document.referralsform.txtFirstname
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter Doctors Name");
		firstName.focus()
		return false		
	}

if (document.referralsform.txtproviderno.value=="" || isNaN(document.referralsform.txtproviderno.value))
	{
	alert('Please enter Provider No.');
	document.referralsform.txtproviderno.focus();
	return false;
	}

TelePhone = document.referralsform.txtTelePhoneNumber
	if (isNaN(TelePhone.value))
	{
		alert("Phone number you have entered is invalid");
		TelePhone.focus()
		return false		
	}

	mailid = document.referralsform.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
	}
	
	patientsName = document.referralsform.txtpatientname
	if (patientsName.value == "" || !isNaN(patientsName.value))
	{
		alert("Please enter Patients Name");
		patientsName.focus()
		return false		
	}
	
	Medicare = document.referralsform.txtmedicare
	if (isNaN(Medicare.value))
	{
		alert("Medicare number you have entered is invalid");
		Medicare.focus()
		return false		
	}

}	
function Login()
 {
 

	username = document.loginform.login
	if (username.value == "" || !isNaN(username.value))
	{
		alert("Please enter your username");
		username.focus()
		return false		
	}
	
	password = document.loginform.password
	if (password.value == "" || !isNaN(password.value))
	{
		alert("Please enter your story password");
		password.focus()
		return false		
	}	
		window.location="Pages/LogIn.aspx";

}

