// 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,hide,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+'yes') != null){
document.getElementById(i+'yes').style.backgroundImage = 'url(/scriptcontent/fdha/images/' + section + '_bg_yes_off.gif)';
}

if (document.getElementById(i+'no') != null){
document.getElementById(i+'no').style.backgroundImage = 'url(/scriptcontent/fdha/images/' +section +'_bg_no_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
document.getElementById(id+'yes').style.backgroundImage = 'url(/scriptcontent/fdha/images/' + section +'_bg_yes_off.gif)';
document.getElementById(id+'no').style.backgroundImage = 'url(/scriptcontent/fdha/images/' + section +'_bg_no_off.gif)';

if (choice=='yes'){
document.getElementById(id+choice).style.backgroundImage = 'url(/scriptcontent/fdha/images/' + section +'_bg_yes_on.gif)';
}

if (choice=='no'){
document.getElementById(id+choice).style.backgroundImage = 'url(/scriptcontent/fdha/images/' + section +'_bg_no_on.gif)';
}

//arrow path
document.getElementById(id+'yesarrow').style.display = 'none';
document.getElementById(id+'noarrow').style.display = 'none';
document.getElementById(id+choice+'arrow').style.display = 'block';

//content box
document.getElementById(show).style.display = 'block';
document.getElementById(hide).style.display = 'none';
 

} 