function suggestEngine(node,url)
{
  
  var e = (e)?e:((window.event)?window.event:null);
  var target = (e && e.srcElement)?e.srcElement:((e)?e.target:null);
  
  this.change = function()
  {
    if (this.href)
    {
      document.location = this.href;
    }
    else
    {
      if (this.list.children.length == 1) 
      {
        document.location  = this.list.children[0].firstChild.href;
      } 
      else
      {
         var find = false;
         var anchorurl = '';
         
         for(var i=0;i<this.list.children.length;i++)
         {
           var anchor = this.list.children[i].firstChild;
           
           if (anchor.href.toLowerCase().indexOf(this.node.value.toLowerCase()) != -1)
           {
             anchorurl = anchor.href;
             this.node.value = anchor.innerHTML;
             find = true;
             break;
           }  
         }
         
         if (!find)
         {
           alert('Wpisz nazwę szukanej miejscowości. Nazwa miejscowości musi znajdować się na liście rozwijanej.');       
         } 
         else
         {
            document.location = anchorurl; 
         }
         
      } 
      
      //
    }
  }
  
  this.ajax = null;
  this.node = node;
  this.node.owner = this;
  this.url = url;
  this.index = -1;
  this.all = 0;
  this.href = null;
  
  this.getTopPos = function(inputObj)
    {        
      var returnValue = inputObj.offsetTop;
      while((inputObj = inputObj.offsetParent) != null){
          if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
      }
      return returnValue;
    }
    
    this.getLeftPos = function(inputObj)
    {
      var returnValue = inputObj.offsetLeft;
      while((inputObj = inputObj.offsetParent) != null){
          if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
      }
      return returnValue;
    }
    
  this.ajax = createAjaxObject();
  
    
  
  this.getResponse = function(owner,xmlResponse)
  {
    var xmlDoc = xmlResponse.documentElement;
    var result = xmlDoc.getElementsByTagName('item');
    var len = result.length;
    
    owner.all = len;
    owner.index = -1;
    owner.href = null;
    
    owner.popup.innerHTML = '';
    
    owner.list = document.createElement('div');
    owner.list.className = 'suggest-list';
    
    for(var i=0;i<len;i++)
    {
      var a_name = result[i].childNodes[0].firstChild.data;
      var url_a_name = result[i].childNodes[1].firstChild.data;
      var type = result[i].childNodes[3].firstChild.data;
      
      var div = document.createElement('div');
    
      if (type == 'city') 
       div.innerHTML = '<a href="' +owner.url+url_a_name+'">'+a_name+'</a>';
      else
       div.innerHTML = '<a href="http://www.pogoda.ekologia.pl/Pogoda_na_Swiecie/' +url_a_name+'">'+a_name+'</a>';
       
      div.owner = owner;
      div.onmousemove = function()
                                   {
                                     this.owner.node.value = this.firstChild.innerHTML;
                                     this.owner.href = this.firstChild.href;
                                     var index = 0;
                                     var find = this;
                                     if (owner.index >= 0) owner.list.children[owner.index].className = '';   
                                     while (find = find.previousSibling)
                                     {
                                       index++;  
                                     }
                                     owner.index = index;
                                     
                                     owner.list.children[owner.index].className = 'selected';   
                                     
                                   }
      owner.list.appendChild(div);
    }
    
    owner.popup.appendChild(owner.list);
    
    var close = document.createElement('div');
        closebtn = document.createElement('span');
        closebtn.innerHTML = ' > Zamknij < ';
        close.className = 'suggest-close';
        close.appendChild(closebtn);
        owner.popup.appendChild(close);
    
  }
  this.onClose = function()
  {
      
  }
  this.dispose = function(e)
  {
    var e = (e)?e:((window.event)?window.event:null);
    var target = (e && e.srcElement)?e.srcElement:((e)?e.target:null);
    
    
     
    var owner = document.getElementById('suggest-popup').owner;
    if (!owner) owner = this;
    
    owner.onClose();
    
    if (target != owner.node)
    {
     owner.popup.style.display = 'none'; 
     document.onclick = owner.oldDocClk;
     if (document.onclick != undefined && document.onclick != owner.dispose) document.onclick(e);
    }
    
    

     
     if (e != null)
     {
      e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
     }
    
      
    return true;  
  }
  this.onClickEvent = function(owner,cid)
  {
    if (owner.href) document.location = owner.href;  
    else document.location = url_path_city + owner.node.value;
    
    return false;    
  }
  this.sendAjax = function(e)
  {
   var owner = this;
   if (this.owner) owner = this.owner;
    
   var e = (e)?e:((window.event)?window.event:null);
   var target = (e && e.srcElement)?e.srcElement:((e)?e.target:null);
  
   if (e && e.keyCode && e.keyCode == 13)
   {
     owner.change();
   }
  
   if (e && e.keyCode && e.keyCode == 38)
   {
     if (owner.index > 0)
     {
       owner.list.children[owner.index].className = '';     
       owner.index--;
       owner.list.children[owner.index].className = 'selected';
       owner.node.value = owner.list.children[owner.index].firstChild.innerHTML;
       owner.href = owner.list.children[owner.index].firstChild.href;
     }
     return false; 
   } 
   
  if (e && e.keyCode && e.keyCode == 40)
  { 
    if (owner.index < owner.all - 1)
    {
      if (owner.index >= 0) owner.list.children[owner.index].className = '';   
      owner.index++;
      owner.list.children[owner.index].className = 'selected';
      owner.node.value = owner.list.children[owner.index].firstChild.innerHTML;
      owner.href = owner.list.children[owner.index].firstChild.href;
    }
    return false;
  }  
   
   
   
   if (document.onclick && document.onclick != owner.dispose) document.onclick(e);
   
   owner.oldDocClk = document.onclick;
   
   document.onclick = owner.dispose;
   
   
   if (!document.getElementById('suggest-popup'))
     {
      owner.top = owner.getTopPos(node);
      owner.left = owner.getLeftPos(node);
    
      owner.popup = document.createElement('div');
      owner.popup.className = 'suggest-popup';
      owner.popup.id = 'suggest-popup';
    
      owner.popup.style.position = 'absolute';
      owner.popup.style.top = (owner.top + node.offsetHeight) + 'px';
      owner.popup.style.left = owner.left + 'px';
      owner.popup.owner = owner;
    document.body.appendChild(owner.popup);
   } 
   
   
   
   owner.popup.style.display = 'block';
   
   if (owner.ajax)
   {
     
     var today = new Date();
     
     owner.getSuggest = function(xmlResponse){owner.getResponse(owner,xmlResponse)}
     
     if (owner.query == '') node.value = '';
     
     var lastQuery = owner.query; 
     
     
     
     owner.query = "http://"+document.domain+"/ajax/suggest.php?filtr="+node.value+"&source="+source+"&menu_id="+menu_id;
     
     if (lastQuery != owner.query)
       sendQuery(owner.ajax,'GET',owner.query+"&t="+today.getTime(),owner.getSuggest);
   }
   
    
    if (e != null)
    {
      e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
    }
   
   
   return false;
  }
  
  this.query = '';
  this.node.onkeyup = this.sendAjax;
  this.node.onfocus = this.sendAjax;
}

