var sfondoColore1 = false;
var sfondoColore3 = false;
var sfondoColore4 = false;
var sfondoColore8 = false;
var errore = false;

function controllaDati(messaggio){
	sfondoColore1 = false;
	sfondoColore3 = false;
	sfondoColore4 = false;
	sfondoColore8 = false;
	errore = false;
	var ogg1 = document.getElementById('i4');
	var ogg2 = document.getElementById('i5');
	var ogg3 = document.getElementById('s1');
	var ogg4 = document.getElementById('s2');
	var ogg5 = document.getElementById('pd2');
	var ogg6 = document.getElementById('pd3');
	var ogg7 = document.getElementById('pd4');
	var ogg8 = document.getElementById('d1'); 
	var titolo1 = document.getElementById('td1');
	var titolo2 = document.getElementById('td3');
	var titolo3 = document.getElementById('td4');
	var titolo4 = document.getElementById('td8');
	if (ogg1.value == ''){
		titolo1.style.background = 'red';
		var divevidenzia1 = document.getElementById('divEvidenzia' + ogg1.name)
		divevidenzia1.style.color = 'red';
		sfondoColore1 = true;
		errore = true;
	}else{
		titolo1.style.background = '';
		var divevidenzia1 = document.getElementById('divEvidenzia' + ogg1.name)
		divevidenzia1.style.color = '';
	}
	if (ogg2.value == ''){
		titolo1.style.background = 'red';
		var divevidenzia2 = document.getElementById('divEvidenzia' + ogg2.name)
		divevidenzia2.style.color = 'red';
		sfondoColore1 = true;
		errore = true;
	}else{
		titolo1.style.background = '';
		var divevidenzia2 = document.getElementById('divEvidenzia' + ogg2.name)
		divevidenzia2.style.color = '';
	}
	if (ogg3.value == ''){
		titolo2.style.background = 'red';
		var divevidenzia3 = document.getElementById('divEvidenzia' + ogg3.name)
		divevidenzia3.style.color = 'red';
		sfondoColore3 = true;
		errore = true;
	}else{
		titolo2.style.background = '';
		var divevidenzia3 = document.getElementById('divEvidenzia' + ogg3.name)
		divevidenzia3.style.color = '';
	}
	if (ogg4.value == ''){
		titolo2.style.background = 'red';
		var divevidenzia4 = document.getElementById('divEvidenzia' + ogg4.name)
		divevidenzia4.style.color = 'red';
		sfondoColore3 = true;
		errore = true;
	}else{
		titolo2.style.background = '';
		var divevidenzia4 = document.getElementById('divEvidenzia' + ogg4.name)
		divevidenzia4.style.color = '';
	}
	if (ogg5.value == ''){
		titolo3.style.background = 'red';
		var divevidenzia5 = document.getElementById('divEvidenzia' + ogg5.name)
		divevidenzia5.style.color = 'red';
		sfondoColore4 = true;
		errore = true;
	}else{
		titolo3.style.background = '';
		var divevidenzia5 = document.getElementById('divEvidenzia' + ogg5.name)
		divevidenzia5.style.color = '';
	}
	if (ogg6.value == ''){
		titolo3.style.background = 'red';
		var divevidenzia6 = document.getElementById('divEvidenzia' + ogg6.name)
		divevidenzia6.style.color = 'red';
		sfondoColore4 = true;
		errore = true;
	}else{
		titolo3.style.background = '';
		var divevidenzia6 = document.getElementById('divEvidenzia' + ogg6.name)
		divevidenzia6.style.color = '';
	}
	if (ogg7.value == ''){
		titolo3.style.background = 'red';
		var divevidenzia7 = document.getElementById('divEvidenzia' + ogg7.name)
		divevidenzia7.style.color = 'red';
		sfondoColore4 = true;
		errore = true;
	}else{
		titolo3.style.background = '';
		var divevidenzia7 = document.getElementById('divEvidenzia' + ogg7.name)
		divevidenzia7.style.color = '';
	}
	if (ogg8.value == ''){
		titolo4.style.background = 'red';
		var divevidenzia8 = document.getElementById('divEvidenzia' + ogg8.name)
		divevidenzia8.style.color = 'red';
		sfondoColore8 = true;
		errore = true;
	}else{
		titolo4.style.background = '';
		var divevidenzia8 = document.getElementById('divEvidenzia' + ogg8.name)
		divevidenzia8.style.color = '';
	}
	apriDiv(1);
	if (messaggio){
		if (errore){
			alert('Controllo completato. \n I campi segnalati in rosso devono essere compilati.');
		}else{
			alert('Controllo completato. \n I dati sono stati inseriti correttamente.');
		}
	}
}

function salvaDati(){
	controllaDati(false);
	if(errore){
		alert('I campi segnalati in rosso devono essere compilati.');
	}else{
		var oggFrm = document.getElementById('pAggiungi');
		var ogg = document.getElementById('idpag');
		//oggFrm.action = 'paggiungi_2.asp?idpag=' + ogg.value;
		oggFrm.action = 'paggiungi_2.asp';
		oggFrm.submit();
	}
}

