$( function()
{
$("#completa-ordine").click(function()
{
if ( parseInt( $('#ordine_acquistabile').val() ) > 0 )
{
if( fCheckObbligatori() ) fSaveData();
}
else swal( "Vorsicht!", "Die Bestellung ist nicht verfügbar.", "error" );
});
$('#txtEmail').change(function()
{
$('.loader-txtEmail').removeClass('hide');
$('#lbltxtEmail-login').addClass('hide');
$('#lbltxtEmail, #lbltxtEmail-login').html('');
$( ".fg-txtEmail" ).removeClass( "has-error" );
if ( $(this).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)
{
if ( data.email_check == 0 )
{
// Email non corretta
if ( data.email_errore == 2 )
{
// ERRORE : email NON esiste
$('#lbltxtEmail').html( fHTMLErrore( "Die Adresse existiert nicht." ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
}
else if ( data.email_errore == 1 )
{
// ERRORE : email NON corretta
$('#lbltxtEmail').html( fHTMLErrore( "Die Adresse ist nicht korrekt." ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
}
}
else if ( $('#id_cliente').val() == '' )
{
// 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, or re-enter the data and complete the order.' );
$('.row-scelta-registrazione-box').addClass('hide');
$('#email_gia_registrata').val( 1 );
}
else
{
$('.row-scelta-registrazione-box').removeClass('hide');
$('#email_gia_registrata').val( 0 );
}
}
}
}); /* ajax */
}
else
{
// ERRORE : email obbligatoria
$('#lbltxtEmail').html( fHTMLErrore( "Pflichtfeld" ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
}
$('.loader-txtEmail').addClass('hide');
});
$('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');
});
// sp_nazione
$('#cmbSpNazione').change(function()
{
if ( $(this).val() == 'IT' )
{
$('#label_ricarica_postepay').removeClass('hide');
$('#col-sp-citta').removeClass('col-md-8').addClass('col-md-4');
$('#col-sp-provincia').removeClass('hide');
//$('#via_ig').addClass('input-group');
}
else
{
$('#label_ricarica_postepay').addClass('hide');
if ( $("input[name=pagamento]:checked").val() == 'ricarica_postepay' )
{
$('.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-sp-provincia').addClass('hide');
$('#col-sp-citta').removeClass('col-md-4').addClass('col-md-8');
//$('#via_ig').removeClass('input-group');
}
fAggiornaTotaleOrdine();
});
// nazione
$('#cmbNazione').change(function()
{
if ( $(this).val() == 'IT' )
{
$('#label_ricarica_postepay').removeClass('hide');
$('#col-citta').removeClass('col-md-8').addClass('col-md-4');
$('#col-provincia').removeClass('hide');
//$('#via_ig').addClass('input-group');
}
else
{
$('#label_ricarica_postepay').addClass('hide');
if ( $("input[name=pagamento]:checked").val() == 'ricarica_postepay' )
{
$('.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');
//$('#via_ig').removeClass('input-group');
}
fAggiornaTotaleOrdine();
});
// nazione
$('#cmbFattNazione').change(function()
{
if ( $(this).val() == 'IT' )
{
$('#col-fatt-citta').removeClass('col-md-8').addClass('col-md-4');
$('#col-fatt-provincia').removeClass('hide');
}
else
{
$('#col-fatt-provincia').addClass('hide');
$('#col-fatt-citta').removeClass('col-md-4').addClass('col-md-8');
}
fAggiornaTotaleOrdine();
});
/*$('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 = "Der Rabattcode wurde korrekt eingegeben.";
strLabelType = "success";
}
else
{
strLabelTop = data.label_top;
strLabel = data.label;
strLabelType = data.label_type;
}
}
else swal("Oops!", "Die Operation konnte nicht ausgeführt werden.", "error");
},
error: function(data) { swal("Oops!", "Prozedur nicht abgeschlossen", "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" );
});
// 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();
});
});
function fAggiornaTotaleOrdine()
{
$('#totale_ordine_loader').removeClass('hide');
var data;
var strID_Pagamento = $("input[name=pagamento]:checked").val();
var strNazione = $("#cmbSpNazione").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=" + $("#cmbSpProvincia").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()
+ "&totale_carrello_shop=" + $("#totale_carrello_shop").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_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( ' FREE' );
if ( data.spedizione_totale > 0 )
$('.crl_spedizione_costo_label').html( data.spedizione_totale_format );
else $('.crl_spedizione_costo_label').html( 'FREE' );
$('.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( 'Wähle die Provinz' );
$('.assicurata_box').addClass('hide');
$('.spedizione_nondisponibile').addClass('hide');
$('.spedizione_nondisponibile_provincia').removeClass('hide');
}
else
{
$('.crl_spedizione_costo_label').html( 'nicht verfügbar' );
$('.spedizione_nondisponibile_provincia').addClass('hide');
$('.assicurata_box').addClass('hide');
$('.spedizione_nondisponibile').removeClass('hide');
}
$('#crl_totale_label').html( data.totale_ordine );
$('#ordine_acquistabile').val( parseInt( data.ordine_acquistabile ) );
}
else swal("Oops!", "Die Operation konnte nicht ausgeführt werden.", "error");
},
error: function(data) { swal("Oops!", "Prozedur nicht abgeschlossen", "error"); }
});
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;
strDestination = data.destination;
}
else swal("Oops!", "Etwas ist schief gelaufen.", "error");
},
error: function(data) { swal("Oops!", "Etwas ist schief gelaufen.", "error"); }
});
if ( strID_Ordine != '' && strDestination != '' ) {
location.href = strDestination; } 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');
$( ".has-error" ).removeClass( "has-error" );
$( ".lbl" ).html("");
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( "Die Adresse ist falsch." ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
strAlert = "Die Adresse ist nicht korrekt.";
}
else if ( intErrore == 2 )
{
// ERRORE : email NON esiste
blnReturn = false;
$('#lbltxtEmail').html( fHTMLErrore( "Die Adresse existiert nicht" ) );
$( ".fg-txtEmail" ).addClass( "has-error" );
strAlert = "Die Adresse existiert nicht.";
}
if ( data.status == 'errore' )
blnSaved = false;
else if ( data.status == 'ok' )
blnSaved = true;
else swal("Ops...", "Überprüfung fehlgeschlagen", "error");
},
error: function(data) {
swal("Ops...", "Prozedur nicht abgeschlossen", "error");
}
});
}
if ( blnReturn )
{
$('.required').each(function()
{
if ( $.trim( $(this).val() ) == "" )
{
blnReturn = false;
$( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Pflichtfeld" ) );
$( ".fg-" + $(this).attr("name") ).addClass( "has-error" );
if ( strAlert == "" )
strAlert = "Inserisci i campi obbligatori "; /* + $(this).attr("name") + $( "#lbl" + $(this).attr("name") ).attr("title");*/
}
else $( "#lbl" + $(this).attr("name") ).html("");
});
}
if ( blnReturn && $('#fattura_si').prop('checked') )
{
// Controllo ragione sociale
if ( $.trim( $('#txtFattNominativo').val() ) == '' )
{
blnReturn = false;
$('#lbltxtFattNominativo').html( fHTMLErrore( "" ) );
$( ".fg-txtFattNominativo" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la ragione sociale per la fattura";
}
else $('#lbltxtFattNominativo').html("");
// Controllo codice fiscale o partita IVA
if ( $.trim( $('#txtCodiceFiscale').val() ) == '' && $.trim( $('#txtPartitaIva').val() ) == '' )
{
blnReturn = false;
$('#lbltxtCodiceFiscale, #lbltxtPartitaIva').html( fHTMLErrore( "" ) );
$( ".fg-txtCodiceFiscale, .fg-txtPartitaIva" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci il codice fiscale o la partita IVA per la fattura";
}
else $('#lbltxtCodiceFiscale, #lbltxtPartitaIva').html("");
// Controllo indirizzo
if ( $.trim( $('#txtFattIndirizzo').val() ) == '' )
{
blnReturn = false;
$('#lbltxtFattIndirizzo').html( fHTMLErrore( "" ) );
$( ".fg-txtFattIndirizzo" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci l'indirizzo per la fattura";
}
else $('#lbltxtFattIndirizzo').html("");
// Controllo cap
if ( $.trim( $('#txtFattCap').val() ) == '' )
{
blnReturn = false;
$('#lbltxtFattCap').html( fHTMLErrore( "" ) );
$( ".fg-txtFattCap" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci il CAP per la fattura";
}
else $('#lbltxtFattCap').html("");
// Controllo citta
if ( $.trim( $('#txtFattCitta').val() ) == '' )
{
blnReturn = false;
$('#lbltxtFattCitta').html( fHTMLErrore( "" ) );
$( ".fg-txtFattCitta" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la città per la fattura";
}
else $('#lbltxtFattCitta').html("");
// Controllo nazione
if ( $.trim( $('#cmbFattNazione').val() ) == '' )
{
blnReturn = false;
$('#lblcmbFattNazione').html( fHTMLErrore( "" ) );
$( ".fg-cmbFattNazione" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la nazione per la fattura";
}
else $('#lblcmbFattNazione').html("");
// Controllo provincia
if ( $('#cmbFattNazione').val() == 'IT' && $.trim( $('#cmbFattProvincia').val() ) == '' )
{
blnReturn = false;
$('#lblcmbFattProvincia').html( fHTMLErrore( "" ) );
$( ".fg-cmbFattProvincia" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la provincia per la fattura";
}
else $('#lblcmbFattProvincia').html("");
}
if ( blnReturn && parseInt($('#has_shop').val()) > 0 )
{
// Controllo indirizzo
if ( $.trim( $('#txtSpIndirizzo').val() ) == '' )
{
blnReturn = false;
$('#lbltxtSpIndirizzo').html( fHTMLErrore( "" ) );
$( ".fg-txtSpIndirizzo" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci l'indirizzo per la spedizione";
}
else $('#lbltxtSpIndirizzo').html("");
// Controllo civico
if ( $.trim( $('#txtCivico').val() ) == '' )
{
blnReturn = false;
$('#lbltxtCivico').html( fHTMLErrore( "" ) );
$( ".fg-txtCivico" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci il numero civico per la spedizione";
}
else $('#lbltxtCivico').html("");
// Controllo cap
if ( $.trim( $('#txtSpCap').val() ) == '' )
{
blnReturn = false;
$('#lbltxtSpCap').html( fHTMLErrore( "" ) );
$( ".fg-txtSpCap" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci il CAP per la spedizione";
}
else $('#lbltxtSpCap').html("");
// Controllo citta
if ( $.trim( $('#txtSpCitta').val() ) == '' )
{
blnReturn = false;
$('#lbltxtSpCitta').html( fHTMLErrore( "" ) );
$( ".fg-txtSpCitta" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la città per la spedizione";
}
else $('#lbltxtSpCitta').html("");
// Controllo nazione
if ( $.trim( $('#cmbSpNazione').val() ) == '' )
{
blnReturn = false;
$('#lblcmbSpNazione').html( fHTMLErrore( "" ) );
$( ".fg-cmbSpNazione" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la nazione per la spedizione";
}
else $('#lblcmbSpNazione').html("");
// Controllo provincia
if ( $('#cmbSpNazione').val() == 'IT' && $.trim( $('#cmbSpProvincia').val() ) == '' )
{
blnReturn = false;
$('#lblcmbSpProvincia').html( fHTMLErrore( "" ) );
$( ".fg-cmbSpProvincia" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Inserisci la provincia per la spedizione";
}
else $('#lblcmbSpProvincia').html("");
}
if ( blnReturn )
{
if ( ! parseInt( $('#email_gia_registrata').val() ) )
{
// Controllo password
if ( $.trim( $('#txtPassword').val() ) == '' )
{
blnReturn = false;
$("#lbltxtPassword").html( fHTMLErrore( "Pflichtfeld" ) );
$(".fg-txtPassword").addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Geben Sie Ihr Passwort ein";
}
else $("#lbltxtPassword").html("");
if ( $.trim( $('#txtConfermaPassword').val() ) == '' )
{
blnReturn = false;
$("#lbltxtConfermaPassword").html( fHTMLErrore( "Pflichtfeld" ) );
$(".fg-txtConfermaPassword").addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Geben Sie die Passwortbestätigung ein";
}
else $("#lbltxtConfermaPassword").html("");
if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' )
{
if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() )
{
blnReturn = false;
$('#lbltxtConfermaPassword').html( fHTMLErrore( "Das Passwort ist nicht dasselbe." ) );
$( ".fg-txtConfermaPassword" ).addClass( "has-error" );
if ( strAlert == "" ) strAlert = "Das Passwort ist nicht dasselbe.";
}
else $('#lbltxtConfermaPassword').html("");
}
if ( $.trim( $('#txtDomanda').val() ) == '' )
{
$( '#boxlista_txtDomanda' ).addClass('hide');
$( '#box_txtDomanda' ).removeClass('hide');
blnReturn = false;
$('#lbltxtDomanda').html( fHTMLErrore( "Pflichtfeld" ) );
$( ".fg-txtDomanda" ).addClass( "has-error" );
}
else $('#lbltxtRisposta').html("");
if ( $.trim( $('#txtRisposta').val() ) == '' )
{
blnReturn = false;
$('#lbltxtRisposta').html( fHTMLErrore( "Pflichtfeld" ) );
$( ".fg-txtRisposta" ).addClass( "has-error" );
}
else $('#lbltxtRisposta').html("");
}
}
if ( blnReturn )
{
if ( parseFloat($('#totale_paga_struttura').val()) > 0 )
{
if ( ! $('#cardToken').length || $.trim( $('#cardToken').text() ) == '' )
{
blnReturn = false;
$('#lbltxtAggiungiCarta').html( '