<!--//
	function makevisible(cur,which){
	strength=(which==0)? 1 : 0.2
	
	if (cur.style.MozOpacity)
	cur.style.MozOpacity=strength
	else if (cur.filters)
	cur.filters.alpha.opacity=strength*100
	}
	
	
	function colore(id_colore)
	{
		var id_colore = document.getElementById(id_colore);
		id_colore.style.filter = false;
	}
	function opaco(id_opaco)
	{
		var id_opaco = document.getElementById(id_opaco);
		id_opaco.style.filter = "gray()";
	}
	
	function colore1(id_colore)
	{
		var id_colore = document.getElementById(id_colore);
		id_colore.style.filter = "fliph()";
		
	}
	function opaco1(id_opaco)
	{
		var id_opaco = document.getElementById(id_opaco);
		id_opaco.style.filter = false;
	}


	function contr(obj, blReturnValue) {
		var ERRORE = ""
		
		for (key=0;key<obj.length;key++) {
			if (obj[key].name.toUpperCase().indexOf("OBL") >= 0 && !Disabled(obj[key])) ERRORE += isCompulsory(obj[key]);//campo obbligatorio
			if (obj[key].name.toUpperCase().indexOf("EML") >= 0 && obj[key].value != "") ERRORE += isEmail(obj[key]);//campo email
			if (obj[key].name.toUpperCase().indexOf("WEB") >= 0 && obj[key].value != "") ERRORE += isSite(obj[key]);//campo sito
			if (obj[key].name.toUpperCase().indexOf("DTE") >= 0 && obj[key].value != "") ERRORE += isData(obj[key]);//campo data
			if (obj[key].name.toUpperCase().indexOf("NMB") >= 0 && obj[key].value != "") ERRORE += isNumber(obj[key]);//campo numerico intero positivo
			if (obj[key].name.toUpperCase().indexOf("CCP") >= 0 && obj[key].value != "") ERRORE += isCap(obj[key]);//campo CAP
			if (obj[key].name.toUpperCase().indexOf("TCL") >= 0 && obj[key].value != "") ERRORE += isCell(obj[key]);//campo cellulare
			if (obj[key].name.toUpperCase().indexOf("LNG") >= 0 && obj[key].value != "") ERRORE += isSignedDouble(obj[key]);//campo numerico decimale positivo/negativo
			if (obj[key].name.toUpperCase().indexOf("UID") >= 0 && obj[key].value != "") ERRORE += isUserID(obj[key]);//campo userID
			if (obj[key].name.toUpperCase().indexOf("PWD") >= 0 && obj[key].value != "") ERRORE += isPassword(obj[key]);//campo password
		}
		
		if (blReturnValue == false){
			if (ERRORE == "") return true;
		
			alert("ATTENZIONE!\n" + ERRORE + "\n\nControlla i campi del modulo.");
			return false;
		}
		else{
			return ERRORE;
		}
		
	}
	function Disabled(obj){
		var z = obj.disabled;
		
		if(z==true || z==false){
			return obj.disabled;
		}
		else{//Netscape 4 non ha la proprietà disabled
			obj.disabled = false;
			return obj.disabled;
		}
	}
	
	function trimstr(str){
		while (str != (tmpstr=str.replace(/ +/,""))){
			str = tmpstr;
		}
		return str;
	}
	
	function FieldName(obj){
		var x = obj.name;
		x = x.replace("OBL", "");
		x = x.replace("WEB", "");
		x = x.replace("NMB", "");
		x = x.replace("DTE", "");
		x = x.replace("CRC", "");
		x = x.replace("HDN", "");
		x = x.replace("EML", "");
		x = x.replace("CCP", "");
		x = x.replace("LNG", "");
		x = x.replace("UID", "");
		x = x.replace("PWD", "");
		x = x.charAt(0).toUpperCase() + x.substring(1, x.length);
		return x;
	}
		
	function isCompulsory(obj){
		nomecampo=FieldName(obj).replace("_"," ");
		//if ((obj.type=="text"||obj.type=="textarea"||obj.type=="password") && obj.value=='') return "\n''"+FieldName(obj)+"'' è un campo obbligatorio.\n";
		if ((obj.type=="text"||obj.type=="textarea"||obj.type=="password") && obj.value=='') return "\n''"+nomecampo+"'' è un campo obbligatorio.\n";
		
		if (obj.type.toLowerCase().indexOf("select")>=0 && obj.selectedIndex==0) return "\n Nel menu ''"+nomecampo+"'' è obbligatorio selezionare qualcosa.\n";
		//if (obj.type.toLowerCase().indexOf("select")>=0 && obj.selectedIndex==0) return "\n Nel menu ''"+FieldName(obj)+"'' è obbligatorio selezionare qualcosa.\n";
		return "";
	}
	
	function isData(obj){
		nomecampo=FieldName(obj).replace("_"," ");
		var val = trimstr(obj.value);
		var e = 0;
		obj.value=val;
		var re = new RegExp("^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$");
		var x = re.exec(val);
		
		if(x!=null){
			var dd = parseInt(RegExp.$1.replace("0", ""));
			var mm = parseInt(RegExp.$2);
			var yy = parseInt(RegExp.$3);
			var bis = 0;
			var maxg = 31;
			
			if((yy < 1753) || (yy > 10000))
				return "\n L\'anno nel campo ''" + nomecampo + "'' deve essere compreso tra 1753 e 9999.\n";
			
			if((mm < 0) || (mm > 12))
				return "\n Il mese nel campo ''" + nomecampo + "'' non è valido.\n";
			
			if(yy % 4 == 0)
				bis++;
			
			switch(mm){
				case 2 :
					maxg = 28 + bis;
					break;
				case 4 :
				case 6 :
				case 9 :
				case 11 :
					maxg--;
					break;
				default:
					break;
			}
			if((dd < 1) || (dd > maxg))
				return "\n il giorno nel campo ''" + nomecampo + "'' non è valido.\n";
			
			return "";
		}
		return "\n La data nel campo ''" + nomecampo + "'' non è valido.\n";
	}
	
	function isNumber(obj){
		nomecampo=FieldName(obj).replace("_"," ");
		var val = trimstr(obj.value);
		obj.value=val;
		if (val=="") return "";
		if (val.match(/^[0-9]*$/)==null && val!="") return "\n Il Numero nel campo ''"+nomecampo+"'' non è corretto.\n";
		return "";
	}

	function isSignedDouble(obj){
		nomecampo=FieldName(obj).replace("_"," ");
		var val = trimstr(obj.value);
		obj.value=val;
		if (val=="") return "";
		if (val.match(/^[-]{0,1}[0-9]*[,]{0,1}[0-9]*$/)==null && val!="") return "\n Il Numero nel campo ''"+nomecampo+"'' non è corretto.\n";
		return "";
	}
	
	function isEmail(obj) {
		nomecampo=FieldName(obj).replace("_"," ");
		var email = obj.value;	
		if ((tmpint = email.indexOf ('@',0)) == -1)
			return "\n La chiocciola (@) non è stata inserita nel campo ''" + nomecampo + "''.\n";
		if (tmpint==0)
			return "\n L'indirizzo e-mail non può iniziare con la chiocciola (@).\n";
		if ((tmpint2 = email.indexOf ('.',tmpint)) == -1) 
			return "\n Nel campo ''" + nomecampo + "'' è obbligatorio inserire un punto dopo la chiocciola (@).\n";
		if (tmpint2-tmpint==1)
			return "\n La sequenza dei simboli '@.' non può appartenere all'indirizzo e-mail.\n";
		if (tmpint2 == email.length-1)
			return "\n L'indirizzo e-mail del campo ''" + nomecampo + "'' non può finire con il simbolo '.'\n";		
		return "";
	}
	function isSite(obj) {
		nomecampo=FieldName(obj).replace("_"," ");
		var site = obj.value;	
		if ((tmpstart = site.indexOf ('http://',0)) == 0)
			return "\n Il prefisso http:// nel campo ''" + nomecampo + "'' non si deve inserire.\n";
		if ((tmpint = site.indexOf ('www',0)) == -1)
			return "\n Il prefisso www nel campo ''" + nomecampo + "'' non è stato inserito.\n";
		
		if ((tmpint2 = site.indexOf ('.',3)) == -1) 
			return "\n Nel campo ''" + nomecampo + "'' è obbligatorio inserire un punto dopo il www.\n";
		if (tmpint2 == site.length-1)
			return "\n L'indirizzo internet del campo ''" + nomecampo + "'' non può finire con il simbolo '.'\n";
		if (site.indexOf(" ") >= 0)
			return "\n Il campo ''" + nomecampo + "'' non può contenere spazi.\n";
		return "";
	}
	
	function isCap(obj){
		nomecampo=FieldName(obj).replace("_"," ");
		var cap = trimstr(obj.value);
		obj.value = cap;
		if(cap.match(/^[0-9]{5}$/) == null) return "\n Inserire un codice valido nel campo ''" + nomecampo + "''.\n"
		return "";
	}
	
	function isCell(obj){
		nomecampo=FieldName(obj).replace("_"," ");
		var val = trimstr(obj.value);
		obj.value=val;
		if (val=="") return "";
		if (val.match(/^[1-9]{1}[0-9]*$/)==null && val!="") return "\n Il Numero nel campo ''" + nomecampo + "'' non è corretto.\n";
		return "";
	}
	
	function isUserID(obj) {
		nomecampo=FieldName(obj).replace("_"," ");
		var strUID = obj.value;	
		if (strUID.indexOf(" ") >= 0)
			return "\n Il campo ''" + nomecampo + "'' non può contenere spazi.\n";
		return "";
	}
	
	function isPassword(obj) {
		nomecampo=FieldName(obj).replace("_"," ");
		var strPW = obj.value;	
		if (strPW.indexOf(" ") >= 0)
			return "\n Il campo ''" + nomecampo + "'' non può contenere spazi.\n";
		return "";
	}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function StartDateCheck() {
	var today = new Date();
	var day = today.getDate();
	var month = today.getMonth() + 1 ;
	var year = today.getFullYear();
	
	myf = document.form_step_3; //form_step_3 è il nome del form in questione

	mysd = myf.dal_giorno.selectedIndex; // my start Day --> DALGIORNO
	if (mysd == 0) return true;
	
	mysm = myf.dal_mese.selectedIndex;  // my start Month --> DALMESE
	if (mysm == 0) return true;
	
	mysy = myf.dal_anno.value; // my start Month --> DALANNO
	if (mysy == 0) return true;
	tmp_m = myf.dal_mese.selectedIndex; // si immagazzina la variabile mese in una var temp --- my start Month --> DALMESE
	if (tmp_m == 0) return true;
	
	tmp_y = myf.dal_anno.selectedIndex; // si immagazzina la variabile anno in una var temp --- my start Year --> DALANNO
	if (tmp_y == 0) return true;
	
	if (mysm > 12) { mysy = mysy + 1; mysm = mysm - 12; }
	
	if (mysd == 31) {
		if ((mysm == 4) || (mysm == 6) || (mysm == 9) || (mysm == 11)) mysd = 30;
	}
	if ((mysd > 29) && (mysm == 2)) mysd = 29;
	if (((mysy) %4 != 0) && (mysm == 2) && (mysd > 28)) mysd = 28;
	
	myf.dal_giorno.selectedIndex = mysd;
	
	/*myed = mysd + 1;
	myem = mysm;
	myey = mysy;
	if (myed > 31) myed = -1;
	if (myed == 31) {
		if ((myem == 4) || (myem == 6) || (myem == 9) || (myem == 11)) myed = -1;
	}
	if ((myed > 29) && (myem == 2)) myed = -1;
	if (((myey-2) %4 != 0) && (myem == 2) && (myed > 28)) myed = -1;
	if (myed == -1) { myed = 1;	if (tmp_m == 12) {tmp_m = 1; tmp_y = tmp_y + 1 } else {tmp_m = tmp_m + 1}}

	myf.al_giorno.selectedIndex = myed;
	myf.al_mese.selectedIndex = tmp_m;
	myf.al_anno.selectedIndex = tmp_y;*/
}



