function accetto_non()
	{
		if (document.f1.c_accetto.value==1)
		{
		document.f1.c_accetto.value=0
		document.f1.inviarichiesta.disabled = true;
		}
		else
		{
		document.f1.c_accetto.value=1
		document.f1.inviarichiesta.disabled = false;
		}
	}

function accendi(a) {
	a.style.color ="#C5030B";
}

function spengi(a) {
	a.style.color = "#ffffff";
}

function accendi1(a) {
	a.style.color ="#C5030B";
}

function spengi1(a) {
	a.style.color = "#0054A3";
}

function cambiaImg(ico, pathImmagine) 
{
ico.src = pathImmagine;
}

function ricarica()
	{
		document.f1.method = "post"
		document.f1.action="modulo_abbonamento.asp";
		document.f1.submit();
	}	

function funz_datipersonali()
	{
		if (document.f1.datipersonali.value == "no")
		{
		document.f1.inviarichiesta.disabled = true;
		}
		else
		{
		document.f1.inviarichiesta.disabled = false;
		}
	}
	
function controllacodfisc_completa()
   {
   cod=document.f1.codicefiscale.value.toLowerCase();
   var msg
   msg = ""
   if (cod.length!=16)
      msg=" Codice Fiscale Errato "
      else
      {
      lettere=cod.substr(0,6)+cod.substr(8,1)+cod.substr(11,1)+cod.substr(15);
      numeri=cod.substr(6,2)+cod.substr(9,2)+cod.substr(12,3);
      for (i=0;i<10;i++)
         if (lettere.charCodeAt(i)<97 || lettere.charCodeAt(i)>122)
     		 msg=" Codice Fiscale Errato "
      for (i=0;i<8;i++)
         if (numeri.charCodeAt(i)<48 || numeri.charCodeAt(i)>57)
		  msg= " Codice Fiscale Errato "
      }
	//fine controlli
	if (msg != "")
		{
		document.f1.codicefiscale.value = ""
		alert(msg)
		}			
	 }	
	

function controllacodfisc()
{
cod=document.f1.codicefiscale.value.toLowerCase();
if (cod.length != 16)
	{
		alert("Codice fiscale errato")
	}	
} 
	 
function validacap()
{
	var cap
	cap = document.f1.cap.value
	if ((cap.length != 5) || (isNaN(cap)))
	{
		document.f1.cap.value = ""
		document.f1.cap.focus()
		alert("CAP non valido")
	}
}	 
	 
function validaobbligatori()
{
	



var msg
msg = ""
	if ((document.f1.nome.value == "") || (document.f1.cap.value == "") || (document.f1.cognome.value == "") || (document.f1.codicefiscale.value == "") || (document.f1.datanascita.value == "") || (document.f1.toponimo.value == "" || (document.f1.toponimo.value == "Altro" && document.f1.altroToponimo.value == "" ) ) || (document.f1.via.value == "") || ((document.f1.tipoabbonamento.value == 'studenti') && (document.f1.istitutoscolastico.value == "")))
	{
		//"I campi contrassegnati da asterisco sono obbligatori")
		msg = msg + "- I campi contrassegnati da asterisco sono obbligatori"
	}

	//if (document.f1.zonaa.value == document.f1.zonada.value)
	//{
	//	msg = msg + "\n\n- La zona di partenza e arrivo non possono coincidere"
	//}	
	
	//if ((document.f1.telefono.value == "") && (document.f1.cellulare.value == "") && (document.f1.email.value == ""))
	//{
	//	msg = msg + "\n\n- Compilare almeno un campo tra telefono, cellulare ed email"
	//}
	
	if (msg.length > 0)
	{
		alert(msg)
	}
	else
	{
		if (document.f1.questionario.value == "")
		{
			alert('Decidere se autorizzare o non autorizzare la Provincia ad inviarle un Questionario Valutativo')
			return;	
		}
		else
		{
			document.f1.method = "post"
			document.f1.action="registra_modulo.asp";
			document.f1.submit();
		}
	}
}

