Smart javascript form validation