Declare `var dialog` before you assign to the variable; otherwise, `dialog` will be a global variable.