--- recaptcha.module.orig	2008-12-04 01:26:48.000000000 -0800
+++ recaptcha.module	2008-12-04 02:24:53.000000000 -0800
@@ -129,11 +129,40 @@
 }
 
 /**
+ * Constructs the javascript to modify the reCAPTCHA theme
+ */
+function _recaptcha_construct_javascript($recaptcha_theme, $recaptcha_tabindex) 
+{
+  global $_recaptcha_jsadded;
+  if (!isset($_recaptcha_jsadded)) { // only display the javascript once.
+    $_recaptcha_jsadded = TRUE;
+    $js = "var RecaptchaOptions = {theme : '$recaptcha_theme'";
+    
+    // Add support to display the custom theme
+    if ($recaptcha_theme == 'custom') {
+     $js .= ", custom_theme_widget : 'recaptcha_custom_theme_widget'";
+     $recaptcha_form_value = theme('recaptcha_custom_widget');
+    }
+    
+    // Set the default tab index
+    if (!empty($recaptcha_tabindex)) {
+      $js .= ', tabindex : '. $recaptcha_tabindex;
+    }
+    drupal_add_js($js .'};', 'inline');
+    return $recaptcha_form_value;
+  }
+  return NULL;
+}
+
+/**
  * reCAPTCHA implementation of hook_captcha
  */
 function recaptcha_captcha() {  
   $args = func_get_args();
   $op = array_shift($args); 
+
+  print "reCAPTCHA: " . $op . "\n";
+
   switch ($op) {
     case 'list':
       return array('reCAPTCHA');
@@ -143,7 +172,6 @@
       $result = array();
       if ($captcha_type == 'reCAPTCHA') {
         require_once('recaptcha.inc');
-        global $_recaptcha_jsadded;
         @(include_once('recaptcha/recaptchalib.php')) or _recaptcha_library_not_found();
 
         // Check if reCAPTCHA is available and show Math if not
@@ -158,25 +186,9 @@
         $recaptcha_theme = variable_get('recaptcha_theme', 'red');
         $recaptcha_tabindex = variable_get('recaptcha_tabindex', NULL);
         $recaptcha_public_key = variable_get('recaptcha_public_key', '');
-        $recaptcha_form_value = NULL;
         
         // Construct the Javascript
-        if (!isset($_recaptcha_jsadded)) { // only display the javascript once.
-          $_recaptcha_jsadded = TRUE;
-          $js = "var RecaptchaOptions = {theme : '$recaptcha_theme'";
-          
-          // Add support to display the custom theme
-          if ($recaptcha_theme == 'custom') {
-           $js .= ", custom_theme_widget : 'recaptcha_custom_theme_widget'";
-           $recaptcha_form_value = theme('recaptcha_custom_widget');
-          }
-          
-          // Set the default tab index
-          if (!empty($recaptcha_tabindex)) {
-            $js .= ', tabindex : '. $recaptcha_tabindex;
-          }
-          drupal_add_js($js .'};', 'inline');
-        }
+        $recaptcha_form_value = _recaptcha_construct_javascript($recaptcha_theme, $recaptcha_tabindex);
         
         // Create the form
         $result['preprocess'] = TRUE; // tell captcha to preprocess the form
@@ -193,6 +205,12 @@
     case 'preprocess':
       require_once('recaptcha.inc');
       @(include_once('recaptcha/recaptchalib.php')) or _recaptcha_library_not_found();
+
+      // Construct the Javascript
+      $recaptcha_theme = variable_get('recaptcha_theme', 'red');
+      $recaptcha_tabindex = variable_get('recaptcha_tabindex', NULL);
+      _recaptcha_construct_javascript($recaptcha_theme, $recaptcha_tabindex);
+
       $resp = recaptcha_check_answer(
         variable_get('recaptcha_private_key', ''),
         $_SERVER['REMOTE_ADDR'],
