//fadein for all the pages

$(document).ready( function(){ $('#portfolio').innerfade({ speed: 1500, timeout: 6000, type: 'sequence', containerheight: '220px' }); } );


function popitup(url) {
	newwindow=window.open(url,'name','height=450,width=730,scrollbars');
	if (window.focus) {newwindow.focus()}
	return false;
}


// To open a popup window
 // 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();
	
	
}

// 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=="" )
	{
	alert('Enter Home Phone No.');
	document.frmAppointment.txtHomePhoneNumber.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
	}	
	
	if (document.frmAppointment.uword2.value=="" )
	{
	alert('Enter the code as it is shown');
	document.frmAppointment.uword2.focus();
	return false;
	}
	return jcap2();
}


// 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;
}
}


// Contact Us form validation
function Contactus() {
	
	firstName = document.cuForm.txtName
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your first name");
		firstName.focus()
		return false		
	}

	mailid = document.cuForm.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
	}

	comments = document.cuForm.txtMessage
	if (comments.value == "" || !isNaN(comments.value))
	{
		alert("Please add your comments");
		comments.focus()
		return false		
	}	
	if (document.cuForm.uword1.value=="" )
	{
	alert('Enter the code as it is shown');
	document.cuForm.uword1.focus();
	return false;
	}
	return jcap1();


	
	
}

// Testimonials form validation
function Testimonials() {

	yourName = document.TestimonialsForm.txtyourname
	if (yourName.value == "")
	{
		alert("Please enter Your Name");
		yourName.focus()
		return false		
	}

	mailid = document.TestimonialsForm.txtyouremail
	if (mailid.value == '')
	{
		alert("Please enter Your 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
	}
	
	testimonial = document.TestimonialsForm.txttestimonial
	if (testimonial.value == "" || !isNaN(testimonial.value))
	{
		alert("Please add Your Testimonial");
		testimonial.focus()
		return false		
	}	
	
	if (document.TestimonialsForm.uword.value=="" )
	{
	alert('Enter the code as it is shown');
	document.TestimonialsForm.uword.focus();
	return false;
	}
	return jcap();
	
	
}

// Testimonials add remove script

function addElement(id,test) {

  var ni = document.getElementById(id);
  var numi = document.getElementById('theValue');
  //alert(ni+" "+numi.value);
  //alert(numi.value);
  //var num = (document.getElementById('theValue').value -1)+ 2;

  if(numi.value<2)
  {
  	  var num = (numi.value -1)+ 2;
      numi.value = num;
  } else {
  	return false;  
  }
  var newdiv = document.createElement('div');
  var divId = 'row'+num;
  
  newdiv.setAttribute('id',divId);

  //alert(test.length);
  for(var i=0;i<test.length;i++){
  	  var input=document.createElement('input');
	  input.setAttribute('type','file');
	  input.setAttribute('class','txtfield');
	  input.setAttribute('className','txtfield');
	  
	  input.setAttribute('name',test[i]+'[]');
	  newdiv.appendChild(input);	
  }
  var a=document.createElement('a');
  
  //a.href='javascript:removeElement(\''+divId+'\');';
  a.href='#';
  a.onclick=function(){removeElement(divId,id);return false;}
 
  a.innerHTML='<input type="button" name="button" value="- Remove Image" class="button"  >';
  newdiv.appendChild(a);
  
  ni.appendChild(newdiv);

}

function removeElement(divNum,fieldsetid) {

  var d = document.getElementById(fieldsetid);
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);  
  document.getElementById('theValue').value--;
  
}
function trim_obj(obj){
obj.value=obj.value.replace(/^[\r\n\s]+|[\r\n\s]+$/g,'');
return(obj)
}


