  <?php
 require_once"labClass.php";
  $con=new labClass();

  $row=$con->getRowCount();                                                                //FUNCTION FOR VISITORS OF HOTEL HERE
  $nr=$row->rowCount()+1;
///
?>
 
 <div class="container mt-3">
 
  <h6>PATIENT REGISTRATION FORM:</h6> 
 

  <!--<form action="https://www.w3schools.com/action_page.php" id="pr" name="pr" class="was-validated">-->
    <div class="row">
    <div class="col">
     <div class="form-floating mb-3 mt-3">
        <h6><small></small></h6>
          <input type="text" class="form-control"  id="patientID" value="<?php echo $nr;?>"  name="patientID" disabled="true" required>
       <label for="fname">Patient ID:</label>
       <sup class="text-danger" id="pid"></sup>
       </div>
     </div>
   <div class="col">

    <div class="form-floating mb-3 mt-3"> 
      <input type="text" class="form-control" value="<?php echo $con->vFname($fname);?>" id="fname" style="height:20px;" placeholder="First name" name="fname" required>
       <label for="fname">First Name:</label>
      <sup class="text-danger" id="nf"><?php echo $con->eFname($fname);?></sup>
    </div>
</div>
</div>
<div class="row">
 <div class="col">
       <div class="form-floating mb-3 mt-3"> 
      <input type="text" class="form-control" value="<?php echo $con->vMname($mname);?>" id="mname" placeholder="Middle name" name="mname" required>
       <label for="mname">Middle Name:</label>
      <sup class="text-danger" id="mn"><?php echo $con->eMname($mname);?></sup>
    </div>
 </div>

    <div class="col">
    <div class="form-floating mb-3 mt-3"> 
      <input type="text" class="form-control" value="<?php echo $con->vLname($lname);?>" id="lname" placeholder="Last name" name="lname" required>
       <label for="lname">Last Name:</label>
      <sup class="text-danger" id="ln"> <?php echo $con->eLname($lname);?></sup>
    </div>
</div>
    </div>
   <div class="row">
   <div class="col">

   <div class="form-floating mb-3 mt-3"> 
      <input type="number" class="form-control" value="<?php echo $con->vPhoneno($phoneno);?>" id="phoneno" placeholder="Phone number" name="phoneno" required>
       <label for="phoneno">Phone number:</label>
      <sup class="text-danger" id="p"> <?php echo $con->ePhoneno($phoneno);?></sup>
    </div>
  </div>
 
  
  <div class="col">
       <div class="form-floating mb-3 mt-3"> 
      <input type="text" class="form-control" value="<?php echo $con->vAddress($address);?>" id="address" placeholder="Address" name="address" required>
       <label for="address">Address:</label>
      <sup class="text-danger" id="ad"><?php echo $con->eAddress($address);?> </sup>
    </div>
 </div>
 </div>
  <div class="row">
    <div class="col">
       <div class="form-floating mb-3 mt-3"> 
      <input type="text" class="form-control" value="<?php echo $con->vCountry($country);?>" id="country" placeholder="Citizenship" name="country" required>
       <label for="country">Citizenship:</label>
      <sup class="text-danger" id="c"> <?php echo $con->eCountry($country);?></sup>
    </div> 
  </div>


    <div class="col">
     <div class="form-floating mb-3 mt-3">   
      <input type="date" class="form-control" id="dob" value="<?php echo $con->vDate($dob);?>" placeholder="Date of birth" name="dob" required>
       <label for="dob">Date of birth:</label>
      <sup class="text-danger" id="ob"><?php echo $con->eDate($dob);?> </sup>
    </div>
    </div>
     </div>
 <div class="row">
    <div class="col">
    <div class="form-floating mb-3 mt-3"> 
      <select class="form-select" id="gender" name="gender">
      <option value="<?php echo $con->vGender($gender);?>"><?php echo $con->vGender($gender);?></option>
      <option value="Female">Female</option> 
    </select> 
     <sup class="text-danger" id="g"> <?php echo $con->eGender($gender);?></sup>
    </div>
    </div>
 
  <div class="col">
      <div class="form-floating mb-3 mt-3"> 
      <input type="text" class="form-control" id="occupation" value="<?php echo $con->vOccupation($occupation);?>" width="30%" placeholder="Occupation" name="occupation" required>
       <label for="occupation">Occupation:</label>
      <sup class="text-danger" id="o"><?php echo $con->eOccupation($occupation);?> </sup>
    </div>
   
  
  <input type="submit" class="btn btn-primary" id="submit" name="submit" style="height:60PX;" onclick="saveData();" value="Submit"/>
 
</div>
</div>
 <!--</form>-->
</div>

 </div>
<script>
//$(document).ready(function(){
  
