$(function() { $('#privacy4newsletter').change(function() { fCheckNLFooterObbligatori(); }); $('#name4newsletter, #email4newsletter').change(function() { if ( $(this).val() != '' ) $(this).css('color', '#fff'); else $(this).css('color', '#666'); }); }); //--- Controllo campi obbligatori function fCheckNLFooterObbligatori( pintSubmit ) { var blnReturn = true; fLogColor( blnReturn ); $('#errorLog').html(''); //--- name4newsletter if ( ! $('#name4newsletter').val() ) { blnReturn = false; $('#errorLog').html('Inserisci il campo Nominativo'); $('#name4newsletter').focus(); } //--- email4newsletter if ( blnReturn && ! $('#email4newsletter').val() ) { blnReturn = false; $('#errorLog').html('Inserisci il campo Email'); $('#email4newsletter').focus(); } //--- privacy4newsletter if ( blnReturn && ( $('#privacy4newsletter').attr('checked') != null && ! $('#privacy4newsletter').attr('checked') ) ) { blnReturn = false; $('#errorLog').html('Accettazione obbligatoria.'); } if ( blnReturn ) { if ( $('#email4newsletter').val() ) { fLogColor( blnReturn ); $('#errorLog').html(''); //-- Ajax : inizio $.ajax({ url: 'include/ajax/checkEmail.php' , data: 'command=checkEmail' + '&pstrEmail=' + $('#email4newsletter').val() , success: function(data) { // Ritorno : Inizio update = data.split('|'); if( update[0] == 'checkEmail' ) { if( update[1] == 1 ) { fLogColor( 0 ); //$('#errorLog').html("L'indirizzo sembra corretto. Ok."); if ( ! pintSubmit ) $('#errorLog').html(" "); } else { blnReturn = false; fLogColor( blnReturn ); $('#errorLog').html("L'indirizzo non è corretto."); } if ( blnReturn ) if ( pintSubmit > 0 ) { //$('#formNewsletterFooter').submit(); //--- Ajax : inizio $.ajax({ type: "POST" , url: 'include/ajax/sendNewsletterFooter.php' , data: 'command=sendNewsletterFooter' +'&pstrAction=' + $('#action4newsletter').val() +'&pstrNominativo=' + $('#name4newsletter').val() +'&pstrEmail=' + $('#email4newsletter').val() +'&pstrPrivacy=' + ( $('#privacy4newsletter').attr('checked') ? 'accept' : '' ) , success: function(data) { // Ritorno : Inizio update = data.split('|'); if( update[0] == 'sendNewsletterFooter' ) { if( update[1] == 1 ) location.href = 'newsletter_thanks.php?email=' +$('#email4newsletter').val() +'&found='+update[2] +'&action='+$('#action4newsletter').val(); else location.href = 'newsletter.php'; } // Ritorno : Fine } }); //--- Ajax : fine } } // Ritorno : Fine } }); //-- Ajax : inizio } else { blnReturn = false; fLogColor( blnReturn ); } } return blnReturn; } // Cambia colore elemento selezionato function fLogColor( pstrStatus ) { if ( pstrStatus ) $('#errorLog').css('color','#f00'); else $('#errorLog').css('color','#666'); }