function validaobbligatoriModifica()
{
var msg
msg = ""
	if ((document.f1.nome.value == "") || (document.f1.cap.value == "") || (document.f1.cognome.value == "") || (document.f1.codicefiscale.value == "") || (document.f1.datanascita.value == "") || (document.f1.toponimo.value == "" || (document.f1.toponimo.value == "Altro" && document.f1.altroToponimo.value == "" ) ) || (document.f1.via.value == "") || ((document.f1.tipoabbonamento.value == 'studenti' || document.f1.tipoabbonamento.value == 'STUDENTI') && (document.f1.istitutoscolastico.value == "")))
	{
		//"I campi contrassegnati da asterisco sono obbligatori")
		msg = msg + "- I campi contrassegnati da asterisco sono obbligatori"
	}

	//if (document.f1.zonaa.value == document.f1.zonada.value)
	//{
	//	msg = msg + "\n\n- La zona di partenza e arrivo non possono coincidere"
	//}	
	
	//if ((document.f1.telefono.value == "") && (document.f1.cellulare.value == "") && (document.f1.email.value == ""))
	//{
	//	msg = msg + "\n\n- Compilare almeno un campo tra telefono, cellulare ed email"
	//}
	
	if (msg.length > 0)
	{
		alert(msg)
	}
	else
	{
		if (document.f1.questionario.value == "")
		{
			alert('Decidere se autorizzare o non autorizzare la Provincia ad inviarle un Questionario Valutativo')
			return;	
		}
		else
		{
		document.f1.method = "post"
		document.f1.action="registra_moduloModifica.asp";
		document.f1.submit();
		}
	}
}	 	 
	 
function validaobbligatori1()
{
var msg
msg = ""
	if ((document.f1.nome.value == "") || (document.f1.cap.value == "") || (document.f1.cognome.value == "") || (document.f1.codicefiscale.value == "") || (document.f1.datanascita.value == "") || (document.f1.toponimo.value == "" || (document.f1.toponimo.value == "Altro" && document.f1.altroToponimo.value == "" ) ) || (document.f1.via.value == "") || ((document.f1.tipoabbonamento.value == 'studenti'|| document.f1.tipoabbonamento.value == 'STUDENTI') && (document.f1.istitutoscolastico.value == "")))
	{
		//"I campi contrassegnati da asterisco sono obbligatori")
		msg = msg + "- I campi contrassegnati da asterisco sono obbligatori"
	}

	//if (document.f1.zonaa.value == document.f1.zonada.value)
	//{
	//	msg = msg + "\n\n- La zona di partenza e arrivo non possono coincidere"
	//}	
	
	//if ((document.f1.telefono.value == "") && (document.f1.cellulare.value == "") && (document.f1.email.value == ""))
	//{
	//	msg = msg + "\n\n- Compilare almeno un campo tra telefono, cellulare ed email"
	//}
	
	if (msg.length > 0)
	{
		alert(msg)
	}
	else
	{
		if (document.f1.questionario.value == "")
		{
			alert('Decidere se autorizzare o non autorizzare la Provincia ad inviarle un Questionario Valutativo')
			return;	
		}
		else
		{
		document.f1.method = "post"
		document.f1.action="registra_modulo1.asp";
		document.f1.submit();
		}
	}
}	 

function verificadata2()
{
var vdata, gg, aa, mm
vdata = document.f1.datanascita.value
gg=parseFloat(vdata.substring(0,2))
mm=parseFloat(vdata.substring(3,5))
aa=parseFloat(vdata.substring(6,10))
	if(vdata.length!=10 |gg<1|gg>31|mm<1|mm>12|aa<1900|aa>2050)
		{
		document.f1.datanascita.value=""
		document.f1.datanascita.focus()
		alert("Formato data non valido")

		}
}	 

