function lookup_word(event, elem, override) {

    var word = elem.innerHTML;
    if(override != null) {
        word = override;
    }
    var gloss = document.getElementById('definition');
    var gtitle = document.getElementById('def_title');
    var gcon = document.getElementById('def_cont');
    var def = null;
    for (var term in glossary) {
        if(word.toLowerCase() == term.toLowerCase()) {
            def = glossary[term];
            break;
        }
    }
    if(def == null) {
        def = "I'm sorry, we have no definition for that term.";
    } else {
        if(def.length > 150) {
            var reg = /\s+/gi;
            var word_id = idify_word(word);
            def = def.substring(0, 150) + "... <a href=\"/help_and_resources/glossary.jsp#" + word_id + "\">More</a>";
        }
    }
    
    var y = 0;
    var x = 0;
    
    if(event.pageX || event.pageY) {
        x = event.pageX;
        y = event.pageY;
    } else {
        if(document.documentElement) {
            x = event.clientX + document.documentElement.scrollLeft;
            y = event.clientY + document.documentElement.scrollTop;
        } else if(document.body) {
            x = this.clientX + document.body.scrollLeft;
            y = this.clientY + document.body.scrollTop;
        }
    }
    
    gloss.style.top = y + 'px';
    gloss.style.left = (x - 100) + 'px';
    gtitle.innerHTML = word;
    gcon.innerHTML = def;

    if(gloss.style.display == 'none') {
        showhide('definition');
    }
}

function populate_glossary(el) {
    
    var element = document.getElementById(el);
    
    var letters = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
        "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
        "Y", "Z"
    );
    
    var letter_terms = new Array();
    for(var term in glossary) {
        var first = term.substring(0, 1).toUpperCase();
        if(!letter_terms[first]) {
            letter_terms[first] = new Array();
        }
        letter_terms[first].push(term);
    }

    var gloss = "";
    // for(var letter in letters) {
    for(var j = 0; j < letters.length; j++) {
        gloss += "<h2 id=\"gloss_" + letters[j].toLowerCase() + "\">" + letters[j] + "</h2>\n";
        if(letter_terms[letters[j]]) {
            for(var k = 0; k < letter_terms[letters[j]].length; k++) {
            // for (var term in letter_terms[letters[j]]) {
                var word = letter_terms[letters[j]][k];
                var word_id = idify_word(word);
                gloss += "<h3 id=\"" + word_id + "\">" + word + "</h3><br>\n"
                gloss += "<div>" + glossary[word] + "</div><br>\n";
            }
        } else {
            gloss += "<p>There are no entries for this letter.<p>\n";
        }
        gloss += "<p><a href=\"#top\">Back To Top</a></p>\n";
    }
    element.innerHTML = gloss;

    var anchor_reg = /(#\S+)$/;
    var match = anchor_reg.exec(window.location);
    if(match != null) {
        window.location = window.location;
    }
}

function idify_word(word) {
    var reg = /\s+/gi;
    var letter_reg = /[^a-zA-Z0-9]/g;
    var acro_reg = /\(\S+\)/gi;
    var trail_reg = /\s+$/;
    var dupe_reg = /_+/g;
    
    return word.replace(acro_reg, '').replace(trail_reg, '').replace(letter_reg, '_').replace(reg, '_').replace(dupe_reg, '_').toLowerCase();
}

