
//VISUALIZZA ALERT IN SCHEDA PRODOTTO
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/

if(!window.event) // Netscape/Firefox/Opera
{	
	if (keynum == undefined){
		return(e);
	} else {
		if (keynum == 8){
			return(e);
		}
	}
}

return numcheck.test(keychar)
}

function noNumbersAndComma(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)

if (keychar == ","){
	return(keychar);	
}

numcheck = /\d/

if(!window.event) // Netscape/Firefox/Opera
{	
	if (keynum == undefined){
		return(e);
	} else {
		if (keynum == 8 ){
			return(e);
		}
	}
}

return numcheck.test(keychar)
}

function noNumbersAndCommaAndMinus(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)

if (keychar == "," || keychar == "-"){
	return(keychar);	
}

numcheck = /\d/

if(!window.event) // Netscape/Firefox/Opera
{	
	if (keynum == undefined){
		return(e);
	} else {
		if (keynum == 8 ){
			return(e);
		}
	}
}

return numcheck.test(keychar)
}

function numbersonly(myfield, e, dec) {
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  } else
    return false;
}




function caricaCliente(valCodice){
	if (valCodice == ""){
		return false;	
	}
	
	location.href="carrello.asp?Codice="+valCodice;
}

function chiama_carico(){
	var bContinua = false;
	len = document.scheda.elements.length;
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
			if ( document.scheda.elements[i].value != '' && eval(document.scheda.elements[i].value) != 0){
				bContinua = true;
				i = len;
			}
		}
	}
	if (bContinua != true){
		alert("Nessuna quantità da caricare");	
	} else {
		if(confirm("Confermare l'operazione di carico del magazzino?")){
			bContinua = true;
		} else {
			bContinua = false;
		}
	}
	if (bContinua == true){
		document.scheda.action = "gest_carica_magazzino.asp"
		document.scheda.submit();
	}
}

function chiama_carrello(){
	var bContinua = false;
	len = document.scheda.elements.length;
	
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
			if ( document.scheda.elements[i].value != '' && eval(document.scheda.elements[i].value) != 0){
				bContinua = true;
				i = len;
			}
		}
	}
	if (bContinua == true){
		for( i=0; i<len; i++) {
			if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
				if ( document.scheda.elements[i].value != '' ) {
					//alert (document.scheda.elements[i].name);
					//alert (document.scheda.elements[i].value);
					
					if ( eval(document.scheda.elements[i].value) > eval(document.getElementById(document.scheda.elements[i].name.substr(0,document.scheda.elements[i].name.length - 7) + '_quantita').value )){
						alert("Quantità ordinata superiore a quella disponibile");	
						document.scheda.elements[i].select();
						bContinua = false;
						i = len;
					}
				}
			}
		}
	} else {
		alert("Nessuna quantità ordinata");	
	}
	if (bContinua == true){
		document.scheda.submit();
	}
}

function chiama_aggiornacarrello(){
	var bContinua = false;
	len = document.scheda.elements.length;
	
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
			if ( document.scheda.elements[i].value != '' && eval(document.scheda.elements[i].value) != 0){
				bContinua = true;
				i = len;
			}
		}
	}
	if (bContinua == true){
		for( i=0; i<len; i++) {
			if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
				if ( document.scheda.elements[i].value != '' ) {
					//alert (document.scheda.elements[i].name);
					//alert (document.scheda.elements[i].value);
					
					if ( eval(document.scheda.elements[i].value) > eval(document.getElementById(document.scheda.elements[i].name.substr(0,document.scheda.elements[i].name.length - 7) + '_quantita').value )){
						alert("Quantità ordinata superiore a quella disponibile");	
						document.scheda.elements[i].select();
						bContinua = false;
						i = len;
					}
				}
			}
		}
	} else {
		alert("Nessuna quantità ordinata");	
	}

	if (bContinua == true){
		document.scheda.submit();
	}
}

function chiama_cassa(){
	var bContinua = true;
	var contaNomi = 0;
	var contaNGrandi = 0;
	var contaNPiccoli = 0;
	var bNGprocedi = false;
	var bNPprocedi = false;
	
	len = document.scheda.elements.length;

	/*
	alert(document.getElementById("pSupporti").value);	
	alert(document.getElementById("pNomi").value);	
	alert(document.getElementById("pGrande").value);	
	alert(document.getElementById("pPiccolo").value);	
	*/


	//controllo se ci sono duplicazioni tra i numeri grandi
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 13,13) == '_numerogrande') {
			if(!bNGprocedi){
				arColoreElementoI = document.scheda.elements[i].name.split('_');
				
				if (document.scheda.elements[i].value != "") {
						for( y=0; y<len; y++) {
							if(!bNGprocedi){
								if (document.scheda.elements[y].name.substr(0, 3) == 'ms_' && document.scheda.elements[y].name.substr(document.scheda.elements[y].name.length - 13,13) == '_numerogrande') {
										if (document.scheda.elements[i].name != document.scheda.elements[y].name) {
												arColoreElementoY = document.scheda.elements[y].name.split('_');
												
												if (arColoreElementoI[2] == arColoreElementoY[2] && arColoreElementoI[3] == arColoreElementoY[3] && arColoreElementoI[4] == arColoreElementoY[4]){
														if (document.scheda.elements[i].value == document.scheda.elements[y].value) {
																if (!(confirm("Ci sono due o più numeri grandi uguali. Vuoi procedere comunque?"))){
																		document.scheda.elements[y].focus();
																		return(false);
																} else {
																		bNGprocedi = true;
																}
														}
												}
										}
								}
							}
						}
				}			
			}
		}
	}

	//controllo se ci sono duplicazioni tra i numeri piccoli
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 14,14) == '_numeropiccolo') {
			if(!bNPprocedi){
				arColoreElementoI = document.scheda.elements[i].name.split('_');
				
				if (document.scheda.elements[i].value != "") {
						for( y=0; y<len; y++) {
							if(!bNPprocedi){
								if (document.scheda.elements[y].name.substr(0, 3) == 'ms_' && document.scheda.elements[y].name.substr(document.scheda.elements[y].name.length - 14,14) == '_numeropiccolo') {
										if (document.scheda.elements[i].name != document.scheda.elements[y].name) {
												arColoreElementoY = document.scheda.elements[y].name.split('_');
												
												if (arColoreElementoI[2] == arColoreElementoY[2] && arColoreElementoI[3] == arColoreElementoY[3] && arColoreElementoI[4] == arColoreElementoY[4]){
														if (document.scheda.elements[i].value == document.scheda.elements[y].value) {
																if (!(confirm("Ci sono due o più numeri piccoli uguali. Vuoi procedere comunque?"))){
																		document.scheda.elements[y].focus();
																		return(false);
																} else {
																		bNPprocedi = true;
																}
														}
												}
										}
								}
							}
						}
				}			
			}
		}
	}
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 5,5) == '_nome') {
			if (document.scheda.elements[i].value != '') {
				contaNomi = contaNomi + 1;
			}
		}
	}
	if (contaNomi > eval(document.getElementById("pNomi").value)){
				alert("Sono stati indicati più nomi rispetto a quelli acquistati");	
				return(false);
	}

	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 13,13) == '_numerogrande') {
			if (document.scheda.elements[i].value != '') {
				contaNGrandi = contaNGrandi + 1;
			}
		}
	}
	if (contaNGrandi > eval(document.getElementById("pGrande").value)){
				alert("Sono stati indicati più numeri grandi rispetto a quelli acquistati");	
				return(false);
	}
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 14,14) == '_numeropiccolo') {
			if (document.scheda.elements[i].value != '') {
				contaNPiccoli = contaNPiccoli + 1;
			}
		}
	}
	if (contaNPiccoli > eval(document.getElementById("pPiccolo").value)){
				alert("Sono stati indicati più numeri piccoli rispetto a quelli acquistati");	
				return(false);
	}

	var strAppEl = "";
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 5,5) == '_nome') {
			if (document.scheda.elements[i].value != '') {
				strAppEl = document.scheda.elements[i].name;
				strAppEl = strAppEl.replace('_nome','_colorenome');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i nomi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 11,11) == '_colorenome') {
			if (document.scheda.elements[i].value != '') {
				strAppEl = document.scheda.elements[i].name;
				strAppEl = strAppEl.replace('_colorenome','_nome');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i nomi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
	}
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 13,13) == '_numerogrande') {
			if (document.scheda.elements[i].value != '') {
				strAppEl = document.scheda.elements[i].name;
				strAppEl = strAppEl.replace('_numerogrande','_colorenumerogrande');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri grandi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 19,19) == '_colorenumerogrande') {
			if (document.scheda.elements[i].value != '') {
				strAppEl = document.scheda.elements[i].name;
				strAppEl = strAppEl.replace('_colorenumerogrande','_numerogrande');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri grandi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
	}
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 14,14) == '_numeropiccolo') {
			if (document.scheda.elements[i].value != '') {
				strAppEl = document.scheda.elements[i].name;
				strAppEl = strAppEl.replace('_numeropiccolo','_colorenumeropiccolo');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri piccoli e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
		if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 20,20) == '_colorenumeropiccolo') {
			if (document.scheda.elements[i].value != '') {
				strAppEl = document.scheda.elements[i].name;
				strAppEl = strAppEl.replace('_colorenumeropiccolo','_numeropiccolo');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri piccoli e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
	}

	if (bContinua) {
		for( i=0; i<len; i++) {
			if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
				if ( document.scheda.elements[i].value != '' ) {
					//alert (document.scheda.elements[i].name);
					//alert (document.scheda.elements[i].value);
					
					if ( eval(document.scheda.elements[i].value) > eval(document.getElementById(document.scheda.elements[i].name.substr(0,document.scheda.elements[i].name.length - 7) + '_quantita').value )){
						alert("Quantità ordinata superiore a quella disponibile");	
						document.scheda.elements[i].select();
						bContinua = false;
						i = len;
					}
				}
			}
		}
	}
		
	if (bContinua) {
		if ( document.getElementById("importo_spese_extra1") != null ){
			if ( document.getElementById("descrizione_spese_extra1").value == "" && document.getElementById("importo_spese_extra1").value != "") {
				alert("E' necessario valorizzare il campo descrizione");
				document.getElementById("descrizione_spese_extra1").focus();
				return(false);
			}	
			if ( document.getElementById("descrizione_spese_extra1").value != "" && document.getElementById("importo_spese_extra1").value == "") {
				alert("E' necessario valorizzare il campo importo");
				document.getElementById("importo_spese_extra1").focus();
				return(false);
			}	
		}	
		if ( document.getElementById("importo_spese_extra2") != null ){
			if ( document.getElementById("descrizione_spese_extra2").value == "" && document.getElementById("importo_spese_extra2").value != "") {
				alert("E' necessario valorizzare il campo descrizione");
				document.getElementById("descrizione_spese_extra2").focus();
				return(false);
			}	
			if ( document.getElementById("descrizione_spese_extra2").value != "" && document.getElementById("importo_spese_extra2").value == "") {
				alert("E' necessario valorizzare il campo importo");
				document.getElementById("importo_spese_extra2").focus();
				return(false);
			}	
		}	
		if ( document.getElementById("importo_spese_extra3") != null ){
			if ( document.getElementById("descrizione_spese_extra3").value == "" && document.getElementById("importo_spese_extra3").value != "") {
				alert("E' necessario valorizzare il campo descrizione");
				document.getElementById("descrizione_spese_extra3").focus();
				return(false);
			}	
			if ( document.getElementById("descrizione_spese_extra3").value != "" && document.getElementById("importo_spese_extra3").value == "") {
				alert("E' necessario valorizzare il campo importo");
				document.getElementById("importo_spese_extra3").focus();
				return(false);
			}	
		}	
	}	
