$( function() { // tipo_registrazione $('.tipo_registrazione').change(function() { if ( $('.tipo_registrazione:checked').val() == 'azienda' ) { // AZIENDA $('.fg-txtRagioneSociale').removeClass('hide'); $('#col-codicefiscale, #col-partitaiva').removeClass('hide'); } else { // PRIVATO $('.fg-txtRagioneSociale').addClass('hide'); $('#col-partitaiva').addClass('hide'); $('#col-codicefiscale').removeClass('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'); } else { $('#col-provincia').addClass('hide'); $('#col-citta').removeClass('col-sm-4').addClass('col-sm-8'); } $('#col-codicefiscale').removeClass('hide'); }); $('#cmbSpNazione').change(function() { if ( $(this).val() == 'IT' ) { $('#col-sp-citta').removeClass('col-sm-8').addClass('col-sm-4'); $('#col-sp-provincia').removeClass('hide'); } else { $('#col-sp-provincia').addClass('hide'); $('#col-sp-citta').removeClass('col-sm-4').addClass('col-sm-8'); } }); $('#form-spedizione-but').click(function() { $('#indirizzo_differente').val( '1' ); $('.form-spedizione-but-box').addClass('hide'); $('.form-spedizione-hide-box').removeClass('hide'); $('#form-spedizione-box').removeClass('hide'); $('#espedizione_label').addClass('hide'); }); $('#form-spedizione-hide').click(function() { var blnSpHide = false; var blnSpFull = ( $.trim( $('#txtSpIndirizzo').val() ) != '' ); if ( blnSpFull ) { swal({ title: "Attenzione!", text: "Vuoi cancellare i campi per la spedizione ed utilizzare l'indirizzo di fatturazione anche per la spedizione?", type: "warning", showCancelButton: true, cancelButtonText: "No, annulla", confirmButtonText: "Si, procedi", closeOnConfirm: true }, function(isConfirm) { if ( isConfirm ) fHideSpedizione(); }); } else fHideSpedizione(); }); // Evidenzia privacy $('#showprivacy').click(function() { if( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblPrivacy').html("Accettazione obbligatoria."); } else $('#lblPrivacy').html(''); }); }); function fHideSpedizione() { $('#indirizzo_differente').val( '0' ); $('.form-spedizione-hide-box').addClass('hide'); $('.form-spedizione-but-box').removeClass('hide'); $('#form-spedizione-box').addClass('hide'); $('#espedizione_label').removeClass('hide'); $('.sp-input').val(''); $('.sp-select option:first').attr('selected', true); } 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...", "Procedura non completata.", "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'); } }); if ( $('#mod').val() == '' || $('#mod').val() == 'accesso' ) { $('.required_accesso').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-" + $(this).attr("name") ).addClass( "has-error" ); } else $( "#lbl" + $(this).attr("name") ).html(""); }); } if ( $('#mod').val() == '' || $('#mod').val() == 'cliente' ) { $('.required_cliente').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-" + $(this).attr("name") ).addClass( "has-error" ); } else $( "#lbl" + $(this).attr("name") ).html(""); }); } if ( ( $('#mod').val() == '' && parseInt( $('#indirizzo_differente').val() ) > 0 ) || $('#mod').val() == 'spedizione' ) { $('.required_spedizione').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-" + $(this).attr("name") ).addClass( "has-error" ); } else $( "#lbl" + $(this).attr("name") ).html(""); }); } // 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...", "Procedura non completata.", "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 ( ! 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...", "Verifica non riuscita.", "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...", "Verifica non riuscita.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); } } $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); if ( ! blnReturn ) $('#avvisoObbligatori').removeClass('hide'); return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }