Move Dialog code to a seperate JS script for easier maintenance