 // stores the reference to the XMLHttpRequest object
var xmlHttpdownload = createXmlHttpRequestObjectdownload();

 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObjectdownload()
{
   // will store the reference to the XMLHttpRequest object
   var xmlHttpdownload;
   // if running Internet Explorer
   if(window.ActiveXObject)
   {
      try
      {
         xmlHttpdownload = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
         xmlHttpdownload = false;
      }
   }
   // if running Mozilla or other browsers
   else
   {
      try
      {
         xmlHttpdownload = new XMLHttpRequest();
      }
      catch (e)
      {
         xmlHttpdownload = false;
      }
   }
   // return the created object or display an error message
   if (!xmlHttpdownload)
      alert("Error creating the XMLHttpRequest object.");
   else
      return xmlHttpdownload;
}
// make asynchronous HTTP request using the XMLHttpRequest object
function process_download()
{
   // proceed only if the xmlHttp object isn't busy
   if (xmlHttpdownload.readyState == 4 || xmlHttpdownload.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 produktgruppe = escape(document.getElementById("produktgruppe").options[document.getElementById('produktgruppe').selectedIndex].value);
      var produkt = escape(document.getElementById("produkt").options[document.getElementById('produkt').selectedIndex].value);
      var lang = escape(document.getElementById("lang").value);




if(produkt == 0) {  


document.getElementById("produkt").options[0].text = "Bitte erst Produkt wählen";
document.getElementById("produkt").selectedIndex = 0;

};






       // execute the download.php page from the server
      xmlHttpdownload.open("GET", "process_download.php?hersteller=" + hersteller + "&lang="+lang+"&produktgruppe="+produktgruppe+"&produkt="+produkt, true);
      // define the method to handle server responses
      xmlHttpdownload.onreadystatechange = handleServerResponsedownload;
      // make the server request
      xmlHttpdownload.send(null);
   }
   else {
      // if the connection is busy, try again after one second
      // setTimeout('process_download()', 10000);
   };
}




// executed automatically when a message is received from the server
function handleServerResponsedownload()
{
   // move forward only if the transaction has completed
   if (xmlHttpdownload.readyState == 4)
   {
      // status of 200 indicates the transaction completed successfully
      if (xmlHttpdownload.status == 200)
      {
	// extract the XML retrieved from the server
	xmlResponse = xmlHttpdownload.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");
	arrsprache = xmlRoot.getElementsByTagName("sprache");
	arrhersteller = xmlRoot.getElementsByTagName("hersteller");
	arrproduktgruppe = xmlRoot.getElementsByTagName("produktgruppe");
	arrfilename = xmlRoot.getElementsByTagName("filename");
	arrtimestamp = xmlRoot.getElementsByTagName("timestamp");
	arrsort_id = xmlRoot.getElementsByTagName("sort_id");
	arrtype = xmlRoot.getElementsByTagName("type");
	arrlinkname = xmlRoot.getElementsByTagName("linkname");


var output = "";


	 for(var i=0; i<arrid.length; i++) {


// defines used variables
var id = "";
var sprache = "";
var hersteller = "";
var produktgruppe = "";
var filename = "";
var timestamp = "";
var sort_id = "";
var type = "";
var linkname = "";



if (arrid.item(i).hasChildNodes())
{
id = arrid.item(i).firstChild.data;
};

if (arrsprache.item(i).hasChildNodes())
{
sprache = arrsprache.item(i).firstChild.data;
};

if (arrhersteller.item(i).hasChildNodes())
{
hersteller = arrhersteller.item(i).firstChild.data;
};

if (arrproduktgruppe.item(i).hasChildNodes())
{
produktgruppe = arrproduktgruppe.item(i).firstChild.data;
};

if (arrfilename.item(i).hasChildNodes())
{
filename = arrfilename.item(i).firstChild.data;
};

if (arrtimestamp.item(i).hasChildNodes())
{
timestamp = arrtimestamp.item(i).firstChild.data;
};

if (arrsort_id.item(i).hasChildNodes())
{
sort_id = arrsort_id.item(i).firstChild.data;
};

if (arrtype.item(i).hasChildNodes())
{
type = arrtype.item(i).firstChild.data;
};

if (arrlinkname.item(i).hasChildNodes())
{
linkname = arrlinkname.item(i).firstChild.data;
};





output += "<p><a href=\"downloads_send.php?send="+id+"\">"+filename+"</a></p>";


	 };






         // update the client display using the data received from the server
	document.getElementById("dlcontent").innerHTML = output;
         // restart sequence
         // setTimeout('process_produkt()', 1000000000000);
      }
      // a HTTP status different than 200 signals 
      else
      {
       //  alert("There was a problem accessing the server: " + xmlHttpprodukt.statusText);
      }
   }
} 