if (bContinua) {
		if ((document.scheda.controllofelpe.value != '')){
				var datagiorno = document.scheda.datagiorno.value;
				var datamese = document.scheda.datamese.value;
				var dataanno = document.scheda.dataanno.value;
				var colorefilogiornomese = document.scheda.colorefilogiornomese.value;
				var colorefilobordoanno = document.scheda.colorefilobordoanno.value;
				var coloreinternoanno = document.scheda.coloreinternoanno.value;
				
				
				if ((datagiorno == "") || (datagiorno == "undefined")) {
		          alert("Il GIORNO della data da ricamare è obbligatorio ");
		          document.scheda.datagiorno.focus();
		          return(false);
		       }
		    if ((datamese == "") || (datamese == "undefined")) {
		          alert("Il MESE della data da ricamare è obbligatorio ");
		          document.scheda.datamese.focus();
		          return(false);
		       }
		    if ((isNaN(dataanno)) ||(dataanno == "") || (dataanno == "undefined")) {
		          alert("L'ANNO della data da ricamare è obbligatorio e deve essere un numero ");
		          document.scheda.dataanno.focus();
		          return(false);
		       }
		    if ((colorefilogiornomese == "") || (colorefilogiornomese == "undefined")) {
		          alert("Seleziona il COLORE FILO GIORNO E MESE");
		          document.scheda.colorefilogiornomese.focus();
		          return(false);
		       }
		     if ((colorefilobordoanno == "") || (colorefilobordoanno == "undefined")) {
		          alert("Seleziona il COLORE FILO BORDO ANNO");
		          document.scheda.colorefilobordoanno.focus();
		          return(false);
		       }
		     if ((coloreinternoanno == "") || (coloreinternoanno == "undefined")) {
		          alert("Seleziona il COLORE INTERNO DELL'ANNO");
		          document.scheda.coloreinternoanno.focus();
		          return(false);
		       }
		   
		}
}

	return(bContinua);
}

function visualizza(){
	
	len = document.scheda.elements.length;
	
	var bVedi = false;
	var confronto = '';
	var precedente = '';
	var somma = 0;
	var sElem = '';
	var valUnitario = 0;
	var sSomma = '';
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_prezzo') {
			document.scheda.elements[i].value = '';
		}
	}

	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
			if (isNaN(document.scheda.elements[i].value) || document.scheda.elements[i].value == ' ' || document.scheda.elements[i].value.indexOf('.') != -1 ){
				document.scheda.elements[i].value = '';
			}
			if (document.scheda.elements[i].value != '') {
				confronto = document.scheda.elements[i].name.substr(0,document.scheda.elements[i].name.indexOf('_',document.scheda.elements[i].name.indexOf('_')+1));
				if (confronto == precedente) {
					sElem = precedente + '_prezzounitario';
					valUnitario = parseFloat(document.getElementById(sElem).value.replace(',','.') ,2);
					somma = somma + ( eval(document.scheda.elements[i].value) * valUnitario);
				} else {
					if (precedente != ''){
						sElem = precedente + '_prezzo';
						sSomma =  Math.round((Math.round(somma*100)/100) * 100);
						if (sSomma != 0) {
							if ( sSomma.toString().length == 1){
								document.getElementById(sElem).value = '0,0' + sSomma.toString();
							} else {
								if ( sSomma.toString().length == 2){
									document.getElementById(sElem).value = '0,' + sSomma.toString();
								} else {
									document.getElementById(sElem).value = sSomma.toString().substr(0,sSomma.toString().length-2)+','+sSomma.toString().substr(sSomma.toString().length-2,sSomma.toString().length);
								}
							}
							bVedi = true;
						}
					}
					sElem = confronto + '_prezzounitario';
					valUnitario = parseFloat(document.getElementById(sElem).value.replace(',','.') ,2);

					somma = eval(document.scheda.elements[i].value) * valUnitario;
					precedente = confronto;
				}
			}
		}
	}
	if (precedente != ''){
		sElem = confronto + '_prezzo';
		sSomma = Math.round((Math.round(somma*100)/100) * 100);
		if (sSomma != 0) {
			if ( sSomma.toString().length == 1){
				document.getElementById(sElem).value = '0,0' + sSomma.toString();
			} else {
				if ( sSomma.toString().length == 2){
					document.getElementById(sElem).value = '0,' + sSomma.toString();
				} else {
					document.getElementById(sElem).value = sSomma.toString().substr(0,sSomma.toString().length-2)+','+sSomma.toString().substr(sSomma.toString().length-2,sSomma.toString().length);
				}
			}
			bVedi = true;
		}
	}
	
	var vuoto = document.getElementById( 'vuoto' );
	var pieno = document.getElementById( 'pieno' );
	var tastofisso = document.getElementById( 'tastofisso' );
	var tastoanimato = document.getElementById( 'tastoanimato' );
	
	if (bVedi == true){
		vuoto.style.display = "none";
		pieno.style.display = "block";
		tastoanimato.style.display = "block";
		tastofisso.style.display = "none";   
	} else {
		vuoto.style.display = "block";
		pieno.style.display = "none";
		tastoanimato.style.display = "none";
		tastofisso.style.display = "block";   
	}
	return(true);
}

function reset_carrello(){
	document.scheda.reset();
	visualizza_carrello();
	visualizzatotspesa();
}

