﻿$(document).ready(function() {

    initializeTextResizing();
    populateInsuranceDropDown();

    /*Accordion for Faqs page */
    $('.accordion').accordion({
        autoHeight: false,
        collapsible: true,
        active: false
    });

    // when the page is loaded..
    $(function() {
        // make the cursor over <li> element to be a pointer instead of default
        $(".snavContainer li").css('cursor', 'pointer')
        // iterate through all <li> elements with CSS class = "clickable"
        // and bind onclick event to each of them
        .click(function() {
            // when user clicks this <li> element, redirect it to the page
            // to where the fist child <a> element points
            window.location = $('a', this).attr('href');
        });
    });



   

    $("#ctl00_ctl00_header_main_main_sub_header_main_ddlDescribes").change(function() {

        // Hide all div content on page load
        document.getElementById("ph1").style.display = "none";
        document.getElementById("ph2").style.display = "none";
        document.getElementById("ph3").style.display = "none";
        document.getElementById("ph4").style.display = "none";
        document.getElementById("ph5").style.display = "none";
        document.getElementById("ph6").style.display = "none";
        document.getElementById("ph7").style.display = "none";
        document.getElementById("ph8").style.display = "none";
        document.getElementById("ph9").style.display = "none";
        document.getElementById("ph10").style.display = "none";
        document.getElementById("ph11").style.display = "none";
        document.getElementById("ph12").style.display = "none";
        document.getElementById("ph13").style.display = "none";
        document.getElementById("ph14").style.display = "none";

        var describesSelected = $("#ctl00_ctl00_header_main_main_sub_header_main_ddlDescribes option:selected").val();

        var insuranceNeedHelp = $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp option:selected").val();

        if (describesSelected == "patientCaregiver") {
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").removeAttr("disabled");

            //$("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").Attr("onchange", "alert('hello')");
            //describesSelected.Attributes.Add("onclick", "trackLink(this, '/flashtrack/VH/step1/patient', 'e');");
            //$("#ctl00_ctl00_header_main_main_sub_header_main_ddlDescribes").Attributes.Add("onchange", "alert('hello')");
        }

        else if (describesSelected == "BestDescribes") {
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").get(0).selectedIndex = 0;

            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").get(0).selectedIndex = 0;

            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").attr("disabled", "disabled");
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").attr("disabled", "disabled");

        }

        else if (describesSelected == "HealthcareProfessional") {

        tb_show("", "popup_hcp.aspx?page=hcp_default.aspx?KeepThis=true&TB_iframe=true&height=400&width=600", "");


            //$("#ctl00_ctl00_header_main_main_sub_header_main_ddlDescribes").attr("class", "thickbox");
            //$("#ctl00_ctl00_header_main_main_sub_header_main_ddlDescribes").attr("href", "popup/hcp.aspx?page=hcp_default.aspx?KeepThis=true&TB_iframe=true&height=400&width=600");
            //centering with css
            //centerPopup('HCP');
            //load popup
            //loadPopup('HCP', $(this).attr("href"));

            // if HCP, reset the other two dropdownlists to their default values and disable them.

            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").val('InsuranceStatus');
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").val('NeedHelp');

            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").attr("disabled", "disabled");
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").attr("disabled", "disabled");

            // move to top if IE6
            var IE6 = (navigator.userAgent.indexOf("MSIE 6") >= 0) ? true : false;
            if (IE6) {
                $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").hide();
                $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").hide();
                $("#ctl00_ctl00_header_main_main_sub_header_main_ddlDescribes").hide();
            }

            return false;
        }
    });

    // *End* from pageLoad

    // *Begin* Results Functions

    $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").change(function() {



        var insuranceSelected = $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance option:selected").val();

        if (insuranceSelected == "InsuranceStatus" || insuranceSelected == "NoInsurance" || insuranceSelected == "IDontKnow") {
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").get(0).selectedIndex = 0;
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").attr("disabled", "disabled");
        }

        else if (insuranceSelected == "Insured") {
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").get(0).selectedIndex = 0;
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").removeAttr("disabled");
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").html("");
            populateInsuranceDropDown();
            //$("option[value='PrescriptionProcess']").attr("display", "block");
            hide_content();
        }

        else if (insuranceSelected == "NotEnoughInsurance") {
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").get(0).selectedIndex = 0;
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").removeAttr("disabled");
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp option[value='PrescriptionProcess']").remove();
            $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp option[value='FindingPharmacy']").remove();
            hide_content();


        }

        return false;

    });



});