//-->


//CONTROLLO PARTITA IVA
function partitaIVA(sz_Codice)
   {
   var n_Val,n_Som1=0,n_Som2=0,lcv;
   if (sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0))
      return false;
   
   for (lcv=0;lcv<9;lcv+=2)
   {
      n_Val=parseInt(sz_Codice.charAt(lcv));
      n_Som1+=n_Val;
      n_Val=parseInt(sz_Codice.charAt(lcv+1));
      n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10;
   }
   n_Som2 = 10 - (n_Som1 % 10);
   n_Val=parseInt(sz_Codice.charAt(10));
   if (n_Som2==n_Val)
      return true;
   return false;
   }


//CONTROLLO CODICE FISCALE
var lung=null;
var test=null;
lettere=new Array();

//array= lettera, valore se pari, valore se dispari

lettere[0]=["A","0","1"];
lettere[1]=["B","1","0"];
lettere[2]=["C","2","5"];
lettere[3]=["D","3","7"];
lettere[4]=["E","4","9"];
lettere[5]=["F","5","13"];
lettere[6]=["G","6","15"];
lettere[7]=["H","7","17"];
lettere[8]=["I","8","19"];
lettere[9]=["J","9","21"];
lettere[10]=["K","10","2"];
lettere[11]=["L","11","4"];
lettere[12]=["M","12","18"];
lettere[13]=["N","13","20"];
lettere[14]=["O","14","11"];
lettere[15]=["P","15","3"];
lettere[16]=["Q","16","6"];
lettere[17]=["R","17","8"];
lettere[18]=["S","18","12"];
lettere[19]=["T","19","14"];
lettere[20]=["U","20","16"];
lettere[21]=["V","21","10"];
lettere[22]=["W","22","22"];
lettere[23]=["X","23","25"];
lettere[24]=["Y","24","24"];
lettere[25]=["Z","25","23"];