function verificadata()
	{
	pa_data = document.f1.datanascita.value
	var anno = pa_data.substring(6, 10);
//Aggiunta della funzione per il controllo delle stringhe
	if (pa_data != "" )
        	{
                if (((pa_data.substring(0, 1)<"0")||(pa_data.substring(0, 1)>"9"))||
                   ((pa_data.substring(1, 2)<"0")||(pa_data.substring(1, 2)>"9"))||
                   ((pa_data.substring(3, 4)<"0")||(pa_data.substring(3, 4)>"9"))||
                   ((pa_data.substring(4, 5)<"0")||(pa_data.substring(4, 5)>"9"))||
                   ((pa_data.substring(6, 7)<"0")||(pa_data.substring(6, 7)>"9"))||
                   ((pa_data.substring(7, 8)<"0")||(pa_data.substring(7, 8)>"9"))||
                   ((pa_data.substring(8, 9)<"0")||(pa_data.substring(8, 9)>"9"))||
                   ((pa_data.substring(9, 10)<"0")||(pa_data.substring(9, 10)>"9")))
			{
                        alert("La data deve essere nel formato gg/mm/aaaa.");
			document.f1.datanascita.value=""
			document.f1.datanascita.focus()
                        return false;
                        }		
		if ((pa_data.length != 10)||(pa_data.substring(2, 3)!="/")||(pa_data.substring(5, 6)!="/"))
                	{
                        alert("La data essere nel formato gg/mm/aaaa.");
			document.f1.datanascita.value=""
			document.f1.datanascita.focus()
                        }

		var gg=pa_data.substring(0, 2);
		var mm=pa_data.substring(3, 5);
		var aa=pa_data.substring(6, 10);
		if (
		     (eval(mm) < 1)  ||
		     (eval(mm) > 12) ||
		     (eval(gg) > 31) ||
		     (eval(gg) < 1)  ||
		    (
		     ((eval(mm) == 11)|| (eval(mm) == 4)||
		     (eval(mm) == 6)|| (eval(mm) == 9))
			&&
		     ((eval(gg) < 1)||(eval(gg)>30))
		    )
		||
		    (
		     (eval(mm) == 2)
			&&
		     ((eval(gg) < 1)||(eval(gg)>(((eval(aa) % 4 == 0) && ((!(eval(aa) % 100 == 0)) || (eval(aa) % 400 == 0))) ? 29 : 28)))
		    )
		   )
			{
			alert ("La data non è corretta.");
			document.f1.datanascita.value=""
			document.f1.datanascita.focus()
			}
		if (eval(aa) < 1800 )
			{
			alert("La data non è corretta.");
			document.f1.datanascita.value=""
			document.f1.datanascita.focus()
			}
		}
	//else
	//{		
	//	alert('Bisogna inserire una data.');
	//	return false;
	//}
	return true;
	}

function verificadataDettaglio()
	{
	pa_data = document.form1.dataNascita.value
	var anno = pa_data.substring(6, 10);
//Aggiunta della funzione per il controllo delle stringhe
	if (pa_data != "" )
        	{
                if (((pa_data.substring(0, 1)<"0")||(pa_data.substring(0, 1)>"9"))||
                   ((pa_data.substring(1, 2)<"0")||(pa_data.substring(1, 2)>"9"))||
                   ((pa_data.substring(3, 4)<"0")||(pa_data.substring(3, 4)>"9"))||
                   ((pa_data.substring(4, 5)<"0")||(pa_data.substring(4, 5)>"9"))||
                   ((pa_data.substring(6, 7)<"0")||(pa_data.substring(6, 7)>"9"))||
                   ((pa_data.substring(7, 8)<"0")||(pa_data.substring(7, 8)>"9"))||
                   ((pa_data.substring(8, 9)<"0")||(pa_data.substring(8, 9)>"9"))||
                   ((pa_data.substring(9, 10)<"0")||(pa_data.substring(9, 10)>"9")))
			{
                        alert("La data deve essere nel formato gg/mm/aaaa.");
			document.form1.dataNascita.value=document.form1.dN.value
			document.form1.dataNascita.focus()
                        return false;
                        }		
		if ((pa_data.length != 10)||(pa_data.substring(2, 3)!="/")||(pa_data.substring(5, 6)!="/"))
                	{
                        alert("La data essere nel formato gg/mm/aaaa.");
			document.form1.dataNascita.value=document.form1.dN.value
			document.form1.dataNascita.focus()
                        }

		var gg=pa_data.substring(0, 2);
		var mm=pa_data.substring(3, 5);
		var aa=pa_data.substring(6, 10);
		if (
		     (eval(mm) < 1)  ||
		     (eval(mm) > 12) ||
		     (eval(gg) > 31) ||
		     (eval(gg) < 1)  ||
		    (
		     ((eval(mm) == 11)|| (eval(mm) == 4)||
		     (eval(mm) == 6)|| (eval(mm) == 9))
			&&
		     ((eval(gg) < 1)||(eval(gg)>30))
		    )
		||
		    (
		     (eval(mm) == 2)
			&&
		     ((eval(gg) < 1)||(eval(gg)>(((eval(aa) % 4 == 0) && ((!(eval(aa) % 100 == 0)) || (eval(aa) % 400 == 0))) ? 29 : 28)))
		    )
		   )
			{
			alert ("La data non è corretta.");
			document.form1.dataNascita.value=document.form1.dN.value
			document.form1.dataNascita.focus()
			}
		if (eval(aa) < 1800 )
			{
			alert("La data non è corretta.");
			document.form1.dataNascita.value=document.form1.dN.value
			document.form1.dataNascita.focus()
			}
		}
	//else
	//{		
	//	alert('Bisogna inserire una data.');
	//	return false;
	//}
	return true;
	}

