// najbardziej namieszany skrypt jaki pisalem

function podpowiedz()
{
	clearTimeout(t);
	t = setTimeout("ParseQuery()",800);
}


function ParseQuery()
{
	q = document.wyszukiwarka.q.value;
	
	if(q.length > 0 && old_q != q)
	{
		jQuery.post("http://www.autocentrum.pl/scripts/search/podpowiedz.php",{q : q});
		old_q = q;
	}
}



























/*
function get(q){
 plik = "http://"+location.host+"/scripts/search/podpowiedz.php?q="+q;
 xml = null;
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
      document.getElementById('podpowiedz').innerHTML="";
      document.getElementById('podpowiedz').innerHTML = xml.responseText;
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 }
 return false;
}

var background = '#295d99';
var kolor = '#ffffff';

  function koloruj(el) {
    el.style.color = kolor;
    el.style.backgroundColor = background;              
  }
  function wybiel(el) {
    el.style.color = '#000000';
    el.style.backgroundColor = '#ffffff';              
  }
  function wybielWszystko(el) {
    var ile = el.length;
    for (var i=0;i<ile;i++) {
      wybiel(el[i]);
    }
  }

  var sugestia =-1;
  var enter = 0;
  
  function submituj() {
    if (sugestia < 0) {
      document.wyszukiwarka.submit();
//      alert ('submituje');
    } else {
      return false;
//      alert (' nie submituje');
    }
  }

function goDown() {
  element = document.getElementById('podpowiedz');
  var tab = element.getElementsByTagName('a');
  var ile = tab.length;
              sugestia++;
              if (sugestia > 6) {
                element.scrollTop += 14;
              }
              if (sugestia > ile-1) {sugestia = ile -1;}
              for (i=0;i<ile;i++) {
                tab[i].style.color = '#000000';
                tab[i].style.backgroundColor = '#ffffff';
              }
              document.getElementById('link[' + sugestia + ']').style.color = kolor;
              document.getElementById('link[' + sugestia + ']').style.backgroundColor = background;
}
function goUp() {
  element = document.getElementById('podpowiedz');
  var tab = element.getElementsByTagName('a');
  var ile = tab.length;
              sugestia --;
              if (sugestia < ile -6) {
                element.scrollTop -= 14;
              }
              if (sugestia <0) {sugestia =0;}
              for (i=0;i<ile;i++) {
                tab[i].style.color = '#000000';
                tab[i].style.backgroundColor = '#ffffff';
              }
              document.getElementById('link[' + sugestia + ']').style.color = kolor;
              document.getElementById('link[' + sugestia + ']').style.backgroundColor = background;              
}
var cykl;


function klawisz(e) {
  var kod = (window.event) ? window.event.keyCode : e.which;
  element = document.getElementById('podpowiedz');
//  alert("kod" + kod);
  var tab = element.getElementsByTagName('div');
  var ile = tab.length;
  switch(kod) {
    case 13 : if (sugestia >= 0) { // ENTER
//              alert ("taki alert" + tab[sugestia].innerHTML);
              document.getElementById('q').value = tab[sugestia].innerHTML;
              document.getElementById('podpowiedz').innerHTML="";
              document.getElementById('podpowiedz').style.display = "none";
              enter = 1;
              sugestia = -2;
              }
          //     else {
            //  sugestia = 0;
              submituj();
              //}
              break;
    case 33 : // PageUp
              sugestia = sugestia - 6;
              element.scrollTop -= 6*14;
              if (sugestia <0) {sugestia =0;}
              for (i=0;i<ile;i++) {
                tab[i].style.color = '#000000';
                tab[i].style.backgroundColor = '#ffffff';
              }              
              document.getElementById('link[' + sugestia + ']').style.color = kolor;
              document.getElementById('link[' + sugestia + ']').style.backgroundColor = background;              
              break;
    case 34 : // PageDown
              sugestia = sugestia + 6;
              element.scrollTop += 6*14;
              if (sugestia > ile-1) {sugestia = ile -1;}
              for (i=0;i<ile;i++) {
                tab[i].style.color = '#000000';
                tab[i].style.backgroundColor = '#ffffff';
              }              
              document.getElementById('link[' + sugestia + ']').style.color = kolor;
              document.getElementById('link[' + sugestia + ']').style.backgroundColor = background;              
              break;
    case 38 : // STRZALKA  W GORE
              clearInterval(cykl);
              sugestia --;
              if (sugestia < ile -4) {
                element.scrollTop -= 14;
              }
              if (sugestia <0) {sugestia =0;}
              for (i=0;i<ile;i++) {
                tab[i].style.color = '#000000';
                tab[i].style.backgroundColor = '#ffffff';
              }
              document.getElementById('link[' + sugestia + ']').style.color = kolor;
              document.getElementById('link[' + sugestia + ']').style.backgroundColor = background;
              document.getElementById('q').value = tab[sugestia].innerHTML + ' ';
              break;
    case 40 : // STRZALKA W DOL
              clearInterval(cykl);
              sugestia++;
              if (sugestia > 4) {
                element.scrollTop += 14;
              }
              if (sugestia > ile-1) {sugestia = ile -1;}
              for (i=0;i<ile;i++) {
                tab[i].style.color = '#000000';
                tab[i].style.backgroundColor = '#ffffff';
              }
              document.getElementById('link[' + sugestia + ']').style.color = kolor;
              document.getElementById('link[' + sugestia + ']').style.backgroundColor = background;
              document.getElementById('q').value = tab[sugestia].innerHTML + ' ';
              break;
    default:  sugeruj(); break;
  }  
}

function sugeruj() {
sugestia = -1;
//fokus = TRUE;
element = document.getElementById('podpowiedz');
element.scrollTop = 0;
var q = document.getElementById('q').value ;
 tab_q = q.split(' ');
var wielkosc = tab_q.length;
if (q.length >2) {
  if(window.navigator.appName=="Microsoft Internet Explorer"){
//    element.style.display = "inline";
    element.style.position = "relative";
    element.style.top = -20 + "px";
//    element.style.top = 208 + "px";
//    element.style.left = 580+ "px";
  }
  element.style.display = "block";
  if (tab_q[wielkosc-1].length >2)
    { get(q); }
  else {
    document.getElementById('q').innerHTML = '';
  }
}
else {
  element.style.display = "none";
}
//window.setTimeout('fokustak()', 2000);
}

function klik(obiekt) {
  if (obiekt != false) {
    document.getElementById('q').value = obiekt;
  }
  document.getElementById('podpowiedz').innerHTML="";
  document.getElementById('podpowiedz').style.display = "none";
}


function _GET(in_zmienna)
{
	adres = document.URL;
	query = adres.substring( adres.indexOf('?') + 1 );
	zmienne = query.split('&'); //3
	for (i=0; i<zmienne.length; i++) { //4
		nazwa = zmienne[i].split("=")[0]; //5
		wartosc = zmienne[i].split("=")[1]; //6
		if (nazwa == in_zmienna) {
			return unescape(wartosc);
		} //7
	}
}
*/
