// Caricamento pagina $(function() { $("#frmNewsletter").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); // Cattura i change $(".radact").change(function() { fCheckObbligatori(); }); $('#txtEmail').focus(); }); // Registra i dati function fSaveData() { $('#submitBut').hide(); $('#submitLoad').show(); var data; var strResult = ''; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/saveNewsletter.php", data: $("#frmNewsletter").serialize(), success: function(data) { strResult = data.result; $('#submitLoad').hide(); if ( data.status == 'ok' ) { blnSaved = true; } else if ( data.status == 'obbligatori' ) { // campi obbligatori mancanti $('#submitBut').show(); } else if ( data.status == 'found' ) { // ERRORE REGISTRAZIONE : indirizzo gia' presente in archivio $('#submitBut').show(); } else if ( data.status == 'notfound' ) { // ERRORE RIMOZIONE : Indirizzo non presente $('#submitBut').show(); } else alert("salvataggio non riuscito."); }, error: function(data) { alert("Procedura non completata."); } }); if ( blnSaved ) { $('#submitResult').show(); location.href = $('#urlResult').val() + strResult; } } // Controllo campi obbligatori function fCheckObbligatori() { $('#submitBut').hide(); $('#submitLoad').show(); var blnReturn = true; var email = $.trim( $('#txtEmail').val() ); var emailLabel = $('#lbltxtEmail'); var blnActionRemove = $('#radioActionRemove').attr('checked'); // Email if ( email != '' ) { emailLabel.html(''); //-- Ajax : inizio $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/checkEmail.php", data: "action=checkEmailComplete_Newsletter&pstrEmail="+email, success: function(data) { if ( data.status == 'ok' ) { if ( data.found == '1' && ! blnActionRemove ) { // ERRORE REGISTRAZIONE : indirizzo gia' presente in archivio blnReturn = false; emailLabel.html( fHTMLErrore( 'L\'indirizzo risulta già inserito nel nostro archivio!' ) ); } else if ( data.found == '0' && blnActionRemove ) { // ERRORE RIMOZIONE : indirizzo non presente in archivio blnReturn = false; emailLabel.html( fHTMLErrore( 'L\'indirizzo non risulta inserito nel nostro archivio!' ) ); } else { // OK if ( blnActionRemove ) { emailLabel.html(""); } else { emailLabel.html(""); } } } else if ( data.status == 'errore' && data.errore == '1' ) { // ERRORE SINTASSI EMAIL blnReturn = false; emailLabel.html( fHTMLErrore( "L'indirizzo non è corretto." ) ); } else if ( data.status == 'errore' && data.errore == '2' ) { // ERRORE RECORD MX EMAIL blnReturn = false; emailLabel.html( fHTMLErrore( "Questo indirizzo non esiste." ) ); } else alert("Verifica email non riuscita."); }, error: function(data) { alert("Procedura non completata."); } }); //-- Ajax : inizio } else { blnReturn = false; emailLabel.html( fHTMLErrore( 'Campo obbligatorio' ) ); } if ( blnActionRemove ) { // Rimuovi indirizzo $('#lbltxtNominativo, #lblchkPrivacy').html(''); $('#boxNominativo, #boxPrivacy').hide(''); } else { // Aggiungi indirizzo $('#boxNominativo, #boxPrivacy').show(''); // Nomivativo if ( $('#txtNominativo').val() == '' ) { blnReturn = false; $('#lbltxtNominativo').html( fHTMLErrore( 'Campo obbligatorio.' ) ); } else $('#lbltxtNominativo').html(''); // Privacy if ( ! $('#chkPrivacy').attr('checked') ) { blnReturn = false; $('#lblchkPrivacy').html( fHTMLErrore( 'Accettazione obbligatoria.' ) ); } else $('#lblchkPrivacy').html(''); } $('#submitLoad').hide(); $('#submitBut').show(); return blnReturn; } function fHTMLErrore( pstr ) { return '
' + pstr + '
'; }