// Testimonials form validation of all subpages
function TestimonialsSub() {

	yourName = document.TestimonialsFormSub.txtyourname
	if (yourName.value == "")
	{
		alert("Please enter Your Name");
		yourName.focus()
		return false		
	}

	mailid = document.TestimonialsFormSub.txtyouremail
	if (mailid.value == '')
	{
		alert("Please enter Your 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
	}
	
	testimonial = document.TestimonialsFormSub.txttestimonial
	if (testimonial.value == "" || !isNaN(testimonial.value))
	{
		alert("Please add Your Testimonial");
		testimonial.focus()
		return false		
	}	
	
	if (document.TestimonialsFormSub.uword3.value=="" )
	{
	alert('Enter the code as it is shown');
	document.TestimonialsFormSub.uword3.focus();
	return false;
	}
	return jcap3();
	
	
}

// Schedule your Complimentary Phone Consultation form validation
function schedule() {
	
	firstName = document.scheduleForm.txtName
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your Name");
		firstName.focus()
		return false		
	}

	mailid = document.scheduleForm.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
	}
	
	phone = document.scheduleForm.txtPhone
	if (phone.value=="" )
	{
	alert('Enter Phone No.');
	phone.focus();
	return false;
	}

	comments = document.scheduleForm.txtMessage
	if (comments.value == "" || !isNaN(comments.value))
	{
		alert("Please enter Message");
		comments.focus()
		return false		
	}
	
	if (document.scheduleForm.uword4.value=="" )
	{
	alert('Enter the code as it is shown');
	document.scheduleForm.uword4.focus();
	return false;
	}
	return jcap4();
	
	
}


// seminar form validation
function seminar() {
	
	firstName = document.seminarForm.txtName
	if (firstName.value == "" || !isNaN(firstName.value))
	{
		alert("Please enter your Name");
		firstName.focus()
		return false		
	}

	mailid = document.seminarForm.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
	}
	
	phone = document.seminarForm.txtPhone
	if (phone.value=="" )
	{
	alert('Enter Phone No.');
	phone.focus();
	return false;
	}

	comments = document.seminarForm.txtMessage
	if (comments.value == "" || !isNaN(comments.value))
	{
		alert("Please enter Message");
		comments.focus()
		return false		
	}
	
	if (document.seminarForm.uword5.value=="" )
	{
	alert('Enter the code as it is shown');
	document.seminarForm.uword5.focus();
	return false;
	}
	return jcap5();
	
	
	
}


function showForm(subSchedule,subSeminar,subTestimonial){

	document.getElementById('subSchedule').style.display=subSchedule;
	document.getElementById('subSeminar').style.display=subSeminar;
	document.getElementById('subTestimonial').style.display=subTestimonial;
}

function showForm2(subTestimonial){

	document.getElementById('subTestimonial').style.display=subTestimonial;
}

 // 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;
}
}

// BMI Calculator

function mod(div,base) 
{
	return Math.round(div - (Math.floor(div/base)*base));
}

function calcBmi() 
{
var w = document.bmi.weight.value * 1;
var HeightFeetInt = document.bmi.htf.value * 1;
var HeightInchesInt = document.bmi.hti.value * 1;
HeightFeetConvert = HeightFeetInt * 12;
h = HeightFeetConvert + HeightInchesInt;
displaybmi = (Math.round((w * 703) / (h * h)));
var rvalue = true;
	if ( (w <= 35) || (w >= 999)  || (h <= 48) || (h >= 120) ) 
	{
		alert ("Invalid data.  Please check and re-enter!");
		rvalue = false;
	}
	
	if (rvalue) 
	{
		if (HeightInchesInt > 11) 
		{
			reminderinches = mod(HeightInchesInt,12);
			document.bmi.hti.value = reminderinches;
			document.bmi.htf.value = HeightFeetInt + 
			((HeightInchesInt - reminderinches)/12);
			document.bmi.answer.value = displaybmi;
		}
		document.bmi.answer.value = displaybmi; 
	}
		return rvalue;
}

// Ask Dr form validation
function AskDr() {

	txtName = document.askDrform.txtName
	if (txtName.value == "" || !isNaN(txtName.value) || txtName.value == "Name")
	{
		alert("Please enter your name");
		txtName.focus()
		return false		
	}

	txtPhone = document.askDrform.txtPhone
	if (txtPhone.value == "" || txtPhone.value == "Phone")
	{
		alert("Please enter your phone number");
		txtPhone.focus()
		return false		
	}

	procedureInterest = document.askDrform.procedureInterest
	if (procedureInterest.options[procedureInterest.selectedIndex].value == "")
	{
		alert("Please select procedure of interest");
	procedureInterest.focus()
	return false		
	}	

	mailid = document.askDrform.txtEmail
	if (mailid.value == '' || mailid.value == "E-mail")
	{
		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
	}

	textComments = document.askDrform.textComments
	if (textComments.value == "" || !isNaN(textComments.value) || textComments.value == "Comments")
	{
		alert("Please add your comments");
		textComments.focus()
		return false		
	}	
	
	if (document.askDrform.uword6.value=="" )
	{
	alert('Enter the code as it is shown');
	document.askDrform.uword6.focus();
	return false;
	}
	return jcap6();
}
