Legal Question Answering System
Ask a question to receive information based on general U.S. legal principles.
Enter Your Legal Question
Searching for an answer...
Answer
Your Question:
Sources:
Please ask a question on the first tab to see an answer here.
Important Disclaimer
The information provided by this tool is for educational purposes only and does not constitute legal advice. It is not a substitute for consultation with a qualified legal professional.
Question History
${item.question}
`; historyContainer.appendChild(el); }); } function displayAnswer() { if (!state.currentQuestion) { noAnswerYetDiv.style.display = 'block'; answerContent.style.display = 'none'; return; } noAnswerYetDiv.style.display = 'none'; answerContent.style.display = 'block'; loadingSpinner.style.display = 'none'; questionAskedElem.textContent = state.currentQuestion; answerDisplayElem.textContent = state.currentAnswer; answerSourcesElem.textContent = state.currentSources; } // --- CORE FUNCTIONS --- window.showTab = function(tabIndex) { if (tabIndex < 0 || tabIndex >= tabButtons.length) return; state.currentTab = tabIndex; tabButtons.forEach((btn, i) => btn.classList.toggle('active', i === state.currentTab)); tabContents.forEach((content, i) => content.classList.toggle('active', i === state.currentTab)); updateNavButtons(); }; window.viewHistoryItem = function(index) { const item = state.history[index]; if (item) { state.currentQuestion = item.question; state.currentAnswer = item.answer; state.currentSources = item.sources; displayAnswer(); showTab(1); } } function updateNavButtons() { prevBtn.disabled = state.currentTab === 0; nextBtn.disabled = state.currentTab === tabButtons.length - 1; } function fetchAnswer(question) { // Show loading state noAnswerYetDiv.style.display = 'none'; answerContent.style.display = 'none'; loadingSpinner.style.display = 'block'; showTab(1); // --- MOCK API CALL --- // This simulates a network request to a legal AI. setTimeout(() => { const lowerCaseQuestion = question.toLowerCase(); let answer = "Based on general legal principles in the United States, we cannot provide a specific answer for your query. It's recommended to consult with a legal professional for matters concerning your specific situation."; let sources = "General Legal Information Databases."; if (lowerCaseQuestion.includes('contract')) { answer = "In the United States, a legally valid contract generally requires three core elements: an offer, acceptance of that offer, and consideration. An offer is a clear proposal from one party to another. Acceptance is the unequivocal agreement to the terms of the offer. Consideration is something of value (money, services, goods, or a promise) exchanged between the parties. All parties must also have the legal capacity to enter into a contract and the contract's purpose must be legal."; sources = "U.S. Contract Law Principles, Restatement (Second) of Contracts."; } else if (lowerCaseQuestion.includes('negligence')) { answer = "Negligence is a legal theory in tort law. To prove negligence in the U.S., a plaintiff typically must establish four elements: \n1. Duty: The defendant owed a legal duty of care to the plaintiff. \n2. Breach: The defendant breached that duty by acting or failing to act in a certain way. \n3. Causation: The defendant's actions (or inaction) were the actual and proximate cause of the plaintiff's injuries. \n4. Damages: The plaintiff suffered actual harm or loss as a result."; sources = "U.S. Tort Law Principles."; } else if (lowerCaseQuestion.includes('copyright')) { answer = "Copyright is a form of intellectual property law that protects original works of authorship including literary, dramatic, musical, and artistic works. In the U.S., copyright protection is automatic once a work is fixed in a tangible medium. The owner of a copyright has the exclusive rights to reproduce, distribute, perform, display, and create derivative works. These rights are not unlimited and are subject to limitations like 'fair use'."; sources = "U.S. Copyright Act (Title 17 of the U.S. Code)."; } // Update state and UI state.currentQuestion = question; state.currentAnswer = answer; state.currentSources = sources; state.history.push({ question, answer, sources }); displayAnswer(); renderHistory(); }, 1500); // Simulate 1.5 second delay } function downloadPDF() { if (!state.currentQuestion) return; const { jsPDF } = jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'letter' }); const margin = 72; // 1 inch const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - (margin * 2); let currentY = margin; doc.setFontSize(18); doc.setFont("helvetica", "bold"); doc.text("Legal Question & Answer Summary", pageWidth / 2, currentY, { align: 'center' }); currentY += 40; doc.setFontSize(12); doc.setFont("helvetica", "bold"); doc.text("Question:", margin, currentY); currentY += 20; doc.setFont("times", "italic"); const questionLines = doc.splitTextToSize(state.currentQuestion, usableWidth); doc.text(questionLines, margin, currentY); currentY += (questionLines.length * 14) + 20; doc.setFontSize(12); doc.setFont("helvetica", "bold"); doc.text("Answer:", margin, currentY); currentY += 20; doc.setFont("times", "normal"); const answerLines = doc.splitTextToSize(state.currentAnswer, usableWidth); doc.text(answerLines, margin, currentY); currentY += (answerLines.length * 14) + 20; doc.setFontSize(10); doc.setFont("helvetica", "normal"); doc.text("Sources: " + state.currentSources, margin, currentY); doc.save(`Legal_QA_Report.pdf`); } // --- EVENT LISTENERS --- questionForm.addEventListener('submit', (e) => { e.preventDefault(); const question = questionInput.value.trim(); if (question) { fetchAnswer(question); } }); pdfDownloadBtn.addEventListener('click', downloadPDF); nextBtn.addEventListener('click', () => showTab(state.currentTab + 1)); prevBtn.addEventListener('click', () => showTab(state.currentTab - 1)); // --- INITIALIZATION --- function initialize() { renderHistory(); displayAnswer(); showTab(0); } initialize(); });