﻿// uses .Homework_Info CSSClass
function HomeworkHTML(homework_id, div_container_name) {

    $.ajax({
        type: "POST",
        url: "/misc/Journals.asmx/HomeworkHTML",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: "{" + WS_JSon + ", homework_id: " + homework_id + "}",
        success: function(data) {
            if (data.d != null && data.d != "") {

                $(div_container_name + ".Homework_Info").html(data.d);
                $(div_container_name + ".Homework_Info").show();
            } else {
            $(div_container_name + ".Homework_Info").hide();
            }
        }
    });

}

function MarkAsReviewed(content_type, content_id) {

    $.ajax({
        type: "POST",
        url: "/misc/Journals.asmx/MarkAsReviewed",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: "{" + WS_JSon + ", content_type: " + content_type + ", content_id: " + content_id + "}",
        success: function(data) {
            if (data.d != null && data.d == true) {
                $("#div_reviewed_" + content_type + "_" + content_id).html("<b>Reviewed by " + My_Username + "</b>");
            } 
        }
    });

}

function Fill_MyHomework(div_container_name) {

    // var ddl_id = $(div_j + ".Homework_ddl").attr('id');
    var ddl_id = $(TurnIntoIDSelector(div_container_name, true) + ".MyHomework_ddl").attr('id');

    
    if ($("#" + ddl_id + " option").size() == 0) {

        $.ajax({
            type: "POST",
            url: "/misc/Journals.asmx/Homework_MyList",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: "{" + WS_JSon + "}",
            success: function(data) {

                if (data.d != null && data.d.length > 0) {
                    Fill_DLL(ddl_id, data.d);
                }
            }
        });
    }
}

function Update_Journal_Review(journal_id) {

    var d = "#div_jr_" + journal_id.toString();
    var category = AlwaysReturnInt($(d + " .review_status_ddl").val());
    var assign_to_coach_id = -1;
    if ($(d + " .review_assigned_ddl") != null)
        assign_to_coach_id = AlwaysReturnInt($(d + " .review_assigned_ddl").val());
        
    var free_entry = false; // AlwaysReturnBool($(d + ' .free_entry_chk').is(':checked'));
    
    $.ajax({
        type: "POST",
        url: "/misc/Journals.asmx/Update_Journal_Review",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: "{" + WS_JSon + ", content_id: " + journal_id + ", journal_review_status: " + category + ", assign_to_coach_id: " + assign_to_coach_id + ", free_entry: " + free_entry + "}",
        success: function(data) {
            if (data.d.Success) {
                $(d + ' .lnk_submit').html("<b>Updated!</b>");
            } else {
                $(d + ' .lnk_submit').html(data.d.Message);
            }
        }
    });

}

function PrivacyList(course_or_self_guided_id) {

    var course_id = 0;
    var self_guided_course_id = 0;
    if (course_or_self_guided_id > 0)
        course_id = course_or_self_guided_id;
    else if (course_or_self_guided_id < 0)
        self_guided_course_id = course_or_self_guided_id * -1;


    var ddl_id = $(div_j + ".Privacy_ddl").attr('id');
    $.ajax({
        type: "POST",
        url: "/misc/Journals.asmx/PrivacyList",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: "{my_member_id: " + My_Member_ID + " , course_id: " + course_id +
            ", self_guided_course_id: " + self_guided_course_id +
            ", selected_privacy: " + AlwaysReturnInt($('#' + ddl_id).val()) +
            ", have_courses: " + Have_Courses +
            ", have_self_guided: " + Have_Self_Guided +
            ", have_coaches: " + Have_Coaches +
            "}",
        success: function(data) {

            if (data.d != null && data.d.length > 0) {
                Fill_DLL(ddl_id, data.d);
            }
        }
    });

}