Index: image_captcha/image_captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.module,v
retrieving revision 1.8.2.2
diff -b -u -p -r1.8.2.2 image_captcha.module
--- image_captcha/image_captcha.module	7 Apr 2008 22:25:45 -0000	1.8.2.2
+++ image_captcha/image_captcha.module	21 Dec 2009 14:15:52 -0000
@@ -44,6 +44,11 @@ function image_captcha_menu() {
     'access callback' => TRUE,
     'type' => MENU_CALLBACK,
   );
+  $items['image_captcha/refresh'] = array(
+    'page callback' => 'image_captcha_captcha_refresh',
+    'access callback' => TRUE,
+    'type' => MENU_LOCAL_TASK
+  );
   return $items;
 }
 
@@ -137,7 +142,7 @@ function image_captcha_captcha($op, $cap
         $result['solution'] = $code;
         $result['form']['captcha_image'] = array(
           '#type' => 'markup',
-          '#value' => '<img src="'. check_url(url("image_captcha/$seed")) .'" alt="'. t('Image CAPTCHA') .'" title="'. t('Image CAPTCHA') .'" />',
+          '#value' => '<img id="image-captcha-image" src="'. check_url(url("image_captcha/$seed")) .'" align="middle" alt="'. t('Image CAPTCHA') .'" title="'. t('Image CAPTCHA') .'" /><a href="javascript:void(0)" onclick= "change_image();return false;" title="Refresh Image">Refresh Image </a>',
           '#weight' => -2,
         );
         $result['form']['captcha_response'] = array(
@@ -148,8 +153,39 @@ function image_captcha_captcha($op, $cap
           '#required' => TRUE,
           '#size' => 15,
         );
+        $result['image_url'] = check_url(url("image_captcha/$seed"));
+        drupal_add_js(array(
+          'image_captcha' => array(
+            'ajaxUrl' => url('image_captcha/refresh/', array('absolute'=>true)),
+          ),
+        ), 'setting');
+        drupal_add_js('
+        function change_image() {
+          $.get(
+            Drupal.settings.image_captcha.ajaxUrl
+            + $("input[@name=\'form_id\']").val()
+            + "/"
+            + $("input[@name=\'captcha_token\']").val(),
+            function(response) {
+              $("#image-captcha-image").attr("src",response);
+              $("#edit-captcha-response").val("");
+            }
+          );
+          return false;
+        }
+        ', 'inline');
         return $result;
       }
     break;
   }
 }
+
+/**
+ * menu callback function that refresh the CAPTCHA image
+ */
+function image_captcha_captcha_refresh($form_id, $captcha_token) {
+  $result = image_captcha_captcha('generate', 'Image');
+  $_SESSION['captcha'][$form_id][$captcha_token] = $result['solution'];
+  echo $result['image_url'];
+  exit;
+}
