<script>

    //Create a boolean variable to check for a valid Internet Explorer instance.
    var xmlhttp = false;
//Check if we are using IE.
    try {
        //If the Javascript version is greater than 5.
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

        //alert ("You are using Microsoft Internet Explorer.");
    } catch (e) {

        //If not, then use the older active x object.
        try {
            //If we are using Internet Explorer.
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            //alert ("You are using Microsoft Internet Explorer");
        } catch (E) {
            //Else we must be using a non-IE browser.
            xmlhttp = false;
        }
    }
//If we are using a non-IE browser, create a javascript instance of the object.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
        //alert ("You are not using Microsoft Internet Explorer");
    }
</script>

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <!--START Relative Path-->
    <div class="">
        <a href="<?php echo base_url(); ?>super_admin">Dashboard <?php // echo $person_role;                ?></a>->>
        <a href="<?php echo base_url(); ?>super_admin/user_list/Organization/<?php echo $this->session->userdata('role_id'); ?>"><?php echo $person_role; ?> List</a>->>
        <a href="<?php echo base_url(); ?>super_admin/view_detail/Organization/<?php echo $org_info->person_id; ?>"><?php echo $person_role; ?> Detail</a>->>
        <span> <?php echo $person_role; ?> Detail</span>
        <div>
            <?php
            $message = $this->session->userdata('message');
            if ($message) {
                echo $message;
            }
            ?>
        </div>
    </div>
    <!--END Relative Path-->
    <br>
    <h3 class="page-header">Add Course Form</h3>
    <div id="main">
        <!--<form  method="post" action="">-->
        <form class="cmxform" id="formID2" action="<?php echo base_url(); ?>super_admin_organization/add_course" method="post" name="courseForm" enctype="multipart/form-data" >
            <input type="hidden" name="person_id" id="person_id" value="<?php echo $org_info->person_id?>">
            <fieldset>
                <div class="form-group col-sm-12">
                    <div class="form-group col-sm-4">
                        <label for="course_category_id">Select Category:</label><span class="required"> * </span>
                        <select data-errormessage-value-missing="Course Category is Required!" 
                                class="form-control validate[required] text-input" 
                                name="course_category_id"
                                id="course_category_id" 
                                onchange="categoryStatus(this.value, 'course_category_status');" 
                                autofocus="true">
                            <option value="">Select Category</option>
                            <?php foreach ($course_categories as $v_category) { ?>
                                <option value="<?php echo $v_category->course_category_id; ?>"><?php echo $v_category->course_category_name; ?></option>
                            <?php } ?>
                        </select>

                    </div>

                    <script type="text/javascript">

                        document.forms['courseForm'].elements['course_category_id'].value = '<?php echo set_value('course_category_id'); ?>';

                        function categoryStatus(givenValue, objID) {
                            if (givenValue == '') {
                                if (document.getElementById('course_name').value == null) {
                                    document.getElementById('course_name_status').innerHTML = '<p style="color:red;">Please Enter New Course Name</p>';
                                } else {
                                    document.getElementById('course_name_status').innerHTML = '<p style="color:red;"></p>';
                                }
                                document.getElementById(objID).innerHTML = '<p style="color:red;">Please Select Course Category</p>';
                            } else if (givenValue != '') {

                                serverPage = '<?php echo base_url(); ?>super_admin_course/Select_category_resource_person/' + givenValue;  // Passing Category ID to Controller Field Value 
                                /*
                                 *  After Database Check
                                 *  manupulated data will show in Resourse person field
                                 */
                                xmlhttp.open("GET", serverPage);
                                xmlhttp.onreadystatechange = function ()
                                {
                                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                    {
                                        document.getElementById('category_resource_person').innerHTML = xmlhttp.responseText;
                                    }
                                }
                                xmlhttp.send(null);
                                document.getElementById(objID).innerHTML = '<p style="color:red;"></p>';
                                document.getElementById('course_name_status').innerHTML = '<p style="color:red;">Please Enter New Course Name</p>';
                            }
                        }

                    </script>

                    <div class="form-group col-sm-4 required" id=""><?php echo form_error('course_category_id'); ?></div>
                    <div class="form-group col-sm-8 required" id="course_category_status"></div>
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-4">
                        <label for="course_name">Course Name:</label><span class="required"> * </span>
                        <input type="text" 
                               data-errormessage-value-missing="Course Name is Required!" 
                               class="form-control validate[required, custom[courseName],custom[courseNameExistence]] text-input" 
                               id="course_name" 
                               name="course_name" 
                               onblur="checkCourseName(this.value, 'course_name_status')" 
                               value="<?php echo set_value('course_name'); ?>" 
                               placeholder="Enter Your Course Title">

                        <input type="hidden" name="course_name_exist" id="course_name_exist" value="">
                        <script>
                            < div class = "col-sm-4 required" id = "" ><?php echo set_value('course_category_id'); ?> < /div
                                    function checkCourseName(given_text, objID)
                                    {
                                        given_text = encodeURIComponent(given_text);
                                        if (given_text != '') {
                                            document.getElementById('submit').disabled = false;
                                            serverPage = '<?php echo base_url(); ?>super_admin_course/check_course_name/' + given_text;  // Passing Category Name to Controller Field Value 
                                            /*
                                             *  After Database Check display message 
                                             *  if available the message will be Email Address Available
                                             *  if same email address exist in database then message show Email Address Already Exists
                                             */
                                            xmlhttp.open("GET", serverPage);
                                            xmlhttp.onreadystatechange = function ()
                                            {
                                                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                                {
                                                    if (xmlhttp.responseText == 1)
                                                    {
                                                        document.getElementById(objID).innerHTML = '<p style="color:red;">This Course Already Exists</p>';
                                                        document.getElementById('submit').disabled = true;
                                                        document.getElementById('course_name_exist').value = '1';
                                                    } else if (xmlhttp.responseText == 2)
                                                    {
                                                        document.getElementById(objID).innerHTML = '<p style="color:green;"></p>';
                                                        document.getElementById('submit').disabled = false;
                                                        document.getElementById('course_name_exist').value = '';
                                                    }
                                                }
                                            }
                                            xmlhttp.send(null);
                                        } else if (given_text == '') {
                                            document.getElementById('submit').disabled = true;
                                            document.getElementById(objID).innerHTML = '<p style="color:red;">Please Enter Course Name</p>';
                                        }
                                    }
                        </script>
                    </div>
                    <div class="form-group col-sm-5">
                        <label for="course_level">Course Level:</label><span class="required"> * </span>
                        <select data-errormessage-value-missing="Course Level is Required!" class="form-control validate[required] text-input" name="course_level" id="course_level">
                            <option value="">Select Course Level</option>
                            <option value="1">Basic</option>
                            <option value="2">Intermediate</option>
                            <option value="3">Advance</option>
                        </select>

                        <script>
                            document.forms['courseForm'].elements['course_level'].value = '<?php echo set_value('course_level'); ?>';
                        </script>
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_name'); ?></div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_level'); ?></div>
                </div>



                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-4">
                        <label for="course_url">Course URL:</label><span class="required"> * </span>
                        <input data-errormessage-value-missing="Course Level is Required!" class="form-control validate[required, custom[urlExistence]] text-input" type="text" class="form-control" id="course_url" name="course_url" onkeyup="checkCourseUrl(this.value, 'course_url_status');" placeholder="Use dash (-) in the place of space"  value="<?php echo set_value('course_url'); ?>">
                        <input type="hidden" name="url_exist" id="url_exist" value="">
                        <script>

                            function checkCourseUrl(given_text, objID)
                            {
                                // alert(given_text);
                                if (given_text != '') {
                                    var patt = new RegExp(" ");
                                    var res = patt.test(given_text);
                                    if (res) {
                                        document.getElementById('submit').disabled = true;
                                        document.getElementById(objID).innerHTML = "<p style='color:red;'>Please avoide Space in URL You can use '-'</p>";
                                    } else {
                                        serverPage = '<?php echo base_url(); ?>super_admin_course/check_course_category_url/' + given_text;
                                        xmlhttp.open("GET", serverPage);
                                        xmlhttp.onreadystatechange = function ()
                                        {
                                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                            {
                                                if (xmlhttp.responseText == 1)
                                                {
                                                    document.getElementById(objID).innerHTML = '<p style="color:red;">This Course Category URL Already Exists</p>';
                                                    document.getElementById('submit').disabled = true;
                                                    document.getElementById('url_exist').value = '1';
                                                } else if (xmlhttp.responseText == 2)
                                                {
                                                    document.getElementById(objID).innerHTML = '<p style="color:green;">Yes You Can Create This Category</p>';
                                                    document.getElementById('submit').disabled = false;
                                                    document.getElementById('url_exist').value = '';
                                                }
                                            }
                                        }
                                        xmlhttp.send(null);
                                        document.getElementById('submit').disabled = false;
                                    }
                                } else if (given_text == '') {
                                    document.getElementById('submit').disabled = true;
                                    document.getElementById(objID).innerHTML = '<p style="color:red;">Please Enter Course Category URL and Use dash (-) in the place of space</p>';
                                }
                            }
                            //                        
                        </script>    
                    </div>
                    <div class="form-group col-sm-5 required" id="course_url_status"><?php
                        if (form_error('course_url')) {
                            echo form_error('course_url');
                        } else {
                            echo "";
                        }
                        ?></div>
                </div>

                <div class="form-group col-sm-12" id="category_resource_person">
                    <div class="form-group col-sm-4">
                        <label for="resource_person_id">Resource Person:</label><span class="required"> * </span>
                        <select data-errormessage-value-missing="Resource person is Required!" 
                                class="form-control validate[required]] text-input" 
                                name="resource_person_id" 
                                id="resource_person_id" 
                                onchange="categoryStatus(this.value, 'course_category_status');" 
                                >
                            <option value="">Resource Person</option>
                            <?php foreach ($resource_persons as $v_resource_person) { ?>
                                <option value="<?php echo $v_resource_person->resource_person_id; ?>"><?php echo $v_resource_person->person_first_name; ?></option>
                            <?php } ?>
                        </select>
                    </div>

                    <script>
                        document.forms['courseForm'].elements['resource_person_id'].value = '<?php echo set_value('resource_person_id'); ?>';
                    </script>
                    <div class="col-sm-4 required" id=""><?php echo form_error('resource_person_id'); ?></div>
                </div>


                <div class="form-group col-sm-12">
                    <div class="form-group col-sm-3">
                        <label for="course_price">Course Price:</label><span class="required"> * </span>
                        <input type="number" 
                               data-errormessage-value-missing="Course Price is Required!" 
                               class="form-control validate[required, custom[number], custom[coursePriceValue], custom[checkCoursePrice], custom[integer]] text-input" 
                               id="course_price" 
                               name="course_price" 
                               placeholder="Set Course Price"  
                               value="<?php echo set_value('course_price'); ?>"
                               maxlength="10" >
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_price'); ?></div>

                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-3">
                        <label for="total_class_hour">Total Class Hour:</label><span class="required"> * </span>
                        <input type="text" 
                               data-errormessage-value-missing="Total Class Hour is Required!" 
                               class="form-control validate[required]] text-input"  
                               id="total_class_hour" 
                               name="total_class_hour"
                               onblur="distributeTotalClassHours();"
                               placeholder="Total Class Hour"  
                               value="<?php echo set_value('number_of_classes'); ?>">
                    </div>

                    <script>
                        function distributeTotalClassHours() {
                            var totalClassHours = document.getElementById('total_class_hour').value;
                            var classHoursPerDay = 3;
                            var numberOfClasses = Number(totalClassHours) / Number(classHoursPerDay);
                            document.forms['courseForm'].elements['class_hour_per_day'].value = Math.abs(classHoursPerDay);
                            document.forms['courseForm'].elements['number_of_classes'].value = Math.abs(numberOfClasses);
                            document.forms['courseForm'].elements['total_class_hour'].value = Math.abs(totalClassHours);
                        }
                    </script>
                    <div class="col-sm-4 required" id=""><?php echo form_error('total_class_hour'); ?></div>
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-3">
                        <label for="">Number of Classes:</label><span class="required"> * </span>
                        <input type="number" 
                               data-errormessage-value-missing="Number of Class is Required!" 
                               class="form-control validate[required]] text-input" 
                               id="number_of_classes" 
                               name="number_of_classes" 
                               placeholder="Total Number of Class" 
                               onchange="calculateTotalClassHours();"
                               value="<?php echo set_value('number_of_classes'); ?>" maxlength="2">
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('number_of_classes'); ?></div>
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-3">
                        <label for="class_hour_per_day">Class Hour Per Day:</label><span class="required"> * </span>
                        <input type="number" 
                               data-errormessage-value-missing="Class Hour Per Day is Required!" 
                               class="form-control validate[required]] text-input" 
                               id="class_hour_per_day" name="class_hour_per_day" 
                               maxlength="2" placeholder="Class hour per day"
                               onchange="calculateTotalClassHours();"
                               value="<?php echo set_value('class_hour_per_day'); ?>"/>
                    </div>
                    <script>
                        function calculateTotalClassHours() {
                            var numberOfClasses = document.getElementById('number_of_classes').value;
                            var classHoursPerDay = document.getElementById('class_hour_per_day').value;
                            if (!classHoursPerDay && numberOfClasses) {
                                var classHoursPerDay = 1;
                            }
                            if (classHoursPerDay && !numberOfClasses) {
                                var numberOfClasses = 1;
                            }
                            var totalClassHours = Number(classHoursPerDay) * Number(numberOfClasses);
                            document.forms['courseForm'].elements['class_hour_per_day'].value = Math.abs(classHoursPerDay);
                            document.forms['courseForm'].elements['number_of_classes'].value = Math.abs(numberOfClasses);
                            document.forms['courseForm'].elements['total_class_hour'].value = Math.abs(totalClassHours);
                        }
                    </script>
                    <div class="col-sm-4 required" id=""><?php echo form_error('class_hour_per_day'); ?></div>
                </div>


                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-3">
                        <label for="course_start_date">Course Start Date:</label><span class="required"> * </span>
                        <input type="date" 
                               data-errormessage-value-missing="Course Start Date is Required!" 
                               class="form-control validate[required]] text-input"  
                               id="course_start_date" 
                               name="course_start_date" 
                               placeholder="Course Start Date"  
                               value="<?php echo set_value('course_start_date'); ?>">
                    </div>

                    <div class="form-group col-sm-3">
                        <label for="class_time">Class Time :</label><span class="required"> * </span>
                        <input type="time" 
                               data-errormessage-value-missing="Class Time Date is Required!"
                               class="form-control validate[required]] text-input"
                               id="class_time" 
                               name="class_time" 
                               placeholder="Class Time"  
                               value="<?php echo set_value('class_time'); ?>"/>
                    </div>
                    <div class="col-sm-3 required" id=""><?php echo form_error('course_start_date'); ?></div>
                    <div class="col-sm-3 required" id=""><?php echo form_error('class_time'); ?></div>
                </div>

                <div class="form-group col-sm-8">
                    <div class="form-group col-sm-3">
                        <label for="course_work_files"> Course Work Files </label>
                        <input type="checkbox" 
                               name="course_work_files" 
                               id="course_work_files" />
                    </div>
                    <script>
                        document.forms['courseForm'].elements['course_work_files'].checked = '<?php echo set_value('course_work_files'); ?>';
                    </script>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_work_files'); ?></div>
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-3">
                        <label for="last_date_of_registration">Last Date of Registration:</label><span class="required"> * </span>
                        <input type="date" 
                               data-errormessage-value-missing="Last Date of Registration is Required!" 
                               class="form-control validate[required]] text-input"  
                               id="last_date_of_registration" 
                               name="last_date_of_registration" 
                               placeholder="Last Date of Registration"  
                               value="<?php echo set_value('last_date_of_registration'); ?>">
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('last_date_of_registration'); ?></div>
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-10">
                        <div id="image_field">
                            <label for="course_image" style="float:left;">Image</label><br><br>
                            <input type='file' 
                                   style="float:left;"
                                   onchange="readURL(this, 'photo_0');"
                                   id="course_image"
                                   name="course_image"
                                   value="<?php echo set_value('course_image'); ?>"/>
                        </div>
                        <div id="image" style="float:left;width: 150px; height: 50px;" > </div>
                        <script>

                            function readURL(input, objID) {
                                var node = document.createElement("img");
                                var parentDIV = document.getElementById("image");
                                parentDIV.appendChild(node);
                                document.getElementById("image").appendChild(node);
                                node.setAttribute("id", objID);
                                node.setAttribute("src", "");

                                var file = input.files[0];
                                if (file.size > 300000) {
                                    alert('Your Selected file size exceeded!!! max File Size 300 KB and Resulation ');
                                    serverPage = '<?php echo base_url(); ?>super_admin/load_image_field';
                                    xmlhttp.open("GET", serverPage);
                                    xmlhttp.onreadystatechange = function ()
                                    {
                                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                        {
                                            document.getElementById('image').innerHTML = 'Maximum File Size 300 KB and Resulation 1024x1024';
                                            document.getElementById('image_field').innerHTML = xmlhttp.responseText;
                                            document.getElementById('submit').disabled = true;
                                            document.getElementById('agree').checked = false;
                                        }
                                    }
                                    xmlhttp.send(null);
                                } else {
                                    var list = document.getElementById("image");
                                    list.removeChild(list.childNodes[0]);
                                    if (input.files && input.files[0]) {
                                        var reader = new FileReader();
                                        reader.onload = function (e) {
                                            $('#' + objID)
                                                    .attr('src', e.target.result)
                                                    .width(50)
                                                    .height(50);
                                        };
                                        reader.readAsDataURL(input.files[0]);
                                    }
                                }
                            }
                        </script>

                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_image'); ?></div>
                </div>

                <div class="form-group col-sm-6">

                    <div class="form-group col-sm-6">
                        <label for="course_author">Course Author:</label>
                        <input type="text"
                               data-errormessage-value-missing="Please Select Course Author" 
                               class="form-control validate[required]" 
                               name="course_author" 
                               id="course_category_author"
                               value="<?php echo set_value('course_author') ?>">
                    </div>

                </div>

                <div class="form-group col-sm-10">

                    <div class="form-group col-sm-10">
                        <label for="course_meta_description">Course Meta Description</label><span class="required"> * </span>
                        <textarea type="text" 
                                  data-errormessage-value-missing="Course Meta Description is Required!" 
                                  class="form-control texteditor validate[required]] text-input"
                                  rows="5" cols="20" 
                                  id="course_meta_description" 
                                  name="course_meta_description" 
                                  value=""><?php echo set_value('course_meta_description'); ?></textarea>
                    </div>

                    <div class="form-group col-sm-10">
                        <label for="course_meta_keywords">Course Meta Keyword</label><span class="required"> * </span>
                        <textarea type="text" 
                                  data-errormessage-value-missing="Total Class Hour is Required!" 
                                  class="form-control texteditor validate[required]] text-input"  
                                  rows="5" cols="20"
                                  id="course_meta_keywords" 
                                  name="course_meta_keywords" 
                                  value=""><?php echo set_value('course_meta_keywords'); ?></textarea>
                    </div>

                    <div class="form-group col-sm-10">
                        <label for="course_keyword">Course Keyword</label><span class="required"> * </span>
                        <textarea type="text" 
                                  data-errormessage-value-missing="Course Keyword is Required!" 
                                  class="form-control texteditor validate[required]] text-input"  
                                  rows="5" cols="20" 
                                  id="course_keyword" 
                                  name="course_keyword"
                                  value=""><?php echo set_value('course_keyword'); ?></textarea>
                    </div>

                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-10">
                        <label for="course_registration_details">Course Registration Detail</label><span class="required"> * </span>
                        <textarea type="text" 
                                  data-errormessage-value-missing="Course Registration Detail is Required!" 
                                  class="form-control texteditor validate[required]] text-input"  
                                  rows="5"  cols="20" 
                                  id="course_registration_details" 
                                  name="course_registration_details" 
                                  value=""><?php echo set_value('course_registration_details'); ?></textarea>
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_registration_details'); ?></div>
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-10">
                        <label for="course_training_objectives">Course Training Objectives</label><span class="required"> * </span>
                        <textarea type="text" 
                                  data-errormessage-value-missing="Course Training Objectives is Required!" 
                                  class="form-control texteditor validate[required]] text-input"   
                                  rows="5"  cols="20" 
                                  id="course_training_objectives" 
                                  name="course_training_objectives" 
                                  value=""><?php echo set_value('course_training_objectives'); ?></textarea>
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_training_objectives'); ?></div>
                </div>

                <div class="form-group col-sm-10">
                    <div class="form-group col-sm-10">
                        <label for="course_training_outline">Course Outline</label><span class="required"> * </span>
                        <textarea type="text" 
                                  data-errormessage-value-missing="Total Class Hour is Required!" 
                                  class="form-control texteditor validate[required]] text-input"  
                                  rows="5"  cols="20" 
                                  id="course_training_outline" 
                                  name="course_training_outline" 
                                  value=""><?php echo set_value('course_training_outline'); ?></textarea>
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_training_outline'); ?></div>
                </div>
                <div class="form-group col-sm-12">
                    <div class="form-group col-sm-4">
                        <label for="course_language">Course Language:</label><span class="required"> * </span>
                        <select data-errormessage-value-missing="Course Language is Required!" 
                                class="form-control validate[required]] text-input"   
                                name="course_language" >
                            <option value="">Select Language</option>
                            <option value="1">English</option>
                            <option value="3">বাংলা</option>
                            <option value="4">हिन्दी (Hindi)</option>
                        </select>
                        <script>
                            document.forms['courseForm'].elements['course_language'].value = '<?php echo set_value('course_language'); ?>';
                        </script>

                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <div class="form-group col-sm-4">
                        <label for="course_access_level">Access Level:</label><span class="required"> * </span>
                        <select data-errormessage-value-missing="Access Level is Required!" 
                                class="form-control texteditor validate[required]] text-input"   
                                name="course_access_level" 
                                onchange="accessLevel(this.value);">

                            <option value="">Select Access Level</option>
                            <option value="1">Public</option>
                            <option value="3">Resource Person</option>
                            <option value="4">Student</option>
                            <option value="5">Special</option>
                        </select>
                        <script>
                            document.forms['courseForm'].elements['course_access_level'].value = '<?php echo set_value('course_access_level'); ?>';
                        </script>

                        <script>

                            function accessLevel(level) {
                                if (level == 5) {
                                    document.getElementById('permissions').innerHTML = "<label for='course_category_permissions'>Permission</label><input onkeyup='search(this.value);'class='form-control' type='text' name='course_category_permissions' id='permission' value=''>";
                                } else {
                                    document.getElementById('permissions').innerHTML = '';
                                }
                            }

                            function search(givenText) {
                                if (givenText) {
                                    serverPage = '<?php echo base_url(); ?>super_admin_course/search/' + givenText;
                                    xmlhttp.open("GET", serverPage);
                                    xmlhttp.onreadystatechange = function ()
                                    {
                                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                        {
                                            document.getElementById('permissions_list').innerHTML = xmlhttp.responseText;
                                        }
                                    }
                                    xmlhttp.send(null);
                                }
                            }

                            function addToPermissions(id) {
                                var node = document.createElement("input");
                                var parentDIV = document.getElementById("permission_list_input");
                                parentDIV.appendChild(node);
                                document.getElementById("permission_list_input").appendChild(node);
                                node.setAttribute("id", 'permission_all_list[' + id + ']');
                                node.setAttribute("type", 'text');
                                node.setAttribute("name", 'permission_all_list[' + id + ']');
                                node.setAttribute("value", id);

                                var child = document.getElementById("single_person_button[" + id + "]");
                                child.parentNode.removeChild(child);


                                var minusNode = document.createElement("a");
                                var parentDIV2 = document.getElementById("single_person[" + id + "]");
                                parentDIV2.appendChild(minusNode);
                                document.getElementById("single_person[" + id + "]").appendChild(minusNode);
                                minusNode.setAttribute("id", "single_person_button[" + id + "]");
                                minusNode.setAttribute("class", "fa fa-user-times");
                                minusNode.setAttribute("title", "Remove From Permission");
                                minusNode.setAttribute("onclick", "removeFromPermissions(" + id + ")");
                            }


                            function removeFromPermissions(id) {

                                var child = document.getElementById('permission_all_list[' + id + ']');
                                child.parentNode.removeChild(child);

                                var child = document.getElementById("single_person_button[" + id + "]");
                                child.parentNode.removeChild(child);

                                var addNode = document.createElement("a");
                                var parentDIV2 = document.getElementById("single_person[" + id + "]");
                                parentDIV2.appendChild(addNode);
                                document.getElementById("single_person[" + id + "]").appendChild(addNode);
                                addNode.setAttribute("id", "single_person_button[" + id + "]");
                                addNode.setAttribute("class", "fa fa-user-plus");
                                addNode.setAttribute("title", "Remove From Permission");
                                addNode.setAttribute("onclick", "addToPermissions(" + id + ")");
                            }
                        </script>
                    </div>

                </div>

                <!-- permission management-->
                <div class="form-group col-sm-12">
                    <div class="form-group col-sm-4" id="permissions"></div>
                    <div class="form-group col-sm-8" id="permission_list_input"></div>
                </div>
                <div class="form-group col-sm-4" id="permissions_list"></div>
                <!-- permission management-->
                <div class="form-group col-sm-12">
                    <div class="form-group col-sm-8">
                        <label for="course_status">Course Status</label><span class="required"> * <?php echo form_error('status'); ?></span>
                        <input  type="radio" 
                                data-errormessage-value-missing="Course Status is Required!" 
                                class="validate[required]] text-input"  
                                name="course_status" 
                                id="course_status"
                                value="1"/>Active
                        <input type="radio" 
                               data-errormessage-value-missing="Course Status is Required!" 
                               class="validate[required]] text-input"  
                               name="course_status" 
                               id="course_status" 
                               value="2"/>Inactive
                        <script>
                            document.forms['courseForm'].elements['course_status'].value = '<?php echo set_value('course_status'); ?>';
                        </script>
                    </div>
                    <div class="col-sm-4 required" id=""><?php echo form_error('course_status'); ?></div>
                    <div class="form-group col-sm-8">
                        <label for="upcoming_course" > Course Up-coming</label>
                        <input type="checkbox"   
                               name="upcoming_course" 
                               id="upcoming_course" />
                    </div>
                    <script>
                        document.forms['courseForm'].elements['upcoming_course'].checked = '<?php echo set_value('upcoming_course'); ?>';
                    </script>
                    <div class="form-group col-sm-8">
                        <label for="view_in_home_page">View in Home Page ?</label>
                        <input type="checkbox" 
                               name="view_in_home_page" 
                               id="view_in_home_page" />
                    </div>
                    <script>
                        document.forms['courseForm'].elements['view_in_home_page'].checked = '<?php echo set_value('view_in_home_page'); ?>';
                    </script>
                </div>
                <div class="form-group col-sm-12">
                    <div class="form-group col-sm-3">
                        <label for="course_rating">Course Rating:</label><span class="required"> * </span>
                        <input type="text" 
                               data-errormessage-value-missing="Access Level is Required!" 
                               class="form-control texteditor validate[required, custom[integer]]] text-input"  
                               name="course_rating" 
                               id="course_rating" 
                               value="<?php echo set_value('course_rating'); ?>" 
                               onkeyup="checkRatingValue();">
                        <div id="course_rating_status"></div>
                        <div class="col-sm-4 required" id=""><?php echo form_error('course_rating'); ?></div>
                    </div>

                    <script>
                        function checkRatingValue() {
                            var rating;
                            rating = Number(document.getElementById('course_rating').value);
                            if (rating > 5) {
                                document.getElementById('course_rating_status').innerHTML = "<p style='color:red'>Please Enter a value in between 1-5</p>";
                                document.getElementById('course_rating').value = '';
                            } else {
                                document.getElementById('course_rating_status').innerHTML = "<p style='color:green'>Thank you for rating this course</p>";
                            }
                        }
                    </script>
                </div>

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

                    <div class="checkbox col-sm-3" >
                        <button type="submit" id="submit" class="btn btn-default" >Submit</button>
                        <button type="reset" class="btn btn-default">Reset</button>
                    </div>

                </div>
            </fieldset>
        </form>

    </div>
</div>