// 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 var blnActionRemove = $('#radioActionRemove').attr('checked'); if ( ! blnActionRemove ) blnSaved = true; else $('#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(''); var strAction = "action=checkEmailComplete_Newsletter"; strAction += "&pstrEmail=" + email; strAction += "&pstrID_Lingua=" + $('#id_lingua').val(); //-- Ajax : inizio $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/checkEmail.php", data: strAction, success: function(data) { if ( data.status == 'ok' ) { if ( data.found == '1' && ! blnActionRemove ) { // ERRORE REGISTRAZIONE : indirizzo gia' presente in archivio //blnReturn = false; //emailLabel.removeClass('conferma').addClass('errore').html("L'indirizzo risulta già inserito nel nostro archivio!"); } else if ( data.found == '0' && blnActionRemove ) { // ERRORE RIMOZIONE : indirizzo non presente in archivio blnReturn = false; emailLabel.removeClass('conferma').addClass('errore').html("L'indirizzo non risulta inserito nel nostro archivio!"); } else { // OK if ( blnActionRemove ) { emailLabel.removeClass('errore').addClass('conferma').html(""); } else { emailLabel.removeClass('errore').addClass('conferma').html(""); } } } else if ( data.status == 'errore' && data.errore == '1' ) { // ERRORE SINTASSI EMAIL blnReturn = false; emailLabel.removeClass('conferma').addClass('errore').html("L'indirizzo non è corretto."); } else if ( data.status == 'errore' && data.errore == '2' ) { // ERRORE RECORD MX EMAIL blnReturn = false; emailLabel.removeClass('conferma').addClass('errore').html("Questo indirizzo non esiste."); strAlert += '- Indirizzo Email non esistente \n'; } else alert("Verifica email non riuscita."); }, error: function(data) { alert("Procedura non completata."); } }); //-- Ajax : inizio } else { blnReturn = false; emailLabel.removeClass('conferma').addClass('errore').html('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').removeClass("conferma").addClass("errore").html('Campo obbligatorio.'); } else $('#lbltxtNominativo').removeClass("conferma").removeClass("errore").html(''); // Privacy if ( ! $('#chkPrivacy').attr('checked') ) { blnReturn = false; $('#lblchkPrivacy').html('Accettazione obbligatoria.'); } else $('#lblchkPrivacy').html(''); } $('#submitLoad').hide(); $('#submitBut').show(); return blnReturn; }