

/************************************
*				UTILITY				*
************************************/



function email_validate(email){
	var regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if (regex.test(email)){
		return true;
	}else{
		return false;
	}
}



/* ---------------------------------------------------------------------------- */



function clear_white_spaces(stringa){
	str = stringa.replace(/^\s*/,"").replace(/\s*$/,"").replace(/\s+/g,"");
	return str;
}





/************************************
*				USER				*
************************************/



function user_check_form(){
	var procedi = true;

	// TITOLO //
	if(clear_white_spaces(document.user_form.titolo_id.value).length==0){
		document.user_form.titolo_id.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.titolo_id.style.backgroundColor = '#FFFFFF';
	}
	// NOME //
	if(clear_white_spaces(document.user_form.nome.value).length==0){
		document.user_form.nome.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.nome.style.backgroundColor = '#FFFFFF';
	}
	// COGNOME //
	if(clear_white_spaces(document.user_form.cognome.value).length==0){
		document.user_form.cognome.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.cognome.style.backgroundColor = '#FFFFFF';
	}
	// TELEFONO PREFISSO //
	if(clear_white_spaces(document.user_form.tel_pr.value).length==0){
		document.user_form.tel_pr.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.tel_pr.style.backgroundColor = '#FFFFFF';
	}
	// TELEFONO NUM //
	if(clear_white_spaces(document.user_form.tel_num.value).length==0){
		document.user_form.tel_num.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.tel_num.style.backgroundColor = '#FFFFFF';
	}
	// INDIRIZZO TIPO //
	if(clear_white_spaces(document.user_form.indirizzo_tipo.value).length==0){
		document.user_form.indirizzo_tipo.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.indirizzo_tipo.style.backgroundColor = '#FFFFFF';
	}
	// INDIRIZZO //
	if(clear_white_spaces(document.user_form.indirizzo.value).length==0){
		document.user_form.indirizzo.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.indirizzo.style.backgroundColor = '#FFFFFF';
	}
	// INDIRIZZO CIVICO //
	if(clear_white_spaces(document.user_form.indirizzo_civico.value).length==0){
		document.user_form.indirizzo_civico.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.indirizzo_civico.style.backgroundColor = '#FFFFFF';
	}
	// CAP //
	if(clear_white_spaces(document.user_form.cap.value).length==0){
		document.user_form.cap.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.cap.style.backgroundColor = '#FFFFFF';
	}
	// CITTA' //
	if(clear_white_spaces(document.user_form.citta.value).length==0){
		document.user_form.citta.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.citta.style.backgroundColor = '#FFFFFF';
	}
	// PROVINCIA //
	if(clear_white_spaces(document.user_form.provincia.value).length==0){
		document.user_form.provincia.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.provincia.style.backgroundColor = '#FFFFFF';
	}
	// STATO //
	if(clear_white_spaces(document.user_form.nazione.value).length==0){
		document.user_form.nazione.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.nazione.style.backgroundColor = '#FFFFFF';
	}
	// USERNAME //
	if(clear_white_spaces(document.user_form.username.value).length==0){
		document.user_form.username.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.username.style.backgroundColor = '#FFFFFF';
	}
	// EMAIL //
	if(email_validate(clear_white_spaces(document.user_form.email.value))==false){
		document.user_form.email.value = '';
		document.user_form.email.style.backgroundColor = '#FF6666';
		procedi = false;
	}else{
		document.user_form.email.style.backgroundColor = '#FFFFFF';
	}

	// PASSOWRD //
	if(clear_white_spaces(document.user_form.password1.value)!=clear_white_spaces(document.user_form.password2.value)){
		document.user_form.password1.style.backgroundColor = '#FF6666';
		document.user_form.password1.value = "";
		document.user_form.password2.style.backgroundColor = '#FF6666';
		document.user_form.password2.value = "";
		procedi = false;
	}else{
		document.user_form.password1.style.backgroundColor = '#FFFFFF';
		document.user_form.password2.style.backgroundColor = '#FFFFFF';
	}

	if(document.user_form.type.value==1){
		// TIPO //
		if(clear_white_spaces(document.user_form.soc_tipo.value).length==0){
			document.user_form.soc_tipo.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.user_form.soc_tipo.style.backgroundColor = '#FFFFFF';
		}
		// RAGIONE SOCIALE //
		if(document.user_form.soc_ragione_sociale.value==""){
			document.user_form.soc_ragione_sociale.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.user_form.soc_ragione_sociale.style.backgroundColor = '#FFFFFF';
		}
	}

	// PRIVACY //
	if(!document.user_form.privacy){
		if(procedi==true){
			document.user_form.submit();
		}
	}else{
		if(!document.user_form.privacy[0].checked){
			privacy_error();
		}else{
			if(procedi==true){
				document.user_form.submit();
			}else{
				fill_all();
			}
		}
	}
}





/******************************************************************/





function agenda_calcola_costo(gn,sn,checked){
	giornate[gn][sn][1] = checked;
	var costo = 0;
	var costo_con_iva = 0;
	// scorro le giornate
	for(var g=0; g<giornate.length; g++){
		var free = true;
		// scorro le sessioni della giornata
		for(var s=0; s<giornate[g].length; s++){
			if(giornate[g][s][0] == 0 && giornate[g][s][1]){
					// c'è una sessione a pagamento
				free = false;
			}
		}
		if(!free){
			// incremento i costi
			costo = costo+giornate_costi[g][0];
			costo_con_iva = costo_con_iva+giornate_costi[g][1];
		}
	}

	if(costo_con_iva>evento_costo_con_iva && evento_costo!=""){
		costo = evento_costo;
		costo_con_iva = evento_costo_con_iva;
	}

	var costo_senza_iva = roundTo(costo,2);
//	var costo_con_iva = roundTo(costo*1.2,2);
	var costo_con_iva = roundTo(costo_con_iva,2);


	if(costo_senza_iva==0){
		document.getElementById("totale_senza_iva").innerHTML = "---";
		document.getElementById("totale_con_iva").innerHTML = "---";
	}else{
		document.getElementById("totale_senza_iva").innerHTML = costo_senza_iva+" €";
		document.getElementById("totale_con_iva").innerHTML = costo_con_iva+" €";
	}
}


function roundTo(value, decimalpositions){
    var i = value * Math.pow(10,decimalpositions);
    i = Math.round(i);
    return i / Math.pow(10,decimalpositions);
}





/*********************************
*		CONFERMA REGISTRAZIONE   *
*********************************/


function registrazione_conferma_check(){
	var procedi = true;
	
	if (document.registrazione_conferma_form.anno_nascita) {
		// ANNO DI NASCITA//
		if(clear_white_spaces(document.registrazione_conferma_form.anno_nascita.value).length==0){
			document.registrazione_conferma_form.anno_nascita.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.anno_nascita.style.backgroundColor = '#FFFFFF';
		}
		
		// FACOLTA//
		if(clear_white_spaces(document.registrazione_conferma_form.facolta.value).length==0){
			document.registrazione_conferma_form.facolta.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.facolta.style.backgroundColor = '#FFFFFF';
		}
		
		// ATENEO //
		if(clear_white_spaces(document.registrazione_conferma_form.ateneo.value).length==0){
			document.registrazione_conferma_form.ateneo.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.ateneo.style.backgroundColor = '#FFFFFF';
		}
		
		if(procedi==true){
				document.registrazione_conferma_form.submit();
			}else{
				fill_all();
				return false;
			}
		}

	
	
	if(document.registrazione_conferma_form.costo && document.registrazione_conferma_form.costo.value>0){
		// PARTITA IVA //
		if(document.registrazione_conferma_form.fat_int_codice.type!='hidden' && clear_white_spaces(document.registrazione_conferma_form.fat_int_codice.value).length==0){
			document.registrazione_conferma_form.fat_int_codice.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_codice.style.backgroundColor = '#FFFFFF';
		}
		//	CODICE FISCALE	//
		if(document.registrazione_conferma_form.fat_int_cf && clear_white_spaces(document.registrazione_conferma_form.fat_int_cf.value).length==0){
			document.registrazione_conferma_form.fat_int_cf.style.backgroundColor = '#FF6666';
			procedi = false;
		}else if(document.registrazione_conferma_form.fat_int_cf){
			document.registrazione_conferma_form.fat_int_cf.style.backgroundColor = '#FFFFFF';
		}
		// NOME //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_nome.value).length==0){
			document.registrazione_conferma_form.fat_int_nome.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_nome.style.backgroundColor = '#FFFFFF';
		}
		
	
		
		// INDIRIZZO TIPO //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_indirizzo_tipo.value).length==0){
			document.registrazione_conferma_form.fat_int_indirizzo_tipo.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_indirizzo_tipo.style.backgroundColor = '#FFFFFF';
		}
		// INDIRIZZO //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_indirizzo.value).length==0){
			document.registrazione_conferma_form.fat_int_indirizzo.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_indirizzo.style.backgroundColor = '#FFFFFF';
		}
		// INDIRIZZO CIVICO //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_indirizzo_civico.value).length==0){
			document.registrazione_conferma_form.fat_int_indirizzo_civico.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_indirizzo_civico.style.backgroundColor = '#FFFFFF';
		}
		// CAP //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_cap.value).length==0){
			document.registrazione_conferma_form.fat_int_cap.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_cap.style.backgroundColor = '#FFFFFF';
		}
		// CITTA //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_citta.value).length==0){
			document.registrazione_conferma_form.fat_int_citta.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_citta.style.backgroundColor = '#FFFFFF';
		}
		// PROVINCIA //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_provincia.value).length==0){
			document.registrazione_conferma_form.fat_int_provincia.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_provincia.style.backgroundColor = '#FFFFFF';
		}
		// STATO //
		if(clear_white_spaces(document.registrazione_conferma_form.fat_int_nazione.value).length==0){
			document.registrazione_conferma_form.fat_int_nazione.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.fat_int_nazione.style.backgroundColor = '#FFFFFF';
		}

		//	ESENTE IVA
		if(document.registrazione_conferma_form.esente_iva.value==1 && clear_white_spaces(document.registrazione_conferma_form.esente_iva_text.value).length==0){
			document.registrazione_conferma_form.esente_iva_text.style.backgroundColor = '#FF6666';
			procedi = false;
		}else{
			document.registrazione_conferma_form.esente_iva_text.style.backgroundColor = '#FFFFFF';
		}


		// spedizione

		var fat_spe_nome = clear_white_spaces(document.registrazione_conferma_form.fat_spe_nome.value);
		var fat_spe_indirizzo_tipo = clear_white_spaces(document.registrazione_conferma_form.fat_spe_indirizzo_tipo.value);
		var fat_spe_indirizzo = clear_white_spaces(document.registrazione_conferma_form.fat_spe_indirizzo.value);
		var fat_spe_indirizzo_civico = clear_white_spaces(document.registrazione_conferma_form.fat_spe_indirizzo_civico.value);
		var fat_spe_cap = clear_white_spaces(document.registrazione_conferma_form.fat_spe_cap.value);
		var fat_spe_citta = clear_white_spaces(document.registrazione_conferma_form.fat_spe_citta.value);
		var fat_spe_provincia = clear_white_spaces(document.registrazione_conferma_form.fat_spe_provincia.value);
		var fat_spe_nazione = clear_white_spaces(document.registrazione_conferma_form.fat_spe_nazione.value);
		// nome
		if(fat_spe_nome.length>0){
			document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FFFFFF";
			if(fat_spe_indirizzo_tipo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_civico.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_cap.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_citta.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_provincia.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_nazione.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FFFFFF";
		}

		// indirizzo tipo
		if(fat_spe_indirizzo_tipo.length>0){
			document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FFFFFF";
			if(fat_spe_nome.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_civico.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_cap.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_citta.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_provincia.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_nazione.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FFFFFF";
		}

		// indirizzo
		if(fat_spe_indirizzo.length>0){
			document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FFFFFF";
			if(fat_spe_nome.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_tipo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_civico.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_cap.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_citta.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_provincia.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_nazione.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FFFFFF";
		}

		// indirizzo civico
		if(fat_spe_indirizzo_civico.length>0){
			document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FFFFFF";
			if(fat_spe_nome.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_tipo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_cap.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_citta.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_provincia.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_nazione.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FFFFFF";
		}

		// cap
		if(fat_spe_cap.length>0){
			document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FFFFFF";
			if(fat_spe_nome.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_tipo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_civico.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_citta.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_provincia.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_nazione.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FFFFFF";
		}

		// citta
		if(fat_spe_citta.length>0){
			document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FFFFFF";
			if(fat_spe_nome.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_tipo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_civico.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_cap.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_provincia.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_nazione.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FFFFFF";
		}

		// provincia
		if(fat_spe_provincia.length>0){
			document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FFFFFF";
			if(fat_spe_nome.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_tipo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_civico.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_cap.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_citta.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_nazione.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FFFFFF";
		}

		// nazione
		if(fat_spe_nazione.length>0){
			document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FFFFFF";
			if(fat_spe_nome.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_nome.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_tipo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_tipo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_indirizzo_civico.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_indirizzo_civico.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_cap.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_cap.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_citta.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_citta.style.backgroundColor = "#FF6666";
			}
			if(fat_spe_provincia.length==0){
				procedi = false;
				document.registrazione_conferma_form.fat_spe_provincia.style.backgroundColor = "#FF6666";
			}
		}else{
			document.registrazione_conferma_form.fat_spe_nazione.style.backgroundColor = "#FFFFFF";
		}


		if(procedi && !document.registrazione_conferma_form.pagamento_tipo[0].checked && !document.registrazione_conferma_form.pagamento_tipo[1].checked && !document.registrazione_conferma_form.pagamento_tipo[2].checked){
			modalita_pagamento_error();
		}else{
			if(!procedi){
				fill_all();
			}else if((document.getElementById("condizione_1") && document.getElementById("condizione_1").checked==false) || (document.getElementById("condizione_2") && document.getElementById("condizione_2").checked==false)){
				//	Accettazione condizioni mancante
				condizioni_mancanti_alert();
			}else{
				document.registrazione_conferma_form.submit();
			}
		}
	}else{
		document.registrazione_conferma_form.submit();
	}
	

}



/******************************************************/



function one2onecheckform(){
	var procedi = true;

	if(procedi){
		document.one2onecontactform.submit();
	}else{
		return false;
	}
}


/******************************************************/



function cercaregistrazione(ABSOLUTE_URI, evento_id){
	document.getElementById("cr_result").innerHTML = "Searching...";
	var nome = document.getElementById("cr_nome").value;
	var cognome = document.getElementById("cr_cognome").value;
	var societa = document.getElementById("cr_societa").value;
	var url = ABSOLUTE_URI+"includes/components/cerca_registrazione.php?nome="+escape(nome)+"&cognome="+escape(cognome)+"&societa="+escape(societa)+"&evento_id="+evento_id;
	createRequest();
	//hack for IE caching
	url = url + "&time=" + new Date().getTime();
	request.open("GET",url,true);
	request.onreadystatechange = visualizzaregistrazione;
	request.send(null);
}



/******************************************************/



function visualizzaregistrazione(){
		if (request.readyState == 4){
		var result = request.responseText;
		document.getElementById("cr_result").innerHTML = result;
	}
}



/******************************************************/



var request = null;

function createRequest(){
	try{
		request = new XMLHttpRequest();
	}catch (trymicrosoft){
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (othermicrosoft){
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (failed){
				request = null;
			}
		}
	}
	if (request == null){
		alert("Error creating request object!");
	}

}





//****************************************************************************//





function evento_registrazione_check_orari_sessioni(sessione){
	//return true;
	//	Vedo se ho selezionato la sessione
	if(sessione.checked==true){
		//	La sessione è appena stata selezionata, verifico non ce ne siano altre attive con orari sovrapposti
		var sessione_id = sessione.value;

		//	Calcolo inizio e fine di questa sessione
		for(var i=0; i<sessioni.length; i++){
			if(sessioni[i][1]==sessione_id){
				var giornata_id = sessioni[i][0];
				var sessione_inizio = sessioni[i][2]*1;
				var sessione_fine = sessioni[i][3]*1;
				i = sessioni.length;
			}
		}
		//	Ora verifico che non ci siano altre sessioni selezionate che si sovrappongano a questa
		for(var i=0; i<sessioni.length; i++){
			if(sessioni[i][1]!=sessione_id && sessioni[i][0]==giornata_id && document.getElementById("sessione_"+sessioni[i][1]).checked==true){
				//	Controllo solo le sessioni diverse da quella appena selezionata e che sono selezionate
//				alert(sessioni[i][1]+": "+sessioni[i][2]+"/"+sessioni[i][3]+" - "+sessione_inizio+"/"+sessione_fine);
				var inizio = sessioni[i][2]*1;
				var fine = sessioni[i][3]*1;
				if(
					(sessione_inizio>=inizio && sessione_inizio<fine)
					||
					(sessione_fine>inizio && sessione_fine<=fine)
				){
					//	C'è una sessione già selezionata che si sovrappone a questa
					sessione.checked = false;
					overlapped_session();
					i = sessioni.length;
				}

			}
		}
	}

}



function evento_registrazione_check_orari_sessioni_t(sessione){

	//	Vedo se ho selezionato la sessione
	alert(sessione.value);

}
