function aprifinestra(URL, nome) {

	var indiceFinestra=window.open(URL, nome, 'width=400px,height=300px,resizable=yes');

	indiceFinestra.focus();

}

function Attenzione() {
	return confirm("Confermi la cancellazione?");
}

function controlloBuste() {

	oDim11=document.getElementById('dimensione1');
	oDim33=document.getElementById('dimensione2');
	oDim3=document.getElementById('dimensione3');


	oColore1=document.getElementById('colore1');
	oColore4=document.getElementById('colore4');

	oFinestra1=document.getElementById('finestra1');
	oFinestra2=document.getElementById('finestra2');

	oQuantita500=document.getElementById('quantita500');
	oQuantita1000=document.getElementById('quantita1000');
	oQuantita2000=document.getElementById('quantita2000');
	oQuantita3000=document.getElementById('quantita3000');
	oQuantita4000=document.getElementById('quantita4000');

	if (!oDim33.checked && !oDim11.checked && !oDim3.checked) {
		alert ("Scegli la dimensione delle buste");
		return false;
	}

	if (!oColore1.checked && !oColore4.checked) {
		alert ("Scegli il colore della stampa");
		return false;
	}

	if (!oFinestra1.checked && !oFinestra2.checked) {
		alert ("Scegli se la busta deve avere la finestra o no");
		return false;
	}

	if (!oQuantita500.checked && !oQuantita1000.checked && !oQuantita2000.checked && !oQuantita3000.checked && !oQuantita4000.checked) {
		alert ("Scegli la quantità di buste da stampare");
		return false;
	}

	return true;
}

function selBusteDimensioni() {

	oDim11=document.getElementById('dimensione1');
	oDim33=document.getElementById('dimensione2');
	oDim3=document.getElementById('dimensione3');
	oFinestra1=document.getElementById('finestra1');
	oFinestra2=document.getElementById('finestra2');
	oColore1=document.getElementById('colore1');

	if (oDim33.checked) {
		oFinestra2.checked=false;
		oFinestra2.disabled=true;
		oFinestra1.checked=true;
		alert ("Le buste 23x33 non hanno la finestra.");

	}

	if (oDim3.checked) {
		oFinestra2.checked=false;
		oFinestra2.disabled=true;
		oFinestra1.checked=true;
		alert ("Le buste 16x23 non hanno la finestra.");

	}

	if (oDim11.checked  && !oColore1.checked) {
		oFinestra2.disabled=false;
	}

	return;
}

function selBusteColori() {

	oColore1=document.getElementById('colore1');
	oColore4=document.getElementById('colore4');
	oDim33=document.getElementById('dimensione2');
	oDim3=document.getElementById('dimensione3');
	oFinestra1=document.getElementById('finestra1');
	oFinestra2=document.getElementById('finestra2');

	if (oColore1.checked) {
		oFinestra2.checked=false;
		oFinestra2.disabled=true;
		oFinestra1.checked=true;
		alert ("La stampa a 1 colore è solo per le buste senza finestra.");

	}

	if (oColore4.checked && !oDim33.checked && !oDim3.checked) {
		oFinestra2.disabled=false;
	}

	return;
}


function controlloCartaIntestata() {

	oColore1=document.getElementById('colore1');
	oColore4=document.getElementById('colore4');

	oQuantita1000=document.getElementById('quantita1000');
	oQuantita2000=document.getElementById('quantita2000');
	oQuantita3000=document.getElementById('quantita3000');
	oQuantita4000=document.getElementById('quantita4000');

	if (!oColore1.checked && !oColore4.checked) {
		alert ("Scegli il colore della stampa");
		return false;
	}

	if (!oQuantita1000.checked && !oQuantita2000.checked && !oQuantita3000.checked && !oQuantita4000.checked) {
		alert ("Scegli la quantità da stampare");
		return false;
	}

	return true;
}

function selVolantiniDimensioni() {

	oA4=document.getElementById('dimensione1');
	oA3=document.getElementById('dimensione2');
	oA5=document.getElementById('dimensione3');
	o105=document.getElementById('dimensione4');

	oElabSingola=document.getElementById('elaborazione1');
	oElab2Falde=document.getElementById('elaborazione2');
	oElab3Falde=document.getElementById('elaborazione3');
	oElab3Soffietto=document.getElementById('elaborazione4');

	oQuantita50=document.getElementById('quantita50');
	oQuantita100=document.getElementById('quantita100');
	oQuantita200=document.getElementById('quantita200');
	oQuantita500=document.getElementById('quantita500');
	oQuantita1000=document.getElementById('quantita1000');


	if (oA5.checked) {

		oElab2Falde.disabled=false;

		oElab3Falde.checked=false;
		oElab3Falde.disabled=true;

		oElab3Soffietto.checked=false;
		oElab3Soffietto.disabled=true;

		alert ("A5 elaborazioni compatibili: pagina singola e 2 falde.");

	}

	if (o105.checked) {

		oElab2Falde.checked=false;
		oElab2Falde.disabled=true;

		oElab3Falde.checked=false;
		oElab3Falde.disabled=true;

		oElab3Soffietto.checked=false;
		oElab3Soffietto.disabled=true;

		alert ("105 x 210 mm elaborazioni compatibili: pagina singola.");

	}

	if (oA4.checked || oA3.checked) {
		oElab2Falde.disabled=false;
		oElab3Falde.disabled=false;
		oElab3Soffietto.disabled=false;

	}

	return;
}

