--- webfm/modules/webfm_popup/webfm_popup.js.OLD	2010-03-10 16:41:02.000000000 +1100
+++ webfm/modules/webfm_popup/webfm_popup.js	2010-03-10 16:41:02.000000000 +1100
@@ -22,6 +22,17 @@
     return;
   }
 
+  if (get_url_param('wysiwyg').length > 0) {
+    var doc = $(window.opener.Drupal.settings.wysiwygDialogWindow.document);
+    var fid = $('#'+obj.row_id).find('td').eq(1).find('a').attr('title');
+    var url_id = '#'+get_url_param('url');
+    doc.find(url_id).val(Drupal.settings.basePath + 'webfm_send/' + fid);
+    doc.find(url_id).change();
+    window.opener.focus();
+    window.close();
+    return;
+  }
+
   // the window this popup was called from
   var doc = $(window.opener.document);
 
@@ -53,3 +64,11 @@
 	if( results == null ) return "";
 	else return results[1];
 }
+
+// Integration for WebFM and wiyisyg module
+// This function opens the webfm_popup
+function webfmImageBrowser(field_name, url, type, win) {
+  Drupal.settings.wysiwygDialogWindow = win;
+  window.open(getBasePath() + 'webfm_popup?url=' + field_name + '&wysiwyg=yes', 'ImageBrowser',
+    'width=750,height=500,toolbar=0,resizable=1,location=0,status=0,menubar=0');
+}
