function ajax_process()
{

  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // retrieve the name typed by the user on the form
    name = encodeURIComponent(document.getElementById("udstilling").value);
   
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "../../../plugins/udstilling/includes/getudstillinginfo.php?id=" + name, 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('ajax_process()', 1000);
}

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
      xmlRoot = xmlResponse.documentElement;
      // get the text message, which is in the first child of
      // the the document element
      
      yearArray = xmlRoot.getElementsByTagName("year");
      dateArray = xmlRoot.getElementsByTagName("udate");
      pkl1Array = xmlRoot.getElementsByTagName("pkl1");
      pkl2Array = xmlRoot.getElementsByTagName("pkl2");
      prallyArray = xmlRoot.getElementsByTagName("prally");
      pkl1activeArray = xmlRoot.getElementsByTagName("pkl1active");
      pkl2activeArray = xmlRoot.getElementsByTagName("pkl2active");
      prallyactiveArray = xmlRoot.getElementsByTagName("prallyactive");


      for (var i=0; i<yearArray.length; i++){
       
            yearVal = yearArray.item(i).firstChild.data;
            dateVal = dateArray.item(i).firstChild.data;
            pkl1Val = pkl1Array.item(i).firstChild.data;
            pkl2Val = pkl2Array.item(i).firstChild.data;
			prallyVal = prallyArray.item(i).firstChild.data;

            pkl1activeVal = pkl1activeArray.item(i).firstChild.data;
            pkl2activeVal = pkl2activeArray.item(i).firstChild.data;
            prallyactiveVal = prallyactiveArray.item(i).firstChild.data;
       }
     
       
      if(pkl1activeVal==1){
	 	    document.getElementById("lpfields").style.visibility = "visible";
			document.getElementById("lpfields").style.display = "block";	  
 	  }else{
			document.getElementById("lpfields").style.display = "none";	  
		}

    

      if(prallyactiveVal==1){
	 	    document.getElementById("rallyfields2").style.visibility = "visible";
			document.getElementById("rallyfields2").style.display = "block";	  
	 	    document.getElementById("wdfields2").style.display = "none";	  
 	  }else{
	 	    document.getElementById("rallyfields2").style.display = "none";	  
	
	  }

 
	 if(pkl2activeVal==1){
	 	    document.getElementById("wdfields2").style.visibility = "visible";
			document.getElementById("wdfields2").style.display = "block";
	 	    document.getElementById("lpfields").style.visibility = "visible";
			document.getElementById("lpfields").style.display = "block";	  
	 	    document.getElementById("rallyfields2").style.visibility = "visible";
			document.getElementById("rallyfields2").style.display = "block";	  
 	  }else{
		document.getElementById("wdfields2").style.display = "none";	  
	  }

      document.getElementById("udst_year").innerHTML =dateVal + " " + yearVal;
	  if(pkl1Val==0){
		pkl1Val="";
	  }

      document.getElementById("pkl1").innerHTML = pkl1Val;
	  if(pkl2Val==0){
		pkl2Val="";
	  }
      document.getElementById("pkl2").innerHTML = pkl2Val; 
	  if(prallyVal==0){
		prallyVal="";
	  }

	  document.getElementById("prally").innerHTML = prallyVal; 
      
     
   
      //setTimeout('ajax_ process()', 1000);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
