Add error handling and move functions

Add showing of alerts if there is a problem with the request;
This can for instance be wrong title, not started, expired or wrong pin
Move some functions around, out of the document ready and getJSON