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) {
	document.body.style.cursor = 'wait';
    
    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;
    }
	
	//ADD VIDEO LINKS
	/* for (i in glossary_vids) {
		jQuery('#'+i).append(' <img src="/images/video_play_button.gif" />');
		jQuery('#'+i).addClass('glossary_video_link');
	}
	jQuery('.glossary_video_link').click(function() {
		jQuery('#video_modal_content').modal({overlayId: 'vidhelp_modaloverlay'});
		jQuery('#video_modal_content img, #vidhelp_modaloverlay').click(function() {
			jQuery.modal.close();
			jQuery('#vidhelp_modaloverlay').remove();
		});
		var thisvidname = glossary_vids[this.id];
		jwplayer("video_container").setup({
			"flashplayer": "/player/jwplayer-5.7.swf",
			"width": "640",
			"height": "360",
			"file": "/videos/"+thisvidname+".mp4",
			//"image": "/images/"+thisvidname+"_pre.jpg",
			//"image": "/images/video_buffer_anim.gif",
			//"skin": "/player/player-skin/player-skin.xml",
			"autostart": "true",
			"stretching": "uniform",
			"volume": "100",
			"icons": "true"
		});
	}); */
	
	document.body.style.cursor = 'default';
}

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 Election Period (AEP)" : "October 15 through December 7, 2011.  Benefits for the new year begin on January 1, 2012.",
    "Balance Billing" : "Billing patients to make up the difference between the doctor's or hospital's usual fee and the amount they are paid by the health plan. Doctors and hospitals contracted with Aetna are not permitted to balance bill members.<br><br>If you receive a balance bill from for service provided by an out-of-network provider, please contact Member Services. You are only responsible for paying the plan's cost sharing amount for a covered service.",
    "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.",
	"Brand Name Drug" : "A prescription drug that has a trade name and is protected by a patent (the drug can be produced and sold only by the company holding the patent).",
	"Catastrophic Coverage" : "The phase of a Medicare Part D plan where you pay only a small coinsurance or copay for a covered prescription drug and your plan pays the rest of the cost for the remainder of the year. Catastrophic coverage begins when you have spent $4,550 in total out-of-pocket costs for covered drugs in 2011.",
    "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.",
	"Cost-Sharing" : "A term for the costs that members are accountable to pay. The most common types of cost-sharing are deductibles, copays and coinsurance.",
    "Coverage Gap" : "Commonly referred to as the “donut hole”. The coverage gap occurs after your total covered prescription drug costs reach $2,840 in 2011 and continues until the total you pay out of your pocket for covered Part D prescription drugs reaches $4,550. This amount includes your annual deductible and copayments or coinsurance for covered prescription drugs (excluding premium). Once you reach $4,550 in total out-of-pocket spending, you'll enter the next phase called <a href=\"#catastrophic_coverage\">catastrophic coverage</a>.",
    "Creditable Coverage" : "Prescription drug coverage from a plan which meets certain Medicare standards and is not a standalone PDP or MAPD plan. If you are enrolled in a plan that gives you prescription drug coverage, your plan will tell you if it meets the requirements for creditable prescription drug coverage. OR<br><br>Medical health coverage that you had in the past that was not interrupted by a significant break in coverage. It gives you certain rights when you apply for new coverage. You may need to provide proof of your creditable coverage in the form of a document or health insurance ID card.",
    "Deductible" : "The first phase of a Medicare Part D prescription drug plan. It requires you to pay your prescription drug costs in full before reaching the initial coverage phase. Some plans may offer a $0 deductible. OR<br><br>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.",
    "Election 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 drug that is not protected by a patent and may be produced by any manufacturer. A generic name is a common name that refers to a drug's chemical identity, as opposed to a brand name used by a particular company for marketing purposes. 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 Original Medicare and many Medicare supplement plans.",
	"Initial Coverage Phase" : "Begins once a member has met the deductible phase and continues until the member reaches the <a href=\"#coverage_gap\">coverage gap</a>. This phase includes covered prescription drug costs paid by all parties to the plan (such as Part D carrier, member, Extra Help, etc.). During this phase, the member is responsible for copays and/or coinsurance up to $2,840 in total drug costs in 2011. After reaching $2,840 in total drug costs, the member moves to the next phase in the plan known as the coverage gap.<br><br> The point at which the member moves from the initial coverage phase to the coverage gap phase is often referred to as the initial coverage limit (ICL).",
    "Initial Election 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.",
	"In Network" : "This means we have a contract with that doctor or other health care provider. We negotiate discounted rates with them to help you save money. As a result, you can save more money by using doctors, other health care providers, and pharmacies that are in network.<br><br> There are other benefits to using doctors in network. They won't bill you for the difference between their standard rates and the rate they've agreed to with us. All you have to pay is your coinsurance or copay, along with any deductible. And network doctors will handle any precertification your plan requires.",
    "MA Plan" : "A Medicare Advantage plan has the same or even more benefits than the Original Medicare Plan. When you use network doctors and hospitals you can take advantage of easy-to-budget copay and insurance amounts.  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>.",
	"Medicaid" : "A jointly funded federal and state government program managed by the states that provides financial assistance to individuals and families with low incomes and few resources.  Medicaid can help eligible beneficiaries pay Medicare premiums and cost-sharing.",
    "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 if they reside in the service area of the plan, except those who have End-Stage Renal Disease (unless certain CMS exceptions apply). For example, if you have End-Stage Renal Disease and are already enrolled in an Aetna Medicare Advantage plan, you can choose to enroll in another Aetna Medicare Advantage plan if:<br><br>The new Aetna Medicare Advantage plan operates in the same state as the previous Aetna Medicare Advantage plan, and<br><br>You meet all the other requirements for enrollment in that Aetna Medicare Advantage plan.<br><br>  Medicare Advantage Plans are sometimes referred to as \"Medicare Part C\".<br><br> Beneficiaries with ESRD may enroll in a group Aetna Medicare Advantage plan.",
    "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 Original Medicare managed by the federal government. It helps cover 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 Original Medicare managed by the federal government. This helps cover 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 companies (with a Medicare approved contract) known as Medicare Advantage plans. A Medicare Advantage Plan covers the same benefits as Original Medicare and typically includes additional benefits not covered by Original Medicare. When you use network doctors and hospitals you can take advantage of easy-to-budget copay and coinsurance amounts. You can choose a Medicare Advantage plan that includes Medicare prescription drug coverage (MA-PD) or one that does not (MA).",
    "Medicare Part D" : "The name sometimes used to describe the optional Medicare prescription drug coverage that helps with your prescription drug 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 private companies like Aetna to help pay for select benefits not covered by Original Medicare (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 Pharmacy" : "A licensed pharmacy that is under contract with a Part D sponsor to provide covered Part D prescription drugs at negotiated prices to its Part D plan enrollees.",
    "Network Provider" : "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.",
	"Out-of-Network Doctor" : "A doctor with whom we do not have a contract. If your plan allows you to receive covered services from a doctor or other health care provider who is out of network, your cost sharing may be higher.",
	"Out-of-Network Pharmacy" : "A pharmacy with whom we do not have a contract. Most drugs you get from out-of-network pharmacies are not covered by our plan unless certain conditions apply.<br><br> Please <a href=\"/plan_choices/rx_filling_prescriptions.jsp?tab=4\">refer to the Out-of-Network Pharmacies section</a> or the <a href=\"/help_and_resources/downloadable_forms.jsp?tab=5\">Evidence of Coverage</a> for more information.",
    "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 may 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 Original Medicare and many Medicare supplement plans. PPOs also allow you to use any doctor or hospital outside of the network and generally have 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.  See \"<a href=\"#prior_authorization_for_medical_coverage\">Prior Authorization</a>.\"",
