function bCheck() {
	if (document.frm_associati.ds_ragione_sociale.value == '') {
		alert('Inserire i primi 5 caratteri della ragione sociale riportata sulla tessera!');
		document.frm_associati.ds_ragione_sociale.focus();
		return false;
	}
	if (document.frm_associati.cd_tessera.value == '') {
		alert('Inserire il codice tessera!');
		document.frm_associati.cd_tessera.focus();
		return false;
	}
	if (document.frm_associati.ds_mail.value == '') {
		alert('Inserire un indirizzo mail valido, esso sara\' anche la tua password!');
		document.frm_associati.ds_mail.focus();
		return false;
	}
	if (!checkEmail(document.frm_associati.ds_mail.value)) {
                alert('Inserire un indirizzo mail valido, esso sara\' anche la tua password!');
                document.frm_associati.ds_mail.focus();
                return false;
        }
	if (document.frm_associati.ds_mail.value != document.frm_associati.ds_mail2.value) {
		alert('I valori di mail e conferma mail saranno la tua password: devono essere identici!');
		document.frm_associati.ds_mail.focus();
		return false;
	}
	if (document.getElementById('dati_aggiuntivi').style.visibility == "hidden") {
		if (document.frm_associati.chk_privacy.checked == false) {
			alert('E\' necessario leggere ed accettare l\'informativa sulla privacy per proseguire nella registrazione!');
			document.frm_associati.ds_mail.focus();
			return false;
		}
	}

	var bIdentif = bCheckIdentificativo();
	if (bIdentif == 'ESCI') { return false; }
	if (bIdentif == true) {
		if (document.getElementById('dati_aggiuntivi').style.visibility == "visible") {
			document.frm_associati.ds_ragione_sociale1.value = document.frm_associati.ds_ragione_sociale1.value.toUpperCase();
			if (document.frm_associati.ds_ragione_sociale1.value == '') {
				alert('Inserire per esteso la ragione sociale nei dati aggiuntivi!');
				document.frm_associati.ds_ragione_sociale1.focus();
				return false;
			}
			document.frm_associati.cd_fiscale.value = document.frm_associati.cd_fiscale.value.toUpperCase();
			if (document.frm_associati.cd_fiscale.value == '') {
				alert('Inserire il codice fiscale/partita iva nei dati aggiuntivi!');
				document.frm_associati.cd_fiscale.focus();
				return false;
			}
			document.frm_associati.ds_indirizzo.value = document.frm_associati.ds_indirizzo.value.toUpperCase();
			if (document.frm_associati.ds_indirizzo.value == '') {
				alert('Inserire l\'indirizzo nei dati aggiuntivi!');
				document.frm_associati.ds_indirizzo.focus();
				return false;
			}
			if (document.frm_associati.cd_cap.value == '') {
				alert('Inserire il cap nei dati aggiuntivi!');
				document.frm_associati.cd_cap.focus();
				return false;
			}
			document.frm_associati.ds_comune.value = document.frm_associati.ds_comune.value.toUpperCase();
			if (document.frm_associati.ds_comune.value == '') {
				alert('Inserire il comune nei dati aggiuntivi!');
				document.frm_associati.ds_comune.focus();
				return false;
			}
			document.frm_associati.ds_provincia.value = document.frm_associati.ds_provincia.value.toUpperCase();
			if (document.frm_associati.ds_provincia.value == '') {
				alert('Inserire la provincia nei dati aggiuntivi!');
				document.frm_associati.ds_provincia.focus();
				return false;
			}
		}
	}

	if (document.getElementById('dati_aggiuntivi').style.visibility == "visible") {
		if (document.frm_associati.chk_privacy.checked == false) {
			alert('E\' necessario leggere ed accettare l\'informativa sulla privacy per proseguire nella registrazione!');
			document.frm_associati.ds_mail.focus();
			return false;
		}
	}

	return true;
}

function bCheckIdentificativo() {
	if (document.frm_associati.fl_identificativo.value == '') {
	        var url = "../getflidentificativo.php?rag_soc="+document.frm_associati.ds_ragione_sociale.value+"&tessera="+document.frm_associati.cd_tessera.value;
	        //var url = "getprovincie.php?regid="+regid+"&mod=xml";
        	//qry = '';
	        new Ajax.Request(url,   {
					asynchronous:false,
       	                                method:'get',
               	                        parameters:{'rag_soc' : document.frm_associati.ds_ragione_sociale.value, /*},*/
						    'tessera' : document.frm_associati.cd_tessera.value},
                       	                onSuccess: function(resp){
						try {
                                                       	document.frm_associati.fl_identificativo.value = resp.responseText;
					    	} catch(e) { alert("Error: " + e.message);}
					},
						onFailure: function(){ alert('Asyncron call failed'); }
                                });
		if (document.frm_associati.fl_identificativo.value == 'S') {
			document.getElementById('dati_aggiuntivi').style.visibility = "visible";
			document.getElementById('dati_aggiuntivi').style.display = "block";
			return 'ESCI';
		} else {
			document.getElementById('dati_aggiuntivi').style.visibility = "hidden";
			document.getElementById('dati_aggiuntivi').style.display = "none";
			return false;
		}


	} else if (document.frm_associati.fl_identificativo.value == 'S') {
		return true;
	} else {
		return false;
	}

}

function bIdentificativoClear() {
	document.frm_associati.fl_identificativo.value = '';
}
