Iuri,
You might be interested in the qf_ form API. It's made for scenarios like the one you have, with multiple arrays, dynamically declared forms and fields etc:
https://openacs.org/forums/message-view?message_id=3602056
It doesn't include javascript, but it's easily added.
cheers,
Torben