function ProcessCart(strOP) {
	var arrOp = String(strOP).split(",");
	document.frmProcess.OP.value=String(arrOp[0]);
	if (arrOp.length>1) document.frmProcess.OTHER.value=arrOp[1];
	document.frmProcess.submit();
}

function SubmitCart() {
	if (document.frmCart.selSpedizione.value=="0") alert("Non hai selezionato le spese di spedizione.")
	else if (document.frmCart.selPagamento.value=="0") alert("Non hai selezionato la modalità di pagamento")
	else document.frmCart.submit();
}


function checkIsPagConsegna(magg){
	
	var selPag=document.getElementById("selPagamento");
	var pag=document.getElementById("pagamento");
	var span=document.getElementById("valuta_pagamento");
	var desc_match="Contanti (pag. Alla Consegna)";
	
		if (selPag.value==desc_match){
		span.style.display='block';
		pag.style.display='block';
		pag.value=magg;
		}
		else{
			span.style.display='none';
			pag.style.display='none';
			pag.value=0;
			}
	EvalCart(document.frmCart);
	
	}

function checkIsAssDanni(){
	
	var selAss=document.getElementById("selAssicurazione");
	var Ass=document.getElementById("assicurazione");
	var span=document.getElementById("valuta_ass");
	var desc_match="Non Richiesta";
	
		if (selAss.value!="novalue"){
		span.style.display='block';
		Ass.style.display='block';
		Ass.value=selAss.value;
		}
		else{
			span.style.display='none';
			Ass.style.display='none';
			Ass.value=0;
			}
	EvalCart(document.frmCart);
	
	}




function EvalCart( TheForm ) {
//	indice posizione campi nel modulo (per riga)
	var idPrezzo = 0;
	var idQuantita = 1;
	var idItemId = 2;
	var idListino = 3;
	var idImporto = 4;
	
	var empty = true;
	var prz, qta, somma, imp, iva, tot, spedizione, commissioni,extra,pagamento,assicurazione;
	
	somma = 0;
	/*commissioni=parseFloat(document.getElementById("commissioni").value);
	extra=parseFloat(document.getElementById("extra").value);
	pagamento=parseFloat(document.getElementById("pagamento").value);
	assicurazione=parseFloat(document.getElementById("assicurazione").value);*/
	commissioni=parseFloat(TheForm.commissioni.value);
	extra=parseFloat(TheForm.extra.value);
	pagamento=parseFloat(TheForm.pagamento.value);
	assicurazione=parseFloat(TheForm.assicurazione.value);
	somma_other=commissioni+extra+pagamento+assicurazione;
	for (var i=0; i<TheForm.elements.length && TheForm.elements[i].name.toLowerCase()=="prezzo"; i=i+5) {
		empty = false;
		
		prz = parseFloat(TheForm.elements[ i + idPrezzo ].value);
		qta = parseInt(TheForm.elements[ i + idQuantita ].value);
		imp = Math.round( prz * qta * 100 ) / 100;
		
		TheForm.elements[ i + idImporto ].value = String(imp+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		somma += imp;
		}

// se il carrello non è vuoto allora calcola il totale
		if (!empty) {
			somma = Math.round( somma * 100 ) / 100;
	
			//	calcola lo sconto promozionale
			//promozione.calcPromo( somma );
			
			spedizione=eval(TheForm.spedizione.value);
			iva=Math.round((somma+spedizione+somma_other)*20) / 100;
			tot=Math.round((somma+spedizione+somma_other+iva)*100) / 100;
			
			TheForm.sconto.value = 0;		
			TheForm.somma.value = String(somma+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
			TheForm.iva.value = String(iva+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
			TheForm.totale.value = String(tot+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		}
}

function EvalCartEx(TheForm) {
	// inutilizzato!!!!!!
	var prz, qta, somma, imp, iva, tot, spedizione


document.write( ">>>>>>" + typeOf(TheForm.prezzo) )
return

	if (String(TheForm.prezzo).toLowerCase()=="undefined") {
		prz=eval(TheForm.prezzo.value);
		qta=eval(TheForm.quantita.value);
		imp=prz*qta;
		spedizione=eval(TheForm.spedizione.value);
		somma=Math.round(imp*100)/100;

		//	calcola lo sconto promozionale
		promozione.calcPromo( somma );

		iva=Math.round((somma-promozione.sconto+spedizione)*20) / 100;
//		tot=Math.round((somma+spedizione+iva)*100) / 100;
		tot=Math.round((somma-promozione.sconto+spedizione+iva)*100) / 100;
		
		TheForm.sconto.value = String(promozione.sconto+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");		
		TheForm.importo.value = String(imp+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		TheForm.somma.value = String(somma+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		TheForm.iva.value = String(iva+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		TheForm.totale.value = String(tot+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		
	} else {
		somma=0;
		for (var cItem=0;cItem<TheForm.prezzo.length;cItem++) {
			prz=eval(TheForm.prezzo[cItem].value);
			qta=eval(TheForm.quantita[cItem].value);
//			imp=Math.round((prz*100)*(qta*100))/10000;
			imp=Math.round(prz*qta*100)/100;
			
			TheForm.importo[cItem].value = String(imp+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
			somma+=imp;
		}
		somma = Math.round(somma*100)/100;

		//	calcola lo sconto promozionale
		promozione.calcPromo( somma );
		
		spedizione=eval(TheForm.spedizione.value);
		iva=Math.round((somma-promozione.sconto+spedizione)*20) / 100;
//		tot=Math.round((somma+spedizione+iva)*100) / 100;
		tot=Math.round((somma-promozione.sconto+spedizione+iva)*100) / 100;
		
		TheForm.sconto.value = String(promozione.sconto+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");		
		TheForm.somma.value = String(somma+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		TheForm.iva.value = String(iva+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
		TheForm.totale.value = String(tot+"00").replace(/^(\d*)\.?(\d{2}).*$/,"$1.$2");
	}
}

function ChangeQta( pQta, pCountListino, pItemId ) {
	var notGood=/\D{1,}/g;
	var newQta = prompt("Digita il nuovo valore per quantità:", pQta);
	if (!notGood.test(newQta) && newQta!="" && newQta!="0") ProcessCart("UPDATE_QTA," + pCountListino + ";" + pItemId + ";" + newQta)
	else alert("Valore non valido,\ndigitare un valore numerico diverso da zero.");
}