var bf_zygote = null;
var bf_count = 0

$(document).ready(function() {
    if(!$("#id_regulations_kind_1").attr('checked')) {
        $("#regulationsupload").hide();
    }
    
    if(!$("#id_wants_presstod").attr('checked')) {
        $("#accnli").hide();
    }
    
    $("#id_wants_presstod").bind('click', function(e) {
       $("#accnli").toggle();
    });
    
    $("#id_regulations_kind_1").bind('click', function(e) {
        if ($(e.target).attr('checked'))
            $("#regulationsupload").show();
    });
    $("#id_regulations_kind_0").bind('click', function(e) {
        if ($(e.target).attr('checked'))
            $("#regulationsupload").hide();
    });
    
    $("#boardol").append('<li><a href="#" id="add_boardmember">Lägg till styrelsemedlem</a></li>');
    $("#add_boardmember").bind('click', bmCallback);
    bf_zygote = $('#boardol').children('li').slice(0, 2);
    bf_count = Number($("#id_bf-TOTAL_FORMS").val());
});

function bmCallback(e) {
    var $clone = $(bf_zygote).clone();
    
    bf_count += 1;
    $clone.each(function() {
        $("#add_boardmember").parent('li').before('<li>'+$(this).html().replace(/bf\-0-/g, 'bf-'+(bf_count - 1)+'-')+'</li>');
    });
    $("#id_bf-TOTAL_FORMS").val(bf_count);
    
    e.preventDefault();
}