// JavaScript for Family Doctor Health Advisor Jaz Smith August 2008

//stop IE image flicker on rollover

try
{
	document.execCommand("BackgroundImageCache", false, true);
}
catch(err)
{
}

//bug fix IE that can't handle getElementsByName so we need to check elementsbytagname that are named boxblock
function getElementsByName_iefix(tag, name)
{
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for(i = 0,iarr = 0; i < elem.length; i++)
	{
		att = elem[i].getAttribute("name");
		if(att == name)
		{
			arr[iarr] = elem[i];
			iarr++;
		}
	}

	return arr;
}



function doTheStuff(show,hide1,hide2,id,choice,section)
{
	var numberid = id * 1;  //convert string to number to get id in numerical form
	var collapseall = (numberid+1); // add one to the id to get the collapseall value

	//Find out how many box blocks there are - this only works on IE see bugfix above
	//elems=document.getElementsByName("boxblock");

	var elems=getElementsByName_iefix('div','boxblock');
	//alert(elems.length); Check to see if the browser has the correct count of boxblocks
	//loop through and do the stuff only if elem exists in html
	// remove anything further down the tree than the current boxblock

	for (i=collapseall;i<=elems.length;i++)
	//for (i=collapseall;i<=27;i++)
	{
		document.getElementById(i).style.display = 'none';

		if(document.getElementById(i+'yesarrow') != null)
		{
			document.getElementById(i+'yesarrow').style.display = 'none';
		}
		if(document.getElementById(i+'noarrow') != null)
		{
			document.getElementById(i+'noarrow').style.display = 'none';
		}
		if (document.getElementById(i+'leftarrow') != null)
		{
			document.getElementById(i+'leftarrow').style.display = 'none';
		}
		if (document.getElementById(i+'centerarrow') != null)
		{
			document.getElementById(i+'centerarrow').style.display = 'none';
		}
		if (document.getElementById(i+'rightarrow') != null)
		{
			document.getElementById(i+'rightarrow').style.display = 'none';
		}

		if (document.getElementById(i+'yes') != null)
		{
			document.getElementById(i+'yes').style.backgroundImage =
							'url(/scriptcontent/assessment/pathway/images/'
							+ section + '_bg_yes_off.gif)';
		}
		if (document.getElementById(i+'no') != null)
		{
			document.getElementById(i+'no').style.backgroundImage =
							'url(/scriptcontent/assessment/pathway/images/'
							+ section + '_bg_no_off.gif)';
		}
		if (document.getElementById(i+'left') != null)
		{
			document.getElementById(i+'left').style.backgroundImage =
							'url(/scriptcontent/assessment/pathway/images/'
							+ section + '_bg_left_off.gif)';
		}
		if (document.getElementById(i+'center') != null)
		{
			document.getElementById(i+'center').style.backgroundImage =
							'url(/scriptcontent/assessment/pathway/images/'
							+ section + '_bg_center_off.gif)';
		}
		if (document.getElementById(i+'right') != null)
		{
			document.getElementById(i+'right').style.backgroundImage =
							'url(/scriptcontent/assessment/pathway/images/'
							+ section + '_bg_right_off.gif)';
		}
	}
/*
	// fix a bit of a bug with the first line showing the arrows from row 2
	if (id==1)
	{
		document.getElementById(2+'yesarrow').style.display = 'none';
		document.getElementById(2+'noarrow').style.display = 'none';
		document.getElementById(1+choice+'arrow').style.display = 'block';
	}
*/
/**/
	//highlight selected buttons
	if(null != document.getElementById(id+'yes'))
	{
		document.getElementById(id+'yes').style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_yes_off.gif)';
	}
	if(null != document.getElementById(id+'no'))
	{
		document.getElementById(id+'no').style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_no_off.gif)';
	}
	if(null != document.getElementById(id+'left'))
	{
		document.getElementById(id+'left').style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_left_off.gif)';
	}
	if(null != document.getElementById(id+'center'))
	{
		document.getElementById(id+'center').style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_center_off.gif)';
	}
	if(null != document.getElementById(id+'right'))
	{
		document.getElementById(id+'right').style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_right_off.gif)';
	}
	
	if (choice=='yes')
	{
		document.getElementById(id+choice).style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_yes_on.gif)';
	}
	if (choice=='no')
	{
		document.getElementById(id+choice).style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_no_on.gif)';
	}
	if (choice=='left')
	{
		document.getElementById(id+choice).style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_left_on.gif)';
	}
	if (choice=='center')
	{
		document.getElementById(id+choice).style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_center_on.gif)';
	}
	if (choice=='right')
	{
		document.getElementById(id+choice).style.backgroundImage =
						'url(/scriptcontent/assessment/pathway/images/' + section + '_bg_right_on.gif)';
	}
	
	//arrow path
	if(null != document.getElementById(id+'yesarrow'))
	{
		document.getElementById(id+'yesarrow').style.display = 'none';
	}
	if(null != document.getElementById(id+'noarrow'))
	{
		document.getElementById(id+'noarrow').style.display = 'none';
	}
	if(null != document.getElementById(id+'leftarrow'))
	{
		document.getElementById(id+'leftarrow').style.display = 'none';
	}
	if(null != document.getElementById(id+'centerarrow'))
	{
		document.getElementById(id+'centerarrow').style.display = 'none';
	}
	if(null != document.getElementById(id+'rightarrow'))
	{
		document.getElementById(id+'rightarrow').style.display = 'none';
	}
	if(null != document.getElementById(id+choice+'arrow'))
	{
		document.getElementById(id+choice+'arrow').style.display = 'block';
	}
	
	//content box
	if(null != document.getElementById(show))
	{
		document.getElementById(show).style.display = 'block';
	}
	if(null != document.getElementById(hide1))
	{
		document.getElementById(hide1).style.display = 'none';
	}
	if(null != document.getElementById(hide2))
	{
		document.getElementById(hide2).style.display = 'none';
	}
/**/
}



function setVisibility(ID, show)
{
	var showvarl="block";
	if (show)
	{
		showvar1="block";
	}
	else
	{
		showvar1="none";
	}

	document.getElementById(ID).style.display = showvar1;
}

