test

<style>
  .form-group {
    margin-bottom: 25px;
  }

  .form-group label {
    font-size: 17px;
    font-weight: normal;
    line-height: 1.2em;
    display: block;
    margin-bottom: 8px;
    color: #000;
    padding-top: 10px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
  }

  .form-required {
    color: #ff0000;
  }
</style>

<form class="jotform-form p-3" action="https://hipaa-submit.jotform.com/submit/250034603539350" method="post"
    id="250034603539350" name="form_250034603539350" style="width: 100%;">
  <input type="hidden" name="formID" value="250034603539350">
  <input type="hidden" id="current_page_url" name="current_page_url" value="">

  <!-- Honeypot -->
  <div style="display: none !important; visibility: hidden; position: absolute; left: -9999px;">
    <label for="website_field">Website</label>
    <input type="text" id="website_field" name="website" tabindex="-1" autocomplete="off">
  </div>

  <div style="width: 100%;">
    <h2 class="leading-normal text-[20px] text-black mb-[30px] font-[500] text-center">New Patient Form</h2>

    <div class="form-group">
      <label for="input_3">How can we help you?</label>
      <select id="input_3" name="q3_howCan">
        <option value="">Please Select</option>
        <option value="Psychiatry">Psychiatry</option>
        <option value="Therapy">Therapy</option>
        <option value="Addiction Treatment/PHP/IOP">Addiction Treatment/PHP/IOP</option>
        <option value="TL/Sober Living">TL/Sober Living</option>
        <option value="TMS for Depression">TMS for Depression</option>
        <option value="Medication Management">Medication Management</option>
        <option value="I'm not sure…">I'm not sure…</option>
      </select>
    </div>

    <div class="form-group">
      <label for="input_4">First Name<span class="form-required">*</span></label>
      <input type="text" id="input_4" name="q4_firstName" required>
    </div>

    <div class="form-group">
      <label for="input_5">Last Name<span class="form-required">*</span></label>
      <input type="text" id="input_5" name="q5_lastName" required>
    </div>

    <div class="form-group">
      <label for="input_6">Email address<span class="form-required">*</span></label>
      <input type="email" id="input_6" name="q6_emailAddress"
        pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" required
        title="Please enter a valid email address">
    </div>

<div class="form-group">
  <label>Do we have permission to text you?<span class="form-required">*</span></label>
  <div style="display: flex; gap: 20px; align-items: center; padding-top: 10px;">
    <div style="display: flex; align-items: center;">
      <input type="radio" id="input_10_0" name="q10_doWe" value="Yes" required style="margin-right: 8px;">
      <label for="input_10_0">Yes</label>
    </div>
    <div style="display: flex; align-items: center;">
      <input type="radio" id="input_10_1" name="q10_doWe" value="No" required style="margin-right: 8px;">
      <label for="input_10_1">No</label>
    </div>
  </div>
</div>

    <div class="form-group">
      <label for="input_11">What location are you interested in?</label>
      <select id="input_11" name="q11_whatLocation">
        <option value="">Please Select</option>
        <option value="Cary">Cary</option>
        <option value="Chapel Hill">Chapel Hill</option>
        <option value="Raleigh">Raleigh</option>
        <option value="Telehealth">Telehealth</option>
      </select>
    </div>

    <div class="form-group">
      <label for="input_12">Is there anything else you would like us to know?</label>
      <textarea id="input_12" name="q12_isThere" rows="4"></textarea>
    </div>

    <div class="form-group">
      <label for="lite_mode_24">Date of Birth<span class="form-required">*</span></label>
      <input type="text" id="lite_mode_24" name="q24_date[month]" placeholder="MM/DD/YYYY" required>
    </div>

    <div class="form-group">
      <label for="input_22_full">Phone Number<span class="form-required">*</span></label>
      <input type="tel" id="input_22_full" name="q22_phoneNumber[full]" placeholder="(000) 000-0000" required>
    </div>

    <div class="form-group">
      <label for="input_referred_by">Referred by</label>
      <input type="text" id="input_referred_by" name="q_referred_by">
    </div>

    <input type="hidden" id="input_23" name="q23_typeA" value="999999">

    <!-- Captcha -->
    <div class="form-group">
      <label for="input_26">Please verify that you are human<span class="form-required">*</span></label>
      <div id="cid_26" class="form-input-wide jf-required" data-layout="full">
        <div class="form-captcha" data-component="captcha">
          <label for="input_26">
            <img alt="Captcha - Reload if not displayed" id="input_26_captcha" class="form-captcha-image"
              style="background:url(https://cdn.jotfor.ms/images/loader-big.gif) no-repeat center; border-radius: 8px;"
              src="https://cdn.jotfor.ms/images/blank.gif" width="150" height="41" />
          </label>
          <div class="flex gap-[10px] items-center mt-[10px]" style="white-space:nowrap">
            <input type="text" id="input_26" name="captcha" required placeholder="Enter code">
            <img width="16" height="16" src="https://cdn.jotfor.ms/images/reload.png" alt="Reload"
              id="input_26_reload" style="cursor:pointer;vertical-align:middle">
            <input type="hidden" name="captcha_id" id="input_26_captcha_id" value="0">
          </div>
        </div>
      </div>
    </div>

    <div id="error-container" style="color: #ff0000; margin-bottom: 20px; text-align: center;"></div>

    <div>
      <p class="text-center pb-[20px] leading-[15px] text-[14px]">
        After submitting your contact information, you will be redirected to our online scheduling system to choose an
        appointment time that works best for you
      </p>
    </div>

    <div style="text-align: center;">
      <button type="submit"
        class="w-full bg-[#2a3b5a] hover:bg-ebony text-white py-3 px-7 rounded-[8px] cursor-pointer"
        style="transition: background-color 0.3s;">Submit</button>
    </div>
  </div>
</form>

<div class="flex justify-center">
  <span style="font-size: 14px;color: var(--east-bay);">
    By filling out the above form you agree to our
    <a href="/privacy-policy/" target="_blank" style="font-weight: 600; color:var(--ebony)">
      Privacy Policy
    </a>
  </span>
</div>


<script>
    document.addEventListener('DOMContentLoaded', function () {
        // Set current page URL without query parameters
        document.getElementById('current_page_url').value = window.location.origin + window.location.pathname;

        // Load JotForm captcha scripts
        if (!document.querySelector('script[src*="prototype.forms.js"]')) {
            const prototypeScript = document.createElement('script');
            prototypeScript.src = "https://cdn02.jotfor.ms/static/prototype.forms.js?v=3.3.61544";
            prototypeScript.type = "text/javascript";
            document.head.appendChild(prototypeScript);
        }

        if (!document.querySelector('script[src*="jotform.forms.js"]')) {
            const jotformScript = document.createElement('script');
            jotformScript.src = "https://cdn03.jotfor.ms/static/jotform.forms.js?v=3.3.61544";
            jotformScript.type = "text/javascript";
            document.head.appendChild(jotformScript);
        }

        // Initialize Jotform captcha
        setTimeout(function () {
            if (typeof JotForm !== 'undefined') {
                JotForm.initCaptcha('input_26');
                document.getElementById('input_26_reload').addEventListener('click', function () {
                    JotForm.reloadCaptcha('input_26');
                });
            }
        }, 1000);

        const form = document.getElementById('250034603539350');
        const errorContainer = document.getElementById('error-container');

        // Phone formatting and validation
        const phoneInput = document.getElementById('input_22_full');
        phoneInput.addEventListener('input', function (e) {
            let value = e.target.value.replace(/\D/g, '');
            if (value.length > 10) value = value.substr(0, 10);

            if (value.length >= 6) {
                value = '(' + value.substr(0, 3) + ') ' + value.substr(3, 3) + '-' + value.substr(6);
            } else if (value.length >= 3) {
                value = '(' + value.substr(0, 3) + ') ' + value.substr(3);
            } else if (value.length > 0) {
                value = '(' + value;
            }

            e.target.value = value;

            // Validate length
            if (value.replace(/\D/g, '').length !== 10) {
                this.style.borderColor = '#ff0000';
                this.setCustomValidity('Please enter a valid 10-digit phone number');
            } else {
                this.style.borderColor = '#ddd';
                this.setCustomValidity('');
            }
        });

const dateInput = document.getElementById('lite_mode_24');
dateInput.addEventListener('input', function (e) {
  let value = e.target.value.replace(/\D/g, '');
  if (value.length > 8) value = value.substr(0, 8);

  if (value.length >= 4) {
    value = value.substr(0, 2) + '/' + value.substr(2, 2) + '/' + value.substr(4);
  } else if (value.length >= 2) {
    value = value.substr(0, 2) + '/' + value.substr(2);
  }

  e.target.value = value;
});

// Full DOB format check on blur
dateInput.addEventListener('blur', function () {
  const value = this.value;
  const isValidFormat = /^\d{2}\/\d{2}\/\d{4}$/.test(value);

  if (!isValidFormat) {
    this.style.borderColor = '#ff0000';
    this.setCustomValidity('Please enter a complete date in MM/DD/YYYY format');
    return;
  }

  const [mm, dd, yyyy] = value.split('/').map(Number);
  const isValidDate = (d => d && d.getMonth() + 1 === mm && d.getDate() === dd && d.getFullYear() === yyyy)
    (new Date(`${yyyy}-${mm}-${dd}`));

  if (!isValidDate || yyyy < 1900 || yyyy > new Date().getFullYear()) {
    this.style.borderColor = '#ff0000';
    this.setCustomValidity('Please enter a valid date');
  } else {
    this.style.borderColor = '#ddd';
    this.setCustomValidity('');
  }
});

        // Email validation
        const emailInput = document.getElementById('input_6');
        emailInput.addEventListener('input', function () {
            if (this.validity.typeMismatch) {
                this.setCustomValidity('Please enter a valid email address');
                this.style.borderColor = '#ff0000';
            } else {
                this.setCustomValidity('');
                this.style.borderColor = '#ddd';
            }
        });

        // Form validation
        function validateForm() {
            let isValid = true;
            const errors = [];

            // Reset previous errors
            const inputs = form.querySelectorAll('input, select, textarea');
            inputs.forEach(input => input.style.borderColor = '#ddd');
            errorContainer.innerHTML = '';

            // First Name
            const firstName = document.getElementById('input_4');
            if (!firstName.value.trim()) {
                isValid = false;
                firstName.style.borderColor = '#ff0000';
                errors.push('First Name is required');
            }

            // Last Name
            const lastName = document.getElementById('input_5');
            if (!lastName.value.trim()) {
                isValid = false;
                lastName.style.borderColor = '#ff0000';
                errors.push('Last Name is required');
            }

            // Email
            const email = document.getElementById('input_6');
            const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            if (!email.value.trim() || !emailRegex.test(email.value)) {
                isValid = false;
                email.style.borderColor = '#ff0000';
                errors.push('Valid email address is required');
            }

            // Date of Birth
            const dob = document.getElementById('lite_mode_24');
            const dateValue = dob.value;
            if (!/^\d{2}\/\d{2}\/\d{4}$/.test(dateValue)) {
                isValid = false;
                dob.style.borderColor = '#ff0000';
                errors.push('Please enter a valid date in MM/DD/YYYY format');
            } else {
                const parts = dateValue.split('/');
                const month = parseInt(parts[0]);
                const day = parseInt(parts[1]);
                const year = parseInt(parts[2]);
                const currentYear = new Date().getFullYear();

                if (month < 1 || month > 12 || day < 1 || day > 31 || year < 1900 || year > currentYear) {
                    isValid = false;
                    dob.style.borderColor = '#ff0000';
                    errors.push('Please enter a valid date');
                } else {
                    const date = new Date(year, month - 1, day);
                    if (date.getMonth() !== month - 1) {
                        isValid = false;
                        dob.style.borderColor = '#ff0000';
                        errors.push('Please enter a valid date');
                    }
                }
            }

            // Text Permission
            const textPermission = form.querySelector('input[name="q10_doWe"]:checked');
            if (!textPermission) {
                isValid = false;
                errors.push('Please select whether we can text you');
            }

            // Phone Number
            const phone = document.getElementById('input_22_full');
            const phoneDigits = phone.value.replace(/\D/g, '');
            if (phoneDigits.length !== 10) {
                isValid = false;
                phone.style.borderColor = '#ff0000';
                errors.push('Please enter a valid 10-digit phone number');
            }

            // hCaptcha Validation
            const hcaptchaInput = document.getElementById('input_25');
            if (!hcaptchaInput.value) {
                isValid = false;
                errors.push('Please complete the captcha verification');
            }

            // Show errors if any
            if (errors.length > 0) {
                errorContainer.innerHTML = errors.map(error => `<div style="margin: 5px 0;">${error}</div>`)
                    .join(
                        '');
            }

            return isValid;
        }

        // Form submission
        form.addEventListener('submit', function (e) {
            if (!validateForm()) {
                e.preventDefault();
                errorContainer.scrollIntoView({
                    behavior: 'smooth'
                });
            }
        });

        // Real-time validation
        const requiredInputs = form.querySelectorAll('input[required], select[required]');
        requiredInputs.forEach(input => {
            input.addEventListener('blur', function () {
                if (!this.value.trim()) {
                    this.style.borderColor = '#ff0000';
                } else {
                    this.style.borderColor = '#ddd';
                }
            });
        });
    });
</script>