// ArtPrint Web Application
// ========================
//
// [ AJAX Script ]
// Script gestione richieste con tecnologia AJAX
//
// Versione: 1.07 [02.07.2009]
// Autore: Enrico Alborali
// Copyright: ©2007-2009 ArtPrint s.a.s.

// Inizializzo le variabli globali
var xmlHttp = createXmlHttpRequestObject(); 

/// Funzione ottenere l'oggetto XMLHttpRequest
/// \author: Enrico Alborali
/// \version: 1.02 [03.12.2007]
function createXmlHttpRequestObject() 
{	
	// Variabile che memorizza l'oggetto XMLHttpRequest
	var xmlHttp;
	// Se sto utilizzando Internet Explorer
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) 
		{
			xmlHttp = false;
		}
	}
	// Se sto utilizzando Mozilla Firefox o altri browser
	else
	{
		try 
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) 
		{
			xmlHttp = false;
		}
	}
	// Ritorno l'oggetto creato oppure scrivo un messaggio di errore
	if (!xmlHttp)
		alert("ERRORE! impossibile creare l'oggetto XMLHttpRequest.");
	else 
		return xmlHttp;
}

/// Funzione richiedere le informazioni sulla carta via AJAX
/// \author: Enrico Alborali
/// \version: 1.02 [06.08.2008]
function apAJAXGetPaperInfo()
{
  var TipoCarta;
  // 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
    if (document.getElementById("carta") != null)
	TipoCarta = encodeURIComponent(document.getElementById("carta").value);
	else if (document.getElementById("materiale") != null)
	TipoCarta = encodeURIComponent(document.getElementById("materiale").value);
	// execute the page from the server
    xmlHttp.open("GET", "ajax/ajaxInfoCarta.php?tipo_carta=" + TipoCarta, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = apAJAXHandleGetPaperInfoResponse;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('apAJAXGetPaperInfo()', 1000);
}

/// Funzione richiedere il massimo numero di facciate per brossura di una carta via AJAX
/// \author: Enrico Alborali
/// \version: 1.00 [26.09.2008]
function apAJAXGetPaperMaxFaces()
{
  var GrammaturaCarta;
  // 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
    GrammaturaCarta = encodeURIComponent(document.getElementById("grammatura").value);
    // execute the page from the server
    xmlHttp.open("GET", "ajax/ajaxMaxFacciateBrossura.php?grammatura=" + GrammaturaCarta, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = apAJAXHandleGetPaperMaxFacesResponse;
    // make the server request
    xmlHttp.send(null);
	
	//alert("DEBUG: URL:" + "ajax/ajaxMaxFacciateBrossura.php?grammatura=" + GrammaturaCarta);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('apAJAXGetPaperMaxFaces()', 1000);
}

/// Funzione richiedere le dimensioni di una carta via AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [20.06.2008]
function apAJAXGetPaperSize()
{
  var TipoCarta;
  // 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
    TipoCarta = encodeURIComponent(document.getElementById("materiale").value);
    // execute the page from the server
    xmlHttp.open("GET", "ajax/ajaxDimensioniCarta.php?tipo_carta=" + TipoCarta, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = apAJAXHandleGetPaperSizeResponse;
    // make the server request
    xmlHttp.send(null);
	
	//alert("DEBUG: URL:" + "ajax/ajaxDimensioniCarta.php?tipo_carta=" + TipoCarta);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('apAJAXGetPaperSize()', 1000);
}


/// Funzione richiedere le possibili lavorazioni di una carta via AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [11.07.2008]
function apAJAXGetPaperWorks()
{
	var TipoCarta;
	// 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
		TipoCarta = encodeURIComponent(document.getElementById("materiale").value);
		// execute the page from the server
		xmlHttp.open("GET", "ajax/ajaxLavorazioniCarta.php?tipo_carta=" + TipoCarta, true);  
		// define the method to handle server responses
		xmlHttp.onreadystatechange = apAJAXHandleGetPaperWorksResponse;
		// make the server request
		xmlHttp.send(null);
		//alert("DEBUG: URL:" + "ajax/ajaxDimensioniCarta.php?tipo_carta=" + TipoCarta);
	}
	else
		// if the connection is busy, try again after one second  
		setTimeout('apAJAXGetPaperWorks()', 1000);
}

/// Funzione per richiedere tutte le possibili tipologie di copertina
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXGetCovers()
{
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Richiedo al server la pagina
		xmlHttp.open("GET", "ajax/ajaxCopertine.php", true);  
		// Definisco il metodo che gestisce le risposte del server
		xmlHttp.onreadystatechange = apAJAXHandleGetCoversResponse;
		// Eseguo la richiesta al server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo un secondo
		setTimeout('apAJAXGetCovers()', 1000);
}

/// Funzione per richiedere la copertina rigida
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXGetHardCover()
{
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Richiedo al server la pagina
		xmlHttp.open("GET", "ajax/ajaxCopertine.php?copertina=1", true);  
		// Definisco il metodo che gestisce le risposte del server
		xmlHttp.onreadystatechange = apAJAXHandleGetCoversResponse;
		// Eseguo la richiesta al server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo un secondo
		setTimeout('apAJAXGetHardCover()', 1000);
}

/// Funzione per richiedere le rilegature
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXGetBindings()
{
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Richiedo al server la pagina
		xmlHttp.open("GET", "ajax/ajaxRilegature.php", true);  
		// Definisco il metodo che gestisce le risposte del server
		xmlHttp.onreadystatechange = apAJAXHandleGetBindingsResponse;
		// Eseguo la richiesta al server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo un secondo
		setTimeout('apAJAXGetBindings()', 1000);
}

/// Funzione per richiedere la rilegatura brossura
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXGetPaperBackBindings()
{
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Richiedo al server la pagina
		xmlHttp.open("GET", "ajax/ajaxRilegature.php?rilegatura=7", true);  
		// Definisco il metodo che gestisce le risposte del server
		xmlHttp.onreadystatechange = apAJAXHandleGetBindingsResponse;
		// Eseguo la richiesta al server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo un secondo
		setTimeout('apAJAXGetPaperBackBindings()', 1000);
}

/// Funzione per richiedere la rilegatura spirale metallica
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXGetSpiralBinding()
{
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Richiedo al server la pagina
		xmlHttp.open("GET", "ajax/ajaxRilegature.php?rilegatura=8", true);  
		// Definisco il metodo che gestisce le risposte del server
		xmlHttp.onreadystatechange = apAJAXHandleGetBindingsResponse;
		// Eseguo la richiesta al server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo un secondo
		setTimeout('apAJAXGetNoBindings()', 1000);
}

/// Funzione per richiedere la nessuna rilegatura
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXGetNoBindings()
{
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Richiedo al server la pagina
		xmlHttp.open("GET", "ajax/ajaxRilegature.php?rilegatura=10", true);  
		// Definisco il metodo che gestisce le risposte del server
		xmlHttp.onreadystatechange = apAJAXHandleGetBindingsResponse;
		// Eseguo la richiesta al server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo un secondo
		setTimeout('apAJAXGetNoBindings()', 1000);
}

/// Funzione richiedere le informazioni sulla lavorazione via AJAX
/// \author: Enrico Alborali
/// \version: 1.02 [30.05.2008]
function apAJAXGetWorkInfo( work )
{
	var TipoLavorazione;
	// 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
		TipoLavorazione = encodeURIComponent(document.getElementById( work ).value);
		// execute the page from the server
		xmlHttp.open("GET", "ajax/ajaxInfoLavorazione.php?tipo_lavorazione=" + TipoLavorazione, true);  
		// define the method to handle server responses
		xmlHttp.onreadystatechange = apAJAXHandleGetWorkInfoResponse;
		// make the server request
		xmlHttp.send(null);
		//alert("DEBUG: url=ajax/ajaxInfoLavorazione.php?tipo_lavorazione=" + TipoLavorazione);
	}
	else
	{
		// if the connection is busy, try again after one second  
		setTimeout('apAJAXGetWorkInfo(\''+work+'\')', 1000);
	}
}


/// Funzione richiedere le grammature carta via AJAX
/// \author: Enrico Alborali
/// \version: 1.02 [30.11.2007]
function apAJAXGetPaperGr()
{
	var TipoCarta;
    
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Recupero dal form il tipo carta selezionato
		TipoCarta = encodeURIComponent(document.getElementById("carta").value);
		// execute the page from the server
		xmlHttp.open("GET", "ajax/ajaxGrammature.php?tipo_carta=" + TipoCarta, true);  
		// define the method to handle server responses
		xmlHttp.onreadystatechange = apAJAXHandleGetPaperGrResponse;
		// make the server request
		xmlHttp.send(null);
	}
	else
	{
		// if the connection is busy, try again after one second  
		setTimeout('apAJAXGetPaperGr()', 1000);
	}
}

/// Funzione richiedere le grammature copertina via AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [19.12.2007]
function apAJAXGetCoverGr()
{
	var CartaCopertina;
    
	// Procedo solo se l'oggetto xmlHttp non e' occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Recupero i parametri inseriti nel form del documento
		CartaCopertina = encodeURIComponent(document.getElementById("copertina_carta").value);
		// execute the page from the server
		xmlHttp.open("GET", "ajax/ajaxGrammature.php?tipo_carta=" + CartaCopertina, true);  
		// define the method to handle server responses
		xmlHttp.onreadystatechange = apAJAXHandleGetCoverGrResponse;
		// make the server request
		xmlHttp.send(null);
	}
	else
	{
		// if the connection is busy, try again after one second  
		setTimeout('apAJAXGetCoverGr()', 1000);
	}
}

/// Funzione richiedere il codice VAT europeo per una nazione via AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [15.05.2008]
function apAJAXGetVATCode()
{
  var Nazione;
  // 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
    Nazione = encodeURIComponent(document.getElementById( "nazione" ).value);
    // execute the page from the server
    xmlHttp.open("GET", "ajax/ajaxVATCode.php?nazione=" + Nazione, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = apAJAXHandleGetVATCodeResponse;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('apAJAXGetVATCode()', 1000);
}

/// Funzione elaborare la risposta sulle informazioni sulla carta
/// \author: Enrico Alborali
/// \version: 1.01 [28.11.2007]
function apAJAXHandleGetPaperInfoResponse() 
{
	var object_img = document.getElementById("carta_img");
	var object_info = document.getElementById("descrizione_carta");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array degli elementi <value>
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = valueArray.length;
				// Aggiungo le option grammature
				if (elementsNum > 0)
				{
					object_img.setAttribute("src", "images/"+valueArray.item(0).firstChild.data );
					object_info.innerHTML = valueArray.item(1).firstChild.data;	
				}
				else
				{
					alert("ERRORE! non ci sono informazioni riguardo il tipo di carta selezionato.");	
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sul massimo numero di facciate
/// \author: Enrico Alborali
/// \version: 1.01 [20.06.2008]
function apAJAXHandleGetPaperMaxFacesResponse() 
{
	var object_max_faces	= document.getElementById("max_faces");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array degli elementi <value>
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = valueArray.length;
				// Aggiungo le option grammature
				if (elementsNum > 0)
				{
					object_max_faces.value	= valueArray.item(0).firstChild.data;
					
					//alert("DEBUG: max faces:" + object_max_faces.value );
				}
				else
				{
					alert("ERRORE! non ci sono informazioni riguardo sul massimo numero di facciate.");	
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sulle dimensioni di una carta
/// \author: Enrico Alborali
/// \version: 1.01 [20.06.2008]
function apAJAXHandleGetPaperSizeResponse() 
{
	var object_larghezza	= document.getElementById("materiale_larghezza");
	var object_altezza		= document.getElementById("materiale_altezza");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array degli elementi <value>
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = valueArray.length;
				// Aggiungo le option grammature
				if (elementsNum > 0)
				{
					object_larghezza.value	= valueArray.item(0).firstChild.data;
					object_altezza.value	= valueArray.item(1).firstChild.data;
					
					//alert("DEBUG: larghezza:" + object_larghezza.value + " altezza:" + object_altezza.value);
				}
				else
				{
					alert("ERRORE! non ci sono informazioni riguardo il tipo di carta selezionato.");	
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sulle lavorazioni di una carta
/// \author: Enrico Alborali
/// \version: 1.02 [20.07.2008]
function apAJAXHandleGetPaperWorksResponse() 
{
	var object_plastificazione		= document.getElementById("plastificazione");
	var object_supporto_rigido		= document.getElementById("supporto_rigido");
	var object_numero_occhielli		= document.getElementById("numero_occhielli");
	var object_disposizione_occhielli	= document.getElementById("disposizione_occhielli");
	var object_rinforzo_perimetrale		= document.getElementById("rinforzo_perimetrale");
	var object_asola			= document.getElementById("asola");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array degli elementi <value>
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = valueArray.length;
				// Aggiungo le option grammature
				if (elementsNum > 0)
				{
					if (object_plastificazione != null)
					{
						if (valueArray.item(0).firstChild.data == "1")
							object_plastificazione.disabled = false;
						else
							object_plastificazione.disabled = true;
					}
					if (object_supporto_rigido != null)
					{
						if (valueArray.item(1).firstChild.data == "1")
							object_supporto_rigido.disabled = false;
						else
							object_supporto_rigido.disabled = true;
					}
					if (object_numero_occhielli != null)
					{
						if (valueArray.item(2).firstChild.data == "1")
							object_numero_occhielli.disabled = false;
						else
							object_numero_occhielli.disabled = true;
					}
					if (object_disposizione_occhielli != null)
					{
						if (valueArray.item(3).firstChild.data == "1")
							object_disposizione_occhielli.disabled = false;
						else
							object_disposizione_occhielli.disabled = true;
					}
					if (object_rinforzo_perimetrale != null)
					{
						if (valueArray.item(4).firstChild.data == "1")
							object_rinforzo_perimetrale.disabled = false;
						else
							object_rinforzo_perimetrale.disabled = true;
					}
					if (object_asola != null)
					{
						if (valueArray.item(5).firstChild.data == "1")
							object_asola.disabled = false;
						else
							object_asola.disabled = true;
					}
					
					//alert("DEBUG: plast:" + object_plastificazione.value + " sup_rig:" + object_supporto_rigido.value);
				}
				else
				{
					alert("ERRORE! non ci sono informazioni riguardo il tipo di carta selezionato.");	
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sulle tipologie di copertina
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXHandleGetCoversResponse() 
{
	var object_cover = document.getElementById("copertina_tipo");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
			try
			{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array con gli elementi <id> e <value>
				var idArray = xmlDocumentElement.getElementsByTagName("id");
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = idArray.length;
				var optionElement;
				var coverText;
				var coverName;
				// Elimino le grammature precedenti
				while (object_cover.firstChild) 
 				{
    				//The list is LIVE so it will re-index each call
    				object_cover.removeChild(object_cover.firstChild);
 				}
				// Aggiungo le option copertine
				if (elementsNum > 0)
				{
					for ( i=0; i<elementsNum; i++ )
					{
						// Genero il tag <option>
						optionElement = document.createElement("option");
						
						coverName = valueArray.item(i).firstChild.data.split(".");
						
						if (coverName[0]=="SLCTD")
						{
							coverName[0]=coverName[1];
							optionElement.setAttribute("selected", "selected" );
						}
						
						optionElement.setAttribute("value", idArray.item(i).firstChild.data );
						coverText = document.createTextNode( coverName[0] );
						optionElement.appendChild(coverText);
						// Aggiungo il tag dentro a <select>
						object_cover.appendChild(optionElement);
					}
					// Abilito select copertine
					object_cover.disabled = false;
					
					apAJAXUpdateCoverData();
				}
				else
				{
					// Disabilito select copertine
					object_cover.disabled = true;
					alert("ERRORE! non ci sono tipologie di copertine disponibili.");	
				}
			}
			catch(e)
			{
			 	// Disabilito select grammatura
				object_cover.disabled = true;
				alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	// Disabilito select grammatura
			object_cover.disabled = true;
			alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sulle tipologie di rilegatura
/// \author: Enrico Alborali
/// \version: 1.00 [30.03.2009]
function apAJAXHandleGetBindingsResponse() 
{
	var object_binding = document.getElementById("copertina_rilegatura");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
			try
			{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array con gli elementi <id> e <value>
				var idArray = xmlDocumentElement.getElementsByTagName("id");
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = idArray.length;
				var optionElement;
				var coverText;
				var coverName;
				// Elimino le grammature precedenti
				while (object_binding.firstChild) 
 				{
    				//The list is LIVE so it will re-index each call
    				object_binding.removeChild(object_binding.firstChild);
 				}
				// Aggiungo le option copertine
				if (elementsNum > 0)
				{
					for ( i=0; i<elementsNum; i++ )
					{
						// Genero il tag <option>
						optionElement = document.createElement("option");
						
						coverName = valueArray.item(i).firstChild.data.split(".");
						
						if (coverName[0]=="SLCTD")
						{
							coverName[0]=coverName[1];
							optionElement.setAttribute("selected", "selected" );
						}
						
						optionElement.setAttribute("value", idArray.item(i).firstChild.data );
						coverText = document.createTextNode( coverName[0] );
						optionElement.appendChild(coverText);
						// Aggiungo il tag dentro a <select>
						object_binding.appendChild(optionElement);
					}
					// Abilito select copertine
					object_binding.disabled = false;
					
					//apAJAXUpdateCoverData();
				}
				else
				{
					// Disabilito select copertine
					object_binding.disabled = true;
					alert("ERRORE! non ci sono tipologie di rilegatura disponibili.");	
				}
			}
			catch(e)
			{
			 	// Disabilito select grammatura
				object_binding.disabled = true;
				alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	// Disabilito select grammatura
			object_binding.disabled = true;
			alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sulle informazioni sulla lavorazione
/// \author: Enrico Alborali
/// \version: 1.01 [15.05.2008]
function apAJAXHandleGetWorkInfoResponse() 
{
	var object_img = document.getElementById("lavorazione_img");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array degli elementi <value>
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = valueArray.length;
				// Visualizzo img
				if (elementsNum > 0)
				{
					object_img.setAttribute("src", "images/"+valueArray.item(0).firstChild.data );
				}
				else
				{
					alert("ERRORE! non ci sono informazioni riguardo la lavorazione selezionata.");	
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sulle grammatura della carta
/// \author: Enrico Alborali
/// \version: 1.03 [01.12.2007]
function apAJAXHandleGetPaperGrResponse() 
{
	var object_gr = document.getElementById("grammatura");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
			try
			{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array con gli elementi <id> e <value>
				var idArray = xmlDocumentElement.getElementsByTagName("id");
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = idArray.length;
				var optionElement;
				var grammText;
				var grammName;
				// Elimino le grammature precedenti
				while (object_gr.firstChild) 
 				{
    				//The list is LIVE so it will re-index each call
    				object_gr.removeChild(object_gr.firstChild);
 				}
				// Aggiungo le option grammature
				if (elementsNum > 0)
				{
					for ( i=0; i<elementsNum; i++ )
					{
						// Genero il tag <option>
						optionElement = document.createElement("option");
						
						grammName = valueArray.item(i).firstChild.data.split(".");
						
						if (grammName[0]=="SLCTD")
						{
							grammName[0]=grammName[1];
							optionElement.setAttribute("selected", "selected" );
						}
						
						optionElement.setAttribute("value", idArray.item(i).firstChild.data );
						grammText = document.createTextNode( grammName[0] );
						optionElement.appendChild(grammText);
						// Aggiungo il tag dentro a <select>
						object_gr.appendChild(optionElement);
					}
					// Abilito select grammatura
					object_gr.disabled = false;
				}
				else
				{
					// Disabilito select grammatura
					object_gr.disabled = true;
					alert("ERRORE! non ci sono grammature disponibili per il tipo di carta selezionato.");	
				}
			}
			catch(e)
			{
			 	// Disabilito select grammatura
				object_gr.disabled = true;
				alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	// Disabilito select grammatura
			object_gr.disabled = true;
			alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sulle grammature sulla carta copertina
/// \author: Enrico Alborali
/// \version: 1.01 [19.12.2007]
function apAJAXHandleGetCoverGrResponse() 
{
	var object_gr = document.getElementById("copertina_grammatura");
	// Proseguo solo se la transazione e' stata completata
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
			try
			{
		 	 	// Estraggo il file XML restituito dal server
				xmlResponse = xmlHttp.responseXML;
				// Ottengo l'elemento principale dell'XML ricevuto
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array con gli elementi <id> e <value>
				var idArray = xmlDocumentElement.getElementsByTagName("id");
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = idArray.length;
				var optionElement;
				var grammText;
				var grammName;
				// Elimino le grammature precedenti
				while (object_gr.firstChild) 
 				{
    				// Rimuovo il primo elemento figlio
    				object_gr.removeChild(object_gr.firstChild);
 				}
				// Aggiungo le option grammature
				if (elementsNum > 0)
				{
					for ( i=0; i<elementsNum; i++ )
					{
						// Genero il tag <option>
						optionElement = document.createElement("option");
						
						grammName = valueArray.item(i).firstChild.data.split(".");
						
						if (grammName[0]=="SLCTD")
						{
							grammName[0]=grammName[1];
							optionElement.setAttribute("selected", "selected" );
						}
						
						optionElement.setAttribute("value", idArray.item(i).firstChild.data );
						grammText = document.createTextNode( grammName[0] );
						optionElement.appendChild(grammText);
						// Aggiungo il tag dentro a <select>
						object_gr.appendChild(optionElement);
					}
					// Abilito select grammatura
					//object_gr.disabled = false;
				}
				else
				{
					// Disabilito select grammatura
					object_gr.disabled = true;
					alert("ERRORE! non ci sono grammature disponibili per il tipo di carta selezionato.");	
				}
			}
			catch(e)
			{
			 	// Disabilito select grammatura
				object_gr.disabled = true;
				alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	// Disabilito select grammatura
			object_gr.disabled = true;
			alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione elaborare la risposta sul codice VAT
/// \author: Enrico Alborali
/// \version: 1.01 [30.05.2008]
function apAJAXHandleGetVATCodeResponse() 
{
	var object_div = document.getElementById("vat_code");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) 
	{
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// extract the XML retrieved from the server
				xmlResponse = xmlHttp.responseXML;
				// obtain the document element (the root element) of the XML structure
				xmlDocumentElement = xmlResponse.documentElement;
				// Ottengo gli array degli elementi <value>
				var valueArray = xmlDocumentElement.getElementsByTagName("value");
				// Ciclo per costruire tutti gli <options>			
				var elementsNum = valueArray.length;
				// Visualizzo img
				if (elementsNum > 0)
				{
					object_div.innerHTML = valueArray.item(0).firstChild.data;
				}
				else
				{
					alert("ERRORE! non ci sono informazioni riguardo la nazione selezionata.");	
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// a HTTP status different than 200 signals an error
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione per aggiornare i campi della copertina
/// \author: Enrico Alborali
/// \version: 1.03 [02.07.2009]
function apAJAXUpdateCoverData()
{
    var abilita = document.preventivo_opuscoli.copertina_tipo.value == 1; 
	
	if ( abilita && document.getElementById('copertina_grammatura').firstChild == null)
	{
       // Aggiorno le grammature della copertina
	   apAJAXGetCoverGr(); 
    }
	// Controllo i campi che riguardano la copertina
	document.getElementById('copertina_carta').disabled = !abilita;
	document.getElementById('copertina_grammatura').disabled = !abilita;
	
	//alert("DEBUG Abilita: " + abilita);
	
}

/// Funzione richiedere un preventivo di stampa tramite AJAX
/// \author: Enrico Alborali
/// \version: 1.03 [19.12.2007]
function apAJAXGetPrintEstimation()
{
	var	TipoPreventivo = encodeURIComponent(document.getElementById("tipo_preventivo").value);
	var tipo_utente = encodeURIComponent(document.getElementById("tipo_utente").value);
	var formato_chiuso = encodeURIComponent(document.getElementById("formato_chiuso").value);
	var numero_copie = encodeURIComponent(document.getElementById("numero_copie").value);
	var facciate_totali = encodeURIComponent(document.getElementById("facciate_totali").value);
	var fronte_retro = encodeURIComponent(document.getElementById("fronte_retro").value);
	var carta = encodeURIComponent(document.getElementById("carta").value);
	var grammatura = encodeURIComponent(document.getElementById("grammatura").value);
	var copertina_tipo = encodeURIComponent(document.getElementById("copertina_tipo").value);
	var copertina_carta = encodeURIComponent(document.getElementById("copertina_carta").value);
	var copertina_grammatura = encodeURIComponent(document.getElementById("copertina_grammatura").value);
	var copertina_plastificazione = encodeURIComponent(document.getElementById("copertina_plastificazione").value);
	var copertina_rilegatura = encodeURIComponent(document.getElementById("copertina_rilegatura").value);
	
	var RequestURL = "ajax/ajaxPreventivo.php";
    
	// Procedo solo se l'oggetto xmlHttp non Ë occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		RequestURL = RequestURL + "?tipo_preventivo=" + TipoPreventivo;
		RequestURL = RequestURL + "&tipo_utente=" + tipo_utente;
		RequestURL = RequestURL + "&numero_copie=" + numero_copie;
		RequestURL = RequestURL + "&facciate_totali=" + facciate_totali;
		RequestURL = RequestURL + "&fronte_retro=" + fronte_retro;
		RequestURL = RequestURL + "&carta=" + carta;
		RequestURL = RequestURL + "&formato_chiuso=" + formato_chiuso;
		RequestURL = RequestURL + "&grammatura=" + grammatura;
		RequestURL = RequestURL + "&copertina_tipo=" + copertina_tipo;
		RequestURL = RequestURL + "&copertina_carta=" + copertina_carta;
		RequestURL = RequestURL + "&copertina_grammatura=" + copertina_grammatura;
		RequestURL = RequestURL + "&copertina_plastificazione=" + copertina_plastificazione;
		RequestURL = RequestURL + "&copertina_rilegatura=" + copertina_rilegatura;
		
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", RequestURL, true);  
		// Definisco il metodo che interpreter‡ la risposta
		xmlHttp.onreadystatechange = apAJAXGetPrintEstimationResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo 2 secondi
		setTimeout('apAJAXGetPrintEstimation()', 2000);
}

/// Funzione richiedere un preventivo di stampa (TiR) tramite AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [11.05.2008]
function apAJAXGetTiRPrintEstimation()
{
	var TipoPreventivo	= encodeURIComponent(document.getElementById("tipo_preventivo").value);
	var tipo_utente 	= encodeURIComponent(document.getElementById("tipo_utente").value);
	var formato		= encodeURIComponent(document.getElementById("formato").value);
	var numero_copie	= encodeURIComponent(document.getElementById("numero_copie").value);
	var fronte		= encodeURIComponent(document.getElementById("fronte").value);
	var retro		= encodeURIComponent(document.getElementById("retro").value);
	var carta		= encodeURIComponent(document.getElementById("carta").value);
	var grammatura		= encodeURIComponent(document.getElementById("grammatura").value);
	var rifilo		= encodeURIComponent(document.getElementById("rifilo").value);
	var piegatura		= encodeURIComponent(document.getElementById("piegatura").value);
	var plastificazione	= encodeURIComponent(document.getElementById("plastificazione").value);
	
	var RequestURL = "ajax/ajaxPreventivo.php";
    
	// Procedo solo se l'oggetto xmlHttp non è occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		RequestURL = RequestURL + "?tipo_preventivo=" + TipoPreventivo;
		RequestURL = RequestURL + "&tipo_utente=" + tipo_utente;
		RequestURL = RequestURL + "&numero_copie=" + numero_copie;
		RequestURL = RequestURL + "&fronte=" + fronte;
		RequestURL = RequestURL + "&retro=" + retro;
		RequestURL = RequestURL + "&carta=" + carta;
		RequestURL = RequestURL + "&formato=" + formato;
		RequestURL = RequestURL + "&grammatura=" + grammatura;
		RequestURL = RequestURL + "&rifilo=" + rifilo;
		RequestURL = RequestURL + "&piegatura=" + piegatura;
		RequestURL = RequestURL + "&plastificazione=" + plastificazione;
		
		//alert(RequestURL);
		
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", RequestURL, true);  
		// Definisco il metodo che interpreterà la risposta
		xmlHttp.onreadystatechange = apAJAXGetPrintEstimationResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione è occupata riprova dopo 2 secondi
		setTimeout('apAJAXGetTiRPrintEstimation()', 2000);
}

/// Funzione richiedere un preventivo di stampa (EA) tramite AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [20.06.2008]
function apAJAXGetEAPrintEstimation()
{
	var TipoPreventivo	= encodeURIComponent(document.getElementById("tipo_preventivo").value);
	var tipo_utente 	= encodeURIComponent(document.getElementById("tipo_utente").value);
	var numero_copie	= encodeURIComponent(document.getElementById("numero_copie").value);
	var base		= encodeURIComponent(document.getElementById("base").value);
	var altezza		= encodeURIComponent(document.getElementById("altezza").value);
	var materiale		= encodeURIComponent(document.getElementById("materiale").value);
	var taglio		= encodeURIComponent(document.getElementById("taglio").value);
	
	var RequestURL = "ajax/ajaxPreventivo.php";
    
	// Procedo solo se l'oggetto xmlHttp non Ë occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		RequestURL = RequestURL + "?tipo_preventivo=" + TipoPreventivo;
		RequestURL = RequestURL + "&tipo_utente=" + tipo_utente;
		RequestURL = RequestURL + "&numero_copie=" + numero_copie;
		RequestURL = RequestURL + "&base=" + base;
		RequestURL = RequestURL + "&altezza=" + altezza;
		RequestURL = RequestURL + "&materiale=" + materiale;
		RequestURL = RequestURL + "&taglio=" + taglio;
		
		//alert("DEBUG: Request URL: "+RequestURL);
		
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", RequestURL, true);  
		// Definisco il metodo che interpreter‡ la risposta
		xmlHttp.onreadystatechange = apAJAXGetPrintEstimationResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione e' occupata riprova dopo 2 secondi
		setTimeout('apAJAXGetEAPrintEstimation()', 2000);
}

// Funzione richiedere un preventivo di stampa (AQ) tramite AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [14.07.2008]
function apAJAXGetAQPrintEstimation()
{
	var TipoPreventivo	= encodeURIComponent(document.getElementById("tipo_preventivo").value);
	var tipo_utente 	= encodeURIComponent(document.getElementById("tipo_utente").value);
	var numero_copie	= encodeURIComponent(document.getElementById("numero_copie").value);
	var base		= encodeURIComponent(document.getElementById("base").value);
	var altezza		= encodeURIComponent(document.getElementById("altezza").value);
	var materiale		= encodeURIComponent(document.getElementById("materiale").value);
	var plastificazione	= encodeURIComponent(document.getElementById("plastificazione").value);
	var supporto_rigido	= encodeURIComponent(document.getElementById("supporto_rigido").value);
	
	var RequestURL = "ajax/ajaxPreventivo.php";
    
	// Procedo solo se l'oggetto xmlHttp non è occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		RequestURL = RequestURL + "?tipo_preventivo=" + TipoPreventivo;
		RequestURL = RequestURL + "&tipo_utente=" + tipo_utente;
		RequestURL = RequestURL + "&numero_copie=" + numero_copie;
		RequestURL = RequestURL + "&base=" + base;
		RequestURL = RequestURL + "&altezza=" + altezza;
		RequestURL = RequestURL + "&materiale=" + materiale;
		RequestURL = RequestURL + "&plastificazione=" + plastificazione;
		RequestURL = RequestURL + "&supporto_rigido=" + supporto_rigido;
		
		//alert("DEBUG: Request URL: "+RequestURL);
		
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", RequestURL, true);  
		// Definisco il metodo che interpreterà la risposta
		xmlHttp.onreadystatechange = apAJAXGetPrintEstimationResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione è occupata riprova dopo 2 secondi
		setTimeout('apAJAXGetAQPrintEstimation()', 2000);
}

// Funzione richiedere un preventivo di stampa (MeA) tramite AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [22.07.2008]
/// \last modify: 31/08/09 - Diego Vicentini
function apAJAXGetMeAPrintEstimation()
{
	var TipoPreventivo	= encodeURIComponent(document.getElementById("tipo_preventivo").value);
	var tipo_utente 	= encodeURIComponent(document.getElementById("tipo_utente").value);
	var numero_copie	= encodeURIComponent(document.getElementById("numero_copie").value);
	var formato			= encodeURIComponent(document.getElementById("formato").value);
	var base			= encodeURIComponent(document.getElementById("base").value);
	var altezza			= encodeURIComponent(document.getElementById("altezza").value);
	var materiale		= encodeURIComponent(document.getElementById("materiale").value);
	var plastificazione	= encodeURIComponent(document.getElementById("plastificazione").value);
	var supporto_rigido	= encodeURIComponent(document.getElementById("supporto_rigido").value);
	
	var RequestURL = "ajax/ajaxPreventivo.php";
    
	// Procedo solo se l'oggetto xmlHttp non è occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		RequestURL = RequestURL + "?tipo_preventivo=" + TipoPreventivo;
		RequestURL = RequestURL + "&tipo_utente=" + tipo_utente;
		RequestURL = RequestURL + "&numero_copie=" + numero_copie;
		RequestURL = RequestURL + "&formato=" + formato;
		RequestURL = RequestURL + "&base=" + base;
		RequestURL = RequestURL + "&altezza=" + altezza;
		RequestURL = RequestURL + "&materiale=" + materiale;
		RequestURL = RequestURL + "&plastificazione=" + plastificazione;
		RequestURL = RequestURL + "&supporto_rigido=" + supporto_rigido;
		
		//alert("DEBUG: Request URL: "+RequestURL);
		
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", RequestURL, true);  
		// Definisco il metodo che interpreterà la risposta
		xmlHttp.onreadystatechange = apAJAXGetPrintEstimationResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione è occupata riprova dopo 2 secondi
		setTimeout('apAJAXGetMeAPrintEstimation()', 2000);
}

// Funzione richiedere un preventivo di stampa (AeB) tramite AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [22.07.2008]
function apAJAXGetAeBPrintEstimation()
{
	var TipoPreventivo		= encodeURIComponent(document.getElementById("tipo_preventivo").value);
	var tipo_utente 		= encodeURIComponent(document.getElementById("tipo_utente").value);
	var numero_copie		= encodeURIComponent(document.getElementById("numero_copie").value);
	var base			= encodeURIComponent(document.getElementById("base").value);
	var altezza			= encodeURIComponent(document.getElementById("altezza").value);
	var materiale			= encodeURIComponent(document.getElementById("materiale").value);
	var plastificazione		= encodeURIComponent(document.getElementById("plastificazione").value);
	var supporto_rigido		= encodeURIComponent(document.getElementById("supporto_rigido").value);
	
	var numero_occhielli		= encodeURIComponent(document.getElementById("numero_occhielli").value);
	var disposizione_occhielli	= encodeURIComponent(document.getElementById("disposizione_occhielli").value);
	var rinforzo_perimetrale	= 0;
	var asola			= encodeURIComponent(document.getElementById("asola").value);
	
	var RequestURL = "ajax/ajaxPreventivo.php";
	
	if (document.getElementById("rinforzo_perimetrale").checked == true)
	{
		rinforzo_perimetrale = encodeURIComponent(document.getElementById("rinforzo_perimetrale").value);
	}
    
	// Procedo solo se l'oggetto xmlHttp non è occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		RequestURL = RequestURL + "?tipo_preventivo=" + TipoPreventivo;
		RequestURL = RequestURL + "&tipo_utente=" + tipo_utente;
		RequestURL = RequestURL + "&numero_copie=" + numero_copie;
		RequestURL = RequestURL + "&base=" + base;
		RequestURL = RequestURL + "&altezza=" + altezza;
		RequestURL = RequestURL + "&materiale=" + materiale;
		RequestURL = RequestURL + "&plastificazione=" + plastificazione;
		RequestURL = RequestURL + "&supporto_rigido=" + supporto_rigido;
		
		RequestURL = RequestURL + "&numero_occhielli=" + numero_occhielli;
		RequestURL = RequestURL + "&disposizione_occhielli=" + disposizione_occhielli;
		RequestURL = RequestURL + "&rinforzo_perimetrale=" + rinforzo_perimetrale;
		RequestURL = RequestURL + "&asola=" + asola;
		
		//alert("DEBUG: Request URL: "+RequestURL);
		
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", RequestURL, true);  
		// Definisco il metodo che interpreterà la risposta
		xmlHttp.onreadystatechange = apAJAXGetPrintEstimationResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione è occupata riprova dopo 2 secondi
		setTimeout('apAJAXGetAeBPrintEstimation()', 2000);
}

/// Funzione elaborare la risposta del preventivo stampa
/// \author: Enrico Alborali
/// \version: 1.05 [30.05.2008]
/// \last modify: [23.04.2010] Diego Vicentini
function apAJAXGetPrintEstimationResponse() 
{
	// Recupero gli oggetti da gestire in base alla risposta
//	var object_lavorazione_materiale	= document.getElementById("lavorazione_materiale");
//	var object_peso_materiale		= document.getElementById("peso_materiale");
//	var object_costo_unitario		= document.getElementById("costo_unitario");
//	var object_totale_iva_esclusa		= document.getElementById("totale_iva_esclusa");
//	var object_sconto_promozionale		= document.getElementById("sconto_promozione");
//	var object_totale_iva_compresa		= document.getElementById("totale_iva_compresa");
//	var objects_costi_consegne			= document.getElementsByName("costo_consegna_iva_esclusa");
	var object_num_consegne				= document.getElementById("num_consegne");
	var objects_costi_consegne_iva_esclusa = new Array();
	var objects_costi_consegne_iva_compresa = new Array();
	for (i=0;i<object_num_consegne.value;i++) {
		objects_costi_consegne_iva_esclusa[i] = document.getElementById("costo_consegna_iva_esclusa_"+i);
		objects_costi_consegne_iva_compresa[i] = document.getElementById("costo_consegna_iva_compresa_"+i);
	}
	// Continua solo se la transazione è stata completata
	if (xmlHttp.readyState == 4) 
	{
		// Se ho stato HTTP a 200 significa che l'operazione e' stata completata con successo
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// Estraggo l'XML ricevuto
				xmlResponse = xmlHttp.responseXML;
				if (xmlResponse != null)
				{
					// obtain the document element (the root element) of the XML structure
					xmlDocumentElement = xmlResponse.documentElement;
					// Ottengo gli array degli elementi <value>
					var valueArray = xmlDocumentElement.getElementsByTagName("value");
					// Ottengo il numero di elementi contenuti nella risposta			
					var elementsNum = valueArray.length;
					// Stampo sul documento i risultati preventivo
					if ( elementsNum >= (6 + (object_num_consegne.value * 2)) )
					{
	//					object_lavorazione_materiale.innerHTML 	= "&euro;&nbsp;" + valueArray.item(0).firstChild.data;
	//					object_peso_materiale.innerHTML		= "Kg&nbsp;" + valueArray.item(1).firstChild.data;
	//					object_costo_unitario.innerHTML 	= "&euro;&nbsp;" + valueArray.item(2).firstChild.data;
	//					object_totale_iva_esclusa.innerHTML 	= "<b>&euro;&nbsp;" + valueArray.item(3).firstChild.data + "</b>";
	//					object_sconto_promozionale.innerHTML 	= "<b style=\"color:#cc0000\">&euro;&nbsp;" + valueArray.item(4).firstChild.data + "</b>";
	//					object_totale_iva_compresa.innerHTML 	= "&euro;&nbsp;" + valueArray.item(5).firstChild.data;
						for (i=0;i<object_num_consegne.value;i++) {
							if (valueArray.item(6+(2*i)) != null) {
								objects_costi_consegne_iva_esclusa[i].innerHTML = "&euro;&nbsp;" + valueArray.item(6+(2*i)).firstChild.data;
							} else {
								objects_costi_consegne_iva_esclusa[i].innerHTML = "ERROR";
							}
							if (valueArray.item(7+(2*i)) != null) {
								objects_costi_consegne_iva_compresa[i].innerHTML = "&euro;&nbsp;" + valueArray.item(7+(2*i)).firstChild.data;
							} else {
								objects_costi_consegne_iva_compresa[i].innerHTML = "ERROR";
							}
						}					
						if ( elementsNum > (6 + (object_num_consegne.value*2)) )
						{
							var object_totale_iva_esclusa = document.getElementById("totale_iva_esclusa");						
							var object_debug_numero_pagine = document.getElementById("debug_numero_pagine");
							var object_debug_resa_formato = document.getElementById("debug_resa_formato");
							var object_debug_numero_pagine_copertina = document.getElementById("debug_numero_pagine_copertina");
							var object_debug_metodo_scarto = document.getElementById("debug_metodo_scarto");
							var object_debug_scarto_totale = document.getElementById("debug_scarto_totale");
							var object_debug_numero_fogli = document.getElementById("debug_numero_fogli");
							var object_debug_numero_fogli_copertina = document.getElementById("debug_numero_fogli_copertina");
							var object_debug_peso_carta = document.getElementById("debug_peso_carta");
							var object_debug_costo_carta = document.getElementById("debug_costo_carta");
							
							var object_debug_peso_carta_tagliata = document.getElementById("debug_peso_carta_tagliata");
							var object_debug_passaggi_stampa = document.getElementById("debug_passaggi_stampa");
							var object_debug_costo_stampa = document.getElementById("debug_costo_stampa");
							var object_debug_costo_lavorazione1 = document.getElementById("debug_costo_lavorazione1");
							var object_debug_costo_lavorazione2 = document.getElementById("debug_costo_lavorazione2");
							var object_debug_costo_lavorazione3 = document.getElementById("debug_costo_lavorazione3");
							var object_debug_peso_carta_copertina = document.getElementById("debug_peso_carta_copertina");
							var object_debug_costo_carta_copertina = document.getElementById("debug_costo_carta_copertina");
							var object_debug_peso_carta_copertina_tagliata = document.getElementById("debug_peso_carta_copertina_tagliata");
							
							// Totale iva esclusa (spostato nel debug di admin)
							if (valueArray.item(3) != null) {
								object_totale_iva_esclusa.innerHTML	= "<b>&euro;&nbsp;" + valueArray.item(3).firstChild.data + "</b>";
							} else {object_totale_iva_esclusa.innerHTML = "ERROR";}
							
							// Numero di oggetti nel vettore object_costi_consegne
							var j = object_num_consegne.value*2;
							
							if (valueArray.item(6+j) != null) {
								object_debug_numero_pagine.innerHTML = valueArray.item(6+j).firstChild.data;
							} else {object_debug_numero_pagine.innerHTML = "ERROR";}
							
							if (valueArray.item(7+j) != null) {
								object_debug_numero_pagine_copertina.innerHTML = valueArray.item(7+j).firstChild.data;
							} else {object_debug_numero_pagine_copertina.innerHTML = "ERROR";}
							
							if (valueArray.item(8+j) != null) {
								object_debug_resa_formato.innerHTML = valueArray.item(8+j).firstChild.data;
							} else {object_debug_resa_formato.innerHTML = "ERROR";}
							
							if (valueArray.item(9+j) != null) {
								object_debug_metodo_scarto.innerHTML = valueArray.item(9+j).firstChild.data;
							} else {object_debug_metodo_scarto.innerHTML = "ERROR";}
							
							if (valueArray.item(10+j) != null) {
								object_debug_scarto_totale.innerHTML = valueArray.item(10+j).firstChild.data;
							} else {object_debug_scarto_totale.innerHTML = "ERROR";}
							
							if (valueArray.item(11+j) != null) {
								object_debug_numero_fogli.innerHTML = valueArray.item(11+j).firstChild.data;
							} else {object_debug_numero_fogli.innerHTML = "ERROR";}
							
							if (valueArray.item(12+j) != null) {
								object_debug_numero_fogli_copertina.innerHTML = valueArray.item(12+j).firstChild.data;
							} else {object_debug_numero_fogli_copertina.innerHTML = "ERROR";}
							
							if (valueArray.item(13+j) != null) {
								object_debug_peso_carta.innerHTML = "Kg "+valueArray.item(13+j).firstChild.data;
							} else {object_debug_numero_fogli_copertina.innerHTML = "ERROR";}
							
							if (valueArray.item(14+j) != null) {
								object_debug_costo_carta.innerHTML = "<b>&euro; "+ valueArray.item(14+j).firstChild.data + "</b>";
							} else {object_debug_costo_carta.innerHTML = "ERROR";}
							
							if (valueArray.item(15+j) != null) {
								object_debug_peso_carta_tagliata.innerHTML = "Kg "+valueArray.item(15+j).firstChild.data;
							} else {object_debug_peso_carta_tagliata.innerHTML = "ERROR";}
							
							if (valueArray.item(16+j) != null) {
								object_debug_passaggi_stampa.innerHTML = valueArray.item(16+j).firstChild.data;
							} else {object_debug_passaggi_stampa.innerHTML = "ERROR";}
							
							if (valueArray.item(17+j) != null) {
								object_debug_costo_stampa.innerHTML = "<b>&euro; "+valueArray.item(17+j).firstChild.data + "</b>";
							} else {object_debug_costo_stampa.innerHTML = "ERROR";}
							
							if (valueArray.item(18+j) != null) {
								object_debug_costo_lavorazione1.innerHTML = "<b>&euro; "+valueArray.item(18+j).firstChild.data + "</b>";
							} else {object_debug_costo_lavorazione1.innerHTML = "ERROR";}
							
							if (valueArray.item(19+j) != null) {
								object_debug_costo_lavorazione2.innerHTML = "<b>&euro; "+valueArray.item(19+j).firstChild.data + "</b>";
							} else {object_debug_costo_lavorazione2.innerHTML = "ERROR";}
							
							if (valueArray.item(20+j) != null) {
								object_debug_costo_lavorazione3.innerHTML = "<b>&euro; "+valueArray.item(20+j).firstChild.data + "</b>";
							} else {object_debug_costo_lavorazione3.innerHTML = "ERROR";}
							
							if (valueArray.item(21+j) != null) {
								object_debug_peso_carta_copertina.innerHTML = "Kg "+valueArray.item(21+j).firstChild.data;
							} else {object_debug_peso_carta_copertina.innerHTML = "ERROR";}
							
							if (valueArray.item(22+j) != null) {
								object_debug_costo_carta_copertina.innerHTML = "<b>&euro; "+ valueArray.item(22+j).firstChild.data + "</b>";
							} else {object_debug_costo_carta_copertina.innerHTML = "ERROR";}
							
							if (valueArray.item(23+j) != null) {
								object_debug_peso_carta_copertina_tagliata.innerHTML = "Kg "+valueArray.item(23+j).firstChild.data;
							} else {object_debug_peso_carta_copertina_tagliata.innerHTML = "ERROR";}
						}
					}
					else
					{
						alert("ERRORE! non ci sono informazioni riguardo il tipo di carta selezionato.");	
					}
				}
				else
				{
					alert("Sistema di calcolo preventivi temporaneamente non disponibile.");
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// Se lo stato HTTP Ë diverso da 200 ho un errore
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    	}
	}
}

/// Funzione richiedere le informazioni su un metodo spedizione via AJAX
/// \author: Enrico Alborali
/// \version: 1.01 [17.06.2009]
function apAJAXGetShippingInfo()
{
  var TipoSpedizione;
  // Si procede sonl se l'oggetto xmlhttp non è occupato
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	// Recupero il tipo spedizione dal form
	if (document.getElementById("spedizione") != null)
		TipoSpedizione = encodeURIComponent(document.getElementById("spedizione").value);
	// Eseguo la pagina dal server
	xmlHttp.open("GET", "ajax/ajaxInfoSpedizione.php?tipo_spedizione=" + TipoSpedizione, true);  
	// Definisco il metodo che gestisce la risposta del server
	xmlHttp.onreadystatechange = apAJAXHandleGetPaperInfoResponse;
	// Eseguo la richiesta al server
	xmlHttp.send(null);
  }
  else
	// Se la connessione e' occupata riprovo dopo un secondo 
	setTimeout('apAJAXGetShippingInfo()', 1000);
}

// Funzione richiedere le info del carrello tramite AJAX
/// \author: Enrico Alborali
/// \version: 1.04 [10.05.2010]
function apAJAXGetCartInfo()
{
	var check = true; // verifica la presenza di tutti i parametri necessari
	
	// Spedizione nazione
	if (document.getElementById("spedizione_nazione") != null) {
		var spedizione_nazione = encodeURIComponent(document.getElementById("spedizione_nazione").value);
	} else {
		check = false;
	}
	// Spedizione
	if (document.getElementById("spedizione") != null) {
		var spedizione = encodeURIComponent(document.getElementById("spedizione").value);
	} else {
		check = false;
	}
	// Pagamento
	if (document.getElementById("pagamento") != null) {
		var pagamento = encodeURIComponent(document.getElementById("pagamento").value);
	} else {
		check = false;
	}
	// Pacco anonimo
	if (document.getElementById("pacco_anonimo") != null) {
		var pacco_anonimo = document.getElementById("pacco_anonimo");
		var pacco_anonimo_value = 1;
		if (pacco_anonimo.checked == true) {
			pacco_anonimo_value = 1;
		} else {
			pacco_anonimo_value = 0;
		}
	} else {
		check = false;
	}
	// Codice sconto
	if (document.getElementById("codice_sconto") != null) {
		var codice_sconto = encodeURIComponent(document.getElementById("codice_sconto").value);
	} else {
		check = false;
	}
	// Language
	if (document.getElementById("lang") != null) {
		var language = encodeURIComponent(document.getElementById("lang").value);
	} else {
		var language = encodeURIComponent("it");
	}
	
	// Procedo se i valori raccolti esistono.
	// Se uno tra i valori spedizione_nazione, spedizione e pagamento
	// non sono presenti non viene eseguita la richiesta ajax.
	// Questo si verifica nel caso in cui venga visualizzata la pagina
	// del carrello a carrello vuoto.
	if (check) {
		var RequestURL = "ajax/ajaxCarrello.php";
	    
		// Procedo solo se l'oggetto xmlHttp non e' occupato
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
		{
			// Costrisco l'URL da richiedere al server
			RequestURL = RequestURL + "?spedizione_nazione=" + spedizione_nazione;
			RequestURL = RequestURL + "&spedizione=" + spedizione;
			RequestURL = RequestURL + "&pagamento=" + pagamento;
			RequestURL = RequestURL + "&pacco_anonimo=" + pacco_anonimo_value;
			RequestURL = RequestURL + "&codice_sconto=" + codice_sconto;
			RequestURL = RequestURL + "&lang=" + language;
			
			//alert("DEBUG: Request URL: "+RequestURL);
			
			// Eseguo la pagina PHP sul server
			xmlHttp.open("GET", RequestURL, true);  
			// Definisco il metodo che interpreterà la risposta
			xmlHttp.onreadystatechange = apAJAXGetCartInfoResponse;
			// Effettuo la richiesta verso il server
			xmlHttp.send(null);
		}
		else
			// Se la connessione è occupata riprova dopo 2 secondi
			setTimeout('apAJAXGetCartInfo()', 2000);
	}
}

/// Funzione per elaborare la risposta delle info carrello
/// \author: Enrico Alborali
/// \version: 1.02 [29.06.2009]
/// \last modify: 10/06/10 - Diego Vicentini
function apAJAXGetCartInfoResponse() 
{
	// Recupero gli oggetti da gestire in base alla risposta
	var object_totale_peso				= document.getElementById("totale_peso");
	var object_totale_lavori			= document.getElementById("totale_lavori");
	var object_totale_spedizione		= document.getElementById("totale_spedizione");
//	var object_voce_pagamento			= document.getElementById("voce_pagamento");
//	var object_segno_pagamento			= document.getElementById("segno_pagamento");
	var object_totale_pagamento			= document.getElementById("totale_pagamento");
//	var object_totale_nonivato			= document.getElementById("totale_nonivato");
	var object_totale_ivato				= document.getElementById("totale_ivato");
	var object_totale_iva				= document.getElementById("totale_iva");
//	var object_nota_iva					= document.getElementById("nota_iva");
//	var object_descrizione_spedizione	= document.getElementById("descrizione_spedizione");
	var object_descrizione_spedizioneritiro	= document.getElementById("descrizione_spedizioneritiro");
	var object_descrizione_pagamento	= document.getElementById("descrizione_pagamento");
	var object_pagamento				= document.getElementById("pagamento");
	var object_spedizione				= document.getElementById("spedizione");
	var object_pacco_anonimo			= document.getElementById("pacco_anonimo");
	var object_codice_sconto            = document.getElementById("codice_sconto");
	var object_totale_sconto			= document.getElementById("totale_sconto");
	
	// Continua solo se la transazione e' stata completata
	if (xmlHttp.readyState == 4) 
	{
		// Se ho stato HTTP a 200 significa che l'operazione è stata completata con successo
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// Estraggo l'XML ricevuto
				xmlResponse = xmlHttp.responseXML;
				if (xmlResponse != null)
				{
					// obtain the document element (the root element) of the XML structure
					xmlDocumentElement = xmlResponse.documentElement;
					// Ottengo gli array degli elementi <value>
					var valueArray = xmlDocumentElement.getElementsByTagName("value");
					// Ottengo il numero di elementi contenuti nella risposta			
					var elementsNum = valueArray.length;
					// Stampo sul documento i risultati preventivo
					if (elementsNum > 0)
					{
						// Totale peso
						if (valueArray.item(0).firstChild != null) {
							object_totale_peso.innerHTML 		= valueArray.item(0).firstChild.data;
						} else {
							object_totale_peso.innerHTML		= "&nbsp;";
						}
						// Totale lavori
						if (valueArray.item(1).firstChild != null) {
							object_totale_lavori.innerHTML 		= valueArray.item(1).firstChild.data;
						} else {
							object_totale_lavori.innerHTML 		= "&nbsp;";
						}
						// Totale spedizione
						if (valueArray.item(2).firstChild != null) {
							object_totale_spedizione.innerHTML 	= valueArray.item(2).firstChild.data;
						} else {
							object_totale_spedizione.innerHTML 	= "&nbsp;";
						}
						/* Voce pagamento
						if (valueArray.item(3).firstChild != null) { 
							object_voce_pagamento.innerHTML 	= valueArray.item(3).firstChild.data;
						} else {
							object_voce_pagamento.innerHTML 	= "&nbsp;";
						}*/
						/* Segno pagamento
						if (valueArray.item(4).firstChild != null) {
							object_segno_pagamento.innerHTML 	= valueArray.item(4).firstChild.data;
						} else {
							object_segno_pagamento.innerHTML	= "&nbsp;";
						}*/
						// Totale pagamento
						if (valueArray.item(5).firstChild != null) {
							object_totale_pagamento.innerHTML 	= valueArray.item(5).firstChild.data;
						} else {
							object_totale_pagamento.innerHTML 	= "&nbsp;";
						}
						/* Totale non ivato
						if (valueArray.item(6).firstChild != null) {
							object_totale_nonivato.innerHTML 	= valueArray.item(6).firstChild.data;
						} else {
							object_totale_nonivato.innerHTML 	= "&nbsp;";
						}*/
						// Totale ivato
						if (valueArray.item(7).firstChild != null) {
							object_totale_ivato.innerHTML 		= valueArray.item(7).firstChild.data;
						} else {
							object_totale_ivato.innerHTML 		= "&nbsp;";
						}
						// Totale iva
						if (valueArray.item(8).firstChild != null) {
							object_totale_iva.innerHTML 		= valueArray.item(8).firstChild.data;
						} else {
							object_totale_iva.innerHTML			= "&nbsp";
						}
						/* Nota iva
						if (valueArray.item(9).firstChild != null) {
							object_nota_iva.innerHTML 		= valueArray.item(9).firstChild.data;
						} else {
							object_nota_iva.innerHTML 		= "&nbsp;";
						}*/
						// Descrizione spedizione
						if (valueArray.item(10).firstChild != null) {
							object_descrizione_spedizioneritiro.innerHTML	= valueArray.item(10).firstChild.nodeValue;
						} else {
							object_descrizione_spedizioneritiro.innerHTML	= "--";
						}
						// Descrizione pagamento
						if (valueArray.item(11).firstChild != null) {
							object_descrizione_pagamento.innerHTML	= valueArray.item(11).firstChild.data;
						} else {
							object_descrizione_pagamento.innerHTML	= "--";
						}
						// Pacco anonimo
						if (valueArray.item(12).firstChild != null) {
							if (valueArray.item(12).firstChild.data == 1) {
								object_pacco_anonimo.checked = true;
							} else {
								object_pacco_anonimo.checked = false;
							}
						} else {
							object_pacco_anonimo.checked = true;
						}
						// Sconto
						if (valueArray.item(13).firstChild != null) {
							if (valueArray.item(13).firstChild.data != "0,00" && valueArray.item(13).firstChild.data != "") {
								object_totale_sconto.innerHTML	= "*PROMO - sconto &euro; " + valueArray.item(13).firstChild.data;
							} else {
								object_totale_sconto.innerHTML	= "";
							}
						} else {
							object_totale_sconto.innerHTML	= "";
						}
						// Codice sconto
						if (valueArray.item(14).firstChild != null) {
							object_codice_sconto.value	= valueArray.item(14).firstChild.data;
						} else {
							object_codice_sconto.value	= "";
						}						
						// Se la spedizione è 'ritiro del cliente' allora elimina il contrassegno nella lista dei metodi
						// di pagamento...
						if (valueArray.item(15).firstChild != null) { 
							if (valueArray.item(15).firstChild.data == "true")
							{
								for (var i=0; i<object_pagamento.length; i++)
								{
									if (object_pagamento.options[i].value == 3)
										object_pagamento.remove(i);
								}
								
								// Richiama la funzione di calcolo
								apAJAXGetCartInfo();
							}
							else //... altrimenti la riabilita se non è già presente
							{
								var exists = false;
								for (i=0;i<object_pagamento.length;i++) {
									if (object_pagamento.options[i].value == 3) exists = true;
								}
								if (!exists) {
									var opt = document.createElement('option');
									opt.text = 'Contrassegno';
									opt.value = 3;
									try {
										object_pagamento.add(opt, null); // standards compliant; doesn't work in IE
									} catch(ex) {
										object_pagamento.add(opt); // IE only
									}
								}
							}
						}
					}
					else
					{
						alert("ERRORE! mancano alcune informazioni riguardo al carrello.");	
					}
					
					// Se il metodo di pagamento è 'contrassegno' allora elimina nella lista dei profili di spedizione
					// il profilo ritiro del cliente...
/*					if (object_pagamento.value == 3)
					{
						for (var i=0; i<object_spedizione.length; i++)
						{
							if (object_spedizione.options[i].value == 5)
								object_spedizione.remove(i);
						}
					}
					else //... altrimeni la riabilita se non è già presente
					{
						var exists = false;
						for (i=0;i<object_spedizione.length;i++) {
							if (object_spedizione.options[i].value == 5) exists = true;
						}
						if (!exists) {
							var opt = document.createElement('option');
							opt.text = 'Ritiro del cliente';
							opt.value = 5;
							try {
								object_spedizione.add(opt, null); // standards compliant; doesn't work in IE
							} catch(ex) {
								object_spedizione.add(opt); // IE only
							}
						}
					}*/
				}
				else
				{
					alert("Sistema di calcolo totale carrello temporaneamente non disponibile.");
				}
			}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
      	} 
		// Se lo stato HTTP e' diverso da 200 ho un errore
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
    		}
	}
}

/// Funzione per visualizzare l'invio della mail e la selezione del corriere
/// \author: Diego Vicentini
/// \version: 1.02 [03.09.2009]
function apAJAXUpdateSendMail()
{
	var stato = document.getElementById('stato');
	var valore = stato.options[stato.selectedIndex].value; 
	
	if ( valore == 2 )
	{
		// Abilita la checkbox per l'invio della mail e la selezione del corriere
		document.getElementById('riga_corriere').style.visibility = 'visible'; 
	}
	else
	{
		// Disabilita la checkbox per l'invio della mail e la selezione del corriere
		document.getElementById('riga_corriere').style.visibility = 'hidden'; 
	}
	
	//alert("DEBUG Abilita: " + abilita);	
}

/// Funzione per visualizzare le misure del formato
/// \author: Diego Vicentini
/// \version: 1.01 [01.09.2009]
function apAJAXUpdateFormatSize()
{
	var formato = document.getElementById("formato");
	var abilita = formato.options[formato.selectedIndex].value == -1; 
	
	if ( abilita )
	{
		// Abilita l'inserimento manuale di base ed altezza
		document.getElementById('misura_base').style.visibility = 'visible'; 
		document.getElementById('misura_altezza').style.visibility = 'visible'; 
	}
	else
	{
		// Disabilita l'inserimento manuale di base ed altezza
		document.getElementById('misura_base').style.visibility = 'hidden'; 
		document.getElementById('misura_altezza').style.visibility = 'hidden'; 
	}	
	
	//alert("DEBUG Abilita: " + abilita);		
}

/// Funzione per sincronizzare gli utenti del db del sito con
/// gli utenti del db della newsletter
/// \author: Diego Vicentini
/// \version: 1.00 [16.09.2009]
function apAJAXSynchronizeWeb3NewsUsers()
{
	// Procedo solo se l'oggetto xmlHttp non è occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", "ajax/ajaxSincronizzaWeb3News.php", true);
		// Definisco il metodo che interpreterà la risposta
		xmlHttp.onreadystatechange = apAJAXSynchronizeWeb3NewsUsersResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione è occupata riprova dopo 2 secondi
		setTimeout('apAJAXSynchronizeWeb3NewsUsers()', 2000);
}

/// Funzione per gestire la risposta della sincronizzazione gli utenti
/// del db del sito con gli utenti del db della newsletter
/// \author: Diego Vicentini
/// \version: 1.00 [28.09.2009]
function apAJAXSynchronizeWeb3NewsUsersResponse()
{
	// Continua solo se la transazione è stata completata
	if (xmlHttp.readyState == 4) 
	{
		// Se ho stato HTTP a 200 significa che l'operazione è stata completata con successo
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// Estraggo l'XML ricevuto
				xmlResponse = xmlHttp.responseXML;
				if (xmlResponse != null)
				{
					// obtain the document element (the root element) of the XML structure
					xmlDocumentElement = xmlResponse.documentElement;
					// Ottengo gli array degli elementi <value>
					var valueArray = xmlDocumentElement.getElementsByTagName("value");
					// Ottengo il numero di elementi contenuti nella risposta			
					var elementsNum = valueArray.length;
					
					if (elementsNum > 0) {
						// Stampo sul documento i risultati
						var object_debug_utenti_sito = document.getElementById("debug_utenti_sito");
						//var object_debug_utenti_web3news = document.getElementById("debug_utenti_web3news");
						var object_debug_utenti_copiati = document.getElementById("debug_utenti_copiati");
						var object_debug_utenti_presenti = document.getElementById("debug_utenti_presenti");
						var object_debug_utenti_attivi = document.getElementById("debug_utenti_attivi");
						var object_debug_utenti_standby = document.getElementById("debug_utenti_standby");
						var object_debug_errori = document.getElementById("debug_errori");
						var object_debug_errori_iscrizione = document.getElementById("debug_errori_iscrizione");
						var object_debug_errori_cancellazione = document.getElementById("debug_errori_cancellazione");
						var object_debug_errori_nuovoUtente = document.getElementById("debug_errori_nuovoUtente");
						
						if (valueArray.item(0) != null) object_debug_utenti_sito.innerHTML = valueArray.item(0).firstChild.data;
						else object_debug_utenti_sito.innerHTML = "ERROR";
						//if (valueArray.item(1) != null) object_debug_utenti_web3news.innerHTML = valueArray.item(1).firstChild.data;
						//else object_debug_utenti_web3news.innerHTML = "ERROR";
						if (valueArray.item(2) != null) object_debug_utenti_copiati.innerHTML = valueArray.item(2).firstChild.data;
						else object_debug_utenti_copiati.innerHTML = "ERROR";
						if (valueArray.item(3) != null) object_debug_utenti_presenti.innerHTML = valueArray.item(3).firstChild.data;
						else object_debug_utenti_presenti.innerHTML = "ERROR";
						if (valueArray.item(4) != null) object_debug_utenti_attivi.innerHTML = valueArray.item(4).firstChild.data;
						else object_debug_utenti_attivi.innerHTML = "ERROR";
						if (valueArray.item(5) != null) object_debug_utenti_standby.innerHTML = valueArray.item(5).firstChild.data;
						else object_debug_utenti_standby.innerHTML = "ERROR";
						if (valueArray.item(6) != null) object_debug_errori.innerHTML = valueArray.item(6).firstChild.data;
						else object_debug_errori.innerHTML = "ERROR";
						if (valueArray.item(7) != null) object_debug_errori_iscrizione.innerHTML = valueArray.item(7).firstChild.data;
						else object_debug_errori_iscrizione.innerHTML = "ERROR";
						if (valueArray.item(8) != null) object_debug_errori_cancellazione.innerHTML = valueArray.item(8).firstChild.data;
						else object_debug_errori_cancellazione.innerHTML = "ERROR";
						if (valueArray.item(9) != null) object_debug_errori_nuovoUtente.innerHTML = valueArray.item(9).firstChild.data;
						else object_debug_errori_nuovoUtente.innerHTML = "ERROR";
					}
				}
				else
				{
					alert("Sistema di sincronizzazione newsletter temporaneamente non disponibile.");
				}
		 	}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
		}
		// Se lo stato HTTP è diverso da 200 ho un errore
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
		}
	}
}

/// Funzione per la creazione del link temporaneo per la consultazione
/// del report feedback da parte degli utenti
/// \author: Diego Vicentini
/// \version: 1.00 [19.01.2010]
function apAJAXTempFeedbackReport(active, link)
{
	if (link == null || link == "") {
		// Genero il link casuale
		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length = 16;
		var randomstring = '';
		for (var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			randomstring += chars.substring(rnum,rnum+1);
		}
		randomstring += ".php";
		link = randomstring;
	}
	
	// Procedo solo se l'oggetto xmlHttp non è occupato
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// Costrisco l'URL da richiedere al server
		// Eseguo la pagina PHP sul server
		xmlHttp.open("GET", "ajax/ajaxTempFeedbackReport.php?attiva="+active+"&link="+link, true);
		// Definisco il metodo che interpreterà la risposta
		xmlHttp.onreadystatechange = apAJAXTempFeedbackReportResponse;
		// Effettuo la richiesta verso il server
		xmlHttp.send(null);
	}
	else
		// Se la connessione è occupata riprova dopo 2 secondi
		setTimeout("apAJAXTempFeedbackReport("+active+")", 2000);
}

/// Funzione per gestire la risposta della creazione del link temporaneo per
/// la consultazione del report feedback
/// \author: Diego Vicentini
/// \version: 1.02 [28.01.2010]
function apAJAXTempFeedbackReportResponse()
{
	// Continua solo se la transazione è stata completata
	if (xmlHttp.readyState == 4) 
	{
		// Se ho stato HTTP a 200 significa che l'operazione è stata completata con successo
		if (xmlHttp.status == 200) 
		{
		 	try
		 	{
		 	 	// Estraggo l'XML ricevuto
				xmlResponse = xmlHttp.responseXML;
				if (xmlResponse != null)
				{
					// obtain the document element (the root element) of the XML structure
					xmlDocumentElement = xmlResponse.documentElement;
					// Ottengo gli array degli elementi <value>
					var valueArray = xmlDocumentElement.getElementsByTagName("value");
					// Ottengo il numero di elementi contenuti nella risposta			
					var elementsNum = valueArray.length;
					
					if (elementsNum > 0) {
						//var object_debug_feedback_error = document.getElementById("inputerrormsg");
						var object_debug_feedback_link = document.getElementById("link_report");
						var object_debug_feedback_link_button = document.getElementById("link_button");
						
/*						if (valueArray.item(0) != null) {
							object_debug_feedback_error.style.color = '#cc0000';
							object_debug_feedback_error.style.fontSize = '9pt';
							object_debug_feedback_error.style.fontWeight = 'bold';
							if (valueArray.item(0).firstChild.data == '0') {
								object_debug_feedback_error.innerHTML = "Operazione terminata con successo. Salva!";
							}
							if (valueArray.item(0).firstChild.data == '1') {
								object_debug_feedback_error.innerHTML = "Nome file non presente";
							}
							if (valueArray.item(0).firstChild.data == '2') {
								object_debug_feedback_error.innerHTML = "Errore nella creazione del file";
							}
							if (valueArray.item(0).firstChild.data == '3') {
								object_debug_feedback_error.innerHTML = "Errore nel'eliminazione del file";
							}
						} else object_debug_feedback_error.innerHTML = "ERROR";
*/
						var link = "";
						if (valueArray.item(1) != null) {
							object_debug_feedback_link.innerHTML = valueArray.item(1).firstChild.data;
							link = valueArray.item(1).firstChild.data;
						} else object_debug_feedback_link.innerHTML = "ERROR";
						
						if (valueArray.item(2) != null && object_debug_feedback_link_button != null) {
							if (valueArray.item(2).firstChild.data == 1) {
								object_debug_feedback_link_button.value = "Nascondi URL";
								object_debug_feedback_link_button.setAttribute("onclick", "apAJAXTempFeedbackReport(0, '"+link+"');");
							} else {
								object_debug_feedback_link_button.value = "Pubblica URL";
								object_debug_feedback_link_button.setAttribute("onclick", "apAJAXTempFeedbackReport(1, null);");
							}
						}						
					}
				}
				else
				{
					alert("Sistema di generazione automatica link report temporaneamente non disponibile.");
				}
		 	}
			catch(e)
			{
			 	alert("ERRORE! Si e' verificato un problema durante l'elaborazione dei dati: " + e.toString());
			}
		}
		// Se lo stato HTTP è diverso da 200 ho un errore
		else 
		{
		 	alert("ERRORE! Si e' verificato un problema durante l'accesso al server: " + xmlHttp.statusText);
		}
	}
}