/* function for validating the user id and password */
function validate(theForm)
{
if(theForm.UserId.value == "")
   {
   alert("Please enter your User ID.");
   theForm.UserId.focus();
   return false;
   }
   if(theForm.Password.value == "")
   {
   alert("Please enter your password.");
   theForm.Password.focus();
   return false;
   }
return true;
}

function validatesugg(theform)
{
if (theform.area.selectedIndex==0)
 {
 alert("Please select the area of suggestion.");
 theform.area.focus();
 return false;
 }

if (theform.suggestion.value=="")
 {
 alert("Please enter your suggestion.");
 theform.suggestion.focus();
 theform.suggestion.select();
 return false;
 }

if (theform.Name.value=="")
 {
 alert("Please enter your name.");
 theform.Name.select();
 theform.Name.focus();
 return false;
 }
else
{
for(var i=0;i<theform.Name.value.length;i++)
{
 if(theform.Name.value.charAt(i)<'A' ||  theform.Name.value.charAt(i)>'Z')
{
 if(theform.Name.value.charAt(i)<'a' ||  theform.Name.value.charAt(i)>'z')
{
 if(!((theform.Name.value.charAt(i)=='.') || (theform.Name.value.charAt(i)==' ')))
 {
  alert("Only alphabets, a space and a . are allowed in the name field.");
  theform.Name.select();
  theform.Name.focus();
  return false;
 }
}
}
}
}

if (theform.Address.value=="")
 {
 alert("Please enter your address.");
 theform.Address.select();
 theform.Address.focus();
 return false;
 }

if (theform.mail.value=="")
 {
 alert("Please enter your email address.");
 theform.mail.select();
 theform.mail.focus();
 return false;
 }
else
 {
  if (theform.mail.value.indexOf(".")==-1 || theform.mail.value.indexOf("@")==-1)
  {
  alert("Please enter a valid email address.");
  theform.mail.focus();
  theform.mail.select();
  return false;
  }
 }

if (theform.ccode.value=="")
 {
 alert("Please enter your country code.");
 theform.ccode.select();
 theform.ccode.focus();
 return false;
 }
else
 {
 if (theform.ccode.value!="")
 {
  a = theform.ccode.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
   if(a.charAt(i) < '0' || a.charAt(i) > '9') 
   {
   if(!(a.charAt(i) == ' ' || a.charAt(i) == '(' || a.charAt(i)==')' || a.charAt(i)==',' || a.charAt(i)=='/' || a.charAt(i)=='-' || a.charAt(i)=='+' || a.charAt(i)=='[' || a.charAt(i)==']')) 
    {
     alert("Characters and Special symbols are not allowed in the Country Code field.");
     theform.ccode.select();
     theform.ccode.focus();
     return false;
    }
   }
  }
 }
}

if (theform.acode.value=="")
 {
 alert("Please enter your area code.");
 theform.acode.select();
 theform.acode.focus();
 return false;
 }
else
 {
 if (theform.acode.value!="")
 {
  a = theform.acode.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
   if(a.charAt(i) < '0' || a.charAt(i) > '9') 
   {
   if(!(a.charAt(i) == ' ' || a.charAt(i) == '(' || a.charAt(i)==')' || a.charAt(i)==',' || a.charAt(i)=='/' || a.charAt(i)=='-' || a.charAt(i)=='+' || a.charAt(i)=='[' || a.charAt(i)==']')) 
    {
     alert("Characters and Special symbols are not allowed in the Area Code field.");
     theform.acode.select();
     theform.acode.focus();
     return false;
    }
   }
  }
 }
}

if (theform.telno.value=="")
 {
 alert("Please enter your telephone number.");
 theform.telno.select();
 theform.telno.focus();
 return false;
 }
else
 {
 if (theform.telno.value!="")
 {
  a = theform.telno.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
   if(a.charAt(i) < '0' || a.charAt(i) > '9') 
   {
   if(!(a.charAt(i) == ' ' || a.charAt(i) == '(' || a.charAt(i)==')' || a.charAt(i)==',' || a.charAt(i)=='/' || a.charAt(i)=='-' || a.charAt(i)=='+' || a.charAt(i)=='[' || a.charAt(i)==']')) 
    {
     alert("Characters and Special symbols are not allowed in the Phone field.");
     theform.telno.select();
     theform.telno.focus();
     return false;
    }
   }
  }
 }
}
 
return true;
}

/* function to check if the payment mode is selected or not */
function payment(theform)
{
if(theform.Payment.selectedIndex==0)
{
alert("Please select the mode of payment.");
theform.Payment.focus()
return false;
}
return true;
}