lettere[26]=["0","0","1"];
lettere[27]=["1","1","0"];
lettere[28]=["2","2","5"];
lettere[29]=["3","3","7"];
lettere[30]=["4","4","9"];
lettere[31]=["5","5","13"];
lettere[32]=["6","6","15"];
lettere[33]=["7","7","17"];
lettere[34]=["8","8","19"];
lettere[35]=["9","9","21"];


ConfrontoCarattereControllo=new Array();

ConfrontoCarattereControllo[0]=["A"];
ConfrontoCarattereControllo[1]=["B"];
ConfrontoCarattereControllo[2]=["C"];
ConfrontoCarattereControllo[3]=["D"];
ConfrontoCarattereControllo[4]=["E"];
ConfrontoCarattereControllo[5]=["F"];
ConfrontoCarattereControllo[6]=["G"];
ConfrontoCarattereControllo[7]=["H"];
ConfrontoCarattereControllo[8]=["I"];
ConfrontoCarattereControllo[9]=["J"];
ConfrontoCarattereControllo[10]=["K"];
ConfrontoCarattereControllo[11]=["L"];
ConfrontoCarattereControllo[12]=["M"];
ConfrontoCarattereControllo[13]=["N"];
ConfrontoCarattereControllo[14]=["O"];
ConfrontoCarattereControllo[15]=["P"];
ConfrontoCarattereControllo[16]=["Q"];
ConfrontoCarattereControllo[17]=["R"];
ConfrontoCarattereControllo[18]=["S"];
ConfrontoCarattereControllo[19]=["T"];
ConfrontoCarattereControllo[20]=["U"];
ConfrontoCarattereControllo[21]=["V"];
ConfrontoCarattereControllo[22]=["W"];
ConfrontoCarattereControllo[23]=["X"];
ConfrontoCarattereControllo[24]=["Y"];
ConfrontoCarattereControllo[25]=["Z"];