function validaemail2() {
  var sEmail = document.f1.email.value
  if (sEmail == "") 
  {
   // window.alert("L'indirizzo email è obbligatorio.");
   //return(false);
  } else if ((sEmail.indexOf("@") == -1) ||
             (sEmail.indexOf(".") == -1) || 
             (sEmail.length < 6)) {
    window.alert("Indirizzo email non valido.");
    return(false);
  } else {
    return(true);
  }
}

function validaemail()
   {
   // Controllo il formato dell'indirizzo e-mail. rstituisce true o false
   var StrMail;
   StrMail=document.f1.email.value
   if (StrMail.length>6)
      {
      var pos;
      var dotpos;
      pos = StrMail.indexOf("@");
      if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
         {
         document.f1.email.focus();
		 alert("Indirizzo email non valido")
         return (false);
         }
      pos=pos+1;
      dotpos = StrMail.indexOf(".", pos);
      if (dotpos > (StrMail.length-3) )
         {
         document.f1.email.focus();
		 alert("Indirizzo email non valido")
         return (false);
         }
      Strmail=StrMail.substr(pos);
      if ( (StrMail.length < 5) || (dotpos <= 0) )
         {
		 alert("Indirizzo email non valido")
         document.f1.email.focus();
         return (false);
         }
      }
   else
      {
	 alert("Indirizzo email non valido")
      document.f1.email.focus();
      return (false);
      }
   return true;
   }


function verifica_salva(ord,stud,spedi,nospedi,proto,noproto,cercacomune,cognome,nome,avanzata,id,ricid,page,codice)
{

if (document.form1.toponimo.value == "" || (document.form1.toponimo.value == "Altro" && document.form1.altroToponimo.value == "" ) )

{
	alert('Inserire i Campi Obbligatori')
}

else
{

var proto = proto;
var spedi = spedi;
var noproto = noproto;
var nospedi = nospedi;
var ord = ord;
var stud = stud;
var cognome_chk = cognome;
var nome_chk = nome;
avanzata = avanzata;
cercacomune = cercacomune;
var DataProtocollo = document.form1.DataProtocollo.value
var NumeroProtocollo = document.form1.NumeroProtocollo.value
if	((DataProtocollo.length == 0) || (NumeroProtocollo.length == 0))
	{
		alert("I campi PROTOCOLLO e DATA PROTOCOLLO sono obbligatori")
	}
else
	{

		if (document.form1.questionario.value == "")
		{
			alert('Decidere se autorizzare o non autorizzare la Provincia ad inviarle un Questionario Valutativo')
			return;	
		}
		else
		{

		var stringa
		stringa = "elencoDomande_dettaglio.asp?ord="+ord+"&stud="+stud+"&nospedi="+nospedi+"&spedi="+spedi+"&avanzata="+avanzata+"&cercacomune="+cercacomune+"&nome_chk="+nome_chk+"&cognome_chk="+cognome_chk+"&noproto="+noproto+"&proto="+proto+"&salva=1&Id="+id+"&RicId="+ricid+"&Page="+page+"&codice="+codice 
		document.location.href = stringa
		document.form1.action = stringa		
		document.form1.method = "post"
		document.form1.submit()
		}
	}

}

}




