var residenza = "I";

var tipoClientidb = new Object()

tipoClientidb["impresa"] = [
	{value:"Servizi alle imprese", text:"Service Company"},
	{value:"Informatica", text:"Information Technology"}, 
	{value:"Commercio", text:"Commerce"},
	{value:"Telecomunicazioni", text:"Telecommunications"},
	{value:"Editoria/Stampa", text:"Publishing/Press"},
	{value:"Meccanica/Elettrica", text:"Mechanics/Electric"},
	{value:"Alimentare", text:"Food Industry"},
	{value:"Chimica/Farmaceutica", text:"Chemistry/Pharmaceutical"},
	{value:"Edilizia" , text:"Construction engineering"},
	{value:"Tessile/Moda" , text:"Textile/Fashion"},
	{value:"Mobili/Arredamento", text:"Furnishings"},
	{value:"Alberghi/Ristoranti", text:"Hotel/Restaurant"},
	{value:"Trasporti/Logistica", text:"Transport/Logistic"},
	{value:"Finanza", text:"Finance"},
	{value:"Altro", text:"Other"}];
tipoClientidb["professionista"] = [
	{value:"Commercialista", text:"Accountant"},
	{value:"Ragioniere", text:"CPA"},
	{value:"Notaio", text:"Notary"},	
	{value:"Avvocato", text:"Lawyer"},		
	{value:"Altro", text:"Other"}];
tipoClientidb["pubblicaAmmiCentrale"] = [];
tipoClientidb["associazioniDiCategoria"] = [];
tipoClientidb["privato"] = [];
tipoClientidb["altro"] = [];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var controlServizi=false;

//se si aggiunge un nuovo cantiere aggiungere un elemento che identifica il cantiere (sempre di 3 caratteri) nell'arrey elencoServizi
var elencoServizi = new Array("CRM","BCK","VCI","FAX","SIT");

//nell'oggetto servizio seguente, aggiungere i paramentri caratteristici del nuovo cantiere
var servizio=new Object()
servizio["CRM"] =[
	{value:"registra_campi_servizio", text:"registra_campi_servizio_crm"},
	{value:"cb", text:"cbCRM"},
	{value:"servizio", text:"servizioCRM"},	
	{value:"Software per la gestione dei clienti", text:"Software per la gestione dei clienti"},	
	{value:"checkServizio", text:"checkServizioCRM"},
	{value:"checkContratto",text:"accettoContrattoCRM"}];

servizio["BCK"] =[
	{value:"registra_campi_servizio", text:"registra_campi_servizio_backup"},
	{value:"cb", text:"cbBackup"},
	{value:"servizio", text:"servizioBackup"},	
	{value:"Backup", text:"Backup"},	
	{value:"checkServizio", text:"checkServizioBackup"},
	{value:"checkContratto",text:"accettoContrattoBackup"}];
	
servizio["VCI"] =[
	{value:"registra_campi_servizio", text:"registra_campi_servizio_voci"},
	{value:"cb", text:"cbVoci"},
	{value:"servizio", text:"servizioVoci"},	
	{value:"Voci", text:"Voci"},	
	{value:"checkServizio", text:"checkServizioVoci"},
	{value:"checkContratto",text:"accettoContrattoVoci"}];

servizio["FAX"] =[
	{value:"registra_campi_servizio", text:"registra_campi_servizio_fax"},
	{value:"cb", text:"cbFax"},
	{value:"servizio", text:"servizioFax"},	
	{value:"Fax", text:"Fax"},	
	{value:"checkServizio", text:"checkServizioFax"},
	{value:"checkContratto",text:"accettoContrattoFax"}];
	
servizio["SIT"] =[
	{value:"registra_campi_servizio", text:"registra_campi_servizio_sito"},
	{value:"cb", text:"cbSito"},
	{value:"servizio", text:"servizioSito"},	
	{value:"Sito", text:"Sito"},	
	{value:"checkServizio", text:"checkServizioSito"},
	{value:"checkContratto",text:"accettoContrattoSito"}];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function gestisciDivServizioVoci(){
	if(document.getElementById("servizioVoci").checked == false)
		nascondiDIV('alertServizioVoci');
	else
		mostraDIV('alertServizioVoci');
}


function settaAccettoContrattoVisure(val){
	document.getElementById("accettoContrattoVisure").value=val;
}

function settaAccettoContrattoVisure2(val){
	document.getElementById("accettoContrattoVisure2").value=val;
}

function settaAccettoContrattoCRM(val){
	document.getElementById("accettoContrattoCRM").value=val;
}

function settaAccettoContrattoBackup(val){
	document.getElementById("accettoContrattoBackup").value=val;
}

function settaAccettoContrattoServizio(val,nomeServizio){
	document.getElementById(nomeServizio).value=val;
}

function caricaDatiFromPortale(tipoCli,seltipo,resUte,nazioneNascita,dir,indiceProvNas,indiceProvRes,indiceProvSpe,indiceComNas,indiceComRes,indiceComSpe,promo,indietro,tipoDocumento,nazioneDocumento){
		var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    	var choice = tipoCli;
		var choiceSel2 = seltipo;
		if(choice == 'impresa'||choice == 'professionista'||choice == 'pubblicaAmmiLoc'||choice == 'pubblicaAmmiCentrale'||choice == 'associazioniDiCategoria'||choice == 'privato'){
		var db = tipoClientidb[choice];}
		else{var db='';}
		var cliChooser =document.getElementById("seltipo2");
		if (choice != "") {
			if(db.length == 0){
			     nascondi('seltipo2');
			} 
			else{
				mostra('seltipo2');
				for (var i = 0; i < db.length; i++) {
					newElem = document.createElement("option");
					newElem.text = db[i].text;
					newElem.value = db[i].value;
					cliChooser.add(newElem, where);
					if(db[i].value == seltipo)
					{
						cliChooser.selectedIndex=i+1;
					}
				}
			}
		}else{
			  nascondi('seltipo2');
		}
		if(resUte == 'E'){
			visualizzaEstero();
			if("PROPRIO" == dir){
				document.form1.dirI[0].checked = true;
				document.form1.dirI[1].checked = false; 
			}else{
	 		    document.form1.dirI[0].checked = false;
				document.form1.dirI[1].checked = true; 
			}			
		}else{
			visualizzaItaliano();
			if("PROPRIO" == dir){
				document.form1.dirI[0].checked = true;
				document.form1.dirI[1].checked = false; 
			}else{
	 		    document.form1.dirI[0].checked = false;
				document.form1.dirI[1].checked = true; 
			}
		}

		visualizzaDatiPerNazione(nazioneNascita,tipoDocumento,nazioneDocumento);
		
		
		visualizzaInputPromo();
		RicreaComuni('comnasUte' ,indiceProvNas,indiceComNas);
		RicreaComuni('comuneCliI',indiceProvRes,indiceComRes);
		RicreaComuni('comuneKitI',indiceProvSpe,indiceComSpe);
		
		if("SI" == indietro){
			if(tipoCli == 'impresa'){
				document.getElementById("campo_registra_leg_rappr").style.display="none";
				document.getElementById("registra_campi_leg_rappr").style.display="none";
				document.form1.dirI[1].checked = true;
				document.getElementById("denom_cli").value="-";
				cambiaLabel('LEGALE');
			}else{
				document.getElementById("campo_registra_leg_rappr").style.display="block";
				document.getElementById("registra_campi_leg_rappr").style.display="block";
				if(document.getElementById("denom_cli").value =="")
					{
					document.form1.dirI[0].checked = true;
					cambiaLabel('PROPRIO');
					}
				else
					{
					document.form1.dirI[1].checked = true;
				    cambiaLabel('LEGALE');
				    }
			}
		var tipoDoc=document.getElementById("tipoDocumentoUtente").value;
		if (tipoDoc != "CF"){
			mostraDIV('registra_campi_numSerie_nascita');
			nascondiDIV('registra_campi_codfis_nascita');
			}
			else
			{
			nascondiDIV('registra_campi_numSerie_nascita');
			mostraDIV('registra_campi_codfis_nascita');
			}
		}

}

function caricaDati(tipoCli,seltipo,resUte,nazioneNascita,dir,indiceProvNas,indiceProvRes,indiceProvSpe,indiceComNas,indiceComRes,indiceComSpe,indietro,checkServizioCRM,checkServizioBackup,checkServizioVoci,cciaa){
		var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    	var choice = tipoCli;
		var choiceSel2 = seltipo;
		var db = tipoClientidb[choice];
		var cliChooser =document.getElementById("seltipo2");
		if (choice != "") {
			if(db.length == 0){
			     nascondi('seltipo2');
			} 
			else{
				mostra('seltipo2');
				for (var i = 0; i < db.length; i++) {
					newElem = document.createElement("option");
					newElem.text = db[i].text;
					newElem.value = db[i].value;
					cliChooser.add(newElem, where);
					if(db[i].value == seltipo)
					{
						cliChooser.selectedIndex=i+1;
					}
				}
			}
		}else{
			  nascondi('seltipo2');
		}
		if("SI" == indietro){
			//alert(cciaa);
			document.getElementById('cciaaReg').value=cciaa;
			listaServizi('');
			//document.getElementById("denom_cli").value=denom_cli;
			var serviziChecked=new Array(checkServizioCRM,checkServizioBackup,checkServizioVoci);
			
		 	for (i=0; i< elencoServizi.length; i++){
				var servizioTemp = elencoServizi[i];
				var choice = elencoServizi[i];
				var sv = servizio[choice];
				var registra_campi_servizio=sv[0].text;
				if("checked" == serviziChecked[i]){
		 		document.getElementById(registra_campi_servizio).checked=true;
		 		}		 	
		 	}			
		 	controllaServizi();
			controllaPromo("indietro");
			var tipoDoc=document.getElementById("tipoDocumentoUtente").value;
			if (tipoDoc != "CF"){
				mostraDIV('registra_campi_numSerie_nascita');
				nascondiDIV('registra_campi_codfis_nascita');
			}
			else
			{
				nascondiDIV('registra_campi_numSerie_nascita');
				mostraDIV('registra_campi_codfis_nascita');
			}
		}
		
		
		
		if(resUte == 'E'){
			visualizzaEstero();
			if("PROPRIO" == dir){
				document.form1.dirE[0].checked = true;
				document.form1.dirE[1].checked = false; 
				document.form1.dirE[2].checked = false;
			}else if("PASSIVO" == dir){
	 		    document.form1.dirE[0].checked = false;
				document.form1.dirE[1].checked = true; 
				document.form1.dirE[2].checked = false;
			}else{
	 		    document.form1.dirE[0].checked = false;
				document.form1.dirE[1].checked = false; 
				document.form1.dirE[2].checked = true;
			}
		}else{
			visualizzaItaliano();
			if("PROPRIO" == dir){
				document.form1.dirI[0].checked = true;
				document.form1.dirI[1].checked = false; 
			}else{
	 		    document.form1.dirI[0].checked = false;
				document.form1.dirI[1].checked = true; 
			}
		}
		
		visualizzaDatiPerNazione(nazioneNascita);
		visualizzaInputPromo();
		RicreaComuni('comnasUte' ,indiceProvNas,indiceComNas);
		RicreaComuni('comuneCliI',indiceProvRes,indiceComRes);
		RicreaComuni('comuneKitI',indiceProvSpe,indiceComSpe);

}

