Treat contactId consistently in is_...() functions.

That is, do not contact the DB if contactId is 0.
Use `api.php` URLs for AJAX requests.