function codiceFISCALE(cfins){
   var cf = cfins.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if (!cfReg.test(cf))
      return false;
   var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
   var 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) )
      return false;
   return true;
}


function ControllaPIVA(pi){ 
	if((pi == '') || (pi == '00000000000')) return false; 
	if( pi.length != 11 ) return false; 
	validi = "0123456789"; 
	for( i = 0; i < 11; i++ ){ 
		if( validi.indexOf( pi.charAt(i) ) == -1 ) return false; 
	} 
	s = 0; 
	for( i = 0; i <= 9; i += 2 ) s += pi.charCodeAt(i) - '0'.charCodeAt(0); 
	for( i = 1; i <= 9; i += 2 ){ 
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) ); 
		if( c > 9 ) c = c - 9; 
		s += c; 
	} 
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ) return false; 
	return true;
}


function isLiteral(s) {
	s = s.toLowerCase();
	for (var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (((c < 'a') || (c > 'z')) && (c != ' ') && (c != ',') && (c != '.') && (c != '\'') && (c != '/') && (c != '\(') && (c != '\)')) return false;
	}
	return true
}

function isNumeric(s) { 
	for (var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c < '0') || (c > '9')) {return false;}
	}
	return true
}

function isAlphaNum(s) {
	for (var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((!isLiteral(c)) && (!isNumeric(c))) return false;
	}
	return true
}

function sizeIs(s,n) {
	if (s.length == n) return true; return false
}


function isEmail(s) {
	if (s != '') {	
		var chiocciola,chiocciola2,punto;
		chiocciola = s.indexOf('@');
		chiocciola2 = s.lastIndexOf('@');
		punto = s.lastIndexOf('.'); 
		s = s.toLowerCase();
		if ((chiocciola < 2) || (chiocciola2 != chiocciola) || (punto < chiocciola+4) || (s.length-punto < 3)) 
			return false;
		for (var i = 0; i < s.length; i++) {
			var c = s.charAt(i);
			if ((!isAlphaNum(c)) && (c != '@') && (c != "_")) return false;
		}
		
	}
	return true;
}

function isGGMMAAAA(s) {
	if (minAge == null) var minAge = 0;
	if (!sizeIs(s,10)) return false;
	var GG = s.substr(0,2);	
	var MM = s.substr(3,2);
	var AAAA = s.substr(6,4);
	var lRitorno=false;
	if (MM=="11" || MM=="04" || MM=="06" || MM=="09") lRitorno=(GG<"31");
	else 
		if (MM=="02") lRitorno = ((GG < "29") || ((GG == "29") && (AAAA % 4 == 0) && (AAAA % 400 == 0)));
		else
			lRitorno = (MM<"13" && GG<"32")
	return lRitorno;
}





function visualizzaOggetto(valore) {
	if (valore=='altro') {
		document.getElementById("riga_altro").style.display='';

	} else {
		document.getElementById("riga_altro").style.display='none';
	}
	
	CSBfleXcroll('testo1');
}

function visualizzaContatto(valore) {
	if (valore=='') {
		document.getElementById("riga_contatto").style.display='none';		
	} else {
		document.getElementById("riga_contatto").style.display='';		
	}
  document.getElementById("contatto_label").innerHTML = valore;	
	CSBfleXcroll('testo1');
}


function Verifica(mioform) {

		if (mioform.email.value=='') {
		alert("Attenzione!\nNon hai inserito nessuna email.");
		return false;
	}
	
		if (!isEmail(mioform.email.value)) {
		alert("Attenzione!\nIl formato del campo email non e\' corretto.");
		return false;
	}

	if (mioform.accetto[1].checked) {
		alert("Attenzione!\nE' necessario prendere visione e acconsentire l'avviso legale.");
		return false;
	}
	return true;
}


function Verifica2(mioform) {


	if (mioform.nome.value=='') {
		alert("Attenzione!\nIl campo nome e\' obbligatorio.");
		return false;
	}

	if (mioform.cognome.value=='') {
		alert("Attenzione!\nIl campo cognome e\' obbligatorio.");
		return false;
	}
	
	
	
	if (mioform.canale.value=='') {
		alert("Attenzione!\nIl campo seleziona il modo in cui vuoi essere contattato e\' obbligatorio.");
		return false;
	}	

	
	if (mioform.canale.value!='') {
		if (mioform.eventuale_contatto.value=='') {		
			alert("Attenzione!\nIl campo eventuale contatto e\' obbligatorio.");
			return false;
		}
	}
	
	if (mioform.collezione.value=='') {
		alert("Attenzione!\nIl campo collezione e\' obbligatorio.");
		return false;
	}		
	
	if (mioform.articolo.value=='') {
		alert("Attenzione!\nIl campo articolo e\' obbligatorio.");
		return false;
	}		
	
	return true;
}

