<style type="text/css">
    .line{
        border-right: 1px solid #4c0870;
        border-right-style: dashed;
    }
    .pic {
        text-align: center;
        font-size:10em;
        width: 210px;
        height: 210px;
        margin-left: 26px;
        margin-top: 37px;
        overflow: hidden;
    }
    .form-group-default.form-group-default-select2 .select2-container .select2-choice {
        opacity: 1;
        color:#000 !important;
    }
</style>

<?php 
//echo"<pre>";
//die(print_r($emergency_details));
?>
<div class="container-fluid container-fixed-lg bg-white" >
    <?php echo Forms::ModalLoader('EmergencyBusy')?>
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print CommonLanguage::getMessage('add_emergency_contact'); ?></div>
            <div id="SubmitItemSuccess" class="alert alert-success hidden"></div>
            <form id="EmergencyContact_Form">
                <div class="col-md-4">
                    <i class="fa fa-ambulance fa-5x pic"></i>
                </div>
                <div class="col-md-8  line">
                    <div class="col-sm-6">
                        <div class="form-group form-group-default form-group-default-select2 required">
                            <label><?php print CommonLanguage::getMessage('employee'); ?></label>

                            <input class="Employee_ID full-width" id="Employee_ID" name="Employee_ID" type="hidden" value="<?=  $IsEdit ? $emergency_details[0]['Employee_ID'] :''?>" data-select-name="<?=  ($IsEdit ? $emergency_details[0]['Employee_Name'] :"")?>" required/>



                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group form-group-default form-group-default-select2 required">
                            <label><?php print CommonLanguage::getMessage('relationship'); ?></label>

                            <input class="Employee_Relationship_ID full-width" id="Employee_Relationship_ID" name="Employee_Relationship_ID" type="hidden" required value="<?=  $IsEdit ? $emergency_details[0]['Employee_Relationship_ID'] :''?>" data-select-name="<?=  ($IsEdit ? $emergency_details[0]['Relation_Name'] :"")?>" />

                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="col-sm-3">
                                <div class="form-group form-group-default ">
                                    <label><?php print CommonLanguage::getMessage('first_name'); ?><span class="red-star">*</span></label>
                                    <input type="text" value="<?= $IsEdit ? $name[0]: ""?>"id="EmergencyContact_FirstName"	name="EmergencyContact_FirstName" class="form-control" required	>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="form-group form-group-default ">
                                    <label><?php print CommonLanguage::getMessage('middle_name'); ?></label>
                                    <input type="text" value="<?= $IsEdit ? $name[1]: ""?>"	id="EmergencyContact_MiddleName"name="EmergencyContact_MiddleName" class="form-control"	/>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="form-group form-group-default ">
                                    <label><?php print CommonLanguage::getMessage('last_name'); ?><span class="red-star">*</span></label>
                                    <input type="text"	value="<?= $IsEdit ? $name[2]: ""?>" id="EmergencyContact_LastName" name="EmergencyContact_LastName" class="form-control" required/>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="form-group form-group-default ">
                                    <label><?php print CommonLanguage::getMessage('home_phone'); ?></label>
                                    <input type="text" value="<?= $IsEdit ? $emergency_details[0]['EmergencyContact_HomePhone']: ""?>"	id="EmergencyContact_HomePhone" name="EmergencyContact_HomePhone" class="form-control"	/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="col-sm-3">
                                <div class="form-group form-group-default ">
                                    <label><?php print CommonLanguage::getMessage('mobile_phone'); ?><span class="red-star">*</span></label>
                                    <input type="text" value="<?= $IsEdit ? $emergency_details[0]['EmergencyContact_MobilePhone']: ""?>"	id="EmergencyContact_MobilePhone" name="EmergencyContact_MobilePhone"	class="form-control" required	/>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="form-group form-group-default ">
                                    <label><?php print CommonLanguage::getMessage('work_phone'); ?></label>
                                    <input type="text" value="<?= $IsEdit ? $emergency_details[0]['EmergencyContact_WorkPhone']: ""?>"	name="EmergencyContact_WorkPhone" id="EmergencyContact_WorkPhone"	class="form-control" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <div class="col-md-4 pull-right">
                <button class=" btn btn-success btn-cons m-b-10 pull-right "   id="SubmitEmergency"> <span class="bold"><?php print CommonLanguage::getMessage('Save'); ?></span></button>
            </div>
        </div>
    </div>
</div>
<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
        Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
                IsEdit = <?php echo json_encode($IsEdit) ?>, ID = <?php echo json_encode($id) ?>,
                is_actual = <?php echo json_encode($is_actual);?>;
              
            $(function () {

                build_select2($('.Employee_ID'),'xhr/employeeSearch?is_actual='+is_actual);
                build_select2($('.Employee_Relationship_ID'),'xhr/emergencySearch');
                $("#SubmitEmergency").on("click", function () {
                    if (!$("#EmergencyContact_Form").find("input").blur().end().valid()) {
                        $("#SubmitItemSuccess").attr("class", "alert alert-danger").show().html(Required_Fields)
                        return
                    }
                    $("#EmergencyBusy").removeClass('hidden');
                    var Data = {
                        EmergencyContact_FirstName: $("#EmergencyContact_FirstName").val(),
                        EmergencyContact_MiddleName: $("#EmergencyContact_MiddleName").val(),
                        EmergencyContact_LastName: $("#EmergencyContact_LastName").val(),
                        Employee_Relationship_ID: $("#Employee_Relationship_ID").val(),
                        EmergencyContact_HomePhone: $("#EmergencyContact_HomePhone").val(),
                        EmergencyContact_MobilePhone: $("#EmergencyContact_MobilePhone").val(),
                        EmergencyContact_WorkPhone: $("#EmergencyContact_WorkPhone").val(),
                        Employee_ID: $("#Employee_ID").val(),
                       
                    };
                    
                    if(IsEdit)
                        Data.EmergencyContact_ID = ID;
                        Data.IsEdit = IsEdit ? 1 : 0;
                    $.ajax({
                        url: "HRMAjax/addEmergencyContact",
                        data: Data,
                        type: "POST",
                        complete: function (xhr, status) {
                            if (status == "success" && xhr.responseText == 'success') {
                                //                        console.log(xhr.responseText);
                                $(document.body).animate({scrollTop: 0})
                                $("#SubmitItemSuccess").attr("class", "alert alert-success").html(Submitted_Successfully)
                            } else {
                                $("#SubmitItemSuccess").attr("class", "alert alert-danger").html(Failed_Submit)
                            }
                            $("#EmergencyBusy").addClass('hidden');
                        }
                    });
                });
            });
</script>