//Cookie functions
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

//Text resize functions

initializeTextResizing = function() {
    var textSize = readCookie("text-size");

    if (textSize == null) {
        setTextsize("med");
    }
    else {
        setTextsize(textSize);
    }
}

setTextsize = function(size) {
    var el = $("link[id$=textsize]");

    el.attr("href", "common/" + size + ".css");

    createCookie("text-size", size);
}


increaseTextsize = function() {
    var el = $("link[id$=textsize]");

    var currentSize = readCookie("text-size");

    if (currentSize === "large") {
        return;
    }

    switch (currentSize) {
        case "small":
            currentSize = "med";
            break;
        case "med":
            currentSize = "large";
            break;
    }

    setTextsize(currentSize);
}

decreaseTextsize = function() {
    var el = $("link[id$=textsize]");

    var currentSize = readCookie("text-size");

    if (currentSize === "small") {
        return;
    }

    switch (currentSize) {
        case "large":
            currentSize = "med";
            break;
        case "med":
            currentSize = "small";
            break;
    }

    setTextsize(currentSize);
}
                                  



//GLOSSARY
var offsetfrommouse = [20, -10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration = 0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 0; // maximum image size.

if (document.getElementById || document.all) {
    document.write('<div id="trailimageid">');
    document.write('</div>');
}

function gettrailobj() {
    if (document.getElementById)
        return document.getElementById("trailimageid").style
    else if (document.all)
        return document.all.trailimageid.style
}

function gettrailobjnostyle() {
    if (document.getElementById)
        return document.getElementById("trailimageid")
    else if (document.all)
        return document.all.trailimageid
}


function truebody() {
    return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function showGlossPop(id) {
    document.onmousemove = followmouse;
   // alert(id);
    gettrailobjnostyle().innerHTML = document.getElementById(id).innerHTML;
    gettrailobj().display = "block";
}
function hideGlossPop() {
    gettrailobj().display = "none";
    document.onmousemove = "";
    gettrailobj().left = "-500px";

}
function followmouse(e) {

    var xcoord = offsetfrommouse[0]
    var ycoord = offsetfrommouse[1]

    var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

    /*
    if (document.all){
    gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
    } else {
    gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
    }
    */

    if (typeof e != "undefined") {
        if (docwidth - e.pageX < 380) {
            xcoord = e.pageX - xcoord - 350; // Move to the left side of the cursor
        } else {
            xcoord += e.pageX;
        }
        if (docheight - e.pageY < (currentimageheight + 110)) {
            ycoord += e.pageY - Math.max(0, (110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
        } else {
            ycoord += e.pageY;
        }

    } else if (typeof window.event != "undefined") {
        if (docwidth - event.clientX < 400) {
            xcoord = event.clientX + truebody().scrollLeft - xcoord - 380; // Move to the left side of the cursor
        } else {
            xcoord += truebody().scrollLeft + event.clientX
        }
        if (docheight - event.clientY < (currentimageheight + 110)) {
            ycoord += event.clientY + truebody().scrollTop - Math.max(0, (110 + currentimageheight + event.clientY - docheight));
        } else {
            ycoord += truebody().scrollTop + event.clientY;
        }
    }

    docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    docheight = document.all ? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
    if (ycoord < 0) { ycoord = ycoord * -1; }
    gettrailobj().left = xcoord + "px"
    gettrailobj().top = ycoord + "px"

}
//END GLOSSARY

function hide_content() {
    // Hide all div content on page load
    document.getElementById("ph1").style.display = "none";
    document.getElementById("ph2").style.display = "none";
    document.getElementById("ph3").style.display = "none";
    document.getElementById("ph4").style.display = "none";
    document.getElementById("ph5").style.display = "none";
    document.getElementById("ph6").style.display = "none";
    document.getElementById("ph7").style.display = "none";
    document.getElementById("ph8").style.display = "none";
    document.getElementById("ph9").style.display = "none";
    document.getElementById("ph10").style.display = "none";
    document.getElementById("ph11").style.display = "none";
    document.getElementById("ph12").style.display = "none";
    document.getElementById("ph13").style.display = "none";
    document.getElementById("ph14").style.display = "none";
}

function populateInsuranceDropDown() {
    $("#ctl00_ctl00_header_main_main_sub_header_main_ddlNeedHelp").html("<option selected=\"selected\" value=\"NeedHelp\">&#160;What do you need help with?</option><option value=\"PaymentAssistance\">&#160;Payment Assistance</option><option value=\"MedicarePartD\">&#160;Medicare Part D</option><option value=\"VeteransBenefits\">&#160;Veterans Benefits</option><option value=\"PrescriptionProcess\">&#160;Prescription Process</option><option value=\"FindingPharmacy\">&#160;Finding a Pharmacy</option><option value=\"Forms\">&#160;Forms</option><option value=\"IDontKnow_a\">&#160;I Don’t Know</option>");
}

// Code below for tracking on Results.aspx header drop down list. Also See results.aspx.cs for other code.
function handleTrackLink(object) {

    var option = object.value;

    var insurance = $("#ctl00_ctl00_header_main_main_sub_header_main_ddlInsurance").val();

    if (option == "NoInsurance") {
        hide_content();
        document.getElementById("ph13").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/No_Insurance', 'o');
        }
        else if (option == "IDontKnow") {
        hide_content();
        document.getElementById("ph14").style.display = "block";
        trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Dont_Know', 'o');
    }
    else if (option == "HealthcareProfessional") {    
 
    trackLink(option, '/flashtrack/VH/step4/HCP', 'o');
    
    
        
    }

    else if (insurance == "Insured") {
    if (option == "PaymentAssistance") {
        hide_content();
            document.getElementById("ph1").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Insured/Payment_Assistance', 'o');
        }
        else if (option == "MedicarePartD") {
        hide_content();
            document.getElementById("ph2").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Insured/Medicare_Part_D', 'o');
        }
        else if (option == "VeteransBenefits") {
        hide_content();
        document.getElementById("ph3").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Insured/Veterans_Benefits', 'o');
        }
        else if (option == "PrescriptionProcess") {
        hide_content();
        document.getElementById("ph4").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Insured/Prescription_Process', 'o');
        }
        else if (option == "FindingPharmacy") {
        hide_content();
        document.getElementById("ph5").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Insured/Finding_a_Pharmacy', 'o');
        }
        else if (option == "Forms") {
        hide_content();
        document.getElementById("ph6").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Insured/Forms', 'o');
        }
        else if (option == "IDontKnow_a") {
        hide_content();
        document.getElementById("ph7").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Insured/Dont_Know', 'o');
        }
    }

    else if (insurance == "NotEnoughInsurance") {
    if (option == "PaymentAssistance") {
        hide_content();
        document.getElementById("ph8").style.display = "block";
            trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Not_Enough_Insurance/Payment_Assistance', 'o');
        }
        else if (option == "MedicarePartD") {
        hide_content();
        document.getElementById("ph9").style.display = "block";
        trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Not_Enough_Insurance/Medicare_Part_D', 'o');
        }
        else if (option == "VeteransBenefits") {
        hide_content();
        document.getElementById("ph10").style.display = "block";
        trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Not_Enough_Insurance/Veterans_Benefits', 'o');
        }
        else if (option == "Forms") {
        hide_content();
        document.getElementById("ph11").style.display = "block";
        trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Not_Enough_Insurance/Forms', 'o');
        }
        else if (option == "IDontKnow_a") {
        hide_content();
        document.getElementById("ph12").style.display = "block";
        trackLink(option, '/flashtrack/VH/step4/pat_caregiver/Not_Enough_Insurance/Dont_Know', 'o');
        }

    }  
    
}





