// JavaScript Document
//Controllo campi moduli by Briganti Filippo


function controllaform(){
var allora = true
document.modulo.mail.value = document.modulo.mail.value.toLowerCase()

var Filtro = /^([a-zA-Z0-9])+$/;
var controllo = false;
var bottone = document.modulo.sesso;

if (!document.modulo.nome.value){
alert("TI RICORDO CHE IL CAMPO \"NOME\" È OBBLIGATORIO!!");
document.modulo.nome.focus();
return allora
}
if ((document.modulo.nome.value.length < 3) || (!isNaN(document.modulo.nome.value))){
alert("TI PREGHIAMO DI INSERIRE UN NOME VALIDO");
document.modulo.nome.focus();
return allora
}
if (!document.modulo.cognome.value){
alert("TI RICORDO CHE IL CAMPO \"COGNOME\" È OBBLIGATORIO!!");
document.modulo.cognome.focus();
return allora
}
if ((document.modulo.cognome.value.length < 3) || (!isNaN(document.modulo.cognome.value))){
alert("TI PREGHIAMO DI INSERIRE UN COGNOME VALIDO");
document.modulo.cognome.focus();
return allora
}
if (!document.modulo.data.value){
alert("TI RICORDO CHE IL CAMPO \"DATA NASCITA\" È OBBLIGATORIO!!");
document.modulo.data.focus();
return allora
}
if (document.modulo.data.value.length < 10){
alert("INSERIRE \"DATA NASCITA\" NEL FORMATO GG/MM/AAAA");
document.modulo.data.focus();
return allora
}
if (document.modulo.data.value.charAt(2) != "/" || document.modulo.data.value.charAt(5) != "/"){
alert("NELLA \"DATA NASCITA\" UTILIZZARE COME SEPARATORE IL SIMBOLO \"/\"");
document.modulo.data.focus();
return allora
}


for(var i=0; i<bottone.length; i++) {
  if(bottone[i].checked) {
    controllo = true;
    break;
  }
}
if(!controllo) {
  alert("TI RICORDO CHE IL CAMPO \"GENERALITA\" È OBBLIGATORIO!!");
  return allora
} 


if (!document.modulo.via.value){
alert("TI RICORDO CHE IL CAMPO \"INDIRIZZO\" È OBBLIGATORIO!!");
document.modulo.via.focus();
return allora
}
if ((document.modulo.via.value.length < 3)){
alert("TI PREGHIAMO DI INSERIRE UN INDIRIZZO VALIDO");
document.modulo.via.focus();
return allora
}
if (!document.modulo.citta.value){
alert("TI RICORDO CHE IL CAMPO \"COMUNE\" È OBBLIGATORIO!!");
document.modulo.citta.focus();
return allora
}
if ((document.modulo.citta.value.length < 3) || (!isNaN(document.modulo.citta.value))){
alert("TI PREGHIAMO DI INSERIRE UN NOME DI COMUNE VALIDO");
document.modulo.citta.focus();
return allora
}
if (!document.modulo.cap.value){
alert("TI RICORDO CHE IL CAMPO \"CAP\" È OBBLIGATORIO!!");
document.modulo.cap.focus();
return allora
}
if (isNaN(document.modulo.cap.value)){
alert("INSERIRE IL C.A.P. ESCLUSIVAMENTE IN CIFRE es.12345");
document.modulo.cap.focus();
return allora
}
if ((document.modulo.cap.value.length > 5) || (document.modulo.cap.value.length < 5)){
alert("IL C.A.P. È UN CODICE DI 5 CIFRE");
document.modulo.cap.focus();
return allora
}
if (!document.modulo.prov.value){
alert("TI RICORDO CHE IL CAMPO \"PROVINCIA\" È OBBLIGATORIO!!");
document.modulo.prov.focus();
return allora
}
if (!document.modulo.username.value){
alert("TI RICORDO CHE IL CAMPO \"USER NAME\" È OBBLIGATORIO!!");
document.modulo.username.focus();
return allora
}
if (document.modulo.username.value.indexOf(' ') != -1 ){
alert("NEL CAMPO \"USER NAME\" GLI SPAZI NON SONO CONSENTITI");
document.modulo.username.focus();
return allora
}

if (Filtro.test(document.modulo.username.value)){
  }else{
alert("ATTENZIONE:\n NEL CAMPO \"USER NAME\" HAI INSERITO UN CARATTERE NON VALIDO");
document.modulo.username.focus();
return allora
}
if ((document.modulo.username.value.length < 5)){
alert("INSERIRE \"USER NAME\" DI ALMENO 5 CARATTERI");
document.modulo.username.focus();
return allora
}
if ((document.modulo.username.value.length > 10)){
alert("INSERIRE \"USER NAME\" NON PIU' DI 10 CARATTERI");
document.modulo.username.focus();
return allora
}
if (!document.modulo.password.value){
alert("TI RICORDO CHE IL CAMPO \"PASSWORD\" È OBBLIGATORIO!!");
document.modulo.password.focus();
return allora
}
if (document.modulo.password.value.indexOf(" ") != -1 ){
alert("NEL CAMPO \"PASSWORD\" GLI SPAZI NON SONO CONSENTITI");
document.modulo.password.focus();
return allora
}
if (Filtro.test(document.modulo.password.value)){
      
   }else{
alert("ATTENZIONE:\n NEL CAMPO \"PASSWORD\" HAI INSERITO UN CARATTERE NON VALIDO");
document.modulo.password.focus();
return allora
}
if ((document.modulo.password.value.length < 6)){
alert("INSERIRE \"PASSWORD\" DI ALMENO 6 CARATTERI");
document.modulo.password.focus();
return allora
}
if ((document.modulo.password.value.length > 10)){
alert("INSERIRE \"PASSWORD\" NON PIU' DI 10 CARATTERI");
document.modulo.password.focus();
return allora
}
if (!document.modulo.c_password.value){
alert("TI RICORDO CHE IL CAMPO \"CONFERMA PASSWORD\" È OBBLIGATORIO!!");
document.modulo.c_password.focus();
return allora
}
if ((document.modulo.c_password.value != document.modulo.password.value)){
alert("ATTENZIONE:\nI VALORI IMMESSI NEI CAMPI\n\"PASSWORD\"\nE\n\"CONFERMA PASSWORD\"\nNON CORRISPONDONO!");
document.modulo.c_password.focus();
return allora
}
if (!document.modulo.mail.value){
alert("TI RICORDO CHE IL CAMPO \"E-MAIL\" È OBBLIGATORIO!!");
document.modulo.mail.focus();
return allora
}  
if (document.modulo.mail.value.indexOf ('@',0) == -1 || document.modulo.mail.value.indexOf ('.',0) == -1){
alert("ATTENZIONE:\nDEVI INSERIRE UN INDIRIZZO E-MAIL VALIDO\nALTRIMENTI NON POTREMO INVIARTI IL CODICE PER ATTIVARE IL TUO ACCOUNT!");
document.modulo.mail.focus();
return allora
}


else{

var elenco = new Array();
		
     elenco[0] ="L’utente, dichiara di aver letto l’informativa sulla PRIVACY e acquisite le informazioni, fornite dal titolare del trattamento ai sensi dell’articolo 13 del D.Lgs. 196/2003, completando la registrazione, presta il suo consenso al trattamento dei dati personali per i fini indicati nella suddetta informativa, dichiarando di essere a conoscenza dei diritti riconosciutimi dall’art. 7 del D.lgs. n° 196/2003."
	
	
	
	
	
	
	
	
	
	
	
	
		
		function dati(){
		
		 consenso = confirm('\t\t\tCONSENSO TRATTAMENTO DATI PERSONALI\n\n' +elenco[0])
		if(consenso == true){
		document.modulo.password.value = encode64(document.modulo.password.value);
        document.modulo.c_password.value = encode64(document.modulo.c_password.value);
        document.modulo.submit();
		}else{
		alert("IL CONSENSO AL TRATTAMENTO DEI DATI PERSONALI È INDISPENSABILE, SENZA IL TUO CONSENSO NON PUOI PROSEGUIRE CON LA REGISTRAZIONE");
		}

}
return dati();

}
}

// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

function centradiv(id){ 
if (document.layers){ 
document.layers[id].width=700; 
document.layers[id].pageX =(window.innerWidth/2)-(document.layers[id].width/2); 
document.layers[id].height=400; 
document.layers[id].pageY =(window.innerHeight/2)-(document.layers[id].height/2); 
} 
else if (document.all){ 
document.all[id].width=700; 
document.all[id].style.posLeft =(document.documentElement.clientWidth/2)-(document.all[id].width/2); 
document.all[id].height=400; 
document.all[id].style.posTop =(document.documentElement.clientHeight/2)-(document.all[id].height/2); 
} 
else if(document.getElementById){ 
document.getElementById(id).width=700; 
document.getElementById(id).style.left =(window.innerWidth/2)-(document.getElementById(id).width/2); 
document.getElementById(id).height=400; 
document.getElementById(id).style.top =(window.innerHeight/2)-(document.getElementById(id).height/2); 
} 
} 
