Javascript event manager implemented in PHP