//    "Precertification (for medical coverage)" : "Some medical services are covered only if your doctor or other network provider gets approval in advance (sometimes called “prior authorization”) from Aetna. Covered services that need approval in advance are marked by an asterisk in the <a href=\"/help_and_resources/downloadable_forms.jsp?tab=5\">Evidence of Coverage “Medical Benefits Chart.”</a>",
	"Premium" : "A fixed monthly amount a beneficiary pays to participate in a medical or prescription drug plan.",
    "Prescription Drug Plan (PDP)" : "Standalone Medicare prescription drug plans offered by private entities and approved by the federal government that provide insurance protection for the costs of prescription medications.",
	"Prior Authorization (for medical coverage)" : "Prior authorization applies to certain medical services covered under your medical plan. Your physician must obtain approval from Aetna prior to you receiving the service. Without this approval, Aetna may not provide coverage or pay for the service. Covered services that require prior authorization are marked by an asterisk in the <a href=\"/help_and_resources/downloadable_forms.jsp?tab=5\">Evidence of Coverage</a> \"Medical Benefits Chart.\"",
	"Prior Authorization (for prescription drug coverage)" : "Process under which certain drugs require prior approval before members can obtain them as a covered benefit. The prior authorization program is based upon current medical findings, manufacturer labeling information, and Food and Drug Administration guidelines. Prior authorization 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. Your doctor or other network provider should call Aetna and request coverage for medications that require prior authorization.",
    "Private Fee-for-Service (PFFS)" : "A Medicare Advantage Plan that provides you with those services covered by Original Medicare and more. These plans are offered by private insurance companies 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.",
	"Quantity Limits (QL)" : "Assigned to medications that are frequently taken in an inappropriate manner or used in amounts that exceed recommendations for dosage or length of treatment. Limits are based on Federal Medication Administration (FDA) and pharmaceutical manufacturer recommendations.",
    "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 election period that allows a Medicare beneficiary to make a plan change or selection outside of the typical yearly election periods. Individuals qualify for SEPs when a special circumstance occurs, 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.",
    "Step Therapy" : "The practice of starting prescription drug therapy for a medical condition with the most cost-effective and safest drug therapy, then progressing to other more costly or risky therapy, only if necessary. The goal is to control costs and minimize risks. Also called step protocol.",
	"Tier" : "Formulary tiers are the organization of prescription drugs into different groups of drug types. A member's coinsurance or copayment depends on which tier a drug is in.",
	"True Out-of-Pocket (TrOOP)" : "The Medicare-defined amount of out-of-pocket cost before moving into the catastrophic phase of the plan. Once that amount is reached, your prescription cost sharing will change to the catastrophic coverage phase. This amount can change from year to year.<br><br> In 2011 your true out-of-pocket costs must reach $4,550 before you enter the catastrophic phase.<br><br> TrOOP expenses include your yearly prescription drug deductible, copayments or coinsurance for covered prescription drugs, and what you pay during the coverage gap. Your Medicare prescription drug plan premium and costs for prescription drugs that aren’t covered by the plan do not count toward this limit."
};

