﻿$(document).ready(function () {
    doAccordian();
});

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function doAccordian() {
    $("#accordian h6").click(function () {
        if ($(this).children("img").attr("src").indexOf("add") > 0) {
            $(this).children("img").attr("src", "Assets/CSS/Images/minus.png");
        }
        else {
            $(this).children("img").attr("src", "Assets/CSS/Images/add.png");
        }
        $(this).siblings("ul").slideToggle(400);
    });

    var x = 0;
    $("#accordian input").click(function () {
        var currentValue = $(".selectedCheckboxes").val();
        $(".selectedCheckboxes").val(" ");
        if (!$(this)[0].checked) {
            currentValue = "";
            x = 0;
        }
        $(".selectedCheckboxes").val(" ");
        $("#accordian input").each(function () {
            if ($(this)[0].checked) {
                var value = $(this).attr("id");
                if (x == 0) {
                    $(".selectedCheckboxes").val(value);
                    x++;
                }
                else {
                    $(".selectedCheckboxes").val(currentValue + "|" + value);
                }
            }
        });

    });

    $("#accordian ul").each(function () {
        if ($(this).text() == "") $(this).parent().addClass("hide");
    });
}