/* function to check if assesment no is not null and property tax or water tax is selected */
function propertywater(theform)
{
if(!theform.R1(0).checked && !theform.R1(1).checked)
{
alert(" You should select atleast one service before submiting.");
theform.R1(0).focus();
return false;
}

if((theform.R1(0).checked || theform.R1(1).checked) && (theform.asno.value==""))
{
alert("Please enter the assessment no.");
theform.asno.focus();
return false;
}
else
{
a = theform.asno.value;
 var i=0;
 for(i=0;i<a.length;i++)
 {
  if(a.charAt(i) < '0' || a.charAt(i) > '9') 
  {
     alert("Characters and Special symbols are not allowed in the field.");
     theform.asno.select();
     theform.asno.focus();
     return false;
    }
   }
}


for(var i=0;i<theform.alfa.value.length;i++)
{
 if(theform.alfa.value.charAt(i)<'A' ||  theform.alfa.value.charAt(i)>'Z')
{
 if(theform.alfa.value.charAt(i)<'a' ||  theform.alfa.value.charAt(i)>'z')
{

if(!((theform.alfa.value.charAt(i)=='0') || (theform.alfa.value.charAt(i)=='1') || (theform.alfa.value.charAt(i)=='2') || (theform.alfa.value.charAt(i)=='3') || (theform.alfa.value.charAt(i)=='4') || (theform.alfa.value.charAt(i)=='5') || (theform.alfa.value.charAt(i)=='6') || (theform.alfa.value.charAt(i)=='7') || (theform.alfa.value.charAt(i)=='8') || (theform.alfa.value.charAt(i)=='9')))
 {
  alert("Only alphabets, a space and '.' are allowed in the  field.");
  theform.alfa.select();
  theform.alfa.focus();
  return false;
 }
}
}
}
return true;
}
/* function to validate the form with hospital and individual */
function loginvalidate(theForm)
{
if(theForm.HI[0].checked==false && theForm.HI[1].checked==false)
{
alert("Choose an Individual/Hospital")
theForm.HI[0].focus();
return false;
}

if(theForm.UserId.value == "")
{
alert("Please enter your User ID.");
theForm.UserId.focus();
return false;
}

if(theForm.Password.value == "")
{
alert("Please enter your password.");
theForm.Password.focus();
return false;
}

return true                  
}

/* validations for birth registration */
function blpob()
{
if(document.birthr.Pob.value.length > 50)
{
 alert("The length of the place of birth (house/hospital address) should be within 50 characters.");
 document.birthr.Pob.select();
 document.birthr.Pob.focus();
}
}

function blmotheroccu()
{
if(document.birthr.MotherOccu.value.length > 50)
{
 alert("The length of mother's occupation should be within 50 characters.");
 document.birthr.MotherOccu.select();
 document.birthr.MotherOccu.focus();
}
}

function blfatheroccu()
{
if(document.birthr.FatherOccu.value.length > 50)
{
 alert("The length of father's occupation should be within 50 characters.");
 document.birthr.FatherOccu.select();
 document.birthr.FatherOccu.focus();
}
}

function blmotheredu()
{
if(document.birthr.MotherEdu.value.length > 50)
{
 alert("The length of mother's level of education should be within 50 characters.");
 document.birthr.MotherEdu.select();
 document.birthr.MotherEdu.focus();
}
}


function blfatheredu()
{
if(document.birthr.FatherEdu.value.length > 50)
{
 alert("The length of father's level of education should be within 50 characters.");
 document.birthr.FatherEdu.select();
 document.birthr.FatherEdu.focus();
}
}


function blmotherstate()
{
if(document.birthr.MotherState.value.length > 50)
{
 alert("The length of mother's state name should be within 50 characters.");
 document.birthr.MotherState.select();
 document.birthr.MotherState.focus();
}
}

function blmotherdist()
{
if(document.birthr.MotherDist.value.length > 50)
{
 alert("The length of mother's district name should be within 50 characters.");
 document.birthr.MotherDist.select();
 document.birthr.MotherDist.focus();
}
}


function blmothertvname()
{
if(document.birthr.Mothertvname.value.length > 50)
{
 alert("The length of mother's town or village name should be within 50 characters.");
 document.birthr.Mothertvname.select();
 document.birthr.Mothertvname.focus();
}
}


function blinfoname()
{
if(document.birthr.IName.value.length > 30)
{
 alert("The length of informant's name should be within 30 characters.");
 document.birthr.IName.select();
 document.birthr.IName.focus();
}
}

function blinforadd()
{
if(document.birthr.IAdd.value.length > 50)
{
 alert("The length of informant's address should be within 50 characters.");
 document.birthr.IAdd.select();
 document.birthr.IAdd.focus();
}
}

function blmothername()
{
if(document.birthr.MotherName.value.length > 50)
{
 alert("The length of mother name should be within 50 characters.");
 document.birthr.MotherName.select();
 document.birthr.MotherName.focus();
}
}

function blmothersurname()
{
if(document.birthr.MotherSurname.value.length > 50)
{
 alert("The length of mother surname should be within 50 characters.");
 document.birthr.MotherSurname.select();
 document.birthr.MotherSurname.focus();
}
}

function blfathername()
{
if(document.birthr.FatherName.value.length > 50)
{
 alert("The length of father name should be within 50 characters.");
 document.birthr.FatherName.select();
 document.birthr.FatherName.focus();
}
}

function blfathersurname()
{
if(document.birthr.FatherSurname.value.length > 50)
{
 alert("The length of father surname should be within 50 characters.");
 document.birthr.FatherSurname.select();
 document.birthr.FatherSurname.focus();
}
}

