
<div class="breadcrumb">
    <h1>Dummy PMS Data</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Dummy PMS Data</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
    <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <form action="" id='frm-user' method="post" enctype="multipart/form-data">
                    <div class="row">
                      <div class="col-md-6 form-group mb-3">
                            <label for="select_data">Select Data </label>
                            <select name="select_data" id="select_data" class="form-control" required="true">
                              <option value="">Select Data</option>
                              <option value="1">Guranoter</option>
                              <option value="2">Patient</option>
                              <option value="3">Appoinment</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_select_data"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3">
                            <label for="clinic_data">Select Clinic </label>
                           <select class="form-control" id="clinic_id" name="clinic_id" required="true">
                            <option value="">Select Client</option>
                            <?php if($allClinic && count($allClinic) > 0){ foreach($allClinic as $clinic){ ?>
                            <option value="<?php echo $clinic->clinic_id; ?>" ><?php echo $clinic->clinic_name; ?></option>
                            <?php } } ?>
                           </select>
                            <div class="invalid-tooltip" id="msg_clinic_data"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" style="display: none;" id="div_search_patient">
                            <label for="search_patient">Search patient </label>
                            <input type="text" class="form-control" id="search_patient" name="search_patient" placeholder="Search patient" >
                            <div class="invalid-tooltip" id="msg_search_patient"></div>
                      </div>
                      <div class="col-md-12">
                      <div class="row" style="display: none;" id="div_search_patient_data">
                      
                            <span id="search_patient_data"></span>
                            <div class="invalid-tooltip" id="msg_search_patient_data"></div>
                        
                      </div>
                    </div>

                      
                      <div class="col-md-6 form-group mb-3" style="display: none;" id="div_manual_patient">
                            <label for="manual_patient_id">Patient Id </label>
                            <input type="text" class="form-control" id="manual_patient_id" name="manual_patient_id" placeholder="Enter patient id" >
                            <div class="invalid-tooltip" id="msg_manual_patient_id"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" style="display: none;" id="div_manual_apppatient_id">
                            <label for="manual_apppatient_id">Patient Id </label><br/>
                            <select class="form-control" id="manual_apppatient_id" name="manual_apppatient_id">
                            <option value="">Select Patient</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_manual_apppatient_id"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3">
                            <label for="manual_flag">Flag </label>
                            <select name="manual_flag" id="manual_flag" class="form-control" required="true">
                              <option value="">Select Flag</option>
                              <option value="Added">Added</option>
                              <option value="updated">updated</option>
                              <option value="Deleted">Deleted</option>
                              <option value="Completed">Completed</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_manual_flag"></div>
                      </div>
                      <div class="col-md-12" >
                        <div class="row" style="display: none;" id="div_appoinment_data">
                        
                              <span id="appoinment_data"></span>
                              <div class="invalid-tooltip" id="msg_appoinment_data"></div>
                          
                        </div>
                      </div>
                      <div class="col-md-6 form-group mb-3" id="div_manual_guarantor_id">
                            <label for="manual_guarantor_id">Guarantor Id </label>
                            <input type="text" class="form-control" id="manual_guarantor_id" name="manual_guarantor_id"  placeholder="Enter guarantor id" > 
                            <div class="invalid-tooltip" id="msg_manual_guarantor_id"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" style="display: none" id="div_manual_selectguarantor_id">
                            <label for="manual_selectguarantor_id">Guarantor Id </label>
                            <select class="form-control" id="manual_selectguarantor_id" name="manual_selectguarantor_id">
                            <option value="">Select Guarantor</option>
                            </select>

                            <div class="invalid-tooltip" id="msg_manual_selectguarantor_id"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" id="div_manual_guarantor_patient_id" style="display:none;">
                            <label for="manual_guarantor_patient_id">Patient Id </label>
                            <!-- <input type="text" class="form-control" id="manual_guarantor_patient_id" name="manual_guarantor_patient_id"  placeholder="Enter patient id" >  -->
                            <select class="form-control" id="manual_guarantor_patient_id" name="manual_guarantor_patient_id">
                            <option value="">Select Patient</option>
                            </select>

                            <div class="invalid-tooltip" id="msg_manual_guarantor_patient_id"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" style="display: none" id="div_manual_patientguarantor_id">
                            <label for="manual_patientguarantor_id">Guarantor Id </label>
                            <select class="form-control" id="manual_patientguarantor_id" name="manual_patientguarantor_id">
                            <option value="">Select Guarantor</option>
                            </select>

                            <div class="invalid-tooltip" id="msg_manual_patientguarantor_id"></div>
                      </div>

                      <div class="col-md-6 form-group mb-3" style="display: none" id="div_manual_old_patientguarantor_id">
                            <label for="manual_old_patientguarantor_id">Old Guarantor Id </label>
                            <select class="form-control" id="manual_old_patientguarantor_id" name="manual_old_patientguarantor_id">
                            <option value="">Select Guarantor</option>
                            </select>

                            <div class="invalid-tooltip" id="msg_manual_old_patientguarantor_id"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" id="div_appointment_sr_no" style="display: none;">
                            <label for="appointment_sr_no">Appointment sr no</label>
                            <input type="text" class="form-control" id="appointment_sr_no" name="appointment_sr_no"  placeholder="Enter appointment sr no">
                            <div class="invalid-tooltip" id="msg_appointment_sr_no"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" id="div_provider_id" style="display: none;">
                            <label for="provider_id">Provider Id</label>
                            <select class="form-control" id="provider_id" name="provider_id">
                            <option value="">Select Provider</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_provider_id"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" id="div_app_date" style="display: none;">
                            <label for="app_date">Date</label>
                            <input type="date" class="form-control" id="app_date" name="app_date"  placeholder="Enter Date">
                            <div class="invalid-tooltip" id="msg_app_date"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" id="div_app_time" style="display: none;">
                            <label for="app_time">Time</label>
                            <input type="time" class="form-control" id="app_time" name="app_time"  placeholder="Enter Time">
                            <div class="invalid-tooltip" id="msg_app_time"></div>
                      </div>
                      <div class="col-md-6 form-group mb-3" id="div_app_length" style="display: none;">
                            <label for="app_length">Length</label>
                            <input type="text" class="form-control" id="app_length" name="app_length"  placeholder="Enter Length">
                            <div class="invalid-tooltip" id="msg_app_length"></div>
                      </div>

                      <div class="col-md-6 form-group mb-3" id="div_app_amount" style="display: none;">
                            <label for="app_amount">Amount</label>
                            <input type="text" class="form-control" id="app_amount" name="app_amount"  placeholder="Enter Amount">
                            <div class="invalid-tooltip" id="msg_app_amount"></div>
                      </div>

                      <div class="col-md-6 form-group mb-3" id="div_app_status" style="display: none;">
                            <label for="app_status">Status</label>
                            <!-- <input type="text" class="form-control" id="app_status" name="app_status"  placeholder="Enter Status"> -->
                            <select class="form-control" id="app_status" name="app_status">
                            <option value="">Select Status</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_app_status"></div>
                      </div>
                      
                      <div class="col-md-6 form-group mb-3" id="div_manual_guarantor_fname">
                            <label for="manual_guarantor_fname">First name </label>
                            <input type="text" class="form-control" id="manual_guarantor_fname" name="manual_guarantor_fname"  placeholder="Enter first name" >
                            <div class="invalid-tooltip" id="msg_manual_guarantor_fname"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_manual_guarantor_lname">
                            <label for="manual_guarantor_lname">Last name </label>
                            <input type="text" class="form-control" id="manual_guarantor_lname" name="manual_guarantor_lname"  placeholder="Enter last name" >
                            <div class="invalid-tooltip" id="msg_manual_guarantor_lname" ></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_manual_birthdate">
                            <label for="manual_birthdate">Birth Date </label>
                            <input type="date" class="form-control" id="manual_birthdate" name="manual_birthdate"  placeholder="Enter birthdate" >
                            <div class="invalid-tooltip" id="msg_manual_birthdate"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_manual_phone" style="display: none">
                            <label for="manual_phone">Phone </label>
                            <input type="text" class="form-control" id="manual_phone" name="manual_phone"  placeholder="Enter Phone">
                            <div class="invalid-tooltip" id="msg_manual_phone"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_manual_homephone" style="display: none">
                            <label for="manual_homephone">homephone </label>
                            <input type="text" class="form-control" id="manual_homephone" name="manual_homephone" placeholder="Enter Homephone">
                            <div class="invalid-tooltip" id="msg_manual_homephone"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_manual_workphone">
                            <label for="manual_workphone">Work Phone </label>
                            <input type="text" class="form-control" id="manual_workphone" name="manual_workphone"  placeholder="Enter workphone">
                            <div class="invalid-tooltip" id="msg_manual_workphone"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_manual_cell">
                            <label for="manual_cell">Cell</label>
                            <input type="text" class="form-control" id="manual_cell" name="manual_cell" placeholder="Enter last name">
                            <div class="invalid-tooltip" id="msg_manual_cell"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_manual_email_address">
                            <label for="manual_email_address">Email address </label>
                            <input type="text" class="form-control" id="manual_email_address" name="manual_email_address" placeholder="Enter email address">
                            <div class="invalid-tooltip" id="msg_manual_email_address"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_app_loadedate">
                            <label for="manual_loadedate">Loaded Date </label>
                            <input type="text" class="form-control" id="manual_loadedate" name="manual_loadedate"  placeholder="Enter date and time" required="true">
                            <div class="invalid-tooltip" id="msg_manual_loadedate"></div>
                        </div>
                        
                        <div class="col-md-6 form-group mb-3" id="div_manual_gender">
                            <label for="manual_gender">Gender</label>
                            <select name="manual_gender" id="manual_gender" class="form-control">
                              <option value="">Select Gender</option>
                              <option value="M">Male</option>
                              <option value="F">Female</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_user_email_address"></div>
                        </div>
                        <?php for($pr=1;$pr<=7;$pr++){?> 

                          <!-- <div class="col-md-12 form-group mb-3">
                            
                        </div> -->
                        <!-- <div class="col-md-12 form-group mb-3"  id="div_app_procedure<?php //echo $pr; ?>" style="display: none;">
                            <label for="Procedure<?php //echo $pr; ?>"><h5>Procedure <?php //echo $pr; ?></h5></label>
                        </div> -->
                        <div class="col-md-4 form-group mb-3"  id="div_app_procdedure<?php echo $pr; ?>_catagory_id" style="display: none;">
                            <label for="app_procedure<?php echo $pr; ?>_categoryId">Procedure Category <?php echo $pr; ?> </label>
                            <select class="form-control" id="app_procedure<?php echo $pr; ?>_categoryId" name="app_procedure<?php echo $pr; ?>_categoryId">
                            <option value="">Select Category</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_app_procedure<?php echo $pr; ?>_categoryId"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3" id="div_app_procdedure<?php echo $pr; ?>_codesikkaid" style="display: none;">
                            <label for="app_procedure<?php echo $pr; ?>_codesikkaid">Procedure Code <?php echo $pr; ?> </label>
                            <select id="app_procedure<?php echo $pr; ?>_codesikkaid" name="app_procedure<?php echo $pr; ?>_codesikkaid" class="form-control">
                                <option value="">Select Code</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_app_procedure<?php echo $pr; ?>_codesikkaid"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3" id="div_app_procdedure<?php echo $pr; ?>_amount" style="display: none;">
                            <label for="app_procedure<?php echo $pr; ?>_amount">Procedure Amount <?php echo $pr; ?> </label>
                            <input type="text" class="form-control" 
                            id="app_procedure<?php echo $pr; ?>_amount" name="app_procedure<?php echo $pr; ?>_amount" placeholder="Enter Amount">
                            <div class="invalid-tooltip" id="msg_app_procedure<?php echo $pr; ?>_amount"></div>
                        </div>
                        <?php } ?>

                        


                        <!-- Start Other changes -->
                        <div class="col-md-6 form-group mb-3">
                            
                        </div>
                        <div class="col-md-12 form-group mb-3" style="display: none;" id="div_other_cahnges">
                            <label for="other_changes"><h5>Other Changes</h5></label>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_guarantor">
                            <label for="othermanual_guarantor_id">Guarantor Id </label>
                            <!-- <input type="text" class="form-control" 
                            id="othermanual_guarantor_id" name="othermanual_guarantor_id" placeholder="Enter other guarantor id"> -->

                            <select class="form-control" id="othermanual_guarantor_id" name="othermanual_guarantor_id">
                            <option value="">Select Guarantor</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_othermanual_guarantor_id"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othermanual_patientguarantor_id">
                            <label for="othermanual_patientguarantor_id">Guarantor Id </label>
                            <select id="othermanual_patientguarantor_id" name="othermanual_patientguarantor_id" class="form-control">
                                <option value="">Select Guarantor</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_othermanual_patientguarantor_id"></div>
                        </div>
                      <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_firstname">
                            <label for="othermanual_guarantor_fname">First name </label>
                            <input type="text" class="form-control" id="othermanual_guarantor_fname" name="othermanual_guarantor_fname"  placeholder="Enter first name" >
                            <div class="invalid-tooltip" id="msg_othermanual_guarantor_fname"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_lastname">
                            <label for="othermanual_guarantor_lname">Last name </label>
                            <input type="text" class="form-control" id="othermanual_guarantor_lname" name="othermanual_guarantor_lname" placeholder="Enter last name" >
                            <div class="invalid-tooltip" id="msg_othermanual_guarantor_lname" ></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_birthdate">
                            <label for="othermanual_birthdate">Birth Date </label>
                            <input type="date" class="form-control" id="othermanual_birthdate" name="othermanual_birthdate"  placeholder="Enter birthdate" >
                            <div class="invalid-tooltip" id="msg_othermanual_birthdate"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_phone">
                            <label for="othermanual_phone">Phone </label>
                            <input type="text" class="form-control" id="othermanual_phone" name="othermanual_phone" placeholder="Enter Phone">
                            <div class="invalid-tooltip" id="msg_othermanual_phone"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_homephone">
                            <label for="othermanual_homephone">homephone </label>
                            <input type="text" class="form-control" id="othermanual_homephone" name="othermanual_homephone" placeholder="Enter Phone">
                            <div class="invalid-tooltip" id="msg_othermanual_phone"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_workphone">
                            <label for="othermanual_workphone">Work Phone </label>
                            <input type="text" class="form-control" id="othermanual_workphone" name="othermanual_workphone"  placeholder="Enter workphone">
                            <div class="invalid-tooltip" id="msg_othermanual_workphone"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_cell">
                            <label for="otehrmanual_cell">Cell</label>
                            <input type="text" class="form-control" id="otehrmanual_cell" name="otehrmanual_cell"  placeholder="Enter cell">
                            <div class="invalid-tooltip" id="msg_manual_cell"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othercahnges_emailaddress">
                            <label for="othermanual_email_address">Email address </label>
                            <input type="text" class="form-control" id="othermanual_email_address" name="othermanual_email_address"  placeholder="Enter email address">
                            <div class="invalid-tooltip" id="msg_manual_email_address"></div>
                        </div>

                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othermanual_provider_id">
                            <label for="othermanual_provider_id">Provider Id </label>
                            <select class="form-control" id="othermanual_provider_id" name="othermanual_provider_id">
                            <option value="">Select Provider</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_othermanual_provider_id"></div>
                        </div>

                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othermanual_appstatus">
                            <label for="othermanual_appstatus">Status </label>
                            <select class="form-control" id="othermanual_appstatus" name="othermanual_appstatus">
                            <option value="">Select Status</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_othermanual_appstatus"></div>
                        </div>

                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othermanual_appdate">
                            <label for="othermanual_appdate">Date </label>
                            <input type="date" class="form-control" id="othermanual_appdate" name="othermanual_appdate"  placeholder="Enter Date">
                            <div class="invalid-tooltip" id="msg_othermanual_appdate"></div>
                        </div>

                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othermanual_apptime">
                            <label for="othermanual_apptime">Time </label>
                            <input type="time" class="form-control" id="othermanual_apptime" name="othermanual_apptime"  placeholder="Enter Time">
                            <div class="invalid-tooltip" id="msg_othermanual_apptime"></div>
                        </div>

                        <div class="col-md-6 form-group mb-3" style="display: none;" id="div_othermanual_amount">
                            <label for="othermanual_amount">Amount </label>
                            <input type="text" class="form-control" id="othermanual_amount" name="othermanual_amount"  placeholder="Enter Amount">
                            <div class="invalid-tooltip" id="msg_othermanual_amount"></div>
                        </div>

                        <div class="col-md-6 form-group mb-3"  id="div_othermanual_amount">
                            
                        </div>

                         <?php for($pr=1;$pr<=7;$pr++){?> 

                        <div class="col-md-4 form-group mb-3"  id="div_app_other_procdedure<?php echo $pr; ?>_catagory_id" style="display: none;">
                            <label for="app_other_procedure<?php echo $pr; ?>_categoryId">Procedure Category <?php echo $pr; ?> </label>
                            <select class="form-control" id="app_other_procedure<?php echo $pr; ?>_categoryId" name="app_other_procedure<?php echo $pr; ?>_categoryId">
                            <option value="">Select Category</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_app_other_procedure<?php echo $pr; ?>_categoryId"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3" id="div_app_other_procdedure<?php echo $pr; ?>_codesikkaid" style="display: none;">
                            <label for="app_other_procedure<?php echo $pr; ?>_codesikkaid">Procedure Code <?php echo $pr; ?> </label>
                            <select id="app_other_procedure<?php echo $pr; ?>_codesikkaid" name="app_other_procedure<?php echo $pr; ?>_codesikkaid" class="form-control">
                                <option value="">Select Code</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_app_other_procedure<?php echo $pr; ?>_codesikkaid"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3" id="div_app_other_procdedure<?php echo $pr; ?>_amount" style="display: none;">
                            <label for="app_other_procedure<?php echo $pr; ?>_amount">Procedure Amount <?php echo $pr; ?> </label>
                            <input type="text" class="form-control" 
                            id="app_other_procedure<?php echo $pr; ?>_amount" name="app_other_procedure<?php echo $pr; ?>_amount" placeholder="Enter Amount">
                            <div class="invalid-tooltip" id="msg_app_other_procedure<?php echo $pr; ?>_amount"></div>
                        </div>
                        <?php } ?>

                        <div class="col-md-12" id="div_app_submit">
                            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                        </div>

                        <div class='col-md-12' id="div_app_completed" style="display:none;">
                            <input type='submit' class='btn btn-primary' name='completed' id='completed' value='Completed'/>
                        </div>

                        <div class="col-md-12" >
                          <p id="guarantor_result"> </p>
                        </div>

                        <!-- start iframe code -->
                        
                        <div class="col-md-12 " >
                          <p id="manual_iframe" class="manual_iframe"> </p>  
                          <div id="loader" class="loader" style="display: none;"></div>
                        </div>

                        <!-- end iframe code -->
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
 <div class='loader-bubble loader-bubble-secondary m-5' align="center" style="display: none;"></div>
