﻿

var lastAnswer = null;

function TogglePanel(index, arrow)
{
    var divPanelContainer = GetObject('divPanelContainer');
    var panel_items = divPanelContainer.getElementsByTagName('div');
    
    var arrow_img_set = new Array();
    arrow_img_set[0] = '../images/clinicalstudies/arrow_rt.jpg';
    arrow_img_set[1] = '../images/clinicalstudies/arrow_dwn2.jpg';
    arrow_img_set[2] = '../images/whysonicare/blue_arrow_rt3.jpg';
    arrow_img_set[3] = '../images/whysonicare/blue_arrow_down4.jpg';
    
    var cntr = 0;

    if (parseInt(panel_items.length) > 0)
    {
        for (var i = 0; i < parseInt(panel_items.length); i++)
        {
            if (panel_items[i].className.toLowerCase().indexOf('panel_title') != -1)
            {
                var arrow_img = panel_items[i].getElementsByTagName('img')[0];
                var p = panel_items[i].getElementsByTagName('p')[0];
                var a = panel_items[i].getElementsByTagName('a')[0];
                var smallQuote = panel_items[i].getElementsByTagName('div')[0];
            }
            
            if (panel_items[i].className.toLowerCase().indexOf('panel_list') != -1)
            {
                if (cntr == index)
                {
                    if (panel_items[i].className.toLowerCase().indexOf('hide') != -1)
                    {
                        panel_items[i].className = 'panel_list show';
                        
                        arrow_img.src = arrow_img_set[arrow+1];
                        arrow_img.alt = 'Collapse';
                        arrow_img.title = 'Collapse';
                        
                        if (p)
                        {
                            p.innerHTML = 'click to collapse';
                            p.title = 'click to collapse';
                        }
                        
                        a.title = 'click to collapse';
                        
                        if (smallQuote)
                        	smallQuote.className = smallQuote.className.replace("show", "hide");
                        

                        if (lastAnswer != null)
							lastAnswer.className = lastAnswer.className.replace('show', 'hide');
                    }
                    else
                    {
                        panel_items[i].className = 'panel_list hide';
                        
                        arrow_img.src = arrow_img_set[arrow];
                        arrow_img.alt = 'Expand';
                        arrow_img.title = 'Expand';
                        
                        if (p)
                        {
                            p.innerHTML = 'click to expand';
                            p.title = 'click to expand';
                        }
                        
                        a.title = 'click to expand';
                        
                        if (smallQuote)
                            smallQuote.className = smallQuote.className.replace("hide", "show");
                    }
                }
                else
                {
                    // comment the following lines of code if you wish to keep the panel lists open between clicks
                    panel_items[i].className = 'panel_list hide';
                    
                    arrow_img.src = arrow_img_set[arrow];
                    arrow_img.alt = 'Expand';
                    arrow_img.title = 'Expand';
                    
                    if (p)
                    {
                        p.innerHTML = 'click to expand';
                        p.title = 'click to expand';
                    }
                    
                    a.title = 'click to expand';
                    
                    if (smallQuote)
                        smallQuote.className = smallQuote.className.replace("hide", "show");
                }
                
                cntr++;
            }
        }
    }
    
    return;
   }


function ToggleAnswer(questionSetIndex, answerIndex)
{
	var questionSet = GetObject('divQuestionSet' + questionSetIndex.toString());
	var answer = questionSet.getElementsByTagName('div');
	var cntr = 0;

	for (var a = 0; a < answer.length; a++)
	{
		if (answer[a].className.indexOf('answer') != -1)
		{
			if (cntr == answerIndex)
			{
				if (answer[a].className.indexOf('hide') != -1)
				{
					answer[a].className = answer[a].className.replace('hide', 'show');

					lastAnswer = answer[a];
				}
				else
				{
					answer[a].className = answer[a].className.replace('show', 'hide');
				}
			}
			else
			{
				// comment the following lines of code if you wish to keep the answers open between clicks
				answer[a].className = answer[a].className.replace('show', 'hide');
			}
			
			cntr++;
		}
	}

	return;
}


// --- HELPER METHODS --- //
function GetObject(obj)
{
    return ((typeof(obj) != 'object') ? document.getElementById(obj) : obj);
}