var glossary_vids = {
	"annual_election_period": "AnnualElectionPeriod",
	"brand_name_drug": "Brand-Name",
	"catastrophic_coverage": "CatastrophicCoverage",
	"coinsurance": "Coinsurance",
	"coverage_gap": "CoverageGap",
	"deductible": "Deductible",
	"formulary": "Formulary",
	"generic_drug": "GenericDrugs",
	"hmo": "HealthMaintenanceOrganiza",
	"in_network": "In-Network",
	"initial_coverage_phase": "InitialCoverageLimitandIC",
	//"": "LowIncomeSubsidyorLIS",
	//"": "MedicareAdvantageDisenrol",
	"medicare_part_a": "MedicarePartA",
	"medicare_part_b": "MedicarePartB",
	"medicare_part_c": "MedicarePartC",
	"medicare_part_d": "MedicarePartD",
	"medicare_supplement_plan": "MedicareSupplementPlan",
	"out_of_network_doctor": "Out-of-NetworkProviders",
	"out_of_network_pharmacy": "Out-of-NetworkProviders",
	//"": "OutOfPocketMaximum",
	//"": "PreferredDrug",
	"ppo": "PreferredProviderOrganiza",
	"prior_authorization_for_medical_coverage_": "PriorAuthorizationforMedi",
	"prior_authorization_for_prescription_drug_coverage_": "PriorAuthorizationforPres",
	"quantity_limits": "Quantitylimits",
	//"": "SpecialtyCoinsurance",
	"step_therapy": "StepTherapy",
	"tier": "Tiers",
	"true_out_of_pocket": "TrOOP-Trueout-of-pocketco"
};