var Carattere=0;
var ValorePari=1;
var ValoreDispari=2;

function ControlloFisc(stringa){

	var SommaCaratteri=0;

	var PariDispari=null;
	
	stringa=stringa.toUpperCase();
	
	//alert(stringa);
	
	lung=stringa.length;
	
	//alert(lung);
	
	CarattereControllo=stringa.substr(lung-1,1);
	
	//alert(CarattereControllo)
	
	stringa=stringa.substring(lung-1,0);
	
	//alert(stringa);
	
	lung=stringa.length;
	
	//alert(lung);
	
	
	for (i=0; i<=lung-1; i++){
		if ((i+1)%2==0) {
			PariDispari='P'
		}
		else {
			PariDispari='D'
		}
	
		//alert(PariDispari);	
				
		temp=stringa.charAt(i);
		for (t=0; t<=35; t++){
			test=lettere[t][Carattere];
			if (temp==test){break}
		}
		
		if(PariDispari=='P')	{
			SommaCaratteri=SommaCaratteri+parseInt(lettere[t][ValorePari])
		}
		else {
			SommaCaratteri=SommaCaratteri+parseInt(lettere[t][ValoreDispari])
		}
	}
	
	Risultato=SommaCaratteri % 26;
	
	//alert(Risultato);
	
	Risultato=ConfrontoCarattereControllo[Risultato][0];
	
	//alert(Risultato);
	
	if (Risultato==CarattereControllo) {
		alert("Il Codice Fiscale inserito è corretto!")
	}
	
	else {
		alert("Il Codice Fiscale inserito è errato!")
	}
}