function visualizza_carrello(prima){
	
	len = document.scheda.elements.length;


	bContinua = false;
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
			if ( document.scheda.elements[i].value != '' && eval(document.scheda.elements[i].value) != 0){
				bContinua = true;
				i = len;
			}
		}
	}
	if (bContinua == false){
		riepilogospesa();

		for( i=0; i<len; i++) {
			if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_totale') {
				document.scheda.elements[i].value = '';
			}
		}
	
		return (false);
	}

	var bVedi = false;
	var confronto = '';
	var precedente = '';
	var somma = 0;
	var sElem = '';
	var valUnitario = 0;
	var sSomma = '';
	var sSommaTot = 0;
	var sSpese = 0;
	var sIva = 0;
	var bIva = document.getElementById("h_ivato").value;
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_totale') {
			document.scheda.elements[i].value = '';
		}
	}

	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
			if (isNaN(document.scheda.elements[i].value) || document.scheda.elements[i].value == ' ' || document.scheda.elements[i].value.indexOf('.') != -1 ){
				document.scheda.elements[i].value = '';
			}
			if (document.scheda.elements[i].value != '') {
				confronto = document.scheda.elements[i].name.substr(0,document.scheda.elements[i].name.indexOf('_',document.scheda.elements[i].name.indexOf('_')+1));
				if (confronto == precedente) {
					sElem = precedente + '_prezzounitario';
					valUnitario = parseFloat(document.getElementById(sElem).value.replace(',','.') ,2);
					somma = somma + ( eval(document.scheda.elements[i].value) * valUnitario);
				} else {
					if (precedente != ''){
						sElem = precedente + '_totale';
						sSomma =  Math.round((Math.round(somma*100)/100) * 100);
						sSommaTot = sSommaTot + sSomma;
						if (sSomma != 0) {
							if ( sSomma.toString().length == 1){
								document.getElementById(sElem).value = '0,0' + sSomma.toString();
							} else {
								if ( sSomma.toString().length == 2){
									document.getElementById(sElem).value = '0,' + sSomma.toString();
								} else {
									document.getElementById(sElem).value = sSomma.toString().substr(0,sSomma.toString().length-2)+','+sSomma.toString().substr(sSomma.toString().length-2,sSomma.toString().length);
								}
							}
							bVedi = true;
						}
					}
					sElem = confronto + '_prezzounitario';
					valUnitario = parseFloat(document.getElementById(sElem).value.replace(',','.') ,2);

					somma = eval(document.scheda.elements[i].value) * valUnitario;
					precedente = confronto;
				}
			}
		}
	}
	if (precedente != ''){
		sElem = confronto + '_totale';
		sSomma = Math.round((Math.round(somma*100)/100) * 100);
		sSommaTot = sSommaTot + sSomma;
		if (sSomma != 0) {
			if ( sSomma.toString().length == 1){
				document.getElementById(sElem).value = '0,0' + sSomma.toString();
			} else {
				if ( sSomma.toString().length == 2){
					document.getElementById(sElem).value = '0,' + sSomma.toString();
				} else {
					document.getElementById(sElem).value = sSomma.toString().substr(0,sSomma.toString().length-2)+','+sSomma.toString().substr(sSomma.toString().length-2,sSomma.toString().length);
				}
			}
			bVedi = true;
		}
	}

	if (sSommaTot != 0) {
		if ( sSommaTot.toString().length == 1){
			document.getElementById("totspesa").value = '0,0' + sSommaTot.toString();
		} else {
			if ( sSommaTot.toString().length == 2){
				document.getElementById("totspesa").value = '0,' + sSommaTot.toString();
			} else {
				document.getElementById("totspesa").value = sSommaTot.toString().substr(0,sSommaTot.toString().length-2)+','+sSommaTot.toString().substr(sSommaTot.toString().length-2,sSommaTot.toString().length);
			}
		}
	}

	if (bIva=='False'){
		sIva = Math.round((Math.round(sSommaTot*20)/100));
		
		if (sIva == 0){
			document.getElementById("totiva").value = 0;
		} else {
			if ( sIva.toString().length == 1){
				document.getElementById("totiva").value = '0,0' + sIva.toString();
			} else {
				if ( sIva.toString().length == 2){
					document.getElementById("totiva").value = '0,' + sIva.toString();
				} else {
					document.getElementById("totiva").value = sIva.toString().substr(0,sIva.toString().length-2)+','+sIva.toString().substr(sIva.toString().length-2,sIva.toString().length);
				}
			}
		}
	}
	
	sSommaTot = sSommaTot + sIva;
	
	document.getElementById("totspedizione").value = '0';
	
	if (document.getElementById("spedizione").checked == false) {
		if (sSommaTot <= Number(document.getElementById("h_totale_spese").value)) {
			
			sSpese = Number(document.getElementById("h_spese_spedizione").value);
			sSommaTot = sSommaTot + sSpese;

			if ( sSpese.toString().length == 1){
				document.getElementById("totspedizione").value = '0,0' + sSpese.toString();
			} else {
				if ( sSpese.toString().length == 2){
					document.getElementById("totspedizione").value = '0,' + sSpese.toString();
				} else {
					document.getElementById("totspedizione").value = sSpese.toString().substr(0,sSpese.toString().length-2)+','+sSpese.toString().substr(sSpese.toString().length-2,sSpese.toString().length);
				}
			}
		}
	}
	
	
	var valSpese1 = 0;
	var valSpese2 = 0;
	var valSpese3 = 0;
	if ( document.getElementById("importo_spese_extra1") != null ){
		var strSpese1 = document.getElementById("importo_spese_extra1").value.replace(',','.');
		if ( strSpese1 != "" && strSpese1 != "-"){
			if (isNaN(strSpese1)){
				document.getElementById("importo_spese_extra1").value = "";
			} else {
				valSpese1 = parseFloat(strSpese1, 2) * 100;
			}
		}	
	}	
	if ( document.getElementById("importo_spese_extra2") != null ){
		var strSpese2 = document.getElementById("importo_spese_extra2").value.replace(',','.');
		if ( strSpese2 != "" && strSpese2 != "-"){
			if (isNaN(strSpese2)){
				document.getElementById("importo_spese_extra2").value = "";
			} else {
				valSpese2 = parseFloat(strSpese2, 2) * 100;
			}
		}	
	}	
	if ( document.getElementById("importo_spese_extra3") != null ){
		var strSpese3 = document.getElementById("importo_spese_extra3").value.replace(',','.');
		if ( strSpese3 != "" && strSpese3 != "-"){
			if (isNaN(strSpese3)){
				document.getElementById("importo_spese_extra3").value = "";
			} else {
				valSpese3 = parseFloat(strSpese3, 2) * 100;
			}
		}	
	}	
	
	sSommaTot = sSommaTot + valSpese1 + valSpese2 + valSpese3;
	
	if ( sSommaTot.toString().length == 1){
		document.getElementById("totfornitura").value = '0,0' + sSommaTot.toString();
	} else {
		if ( sSommaTot.toString().length == 2){
			document.getElementById("totfornitura").value = '0,' + sSommaTot.toString();
		} else {
			document.getElementById("totfornitura").value = sSommaTot.toString().substr(0,sSommaTot.toString().length-2)+','+sSommaTot.toString().substr(sSommaTot.toString().length-2,sSommaTot.toString().length);
		}
	}

	if (sSommaTot == 0){
		riepilogospesa();
	} else {
		if (bVedi == true && prima == false){
			riepilogospesa();
		} else {
			visualizzatotspesa();   
		}
	}
	
	acconto();
	
	return(true);
}

