I have a php page with a form, and a list that is divided into two categories: aircraft/pilots. It is laid out like this:

(option=view) Day
(option=view) Week
(option=view) Month

Choose Aircraft:
(checkbox=aircraft[]) NS1234
(checkbox=aircraft[]) NS1235
(checkbox=aircraft[]) NS1236

Choose Pilot:
(checkbox=pilot[]) John Smith
(checkbox=pilot[]) Jane Doe
(checkbox=pilot[]) Bob Brown

What I need to happen is when the user selects a view, the maximum number of checkboxes for both sets will be set (i.e. day =3, week = 2, month = 1).

I have this code on the end of the check box:
<script type="text/javascript" language="JavaScript"> 
var freeItemCount=0 
var maxFreeItems=2  

function setItems(pilot)


if (freeItemCount>maxFreeItems)
  alert('You may only choose '+maxFreeItems+' pilot(s). Please choose the '+maxFreeItems+' pilot(s) you want included in your custom view') 
But I need to seperate the two categories and be able to dynamically change maxFreeItems according to the view selected!