$(function() { $('.tipo_registrazione').change(function() { if ( $('.tipo_registrazione:checked').val() == 'azienda' ) { $('.row-azienda').removeClass('hide'); } else { $('.row-azienda').addClass('hide'); } }); }); function fSaveData() { $('submit').focus(); $('#submitBut').addClass('hide'); $('#submitLoad').removeClass('hide'); if ($('#txtRichiesta').val() !== undefined) { $('#txtNote').val( ($('#txtRichiesta').val()).replace(/[\r\n]/gm, '[n]') ); } var data; var strDestination = ''; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/sendPropostaEsclusivo.php", data: $("#frmPropostaEsclusivo").serialize(), success: function(data) { strDestination = data.destination; if ( data.status == 'ok' ) { blnSaved = true; } else { swal("Oops!", "Qualcosa è andato storto.", "error"); } }, error: function(data) { swal("Oops!", "Qualcosa è andato storto.", "error"); } }); if ( blnSaved ) { location.href = strDestination; } else { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); $('.required').each(function(){ if ( $.trim( $(this).val() ) == "" ){ blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-" + $(this).attr("name") ).addClass( "has-error" ); } }); // Controllo privacy if ( ! $('#privacy').prop('checked') ){ blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) ); $( ".fg-privacy" ).addClass( "has-error" ); } // 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'email non è corretta." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } if ( data.status == 'errore' ) { blnSaved = false; } else if ( data.status == 'ok' ) { blnSaved = true; } else { swal("Oops!", "Qualcosa è andato storto.", "error"); } }, error: function(data) { swal("Oops!", "Qualcosa è andato storto.", "error"); } }); } $('.periodo_input').each(function(){ var index = ( $(this).attr('name') ).replace( 'periodo_', '' ); }); var bambini = parseInt( $('#intBambini').val() ); var etas = ''; if ( bambini > 0 ) { for ( let i = 0; i < bambini; i++ ) { if ( $('#eta_bambino_'+i).val() == '' ) { blnReturn = false; $('#lbleta_box').html( fHTMLErrore( "Inserisci l'età dei bambini" ) ); $( '.fg-eta' ).addClass( "has-error" ); } else { etas += (etas != '' ? ',' : '') + $('#eta_bambino_'+i).val(); } } $('#etas').val(etas); } console.log('etas '+etas); if ( ! blnReturn ) { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } $('#loader-email').addClass('hide'); return blnReturn; } function fHTMLErrore( pstr ){ return '' + pstr + ''; }