function visualizza_cassa(prima){
	
	len = document.scheda.elements.length;
	
	var bVedi = false;
	var confronto = '';
	var precedente = '';
	var somma = 0;
	var sElem = '';
	var valUnitario = 0;
	var sSomma = '';
	var sSommaTot = 0;
	var sSpese = 0;
	var sIva = 0;
	var bIva = document.getElementById("h_ivato").value;
	
	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_totale') {
			document.scheda.elements[i].value = '';
		}
	}

	for( i=0; i<len; i++) {
		if (document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 7,7) == '_valore') {
			if (isNaN(document.scheda.elements[i].value) || document.scheda.elements[i].value == ' ' || document.scheda.elements[i].value.indexOf('.') != -1 ){
				document.scheda.elements[i].value = '';
			}
			if (document.scheda.elements[i].value != '') {
				confronto = document.scheda.elements[i].name.substr(0,document.scheda.elements[i].name.indexOf('_',document.scheda.elements[i].name.indexOf('_')+1));
				if (confronto == precedente) {
					sElem = precedente + '_prezzounitario';
					valUnitario = parseFloat(document.getElementById(sElem).value.replace(',','.') ,2);
					somma = somma + ( eval(document.scheda.elements[i].value) * valUnitario);
				} else {
					if (precedente != ''){
						sElem = precedente + '_totale';
						sSomma =  Math.round((Math.round(somma*100)/100) * 100);
						sSommaTot = sSommaTot + sSomma;
						if (sSomma != 0) {
							if ( sSomma.toString().length == 1){
								document.getElementById(sElem).value = '0,0' + sSomma.toString();
							} else {
								if ( sSomma.toString().length == 2){
									document.getElementById(sElem).value = '0,' + sSomma.toString();
								} else {
									document.getElementById(sElem).value = sSomma.toString().substr(0,sSomma.toString().length-2)+','+sSomma.toString().substr(sSomma.toString().length-2,sSomma.toString().length);
								}
							}
							bVedi = true;
						}
					}
					sElem = confronto + '_prezzounitario';
					valUnitario = parseFloat(document.getElementById(sElem).value.replace(',','.') ,2);

					somma = eval(document.scheda.elements[i].value) * valUnitario;
					precedente = confronto;
				}
			}
		}
	}
	if (precedente != ''){
		sElem = confronto + '_totale';
		sSomma = Math.round((Math.round(somma*100)/100) * 100);
		sSommaTot = sSommaTot + sSomma;
		if (sSomma != 0) {
			if ( sSomma.toString().length == 1){
				document.getElementById(sElem).value = '0,0' + sSomma.toString();
			} else {
				if ( sSomma.toString().length == 2){
					document.getElementById(sElem).value = '0,' + sSomma.toString();
				} else {
					document.getElementById(sElem).value = sSomma.toString().substr(0,sSomma.toString().length-2)+','+sSomma.toString().substr(sSomma.toString().length-2,sSomma.toString().length);
				}
			}
			bVedi = true;
		}
	}

	//applico lo sconto promozione
	if (sSommaTot != 0) {
		if ( document.getElementById('h_sconto_promozione').value != ""){
			
			if (sSommaTot != 0) {
				if ( sSommaTot.toString().length == 1){
					document.getElementById("promozione_spesa_ns").value = '0,0' + sSommaTot.toString();
				} else {
					if ( sSommaTot.toString().length == 2){
						document.getElementById("promozione_spesa_ns").value = '0,' + sSommaTot.toString();
					} else {
						document.getElementById("promozione_spesa_ns").value = sSommaTot.toString().substr(0,sSommaTot.toString().length-2)+','+sSommaTot.toString().substr(sSommaTot.toString().length-2,sSommaTot.toString().length);
					}
				}
			}
			
			valScontoPromozione = parseFloat(document.getElementById('h_sconto_promozione').value.replace(',','.') ,2);
			
			sSommaTot = sSommaTot - (Math.round(sSommaTot*valScontoPromozione/100));
			
		}
	}
	
	if (sSommaTot != 0) {
		if ( sSommaTot.toString().length == 1){
			document.getElementById("totspesa").value = '0,0' + sSommaTot.toString();
		} else {
			if ( sSommaTot.toString().length == 2){
				document.getElementById("totspesa").value = '0,' + sSommaTot.toString();
			} else {
				document.getElementById("totspesa").value = sSommaTot.toString().substr(0,sSommaTot.toString().length-2)+','+sSommaTot.toString().substr(sSommaTot.toString().length-2,sSommaTot.toString().length);
			}
		}
	}

	if (bIva=='False'){
		sIva = Math.round((Math.round(sSommaTot*20)/100));
		
		if (sIva == 0){
			document.getElementById("totiva").value = 0;
		} else {
			if ( sIva.toString().length == 1){
				document.getElementById("totiva").value = '0,0' + sIva.toString();
			} else {
				if ( sIva.toString().length == 2){
					document.getElementById("totiva").value = '0,' + sIva.toString();
				} else {
					document.getElementById("totiva").value = sIva.toString().substr(0,sIva.toString().length-2)+','+sIva.toString().substr(sIva.toString().length-2,sIva.toString().length);
				}
			}
		}
	}
	
	sSommaTot = sSommaTot + sIva;

	document.getElementById("totspedizione").value = '0';
	
	if (document.getElementById("spedizione").value == 'medas') {
		if (sSommaTot <= Number(document.getElementById("h_totale_spese").value)) {
			
			sSpese = Number(document.getElementById("h_spese_spedizione").value);
			sSommaTot = sSommaTot + sSpese;

			if ( sSpese.toString().length == 1){
				document.getElementById("totspedizione").value = '0,0' + sSpese.toString();
			} else {
				if ( sSpese.toString().length == 2){
					document.getElementById("totspedizione").value = '0,' + sSpese.toString();
				} else {
					document.getElementById("totspedizione").value = sSpese.toString().substr(0,sSpese.toString().length-2)+','+sSpese.toString().substr(sSpese.toString().length-2,sSpese.toString().length);
				}
			}
		}
	}
	
	var valSpese1 = 0;
	var valSpese2 = 0;
	var valSpese3 = 0;
	if ( document.getElementById("importo_spese_extra1") != null ){
		var strSpese1 = document.getElementById("importo_spese_extra1").value.replace(',','.');
		if ( strSpese1 != "" && strSpese1 != "-"){
			if (isNaN(strSpese1)){
				document.getElementById("importo_spese_extra1").value = "";
			} else {
				valSpese1 = parseFloat(strSpese1, 2) * 100;
			}
		}	
	}	
	if ( document.getElementById("importo_spese_extra2") != null ){
		var strSpese2 = document.getElementById("importo_spese_extra2").value.replace(',','.');
		if ( strSpese2 != "" && strSpese2 != "-"){
			if (isNaN(strSpese2)){
				document.getElementById("importo_spese_extra2").value = "";
			} else {
				valSpese2 = parseFloat(strSpese2, 2) * 100;
			}
		}	
	}	
	if ( document.getElementById("importo_spese_extra3") != null ){
		var strSpese3 = document.getElementById("importo_spese_extra3").value.replace(',','.');
		if ( strSpese3 != "" && strSpese3 != "-"){
			if (isNaN(strSpese3)){
				document.getElementById("importo_spese_extra3").value = "";
			} else {
				valSpese3 = parseFloat(strSpese3, 2) * 100;
			}
		}	
	}	

	if ( sSommaTot.toString().length == 1){
		document.getElementById("pre_fornitura").value = '0,0' + sSommaTot.toString();
	} else {
		if ( sSommaTot.toString().length == 2){
			document.getElementById("pre_fornitura").value = '0,' + sSommaTot.toString();
		} else {
			document.getElementById("pre_fornitura").value = sSommaTot.toString().substr(0,sSommaTot.toString().length-2)+','+sSommaTot.toString().substr(sSommaTot.toString().length-2,sSommaTot.toString().length);
		}
	}
	
	sSommaTot = sSommaTot + valSpese1 + valSpese2 + valSpese3;
	
	/*recupero eventuale credito*/
	var valACCR = 0;
	var valACCR_USED = 0;
	if ( document.getElementById("tot_accredito") != null ){
		if (document.getElementById("uso_accredito0").checked) {
			var strACCR = document.getElementById("tot_accredito").value.replace(',','.');
			valACCR = Math.round(parseFloat(strACCR, 2) * 100);
			if ( sSommaTot >= valACCR ) {
				valACCR_USED = valACCR;
			} else {
				valACCR_USED = sSommaTot;
			}
			if ( valACCR_USED.toString().length == 1){
				document.getElementById("tot_accredito_utilizzato").value = '0,0' + valACCR_USED.toString();
			} else {
				if ( valACCR_USED.toString().length == 2){
					document.getElementById("tot_accredito_utilizzato").value = '0,' + valACCR_USED.toString();
				} else {
					document.getElementById("tot_accredito_utilizzato").value = valACCR_USED.toString().substr(0,valACCR_USED.toString().length-2)+','+valACCR_USED.toString().substr(valACCR_USED.toString().length-2,valACCR_USED.toString().length);
				}
			}
		}
	}
	sSommaTot = sSommaTot - valACCR;
	if ( sSommaTot < 0 ) {
			sSommaTot = 0;
	}
	/*fine recupero eventuale credito*/
	
	if ( sSommaTot < 30000 ){
		if (document.getElementById("mp_contrassegno") != null){
			document.getElementById("mp_contrassegno").style.visibility = "hidden"; 
			document.getElementById("tr_contrassegno").style.visibility = "hidden";
		}
	}

	if ( sSommaTot.toString().length == 1){
		document.getElementById("totfornitura").value = '0,0' + sSommaTot.toString();
	} else {
		if ( sSommaTot.toString().length == 2){
			document.getElementById("totfornitura").value = '0,' + sSommaTot.toString();
		} else {
			document.getElementById("totfornitura").value = sSommaTot.toString().substr(0,sSommaTot.toString().length-2)+','+sSommaTot.toString().substr(sSommaTot.toString().length-2,sSommaTot.toString().length);
		}
	}
/*
	if (sSommaTot == 0){
		riepilogospesa();
	} else {
		if (bVedi == true && prima == false){
			riepilogospesa();
		} else {
			visualizzatotspesa_cassa();   
		}
	}
*/

	visualizzatotspesa_cassa();
	var divfirmaok = document.getElementById( 'firmaok' );
	var divscarico = document.getElementById( 'ScaricaMagazzino' );

	var trPP = document.getElementById( 'labelPP' );
	var trCS = document.getElementById( 'tr_contrassegno' );

	if (divscarico == null){
		//se null non è in sede
		if ( divfirmaok == null ) {
				var divOrdina = document.getElementById( 'div_ordina' );
				if (sSommaTot == 0){
					divOrdina.style.display = 'block';
					document.getElementById('labelMP').style.display = 'none';
					document.getElementById('mp_sella').checked = false;
					document.getElementById('labelBS').style.display = 'none';
					document.getElementById('mp_carta').checked = false;
					document.getElementById('labelCC').style.display = 'none';
					document.getElementById('mp_bonifico').checked = false;
					document.getElementById('labelBB').style.display = 'none';
					document.getElementById('mp_bollettino').checked = false;
					document.getElementById('labelBP').style.display = 'none';
					document.getElementById('div_carta').style.display = 'none';
					document.getElementById('div_sella').style.display = 'none';
					if ( trPP != null ) {
						document.getElementById('mp_postepay').checked = false;
						trPP.style.display = 'none';
					}
					if ( trCS != null ) {
						document.getElementById('mp_contrassegno').checked = false;
						trCS.style.display = 'none';
					}
				} else {
					divOrdina.style.display = 'none';
					document.getElementById('labelMP').style.display = 'block';
					document.getElementById('labelBS').style.display = 'block';
					document.getElementById('labelCC').style.display = 'block';
					document.getElementById('labelBB').style.display = 'block';
					document.getElementById('labelBP').style.display = 'block';
					if ( trPP != null ) {
						trPP.style.display = 'block';
					}
					if ( trCS != null ) {
						trCS.style.display = 'block';
					}
				}
		} else {
			acconto();
		}
	}

	//document.getElementById("amount").value = document.getElementById("totfornitura").value;
	
	return(true);
}

//MODULO RECUPERA PASSWORD

function ctrlCassa() {
	if ( document.getElementById("documento1") !=  null ) {
		if (document.getElementById("documento1").checked == true ){
			if( document.getElementById("f_ragionesociale").value == "" ){
				alert ("La RAGIONE SOCIALE è obbligatoria");
				document.getElementById("f_ragionesociale").focus();
				return(false);
			}
			if( document.getElementById("f_indirizzo").value == "" ){
				alert ("L'INDIRIZZO è obbligatorio");
				document.getElementById("f_indirizzo").focus();
				return(false);
			}
			if( document.getElementById("f_cap").value == "" ){
				alert ("Il CAP è obbligatorio");
				document.getElementById("f_cap").focus();
				return(false);
			}
			if( document.getElementById("f_citta").value == "" ){
				alert ("La CITTA' è obbligatoria");
				document.getElementById("f_citta").focus();
				return(false);
			}
			if( document.getElementById("f_provincia").value == "" ){
				alert ("La PROVINCIA è obbligatoria");
				document.getElementById("f_provincia").focus();
				return(false);
			}
			if( document.getElementById("f_piva").value == "" ){
				alert ("La PARTITA IVA è obbligatoria");
				document.getElementById("f_piva").focus();
				return(false);
			}
			if( document.getElementById("f_codfiscale").value == "" ){
				alert ("Il CODICE FISCALE è obbligatorio");
				document.getElementById("f_codfiscale").focus();
				return(false);
			}
		}
	}
	
	eliminaCookieNote();
	
	return(true);   
}

