jQuery is available if it helps simplify any of the above.