var imageExpand = new Image();
imageExpand.src = "/~/media/OptumHealth/Site_Shell/Icons/green_arrow.gif";

var imageCollapse = new Image();
imageCollapse.src = "/~/media/OptumHealth/Site_Shell/Icons/green_arrow_down.gif";

var curimgSection = null;
var curulSection = null;
var curimgSubSection = null;
var curulSubSection = null;
var curIdx = null;
var cursubIdx = null;

function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\\\s)' + searchClass + '(\\\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function expandcollapseSection(i) {
    var objimgSection = document.getElementById("img_Section" + i);
    var objulSection = document.getElementById("ul_Section" + i);
    var collapse = false;

    if (curimgSection != null) {
        if (curimgSection != objimgSection) {
            curimgSection.src = "/~/media/OptumHealth/Site_Shell/Icons/green_arrow.gif";
            curulSection.style.display = "none";
        }
    }

    if (objimgSection.src.indexOf("green_arrow.gif") != -1) {
        objimgSection.src = "/~/media/OptumHealth/Site_Shell/Icons/green_arrow_down.gif";
        objulSection.style.display = "block";
    }
    else {
        objimgSection.src = "/~/media/OptumHealth/Site_Shell/Icons/green_arrow.gif";
        objulSection.style.display = "none";
        collapse = true;
    }

    curimgSection = objimgSection;
    curulSection = objulSection;
    curIdx = i;
    if (collapse) {
        if (curimgSubSection != null && curulSubSection != null) {
            curimgSubSection.src = "/~/media/OptumHealth/Site_Shell/Icons/gr_arrow_right.gif";
            curulSubSection.style.display = "none";
        }
    }
    else
        expandcollapseSubSection(null, 0);
}

function expandcollapseSubSection(obj, idx) {
    var s = curimgSection.id.toString();
    var key = "Sub" + s.split("_")[1];

    if (obj != null) {
        if (obj == curimgSubSection) {
            if (curimgSubSection.src.indexOf("gr_arrow_right") != -1) {
                curimgSubSection.src = "/~/media/OptumHealth/Site_Shell/Icons/gr_arrow_down.gif";
                curulSubSection.style.display = "block";
            }
            else {
                curimgSubSection.src = "/~/media/OptumHealth/Site_Shell/Icons/gr_arrow_right.gif";
                curulSubSection.style.display = "none";
            }
        }
        else {
            var curImage = new Image();
            curImage = obj;
            var curul = document.getElementById("ul_" + key + idx);

            if (curImage != null && curul != null) {
                //hide cursub...
                if (curimgSubSection != null & curulSubSection != null) {
                    curimgSubSection.src = "/~/media/OptumHealth/Site_Shell/Icons/gr_arrow_right.gif";
                    curulSubSection.style.display = "none";
                }

                curImage.src = "/~/media/OptumHealth/Site_Shell/Icons/gr_arrow_down.gif";
                curul.style.display = "block";

                curimgSubSection = curImage;
                curulSubSection = curul;
            }
        }
    }
    else {
        if (curIdx != null) {
            var curImage = new Image();

            curImage = document.getElementById("img_" + key + idx);
            var curul = document.getElementById("ul_" + key + idx);

            if (curImage != null && curul != null) {
                curImage.src = "/~/media/OptumHealth/Site_Shell/Icons/gr_arrow_down.gif";
                curul.style.display = "block";

                curimgSubSection = curImage;
                curulSubSection = curul;
            }
        }
    }
    cursubIdx = idx;
}

