$(function() { $('#frmDomanda').submit(function() { $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); $('#submitBut').addClass('hide'); $('#submitLoad').removeClass('hide'); if ( fCheckObbligatoriDomanda() ) { // Controlla la risposta var data; var intRispostaValida = 0; var intEmailInviata = 0; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkContatto.php", data: 'action=checkRispostaRecuperoCodici&pstrEmailVerifica=' + $('#email_verifica').val() + '&pstrRisposta=' + $('#risposta').val(), success: function(data) { intRispostaValida = data.risposta_valida; intEmailInviata = data.email_inviata; if ( data.status == 'ok' ) { $('#box_richiesta').addClass('hide'); if ( intRispostaValida == '1' ) { // risposta valida $('#box_domanda').addClass('hide'); if ( intEmailInviata == '1' ) $('#box_message').removeClass('hide'); else $('#box_message_none').removeClass('hide'); } else { // risposta non valida blnReturn = false; $( ".fg-risposta" ).addClass( "has-error" ); $('#box_riconoscimento').addClass('hide'); $('#risposta').val('').focus(); swal("Ops...", "The answer is wrong.", "error"); } } else swal("Ops...", "", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); } $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); return false; }); }); // Riconoscimento utente function fRiconoscimento() { $('#box_richiesta').addClass('hide'); $('#box_riconoscimento').removeClass('hide'); $('#email').val(''); $('#email').focus(); } // Annulla Riconoscimento utente function fAnnullaRiconoscimento() { $('#email').val(''); $('#box_riconoscimento').addClass('hide'); $('#box_richiesta').removeClass('hide'); } // Controllo campi obbligatori Box Riconoscimento function fCheckObbligatoriRiconoscimento() { var blnReturn = true; $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); if ( $('#email').val() == "" ) { blnReturn = false; $( ".fg-email" ).addClass( "has-error" ); $('#lblemail').html(""); //swal("Ops...", "Insert the email address.", "error"); $('#email').focus(); } else { $('#lblemail').html(''); var data; var strEmail = ''; var intEmailExists = 0; var strDomanda = ''; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkContatto.php", data: 'action=checkEmailCodici&pstrEmail=' + $('#email').val(), success: function(data) { strEmail = data.email; intEmailExists = data.email_exists; strDomanda = data.domanda; if ( data.status == 'ok' ) { if ( intEmailExists == '1' ) { $('#lblemail').html(""); fDomanda( strDomanda, strEmail ); } else { blnReturn = false; $('#lblemail').html("The address is not registered in our archive!"); $( ".fg-email" ).addClass( "has-error" ); } } else swal("Ops...", "", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); } return blnReturn; } // Domanda di sicurezza function fDomanda( pstrDomanda, pstrEmail ) { if ( pstrDomanda == "" ) { swal("Ops...", "The automatic access code recovery is not active.", "warning"); $('#box_riconoscimento').addClass('hide'); $('#email').val(''); $('#box_domanda').addClass('hide'); $('#box_richiesta').removeClass('hide'); } else { $('#box_riconoscimento').addClass('hide'); $('#box_domanda').removeClass('hide'); $('#email_verifica').val( pstrEmail ); $('#domanda').html( pstrDomanda ); $('#risposta').focus(); } } // Annulla Domanda function fAnnullaDomanda() { $('#email, #email_verifica, #risposta').val(''); $('#box_domanda, #box_richiesta, #box_riconoscimento').addClass('hide'); $('#domanda').html(''); $('#box_richiesta').removeClass('hide'); } // Controllo campi obbligatori Box Domanda function fCheckObbligatoriDomanda() { var blnReturn = true; if ( $('#risposta').val() == "" ) { blnReturn = false; swal("Ops...", "Enter the answer.", "warning"); $('#risposta').focus(); } return blnReturn; }