$(document).ready(function() { // Auto-select "Third Party" as default on load // STEP NAVIGATION + VALIDATION (function($) { const $steps = $('#msform > div[id^="step"]'); $steps.hide(); $('#step01').show(); $('#msform').on('click', '.next, .prev', function() { const $btn = $(this); const current = $btn.data('id'); // e.g. "step02" const isNext = $btn.hasClass('next'); // === VALIDATION FOR STEP01 === if (current === "step01") { const vehicleNo = $("#VehicleExist").val().trim(); if (!vehicleNo) { Swal.fire({ icon: 'warning', title: 'Vehicle No required', text: 'The Registration Details Missing at Licensing Office!' }); return; // abort navigation } } // Navigation logic const num = parseInt(current.replace('step', ''), 10); const targetNum = isNext ? num + 1 : num - 1; const target = 'step' + String(targetNum).padStart(2, '0'); $('#' + current).hide(); $('#' + target).show(); $('html, body').animate({ scrollTop: $('#msform').offset().top - 70 }, 200); }); })(jQuery); // FORM SUBMISSION $('#submitBtn').on('click', function(e) { e.preventDefault(); const $btn = $(this); // disable immediately to block further clicks $btn.prop('disabled', true) .text('Submitting…'); // optional feedback const fd = new FormData($('#msform')[0]); $.ajax({ url: 'https://api.insureongo.com/?endpoint=accessapi', type: 'POST', data: fd, processData: false, contentType: false, success(response) { try { const res = typeof response === 'string' ? sanitizeJSON(response) : response; if (res.success === 'Yes') { Swal.fire({ icon: 'success', title: 'Success', text: res.message, timer: 3000, // auto close after 3 seconds timerProgressBar: true, showConfirmButton: false }).then(() => { // Redirect to Quotation_Pending.eis after success message window.location.href = res.redirect; }); } else { $btn.prop('disabled', false).text('Submit'); Swal.fire({ icon: 'error', title: 'Error!', text: res.message }); } } catch (err) { $btn.prop('disabled', false).text('Submit'); Swal.fire({ icon: 'error', title: 'Invalid JSON response', text: err.message }); } }, error(xhr) { $btn.prop('disabled', false).text('Submit'); Swal.fire({ icon: 'error', title: 'Exceptional Error', text: xhr.responseText }); } }); }); // Function to filter out non-JSON data function sanitizeJSON(obj) { // Recursively remove non-serializable properties (if needed) return JSON.parse(JSON.stringify(obj)); // This removes circular references and non-JSON-safe properties } $(document).on('contextmenu keydown', function(e) { if (e.type === 'contextmenu' || e.key === 'F12' || (e.ctrlKey && ['I','J','U'].includes(e.key))) { e.preventDefault(); } }); });