<script type="text/javascript">
$(document).ready(function(){
	$("#frm-patient").submit(function(e){
            if(!validate_patient()){
                e.preventDefault();
            }
	});
        $("#patient_email_address").blur(function(){
            var email = $("#patient_email_address");
            var emailmsg = $("#msg_patient_email_address");
            if(email.val()==""){
                email.addClass('error');email.focus();emailmsg.html('Please enter email address').show();
                return false;
            }
            if($("#patient_id").length > 0){var patient_id = $("#patient_id").val();
            }else{var patient_id = '';}
            $("#submit").prop('disabled', true);
            $.ajax({
                url: "patientadd.php",
                data: 'act=validate_email&email='+email.val()+'&patient_id='+patient_id,
                method: 'POST',
                success: function(msg){
                    if(msg!=''){
                        email.addClass('error');email.focus();emailmsg.html(msg).show();
                        return false;
                    }else{
                        $("#submit").prop('disabled', false);
                        email.removeClass('error');emailmsg.hide();
                    }
                }
            });
	});
        $("#patient_phone").blur(function(){
            var phone = $("#patient_phone");
            var phonemsg = $("#msg_patient_phone");
            if(phone.val()==""){
                phone.addClass('error');phone.focus();phonemsg.html('Please enter phone').show();
                return false;
            }
            if($("#patient_id").length > 0){var patient_id = $("#patient_id").val();
            }else{var patient_id = '';}
            $("#submit").prop('disabled', true);
            $.ajax({
                url: "patientadd.php",
                data: 'act=validate_phone&phone='+phone.val()+'&patient_id='+patient_id,
                method: 'POST',
                success: function(msg){
                    if(msg!=''){
                        phone.addClass('error');phone.focus();phonemsg.html(msg).show();
                        return false;
                    }else{
                        $("#submit").prop('disabled', false);
                        phone.removeClass('error');emailmsg.hide();
                    }
                }
            });
    });
	
});
function validate_patient(){
	var fname = $("#patient_fname");var fnamemsg = $("#msg_patient_fname");
	var lname = $("#patient_lname");var lnamemsg = $("#msg_patient_lname");
	var email = $("#patient_email_address");var emailmsg = $("#msg_patient_email_address");
	var phone = $("#patient_phone");var phonemsg = $("#msg_patient_phone");
	var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;
        if(fname.val()==''){fname.addClass('error');fname.focus();fnamemsg.html('Please enter first name').show();
            return false;
	}else{fname.removeClass('error');fnamemsg.hide();}
        if(lname.val()==''){lname.addClass('error');lname.focus();lnamemsg.html('Please enter last name').show();return false;
	}else{lname.removeClass('error');lnamemsg.hide();}
        if(email.val()==''){
          email.addClass('error');email.focus();emailmsg.html('Please enter email address').show();return false;
	}else if(email.val()!='' && !(emailFilter.test(email.val())) ){
	    email.addClass('error');email.focus();emailmsg.html('Please enter valid email address').show();return false;
	}
        if(phone.val()==''){phone.addClass('error');phone.focus();phonemsg.html('Please enter phone number').show();return false;
        }else{phone.removeClass('error');phonemsg.hide();}
       return true;
}

</script>
<div class="breadcrumb">
    <h1>Patientss</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Add New Patients</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Add New Patients</div>
                <form action="" id='frm-patient' method="post" enctype="multipart/form-data">
                    <?php if(isset($patientDetail->patient_id) && $patientDetail->patient_id!=0) { ?>
                       <input type="hidden" id="patient_id" name="patient_id" value="<?php echo $patientDetail->patient_id ?>" />
                    <?php } ?>
                    <div class="row">
                    	<div class="col-md-6 form-group mb-3">
                            <label for="patient_fname">First name <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_fname" name="patient_fname" value="<?php echo $patientDetail->patient_fname; ?>" placeholder="Enter first name">
                            <div class="invalid-tooltip" id="msg_patient_fname"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_lname">Last name <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_lname" name="patient_lname" value="<?php echo $patientDetail->patient_lname; ?>" placeholder="Enter last name">
                            <div class="invalid-tooltip" id="msg_patient_lname"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_email_address">Email address <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_email_address" name="patient_email_address" value="<?php echo $patientDetail->patient_email_address; ?>" placeholder="Enter email address">
                            <div class="invalid-tooltip" id="msg_patient_email_address"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_phone">Phone <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_phone" name="patient_phone" value="<?php echo $patientDetail->patient_phone; ?>" placeholder="Enter Phone">
                            <div class="invalid-tooltip" id="msg_patient_phone"></div>
                        </div>
                        <?php if(!isset($patientDetail->patientadmin_password) || $patientDetail->patientadmin_password==''){ ?>

                       <div class="col-md-6 form-group mb-3">
                            <label for="patient_password">Password <span class="asterisk">*</span></label>
                            <input type="password" class="form-control" id="patient_password" name="patient_password" placeholder="Enter your password">
                            <div class="invalid-tooltip" id="msg_patient_password"></div>
                        </div>

                       <div class="col-md-6 form-group mb-3">
                            <label for="patient_repassword">Password <span class="asterisk">*</span></label>
                            <input type="password" class="form-control" id="patient_repassword" name="patient_repassword" placeholder="Enter your password again">
                            <div class="invalid-tooltip" id="msg_patient_repassword"></div>
                        </div>

                        <?php } ?>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_dob">Date Of Birth <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_dob" name="patient_phone" value="<?php echo $patientDetail->patient_dob; ?>" placeholder="Enter Date of birth">
                            <div class="invalid-tooltip" id="msg_patient_dob"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_gender">Gender <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_gender" name="patient_gender" value="<?php echo $patientDetail->patient_gender; ?>" placeholder="Enter Gender">
                            <div class="invalid-tooltip" id="msg_patient_gender"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_addressline1">Address Line 1 <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_addressline1" name="patient_addressline1" value="<?php echo $patientDetail->patient_addressline1; ?>" placeholder="Enter Address Line 1">
                            <div class="invalid-tooltip" id="msg_patient_addressline1"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_addressline2">Address Line 2 <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_addressline2" name="patient_addressline2" value="<?php echo $patientDetail->patient_addressline2; ?>" placeholder="Enter Address Line 1">
                            <div class="invalid-tooltip" id="msg_patient_addressline2"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_country">Country <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_country" name="patient_country" value="<?php echo $patientDetail->patient_country; ?>" placeholder="Enter country">
                            <div class="invalid-tooltip" id="msg_patient_country"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_state">State <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_state" name="patient_state" value="<?php echo $patientDetail->patient_state; ?>" placeholder="Enter State">
                            <div class="invalid-tooltip" id="msg_patient_state"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_city">City <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_city" name="patient_city" value="<?php echo $patientDetail->patient_city; ?>" placeholder="Enter City">
                            <div class="invalid-tooltip" id="msg_patient_city"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="patient_postal_code">Postal Code <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="patient_postal_code" name="patient_postal_code" value="<?php echo $patientDetail->patient_postal_code; ?>" placeholder="Enter Postal Code">
                            <div class="invalid-tooltip" id="msg_patient_postal_code"></div>
                        </div>
                        <div class="col-md-3 form-group mb-3">
                            <label class="control-label">Status</label>
                            <div class="controls">

                            <label class="switch switch-primary mr-3">
                                <input type="checkbox" id="patient_status" name="patient_status" <?php echo ($patientDetail->patient_status=='1') ? "checked='checked'" : "" ?>>
                                <span class="slider"></span>
                            </label>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>