Warn when navigating away from plan

Includes significant refactoring of plans.js - fewer AJAX calls, better performance, hopefully more readable.