function visualizzaInputPromo(){
	if(document.form1.promo[0].checked){
		document.getElementById("codicePromo").style.display = 'none';
		document.getElementById("noCodicePromo").style.display = 'block';
	}else{
		document.getElementById("codicePromo").style.display = 'block';
		document.getElementById("noCodicePromo").style.display = 'none';
	}
}

function caricaDatiCCIAA(tipoCli,seltipo,resUte,nazioneNascita,dir,indiceProvNas,indiceProvRes,indiceProvSpe,indiceComNas,indiceComRes,indiceComSpe){
		var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    	var choice = tipoCli;
		var choiceSel2 = seltipo;
		var db = tipoClientidb[choice];
		var cliChooser =document.getElementById("seltipo2");
		if (choice != "") {
			if(db.length == 0){
			     nascondi('seltipo2');
			} 
			else{
				mostra('seltipo2');
				for (var i = 0; i < db.length; i++) {
					newElem = document.createElement("option");
					newElem.text = db[i].text;
					newElem.value = db[i].value;
					cliChooser.add(newElem, where);
					if(db[i].value == seltipo)
					{
						cliChooser.selectedIndex=i+1;
					}
				}
			}
		}else{
			  nascondi('seltipo2');
		}
		if(resUte == 'E'){
			visualizzaEsteroCCIAA();
			if("PROPRIO" == dir){
				document.form1.dirE[0].checked = true;
				document.form1.dirE[1].checked = false; 
				document.form1.dirE[2].checked = false;
			}else if("PASSIVO" == dir){
	 		    document.form1.dirE[0].checked = false;
				document.form1.dirE[1].checked = true; 
				document.form1.dirE[2].checked = false;
			}else{
	 		    document.form1.dirE[0].checked = false;
				document.form1.dirE[1].checked = false; 
				document.form1.dirE[2].checked = true;
			}
		}else{
			visualizzaItalianoCCIAA();
			if("PROPRIO" == dir){
				document.form1.dirI[0].checked = true;
				document.form1.dirI[1].checked = false; 
			}else{
	 		    document.form1.dirI[0].checked = false;
				document.form1.dirI[1].checked = true; 
			}
		}

		visualizzaDatiPerNazione(nazioneNascita);
		
		RicreaComuni('comnasUte' ,indiceProvNas,indiceComNas);
		RicreaComuni('comuneCliI',indiceProvRes,indiceComRes);
		RicreaComuni('comuneKitI',indiceProvSpe,indiceComSpe);

}

function setTipoClienteNoServizi(chooser) {
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var cliChooser = chooser.form.elements["seltipo2"];
    while (cliChooser.options.length) {
        cliChooser.remove(0);
    }
    var choice = chooser.options[chooser.selectedIndex].value;
    if(choice == "altro"){
		 newTipoCliente = prompt ("Insert a new value for the activity:", "");
		 if (newTipoCliente != null) {
		 		document.form1.tipoCli.options[(document.form1.tipoCli.options.length)]=new Option(newTipoCliente,newTipoCliente,true,true);
		}
		document.getElementById("seltipo2").value="";
		nascondi('seltipo2');
	}else if(choice == "pubblicaAmmiCentrale" || choice == "associazioniDiCategoria" || choice == "privato" ) {
		document.getElementById("seltipo2").value="";
		nascondi('seltipo2');
		}
		else{
		var db = tipoClientidb[choice];
		newElem = document.createElement("option");
		newElem.text = "Select  type";
		newElem.value = "";
		cliChooser.add(newElem, where);
		if (choice != "") {
			if(db.length == 0){
				 document.getElementById("descSeltipo2").value="";
				 document.getElementById("seltipo2").value="";
				 nascondi('seltipo2');
				 
			} 
			else{
				mostra('seltipo2');
				for (var i = 0; i < db.length; i++) {
					newElem = document.createElement("option");
					newElem.text = db[i].text;
					newElem.value = db[i].value;
					cliChooser.add(newElem, where);
					
					
				}
				
			}
		}else{
			  document.getElementById("descSeltipo2").value="";
			  document.getElementById("seltipo2").value="";
			  nascondi('seltipo2');
		}

	}
		
	if(choice == "impresa"){
			if(document.getElementById("resUte").value=='I'){
				nascondiDIV('tipoDocImpresaEstera');
				mostraDIV('tipoDoc');
				mostraDIV('tipoDocImpresaEstera');
				nascondiDIV('tipoDoc');
			}else{
				mostraDIV('tipoDocImpresaEstera');
				nascondiDIV('tipoDoc');
			
			}
			document.getElementById("campo_registra_leg_rappr").style.display="none";
			document.getElementById("registra_campi_leg_rappr").style.display="none";
			document.form1.dirI[1].checked = true;
			document.getElementById("denom_cli").value="-";
			document.getElementById('labelImpresa').style.display='block';
			document.getElementById('labelProprio').style.display='none';
			document.getElementById('recapiti_cliente').innerHTML="Dati Impresa";
			document.getElementById('labelText16').innerHTML="Indirizzo Sede";
			cambiaLabel('LEGALE');
			
			}
	else {
			nascondiDIV('tipoDocImpresaEstera');
			mostraDIV('tipoDoc');
			document.getElementById("campo_registra_leg_rappr").style.display="block";
			document.getElementById("registra_campi_leg_rappr").style.display="block";
			document.form1.dirI[0].checked = true;
			document.getElementById("denom_cli").value="";
			document.getElementById('labelImpresa').style.display='none';
			document.getElementById('labelProprio').style.display='block';
			document.getElementById('labelText16').innerHTML="Indirizzo Residenza/Domicilio";
			document.getElementById('recapiti_cliente').innerHTML="Dati Residenza/Domicilio";
			cambiaLabel('PROPRIO');
			}
			
	option_text("tipoCli","descTipoCli");
//listaServizi('');
}

function setTipoCliente(chooser) {
	
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var cliChooser = chooser.form.elements["seltipo2"];
    while (cliChooser.options.length) {
        cliChooser.remove(0);
    }
    var choice = chooser.options[chooser.selectedIndex].value;
    if(choice == ""){
    	document.getElementById("descSeltipo2").value="";
		document.getElementById("seltipo2bis").value="";
		document.getElementById("seltipo2").value="";
		nascondi('seltipo2');
	}else if(choice == "altro"){
		 newTipoCliente = prompt ("Insert a new value for the activity:", "");
		 if (newTipoCliente != null) {
		 		document.form1.tipoCli.options[(document.form1.tipoCli.options.length)]=new Option(newTipoCliente,newTipoCliente,true,true);
		}
		document.getElementById("seltipo2bis").value="xxx";
		document.getElementById("seltipo2").value="";
		nascondi('seltipo2');
	}else if(choice == "pubblicaAmmiCentrale" || choice == "associazioniDiCategoria" || choice == "privato" ) {
		document.getElementById("seltipo2bis").value="xxx";
		document.getElementById("seltipo2").value="";
		nascondi('seltipo2');
		}
		else{
		var db = tipoClientidb[choice];
		newElem = document.createElement("option");
		newElem.text = "Scegli area";
		newElem.value = "";
		cliChooser.add(newElem, where);
		if (choice != "") {
			if(db.length == 0){
				 document.getElementById("descSeltipo2").value="";
				 document.getElementById("seltipo2bis").value="";
				 document.getElementById("seltipo2").value="";
				 nascondi('seltipo2');
				 
			} 
			else{
				mostra('seltipo2');
				for (var i = 0; i < db.length; i++) {
					newElem = document.createElement("option");
					newElem.text = db[i].text;
					newElem.value = db[i].value;
					cliChooser.add(newElem, where);
				}
			}
		}else{
			  document.getElementById("descSeltipo2").value="";
			  document.getElementById("seltipo2bis").value="";
			  document.getElementById("seltipo2").value="";
			  nascondi('seltipo2');
		}
	}
	
	option_text("tipoCli","descTipoCli");
	
	listaServizi('');
	
	if(choice != "impresa")	{
		nascondiDIV('tipoDocImpresaEstera');
		mostraDIV('tipoDoc');
		document.getElementById('labelText16').innerHTML="Indirizzo Residenza/Domicilio";
		document.getElementById('recapiti_cliente').innerHTML="Dati Residenza/Domicilio";
		document.form1.dirI[0].checked = true;
		document.getElementById("denom_cli").value="";
		cambiaLabel('PROPRIO');
	}else{
		if(document.getElementById("resUte").value=='I'){
			nascondiDIV('tipoDocImpresaEstera');
			mostraDIV('tipoDoc');
			mostraDIV('tipoDocImpresaEstera');
			nascondiDIV('tipoDoc');
		}else{
			mostraDIV('tipoDocImpresaEstera');
			nascondiDIV('tipoDoc');
		}
		document.getElementById('recapiti_cliente').innerHTML="Dati Impresa";
		document.getElementById('labelText16').innerHTML="Indirizzo Sede";
		cambiaLabel('LEGALE');
	}
		
}


function datiImpresa(tipoCli){
	if(tipoCli != "impresa")	{
		nascondiDIV('tipoDocImpresaEstera');
		mostraDIV('tipoDoc');
		document.getElementById('labelText16').innerHTML="Indirizzo Residenza/Domicilio";
		document.getElementById('recapiti_cliente').innerHTML="Dati Residenza/Domicilio";
		document.form1.dirI[0].checked = true;
		document.getElementById("denom_cli").value="";
		cambiaLabel('PROPRIO');
	}else{
		if(document.getElementById("resUte").value=='I'){
			nascondiDIV('tipoDocImpresaEstera');
			mostraDIV('tipoDoc');
			mostraDIV('tipoDocImpresaEstera');
			nascondiDIV('tipoDoc');
		}else{
			mostraDIV('tipoDocImpresaEstera');
			nascondiDIV('tipoDoc');
		}
		document.getElementById('recapiti_cliente').innerHTML="Dati Impresa";
		document.getElementById('labelText16').innerHTML="Indirizzo Sede";
		cambiaLabel('LEGALE');
	}
}

function setDescSeltipo2(chooser) {
	 var seltipo2Chooser = chooser.form.elements["seltipo2"];
	 var choice = chooser.options[chooser.selectedIndex].value;
	 document.getElementById("seltipo2bis").value=choice;
	 if(choice == "Altro"){
		 newTipoCliente = prompt ("Insert a new value for the activity:", "");
		 if (newTipoCliente != null) {
				document.form1.seltipo2.options[(document.form1.seltipo2.options.length-1)]=new Option(newTipoCliente,newTipoCliente,true,true);
		}
	}
	
	//settaSeltipo2('seltipo2',chooser.options.selectedIndex);
	option_text("seltipo2","descSeltipo2");
   	listaServizi('');
   	
}

