`; return html; } // Function to download inspection report function downloadInspectionReport() { if (!window.lastInspectionData) { alert('No inspection data available for download.'); return; } const html = createInspectionReportHTML(window.lastInspectionData); const blob = new Blob([html], { type: 'text/html' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `SFP_Inspection_${window.lastInspectionData.sfpvId}_${window.lastInspectionData.inspectionDate}.html`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); } // Function to print inspection report function printInspectionReport() { if (!window.lastInspectionData) { alert('No inspection data available for printing.'); return; } const html = createInspectionReportHTML(window.lastInspectionData); const printWindow = window.open('', '_blank'); printWindow.document.write(html); printWindow.document.close(); // Wait for content to load then print printWindow.onload = function() { printWindow.print(); // Close window after printing printWindow.onafterprint = function() { printWindow.close(); }; }; } // Function to email copy to self function emailCopyToSelf() { if (!window.lastInspectionData) { alert('No inspection data available.'); return; } const data = window.lastInspectionData; const subject = `SFP Inspection Report - ${data.sfpvId}`; const body = `Dear Inspector, This is a copy of your completed Safe Freight Program inspection: Vehicle ID: ${data.sfpvId} Registration: ${data.rego || 'N/A'} Inspection Date: ${data.inspectionDate} Outcome: ${data.outcome} AIL: ${data.ailName || 'N/A'} The detailed report has been saved to your system and an email confirmation has been sent. Thank you for maintaining safety standards. Safe Freight Program Generated: ${new Date().toLocaleString()}`; const mailtoLink = `mailto:${data.inspectorEmail}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`; window.open(mailtoLink); }