SearchBox.prototype.onChange = function(){}
var inst;

function SearchBox()
{
this.kw=undefined;
this.box=undefined;
this.tb=undefined;
inst=this;

this.show=function(textbox)
 {
 if (typeof tb != 'undefined')
    {
    this.close();
    return;
    }

 tb=textbox;
 var d=document.createElement('div');
 d.style.position='absolute';
 d.style.border='2px solid #6F9BFC';
 d.style.backgroundColor='white';

 var top=0;
 var left=0;
 for (var p=textbox; p; p=p.offsetParent){
     top+=p.offsetTop;
     left+=p.offsetLeft;
     }
 d.style.left=left+'px';
 d.style.top=top+textbox.offsetHeight+'px';


 var table=document.createElement('table');
 var tbody=document.createElement('tbody');
 table.appendChild(tbody);

 var row=tbody.insertRow(-1);

 var cell=row.insertCell(-1);
 cell.innerHTML='<span class="hyperLink"><a href="javascript:void(0)" onclick="window.open(\'suggestion.php\',\'sugg\',\'width=400,height=350,resizable=1,scrollbars=no\').focus();"><span class="tinyText">Suggest a New Talent</span></a></span>';

 var img=document.createElement('img');
 img.src='/images/buttons/x.gif';
 img.style.cursor='pointer';
 img.onclick=this.close;
 cell=row.insertCell(-1);
 cell.appendChild(img);

 row=tbody.insertRow(-1);
 cell=row.insertCell(-1);
 cell.innerHTML='<span style="font:bold 12px arial,verdana">Search Your Talent:</span><br />';
 var inp=document.createElement('input');
 inp.type='text';
 inp.style.border='2px solid #19E701';
 inp.style.fontSize='14px';
 inp.style.fontFamily='verdana,arial,helvetica,sans-serif';
 inp.style.backgroundColor='#FEFF93';
 inp.size=25;
 inp.onkeyup=this.query;
 kw=inp;
 cell.appendChild(inp);

 row=tbody.insertRow(-1);
 cell=row.insertCell(-1);
 var rd=document.createElement('div');
 cell.appendChild(rd);
 res=rd;

 d.appendChild(table);

 document.body.appendChild(d);
 box=d;
 kw.focus();
 }

this.assign=function(event,lb)
 {
 if (event!=null)
    {
    var k = event.keyCode ? event.keyCode : event.charCode;
    if (k==38||k==40)
        return true;
    else
    if (k!=13)
        return false;
    }

 tb.value=lb.value;
 this.close();
 this.onChange();
 }

this.close=function()
 {
 if (typeof box!='undefined')
     document.body.removeChild(box);
 box=undefined;
 tb=undefined;
 kw=undefined;
 }

this.query=function()
 {
 var req=undefined;
 if (window.XMLHttpRequest)
    {
    req=new XMLHttpRequest();
    if (req.overrideMimeType)
       {
       req.overrideMimeType('text/xml');
       }
    }
 else
 if (window.ActiveXObject)
    {
    try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(e)
      {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(e) { }
      }
    }

 req.onreadystatechange = function()
   {
   if (req.readyState == 4)
      {
      if (req.status == 200 && req.statusText == 'OK')
         {
         if (req.responseText.indexOf("<resp>empty</resp>") != -1)
            {
            res.innerHTML = '<div align="center">- No matches found -</div>';
            }
         else
            {
            var out = '<select size="5" onclick="inst.assign(null,this)" onkeydown="return inst.assign(event,this)">';
            out += req.responseText;
            out += '</select>';
            res.innerHTML = out;
            }
         }
      }
   };

 req.open('GET','../../ajax.php?action=get&item=subtalents&term='+escape(kw.value),true);
 req.send(undefined);
 }

};