function selVolantiniGrammatura() {

	oGr70=document.getElementById('cartaGrammatura1');
	oGr80=document.getElementById('cartaGrammatura2');
	oGr100=document.getElementById('cartaGrammatura3');
	oGr135=document.getElementById('cartaGrammatura4');
	oGr150=document.getElementById('cartaGrammatura5');
	oGr170=document.getElementById('cartaGrammatura6');

	oFronte1=document.getElementById('fronte1');
	oFronte4=document.getElementById('fronte4');
	oRetro4=document.getElementById('retro4');

	if (oGr70.checked || oGr80.checked || oGr100.checked) {

		oFronte4.checked=false;
		oFronte4.disabled=true;

		oRetro4.checked=false;
		oRetro4.disabled=true;

		if (!oFronte1.checked) {
			alert ("Attenzione: non è possibile stampare in quadricromia con questa grammatura.");

		}

	}

	if (oGr135.checked || oGr150.checked || oGr170.checked) {

		oFronte4.disabled=false;
		oRetro4.disabled=false;

	}

	return;
}

function controlloVolantini() {

	oA4=document.getElementById('dimensione1');
	oA3=document.getElementById('dimensione2');
	oA5=document.getElementById('dimensione3');
	o105=document.getElementById('dimensione4');

	if (!oA4.checked && !oA3.checked && !oA5.checked && !o105.checked) {
		alert ("Scegli la dimensione del volantino");
		return false;
	}

	oFronte1=document.getElementById('fronte1');
	oFronte4=document.getElementById('fronte4');

	if (!oFronte1.checked && !oFronte4.checked) {
		alert ("Scegli il numero di colori per la stampa del fronte");
		return false;
	}


	oCartaTipo1=document.getElementById('cartaTipo1');
	oCartaTipo2=document.getElementById('cartaTipo2');
	oCartaTipo3=document.getElementById('cartaTipo3');

	if (!oCartaTipo1.checked && !oCartaTipo2.checked && !oCartaTipo3.checked) {
		alert ("Scegli il tipo di carta");
		return false;
	}

	oGr70=document.getElementById('cartaGrammatura1');
	oGr80=document.getElementById('cartaGrammatura2');
	oGr100=document.getElementById('cartaGrammatura3');
	oGr135=document.getElementById('cartaGrammatura4');
	oGr150=document.getElementById('cartaGrammatura5');
	oGr170=document.getElementById('cartaGrammatura6');

	if (!oGr70.checked && !oGr80.checked && !oGr100.checked && !oGr135.checked && !oGr150.checked && !oGr170.checked) {
		alert ("Scegli la grammatura");
		return false;
	}

	oElabSingola=document.getElementById('elaborazione1');
	oElab2Falde=document.getElementById('elaborazione2');
	oElab3Falde=document.getElementById('elaborazione3');
	oElab3Soffietto=document.getElementById('elaborazione4');

	if (!oElabSingola.checked && !oElab2Falde.checked && !oElab3Falde.checked && !oElab3Soffietto.checked) {
		alert ("Scegli l'elaborazione");
		return false;
	}



	var quantita = 0;

	oQuantita50=document.getElementById('quantita50');
	oQuantita100=document.getElementById('quantita100');
	oQuantita200=document.getElementById('quantita200');
	oQuantita500=document.getElementById('quantita500');
	oQuantita1000=document.getElementById('quantita1000');


	if (oQuantita50.checked || oQuantita100.checked || oQuantita200.checked || oQuantita500.checked || oQuantita1000.checked) {
		quantita = 1;
	}

	if (quantita == 0) {

		for (var i = 5000; i <= 100000; i=i+5000) {

			oQuantita=document.getElementById('quantita'+ i);
			if (oQuantita.checked) {
				quantita = 1;
			}

		}

	}

	if (quantita == 0) {
		alert ("Scegli la quantità di volantini da stampare");
		return false;
	}

}

function validazioneIntestazione() {

	oIntestazione=document.getElementById('intestazione');

	if (oIntestazione.value=='' || oIntestazione.value.length<3) {
		alert ("Inserisci il testo");
		return false;
	}
}