function ctrlcampi_recupera() {
     
	var email = document.recuperapassword.email.value;
	 
      var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
             
        if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.recuperapassword.email.select();
           return false;
        }
	    
        //INVIA IL MODULO
        else {
           return true;
        }
  }

//MODULO CONTATTI

function ctrlcampi_contatti() {
	var nome = document.contatti.nome.value;
     var cognome = document.contatti.cognome.value;
     var provincia = document.contatti.provincia.value;
     var email = document.contatti.email.value;
     var telefono = document.contatti.telefono.value;
     var richiesta = document.contatti.richiesta.value;
	 
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
     
        if ((nome == "") || (nome == "undefined")) {
           alert("Il campo Nome è obbligatorio.");
           document.contatti.nome.focus();
           return false;
        }
        
        if ((cognome == "") || (cognome == "undefined")) {
          alert("Il campo Cognome è obbligatorio.");
          document.contatti.cognome.focus();
          return false;
        }
        if ((provincia == "") || (provincia == "undefined")) {
          alert("Il campo Provincia è obbligatorio.");
          document.contatti.provincia.focus();
          return false;
        }
        
        if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.contatti.email.select();
           return false;
        }
        if ((telefono == "") || (telefono == "undefined")) {
          alert("Il campo Telefono è obbligatorio.");
          document.contatti.telefono.focus();
          return false;
        }
        if ((richiesta == "") || (richiesta == "undefined")) {
          alert("Il campo Richiesta è obbligatorio.");
          document.contatti.richiesta.focus();
          return false;
        }
	    if (contatti.accetto.checked == false){
	alert('Impossibile inviare la richiesta\nnon è stata data l\'autorizzazione al trattamento dei dati personali');
	return false;
	}	
        //INVIA IL MODULO
        else {
           return true;
        }
    }


//MODULO PREVENTIVI

function ctrlcampi_preventivi() {
    
	var nome = document.preventivi.nome.value;
     var cognome = document.preventivi.cognome.value;
     var email = document.preventivi.email.value;
	 var telefono = document.preventivi.telefono.value;
	 var richiesta = document.preventivi.richiesta.value;
	 
     
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
     
        
        if ((nome == "") || (nome == "undefined")) {
           alert("Il campo Nome è obbligatorio.");
           document.preventivi.nome.focus();
           return false;
        }
        else if ((cognome == "") || (cognome == "undefined")) {
          alert("Il campo Cognome è obbligatorio.");
          document.preventivi.cognome.focus();
          return false;
        }        
        else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.preventivi.email.select();
           return false;
        }
		 else if ((telefono == "") || (telefono == "undefined")) {
          alert("Il campo Telefono è obbligatorio.");
          document.preventivi.telefono.focus();
          return false;
        }
		 else if ((richiesta == "") || (richiesta == "undefined")) {
          alert("Il campo Richiesta è obbligatorio.");
          document.preventivi.richiesta.focus();
          return false;
        }

	    else if (richiesta.accetto.checked == false){
	alert('Impossibile inviare la richiesta\nnon è stata data l\'autorizzazione al trattamento dei dati personali');
	return false;
	}	
        //INVIA IL MODULO
        else {
           return true;
        }
    }



//MODULO ISCRIZIONE AZIENDA

function ctrlCampiAzienda() {
	
	var ragsoc = document.datiazienda.ragsoc.value;
	var via = document.datiazienda.via.value;
	var civico = document.datiazienda.civico.value;
	var cap = document.datiazienda.cap.value;
	var citta = document.datiazienda.citta.value;
	var provincia = document.datiazienda.provincia.value;
	var piva = document.datiazienda.piva.value;
	var codicefiscale = document.datiazienda.codicefiscale.value;
	var telefono = document.datiazienda.telefono.value;
	var email = document.datiazienda.email.value;
	var email2 = document.datiazienda.email2.value;
	var contatto = document.datiazienda.contatto.value;
	var nomeutente = document.datiazienda.nomeutente.value;
	var password = document.datiazienda.password.value;

     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((ragsoc == "") || (ragsoc == "undefined")) {
           alert("Il campo Ragione Sociale è obbligatorio.");
           document.datiazienda.ragsoc.focus();
           return false;
        }
        else if ((via == "") || (via == "undefined")) {
          alert("Il campo Indirizzo è obbligatorio.");
          document.datiazienda.via.focus();
          return false;
        }
		else if ((civico == "") || (civico == "undefined")) {
          alert("Il campo Numero Civico è obbligatorio.");
          document.datiazienda.civico.focus();
          return false;
        }
		else if ((cap == "") || (cap == "undefined")) {
          alert("Il campo CAP è obbligatorio.");
          document.datiazienda.cap.focus();
          return false;
        }
		else if ((citta == "") || (citta == "undefined")) {
          alert("Il campo Città è obbligatorio.");
          document.datiazienda.citta.focus();
          return false;
        }
		else if ((provincia == "") || (provincia == "undefined")) {
          alert("Il campo Provincia è obbligatorio.");
          document.datiazienda.provincia.focus();
          return false;
        }
		else if ((piva == "") || (piva == "undefined")) {
          alert("Il campo Partita Iva è obbligatorio.");
          document.datiazienda.piva.focus();
          return false;
        }
		else if ((codicefiscale == "") || (codicefiscale == "undefined")) {
          alert("Il campo Codice Fiscale è obbligatorio.");
          document.datiazienda.codicefiscale.focus();
          return false;
        }
		else if ((telefono == "") || (telefono == "undefined")) {
          alert("Il campo Telefono è obbligatorio.");
          document.datiazienda.telefono.focus();
          return false;
        }
		
        else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.datiazienda.email.select();
           return false;
        }
        else if ((email2 == "") || (email2 == "undefined") || (email2 != email)) {
          alert("Il campo Ripeti E-mail è diverso dal campo E-mail");
          document.datiazienda.email2.focus();
          return false;
        }
		else if ((contatto == "") || (contatto == "undefined")) {
          alert("Il campo Persona di riferimento è obbligatorio.");
          document.datiazienda.contatto.focus();
          return false;
        }
		else if ((nomeutente == "") || (nomeutente == "undefined")) {
          alert("Il campo Nome Utente è obbligatorio.");
          document.datiazienda.nomeutente.focus();
          return false;
        }
		else if ((password == "") || (password == "undefined")) {
          alert("Il campo Password è obbligatorio.");
          document.datiazienda.password.focus();
          return false;
        }
		else if (document.datiazienda.accetto.checked == false){
	alert('Impossibile inviare la richiesta di iscrizione\nnon è stata data l\'autorizzazione al trattamento dei dati personali');
	return false;
	}	
	    
        else {
           return true;
        }
  }



//MODULO ISCRIZIONE PRIVATO  
function ctrlCampiPrivato() {
	
	var nome = document.privato.nome.value;
	var cognome = document.privato.cognome.value;
	var via = document.privato.via.value;
	var civico = document.privato.civico.value;
	var cap = document.privato.cap.value;
	var citta = document.privato.citta.value;
	var provincia = document.privato.provincia.value;
	//var codicefiscale = document.privato.codicefiscale.value;
	var telefono = document.privato.telefono.value;
	var email = document.privato.email.value;
	var email2 = document.privato.email2.value;
	var nomeutente = document.privato.nomeutente.value;
	var password = document.privato.password.value;

     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((nome == "") || (nome == "undefined")) {
           alert("Il campo Nome è obbligatorio.");
           document.privato.nome.focus();
           return false;
        }
		else if ((cognome == "") || (cognome == "undefined")) {
          alert("Il campo Cognome è obbligatorio.");
          document.privato.cognome.focus();
          return false;
        }
        else if ((via == "") || (via == "undefined")) {
          alert("Il campo Indirizzo è obbligatorio.");
          document.privato.via.focus();
          return false;
        }
		else if ((civico == "") || (civico == "undefined")) {
          alert("Il campo Numero Civico è obbligatorio.");
          document.privato.civico.focus();
          return false;
        }
		else if ((cap == "") || (cap == "undefined")) {
          alert("Il campo CAP è obbligatorio.");
          document.privato.cap.focus();
          return false;
        }
		else if ((citta == "") || (citta == "undefined")) {
          alert("Il campo Città è obbligatorio.");
          document.privato.citta.focus();
          return false;
        }
		else if ((provincia == "") || (provincia == "undefined")) {
          alert("Il campo Provincia è obbligatorio.");
          document.privato.provincia.focus();
          return false;
        }
	/*	
		else if ((codicefiscale == "") || (codicefiscale == "undefined")) {
          alert("Il campo Codice Fiscale è obbligatorio.");
          document.privato.codicefiscale.focus();
          return false;
        }
        */
		else if ((telefono == "") || (telefono == "undefined")) {
          alert("Il campo Telefono è obbligatorio.");
          document.privato.telefono.focus();
          return false;
        }
		
        else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.privato.email.select();
           return false;
        }
        
        else if ((email2 == "") || (email2 == "undefined") || (email2 != email)) {
          alert("Il campo Ripeti E-mail è diverso dal campo E-mail");
          document.privato.email2.focus();
          return false;
        }
		
		else if ((nomeutente == "") || (nomeutente == "undefined")) {
          alert("Il campo Nome Utente è obbligatorio.");
          document.privato.nomeutente.focus();
          return false;
        }
		else if ((password == "") || (password == "undefined")) {
          alert("Il campo Password è obbligatorio.");
          document.privato.password.focus();
          return false;
        }
		else if (document.privato.accetto.checked == false){
	alert('Impossibile inviare la richiesta di iscrizione\nnon è stata data l\'autorizzazione al trattamento dei dati personali');
	return false;
	}	
	    
        else {
           return true;
        }
  }

