<script type="text/javascript">
$(document).ready(function(){
	$("#frm-clinicsetting").submit(function(e){
            if(!validate_practice()){
                e.preventDefault();
            }
	});

    var maxField = 5; //Input fields increment limitation
    var addButton = $('.add_button'); //Add button selector
    var wrapper = $('.field_wrapper'); //Input field wrapper
    var fieldHTML = '<div><br/><input type="text" name="fname[]" value="" placeholder="Provider First Name"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="lname[]" value="" placeholder="Provider Last Name"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="code[]" value="" placeholder="PMS Provider Code" /><a href="javascript:void(0);" class="remove_button"><img src="<?Php echo SITE_URL."x-admin/assets/images/clinic_setting/remove-icon.png" ?>"/></a></div>'; //New input field html 
    var x = 1; //Initial field counter is 1
    //<input type="text" name="field_setting2[]" value=""/>
    //Once add button is clicked
    $(addButton).click(function(){
        //Check maximum number of input fields
        if(x < maxField){ 
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); //Add field html
        }
    });
    
    //Once remove button is clicked
    $(wrapper).on('click', '.remove_button', function(e){
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});
function validate_practice(){
	var practicename = $("#practice_name");var practicenamemsg = $("#msg_practice_name");
	var practice_xcare_id = $("#xcare_id");var xcare_idmsg = $("#msg_xcare_id");
	var pullguarantors = $("#pullguarantors_name");var pullguarantorsmsg = $("#msg_pullguarantors_name");
	var pullPatients = $("#PullPatients_name");var pullPatientsmsg = $("#msg_PullPatients_name");
    var pullAppointments = $("#PullAppointments_name");var pullAppointmentsmsg = $("#msg_PullAppointments_name");
	
    if(practicename.val()==''){practicename.addClass('error');practicename.focus();practicenamemsg.html('Please enter practice name').show();
            return false;
	}else
    {
        practicename.removeClass('error');
        practicenamemsg.hide();
    }
        
    if(practice_xcare_id.val()=='')
    {
        practice_xcare_id.addClass('error');
        practice_xcare_id.focus();
        xcare_idmsg.html('Please select xcareId').show();
        return false;
	}else
    {
        practice_xcare_id.removeClass('error');
        xcare_idmsg.hide();
    }

    if(pullguarantors.val()=='')
    {
          pullguarantors.addClass('error');
          pullguarantors.focus();
          pullguarantorsmsg.html('Please select guarantor').show();
          return false;
    }else
    {   
        pullguarantors.removeClass('error');
        pullguarantorsmsg.hide();
    }

    if(pullPatients.val()=='')
    {
          pullPatients.addClass('error');
          pullPatients.focus();
          pullPatientsmsg.html('Please select patient').show();
          return false;
    }else
    {   
        pullPatients.removeClass('error');
        pullPatientsmsg.hide();
    }

    

    if(pullAppointments.val()=='')
    {
        pullAppointments.addClass('error');
        pullAppointments.focus();
        pullAppointmentsmsg.html('Please select appoinment').show();
        return false;
    }else
    {   
        pullAppointments.removeClass('error');
        pullAppointmentsmsg.hide();
    }
    return true;
}

</script>
<div class="breadcrumb">
    <h1>Demo PMS Setup</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>/cliniclist.php">Clinic List</a></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">Demo Clinic Name : <?php echo $clinic->clinic_name ?></div>
                <div class="card-title mb-3">Please enter provider name and pms code to set up Demo Clinic.</div>
                <?php 
                if(isset($_GET['msg']) && $_GET['msg']!=""){?>
                    <div class="card-title mb-3"><?php echo $_GET['msg']; ?></div>
                <?php }?>
                <form action="" id='frm-clinicsetting' method="post" enctype="multipart/form-data">
                    <?php  if(isset($clinic) && $clinic->clinic_id!=0 && $clinic->clinic_id!="") { ?>
                       <input type="hidden" id="clinic_id" name="clinic_id" value="<?php echo $clinic->clinic_id ?>" />
                    <?php } ?>
                    <div class="row">
                        <div class="col-md-12 form-group mb-12 field_wrapper">
                            <input type="text" name="fname[]" value="" placeholder="Provider First Name" />&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="text" name="lname[]" value="" placeholder="Provider Last Name" />&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="text" name="code[]" value="" placeholder="PMS Provider Code"/>
                            <a href="javascript:void(0);" class="add_button" title="Add field"><img src=<?Php echo SITE_URL."x-admin/assets/images/clinic_setting/add-icon.png" ?>></a>
                        </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>

