Use events to handle login flow

Used custom events to trigger the next step in the login process,
otherwise async requests run into each other.
Also fixed an issue between firefox and chrome regarding the returned
data from an ajax call.  used dataType to force a json response from
jquery.ajax.
Close #6