$( function()
{
$("#completa-ordine").click(function()
{
if ( parseInt( $('#ordine_acquistabile').val() ) > 0 )
{
if( fCheckObbligatori() ) fSaveData();
}
else swal( "Attenzione!", "L'ordine non è disponibile.", "error" );
});
$('input[name=scelta]').change(function()
{
$('.label_scelta span').removeClass('active');
if ( $(this).val() == 'registrazione' )
{
$('#label_scelta_registrazione span').addClass('active');
$('.row-nessuna-registrazione-box').addClass('hide');
$('.row-registrazione-box').removeClass('hide');
$('#registra-newsletter').prop('checked', true);
$('#txtPassword').focus();
}
else
{
$('#label_scelta_nessuna_registrazione span').addClass('active');
$('.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()
{
$('#totale_ordine_loader').removeClass('hide');
$('.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();
$('#totale_ordine_loader').addClass('hide');
});
// tipo_registrazione
$('.tipo_registrazione').change(function()
{
if ( $('.tipo_registrazione:checked').val() == 'azienda' )
{
// AZIENDA
$('.fg-txtRagioneSociale').removeClass('hide');
$('#col-codicefiscale, #col-partitaiva').removeClass('hide');
}
else
{
// PRIVATO
$('.fg-txtRagioneSociale').addClass('hide');
$('#col-partitaiva').addClass('hide');
$('#col-codicefiscale').removeClass('hide');
}
});
// nazione
$('#cmbNazione').change(function()
{
if ( $(this).val() == 'IT' )
{
$('#label_ricarica_postepay, #label_vaglia, #label_contrassegno').removeClass('hide');
$('#col-citta').removeClass('col-md-8').addClass('col-md-4');
$('#col-provincia').removeClass('hide');
$('#col-codicefiscale').removeClass('hide');
}
else
{
$('.panel-spedizione').addClass('hide');
$('#label_ricarica_postepay, #label_vaglia, #label_contrassegno').addClass('hide');
if ( $("input[name=pagamento]:checked").val() == 'ricarica_postepay'
|| $("input[name=pagamento]:checked").val() == 'vaglia'
|| $("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').addClass('hide');
$('#col-citta').removeClass('col-md-4').addClass('col-md-8');
$('#col-codicefiscale').addClass('hide');
}
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/setCarrello.php",
data: "action=checkSpedizioniBloccate&pstrNazione=" + $('#cmbNazione').val(),
success: function(data)
{
if ( parseInt( data.spedizioni_bloccate ) > 0 )
{
$('#crl_spedizione_box').addClass('hide');
}
else
{
$('#crl_spedizione_box').removeClass('hide');
}
}
}); /* ajax */
fAggiornaTotaleOrdine();
});
// provincia
$('#cmbProvincia').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 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 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 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("Campo obbligatorio");
$( "#txtEmail" ).focus();
}
else if ( $.trim( $('#txtPasswordLogin').val() ) == '' )
{
$( ".fg-txtPasswordLogin" ).addClass( "has-error" );
$( "#lbltxtPasswordLogin" ).html("Campo 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');
}
}
});
$('input[name=radioAssicurata]').change(function()
{
fAggiornaTotaleOrdine();
});
$('#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() + "&totale_peso=" + $("#totale_peso").val() + "&assicurata_con=" + ( $("#radioAssicurata_assicurata").prop('checked') ? 1 : 0 ) + "&pstrLangCurrent=" + $("#lang_current").val() + "&totale_carrello_prodotti=" + $("#totale_carrello_prodotti").val(),
success: function(data)
{
if ( data.status == 'ok' )
{
$('#costo_spedizione').val( data.spedizione_totale );
$('#costo_spedizione_standard').val( data.spedizione_costo_db );
$('#costo_spedizione_assicurata').val( data.assicurazione_db );
/*$('#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 );*/
$('.crl_spedizione_label').html( data.spedizione_label );
$('.crl_spedizione_totale_label').html( data.spedizione_totale_label );
if ( parseInt( data.ordine_acquistabile ) > 0 )
{
if ( data.spedizione_costo_db > 0 )
$('.crl_spedizione_standard').html( '+ € ' + data.spedizione_costo );
else $('.crl_spedizione_standard').html( ' GRATIS' );
if ( data.spedizione_totale > 0 )
$('.crl_spedizione_costo_label').html( '€' + data.spedizione_totale );
else $('.crl_spedizione_costo_label').html( 'GRATIS' );
$('.crl_costo_assicurata').html( '€ ' + data.assicurazione );
$('.spedizione_nondisponibile_provincia').addClass('hide');
$('.spedizione_nondisponibile').addClass('hide');
$('.assicurata_box').removeClass('hide');
}
else if ( $("#cmbNazione").val() == 'IT' && $.trim( $("#cmbProvincia").val() ) == '' )
{
$('.crl_spedizione_costo_label').html( 'scegli la provincia' );
$('.assicurata_box').addClass('hide');
$('.spedizione_nondisponibile').addClass('hide');
$('.spedizione_nondisponibile_provincia').removeClass('hide');
}
else
{
$('.crl_spedizione_costo_label').html( 'non disponibile' );
$('.spedizione_nondisponibile_provincia').addClass('hide');
$('.assicurata_box').addClass('hide');
$('.spedizione_nondisponibile').removeClass('hide');
}
$('#crl_imponibile').html( '€' + data.imponibile );
$('#crl_totale_iva').html( '€' + data.totale_iva );
$('#crl_totale_label').html( '€' + data.totale_ordine );
$('#ordine_acquistabile').val( parseInt( data.ordine_acquistabile ) );
if ( strID_Pagamento == 'contrassegno' && ! parseInt( data.has_contrassegno_free ) ) $('#row-contrassegno').removeClass('hide'); else $('#row-contrassegno').addClass('hide');
/*if ( parseInt( data.spedizione_bloccata ) > 0 )
{
$('#spedizione_non_disponibile').removeClass('hide');
$('#completa-ordine').addClass('hide');
$('#completa-ordine-blocked-spedizione').removeClass('hide');
}
else
{
$('#spedizione_non_disponibile').addClass('hide');
$('#completa-ordine-blocked-spedizione').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 strPagamento = '';
var blnSaved = false;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/sendOrder.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 if ( data.status == 'spedizioni_bloccate' )
{
swal("Attenzione!", "Per la spedizione al di fuori dell'Europa 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 ( blnSaved && strID_Ordine != '' )
{
if ( strPagamento == 'paypal' )
{
// PAGAMENTO PAYPAL
fLoading( 1 );
$('#frameAcquista').attr( 'src', '/include/paypal_form.php?lang_current=it&id_ordine=' + strID_Ordine + '&pagamento=' + $("input[name=pagamento]:checked").val() );
}
else
{
location.href = '/ordine-inviato/';
}
}
else
{
$('#submitLoad').addClass('hide');
$('#submitBut').removeClass('hide');
}
}
// Controllo campi obbligatori
function fCheckObbligatori()
{
var blnReturn = true;
var strAlert = "";
$('submit').focus();
$('#submitBut').addClass('hide');
$('#submitLoad').removeClass('hide');
$( ".form-group, .fg-txtRecapito1" ).removeClass( "has-error" );
$( ".lbl" ).html("");
var sceltaRegistrazione = $('#scelta_registrazione').prop('checked');
var strID_Contatto = ( $('#id_cliente').length ? $('#id_cliente').val() : '' );
// Controllo email
if ( $("#txtEmail").val() != '' )
{
$('#loader-email').removeClass('hide');
$('#lbltxtEmail').html( '' );
var intErrore = '';
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/checkEmail.php",
data: "action=checkEmail&pstrEmail=" + $("#txtEmail").val(),
success: function(data)
{
intErrore = data.errore;
if ( intErrore == 1 )
{
// ERRORE : email NON corretta
blnReturn = false;
$('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non è corretto." ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
strAlert = "L'email non è corretta.";
}
else if ( intErrore == 2 )
{
// ERRORE : email NON esiste
blnReturn = false;
$('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non esiste" ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
strAlert = "L'email non esiste.";
}
if ( data.status == 'errore' )
blnSaved = false;
else if ( data.status == 'ok' )
blnSaved = true;
else swal("Ops...", "Verifica non riuscita", "error");
},
error: function(data) {
swal("Ops...", "Procedura non completata.", "error");
}
});
}
$('.required').each(function()
{
if ( $.trim( $(this).val() ) == "" )
{
blnReturn = false;
$( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Campo 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 ( $('#cmbNazione').val() == 'IT' && $.trim( $('#cmbProvincia').val() ) == '' )
{
blnReturn = false;
$('#lblcmbProvincia').html( fHTMLErrore( "" ) );
$( ".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( "Campo obbligatorio" ) );
$(".fg-txtPassword").addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la password";
}
else $("#lbltxtPassword").html("");
if ( $.trim( $('#txtConfermaPassword').val() ) == '' )
{
blnReturn = false;
$("#lbltxtConfermaPassword").html( fHTMLErrore( "Campo 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( "Campo obbligatorio" ) );
$( ".fg-txtRagioneSociale" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la ragione sociale";
}
else
{
$( "#lbltxtRagioneSociale" ).html("");
}
}
var blnEstero = ( $('#cmbNazione').val() != 'IT' ? true : false ); //;
// Controllo Codice fiscale
if ( ! blnEstero && $('.tipo_registrazione:checked').val() == 'privato' )
{
if ( $.trim( $('#txtCodiceFiscale').val() ) == "" )
{
blnReturn = false;
$( "#lbltxtCodiceFiscale" ).html( fHTMLErrore( "Campo obbligatorio" ) );
$( ".fg-txtCodiceFiscale" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci il codice fiscale";
}
else
{
$( "#lbltxtCodiceFiscale" ).html("");
$('#lbltxtCodiceFiscale').html( '
' );
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 ( $('.tipo_registrazione:checked').val() != 'privato' )
{
if ( $.trim( $('#txtPartitaIva').val() ) == "" )
{
blnReturn = false;
$( "#lbltxtPartitaIva" ).html( fHTMLErrore( "Campo obbligatorio" ) );
$( ".fg-txtPartitaIva" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la partita IVA";
}
else
{
$( "#lbltxtPartitaIva" ).html("");
$('#lbltxtPartitaIva').html( '
' );
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 != "" ) 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();
$.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 */
});
}