I'm training myself on jQueryMobile and using dialog windows for form submission

The form itself is being submitting via AJAX and when there is a problem with the logon attempt the response kicks in an alert with the error message.

While the submission technically works I'm running into three problems.The first is that when a user successfully logs on jQueryMobile itself flashes an error dialog momentarily and then proceeds as normal.The second being that when an error alert is kicked in, the alert appears as intended but the the dialog window opens again on top of itself.The third is that the first dialog window is blanked out.