//$("#pr").on('submit',function(e){
 function saveData(){
//e.preventDefault();
var ecc=0;
var patientID =document.getElementById('patientID').value;
$.trim(patientID);
var fname =document.getElementById('fname').value; 
$.trim(fname);
var submit =document.getElementById('submit').value; 

var mname =document.getElementById('mname').value;
$.trim(mname);

var lname =document.getElementById('lname').value;
$.trim(lname);

var address =document.getElementById('address').value;
$.trim(address); 

var country =document.getElementById('country').value;
$.trim(country);
 
var phoneno =document.getElementById('phoneno').value;
$.trim(phoneno);

var occupation =document.getElementById('occupation').value;
$.trim(occupation);

var dob =document.getElementById('dob').value;

var gender =document.getElementById('gender').value;
$.trim(gender); 

var vN =/[\(A-Za-z)]/g; 

var nV =/[a-z\s]/i;
  var j=0,k=0, g=0,i=0;

                                                         //FIRST NAME VALIDATION
if(fname=="")
{
//e.preventDefault();
ecc++;
document.getElementById('nf').innerHTML="First name is required!..";
 } 
 else
 {

      for(i=0;i<fname.length;i++)
       {
         if(!fname[i].match(vN))
          {
             j++;

           }
        }
      
       if(j>0){
        //e.preventDefault();
        ecc++;
       
        document.getElementById('nf').innerHTML="Invalid name"; 


              }
         else{

        document.getElementById('nf').innerHTML="";

              }
   }
 
    j=0, i=0;
                                                                               ///MIDDLE NAME VALIDATION
 

if(mname==""){
//e.preventDefault();
ecc++;
document.getElementById('mn').innerHTML="Middle name is required!..";
 }
 else{

     for(i=0;i<mname.length;i++)
       {
         if(!mname[i].match(vN))
          {
             j++;

           }
        }
      
       if(j>0){
       //e.preventDefault();
      ecc++;
        document.getElementById('mn').innerHTML="Invalid name"; 
              }
         else{
       

        document.getElementById('mn').innerHTML="";

              }
   }
 
    j=0, i=0;
               
 


                                                                            ///LAST NAME VALIDATION



if(lname==""){
 //e.preventDefault();
 ecc++;
  document.getElementById('ln').innerHTML="Last name is required!..";
 
 
              }
 else{

     for(i=0;i<lname.length;i++)
       {
         if(!lname[i].match(vN))
          {
             j++;

           }
        }
      
       if(j>0){
        //e.preventDefault();
        ecc++;
        document.getElementById('ln').innerHTML="Invalid name"; 
              }
         else{

        document.getElementById('ln').innerHTML="";

              }
   }
 
    j=0, i=0;
               


 
                                                                            ///STREET VALIDATION
 

if(address==""){
 //e.preventDefault();
 ecc++;
document.getElementById('ad').innerHTML="Address is required!..";
 

 }
 else{

       for(i=0;i<address.length;i++)
         {
         if(!address[i].match(nV))
          {
             j++;

           }
          }
      if(j>0){
       //e.preventDefault();
       ecc++;
        document.getElementById('ad').innerHTML="Invalid address"; 
              }
         else{
 
        document.getElementById('ad').innerHTML="";

              }
   }
 
    j=0, i=0;
               
 

 

  
                                                                ///COUNTRY VALIDATION

 
if(country==""){
//e.preventDefault();
ecc++;
document.getElementById('c').innerHTML="Country is required!..";
 

               }
 else{

    for(i=0;i<country.length;i++)
       {
         if(!country[i].match(nV))
          {
             j++;

           }
        }
      
       if(j>0){
       // e.preventDefault();
        ecc++;
        document.getElementById('c').innerHTML="Invalid country name!.."; 
              }
         else{ 
        document.getElementById('c').innerHTML="";

              }
   }
 
    j=0, i=0;                                                                        


     ///PHONE NUMBER VALIDATION

 var phn =/[\(0-9)]{12}/;
   
if(phoneno==""){
//e.preventDefault();
ecc++;
document.getElementById('p').innerHTML="Phone is required valid one!..";
 
 
              }
 else{ 
       
       
  

       if(phoneno.length >12 || phoneno.length < 10)
         {
 
        //e.preventDefault();
        ecc++;
        document.getElementById('p').innerHTML="Valid phone number must contain either 10 or 12 digits.."; 
              

         }

         else
         {

        document.getElementById('p').innerHTML="";

        }
   }
 
    j=0, i=0; 
                                                               /// GENGER VALIDATION

if(  dob==""){
//e.preventDefault();
ecc++;
document.getElementById('ob').innerHTML="Gender is required!..";
 

               }
else{

document.getElementById('ob').innerHTML="";
    }
  
 if(  patientID==""){
//e.preventDefault();
ecc++;
document.getElementById('pid').innerHTML="patientID is required!..";
 

               }
else{

document.getElementById('pid').innerHTML="";
    }
  
if(  gender==""){
//e.preventDefault();
ecc++;
document.getElementById('g').innerHTML="patientID is required!..";
 

               }
else{

document.getElementById('g').innerHTML="";
    }
  
                                                           ///OCCUPATION VALIDATION

 

if(occupation=="")
{
//e.preventDefault();
ecc++;
document.getElementById('o').innerHTML="Occupation is required!..";
 
}
 else{

     for(i=0;i<occupation.length;i++)
       {
         if(!occupation[i].match(nV))
          {
             j++;

           }
        }
      
       if(j>0){
        //e.preventDefault();
        ecc++;
        document.getElementById('o').innerHTML="You typed occupation with error"; 
              }
         else{

        document.getElementById('o').innerHTML="";

              }
   }
 
    j=0, i=0; 
                                                                   ///PASSWORD VALIDATION

  
    if(ecc==0)
    {
      //alert("Error found:"+ecc);
        $.post("pregPro.php",
          {submit:submit,patientID:patientID,fname:fname,mname:mname,lname:lname,phoneno:phoneno,address:address,occupation:occupation,country:country,gender:gender,dob:dob},
          function(data){
      $('#outp').html(data).show();

    });
    }


 
//}
//);
//}
}
//);

</script>