//CALCOLO CODICE FISCALE
var consonanti =  "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
var numeri = "0123456789";
var nn=document.layers?true:false,liv;

function inizia()
	{
	liv=nn?document.layers.livelloNN:top.frames.livelloIE;
	}

function CalcolaCodiceFiscale()
	{
	document.form_step_3.codice_fiscale.value = "Calcolo C.F. in corso...";
	with (document.form_step_3)
		 {
		 Cognome=cognome.value;
		 Nome=nome.value
		 GiornoNascita=dal_giorno.options[dal_giorno.selectedIndex].value;
		 MeseNascita=dal_mese.options[dal_mese.selectedIndex].value;
		 AnnoNascita=dal_anno.value;
 		 Sesso=sesso.options[sesso.selectedIndex].value;
		Comune=luogo.value;
		 }
	
   if (Cognome != "" && Nome != "" && Comune != "")
   {
      ComuneCalcolato=CalcolaComune(Comune);
      rc = CalcolaCognome(Cognome);
	  rn = CalcolaNome(Nome)
	  rN = CalcolaNascita(GiornoNascita, MeseNascita, AnnoNascita, Sesso);

      //var cf = rc+" "+rn+" "+rN+" "+ComuneCalcolato+" ";
		
		var cf = rc+rn+rN+ComuneCalcolato;

      cf += CalcolaK(rc+rn+rN+ComuneCalcolato);
      if (ComuneCalcolato != -1)
		  document.form_step_3.codice_fiscale.value = cf;
		else
		  document.form_step_3.codice_fiscale.value = "Comune non presente";
   }
	
	ControlloFisc(cf);
	
}

