$( function()
{
$("#completa-ordine").click(function()
{
if( fCheckObbligatori() ) fSaveData();
});
$('#richiedi-preventivo').click(function()
{
if( fCheckObbligatori() ) fSavePreventivo();
});
$('input[name=scelta]').change(function()
{
if ( $(this).val() == 'registrazione' )
{
$('.row-nessuna-registrazione-box').addClass('hide');
$('.row-registrazione-box').removeClass('hide');
$('#registra-newsletter').prop('checked', true);
$('#txtPassword').focus();
}
else
{
$('.row-registrazione-box').addClass('hide');
$('.row-nessuna-registrazione-box').removeClass('hide');
$('#registra-newsletter').prop('checked', false);
$('.fg-txtPassword, .fg-txtConfermaPassword').removeClass('has-error');
$('#lbltxtPassword, #lbltxtConfermaPassword').html('');
}
});
$('input[name=pagamento]').change(function()
{
fLoading( 1 );
$('.scegli-pagamento-radio label > span').removeClass('active');
$('.pagamento_descrizione').addClass('hide');
var pagid = $(this).val();
if ( $(this).prop('checked') )
{
$( '#pagamento_span_' + pagid ).addClass('active');
$( '.pagamento_descrizione_' + pagid ).removeClass('hide');
}
fAggiornaTotaleOrdine();
fLoading( 0 );
});
// tipo_registrazione
$('.tipo_registrazione').change(function()
{
if ( $('.tipo_registrazione:checked').val() == 'azienda' )
{
// AZIENDA
$('.fg-txtRagioneSociale').removeClass('hide');
if ( $('#cmbNazione').val() == 'IT' )
{
// AZIENDA ITALIA
$('#col-partitaiva').removeClass('col-md-12').addClass('col-md-6').removeClass('hide');
$('#col-codicefiscale').removeClass('col-md-12').addClass('col-md-6').removeClass('hide');
$('#fastk-txtCodiceFiscale, #fastk-txtPartitaIva').removeClass('hide');
}
else
{
// AZIENDA ESTERO
$('#col-partitaiva').removeClass('col-md-6').addClass('col-md-12').removeClass('hide');
$('#col-codicefiscale').removeClass('col-md-6').addClass('col-md-12').addClass('hide');
$('#fastk-txtCodiceFiscale, #fastk-txtPartitaIva').addClass('hide');
}
}
else
{
// PRIVATO
$('.fg-txtRagioneSociale').addClass('hide');
$('#col-partitaiva').removeClass('col-md-12').addClass('col-md-6').addClass('hide');
if ( $('#cmbNazione').val() == 'IT' )
{
// PRIVATO ITALIA
$('#col-codicefiscale').removeClass('col-md-6').addClass('col-md-12').removeClass('hide');
$('#fastk-txtCodiceFiscale, #fastk-txtPartitaIva').removeClass('hide');
}
else
{
// PRIVATO ESTERO
$('#col-codicefiscale').removeClass('col-md-6').addClass('col-md-12').removeClass('hide');
$('#fastk-txtCodiceFiscale, #fastk-txtPartitaIva').addClass('hide');
}
}
fCheckObbligatori(1);
});
// nazione
$('#cmbNazione').change(function()
{
if ( $(this).val() == 'IT' )
{
// ITALIA
$('#label_contrassegno').removeClass('hide');
$('#col-citta').removeClass('col-md-12').addClass('col-md-4');
$('#col-provincia, #col-frazione').removeClass('hide');
$('#fastk-txtCodiceFiscale, #fastk-txtPartitaIva').removeClass('hide');
if ( $('.tipo_registrazione:checked').val() == 'azienda' )
{
// AZIENDA ITALIA
$('#col-partitaiva').removeClass('col-md-12').addClass('col-md-6').removeClass('hide');
$('#col-codicefiscale').removeClass('col-md-12').addClass('col-md-6').removeClass('hide');
}
else
{
// PRIVATO ITALIA
$('#col-partitaiva').removeClass('col-md-12').addClass('col-md-6').addClass('hide');
$('#col-codicefiscale').removeClass('col-md-6').addClass('col-md-12').removeClass('hide');
}
}
else
{
// ESTERO
$('.panel-spedizione').addClass('hide');
$('#label_contrassegno').addClass('hide');
if ( $("input[name=pagamento]:checked").val() == 'contrassegno' )
{
$('.scegli-pagamento-radio label > span').removeClass('active');
$('.pagamento_descrizione').addClass('hide');
$('#pagamento_paypal').prop('checked', true);
$( '#pagamento_span_paypal' ).addClass('active');
$( '.pagamento_descrizione_paypal' ).removeClass('hide');
}
$('#col-provincia, #col-frazione').addClass('hide');
$('#col-citta').removeClass('col-md-4').addClass('col-md-12');
$('#fastk-txtCodiceFiscale, #fastk-txtPartitaIva').addClass('hide');
if ( $('.tipo_registrazione:checked').val() == 'azienda' )
{
// AZIENDA ESTERO
$('#col-partitaiva').removeClass('col-md-6').addClass('col-md-12').removeClass('hide');
$('#col-codicefiscale').removeClass('col-md-6').addClass('col-md-12').addClass('hide');
}
else
{
// PRIVATO ESTERO
$('#col-partitaiva').removeClass('col-md-12').addClass('col-md-6').addClass('hide');
$('#col-codicefiscale').removeClass('col-md-6').addClass('col-md-12').removeClass('hide');
}
}
fAggiornaTotaleOrdine();
fCheckObbligatori(1);
});
// provincia
$('#cmbProvincia').change(function()
{
fAggiornaTotaleOrdine();
});
// Mostra domanda
$('.showdomanda').click(function()
{
$( '#box_txtDomanda' ).addClass('hide');
$( '#boxlista_txtDomanda' ).removeClass('hide');
});
// Mostra lista domande
$('.listadomande').change(function()
{
$( '#txtDomanda' ).val( $(this).val() );
$( '#boxlista_txtDomanda' ).addClass('hide');
$( '#lbltxtDomanda' ).html('');
$( '#box_txtDomanda' ).removeClass('hide');
$( '#txtDomanda' ).focus();
});
// spedizione
$('#cmbSpedizione').change(function()
{
fAggiornaTotaleOrdine();
});
$('.email-continua').click(function()
{
var blnReturn = true;
if ( $('#txtEmail').val() != '' )
{
$('.rblock').addClass('hide');
$('#loader-login').removeClass('hide');
$( ".fg-txtEmail" ).removeClass( "has-error" );
$('#lbltxtEmail').html('');
$('#ciao-cliente').html( '' );
var data;
var strAlert = "";
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/checkContatto.php",
data: "action=checkEmailCarrello&pstrEmail=" + $('#txtEmail').val(),
success: function(data)
{
$('#loader-login').addClass('hide');
if ( data.email_check == 0 )
{
// Email non corretta
if ( data.email_errore == 2 )
{
// ERRORE : email NON esiste
blnReturn = false;
$('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non esiste" ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "L'indirizzo email non esiste";
}
else if ( data.email_errore == 1 )
{
// ERRORE : email NON corretta
blnReturn = false;
$('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non è corretto." ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "L'indirizzo email non è corretto";
}
}
else
{
// Email corretta
if ( data.email_exists == 1 )
{
// ERRORE : email già in archivio
$('.rblock').addClass('hide');
$('.rblock-login').removeClass('hide');
$('#ciao-cliente').html( 'Ciao ' + data.nome + ',
inserisci la tua password per accedere al sito:
' );
}
else
{
// OK : Email unica, corretta e non in archivio
$('.rblock-login').addClass('hide');
$('.rblock').removeClass('hide');
$('#scelta_registrazione').prop('checked',true);
$('#registra-newsletter').prop('checked',true);
}
}
}
}); /* ajax */
}
else
{
$('#txtEmail').focus();
}
if ( ! blnReturn && strAlert != "" )
{
swal("Attenzione!", strAlert, "error");
}
return false;
});
$('#procedi_senza_login').click(function()
{
$('.rblock-login').addClass('hide');
$('.rblock').removeClass('hide');
$('.row-scelta-registrazione, .row-scelta-registrazione-box').addClass('hide');
$('#scelta_nessuna_registrazione').prop('checked', true);
$('#registra-newsletter').prop('checked', false);
$('#ciao-cliente').html( '' );
});
$('#but_login').click(function()
{
$('#submitButLogin').addClass('hide');
$('#submitLoadLogin').removeClass('hide');
$( ".fg-txtEmail" ).removeClass( "has-error" );
$( "#lbltxtEmail" ).html("");
$( ".fg-txtPasswordLogin" ).removeClass( "has-error" );
$( "#lbltxtPasswordLogin" ).html("");
if ( $.trim( $('#txtEmail').val() ) == '' )
{
$( ".fg-txtEmail" ).addClass( "has-error" );
$( "#lbltxtEmail" ).html("Obbligatorio");
$( "#txtEmail" ).focus();
}
else if ( $.trim( $('#txtPasswordLogin').val() ) == '' )
{
$( ".fg-txtPasswordLogin" ).addClass( "has-error" );
$( "#lbltxtPasswordLogin" ).html("Obbligatorio");
$( "#txtPasswordLogin" ).focus();
}
else
{
var data;
var strDestination = '';
var blnSaved = false;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/loginCliente.php",
data: "lang_current=it&txtUsernameCliente=" + $("#txtEmail").val() + "&txtPasswordCliente=" + $("#txtPasswordLogin").val(),
success: function(data)
{
strDestination = data.destination;
if ( data.status == 'ok' )
blnSaved = true;
else swal("Ops...", "Impossibile effettuare l'operazione.", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
}); /* ajax */
if ( blnSaved )
{
if ( strDestination != '' )
{
location.href = strDestination;
}
else
{
$('#submitLoadLogin').addClass('hide');
$('#submitButLogin').removeClass('hide');
$('#loginErrore').removeClass('hide');
fLoading( 0 );
}
}
else
{
$('#submitLoadLogin').addClass('hide');
$('#submitButLogin').removeClass('hide');
}
}
});
$('#verifica_codice_sconto').click(function()
{
$('#row-sconto-carrello').addClass('hide');
$('#sconto_carrello_descrizione, #sconto_carrello_label').html( '' );
$('#sconto_carrello').val( 0 );
$('#codice_sconto_carrello').val( '' );
$('.fg-txtCodiceScontoInput').removeClass('has-error');
if ( $.trim( $('#txtCodiceScontoInput').val() ) == '' )
{
$('.fg-txtCodiceScontoInput').addClass('has-error');
$('#txtCodiceScontoInput').focus();
}
else
{
$('.panel-hai-un-codice').addClass('hide');
$('.panel-hai-un-codice-loader').removeClass('hide');
var data;
var blnVerifica = false;
var strLabelTop = "";
var strLabel = "";
var strLabelType = "";
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/setCodiceSconto.php",
data: "action=setCodiceSconto&id_cliente=" + $("#id_cliente").val() + "&codice_sconto=" + $('#txtCodiceScontoInput').val() + "&lang_current=" + $('#lang_current').val(),
success: function(data)
{
$('#hai-un-codice-loader').addClass('hide');
if ( data.status == 'ok' )
{
if ( data.verifica > 0 )
{
blnVerifica = true;
$('#sconto_carrello_descrizione').html( data.sconto_descrizione );
$('#sconto_carrello_label').html( data.sconto_valore_label );
$('#sconto_carrello').val( data.sconto_valore );
$('#codice_sconto_carrello').val( data.codice );
$('#row-sconto-carrello').removeClass('hide');
$('#codice_success_label').html( data.sconto_success_label );
strLabelTop = "Ok";
strLabel = "Lo sconto è stato inserito correttamente.";
strLabelType = "success";
}
else
{
strLabelTop = data.label_top;
strLabel = data.label;
strLabelType = data.label_type;
}
}
else
{
swal("Ops...", "Impossibile effettuare l'operazione.", "error");
}
},
error: function(data)
{
swal("Ops...", "Procedura non completata.", "error");
}
});
fAggiornaTotaleOrdine();
$('.panel-hai-un-codice-loader').addClass('hide');
if ( blnVerifica )
$('.panel-hai-un-codice-success').removeClass('hide');
else $('.panel-hai-un-codice').removeClass('hide');
if ( strLabelTop != "" ) swal( strLabelTop, strLabel,strLabelType );
}
});
$('#rimuovi_codice_sconto').click(function()
{
$('.panel-hai-un-codice-success').addClass('hide');
$('.panel-hai-un-codice-loader').removeClass('hide');
$('#row-sconto-carrello').addClass('hide');
$('#sconto_carrello_descrizione, #sconto_carrello_label').html( '' );
$('#sconto_carrello').val( 0 );
$('#codice_sconto_carrello').val( '' );
$('#txtCodiceScontoInput').val( '' );
fAggiornaTotaleOrdine();
$('.panel-hai-un-codice-loader').addClass('hide');
$('.panel-hai-un-codice').removeClass('hide');
swal( "Ok", "Lo sconto è stato rimosso.", "success" );
});
});
function fAggiornaTotaleOrdine()
{
$('#totale_ordine_loader').removeClass('hide');
var data;
var strID_Pagamento = $("input[name=pagamento]:checked").val();
var strNazione = $("#cmbNazione").val();
if ( strNazione == '' ) strNazione = 'IT';
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/setCarrello.php",
data: "action=setTotaleCarrello&id_cliente=" + $("#id_cliente").val() + "&provincia=" + $("#cmbProvincia").val() + "&nazione=" + strNazione + "&id_pagamento=" + strID_Pagamento + "&sconto=" + $("#sconto_carrello").val() + "&spedizione=" + $("#cmbSpedizione").val() + "&pstrLangCurrent=" + $("#lang_current").val() + "&totale_carrello_prodotti=" + $("#totale_carrello_prodotti").val(),
success: function(data)
{
if ( data.status == 'ok' )
{
$('#crl_spedizione_label').html( data.spedizione_label );
$('#crl_spedizione_costo_label').html( data.spedizione_costo );
$('#crl_contrassegno').html( data.contrassegno_costo );
$('#crl_paypal_commissioni').html( data.paypal_commissioni );
$('#crl_totale_label').html( data.totale_ordine );
if ( data.nazione != 'it' )
{
$('#spedizione_non_disponibile').removeClass('hide');
$('#completa-ordine').addClass('hide');
$('#richiedi-preventivo').removeClass('hide');
}
else
{
$('#spedizione_non_disponibile').addClass('hide');
$('#richiedi-preventivo').addClass('hide');
$('#completa-ordine').removeClass('hide');
}
}
else swal("Ops...", "Impossibile effettuare l'operazione.", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
});
if ( strID_Pagamento == 'contrassegno' ) $('#row-contrassegno').removeClass('hide'); else $('#row-contrassegno').addClass('hide');
if ( strID_Pagamento == 'paypal' || strID_Pagamento == 'carta' || strID_Pagamento == 'postepay' )
$('#row-paypal-commissioni').removeClass('hide'); else $('#row-paypal-commissioni').addClass('hide');
$('#totale_ordine_loader').addClass('hide');
}
function fSaveData()
{
$('submit').focus();
$('#submitBut').addClass('hide');
$('#submitLoad').removeClass('hide');
var data;
var strDestination = '';
var strID_Ordine = '';
var blnSaved = false;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/sendOrder2.php",
data: $("#frmCompletaOrdine").serialize(),
success: function(data)
{
if ( data.status == 'obbligatori' )
$('#completaErrore').removeClass('hide');
else $('#completaErrore').addClass('hide');
if ( data.status == 'ok' )
{
blnSaved = true;
strID_Ordine = data.id_ordine;
strDestination = data.destination;
}
else if ( data.status == 'estero' )
{
swal("Attenzione!", "Per la spedizione all'estero contatta il nostro staff per un preventivo, grazie.", "warning");
}
else swal("Ops...", "Impossibile effettuare l'operazione.", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
});
if ( strID_Ordine != '' && strDestination != '' )
{
location.href = strDestination;
}
else
{
$('#submitLoad').addClass('hide');
$('#submitBut').removeClass('hide');
}
}
function fSavePreventivo()
{
$('submit').focus();
$('#submitBut').addClass('hide');
$('#submitLoad').removeClass('hide');
var data;
var strDestination = '';
var strID_Ordine = '';
var strPagamento = '';
var blnSaved = false;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/sendPreventivo.php",
data: $("#frmCompletaOrdine").serialize(),
success: function(data)
{
strPagamento = data.pagamento;
if ( data.status == 'obbligatori' )
$('#completaErrore').removeClass('hide');
else $('#completaErrore').addClass('hide');
if ( data.status == 'ok' )
{
blnSaved = true;
strID_Ordine = data.id_ordine;
}
else swal("Ops...", "Impossibile effettuare l'operazione.", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
});
if ( blnSaved && strID_Ordine != '' )
{
location.href = '/preventivo-inviato/';
}
else
{
$('#submitLoad').addClass('hide');
$('#submitBut').removeClass('hide');
}
}
// Controllo campi obbligatori
function fCheckObbligatori( pintHideAlert )
{
var blnReturn = true;
var blnItalia = ( $('#cmbNazione').val() == 'IT' );
var strAlert = "";
$('submit').focus();
$('#submitBut').addClass('hide');
$('#submitLoad').removeClass('hide');
$( ".form-group, .fg-txtRecapito1, .fg-txtRagioneSociale" ).removeClass( "has-error" );
$( ".lbl" ).html("");
var sceltaRegistrazione = $('#scelta_registrazione').prop('checked');
var strID_Contatto = ( $('#id_cliente').length ? $('#id_cliente').val() : '' );
$('.required').each(function()
{
if ( $.trim( $(this).val() ) == "" )
{
blnReturn = false;
$( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Obbligatorio" ) );
$( ".fg-" + $(this).attr("name") ).addClass( "has-error" );
if ( strAlert == "" )
if ( $(this).attr("name") == "txtEmail" )
strAlert = "Inserisci la tua email e clicca su continua per inserire i dati per la spedizione.";
else strAlert = "Inserisci il campo: " + $( "#lbl" + $(this).attr("name") ).attr("title");
}
else $( "#lbl" + $(this).attr("name") ).html("");
});
// Controllo provincia
if ( blnItalia && $.trim( $('#cmbProvincia').val() ) == '' )
{
blnReturn = false;
$('#lblcmbProvincia').html( fHTMLErrore( "Obbligatorio" ) );
$( ".fg-cmbProvincia" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la provincia";
}
else $('#lblcmbProvincia').html("");
if ( $('#scelta_registrazione').prop('checked') )
{
// Controllo password
if ( $.trim( $('#txtPassword').val() ) == '' )
{
blnReturn = false;
$("#lbltxtPassword").html( fHTMLErrore( "Obbligatorio" ) );
$(".fg-txtPassword").addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la password";
}
else $("#lbltxtPassword").html("");
if ( $.trim( $('#txtConfermaPassword').val() ) == '' )
{
blnReturn = false;
$("#lbltxtConfermaPassword").html( fHTMLErrore( "Obbligatorio" ) );
$(".fg-txtConfermaPassword").addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la conferma password";
}
else $("#lbltxtConfermaPassword").html("");
if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' )
{
if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() )
{
blnReturn = false;
$('#lbltxtConfermaPassword').html( fHTMLErrore( "La password non è uguale." ) );
$( ".fg-txtConfermaPassword" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "La password non è uguale";
}
else $('#lbltxtConfermaPassword').html("");
}
}
// Controllo privacy
if( ! $('#privacy').prop('checked') )
{
blnReturn = false;
$('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) );
$( ".fg-privacy" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "L'accettazione delle norme sulla privacy è obbligatoria";
}
else $('#lblprivacy').html("");
// Controllo RagioneSociale
if ( $('.tipo_registrazione:checked').val() != 'privato' )
{
if ( $.trim( $('#txtRagioneSociale').val() ) == "" )
{
blnReturn = false;
$( "#lbltxtRagioneSociale" ).html( fHTMLErrore( "Obbligatorio" ) );
$( ".fg-txtRagioneSociale" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la ragione sociale";
}
else
{
$( "#lbltxtRagioneSociale" ).html("");
}
}
// Controllo Codice fiscale
if ( blnItalia )
{
$('#txtCodiceFiscale').val( $.trim( $('#txtCodiceFiscale').val() ) );
if ( $.trim( $('#txtCodiceFiscale').val() ) == "" )
{
blnReturn = false;
$( "#lbltxtCodiceFiscale" ).html( fHTMLErrore( "Obbligatorio" ) );
$( ".fg-txtCodiceFiscale" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci il codice fiscale";
}
else
{
$( "#lbltxtCodiceFiscale" ).html("");
$('#lbltxtCodiceFiscale').html( '' );
var strControllaCF = ControllaCF( $('#txtCodiceFiscale').val() );
if ( strControllaCF != "" && $('.tipo_registrazione:checked').val() == 'privato' )
{
// ERRORE : NON valido
blnReturn = false;
$('#lbltxtCodiceFiscale').html( fHTMLErrore( strControllaCF ) );
$( ".fg-txtCodiceFiscale" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = strControllaCF;
}
else
{
var data;
var intExists = 0;
var blnSaved = false;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/checkContatto.php",
data: "action=checkCodiceFiscale&pstrCodiceFiscale=" + $("#txtCodiceFiscale").val() + "&pstrID_Contatto=" +strID_Contatto,
success: function(data)
{
intExists = data.codice_fiscale_exists;
if ( intExists == 1 && ! $('#scelta_nessuna_registrazione').prop('checked') )
{
// ERRORE : valore NON unico
blnReturn = false;
$('#lbltxtCodiceFiscale').html( fHTMLErrore( "Il valore è già in archivio." ) );
$( ".fg-txtCodiceFiscale" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Il codice fiscale è già in archivio";
}
else
{
// OK : valore unico
$('#lbltxtCodiceFiscale').html("");
}
if ( data.status == 'ok' )
blnSaved = true;
else swal("Ops...", "LNG_AJAX_VERIFICA", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
});
}
}
}
// Controllo Partita IVA
if ( blnItalia && $('.tipo_registrazione:checked').val() == 'azienda' )
{
$('#txtPartitaIva').val( $.trim( $('#txtPartitaIva').val() ) );
if ( $.trim( $('#txtPartitaIva').val() ) == "" )
{
blnReturn = false;
$( "#lbltxtPartitaIva" ).html( fHTMLErrore( "Obbligatorio" ) );
$( ".fg-txtPartitaIva" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la partita IVA";
}
else
{
$( "#lbltxtPartitaIva" ).html("");
$('#lbltxtPartitaIva').html( '' );
var strControllaPIVA = ControllaPIVA( $('#txtPartitaIva').val() );
if ( strControllaPIVA != "" )
{
// ERRORE : NON valido
blnReturn = false;
$('#lbltxtPartitaIva').html( fHTMLErrore( strControllaPIVA ) );
$( ".fg-txtPartitaIva" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = strControllaPIVA;
}
else
{
var data;
var intExists = 0;
var blnSaved = false;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/checkContatto.php",
data: "action=checkPartitaIva&pstrPartitaIva=" + $("#txtPartitaIva").val() + "&pstrID_Contatto=" +strID_Contatto,
success: function(data)
{
intExists = data.partita_iva_exists;
if ( intExists == 1 && ! $('#scelta_nessuna_registrazione').prop('checked') )
{
// ERRORE : valore NON unico
blnReturn = false;
$('#lbltxtPartitaIva').html( fHTMLErrore( "Il valore è già in archivio." ) );
$( ".fg-txtPartitaIva" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "La partita IVA è già in archivio";
}
else
{
// OK : valore unico
$('#lbltxtPartitaIva').html("");
}
if ( data.status == 'ok' )
blnSaved = true;
else swal("Ops...", "LNG_AJAX_VERIFICA", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
});
}
}
}
$('#submitLoad').addClass('hide');
$('#submitBut').removeClass('hide');
if ( ! blnReturn )
{
$('#completaErrore').removeClass('hide');
if ( strAlert != "" && ! ( parseInt( pintHideAlert ) > 0 ) ) swal("Attenzione!", strAlert, "error");
}
else $('#completaErrore').addClass('hide');
return blnReturn;
}
function fHTMLErrore( pstr )
{
return '' + pstr + '';
}
// Aggiorna quantita
function fAggiornaQuantita( pstrKey, pintID_Riga )
{
fLoading( 1 );
var pintQuantita = $('#quantita_'+pintID_Riga).val();
if ( ! parseInt( pintQuantita ) ) pintQuantita = 1;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/setCarrello.php",
data: "action=aggiornaQuantita&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga + "&pintQuantita=" + pintQuantita,
success: function(data)
{
if ( data.status == 'ok' )
{
location.href = '/carrello/' + ( data.max == 'exceed' ? '?max=exceed' : '' );
}
else swal("Ops...", "Impossibile effettuare l'operazione.", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
}); /* ajax */
}
// Rimuovi prodotto
function fDelProd( pstrKey, pintID_Riga )
{
swal({
title: "Attenzione!",
text: "Vuoi cancellare questo prodotto dal carrello?",
type: "warning",
showCancelButton: true,
cancelButtonText: "No, annulla",
confirmButtonText: "Si, cancella!",
closeOnConfirm: true
},
function()
{
fLoading( 1 );
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/setCarrello.php",
data: "action=rimuoviProdotto&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga,
success: function(data)
{
if ( data.status == 'ok' )
{
location.href = '/carrello/';
}
else swal("Ops...", "Impossibile effettuare l'operazione.", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
}); /* ajax */
});
}
// Svuota carrello
function fSvuotaCarrello( pstrKey )
{
swal({
title: "Attenzione!",
text: "Vuoi cancellare tutti i prodotti dal carrello?",
type: "warning",
showCancelButton: true,
cancelButtonText: "No, annulla",
confirmButtonText: "Si, cancella!",
closeOnConfirm: true
},
function()
{
fLoading( 1 );
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/setCarrello.php",
data: "action=svuotaCarrello&pstrKey=" + pstrKey,
success: function(data)
{
if ( data.status == 'ok' )
{
location.href = '/carrello/';
}
else swal("Ops...", "Impossibile effettuare l'operazione.", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
}); /* ajax */
});
}