Working with checkboxes

Working with checkboxes

Hello everyone!!!
I am really need your help.
I have a list with checkboxes, like:
CHK1(main category)
--CHK2(sub category)
--CHK3(sub category)
--CHK4(sub category)

How can I do the next things:
1) When I click the CHK1 all sub categories will checked?
2) When I check the sub category, the main category will checked automatic?

THANKS.