
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <div class="">
        <a href="<?php echo base_url(); ?>super_admin">Dashboard </a>->>
        <a href="<?php echo base_url(); ?>super_admin/user_list/<?php echo $role_name . '/' . $this->session->userdata('role_id'); ?>"><?php echo $role_name; ?> List</a>->>
        <a href="<?php echo base_url(); ?>super_admin/view_detail/<?php echo $role_name . '/' . $person_id; ?>"><?php echo $role_name; ?> Detail</a>->>
        <a href="<?php echo base_url(); ?>super_admin_profile/education/<?php echo $role_name . '/' . $person_id; ?>"><?php echo $role_name; ?><span>Education Details->></span></a>
        <span>Edit Education Details</span>
    </div>
    <br>
    <h3 class="page-header">Edit Education Information</h3>
    <p>
        <?php
        $message = $this->session->userdata('message');
        $this->session->unset_userdata('message');
        if ($message) {
            echo $message;
        }
        ?>
    </p>

    <div class="table-responsive col-sm-12" id="education_form"> <!---->
        <form class="cmxform" id="formID2" action="<?php echo base_url(); ?>super_admin_profile/edit_edication_information/<?php echo $role_name . '/' . $person_id . '/' . $education_detail_id; ?>" method="post" name="add_education" enctype="multipart/form-data" >
            
            <input type="hidden" name="person_id" id="person_id" value="<?php echo $person_id ?>">

            <div class="form-group col-sm-8">
                <label for="attended_for">Attended For</label><span class="required"> * </span><br>
                <input data-errormessage-value-missing="Attended For is required!" class="validate[required]" type="radio" name="attended_for" id="attended_for1" value="1" onchange="selectInstitute();" />School
                <input data-errormessage-value-missing="Attended For is required!" class="validate[required]" type="radio" name="attended_for" id="attended_for2" value="2" onchange="selectInstitute();" />Collage
                <input data-errormessage-value-missing="Attended For is required!" class="validate[required]" type="radio" name="attended_for" id="attended_for3" value="3" onchange="selectInstitute();" />Graduation
                <input data-errormessage-value-missing="Attended For is required!" class="validate[required]" type="radio" name="attended_for" id="attended_for4" value="4" onchange="selectInstitute();" />Post-Graduation
            </div>

            <div class="form-group col-sm-5">
                <label for="country">Education Institution Country</label><span class="required"> * </span>
                <select  
                    data-errormessage-value-missing="Person Country is required!"
                    class="form-control validate[required] text-input" 
                    id="person_country" 
                    name ="education_institution_country"
                    onchange="selectInstitute();">

                    <script language="javascript">
                        populateCountries("person_country", "person_city");  // ....for Country with State

                    </script>

                </select>
            </div>
            <div class="form-group col-sm-8" style="color: red"><?php echo form_error('person_country'); ?>  </div>
            <div class="form-group col-sm-4" id="person_country"></div>

            <div class="form-group col-sm-5">
                <label for="city">Education Institution City</label><span class="required"> * </span><br>

                <select data-errormessage-value-missing="Person City is required!" 
                        class="form-control validate[required]" 
                        name ="education_institution_city" id ="person_city"  
                        onchange="selectInstitute();">
                    <option></option>
                </select>

                <div class="form-group col-sm-4" id="person_city"></div>
            </div>
            <div class="form-group col-sm-5" style="color: red"><?php echo form_error('person_city'); ?>  </div>

            <script>
                function selectInstitute() {
                    if (document.getElementById('attended_for1').checked) {
                        attendedFor = document.getElementById('attended_for1').value;
                    }
                    if (document.getElementById('attended_for2').checked) {
                        attendedFor = document.getElementById('attended_for2').value;
                    }
                    if (document.getElementById('attended_for3').checked) {
                        attendedFor = document.getElementById('attended_for3').value;
                    }
                    if (document.getElementById('attended_for4').checked) {
                        attendedFor = document.getElementById('attended_for4').value;
                    }
//                        alert(attendedFor);
                    country = document.getElementById('person_country').value;
                    city = document.getElementById('person_city').value;

                    serverPage = '<?php echo base_url(); ?>super_admin_profile/select_institute/' + country + '/' + city + '/' + attendedFor;
                    xmlhttp.open("GET", serverPage);
                    xmlhttp.onreadystatechange = function ()
                    {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {
//                                alert(xmlhttp.responseText);
                            document.getElementById('country_city_institute').innerHTML = xmlhttp.responseText;
                            var a = document.getElementById('country_city_institute');
                            a.setAttribute("style", 'display:block');
                        }
                    }
                    xmlhttp.send(null);

                }

            </script>

            <div style="display:none">
                <select  type="hidden" data-errormessage-value-missing='Education Institution Name is required!' 
                         class='form-control validate[required]'
                         name ="education_institution_name" 
                         id ="country_code" >


                </select>
            </div>

            <div class="form-group col-sm-12">
                <div class="form-group col-sm-5" id="country_city_institute" style="display:block">
                    <label for="education_institution_id">Education Institution Name</label><span class="required"> * <?php // echo form_error('institute_id');    ?></span>
                    <select data-errormessage-value-missing="Education Institution Name is required!" 
                            class="form-control validate[required] text-input"
                            name="education_institution_id" 
                            id="education_institution_id"
                            onchange="otherInstitute();">
                        <option value="">--Select Institution--</option>
                        <?php foreach ($education_institute as $v_education_institute) { ?>
                            <option value="<?php echo $v_education_institute->education_institute_id ?>"><?php echo $v_education_institute->education_institute_name ?></option>
                        <?php } ?>
                        <option value="other">Other</option>
                    </select>
                </div>
            </div>

            <script>
                function otherInstitute() {
                    other = document.getElementById('education_institution_id').value;
                    if (other == 'other') {
                        var a = document.getElementById('other_institute');
                        a.setAttribute("style", 'display:block');
                    } else {
                        var a = document.getElementById('other_institute');
                        a.setAttribute("style", 'display:none');
                    }
                }
            </script>

            <div class="form-group col-sm-12">
                <?php // echo $person_edu_info->education_institute_id;?>
                <div class="form-group col-sm-5" id="other_institute" style="display:none">
                    <input type="text"
                           data-errormessage-value-missing='Education Institution Name is required!' 
                           class='form-control validate[required]'
                           name="other_institute" id="other_institute" value="" placeholder="Please Enter Your Education Institute Name">
                </div>
            </div>

            <div class="form-group col-sm-5">
                <label for="start_time_period">Start Time Period</label><span class="required"> * </span>
                <input type="date" min="1971-12-26" max="<?php echo date('Y-m-d'); ?>" data-errormessage-value-missing="Start Time Period is required!" 
                       class="form-control validate[required, custom[eduStartTime]]" 
                       id="start_time_period" name="start_time_period" 
                       value="<?php
                       if (set_value('start_time_period')) {
                           echo set_value('start_time_period');
                       } else {
                           echo $person_edu_info->start_time_period;
                       }
                       ?>" 
                       onchange="setEndDateMinValue();">
            </div>

            <script>
                function setEndDateMinValue() {
                    var endTimePeriod = document.getElementById('end_time_period');
                    var startTimePeriod = document.getElementById('start_time_period').value;
                    endTimePeriod.setAttribute("min", startTimePeriod);
                }
            </script>
            <div class="form-group col-sm-8" style="color: red"><?php echo form_error('start_time_period'); ?>  </div>

            <div class="form-group col-sm-5">
                <label for="end_time_period">End Time Period</label><span class="required"> * </span>
                <input type="date" min="" 
                       data-errormessage-value-missing="End Time Period is required!" 
                       class="form-control validate[required, custom[eduStartTime]]" 
                       id="end_time_period" name="end_time_period" value="<?php
                       if (set_value('end_time_period')) {
                           echo set_value('end_time_period');
                       } else {
                           echo $person_edu_info->end_time_period;
                       }
                       ?>">
            </div>

            <div class="form-group col-sm-8">
                <label for="address">Educational Description </label>
                <textarea name="educational_description" data-errormessage-value-missing="Educational Description is required!" class="form-control validate[required]"  ><?php
                    if (set_value('educational_description')) {
                        echo set_value('educational_description');
                    } else {
                        echo $person_edu_info->educational_description;
                    }
                    ?></textarea>
            </div>
            <div class="form-group col-sm-8" style="color: red"><?php echo form_error('educational_description'); ?>  </div> 

            <div class="form-group col-sm-8">
                <label for="person_education_view_status">Who can see my Education details</label><span class="required"> * </span>
                <select data-errormessage-value-missing="Education View Status is required!" 
                        class="form-control validate[required]" 
                        id="person_education_view_status"  name="person_education_view_status" >
                    <option value="">--Select User--</option>
                    <option value="1">Public</option>
                    <option value="2">Talha Training User</option>
                    <option value="3">My Link</option>
                    <option value="4">Only Me</option>
                </select>
            </div>
            <div class="form-group col-sm-8">
                <label for="person_education_status">Who can see this Education details</label><span class="required"> * </span>
                <select data-errormessage-value-missing="Education Status is required!" class="form-control validate[required]" id="person_education_status"  name="person_education_status" >
                    <option value="">--Select User--</option>
                    <option value="1">Active</option>
                    <option value="0">Inactive</option>
                    <option value="2">Archive</option>
                </select>
            </div>
            <div class="form-group col-sm-8" style="color: red"><?php echo form_error('person_education_status'); ?>  </div> 
            <div class="checkbox col-sm-6" >
                <button type="submit" id="submit" class="btn btn-default">Submit</button>
                <button type="reset" class="btn btn-default">Reset</button>
            </div>

        </form>
    </div>

