Index: autocomplete.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/autocomplete.js,v
retrieving revision 1.24
diff -u -r1.24 autocomplete.js
--- autocomplete.js	12 Oct 2008 00:29:09 -0000	1.24
+++ autocomplete.js	16 Oct 2008 22:58:35 -0000
@@ -100,10 +100,79 @@
 };
 
 /**
+ * Create a function call from a string.
+ */
+Drupal.jsAC.prototype.makeCallback = function (callback) {
+  var func = window;
+  var parts = callback.split('.');
+
+  for (var i = 0; i < parts.length; i++) {
+    if (func[parts[i]]) {
+      func = func[parts[i]];
+    }
+  }
+
+  return func;
+}
+
+/**
+ * Parses the value to extract any ids that may be there.
+ */
+Drupal.jsAC.prototype.parseValue = function (value, id) {
+  var return_val = value;
+
+  if (Drupal.settings.autocomplete_ids && Drupal.settings.autocomplete_ids[id]) {
+    var callbacks = Drupal.settings.autocomplete_ids[id];
+    if (callbacks instanceof Array) {
+      for (var i = 0; i < callbacks.length; i++) {
+        var func = Drupal.jsAC.prototype.makeCallback(callbacks[i]);
+        return_val = func(return_val, id);
+      }
+    }
+    else if (typeof(callbacks) == 'string') {
+      var func = Drupal.jsAC.prototype.makeCallback(callbacks);
+      return_val = func(return_val, id);
+    }
+  }
+
+  return return_val;
+};
+
+/**
+ * Helper function to extract an nid
+ */
+Drupal.jsAC.prototype.extractNid = function(value, id) {
+  var matches = /^(.*) \[nid:([0-9]{1,10})\]$/.exec(value);
+
+  if (matches[1] && matches[2]) {
+    $('#' + id + '-nid').val(matches[2]);
+    return matches[1];
+  }
+  else {
+    return '';
+  }
+};
+
+/**
+ * Helper function to extract a vid
+ */
+Drupal.jsAC.prototype.extractVid = function(value, id) {
+  var matches = /^(.*) \[vid:([0-9]{1,10})\]$/.exec(value);
+
+  if (matches[1] && matches[2]) {
+    $('#' + id + '-vid').val(matches[2]);
+    return matches[1];
+  }
+  else {
+    return '';
+  }
+};
+
+/**
  * Puts the currently highlighted suggestion into the autocomplete field.
  */
 Drupal.jsAC.prototype.select = function (node) {
-  this.input.value = node.autocompleteValue;
+  this.input.value = this.parseValue(node.autocompleteValue, this.input.id);
 };
 
 /**
@@ -155,7 +224,7 @@
 Drupal.jsAC.prototype.hidePopup = function (keycode) {
   // Select item if the right key or mousebutton was pressed.
   if (this.selected && ((keycode && keycode != 46 && keycode != 8 && keycode != 27) || !keycode)) {
-    this.input.value = this.selected.autocompleteValue;
+    this.input.value = Drupal.jsAC.prototype.parseValue(this.selected.autocompleteValue, this.input.id);
   }
   // Hide popup.
   var popup = this.popup;