function blchildname()
{
if(document.birthr.ChildName.value.length > 50)
{
 alert("The length of child name should be within 50 characters.");
 document.birthr.ChildName.select();
 document.birthr.ChildName.focus();
}
}

function blchildsname()
{
if(document.birthr.ChildSname.value.length > 50)
{
 alert("The length of child surname should be within 50 characters.");
 document.birthr.ChildSname.select();
 document.birthr.ChildSname.focus();
}
}

/*function blyear()
{
if(isNaN(document.birthr.Byy.value)==true || document.birthr.Byy.value=="")
{
 alert("Please enter a valid year.");
 document.birthr.Byy.select();
 document.birthr.Byy.focus();
}
else if(document.birthr.Byy.value.length<4 || document.birthr.Byy.value.length>4)
{
 alert("The lenght of the year should be four digits only.");
 document.birthr.Byy.select();
 document.birthr.Byy.focus();
}
}*/


function blmage()
{
if(document.birthr.MotherMarriageAge.value.length>2)
{
 alert("The length of the mother marriage age should not be more than two digits.");
 document.birthr.MotherMarriageAge.select();
 document.birthr.MotherMarriageAge.focus();
}
}

function blmbage()
{
if(document.birthr.MotherBirthAge.value.length>2)
{
 alert("The length of the age of the mother at this time of birth should not be more than two digits.");
 document.birthr.MotherBirthAge.select();
  document.birthr.MotherBirthAge.focus();
}
}

function blcno()
{
if(document.birthr.ChildrenNo.value.length>2)
{
 alert("The length of the number of children should not be more than two digits.");
 document.birthr.ChildrenNo.select();
 document.birthr.ChildrenNo.focus();
}
}

function blbw()
{
if(document.birthr.BirthWt.value.length>4)
{
 alert("The length of the Birth weight should not be more than four digits.");
 document.birthr.BirthWt.select();
 document.birthr.BirthWt.focus();
}
}

function blpd()
{
if(document.birthr.PregDura.value.length>2)
{
 alert("The length of the pregnancy duration should not be more than two digits.");
 document.birthr.PregDura.select();
 document.birthr.PregDura.focus();
}
}

/*individual users validation*/

function birthreport(theForm)
{

var a,i;
var c,c1;

var x=document.birthr.dat.value;

x=new Date(x);

var m = x.getMonth()+1;
var y = x.getYear();
var d = x.getDate();

var dtm = theForm.Bmm.selectedIndex;
var dtd = theForm.Bdd.selectedIndex;
var dty = theForm.Byy.selectedIndex;

var dtyv =theForm.Byy[dty].value;
var dtmv =theForm.Bmm[dtm].value;
var dtdv =theForm.Bdd[dtd].value;


if(theForm.Bdd.selectedIndex == 0)
 {
  alert("Please select the day.");
  theForm.Bdd.focus();
  return false;
 }
 
if(theForm.Bmm.selectedIndex == 0)
 {
  alert("Please select the month.");
  theForm.Bmm.focus();
  return false;
 }

if(theForm.Byy.selectedIndex == 0)
 {
  alert("Please select the year.");
  theForm.Byy.select();  
  theForm.Byy.focus();
  return false;
 }

if(theForm.Byy.selectedIndex == 0)
 {
  alert("Please select the year.");
  theForm.Byy.focus();
  return false;
 }


if((dtm == 2 || dtm == 4 || dtm == 6 || dtm == 9 || dtm == 11) && dtd == 31)
{
alert("Please select the day again as this month does not have 31 days.");
document.birthr.Bdd.focus();
return false;
}

if(dtm == 2 && dtd == 30)
{
alert("Please select the day again as this month does not have 30 days.");
document.birthr.Bdd.focus();
return false;
}

if(dtyv %4 !=0 && dtm == 2 && dtd ==29)
{
alert("This is not a leap year.");

document.birthr.Bdd.focus();
return false;
}


//if the  selected day is above  the curruent day

if(dtyv-y==0 && dtmv-m==0 && d-dtdv<0)
{
alert("Invalid entry.");
document.birthr.Bdd.focus();
return false;
}

//if the  selected month is below  the curruent month 

if(dtyv-y==0 && m-dtmv<0)
{
alert("Invalid entry.");
document.birthr.Bmm.focus();
return false;
}


//if the  selected year is above the curruent year 


if(y-dtyv<0)
{
alert("Invalid entry.");
document.birthr.Byy.focus();
return false;
}

/*if(isNaN(theForm.Byy.value)==true)
{
 alert("Please enter a valid year.");
 theForm.Byy.select();
 theForm.Byy.focus();
 return false;
}


if(theForm.Byy.value.length<4 || theForm.Byy.value.length>4 || theForm.Byy.value<1900)
{
 alert("Please enter a valid year.");
 theForm.Byy.select();
 theForm.Byy.focus();
 return false;
}*/

/*if(isNaN(theForm.ChildSname.value)==false || theForm.ChildSname.value=="")
 {
  alert("Please enter a valid child surname.");
  theForm.ChildSname.select();  
  theForm.ChildSname.focus();
  return false;
 }
else
{
  var a=theForm.ChildSname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the child surname field");
     theForm.ChildSname.select();
     theForm.ChildSname.focus();
     return false;
     }
    }
  }*/

  var a=theForm.ChildSname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the child surname field");
     theForm.ChildSname.select();
     theForm.ChildSname.focus();
     return false;
     }
    }

  var a=theForm.ChildName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the child name field");
     theForm.ChildName.select();
     theForm.ChildName.focus();
     return false;
     }
    }
 
  var a=theForm.FatherSurname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the father surname field");
     theForm.FatherSurname.select();
     theForm.FatherSurname.focus();
     return false;
     }
    }

