function Prosegui (theForm,button) {
	var fValid;
	
	fValid = true;
	
	if (button=="1") {
		theForm.perso.value="NO";
	}
	else if (button=="2") {
		theForm.perso.value="SI";
	}
	
	if ((theForm.qtatot.value!=0) && (theForm.qtatot.value.length>0) && (isNaN(theForm.qtatot.value) || theForm.qtatot.value<0)) {
		alert("Non hai inserito un valore valido !");
		theForm.qtatot.focus();
		fValid = false
		}
	else if (theForm.qtatot.value.length<=0) {
		alert("Non hai inserito la quantità !");
		theForm.qtatot.focus();
		fValid = false
		}
	else if (theForm.qtatot.value=="0") {
		alert("Non puoi inserire una quantità nulla !");
		theForm.qtatot.focus();
		fValid = false
		}
	else if (parseInt(theForm.qtatot.value)<qtymin) {
		alert("La quantita minima è " + qtymin + " pz. !");
		theForm.qtatot.focus();
		fValid = false
		}
	else if (theForm.qtatot.value!=theForm.qtatotck.value) {
		alert("Il totale della suddivisione non è uguale alla quantità totale !");
		theForm.qtatot.focus();
		fValid = false
		}
	else if (button=="2" && (fValid)) {
		theForm.perso.value="SI";
		
		if (fValid && (theForm.colorestp.value=="0") && (theForm.altrocolore.value==0) && (theForm.altrocolore.value.length<=0)) {
			alert("Devi selezionare o indicare un colore di stampa !");
			fValid = false;
			}
			
		if (fValid && (theForm.testostamp.value==0) && (theForm.testostamp.value.length<=0) && !(theForm.logo.checked)) {
			alert("Devi indicare un testo o inviarci un logo per la personalizzazione !");
			fValid = false;
			}
		}
	
	if (fValid) {
		theForm.submit();
	}
}

function computeprice(theForm,sorg) {
	if (sorg=="qt") {
		qtatot = parseInt(theForm.qtatot.value);
		theForm.totqta.value = qtatot;
		}
	else {
		if (theForm.totqta.value!="" && !isNaN(theForm.totqta.value)) {
			totqta = parseInt(theForm.totqta.value);
			theForm.qtatot.value = totqta;
			}
		}
	qtatot = parseInt(theForm.qtatot.value);
	posQta = findPosQty(theForm);
	
	//if (nColTg!=0) theForm.qtatotck.value = qtatot;
	totnopers = 0;
	totpers = 0;
	toteur = 0;
	if (posQta >= 0) {
		totnopers = Math.round(qtatot*prezzo[posQta]*100)/100;
		}
	theForm.totnopers.value = Math.round(totnopers * 100) / 100;
	theForm.totnopers1.value = theForm.totnopers.value;
	toteur += totnopers;
	if (theForm.person.value=="SI") {
		computepers(theForm);
		if (!(isNaN(theForm.perscost.value))) {
			totpers += parseFloat(theForm.perscost.value);
		}
		if ((!isNaN(theForm.impcost.value))) {
			totpers += parseFloat(theForm.impcost.value);
		}
		theForm.totpers.value = Math.round(totpers * 100) / 100;
	}
	toteur += totpers;
	if (isNaN(toteur)) {
		toteur = 0
	}
	if (theForm.person.value=="SI") {
		theForm.toteuro.value = Math.round(toteur * 100) / 100;
		theForm.toteuro1.value = theForm.toteuro.value;
	}
}

function computeqty(theForm) {
	startIt = offsetForm;
	stopIt = startIt + nColTg;
	qtyColTg = 0;
	while (startIt < stopIt) {
		if (!isNaN(parseInt(theForm.elements[startIt].value))) {
			qtyColTg += parseInt(theForm.elements[startIt].value);
			}
		startIt++;
	}
	theForm.qtatotck.value = qtyColTg;
	computeprice(theForm,'tq');
}

function computepers(theForm) {
	qtatot = parseInt(theForm.qtatot.value);
	if (qtatot >= qtymin) {
		indTSt = 0;
		posQta = findPosQty(theForm);
		if (indTSt >= 0) {
			theForm.perscost.value = Math.round(qtatot * tipStp[indTSt][posQta] * 100) / 100;
			theForm.impcost.value = tipStp[indTSt][4];
		}
		else {
			theForm.perscost.value = 0;
			theForm.impcost.value = 0;
		}
	}
	else {
		deletepers(theForm);
	}
}

function deletepers(theForm) {
	theForm.perscost.value = 0;
	theForm.impcost.value = 0;
}

function findPosQty(theForm) {
	posQty = 0;
	campi = 3;
	qty = parseInt(theForm.qtatot.value);
	if (qty >= qtymin) {
		exit = false;
		while (!exit && posQty <= campi) {
			if (qty < parseInt(qta[posQty])) {
				exit = true;
				posQty--;
				}
			else {
				posQty++;
				}
		}
	}
	else {
		posQty = -1;
	}
	if (posQty > campi) {
		posQty = campi;
	}
	return posQty;
}

