Issue #492720 by pivica, seutje, nod_, JamesAn, sun: Refactor system.js file and use Drupal form states and form ajax.

PR for https://drupal.org/node/492720