<div id="btnid"></div>

<link href="./assets/styles/css/select2.min.css" rel="stylesheet" />
<script src="./assets/js/select2.min.js"></script>



<style type="text/css">
.select2 {
  width: 400px !important;  
}

</style>
<script type="application/javascript">
   $(document).ready(function() {
    //event.preventDefault();
          

    $("#manual_apppatient_id").select2({
        tags: true
    });
    
    $("#manual_flag").on('change',function(){

       var manual_flag = $("#manual_flag").val();
       var select_data = $("#select_data").val();
       var ClinicId = $("#clinic_id").val();
       var apppatientid = $("#manual_apppatient_id").val();
       if(manual_flag == 'updated' && select_data != '3')
       {
          $("#div_other_cahnges").show();
          if(select_data == '1')
          {
              $("#div_othercahnges_guarantor").show();
              $("#div_manual_guarantor_patient_id").hide();
            }else if(select_data == '2')
            {
              $("#div_othermanual_patientguarantor_id").show();
              $("#div_manual_old_patientguarantor_id").show();     
            }
          
          $("#div_othercahnges_firstname").show();
          $("#div_othercahnges_lastname").show();
          $("#div_othercahnges_birthdate").show();
          if(select_data == '1')
          {
             $("#div_othercahnges_phone").show();
             $.ajax({
                  url: "manual_entry.php?act=getdata&select_data="+select_data, 
                  type: "POST",
                  dataType: 'json',
                  cache: false,
                  //data: ({clinic_id: ClinicId}),
                  success: function(data)
                  {  
                    $("#manual_guarantor_id").val(data.guarantor_id);  
                    $("#manual_selectguarantor_id").val(data.guarantor_id); 
                  }
             });

             if(manual_flag == 'updated')
             {
                $("#div_manual_selectguarantor_id").show();
                $("#div_manual_guarantor_id").hide();

                $.ajax({
                    url: "getguarantor.php", 
                    type: "POST",
                    data: ({clinic_id: ClinicId}),
                    success: function(data)
                    {  
                      $("#manual_selectguarantor_id").html(data);
                      $("#othermanual_guarantor_id").html(data); 
                    }
                });
             }
          }
          $("#div_othercahnges_workphone").show();
          $("#div_othercahnges_cell").show();
          $("#div_othercahnges_emailaddress").show(); 
          if(select_data == '2')
          {
            $("#div_othercahnges_homephone").show(); 

                $.ajax({
                  url: 'getguarantor.php', 
                  type: "POST",
                  data: ({clinic_id: ClinicId}),
                  success: function(data){
                      $("#manual_patientguarantor_id").html(data);
                      if(manual_flag == 'updated')
                      {
                        $("#othermanual_patientguarantor_id").html(data);
                        $("#manual_old_patientguarantor_id").html(data);
                      }

                      $.ajax({
                          url: "manual_entry.php?act=getdata&select_data="+select_data, 
                          type: "POST",
                          dataType: 'json',
                          cache: false,
                          //data: ({clinic_id: ClinicId}),
                          success: function(data)
                          {  
                            $("#manual_patient_id").val(data.patient_id);   
                          }
                        });

                    }
                });
          }


       }else if(manual_flag == 'updated' && select_data == '3')
       {

            $("#div_other_cahnges").show();
            $("#div_othermanual_provider_id").show();
            $("#div_othermanual_appstatus").show();
            $("#div_othermanual_appdate").show();
            $("#div_othermanual_apptime").show();
            $("#div_othermanual_amount").show();

            $("#div_appointment_sr_no").show();
            $("#div_provider_id").show();
            $("#div_app_date").show();
            $("#div_app_time").show();
            $("#div_app_length").show();
            $("#div_app_amount").show();
            $("#div_app_status").show();
            $("#div_app_loadedate").show();
            $("#div_app_submit").show();
            $("#div_app_completed").hide();
            $("#div_manual_selectguarantor_id").hide();

            for(var pi = 1; pi <= 7; pi++) 
            {
              $("#div_app_procedure"+pi).show();
              $("#div_app_procdedure"+pi+"_catagory_id").show();
              $("#app_procedure"+pi+"_categoryId").show();
              $("#div_app_procdedure"+pi+"_codesikkaid").show();
              $("#app_procedure"+pi+"_codesikkaid").show();
              $("#div_app_procdedure"+pi+"_amount").show();
              $("#app_procedure"+pi+"_amount").show();

              $("#div_app_other_procdedure"+pi+"_catagory_id").show();
              $("#app_other_procedure"+pi+"_categoryId").show();
              $("#div_app_other_procdedure"+pi+"_codesikkaid").show();
              $("#app_other_procedure"+pi+"_codesikkaid").show();
              $("#div_app_other_procdedure"+pi+"_amount").show();
              $("#app_other_procedure"+pi+"_amount").show();
            }

            $.ajax({
                  url: 'getprovider.php', 
                  type: "POST",
                  data: ({clinic_id: ClinicId}),
                  success: function(data){
                      $("#othermanual_provider_id").html(data);

                  }
              });

            $.ajax({
                      url: 'getpmsappstaus.php', 
                      type: "POST",
                      data: ({clinic_id: ClinicId}),
                      success: function(data){
                          $("#othermanual_appstatus").html(data);

                      }
                  });

            $.ajax({
                  url: "manual_entry.php?act=getdata&select_data="+select_data, 
                  type: "POST",
                  dataType: 'json',
                  cache: false,
                  //data: ({clinic_id: ClinicId}),
                  success: function(data)
                  {
                      if(select_data == '3')
                      {
                        $("#appointment_sr_no").val(data.appointment_sr_no);
                      }

                      $("#div_appoinment_data").html('');
                      $.ajax({
                            url: "manual_entry.php", 
                            type: "POST",
                            dataType: 'json',
                            cache: false,
                            data: ({act:"getappoinmnet",clinic_id: ClinicId,apppatientid:apppatientid,flag_data:manual_flag}),
                            success: function(data)
                            {
                                //console.log(data);
                                $("#div_appoinment_data").show();  
                                var len = data.appointments.length;
                                
                                for (i = 0; i < len; i++) 
                                {
                                   $("#div_appoinment_data").append(data.appointments[i]);
                                }
                            }
                      });
                  }
            });

       }else if(manual_flag == 'Added' && select_data == '3')
       {

            $("#div_other_cahnges").hide();
            $("#div_othermanual_provider_id").hide();
            $("#div_othermanual_appstatus").hide();
            $("#div_othermanual_appdate").hide();
            $("#div_othermanual_apptime").hide();
            $("#div_othermanual_amount").hide();
            $("#div_appoinment_data").hide();

            $("#div_appointment_sr_no").show();
            $("#div_provider_id").show();
            $("#div_app_date").show();
            $("#div_app_time").show();
            $("#div_app_length").show();
            $("#div_app_amount").show();
            $("#div_app_status").show();
            $("#div_app_loadedate").show();
            $("#div_app_submit").show();
            $("#div_app_completed").hide();
            $("#div_manual_selectguarantor_id").hide();

            for(var pi = 1; pi <= 7; pi++) 
            {
              $("#div_app_procedure"+pi).show();
              $("#div_app_procdedure"+pi+"_catagory_id").show();
              $("#app_procedure"+pi+"_categoryId").show();
              $("#div_app_procdedure"+pi+"_codesikkaid").show();
              $("#app_procedure"+pi+"_codesikkaid").show();
              $("#div_app_procdedure"+pi+"_amount").show();
              $("#app_procedure"+pi+"_amount").show();

              $("#div_app_other_procdedure"+pi+"_catagory_id").hide();
              $("#app_other_procedure"+pi+"_categoryId").hide();
              $("#div_app_other_procdedure"+pi+"_codesikkaid").hide();
              $("#app_other_procedure"+pi+"_codesikkaid").hide();
              $("#div_app_other_procdedure"+pi+"_amount").hide();
              $("#app_other_procedure"+pi+"_amount").hide();
            }

            $.ajax({
                      url: 'getappoinmnet_srno.php', 
                      type: "POST",
                      data: ({act :'appointments',select_data: 'appointments'}),
                      dataType:"json",
                      success: function(data){
                          $("#appointment_sr_no").val(data.app_sr_no);

                      }
                  });
       }else if(manual_flag == 'Deleted')
       {
            if(select_data == '3')
            {
                $("#div_other_cahnges").hide();
                $("#div_othermanual_provider_id").hide();
                $("#div_othermanual_appstatus").hide();
                $("#div_othermanual_appdate").hide();
                $("#div_othermanual_apptime").hide();
                $("#div_othermanual_amount").hide();

                $("#div_appointment_sr_no").hide();
                $("#div_provider_id").hide();
                $("#div_app_date").hide();
                $("#div_app_time").hide();
                $("#div_app_length").hide();
                $("#div_app_amount").hide();
                $("#div_app_status").hide();
                $("#div_app_loadedate").hide();
                $("#div_app_submit").hide();
                $("#div_app_completed").hide();
                $("#div_manual_selectguarantor_id").hide();

                for(var pida = 1; pida <= 7; pida++) 
                {
                  $("#div_app_procedure"+pida).hide();
                  $("#div_app_procdedure"+pida+"_catagory_id").hide();
                  $("#app_procedure"+pida+"_categoryId").hide();
                  $("#div_app_procdedure"+pida+"_codesikkaid").hide();
                  $("#app_procedure"+pida+"_codesikkaid").hide();
                  $("#div_app_procdedure"+pida+"_amount").hide();
                  $("#app_procedure"+pida+"_amount").hide();

                  $("#div_app_other_procdedure"+pida+"_catagory_id").hide();
                  $("#app_other_procedure"+pida+"_categoryId").hide();
                  $("#div_app_other_procdedure"+pida+"_codesikkaid").hide();
                  $("#app_other_procedure"+pida+"_codesikkaid").hide();
                  $("#div_app_other_procdedure"+pida+"_amount").hide();
                  $("#app_other_procedure"+pida+"_amount").hide();
                }

                $("#div_appoinment_data").html('');
                $.ajax({
                      url: "manual_entry.php", 
                      type: "POST",
                      dataType: 'json',
                      cache: false,
                      data: ({act:"getappoinmnet",clinic_id: ClinicId,apppatientid:apppatientid,flag_data:manual_flag}),
                      success: function(data)
                      {
                          //console.log(data);
                          $("#div_appoinment_data").show();  
                          var len = data.appointments.length;
                          
                          for (i = 0; i < len; i++) 
                          {
                             $("#div_appoinment_data").append(data.appointments[i]);
                          }
                          $("#div_appoinment_data").append("<div class='col-md-12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' class='btn btn-primary' name='canceled' id='canceled' value='Delete/Cancel'/> </div>");
                      }
                });   
            }

            if(select_data == '1')
            {
                $("#div_other_cahnges").hide();
                $("#div_othercahnges_guarantor").hide();
                $("#div_othermanual_patientguarantor_id").hide();
                $("#div_othercahnges_firstname").hide();
                $("#div_othercahnges_lastname").hide();
                $("#div_othercahnges_birthdate").hide();
                $("#div_othercahnges_phone").hide();
                $("#div_othercahnges_homephone").hide();   
                $("#div_othercahnges_workphone").hide();
                $("#div_othercahnges_cell").hide();
                $("#div_othercahnges_emailaddress").hide();

                $("#div_manual_guarantor_patient_id").show();
                $("#div_manual_selectguarantor_id").show();
                $("#div_manual_guarantor_id").hide();
            }

            if(select_data == '2')
            {
                $("#div_other_cahnges").hide();
                $("#div_othercahnges_guarantor").hide();
                $("#div_othermanual_patientguarantor_id").hide();
                $("#div_othercahnges_firstname").hide();
                $("#div_othercahnges_lastname").hide();
                $("#div_othercahnges_birthdate").hide();
                $("#div_othercahnges_phone").hide();
                $("#div_othercahnges_homephone").hide();   
                $("#div_othercahnges_workphone").hide();
                $("#div_othercahnges_cell").hide();
                $("#div_othercahnges_emailaddress").hide();
                $("#div_manual_old_patientguarantor_id").hide();
                $("#div_manual_selectguarantor_id").hide();
            }
            

            $.ajax({
                  url: "manual_entry.php?act=getdata&select_data="+select_data, 
                  type: "POST",
                  dataType: 'json',
                  cache: false,
                  //data: ({clinic_id: ClinicId}),
                  success: function(data){
                      
                      if(select_data == '1')
                      {
                        $("#manual_guarantor_id").val(data.guarantor_id);
                        if(manual_flag == 'Deleted')
                        {
                          var mguarantor_id = data.guarantor_id;
                          if(manual_flag == 'Deleted' && select_data == '1')
                          {
                            $.ajax({
                              url: "manual_entry.php", 
                              type: "POST",
                              /*dataType: 'json',
                              cache: false,*/
                              data: ({act:"getpatient",selectguarantor_id: mguarantor_id,flag_data:manual_flag}),
                              success: function(data)
                              {
                                  //console.log(data);
                                  $("#manual_guarantor_patient_id").html(data);
                              }
                            });
                          }
                            
                        }
                        
                      }else if(select_data == '2')
                      {
                        $("#manual_patient_id").val(data.patient_id);
                      }
                      else if(select_data == '3')
                      {
                        $("#appointment_sr_no").val(data.appointment_sr_no);
                      }
                  }
              });
       }else if(manual_flag == 'Completed')
       {
            if(select_data == '3')
            {
                $("#div_other_cahnges").hide();
                $("#div_othermanual_provider_id").hide();
                $("#div_othermanual_appstatus").hide();
                $("#div_othermanual_appdate").hide();
                $("#div_othermanual_apptime").hide();
                $("#div_othermanual_amount").hide();

                $("#div_appointment_sr_no").hide();
                $("#div_provider_id").hide();
                $("#div_app_date").hide();
                $("#div_app_time").hide();
                $("#div_app_length").hide();
                $("#div_app_amount").hide();
                $("#div_app_loadedate").hide();
                $("#div_app_submit").hide();
                $("#div_app_completed").show();
                $("#div_app_status").show();
                $("#div_manual_selectguarantor_id").hide();

                for(var pi = 1; pi <= 7; pi++) 
                {
                  $("#div_app_procedure"+pi).hide();
                  $("#div_app_procdedure"+pi+"_catagory_id").hide();
                  $("#app_procedure"+pi+"_categoryId").hide();
                  $("#div_app_procdedure"+pi+"_codesikkaid").hide();
                  $("#app_procedure"+pi+"_codesikkaid").hide();
                  $("#div_app_procdedure"+pi+"_amount").hide();
                  $("#app_procedure"+pi+"_amount").hide();

                  $("#div_app_other_procdedure"+pi+"_catagory_id").hide();
                  $("#app_other_procedure"+pi+"_categoryId").hide();
                  $("#div_app_other_procdedure"+pi+"_codesikkaid").hide();
                  $("#app_other_procedure"+pi+"_codesikkaid").hide();
                  $("#div_app_other_procdedure"+pi+"_amount").hide();
                  $("#app_other_procedure"+pi+"_amount").hide();
                }


                $("#div_appoinment_data").html('');
                $.ajax({
                      url: "manual_entry.php", 
                      type: "POST",
                      dataType: 'json',
                      cache: false,
                      data: ({act:"getappoinmnet",clinic_id: ClinicId,apppatientid:apppatientid,flag_data:manual_flag}),
                      success: function(data)
                      {
                          //console.log(data);
                          $("#div_appoinment_data").show();  
                          var len = data.appointments.length;
                          
                          for (i = 0; i < len; i++) 
                          {
                             $("#div_appoinment_data").append(data.appointments[i]);
                          }
                          //$("#div_appoinment_data").append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='completed' id='completed' value='Completed'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='canceled' id='canceled' value='Delete/Cancel'/>");
                          //$("#div_appoinment_data").append("<div class='col-md-12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' class='btn btn-primary' name='completed' id='completed' value='Completed'/></div>");
                      }
                });   
            }

            if(select_data == '1')
            {
                $("#div_other_cahnges").hide();
                $("#div_othercahnges_guarantor").hide();
                $("#div_othermanual_patientguarantor_id").hide();
                $("#div_othercahnges_firstname").hide();
                $("#div_othercahnges_lastname").hide();
                $("#div_othercahnges_birthdate").hide();
                $("#div_othercahnges_phone").hide();
                $("#div_othercahnges_homephone").hide();   
                $("#div_othercahnges_workphone").hide();
                $("#div_othercahnges_cell").hide();
                $("#div_othercahnges_emailaddress").hide();
                $("#div_manual_guarantor_patient_id").hide();
                $("#div_manual_selectguarantor_id").hide();
                $("#div_manual_guarantor_id").show();
            }

            if(select_data == '2')
            {
                $("#div_other_cahnges").hide();
                $("#div_othercahnges_guarantor").hide();
                $("#div_othermanual_patientguarantor_id").hide();
                $("#div_othercahnges_firstname").hide();
                $("#div_othercahnges_lastname").hide();
                $("#div_othercahnges_birthdate").hide();
                $("#div_othercahnges_phone").hide();
                $("#div_othercahnges_homephone").hide();   
                $("#div_othercahnges_workphone").hide();
                $("#div_othercahnges_cell").hide();
                $("#div_othercahnges_emailaddress").hide();
                $("#div_manual_old_patientguarantor_id").hide();
                $("#div_manual_selectguarantor_id").hide();
            }
            

            $.ajax({
                  url: "manual_entry.php?act=getdata&select_data="+select_data, 
                  type: "POST",
                  dataType: 'json',
                  cache: false,
                  //data: ({clinic_id: ClinicId}),
                  success: function(data){
                      
                      if(select_data == '1')
                      {
                        $("#manual_guarantor_id").val(data.guarantor_id);
                      }else if(select_data == '2')
                      {
                        $("#manual_patient_id").val(data.patient_id);
                      }
                      else if(select_data == '3')
                      {
                        $("#appointment_sr_no").val(data.appointment_sr_no);
                      }
                  }
              });
       }
       else if(manual_flag == 'Added' && select_data == '1')
       {

            $("#div_other_cahnges").hide();
            $("#div_othercahnges_guarantor").hide();
            $("#div_othermanual_patientguarantor_id").hide();
            $("#div_othercahnges_firstname").hide();
            $("#div_othercahnges_lastname").hide();
            $("#div_othercahnges_birthdate").hide();
            $("#div_othercahnges_phone").hide();
            $("#div_othercahnges_homephone").hide();   
            $("#div_othercahnges_workphone").hide();
            $("#div_othercahnges_cell").hide();
            $("#div_othercahnges_emailaddress").hide();
            $("#div_manual_guarantor_patient_id").hide();
            $("#div_manual_selectguarantor_id").hide();
            $("#div_manual_guarantor_id").show();
            


            $.ajax({
                      url: 'getappoinmnet_srno.php', 
                      type: "POST",
                      data: ({act :'guranoters',select_data: 'guranoters'}),
                      dataType:"json",
                      success: function(data){
                          $("#manual_guarantor_id").val(data.guarantor_sr_no);

                      }
                  });
       }
       else if(manual_flag == 'Added' && select_data == '2')
       {

            $("#div_other_cahnges").hide();
            $("#div_othercahnges_guarantor").hide();
            $("#div_othermanual_patientguarantor_id").hide();
            $("#div_othercahnges_firstname").hide();
            $("#div_othercahnges_lastname").hide();
            $("#div_othercahnges_birthdate").hide();
            $("#div_othercahnges_phone").hide();
            $("#div_othercahnges_homephone").hide();   
            $("#div_othercahnges_workphone").hide();
            $("#div_othercahnges_cell").hide();
            $("#div_othercahnges_emailaddress").hide();
            $("#div_manual_old_patientguarantor_id").hide();
            $("#div_manual_selectguarantor_id").hide();

            $.ajax({
                      url: 'getappoinmnet_srno.php', 
                      type: "POST",
                      data: ({act :'patient',select_data: 'patient'}),
                      dataType:"json",
                      success: function(data){
                          $("#manual_patient_id").val(data.patient_sr_no);

                      }
                  });
       }
       else
       {
          
            $("#div_other_cahnges").hide();
            $("#div_othercahnges_guarantor").hide();
            $("#div_othermanual_patientguarantor_id").hide();
            $("#div_othercahnges_firstname").hide();
            $("#div_othercahnges_lastname").hide();
            $("#div_othercahnges_birthdate").hide();
            $("#div_othercahnges_phone").hide();
            $("#div_othercahnges_workphone").hide();
            $("#div_othercahnges_cell").hide();
            $("#div_othercahnges_emailaddress").hide();
            $("#div_othercahnges_homephone").hide();

            $("#othermanual_guarantor_id").val('');
            $("#othermanual_guarantor_fname").val('');
            $("#othermanual_guarantor_lname").val('');
            $("#othermanual_birthdate").val('');
            $("#othermanual_phone").val('');
            $("#othermanual_workphone").val('');
            $("#otehrmanual_cell").val('');
            $("#othermanual_email_address").val('');
            $("#othercahnges_homephone").val('');
            $("#othermanual_provider_id").val('');
            $("#othermanual_appstatus").val('');
            $("#othermanual_appdate").val('');
            $("#othermanual_apptime").val('');
            $("#othermanual_amount").val('');
            
            $("#div_othermanual_provider_id").hide();
            $("#div_othermanual_appstatus").hide();
            $("#div_othermanual_appdate").hide();
            $("#div_othermanual_apptime").hide();
            $("#div_othermanual_amount").hide();
            $("#div_manual_selectguarantor_id").hide();
            $("#div_manual_guarantor_id").show();

            $("#div_app_procedure1").hide();
            $("#div_app_procedure2").hide();
            $("#div_app_procedure3").hide();
            $("#div_app_procedure4").hide();
            $("#div_app_procedure5").hide();
            $("#div_app_procedure6").hide();
            $("#div_app_procedure7").hide();
            
            $("#div_app_other_procedure1").hide();
            $("#div_app_other_procedure2").hide();
            $("#div_app_other_procedure3").hide();
            $("#div_app_other_procedure4").hide();
            $("#div_app_other_procedure5").hide();
            $("#div_app_other_procedure6").hide();
            $("#div_app_other_procedure7").hide();
       }
     });
      
    $("#clinic_id").on('change',function(){

        var ClinicId = $("#clinic_id").val();
        var select_data = $("#select_data").val();
        var manual_flag = $("#manual_flag").val();
        //console.log(manual_flag);
        if(select_data == '1')
        {
          if(manual_flag == 'updated')
          {
            $.ajax({
                  url: 'getguarantor.php', 
                  type: "POST",
                  data: ({clinic_id: ClinicId}),
                  success: function(data)
                  {
                      if(manual_flag == 'updated')
                      {
                        $("#manual_selectguarantor_id").html(data);
                        $("#othermanual_guarantor_id").html(data);
                      }
                      

                      $.ajax({
                              url: "manual_entry.php?act=getdata&select_data="+select_data, 
                              type: "POST",
                              dataType: 'json',
                              cache: false,
                              //data: ({clinic_id: ClinicId}),
                              success: function(data){
                                  if(select_data == '1')
                                  {
                                    $("#manual_selectguarantor_id").val(data.guarantor_id);

                                  }
                                  
                                  if(data.guarantor_flag == 'updated')
                                  {
                                      $.each(data.guarantor_changes, function(index, value) 
                                      {
                                          if(value.field == 'guarantorid')
                                          {
                                             $("#othermanual_guarantor_id").val(value.new_value);
                                          }
                                              
                                      });
                                  }
                                  

                              }
                            });
                  }
                });
          }

          if(manual_flag == 'Deleted')
          {
            $.ajax({
                  url: 'getguarantor.php', 
                  type: "POST",
                  data: ({clinic_id: ClinicId}),
                  success: function(data)
                  {
                      if(manual_flag == 'Deleted')
                      {
                        $("#manual_selectguarantor_id").html(data);
                      }
                      

                      $.ajax({
                              url: "manual_entry.php?act=getdata&select_data="+select_data, 
                              type: "POST",
                              dataType: 'json',
                              cache: false,
                              //data: ({clinic_id: ClinicId}),
                              success: function(data){
                                  if(select_data == '1')
                                  {
                                    $("#manual_selectguarantor_id").val(data.guarantor_id);
                                  }

                                  $.ajax({
                                    url: "manual_entry.php", 
                                    type: "POST",
                                    data: ({act:'getpatient',selectguarantor_id:data.guarantor_id}),
                                    success: function(data){
                                        if(select_data == '1')
                                        {
                                          $("#manual_guarantor_patient_id").html(data);
                                        }
                                    }
                                  });
                              }
                            });
                  }
                });
          }
          
        }
        if(select_data == '2')
        {
            
              $.ajax({
                  url: 'getguarantor.php', 
                  type: "POST",
                  data: ({clinic_id: ClinicId}),
                  success: function(data){
                      $("#manual_patientguarantor_id").html(data);
                      if(manual_flag == 'updated')
                      {
                        $("#othermanual_patientguarantor_id").html(data);
                        $("#manual_old_patientguarantor_id").html(data);
                      }
                      

                      $.ajax({
                              url: "manual_entry.php?act=getdata&select_data="+select_data, 
                              type: "POST",
                              dataType: 'json',
                              cache: false,
                              //data: ({clinic_id: ClinicId}),
                              success: function(data){
                                  if(select_data == '2')
                                  {
                                    $("#manual_patientguarantor_id").val(data.guarantor_id);
                                  }
                                  /*if(manual_flag == 'updated')
                                  {
                                    $("#othermanual_patientguarantor_id").html(data);
                                  }*/
                                  if(data.guarantor_flag == 'updated')
                                  {
                                      $.each(data.guarantor_changes, function(index, value) 
                                      {
                                          if(value.field == 'guarantorid')
                                          {
                                             $("#othermanual_patientguarantor_id").val(value.new_value);
                                             $("#manual_old_patientguarantor_id").val(value.old_value);
                                          }
                                              
                                      });
                                  }
                                  

                              }
                            });
                  }
              });
        }
        if(select_data == '3')
        {
            $.ajax({
                  url: 'getpmspatient.php', 
                  type: "POST",
                  data: ({clinic_id: ClinicId}),
                  //dataType: 'json',
                  success: function(data)
                  {
                      $("#manual_apppatient_id").html(data);

                      $.ajax({
                          url: 'getprovider.php', 
                          type: "POST",
                          data: ({clinic_id: ClinicId}),
                          success: function(data){
                              $("#provider_id").html(data);

                               $.ajax({
                                  url: 'getprovider.php', 
                                  type: "POST",
                                  data: ({clinic_id: ClinicId}),
                                  success: function(data){
                                      $("#provider_id").html(data);
                                      if(manual_flag == 'updated' && select_data == '3')
                                      {
                                          $("#othermanual_provider_id").html(data);
                                      }

                                      $.ajax({
                                        url: 'getpmsappstaus.php', 
                                        type: "POST",
                                        data: ({clinic_id: ClinicId}),
                                        success: function(data){
                                            $("#app_status").html(data);
                                            if(manual_flag == 'updated' && select_data == '3')
                                            {
                                                $("#othermanual_appstatus").html(data);
                                            }

                                            $.ajax({
                                              url: 'manual_entry.php', 
                                              type: "POST",
                                              data: ({act:'getprocedurecategory',clinic_id: ClinicId}),
                                              success: function(data){
                                                  $("#app_procedure1_categoryId").html(data);
                                                  $("#app_procedure2_categoryId").html(data);
                                                  $("#app_procedure3_categoryId").html(data);
                                                  $("#app_procedure4_categoryId").html(data);
                                                  $("#app_procedure5_categoryId").html(data);
                                                  $("#app_procedure6_categoryId").html(data);
                                                  $("#app_procedure7_categoryId").html(data);

                                                  for(var othcat=1; othcat<=7; othcat++)
                                                  {
                                                    $("#app_other_procedure"+othcat+"_categoryId").html(data);
                                                  }
                                                  /*if(manual_flag == 'updated' && select_data == '3')
                                                  {
                                                      $("#othermanual_appstatus").html(data);
                                                  }*/

                                                   $.ajax({
                                                        url: "manual_entry.php?act=getdata&select_data="+select_data, 
                                                        type: "POST",
                                                        dataType: 'json',
                                                        cache: false,
                                                        //data: ({clinic_id: ClinicId}),
                                                        success: function(data){
                                                            //console.log(data.guarantor_id);
                                                            //return false;
                                                            if(select_data == '3')
                                                            {
                                                              /*$("#manual_apppatient_id").val(data.patient_id);*/
                                                              $("#manual_apppatient_id").val(data.patient_id).trigger('change');
                                                              if(data.guarantor_flag != 'Added')
                                                              {
                                                                  $("#appointment_sr_no").val(data.appointment_sr_no);    
                                                              }
                                                              
                                                              $("#provider_id").val(data.provider_id);
                                                              //$("#provider_id option:selected").val(data.provider_id)
                                                              $("#app_date").val(data.app_date);
                                                              $("#app_time").val(data.app_time);
                                                              $("#app_length").val(data.app_length);
                                                              $("#app_amount").val(data.app_amount);
                                                              $("#app_status").val(data.app_status);

                                                              $.each(data.guarantor_changes, function(index, value) 
                                                              {
                                                                    if(value.field == 'provider_id')
                                                                    {
                                                                       $("#othermanual_provider_id").val(value.new_value);
                                                                    }else if(value.field == 'status')
                                                                    {
                                                                       $("#othermanual_appstatus").val(value.new_value);
                                                                    }else if(value.field == 'date')
                                                                    {
                                                                       $("#othermanual_appdate").val(value.new_value);
                                                                    }else if(value.field == 'time')
                                                                    {
                                                                       $("#othermanual_apptime").val(value.new_value);
                                                                    }else if(value.field == 'amount')
                                                                    {
                                                                       $("#othermanual_amount").val(value.new_value);
                                                                    }
                                                                    
                                                              });
                                                            }
                                                        }
                                                   });

                                              }
                                            }); 

                                        }
                                    });
                                  }
                              });
                            }
                        })
                  }
                });   
        }
    });  
      
      

    $("#select_data").on('change',function()
    {

       var select_data = $("#select_data").val();
       var clinic_id = $("#clinic_id").val();
         
       if(select_data == '1')
       {
         
          $("#div_manual_patient").hide();
          $("#div_manual_homephone").hide(); 
          $("#div_manual_phone").show(); 
          $("#div_othercahnges_homephone").hide();
          $("#div_appointment_sr_no").hide();
          $("#div_provider_id").hide();
          $("#div_app_date").hide();
          $("#div_app_time").hide();
          $("#div_app_length").hide();
          $("#div_app_amount").hide();
          $("#div_app_status").hide();
          $("#div_search_patient").hide();
          
          $("#div_other_cahnges").hide();
          $("#div_othermanual_provider_id").hide();
          $("#div_othermanual_appstatus").hide();
          $("#div_othermanual_appdate").hide();
          $("#div_othermanual_apptime").hide();
          $("#div_othermanual_amount").hide();
          $("#div_manual_apppatient_id").hide();
          $("#div_manual_patientguarantor_id").hide();


          $("#div_manual_guarantor_id").show();
          $("#div_manual_guarantor_fname").show();
          $("#div_manual_guarantor_lname").show();
          $("#div_manual_birthdate").show();
          $("#div_manual_workphone").show();
          $("#div_manual_cell").show();
          $("#div_manual_gender").show();
          $("#div_manual_email_address").show();
          $("#div_manual_phone").show();

          $("#othermanual_guarantor_id").val('');
          $("#othermanual_guarantor_fname").val('');
          $("#othermanual_guarantor_lname").val('');
          $("#othermanual_birthdate").val('');
          $("#othermanual_homephone").val('');
          $("#othermanual_workphone").val('');
          $("#otehrmanual_cell").val('');
          $("#othermanual_email_address").val('');

          $("#manual_guarantor_id").attr('required',true);
          $("#manual_guarantor_fname").attr('required',true);
          $("#manual_guarantor_lname").attr('required',true);
          $("#manual_birthdate").attr('required',true);
          $("#manual_gender").attr('required',true);
          $("#clinic_id").val('');
          $("#div_search_patient_data").html('');
          $("#search_patient").val('');
          $("#div_search_patient_data").hide();
          $("#div_appoinment_data").hide();

          $("#div_manual_old_patientguarantor_id").hide();

          for(var pi = 1; pi <= 7; pi++) 
          {
            $("#div_app_procedure"+pi).hide();
            $("#div_app_procdedure"+pi+"_catagory_id").hide();
            $("#app_procedure"+pi+"_categoryId").hide();
            $("#div_app_procdedure"+pi+"_codesikkaid").hide();
            $("#app_procedure"+pi+"_codesikkaid").hide();
            $("#div_app_procdedure"+pi+"_amount").hide();
            $("#app_procedure"+pi+"_amount").hide();


            $("#div_app_other_procdedure"+pi+"_catagory_id").hide();
            $("#app_other_procedure"+pi+"_categoryId").hide();
            $("#div_app_other_procdedure"+pi+"_codesikkaid").hide();
            $("#app_other_procedure"+pi+"_codesikkaid").hide();
            $("#div_app_other_procdedure"+pi+"_amount").hide();
            $("#app_other_procedure"+pi+"_amount").hide();


          }
          
       }

       if(select_data == '2')
       {
          $("#div_manual_patient").show();
          $("#div_manual_homephone").show();
          $("#div_manual_patientguarantor_id").show();
          $("#div_manual_guarantor_fname").show();
          $("#div_manual_guarantor_lname").show();
          $("#div_manual_birthdate").show();
          $("#div_manual_workphone").show();
          $("#div_manual_cell").show();
          $("#div_manual_gender").show();
          $("#div_manual_email_address").show();
          $("#div_manual_phone").show();
          $("#div_manual_guarantor_id").hide();
          $("#div_othermanual_provider_id").hide();
          $("#div_othermanual_appstatus").hide();
          $("#div_othermanual_appdate").hide();
          $("#div_othermanual_apptime").hide();
          $("#div_othermanual_amount").hide();
          $("#div_manual_apppatient_id").hide();

          $("#div_manual_phone").hide();
          $("#div_provider_id").hide();
          $("#div_app_date").hide();
          $("#div_app_time").hide();
          $("#div_app_length").hide();
          $("#div_app_amount").hide();
          $("#div_app_status").hide();


          $("#div_other_cahnges").hide();
          $("#div_othercahnges_guarantor").hide();

          $("#div_othercahnges_firstname").hide();
          $("#div_othercahnges_lastname").hide();
          $("#div_othercahnges_birthdate").hide();
          $("#div_othercahnges_phone").hide();
          $("#div_othercahnges_workphone").hide();
          $("#div_othercahnges_cell").hide();
          $("#div_othercahnges_emailaddress").hide();

          $("#div_appointment_sr_no").hide();

          $("#othermanual_guarantor_id").val('');
          $("#othermanual_guarantor_fname").val('');
          $("#othermanual_guarantor_lname").val('');
          $("#othermanual_birthdate").val('');
          $("#othermanual_homephone").val('');
          $("#othermanual_workphone").val('');
          $("#otehrmanual_cell").val('');
          $("#othermanual_email_address").val('');

          $("#manual_patient_id").attr('required',true);
          //$("#manual_guarantor_id").attr('required',true);
          $("#manual_guarantor_fname").attr('required',true);
          $("#manual_guarantor_lname").attr('required',true);
          $("#manual_birthdate").attr('required',true);
          $("#manual_gender").attr('required',true);

          $("#div_search_patient").show();

          $("#clinic_id").val('');
          $("#search_patient").val('');

          $("#div_appoinment_data").hide();

          $("#div_manual_guarantor_patient_id").hide();

          $("#div_manual_selectguarantor_id").hide();

          for(var pi = 1; pi <= 7; pi++) 
          {
            $("#div_app_procedure"+pi).hide();
            $("#div_app_procdedure"+pi+"_catagory_id").hide();
            $("#app_procedure"+pi+"_categoryId").hide();
            $("#div_app_procdedure"+pi+"_codesikkaid").hide();
            $("#app_procedure"+pi+"_codesikkaid").hide();
            $("#div_app_procdedure"+pi+"_amount").hide();
            $("#app_procedure"+pi+"_amount").hide();

            $("#div_app_other_procdedure"+pi+"_catagory_id").hide();
            $("#app_other_procedure"+pi+"_categoryId").hide();
            $("#div_app_other_procdedure"+pi+"_codesikkaid").hide();
            $("#app_other_procedure"+pi+"_codesikkaid").hide();
            $("#div_app_other_procdedure"+pi+"_amount").hide();
            $("#app_other_procedure"+pi+"_amount").hide();
          }
          
       }


       if(select_data == '3')
       {

          $("#div_appointment_sr_no").show();
          $("#div_manual_patient").hide();
          $("#div_manual_apppatient_id").show();
          $("#div_provider_id").show();
          $("#div_app_date").show();
          $("#div_app_time").show();
          $("#div_app_length").show();
          $("#div_app_amount").show();
          $("#div_app_status").show();

          $("#div_manual_guarantor_id").hide();
          $("#div_manual_guarantor_fname").hide();
          $("#div_manual_guarantor_lname").hide();
          $("#div_manual_birthdate").hide();
          $("#div_manual_workphone").hide();
          $("#div_manual_cell").hide();
          $("#div_manual_gender").hide();
          $("#div_manual_email_address").hide();
          $("#div_manual_phone").hide(); 
          $("#div_manual_homephone").hide();

          $("#div_other_cahnges").hide();
          $("#div_othercahnges_guarantor").hide();
          $("#div_othercahnges_firstname").hide();
          $("#div_othercahnges_lastname").hide();
          $("#div_othercahnges_birthdate").hide();
          $("#div_othercahnges_phone").hide();
          $("#div_othercahnges_workphone").hide();
          $("#div_othercahnges_cell").hide();
          $("#div_othercahnges_emailaddress").hide();
          $("#div_othercahnges_homephone").hide();
          $("#div_manual_patientguarantor_id").hide();
          $("#div_othermanual_patientguarantor_id").hide();

          $("#manual_patient_id").val('');
          $("#clinic_id").val('');
          $("#div_search_patient_data").html('');
          $("#search_patient").val('');

          $("#appointment_sr_no").attr('required',true);
          $("#manual_guarantor_id").removeAttr('required');
          $("#manual_guarantor_fname").removeAttr('required');
          $("#manual_guarantor_lname").removeAttr('required');
          $("#manual_birthdate").removeAttr('required');
          $("#manual_gender").removeAttr('required');

          $("#div_search_patient").hide();
          $("#div_search_patient_data").hide();


          $("#div_manual_guarantor_patient_id").hide();
          $("#div_manual_old_patientguarantor_id").hide();

          $("#div_manual_selectguarantor_id").hide();

          for(var pi = 1; pi <= 7; pi++) 
          {
            $("#div_app_procedure"+pi).show();
            $("#div_app_procdedure"+pi+"_catagory_id").show();
            $("#app_procedure"+pi+"_categoryId").show();
            $("#div_app_procdedure"+pi+"_codesikkaid").show();
            $("#app_procedure"+pi+"_codesikkaid").show();
            $("#div_app_procdedure"+pi+"_amount").show();
            $("#app_procedure"+pi+"_amount").show();
          }
          


       } 
       $.ajax({
                  url: "manual_entry.php?act=getdata&select_data="+select_data, 
                  type: "POST",
                  dataType: 'json',
                  cache: false,
                  //data: ({clinic_id: ClinicId}),
                  success: function(data){
                      /*console.log(data.guarantor_flag);
                      return false;*/

                      if(select_data == '1' && data.guarantor_flag == 'Added')
                      {

                        $("#div_othercahnges_guarantor").hide();
                        $("#div_othercahnges_firstname").hide();
                        $("#div_othercahnges_lastname").hide();
                        $("#div_othercahnges_birthdate").hide();
                        $("#div_othercahnges_phone").hide();
                        $("#div_othercahnges_homephone").hide();
                        $("#div_othercahnges_workphone").hide();
                        $("#div_othercahnges_cell").hide();
                        $("#div_othercahnges_emailaddress").hide();
                        $.ajax({
                              url: 'getappoinmnet_srno.php', 
                              type: "POST",
                              data: ({act :'guranoters',select_data: 'guranoters'}),
                              dataType:"json",
                              success: function(data){
                                  $("#manual_guarantor_id").val(data.guarantor_sr_no);

                              }
                          });
                      }
                      if(select_data == '2')
                      {
                        if(data.guarantor_flag == 'updated')
                        {
                            $("#manual_patient_id").val(data.patient_id);   
                        }
                        
                        $("#manual_homephone").val(data.homephone);
                        if(data.guarantor_flag == 'Added')
                        {
                            $.ajax({
                              url: 'getappoinmnet_srno.php', 
                              type: "POST",
                              data: ({act :'patient',select_data: 'patient'}),
                              dataType:"json",
                              success: function(data){
                                  $("#manual_patient_id").val(data.patient_sr_no);

                              }
                          });
                        }
                        
                      }
                      if(select_data == '3')
                      {
                        //$("#manual_patient_id").val(data.patient_id);
                        $("#manual_apppatient_id").val(data.patient_id).trigger("change");
                        $("#appointment_sr_no").val(data.appointment_sr_no);
                        $("#provider_id").val(data.provider_id);
                        $("#app_date").val(data.app_date);
                        $("#app_time").val(data.app_time);
                        $("#app_length").val(data.app_length);
                        $("#app_amount").val(data.app_amount);
                        $("#app_status").val(data.app_status);


                        if(data.guarantor_flag == 'Added')
                        {
                             $.ajax({
                                  url: 'getappoinmnet_srno.php', 
                                  type: "POST",
                                  data: ({act :'appointments',select_data: 'appointments'}),
                                  dataType:"json",
                                  success: function(data){
                                      $("#appointment_sr_no").val(data.app_sr_no);
                                  }
                              });
                        }

                        if(data.guarantor_flag == 'Deleted')
                        {
                            
                            $("#div_manual_selectguarantor_id").hide();
                            $("#div_manual_guarantor_patient_id").hide();
                            $("#div_provider_id").hide();
                            $("#div_app_date").hide();
                            $("#div_app_time").hide();
                            $("#div_app_length").hide();
                            $("#div_app_amount").hide();
                            $("#div_app_status").hide();
                            $("#div_manual_guarantor_id").hide();
                            $("#div_app_loadedate").hide();
                            $("#div_appointment_sr_no").hide();
                            $("#div_app_submit").hide();
                            for(var pisd = 1; pisd <= 7; pisd++) 
                            {
                              $("#div_app_procedure"+pisd).hide();
                              $("#div_app_procdedure"+pisd+"_catagory_id").hide();
                              $("#app_procedure"+pisd+"_categoryId").hide();
                              $("#div_app_procdedure"+pisd+"_codesikkaid").hide();
                              $("#app_procedure"+pisd+"_codesikkaid").hide();
                              $("#div_app_procdedure"+pisd+"_amount").hide();
                              $("#app_procedure"+pisd+"_amount").hide();
                            }
                        }
                      }
                      $("#manual_guarantor_id").val(data.guarantor_id);
                      $("#manual_guarantor_fname").val(data.guarantor_firstname);
                      $("#manual_guarantor_lname").val(data.guarantor_lastname);
                      $("#manual_birthdate").val(data.guarantor_birthdate);
                      $("#manual_phone").val(data.guarantor_phone);
                      $("#manual_workphone").val(data.guarantor_workphone);
                      $("#manual_cell").val(data.guarantor_cell);
                      $("#manual_email_address").val(data.guarantor_email);
                      $("#manual_loadedate").val(data.guarantor_loadeddate);
                      $("#manual_flag").val(data.guarantor_flag);
                      $("#manual_gender").val(data.guarantor_gender);
                      
                      
                      if(data.guarantor_flag == 'updated')
                      {
                          if(select_data != '3')
                          {
                              $("#div_other_cahnges").show();

                              
                              $("#div_othercahnges_firstname").show();
                              $("#div_othercahnges_lastname").show();
                              $("#div_othercahnges_birthdate").show();
                              if(select_data == '1')
                              {
                                 $("#div_othercahnges_phone").show();
                                 $("#div_othercahnges_guarantor").show();
                                 $("#div_manual_selectguarantor_id").show();
                                 $("#div_manual_guarantor_id").hide();
                              }
                              if(select_data == '2')
                              {
                                 $("#div_othercahnges_homephone").show();
                                 $("#div_othermanual_patientguarantor_id").show();
                                 $("#div_manual_old_patientguarantor_id").show();
                              }
                              $("#div_othercahnges_workphone").show();
                              $("#div_othercahnges_cell").show();
                              $("#div_othercahnges_emailaddress").show();
                              $("#div_othermanual_provider_id").hide();
                              $("#div_othermanual_appstatus").hide();
                              $("#div_othermanual_appdate").hide();
                              $("#div_othermanual_apptime").hide();
                              $("#div_othermanual_amount").hide();
                          }

                          if(select_data == '3')
                          {

                              $("#div_other_cahnges").show();
                              $("#div_othermanual_provider_id").show();
                              $("#div_othermanual_appstatus").show();
                              $("#div_othermanual_appdate").show();
                              $("#div_othermanual_apptime").show();
                              $("#div_othermanual_amount").show();

                               for(var otpi = 1; otpi <= 7; otpi++) 
                               {
                                  $("#div_app_other_procedure"+otpi).show();
                                  $("#div_app_other_procdedure"+otpi+"_catagory_id").show();
                                  $("#app_other_procedure"+otpi+"_categoryId").show();
                                  $("#div_app_other_procdedure"+otpi+"_codesikkaid").show();
                                  $("#app_other_procedure"+otpi+"_codesikkaid").show();
                                  $("#div_app_other_procdedure"+otpi+"_amount").show();
                                  $("#app_other_procedure"+otpi+"_amount").show();
                               }

                              $("#app_procedure1_amount").val(data.procedure_code1_amount);
                              $("#app_procedure2_amount").val(data.procedure_code2_amount);
                              $("#app_procedure3_amount").val(data.procedure_code3_amount);
                              $("#app_procedure4_amount").val(data.procedure_code4_amount);
                              $("#app_procedure5_amount").val(data.procedure_code5_amount);
                              $("#app_procedure6_amount").val(data.procedure_code6_amount);
                              $("#app_procedure7_amount").val(data.procedure_code7_amount);
                              
                              $("#app_procedure1_codesikkaid").append('<option value='+data.procedure_code1+' selected>'+data.procedure_code1+'</option>');

                              $("#app_procedure2_codesikkaid").append('<option value='+data.procedure_code2+' selected>'+data.procedure_code2+'</option>');

                              $("#app_procedure3_codesikkaid").append('<option value='+data.procedure_code3+' selected>'+data.procedure_code3+'</option>');

                              $("#app_procedure4_codesikkaid").append('<option value='+data.procedure_code4+' selected>'+data.procedure_code4+'</option>');

                              $("#app_procedure5_codesikkaid").append('<option value='+data.procedure_code5+' selected>'+data.procedure_code5+'</option>');

                              $("#app_procedure6_codesikkaid").append('<option value='+data.procedure_code6+' selected>'+data.procedure_code6+'</option>');

                              $("#app_procedure7_codesikkaid").append('<option value='+data.procedure_code7+' selected>'+data.procedure_code7+'</option>');
                              
                              
                          }
                          $.each(data.guarantor_changes, function(index, value) 
                          {     
                                if(value.field == 'guarantorid')
                                {
                                    if(select_data == '1')
                                    {
                                        $("#othermanual_guarantor_id").val(value.new_value);
                                        if(data.guarantor_flag == 'updated')
                                        {
                                          $("#manual_selectguarantor_id").val(value.new_value);  
                                        }
                                    }else if(select_data == '2')
                                    {
                                        $("#othermanual_patientguarantor_id").val(value.new_value);
                                        $("#manual_old_patientguarantor_id").val(value.old_value);
                                    }
                                }else if(value.field == 'firstname')
                                {
                                   $("#othermanual_guarantor_fname").val(value.new_value);
                                }else if(value.field == 'lastname')
                                {
                                   $("#othermanual_guarantor_lname").val(value.new_value);
                                }else if(value.field == 'birthdate')
                                {
                                   $("#othermanual_birthdate").val(value.new_value);
                                }else if(value.field == 'phone')
                                {
                                   $("#othermanual_phone").val(value.new_value);
                                }else if(value.field == 'homephone')
                                {
                                   $("#othermanual_homephone").val(value.new_value);
                                }
                                else if(value.field == 'workphone')
                                {
                                   $("#othermanual_workphone").val(value.new_value);
                                }else if(value.field == 'cell')
                                {
                                   $("#otehrmanual_cell").val(value.new_value);
                                }else if(value.field == 'email')
                                {
                                   $("#othermanual_email_address").val(value.new_value);
                                }else if(value.field == 'provider_id')
                                {
                                   $("#othermanual_provider_id").val(value.new_value);
                                }else if(value.field == 'status')
                                {
                                   $("#othermanual_appstatus").val(value.new_value);
                                }else if(value.field == 'date')
                                {
                                   $("#othermanual_appdate").val(value.new_value);
                                }else if(value.field == 'time')
                                {
                                   $("#othermanual_apptime").val(value.new_value);
                                }else if(value.field == 'amount')
                                {
                                   $("#othermanual_amount").val(value.new_value);
                                }

                          });
                      }

                      if(data.guarantor_flag == 'Deleted' && select_data != '3')
                      {
                        $("#div_manual_guarantor_id").hide();
                        $("#div_manual_selectguarantor_id").show();
                        $("#div_manual_guarantor_patient_id").show();
                      }

                  }
       });
    });
    
    $("#search_patient").keypress(function(event)
    {
      if(event.which == '13')
      {
        $( "#search_patient" ).blur();
      }
    });

    $("#search_patient").blur(function()
    {
      if($("#clinic_id").val()==""){
        $("#msg_clinic_data").html('Please select Clinic');
        $("#msg_clinic_data").show();
        return false;
      }else{
        $("#msg_clinic_data").html('');
        $("#msg_clinic_data").hide();
      }

        var search_patient = $("#search_patient").val();
        var clinic_id = $("#clinic_id").val();
        $("#div_search_patient_data").html('');
        $.ajax
        ({
            url: 'manual_entry.php', 
            type: "POST",
            dataType: 'json',
            cache: false,
            data: ({act:'getdependant',search_patient: search_patient,clinic_id:clinic_id}),
            success: function(data){
                $("#div_search_patient_data").show();  
                var len = data.dependant.length;
                
                for (i = 0; i < len; i++) 
                {
                   $("#div_search_patient_data").append(data.dependant[i]);
                }

                /*$.each(data.dependant,function(i,v){
                     console.log(v);
                     $("#div_search_patient_data").val(v);
                     //$('.admin_id').val(v.user_id);//use val to append the value, note you have multiple ids so you need multiple inputs 
                });*/
                
            }
        });

    });

    $("#manual_apppatient_id").on('change',function(){

        var ClinicId = $("#clinic_id").val();
        var apppatientid = $("#manual_apppatient_id").val(); 
        var manual_flag = $("#manual_flag").val();

        $("#div_appoinment_data").html('');
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            dataType: 'json',
            cache: false,
            data: ({act:"getappoinmnet",clinic_id: ClinicId,apppatientid:apppatientid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#div_appoinment_data").show();  
                var len = data.appointments.length;
                
                for (i = 0; i < len; i++) 
                {
                   $("#div_appoinment_data").append(data.appointments[i]);
                }

                if(manual_flag == 'Completed')
                {
                    //$("#div_appoinment_data").append("<div class='col-md-12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' class='btn btn-primary' name='completed' id='completed' value='Completed'/></div>");
                    $("#div_app_completed").show();
                }else if(manual_flag == 'Deleted')
                {
                    $("#div_appoinment_data").append("<div class='col-md-12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' class='btn btn-primary' name='canceled' id='canceled' value='Delete/Cancel'/></div>");

                    $("#div_appointment_sr_no").hide();
                    $("#div_provider_id").hide();
                    $("#div_app_date").hide();
                    $("#div_app_time").hide();
                    $("#div_app_length").hide();
                    $("#div_app_amount").hide();
                    $("#div_app_status").hide();
                    $("#div_app_loadedate").hide();
                    $("#div_app_submit").hide();
                }



            }
          });
        }
        
    });

    $("#manual_selectguarantor_id").on('change',function(){
        var select_data = $("#select_data").val();
        var ClinicId = $("#clinic_id").val();
        var manual_flag = $("#manual_flag").val();
        var selectguarantor_id = $("#manual_selectguarantor_id").val();

        if(manual_flag == 'Deleted' && select_data == '1')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            /*dataType: 'json',
            cache: false,*/
            data: ({act:"getpatient",selectguarantor_id: selectguarantor_id,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#manual_guarantor_patient_id").html(data);
            }
          });
        }
        
    });

    $("#app_procedure1_categoryId").on('change',function(){

        var ClinicId = $("#clinic_id").val();
        var categoryid = $("#app_procedure1_categoryId").val(); 
        var manual_flag = $("#manual_flag").val();

       
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure1_codesikkaid").html(data);  
                
            }
          });
        }else if(manual_flag == 'Added'){
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure1_codesikkaid").html(data);  
                
            }
          });
        }
        
    });

    $("#app_procedure2_categoryId").on('change',function(){
        
        var ClinicId = $("#clinic_id").val();
        var categoryid = $("#app_procedure2_categoryId").val(); 
        var manual_flag = $("#manual_flag").val();

        $("#div_appoinment_data").html('');
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure2_codesikkaid").html(data);  
                
            }
          });
        }else if(manual_flag == 'Added'){
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure2_codesikkaid").html(data);  
                
            }
          });
        }
        
    });


    $("#app_procedure3_categoryId").on('change',function(){
        
        var ClinicId = $("#clinic_id").val();
        var categoryid = $("#app_procedure3_categoryId").val(); 
        var manual_flag = $("#manual_flag").val();

        
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure3_codesikkaid").html(data);  
                
            }
          });
        }else if(manual_flag == 'Added'){
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure3_codesikkaid").html(data);  
                
            }
          });
        }
        
    });

    $("#app_procedure4_categoryId").on('change',function(){
        
        var ClinicId = $("#clinic_id").val();
        var categoryid = $("#app_procedure4_categoryId").val(); 
        var manual_flag = $("#manual_flag").val();

        
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure4_codesikkaid").html(data);  
                
            }
          });
        }else if(manual_flag == 'Added'){
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure4_codesikkaid").html(data);  
                
            }
          });
        }
        
    });

    $("#app_procedure5_categoryId").on('change',function(){
        
        var ClinicId = $("#clinic_id").val();
        var categoryid = $("#app_procedure5_categoryId").val(); 
        var manual_flag = $("#manual_flag").val();

        $("#div_appoinment_data").html('');
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure5_codesikkaid").html(data);  
                
            }
          });
        }else if(manual_flag == 'Added'){
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure5_codesikkaid").html(data);  
                
            }
          });
        }
        
    });

    $("#app_procedure6_categoryId").on('change',function(){
        
        var ClinicId = $("#clinic_id").val();
        var categoryid = $("#app_procedure6_categoryId").val(); 
        var manual_flag = $("#manual_flag").val();

        $("#div_appoinment_data").html('');
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure6_codesikkaid").html(data);  
                
            }
          });
        }else if(manual_flag == 'Added'){
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure6_codesikkaid").html(data);  
                
            }
          });
        }
        
    });

    $("#app_procedure7_categoryId").on('change',function(){
        
        var ClinicId = $("#clinic_id").val();
        var categoryid = $("#app_procedure7_categoryId").val(); 
        var manual_flag = $("#manual_flag").val();

        $("#div_appoinment_data").html('');
        if(manual_flag != 'Added')
        {
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure7_codesikkaid").html(data);  
                
            }
          });
        }else if(manual_flag == 'Added'){
          $.ajax({
            url: "manual_entry.php", 
            type: "POST",
            //dataType: 'json',
            //cache: false,
            data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
            success: function(data)
            {
                //console.log(data);
                $("#app_procedure7_codesikkaid").html(data);  
                
            }
          });
        }
        
    });

    
    $("#app_other_procedure1_categoryId").on('change',function(){
      
      var ClinicId = $("#clinic_id").val();
      var categoryid = $("#app_other_procedure1_categoryId").val(); 
      var manual_flag = $("#manual_flag").val();

      $("#div_appoinment_data").html('');
      if(manual_flag != 'Added')
      {
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure1_codesikkaid").html(data);  
              
          }
        });
      }else if(manual_flag == 'Added'){
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure1_codesikkaid").html(data);  
              
          }
        });
      }
    });

    $("#app_other_procedure2_categoryId").on('change',function(){
      
      var ClinicId = $("#clinic_id").val();
      var categoryid = $("#app_other_procedure2_categoryId").val(); 
      var manual_flag = $("#manual_flag").val();

      $("#div_appoinment_data").html('');
      if(manual_flag != 'Added')
      {
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure2_codesikkaid").html(data);  
              
          }
        });
      }else if(manual_flag == 'Added'){
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure2_codesikkaid").html(data);  
              
          }
        });
      }
    });

    $("#app_other_procedure3_categoryId").on('change',function(){
      
      var ClinicId = $("#clinic_id").val();
      var categoryid = $("#app_other_procedure3_categoryId").val(); 
      var manual_flag = $("#manual_flag").val();

      $("#div_appoinment_data").html('');
      if(manual_flag != 'Added')
      {
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure3_codesikkaid").html(data);  
              
          }
        });
      }else if(manual_flag == 'Added'){
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure3_codesikkaid").html(data);  
              
          }
        });
      }
    });

    $("#app_other_procedure4_categoryId").on('change',function(){
      
      var ClinicId = $("#clinic_id").val();
      var categoryid = $("#app_other_procedure4_categoryId").val(); 
      var manual_flag = $("#manual_flag").val();

      $("#div_appoinment_data").html('');
      if(manual_flag != 'Added')
      {
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure4_codesikkaid").html(data);  
              
          }
        });
      }else if(manual_flag == 'Added'){
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure4_codesikkaid").html(data);  
              
          }
        });
      }
    });

    $("#app_other_procedure5_categoryId").on('change',function(){
      
      var ClinicId = $("#clinic_id").val();
      var categoryid = $("#app_other_procedure5_categoryId").val(); 
      var manual_flag = $("#manual_flag").val();

      $("#div_appoinment_data").html('');
      if(manual_flag != 'Added')
      {
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure5_codesikkaid").html(data);  
              
          }
        });
      }else if(manual_flag == 'Added'){
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure5_codesikkaid").html(data);  
              
          }
        });
      }
    });

    $("#app_other_procedure6_categoryId").on('change',function(){
      
      var ClinicId = $("#clinic_id").val();
      var categoryid = $("#app_other_procedure6_categoryId").val(); 
      var manual_flag = $("#manual_flag").val();

      $("#div_appoinment_data").html('');
      if(manual_flag != 'Added')
      {
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure6_codesikkaid").html(data);  
              
          }
        });
      }else if(manual_flag == 'Added'){
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure6_codesikkaid").html(data);  
              
          }
        });
      }
    });

    $("#app_other_procedure7_categoryId").on('change',function(){
      
      var ClinicId = $("#clinic_id").val();
      var categoryid = $("#app_other_procedure7_categoryId").val(); 
      var manual_flag = $("#manual_flag").val();

      $("#div_appoinment_data").html('');
      if(manual_flag != 'Added')
      {
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure7_codesikkaid").html(data);  
              
          }
        });
      }else if(manual_flag == 'Added'){
        $.ajax({
          url: "manual_entry.php", 
          type: "POST",
          data: ({act:"getproceduresikkaid",clinic_id: ClinicId,categoryid:categoryid,flag_data:manual_flag}),
          success: function(data)
          {
              //console.log(data);
              $("#app_other_procedure7_codesikkaid").html(data);  
              
          }
        });
      }
    });

    $('form').on('keypress', function(e) {
      
      // patient search enter not submited form
      if (e.which === 13) {
        //console.log("inside if which");
        return false;
      }
    });

    $( "form" ).on( "submit", function(e) {
        
        var completed = $("#completed").val();
        var canceled = $("#canceled").val();
        var appoinmnet_name = new Array();
        $("input:checked").each(function() {
           appoinmnet_name.push($(this).val());
        });
        

        e.preventDefault();
        if($("#manual_flag").val() == 'updated' && $("#select_data").val() == '1')
        {
          var manual_guarantor_id = $("#manual_selectguarantor_id").val();
        }else if($("#manual_flag").val() != 'updated' && $("#select_data").val() == '1')
        {
          var manual_guarantor_id = $("#manual_guarantor_id").val();
        }
        
        var select_data = $("#select_data").val();
        var clinic_id = $("#clinic_id").val();
        var manual_patient_id = $("#manual_patient_id").val();
        //var manual_guarantor_id = $("#manual_guarantor_id").val();
        var manual_guarantor_fname = $("#manual_guarantor_fname").val();
        var manual_guarantor_lname = $("#manual_guarantor_lname").val();
        var manual_birthdate = $("#manual_birthdate").val();
        var manual_phone = $("#manual_phone").val();
        var manual_workphone = $("#manual_workphone").val();
        var manual_cell = $("#manual_cell").val();
        var manual_email_address = $("#manual_email_address").val();
        var manual_loadedate = $("#manual_loadedate").val();
        var manual_flag = $("#manual_flag").val();
        var manual_gender = $("#manual_gender").val();
        var othermanual_guarantor_id = $("#othermanual_guarantor_id").val();
        var othermanual_guarantor_fname = $("#othermanual_guarantor_fname").val();
        var othermanual_guarantor_lname = $("#othermanual_guarantor_lname").val();
        var othermanual_birthdate = $("#othermanual_birthdate").val();
        var othermanual_phone = $("#othermanual_phone").val();
        var othermanual_workphone = $("#othermanual_workphone").val();
        var otehrmanual_cell = $("#otehrmanual_cell").val();
        var othermanual_email_address = $("#othermanual_email_address").val();
        var homephone = $("#manual_homephone").val();
        var othermanual_homephone = $("#othermanual_homephone").val();
        var appointment_sr_no = $("#appointment_sr_no").val();
        var provider_id = $("#provider_id").val();
        var app_date = $("#app_date").val();
        var app_time = $("#app_time").val();
        var app_length = $("#app_length").val();
        var app_amount = $("#app_amount").val();
        var app_status = $("#app_status").val();
        var othermanual_provider_id = $("#othermanual_provider_id").val();
        var othermanual_appstatus = $("#othermanual_appstatus").val();
        var othermanual_appdate = $("#othermanual_appdate").val();
        var othermanual_apptime = $("#othermanual_apptime").val();
        var othermanual_amount = $("#othermanual_amount").val();
        var manual_apppatient_id = $("#manual_apppatient_id").val();
        var manual_patientguarantor_id = $("#manual_patientguarantor_id").val();
        var othermanual_patientguarantor = $("#othermanual_patientguarantor_id").val();
        var manual_guarantor_patient_id = $("#manual_guarantor_patient_id").val();
        var manual_old_patientguarantor_id = $("#manual_old_patientguarantor_id").val();
        var app_procedure1_categoryId = $("#app_procedure1_categoryId").val();
        var app_procedure1_codesikkaid = $("#app_procedure1_codesikkaid").val();
        var app_procedure1_amount = $("#app_procedure1_amount").val();

        var app_procedure2_categoryId = $("#app_procedure2_categoryId").val();
        var app_procedure2_codesikkaid = $("#app_procedure2_codesikkaid").val();
        var app_procedure2_amount = $("#app_procedure2_amount").val();

        var app_procedure3_categoryId = $("#app_procedure3_categoryId").val();
        var app_procedure3_codesikkaid = $("#app_procedure3_codesikkaid").val();
        var app_procedure3_amount = $("#app_procedure3_amount").val();

        var app_procedure4_categoryId = $("#app_procedure4_categoryId").val();
        var app_procedure4_codesikkaid = $("#app_procedure4_codesikkaid").val();
        var app_procedure4_amount = $("#app_procedure4_amount").val();

        var app_procedure5_categoryId = $("#app_procedure5_categoryId").val();
        var app_procedure5_codesikkaid = $("#app_procedure5_codesikkaid").val();
        var app_procedure5_amount = $("#app_procedure5_amount").val();

        var app_procedure6_categoryId = $("#app_procedure6_categoryId").val();
        var app_procedure6_codesikkaid = $("#app_procedure6_codesikkaid").val();
        var app_procedure6_amount = $("#app_procedure6_amount").val();

        var app_procedure7_categoryId = $("#app_procedure7_categoryId").val();
        var app_procedure7_codesikkaid = $("#app_procedure7_codesikkaid").val();
        var app_procedure7_amount = $("#app_procedure7_amount").val();

        var app_other_procedure1_codesikkaid = $("#app_other_procedure1_codesikkaid").val();
        var app_other_procedure1_amount = $("#app_other_procedure1_amount").val();

        var app_other_procedure2_codesikkaid = $("#app_other_procedure2_codesikkaid").val();
        var app_other_procedure2_amount = $("#app_other_procedure2_amount").val();

        var app_other_procedure3_codesikkaid = $("#app_other_procedure3_codesikkaid").val();
        var app_other_procedure3_amount = $("#app_other_procedure3_amount").val();

        var app_other_procedure4_codesikkaid = $("#app_other_procedure4_codesikkaid").val();
        var app_other_procedure4_amount = $("#app_other_procedure4_amount").val();

        var app_other_procedure5_codesikkaid = $("#app_other_procedure5_codesikkaid").val();
        var app_other_procedure5_amount = $("#app_other_procedure5_amount").val();

        var app_other_procedure6_codesikkaid = $("#app_other_procedure6_codesikkaid").val();
        var app_other_procedure6_amount = $("#app_other_procedure6_amount").val();

        var app_other_procedure7_codesikkaid = $("#app_other_procedure7_codesikkaid").val();
        var app_other_procedure7_amount = $("#app_other_procedure7_amount").val();

        if(manual_flag == 'updated')
        {
            if(manual_guarantor_id != othermanual_guarantor_id && othermanual_guarantor_id != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please guarantor id not same.</div>");
              return false;
            }else if(manual_guarantor_fname != othermanual_guarantor_fname && othermanual_guarantor_fname != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please firstname not same.</div>");
              return false;
            }else if(manual_guarantor_lname != othermanual_guarantor_lname && othermanual_guarantor_lname != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please lastname not same.</div>");
              return false;
            }else if(manual_birthdate != othermanual_birthdate && othermanual_birthdate != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please birthdate not same.</div>");
              return false;
            }else if(manual_phone != othermanual_phone && othermanual_phone != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please phone not same.</div>");
              return false;
            }else if(manual_workphone != othermanual_workphone && othermanual_workphone != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please workphone not same.</div>");
              return false;
            }else if(manual_cell != otehrmanual_cell && otehrmanual_cell != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please cell not same.</div>");
              return false;
            }else if(manual_email_address != othermanual_email_address && othermanual_email_address != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please emailaddress not same.</div>");
              return false;
            }else if(homephone != othermanual_homephone && othermanual_homephone != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>please homephone not same.</div>");
              return false;
            }
            else if(provider_id != othermanual_provider_id && othermanual_provider_id != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>provider id not same.</div>");
              return false;
            }
            else if(app_status != othermanual_appstatus && othermanual_appstatus != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Status not same.</div>");
              return false;
            }else if(app_date != othermanual_appdate && othermanual_appdate != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Date not same.</div>");
              return false;
            }else if(app_time != othermanual_apptime && othermanual_apptime != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Time not same.</div>");
              return false;
            }else if(app_amount != othermanual_amount && othermanual_amount != '')
            {
              $("#alert_msg").show();
              $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Amount not same.</div>");
              return false;
            }else if(manual_patientguarantor_id != othermanual_patientguarantor && othermanual_patientguarantor != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>GuarantorId not same.</div>");
                return false;
            }
            else if(othermanual_patientguarantor != '' && manual_old_patientguarantor_id == '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please Select Old GuarantorId.</div>");
                return false;
            }
            else if(app_procedure1_codesikkaid != app_other_procedure1_codesikkaid && app_other_procedure1_codesikkaid != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Code 1 not same.</div>");
                return false;
            }

            else if(app_procedure2_codesikkaid != app_other_procedure2_codesikkaid && app_other_procedure2_codesikkaid != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Code 2 not same.</div>");
                return false;
            }

            else if(app_procedure3_codesikkaid != app_other_procedure3_codesikkaid && app_other_procedure3_codesikkaid != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Code 3 not same.</div>");
                return false;
            }

            else if(app_procedure4_codesikkaid != app_other_procedure4_codesikkaid && app_other_procedure4_codesikkaid != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Code 4 not same.</div>");
                return false;
            }

            else if(app_procedure5_codesikkaid != app_other_procedure5_codesikkaid && app_other_procedure5_codesikkaid != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Code 5 not same.</div>");
                return false;
            }

            else if(app_procedure6_codesikkaid != app_other_procedure6_codesikkaid && app_other_procedure6_codesikkaid != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Code 6 not same.</div>");
                return false;
            }

            else if(app_procedure7_codesikkaid != app_other_procedure7_codesikkaid && app_other_procedure7_codesikkaid != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Code 7 not same.</div>");
                return false;
            }

            else if(app_procedure1_amount != app_other_procedure1_amount && app_other_procedure1_amount != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Amount 1 not same.</div>");
                return false;
            }

            else if(app_procedure2_amount != app_other_procedure2_amount && app_other_procedure2_amount != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Amount 2 not same.</div>");
                return false;
            }
            else if(app_procedure3_amount != app_other_procedure3_amount && app_other_procedure3_amount != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Amount 3 not same.</div>");
                return false;
            }
            else if(app_procedure4_amount != app_other_procedure4_amount && app_other_procedure4_amount != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Amount 4 not same.</div>");
                return false;
            }
            else if(app_procedure5_amount != app_other_procedure5_amount && app_other_procedure5_amount != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Amount 5 not same.</div>");
                return false;
            }
            else if(app_procedure6_amount != app_other_procedure6_amount && app_other_procedure6_amount != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Amount 6 not same.</div>");
                return false;
            }
            else if(app_procedure7_amount != app_other_procedure7_amount && app_other_procedure7_amount != '')
            {
                $("#alert_msg").show();
                $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Procedure Amount 7 not same.</div>");
                return false;
            }
        }
        
         //$(".loader-bubble").show();
         $(".loader").show();
          
         $.ajax({
            url: "manual_entry.php?act=load&select_data="+select_data+"&clinic_id="+clinic_id+"&manual_guarantor_id="+manual_guarantor_id+"&manual_guarantor_fname="+manual_guarantor_fname+"&manual_guarantor_lname="+manual_guarantor_lname+"&manual_birthdate="+manual_birthdate+"&manual_phone="+manual_phone+"&manual_workphone="+manual_workphone+"&manual_cell="+manual_cell+"&manual_email_address="+manual_email_address+"&manual_loadedate="+manual_loadedate+"&manual_loadedate="+manual_loadedate+"&manual_flag="+manual_flag+"&manual_gender="+manual_gender+"&othermanual_guarantor_id="+othermanual_guarantor_id+"&othermanual_guarantor_fname="+othermanual_guarantor_fname+"&othermanual_guarantor_lname="+othermanual_guarantor_lname+"&othermanual_birthdate="+othermanual_birthdate+"&othermanual_phone="+othermanual_phone+"&othermanual_workphone="+othermanual_workphone+"&otehrmanual_cell="+otehrmanual_cell+"&othermanual_email_address="+othermanual_email_address+"&manual_patient_id="+manual_patient_id+"&homephone="+homephone+"&othermanual_homephone="+othermanual_homephone+"&appointment_sr_no="+appointment_sr_no+"&provider_id="+provider_id+"&app_date="+app_date+"&app_time="+app_time+"&app_length="+app_length+"&app_amount="+app_amount+"&app_status="+app_status+"&othermanual_provider_id="+othermanual_provider_id+"&othermanual_appstatus="+othermanual_appstatus+"&othermanual_appdate="+othermanual_appdate+"&othermanual_apptime="+othermanual_apptime+"&othermanual_amount="+othermanual_amount+"&manual_apppatient_id="+manual_apppatient_id+"&manual_patientguarantor_id="+manual_patientguarantor_id+"&othermanual_patientguarantor="+othermanual_patientguarantor+"&completed="+completed+"&canceled="+canceled+"&appoinmnet_name="+appoinmnet_name+"&manual_guarantor_patient_id="+manual_guarantor_patient_id+"&manual_old_patientguarantor_id="+manual_old_patientguarantor_id+"&app_procedure1_categoryId="+app_procedure1_categoryId+"&app_procedure1_codesikkaid="+app_procedure1_codesikkaid+"&app_procedure2_categoryId="+app_procedure2_categoryId+"&app_procedure2_codesikkaid="+app_procedure2_codesikkaid+"&app_procedure3_categoryId="+app_procedure3_categoryId+"&app_procedure3_codesikkaid="+app_procedure3_codesikkaid+"&app_procedure4_categoryId="+app_procedure4_categoryId+"&app_procedure4_codesikkaid="+app_procedure4_codesikkaid+"&app_procedure5_categoryId="+app_procedure5_categoryId+"&app_procedure5_codesikkaid="+app_procedure5_codesikkaid+"&app_procedure6_categoryId="+app_procedure6_categoryId+"&app_procedure6_codesikkaid="+app_procedure6_codesikkaid+"&app_procedure7_categoryId="+app_procedure7_categoryId+"&app_procedure7_codesikkaid="+app_procedure7_codesikkaid+"&app_procedure1_amount="+app_procedure1_amount+"&app_procedure2_amount="+app_procedure2_amount+"&app_procedure3_amount="+app_procedure3_amount+"&app_procedure4_amount="+app_procedure4_amount+"&app_procedure5_amount="+app_procedure5_amount+"&app_procedure6_amount="+app_procedure6_amount+"&app_procedure7_amount="+app_procedure7_amount+"&app_other_procedure1_codesikkaid="+app_other_procedure1_codesikkaid+"&app_other_procedure2_codesikkaid="+app_other_procedure2_codesikkaid+"&app_other_procedure3_codesikkaid="+app_other_procedure3_codesikkaid+"&app_other_procedure4_codesikkaid="+app_other_procedure4_codesikkaid+"&app_other_procedure5_codesikkaid="+app_other_procedure5_codesikkaid+"&app_other_procedure6_codesikkaid="+app_other_procedure6_codesikkaid+"&app_other_procedure7_codesikkaid="+app_other_procedure7_codesikkaid+"&app_other_procedure1_amount="+app_other_procedure1_amount+"&app_other_procedure2_amount="+app_other_procedure2_amount+"&app_other_procedure3_amount="+app_other_procedure3_amount+"&app_other_procedure4_amount="+app_other_procedure4_amount+"&app_other_procedure5_amount="+app_other_procedure5_amount+"&app_other_procedure6_amount="+app_other_procedure6_amount+"&app_other_procedure7_amount="+app_other_procedure7_amount,
            type:'POST',
            //data: postData,
            dataType: 'json',
            success: function(data){
              
              if(data.msg == 'successd')
              {
                var clinic_id = data.clinic_id;
                
                var url = data.SITE_URL;
                var flag_data = data.flag_data;

               // window.open(url, "_blank");
                //location.reload();
                $("#status_msg").show();
                $("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Pms Entry Successfully...</div>");
                //hideMessage();
                //$(window).scrollTop(0);
                setTimeout(function(){// wait for 5 secs(2)
                     //location.reload(); // then reload the page.(3)
                     hideMessage();
                }, 500); 
                $("#frm-user")[0].reset();
                $("#manual_apppatient_id").val("").trigger('change');
                $("#div_search_patient_data").hide();
                
                $('.manual_iframe').html('<br/><iframe src="'+url+'"  style="height:200px;width:100%;border:none;overflow:hidden;" id="myIframe" name="myIframe"></iframe>');
                $(".loader").hide();

                if(flag_data == 'Completed' || flag_data == 'Deleted')
                {
                    $("#div_appointment_sr_no").show();
                    $("#div_provider_id").show();
                    $("#div_app_date").show();
                    $("#div_app_time").show();
                    $("#div_app_length").show();
                    $("#div_app_amount").show();
                    $("#div_app_status").show();
                    $("#div_app_loadedate").show();
                    $("#div_app_submit").show();
                    $("#div_app_completed").hide();
                    if(flag_data == 'Completed')
                    {
                       $('.manual_iframe').html('<br/>'+data.response_msg);    
                    }
                    
                }
               
                //$(".loader-bubble").hide();
              }
            }
         });
    });
     
});