if(isNaN(theForm.FatherName.value)==false || theForm.FatherName.value=="")
 {
  alert("Please enter a valid father name.");
  theForm.FatherName.select();  
  theForm.FatherName.focus();
  return false;
 }
else
{
  var a=theForm.FatherName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the father name field");
     theForm.FatherName.select();
     theForm.FatherName.focus();
     return false;
     }
    }
  }



/*if(theForm.MotherSurname.value=="" || isNaN(theForm.MotherSurname.value)==false)
 {
  alert("Please enter a valid mother surname.");
  theForm.MotherSurname.select();  
  theForm.MotherSurname.focus();
  return false;
 }
else
{*/

  var a=theForm.MotherSurname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the mother surname field");
     theForm.MotherSurname.select();
     theForm.MotherSurname.focus();
     return false;
     }
    }

  
if(theForm.MotherName.value=="" || isNaN(theForm.MotherName.value)==false)
 {
  alert("Please enter a valid mother name.");
  theForm.MotherName.select();  
  theForm.MotherName.focus();
  return false;
 }
else
{
  var a=theForm.MotherName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the mother name field");
     theForm.MotherName.select();
     theForm.MotherName.focus();
     return false;
     }
    }
  }


if(theForm.Pob.value == "")
 {
  if(theForm.Hr[0].checked == true)
  alert("Please enter hospital name.");
  if(theForm.Hr[1].checked == true)
  alert("Please enter house address.");
  theForm.Pob.select();  
  theForm.Pob.focus();
  return false;
 }

if(isNaN(theForm.IName.value)==false || theForm.IName.value=="")
 {
  alert("Please enter a valid informant's name.");
  theForm.IName.select();  
  theForm.IName.focus();
  return false;
 }
else
{
  var a=theForm.IName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the informant's name field");
     theForm.IName.select();
     theForm.IName.focus();
     return false;
     }
    }
  }

if(theForm.IAdd.value=="")
{
  alert("Please enter a valid informant's address.");
  theForm.IAdd.select();  
  theForm.IAdd.focus();
  return false;
}

if(theForm.Mothertvname=="" || isNaN(theForm.Mothertvname.value)==false)
 {
  if(theForm.Mothertv[0].checked == true)  
  alert("Please enter a valid town name.");
  if(theForm.Mothertv[1].checked == true)
  alert("Please enter a valid village name.");
  theForm.Mothertvname.select();  
  theForm.Mothertvname.focus();
  return false;
 }

if(theForm.MotherDist.value=="" || isNaN(theForm.MotherDist.value)==false)
 {
  alert("Please enter a valid name of the mother's district.");
  theForm.MotherDist.select();  
  theForm.MotherDist.focus();
  return false;
 }

if(theForm.MotherState.value=="" || isNaN(theForm.MotherState.value)==false)
 {
  alert("Please enter a valid name of the mother's state.");
  theForm.MotherState.select();  
  theForm.MotherState.focus();
  return false;
 }


if(theForm.FatherEdu.value=="")
 {
  alert("Please enter a valid father's level of education.");
  theForm.FatherEdu.select();  
  theForm.FatherEdu.focus();
  return false;
 }


if(theForm.MotherEdu.value=="")
 {
  alert("Please enter a valid mother's level of education.");
  theForm.MotherEdu.select();  
  theForm.MotherEdu.focus();
  return false;
 }

if(theForm.FatherOccu.value=="" || isNaN(theForm.FatherOccu.value)==false)
 {
  alert("Please enter a valid father's occupation.");
  theForm.FatherOccu.select();  
  theForm.FatherOccu.focus();
  return false;
 }

if(theForm.MotherOccu.value=="" || isNaN(theForm.MotherOccu.value)==false)
 {
  alert("Please enter a valid mother's occupation.");
  theForm.MotherOccu.select();  
  theForm.MotherOccu.focus();
  return false;
 }

if(theForm.MotherMarriageAge.value=="" || isNaN(theForm.MotherMarriageAge.value)==true || theForm.MotherMarriageAge.value < 13 || theForm.MotherMarriageAge.value > 50)
 {
  alert("Please enter a valid age at the time of mother's marriage (13-50 years).");
  theForm.MotherMarriageAge.select();  
  theForm.MotherMarriageAge.focus();
  return false;
 }


