diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js
index 122f05d..88186be 100644
--- a/core/misc/autocomplete.js
+++ b/core/misc/autocomplete.js
@@ -11,7 +11,7 @@ Drupal.behaviors.autocomplete = {
       if (!acdb[uri]) {
         acdb[uri] = new Drupal.ACDB(uri);
       }
-      var $input = $('#' + this.id.substr(0, this.id.length - 13))
+      var $input = $('#' + this.id.substr(0, this.id.length - 13), context)
         .attr('autocomplete', 'OFF')
         .attr('aria-autocomplete', 'list');
       $($input[0].form).submit(Drupal.autocompleteSubmit);
@@ -43,13 +43,20 @@ Drupal.autocompleteSubmit = function () {
 Drupal.jsAC = function ($input, db) {
   var ac = this;
   this.input = $input[0];
-  this.ariaLive = $('#' + this.input.id + '-autocomplete-aria-live');
+  this.ariaLive = $('#' + $input.attr('id') + '-autocomplete-aria-live');
   this.db = db;
 
   $input
     .keydown(function (event) { return ac.onkeydown(this, event); })
     .keyup(function (event) { ac.onkeyup(this, event); })
-    .blur(function () { ac.hidePopup(); ac.db.cancel(); });
+    .blur(function () { 
+      if (!ac.selected&&ac.db.cache[this.value]&&ac.db.cache[this.value][this.value]) {
+        $input.data('autocompleteValue',ac.db.cache[this.value][this.value]);		
+        ac.select($input);
+      }
+        ac.hidePopup(); 
+        ac.db.cancel(); 
+     });
 };
 
 /**
@@ -114,7 +121,28 @@ Drupal.jsAC.prototype.onkeyup = function (input, e) {
  * Puts the currently highlighted suggestion into the autocomplete field.
  */
 Drupal.jsAC.prototype.select = function (node) {
-  this.input.value = $(node).data('autocompleteValue');
+  var autocompleteValue = $(node).data('autocompleteValue');
+  this.input.value = autocompleteValue['key'];
+  $('.autocomplete-'+this.input.name).each(function () {
+	var $name;
+	if ($(this).hasClass("stripid")) {
+		var reg=/.*[^0-9]/;
+		$name = reg.exec(this.name);
+	}
+	else
+		$name = this.name;
+	if (this.type.indexOf("select")==0) {
+		$(this).val(autocompleteValue[$name]);
+	}
+	else if (this.type.indexOf("checkbox")==0) {
+		if ((autocompleteValue[$name]==1)||(autocompleteValue[$name]=='true')||(autocompleteValue[$name]==true))
+			$(this).attr('checked', true);
+		else
+			$(this).attr('checked', false);
+	}
+	else
+  		this.value = autocompleteValue[$name];
+  });
 };
 
 /**
@@ -169,7 +197,7 @@ Drupal.jsAC.prototype.unhighlight = function (node) {
 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).data('autocompleteValue');
+    this.select(this.selected);
   }
   // Hide popup.
   var popup = this.popup;
@@ -222,11 +250,11 @@ Drupal.jsAC.prototype.found = function (matches) {
   for (var key in matches) {
     if (matches.hasOwnProperty(key)) {
       $('<li></li>')
-        .html($('<div></div>').html(matches[key]))
+        .html($('<div></div>').html(match.title))
         .mousedown(function () { ac.select(this); })
         .mouseover(function () { ac.highlight(this); })
         .mouseout(function () { ac.unhighlight(this); })
-        .data('autocompleteValue', key)
+        .data('autocompleteValue', match)
         .appendTo(ul);
     }
   }
