#571566 by cam8001, Dave Reid: Updated for removed drupal_function_exists() and renamed drupal_to_js().