if(theForm.MotherMarriageAge.value.indexOf(".")>=0)
 {
  alert("Please do not enter fractions in the field at the time of mother's marriage.");
  theForm.MotherMarriageAge.select();  
  theForm.MotherMarriageAge.focus();
  return false;
 }


if(theForm.MotherBirthAge.value=="" || isNaN(theForm.MotherBirthAge.value)==true || (theForm.MotherBirthAge.value - theForm.MotherMarriageAge.value) < 0)
 {
  alert("The age of the mother at the time of this birth should be equal to or greater than the age of the mother at the time of marriage.");
  theForm.MotherBirthAge.select();  
  theForm.MotherBirthAge.focus();
  return false;
 }

if(theForm.MotherBirthAge.value>50)
 {
  alert("Please enter a valid age of the mother at the time of this birth (max.50 years).");
  theForm.MotherBirthAge.select();  
  theForm.MotherBirthAge.focus();
  return false;
 }

if(theForm.MotherBirthAge.value.indexOf(".")>=0)
 {
  alert("Please do not enter in fractions in the field of age of the mother at the time of this birth.");
  theForm.MotherBirthAge.select();  
  theForm.MotherBirthAge.focus();
  return false;
 }

if(theForm.ChildrenNo.value=="" || isNaN(theForm.ChildrenNo.value)==true || theForm.ChildrenNo.value < 0 || theForm.ChildrenNo.value >15)
 {
  alert("Please enter a valid number of children born alive to the mother (0-15).");
  theForm.ChildrenNo.select();  
  theForm.ChildrenNo.focus();
  return false;
 }

if(theForm.ChildrenNo.value.indexOf(".")>=0)
 {
  alert("Please do not enter in fractions in the field of number of children born alove to the mother.");
  theForm.ChildrenNo.select();  
  theForm.ChildrenNo.focus();
  return false;
 }


if(theForm.BirthWt.value=="" || isNaN(theForm.BirthWt.value)==true || theForm.BirthWt.value <= 0 || theForm.BirthWt.value > 10)
 {
  alert("Please enter valid birth weight (1-10 kgs.).");
  theForm.BirthWt.select();  
  theForm.BirthWt.focus();
  return false;
 }


if(theForm.PregDura.value=="" || isNaN(theForm.PregDura.value)==true || theForm.PregDura.value <=0 || theForm.PregDura.value >50 )
 {
  alert("Please enter valid duration of pregnancy weeks. (i.e. 50 weeks max.)");
  theForm.PregDura.select();  
  theForm.PregDura.focus();
  return false;
 }

if(theForm.PregDura.value.indexOf(".")>=0)
 {
  alert("Please do not enter in fractions in the field of duration of pregnancy weeks.");
  theForm.PregDura.select();  
  theForm.PregDura.focus();
  return false;
 }

return true;
}


/*Hospital validation*/


function hbirthreport(theForm)

{

var a,i;
var c,c1,ct;

var x=document.birthr.dat.value;

x=new Date(x);

var m = x.getMonth()+1;
var y = x.getYear();
var d = x.getDate();


var dtm = theForm.Bmm.selectedIndex;
var dtd = theForm.Bdd.selectedIndex;
var dty = theForm.Byy.selectedIndex;

var dtyv =theForm.Byy[dty].value;
var dtmv =theForm.Bmm[dtm].value;
var dtdv =theForm.Bdd[dtd].value;

//ct=birthr.dcnt.value;

if(theForm.Bdd.selectedIndex == 0)
 {
  alert("Please select the day.");
  theForm.Bdd.focus();
  return false;
}
 
if(theForm.Bmm.selectedIndex == 0)
 {
  alert("Please select the month.");
  theForm.Bmm.focus();
  return false;
 }

if(theForm.Byy.selectedIndex == 0)
 {
  alert("Please select the year.");
  theForm.Byy.focus();
  return false;
 }

if((dtm == 2 || dtm == 4 || dtm == 6 || dtm == 9 || dtm == 11) && dtd == 31)
{
alert("Please select the day again as this month does not have 31 days.");
document.birthr.Bdd.focus();
return false;
}

if(dtm == 2 && dtd == 30)
{
alert("Please select the day again as this month does not have 30 days.");
document.birthr.Bdd.focus();
return false;
}

if(dtyv %4 !=0 && dtm == 2 && dtd ==29)
{
alert("This is not a leap year.");

document.birthr.Bdd.focus();
return false;
}

//if the  selected day is above  the curruent day

if(dtyv-y==0 && dtmv-m==0 && d-dtdv<0)
{
alert("Invalid entry.");
document.birthr.Bdd.focus();
return false;
}

//if the  selected month is below  the curruent month 

if(dtyv-y==0 && m-dtmv<0)
{
alert("Invalid entry.");
document.birthr.Bmm.focus();
return false;
}


//if the  selected year is above the curruent year 


if(y-dtyv<0)
{
alert("Invalid entry.");
document.birthr.Byy.focus();
return false;
}


/*if(isNaN(theForm.Byy.value)==true)
{
 alert("Please enter a valid year.");
 theForm.Byy.select();
 theForm.Byy.focus();
 return false;
}


if(theForm.Byy.value.length<4 || theForm.Byy.value.length>4 || theForm.Byy.value<1900)
{
 alert("Please enter a valid year.");
 theForm.Byy.select();
 theForm.Byy.focus();
 return false;
}*/


/*if(isNaN(theForm.ChildSname.value)==false || theForm.ChildSname.value=="")
 {
  alert("Please enter a valid child surname.");
  theForm.ChildSname.select();  
  theForm.ChildSname.focus();
  return false;
 }
else
{
  var a=theForm.ChildSname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the child surname field");
     theForm.ChildSname.select();
     theForm.ChildSname.focus();
     return false;
     }
    }
  }*/

  var a=theForm.ChildSname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the child surname field");
     theForm.ChildSname.select();
     theForm.ChildSname.focus();
     return false;
     }
    }
 
  var a=theForm.ChildName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the child name field");
     theForm.ChildName.select();
     theForm.ChildName.focus();
     return false;
     }
    }

