function ShowPrompt(id)
{
 var eUL = document.getElementById('prompt'+id);

 if (!eUL)  // создаем на месте
 {
   var eUL = document.createElement('UL');
   eUL.id = 'prompt'+id;
   eUL.className = 'prompt';
   document.body.appendChild(eUL);
 }

 eUL.innerHTML = '';

 if (words.length == 0) return;

 for(var i=0; i<words.length; i++)
 {

 var eLI = document.createElement( 'li' );
 var eAnchor = document.createElement( 'a' );
 eAnchor.setAttribute('href', '#');
 eAnchor.onclick = function () { document.getElementById(id).value = this.innerHTML };
 eAnchor.innerHTML = words[i];
 eLI.appendChild( eAnchor );
 eUL.appendChild( eLI );
 }


 var el = document.getElementById(id);
 // получаем координаты (юг,восток) элемента относительно всего окна
 var nwOffset = Coordinates.northwestOffset(el, true);
 var seOffset = Coordinates.southeastOffset(el, true);
 var width = seOffset.x-nwOffset.x;

 var x = nwOffset.x;
 var y = seOffset.y;

 eUL.style.top = y;
 eUL.style.left = x;
 eUL.style.display = 'block';
 eUL.setAttribute('pos', -1);

 if (Timeout2[id]) window.clearTimeout(Timeout2[id]);
 Timeout2[id] = setTimeout(function() {eUL.style.display = 'none' }, 3000);
}/*ShowPrompt*/


var Timeout1 = [];
var Timeout2 = [];
function Request(obj)
{
 var value = obj.value;
 var id = obj.id;
 var old = obj.getAttribute('OldValue');

 if (value.length<3) return;

 if (old != value) 
 {
   if (Timeout1[id]) window.clearTimeout(Timeout1[id]);
   Timeout1[id] = setTimeout(function() {Ajax.SendRequest('/cgi-bin/reestr_prompt.cgi', ('string='+value+'&module='+id), function () {ShowPrompt(id)} )}, 1000);
 }
 obj.setAttribute('OldValue',value)
}/*Request*/

function Select(obj,e)
{
  var id = obj.id;

  var code;
  if (!e) e = window.event;
  if (e.keyCode) code = e.keyCode;
  else if (e.which) code = e.which;

  var eUL = document.getElementById('prompt'+id);
  if (!eUL) return;

  var pos = eUL.getAttribute('pos');
  var li = eUL.getElementsByTagName('LI');

  if (code == 38 && pos>0) pos--; // up
  else if (code == 40 && pos<li.length-1) pos++; // down
  else return;

  for(i=0; i<li.length; i++) li.item(i).className = 'nor';
  li.item(pos).className = 'cur';
  eUL.setAttribute('pos', pos);

  var value = li.item(pos).firstChild.innerHTML;
  obj.value = value;
  obj.setAttribute('OldValue',value)

 if (Timeout2[id]) window.clearTimeout(Timeout2[id]);
 Timeout2[id] = setTimeout(function() {eUL.style.display = 'none' }, 3000);
}/*Select*/
