// JavaScript Document
var httpRequest_NL = false;
var NL_url = "http://"+ window.location.hostname +"/includes/nahrung_liste.php";

function ResetNahrung() {
	document.getElementById("nahrungsuche").value='Suchbegriff Nahrung hier eingeben ...';
	document.getElementById("nahrungsergebnis").style.display='none';  
}

function updateNahrung(type) {
   var nahrungsuche = document.getElementById("nahrungsuche").value;
   var suchkatn = document.getElementById("suchkatn").options[document.getElementById("suchkatn").selectedIndex].value;
   if(nahrungsuche.length > 2) {
			  function clear_eingabe() {
				   ResetNahrung()
				   document.getElementById("nahrungs_such_button").src = 'http://'+ window.location.hostname +'/images/usertabsuchen_los.gif';
				   document.getElementById("nahrungs_such_button").style.width = "48px";
				   return false;
				}
			  document.getElementById("nahrungs_such_button").src = 'http://'+ window.location.hostname +'/images/clear_left.gif';
			   document.getElementById("nahrungs_such_button").style.height = "16px";
			   document.getElementById("nahrungs_such_button").style.width = "16px";
			   document.getElementById("nahrungs_such_button").onclick = clear_eingabe;
   httpRequest_NL = false;
   if(window.XMLHttpRequest)  // Mozilla, Safari,...
       httpRequest_NL = new XMLHttpRequest();
   else if(window.ActiveXObject) { // IE
       try {
           httpRequest_NL = new ActiveXObject("Msxml2.XMLHTTP");
    }
       catch (e) {
           try {
               httpRequest_NL = new ActiveXObject("Microsoft.XMLHTTP");
     }
           catch (e) {}
       }
   }
   if(!httpRequest_NL) 
      return false;
   httpRequest_NL.onreadystatechange = function() {
	  if(httpRequest_NL.readyState == 4) {
         if(httpRequest_NL.status == 200) 
			handleHttpResponse_NL(httpRequest_NL.responseText);
       else
          return false;
         }
    else
       return false;
   }
   if(document.getElementById('nahrungsergebnis')){
	   document.getElementById('nahrungsergebnis').style.display = 'block';
	   document.getElementById('nahrungsergebnis').innerHTML = "<img src='http://"+ window.location.hostname +"/images/loading.gif' alt='wird geladen' style='width:16px; height:16px; margin:50px 50px 50px 50px;' />";
   }
   httpRequest_NL.open('get', NL_url+'?nahrungsuche='+nahrungsuche+'&type='+type+'&suchkatn='+suchkatn, true);
   httpRequest_NL.send(null);

  }
}

function handleHttpResponse_NL(content) {
	document.getElementById('nahrungsergebnis').innerHTML = content;	
}