Javascript dialog trees using state machines