﻿$(function() {
    $(".chkAttribute").click(function() {
        $(".lblCheckedCount").text("(Filter 0)");
        RefreshStudyTable();
        //        $("#lblCheckedAttributes").text(GetCheckedAttributesText());
    });
});

function RefreshStudyTable() {

    var querystring = BuildQueryString();

    $.ajax({
        url: "/Home/StudiesTable" + querystring,
        cache: false,
        success: function(html) {
            $("#AjaxTest").html(html);
            InitDataTables($('.InitDataTables'));
            InitHighslide();
        }
    });
}

function BuildQueryString() {

    var querystring = "?,";
    var category = "";
    var count = 1;

    $(".chkAttribute:checked").each(function() {
        if ($(this).attr("value") != category) {
            count = 1;
            category = $(this).attr("value");
            querystring = querystring.substring(0, querystring.length - 1);
            querystring += (querystring == "?" ? "" : "&") + category + "=";
        }
        $("#lblCheckedCount" + category).text("(Filter " + count++ + ")");
        querystring += $(this).attr("name") + ",";
    });

    querystring = querystring.substring(0, querystring.length - 1);

    return querystring;
}

//function GetCheckedAttributesText() {
//    var text = "";
//    $(".chkAttribute:checked").each(function() {
//        if (text != "")
//            text += ", ";
//        text += $(this).attr("id");
//    });
//    return text;
//}
