General function for opening a dialog