function setDescSeltipo2NoServizi(chooser) {
	 var seltipo2Chooser = chooser.form.elements["seltipo2"];
	 var choice = chooser.options[chooser.selectedIndex].value;
	 if(choice == "Altro"){
		 newTipoCliente = prompt ("Insert a new value for the activity:", "");
		 if (newTipoCliente != null) {
				document.form1.seltipo2.options[(document.form1.seltipo2.options.length-1)]=new Option(newTipoCliente,newTipoCliente,true,true);
		}
	}
	//settaSeltipo2('seltipo2',chooser.options.selectedIndex);
	option_text("seltipo2","descSeltipo2");
}

function listaServizi(click){

	if(document.getElementById("seltipo2bis").value != "" && document.getElementById("tipoCli").value !="" && document.getElementById("cciaaReg").value!="")
	{		
		document.getElementById("divServiziOnlineDisponibili").style.display="block";
		prov = document.getElementById("cciaaReg").value;
 		tipo = document.getElementById("tipoCli").value;
 		cciaaReg = document.getElementById("cciaaReg").value;
 		serviziVisibili=0;
 		
 		for (i=0; i< elencoServizi.length; i++){
			var servizioTemp = elencoServizi[i];
			var choice = elencoServizi[i];
			var sv = servizio[choice];
			var registra_campi_servizio=sv[0].text;
			var tipo_servizio=sv[2].text;
			
			if(tipo == 'impresa' && eval("document.getElementById('"+prov+servizioTemp+"')")){
			document.getElementById(registra_campi_servizio).style.display="block";
			serviziVisibili +=1;
			}else{	
				//condizione particolare: il servizio VCI deve essere visualizzato per tutti gli utenti
				if(servizioTemp == 'VCI' && eval("document.getElementById('"+prov+servizioTemp+"')")){
			 	document.getElementById(registra_campi_servizio).style.display="block";
			 	document.getElementById('apDiv7').style.display="block";
			 	serviziVisibili +=1;
			 	}
			 	else{
			 	document.getElementById(registra_campi_servizio).style.display="none";
			 	document.getElementById(tipo_servizio).checked= false;
			 	}	
			}			
	 }
 		
 		if(tipo == 'impresa'){
			document.getElementById("campo_registra_leg_rappr").style.display="none";
			document.getElementById("registra_campi_leg_rappr").style.display="none";
			document.form1.dirI[1].checked = true;
			document.getElementById("denom_cli").value="-";
		}else{
			document.getElementById("campo_registra_leg_rappr").style.display="block";
			document.getElementById("registra_campi_leg_rappr").style.display="block";
			if(document.getElementById("denom_cli").value =="")
				document.form1.dirI[0].checked = true;
			else
				document.form1.dirI[1].checked = true;
			//document.getElementById("denom_cli").value="";
		}
		
		if( click =='cciaa' || document.getElementById("PROV_RES_PV_I").value == '' || document.getElementById("comuneCliI").value == ''){
			mappaCciaaRegIntiCciaResidenza(cciaaReg);
		}
		
		if(serviziVisibili ==0) {
			document.getElementById("no_servizi").style.display="block";
			document.getElementById("bottoneControllo").style.display="none";
		}else{
			document.getElementById("no_servizi").style.display="none";
			document.getElementById("bottoneControllo").style.display="block";
		}
		
		// ross
		//document.getElementById("bottoneControllo").style.display="block";
	}else{
		document.getElementById("bottoneContinua").value="servizi";
		
		for (i=0; i< elencoServizi.length; i++){
			var servizioTemp = elencoServizi[i];
			var choice = elencoServizi[i];
			var sv = servizio[choice];
			var registra_campi_servizio=sv[0].text;
			document.getElementById(registra_campi_servizio).style.display="none";
	 }
		
		document.getElementById("divServiziOnlineDisponibili").style.display="none";
		document.getElementById("dati").style.display="none";
		document.getElementById("bottoneControllo").style.display="none";
	}
	
}

function mappaCciaaRegIntiCciaResidenza(cciaareg){
	num_option=document.getElementById('PROV_RES_PV_I').options.length;	
	for (i=0; i< num_option; i++){
	   	cciaaRes = document.getElementById('PROV_RES_PV_I').options[i].value;
	   	if(cciaareg == cciaaRes){
	   		document.getElementById('PROV_RES_PV_I').options[i].selected = true;
	   		RiempiComuni('comuneCliI',i,'proRes');
	   		document.getElementById('PROV_RES_PV_I').disabled = true;
	   		break;
	   	}
	 }
}


function controlla(){
	if(document.getElementById("bottoneContinua").value == "servizi")
 	controllaServizi();
 else
 	preCheckMail(document.getElementById("emailUte").value);

}

function controllaServizi(){
	
	var controlCheck=false;		
	for (i=0; i< elencoServizi.length; i++){
			var choice = elencoServizi[i];
			var sv = servizio[choice];
			var camp_servizio=sv[2].text;
			if(document.getElementById(camp_servizio).checked == true){
				controlCheck=true;
				break;
			}
		}
	
	if(document.getElementById("servizioVisure").checked == true || controlCheck==true ){
		document.getElementById("dati").style.display="block";
	    document.getElementById("bottoneContinua").value="tutto";
	    controlServizi=true;
	}else{
	    document.getElementById("bottoneContinua").value="servizi";
		document.getElementById("dati").style.display="none";
		alert("seleziona almeno un servizio online tra quelli disponibili");
	}
	
	
}



function setInfoTpay(chooser) {
	 var infoTpayChooser = chooser.form.elements["infoTpay"];
	 var choice = chooser.options[chooser.selectedIndex].value;
	 if(choice == "AL"){
		 newInfoTpay = prompt ("Please insert who told you about us:", "");
		 if (newInfoTpay != null) {
				document.form1.infoTpay.options[(document.form1.infoTpay.options.length-1)]=new Option(newInfoTpay,"AL",true,true);
		}
	}
	
	option_text("infoTpay","descInfoTpay");
   
}

function setTipoContatto(){
	option_text("tipoContatto","descTipoContatto");
}

function inizializza(){ 
if (document.all) { 
    
   // creo le variabili per la sintassi di IE 
   documento="document.all"; 

   /* notare le virgolette precedute dall'escape ("), 
    * che si sono rese necessarie, per mantenere inalterata 
    * la sinassi e per non incorrere in errori 
    */ 

   parA="['"; 
   parB="']"; 
   visibilita=".style.visibility"; 
   posizione=".style.position"; 
   display=".style.display"; 
   nascosto="'hidden'"; 
   visibile="'visible'"; 
} 
else if (document.layers){ //NN4 
   documento="document.layers"; 
   parA="['"; 
   parB="']"; 
   visibilita=".visibility"; 
   disply=".display"; 
   posizione=".position"; 
   nascosto="'hide'"; 
   visibile="'show'"; 
} 
else if (document.getElementById) { // Opera e NN6 
   documento="document.getElementById"; 
   parA="('"; 
   parB="')"; 
   visibilita=".style.visibility"; 
   posizione=".style.position"; 
   display=".style.display"; 
   nascosto="'hidden'"; 
   visibile="'visible'"; 
} 
} 

function nascondi(elemento) { 

/* eseguo l'istruzione tramite eval, 
    come somma di variabili */ 
inizializza();
eval(documento+parA+elemento+parB+visibilita+"="+nascosto+";"); 
} 

function mostra(elemento) { 

/* istruzione identica alla precedente, 
    soltando che rende visbile */ 
inizializza();
eval(documento+parA+elemento+parB+visibilita+"="+visibile+";"); 

} 

function controllaRadio(){

if (!document.getElementById('radio1').checked) {
		alert("To complete registration your acceptance is needed!");
		return false;
	}
	spostacheck(this.form,true); 
	
} 

/* controlla se il valore passato è un numero */

function isDigit(value) {

	return /^\d+$/.test(value);

}





/* toglie gli spazi all'inizio e alla fine di una stringa */

function trim(value) {

	return value.replace(/^\s+/,"").replace(/\s+$/,"");

}



function riempi(theform){
	if(residenza == 'I'){
		RicreaComuni('comuneKitI',theform.proRes.value,theform.comuneCliI.options.selectedIndex);
		theform.proSpe.value = theform.proRes.value;
		theform.comSpe.value = theform.comuneCliI.options.selectedIndex;
		theform.indKitI.value = theform.indCliI.value;
		theform.capKitI.value = theform.capCliI.value;
		theform.provKitI.value = theform.PROV_RES_PV_I.value;
	}else{
		theform.comuneKitE.value = theform.comuneCliE.value;
		theform.indKitE.value = theform.indCliE.value;
		theform.capKitE.value = theform.capCliE.value;
		theform.provKitE.value = theform.PROV_RES_PV_E.value;
		theform.nazKitE.value = theform.nazCliE.value;
	}
	return false;

}



function copiaMail(theform){

	theform.emailCli.value = theform.emailUte.value;

	return false;

}



function copiaCodFis(theform){

	 theform.cfImpCliI.value = theform.pivaCliI.value;

	return false;

}

function copiaCodFisUtente(theform){
	var tipoUtente = theform.descTipoCli.value;
	if(tipoUtente != "Impresa")
	      theform.cfImpCliI.value = theform.cfCli.value;
	 else
		  theform.cfImpCliI.value='';
}

function spostacheck(theform,al){
	if(residenza == "I"){
		if (theform.denom_cli.value != "" && (theform.dirI[1].checked == false)) {
			theform.dirI[0].checked = false;
			theform.dirI[1].checked = true;
			if (al)
				return false;
			else
				return true;
		} 
		
		if (theform.denom_cli.value == "" && (theform.dirI[1].checked == true)){
			theform.dirI[0].checked = true;
			theform.dirI[1].checked = false;
			if (al)
				return false;
			else
				return true;
		}
	}else{
		if (theform.denom_cli.value != "" && (theform.dirE[2].checked == false)) {
			theform.dirE[0].checked = false;
			theform.dirE[1].checked = false;
			theform.dirE[2].checked = true;
			if (al)
				return false;
			else
				return true;
		} 
		
		
	}	
}


function apriGuida() {
	window.open("/paga/html/home/help_registra.htm", "guida", "toolbar=no,resizable=yes,menubar=no,scrollbars=yes,width=800,height=500");
}

function cambia(n) 

{ 

   var nn = n.toUpperCase(); 

   document.form1.siglaProvincia.value =nn;

   b=document.form1.provnasUte.options.length; 

   trovato=false;

   for(i=0; i<b; i++) 

      if(document.form1.provnasUte.options[i].value==nn) 

	  {

	    document.form1.provnasUte.options[i].selected=true; 

		trovato=true;

	  }

   if(trovato == false)

	  document.form1.provnasUte.options[0].selected=true;

   

}

function ricopia() 

{ 

   a = document.form1.provnasUte;

   document.form1.siglaProvincia.value = a.options[a.selectedIndex].value;    

}

function cambia2(e) 

