<div class="col-sm-10">
    <div class="row gray_ttc">
        <div class="col-sm-10 ">
            <div class="col-sm-12">
                <h3>Edit Batch Information</h3>  
            </div>
            <div class="col-sm-12"> <hr><br></div>
            <div class="col-sm-12">

                <?php
//                        echo validation_errors();
                $url = 'super-admin/edit-batch/' . $batch_info->course_batch_id;
                echo form_open($url, 'class="" id="formID2" name="createBatch" onsubmit="check_form()"');
                ?>

                <div class="col-sm-12">
                    <div class="col-sm-12 form-group">
                        <div class="input-group">
                            <input type="text" 
                                   data-errormessage-value-missing="Batch name is required"
                                   class="form-control validate[required] text-input" 
                                   name="course_batch_name" id="course_batch_name"
                                   placeholder="Type your Batch Name.." aria-describedby="basic-addon1"
                                   value="<?php
                                   if (set_value('course_batch_name')) {
                                       echo set_value('course_batch_name');
                                   } else {
                                       echo $batch_info->course_batch_name;
                                   }
                                   ?>">
                            <span class="input-group-addon" id="basic-addon1" title="Type your Batch Name"><i class="fa fa-ge"></i></span>
                        </div>
                        <span id="course_batch_name_message" style="color: red"><?php echo form_error('course_batch_name'); ?></span>
                    </div>
                    <div class="col-sm-12"><br></div>

                    <div class="col-sm-12 form-group">
                        <select data-errormessage-value-missing="Course is required"
                                class="form-control validate[required]" 
                                name="course" id="course"
                                onchange="get_course_info()">
                            <option value=""> -Select Course - </option>
                            <?php foreach ($courses as $v_courses) { ?>
                                <option value="<?php echo $v_courses->course_id; ?>"><?php echo $v_courses->course_name; ?></option>
                            <?php } ?>
                        </select>
                        <span id="course_message" style="color: red"><?php echo form_error('course'); ?></span>
                    </div>

                    <div id="course_info">
                        <div class="col-sm-12 form-group text-left">
                            <strong id="course_resource_person">
                                <input type="hidden" name="resource_person_id" id="resource_person_id" value="<?php echo $resource_person_info->resource_person_id; ?>">
                                Resource Person Name : <?php echo $resource_person_info->person_first_name; ?>
                            </strong>
                        </div>

                        <input type="hidden" name="course_start_date" id="course_start_date" value="<?php echo $course_info->course_start_date; ?>">
                        <div class="col-sm-6 form-group">
                            <div class="input-group " id="datetimepicker1">
                                <input type="text" 
                                       data-errormessage-value-missing="Class start Date is Required!"
                                       class="form-control validate[required, custom[mindate], custom[batchFinishedDate]] text-input"
                                       name="course_batch_start_date" id="course_batch_start_date" 
                                       placeholder="Please Select  Start Date"
                                       value="<?php
                                       if (set_value('course_batch_start_date')) {
                                           echo set_value('course_batch_start_date');
                                       } else {
                                           echo $batch_info->course_batch_start_date;
                                       }
                                       ?>">
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar" title="Please Select  Start Date"></span>
                                </span>
                            </div>
                            <span id="course_batch_start_date_message" style="color: red"><?php echo form_error('course_batch_start_date'); ?></span>
                        </div>

                        <div class="col-sm-6 form-group">
                            <div class="input-group " id="datetimepicker5">
                                <input type="text" 
                                       data-errormessage-value-missing="Class finish Date is Required!"
                                       class="form-control validate[required, custom[mindate], custom[batchFinishedDate]] text-input"
                                       name="course_batch_finish_date" id="course_batch_finish_date" 
                                       placeholder="Please Select Finish Date"
                                       value="<?php
                                       if (set_value('course_batch_finish_date')) {
                                           echo set_value('course_batch_finish_date');
                                       } else {
                                           echo $batch_info->course_batch_finish_date;
                                       }
                                       ?>">
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar" title="Please Select Finish Date"></span>
                                </span>
                            </div>
                            <span id="course_batch_finish_date_message" style="color: red"><?php echo form_error('course_batch_finish_date'); ?></span>                        
                        </div>

                        <div class="col-sm-12 form-group text-left">
                            <strong>Batch Status: </strong> 
                            <?php
                            $course_batch_status = array('', 'Running', 'Finished', 'Cancel', 'Create');
                            echo $course_batch_status[$batch_info->course_batch_status];
                            ?>
                        </div>

                    </div>


                    <div class="col-sm-12"><br><br></div>

                    <div class="form-group col-sm-4 col-sm-offset-4">
                        <input type="submit" class="green-btn btn btn-default" value=" Update ">
                    </div>

                    <div class="form-group col-sm-2"></div>
                    <div class="col-sm-12"><br><br></div>

                </div>
                <?php echo form_close(); ?>
            </div>

        </div>

    </div>

</div>

<script>
    document.forms['createBatch'].elements['course'].value = '<?php
                if (set_value('course')) {
                    echo set_value('course');
                } else {
                    echo $batch_info->course_id;
                }
                ?>';

    $(document.forms['createBatch']).submit(function (event) {
        event.preventDefault();
    });

    function create_xmlhttp() {
        var xmlhttp = false;
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
    }

    function get_course_info() {
        var course_id = document.getElementById('course').value;
        var xhr = create_xmlhttp();

        var formdata = new FormData();
        formdata.append("course_id", course_id);
        xhr.addEventListener("load", function () {
            document.getElementById('course_info').innerHTML = xhr.responseText;
        }, false);

        xhr.open("POST", "<?php echo base_url() . 'super-admin/batch-course-info'; ?>");
        xhr.send(formdata);
    }

</script>