//MODULO aggiornamento AZIENDA

function ctrlAggiornamentoAzienda() {
	
	var via = document.aggiornamentoazienda.via.value;
	var civico = document.aggiornamentoazienda.civico.value;
	var cap = document.aggiornamentoazienda.cap.value;
	var citta = document.aggiornamentoazienda.citta.value;
	var provincia = document.aggiornamentoazienda.provincia.value;
	var telefono = document.aggiornamentoazienda.telefono.value;
	var email = document.aggiornamentoazienda.email.value;
	var contatto = document.aggiornamentoazienda.contatto.value;
	var password = document.aggiornamentoazienda.password.value;

     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((via == "") || (via == "undefined")) {
          alert("Il campo Indirizzo è obbligatorio.");
          document.aggiornamentoazienda.via.focus();
          return false;
        }
		else if ((civico == "") || (civico == "undefined")) {
          alert("Il campo Numero Civico è obbligatorio.");
          document.aggiornamentoazienda.civico.focus();
          return false;
        }
		else if ((cap == "") || (cap == "undefined")) {
          alert("Il campo CAP è obbligatorio.");
          document.aggiornamentoazienda.cap.focus();
          return false;
        }
		else if ((citta == "") || (citta == "undefined")) {
          alert("Il campo Città è obbligatorio.");
          document.aggiornamentoazienda.citta.focus();
          return false;
        }
		else if ((provincia == "") || (provincia == "undefined")) {
          alert("Il campo Provincia è obbligatorio.");
          document.aggiornamentoazienda.provincia.focus();
          return false;
        }
		else if ((telefono == "") || (telefono == "undefined")) {
          alert("Il campo Telefono è obbligatorio.");
          document.aggiornamentoazienda.telefono.focus();
          return false;
        }
		
        else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.aggiornamentoazienda.email.select();
           return false;
        }
		else if ((contatto == "") || (contatto == "undefined")) {
          alert("Il campo Persona di riferimento è obbligatorio.");
          document.aggiornamentoazienda.contatto.focus();
          return false;
        }
		else if ((password == "") || (password == "undefined")) {
          alert("Il campo Password è obbligatorio.");
          document.aggiornamentoazienda.password.focus();
          return false;
        }
		else if (aggiornamentoazienda.accetto.checked == false){
	alert('Impossibile inviare la richiesta di iscrizione\nnon è stata data l\'autorizzazione al trattamento dei dati personali');
	return false;
	}	
	    
        else {
           return true;
        }
  }



//MODULO aggiornamento PRIVATO  
function ctrlAggiornamentoPrivato() {
	
	var via = document.aggiornamentoprivato.via.value;
	var civico = document.aggiornamentoprivato.civico.value;
	var cap = document.aggiornamentoprivato.cap.value;
	var citta = document.aggiornamentoprivato.citta.value;
	var provincia = document.aggiornamentoprivato.provincia.value;
	//var codicefiscale = document.aggiornamentoprivato.codicefiscale.value;
	var telefono = document.aggiornamentoprivato.telefono.value;
	var email = document.aggiornamentoprivato.email.value;
	var password = document.aggiornamentoprivato.password.value;

     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((via == "") || (via == "undefined")) {
          alert("Il campo Indirizzo è obbligatorio.");
          document.aggiornamentoprivato.via.focus();
          return false;
        }
		else if ((civico == "") || (civico == "undefined")) {
          alert("Il campo Numero Civico è obbligatorio.");
          document.aggiornamentoprivato.civico.focus();
          return false;
        }
		else if ((cap == "") || (cap == "undefined")) {
          alert("Il campo CAP è obbligatorio.");
          document.aggiornamentoprivato.cap.focus();
          return false;
        }
		else if ((citta == "") || (citta == "undefined")) {
          alert("Il campo Città è obbligatorio.");
          document.aggiornamentoprivato.citta.focus();
          return false;
        }
		else if ((provincia == "") || (provincia == "undefined")) {
          alert("Il campo Provincia è obbligatorio.");
          document.aggiornamentoprivato.provincia.focus();
          return false;
        }
	/*	
		else if ((codicefiscale == "") || (codicefiscale == "undefined")) {
          alert("Il campo Codice Fiscale è obbligatorio.");
          document.privato.codicefiscale.focus();
          return false;
        }
        */
		else if ((telefono == "") || (telefono == "undefined")) {
          alert("Il campo Telefono è obbligatorio.");
          document.aggiornamentoprivato.telefono.focus();
          return false;
        }
		
        else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.aggiornamentoprivato.email.select();
           return false;
        }
		
		else if ((password == "") || (password == "undefined")) {
          alert("Il campo Password è obbligatorio.");
          document.aggiornamentoprivato.password.focus();
          return false;
        }
		else if (aggiornamentoprivato.accetto.checked == false){
	alert('Impossibile inviare la richiesta di iscrizione\nnon è stata data l\'autorizzazione al trattamento dei dati personali');
	return false;
	}	
	    
        else {
           return true;
        }
  }
  
//MODULO INFO PRODOTTO  
function ctrlInfoProdotto() {
	
	var oggetto = document.infoprodotto.oggetto.value;
	var riferimento = document.infoprodotto.riferimento.value;
	var richiesta = document.infoprodotto.richiesta.value;
	
	if ((oggetto == "") || (oggetto == "undefined")) {
           alert("Il campo Oggetto è obbligatorio.");
           document.infoprodotto.oggetto.focus();
           return false;
        }
        if ((riferimento == "") || (riferimento == "undefined")) {
           alert("Il campo Riferimento Ordine è obbligatorio.\n\nSe è una richiesta generica scrivere NESSUNO");
           document.infoprodotto.riferimento.focus();
           return false;
        }
	if ((richiesta == "") || (richiesta == "undefined")) {
           alert("Il campo Richiesta è obbligatorio.");
           document.infoprodotto.richiesta.focus();
           return false;
        }       
	    
        else {
           return true;
        }
  }



function finestra (title,w,h)
   {
   Fin=open('','','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,screenX=300,screenY=200,width='+w+',height='+h+'');
   Fin.document.open();
   Fin.document.write("<HTML><HEAD><title>");
   Fin.document.write(title);
   Fin.document.write("</title></HEAD><BODY style='margin-top: 0px; margin-left: 0px'>");
   Fin.document.write("<a href='javascript:window.close()'>");
   Fin.document.write("<img src=\""+ImgGrande_src+"\" style='border: 0px'>");
   Fin.document.write("</a>");
   Fin.document.write("</BODY></HTML>");
   Fin.document.close();
   }
   

function riepilogospesa()
{
	var spesa = document.getElementById( 'totalespesa' );
	spesa.style.display = 'none';
	
	var spesa = document.getElementById( 'gestiscicarrello' );
	spesa.style.display = 'block';

	document.scheda.action = "aggiorna_carrello.asp";
}


function visualizzatotspesa()
{
	var spesa = document.getElementById( 'totalespesa' );
	spesa.style.display = 'block';
	
	var spesa = document.getElementById( 'gestiscicarrello' );
	spesa.style.display = 'none';

	document.scheda.action = "cassa.asp";
}

function visualizzatotspesa_cassa()
{
	var spesa = document.getElementById( 'totalespesa' );
	spesa.style.display = 'block';
	
	var spesa = document.getElementById( 'gestiscicarrello' );
	spesa.style.display = 'none';
}

function visualizza_fattura(id)
{
	var dati = document.getElementById( 'datifattura' );
	dati.style.display = 'block';

}

function nascondi_fattura(id)
{
	var dati = document.getElementById( 'datifattura' );
	dati.style.display = 'none';

}

function cambiaModoPagamento(strModPag)
{	
	var divCarta = document.getElementById( 'div_carta' );
	var divSella = document.getElementById( 'div_sella' );
	var divOrdina = document.getElementById( 'div_ordina' );

	if (strModPag == "cartacredito"){
		divCarta.style.display = 'block';
		divSella.style.display = 'none';
		divOrdina.style.display = 'none';
	} else {
		if (strModPag == "bancasella"){
			divSella.style.display = 'block';
			divCarta.style.display = 'none';
			divOrdina.style.display = 'none';
		} else {
			divOrdina.style.display = 'block';
			divCarta.style.display = 'none';
			divSella.style.display = 'none';
		}
	}

}