var glossary = {
    "Annual Coordinated Election Period (AEP)" : "November 15 through December 31 of every year. Benefits for the new year begin on January 1.",
    "Balance Billing" : "For Private Fee-For-Service members who receive services from a provider that accepts our terms and conditions, but do not accept Medicare assignment, the provider may charge you the difference between the Medicare allowable amount and the <a href=\"#medicare_limiting_charge\">Medicare limiting charge</a>. Providers accepting assignment are not permitted to balance bill over the Medicare allowable charge.",
    "Beneficiary" : "A person who has health care insurance through the Medicare or Medicaid program.",
    "Benefit Period" : "A benefit period begins the first day you stay in a hospital or skilled nursing facility and ends when you have been out of the hospital or skilled nursing facility for 60 days in a row. If you go into the facility after one benefit period has ended, a new benefit period begins. There is no limit to the number of benefit periods you can have.",
    "Centers for Medicare and Medicaid Services (CMS)" : "The federal agency that runs the Medicare program. In addition, CMS works with the states to run the Medicaid program.",
    "Coinsurance" : "The percent of the Medicare-approved amount that you pay for a covered medical service. With some plans, you do not pay coinsurance until you have first paid a deductible.",
    "Copay" : "Typically, an amount you pay that may be a specific dollar amount or a percentage of the total cost for a service or product. Copays are also used for some hospital outpatient services in the Original Medicare Plan. In prescription drug plans, it is the amount you pay for covered medications.",
    "Coverage Gap" : "Commonly referred to as the &#8220;donut hole&#8221; with a PDP or an MA-PD. Amount you pay for Medicare prescription drug coverage, after the initial coverage limit and until the total you pay out of your pocket for covered Part D prescription drugs reaches a certain amount (for 2009 the amount is $4,350; for 2010 the amount is $4,550).",
    "Creditable Coverage" : "Prescription drug coverage purchased by an employer, former employer or union through an insurer for employees/retirees or prescription drug coverage through the Veterans Administration. It consists of a benefit plan at least as good as the standard Medicare Prescription Drug Plan as defined by CMS.",
    "Deductible" : "The amount you must pay for health care before Medicare or the plan begins to pay. These amounts can change every year.",
    "Donut Hole" : "See \"<a href=\"#coverage_gap\">Coverage Gap</a>.\"",
    "Dual Eligibles" : "Individuals eligible for both the Medicare program and their state's Medicaid program. Medicaid is also sometimes called Medical Assistance.",
    "Drug Tiers" : "Cost-sharing categories for different types of medications: for example, generic, brand-name and specialty drugs.",
    "Durable Medical Equipment (DME)" : "Medical equipment that is ordered by a doctor for use in the home. These items must be reusable, such as walkers, wheelchairs or hospital beds. DME is paid for under both Medicare Part B and Part A for home health services.",
    "Enrollment Period" : "A certain period of time when you can join a Medicare health plan if it is open and accepting new Medicare members. If a health plan chooses to be open, it must allow all eligible people with Medicare to join.",
    "Formulary" : "Listing of prescription medications which are approved for use and/or coverage by the plan.",
    "Generic Drug" : "A prescription drug that has the same active-ingredient formulas as the brand-name drug. Generic drugs usually cost less than brand-name drugs and are rated by the Food and Drug Administration (FDA) to be as safe and effective as brand-name drugs.",
    "HMO" : "A Health Maintenance Organization that is contracted with CMS and provides access to a network of doctors and hospitals that coordinate your care. This allows you to get more benefits than the Original Medicare Plan and many Medicare supplement plans.",
    "Initial Coverage Limit" : "Point at which the benefit plan may change under a Medicare Prescription Drug plan. This occurs when covered Medicare Prescription Drug expenses paid by both the member and the plan reach a defined amount. The member is generally responsible for a deductible and/or cost sharing, consisting of either a copay or coinsurance up to this point. Once this point is reached, the plan moves to the coverage gap phase.<br><ul class=\"text\"><li>For 2009 the defined amount is usually $2,700.</li><li>For 2010 the defined amount is usually $2,830.</li></ul>",
    "Initial Enrollment Period (IEP)" : "The seven-month period surrounding your Medicare eligibility that includes three months before, the month of, and three months after the event that qualifies you for Medicare.",
    "MA Plan" : "A Medicare Advantage plan that covers the same or better benefits as the Original Medicare Plan with easy-to-budget copay and coinsurance amounts when you use network doctors and hospitals. See <a href=\"#medicare_advantage_plan\">Medicare Advantage Plan</a> or <a href=\"#medicare_part_c\">Medicare Part C</a>.",
    "MA-PD Plan" : "A Medicare Advantage plan that includes Medicare prescription drug coverage. See <a href=\"#medicare_advantage_plan\">Medicare Advantage Plan</a> or <a href=\"#medicare_part_c\">Medicare Part C</a>.",
    "Medicare" : "The federal health insurance program for people 65 years of age or older, certain people with disabilities, and people with end-stage renal disease (permanent kidney failure with dialysis or a transplant, sometimes called ESRD).",
    "Medicare Advantage Plan" : "A Medicare program that gives you more choices among health plans. Everyone who has Medicare Parts A and B is eligible, except those who have End-Stage Renal Disease (unless certain exceptions apply). Medicare Advantage Plans are sometimes referred to as \"Medicare Part C\".",
    "Medicare Limiting Charge" : "This applies to providers who do not accept Medicare assignment. Typically there is a limit on the amount over the Medicare-allowable charge your doctors and providers can bill you. The most you can be charged for a Medicare covered service by doctors and other providers who don't accept assignment is called the limiting charge. The limiting charge is 15% over Medicare's approved amount.",
    "Medicare Modernization Act" : "The legislation passed by Congress and signed by President George W. Bush creating the Medicare Part D prescription drug benefit. This law preserves and strengthens the current Medicare program and adds important preventive benefits. It also adds a prescription drug benefit (Medicare Part D) that Medicare beneficiaries may purchase from a private insurer. In addition, the legislation provides extra help to people with low incomes.",
    "Medicare Part A" : "Part of the Original Medicare Plan managed by the federal government. Covers some, but not all, of the expenses you incur for inpatient hospital care or medical care that you may receive at a skilled nursing facility (not a custodial care facility). Some hospice care and some home health care are also covered. Limitations apply, and you will have deductibles, copays, or other costs to satisfy.",
    "Medicare Part B" : "Part of the Original Medicare Plan managed by the federal government. This covers medically necessary services from doctors or outpatient hospital care. It also helps with costs associated with some physical and occupational therapist services and some home health care services. You typically must sign up for Part B and pay a monthly premium in order to benefit from that coverage.",
    "Medicare Part C" : "This part of Medicare includes medical and other benefits provided through private health benefits companies (approved by the federal government) known as Medicare Advantage plans. Plans cover the same or better benefits as the Original Medicare plan with easy-to-budget copay and coinsurance amounts when you use network doctors and hospitals. You can choose a Medicare Advantage plan that includes Medicare prescription drug coverage (MA-PD) or one that does not (MA). Both MA and MA-PD plans are available as an HMO, a PPO, or a PFFS.",
    "Medicare Part D" : "The name sometimes used to describe the optional Medicare prescription drug coverage that helps with your prescription costs. This coverage is available as a stand-alone Medicare Prescription Drug plan (PDP) or as part of a Medicare Advantage plan (MA-PD).",
    "Medicare Prescription Drug Plan" : "Optional Medicare prescription drug coverage that helps with your prescription costs only. See <a href=\"#medicare_part_d\">Medicare Part D</a>.",
    "Medicare Supplement Plan" : "Insurance policy offered by companies like Aetna to help pay for select benefits not covered by the Original Medicare Plan (Parts A and B). <b>New Medicare supplement policies have not covered prescription drugs since 2006.</b>",
    "Medigap" : "See <a href=\"#medicare_supplement_plan\">Medicare Supplement Plan</a>.",
    "Monthly Plan Premium" : "The payment you make to a health benefits company like Aetna for your health plan.",
    "Network" : "A group of doctors, hospitals and other health care providers who are contracted with a health benefits company like Aetna to offer you quality health care for low, easy-to-budget copays.",
    "PCP" : "A primary care physician (PCP) you choose from a plan network to provide your routine and preventive care. Traditional HMO plans require you to select a PCP, while Open Access HMO plans and PPO plans don't. However, if you select a PCP with your PPO plan, you'll have a lower copay for office visits.",
    "PDP" : "Another name for standalone Medicare prescription drug plans. See <a href=\"#medicare_part_d\">Medicare Part D</a>.",
    "PPO" : "A Preferred Provider Organization that provides access to a network of doctors and hospitals that coordinate your care. This allows you to get more benefits than the Original Medicare Plan and many Medicare supplement plans. PPOs also allow you to use any doctor or hospital outside of the network for a higher copay or coinsurance.",
    "Precertification (for prescription drug coverage)" : "Process under which certain drugs require prior authorization (prior approval) before members can obtain them as a covered benefit. The precertification program is based upon current medical findings, manufacturer labeling information, and Food and Drug Administration guidelines. The precertification requirement applies to medications that are more likely than others to be taken incorrectly, used inappropriately, or taken in amounts that exceed recommendations for dosage or length of treatment. Physicians must call the Pharmacy Management Precertification Unit and request coverage for medications on the Precertification List.",
    "Prescription Drug Plan (PDP)" : "Standalone Medicare prescription drug plans offered by private entities and approved by the federal government that provides insurance protection for the costs of prescription medications.",
    "Private Fee-for-Service (PFFS)" : "A Medicare Advantage Plan that provides you with those services covered by the Original Medicare plan and more. These plans are offered by private insurance companies, like Aetna, through a contract with the federal government and include a plan premium for medical coverage. Under a PFFS plan, you should choose a health care provider who is eligible to receive payment from Medicare, agrees to treat you, and accepts the Medicare Advantage PFFS Terms and Conditions of payment. The Aetna Medicare Open Plan is a Medicare Advantage Private Fee-for-Service plan.",
    "Rx" : "A commonly used symbol for prescriptions.",
    "Skilled Nursing Facility" : "A facility that provides inpatient skilled nursing care, rehabilitation services or other related health services. \"Skilled nursing\" does not include a convalescent home or custodial care.",
    "Special election period (SEP)" : "An enrollment period that allows a Medicare beneficiary to make a plan change or selection outside of the typical yearly enrollment periods. Individuals qualify for SEPs when special circumstance occurs, such as such as moving out of your plan's service area or becoming eligible for Medicaid.",
    "Special needs plan (SNP)" : "A Medicare Advantage HMO or PPO plan that is designed to meet the needs of a subset of Medicare beneficiaries. There are three types of SNPs: dual eligible (with both Medicare and state Medicaid), institutional (for people residing in a long-term care facility) and chronic and disabling condition. Aetna has dual eligible SNPs for 2009 and 2010.",
    "Step-therapy" : "A type of precertification under which certain medications will be excluded from coverage unless members try one or more prerequisite drug(s) first, or unless a medical exception is obtained.",
	"Tier" : "Formulary tiers are the organization of prescription drugs into different groups of drug types. A member's coinsurance or co-payment depends on which tier a drug is in."
};