function formRegistration() {

	oRagSociale=document.getElementById('ragSociale');
	oPIva=document.getElementById('pIva');
	oIndirizzoFatt=document.getElementById('indirizzoFatt');
	oComuneFatt=document.getElementById('comuneFatt');
	oCap=document.getElementById('capFatt');
	oProvinciaFatt=document.getElementById('provinciaFatt');
	oTel=document.getElementById('telefono');
	oEmail=document.getElementById('email');
	oEmail1=document.getElementById('email1');
	oPsw=document.getElementById('psw');
	oPsw1=document.getElementById('psw1');
	oPrivacy=document.getElementById('privacy');

	if (oRagSociale.value=='') {
		alert ("Inserisci la ragione sociale");
		oRagSociale.focus();
		return false;
	}

	if (oPIva.value=='') {
		alert ("Inserisci la partita iva");
		oPIva.focus();
		return false;
	}

	if (oIndirizzoFatt.value=='') {
		alert ("Inserisci l'indirizzo");
		oIndirizzoFatt.focus();
		return false;
	}

	if (oComuneFatt.value=='') {
		alert ("Inserisci il comune");
		oComuneFatt.focus();
		return false;
	}

	if (oCap.value=='' || oCap.value.length!=5) {
		alert ("Inserisci il cap");
		oCap.focus();
		return false;
	}


	if (oProvinciaFatt.value<0) {
		alert ("Scegli la provincia");
		oProvinciaFatt.focus();
		return false;
	}

	if (oTel.value=='') {
		alert ("Inserisci il numero di telefono");
		oTel.focus();
		return false;
	}

	if (oEmail.value!=oEmail1.value) {
		alert ("Scrivi lo stesso indirizzo di email");
		oEmail.focus();
		return false;
	}

	if ((oEmail.value.length<5)) {
		alert ("Formato email non valido");
		oEmail.focus();
		return false;
	}

	if (oEmail.value.indexOf("@")==-1) {
		alert ("Formato email non valido");
		oEmail.focus();
		return false;
	}

	if (oPsw.value=='') {
		alert ("Inserisci la password");
		oPsw.focus();
		return false;
	}

	if ((oPsw.value.length<8)) {
		alert ("Password troppo corta");
		oPsw.focus();
		return false;
	}

	if (oPsw.value!=oPsw1.value) {
		alert ("Ripeti la password");
		oPsw.focus();
		return false;
	}

	if (oPrivacy.checked!=true) {
		alert ("Per procedere con l'iscrizione al sito e' necessario l'autorizzazione al trattamento dei dati");
		return false;
	}

	var rePsw = /^[a-zA-Z0-9]{8,10}$/;
	
	if (!rePsw.test(oPsw.value)) {
		alert("La password puo' contenere solo lettere non accentate e numeri interi. La password deve avere un numero di caratteri compreso tra 8 e 10.");
		return false;
	}

	return true;

}

function formAddress() {

	oTel=document.getElementById('telefono');

	if (oTel.value=='') {
		alert ("Inserisci il numero di telefono");
		oTel.focus();
		return false;
	}

	return true;
}

function formPsw() {

	oPswOld=document.getElementById('pswOld');
	oPsw=document.getElementById('psw');
	oPsw1=document.getElementById('psw1');

	if (oPswOld.value=='') {
		alert ("Inserisci la vecchia password");
		oPswOld.focus();
		return false;
	}

	if (oPsw.value=='') {
		alert ("Inserisci la nuova password");
		oPsw.focus();
		return false;
	}

	if ((oPsw.value.length<8)) {
		alert ("Password troppo corta");
		oPsw.focus();
		return false;
	}

	if (oPsw.value!=oPsw1.value) {
		alert ("Ripeti la password");
		oPsw1.focus();
		return false;
	}

	var rePsw = /^[a-zA-Z0-9]{8,10}$/;
	
	if (!rePsw.test(oPsw.value)) {
		alert("La password puo' contenere solo lettere non accentate e numeri interi. La password deve avere un numero di caratteri compreso tra 8 e 10.");
		return false;
	}

	return true;

}

function controlloBiglietti() {

	oQuantita500=document.getElementById('quantita500');
	oQuantita1000=document.getElementById('quantita1000');
	oQuantita2000=document.getElementById('quantita2000');
	oQuantita3000=document.getElementById('quantita3000');
	oQuantita4000=document.getElementById('quantita4000');
	oQuantita5000=document.getElementById('quantita5000');
	oQuantita6000=document.getElementById('quantita6000');

	oPlastificazione0=document.getElementById('plastificazione0');
	oPlastificazione1=document.getElementById('plastificazione1');

	if (!oQuantita500.checked && !oQuantita1000.checked && !oQuantita2000.checked && !oQuantita3000.checked && !oQuantita4000.checked && !oQuantita5000.checked && !oQuantita6000.checked) {
		alert ("Scegli la quantità di volantini da stampare");
		return false;
	}

	if (!oPlastificazione0.checked && !oPlastificazione1.checked) {
		alert ("Vuoi la plastificazione?");
		return false;
	}

	return true;

}

function validazioneFileUpld() {

  oAllegato=document.getElementById('fileAll');
  if (oAllegato.value=='') {
	alert ("Scegli il file");
	oAllegato.focus();
	return false;
  }

  return true;

}
