function limitCheckboxSelection(form,fieldName,max)
{
	if(!form)
		return false;
	
	var checkboxes = form.getInputs("checkbox", fieldName);
	
	if(!checkboxes)
		return false;
	
	var clickHandler = function()
	{
		//find all currently checked boxes
		checked = checkboxes.findAll(function(i) { return i.checked; });
		
		for(var c in checkboxes)
		{
			//only disable non-checked boxes, and only if there are more than the max checked currently
			if(checked.length >= max && !checkboxes[c].checked)
				checkboxes[c].disabled = true;
			else
				checkboxes[c].disabled = false;
		}
	}
	
	clickHandler();
	checkboxes.map(function(item){item.onclick = clickHandler});
	
}