Free Cash Flow Calculator | Instant FCF Analysis Tool
`;
printWindow.document.write(printContent);
printWindow.document.close();
printWindow.print();
showToast('PDF export ready (print dialog opened)', 'success');
}
function downloadFile(content, filename, mimeType) {
const blob = new Blob([content], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
function updateProgress() {
const visibleInputs = Array.from(elements.inputs).filter(input =>
input.closest('.input-group').style.display !== 'none'
);
const filledInputs = visibleInputs.filter(input => input.value && !isNaN(parseFloat(input.value)));
const progress = (filledInputs.length / visibleInputs.length) * 100;
elements.progressFill.style.width = `${progress}%`;
}
function animateMethodTransition() {
const container = document.querySelector('.input-section');
container.style.opacity = '0.5';
setTimeout(() => {
container.style.opacity = '1';
}, 150);
}
function scrollToResults() {
const resultsSection = document.querySelector('.results-section');
resultsSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
function showToast(message, type = 'info') {
elements.toast.textContent = message;
elements.toast.className = `toast ${type} show`;
setTimeout(() => {
elements.toast.classList.remove('show');
}, 4000);
}
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
function setupTooltips() {
const helpIcons = document.querySelectorAll('.help-icon');
helpIcons.forEach(icon => {
const tooltipId = icon.getAttribute('aria-describedby');
const tooltip = document.getElementById(tooltipId);
// Move tooltip to body to avoid stacking context issues
document.body.appendChild(tooltip);
icon.addEventListener('mouseenter', () => {
const rect = icon.getBoundingClientRect();
const top = rect.top + window.scrollY - tooltip.offsetHeight - 5;
const left = rect.left + window.scrollX + rect.width / 2 - tooltip.offsetWidth / 2;
tooltip.style.top = top + 'px';
tooltip.style.left = left + 'px';
tooltip.style.opacity = '1';
});
icon.addEventListener('mouseleave', () => {
tooltip.style.opacity = '0';
});
});
}
function setupIntersectionObserver() {
if (!('IntersectionObserver' in window)) return;
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
document.querySelectorAll('.result-card').forEach(card => {
observer.observe(card);
});
}
function updateSchemaMarkup(result) {
const script = document.querySelector('script[type="application/ld+json"]');
if (!script) return;
try {
const data = JSON.parse(script.textContent);
const fcfEntity = data['@graph'].find(item => item['@type'] === 'MonetaryAmount');
if (fcfEntity) {
fcfEntity.value = result.fcf;
}
script.textContent = JSON.stringify(data, null, 2);
} catch (e) {
console.warn('Schema update failed:', e);
}
}
function updateFormValidation() {
// Add custom validation messages
elements.inputs.forEach(input => {
input.addEventListener('invalid', function(e) {
e.preventDefault();
this.classList.add('error');
showToast('Please enter valid numbers', 'error');
});
});
}
function registerServiceWorker() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('data:text/javascript,' + encodeURIComponent(`
self.addEventListener('install', e => e.waitUntil(self.skipWaiting()));
self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
self.addEventListener('fetch', e => e.respondWith(fetch(e.request)));
`)).then(() => {
console.log('Service Worker registered for offline support');
}).catch(() => {});
}
}
// Initialize progress
updateProgress();
console.log('✨ FCF Calculator fully initialized with ultra-premium features');
})();