</div>

<script type="text/javascript">
    document.forms['add_education'].elements['education_institution_country'].value = '<?php
                    if (set_value('education_institute_country')) {
                        echo set_value('education_institute_country');
                    } else {
                        echo $person_edu_info->education_institute_country;
                    }
                    ?>';

    populateStates('person_country', 'person_city');

    document.forms['add_education'].elements['education_institution_city'].value = '<?php
                    if (set_value('education_institute_city')) {
                        echo set_value('education_institute_city');
                    } else {
                        echo $person_edu_info->education_institute_city;
                    }
                    ?>';


    document.forms['add_education'].elements['attended_for'].value = '<?php
                    if (set_value('attended_for')) {
                        echo set_value('attended_for');
                    } else {
                        echo $person_edu_info->attended_for;
                    }
                    ?>';
    document.forms['add_education'].elements['person_education_view_status'].value = '<?php
                    if (set_value('person_education_view_status')) {
                        echo set_value('person_education_view_status');
                    } else {
                        echo $person_edu_info->person_education_view_status;
                    }
                    ?>';
    document.forms['add_education'].elements['person_education_status'].value = '<?php
                    if (set_value('person_education_status')) {
                        echo set_value('person_education_status');
                    } else {
                        echo $person_edu_info->person_education_status;
                    }
                    ?>';

    $(document).ready(function () {
//        selectInstitute();
    });

    document.forms['add_education'].elements['education_institution_id'].value = '<?php
                    if (set_value('education_institute_id')) {
                        echo set_value('education_institute_id');
                    } else {
                        echo $person_edu_info->education_institute_id;
                    }
                    ?>';


</script>