/*if(isNaN(theForm.FatherSurname.value)==false || theForm.FatherSurname.value=="")
 {
  alert("Please enter a valid father surname.");
  theForm.FatherSurname.select();  
  theForm.FatherSurname.focus();
  return false;
 }
else
{*/

  var a=theForm.FatherSurname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the father surname field");
     theForm.FatherSurname.select();
     theForm.FatherSurname.focus();
     return false;
     }
    }



if(isNaN(theForm.FatherName.value)==false || theForm.FatherName.value=="")
 {
  alert("Please enter a valid father name.");
  theForm.FatherName.select();  
  theForm.FatherName.focus();
  return false;
 }
else
{
  var a=theForm.FatherName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the father name field");
     theForm.FatherName.select();
     theForm.FatherName.focus();
     return false;
     }
    }
  }

/*if(theForm.MotherSurname.value=="" || isNaN(theForm.MotherSurname.value)==false)
 {
  alert("Please enter a valid mother surname.");
  theForm.MotherSurname.select();  
  theForm.MotherSurname.focus();
  return false;
 }
else
{*/

  var a=theForm.MotherSurname.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the mother surname field");
     theForm.MotherSurname.select();
     theForm.MotherSurname.focus();
     return false;
     }
    }

  
if(theForm.MotherName.value=="" || isNaN(theForm.MotherName.value)==false)
 {
  alert("Please enter a valid mother name.");
  theForm.MotherName.select();  
  theForm.MotherName.focus();
  return false;
 }
else
{
  var a=theForm.MotherName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the mother name field");
     theForm.MotherName.select();
     theForm.MotherName.focus();
     return false;
     }
    }
  }


if(theForm.Mothertvname=="" || isNaN(theForm.Mothertvname.value)==false)
 {
  if(theForm.Mothertv[0].checked == true)  
  alert("Please enter a valid town name.");
  if(theForm.Mothertv[1].checked == true)
  alert("Please enter a valid village name.");
  theForm.Mothertvname.select();  
  theForm.Mothertvname.focus();
  return false;
 }

if(theForm.MotherDist.value=="" || isNaN(theForm.MotherDist.value)==false)
 {
  alert("Please enter a valid name of the mother's district.");
  theForm.MotherDist.select();  
  theForm.MotherDist.focus();
  return false;
 }

if(theForm.MotherState.value=="" || isNaN(theForm.MotherState.value)==false)
 {
  alert("Please enter a valid name of the mother's state.");
  theForm.MotherState.select();  
  theForm.MotherState.focus();
  return false;
 }


if(theForm.FatherEdu.value=="")
 {
  alert("Please enter a valid father's level of education.");
  theForm.FatherEdu.select();  
  theForm.FatherEdu.focus();
  return false;
 }


if(theForm.MotherEdu.value=="")
 {
  alert("Please enter a valid mother's level of education.");
  theForm.MotherEdu.select();  
  theForm.MotherEdu.focus();
  return false;
 }

if(theForm.FatherOccu.value=="" || isNaN(theForm.FatherOccu.value)==false)
 {
  alert("Please enter a valid father's occupation.");
  theForm.FatherOccu.select();  
  theForm.FatherOccu.focus();
  return false;
 }

if(theForm.MotherOccu.value=="" || isNaN(theForm.MotherOccu.value)==false)
 {
  alert("Please enter a valid mother's occupation.");
  theForm.MotherOccu.select();  
  theForm.MotherOccu.focus();
  return false;
 }

if(theForm.MotherMarriageAge.value=="" || isNaN(theForm.MotherMarriageAge.value)==true || theForm.MotherMarriageAge.value < 13 || theForm.MotherMarriageAge.value > 50)
 {
  alert("Please enter a valid age at the time of mother's marriage (13-50 years).");
  theForm.MotherMarriageAge.select();  
  theForm.MotherMarriageAge.focus();
  return false;
 }

if(theForm.MotherMarriageAge.value.indexOf(".")>=0)
 {
  alert("Please do not enter in fractions in the field at the time of mother's marriage.");
  theForm.MotherMarriageAge.select();  
  theForm.MotherMarriageAge.focus();
  return false;
 }


