/*
 *
 *
 *
 */

var aktywny = 0;
var licznik = 0;
var nope = 0;
var iloscall=0;
var szukane="";

function Ustaw(co){
	document.getElementById("inputSearch").value=co;
}

function Schowaj(){
	aktywny = 0;
	licznik = 0;
	nope=0;
	document.getElementById("txtHint").style.display="none";
}

function Pokaz(){
	aktywny=1;
	licznik = 0;
	nope=0;
	document.getElementById("txtHint").style.display="block";
}

document.getElementById("inputSearch").onkeydown = function(e){

if(aktywny){
    var evtobj=window.event? event : e
    var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode

  switch(unicode) {
          case 38: //up arrow
	if(aktywny){nope=1;      }
	      licznik=licznik-1;
          break;


          case 40: //down arrow
	    	if(aktywny){nope=1;      }
	    licznik=licznik+1;
              break;

          case 13: //enter
	if(aktywny){nope=1;      
		    
		    javascript:document.szukanie.submit()
	}


              break;

          case 8: // BS
	if(aktywny){
	    Schowaj();      
	    nope=1;
	}

              break;

          case 27: // escape
	if(aktywny){
	    Schowaj();      
	    nope=1;
	}
	  
              break;

	      
	      default:
	      nope=0;
  }


	    var is = 1;
	    while (document.getElementById("srta"+is) != null)
	    {
			    document.getElementById("srta"+is).className="srta";
		is++;
	    }

	      iloscall=is;


if(licznik<0){licznik=iloscall-1;}
if(licznik>iloscall-1){licznik=0;}

	    Ustaw(document.getElementById("srtap"+licznik).innerHTML);
    if(licznik == 0){
	Ustaw(szukane);
    }
    	    
			    document.getElementById("srta"+licznik).className="srtahover";
    
}

}

function GetXmlHttpObject() {
var xmlHttp=null;

try {
    xmlHttp=new XMLHttpRequest();
} catch (e) {
    try {
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e){
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
}
return xmlHttp;
}

function stateChanged() {
    if (xmlHttp.readyState==4) {

    if(xmlHttp.responseText.length > 220){
	    document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
	    if(aktywny == 0 && nope == 0){
		Pokaz();
	    }
    } else {
	        Schowaj();
    }
    }
}

function showHint(str2,e) {
    return;
    var str = strtr(str2, '±¡êÊ¿¯¼¬¶¦óÓcÆñÑ³£', 'aAeEzZzZsSoOcCnNlL');
    var re = /^[a-zA-Z0-9\+\#\ ]+/;
    if(str.length > 1 && re.test(str)){
	xmlHttp=GetXmlHttpObject();

	if ( xmlHttp==null ) {
	    alert ("Your browser does not support AJAX!");
	    return;
	}


    if(!nope){
	szukane=document.getElementById("inputSearch").value;
        var url="/geth.cgi";
        url = url + "?q=" + str;
        url = url + "&sid=" + Math.random();
        xmlHttp.onreadystatechange = stateChanged;
        xmlHttp.open( "GET", url, true );
        xmlHttp.setRequestHeader("Content-Type", "text/plain;charset=iso-8859-2");
        xmlHttp.send( null );
	
	} else {

        }
    } else {
    Schowaj();
}
    
}

function strtr (str, from, to) {
var fr = '', i = 0, lgth = 0;

if (typeof from === 'object') {
for (fr in from) {
str = str.replace(fr, from[fr]);
}
return str;
}

lgth = to.length;
if (from.length < to.length) {
lgth = from.length;
}
for (i = 0; i < lgth; i++) {
str = str.replace(from[i], to[i]);
}

return str;
}

