package-selctor2

(function () {
  var mfdAnswers = {};
  var mfdHistory = [];
  var MFD_TOTAL_TEEN = 5;
  var MFD_TOTAL_ADULT = 4;

  function mfdTotalSteps() {
    return mfdAnswers[0] === 'adult' ? MFD_TOTAL_ADULT : MFD_TOTAL_TEEN;
  }

  var mfdPackages = {
    teen_lessons: {
      title: "Teen In-Car Lessons Package",
      desc: "Permit in hand and classroom hours done? Add in-car sessions with a certified MYFIRSTDRIVE instructor to meet TDLR's behind-the-wheel requirement and prepare for the DPS road test.",
      features: [
        "Flexible lesson bundles to meet the 37-hour TDLR driving requirement",
        "7 hours of observation time included",
        "Available at both Richmond and Sugar Land",
        "Instructor tailors lessons to your school schedule",
        "Focus areas: highway, parking, test-route prep"
      ],
      cta: "Book Teen Driving Lessons",
      href: "https://myfirstdrive.net/Products/Category/Teen-Driving-Lessons-Only"
    }
  };

  var mfdAlsoSee = {
    teen_lessons: {
      title: "Teen DE-964 Full Course",
      desc: "Still need classroom credit? Our full DE-964 package covers both the online course and in-car hours."
    }
  };

  function mfdGetPackageKey() {
    var isAdult = mfdAnswers[0] === 'adult';
    if (isAdult) {
      return mfdAnswers[1] === 'permit_no' ? 'adult_full' : 'adult_lessons';
    } else {
      var hasPermit = mfdAnswers[1] === 'permit_yes';
      var hasExp = mfdAnswers[2] === 'road' || mfdAnswers[2] === 'license';
      return (hasPermit && hasExp) ? 'teen_lessons' : 'teen_full';
    }
  }

  function mfdCheckIcon() {
    return '';
  }

  function mfdAdaptQuestions() {
    var isAdult = mfdAnswers[0] === 'adult';
    var q1text = document.getElementById('mfdQ1text');
    var q1opts = document.getElementById('mfdQ1opts');

    if (isAdult) {
      q1text.textContent = "Has the student completed the online course and obtained a learner's permit?";
      q1opts.innerHTML =
        '' +
        '';
    } else {
      q1text.textContent = "Has the student completed the online course and obtained a learner's permit?";
      q1opts.innerHTML =
        '' +
        '';
    }

    document.getElementById('mfdTdlrNote').style.display = isAdult ? 'none' : 'block';

    var teenRoadmap = document.getElementById('mfdTeenRoadmap');
    if (teenRoadmap) teenRoadmap.style.display = isAdult ? 'none' : 'block';

    var adultRoadmap = document.getElementById('mfdAdultRoadmap');
    if (adultRoadmap) adultRoadmap.style.display = isAdult ? 'block' : 'none';

    for (var i = 0; i <= 4; i++) {
      var el = document.getElementById('mfdLabel' + i);
      if (el) el.textContent = 'Question ' + (i + 1);
    }
  }

  function mfdOpenQuiz() {
    document.getElementById('mfdModalBg').classList.add('mfd-open');
    mfdHistory.length = 0;
    Object.keys(mfdAnswers).forEach(function (k) { delete mfdAnswers[k]; });
    mfdGoTo(0);
  }

  function mfdCloseQuiz() {
    document.getElementById('mfdModalBg').classList.remove('mfd-open');
  }

  function mfdBgClick(e) {
    if (e.target === document.getElementById('mfdModalBg')) mfdCloseQuiz();
  }

  function mfdRestart() {
    mfdHistory.length = 0;
    Object.keys(mfdAnswers).forEach(function (k) { delete mfdAnswers[k]; });
    mfdGoTo(0);
  }

  function mfdGoTo(stepIdx) {
    var steps = document.querySelectorAll('.mfd-quiz .mfd-step');
    for (var i = 0; i < steps.length; i++) steps[i].classList.remove('mfd-active');
    var isResult = stepIdx === 'result';
    var el = isResult ? document.getElementById('mfdStepResult') : document.getElementById('mfdStep' + stepIdx);
    if (el) el.classList.add('mfd-active');
    var total = mfdTotalSteps();
    var current = isResult ? total : stepIdx;
    var pct = Math.min(Math.round((current / total) * 100), 100);
    document.getElementById('mfdProgFill').style.width = pct + '%';
  }

  function mfdGoBack(currentStep) {
    if (mfdHistory.length === 0) return;
    var prev = mfdHistory.pop();
    if (currentStep === 'result') {
      delete mfdAnswers[prev];
    } else {
      delete mfdAnswers[currentStep];
    }
    mfdGoTo(prev);
  }

  function mfdPick(stepIdx, value) {
    mfdAnswers[stepIdx] = value;
    if (stepIdx === 0) mfdAdaptQuestions();
    var isAdult = mfdAnswers[0] === 'adult';

    // Teen + "still need to complete the online course" -> Complete Teen Drivers Ed packages
    if (!isAdult && stepIdx === 1 && value === 'permit_no') {
      mfdHistory.push(stepIdx);
      mfdShowTeenPackageList();
      return;
    }

    // Teen + "permit already obtained" -> Teen Driving Lessons and Road Test packages
    if (!isAdult && stepIdx === 1 && value === 'permit_yes') {
      mfdHistory.push(stepIdx);
      mfdShowTeenLessonsList();
      return;
    }

    // Adult + "still need to complete the online course" -> Complete Adult Drivers Ed packages
    if (isAdult && stepIdx === 1 && value === 'permit_no') {
      mfdHistory.push(stepIdx);
      mfdShowAdultPackageList();
      return;
    }

    // Adult + "permit already obtained" -> Adult Driving Lessons and Road Test packages
    if (isAdult && stepIdx === 1 && value === 'permit_yes') {
      mfdHistory.push(stepIdx);
      mfdShowAdultLessonsList();
      return;
    }

    var next;
    if (isAdult) {
      next = stepIdx < 3 ? stepIdx + 1 : 'result';
    } else {
      next = stepIdx < 4 ? stepIdx + 1 : 'result';
    }
    mfdHistory.push(stepIdx);
    if (next === 'result') {
      mfdShowResult();
    } else {
      mfdGoTo(next);
    }
  }

  function mfdShowResult() {
    var key = mfdGetPackageKey();
    if (key === 'teen_full') {
      mfdShowTeenPackageList();
      return;
    }
    var pkg = mfdPackages[key];
    var also = mfdAlsoSee[key];
    var features = pkg.features.map(function (f) {
      return '

  • ' + mfdCheckIcon() + ' ' + f + '

';
    }).join('');
    document.getElementById('mfdResultContent').innerHTML =
      '

' +
        '

Recommended for you

' +
        '

' + pkg.title + '

' +
        '

' + pkg.desc + '

' +
        '
  • ' + features + '
' +
        '
' +
          '' + pkg.cta + '' +
          'See all packages' +
        '
' +
      '

' +
      '

' +
        '

Also worth a look

' +
        '

' + also.title + '

' +
        '

' + also.desc + '

' +
      '

';
    mfdGoTo('result');
  }

  // ── Teen Complete Drivers Ed Packages ──
  var mfdTeenCompletePackages = [
    { name: "Core",     price: "$799",  lessons: "Thirteen (13)",    lessonHours: 13, href: "https://myfirstdrive.net/Package/Core-Teen-Complete-Drivers-Ed-Package",     recommended: true },
    { name: "Min",      price: "$529",  lessons: "Seven (7)",        lessonHours: 7,  href: "https://myfirstdrive.net/Package/Min-Teen-Complete-Drivers-Ed-Package" },
    { name: "Basic",    price: "$599",  lessons: "Nine (9)",         lessonHours: 9,  href: "https://myfirstdrive.net/Package/Basic-Teen-Complete-Drivers-Ed-Package" },
    { name: "Advanced", price: "$1499", lessons: "Twenty Seven (27)",lessonHours: 27, href: "https://myfirstdrive.net/Package/Advanced-Teen-Complete-Drivers-Ed-Package" },
    { name: "Gold",     price: "$1999", lessons: "Thirty Seven (37)",lessonHours: 37, href: "https://myfirstdrive.net/Package/Gold-Teen-Complete-Drivers-Ed-Package" }
  ];

  function mfdShowTeenPackageList() {
    var cards = mfdTeenCompletePackages.map(function (p) {
      var remaining = 37 - p.lessonHours;
      var remainingLine = remaining > 0
        ? '

  • ' + remaining + ' remaining hr' + (remaining === 1 ? '' : 's') + ' to be completed by parent/guardian

'
        : '

  • No additional hours needed \u2013 37-hr requirement fully met

';
      return '

' +
        (p.recommended ? 'Recommended' : '') +
        '

' + p.name + '

' +
        '

' + p.price + '

' +
        '
' +
          '

This package includes:

' +
          '
  • ' +

  •             '
  • 24-hr online permit class
  • ' +

  •             '
  • ' + p.lessons + ' 1-hr driving lessons & 7 observation hrs
  • ' +

  •             '
  • Onsite DPS road test at MYFIRSTDRIVE
  • ' +

  •             remainingLine +

  •           '
' +
        '
' +
        'View Package' +
      '

';
    }).join('');

    document.getElementById('mfdResultContent').innerHTML =
      '

Complete Teen Drivers Ed Packages

' +
      '

TDLR requirement: Texas requires teenagers to complete 37 hours of behind-the-wheel driving, of which a minimum of 7 hours must be completed with a driving school as part of an instructor-led course, before they are eligible to take the DPS road test.

' +
      cards;
    mfdGoTo('result');
  }

  // ── Teen Driving Lessons and Road Test (student already has permit) ──
  var mfdTeenLessonsPackages = [
    { name: "Core",     price: "$729",  lessons: "Thirteen (13)",    lessonHours: 13, href: "https://myfirstdrive.net/Package/Core-Teen-Driving-Lessons-Road-Test",     recommended: true },
    { name: "Min",      price: "$459",  lessons: "Seven (7)",        lessonHours: 7,  href: "https://myfirstdrive.net/Package/Min-Teen-Driving-Lessons-Road-Test" },
    { name: "Basic",    price: "$529",  lessons: "Nine (9)",         lessonHours: 9,  href: "https://myfirstdrive.net/Package/Basic-Teen-Driving-Lessons-Road-Test" },
    { name: "Advanced", price: "$1429", lessons: "Twenty Seven (27)",lessonHours: 27, href: "https://myfirstdrive.net/Package/Advanced-Teen-Driving-Lessons-Road-Test" },
    { name: "Gold",     price: "$1929", lessons: "Thirty Seven (37)",lessonHours: 37, href: "https://myfirstdrive.net/Package/Gold-Teen-Driving-Lessons-Road-Test" }
  ];

  function mfdShowTeenLessonsList() {
    var cards = mfdTeenLessonsPackages.map(function (p) {
      var remaining = 37 - p.lessonHours;
      var remainingLine = remaining > 0
        ? '

  • ' + remaining + ' remaining hr' + (remaining === 1 ? '' : 's') + ' to be completed by parent/guardian

'
        : '

  • No additional hours needed \u2013 37-hr requirement fully met

';
      return '

' +
        (p.recommended ? 'Recommended' : '') +
        '

' + p.name + '

' +
        '

' + p.price + '

' +
        '
' +
          '

This package includes:

' +
          '
  • ' +

  •             '
  • ' + p.lessons + ' 1-hr driving lessons & 7 observation hrs (if needed)
  • ' +

  •             '
  • Onsite DPS road test at MYFIRSTDRIVE
  • ' +

  •             remainingLine +

  •           '
' +
        '
' +
        'View Package' +
      '

';
    }).join('');

    document.getElementById('mfdResultContent').innerHTML =
      '

Teen Driving Lessons and Road Test Packages

' +
      '

TDLR requirement: Texas requires teenagers to complete 37 hours of behind-the-wheel driving, of which a minimum of 7 hours must be completed with a driving school as part of an instructor-led course, before they are eligible to take the DPS road test.

' +
      cards;
    mfdGoTo('result');
  }

  // ── Complete Adult Drivers Ed Packages (student needs online course) ──
  var mfdAdultCompletePackages = [
    { name: "Core",     price: "$799",  lessons: "Ten (10)",      href: "https://myfirstdrive.net/Package/Core-Adult-Complete-Drivers-Ed-Package",     recommended: true },
    { name: "Min",      price: "$599",  lessons: "Six (6)",       href: "https://myfirstdrive.net/Package/Min-Adult-Complete-Drivers-Ed-Package" },
    { name: "Basic",    price: "$699",  lessons: "Eight (8)",     href: "https://myfirstdrive.net/Package/Basic-Adult-Complete-Drivers-Ed-Package" },
    { name: "Advanced", price: "$1199", lessons: "Sixteen (16)",  href: "https://myfirstdrive.net/Package/Advanced-Adult-Complete-Drivers-Ed-Package" }
  ];

  function mfdShowAdultPackageList() {
    var cards = mfdAdultCompletePackages.map(function (p) {
      return '

' +
        (p.recommended ? 'Recommended' : '') +
        '

' + p.name + '

' +
        '

' + p.price + '

' +
        '
' +
          '

This package includes:

' +
          '
  • ' +

  •             '
  • 6-hr online permit class
  • ' +

  •             '
  • ' + p.lessons + ' 1-hr driving lessons
  • ' +

  •             '
  • Onsite DPS road test at MYFIRSTDRIVE
  • ' +

  •           '
' +
        '
' +
        'View Package' +
      '

';
    }).join('');

    document.getElementById('mfdResultContent').innerHTML =
      '

Complete Adult Drivers Ed Packages

' +
      '

Texas requirement: Adults ages 18\u201324 must complete a 6-hour state-approved drivers ed course before applying for a learner\'s permit and taking the DPS road test. Adults 25 and older are not required to take the course, though it is highly recommended.

' +
      cards;
    mfdGoTo('result');
  }

  // ── Adult Driving Lessons and Road Test (student already has permit) ──
  var mfdAdultLessonsPackages = [
    { name: "Core",     price: "$749",  lessons: "Ten (10)",      href: "https://myfirstdrive.net/Package/Core-Adult-Driving-Lessons-Road-Test",     recommended: true },
    { name: "Min",      price: "$549",  lessons: "Six (6)",       href: "https://myfirstdrive.net/Package/Min-Adult-Driving-Lessons-Road-Test" },
    { name: "Basic",    price: "$649",  lessons: "Eight (8)",     href: "https://myfirstdrive.net/Package/Basic-Adult-Driving-Lessons-Road-Test" },
    { name: "Advanced", price: "$1149", lessons: "Sixteen (16)",  href: "https://myfirstdrive.net/Package/Advanced-Adult-Driving-Lessons-Road-Test" }
  ];

  function mfdShowAdultLessonsList() {
    var cards = mfdAdultLessonsPackages.map(function (p) {
      return '

' +
        (p.recommended ? 'Recommended' : '') +
        '

' + p.name + '

' +
        '

' + p.price + '

' +
        '
' +
          '

This package includes:

' +
          '
  • ' +

  •             '
  • ' + p.lessons + ' 1-hr driving lessons
  • ' +

  •             '
  • Onsite DPS road test at MYFIRSTDRIVE
  • ' +

  •           '
' +
        '
' +
        'View Package' +
      '

';
    }).join('');

    document.getElementById('mfdResultContent').innerHTML =
      '

Adult Driving Lessons and Road Test Packages

' +
      '

Texas requirement: Adults ages 18\u201324 must complete a 6-hour state-approved drivers ed course before applying for a learner\'s permit and taking the DPS road test. Adults 25 and older are not required to take the course, though it is highly recommended.

' +
      cards;
    mfdGoTo('result');
  }

  document.addEventListener('keydown', function (e) {
    if (e.key === 'Escape') mfdCloseQuiz();
  });

  document.addEventListener('DOMContentLoaded', function () {
    var trigger = document.querySelector('.mfd-trigger-btn');
    if (trigger) trigger.addEventListener('click', function (e) { e.preventDefault(); mfdOpenQuiz(); });

    var modal = document.querySelector('.mfd-modal');
    if (!modal) return;

    var closeBtn = modal.querySelector('.mfd-close-btn');
    if (closeBtn) closeBtn.addEventListener('click', function (e) { e.preventDefault(); mfdCloseQuiz(); });

    var restartBtn = modal.querySelector('.mfd-restart-btn');
    if (restartBtn) restartBtn.addEventListener('click', function (e) { e.preventDefault(); mfdRestart(); });

    modal.querySelectorAll('.mfd-back-btn').forEach(function (btn) {
      var stepEl = btn.closest('[id^="mfdStep"]');
      if (!stepEl) return;
      var stepKey = stepEl.id === 'mfdStepResult' ? 'result' : parseInt(stepEl.id.replace('mfdStep', ''), 10);
      btn.addEventListener('click', function (e) { e.preventDefault(); mfdGoBack(stepKey); });
    });

    var step0 = document.getElementById('mfdStep0');
    if (step0) {
      var opts = step0.querySelectorAll('.mfd-opt');
      if (opts[0]) opts[0].addEventListener('click', function (e) { e.preventDefault(); mfdPick(0, 'teen'); });
      if (opts[1]) opts[1].addEventListener('click', function (e) { e.preventDefault(); mfdPick(0, 'adult'); });
    }
  });

  // Expose handlers used by inline onclick attributes
  window.mfdOpenQuiz  = mfdOpenQuiz;
  window.mfdCloseQuiz = mfdCloseQuiz;
  window.mfdBgClick   = mfdBgClick;
  window.mfdRestart   = mfdRestart;
  window.mfdGoBack    = mfdGoBack;
  window.mfdPick      = mfdPick;
})();

Back to Top