// 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		
	}	
	if (document.fbForm.uword.value=="" )
	{
	alert('Enter the code as it is shown');
	document.fbForm.uword.focus();
	return false;
	}
	return jcap();
	
	
}
//Online Sleep Test
function OnlineSleep() {

	snore = document.frmOnlinesleep.do_u_snore
	if (snore.value == "" || !isNaN(snore.value))
	{
		alert("Please enter your first name");
		snore.focus()
		return false		
	}
	snoring = document.frmOnlinesleep.snoring_is
	if (snoring.value == "" || !isNaN(snoring.value))
	{
		alert("Please enter your first name");
		snoring.focus()
		return false		
	}
	oftensnore = document.frmOnlinesleep.snore_often
	if (oftensnore.value == "" || !isNaN(oftensnore.value))
	{
		alert("Please enter your first name");
		oftensnore.focus()
		return false		
	}
	snorebothered = document.frmOnlinesleep.snore_bothered
	if (snorebothered.value == "" || !isNaN(snorebothered.value))
	{
		alert("Please enter your first name");
		snorebothered.focus()
		return false		
	}
	stopbreathing = document.frmOnlinesleep.stop_breathing
	if (stopbreathing.value == "" || !isNaN(stopbreathing.value))
	{
		alert("Please enter your first name");
		stopbreathing.focus()
		return false		
	}
	tiredfatigued = document.frmOnlinesleep.tired_fatigued
	if (tiredfatigued.value == "" || !isNaN(tiredfatigued.value))
	{
		alert("Please enter your first name");
		tiredfatigued.focus()
		return false		
	}
	walkingtime = document.frmOnlinesleep.walking_time
	if (walkingtime.value == "" || !isNaN(walkingtime.value))
	{
		alert("Please enter your first name");
		walkingtime.focus()
		return false		
	}
	asleepdriving = document.frmOnlinesleep.asleep_driving
	if (asleepdriving.value == "" || !isNaN(asleepdriving.value))
	{
		alert("Please enter your first name");
		asleepdriving.focus()
		return false		
	}
	occuroften = document.frmOnlinesleep.asleep_driving
	if (occuroften.value == "" || !isNaN(occuroften.value))
	{
		alert("Please enter your first name");
		occuroften.focus()
		return false		
	}
	highbp = document.frmOnlinesleep.high_bp
	if (highbp.value == "" || !isNaN(highbp.value))
	{
		alert("Please enter your first name");
		highbp.focus()
		return false		
	}
	bmlobese = document.frmOnlinesleep.obese
	if (bmlobese.value == "" || !isNaN(bmlobese.value))
	{
		alert("Please enter your first name");
		bmlobese.focus()
		return false		
	}
	watchtv = document.frmOnlinesleep.watch_tv
	if (watchtv.value == "" || !isNaN(watchtv.value))
	{
		alert("Please enter your first name");
		watchtv.focus()
		return false		
	}
	sitread = document.frmOnlinesleep.sit_read
	if (sitread.value == "" || !isNaN(sitread.value))
	{
		alert("Please enter your first name");
		sitread.focus()
		return false		
	}
	sittalk = document.frmOnlinesleep.sit_talk
	if (sittalk.value == "" || !isNaN(sittalk.value))
	{
		alert("Please enter your first name");
		sittalk.focus()
		return false		
	}
	afterlunch = document.frmOnlinesleep.after_lunch
	if (afterlunch.value == "" || !isNaN(afterlunch.value))
	{
		alert("Please enter your first name");
		afterlunch.focus()
		return false		
	}
	publicplace = document.frmOnlinesleep.public_place
	if (publicplace.value == "" || !isNaN(publicplace.value))
	{
		alert("Please enter your first name");
		publicplace.focus()
		return false		
	}
	lyingdown = document.frmOnlinesleep.lying_down
	if (lyingdown.value == "" || !isNaN(lyingdown.value))
	{
		alert("Please enter your first name");
		lyingdown.focus()
		return false		
	}
	pass_enger = document.frmOnlinesleep.passenger
	if (pass_enger.value == "" || !isNaN(pass_enger.value))
	{
		alert("Please enter your first name");
		pass_enger.focus()
		return false		
	}
	cartraffic = document.frmOnlinesleep.car_traffic
	if (cartraffic.value == "" || !isNaN(cartraffic.value))
	{
		alert("Please enter your first name");
		cartraffic.focus()
		return false		
	}
	ep_worth = document.frmOnlinesleep.epworth
	if (ep_worth.value == "" || !isNaN(ep_worth.value))
	{
		alert("Please enter your first name");
		ep_worth.focus()
		return false		
	}
	fallasleep = document.frmOnlinesleep.fall_asleep
	if (fallasleep.value == "" || !isNaN(fallasleep.value))
	{
		alert("Please enter your first name");
		fallasleep.focus()
		return false		
	}
	wakenight = document.frmOnlinesleep.wake_night
	if (wakenight.value == "" || !isNaN(wakenight.value))
	{
		alert("Please enter your first name");
		wakenight.focus()
		return false		
	}
	getoutbed = document.frmOnlinesleep.getout_bed
	if (getoutbed.value == "" || !isNaN(getoutbed.value))
	{
		alert("Please enter your first name");
		getoutbed.focus()
		return false		
	}
	sorejaw = document.frmOnlinesleep.sore_jaw
	if (sorejaw.value == "" || !isNaN(sorejaw.value))
	{
		alert("Please enter your first name");
		sorejaw.focus()
		return false		
	}
	comm_ents = document.frmOnlinesleep.comments
	if (comm_ents.value == "" || !isNaN(comm_ents.value))
	{
		alert("Please enter your first name");
		comm_ents.focus()
		return false		
	}
	
}

// Appointments form validation
function Appointment()
{
	var fname = document.frmAppointment.txtFirstName;
	var lname = document.frmAppointment.txtSurname;
	var mymail = document.frmAppointment.txtEmailAddress;
	var message = document.frmAppointment.textComments;
	
	if (message.value==""){
		alert("Please enter your main reason(s) for requesting a sleep study");
		message.focus();
		return false;					
	}
	else if(fname.value==""){
		alert("Please enter your first name");
		fname.focus();
		return false;
	}
	else if(lname.value==""){
		alert("Please enter your last name");
		lname.focus();
		return false;
	}
	else if (mymail.value==""){
		alert('Enter Email Address');
		mymail.focus();
		return false;
	}
	else if (mymail.value.indexOf("@")==-1 || mymail.value.indexOf(".")==-1){
		alert("Please enter a valid email")
		mymail.focus()	   
		return false
	}	
	
return jcap();	
}

// 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		
	}

}	


//Questions
function checkContact()
{
	var myname = document.Form1.txtName;
	var mymail = document.Form1.txtEmail;
	var txtMessage = document.Form1.txtMessage;
	var uword = document.Form1.uword;
	
	if (myname.value=="")
	{
		alert("Please enter your name");
		myname.focus();
		return false;
	}
	else if (mymail.value=="" || mymail.value.indexOf('@')==-1 || mymail.value.indexOf('.')==-1)
	{
		alert("Please enter valid email");
		mymail.focus();
		return false;		
	}
	else if (txtMessage.value=="")
	{
		alert("Please enter your \n"+"questions or suggestions");
		txtMessage.focus();
		return false;					
	}
	else if (uword.value=="" )
	{
	alert('Enter the code as it is shown');
	uword.focus();
	return false;
	}
	return jcap();	
	
	
	
}

