var oggi = new Date();
var G = oggi.getDate();
var M = (oggi.getMonth() + 1);

if (G < 10)
{
	var gg = "0" + oggi.getDate();
}
else
{
	var gg = oggi.getDate();
}
if (M < 10)
{
	var mm = "0" + (oggi.getMonth() + 1);
}
else
{
	var mm = (oggi.getMonth() + 1);
}

var aa = oggi.getFullYear();
var dataodierna = gg + "/" + mm + "/" + aa;


function sh_errore(campotre, smser)
{
	campotre.focus();	
	document.getElementById('ersms').innerHTML = smser;
	document.getElementById("boxerrore").style.display="block";
	alert("ATTENZIONE!\n"+smser);
	}
	
function sh_errore_radio(campotre, smser)
{
	campotre[0].focus();	
	document.getElementById('ersms').innerHTML = smser;
	document.getElementById("boxerrore").style.display="block";
	alert("ATTENZIONE!\n"+smser);
	}	

function hd_errore()
{
document.getElementById("boxerrore").style.display="none";
}
	
	//stringa="12/02/2008";
function controllo_data(stringa){
	var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if (!espressione.test(stringa))
	{
	    return false;
	}else{
		anno = parseInt(stringa.substr(6),10);
		mese = parseInt(stringa.substr(3, 2),10);
		giorno = parseInt(stringa.substr(0, 2),10);
		
		var data=new Date(anno, mese-1, giorno);
		if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno){
			return true;
		}else{
			return false;
		}
	}
}

//confronto 2 date

function confronta_data(data1, data2){
  data1str = data1.substr(6)+data1.substr(3, 2)+data1.substr(0, 2);
  data2str = data2.substr(6)+data2.substr(3, 2)+data2.substr(0, 2);
  //controllo se la seconda data è successiva alla prima
  if (data2str-data1str<0) {
	  return false;
  }else{
	  return true;
  }
}

function evalGroup(minatore)
{
     var group = minatore
     for (var i=0; i<group.length; i++) {
       if (group[i].checked)
          break;
     }
     if (i==group.length){
			return false;
		}else{
			return true;
		}
}




function abbandona(collegamento)
{
  if (confirm('Attenzione!I dati inseriti nel modulo verranno persi.\nSei sicuro di abbandonare la sessione di registrazione ?'))
    location.href = collegamento;
}

function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	var lettere, cifre;
	
	if( cf == '' )
	{
		//alert("Controllare che il codice fiscale sia stato inserito.\n");
		return false;
	}
	
	cf = cf.toUpperCase();
	
	//Lunghezza
	if( cf.length != 16 )
	{
		//alert("La lunghezza del codice fiscale non è corretta:\n"
		//+"il codice fiscale deve essere lungo\n"
		//+"esattamente 16 caratteri.\n");
		return false;
	}

	lettere = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	cifre = "0123456789";

	//Caratteri corretti
	//6 lettere	
	for (i = 0; i < 6; i++)
	{
		if( lettere.indexOf( cf.charAt(i) ) == -1 )
		{
			//alert( "Il codice fiscale contiene un carattere non valido `" +
				//cf.charAt(i) +
				//"` in posizione " + (i+1) + ".\nI caratteri validi in quella posizione sono lettere.\n");
			return false;	
		}
	}
	
	//2 cifre (anno)
	for (i = 6; i < 8; i++)
	{
		if( cifre.indexOf( cf.charAt(i) ) == -1 )
		{
			//alert( "Il codice fiscale contiene un carattere non valido `" +
				//cf.charAt(i) +
				//"` in posizione " + (i+1) + ".\nI caratteri validi in quella posizione sono cifre.\n");
			return false;	
		}
	}
		
	//1 lettera
	if( lettere.indexOf( cf.charAt(8) ) == -1 )
	{
		//alert( "Il codice fiscale contiene un carattere non valido `" +
			//cf.charAt(i) +
			//"` in posizione 9.\nI caratteri validi in quella posizione sono lettere.\n");
		return false;	
	}	
		
	//2 cifre 1-31 & 41-71 (giorno & sesso)
	if( ! ( ((cf.substring(9,11) >= 1 ) && (cf.substring(9,11) <= 31 )) || ((cf.substring(9,11) >= 41 ) && (cf.substring(9,11) <= 71 )) ) )
	{
		//alert( "Il codice fiscale non è valido.\n");
		return false;	
	}
	
	//1 lettera
	if( lettere.indexOf( cf.charAt(11) ) == -1 )
	{
		//alert( "Il codice fiscale contiene un carattere non valido `" +
		//	cf.charAt(i) +
		//	"` in posizione 12.\nI caratteri validi in quella posizione sono lettere.\n");
		return false;	
	}
	
	//3 cifre
	for (i = 12; i < 15; i++)
	{
		if( cifre.indexOf( cf.charAt(i) ) == -1 )
		{
			//alert( "Il codice fiscale contiene un carattere non valido `" +
			//	cf.charAt(i) +
			//	"` in posizione " + (i+1) + ".\nI caratteri validi in quella posizione sono cifre.\n");
			return false;	
		}
	}
	
	//1 lettera
	if( lettere.indexOf( cf.charAt(15) ) == -1 )
	{
		//alert( "Il codice fiscale contiene un carattere non valido `" +
		//	cf.charAt(i) +
		//	"` in posizione 16.\nI caratteri validi in quella posizione sono lettere.\n");
		return false;	
	}

	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		{
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
		}
	for( i = 0; i <= 14; i += 2 )
		{
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
		}
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
	{
		//alert("Il codice fiscale non è corretto.\n");
		return false;
	}

	return true;
}