{ 

   var dd = e.toUpperCase(); 

   document.form1.siglaProvinciaKit.value =dd;

   bb=document.form1.provKit.options.length; 

   trovato2=false;

   for(i=0; i<bb; i++) 

      if(document.form1.provKit.options[i].value==dd) 

	  {

	    document.form1.provKit.options[i].selected=true; 

        trovato2=true;

	  }

   if(trovato2 == false)

	  document.form1.provKit.options[0].selected=true;

}


function cambia3(e) 

{ 

   var dd = e.toUpperCase(); 

   document.form1.siglaProvinciaRes.value =dd;

   bb=document.form1.PROV_RES_PV.options.length; 

   trovato2=false;

   for(i=0; i<bb; i++) 

      if(document.form1.PROV_RES_PV.options[i].value==dd) 

	  {

	    document.form1.PROV_RES_PV.options[i].selected=true; 

        trovato2=true;

	  }

   if(trovato2 == false)

	  document.form1.PROV_RES_PV.options[0].selected=true;

}






function ricopia2() 

{ 

   c = document.form1.provKit;

   document.form1.siglaProvinciaKit.value = c.options[c.selectedIndex].value;    

}

function ricopia3() 

{ 

 var c3 = document.getElementById('PROV_RES_PV').value;

   document.getElementById('siglaProvinciaRes').value = c3;   

   

}

function ricopia4() 

{ 

    var c4 = document.getElementById('provnasUte').value;

   document.getElementById('siglaProvincia').value = c4;    

}


function init()

{

   ricopia();

   ricopia2();

}



function cambiaU(n,tipo) 

{ 

   var a; var b;	  

   var nn = n.toUpperCase(); 

   if(tipo=="provnasUte1")

   {

     a = document.form1.provnasUte1;

	 b = document.form1.siglaProvnasUte1;

   }

   else if(tipo=="provUte1")

   {

     a = document.form1.provUte1;

	 b = document.form1.siglaProvUte1;

   }

   else if(tipo=="provnasUte2")

   {

     a = document.form1.provnasUte2;

	 b = document.form1.siglaProvnasUte2;

   }

   else if(tipo=="provUte2")

   {

     a = document.form1.provUte2;

	 b = document.form1.siglaProvUte2;

   }

   

   b.value =nn;

   bb=a.options.length; 

   trovato=false;

   for(i=0; i<bb; i++) 

      if(a.options[i].value==nn) 

	  {

	    a.options[i].selected=true; 

		trovato=true;

	  }

   if(trovato == false)

	  a.options[0].selected=true;

      

}



function ricopiaU(tipo) 

{ 

   if(tipo=="provnasUte1")

   {

     a = document.form1.provnasUte1;

	 b = document.form1.siglaProvnasUte1;

   }

   else if(tipo=="provUte1")

   {

     a = document.form1.provUte1;

	 b = document.form1.siglaProvUte1;

   }

   else if(tipo=="provnasUte2")

   {

     a = document.form1.provnasUte2;

	 b = document.form1.siglaProvnasUte2;

   }

   else if(tipo=="provUte2")

   {

     a = document.form1.provUte2;

	 b = document.form1.siglaProvUte2;

   }

      

   b.value = a.options[a.selectedIndex].value;    

}


function initU()

{

   ricopia("provnasUte1");

   ricopia("provUte1");

   ricopia("provnasUte2");

   ricopia("provUte2");

}
//michele ferrulli: visualizzazione provincia preselezionata in RegistraCli
function caricaProv()
{
	var fSGL_PRV = document.getElementById("fSGL_PRV").value;
	
	for (var i=0; i<document.getElementById('PROV').options.length;i++)
		if(document.getElementById('PROV').options[i].value == fSGL_PRV){
			document.getElementById('PROV').options[i].selected = true;
		}
}


function caricaDatiForSelect()
{
	var fSGL_PRV_NASCITA = document.getElementById("fSGL_PRV_NASCITA").value;
	var fC_STATO_NASCITA = document.getElementById("fC_STATO_NASCITA").value;	
	
	for (var i=0; i<document.getElementById('provnasUte').options.length;i++)
		if(document.getElementById('provnasUte').options[i].value == fSGL_PRV_NASCITA){
			document.getElementById('provnasUte').options[i].selected = true;
			document.getElementById("siglaProvincia").value	= fSGL_PRV_NASCITA;			
		}
		
	for (var i=0; i<document.getElementById('naznasUte').options.length;i++)
		if(document.getElementById('naznasUte').options[i].value == fC_STATO_NASCITA){
			document.getElementById('naznasUte').options[i].selected = true;
		}		
		
}

function controllaCodiceFiscale(elemento)
{
    var codfis = document.getElementById(elemento).value;
    var regexpr= new RegExp("^[A-Za-z]{6}[0-9]{2}[A-Za-z]{1}[0-9]{2}[A-Za-z]{1}[0-9]{3}[A-Za-z]{1}$" );
	
	if (!codfis.match(regexpr)){
		return ("Tax code inserted is not in a valid form");
	}else return "true"
	 
}


function ControllaCAP(dtStr){
 if (ControllaCAP2(dtStr)!="true"){
 	alert (ControllaCAP2(dtStr))
 }

}


function ControllaCAP2(dtStr){
var re5digit=new RegExp(/^\d{5}$/) //La data deve avere almeno 5 cifre

	if (!dtStr.match(re5digit)){
		return ("Please insert a valid Postal Code (5 digits)")
		
	}else return "true"

}



function ControllaPIVA(dtStr){
if (ControllaPIVA2(dtStr)!="true"){
	alert(ControllaPIVA2(dtStr))
	
}
}

function ControllaPIVA2(dtStr){
var re5digit=new RegExp(/^\d{11}$/) //La partita iva deve avere almeno 11 cifre

	if (!dtStr.match(re5digit)){
		return "Please insert a valid VAT number(11 digits)"
		
	}else return "true"

}


function ControlloNonVuoto2(valore){
if ((trim2(valore)=="")|| (valore ==" ")){
	 	return "Please fill in all requested fields!"
	 }
	 else {return "true" } 
}

function trim2(stringa)
{
while (stringa.substring(0,1) == ' ')
{
stringa = stringa.substring(1, stringa.length);
}
while (stringa.substring(stringa.length-1, stringa.length) == ' ')
{
stringa = stringa.substring(0,stringa.length-1);
}
return stringa;
}

/*Inizio check per la data..
*/

var dtCh= "/"; // non viene usato (era il separatore della data)
var minYear=1900;// minimo anno possibile
var maxYear=2100;//massimo anno possibile

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Controllo che il carattere corrente sia un numero
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // Tutti i caratteri sono numeri
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// Febraio a 28 giorni in ogni anno divisibile per 4
    // eccetto per gli anni centenari divisibili per 400
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	
	var re5digit=new RegExp(/^\d{8}$/) //La data deve avere almeno 8 cifre

	if (!dtStr.match(re5digit)){
		return "Per favore inserisci una data valida"
		
	}
	var strMonth=dtStr.substring(2,4)
	var strDay=dtStr.substring(0,2)
	var strYear=dtStr.substring(4,8)
	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return "Please insert a valid day"
		
	}
	if (strMonth.length<1 || month<1 || month>12){
		return "Please insert a valid month"

	}
	
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return "Please insert a valid year between "+minYear+" and "+maxYear
		
	}
	if ( isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return "Please insert a valid date"
	}
return "true"
}

function ValidaData(stringa){
	var dt=stringa
	if (isDate(dt.value)!="true"){
		alert(isDate(dt.value))
		dt.focus()
		return false
	}
    return true
 }


function ValidaCaptcha(stringa, baseurl){

	if(!verificaAccept())
		return false;
	var str=trim2(stringa)
	var url=baseurl
	if ( ((str=='')) || ((str ==' '))){
		alert('Please copy the Security Code to complete registration!')
		
	}else {
		impostaProviciaEsteraBlank();
		controlloCaratteriAmmessi();
		document.getElementById('form1').submit();
	}
}

/*
 *	Fine check data
*/



/**

Check EMAIL

*/

function checkMail(x)
{
if (checkMail2(x)!="true"){
alert(checkMail2(x))}
}

function preCheckMail(email){
	email=trim2(email);
	email = email.toUpperCase();
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)){
		ControllaDominioEmail.controllaDominio(email,controllaTutto);
	}else{ 
		controllaTutto("\t- The e-mail address is not in a valid form\n");
	}
}
 
/*
Ecco il Check Finale (devo "ri-checkare" tutto	)

*/ 

function cambiaColoreInput(colore){
	document.getElementById('denom_cli').style.backgroundColor=colore;
	document.getElementById('tipoCli').style.backgroundColor=colore;
	document.getElementById('seltipo2').style.backgroundColor=colore;
	document.getElementById('dtnasUte_gg').style.backgroundColor=colore;
	document.getElementById('dtnasUte_mm').style.backgroundColor=colore;
	document.getElementById('dtnasUte_yy').style.backgroundColor=colore;
	document.getElementById('cognCli').style.backgroundColor=colore;
	document.getElementById('nomeCli').style.backgroundColor=colore;
	document.getElementById('comnasUte').style.backgroundColor=colore;
	document.getElementById('indCliI').style.backgroundColor=colore;
	document.getElementById('indCliE').style.backgroundColor=colore;
	document.getElementById('cfCli').style.backgroundColor=colore;
	document.getElementById('comuneCliI').style.backgroundColor=colore;
	document.getElementById('comuneCliE').style.backgroundColor=colore;
	document.getElementById('telCli2').style.backgroundColor=colore;
	document.getElementById('faxCli2').style.backgroundColor=colore;
	document.getElementById('capCliI').style.backgroundColor=colore;
	document.getElementById('capCliE').style.backgroundColor=colore;
	document.getElementById('emailUte').style.backgroundColor=colore;
	document.getElementById('pivaCli').style.backgroundColor=colore;
	document.getElementById('cfImpCliI').style.backgroundColor=colore;
	document.getElementById('provnasUte').style.backgroundColor=colore;
	document.getElementById('naznasUte').style.backgroundColor=colore;
	document.getElementById('locnasUte').style.backgroundColor=colore;
	document.getElementById('ncf').style.backgroundColor=colore;
	document.getElementById('icf').style.backgroundColor=colore;
	document.getElementById('desc_icf').style.backgroundColor=colore;
	document.getElementById('ncf_nascita').style.backgroundColor=colore;
	document.getElementById('icf_nascita').style.backgroundColor=colore;
	document.getElementById('desc_icf_nascita').style.backgroundColor=colore;
	document.getElementById('nazCliE').style.backgroundColor=colore;
	document.getElementById('PROV_RES_PV_I').style.backgroundColor=colore;
	document.getElementById('indKitE').style.backgroundColor=colore;
	document.getElementById('indKitI').style.backgroundColor=colore;
	document.getElementById('comuneKitI').style.backgroundColor=colore;
	document.getElementById('comuneKitE').style.backgroundColor=colore;
	document.getElementById('capKitI').style.backgroundColor=colore;
	document.getElementById('provKitI').style.backgroundColor=colore;
	document.getElementById('nazKitE').style.backgroundColor=colore;
	document.getElementById('TICKET').style.backgroundColor=colore;
	document.getElementById('cellulare').style.backgroundColor=colore;
	document.getElementById('tipoDocumentoUtente').style.backgroundColor=colore;
	document.getElementById('nazioneDocumentoUtente_NOCF').style.backgroundColor=colore;
	document.getElementById('nazioneDocumentoUtente_CF').style.backgroundColor=colore;
	document.getElementById('tipoDocumentoCliente').style.backgroundColor=colore;
	document.getElementById('nazioneDocumentoCliente').style.backgroundColor=colore;
	
			
}




