Struggling with checkboxes...

Struggling with checkboxes...

Right now I have this code running to actively count how many check boxes are checked actively on a page.

They're are about 20 check boxes, but I want to be able to say after 8 are checked, don't allow anymore to be checked. (Restrict them) BUT... still be able to uncheck them incase you want to change one. 

Say like:

[x] 1
[x] 2
[x] 3
[x] 4
[x] 5
[  ] 6
[x] 7
[x] 8
[x] 9
[  ] 10
[  ] 11
[  ] 12

Ok, that's 8 checked, so I can't check number 11.... But if I uncheck any of the ones that are checked, then I can.

How do I do this?

Here's my code that's counting:

<script language="javascript">
function addone(field) {
field.value = Number(field.value) + 1;
}

function subtractone(field) {
field.value = Number(field.value) - 1;
}

function countChecked() {
  var n = $("input:checked").length;
  $(".remain").text(8 - n + (n === 7 ? " item" : " items") + " remaining!");
  if (n == 8) alert("I am an alert box!");
}
countChecked();
$(":checkbox").click(countChecked);
</script>