function getdependant_data(depId)
{
  $.ajax({
          url: "manual_entry.php",
          data: 'act=searchdependantId&depId='+depId,
          dataType: 'json',
          cache: false,
          success: function(data)
          {
              $("#manual_guarantor_fname").val(data.dependant.dependant_fname);
              $("#manual_guarantor_lname").val(data.dependant.dependant_lname);
              $("#manual_birthdate").val(data.dependant.dependant_dob);
              $("#manual_cell").val(data.dependant.dependant_phone);
              $("#manual_email_address").val(data.dependant.dependant_email_address);
              $("#manual_gender").val(data.dependant.dependant_gender);
          }
      });
}

function getappoinment_data(pmsAppoinmnetId)
{
  $.ajax({
          url: "manual_entry.php",
          data: 'act=getappoinmnetId&pmsAppoinmnetId='+pmsAppoinmnetId,
          dataType: 'json',
          cache: false,
          success: function(data)
          {
              $("#appointment_sr_no").val(data.appointmentdata.pmsAppointment_sr_no);
              /*$("#manual_apppatient_id").val(data.appointmentdata.pmsAppointment_patient_id).trigger('change');*/
              $("#provider_id").val(data.appointmentdata.pmsAppointment_provider_id);
              $("#app_date").val(data.appointmentdata.pmsAppointment_date);
              $("#app_time").val(data.appointmentdata.pmsAppointment_time);
              $("#app_length").val(data.appointmentdata.pmsAppointment_length);
              $("#app_amount").val(data.appointmentdata.pmsAppointment_amount);
              $("#app_status").val(data.appointmentdata.pmsAppointment_status);
              
          }
      });
}

function getappoinment_data(pmsAppoinmnetId)
{
  $.ajax({
          url: "manual_entry.php",
          data: 'act=getappoinmnetId&pmsAppoinmnetId='+pmsAppoinmnetId,
          dataType: 'json',
          cache: false,
          success: function(data)
          {
              $("#appointment_sr_no").val(data.appointmentdata.pmsAppointment_sr_no);
              /*$("#manual_apppatient_id").val(data.appointmentdata.pmsAppointment_patient_id).trigger('change');*/
              $("#provider_id").val(data.appointmentdata.pmsAppointment_provider_id);
              $("#app_date").val(data.appointmentdata.pmsAppointment_date);
              $("#app_time").val(data.appointmentdata.pmsAppointment_time);
              $("#app_length").val(data.appointmentdata.pmsAppointment_length);
              $("#app_amount").val(data.appointmentdata.pmsAppointment_amount);
              $("#app_status").val(data.appointmentdata.pmsAppointment_status);
              
          }
      });
}
</script>
<?php //} ?>