// function to validate email

function validateEmail(tempemail){
  if ((tempemail.indexOf('@')) == -1)
  return false;
 
  emailsplit=tempemail.split('@');

  if (emailsplit.length!=2)
  return false;

  if (emailsplit[0]=='' || emailsplit[0]==' ')
  return false;

  if (emailsplit[1]=='' || emailsplit[1]==' ')
  return false;

  dotsplit=emailsplit[1].split('.');

  if (dotsplit.length <2)
  return false;

  for (i=0;i<dotsplit.length;i++){
   if (dotsplit[i] =='' || dotsplit[i]==' ')
    return false;
  }
  return true;
 }


yearMonths = new Array("31","28","31","30","31","30","31","31","30","31","30","31");

// function to validate date

function validateDate(tempday,tempmonth,tempyear){
  intDay= parseInt(tempday);
  intMonth=parseInt(tempmonth);

   if (tempyear.length == 2)
     tempyear = '20'+tempyear;

   intYear=parseInt(tempyear);


  if (intMonth == 2){
   if (intDay <= 28)
    return true;
    
   if (intDay > 29)
    return false;
   
   if ((intYear%4)!=0)
    return false;
   
 }else{
   if (parseInt(yearMonths[intMonth-1]) < intDay)
   return false;
  }
 return true;
 }


// function to compare the date passed by parameter to system date

function compareDateToToday(tempday,tempmonth,tempyear){
  today = new Date();
  
  intDay= parseInt(tempday);
  intMonth=parseInt(tempmonth) - 1;

    if (tempyear.length == 2)
     tempyear = '20'+tempyear;

  intYear=parseInt(tempyear);

  testdate=new Date();

  testdate.setFullYear(intYear);
  testdate.setMonth(intMonth);
  testdate.setDate(intDay);

  if (today.getTime() > testdate.getTime())
   return false;

 return true;
}

//function to compare 2 dates

function compareFromToDate(fromday,frommonth,fromyear,today,tomonth,toyear){
  intFromDay=parseInt(fromday);
  intToDay=parseInt(today);

  intFromMonth=parseInt(frommonth);
  intToMonth=parseInt(tomonth);

  if (fromyear.length == 2)
   fromyear='20'+fromyear;

  if(toyear.length == 2)
   toyear = '20'+toyear;

   intFromYear=parseInt(fromyear);
   intToYear=parseInt(toyear);

   fromDate = new Date();
   toDate = new Date();

   fromDate.setFullYear(intFromYear);
   toDate.setFullYear(intToYear);

   fromDate.setMonth(intFromMonth);
   toDate.setMonth(intToMonth);

   fromDate.setDate(intFromDay);
   toDate.setDate(intToDay);

   if (fromDate.getTime() > toDate.getTime())
    return false;

    return true;


 }

// function for validation of contact form

function validateContact(form){
 if (form.name.value=='' || form.name.value==' '){
  alert('Please let us know your name');
  return false;
 }

 if (form.country.value=='' || form.country.value==' '){
  alert('It would be nice to know your country');
  return false;
 }
 
 if (form.phone.value=='' || form.phone.value==' '){
  alert('We require to know your contact numbers.');
  return false;
 }

 if (form.email.value=='' || form.email.value==' '){
  alert('Please let us know your email');
  return false;
 }

 if (!validateEmail(form.email.value)){
  alert('We need your valid email address');
  return false;
 }

 if (form.findus.value=='' || form.findus.value==' '){
  alert('Please tell us how you reached the website');
  return false;
 }
 
 
  if (form.whyyoga.value=='' || form.whyyoga.value==' '){
  alert('Please tell us why you want to do yoga');
  return false;
 }
 
 
 if ((form.ifyoga[0].checked) && (form.knowyoga.value=='' || form.knowyoga.value==' ')){
  alert('Please write your previous experience in Yoga practice');
  return false;
 }
 
  if ((form.ifteacher[0].checked) && (form.isteacher.value=='' || form.isteacher.value==' ')){
  alert('Please give details of your teaching experience and expertise');
  return false;
 }
 
 
return true;
}

