function aggiungiCarrello(codPdt){
   $.ajax({
      url: 'aggiungiCarrello.php?cod_pdt='+codPdt,
      success: function(data) {
	   	alert(data);
      }
   });
}
function cambiaQuantita(id,quantita){
	   $.ajax({
	      url: 'aggiungiCarrello.php?id_carrello='+id+"&quantita="+quantita,
	      success: function(data) {
		   	//alert(data);
	      }
	   });
	}
function rimuovi(id){
	   $.ajax({
	      url: 'aggiungiCarrello.php?id_carrello_rimuovi='+id,
	      success: function(data) {
		   	alert(data);
	      }
	   });
	}

function createTarget(t){
	window.open("", t, "width=500,height=200");
	return true;
}
function freshTotale(){
	totale=0;
	$('.conversioneValuta').each(function(index) {
		if($(this).attr('id')!="conversioneValutaTotale"){
			cod_pdt=$(this).attr('id').replace("conversioneValuta","");	
			quantita=$("#quantita_"+cod_pdt).attr('value');
			totLocale=parseFloat( $(this).text())*parseFloat( quantita);
		//	alert(cod_pdt+": "+$(this).text()+" * "+quantita+"="+totLocale );
		totale+= totLocale;
		}
	  });
	$('#conversioneValutaTotale').html( parseFloat(""+totale));
	  $(document).ready(function () {
	
		  $('#conversioneValutaTotale').conversioneValuta({
	      valuta: 'EUR',
	      labelvaluta:'Euro:',
  	  cambio: 'USD',
  	  labelcambio:  'USD:'
	   });
	if(document.getElementById('carrelloTestoCliente')){
		  if(document.getElementById('carrelloTestoCliente').value!=null){
			 
			  document.getElementById('carrelloTestoCliente').value= $("#text_carrello").html()+"<br><br>"+$("#tot_carrello").html();
			  document.getElementById('carrelloTestoRivenditore').value= $("#text_carrello").html()+"<br><br>"+$("#tot_carrello").html();
		  }
	}
	
	  });
	
}
$(document).ready(function() {
	freshTotale();
});