function acconto(val){
	
	if (document.getElementById("accontofornitura")==null){
		return(false);
	}

	var strAcconto = document.getElementById("accontofornitura").value.replace(',','.');
	if ( strAcconto == "" ){
		document.getElementById("saldofornitura").value = document.getElementById("totfornitura").value;
	} else {
		if (isNaN(strAcconto)){
			document.getElementById("accontofornitura").value = "";
			document.getElementById("saldofornitura").value = document.getElementById("totfornitura").value;
		} else {
			var valTotale = parseFloat(document.getElementById("totfornitura").value.replace(',','.'), 2);
			var valAcconto = parseFloat(strAcconto, 2);
			var valDifferenza = valTotale - valAcconto;

			valDifferenza = Math.round((Math.round(valDifferenza*100)/100) * 100);

			var strSegno = "";
			if (valDifferenza < 0){
				valDifferenza = valDifferenza * -1;
				strSegno = "- ";
			}
			
			if (valDifferenza != 0){
				if ( valDifferenza.toString().length == 1){
					document.getElementById("saldofornitura").value = strSegno + '0,0' + valDifferenza.toString();
				} else {
					if ( valDifferenza.toString().length == 2){
						document.getElementById("saldofornitura").value = strSegno + '0,' + valDifferenza.toString();
					} else {
						document.getElementById("saldofornitura").value = strSegno + valDifferenza.toString().substr(0,valDifferenza.toString().length-2)+','+valDifferenza.toString().substr(valDifferenza.toString().length-2,valDifferenza.toString().length);
					}
				}
			} else {
				document.getElementById("saldofornitura").value = "0";
			}			
		}
	}
}


function richiestaPreventivo(){ 
        if(confirm("E' stato richiesto l'invio del preventivo." + "\n" + "Tale richiesta non da origine ad un ordine effettivo" + "\n" + "Confermare l'operazione?")){
		creaCookieVerifica();
                scheda.submit(); 
        } 
}

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

function creaCookieVerifica(){
	var todayDate = largeExpDate = new Date ();
	largeExpDate.setTime(todayDate.getTime() + 1 * 24 * 3600 * 1000);
	document.cookie = 'cookie_verifica'+'='+'ok'+'; expires=' + largeExpDate.toGMTString();
}

function creaCookieNoteOrdine(){
	var re = new RegExp(" ", "g");
	var re_crlf = new RegExp("\n", "g");

	var valore = document.getElementById("noteordine").value;

	valore = valore.replace(re, "<nbsp></nbsp>");
	
	if(window.event){	//IE
		valore = valore.replace(/\r\n/g, "<crlf></crlf>");
	} else {		//NON IE
		valore = valore.replace(re_crlf, "<crlf></crlf>");
	}

	var todayDate = largeExpDate = new Date ();
	largeExpDate.setTime(todayDate.getTime() + 1 * 24 * 3600 * 1000);
	document.cookie = 'cookie_noteordine'+'='+valore+'; expires=' + largeExpDate.toGMTString();
}

function creaCookieNoteSpedizione(){

	var re = new RegExp(" ", "g");
	var re_crlf = new RegExp("\n", "g");

	var valore = document.getElementById("richiesta").value;

	valore = valore.replace(re, "<nbsp></nbsp>");
	
	if(window.event){	//IE
		valore = valore.replace(/\r\n/g, "<crlf></crlf>");
	} else {		//NON IE
		valore = valore.replace(re_crlf, "<crlf></crlf>");
	}
		
	var todayDate = largeExpDate = new Date ();
	largeExpDate.setTime(todayDate.getTime() + 1 * 24 * 3600 * 1000);
	document.cookie = 'cookie_notespedizione'+'='+valore+'; expires=' + largeExpDate.toGMTString();
}

function creaCookieExtraDZ(numExtra){

	var re = new RegExp(" ", "g");
	var re_crlf = new RegExp("\n", "g");

	var valore = document.getElementById("spese_extra"+numExtra).value;

	valore = valore.replace(re, "<nbsp></nbsp>");
	
	if(window.event){	//IE
		valore = valore.replace(/\r\n/g, "<crlf></crlf>");
	} else {		//NON IE
		valore = valore.replace(re_crlf, "<crlf></crlf>");
	}
		
	var todayDate = largeExpDate = new Date ();
	largeExpDate.setTime(todayDate.getTime() + 1 * 24 * 3600 * 1000);
	document.cookie = 'cookie_extradz'+numExtra+'='+valore+'; expires=' + largeExpDate.toGMTString();
}

function creaCookieExtraIMP(numExtra){

	var re = new RegExp(" ", "g");
	var re_crlf = new RegExp("\n", "g");

	var valore = document.getElementById("importo_spese_extra"+numExtra).value;

	valore = valore.replace(re, "<nbsp></nbsp>");
	
	if(window.event){	//IE
		valore = valore.replace(/\r\n/g, "<crlf></crlf>");
	} else {		//NON IE
		valore = valore.replace(re_crlf, "<crlf></crlf>");
	}
		
	var todayDate = largeExpDate = new Date ();
	largeExpDate.setTime(todayDate.getTime() + 1 * 24 * 3600 * 1000);
	document.cookie = 'cookie_extraimp'+numExtra+'='+valore+'; expires=' + largeExpDate.toGMTString();
}

function eliminaCookieNote(){
	document.cookie = 'cookie_noteordine'+'='+'';
	document.cookie = 'cookie_notespedizione'+'='+'';
	document.cookie = 'cookie_extradz1'+'='+'';
	document.cookie = 'cookie_extraimp1'+'='+'';
	document.cookie = 'cookie_extradz2'+'='+'';
	document.cookie = 'cookie_extraimp2'+'='+'';
	document.cookie = 'cookie_extradz3'+'='+'';
	document.cookie = 'cookie_extraimp3'+'='+'';
}

function pulsanti_ordine_sede(){
	if (document.getElementById("registra_ordine").checked==true){
		document.getElementById("invia").disabled=true;
		document.getElementById("scarica").disabled=true;
	} else {
		document.getElementById("invia").disabled=false;
		document.getElementById("scarica").disabled=false;
	}
}

function scarico_sede(){
		document.getElementById("scarico_insede").value="SI";
}

function stampa_scarico(){
		document.getElementById('firmascarico').style.display = "none";
		document.getElementById('datiscarico').style.display = "none";
}

function cambiacolore(nomecampo){
	if (valueNome != ''){
			if (nomecampo.substr(nomecampo.length - 5,5) == '_nome') {
					document.getElementById(nomecampo).style.color = colorNome;
					document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_nome') + 1) +'colorenome').value = valueNome;
			}
	}
	if (valueNGrande != ''){
			if (nomecampo.substr(nomecampo.length - 13,13) == '_numerogrande') {
					document.getElementById(nomecampo).style.color = colorNGrande;
					document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_numerogrande') + 1) +'colorenumerogrande').value = valueNGrande;
			}
	}
	if (valueNPiccolo != ''){
			if (nomecampo.substr(nomecampo.length - 14,14) == '_numeropiccolo') {
					document.getElementById(nomecampo).style.color = colorNPiccolo;
					document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_numeropiccolo') + 1) +'colorenumeropiccolo').value = valueNPiccolo;
			}
	}
}

