How to catch the "Login Failed" event?
You can use the rules module for this if you don't want to write PHP.

If you want it to be an ajax event you will need to write a custom login form.

The user.module has a set of functions you can call for validation: user_login_final_validate().

I suggest rules module, save yourself some time.