{"id":81,"date":"2025-04-24T12:48:51","date_gmt":"2025-04-24T12:48:51","guid":{"rendered":"https:\/\/olcs.decree.om\/?page_id=81"},"modified":"2025-04-25T04:55:24","modified_gmt":"2025-04-25T04:55:24","slug":"citation-assistant","status":"publish","type":"page","link":"https:\/\/olcs.decree.om\/?page_id=81","title":{"rendered":"Citation Assistant"},"content":{"rendered":"\n        <div id=\"cite-assist-container\">\n            <!-- Citation Type Selection -->\n            <div class=\"cite-assist-type-selection\" style=\"margin-bottom: 20px;\">\n                <div class=\"button-group\">\n                    <input type=\"radio\" name=\"citationType\" id=\"legislationRadio\" checked>\n                    <label for=\"legislationRadio\" class=\"button-group-item\">Legislation<\/label>\n                \n                    <input type=\"radio\" name=\"citationType\" id=\"caseFatwaRadio\">\n                    <label for=\"caseFatwaRadio\" class=\"button-group-item\">Cases and Fatwas<\/label>\n                <\/div>\n            <\/div>\n            \n            <!-- Legislation Section (visible by default) -->\n            <div id=\"legislationSection\">\n                <!-- Loading Spinner (initially visible) -->\n                <div id=\"loadingSpinner\" style=\"text-align: center; margin: 20px 0;\">\n                    <div style=\"margin-bottom: 10px;\">Loading citations database...<\/div>\n                    <div class=\"spinner\"><\/div>\n                <\/div>\n                \n                <!-- Main search card (initially hidden) -->\n                <div id=\"searchCard\" style=\"display: none; border: 1px solid #ddd; padding: 15px; margin-bottom: 20px;\">\n                    <div>\n                        <!-- Input without label and container -->\n                        <input type=\"text\" id=\"searchInput\" style=\"width: 100%; padding: 8px; margin-bottom: 10px;\" placeholder=\"Type to locate item...\">\n                        <div id=\"dropdown\" class=\"dropdown-content\">\n                            <!-- Options will be populated here -->\n                            <div class=\"dropdown-loading\" style=\"padding: 10px;\">Loading options...<\/div>\n                        <\/div>\n                        <!-- Submit Button -->\n                        <button type=\"button\" id=\"submitButton\" style=\"width: 100%; padding: 8px; cursor: pointer; background-color: #fff; border: 1px solid #c00; color: #c00;\">\n                            Submit\n                        <\/button>\n                        \n                        <!-- Checkbox for link option -->\n                        <div style=\"margin-top: 10px;\">\n                            <input type=\"checkbox\" id=\"includeLink\" checked>\n                            <label for=\"includeLink\">Hyperlink<\/label>\n                        <\/div>\n                    <\/div>\n                <\/div>\n                \n                <!-- Search Results -->\n                <div id=\"searchResults\" style=\"display: none; border: 1px solid #ddd; margin-bottom: 20px;\">\n                    <div style=\"background-color: #f8f8f8; padding: 10px; border-bottom: 1px solid #ddd;\">\n                        <h3 style=\"margin: 0;\">Search Results<\/h3>\n                    <\/div>\n                    <div style=\"padding: 15px;\">\n                        <div id=\"resultsCount\" style=\"margin-bottom: 15px;\"><\/div>\n                        <div id=\"resultsList\"><\/div>\n                    <\/div>\n                <\/div>\n            <\/div>\n            \n            <!-- Case\/Fatwa Section (hidden by default) -->\n            <div id=\"caseFatwaSection\" style=\"display: none;\">\n                <div style=\"border: 1px solid #ddd; padding: 15px; margin-bottom: 20px;\">\n                    <!-- Case\/Fatwa Type Selection -->\n                    <div style=\"margin-bottom: 15px;\">\n                        <div class=\"button-group\">\n                            <input type=\"radio\" name=\"caseType\" id=\"caseRadio\" checked>\n                            <label for=\"caseRadio\" class=\"button-group-item\">Case<\/label>\n                            \n                            <input type=\"radio\" name=\"caseType\" id=\"fatwaRadio\">\n                            <label for=\"fatwaRadio\" class=\"button-group-item\">Fatwa<\/label>\n                        <\/div>\n                    <\/div>\n                    \n                    <!-- Entity Name Field -->\n                    <div style=\"margin-bottom: 15px;\">\n                        <label for=\"entityName\" style=\"display: block; margin-bottom: 5px;\">Entity Name<\/label>\n                        <input type=\"text\" id=\"entityName\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. Supreme Court\">\n                    <\/div>\n                    \n                    <!-- Additional Fields for Case -->\n                    <div id=\"caseAdditionalFields\">\n                        <!-- Case Type Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"caseTypeField\" style=\"display: block; margin-bottom: 5px;\">Case Type<\/label>\n                            <input type=\"text\" id=\"caseTypeField\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. Contestation\">\n                        <\/div>\n                        \n                        <!-- Number Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"caseNumber\" style=\"display: block; margin-bottom: 5px;\">Number<\/label>\n                            <input type=\"text\" id=\"caseNumber\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. 17\/2020\">\n                        <\/div>\n                        \n                        <!-- Circuit Name Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"circuitName\" style=\"display: block; margin-bottom: 5px;\">Circuit Name<\/label>\n                            <input type=\"text\" id=\"circuitName\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. Commercial Circuit\">\n                        <\/div>\n                        \n                        <!-- Issuance Date Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"issuanceDate\" style=\"display: block; margin-bottom: 5px;\">Issuance Date<\/label>\n                            <input type=\"date\" id=\"issuanceDate\" style=\"width: 100%; padding: 8px;\">\n                        <\/div>\n                        \n                        <!-- Published\/Not Published Radio Buttons -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <div class=\"button-group\">\n                                <input type=\"radio\" name=\"publicationStatus\" id=\"publishedRadio\" checked>\n                                <label for=\"publishedRadio\" class=\"button-group-item\">Published<\/label>\n                                \n                                <input type=\"radio\" name=\"publicationStatus\" id=\"notPublishedRadio\">\n                                <label for=\"notPublishedRadio\" class=\"button-group-item\">Not Published<\/label>\n                            <\/div>\n                        <\/div>\n                        \n                        <!-- Book Title and Page Number Fields (Visible only if Published is selected) -->\n                        <div id=\"publicationDetails\">\n                            <div style=\"margin-bottom: 15px;\">\n                                <label for=\"bookTitle\" style=\"display: block; margin-bottom: 5px;\">Book Title<\/label>\n                                <input type=\"text\" id=\"bookTitle\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. Collection of Supreme Court Judgments (Labour-Commercial) 2021-2022\">\n                            <\/div>\n                            <div style=\"margin-bottom: 15px;\">\n                                <label for=\"pageNumber\" style=\"display: block; margin-bottom: 5px;\">Page Number<\/label>\n                                <input type=\"number\" id=\"pageNumber\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. 12\">\n                            <\/div>\n                        <\/div>\n                    <\/div>\n                    \n                    <!-- Additional Fields for Fatwa -->\n                    <div id=\"fatwaAdditionalFields\" style=\"display: none;\">\n                        <!-- Number Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"fatwaNumber\" style=\"display: block; margin-bottom: 5px;\">Number<\/label>\n                            <input type=\"text\" id=\"fatwaNumber\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. 17\/2020\">\n                        <\/div>\n                        \n                        <!-- Issuance Date Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"fatwaIssuanceDate\" style=\"display: block; margin-bottom: 5px;\">Issuance Date<\/label>\n                            <input type=\"date\" id=\"fatwaIssuanceDate\" style=\"width: 100%; padding: 8px;\">\n                        <\/div>\n                        \n                        <!-- Book Title Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"fatwaBookTitle\" style=\"display: block; margin-bottom: 5px;\">Book Title<\/label>\n                            <input type=\"text\" id=\"fatwaBookTitle\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. Collection of Principles of the MJLA\">\n                        <\/div>\n                        \n                        <!-- Page Number Field -->\n                        <div style=\"margin-bottom: 15px;\">\n                            <label for=\"fatwaPageNumber\" style=\"display: block; margin-bottom: 5px;\">Page Number<\/label>\n                            <input type=\"number\" id=\"fatwaPageNumber\" style=\"width: 100%; padding: 8px;\" placeholder=\"e.g. 12\">\n                        <\/div>\n                    <\/div>\n                    \n                    <!-- Generate and Clear Buttons -->\n                    <div style=\"display: flex; gap: 10px;\">\n                        <button type=\"button\" id=\"generateCaseFatwaButton\" style=\"flex: 1; padding: 8px; cursor: pointer; background-color: #fff; border: 1px solid #c00; color: #c00;\">\n                            Submit\n                        <\/button>\n                        <button type=\"button\" id=\"clearFieldsButton\" style=\"flex: 1; padding: 8px; cursor: pointer; background-color: #fff; border: 1px solid #ccc; color: #333;\">\n                            Clear\n                        <\/button>\n                    <\/div>\n                <\/div>\n            <\/div>\n            \n            <!-- Citation Result Display -->\n            <div id=\"citationContainer\" style=\"display: none; margin-top: 20px;\">\n                <h3>Result<\/h3>  \n                <div style=\"border: 1px solid #c00; padding: 15px; background-color: #fff0f0;\">\n                    <div id=\"citationOutput\"><\/div>\n                <\/div>\n                <div style=\"display: flex; gap: 10px; margin-top: 10px;\">\n                    <!-- Copy Button -->\n                    <button id=\"copyButton\" style=\"padding: 8px; cursor: pointer; background-color: #fff; border: 1px solid #c00; color: #c00;\">\n                        Copy\n                    <\/button>\n                    <!-- Attachment Citation Button (hidden by default) -->\n                    <button id=\"citeAttachmentButton\" style=\"padding: 8px; cursor: pointer; background-color: #fff; border: 1px solid #c00; color: #c00; display: none;\">\n                        Switch to Attachment Citation\n                    <\/button>\n                <\/div>\n                <!-- Copy Feedback Alert (hidden by default) -->\n                <div id=\"copyFeedback\" style=\"display: none; padding: 10px; background-color: #d4edda; border: 1px solid #c3e6cb; color: #155724; margin-top: 10px;\">\n                    Citation Copied!\n                <\/div>\n            <\/div>\n            <!-- Validation Alert -->\n            <div id=\"validationAlert\" style=\"display: none;\"><\/div>\n        <\/div>\n\n        <style>\n            \/* Button Group Styling - similar to Bootstrap but without Bootstrap *\/\n            .button-group {\n                display: inline-flex;\n                position: relative;\n            }\n            \n            .button-group input[type=\"radio\"] {\n                position: absolute;\n                clip: rect(0,0,0,0);\n                pointer-events: none;\n            }\n            \n            .button-group-item {\n                display: inline-block;\n                padding: 6px 12px;\n                margin: 0;\n                line-height: 1.5;\n                text-align: center;\n                white-space: nowrap;\n                vertical-align: middle;\n                cursor: pointer;\n                border: 1px solid #c00;\n                background-color: transparent;\n                color: #c00;\n            }\n            \n            .button-group-item:first-child {\n                border-top-left-radius: 4px;\n                border-bottom-left-radius: 4px;\n            }\n            \n            .button-group-item:last-child {\n                border-top-right-radius: 4px;\n                border-bottom-right-radius: 4px;\n            }\n            \n            .button-group-item:not(:first-child) {\n                margin-left: -1px;\n            }\n            \n            .button-group input[type=\"radio\"]:checked + .button-group-item {\n                background-color: #c00;\n                color: white;\n                z-index: 1;\n            }\n            \n            .button-group-item:hover {\n                background-color: #ffecec;\n            }\n\n            \/* Custom dropdown styles *\/\n            .dropdown-content {\n                display: none;\n                position: absolute;\n                background-color: #fff;\n                min-width: 200px;\n                max-height: 300px;\n                overflow-y: auto;\n                border: 1px solid #ddd;\n                z-index: 1000;\n                width: calc(100% - 30px);\n            }\n            \n            .dropdown-option {\n                padding: 8px;\n                border-bottom: 1px solid #eee;\n                cursor: pointer;\n            }\n            \n            .dropdown-option:hover {\n                background-color: #f8f8f8;\n            }\n            \n            mark {\n                background-color: #ffecec;\n                padding: 0;\n            }\n            \n            \/* Spinner *\/\n            .spinner {\n                border: 4px solid #f3f3f3;\n                border-top: 4px solid #c00;\n                border-radius: 50%;\n                width: 30px;\n                height: 30px;\n                animation: spin 2s linear infinite;\n                margin: 0 auto;\n            }\n            \n            @keyframes spin {\n                0% { transform: rotate(0deg); }\n                100% { transform: rotate(360deg); }\n            }\n            \n            \/* Results list styling *\/\n            #resultsList a {\n                display: block;\n                padding: 10px;\n                border: 1px solid #ddd;\n                margin-bottom: 5px;\n                text-decoration: none;\n                color: inherit;\n            }\n            \n            #resultsList a:hover {\n                background-color: #f8f8f8;\n            }\n            \n            #resultsList a.active {\n                background-color: #f0f0f0;\n                border-color: #ccc;\n            }\n        <\/style>\n\n        <script>\n        jQuery(document).ready(function($) {\n            \/\/ Main initialization function\n            function initCitationTool() {\n                const elements = getDOMElements();\n                let allItems = [];\n                \n                const csvUrls = [\n                    'https:\/\/docs.google.com\/spreadsheets\/d\/e\/2PACX-1vQd36HqmrJaJMJgkN-WpaBlFs6tBUpIc5HGr1wnJa7bfCXSMczicyZmkm6MGcjrWU9Kdc7IR3y8H7vP\/pub?gid=0&single=true&output=csv',\n                    'https:\/\/docs.google.com\/spreadsheets\/d\/e\/2PACX-1vT7LrMmd8nwmaElnm0RxKajd8RRSvZ0-5BNGo-6a3RrnRxFycJ1xwDaPxTA7bfeciil_nPF83tZ2cYj\/pub?gid=0&single=true&output=csv'\n                ];\n                \n                \/\/ Show loading indicator\n                elements.dropdown.innerHTML = '<div style=\"padding: 10px; text-align: center;\">Loading data...<\/div>';\n                \n                \/\/ Check if we have cached data and if it's still valid\n                const cachedData = getCachedData();\n                \n                if (cachedData) {\n                    \/\/ Use cached data\n                    allItems = cachedData;\n                    updateDropdownOptions(allItems, elements.dropdown);\n                    setupEventListeners(elements, allItems);\n                    \n                    \/\/ Hide spinner and show search card\n                    document.getElementById('loadingSpinner').style.display = 'none';\n                    document.getElementById('searchCard').style.display = 'block';\n                } else {\n                    \/\/ Fetch fresh data from both sources and combine them\n                    fetchFromMultipleSources(csvUrls)\n                        .then(items => {\n                            allItems = items;\n                            updateDropdownOptions(allItems, elements.dropdown);\n                            setupEventListeners(elements, allItems);\n                            \n                            \/\/ Cache the data\n                            cacheData(items);\n                            \n                            \/\/ Hide spinner and show search card after data loads\n                            document.getElementById('loadingSpinner').style.display = 'none';\n                            document.getElementById('searchCard').style.display = 'block';\n                        })\n                        .catch(error => {\n                            \/\/ Show error and still hide spinner, show search card\n                            elements.dropdown.innerHTML = `<div style=\"padding: 10px; text-align: center; color: #c00;\">Error: ${error.message}<\/div>`;\n                            document.getElementById('loadingSpinner').style.display = 'none';\n                            document.getElementById('searchCard').style.display = 'block';\n                        });\n                }\n            }\n\n            \/\/ Get all DOM elements in one place for easier maintenance\n            function getDOMElements() {\n                return {\n                    searchInput: document.getElementById('searchInput'),\n                    submitButton: document.getElementById('submitButton'),\n                    dropdown: document.getElementById('dropdown'),\n                    citationOutput: document.getElementById('citationOutput'),\n                    citationContainer: document.getElementById('citationContainer'),\n                    searchResults: document.getElementById('searchResults'),\n                    resultsCount: document.getElementById('resultsCount'),\n                    resultsList: document.getElementById('resultsList'),\n                    includeLink: document.getElementById('includeLink'),\n                    copyButton: document.getElementById('copyButton'),\n                    copyFeedback: document.getElementById('copyFeedback'),\n                    citeAttachmentButton: document.getElementById('citeAttachmentButton'),\n                    loadingSpinner: document.getElementById('loadingSpinner'),\n                    searchCard: document.getElementById('searchCard')\n                };\n            }\n\n            \/\/ Fetch from multiple sources\n            function fetchFromMultipleSources(urls) {\n                const fetchPromises = urls.map(url => fetchAndProcessCsvData(url));\n                return Promise.all(fetchPromises)\n                    .then(resultsArray => {\n                        let combinedItems = [];\n                        resultsArray.forEach(items => {\n                            combinedItems = combinedItems.concat(items);\n                        });\n                        combinedItems.sort((a, b) => {\n                            if (!a.issueDate) return 1;\n                            if (!b.issueDate) return -1;\n                            return b.issueDate.localeCompare(a.issueDate);\n                        });\n                        return combinedItems;\n                    });\n            }\n\n            function cacheData(data) {\n                const cache = {\n                    timestamp: Date.now(),\n                    data: data\n                };\n                try {\n                    localStorage.setItem('decreeCitationDataMultiSource', JSON.stringify(cache));\n                } catch (error) {\n                    console.error('Failed to cache data:', error);\n                }\n            }\n\n            function getCachedData() {\n                try {\n                    const cachedString = localStorage.getItem('decreeCitationDataMultiSource');\n                    if (!cachedString) return null;\n                    \n                    const cache = JSON.parse(cachedString);\n                    const sixHoursInMs = 6 * 60 * 60 * 1000;\n                    \n                    if (Date.now() - cache.timestamp > sixHoursInMs) {\n                        console.log('Cache expired, fetching fresh data');\n                        return null;\n                    }\n                    \n                    console.log('Using cached data from', new Date(cache.timestamp));\n                    return cache.data;\n                } catch (error) {\n                    console.error('Failed to retrieve cached data:', error);\n                    return null;\n                }\n            }\n\n            function fetchAndProcessCsvData(url) {\n                return fetch(url)\n                    .then(response => {\n                        if (!response.ok) {\n                            throw new Error(`Network response error: ${response.status}`);\n                        }\n                        return response.text();\n                    })\n                    .then(csvText => parseCSV(csvText));\n            }\n\n            function parseCSV(csvText) {\n                const lines = csvText.split('\\n');\n                const headers = parseCSVLine(lines[0]);\n                const items = [];\n                \n                for (let i = 1; i < lines.length; i++) {\n                    if (!lines[i].trim()) continue;\n                    \n                    const values = parseCSVLine(lines[i]);\n                    const item = {};\n                    \n                    for (let j = 0; j < Math.min(headers.length, values.length); j++) {\n                        item[headers[j].trim()] = values[j] ? values[j].trim() : '';\n                    }\n                    \n                    items.push({\n                        title: item.Title || '',\n                        numberMatrix: item.Number || '',\n                        issueDate: item.IssueDate || '',\n                        pubDate: item.PublicationDate || '',\n                        gazetteNo: item.GazetteNo || '',\n                        decreeURL: item.DecreeURL || ''\n                    });\n                }\n                \n                items.sort((a, b) => {\n                    if (!a.issueDate) return 1;\n                    if (!b.issueDate) return -1;\n                    return b.issueDate.localeCompare(a.issueDate);\n                });\n                \n                return items;\n            }\n\n            function parseCSVLine(line) {\n                const result = [];\n                let currentField = '';\n                let inQuotes = false;\n                \n                for (let i = 0; i < line.length; i++) {\n                    const char = line[i];\n                    \n                    if (char === '\"') {\n                        if (inQuotes) {\n                            if (i + 1 < line.length && line[i + 1] === '\"') {\n                                currentField += '\"';\n                                i++;\n                            } else {\n                                inQuotes = false;\n                            }\n                        } else {\n                            inQuotes = true;\n                        }\n                    } else if (char === ',' && !inQuotes) {\n                        result.push(currentField);\n                        currentField = '';\n                    } else {\n                        currentField += char;\n                    }\n                }\n                \n                result.push(currentField);\n                return result;\n            }\n\n            function setupEventListeners(elements, allItems) {\n                \/\/ Show dropdown when input is focused\n                elements.searchInput.addEventListener('focus', () => {\n                    elements.dropdown.style.display = 'block';\n                });\n                \n                \/\/ Filter dropdown options when typing\n                elements.searchInput.addEventListener('input', () => {\n                    handleInputChange(elements.searchInput.value, allItems, elements);\n                });\n                \n                \/\/ Hide dropdown when clicking outside\n                document.addEventListener('click', (event) => {\n                    if (!elements.dropdown.contains(event.target) && event.target !== elements.searchInput) {\n                        elements.dropdown.style.display = 'none';\n                    }\n                });\n                \n                \/\/ Add event listener to the submit button\n                elements.submitButton.addEventListener('click', () => {\n                    handleSubmitButton(elements, allItems);\n                });\n                \n                \/\/ Allow pressing Enter key to search\n                elements.searchInput.addEventListener('keypress', (event) => {\n                    if (event.key === 'Enter') {\n                        elements.submitButton.click();\n                    }\n                });\n\n                \/\/ Copy button functionality\n                if (elements.copyButton) {\n                    elements.copyButton.addEventListener('click', () => {\n                        copyCitationToClipboard(elements);\n                    });\n                }\n\n                \/\/ Add event listeners for radio buttons\n                document.getElementById('legislationRadio').addEventListener('change', function() {\n                    if (this.checked) {\n                        document.getElementById('legislationSection').style.display = 'block';\n                        document.getElementById('caseFatwaSection').style.display = 'none';\n                        \/\/ Clear the result\n                        document.getElementById('citationContainer').style.display = 'none';\n                        document.getElementById('citationOutput').innerHTML = '';\n                        document.getElementById('validationAlert').style.display = 'none';\n                    }\n                });\n                \n                document.getElementById('caseFatwaRadio').addEventListener('change', function() {\n                    if (this.checked) {\n                        document.getElementById('legislationSection').style.display = 'none';\n                        document.getElementById('caseFatwaSection').style.display = 'block';\n                        document.getElementById('caseRadio').checked = true;\n                        document.getElementById('caseAdditionalFields').style.display = 'block';\n                        document.getElementById('fatwaAdditionalFields').style.display = 'none';\n                        \/\/ Clear the result\n                        document.getElementById('citationContainer').style.display = 'none';\n                        document.getElementById('citationOutput').innerHTML = '';\n                        document.getElementById('validationAlert').style.display = 'none';\n                        clearAllFields();\n                    }\n                });\n\n                \/\/ Show or hide additional fields based on case\/fatwa selection\n                document.getElementById('caseRadio').addEventListener('change', function() {\n                    document.getElementById('caseAdditionalFields').style.display = this.checked ? 'block' : 'none';\n                    document.getElementById('fatwaAdditionalFields').style.display = this.checked ? 'none' : 'block';\n                    document.getElementById('entityName').placeholder = 'e.g. Supreme Court';\n                    document.getElementById('bookTitle').placeholder = 'e.g. Collection of Supreme Court Judgments (Labour-Commercial) 2021-2022';\n                    clearAllFields();\n                });\n                \n                document.getElementById('fatwaRadio').addEventListener('change', function() {\n                    document.getElementById('caseAdditionalFields').style.display = this.checked ? 'none' : 'block';\n                    document.getElementById('fatwaAdditionalFields').style.display = this.checked ? 'block' : 'none';\n                    document.getElementById('entityName').placeholder = 'e.g. Ministry of Justice and Legal Affairs';\n                    document.getElementById('fatwaBookTitle').placeholder = 'e.g. Collection of Principles of the MJLA';\n                    clearAllFields();\n                });\n\n                \/\/ Show or hide publication details based on publication status\n                document.getElementById('publishedRadio').addEventListener('change', function() {\n                    document.getElementById('publicationDetails').style.display = this.checked ? 'block' : 'none';\n                });\n                \n                document.getElementById('notPublishedRadio').addEventListener('change', function() {\n                    document.getElementById('publicationDetails').style.display = this.checked ? 'none' : 'block';\n                });\n\n                \/\/ Add event listener for clear button\n                document.getElementById('clearFieldsButton').addEventListener('click', clearAllFields);\n\n                \/\/ Add event listener for case\/fatwa citation generation\n                document.getElementById('generateCaseFatwaButton').addEventListener('click', function() {\n                    const isFatwa = document.getElementById('fatwaRadio').checked;\n                    const entityName = document.getElementById('entityName').value.trim();\n                    const issuanceDate = isFatwa ? document.getElementById('fatwaIssuanceDate').value : document.getElementById('issuanceDate').value;\n                    const number = isFatwa ? document.getElementById('fatwaNumber').value.trim() : document.getElementById('caseNumber').value.trim();\n                    const bookTitle = isFatwa ? document.getElementById('fatwaBookTitle').value.trim() : document.getElementById('bookTitle').value.trim();\n                    const pageNumber = isFatwa ? document.getElementById('fatwaPageNumber').value.trim() : document.getElementById('pageNumber').value.trim();\n                    \n                    if (!entityName || !number || !issuanceDate || (isFatwa && (!bookTitle || !pageNumber))) {\n                        const validationAlert = document.getElementById('validationAlert');\n                        validationAlert.style.display = 'block';\n                        validationAlert.innerHTML = `\n                            <div style=\"padding: 10px; border: 1px solid #f5c6cb; background-color: #f8d7da; color: #721c24; margin-top: 15px;\">\n                                Please fill in all required fields\n                            <\/div>\n                        `;\n                        validationAlert.scrollIntoView({ behavior: 'smooth', block: 'center' });\n                        return;\n                    }\n                    \n                    \/\/ Format the date\n                    const date = new Date(issuanceDate);\n                    const formattedDate = `${date.getDate()} ${new Intl.DateTimeFormat('en-US', {month: 'long'}).format(date)} ${date.getFullYear()}`;\n                    \n                    \/\/ Generate citation based on type\n                    let citation = '';\n                    if (isFatwa) {\n                        citation = `${entityName} Fatwa ${number} (issued ${formattedDate}) ${bookTitle}, ${pageNumber}.`;\n                    } else {\n                        const caseType = document.getElementById('caseTypeField').value.trim();\n                        const circuitName = document.getElementById('circuitName').value.trim();\n                        const isPublished = document.getElementById('publishedRadio').checked;\n                        \n                        if (!caseType || !circuitName || (!isPublished && (!entityName || !number || !issuanceDate))) {\n                            alert('Please fill in all fields for the case.');\n                            return;\n                        }\n                        \n                        if (isPublished) {\n                            citation = `${entityName} ${caseType} ${number} ${circuitName} (issued ${formattedDate}) ${bookTitle}, ${pageNumber}.`;\n                        } else {\n                            citation = `${entityName} ${caseType} ${number} ${circuitName} (issued ${formattedDate}) unpublished.`;\n                        }\n                    }\n                    \n                    \/\/ Hide validation alert if it exists\n                    document.getElementById('validationAlert').style.display = 'none';\n                    \n                    \/\/ Display the citation\n                    document.getElementById('citationContainer').style.display = 'block';\n                    document.getElementById('citationOutput').textContent = citation;\n                });\n            }\n\n            \/\/ Copy citation to clipboard\n            function copyCitationToClipboard(elements) {\n                const includeLink = document.getElementById('includeLink').checked;\n                \n                if (includeLink && elements.citationOutput.querySelector('a')) {\n                    const html = elements.citationOutput.innerHTML;\n                    const text = elements.citationOutput.innerText;\n                    \n                    if (navigator.clipboard && window.ClipboardItem) {\n                        const htmlBlob = new Blob([html], { type: 'text\/html' });\n                        const textBlob = new Blob([text], { type: 'text\/plain' });\n                        \n                        navigator.clipboard.write([\n                            new ClipboardItem({\n                                'text\/html': htmlBlob,\n                                'text\/plain': textBlob\n                            })\n                        ]).catch(err => {\n                            copyPlainText(text);\n                        });\n                    } else {\n                        copyPlainText(text);\n                    }\n                } else {\n                    copyPlainText(elements.citationOutput.innerText);\n                }\n                \n                \/\/ Show feedback that text was copied\n                elements.copyFeedback.style.display = 'block';\n                \n                \/\/ Hide feedback after 2 seconds\n                setTimeout(() => {\n                    elements.copyFeedback.style.display = 'none';\n                }, 2000);\n            }\n\n            function copyPlainText(text) {\n                const textarea = document.createElement('textarea');\n                textarea.value = text;\n                document.body.appendChild(textarea);\n                textarea.select();\n                document.execCommand('copy');\n                document.body.removeChild(textarea);\n            }\n\n            function handleInputChange(inputValue, allItems, elements) {\n                const searchTerm = inputValue.trim().toLowerCase();\n                \n                if (searchTerm === '') {\n                    updateDropdownOptions(allItems, elements.dropdown);\n                } else {\n                    const keywords = searchTerm.split(\/\\s+\/).filter(kw => kw.length > 0);\n                    const filteredItems = filterItemsByKeywords(allItems, keywords);\n                    updateDropdownOptions(filteredItems, elements.dropdown, keywords);\n                }\n                \n                elements.dropdown.style.display = 'block';\n            }\n\n            function handleSubmitButton(elements, allItems) {\n                const searchTerm = elements.searchInput.value.trim();\n                \n                if (searchTerm) {\n                    document.getElementById('validationAlert').style.display = 'none';\n                    elements.searchResults.style.display = 'none';\n                    searchForDecree(searchTerm, allItems, elements);\n                } else {\n                    elements.citationContainer.style.display = 'block';\n                    elements.citationOutput.innerHTML = 'Please select an item from the dropdown menu.';\n                }\n            }\n\n            function filterItemsByKeywords(items, keywords) {\n                return items.filter(item => {\n                    const titleLower = item.title.toLowerCase();\n                    const numberMatrixLower = (item.numberMatrix || '').toString().toLowerCase();\n                    \n                    return keywords.every(keyword => \n                        titleLower.includes(keyword) || numberMatrixLower.includes(keyword)\n                    );\n                });\n            }\n\n            function updateDropdownOptions(items, dropdown, keywords = []) {\n                dropdown.innerHTML = '';\n                \n                if (items.length === 0) {\n                    dropdown.innerHTML = '<div style=\"padding: 10px; text-align: center; color: #666;\">No matching decrees found<\/div>';\n                    return;\n                }\n                \n                items.forEach(item => {\n                    const option = document.createElement('div');\n                    option.className = 'dropdown-option';\n                    \n                    if (keywords.length > 0) {\n                        let displayTitle = item.title;\n                        keywords.forEach(keyword => {\n                            if (keyword.length > 1) {\n                                const regex = new RegExp('(' + keyword + ')', 'gi');\n                                displayTitle = displayTitle.replace(regex, '<mark>$1<\/mark>');\n                            }\n                        });\n                        option.innerHTML = displayTitle;\n                    } else {\n                        option.textContent = item.title;\n                    }\n                    \n                    option.addEventListener('click', function() {\n                        document.getElementById('searchInput').value = item.title;\n                        dropdown.style.display = 'none';\n                    });\n                    \n                    dropdown.appendChild(option);\n                });\n            }\n\n            function searchForDecree(searchTerm, allItems, elements) {\n                const keywords = searchTerm.toLowerCase().split(\/\\s+\/).filter(kw => kw.length > 0);\n                const results = filterItemsByKeywords(allItems, keywords);\n                \n                displaySearchResults(results, elements);\n            }\n\n            function displaySearchResults(results, elements) {\n                elements.citationContainer.style.display = 'block';\n                \n                if (results.length === 0) {\n                    elements.citationOutput.innerHTML = 'No decrees found matching your search.';\n                    elements.searchResults.style.display = 'none';\n                    elements.citeAttachmentButton.style.display = 'none';\n                } else if (results.length === 1) {\n                    const item = results[0];\n                    const citation = formatCitation(item);\n                    elements.citationOutput.innerHTML = citation;\n                    elements.searchResults.style.display = 'none';\n                    \n                    const title = item.title.toLowerCase();\n                    const hasIssuing = title.includes('issuing') || title.includes('promulgating');\n                    const hasAmending = title.includes('amending') || title.includes('amendment');\n                    const hasAndIssuing = title.includes('and issuing') || title.includes('and promulgating');\n                    \n                    if (hasIssuing && !hasAmending && !hasAndIssuing) {\n                        elements.citeAttachmentButton.style.display = 'inline-block';\n                        elements.citeAttachmentButton.setAttribute('data-item', JSON.stringify(item));\n                        \n                        elements.citeAttachmentButton.onclick = function() {\n                            const itemData = JSON.parse(this.getAttribute('data-item'));\n                            const attachmentCitation = formatAttachmentCitation(itemData);\n                            elements.citationOutput.innerHTML = attachmentCitation;\n                        };\n                    } else {\n                        elements.citeAttachmentButton.style.display = 'none';\n                    }\n                } else {\n                    elements.resultsCount.textContent = `Found ${results.length} matching decrees. Click on one to view citation:`;\n                    elements.resultsList.innerHTML = '';\n                    \n                    results.forEach(item => {\n                        createResultItem(item, elements.resultsList, elements.citationOutput, elements.citationContainer);\n                    });\n                    \n                    elements.searchResults.style.display = 'block';\n                    elements.citationOutput.innerHTML = 'Click on a result to view its citation.';\n                    elements.citeAttachmentButton.style.display = 'none';\n                }\n            }\n\n            function createResultItem(item, resultsList, citationOutput, citationContainer) {\n                const resultItem = document.createElement('a');\n                resultItem.href = '#';\n                resultItem.textContent = item.title;\n                \n                resultItem.addEventListener('click', function(e) {\n                    e.preventDefault();\n                    \n                    document.querySelectorAll('#resultsList a').forEach(el => {\n                        el.classList.remove('active');\n                    });\n                    \n                    this.classList.add('active');\n                    \n                    citationContainer.style.display = 'block';\n                    citationOutput.innerHTML = formatCitation(item);\n                    \n                    citationContainer.scrollIntoView({ behavior: 'smooth' });\n                });\n                \n                resultsList.appendChild(resultItem);\n            }\n\n            function formatDate(dateString) {\n                if (!dateString || dateString.trim() === '') return '';\n                \n                try {\n                    const [year, month, day] = dateString.split('-');\n                    const date = new Date(year, parseInt(month) - 1, day);\n                    \n                    if (isNaN(date.getTime())) return dateString;\n                    \n                    const months = [\n                        'January', 'February', 'March', 'April', 'May', 'June',\n                        'July', 'August', 'September', 'October', 'November', 'December'\n                    ];\n                    \n                    return `${parseInt(day)} ${months[date.getMonth()]} ${year}`;\n                } catch (e) {\n                    return dateString;\n                }\n            }\n\n            function formatCitation(item) {\n                if (!item.title) return 'Incomplete data for citation';\n                \n                let formattedTitle = item.title;\n                \n                if (!formattedTitle.trim().startsWith(\"Royal Decree\")) {\n                    formattedTitle = formattedTitle.replace(\/:\/g, '');\n                    formattedTitle = formattedTitle.replace(\/Ministerial Decision\/gi, 'Decision');\n                }\n                \n                let citation = '';\n                const includeLink = document.getElementById('includeLink').checked;\n                \n                if (includeLink && item.decreeURL) {\n                    citation = `<a href=\"${item.decreeURL}\" target=\"_blank\">${formattedTitle}<\/a>`;\n                } else {\n                    citation = formattedTitle;\n                }\n                \n                const formattedIssueDate = formatDate(item.issueDate);\n                const formattedPubDate = formatDate(item.pubDate);\n                const hasGazetteNo = item.gazetteNo && item.gazetteNo.trim() !== '';\n                \n                let dateInfo = '';\n                if (formattedIssueDate) {\n                    dateInfo = ` (issued on ${formattedIssueDate}`;\n                    \n                    if (hasGazetteNo && formattedPubDate) {\n                        dateInfo += `, published on ${formattedPubDate}`;\n                    }\n                    \n                    dateInfo += ')';\n                }\n                \n                const gazetteNo = hasGazetteNo ? ` OG ${item.gazetteNo}` : '';\n                \n                return citation + dateInfo + gazetteNo + \".\";\n            }\n\n            function formatAttachmentCitation(item) {\n                if (!item.title) return 'Incomplete data for citation';\n                \n                const title = item.title;\n                let attachmentTitle = '';\n                let issuanceTool = '';\n                \n                const issuingMatch = title.match(\/(?:promulgating|issuing)\\s+(.*?)$\/i);\n                if (issuingMatch && issuingMatch[1]) {\n                    attachmentTitle = issuingMatch[1].trim();\n                    attachmentTitle = attachmentTitle.charAt(0).toUpperCase() + attachmentTitle.slice(1);\n                }\n                \n                const issuanceMatch = title.match(\/^(.*?\\d\\s+)\/i);\n                if (issuanceMatch && issuanceMatch[1]) {\n                    issuanceTool = issuanceMatch[1].trim();\n                }\n                \n                let citation = '';\n                const includeLink = document.getElementById('includeLink').checked;\n                \n                if (includeLink && item.decreeURL) {\n                    citation = attachmentTitle + \", \" + `<a href=\"${item.decreeURL}\" target=\"_blank\">${issuanceTool}<\/a>`;\n                } else {\n                    citation = attachmentTitle + \", \" + issuanceTool;\n                }\n                \n                const formattedIssueDate = formatDate(item.issueDate);\n                const formattedPubDate = formatDate(item.pubDate);\n                const hasGazetteNo = item.gazetteNo && item.gazetteNo.trim() !== '';\n                \n                let dateInfo = '';\n                if (formattedIssueDate) {\n                    dateInfo = ` (issued on ${formattedIssueDate}`;\n                    \n                    if (hasGazetteNo && formattedPubDate) {\n                        dateInfo += `, published on ${formattedPubDate}`;\n                    }\n                    \n                    dateInfo += ')';\n                }\n                \n                const gazetteNo = hasGazetteNo ? ` OG ${item.gazetteNo}` : '';\n                \n                return citation + dateInfo + gazetteNo + \".\";\n            }\n\n            function clearAllFields() {\n                document.getElementById('entityName').value = '';\n                document.getElementById('caseTypeField').value = '';\n                document.getElementById('caseNumber').value = '';\n                document.getElementById('circuitName').value = '';\n                document.getElementById('issuanceDate').value = '';\n                document.getElementById('bookTitle').value = '';\n                document.getElementById('pageNumber').value = '';\n                document.getElementById('fatwaNumber').value = '';\n                document.getElementById('fatwaIssuanceDate').value = '';\n                document.getElementById('fatwaBookTitle').value = '';\n                document.getElementById('fatwaPageNumber').value = '';\n            }\n\n            \/\/ Initialize the tool when document is ready\n            initCitationTool();\n        });\n        <\/script>\n        \n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"templates\/template-full-width.php","meta":{"footnotes":""},"class_list":["post-81","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/olcs.decree.om\/index.php?rest_route=\/wp\/v2\/pages\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/olcs.decree.om\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/olcs.decree.om\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/olcs.decree.om\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/olcs.decree.om\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":1,"href":"https:\/\/olcs.decree.om\/index.php?rest_route=\/wp\/v2\/pages\/81\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/olcs.decree.om\/index.php?rest_route=\/wp\/v2\/pages\/81\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/olcs.decree.om\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}