function addFilters() {
    $("#search_jurisdictions input").each(function () {
       $(this).change(function() {
           filterParishes($(this).attr('name'),$(this).attr('checked'));
       });
       if (! $(this).attr('checked')) {
           filterParishes($(this).attr('name'),false);
       }
    });
}

function filterParishes(jurName,checked) {
    filter_jur = translateCheckBoxName(jurName);
    $("#output_panel > .output_parish").each(function(k) {
        jurisdiction = $(this).find(".parish_jurisdiction").text();
        if (jurisdiction == filter_jur) {
            if (checked) {
                pCountArray = $("#parish_count").text().split("/");
                pNewCount = parseInt(pCountArray[0]) + 1;
                $("#parish_count").text(pNewCount+"/"+pCountArray[1]);
                $(this).slideDown();
                if (markers[k]) markers[k].setVisible(true);
            }
            if (! checked) {
                pCountArray = $("#parish_count").text().split("/");
                pNewCount = parseInt(pCountArray[0]) - 1;
                $("#parish_count").text(pNewCount+"/"+pCountArray[1]);
                $(this).slideUp();
                if (markers[k]) markers[k].setVisible(false);
            } 
        }
    });
}

function translateCheckBoxName(cbName) {
    switch(cbName) {
        case 'alb':
            return 'Albanian Orthodox Diocese of America';
            break;
        case 'ant':
            return 'Antiochian Orthodox Archdiocese';
            break;
        case 'bgr':
            return 'Bulgarian Eastern Orthodox Church';
            break;
        case 'cpr':
            return 'Carpatho-Russian Orthodox Church';
            break;
        case 'goa':
            return 'Greek Orthodox Archdiocese of America';
            break;
        case 'mos':
            return 'Representation of the Moscow Patriarchate';
            break;
        case 'roc':
            return 'Russian Orthodox Church Outside of Russia';
            break;
        case 'oca':
            return 'Orthodox Church in America';
            break;
        case 'rom':
            return 'Romanian Orthodox Archdiocese';
            break;
        case 'ser':
            return 'Serbian Orthodox Church';
            break;
        case 'ukr':
            return 'Ukrainian OC of the US';
            break;
        
    }
}

function showMoreInfo(obj) {
    $(obj).parent().parent().find(".parish_more_info").show();
    $(obj).parent().hide();
}

function checkboxes(cb) {
    $("#search_jurisdictions input").each(function () {
        if (cb) { // all parishes on
            if ($(this).attr('checked') == false) filterParishes($(this).attr("name"),true);
            $(this).attr('checked',true);
        } else { // all parishes off
            if ($(this).attr('checked')) filterParishes($(this).attr("name"),false);
            $(this).attr('checked',false);
        }
    });
}