function CalcolaCognome(Cognome)
{
   var code = "";
   code = GetConsonanti(Cognome);
   if (code.length >= 3)
      code = code.substring(0, 3);
   else
   {
      code += GetVocali(Cognome).substring(0, 3 - code.length)
      if (code.length < 3)
         for (i = code.length; i < 3; i++)
            code += "X";
   }
   return code;
}

function CalcolaNome(Nome)
{
   var code = "";
   cons = GetConsonanti(Nome);
   if (cons.length > 3)
      code = cons.substring(0, 1) + cons.substring(2, 3) + cons.substring(3, 4);
   else if (cons.length == 3)
      code = cons;
   else
   {
      code = cons + GetVocali(Nome).substring(0, 3 - cons.length);
      if (code.length < 3)
         for (i = code.length; i < 3; i++)
            code += "X";
   }
   return code;
}

function GetConsonanti(Stringa)
{
   var cns = "";
   for (i = 0; i < Stringa.length; i++)
      if (consonanti.indexOf(Stringa.substring(i, i + 1)) != -1)
         cns += Stringa.substring(i, i + 1);
   return cns.toUpperCase();
}

function GetVocali(Stringa)
{
   var voc = "";
   for (i = 0; i < Stringa.length; i++)
      if (consonanti.indexOf(Stringa.substring(i, i + 1)) == -1 && Stringa.substring(i, i + 1) != " ")
         voc += Stringa.substring(i, i + 1);
   return voc.toUpperCase();
}

function CalcolaNascita(Giorno, Mese, Anno, Sesso)
{
   var code = "";
   code += Anno.substring(2, 4) + Mese;
   if (Sesso == "M")
      code += Giorno;
   else
      code += parseInt(40, 10) + parseInt(Giorno, 10);
   return code;
}

function CalcolaComune(Comune)
{
var flag = -1;

   for (i = 0; i < arrComuni.length; i++)
   {
      if(Comune.toUpperCase() == arrComuni[i][1])
      {
         flag = i;
         break;
      }
   }
   if (flag < 0)
      return -1;
   else
      return arrComuni[flag][0];            
}

function CalcolaK(Stringa)
{
   var somma = 0, k;
   var arrPari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var arrDispari = new Array(
      Array(0,1),
      Array(1,0),
      Array(2,5),
      Array(3,7),
      Array(4,9),
      Array(5,13),
      Array(6,15),
      Array(7,17),
      Array(8,19),
      Array(9,21),
      Array("A",1),
      Array("B",0),
      Array("C",5),
      Array("D",7),
      Array("E",9),
      Array("F",13),
      Array("G",15),
      Array("H",17),
      Array("I",19),
      Array("J",21),
      Array("K",2),
      Array("L",4),
      Array("M",18),
      Array("N",20),
      Array("O",11),
      Array("P",3),
      Array("Q",6),
      Array("R",8),
      Array("S",12),
      Array("T",14),
      Array("U",16),
      Array("V",10),
      Array("W",22),
      Array("X",25),
      Array("Y",24),
      Array("Z",23)
   );
   for (i = 0; i < Stringa.length; i += 2)
   {
      for (j = 0; j < arrDispari.length; j++)
      {
         if (Stringa.substring(i, i + 1).toUpperCase() == arrDispari[j][0])
         {
            somma += parseInt(arrDispari[j][1], 10);
            break;
         }
      }
   }
   for (i = 1; i < Stringa.length; i += 2)
   {
      if (isNaN(Stringa.substring(i, i + 1)))
         somma += parseInt(arrPari.indexOf(Stringa.substring(i, i + 1)), 10);
      else
         somma += parseInt(Stringa.substring(i, i + 1), 10);
   }
   k = somma % 26;
   k = arrPari.charAt(k);
   return k;
}

function numbersonly(myfield, e, dec) {
  var key;
  var keychar;

  if (window.event)
	 key = window.event.keyCode;
  else if (e)
	 key = e.which;
  else
	 return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	 return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
	 return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
	 myfield.form.elements[dec].focus();
	 return false;
  } else
	 return false;
}

