 // stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject();



// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject()
{
   // will store the reference to the XMLHttpRequest object
   var xmlHttp;
   // if running Internet Explorer
   if(window.ActiveXObject)
   {
      try
      {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }
   // if running Mozilla or other browsers
   else
   {
      try
      {
         xmlHttp = new XMLHttpRequest();
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }
   // return the created object or display an error message
   if (!xmlHttp)
      alert("Error creating the XMLHttpRequest object.");
   else
      return xmlHttp;
}
// make asynchronous HTTP request using the XMLHttpRequest object
function process()
{
   // proceed only if the xmlHttp object isn't busy
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
   {
      // retrieve the search typed by the search on the form
      var hersteller = escape(document.getElementById("hersteller").options[document.getElementById('hersteller').selectedIndex].value);
      var lang = escape(document.getElementById("lang").value);






document.getElementById("produktgruppe").length = null;


if(document.getElementById("lang").value == 1) {
NeuerEintrag = new Option("Bitte erst Hersteller wählen", "0", false, true);
document.getElementById("produktgruppe").options[0] = NeuerEintrag;
};

if(document.getElementById("lang").value == 2) {
NeuerEintrag = new Option("Choose a producer first", "0", false, true);
document.getElementById("produktgruppe").options[0] = NeuerEintrag;
};

if(document.getElementById("lang").value == 3) {
NeuerEintrag = new Option("Selezionare prima il produttore", "0", false, true);
document.getElementById("produktgruppe").options[0] = NeuerEintrag;
};


if(document.getElementById("lang").value == 4) {
NeuerEintrag = new Option("Choisissez d`abord votre fabricant", "0", false, true);
document.getElementById("produktgruppe").options[0] = NeuerEintrag;
};




document.getElementById("produkt").length = null;



if(document.getElementById("lang").value == 1) {
NeuerEintrag = new Option("Bitte erst Produktgruppe wählen", "0", false, true);
document.getElementById("produkt").options[0] = NeuerEintrag;
};

if(document.getElementById("lang").value == 2) {
NeuerEintrag = new Option("Choose a product group first", "0", false, true);
document.getElementById("produkt").options[0] = NeuerEintrag;
};

if(document.getElementById("lang").value == 3) {
NeuerEintrag = new Option("Selezionare prima il prodotto", "0", false, true);
document.getElementById("produkt").options[0] = NeuerEintrag;
};

if(document.getElementById("lang").value == 4) {
NeuerEintrag = new Option("Choisissez d`abord votre fabricant", "0", false, true);
document.getElementById("produkt").options[0] = NeuerEintrag;
};







document.getElementById("dlcontent").innerHTML = "";

       // execute the produktgruppe.php page from the server
      xmlHttp.open("GET", "produktgruppe.php?hersteller=" + hersteller + "&lang="+lang, true);
      // define the method to handle server responses
      xmlHttp.onreadystatechange = handleServerResponse;
      // make the server request
      xmlHttp.send(null);
   }
   else {
      // if the connection is busy, try again after one second
      // setTimeout('process()', 10000);
   };
}




// executed automatically when a message is received from the server
function handleServerResponse()
{
   // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4)
   {
      // status of 200 indicates the transaction completed successfully
      if (xmlHttp.status == 200)
      {
	// extract the XML retrieved from the server
	xmlResponse = xmlHttp.responseXML;
	// obtain the document element (the root element) of the XML structure
	xmlDocumentElement = xmlResponse.documentElement;
	// gets document root
	xmlRoot = xmlResponse.documentElement;




	// reading the content
	arrid = xmlRoot.getElementsByTagName("id");
	arrhersteller_id = xmlRoot.getElementsByTagName("hersteller_id");
	arrname = xmlRoot.getElementsByTagName("name");
	arrtimestamp = xmlRoot.getElementsByTagName("timestamp");
	arrsprache = xmlRoot.getElementsByTagName("sprache");





var counter = 1;


var content = "";






var a = document.getElementById("produktgruppe").options.length;


for(i=0; i<a; i++) {



document.getElementById("produktgruppe").options[1] = null;

if(document.getElementById("lang").value == 1) {
NeuerEintrag = new Option("Bitte erst Hersteller wählen", "0", false, true);
};

if(document.getElementById("lang").value == 2) {
NeuerEintrag = new Option("Choose a producer first", "0", false, true);
};

if(document.getElementById("lang").value == 3) {
NeuerEintrag = new Option("Selezionare prima il produttore", "0", false, true);
};

if(document.getElementById("lang").value == 4) {
NeuerEintrag = new Option("Choisissez d`abord votre fabricant", "0", false, true);
};






document.getElementById("produktgruppe").options[0] = NeuerEintrag;

};








	 for(var i=0; i<arrid.length; i++) {


// defines used variables
var id = '';
var hersteller_id = '';
var name = '';
var timestamp = '';
var sprache = '';





if (arrid.item(i).hasChildNodes())
{
id = arrid.item(i).firstChild.data;
};

if (arrhersteller_id.item(i).hasChildNodes())
{
hersteller_id = arrhersteller_id.item(i).firstChild.data;
};

if (arrname.item(i).hasChildNodes())
{
name = arrname.item(i).firstChild.data;
};

if (arrtimestamp.item(i).hasChildNodes())
{
timestamp = arrtimestamp.item(i).firstChild.data;
};

if (arrsprache.item(i).hasChildNodes())
{
sprache = arrsprache.item(i).firstChild.data;
};



NeuerEintrag = new Option(name, id, false, true);

document.getElementById("produktgruppe").options[counter] = NeuerEintrag;





counter++;
	 };


if(counter > 1) {

if(document.getElementById("lang").value == 1) {
NeuerEintrag = new Option("Alle anzeigen", "showall", false, true);
document.getElementById("produktgruppe").options[counter] = NeuerEintrag;
document.getElementById("produktgruppe").options[0].text = "Bitte wählen";
};

if(document.getElementById("lang").value == 2) {
NeuerEintrag = new Option("Show all", "showall", false, true);
document.getElementById("produktgruppe").options[counter] = NeuerEintrag;
document.getElementById("produktgruppe").options[0].text = "Choose please";
};


if(document.getElementById("lang").value == 3) {
NeuerEintrag = new Option("Mostra tutti", "showall", false, true);
document.getElementById("produktgruppe").options[counter] = NeuerEintrag;
document.getElementById("produktgruppe").options[0].text = "Selezionare";
};

if(document.getElementById("lang").value == 4) {
NeuerEintrag = new Option("Afficher tous", "showall", false, true);
document.getElementById("produktgruppe").options[counter] = NeuerEintrag;
document.getElementById("produktgruppe").options[0].text = "SVP choisissez";
};


};



document.getElementById("produktgruppe").selectedIndex = 0;
document.getElementById("produkt").selectedIndex = 0;



         // update the client display using the data received from the server

         // restart sequence
         // setTimeout('process()', 1000000000000);
      }
      // a HTTP status different than 200 signals 
      else
      {
       //  alert("There was a problem accessing the server: " + xmlHttp.statusText);
      }
   }
} 