function cambiaTipologia(ord,stud,spedi,nospedi,proto,noproto,cercacomune,cognome,nome,avanzata,id,ricid,page,codice)
{

	if (confirm('Confermi il cambio di Tipologia ?'))
	{


		var proto = proto;
		var spedi = spedi;
		var noproto = noproto;
		var nospedi = nospedi;
		var ord = ord;
		var stud = stud;
		var cognome_chk = cognome;
		var nome_chk = nome;
		avanzata = avanzata;
		cercacomune = cercacomune;
		var DataProtocollo = document.form1.DataProtocollo.value
		var NumeroProtocollo = document.form1.NumeroProtocollo.value
		var stringa
		stringa = "cambioTipologia.asp?ord="+ord+"&stud="+stud+"&nospedi="+nospedi+"&spedi="+spedi+"&avanzata="+avanzata+"&cercacomune="+cercacomune+"&nome_chk="+nome_chk+"&cognome_chk="+cognome_chk+"&noproto="+noproto+"&proto="+proto+"&Id="+id+"&RicId="+ricid+"&Page="+page+"&codice="+codice 
		document.location.href = stringa

	}
	else
	{
		return;
	}

}


function verifica_salva1(id,ricid,page,codice)
{

if (document.form1.toponimo.value == "" || (document.form1.toponimo.value == "Altro" && document.form1.altroToponimo.value == "" ) )

{
	alert('Inserire i Campi Obbligatori')
}

else
{

var DataProtocollo = document.form1.DataProtocollo.value
var NumeroProtocollo = document.form1.NumeroProtocollo.value
if	((DataProtocollo.length == 0) || (NumeroProtocollo.length == 0))
	{
		alert("I campi PROTOCOLLO e DATA PROTOCOLLO sono obbligatori")
	}
else
	{

		if (document.form1.questionario.value == "")
		{
			alert('Decidere se autorizzare o non autorizzare la Provincia ad inviarle un Questionario Valutativo')
			return;	
		}
		else
		{

		var stringa
		stringa = "elencoDomande_dettaglio.asp?salva=1&Id="+id+"&RicId="+ricid+"&Page="+page+"&codice="+codice 
		document.location.href = stringa
		document.form1.action = stringa		
		document.form1.method = "post"
		document.form1.submit()
		}
	}

}
}

function verificadata_protocollo()
{

var vdata, gg, aa, mm
vdata = document.form1.DataProtocollo.value
gg=parseFloat(vdata.substring(0,2))
mm=parseFloat(vdata.substring(3,5))
aa=parseFloat(vdata.substring(6,10))
	if(vdata.length!=10 |gg<1|gg>31|mm<1|mm>12|aa<1900|aa>2050)
		{
		document.form1.DataProtocollo.value=""
		document.form1.DataProtocollo.focus()
		alert("Formato data non valido"+"\n"+"(gg/mm/aaaa)")
		}
}	 

function selezione_domande(cod)
{
//alert(document.form1.cercacomune.value)
var proto = 0
var noproto = 0
var spedi = 0
var nospedi = 0
var ord = 0
var stud = 0
	if (document.form1.proto_chk.checked == true)
		{
			proto = 1
		}	
	else
		{
			proto = 0 
		}
		
	if (document.form1.spedi_chk.checked == true)
		{
			spedi = 1
		}	
	else
		{
			spedi = 0 
		}
		
	if (document.form1.ord_chk.checked == true)
		{
			ord = 1
		}	
	else
		{
			ord = 0 
		}
		
	if (document.form1.noproto_chk.checked == true)
		{
			noproto = 1
		}	
	else
		{
			noproto = 0
		}
	if (document.form1.nospedi_chk.checked == true)
		{
			nospedi = 1
		}	
	else
		{
			nospedi = 0
		}
	if (document.form1.stud_chk.checked == true)
		{
			stud = 1
		}	
	else
		{
			stud = 0
		}
		var cognome_chk = document.form1.cognome_chk.value;
		var nome_chk = document.form1.nome_chk.value;
		var codice = cod
		var stringa = "elencodomande.asp?ord="+ord+"&stud="+stud+"&nospedi="+nospedi+"&spedi="+spedi+"&avanzata=1&codice="+codice+"&proto="+proto+"&noproto="+noproto+"&cognome_chk="+cognome_chk+"&nome_chk="+nome_chk
		if (document.form1.cercacomune.value != "%")
			{
					stringa = stringa + "&cercacomune="+document.form1.cercacomune.value
			}
		document.location.href = stringa

		//alert(document.form1.proto.value+" "+document.form1.noproto.value)	
}

