💰
Total Tax Payable
$0.00
Effective Rate: 0%
⏱️
Holding Period
0 days
Short-term
🎯
Net Profit After Tax
$0.00
ROI: 0%
Detailed Tax Breakdown
Sale Price:
$0.00
Purchase Price:
$0.00
Deductible Costs:
-$0.00
Capital Gains:
$0.00
Federal Tax:
$0.00
State Tax:
$0.00
Total Tax:
$0.00
`);
printWindow.document.close();
printWindow.print();
}function updateShareLink() {
const params = new URLSearchParams();
const data = getFormData();
Object.keys(data).forEach(key => {
if (data[key] !== '' && data[key] !== null && data[key] !== 0) {
params.append(key, data[key]);
}
});
const shareUrl = `${window.location.origin}${window.location.pathname}?${params.toString()}`;
document.getElementById('shareLink').value = shareUrl;
return shareUrl;
}function updateUrlWithParams() {
const data = getFormData();
const params = new URLSearchParams();
Object.keys(data).forEach(key => {
if (data[key] !== '' && data[key] !== null && data[key] !== 0) {
params.append(key, data[key]);
}
});
const newUrl = `${window.location.pathname}?${params.toString()}`;
window.history.replaceState({}, '', newUrl);
}function loadFromUrl() {
const params = new URLSearchParams(window.location.search);
if (params.toString() === '') return;
let hasValidParams = false;
params.forEach((value, key) => {
const field = document.getElementById(key) || document.querySelector(`[name="${key}"]`);
if (field) {
field.value = value;
hasValidParams = true;
}
});
if (hasValidParams) {
toggleConditionalFields();
if (validateForm()) {
setTimeout(() => {
calculateTax();
resultsSection.classList.remove('hidden');
shareSection.classList.remove('hidden');
resultsSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 500);
}
}
}async function copyShareLink() {
const shareInput = document.getElementById('shareLink');
try {
await navigator.clipboard.writeText(shareInput.value);
copyLinkBtn.textContent = 'Copied!';
copyLinkBtn.style.background = 'var(--success-color)';
setTimeout(() => {
copyLinkBtn.textContent = 'Copy';
copyLinkBtn.style.background = 'var(--primary-gold)';
}, 2000);
} catch (err) {
// Fallback for older browsers
shareInput.select();
shareInput.setSelectionRange(0, 99999); // For mobile devices
try {
document.execCommand('copy');
copyLinkBtn.textContent = 'Copied!';
copyLinkBtn.style.background = 'var(--success-color)';
setTimeout(() => {
copyLinkBtn.textContent = 'Copy';
copyLinkBtn.style.background = 'var(--primary-gold)';
}, 2000);
} catch (err) {
console.error('Failed to copy:', err);
}
}
}function handleSocialShare(event) {
const platform = event.currentTarget.dataset.platform;
const data = window.calculationResults || {};
const shareText = `I calculated my gold investment tax: ${formatCurrency(data.netProfit || 0)} net profit after ${formatCurrency(data.totalTax || 0)} tax. Try it yourself!`;
const shareUrl = updateShareLink();
const urls = {
facebook: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(shareUrl)}`,
x: `https://twitter.com/intent/tweet?text=${encodeURIComponent(shareText)}&url=${encodeURIComponent(shareUrl)}`,
whatsapp: `https://wa.me/?text=${encodeURIComponent(shareText + ' ' + shareUrl)}`,
telegram: `https://t.me/share/url?url=${encodeURIComponent(shareUrl)}&text=${encodeURIComponent(shareText)}`,
reddit: `https://reddit.com/submit?url=${encodeURIComponent(shareUrl)}&title=${encodeURIComponent('Gold Tax Calculator Results')}`,
pinterest: `https://pinterest.com/pin/create/button/?url=${encodeURIComponent(shareUrl)}&description=${encodeURIComponent(shareText)}`,
linkedin: `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(shareUrl)}`,
email: `mailto:?subject=Gold Tax Calculator Results&body=${encodeURIComponent(shareText + '\n\n' + shareUrl)}`,
tiktok: '', // TikTok doesn't have a web share API
vk: `https://vk.com/share.php?url=${encodeURIComponent(shareUrl)}&title=${encodeURIComponent('Gold Tax Calculator')}`
};
if (platform === 'tiktok') {
alert('TikTok sharing requires the mobile app. Please copy the link and share manually.');
return;
}
if (urls[platform]) {
window.open(urls[platform], '_blank', 'width=600,height=400');
}
}// Expose functions for testing
window.goldTaxCalculator = {
taxRules,
calculateTax,
getFormData,
formatCurrency
};})(); // End IIFE