Guardianship Agreement Generator
Create a temporary or permanent guardianship agreement. Fill in the details step-by-step.
IN WITNESS WHEREOF, the parties have executed this Agreement as of the Effective Date.
${data.parents.map(p => ``).join('')}
${data.guardians.map(g => ``).join('')}
`;
}
function generatePreview() {
const data = getFormData();
const html = generateAgreementHTML(data);
document.getElementById('agreement-preview-container').innerHTML = html.replace(/<[^>]+>/g, ' ').replace(/\s\s+/g, ' ');
}
async function handlePdfDownload() {
const data = getFormData();
const contentHTML = generateAgreementHTML(data);
document.getElementById('pdf-content').innerHTML = contentHTML;
const { jsPDF } = window.jspdf;
const button = document.getElementById('downloadPdfBtn');
button.textContent = 'Generating...';
button.disabled = true;
const pdfContainer = document.getElementById('pdf-container');
pdfContainer.classList.remove('invisible');
try {
const canvas = await html2canvas(pdfContainer, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const imgProps = pdf.getImageProperties(imgData);
const imgHeight = (imgProps.height * pdfWidth) / imgProps.width;
let heightLeft = imgHeight;
let position = 0;
const pageMargin = 10;
const usableHeight = pdfHeight - (2 * pageMargin);
pdf.addImage(imgData, 'PNG', pageMargin, pageMargin, pdfWidth - (2*pageMargin), imgHeight);
pdf.save('Guardianship_Agreement.pdf');
} catch (error) {
console.error("PDF generation failed:", error);
} finally {
button.textContent = 'Download Agreement as PDF';
button.disabled = false;
pdfContainer.classList.add('invisible');
}
}
// --- INITIALIZATION ---
parentCount = addPerson('parent', 'parents-container', parentCount);
childCount = addPerson('child', 'children-container', childCount);
guardianCount = addPerson('guardian', 'guardians-container', guardianCount);
updateTabDisplay();
nextBtn.addEventListener('click', () => changeTab(currentTab + 1));
prevBtn.addEventListener('click', () => changeTab(currentTab - 1));
document.getElementById('downloadPdfBtn').addEventListener('click', handlePdfDownload);
tabButtons.forEach(button => button.addEventListener('click', (e) => changeTab(parseInt(e.target.dataset.tab))));
document.getElementById('agreement-type').addEventListener('change', (e) => {
document.getElementById('temporary-fields').style.display = e.target.value === 'temporary' ? 'block' : 'none';
});
});
Parent: ${p.name}
Guardian: ${g.name}
