$( function()
{
$('.selectpicker').selectpicker({iconBase:'fontawesome',tickIcon:'fa fa-check',dropupAuto:false});
$("#completa-ordine").click(function()
{
if ( parseInt( $('#ordine_acquistabile').val() ) > 0 )
{
if( fCheckObbligatori('completa-ordine') ) fSaveData();
}
else if ( $("#cmbNazione").val() == 'IT' && $.trim( $('#cmbProvincia').val() ) == '' )
swal( "Warning!", "choose province", "error" );
else swal( "Warning!", "The order is not available.", "error" );
});
$(".richiedi-preventivo").click(function()
{
if( fCheckObbligatori('richiedi-preventivo') ) fSaveData();
});
$('#txtEmail').change(function()
{
$('.loader-txtEmail').removeClass('hide');
$('#lbltxtEmail-login').addClass('hide');
$('#lbltxtEmail, #lbltxtEmail-login').html('');
$(".fg-txtEmail").removeClass("has-error");
if ( $('#id_cliente').val() == '' ) $('.row-scelta-registrazione').removeClass('hide');
if ( $.trim( $(this).val() ) == "" )
{
// ERRORE : email obbligatoria
$(".fg-txtEmail").addClass("has-error");
//$('#lbltxtEmail').html( fHTMLErrore( "required" ) );
}
else if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val())))
{
// ERRORE : email NON corretta
$(".fg-txtEmail").addClass("has-error");
$('#lbltxtEmail').html( fHTMLErrore( "The address is not correct." ) );
}
else if ( $('#id_cliente').val() == '' )
{
var data;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/checkContatto.php",
data: "action=checkEmailCarrello&pstrEmail=" + $('#txtEmail').val(),
success: function(data)
{
// Email corretta
if ( data.email_exists == 1 )
{
// AVVISO : email già in archivio
$('#lbltxtEmail-login').removeClass('hide').html( 'Hello ' + data.nome + ', your email is already registered on the site.
You can login if you want (even with your social account),
or re-enter the data.' );
$('.row-scelta-registrazione').addClass('hide');
$('#email_gia_registrata').val( 1 );
$('#scelta_nessuna_registrazione').prop( 'checked', true );
$(".fg-txtEmail").addClass("has-success");
}
else
{
$('#email_gia_registrata').val( 0 );
}
}
}); /* ajax */
}
$('.loader-txtEmail').addClass('hide');
});
$('input[name=scelta]').change(function()
{
if ( $(this).val() == 'registrazione' )
{
$('.row-nessuna-registrazione-box').addClass('hide');
$('.row-scelta-registrazione-box').removeClass('hide');
$('#registra-newsletter').prop('checked', true);
}
else
{
$('.row-scelta-registrazione-box').addClass('hide');
$('.row-nessuna-registrazione-box').removeClass('hide');
$('.fg-txtPassword, .fg-txtConfermaPassword').removeClass('has-error');
$('#lbltxtPassword, #lbltxtConfermaPassword').html('');
}
});
$('.extra').change(function()
{
$('.extra').each(function()
{
if ( $(this).prop('checked') ) $('#span-extra-'+$(this).val()).removeClass('hide'); else $('#span-extra-'+$(this).val()).addClass('hide');
});
fAggiornaTotaleOrdine();
});
$('.extra2').change(function()
{
$('.extra2').each(function()
{
if ( $(this).prop('checked') ) $('#span-extra2-'+$(this).val()).removeClass('hide'); else $('#span-extra2-'+$(this).val()).addClass('hide');
});
fAggiornaTotaleOrdine();
});
$('input[name=pagamento]').change(function()
{
$('#totale_ordine_loader').removeClass('hide');
$('.scegli-pagamento-radio label > span').removeClass('active').removeClass('font2');
$('.pagamento_descrizione').addClass('hide');
var pagid = $(this).val();
if ( $(this).prop('checked') )
{
$( '#pagamento_span_' + pagid ).addClass('active').addClass('font2');
$( '.pagamento_descrizione_' + pagid ).removeClass('hide');
}
fAggiornaTotaleOrdine();
$('#totale_ordine_loader').addClass('hide');
});
// nazione
$('#cmbNazione').change(function()
{
if ( $(this).val() == 'IT' )
{
$('#col-citta').removeClass('col-sm-8').addClass('col-sm-4');
$('#col-provincia').removeClass('hide');
}
else
{
$('#col-provincia').addClass('hide');
$('#col-citta').removeClass('col-sm-4').addClass('col-sm-8');
}
fCambiaIndirizzoSpedizione();
if ( ! $('#chkSpedizioneDifferente').prop('checked') ) fAggiornaTotaleOrdine();
});
// provincia
$('#cmbProvincia').change(function()
{
if ( ! $('#chkSpedizioneDifferente').prop('checked') ) fAggiornaTotaleOrdine();
});
// provincia
$('#cmbProvincia_Aggiuntivo').change(function()
{
fAggiornaTotaleOrdine();
});
// sp_nazione
$('#cmbSpNazione').change(function()
{
if ( $(this).val() == 'IT' )
{
$('#col-sp-citta').removeClass('col-sm-8').addClass('col-sm-4');
$('#col-sp-provincia').removeClass('hide');
}
else
{
$('#col-sp-provincia').addClass('hide');
$('#col-sp-citta').removeClass('col-sm-4').addClass('col-sm-8');
}
});
// agg_nazione
$('#cmbNazione_Aggiuntivo').change(function()
{
if ( $(this).val() == 'IT' )
{
$('#col-agg-citta').removeClass('col-sm-8').addClass('col-sm-4');
$('#col-agg-provincia').removeClass('hide');
}
else
{
$('#col-agg-provincia').addClass('hide');
$('#col-agg-citta').removeClass('col-sm-4').addClass('col-sm-8');
}
fCambiaIndirizzoSpedizione();
fAggiornaTotaleOrdine();
});
// spedizione_differente
$('#chkSpedizioneDifferente').change(function()
{
if ( $(this).prop('checked') )
$('#spedizione_differente').removeClass('hide');
else $('#spedizione_differente').addClass('hide');
fCambiaIndirizzoSpedizione();
fAggiornaTotaleOrdine();
});
// dati_fatturazione
$('#chkDatiFatturazione').change(function()
{
if ( $(this).prop('checked') )
{
//$('.fg-chkDatiFatturazione').css('margin-top','30px');
$('#dati_fatturazione').removeClass('hide');
}
else
{
$('#dati_fatturazione').addClass('hide');
//$('.fg-chkDatiFatturazione').css('margin-top','0');
}
});
$('#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)
{
$('.panel-hai-un-codice-loader').addClass('hide');
if ( data.status == 'ok' )
{
if ( parseInt( 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 );
$('.panel-hai-un-codice-success').removeClass('hide');
strLabelTop = "Ok";
strLabel = "The Coupon has been entered correctly.";
strLabelType = "success";
var arrPL_Scontati = ( data.pl_scontati ).split(',');
var sizeof_arrPL_Scontati = arrPL_Scontati.length;
for ( i=0; i Coupon' );
}
}
else
{
strLabelTop = data.label_top;
strLabel = ( data.label ).replace(/\s?(
)\s?/g, "\r\n");
strLabelType = data.label_type;
}
}
else swal("Ops...", "Oops, something went wrong .....", "error");
},
error: function(data) { swal("Ops...", "Oops, something went wrong ...", "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( '' );
$('.prezzo_riga, .totale_riga, #tot_carrello').css('text-decoration','none');
$('#tot_carrello').css('font-weight','700');
$('.prezzo_riga_scontato, .totale_riga_scontato, #tot_carrello_scontato').html('').addClass('hide');
$('.sconto_label span').html('');
fAggiornaTotaleOrdine();
$('.panel-hai-un-codice-loader').addClass('hide');
$('.panel-hai-un-codice').removeClass('hide');
//swal( "Ok", "The Coupon has been removed.", "success" );
});
$('#verifica_gift_card').click(function()
{
$('#row-sconto-gift-card').addClass('hide');
$('#sconto_gift_card_descrizione, #sconto_gift_card_label').html( '' );
$('#sconto_gift_card').val( 0 );
$('#codice_sconto_gift_card').val( '' );
$('.fg-txtGiftCardInput').removeClass('has-error');
if ( $.trim( $('#txtGiftCardInput').val() ) == '' )
{
$('.fg-txtGiftCardInput').addClass('has-error');
$('#txtGiftCardInput').focus();
}
else
{
$('.panel-hai-una-card').addClass('hide');
$('.panel-hai-una-card-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/setGiftCard.php",
data: "action=setGiftCard&id_cliente=" + $("#id_cliente").val() + "&codice_gift_card=" + $('#txtGiftCardInput').val() + "&lang_current=" + $('#lang_current').val(),
success: function(data)
{
$('.panel-hai-una-card-loader').addClass('hide');
if ( data.status == 'ok' )
{
if ( data.verifica > 0 )
{
blnVerifica = true;
$('#sconto_gift_card_descrizione').html( data.sconto_descrizione );
$('#sconto_gift_card_label').html( data.sconto_valore_label );
$('#sconto_gift_card').val( data.sconto_valore );
$('#codice_sconto_gift_card').val( data.codice );
$('#row-sconto-gift-card').removeClass('hide');
$('#card_success_label').html( data.sconto_success_label );
strLabelTop = "Ok";
strLabel = "The Coupon has been entered correctly.";
strLabelType = "success";
}
else
{
strLabelTop = data.label_top;
strLabel = data.label;
strLabelType = data.label_type;
}
}
else swal("Ops...", "Oops, something went wrong .....", "error");
},
error: function(data)
{
swal("Ops...", "Procedure uncompleted.", "error");
}
});
fAggiornaTotaleOrdine();
$('.panel-hai-una-card-loader').addClass('hide');
if ( blnVerifica )
$('.panel-hai-una-card-success').removeClass('hide');
else $('.panel-hai-una-card').removeClass('hide');
if ( strLabelTop != "" ) swal( strLabelTop, strLabel,strLabelType );
}
});
$('#rimuovi_gift_card').click(function()
{
$('.panel-hai-una-card-success').addClass('hide');
$('.panel-hai-una-card-loader').removeClass('hide');
$('#row-sconto-gift-card').addClass('hide');
$('#sconto_gift_card_descrizione, #sconto_gift_card_label').html( '' );
$('#sconto_gift_card').val( 0 );
$('#codice_sconto_gift_card').val( '' );
$('#txtGiftCardInput').val( '' );
fAggiornaTotaleOrdine();
$('.panel-hai-una-card-loader').addClass('hide');
$('.panel-hai-una-card').removeClass('hide');
swal( "Ok", "The Coupon has been removed.", "success" );
});
$('[data-toggle="popover"]').popover({title:''});
});
function fCambiaIndirizzoSpedizione()
{
var o_nazione = $('#cmbNazione').val();
if ( $('#chkSpedizioneDifferente').prop('checked') ) o_nazione = $('#cmbNazione_Aggiuntivo').val();
if ( o_nazione == 'IT' && parseInt( $('#bln_prodotti_carrello').val() ) > 0 )
$('#label_contrassegno').removeClass('hide');
else $('#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');
}
}
function fAggiornaTotaleOrdine()
{
$('#totale_ordine_loader').removeClass('hide');
var e = document.getElementById('mh-totali');
var newheight = window.getComputedStyle(e).height;
$('#mh-totali').css('min-height',newheight);
var strNazione = $('#cmbNazione').val();
var strProvincia = $('#cmbProvincia').val();
if ( $('#chkSpedizioneDifferente').prop('checked') )
{
strNazione = $('#cmbNazione_Aggiuntivo').val();
strProvincia = $('#cmbProvincia_Aggiuntivo').val();
}
if ( strNazione == '' ) strNazione = 'IT';
var data;
var strID_Pagamento = $("input[name=pagamento]:checked").val();
var blnProdottoHide = ( parseInt( $("#carrello_prodotto_hide").val() ) > 0 );
var blnProdottiRegalo = ( parseInt( $("#carrello_prodotti_regalo").val() ) > 0 );
var blnProdottoCard = ( parseInt( $("#carrello_prodotto_card").val() ) > 0 );
var strExtra = "";
$(".extra").each(function(){ strExtra += ( strExtra != "" ? "|" : "" ) + $(this).val() + "-" + ( $(this).prop("checked") ? 1 : 0 ); });
if ( strExtra != "" ) strExtra = "&extra=" + strExtra;
var strExtra2 = "";
$(".extra2").each(function(){ strExtra2 += ( strExtra2 != "" ? "|" : "" ) + $(this).val() + "-" + ( $(this).prop("checked") ? 1 : 0 ); });
if ( strExtra2 != "" ) strExtra2 = "&extra2=" + strExtra2;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "/tpl/default/assets/ajax/setCarrello.php",
data: "action=setTotaleCarrello&id_cliente=" + $("#id_cliente").val()
+ "&provincia=" + strProvincia
+ "&nazione=" + strNazione
+ "&id_pagamento=" + strID_Pagamento
+ "&doppia_spedizione=" + ( $("#doppia-spedizione").prop("checked") ? 1 : 0 )
+ "&peso_pronta_consegna=" + ( $("#peso_pronta_consegna").val() != undefined ? $("#peso_pronta_consegna").val() : 0 )
+ "&peso_non_pronta_consegna=" + ( $("#peso_non_pronta_consegna").val() != undefined ? $("#peso_non_pronta_consegna").val() : 0 )
+ "&carrello_pronta_consegna_prezzo=" + ( $("#carrello_pronta_consegna_prezzo").val() != undefined ? $("#carrello_pronta_consegna_prezzo").val() : 0 )
+ "&carrello_non_pronta_consegna_prezzo=" + ( $("#carrello_non_pronta_consegna_prezzo").val() != undefined ? $("#carrello_non_pronta_consegna_prezzo").val() : 0 )
+ "&totale_peso=" + ( $("#totale_peso").val() != undefined ? $("#totale_peso").val() : 0 )
+ strExtra
+ strExtra2
+ "&pstrLangCurrent=" + $("#lang_current").val()
+ "&totale_carrello_prodotti=" + $("#totale_carrello_prodotti").val()
+ "&tpi=" + $("#tpi").val()
+ "&blnProdottoHide=" + ( blnProdottoHide ? 1 : 0 )
+ "&blnProdottiRegalo=" + ( blnProdottiRegalo ? 1 : 0 )
+ "&blnProdottiCard=" + ( blnProdottoCard ? 1 : 0 )
+ "&sconto=" + $("#sconto_carrello").val()
+ "&sconto_gift_card=" + $("#sconto_gift_card").val(),
success: function(data)
{
if ( data.status == 'ok' )
{
$('#costo_spedizione').val( data.spedizione_totale );
$('.crl_spedizione_label').html( data.spedizione_label );
$('#riepilogoCarrello').slideUp(400,function()
{
if ( $('#doppia-spedizione').prop('checked') )
{
$('.cstl').addClass('hide');
$('.cstl2').removeClass('hide');
$('#row-dsped-2, #row-extra2').removeClass('hide');
}
else
{
$('.cstl2').addClass('hide');
$('.cstl').removeClass('hide');
$('#row-dsped-2, #row-extra2').addClass('hide');
}
if ( parseInt( data.ordine_acquistabile ) > 0 )
{
if ( $('#doppia_spedizione').val() == '1' )
{
if ( parseFloat( data.spedizione_costo_db ) > 0 )
$('#ds-unica-3').html( '' + data.spedizione_costo + '' );
else $('#ds-unica-3').html( 'FREE' );
if ( parseFloat( data.spedizione_costo1_db ) > 0 )
$('#ds-doppia-2').html( '' + data.spedizione_costo1 + '' );
else $('#ds-doppia-2').html( 'FREE' );
if ( parseFloat( data.spedizione_costo2_db ) > 0 ) $('#ds-doppia-5').html( data.spedizione_costo2 );
$('#row-extra').html( data.extra_html1 );
$('#row-extra2').html( data.extra_html2 );
if ( $('#doppia-spedizione').prop('checked') )
{
if ( parseFloat( data.spedizione_costo1_db ) > 0 )
$('.crl_spedizione_costo_label').html( data.spedizione_costo1 );
else $('.crl_spedizione_costo_label').html( 'FREE' );
}
else
{
if ( parseFloat( data.spedizione_costo_db ) > 0 )
$('.crl_spedizione_costo_label').html( data.spedizione_costo );
else $('.crl_spedizione_costo_label').html( 'FREE' );
}
}
else
{
$('#row-extra').html( data.extra_html );
if ( parseFloat( data.spedizione_costo_db ) > 0 )
$('.crl_spedizione_costo_label').html( data.spedizione_costo );
else $('.crl_spedizione_costo_label').html( 'FREE' );
}
if ( parseFloat( data.spedizione_costo2_db ) > 0 )
$('.crl_spedizione_costo_label2').html( data.spedizione_costo2 );
else $('.crl_spedizione_costo_label2').html( 'FREE' );
//$('.spedizione_nondisponibile_provincia').addClass('hide');
//$('.spedizione_nondisponibile').addClass('hide');
$('[data-toggle="popover"]').popover({title:''});
$('.extra').change(function()
{
$('.extra').each(function()
{
if ( $(this).prop('checked') ) $('#span-extra-'+$(this).val()).removeClass('hide'); else $('#span-extra-'+$(this).val()).addClass('hide');
});
fAggiornaTotaleOrdine();
});
$('.extra2').change(function()
{
$('.extra2').each(function()
{
if ( $(this).prop('checked') ) $('#span-extra2-'+$(this).val()).removeClass('hide'); else $('#span-extra2-'+$(this).val()).addClass('hide');
});
fAggiornaTotaleOrdine();
});
/*if ( parseFloat( data.spedizioni_gratuite ) > 0 )
$('#row-spedizioni-gratuite').removeClass('hide');
else $('#row-spedizioni-gratuite').addClass('hide');*/
$('#crl_spedizioni_gratuite_warning').html( data.spedizioni_gratuite_string );
if ( parseInt( data.spedizioni_gratuite ) > 0 )
$('#crl_spedizioni_gratuite_warning').removeClass('hide');
else $('#crl_spedizioni_gratuite_warning').addClass('hide');
if ( parseFloat( data.blnSpedizioniGratuite ) > 0 )
$('#row-spedizioni-gratuite').addClass('hide');
else $('#row-spedizioni-gratuite').removeClass('hide');
}
else if ( $("#cmbNazione").val() == 'IT' && $.trim( $("#cmbProvincia").val() ) == '' )
{
$('.crl_spedizione_costo_label').html( 'choose province' );
//$('.spedizione_nondisponibile').addClass('hide');
//$('.spedizione_nondisponibile_provincia').removeClass('hide');
}
else
{
$('.crl_spedizione_costo_label').html( 'not available' );
//$('.spedizione_nondisponibile_provincia').addClass('hide');
//$('.spedizione_nondisponibile').removeClass('hide');
}
$('#crl_totale_label').html( '' + data.totale_ordine + '€' );
$(this).slideDown();
});
$('#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');
$('#totale_ordine_loader').addClass('hide');
}
else swal("Ops...", "Oops, something went wrong .....", "error");
},
error: function(data) {
swal("Ops...", "Oops, something went wrong ...", "error");
}
});
$('#totale_ordine_loader').addClass('hide');
}
function fSaveData()
{
$('submit').focus();
var strCompletaErrore = 'completaErrore';
if ( ! parseInt( $('#ordine_acquistabile').val() ) )
{
strCompletaErrore = 'completaErrorePreventivo';
$('.submitButPreventivo').addClass('hide');
$('.submitLoadPreventivo').removeClass('hide');
}
else
{
$('#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)
{
strDestination = data.destination;
strPagamento = data.pagamento;
if ( data.status == 'obbligatori' ) $('.'+strCompletaErrore).removeClass('hide'); else $('.'+strCompletaErrore).addClass('hide');
if ( data.status == 'ok' )
{
blnSaved = true;
strID_Ordine = data.id_ordine;
}
else if ( data.status == 'non_acquistabile' )
{
swal("Ops...", "Oops, something went wrong .....", "error");
}
else
{
swal("Ops...", "Oops, something went wrong ...", "error");
}
},
error: function(data)
{
swal("Ops...", "Oops, something went wrong ...", "error");
}
});
if ( blnSaved && strID_Ordine != '' )
{
location.href = strDestination;
}
else
{
if ( ! parseInt( $('#ordine_acquistabile').val() ) )
{
$('.submitLoadPreventivo').addClass('hide');
$('.submitButPreventivo').removeClass('hide');
}
else
{
$('.submitLoad').addClass('hide');
$('#submitBut').removeClass('hide');
}
}
}
// Controllo campi obbligatori
function fCheckObbligatori( pstrFrom )
{
var blnReturn = true;
$('submit').focus();
if ( pstrFrom == 'richiedi-preventivo' )
{
$('.submitButPreventivo').addClass('hide');
$('.submitLoadPreventivo').removeClass('hide');
}
else
{
$('#submitBut').addClass('hide');
$('.submitLoad').removeClass('hide');
}
if ( $("input[name=pagamento]:checked").val() == 'apple' )
{
if (window.ApplePaySession) {
var merchantIdentifier = 'ceramicavietrese.it';
var promise = ApplePaySession.canMakePaymentsWithActiveCard(merchantIdentifier);
promise.then(function (canMakePayments) {
if (canMakePayments)
{
// Apple Pay disponibile
//swal("", "Apple Pay active and available.", "success");
}
else
{
blnReturn = false;
// Apple Pay non disponibile
swal("", "Apple Pay is not available.\nMake sure you have at least one active card in your wallet.", "warning");
}
});
}
else
{
blnReturn = false;
// Apple Pay non attivo
swal("", "Apple Pay is only available from an Apple device or the latest generation Safari browser.\n\nChoose one of the other payment methods available.", "warning");
}
}
if ( blnReturn )
{
$( ".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-txtEmail').removeClass('hide');
$('#lbltxtEmail').html( '' );
if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($('#txtEmail').val())))
{
// ERRORE : email NON corretta
blnReturn = false;
$('#lbltxtEmail').html( fHTMLErrore( "The address is not correct." ) );
$('.fg-txtEmail').addClass('has-error');
}
$('#loader-txtEmail').addClass('hide');
}
$('.required').each(function()
{
if ( $.trim( $(this).val() ) == "" )
{
var elid = $(this).attr('id');
if ( ! parseInt( $('#bln_prodotto_card').val() ) || ( elid != 'txtIndirizzo' && elid != 'txtCap' && elid != 'txtCitta' ) )
{
blnReturn = false;
$( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "required" ) );
$( ".fg-" + $(this).attr("name") ).addClass( "has-error" );
}
}
else $( "#lbl" + $(this).attr("name") ).html("");
});
if ( ! parseInt( $('#bln_prodotto_card').val() ) )
{
// Controllo provincia
if ( $('#cmbNazione').val() == 'IT' && $.trim( $('#cmbProvincia').val() ) == '' )
{
blnReturn = false;
$('#lblcmbProvincia').html( fHTMLErrore( "Required" ) );
$( ".fg-cmbProvincia" ).addClass( "has-error" );
}
else $('#lblcmbProvincia').html("");
if ( $('#chkDatiFatturazione').prop('checked') )
{
$('.required-fatturazione').each(function()
{
if ( $.trim( $(this).val() ) == "" )
{
blnReturn = false;
$( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "required" ) );
$( ".fg-" + $(this).attr("name") ).addClass( "has-error" );
}
else $( "#lbl" + $(this).attr("name") ).html("");
});
if ( $('#txtCodiceFiscale').val() == '' && $.trim( $('#txtPartitaIva').val() ) == '' )
{
blnReturn = false;
$('#lbltxtCFPIVA').html( fHTMLErrore( "Name or company name" ) );
$( ".fg-txtCodiceFiscale, .fg-txtPartitaIva" ).addClass( "has-error" );
}
else $('#lbltxtCFPIVA').html("");
if ( ( $('#cmbSpNazione').val() == 'IT' || $('#cmbSpNazione').val() == '' ) && $.trim( $('#cmbSpProvincia').val() ) == '' )
{
blnReturn = false;
$('#lblcmbSpProvincia').html( fHTMLErrore( "Required" ) );
$( ".fg-cmbSpProvincia" ).addClass( "has-error" );
}
else $('#lblcmbSpProvincia').html("");
if ( $.trim( $('#cmbSpNazione').val() ) == '' )
{
blnReturn = false;
$('#lblcmbSpNazione').html( fHTMLErrore( "Required" ) );
$( ".fg-cmbSpNazione" ).addClass( "has-error" );
}
else $('#lblcmbSpNazione').html("");
}
if ( $('#chkSpedizioneDifferente').prop('checked') )
{
$('.required-differente').each(function()
{
if ( $.trim( $(this).val() ) == "" )
{
blnReturn = false;
$( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "required" ) );
$( ".fg-" + $(this).attr("name") ).addClass( "has-error" );
}
else $( "#lbl" + $(this).attr("name") ).html("");
});
if ( ( $('#cmbNazione_Aggiuntivo').val() == 'IT' || $('#cmbNazione_Aggiuntivo').val() == '' ) && $.trim( $('#cmbProvincia_Aggiuntivo').val() ) == '' )
{
blnReturn = false;
$('#lblcmbProvincia_Aggiuntivo').html( fHTMLErrore( "Required" ) );
$( ".fg-cmbProvincia_Aggiuntivo" ).addClass( "has-error" );
}
else $('#lblcmbProvincia_Aggiuntivo').html("");
if ( $.trim( $('#cmbNazione_Aggiuntivo').val() ) == '' )
{
blnReturn = false;
$('#lblcmbNazione_Aggiuntivo').html( fHTMLErrore( "Required" ) );
$( ".fg-cmbNazione_Aggiuntivo" ).addClass( "has-error" );
}
else $('#lblcmbNazione_Aggiuntivo').html("");
}
}
if ( $('#scelta_registrazione').prop('checked') && ! parseInt( $('#email_gia_registrata').val() ) )
{
// Controllo password
if ( $.trim( $('#txtPassword').val() ) == '' )
{
blnReturn = false;
$("#lbltxtPassword").html( fHTMLErrore( "required" ) );
$(".fg-txtPassword").addClass( "has-error" );
}
else $("#lbltxtPassword").html("");
if ( $.trim( $('#txtConfermaPassword').val() ) == '' )
{
blnReturn = false;
$("#lbltxtConfermaPassword").html( fHTMLErrore( "required" ) );
$(".fg-txtConfermaPassword").addClass( "has-error" );
}
else $("#lbltxtConfermaPassword").html("");
if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' )
{
if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() )
{
blnReturn = false;
$('#lbltxtConfermaPassword').html( fHTMLErrore( "The password is not equal." ) );
$( ".fg-txtConfermaPassword" ).addClass( "has-error" );
}
else $('#lbltxtConfermaPassword').html("");
}
// Controllo domanda
if ( $('#cmbDomanda').val() == '' )
{
blnReturn = false;
$("#lblcmbDomanda").html( fHTMLErrore( "required" ) );
$( ".fg-cmbDomanda" ).addClass( "has-error" );
}
else $("#lblcmbDomanda").html("");
// Controllo risposta
if ( $.trim( $('#txtRisposta').val() ) == '' )
{
blnReturn = false;
$("#lbltxtRisposta").html( fHTMLErrore( "required" ) );
$( ".fg-txtRisposta" ).addClass( "has-error" );
}
else $("#lbltxtRisposta").html("");
}
// Controllo privacy
if( ! $('#privacy').prop('checked') )
{
blnReturn = false;
$('#lblprivacy').html( fHTMLErrore( "Mandatory acceptance." ) );
$( ".fg-privacy" ).addClass( "has-error" );
}
else $('#lblprivacy').html("");
}
var strCompletaErrore = 'completaErrore';
if ( pstrFrom == 'richiedi-preventivo' )
{
strCompletaErrore = 'completaErrorePreventivo';
$('.submitLoadPreventivo').addClass('hide');
$('.submitButPreventivo').removeClass('hide');
}
else
{
$('.submitLoad').addClass('hide');
$('#submitBut').removeClass('hide');
}
if ( ! blnReturn ) $('.'+strCompletaErrore).removeClass('hide'); else $('.'+strCompletaErrore).addClass('hide');
return blnReturn;
}
function fHTMLErrore( pstr )
{
return '' + pstr + '';
}
// Aggiorna quantita
function fAggiornaQuantita( pstrKey, pintID_Riga )
{
fLoading( 1 );
var pintQuantita = $('#quantita_'+pintID_Riga).val();
var strIDL = $('#id_lista').val();
if ( strIDL == undefined || strIDL == null ) strIDL = '';
$.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 = '/en/cart/?' + ( strIDL != '' ? 'idl=' + strIDL : '' ) + ( data.max == 'exceed' ? '&max=exceed' : '' );
}
else
{
fLoading( 0 );
swal("Ops...", "Oops, something went wrong ...", "error");
}
},
error: function(data)
{
fLoading( 0 );
swal("Ops...", "Oops, something went wrong ...", "error");
}
}); /* ajax */
}
// Rimuovi prodotto
function fDelProd( pstrKey, pintID_Riga )
{
var strIDL = $('#id_lista').val();
if ( strIDL == undefined || strIDL == null ) strIDL = '';
swal({
title: "Warning!",
text: "Remove this product from the cart?",
type: "warning",
showCancelButton: true,
cancelButtonText: "No, cancel",
confirmButtonText: "Yes, delete!",
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 = '/en/cart/' + ( strIDL != '' ? '?idl=' + strIDL : '' );
}
else swal("Ops...", "Oops, something went wrong ...", "error");
},
error: function(data) {
swal("Ops...", "Oops, something went wrong ...", "error");
}
}); /* ajax */
});
}
// Svuota carrello
function fSvuotaCarrello( pstrKey )
{
var strIDL = $('#id_lista').val();
if ( strIDL == undefined || strIDL == null ) strIDL = '';
swal({
title: "Warning!",
text: "Remove all products from the cart?",
type: "warning",
showCancelButton: true,
cancelButtonText: "No, cancel",
confirmButtonText: "Yes, delete!",
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 = '/en/cart/' + ( strIDL != '' ? '?idl=' + strIDL : '' );
}
else swal("Ops...", "Oops, something went wrong ...", "error");
},
error: function(data) {
swal("Ops...", "Oops, something went wrong ...", "error");
}
}); /* ajax */
});
}
function fUpdateAggiuntivo(pval)
{
if ( pval )
{
$('#txtID_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').val() );
$('#txtNominativo_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('nominativo') );
$('#txtIndirizzo_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('indirizzo') );
$('#txtCap_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('cap') );
$('#txtCitta_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('citta') );
$('#cmbProvincia_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('provincia') ).selectpicker('refresh');
$('#cmbNazione_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('nazione') ).selectpicker('refresh');
var l1 = $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('recapito1label');
$('#cmbRecapito1_label_Aggiuntivo').val( String(l1) == '' ? 'cellulare' : l1 ).selectpicker('refresh');
$('#txtRecapito1_Aggiuntivo').val( $('#cmbIndirizziAggiuntivi option[value='+pval+']').data('recapito1') );
}
else
{
$('#txtID_Aggiuntivo').val( '' );
$('#txtNominativo_Aggiuntivo').val( '' );
$('#txtIndirizzo_Aggiuntivo').val( '' );
$('#txtCap_Aggiuntivo').val( '' );
$('#txtCitta_Aggiuntivo').val( '' );
$('#cmbProvincia_Aggiuntivo').val( 'Milano' ).selectpicker('refresh');
$('#cmbNazione_Aggiuntivo').val( 'IT' ).selectpicker('refresh');
$('#cmbRecapito1_label_Aggiuntivo').val( 'cellulare' ).selectpicker('refresh');
$('#txtRecapito1_Aggiuntivo').val( '' );
}
fCambiaIndirizzoSpedizione();
fAggiornaTotaleOrdine();
}