function ricerca_id()
{
var proto
proto = 0 
var noproto
noproto = 0
var spedi 
spedi = 0
var nospedi
nospedi = 0
var ord
ord = 0
var stud
stud = 0
var stringa
var proto_chk = document.form1.proto_chk
var noproto_chk = document.form1.noproto_chk
var spedi_chk = document.form1.spedi_chk;
var nospedi_chk = document.form1.nospedi_chk
var cognome_chk = document.form1.cognome_chk.value;
var nome_chk = document.form1.nome_chk.value;
var avanzata = document.form1.avanzata.value;
var ord_chk = document.form1.ord_chk;
var stud_chk = document.form1.stud_chk
if (proto_chk.checked == true)
	{
		proto = 1
		//alert(proto)
	}
if (spedi_chk.checked == true)
	{
		spedi = 1
		//alert(proto)
	}
if (noproto_chk.checked == true)
	{
		noproto = 1
		//alert(noproto)
	}
if (nospedi_chk.checked == true)
	{
		nospedi = 1
		//alert(noproto)
	}
if (ord_chk.checked == true)
	{
		ord = 1
		//alert(proto)
	}
if (stud_chk.checked == true)
	{
		stud = 1
		//alert(proto)
	}
stringa = "elencoDomande.asp?id="+document.form1.Ricid.value+"&codice="+document.form1.codice.value
stringa = stringa + "&cercacomune="+document.form1.cercacomune.value
stringa = stringa + "&proto="+proto
stringa = stringa + "&spedi="+spedi
stringa = stringa + "&nospedi="+nospedi
stringa = stringa + "&ord="+ord
stringa = stringa + "&stud="+stud
stringa = stringa + "&noproto="+noproto+"&cognome_chk="+cognome_chk+"&nome_chk="+nome_chk+"&avanzata="+avanzata
//alert(stringa)
document.location.href = stringa
}


function cambia_comune()
{
var proto
proto = 0 
var spedi
spedi = 0 
var noproto
noproto = 0
var nospedi
nospedi = 0
var ord
ord = 0
var stud
stud = 0
var stringa
var proto_chk = document.form1.proto_chk
var spedi_chk = document.form1.spedi_chk
var noproto_chk = document.form1.noproto_chk
var nospedi_chk = document.form1.nospedi_chk
var cognome_chk = document.form1.cognome_chk.value;
var nome_chk = document.form1.nome_chk.value;
var avanzata = document.form1.avanzata.value;
var ord_chk = document.form1.ord_chk
var stud_chk = document.form1.stud_chk
if (proto_chk.checked == true)
	{
		proto = 1
		//alert(proto)
	}
if (spedi_chk.checked == true)
	{
		spedi = 1
		//alert(proto)
	}
if (noproto_chk.checked == true)
	{
		noproto = 1
		//alert(noproto)
	}
if (nospedi_chk.checked == true)
	{
		nospedi = 1
		//alert(noproto)
	}
if (ord_chk.checked == true)
	{
		ord = 1
		//alert(proto)
	}
if (stud_chk.checked == true)
	{
		stud = 1
		//alert(proto)
	}
stringa = "elencoDomande.asp?codice="+document.form1.codice.value
stringa = stringa + "&cercacomune="+document.form1.cercacomune.value
stringa = stringa + "&proto="+proto
stringa = stringa + "&spedi="+spedi
stringa = stringa + "&nospedi="+nospedi
stringa = stringa + "&ord="+ord
stringa = stringa + "&stud="+stud
stringa = stringa + "&noproto="+noproto+"&cognome_chk="+cognome_chk+"&nome_chk="+nome_chk+"&avanzata="+avanzata
//alert (stringa)
document.location.href = stringa
}

function ricerca_avanzata(id)
{
	el1=document.getElementById(id)
	if (el1.style.display == "none")
		{
			el1.style.display = "inline"
		}
	else
		{
			el1.style.display = "none"
			document.form1.avanzata.value = ""
			document.form1.noproto_chk.checked = false
			document.form1.nospedi_chk.checked = true
			document.form1.nospedi_chk.checked = true
			document.form1.stud_chk.checked = true
			document.form1.cognome_chk.value = ""
			document.form1.nome_chk.value = ""				
		}
}




