var onloadCallback = function() { grecaptcha.render('recaptcha', { 'sitekey' : '6LeID5AUAAAAAOP1e-eSmparpsmugFSk-072Vba3', 'theme' : 'light' }); }; $(function() { $("#frmContacts").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); $("#email_button").click(function() { $('html, body').animate({ scrollTop: ( $("#scrivi-messaggio").offset().top - 120 ) }, 400); }); }); function fSaveData() { $('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/inviaContatti.php", data: $("#frmContacts").serialize(), success: function(data) { strDestination = data.destination; if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "Registrazione non riuscita.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); if ( blnSaved ) { location.href = strDestination; } else { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; $( ".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" ); } }); // Controllo privacy if ( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) ); $( ".fg-privacy" ).addClass( "has-error" ); } // Controllo Email if ( $('#txtEmail').val() != '' ) { $('#loader-email').removeClass('hide'); $('#lbltxtEmail').html( '' ); var intErrore = ''; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkEmail.php", data: "action=checkEmail&pstrEmail=" + $("#txtEmail").val(), success: function(data) { intErrore = data.errore; if ( intErrore == 1 ) { // ERRORE : email NON corretta blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non รจ corretto." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } else if ( intErrore == 2 ) { // ERRORE : email NON esiste blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non esiste." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } if ( data.status == 'errore' ) blnSaved = false; else if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "Verifica non riuscita.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); } if (!grecaptcha.getResponse()) { grecaptcha.reset(); blnReturn = false; $('#lblrecaptcha').html( fHTMLErrore( "Esegui la verifica" ) ); } if ( ! blnReturn ) { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } $('#loader-email').addClass('hide'); return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }