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


//-----------------------start backend quiz topic add------------------------------





//-----------------------end backend quiz topic add--------------------------------
// backend quiz javascript
//..................... for  start add quiz topic from superadmin........................... 

/* @Function               :   checkName
 * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
 * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
 * @Updated Date Time   :   26/04/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :  'super-admin/check-topic-name-existance'
 * @Works               :  check topic name existance in database
 * @parameter           :  checkName-> given topic  name
 * @Return              :   
 * @Redirect            :   
 * @External call       :   
 * @Internal call       :  
 *
 * */
var topicNameStatus;
function checkName(name) {
    if (name != '') {
        var cn_xmlhttp;
        cn_xmlhttp = AjaxInitialization(cn_xmlhttp);
        var formdata = new FormData();
        formdata.append("topic_name", name);
        cn_xmlhttp.addEventListener("load", function (event) {
            topicNameStatus = cn_xmlhttp.responseText;            
        }, false);
        cn_xmlhttp.open("POST", base_url + 'super-admin/check-topic-name-existance');
        cn_xmlhttp.send(formdata);
    }
}

//END url processing




//..................... for end add quiz topic from superadmin...........................


//.......................start view and manage quiz topic.................... 
/* @Function           :   checkForAction
 * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
 * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
 * @Updated Date Time   :   26/04/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               : given_text
 * @parameter           : url-> controler url for quiz topic 
 *                        acttion->value for action like unpublished, published,pending,approved . 
 *                        quizID->quiz topic id
 * @Return              :  no 
 * @Redirect            :   
 * @External call       :   
 * @Internal call       :  
 *
 * */
function checkForAction(url, action, quizID) { // check for Active Inactives

    swal({
        title: "",
        text: "Are you sure you want to " + action + " this topic?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: 'Yes',
        cancelButtonText: "No",
        closeOnConfirm: true,
        closeOnCancel: true
    },
            function (isConfirm) {
                if (isConfirm) {
                    var xmlhttp = create_xmlhttp();
                    serverPage = url;
                    xmlhttp.open("GET", serverPage);
                    xmlhttp.onreadystatechange = function ()
                    {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {
                            if (action == 'Delete') {
                                location.reload();
                            } else {
                                _("actions" + quizID).innerHTML = xmlhttp.responseText;
                            }
                        }
                    };
                    xmlhttp.send(null);
                } else {
                    return;
                }
            });
}

/* @Function           :   search
 * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
 * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
 * @Updated Date Time   :   26/04/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :   search_value
 * @parameter           :   search_value->the given character for searching the topic
 * @Return              :   no 
 * @Redirect            :   
 * @External call       :   
 * @Internal call       :  
 *
 * */

function search(search_value) {
    var s_xhr = create_xmlhttp();
    var formdata = new FormData();
    formdata.append("search_value", search_value);
    s_xhr.addEventListener("load", function (event) {
        _('topic_data').innerHTML = s_xhr.responseText;
    }, false);
    s_xhr.open("POST", base_url + 'super-admin/search-quiz-topic');
    s_xhr.send(formdata);
}

/* @Function       :   pagination(url, objID)
 * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
 * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
 * @Updated Date Time   :   26/04/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :   search_value
 * @parameter           :   url->controller url wher search action is held,objID->topic 
 * @Return              :   no 
 * @Redirect            :   
 * @External call       :   
 * @Internal call       :  
 *
 * */


function pagination(url, objID) {
    var search_value = _('search_value').value;
    var p_xhr = create_xmlhttp();
    var formdata = new FormData();
    formdata.append("search_value", search_value);
    p_xhr.addEventListener("load", function (event) {
        _('topic_data').innerHTML = p_xhr.responseText;
    }, false);
    p_xhr.open("POST", url);
    p_xhr.send(formdata);
}

//.......................End view and manage quiz topic....................

//.........................START create quiz...............................


//     /* @Function           :   makeUrl
//     * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
//     * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
//     * @Updated Date Time   :   26/04/2016
//     * @Updated By          :   Afrin jahan noumin
//     * @Router              :   
//     * @Works               :   check url value
//     * @parameter           :   profileID
//     * @Return              :  
//     * @Redirect            :    
//     * @External call       :  
//     * @Internal call       :  
//     *
//     * */
//
function makeUrl(profileID) {
    if (profileID === '') {
        document.getElementById('quiz_url').value = '';
    } else {
        profileID = profileID.replace(/  +/g, '');
        for (i = 0; profileID.length > i; i++) {
            if (profileID.charAt(i) === ' ') {
                profileID = profileID.replace(/ +/g, '-');
            }
            if (profileID.charAt(i) === '.') {
                profileID = profileID.replace(/\./g, '');
            }
            if (profileID.charAt(i) === '-') {
                profileID = profileID.replace(/--/g, '-');
            }
        }
        profileID = profileID.replace(/[&\/\\#@!^_=,+()$~%.'":*?<>{}]/g, '');
        if (profileID.charAt(profileID.length - 1) === '-') {
            profileID = setCharAt(profileID, profileID.length - 1, '');
        }
        profileID = profileID.toLowerCase();
        document.getElementById('quiz_url').value = profileID;
        checkUrl(profileID);
    }
}
//      /* @Function          : checkUrl
//     * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
//     * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
//     * @Updated Date Time   :   26/04/2016
//     * @Updated By          :   Afrin jahan noumin
//     * @Router              :   
//     * @Works               :   check url value
//     * @parameter           :   given_text->check url exit
//     * @Return              :  
//     * @Redirect            :    
//     * @External call       :  
//     * @Internal call       :  
//     *
//     * */
function checkUrl(given_text) {
    var xmlhttp2 = create_xmlhttp();
    if (given_text !== '') {
        var serverPage = base_url + 'super-admin/check-quiz-url-existance/' + given_text;
        xmlhttp2.open("GET", serverPage);
        xmlhttp2.onreadystatechange = function ()
        {
            if (xmlhttp2.readyState === 4 && xmlhttp2.status === 200)
            {
                _('quiz_url_message').innerHTML = '';
                _('url_exist').value = xmlhttp2.responseText;
            }
        };
        xmlhttp2.send(null);
    }
}
//     /* @Function       :   Url function
//     * @Developed By        :   Afrin jahan Noumin
//     * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
//     * @Updated Date Time   :   16/06/2016
//     * @Updated By          :   Afrin jahan noumin
//     * @Router              :   
//     * @Works               :   
//     * @parameter           :   profileID
//     * @Return              :  
//     * @Redirect            :    
//     * @External call       :  
//     * @Internal call       : makeUrl(),checkUrl()
//     *
//     * */
//
(function () {
    var quizUrl;
    var quizName;

    document.getElementById('quiz_name').oninput = function () {
        quizName = document.getElementById('quiz_name').value;
        if (quizUrl === undefined || quizUrl === '') {
            makeUrl(quizName);
        } else {
            document.getElementById('quiz_url').value = checkUrl(quizUrl);
        }
    };

    document.getElementById('quiz_url').oninput = function () {
        quizUrl = document.getElementById('quiz_url').value;
        checkUrl(quizUrl);
        document.getElementById('quiz_url').value = quizUrl;
    };
}());


//    //END quiz url processin
//   
//    
//
//   /* @Function             :   accessLevel()
//     * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
//     * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
//     * @Updated Date Time   :   26/04/2016
//     * @Updated By          :   Afrin jahan noumin
//     * @Router              :   
//     * @Works               :   This is user for selecting group course or video course 
//     *                          when we assign a quiz to a course , group or video course.
//     *                          by this function there load input field after permission status field
//     *                          for searching the course by their name.
//     * @parameter           :   given_text-> the permission status that you want to select.
//     * @Return              :  this load a div after permission status by ajax response_text
//     * @Redirect            :    
//     * @External call       :  
//     * @Internal call       :  
//     *
//     * */
function accessLevel(publicationStatus, Url) {
    document.getElementById("quiz_pulication_status_message").innerHTML = "";
    if (publicationStatus == 1) {
        document.getElementById("quiz_permission").innerHTML = '';
        document.getElementById("selected_value").innerHTML = '';
    } else if (publicationStatus == 2) {
        document.getElementById("quiz_permission").innerHTML = '';
        document.getElementById("selected_value").innerHTML = '';
    } else if (publicationStatus == 4 || publicationStatus == 5 || publicationStatus == 6) { // for 4->group , 5->course or 6->video course
        var xmlhttp1;
        xmlhttp1 = AjaxInitialization(xmlhttp1);
        var formdata = new FormData();
        formdata.append("quiz_pulication_status", publicationStatus);
        xmlhttp1.addEventListener("load", function () {
            //alert(xmlhttp1.responseText);
            document.getElementById('quiz_permission').innerHTML = xmlhttp1.responseText;  // ajax page  for input field
            document.getElementById('selected_value').innerHTML = '';
            document.getElementById('previous_selected_id').innerHTML = '';
            document.getElementById('checked_value').value = '';
        }, false);
        xmlhttp1.open("POST", Url);
        xmlhttp1.send(formdata);
    }

}

//    //START group, course and video course search and select option 
//    
//     /* @Function           :   getSearchResult()
//     * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
//     * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
//     * @Updated Date Time   :   26/04/2016
//     * @Updated By          :   Afrin jahan noumin
//     * @Router              :   
//     * @Works               :   This is user for search group , course and video course by thier name
//     *                          so that use can select the bgroups and viseo courses and courses.
//     * @Parameter           :   url-> controller url, inputValue-> given text for search   
//     * @Redirect            :    
//     * @External call       :  
//     * @Internal call       :  
//     *
//     * */
function getSearchResult(url, inputValue) {
    var inputValue1 = inputValue.replace(/ +/g, '');
    var search_text;
    if (inputValue1 === '') { //searching text 
        search_text = 'null';
    } else {
        search_text = inputValue1;
    }
    var quiz_pulication_status = document.getElementById('quiz_pulication_status').value;
    document.getElementById('search_value').value = inputValue1;
    var checkedValue = document.getElementById('checked_value').value;
//   alert(checkedValue);
    var xmlhttp2;
    xmlhttp2 = AjaxInitialization(xmlhttp2);
    var formdata = new FormData();

    formdata.append("quiz_pulication_status", quiz_pulication_status);
    formdata.append("search_text", search_text);
    formdata.append("checked_value", checkedValue);

    xmlhttp2.addEventListener("load", function () {
        //alert(xmlhttp2.responseText);
        document.getElementById('selected_value').innerHTML = xmlhttp2.responseText;
        document.getElementById('group_count').value = 3;
        var id = document.getElementById("checked_value").value;
        if (id && search_text === 'null') {
           //alert(quiz_pulication_status);
            viewSelectedValue(quiz_pulication_status);
            document.getElementById('more_selected_value').innerHTML = '';
            var count = document.getElementById('group_count').value;
            document.getElementById("moregroupword" + count).style.display = 'none';
        } else if (search_text === 'null') {
            document.getElementById('more_selected_value').innerHTML = '';
            var count = document.getElementById('group_count').value;
            document.getElementById("moregroupword" + count).style.display = 'none';
        }
    }, false);
    xmlhttp2.open("POST", url);
    xmlhttp2.send(formdata);
}
//  /* @Function              :   getIDValue()
//     * @Developed By        :   Mahabub-A-Mawla <mahabub.cgbd@yahoo.com> <+8801925821707> |
//     * @DevelopeDateTime    :   29-02-2016 11:05 AM   |
//     * @Updated Date Time   :   26/04/2016
//     * @Updated By          :   Afrin jahan noumin
//     * @Router              :   
//     * @Works               :   This is use for set selected course id,group id or video course id. 
//     * @Parameter           :   inputValue->video course id , accesLevel-> what type of quiz (public, tt etc)
//     * @Redirect            :    
//     * @External call       :  
//     * @Internal call       :  
//     */
//   

function getIDValue(inputValue) {
//    alert(inputValue);
    if ($('#id' + inputValue).is(":checked")) {
        var checkedValue = document.getElementById("checked_value").value;
     
        if (checkedValue === '')
        {
            document.getElementById("checked_value").value = inputValue;
        } else {
            document.getElementById("checked_value").value = checkedValue + ',' + inputValue;
        }
    } else {
        var checkedValue = document.getElementById("checked_value").value;
        var checkedArray = checkedValue.split(",");
        if (checkedArray.indexOf(inputValue) > -1) {
            var index = checkedArray.indexOf(inputValue);
          checkedArray.splice(index, 1);
            document.getElementById("checked_value").value = checkedArray;
        }
    }
}


/* @Function            :   check_quiz_publication_status()
 * @Developed By        :   Afrin jahan noumin
 * @DevelopeDateTime    :   
 * @Updated Date Time   :   26/04/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :   check quiz publication status
 * @Parameter           :  
 * @Redirect            :    
 * @External call       :  
 * @Internal call       :  
 */
function check_quiz_publication_status() {
    var quiz_pulication_status = document.getElementById('quiz_pulication_status').value;
    var checkedValue = document.getElementById('checked_value').value;
    if (quiz_pulication_status == 4) {
        if (checkedValue == '') {
            document.getElementById('quiz_pulication_status_message').innerHTML = "<span style=color:red>Please select group</span>";
            document.getElementById('allow').value = 2;
        }
    } else if (quiz_pulication_status == 5) {
        if (checkedValue == '') {
            document.getElementById('quiz_pulication_status_message').innerHTML = "<span style=color:red>Please select course</span>";
            document.getElementById('allow').value = 2;
        }
    } else if (quiz_pulication_status == 6) {
        if (checkedValue == '') {
            document.getElementById('quiz_pulication_status_message').innerHTML = "<span style=color:red>Please select video</span>";
            document.getElementById('allow').value = 2;
        }
    }
    document.getElementById('allow').value = 1;
    return document.getElementById('allow').value;
}
/* @Function            :   moreSelectedGroup()
 * @Developed By        :   Afrin jahan noumin
 * @DevelopeDateTime    :   
 * @Updated Date Time   :   22/06/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :  show more groups/course/video course after 9 groups while searching by text
 * @Parameter           :  value, accessLevel
 * @Redirect            :    
 * @External call       :  viewVideoInfo(),viewcourseInfo(),viewgroupInfo()
 * @Internal call       :  
 */

function moreSelectedGroup(value, accessLevel) {
    var xmlhttp8;
    xmlhttp8 = AjaxInitialization(xmlhttp8);
    var url = document.getElementById('url_name').value;
    var searchText = document.getElementById('search_value').value;
    var checkedValue = document.getElementById('checked_value').value;
    var formdata = new FormData();

    formdata.append("value", value);
    formdata.append("search_text", searchText);
    formdata.append("access_level", accessLevel);
    formdata.append("checked_value", checkedValue);

    xmlhttp8.addEventListener("load", function () {
        var str = xmlhttp8.responseText;
        var split_word = str.split('###');
        if (accessLevel == 4) {
            viewgroupInfo(split_word[1], split_word[0], accessLevel);
        } else if (accessLevel == 5) {
            viewcourseInfo(split_word[1], split_word[0], accessLevel);
        } else if (accessLevel == 6) {
            viewVideoInfo(split_word[1], split_word[0], accessLevel);
        }
    }, false);
    xmlhttp8.open("POST", url);
    xmlhttp8.send(formdata);
}
/* @Function            :   viewgroupInfo()
 * @Developed By        :   Afrin jahan noumin
 * @DevelopeDateTime    :   
 * @Updated Date Time   :   22/06/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :  show more groups after 9 groups while searching by text (Json formating)
 * @Parameter           :  jsonMemberInfo, value,accessLevel
 * @Redirect            :    
 * @External call       :  
 * @Internal call       :  
 */

function viewgroupInfo(jsonMemberInfo, value, accessLevel) {
    var count = document.getElementById('group_count').value;
    document.getElementById("moregroupword" + count).style.display = 'none';
    var count2 = Number(count) + 1;
    document.getElementById('group_count').value = count2;
    var parent = document.getElementById('more_selected_value');
    var div1 = document.createElement('div');
    div1.setAttribute('id', 'fetch_data' + count2);
    var groupListArray = JSON.parse(jsonMemberInfo);
    var output = '';
    output += '<div class="col-sm-12">';
    for (var i = 0; i < groupListArray.length; i++) {
        output += '<div class="col-sm-4">';
        output += '<div class="checkbox checkbox-success">';
        output += '<input type="checkbox"';
        output += 'onclick="getIDValue(this.value)"';
        output += 'id="id' + groupListArray[i].group_id + '"';
        output += 'class="styled"';
        output += 'name="id[]"';
        output += 'value="' + groupListArray[i].group_id + '" >';
        output += ' <label for="' + groupListArray[i].group_name + '" class="text-justify" >' + groupListArray[i].group_name + '</label>';
        output += '</div>';
        output += ' <div class="col-sm-12" style="color: red" id="checkbox_error' + groupListArray[i].group_id + '"></div>';
        output += '</div>';
    }
    output += '</div>';
    output += '<div id="moregroupword' + count2 + '" class="col-sm-12" style="display:block;">';
    output += '<a href="javascript:;" onclick="moreSelectedGroup(' + value + ',' + accessLevel + ')">More</a>';
    output += '</div>';
    parent.appendChild(div1);
    div1.innerHTML = output;
}
/* @Function            :   viewcourseInfo()
 * @Developed By        :   Afrin jahan noumin
 * @DevelopeDateTime    :   
 * @Updated Date Time   :   22/06/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :  show more groups after 9 courses while searching by text (Json formating)
 * @Parameter           :  jsonMemberInfo, value,accessLevel
 * @Redirect            :    
 * @External call       :  
 * @Internal call       :  
 */
function viewcourseInfo(jsonMemberInfo, value, accessLevel) {
    var count = document.getElementById('group_count').value;
    document.getElementById("moregroupword" + count).style.display = 'none';
    var count2 = Number(count) + 1;
    document.getElementById('group_count').value = count2;
    var parent = document.getElementById('more_selected_value');
    var div1 = document.createElement('div');
    div1.setAttribute('id', 'fetch_data' + count2);
    var courseListArray = JSON.parse(jsonMemberInfo);
    var output = '';
    output += '<div class="col-sm-12">';
    for (var i = 0; i < courseListArray.length; i++) {

        output += '<div class="col-sm-4">';
        output += '<div class="checkbox checkbox-success">';
        output += '<input type="checkbox"';
        output += 'onclick="getIDValue(this.value)"';
        output += 'id="id' + courseListArray[i].course_id + '"';
        output += 'class="styled"';
        output += 'name="id[]"';
        output += 'value="' + courseListArray[i].course_id + '" >';
        output += ' <label for="' + courseListArray[i].course_name + '" class="text-justify" >' + courseListArray[i].course_name + '</label>';
        output += '</div>';
        output += ' <div class="col-sm-12" style="color: red" id="checkbox_error' + courseListArray[i].course_id + '"></div>';
        output += '</div>';
    }
    output += '</div>';
    output += '<div id="moregroupword' + count2 + '" class="col-sm-12" style="display:block;">';
    output += '<a href="javascript:;" onclick="moreSelectedGroup(' + value + ',' + accessLevel + ')">More</a>';
    output += '</div>';
    //alert(output);
    parent.appendChild(div1);
    div1.innerHTML = output;

}
/* @Function            :   viewVideoInfo()
 * @Developed By        :   Afrin jahan noumin
 * @DevelopeDateTime    :   
 * @Updated Date Time   :   22/06/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :  show more videos after 9 videos while searching by text (Json formating)
 * @Parameter           :  jsonMemberInfo, value,accessLevel
 * @Redirect            :    
 * @External call       :  
 * @Internal call       :  
 */
function viewVideoInfo(jsonMemberInfo, value, accessLevel) {
    var count = document.getElementById('group_count').value;
    document.getElementById("moregroupword" + count).style.display = 'none';
    var count2 = Number(count) + 1;
    document.getElementById('group_count').value = count2;
    var parent = document.getElementById('more_selected_value');
    var div1 = document.createElement('div');
    div1.setAttribute('id', 'fetch_data' + count2);
    var videoListArray = JSON.parse(jsonMemberInfo);
    var output = '';
    output += '<div class="col-sm-12">';
    for (var i = 0; i < videoListArray.length; i++) {
        output += '<div class="col-sm-4">';
        output += '<div class="checkbox checkbox-success">';
        output += '<input type="checkbox"';
        output += 'onclick="getIDValue(this.value)"';
        output += 'id="id' + videoListArray[i].video_management_id + '"';
        output += 'class="styled"';
        output += 'name="id[]"';
        output += 'value="' + videoListArray[i].video_management_id + '" >';
        output += ' <label for="' + videoListArray[i].video_course_title + '" class="text-justify" >' + videoListArray[i].video_course_title + '</label>';
        output += '</div>';
        output += ' <div class="col-sm-12" style="color: red" id="checkbox_error' + videoListArray[i].video_management_id + '"></div>';
        output += '</div>';
    }
    output += '</div>';
    output += '<div id="moregroupword' + count2 + '" class="col-sm-12" style="display:block;">';
    output += '<a href="javascript:;" onclick="moreSelectedGroup(' + value + ',' + accessLevel + ')">More</a>';
    output += '</div>';
    //alert(output);
    parent.appendChild(div1);
    div1.innerHTML = output;
}
/* @Function            :   viewSelectedValue()
 * @Developed By        :   Afrin jahan noumin
 * @DevelopeDateTime    :   
 * @Updated Date Time   :   26/06/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :  for show selected video,course and group by searching text
 * @Parameter           :  jsonMemberInfo, value,accessLevel
 * @Redirect            :    
 * @External call       :  
 * @Internal call       :  
 */
function viewSelectedValue(quiz_pulication_status) {
    var base_url = document.getElementById("base_url").value;
    var url = base_url + 'super-admin/pervious-selected-value';
    var previouslySelectedId = document.getElementById("checked_value").value;
    var xmlhttp9;
    xmlhttp9 = AjaxInitialization(xmlhttp9);
    var formdata = new FormData();
    formdata.append("previously_selected_id", previouslySelectedId);
    formdata.append("access_level", quiz_pulication_status);

    xmlhttp9.addEventListener("load", function () {
        previouslySelectedIdShow(xmlhttp9.responseText, quiz_pulication_status);
    }, false);
    xmlhttp9.open("POST", url);
    xmlhttp9.send(formdata);

}
/* @Function            :   previouslySelectedIdShow()
 * @Developed By        :   Afrin jahan noumin
 * @DevelopeDateTime    :   
 * @Updated Date Time   :   26/06/2016
 * @Updated By          :   Afrin jahan noumin
 * @Router              :   
 * @Works               :  for show selected video by searching text
 * @Parameter           :  jsonMemberInfo, value,accessLevel
 * @Redirect            :    
 * @External call       :  
 * @Internal call       :  
 */
function previouslySelectedIdShow(jsonMemberInfo, acessLevel) {

    var previouslyListArray = JSON.parse(jsonMemberInfo);
    var output = '';
    if (acessLevel === '4') {
        for (var i = 0; i < previouslyListArray.length; i++) {
            output += '<div class="checkbox checkbox-success">';
            output += '<input type="checkbox"';
            output += 'onclick="getIDValue(this.value)"';
            output += 'id="id' + previouslyListArray[i].group_id + '"';
            output += 'class="styled"';
            output += 'name="id[]"';
            output += 'value="' + previouslyListArray[i].group_id + '" checked>';
            output += ' <label for="' + previouslyListArray[i].group_name + '" class="text-justify"  >' + previouslyListArray[i].group_name + '</label>';
            output += '</div>';
        }
        document.getElementById("previous_selected_id").innerHTML = output;

    }
    if (acessLevel === '5') {
        for (var i = 0; i < previouslyListArray.length; i++) {
            output += '<div class="checkbox checkbox-success">';
            output += '<input type="checkbox"';
            output += 'onclick="getIDValue(this.value)"';
            output += 'id="id' + previouslyListArray[i].course_id + '"';
            output += 'class="styled"';
            output += 'name="id[]"';
            output += 'value="' + previouslyListArray[i].course_id + '" checked>';
            output += ' <label for="' + previouslyListArray[i].course_name + '" class="text-justify"  >' + previouslyListArray[i].course_name + '</label>';
            output += '</div>';
        }
        document.getElementById("previous_selected_id").innerHTML = output;
    }
    if (acessLevel === '6') {
        for (var i = 0; i < previouslyListArray.length; i++) {
            output += '<div class="checkbox checkbox-success">';
            output += '<input type="checkbox"';
            output += 'onclick="getIDValue(this.value)"';
            output += 'id="id' + previouslyListArray[i].video_management_id + '"';
            output += 'class="styled"';
            output += 'name="id[]"';
            output += 'value="' + previouslyListArray[i].video_management_id + '" checked>';
            output += ' <label for="' + previouslyListArray[i].video_course_title + '" class="text-justify"  >' + previouslyListArray[i].video_course_title + '</label>';
            output += '</div>';
        }
        document.getElementById("previous_selected_id").innerHTML = output;
    }

}


//.........................END create quiz...............................

//.........................Start Edit Quiz................................
function acessLevelEdit(quizPulicationStatus,url,quizId) {
   // alert(quizPulicationStatus);
    var checkedValue=document.getElementById('checked_value').value;
   if (quizPulicationStatus == 1) {
        document.getElementById("quiz_permission").innerHTML = '';
        document.getElementById("selected_value").innerHTML = '';
        document.getElementById('previous_selected_id').innerHTML = '';
        document.getElementById('checked_value').value='';
    } else if (quizPulicationStatus == 2) {
        document.getElementById("quiz_permission").innerHTML = '';
        document.getElementById("selected_value").innerHTML = '';
        document.getElementById('previous_selected_id').innerHTML = '';
        document.getElementById('checked_value').value='';
    } else if (quizPulicationStatus == 4 || quizPulicationStatus == 5 || quizPulicationStatus == 6) { // for 4->group , 5->course or 6->video course
        var xmlhttp1;
        xmlhttp1 = AjaxInitialization(xmlhttp1);
        var formdata = new FormData();
        formdata.append("quiz_pulication_status", quizPulicationStatus);
        formdata.append("checked_value", checkedValue);
        formdata.append("quiz_id", quizId);
        
        xmlhttp1.addEventListener("load", function () {
           // alert(xmlhttp1.responseText);
          
            if(checkedValue){
            var str=xmlhttp1.responseText.split("######");
            if(str[2]==quizPulicationStatus){
            document.getElementById('quiz_permission').innerHTML =str[1];  // ajax page  for input field
            document.getElementById('selected_value').innerHTML = '';
            document.getElementById('previous_selected_id').innerHTML = viewSetectedDataEdit(quizPulicationStatus,str[0]);
            }
            else if(str[2]!=quizPulicationStatus){
            document.getElementById('quiz_permission').innerHTML =str[1];  // ajax page  for input field
            document.getElementById('selected_value').innerHTML = '';
            document.getElementById('previous_selected_id').innerHTML = '';
            document.getElementById('checked_value').value='';
            }
        }
        else{
            var str=xmlhttp1.responseText.split("######");
            document.getElementById('quiz_permission').innerHTML =str[0];  // ajax page  for input field
            document.getElementById('selected_value').innerHTML = ''; 
            
        }
       
      
        }, false);
        xmlhttp1.open("POST", url);
        xmlhttp1.send(formdata);
    }

}
function viewSetectedDataEdit(acessLevel,jsonMemberInfo){
   
     var previouslyListArray=JSON.parse(jsonMemberInfo);
    var output = '';
    if (acessLevel === '4') {
        for (var i = 0; i < previouslyListArray.length; i++) {
            output += '<div class="checkbox checkbox-success">';
            output += '<input type="checkbox"';
            output += 'onclick="getIDValue(this.value)"';
            output += 'id="id' + previouslyListArray[i].group_id + '"';
            output += 'class="styled"';
            output += 'name="id[]"';
            output += 'value="' + previouslyListArray[i].group_id + '" checked>';
            output += ' <label for="' + previouslyListArray[i].group_name + '" class="text-justify"  >' + previouslyListArray[i].group_name + '</label>';
            output += '</div>';
        }
       return output;

    }
    if (acessLevel === '5') {
        for (var i = 0; i < previouslyListArray.length; i++) {
            output += '<div class="checkbox checkbox-success">';
            output += '<input type="checkbox"';
            output += 'onclick="getIDValue(this.value)"';
            output += 'id="id' + previouslyListArray[i].course_id + '"';
            output += 'class="styled"';
            output += 'name="id[]"';
            output += 'value="' + previouslyListArray[i].course_id + '" checked>';
            output += ' <label for="' + previouslyListArray[i].course_name + '" class="text-justify"  >' + previouslyListArray[i].course_name + '</label>';
            output += '</div>';
        }
        return output;
    }
    if (acessLevel === '6') {
        for (var i = 0; i < previouslyListArray.length; i++) {
            output += '<div class="checkbox checkbox-success">';
            output += '<input type="checkbox"';
            output += 'onclick="getIDValue(this.value)"';
            output += 'id="id' + previouslyListArray[i].video_management_id + '"';
            output += 'class="styled"';
            output += 'name="id[]"';
            output += 'value="' + previouslyListArray[i].video_management_id + '" checked>';
            output += ' <label for="' + previouslyListArray[i].video_course_title + '" class="text-justify"  >' + previouslyListArray[i].video_course_title + '</label>';
            output += '</div>';
        }
        return output;
    }
}
//.........................END Edit Quiz................................

//started by tania


//tania 13-08-2016
function getQuiztype(quiztype) { 
    if (quiztype === '2') {
        document.getElementById('paid_quiz_options').style.display = 'block';
    } else if (quiztype === '1') {
        document.getElementById('paid_quiz_options').style.display = 'none';
    }
}

//tania 13-08-2016
function getEditPermissionBuyer(){
    var buyerPermission = document.getElementById('corporate_edit_permission').checked;
    if(buyerPermission){
      document.getElementById('editPermission').style.display = 'block';  
    }else {
      document.getElementById('editPermission').style.display = 'none';
    }   
}

//tania 13-08-2016
function getcorporate_quiz_peice(){
    var corporate = document.getElementById('corporate').checked;
    if(corporate){
      document.getElementById('coporate_price_area').style.display = 'block';  
    }else {
      document.getElementById('coporate_price_area').style.display = 'none';
    } 
}
//tania 13-08-2016
function get_participant_price(){
    var participant = document.getElementById('participant').checked;
    if(participant){
      document.getElementById('participant_price_area').style.display = 'block';  
    }else {
      document.getElementById('participant_price_area').style.display = 'none';
    } 
}




var getParentTopic = function (topicID, url, childTopicID, personID) {
//    alert(topicID + '==='+url + '==='+childTopicID +'==='+ personID);
    var output = '<option value="">Select Topic</option>';
    if (topicID !== '') {
        var serverUrl = url + '/' + topicID + '/' + personID;
        $.get(serverUrl, function (data, status) {
            if (status === 'success') {
                var topicInfo = JSON.parse(data);

                for (var i = 0; i < topicInfo.length; i++) {
                    output += '<option value="' + topicInfo[i].topic_id + '">' + topicInfo[i].topic_name + '</option>';
                }
                output += '<option value="other">Other Topic</option>';
                $('#topic_id').html(output);
                if (childTopicID !== '') {
                    $('#topic_id').val(childTopicID);
                }
            }
        });
    } else {
        $('#topic_id').html(output);
    }
    $('#other_topic_name').val('');
    $('#otherTopic').hide();
};


/*
 * @Function            : getOtherTopic 
 * @Used IN             : @function-'user/course/add_course.php'
 * @Description         : get other topic input fileld
 * @Developed By        : MD Jaherul Islam
 * @Start DateTime      : 23-07-2016 05:39 PM 
 * @Parameter           : topic[STRING]
 * @Return              : NULL      
 * @Status              : available      
 */
var getOtherTopic = function (topic) {
    if (topic === 'other') {
        $('#otherTopic').show();
    } else {
        $('#otherTopic').hide();
    }
};