function impostacolore(nomecampo){
	
	//var len = document.scheda.elements.length;
	var strAppColore = "";
	//var bNome = true;
	//var bNGrandi = true;
	//var bNPiccoli = true;

	if (nomecampo.substr(nomecampo.length - 11,11) == '_colorenome') {
			strAppColore = document.getElementById(nomecampo).value;
			//arColore = nomecampo.split('_');
			arValoreColore = strAppColore.split('_');
			
			if (strAppColore != ""){
				document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_colorenome') + 1) +'nome').style.color = arValoreColore[2];
				colorNome = arValoreColore[2];
				valueNome = strAppColore;
			} else {
				colorNome = dcolorNome;
				document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_colorenome') + 1) +'nome').style.color = colorNome;
				valueNome = "";
			}
	}
	if (nomecampo.substr(nomecampo.length - 19,19) == '_colorenumerogrande') {
			strAppColore = document.getElementById(nomecampo).value;
			//arColore = nomecampo.split('_');
			arValoreColore = strAppColore.split('_');
			
			if (strAppColore != ""){
				document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_colorenumerogrande') + 1) +'numerogrande').style.color = arValoreColore[2];
				colorNGrande = arValoreColore[2];
				valueNGrande = strAppColore;
			} else {
				colorNGrande = dcolorNGrande;
				document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_colorenumerogrande') + 1) +'numerogrande').style.color = colorNGrande;
				valueNGrande = "";
			}
	}
	if (nomecampo.substr(nomecampo.length - 20,20) == '_colorenumeropiccolo') {
			strAppColore = document.getElementById(nomecampo).value;
			//arColore = nomecampo.split('_');
			arValoreColore = strAppColore.split('_');
			
			if (strAppColore != ""){
				document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_colorenumeropiccolo') + 1) +'numeropiccolo').style.color = arValoreColore[2];
				colorNPiccolo = arValoreColore[2];
				valueNPiccolo = strAppColore;
			} else {
				colorNPiccolo = dcolorNPiccolo;
				document.getElementById(nomecampo.substr(0, nomecampo.indexOf('_colorenumeropiccolo') + 1) +'numeropiccolo').style.color = colorNPiccolo;
				valueNPiccolo = "";
			}
	}
		
			/*
			for( i=0; i<len; i++) {
				if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 11,11) == '_colorenome') {
					arColoreElemento = document.scheda.elements[i].name.split('_');
					bNome = true;
					if (arColore[2] == arColoreElemento[2] && arColore[3] == arColoreElemento[3] && arColore[4] == arColoreElemento[4]){
						if (arColore[1] != arColoreElemento[1]){
							if (document.scheda.elements[i].value != ''){
								bNome = false;
							}
						}
					}
				}
			}
			*/
	

/*
	if (nomecampo.substr(nomecampo.length - 11,11) == '_colorenome') {
			strAppColore = document.getElementById(nomecampo).value;
			arColore = nomecampo.split('_');

			if (strAppColore != ""){
				for( i=0; i<len; i++) {
					if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 11,11) == '_colorenome') {
						arColoreElemento = document.scheda.elements[i].name.split('_');
						bNome = true;
						if (arColore[2] == arColoreElemento[2] && arColore[3] == arColoreElemento[3] && arColore[4] == arColoreElemento[4]){
							if (arColore[1] != arColoreElemento[1]){
								if (document.scheda.elements[i].value != ''){
									bNome = false;
								}
							}
						}
					}
				}
				if (bNome == true){
					for( i=0; i<len; i++) {
						if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 11,11) == '_colorenome') {
							arColoreElemento = document.scheda.elements[i].name.split('_');
							if (arColore[2] == arColoreElemento[2] && arColore[3] == arColoreElemento[3] && arColore[4] == arColoreElemento[4]){
								if (arColore[1] != arColoreElemento[1]){
									document.scheda.elements[i].value = strAppColore;
								}
							}
						}
					}
				}
			}
	}	
	strAppColore = "";
	if (nomecampo.substr(nomecampo.length - 19,19) == '_colorenumerogrande') {
			strAppColore = document.getElementById(nomecampo).value;
			arColore = nomecampo.split('_');

			if (strAppColore != ""){
				for( i=0; i<len; i++) {
					if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 19,19) == '_colorenumerogrande') {
						arColoreElemento = document.scheda.elements[i].name.split('_');
						bNGrandi = true;
						if (arColore[2] == arColoreElemento[2] && arColore[3] == arColoreElemento[3] && arColore[4] == arColoreElemento[4]){
							if (arColore[1] != arColoreElemento[1]){
								if (document.scheda.elements[i].value != ''){
									bNGrandi = false;
								}
							}
						}
					}
				}
				if (bNGrandi == true){
					for( i=0; i<len; i++) {
						if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 19,19) == '_colorenumerogrande') {
							arColoreElemento = document.scheda.elements[i].name.split('_');
							if (arColore[2] == arColoreElemento[2] && arColore[3] == arColoreElemento[3] && arColore[4] == arColoreElemento[4]){
								if (arColore[1] != arColoreElemento[1]){
									document.scheda.elements[i].value = strAppColore;
								}
							}
						}
					}
				}
			}
	}	
	strAppColore = "";
	if (nomecampo.substr(nomecampo.length - 20,20) == '_colorenumeropiccolo') {
			strAppColore = document.getElementById(nomecampo).value;
			arColore = nomecampo.split('_');

			if (strAppColore != ""){
				for( i=0; i<len; i++) {
					if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 20,20) == '_colorenumeropiccolo') {
						arColoreElemento = document.scheda.elements[i].name.split('_');
						bNPiccoli = true;
						if (arColore[2] == arColoreElemento[2] && arColore[3] == arColoreElemento[3] && arColore[4] == arColoreElemento[4]){
							if (arColore[1] != arColoreElemento[1]){
								if (document.scheda.elements[i].value != ''){
									bNPiccoli = false;
								}
							}
						}
					}
				}
				if (bNPiccoli == true){
					for( i=0; i<len; i++) {
						if (document.scheda.elements[i].name.substr(0, 3) == 'ms_' && document.scheda.elements[i].name.substr(document.scheda.elements[i].name.length - 20,20) == '_colorenumeropiccolo') {
							arColoreElemento = document.scheda.elements[i].name.split('_');
							if (arColore[2] == arColoreElemento[2] && arColore[3] == arColoreElemento[3] && arColore[4] == arColoreElemento[4]){
								if (arColore[1] != arColoreElemento[1]){
									document.scheda.elements[i].value = strAppColore;
								}
							}
						}
					}
				}
			}
	}	
*/
}
function ctrl_ordine_dettaglio(){
	var contaNomi = 0;
	var contaNGrandi = 0;
	var contaNPiccoli = 0;
	var bNGprocedi = false;
	var bNPprocedi = false;
	
	len = document.dettaglio_ordine.elements.length;

	/*
	alert(document.getElementById("pSupporti").value);	
	alert(document.getElementById("pNomi").value);	
	alert(document.getElementById("pGrande").value);	
	alert(document.getElementById("pPiccolo").value);	
	*/


	//controllo se ci sono duplicazioni tra i numeri grandi
	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 13,13) == '_numerogrande') {
			if(!bNGprocedi){
				arColoreElementoI = document.dettaglio_ordine.elements[i].name.split('_');
				
				if (document.dettaglio_ordine.elements[i].value != "") {
						for( y=0; y<len; y++) {
							if(!bNGprocedi){
								if (document.dettaglio_ordine.elements[y].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[y].name.substr(document.dettaglio_ordine.elements[y].name.length - 13,13) == '_numerogrande') {
										if (document.dettaglio_ordine.elements[i].name != document.dettaglio_ordine.elements[y].name) {
												arColoreElementoY = document.dettaglio_ordine.elements[y].name.split('_');
												
												if (arColoreElementoI[2] == arColoreElementoY[2] && arColoreElementoI[3] == arColoreElementoY[3] && arColoreElementoI[4] == arColoreElementoY[4]){
														if (document.dettaglio_ordine.elements[i].value == document.dettaglio_ordine.elements[y].value) {
																if (!(confirm("Ci sono due o più numeri grandi uguali. Vuoi procedere comunque?"))){
																		document.dettaglio_ordine.elements[y].focus();
																		return(false);
																} else {
																		bNGprocedi = true;
																}
														}
												}
										}
								}
							}
						}
				}			
			}
		}
	}

	//controllo se ci sono duplicazioni tra i numeri piccoli
	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 14,14) == '_numeropiccolo') {
			if(!bNPprocedi){
				arColoreElementoI = document.dettaglio_ordine.elements[i].name.split('_');
				
				if (document.dettaglio_ordine.elements[i].value != "") {
						for( y=0; y<len; y++) {
							if(!bNPprocedi){
								if (document.dettaglio_ordine.elements[y].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[y].name.substr(document.dettaglio_ordine.elements[y].name.length - 14,14) == '_numeropiccolo') {
										if (document.dettaglio_ordine.elements[i].name != document.dettaglio_ordine.elements[y].name) {
												arColoreElementoY = document.dettaglio_ordine.elements[y].name.split('_');
												
												if (arColoreElementoI[2] == arColoreElementoY[2] && arColoreElementoI[3] == arColoreElementoY[3] && arColoreElementoI[4] == arColoreElementoY[4]){
														if (document.dettaglio_ordine.elements[i].value == document.dettaglio_ordine.elements[y].value) {
																if (!(confirm("Ci sono due o più numeri piccoli uguali. Vuoi procedere comunque?"))){
																		document.dettaglio_ordine.elements[y].focus();
																		return(false);
																} else {
																		bNPprocedi = true;
																}
														}
												}
										}
								}
							}
						}
				}			
			}
		}
	}
	
	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 5,5) == '_nome') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				contaNomi = contaNomi + 1;
			}
		}
	}
	if (contaNomi > eval(document.getElementById("pNomi").value)){
				alert("Sono stati indicati più nomi rispetto a quelli acquistati");	
				return(false);
	}

	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 13,13) == '_numerogrande') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				contaNGrandi = contaNGrandi + 1;
			}
		}
	}
	if (contaNGrandi > eval(document.getElementById("pGrande").value)){
				alert("Sono stati indicati più numeri grandi rispetto a quelli acquistati");	
				return(false);
	}
	
	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 14,14) == '_numeropiccolo') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				contaNPiccoli = contaNPiccoli + 1;
			}
		}
	}
	if (contaNPiccoli > eval(document.getElementById("pPiccolo").value)){
				alert("Sono stati indicati più numeri piccoli rispetto a quelli acquistati");	
				return(false);
	}

	var strAppEl = "";
	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 5,5) == '_nome') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				strAppEl = document.dettaglio_ordine.elements[i].name;
				strAppEl = strAppEl.replace('_nome','_colorenome');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i nomi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 11,11) == '_colorenome') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				strAppEl = document.dettaglio_ordine.elements[i].name;
				strAppEl = strAppEl.replace('_colorenome','_nome');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i nomi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
	}
	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 13,13) == '_numerogrande') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				strAppEl = document.dettaglio_ordine.elements[i].name;
				strAppEl = strAppEl.replace('_numerogrande','_colorenumerogrande');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri grandi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 19,19) == '_colorenumerogrande') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				strAppEl = document.dettaglio_ordine.elements[i].name;
				strAppEl = strAppEl.replace('_colorenumerogrande','_numerogrande');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri grandi e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
	}
	for( i=0; i<len; i++) {
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 14,14) == '_numeropiccolo') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				strAppEl = document.dettaglio_ordine.elements[i].name;
				strAppEl = strAppEl.replace('_numeropiccolo','_colorenumeropiccolo');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri piccoli e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
		if (document.dettaglio_ordine.elements[i].name.substr(0, 3) == 'ms_' && document.dettaglio_ordine.elements[i].name.substr(document.dettaglio_ordine.elements[i].name.length - 20,20) == '_colorenumeropiccolo') {
			if (document.dettaglio_ordine.elements[i].value != '') {
				strAppEl = document.dettaglio_ordine.elements[i].name;
				strAppEl = strAppEl.replace('_colorenumeropiccolo','_numeropiccolo');
				if (document.getElementById(strAppEl).value == '') {
					alert("Non sono stati valorizzati correttamente i numeri piccoli e i colori");
					document.getElementById(strAppEl).focus();
					return(false);
				}
			}
		}
	}
	return(true);
}