function controllaTutto(dominioMailIndesiderato){
cambiaColoreInput("#FFFFFF");

var errori="";
var error_bool=false;
var bottoneContinua=document.getElementById("bottoneContinua").value;
 if(controlServizi == true){
 	var controlCheck=false;		
	for (i=0; i< elencoServizi.length; i++){
			var choice = elencoServizi[i];
			var sv = servizio[choice];
			var camp_servizio=sv[2].text;
			if(document.getElementById(camp_servizio).checked == true){
				controlCheck=true;
				break;
			}
		}
 	
	if(document.getElementById("servizioVisure").checked == false && controlCheck == false){
		errori +="\t- Please select at least an online service among the available ones\n";
		if(document.getElementById("servizioVisure").checked == false){
			document.getElementById("cbVisure").style.backgroundColor="#FFFFCC";
		}
		
		for (i=0; i< elencoServizi.length; i++){
			var choice = elencoServizi[i];
			var sv = servizio[choice];
			var camp_servizio=sv[2].text;
			var cb_servizio=sv[1].text;
			if(document.getElementById(camp_servizio).checked == false){
			document.getElementById(cb_servizio).style.backgroundColor="#FFFFCC";
			}
		}		
		error_bool=true;
	}
	
	}
	if (document.getElementById('tipoCli').value == ''){
		errori +="\t- Select a valid client type.\n"
		errori +="\t- Select an area for the client type.\n"
		document.getElementById('tipoCli').style.backgroundColor="#FFFFCC";
		document.getElementById('seltipo2').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if(document.getElementById('tipoCli').value == 'impresa' || document.getElementById('tipoCli').value == 'professionista' ){
	var cliChooser = document.getElementById('seltipo2');
    var numOpt =cliChooser.options.length;
    if (numOpt != 1 && document.getElementById('seltipo2').value==''){
		errori +="\t- Select an area for the client type.\n"
		document.getElementById('seltipo2').style.backgroundColor="#FFFFCC";
		error_bool=true
	}}
	if (document.form1.promo[1].checked == true && ControlloNonVuoto2(document.getElementById('TICKET').value)!="true" ) {
		errori +="\t- Insert promotional code\n"
		document.getElementById('TICKET').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (ControlloNonVuoto2(document.getElementById('cognCli').value)!="true" ) {
		errori +="\t- Insert Second name\n"
		document.getElementById('cognCli').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (ControlloNonVuoto2(document.getElementById('cognCli').value)!="false"  && !controllaCampiCaratteriStrani(document.getElementById('cognCli').value)) {
		errori +="\t- Insert a valid second name\n"
		document.getElementById('cognCli').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (ControlloNonVuoto2(document.getElementById('nomeCli').value)!="true" ) {
		errori +="\t- Insert the name\n"
		document.getElementById('nomeCli').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (ControlloNonVuoto2(document.getElementById('nomeCli').value)!="false"  && !controllaCampiCaratteriStrani(document.getElementById('nomeCli').value)) {
		errori +="\t- Insert a valid Name\n"
		document.getElementById('cognCli').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	var data = document.getElementById('dtnasUte_gg').value + document.getElementById('dtnasUte_mm').value +document.getElementById('dtnasUte_yy').value
	if (isDate(data)!="true"){
		errori +="\t- Insert a valid date of birth\n"
			document.getElementById('dtnasUte_gg').style.backgroundColor="#FFFFCC";
			document.getElementById('dtnasUte_mm').style.backgroundColor="#FFFFCC";
			document.getElementById('dtnasUte_yy').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (document.getElementById('naznasUte').value == "") {
		errori +="\t- Select the birth country\n"
		document.getElementById('naznasUte').style.backgroundColor="#FFFFCC";
		error_bool=true
	}else if (document.getElementById('naznasUte').value == "IT"){
		
		if (document.getElementById('provnasUte').value == "") {
			errori +="\t- Select the province of birth\n"
			document.getElementById('provnasUte').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		if (document.getElementById('comnasUte').value =='' ) {
			errori +="\t- Insert the municipality of birth\n"
			document.getElementById('comnasUte').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		if (document.getElementById('tipoDocumentoUtente').value == "") {
			errori +="\t- Select the document type\n"
			document.getElementById('tipoDocumentoUtente').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if ( document.getElementById('tipoDocumentoUtente').value == 'CF' && document.getElementById('nazioneDocumentoUtente_CF').value == "") {
			errori +="\t- Select the Release Country\n"
			document.getElementById('nazioneDocumentoUtente_CF').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if ( document.getElementById('tipoDocumentoUtente').value != "CF" && document.getElementById('nazioneDocumentoUtente_NOCF').value == "") {
			errori +="\t- Select the Release Country\n"
			document.getElementById('nazioneDocumentoUtente_NOCF').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
			
		if ( document.getElementById('tipoDocumentoUtente').value =='CF' && (ControlloNonVuoto2(document.getElementById('cfCli').value)!="true")) {
			errori +="\t- Insert a Tax code\n"
			document.getElementById('ncf_nascita').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if (document.getElementById('tipoDocumentoUtente').value =='CF' && (ControlloNonVuoto2(document.getElementById('cfCli').value)=="true") && controllaCodiceFiscale('cfCli')!= "true") {
			errori +="\t- Insert a valid Tax code\n"
			document.getElementById('cfCli').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		
		if ( document.getElementById('tipoDocumentoUtente').value!='CF' && (ControlloNonVuoto2(document.getElementById('ncf_nascita').value)!="true")) {
			errori +="\t- Insert a valid document number\n"
			document.getElementById('ncf_nascita').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
	}else{
		if (ControlloNonVuoto2(document.getElementById('locnasUte').value)!="true" ) {
			errori +="\t- Insert the municipality of birth\n"
			document.getElementById('locnasUte').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if (document.getElementById('tipoDocumentoUtente').value == "") {
			errori +="\t- Select the document type\n"
			document.getElementById('tipoDocumentoUtente').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		if ( document.getElementById('tipoDocumentoUtente').value == "CF" && document.getElementById('nazioneDocumentoUtente_CF').value == "") {
			errori +="\t- Select the Release Country\n"
			document.getElementById('nazioneDocumentoUtente_CF').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if ( document.getElementById('tipoDocumentoUtente').value != "CF" && document.getElementById('nazioneDocumentoUtente_NOCF').value == "") {
			errori +="\t- Select the Release Country\n"
			document.getElementById('nazioneDocumentoUtente_NOCF').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if ( document.getElementById('tipoDocumentoUtente').value =='CF' && (ControlloNonVuoto2(document.getElementById('cfCli').value)!="true")) {
			errori +="\t- Insert a Tax Code\n"
			document.getElementById('cfCli').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if ( document.getElementById('tipoDocumentoUtente').value =='CF' && (ControlloNonVuoto2(document.getElementById('cfCli').value)=="true") && controllaCodiceFiscale('cfCli')!="true"  ) {
			errori +="\t- Insert a valid Tax Code\n"
			document.getElementById('cfCli').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
		
		if ( document.getElementById('tipoDocumentoUtente').value!='CF' && (ControlloNonVuoto2(document.getElementById('ncf_nascita').value)!="true")) {
			errori +="\t- Insert the document number\n"
			document.getElementById('ncf_nascita').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
				
		if ( (ControlloNonVuoto2(document.getElementById('ncf_nascita').value)!="false")&& !isAlfanumerico(document.getElementById('ncf_nascita').value)) {
			errori +="\t- Insert a valid document number\n"
			document.getElementById('ncf_nascita').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
	}

	if (document.form1.dirI[1].checked == true &&  ControlloNonVuoto2(document.getElementById('denom_cli').value)!="true" ) {
		errori +="\t- Inserty Enterprise/Company\n"
		document.getElementById('denom_cli').style.backgroundColor="#FFFFCC";
		error_bool=true
	}

	if ((residenza == "I") && ControlloNonVuoto2(document.getElementById('indCliI').value)!="true"  ) {
		errori +="\t- Insert the domicile address \n"
		document.getElementById('indCliI').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "I") && (ControlloNonVuoto2(document.getElementById('indCliI').value)!="false") && !controllaCampiCaratteriStraniIndirizzo(document.getElementById('indCliI').value )) {
		errori +="\t- Insert a valid domicile address\n"
		document.getElementById('indCliI').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "E") && ControlloNonVuoto2(document.getElementById('indCliE').value)!="true" ) {
		errori +="\t- Insert the domicile address\n"
		document.getElementById('indCliE').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "E") && (ControlloNonVuoto2(document.getElementById('indCliE').value)!="false") && !controllaCampiCaratteriStraniIndirizzo(document.getElementById('indCliE').value )) {
		errori +="\t- Insert a valid domicile address\n"
		document.getElementById('indCliE').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "I") && ControllaCAP2(document.getElementById('capCliI').value)!="true"){
		errori +="\t- Insert a valid postal code\n"
		document.getElementById('capCliI').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "E") && ControlloNonVuoto2(document.getElementById('capCliE').value)!="true" ) {
		errori +="\t- Insert the postal code\n"
		document.getElementById('capCliE').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "E") && isNaN(document.getElementById('capCliE').value)) {
		errori +="\t- Insert a valid postal code\n"
		document.getElementById('capCliE').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "I") && document.getElementById('comuneCliI').value =="" ) {
		errori +="\t- Insert domicile municipality\n"
		document.getElementById('comuneCliI').style.backgroundColor="#FFFFCC";
		error_bool=true
	}else{
		comuneC = document.getElementById('comuneCliI').value;
		var comuneResidenza = comuneC.replace(/[\']/g,"%");
	}
	if ((residenza == "E") && ControlloNonVuoto2(document.getElementById('comuneCliE').value)!="true" ) {
		errori +="\t- Insert the official address\n"
		document.getElementById('comuneCliE').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
		
	if ((residenza == "I") && document.getElementById('PROV_RES_PV_I').value == "" ) {
		errori +="\t- Select the province\n"
		document.getElementById('PROV_RES_PV_I').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "E") && document.getElementById('nazCliE').value == "" ) {
		errori +="\t- Select the country\n"
		document.getElementById('nazCliE').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "I") && ControlloNonVuoto2(document.getElementById('pivaCliI').value)=="true" && ControllaPIVA2(document.getElementById('pivaCliI').value) !="true") {
		errori +="\t- Insert a valid Vat number\n"
		document.getElementById('pivaCliI').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "E") && document.getElementById('tipoDocumentoCliente').value == "" ) {
		errori +="\t- Select the document type\n"
		document.getElementById('tipoDocumentoCliente').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if ((residenza == "E") && document.getElementById('nazioneDocumentoCliente').value == "" ) {
		errori +="\t- Select the document release country\n"
		document.getElementById('nazioneDocumentoCliente').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	
	if(residenza == 'I'){
		var cod = trim(document.getElementById('cfImpCliI').value);
		if (cod.length == 16){
			if (controllaCodiceFiscale('cfImpCliI')!="true") {
				errori +="\t- Insert a valid tax code (customer official address)\n"
				document.getElementById('cfImpCliI').style.backgroundColor="#FFFFCC";
				error_bool=true
			}
		}
		else if(cod.length == 11)
		{
			if (ControllaPIVA2(cod)!="true") {
				errori +="\t- Insert a valid tax code (customer official address)\n"
				document.getElementById('cfImpCliI').style.backgroundColor="#FFFFCC";
				error_bool=true
			}
		}
		else{
			errori +="\t- Insert a valid tax code (customer official address)\n"
			document.getElementById('cfImpCliI').style.backgroundColor="#FFFFCC";
			error_bool=true
		}
	}else{
		if ((ControlloNonVuoto2(document.getElementById('ncf').value)!="true")) {
		errori +="\t- Insert official document number\n";
		document.getElementById('ncf').style.backgroundColor="#FFFFCC";
		error_bool=true
		}
		if ( (ControlloNonVuoto2(document.getElementById('ncf').value)!="false")&& !isAlfanumerico(document.getElementById('ncf').value)) {
			errori +="\t- Insert a valid official document number\n"
			document.getElementById('ncf').style.backgroundColor="#FFFFCC";
			error_bool=true
		}

	}

	if (ControlloNonVuoto2(document.getElementById('telCli2').value)!="true" ) {
		errori +="\t- Insert telephone number\n"
		document.getElementById('telCli2').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (isNaN(document.getElementById('telCli2').value)) {
		errori +="\t- Insert a valid telephone number\n"
		document.getElementById('telCli2').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (isNaN(document.getElementById('faxCli2').value)) {
		errori +="\t- Insert a valid fax number\n"
		document.getElementById('faxCli2').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	if (isNaN(document.getElementById('cellulare').value)) {
		errori +="\t- Insert a valid mobile number\n"
		document.getElementById('cellulare').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	
	ritornoMail = dominioMailIndesiderato;
	if (  ritornoMail !="true"){
		errori +=ritornoMail;
		document.getElementById('emailUte').style.backgroundColor="#FFFFCC";
		error_bool=true
	}
	
	
	
	
	if (error_bool){
	alert ("We are sorry, you need to fill the following fields to proceed with registration:\n"+errori)
	}
	else{
		riempi(document.form1);
		if(	residenza == 'I'){
			  radI = document.form1.dirI;
			  val_radI = "";
			  for(i=0; i < radI.length; i++) {
				if(radI[i].checked) {
					val_radI =  radI[i].value;
					break;
				}
			  }
			  document.getElementById('dir').value = val_radI;
			  document.getElementById('indCli').value = document.getElementById('indCliI').value
			  document.getElementById('capCli').value = document.getElementById('capCliI').value
			  //document.getElementById('comuneCli').value = document.getElementById('comuneCliI').value
			  document.getElementById('comuneCli').value = comuneResidenza;
			  document.getElementById('nazCli').value = document.getElementById('nazCliI').value
			  document.getElementById('descNazCli').value = 'ITALY';
			  document.getElementById('siglaProvinciaRes').value = document.getElementById('PROV_RES_PV_I').value
			  document.getElementById('PROV_RES_PV').value = document.getElementById('PROV_RES_PV_I').value
			  document.getElementById('pivaCli').value = document.getElementById('pivaCliI').value
			  document.getElementById('cfImpCli').value = document.getElementById('cfImpCliI').value
			  document.getElementById('indKit').value = document.getElementById('indKitI').value
			  document.getElementById('capKit').value = document.getElementById('capKitI').value
			  document.getElementById('comuneKit').value = document.getElementById('comuneKitI').value
			  document.getElementById('nazKit').value = document.getElementById('nazKitI').value
			  document.getElementById('siglaProvinciaKit').value = document.getElementById('provKitI').value
			  document.getElementById('provKit').value = document.getElementById('provKitI').value
			  document.getElementById('tipoDocumentoCliente').value = 'CF';
			  document.getElementById('nazioneDocumentoCliente').value = 'IT';

		}else{
			  
			  radE = document.form1.dirE;
			  val_radE = "";
			  for(i=0; i < radE.length; i++) {
				if(radE[i].checked) {
					val_radE =  radE[i].value;
					break;
				}
			  }
			  document.getElementById('dir').value = val_radE;
			  document.getElementById('indCli').value = document.getElementById('indCliE').value
			  document.getElementById('capCli').value = document.getElementById('capCliE').value
			  document.getElementById('comuneCli').value = document.getElementById('comuneCliE').value
			  document.getElementById('nazCli').value = document.getElementById('nazCliE').value
			  option_text('nazCliE','descNazCli');
			  document.getElementById('siglaProvinciaRes').value = document.getElementById('siglaProvinciaResE').value
			  document.getElementById('PROV_RES_PV').value = document.getElementById('PROV_RES_PV_E').value
			  document.getElementById('cfImpCli').value = document.getElementById('ncf').value
		      document.getElementById('indKit').value = document.getElementById('indKitE').value
			  document.getElementById('capKit').value = document.getElementById('capKitE').value
			  document.getElementById('comuneKit').value = document.getElementById('comuneKitE').value
			  document.getElementById('nazKit').value = document.getElementById('nazKitE').value
			  document.getElementById('siglaProvinciaKit').value = document.getElementById('siglaProvinciaKitE').value
			  document.getElementById('provKit').value = document.getElementById('provKitE').value
		}
		option_text('tipoCli','descTipoCli');
		var tipoCliTmp=document.getElementById('tipoCli').value;
		if(tipoCliTmp=='impresa' || tipoCliTmp=='professionista'){
			document.getElementById('seltipo2').value=document.getElementById('seltipo2').value;
			option_text('seltipo2','descSeltipo2');
		}
		option_text('naznasUte','descNaznasUte');
		
		if(document.getElementById('tipoDocumentoUtente').value == "CF")
			{
				option_value('nazioneDocumentoUtente_CF','nazioneDocumentoUtente');
				option_text('nazioneDocumentoUtente_CF','descNazioneDocumentoUtente');
			}else{
				option_value('nazioneDocumentoUtente_NOCF','nazioneDocumentoUtente');
				option_text('nazioneDocumentoUtente_NOCF','descNazioneDocumentoUtente');
		}
		option_text('tipoDocumentoUtente','descTipoDocumentoUtente');
		
		
		
		if(residenza == "E"){
			if(document.getElementById('tipoCli').value == 'impresa'){
				select = document.getElementById('tipoDocumentoCliente');
				for (var i = 0; i < select.options.length; i++) {
					if (select.options[i].text == 'Serial Number') {
						select.options[i].selected=true;
						break;
					}	
				}
				document.getElementById('descTipoDocumentoCliente').value ='Serial Number';
			}else {
				option_text('tipoDocumentoCliente','descTipoDocumentoCliente');
			}
		option_text('nazioneDocumentoCliente','descNazioneDocumentoCliente');
		}
		document.getElementById('dtnasUte').value = document.getElementById('dtnasUte_gg').value + document.getElementById('dtnasUte_mm').value +document.getElementById('dtnasUte_yy').value;
		document.getElementById('siglaProvincia').value = document.getElementById('provnasUte').value
		
		
		if( document.getElementById('portale').value == 'no' && document.form1.modReg[0].checked){
			option_text('cod_agente','descCodAgente');
		}
		
		
			  

		
		document.getElementById('form1').submit();
	}


}

function replaceApiceToPercento(elemento)
   {
   var w = document.getElementById(elemento).value;
   var ww = w.replace(/[\']/g, '%');
   document.getElementById(elemento).value =  ww;
   
}

function option_text(elemento,descElemento)
   {
   var w = document.getElementById(elemento).selectedIndex;
   var selected_text = document.getElementById(elemento).options[w].text;
   selected_text = selected_text.replace(/[\']/g,"%");
   document.getElementById(descElemento).value =  selected_text;
}

function option_value(elemento,descElemento)
   {
   var w = document.getElementById(elemento).selectedIndex;
   var selected_text = document.getElementById(elemento).options[w].value;
   document.getElementById(descElemento).value =  selected_text;
}

function verificaAccept(){
	
	var controlCheck=false;		
	for (i=0; i< elencoServizi.length; i++){
			var choice = elencoServizi[i];
			var sv = servizio[choice];
			var camp_servizio=sv[5].text;
			if(document.getElementById(camp_servizio).value == 'no'){
				controlCheck=true;
				break;
			}
		}
		
	if (document.getElementById('accettoContrattoVisure').value == 'no' || document.getElementById('accettoContrattoVisure2').value == 'no' || controlCheck == true){
		alert("To continue with registration your acceptance of  contractual clauses is needed");
		return false;
	}
	else{
	    if(document.getElementById('TICKET').value != '' && document.getElementById('isTicketValidate').value != 'valido'){
			if (confirm("The promotional code is not valid. To take advantage of promotion click on 'Reject' and go back to previous page to correct the code, otherwise to continue with registration click on 'OK'"))
			{
				return true;
			}else{
				return false;
			}
		}else{			
			return true;
		}
	}
	
/*	if (document.getElementById('accettoContrattoVisure').value == 'no' || document.getElementById('accettoContrattoVisure2').value == 'no' || document.getElementById('accettoContrattoCRM').value == 'no' || document.getElementById('accettoContrattoBackup').value == 'no' || document.getElementById('accettoContrattoVoci').value == 'no'){
		alert("Per proseguire è necessario accettare le condizioni contrattuali");
		return false;
	}
	else{
	    if(document.getElementById('TICKET').value != '' && document.getElementById('isTicketValidate').value != 'valido'){
			if (confirm("Il codice promozione indicato non è valido. Per usufruire della promozione clicca su 'Annulla' e torna alla pagina precedente per correggere il codice, in caso contrario per continuare la registrazione clicca su 'OK'"))
			{
				return true;
			}else{
				return false;
			}
		}else{			
			return true;
		}
	}*/
}

function carica_desc_icf_nascita(id_desc){
	id_desc = id_desc.toUpperCase();
	document.getElementById('icf_nascita').value = id_desc;
    num_option = document.getElementById('desc_icf_nascita').options.length;
	esiste = "no";
	for(a=0;a<num_option;a++){
		if(document.getElementById('desc_icf_nascita').options[a].value==id_desc){
			document.getElementById('desc_icf_nascita').options[a].selected = true;
			esiste = "si";
			break;
		}
	}
	if(esiste == "no" ){
		alert("Invalid Country Code"); 
		document.getElementById('icf_nascita').value = "";
		document.getElementById('icf_nascita').style.backgroundColor="#FFFFCC";
		document.getElementById('desc_icf_nascita').options[0].selected = true;
	}
	
}

function carica_icf_nascita(){
    index= document.getElementById('desc_icf_nascita').options.selectedIndex;
	val= document.getElementById('desc_icf_nascita').options[index].value;
	val = val.toUpperCase();
    document.getElementById('icf_nascita').value=val;
	
}





function carica_desc_icf(id_desc){
	id_desc = id_desc.toUpperCase();
	document.getElementById('icf').value = id_desc;
    num_option = document.getElementById('desc_icf').options.length;
	esiste = "no";
	for(a=0;a<num_option;a++){
		if(document.getElementById('desc_icf').options[a].value==id_desc){
			document.getElementById('desc_icf').options[a].selected = true;
			esiste = "si";
			break;
		}
	}
	if(esiste == "no" ){
		alert("Invalid Country Code"); 
		document.getElementById('icf').value = "";
		document.getElementById('icf').style.backgroundColor="#FFFFCC";
		document.getElementById('desc_icf').options[0].selected = true;
	}
	
}

function carica_icf(){
    index= document.getElementById('desc_icf').options.selectedIndex;
	val= document.getElementById('desc_icf').options[index].value;
	val = val.toUpperCase();
    document.getElementById('icf').value=val;
	
}


function mostraDIV(elemento) { 

var testo = documento+parA+elemento+parB+display+"='block';"; 
eval(testo); 
} 

function nascondiDIV(elemento) { 
var testo = documento+parA+elemento+parB+display+"='none';"; 
eval(testo); 
}

function visualizzaItaliano(){
	
	nascondiDIV('tipoDocImpresaEstera');
	nascondiDIV('tipoDoc');
	inizializza();
	residenza = "I";
	cambiaColoreInput("#FFFFFF");
	nascondiDIV('campo_registraEstero');
	nascondiDIV('registra_campi_estero_comune');
	nascondiDIV('registra_campi_estero_provnaz');
	nascondiDIV('registra_campi_estero_piva');
	nascondiDIV('registra_campi_estero_cf');
	nascondiDIV('registra_campi_estero_com_sped');
	nascondiDIV('registra_campi_estero_provnaz_sped');
	mostraDIV('registra_campi_italiano_indirizzo');
	mostraDIV('registra_campi_italiano_comune');
	mostraDIV('registra_campi_italiano_piva');
	nascondiDIV('registra_campi_estero_indirizzo');
	nascondiDIV('registra_campi_tipo_doc_cliente');
	nascondiDIV('registra_campi_nazione_rilascio_doc_cliente');
	nascondiDIV('registra_campi_estero_cf');
		

	radE = document.form1.dirE;
	val_radE = "";
	for(i=0; i < radE.length; i++) {
		if(radE[i].checked) {
			val_radE =  radE[i].value;
			break;
		}
	}
	radI = document.form1.dirI;
	for(e=0; e < radI.length; e++) {
		check="no";
		if(radI[e].value == val_radE) {
			radI[e].checked =true;
			check = "si";
			break;
		}
	}
	if(check == "no")
		radI[0].checked =true;
	
}

function visualizzaEstero(){

	
	if(document.getElementById("tipoCli").value =="impresa" ){
		mostraDIV('tipoDocImpresaEstera');
		nascondiDIV('tipoDoc');
	}else{
		nascondiDIV('tipoDocImpresaEstera');
		mostraDIV('tipoDoc');
	}
	
	inizializza();
	residenza = "E";
	cambiaColoreInput("#FFFFFF");

	
	nascondiDIV('registra_campi_italiano_provnaz_sped');
	nascondiDIV('registra_campi_italiano_ind_sped');
	nascondiDIV('registra_campi_italiano_piva');
	nascondiDIV('registra_campi_italiano_comune');
	nascondiDIV('registra_campi_italiano_indirizzo');
	nascondiDIV('campo_registraEstero');
	mostraDIV('registra_campi_estero_cf');
	nascondiDIV('registra_campi_estero_piva');
	mostraDIV('registra_campi_estero_provnaz');
	mostraDIV('registra_campi_estero_comune');
	mostraDIV('registra_campi_estero_indirizzo');
	mostraDIV('registra_campi_tipo_doc_cliente');
	mostraDIV('registra_campi_nazione_rilascio_doc_cliente');
	mostraDIV('registra_campi_estero_cf');
	
	
	
	radI = document.form1.dirI;
	val_radI = "";
	for(i=0; i < radI.length; i++) {
		if(radI[i].checked) {
			val_radI =  radI[i].value;
			break;
		}
	}
	radE = document.form1.dirE;
	val_radE = "";
	for(e=0; e < radE.length; e++) {
		if(radE[e].value == val_radI) {
			radE[e].checked =true;
			break;
		}
	}
	
}

function selectTipoContatto(){
 if(document.form1.avvisopromo[0].checked)
 	document.getElementById("tipoContatto").disabled=false;
 else
	document.getElementById("tipoContatto").disabled=true;
 
}

function visualizzaItalianoCCIAA(){
	
	inizializza();
	residenza = "I";
	cambiaColoreInput("#FFFFFF");
	
	nascondiDIV('campo_registraEstero');
	//nascondiDIV('registra_campi_estero_indirizzo');
	nascondiDIV('registra_campi_estero_comune');
	nascondiDIV('registra_campi_estero_provnaz');
	nascondiDIV('registra_campi_estero_piva');
	nascondiDIV('registra_campi_estero_cf');
	//nascondiDIV('registra_campi_estero_ind_sped');
	nascondiDIV('registra_campi_estero_com_sped');
	nascondiDIV('registra_campi_estero_provnaz_sped');
	mostraDIV('campo_registra_leg_rappr');
	mostraDIV('registra_campi_italiano_indirizzo');
	mostraDIV('registra_campi_italiano_comune');
	//mostraDIV('registra_campi_italiano_provnaz');
	mostraDIV('registra_campi_italiano_piva');
	mostraDIV('registra_campi_italiano_ind_sped');
	//mostraDIV('registra_campi_italiano_com_sped');
	mostraDIV('registra_campi_italiano_provnaz_sped');
	

	radE = document.form1.dirE;
	val_radE = "";
	for(i=0; i < radE.length; i++) {
		if(radE[i].checked) {
			val_radE =  radE[i].value;
			break;
		}
	}
	radI = document.form1.dirI;
	for(e=0; e < radI.length; e++) {
		check="no";
		if(radI[e].value == val_radE) {
			radI[e].checked =true;
			check = "si";
			break;
		}
	}
	if(check == "no")
		radI[0].checked =true;
	
}

function visualizzaEsteroCCIAA(){
	inizializza();
	residenza = "E";
	cambiaColoreInput("#FFFFFF");
	//nascondiDIV('registra_campi_italiano_com_sped');
	nascondiDIV('registra_campi_italiano_provnaz_sped');
	nascondiDIV('registra_campi_italiano_ind_sped');
	nascondiDIV('registra_campi_italiano_piva');
	//nascondiDIV('registra_campi_italiano_provnaz');
	nascondiDIV('registra_campi_italiano_comune');
	nascondiDIV('registra_campi_italiano_indirizzo');
	nascondiDIV('campo_registra_leg_rappr');
	//mostraDIV('campo_registraEstero');
	nascondiDIV('campo_registraEstero');
	mostraDIV('registra_campi_estero_cf');
	mostraDIV('registra_campi_estero_piva');
	mostraDIV('registra_campi_estero_provnaz');
	mostraDIV('registra_campi_estero_comune');
	//mostraDIV('registra_campi_estero_indirizzo');
	mostraDIV('registra_campi_estero_com_sped');
	mostraDIV('registra_campi_estero_provnaz_sped');
	//mostraDIV('registra_campi_estero_ind_sped');
	
	
	radI = document.form1.dirI;
	val_radI = "";
	for(i=0; i < radI.length; i++) {
		if(radI[i].checked) {
			val_radI =  radI[i].value;
			break;
		}
	}
	radE = document.form1.dirE;
	val_radE = "";
	for(e=0; e < radE.length; e++) {
		if(radE[e].value == val_radI) {
			radE[e].checked =true;
			break;
		}
	}
	
}

function visualizzaDatiPerNazione(nazione,tipoDocumento,nazioneDocumento) {
	
	inizializza();
	
	if(nazione == "IT"){
		nascondiDIV('registra_campi_localita_nascita');
	    nascondiDIV('registra_campi_numSerie_nascita');
		mostraDIV('registra_campi_codfis_nascita');
		mostraDIV('registra_campi_prov_nascita');
		mostraDIV('registra_campi_codfis_nascita');
		mostraDIV('registra_campi_tipo_doc_nascita');
		
	}else if(nazione == ""){
		nascondiDIV('registra_campi_prov_nascita');
	    nascondiDIV('registra_campi_localita_nascita');
	    nascondiDIV('registra_campi_numSerie_nascita');
		nascondiDIV('registra_campi_codfis_nascita');
		nascondiDIV('registra_campi_tipo_doc_nascita');
	    nascondiDIV('registra_campi_nazione_rilascio_doc_nascita');
	}else{
		nascondiDIV('registra_campi_prov_nascita');
	    mostraDIV('registra_campi_localita_nascita');
	    mostraDIV('registra_campi_tipo_doc_nascita');
		nascondiDIV('registra_campi_nazione_rilascio_doc_nascita_CF');
	    mostraDIV('registra_campi_nazione_rilascio_doc_nascita_NOCF');
	    nascondiDIV('registra_campi_numSerie_nascita');
		nascondiDIV('registra_campi_codfis_nascita');
		mostraDIV('registra_campi_numSerie_nascita');
		document.getElementById('tipoDocumentoUtente').value=tipoDocumento; 
		document.getElementById('descTipoDocumentoUtente').value =nazioneDocumento;
		document.getElementById('nazioneDocumentoUtente_NOCF').value= ""; 
		document.getElementById('descNazioneDocumentoUtente_NOCF').value= "";
	}
	
	if(tipoDocumento =="CF"){
		nascondiDIV('registra_campi_nazione_rilascio_doc_nascita_NOCF');
		mostraDIV('registra_campi_nazione_rilascio_doc_nascita_CF');
		document.getElementById('tipoDocumentoUtente').value =tipoDocumento;
		document.getElementById('nazioneDocumentoUtente_CF').value= nazioneDocumento;
		//document.getElementById('cfCli').value="";
	}else{
		nascondiDIV('registra_campi_nazione_rilascio_doc_nascita_CF');
	    mostraDIV('registra_campi_nazione_rilascio_doc_nascita_NOCF');
		document.getElementById('tipoDocumentoUtente').value =tipoDocumento;
		document.getElementById('nazioneDocumentoUtente_NOCF').value= nazioneDocumento;
		//document.getElementById('ncf_nascita').value="";
	    
	}
	
	
}

function modificaNazioneRilascioDocumentoNascita(tipoDocumento){

	if('CF' == tipoDocumento){
		nascondiDIV('registra_campi_nazione_rilascio_doc_nascita_NOCF');
		nascondiDIV('registra_campi_numSerie_nascita');
		mostraDIV('registra_campi_nazione_rilascio_doc_nascita_CF');
		mostraDIV('registra_campi_codfis_nascita');
		document.getElementById('cfCli').value="";
		
	}else{
		nascondiDIV('registra_campi_codfis_nascita');
		nascondiDIV('registra_campi_nazione_rilascio_doc_nascita_CF');
	    mostraDIV('registra_campi_nazione_rilascio_doc_nascita_NOCF');
	    mostraDIV('registra_campi_numSerie_nascita');
		document.getElementById('ncf_nascita').value="";
		
	}
	
}


function visualizzaDatiPerDocumento(documento) {
	inizializza();
	
	if(documento != 'CF'){
		document.getElementById('nazioneDocumentoUtente').selectedIndex=0;
		document.getElementById('nazioneDocumentoUtente').disabled=false;
		mostraDIV('registra_campi_numSerie_nascita');
		nascondiDIV('registra_campi_codfis_nascita');
	}else{
		var idx=document.getElementById('nazioneDocumentoUtente');
		   var dim=idx.options.length;
		   for(var k=0;k<dim;k++){
    		if(idx.options[k].text=='ITALY'){
      		idx.selectedIndex=k;
      		break;
    			}
  			}
		document.getElementById('nazioneDocumentoUtente').disabled=true;
		nascondiDIV('registra_campi_numSerie_nascita');
		mostraDIV('registra_campi_codfis_nascita');
		}
}

function controllaCampiCaratteriStrani(stringa){

	if( stringa.indexOf('|') >=0 ||	stringa.indexOf('!') >=0 ||	stringa.indexOf('\\') >=0 ||
		stringa.indexOf('"') >=0 ||	stringa.indexOf('£') >=0 ||	stringa.indexOf('%') >=0 ||
		stringa.indexOf('/') >=0 ||	stringa.indexOf('(') >=0 ||	stringa.indexOf(')') >=0 ||
		stringa.indexOf('=') >=0 ||	stringa.indexOf('?') >=0 ||	stringa.indexOf('^') >=0 ||
		stringa.indexOf('*') >=0 ||	stringa.indexOf('[') >=0 ||	stringa.indexOf(']') >=0 ||
		stringa.indexOf('#') >=0 ||	stringa.indexOf('§') >=0 ||	stringa.indexOf(';') >=0 ||
		stringa.indexOf(',') >=0 ||	stringa.indexOf(':') >=0 ||	stringa.indexOf('.') >=0 ||	
		stringa.indexOf('-') >=0 ||	stringa.indexOf('_') >=0 ||	stringa.indexOf('<') >=0 ||
		stringa.indexOf('>') >=0 ||	stringa.indexOf('°') >=0 ||	stringa.indexOf('+') >=0)
		return false;
	else
		return true;		

}

function RiempiComuni(select,indice,campo)
{
   com = eval('com'+indice);
   eval("document.getElementById('"+campo+"').value='"+indice+"'");	   
   var arrayComuni = com.split("+"); 
	with (eval("document.form1."+select))
   {
     while (options.length > 0)
       options[0]=null;
     options[0]=new Option(arrayComuni[0],'')
     for (i=1;i< arrayComuni.length;i++){
	   	options[i]=new Option(arrayComuni[i],arrayComuni[i])
     }
     options.selectedIndex=0;
   }
}

function settaComune(select,valore){
   eval("document.getElementById('"+select+"').value='"+valore+"'");	   
}

function settaSeltipo2(select,valore){
    eval("document.getElementById('"+select+"').value='"+valore+"'");	   
}
 
function settaComuneCap(select,valore,provincia,comune){
    
   eval("document.getElementById('"+select+"').value='"+valore+"'");
   indice = eval("document.getElementById('"+provincia+"').value");
   caps = eval("cap"+indice);
   capResult = caps.split("+");
   eval("document.getElementById('"+comune+"').value=capResult["+valore+"]");	   
} 
 

function RicreaComuni(select,indiceProv,indiceComune)
{
   com = eval('com'+indiceProv);
   var arrayComuni = com.split("+"); 
   with (eval("document.form1."+select))
   {
     while (options.length > 0)
       options[0]=null;
     options[0]=new Option(arrayComuni[0],'')
     
     for (i=1;i< arrayComuni.length;i++){
	   	options[i]=new Option(arrayComuni[i],arrayComuni[i])
     }
     options.selectedIndex=indiceComune;
   }
}

function visualizzaReg(){
	document.getElementById('registra_associazione').style.display='block';
	document.getElementById('box_altre_info').style.display='block';
	document.getElementById('box_ricerca_03sped').style.display='block';
	document.getElementById('registra_campi_copia_dati').style.display='block';
}

function visualizzaRegLight(){
	document.getElementById('registra_associazione').style.display='none';
	document.getElementById('box_altre_info').style.display='none';
	document.getElementById('box_ricerca_03sped').style.display='none';
	document.getElementById('registra_campi_copia_dati').style.display='none';
}

function apriHelp(page){
	window.open(page,'Help','width=600,height=300,scrollbars=yes,toolbar=no,resizable=no,menubar=no'); 
}

function cambiaLabel(tipo){

	if(tipo =="PROPRIO"){
		document.getElementById('labelImpresa').style.display='none';
		document.getElementById('labelProprio').style.display='block';
	}
	else {
		document.getElementById('labelImpresa').style.display='block';
		document.getElementById('labelProprio').style.display='none';
	}
}

  /**
  //function isAlfaNumericoSpecialChar
  //
  //@ description Restituisce una stringa che  contiene solo i caratteri
  //              _@.,&/()-+'!0123456789ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz, 
  //              con i caratteri è,é,ç,ò,ì,à,ù, sostituiti da e,e,c,o,i,a,u
  //
  //@ param       inputValue è il valore del campo da sottoporre al controllo
  //
  **/
  function isAlfaNumericoSpecialChar(inputValue)
  {
    var str=inputValue;
	var resultTmp = str.replace(/è/gi, "e");
	resultTmp = resultTmp.replace(/[é\ê\ë\É\Ê\Ë\È]/gi, "e");
	resultTmp = resultTmp.replace(/[ì\ï\î\í\Í\Î\Ï\Ì]/gi, "i");
	resultTmp = resultTmp.replace(/[ç\Ç]/gi, "c");
	resultTmp = resultTmp.replace(/[ò\ô\ö\Ö\ó\Ó\Ô\Ò\õ\Õ]/gi, "o");
	resultTmp = resultTmp.replace(/à/gi, "a");
	resultTmp = resultTmp.replace(/[ù\ü\û\Ü\ú\Ú\Û\Ù]/gi, "u");
	resultTmp = resultTmp.replace(/[â\ä\à\å\Ä\Å\á\Á\Â\À]/gi, "a");
	resultTmp = resultTmp.replace(/[\æ\Æ]/gi, "ae");
	resultTmp = resultTmp.replace(/[\ÿ\ý\Ý]/gi, "y");
	resultTmp = resultTmp.replace(/[\ñ\Ñ]/gi, "n");
	var result = resultTmp.replace(/[^a-zA-Z0-9\&'()\@\+\-\,\_\.\!\/]/gi," ");
	return result;
  } 
  
  function controlloCaratteriAmmessi(){
  var elemento;
  if(document.getElementById('resUte').value=='E'){
  	elemento=new Array("cognCli","nomeCli","denom_cli","indCli","indKit","comnasUte","comuneCli","comuneKit");
  	}
  	else{
  	  elemento=new Array("cognCli","nomeCli","denom_cli","indCli","resUte","indKit","comnasUte");
  }
  
   for (var i = 0; i < elemento.length; i++) {
  	var inputValue=document.getElementById(elemento[i]).value;
  	//alert(inputValue);
  	var newStr=isAlfaNumericoSpecialChar(inputValue);
  	document.getElementById(elemento[i]).value=newStr;
    }
  }
  
// Se si disattiva il servizio visure il campo "Inserisci codice promozionale" viene disattivato 
function controllaPromo(provenienza){
	    if(document.getElementById("servizioVisure").checked == false)
	    {	
	    document.getElementById("registra_campi_promozione").style.display="none";
	    document.getElementById("no_registra_campi_promozione").style.display="block";
	    if(provenienza!="indietro")
	    document.form1.promo[0].click();
	    }
	   else{
	    document.getElementById("registra_campi_promozione").style.display="block";
	    document.getElementById("no_registra_campi_promozione").style.display="none";
	    if(provenienza!="indietro")
	    document.form1.promo[0].click();
	    }

}

function controllaCampiCaratteriStraniIndirizzo(stringa){
    var str=stringa;
	var str2=str.replace(/[ \t\n\r\f\v]/gi,"");
	var patt=new RegExp("[^a-zA-Z0-9./+,()-]","gi");
	if(patt.test(str2))
		return false;
	 else
		return true;
}

function isAlfanumerico(stringa){
	var str=stringa;
	var patt=new RegExp("[^a-zA-Z0-9]","gi");
	if(patt.test(str))
		return false;
	 else
		return true;
}

function copiaEstremiDocStraniero(theForm,stato){
	if(residenza == "E"){
		if(tipoUtente != "Impresa" && stato==true){
		var tipoUtente = theForm.descTipoCli.value;
		  if(theForm.naznasUte.value != "IT")
	      		theForm.nazCliE.value = theForm.naznasUte.value;
	      if(theForm.tipoDocumentoUtente.value != 'CF'){
	      theForm.tipoDocumentoCliente.value=theForm.tipoDocumentoUtente.value;
	      theForm.nazioneDocumentoCliente.value=theForm.nazioneDocumentoUtente.value;
	      theForm.ncf.value=theForm.ncf_nascita.value;
	      	}
	      }
	 else{
		  theForm.nazCliE.value = '';
	      theForm.tipoDocumentoCliente.value='';
	      theForm.nazioneDocumentoCliente.value='';
	      theForm.ncf.value='';
	      
		  }
	}	
}

function azzeraCampiSpedizione(){
	if(residenza == "I"){
		document.getElementById('indKitI').value='';
		document.getElementById('comuneKitI').value='';
		document.getElementById('provKitI').value='';
		document.getElementById('capKitI').value='';
	} else{
		document.getElementById('indKitE').value='';
		document.getElementById('comuneKitE').value='';
		document.getElementById('provKitE').value='';
		document.getElementById('capKitE').value='';
	}
}

function cambiaCCIAAEstero(residenza){

if(residenza=='E'){
	document.getElementById('cciaaReg').value='RM';
	document.getElementById('cciaaReg').disabled=true;
	listaServizi(document.getElementById('cciaaReg').value);
}
else {
	document.getElementById('cciaaReg').value=document.getElementById('PROV_RES_PV_I').value;
	document.getElementById('cciaaReg').disabled=false;
	listaServizi(document.getElementById('PROV_RES_PV_I').value);
}
}

function impostaProviciaEsteraBlank(){
//se il cliente è residente all'estero le province di residenza vengono impostate a blank	
	if(document.getElementById('resUte').value=='E'){
		//alert(document.getElementById('resUte').value);
		document.getElementById('provKit').value='';
		document.getElementById('siglaProvinciaRes').value='';
		document.getElementById('PROV_RES_PV').value='';
	}
}