if(theForm.MotherBirthAge.value=="" || isNaN(theForm.MotherBirthAge.value)==true || (theForm.MotherBirthAge.value - theForm.MotherMarriageAge.value) < 0)
 {
  alert("The age of the mother at the time of this birth should be equal to or greater than the age of the mother at the time of marriage.");
  theForm.MotherBirthAge.select();  
  theForm.MotherBirthAge.focus();
  return false;
 }

if(theForm.MotherBirthAge.value>50)
 {
  alert("Please enter a valid age of the mother at the time of this birth (max. 50 years).");
  theForm.MotherBirthAge.select();  
  theForm.MotherBirthAge.focus();
  return false;
 }

if(theForm.MotherBirthAge.value.indexOf(".")>=0)
 {
  alert("Please do not enter in fractions in the filed of  age of the mother at the time of this birth.");
  theForm.MotherBirthAge.select();  
  theForm.MotherBirthAge.focus();
  return false;
 }

if(theForm.ChildrenNo.value=="" || isNaN(theForm.ChildrenNo.value)==true || theForm.ChildrenNo.value < 0 || theForm.ChildrenNo.value > 15)
 {
  alert("Please enter number of children born alive to the mother (0-15).");
  theForm.ChildrenNo.select();  
  theForm.ChildrenNo.focus();
  return false;
 }

if(theForm.ChildrenNo.value.indexOf(".")>=0)
 {
  alert("Please do not enter in fractions in the field of number of children born alive to the mother.");
  theForm.ChildrenNo.select();  
  theForm.ChildrenNo.focus();
  return false;
 }

if(theForm.BirthWt.value=="" || isNaN(theForm.BirthWt.value)==true || theForm.BirthWt.value <= 0 || theForm.BirthWt.value > 10)
 {
  alert("Please enter valid birth weight (1-10 kgs.).");
  theForm.BirthWt.select();  
  theForm.BirthWt.focus();
  return false;
 }

if(theForm.PregDura.value=="" || isNaN(theForm.PregDura.value)==true || theForm.PregDura.value <=0 || theForm.PregDura.value > 50)
 {
  alert("Please enter valid duration of pregnancy weeks. (i.e. 50 weeks max.)");
  theForm.PregDura.select();  
  theForm.PregDura.focus();
  return false;
 }

if(theForm.PregDura.value.indexOf(".")>=0)
 {
  alert("Please do not enter in fractions in the field of duration of pregnancy weeks.");
  theForm.PregDura.select();  
  theForm.PregDura.focus();
  return false;
 }

return true;
}


/*function datevalidate(theForm)
{
ct=theForm.dcnt.value;
if(ct==1)
{

alert("Kindly note that all registrations of birth should be made within 21 days.")

return false;
}
return true;
}*/

//REGISTRATION PAGE VALIDATIONS
function registration(theForm)
{
 if(theForm.FName.value=="")
 {
  alert("Please enter a valid first name.");
  theForm.FName.select();  
  theForm.FName.focus();
  return false;
 }
 else
 {
  var a=theForm.FName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Integers are not allowed in the first name field.");
     theForm.FName.select();
     theForm.FName.focus();
     return false;
     }
    }
  }


 if(theForm.LName.value=="")
 {
  alert("Please enter a valid last name.");
  theForm.LName.select();  
  theForm.LName.focus();
  return false;
 }
 else
 {
  var a=theForm.LName.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Integers are not allowed in the last name field.");
     theForm.LName.select();
     theForm.LName.focus();
     return false;
     }
    }
  }


if(theForm.RDD.selectedIndex == 0)
 {
  alert("Please select the day.");
  theForm.RDD.focus();
  return false;
 }
 
if(theForm.RMM.selectedIndex == 0)
 {
  alert("Please select the month.");
  theForm.RMM.focus();
  return false;
 }

if(theForm.RYY.value=="")
 {
  alert("Please enter a valid year.");
  theForm.RYY.select();  
  theForm.RYY.focus();
  return false;
 }

if(isNaN(theForm.RYY.value)==true)
{
 alert("Please enter a valid year.");
 theForm.RYY.select();
 theForm.RYY.focus();
 return false;
}


if(theForm.RYY.value.length<4 || theForm.RYY.value.length>4 || theForm.RYY.value<1900)
{
 alert("Please enter a valid year.");
 theForm.RYY.select();
 theForm.RYY.focus();
 return false;
}

 if(theForm.TAddress.value=="" || isNaN(theForm.TAddress.value)==false)
 {
  alert("Please enter a valid temporary address name.");
  theForm.TAddress.select();  
  theForm.TAddress.focus();
  return false;
 }

 if(theForm.PAddress.value=="" || isNaN(theForm.PAddress.value)==false)
 {
  alert("Please enter a valid permanent address.");
  theForm.PAddress.select();  
  theForm.PAddress.focus();
  return false;
 }

 if(theForm.RPhone.value =="")
 {
  alert("Please enter a valid phone number.");
  theForm.RPhone.select();
  theForm.RPhone.focus();
  return false;
 }
 else
 {
  a = theForm.RPhone.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
   if(a.charAt(i) < '0'|| a.charAt(i) > '9') 
   {
    if(!(a.charAt(i) == ' ' || a.charAt(i) == '(' || a.charAt(i)==')' || a.charAt(i)==',' || a.charAt(i)=='/' || a.charAt(i)=='-' || a.charAt(i)=='+' || a.charAt(i)=='[' || a.charAt(i)==']')) 
    {
     alert("Characters and Special symbols are not allowed in the Phone field.");
     theForm.RPhone.select();
     theForm.RPhone.focus();
     return false;
    }
   }
  }
 }


