--- fb_form.module.orig	2009-10-27 21:39:52.000000000 +0100
+++ fb_form.module	2009-11-04 13:43:44.500000000 +0100
@@ -41,12 +41,25 @@ function fb_form_form_alter(&$form, &$fo
     unset($form['#fb_form_type_hack']);
   }
 
-  // Support for ahah (see ahah_forms.module)
-  if (function_exists('fb_canvas_is_fbml') &&
-      fb_canvas_is_fbml()) {
-    $form['#after_build'][] =  'fb_ahah_bind_form';
+  // Support for ahah within iframe canvas. The ahah js connection is done with a new session id.
+  // We set a cookie in the user browser that is the same browser using the ahah feature
+  // That is needed in the case that there were only a fb canvas application without fb connect, because
+  // there is no sessions_id's in the cookies.
+  if ((function_exists('fb_canvas_is_iframe') && fb_canvas_is_iframe()) && array_keys($form, '#ahah')) {
+    // Allows IE to accept cookies within iframe sessions
+    header('P3P: CP="CAO PSA OUR"');
+    // Set a cookie with an expiration of 1 day: 86400 sec
+    setcookie('fb_ahah_iframe', session_id(), time() + 86400);
+    // Safari browser doesn't allow set cookies in iframes with different urls
+    // In this case, we add the session with a hidden field
+    if (!isset($_COOKIE['fb_ahah_iframe'])){
+      $form['fb_forms_iframe_session_id'] = array (
+        '#type' => 'hidden',
+        '#default_value' => session_id(),
+        '#tree' => TRUE,
+      );
+    }
   }
-  
 }
 
 /**
