$(function()
{
$('#frmDomanda').submit(function()
{
$('#submitBut').hide();
$('#submitLoad').show();
if ( fCheckObbligatoriDomanda() )
{
// Controlla la risposta
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/ajax/checkContatto.php",
data: 'action=checkRispostaRecuperoCodici&pstrEmailVerifica=' + $('#email_verifica').val() + '&pstrRisposta=' + $('#risposta').val(),
success: function(data)
{
intRispostaValida = data.risposta_valida;
intEmailInviata = data.email_inviata;
strTmp = data.status;
if ( data.status == 'ok' )
{
$('#box_richiesta').hide();
if ( intRispostaValida == '1' )
{
// risposta valida
$('#box_domanda').hide();
if ( intEmailInviata == '1' )
$('#box_message').show();
else $('#box_message_none').show();
}
else
{
// risposta non valida
blnReturn = false;
$('#box_riconoscimento').hide();
$('#risposta').val('').focus();
alert( "La risposta non corrisponde." );
}
}
else alert("verifica non riuscita.");
},
error: function(data){
alert("errore: " + data);
}
});
}
$('#submitLoad').hide();
$('#submitBut').show();
return false;
});
});
// Riconoscimento utente
function fRiconoscimento()
{
$('#box_richiesta').hide();
$('#box_riconoscimento').show();
$('#email').val('');
$('#email').focus();
}
// Annulla Riconoscimento utente
function fAnnullaRiconoscimento()
{
$('#email').val('');
$('#box_riconoscimento').hide();
$('#box_richiesta').show();
}
// Controllo campi obbligatori Box Riconoscimento
function fCheckObbligatoriRiconoscimento()
{
var blnReturn = true;
if ( $('#email').val() == "" )
{
blnReturn = false;
$('#lblemail').addClass('errore');
$('#lblemail').html("");
alert( "Inserisci l'indirizzo email. \n" );
$('#email').focus();
}
else
{
$('#lblemail').addClass('conferma');
$('#lblemail').html('');
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/ajax/checkContatto.php",
data: 'action=checkEmailCodici&pstrEmail=' + $('#email').val(),
success: function(data)
{
strEmail = data.email;
intEmailExists = data.email_exists;
strDomanda = data.domanda;
strTmp = data.status;
if ( data.status == 'ok' )
{
if ( intEmailExists == '1' )
{
$('#lblemail').removeClass('errore').addClass('conferma');
$('#lblemail').html("");
fDomanda( strDomanda, strEmail );
}
else
{
blnReturn = false;
$('#lblemail').removeClass('conferma').addClass('errore');
$('#lblemail').html("L'indirizzo non risulta inserito nel nostro archivio!");
}
}
else alert("verifica non riuscita.");
},
error: function(data){
alert("errore: " + data);
}
});
}
return blnReturn;
}
// Domanda di sicurezza
function fDomanda( pstrDomanda, pstrEmail )
{
if ( pstrDomanda == "" )
{
alert( "La procedura di recupero automatico dei codici non risulta attiva." );
$('#box_riconoscimento').hide();
$('#email').val('');
$('#box_domanda').hide();
$('#box_richiesta').show();
}
else
{
$('#box_riconoscimento').hide();
$('#box_domanda').show();
$('#email_verifica').val( pstrEmail );
$('#domanda').html( pstrDomanda );
$('#risposta').focus();
}
}
// Annulla Domanda
function fAnnullaDomanda()
{
$('#email, #email_verifica, #risposta').val('');
$('#box_domanda, #box_richiesta, #box_riconoscimento').hide();
$('#domanda').html('');
$('#box_richiesta').show();
}
// Controllo campi obbligatori Box Domanda
function fCheckObbligatoriDomanda()
{
var blnReturn = true;
if ( $('#risposta').val() == "" )
{
blnReturn = false;
alert( "Inserisci la risposta. \n" );
$('#risposta').focus();
}
return blnReturn;
}