if(theForm.emailid.value=="" || theForm.emailid.value.indexOf('@') == -1 || theForm.emailid.value.indexOf('.') == -1)
 {
  alert(" Please enter proper email address.");
  theForm.emailid.select();  
  theForm.emailid.focus();
  return false;
 }
if(theForm.UserId.value == "")
 {
  alert(" Please enter valid userid.");
  theForm.UserId.select();
  theForm.UserId.focus();
  return false;
 }
else
 {
  if(theForm.UserId.value.length > 12)
  {
   alert("The length of the User Id should not exceed 12 alphanumeric characters.");
   theForm.UserId.select();
   theForm.UserId.focus();
   return false;
  }

  var a = theForm.UserId.value;
  var i;
  for(i=0;i< a.length;i++)
  {
   if(a.charAt(i)==" ")
   {
    alert("Please do not leave a blank space.");
    theForm.UserId.select();
    theForm.UserId.focus();
    return false;
   }
  }
 }

if(theForm.password.value == "")
 {
  alert(" Please enter the password.");
  theForm.password.select();
  theForm.password.focus();
  return false;
 }

return true;
}

//REGISTRATION VALIDATIONS FOR HOSPITAL USERS

function reghos(theform)
{
if(theform.Hregname.value=="" || isNaN(theform.Hregname.value)==false)
{
alert("Please enter a valid hospital name.");
theform.Hregname.select();
theform.Hregname.focus();
return false;
}


if(theform.Hregdirector.value=="" || isNaN(theform.Hregdirector.value)==false)
{
alert("Please enter a valid hospital director name.");
theform.Hregdirector.select();
theform.Hregdirector.focus();
return false;
}
else
{
  var a=theform.Hregdirector.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) >='0' && a.charAt(i) <= '9') 
   {
     alert("Numbers are not allowed in the director name field");
     theform.Hregdirector.select();
     theform.Hregdirector.focus();
     return false;
     }
    }
  }


if(theform.Hregaddress.value=="" || isNaN(theform.Hregaddress.value)==false)
{
alert("Please enter a valid hospital address.");
theform.Hregaddress.select();
theform.Hregaddress.focus();
return false;
}


if(theform.Hregphone.value=="")
 {
  alert("Please enter a valid phone number.");
  theform.Hregphone.select();  
  theform.Hregphone.focus();
  return false;
 }
else
{
  var a=theform.Hregphone.value;
  var i=0;
  for(i=0;i<a.length;i++)
  {
    if(a.charAt(i) < '0'|| a.charAt(i) > '9') 
   {
    if(!(a.charAt(i) == ' ' || a.charAt(i) == '(' || a.charAt(i)==')' || a.charAt(i)==',' || a.charAt(i)=='/' || a.charAt(i)=='-' || a.charAt(i)=='+')) 
    {
     alert("Characters and Special symbols are not allowed in the Phone field");
     theform.Hregphone.select();
     theform.Hregphone.focus();
     return false;
     }
    }
   }
  }


if(theform.Hregemail.value=="" || theform.Hregemail.value.lastIndexOf('@')==-1 || theform.Hregemail.value.lastIndexOf('.')==-1)
{
alert("Please enter a valid email id.");
theform.Hregemail.select();
theform.Hregemail.focus();
return false;
}

if(theform.Hregnoofbeds.value=="" || isNaN(theform.Hregnoofbeds.value)==true || theform.Hregnoofbeds.value < 1 || theform.Hregnoofbeds.value.indexOf('.')>=0)
{
alert("Please enter a valid number.");
theform.Hregnoofbeds.select();
theform.Hregnoofbeds.focus();
return false;
}

if(theform.UserId.value=="" || isNaN(theform.UserId.value)==false)
{
alert("Please enter a valid user id.");
theform.UserId.select();
theform.UserId.focus();
return false;
}
else
 {
  var a = theform.UserId.value;
  var i;
  for(i=0;i< a.length;i++)
  {
   if(a.charAt(i)==" ")
   {
    alert("Please do not enter blank spaces.");
    theform.UserId.select();
    theform.UserId.focus();
    return false;
   }
  }
 }

return true;
}

//USERID FOCUS
function useridfocus()
{
document.reg.UserId.blur();
}

function huseridfocus()
{
document.hreg.UserId.blur();
}

function hbeds()
{
document.hreg.Hregnoofbeds.blur();
}
