// Caricamento pagina $(function() { //fCheckObbligatori(); $("#frmNewsletter").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); // Cattura i change /*$("input,select,textarea").change(function() { fCheckObbligatori( 1 ); });*/ $(".radact").change(function() { fCheckObbligatori( 1 ); }); $('#txtEmail').focus(); }); // Registra i dati function fSaveData() { $('#submitBut').hide(); $('#submitLoad').show(); var strID = ''; var strTmp = ''; var data; 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; strTmp = data.status; $('#submitLoad').hide(); if ( data.status == 'ok' ) { blnSaved = true; } else if ( data.status == 'obbligatori' ) { // campi obbligatori mancanti $('#submitBut').show(); alert("Inserisci tutti i campi obbligatori."); } else if ( data.status == 'found' ) { // ERRORE REGISTRAZIONE : indirizzo gia' presente in archivio $('#submitBut').show(); alert("ATTENZIONE, non è possibile effettuare l'operazione.\n\nL'indirizzo risulta già inserito nel nostro archivio!"); } else if ( data.status == 'notfound' ) { // ERRORE RIMOZIONE : Indirizzo non presente $('#submitBut').show(); alert("ATTENZIONE, non è possibile effettuare l'operazione.\n\nL'indirizzo non risulta inserito nel nostro archivio!"); } else alert("salvataggio non riuscito."); }, error: function(data){ alert("errore: " + data); } }); if ( blnSaved ) { $('#submitResult').show(); location.href = $('#urlResult').val() + strResult; } } // Controllo campi obbligatori function fCheckObbligatori( pintHideAlert ) { $('#submitBut').hide(); $('#submitLoad').show(); var blnReturn = true; var intHideAlert = ( pintHideAlert > 0 ? 1 : 0 ); var strAlert = "Verifica i campi: \n\n"; var emailLabel = $('#lbltxtEmail'); var blnActionRemove = $('#radioActionRemove').attr('checked'); // Email if ( $('#txtEmail').val() != '' ) { emailLabel.html(''); //-- Ajax : inizio $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/checkEmail.php", data: "action=checkEmailComplete_Newsletter&pstrEmail="+$("#txtEmail").val(), success: function(data) { strResult = data.result; strTmp = data.status; 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!"); strAlert += '- Indirizzo email gia\' presente in archivio \n'; } 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!"); strAlert += '- Indirizzo email non presente in archivio \n'; } else { // OK if ( blnActionRemove ) { emailLabel.removeClass('errore').addClass('conferma').html(""); } else { emailLabel.removeClass('errore').addClass('conferma').html("L'indirizzo sembra corretto. Ok."); } } } else if ( data.status == 'errore' && data.errore == '1' ) { // ERRORE SINTASSI EMAIL blnReturn = false; emailLabel.removeClass('conferma').addClass('errore').html("L'indirizzo non è corretto."); strAlert += '- Indirizzo Email non corretto \n'; } 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("errore: " + data); } }); //-- Ajax : inizio } else { blnReturn = false; emailLabel.removeClass('conferma').addClass('errore').html('Campo obbligatorio'); strAlert += '- Indirizzo Email \n'; } 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.'); strAlert += '- Nominativo \n'; } else $('#lbltxtNominativo').removeClass("conferma").removeClass("errore").html(''); // Privacy if( ! $('#chkPrivacy').attr('checked') ) { blnReturn = false; $('#lblchkPrivacy').html('Accettazione obbligatoria.'); strAlert += '- Accettazione Privacy \n'; } else $('#lblchkPrivacy').html(''); } if ( ! blnReturn && ! intHideAlert ) alert( strAlert ); $('#submitLoad').hide(); $('#submitBut').show(); return blnReturn; }