$( function() { $("#frmOggetto").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); // tipo_registrazione $('.tipo_registrazione').change(function() { if ( $('.tipo_registrazione:checked').val() == 'azienda' ) { // AZIENDA $('.fg-txtRagioneSociale').removeClass('hide'); //$('#col-codicefiscale').addClass('hide'); $('#col-partitaiva').removeClass('hide'); } else { // PRIVATO $('.fg-txtRagioneSociale').addClass('hide'); $('#col-partitaiva').addClass('hide'); if ( $('#cmbNazione').val() == 'IT' ) { //$('#col-codicefiscale').removeClass('hide'); } else { //$('#col-codicefiscale').addClass('hide'); } } }); // Mostra domanda $('.showdomanda').click(function() { var campo = ( $(this).attr('id') ).replace( 'showdomanda_', '' ); $( '#box_' + campo ).addClass('hide'); $( '#boxlista_' + campo ).removeClass('hide'); }); // Mostra lista domande $('.listadomande').change(function() { var campo = ( $(this).attr('id') ).replace( 'listadomande_' , '' ); $( '#' + campo ).val( $(this).val() ); $( '#boxlista_' + campo ).addClass('hide'); $( '#lbl' + campo ).html(''); $( '#box_' + campo ).removeClass('hide'); $( '#' + campo ).focus(); }); // nazione $('#cmbNazione').change(function() { if ( $(this).val() == 'IT' ) { $('#col-citta').removeClass('col-sm-8').addClass('col-sm-4'); $('#col-provincia').removeClass('hide'); //$('#col-codicefiscale').removeClass('hide'); } else { $('#col-provincia').addClass('hide'); $('#col-citta').removeClass('col-sm-4').addClass('col-sm-8'); //$('#col-codicefiscale').addClass('hide'); } }); // Evidenzia privacy $('#showprivacy').click(function() { if( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblPrivacy').html("Accettazione obbligatoria."); } else $('#lblPrivacy').html(''); }); }); function fSaveData() { fLoading(1); $('submit').focus(); $('#submitBut').addClass('hide'); $('#submitLoad').removeClass('hide'); var data; var strDestination = ''; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/sendSubscription.php", data: $("#frmOggetto").serialize(), success: function(data) { strDestination = data.destination; if ( data.status == 'ok' ) { blnSaved = true; } else swal("Ops...", "Registrazione dati non riuscita", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); if ( blnSaved ) { location.href = strDestination; } else { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); fLoading(0); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; var blnEstero = false; $('submit').focus(); $('#submitBut').addClass('hide'); $('#submitLoad').removeClass('hide'); $('#avvisoObbligatori').addClass('hide'); $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); $('.required').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-" + $(this).attr("name") ).addClass( "has-error" ); $( "#show_" + $(this).attr("name") + ", #showdomanda_" + $(this).attr("name") ).addClass('hide'); } else { $( "#lbl" + $(this).attr("name") ).html(""); $( "#show_" + $(this).attr("name") + ", #showdomanda_" + $(this).attr("name") ).removeClass('hide'); } }); // Controllo provincia if ( $('#cmbNazione').val() == 'IT' && $.trim( $('#cmbProvincia').val() ) == '' ) { blnReturn = false; $('#lblcmbProvincia').html( fHTMLErrore( "" ) ); $( ".fg-cmbProvincia" ).addClass( "has-error" ); } else $('#lblcmbProvincia').html(""); // Controllo password if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' ) { if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() ) { blnReturn = false; $('#lbltxtConfermaPassword').html( fHTMLErrore( "La password non è uguale." ) ); $( ".fg-txtConfermaPassword" ).addClass( "has-error" ); } else $('#lbltxtConfermaPassword').html(""); } // Controllo privacy if( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) ); $( ".fg-privacy" ).addClass( "has-error" ); } else $('#lblprivacy').html(""); var strID_Contatto = ( $('#id_cliente').length ? $('#id_cliente').val() : '' ); // Controllo Email if ( $('#txtEmail').val() != '' ) { $('#lbltxtEmail').html( '' ); var data; var intCheck = 0; var intExists = 0; var intErrore = 0; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkContatto.php", data: "action=checkEmail&pstrEmail=" + $('#txtEmail').val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intCheck = data.email_check; intExists = data.email_exists; intErrore = data.email_errore; if ( intCheck == 0 ) { // Email non corretta if ( intErrore == 2 ) { // ERRORE : email NON esiste blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non esiste" ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } else if ( intErrore == 1 ) { // ERRORE : email NON corretta blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non è corretto." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } } else { // Email corretta if ( intExists == 1 ) { // ERRORE : email non unica blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "Il valore è già in archivio." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } else { // OK : Email unica e corretta $('#lbltxtEmail').html(""); } } if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "Verifica non riuscita", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); } // Controllo RagioneSociale if ( $('.tipo_registrazione:checked').val() != 'privato' ) { if ( $.trim( $('#txtRagioneSociale').val() ) == "" ) { blnReturn = false; $( "#lbltxtRagioneSociale" ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-txtRagioneSociale" ).addClass( "has-error" ); } else { $( "#lbltxtRagioneSociale" ).html(""); } } // Controllo Codice fiscale if ( false && ! blnEstero && $('.tipo_registrazione:checked').val() == 'privato' ) { if ( $.trim( $('#txtCodiceFiscale').val() ) == "" ) { blnReturn = false; $( "#lbltxtCodiceFiscale" ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-txtCodiceFiscale" ).addClass( "has-error" ); } else { $( "#lbltxtCodiceFiscale" ).html(""); $('#lbltxtCodiceFiscale').html( '' ); var data; var intExists = 0; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkContatto.php", data: "action=checkCodiceFiscale&pstrCodiceFiscale=" + $("#txtCodiceFiscale").val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intExists = data.codice_fiscale_exists; if ( intExists == 1 ) { // ERRORE : valore NON unico blnReturn = false; $('#lbltxtCodiceFiscale').html( fHTMLErrore( "Il valore è già in archivio." ) ); $( ".fg-txtCodiceFiscale" ).addClass( "has-error" ); } else { // OK : valore unico $('#lbltxtCodiceFiscale').html(""); } if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "LNG_AJAX_VERIFICA", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); } } // Controllo Partita IVA if ( $('.tipo_registrazione:checked').val() == 'azienda' ) { if ( $.trim( $('#txtPartitaIva').val() ) == "" ) { blnReturn = false; $( "#lbltxtPartitaIva" ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-txtPartitaIva" ).addClass( "has-error" ); } else { $( "#lbltxtPartitaIva" ).html(""); $('#lbltxtPartitaIva').html( '' ); var data; var intExists = 0; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkContatto.php", data: "action=checkPartitaIva&pstrPartitaIva=" + $("#txtPartitaIva").val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intExists = data.partita_iva_exists; if ( intExists == 1 ) { // ERRORE : valore NON unico blnReturn = false; $('#lbltxtPartitaIva').html( fHTMLErrore( "Il valore è già in archivio." ) ); $( ".fg-txtPartitaIva" ).addClass( "has-error" ); } else { // OK : valore unico $('#lbltxtPartitaIva').html(""); } if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "LNG_AJAX_VERIFICA", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); } } if ( ! $('#col-sdi-pec').hasClass('hide') ) { if ( $.trim( $('#txtSdi').val() ) == "" && $.trim( $('#txtPec').val() ) == "" ) { blnReturn = false; $( "#sdi_pec_label" ).css( 'color', '#f00' ); $( ".fg-txtSdi, .fg-txtPec" ).addClass( "has-error" ); } else $( "#sdi_pec_label" ).css( 'color', 'inherit' ); } $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); if ( ! blnReturn ) $('#avvisoObbligatori').removeClass('hide'); return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }