$( function() { /*$("#frmOggetto").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; });*/ // 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(); }); // Evidenzia privacy $('#showprivacy').click(function() { if( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblPrivacy').html("Acceptation obligatoire."); } 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("Oops!", "Echec de l'enregistrement.", "error"); }, error: function(data){swal("Oops!", "Procédure est pas terminée.", "error");} }); if ( blnSaved ) { location.href = strDestination; } else { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); fLoading(0); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; $('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( "obligatoire" ) ); $( ".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 password if ( $.trim( $('#cmbNazionalita').val() ) == "" ) { blnReturn = false; $('#lblcmbNazionalita').html( fHTMLErrore( "obligatoire" ) ); $( ".fg-cmbNazionalita" ).addClass( "has-error" ); } else $('#lblcmbNazionalita').html(""); if ( $('#conferma_dati').val() != 'social' ) { $('.required-full').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "obligatoire" ) ); $( ".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 password if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' ) { if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() ) { blnReturn = false; $('#lbltxtConfermaPassword').html( fHTMLErrore( "Le password est le même." ) ); $( ".fg-txtConfermaPassword" ).addClass( "has-error" ); } else $('#lbltxtConfermaPassword').html(""); } } // Controllo privacy if( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Acceptation obligatoire." ) ); $( ".fg-privacy" ).addClass( "has-error" ); } else $('#lblprivacy').html(""); var strID_Contatto = ( $('#id_cliente').length ? $('#id_cliente').val() : '' ); // Controllo Email if ( $('#txtEmail').val() != '' ) { $('#loader-email').removeClass('hide'); 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( "Ne existe pas l'adresse." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } else if ( intErrore == 1 ) { // ERRORE : email NON corretta blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'adresse est pas correct." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } } else { // Email corretta if ( intExists == 1 ) { // ERRORE : email non unica blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "La valeur est déjà dans le dossier." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } else { // OK : Email unica e corretta $('#lbltxtEmail').html(""); } } $('#loader-email').addClass('hide'); if ( data.status == 'ok' ) blnSaved = true; else swal("Oops!", "Vérifiez échoué.", "error"); }, error: function(data){swal("Oops!", "Procédure est pas terminée.", "error");} }); } /*if ( ! checkRecaptcha() ) { blnReturn = false; $('#lblrecaptcha').html( fHTMLErrore( "Effectuer la vérification" ) ); }*/ $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); if ( ! blnReturn ) $('#avvisoObbligatori').removeClass('hide'); return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }