
function getXMLHttpRequest() {
	// lista delle variabili locali
	var XHR = null;
	// informazioni sul nome del browser
	var browserUtente = navigator.userAgent.toUpperCase();
	// browser standard con supporto nativo
	// non importa il tipo di browser
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object") {
		 // browser Internet Explorer
		 // è necessario filtrare la versione 4
  		XHR = new XMLHttpRequest();
	}
    else if ( window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0 ) {
		// la versione 6 di IE ha un nome differente
		// per il tipo di oggetto ActiveX
		if(browserUtente.indexOf("MSIE 5") < 0) {
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		}
		else {
			// le versioni 5 e 5.5 invece sfruttano lo stesso nome
		    XHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
	 }
	 return XHR;
} 

function qui_carrello_Popup(mainpage,cp, pid) {
	var quantita = document.getElementById("qui_cart_quantity");
	//alert(quantita.value);
	var ajaxObj = getXMLHttpRequest();
	// inizializzo la richiesta in post
	ajaxObj.open("post", "pop_up_carrello.php", true);
	// imposto il giusto header
	ajaxObj.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    // imposto la callback per la ricezione dei dati
    ajaxObj.onreadystatechange = function() {  
      // nel caso in cui la funzione sia completata verifico l'esito
      if(ajaxObj.readyState == 4) {
        // verifico la risposta del server
        if(ajaxObj.status == '200') {
          // operazione avvenuta con successo 
		  if ( ajaxObj.responseText.length > 0 ) {
			document.getElementById('pop_up_info_carrello').style.visibility = 'visible';
			arr = ajaxObj.responseText.split(':');
			document.getElementById('prezzo_totale_carrello').innerHTML = '&euro;&nbsp;' + arr[0];
			document.getElementById('articoli_totali_carrello').innerHTML = arr[1] + ' prodotti';
			document.getElementById('immagine_carrello').innerHTML = "<img src='includes/templates/template_default/images/header/qui_header_carrello_pieno.gif' />";
			var qstring  = "main_page="+mainpage+"&cpvvv="+cp+"&products_id="+pid;
			qui_carrello_left(qstring);
		  }else{ alert('Errore riscontrato: ' + ajaxObj.status);}
		}
        else {
          // errore di caricamento
		  alert('Errore riscontrato: ' + ajaxObj.status);
        }
      } 
    }
	// effettuo la richiesta inviando la variabile
	
	ajaxObj.send("quantita_da_inserire="+quantita.value+"&products_id="+pid);
}


function qui_carrello_left(qstring) {
	
	var ajaxObj = getXMLHttpRequest();
	// inizializzo la richiesta in post
	// imposto il giusto header
	//ajaxObj.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    // imposto la callback per la ricezione dei dati
    ajaxObj.onreadystatechange = function() {  
      // nel caso in cui la funzione sia completata verifico l'esito
      if(ajaxObj.readyState == 4) {
        // verifico la risposta del server
        if(ajaxObj.status == '200') {
          // operazione avvenuta con successo 
		  if ( ajaxObj.responseText.length > 0 ) {		
		  //"<div id='navColumnOneWrapper' style='width: 220px;'>"+ "menu<br><br>carrello" + "</div>";
			document.getElementById('navColumnOne').innerHTML = ajaxObj.responseText;
			
		  }else{ alert('Errore riscontrato: ' + ajaxObj.status);}
		}
        else {
          // errore di caricamento
		  alert('Errore riscontrato: ' + ajaxObj.status);
        }
      } 
    }
	// effettuo la richiesta inviando la variabile
	ajaxObj.open("get", "col_replace.php?"+qstring, true);
	ajaxObj.send(qstring);
}


function qui_remove_item_carello(mainpage, pid) {	
	
	var ajaxObj = getXMLHttpRequest();
	
	// inizializzo la richiesta in post
	ajaxObj.open("post", "remove_item_carrello.php", true);
	// imposto il giusto header
	ajaxObj.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    // imposto la callback per la ricezione dei dati
    ajaxObj.onreadystatechange = function() {  
      // nel caso in cui la funzione sia completata verifico l'esito
      if(ajaxObj.readyState == 4) {
        // verifico la risposta del server
        if(ajaxObj.status == '200') {
          // operazione avvenuta con successo 
		  if ( ajaxObj.responseText.length > 0 ) {
			arr = ajaxObj.responseText.split(':');
			if ( parseInt(arr[1]) > 0 ) {
				document.getElementById('prezzo_totale_carrello').innerHTML = '&euro;&nbsp;' + arr[0];
				document.getElementById('articoli_totali_carrello').innerHTML = arr[1] + ' prodotti';
				document.getElementById('immagine_carrello').innerHTML = "<img src='includes/templates/template_default/images/header/qui_header_carrello_pieno.gif' />";	
			} else {
				document.getElementById('prezzo_totale_carrello').innerHTML = "<span style='font-weight:normal'>Il tuo</span> carrello<span style='font-weight:normal'><br>è</span> vuoto";
				document.getElementById('articoli_totali_carrello').innerHTML = '';
				document.getElementById('immagine_carrello').innerHTML = "<img src='includes/templates/template_default/images/header/qui_header_carrello_vuoto.gif' />";
			}
			var qstring  = "main_page="+mainpage+"&cpvvv&products_id="+pid;
			qui_carrello_left(qstring);	
		  }
		}
        else {
          // errore di caricamento
		  alert('Errore riscontrato: ' + ajaxObj.status);
        }
      } 
    }
	// effettuo la richiesta inviando la variabile
	ajaxObj.send("products_id="+pid);
}

function qui_carrello_Popup_in_list(mainpage,cp, pid) {
	
	var quantita = document.getElementById('products_id['+pid+']');
	
	var ajaxObj = getXMLHttpRequest();
	
	// inizializzo la richiesta in post
	ajaxObj.open("post", "pop_up_carrello.php", true);
	// imposto il giusto header
	ajaxObj.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    // imposto la callback per la ricezione dei dati
    ajaxObj.onreadystatechange = function() {  
      // nel caso in cui la funzione sia completata verifico l'esito
      if(ajaxObj.readyState == 4) {
        // verifico la risposta del server
        if(ajaxObj.status == '200') {
          // operazione avvenuta con successo 
		  if ( ajaxObj.responseText.length > 0 ) {
			
			document.getElementById('pop_up_info_carrello').style.visibility = 'visible';
			arr = ajaxObj.responseText.split(':');
			document.getElementById('prezzo_totale_carrello').innerHTML = '&euro;&nbsp;' + arr[0];
			document.getElementById('articoli_totali_carrello').innerHTML = arr[1] + ' prodotti';
			document.getElementById('immagine_carrello').innerHTML = "<img src='includes/templates/template_default/images/header/qui_header_carrello_pieno.gif' />";	

			var qstring  = "main_page="+mainpage+"&cpvvv="+cp+"&products_id="+pid;
			qui_carrello_left(qstring);	
		  }
		}
        else {
          // errore di caricamento
		  alert('Errore riscontrato: ' + ajaxObj.status);
        }
      } 
    }
	// effettuo la richiesta inviando la variabile
	ajaxObj.send("quantita_da_inserire="+quantita.value+"&products_id="+pid);
}