//------------------------------------------//
// JavaScript General Functions Document
// Copyright St. Jame's Place 2006
// Script creator: Paulo Marques @ CCHM:Ping
//------------------------------------------//

//Function that uses the DOM to find the DIV parent node of a 
//clicked box header and passes it as an object to expandBoxContainer() for handling
function toggleBox(href) {
	var itemEl = href.parentNode;
	while (itemEl.nodeName.toLowerCase() != "div") {
		itemEl = itemEl.parentNode;
	}
	expandBoxContainer(itemEl);
}

//Function that displays or hides sidebar 
//colapsible boxes
function expandBoxContainer(itemEl) {
	var containerId = itemEl.id + "-container"
	var containerEl = document.getElementById(containerId);
	
	if (itemEl.className == "slidetitle-expanded") {
		containerEl.style.display = "none";
		itemEl.className = "slidetitle-colapsed";
		var elStringId = itemEl.id.substring(itemEl.id.length-1);
		initHideSideBoxes(elStringId);
	} else if (itemEl.className == "slidetitle-colapsed"){
		containerEl.style.display = "block";
		itemEl.className = "slidetitle-expanded";
		var elStringId = itemEl.id.substring(itemEl.id.length-1);
		initHideSideBoxes(elStringId);
	}
}

//Function that parses the entire webpage DOM 
//to look for the sidebar boxes and hides them
function initHideSideBoxes(init) {
	var pos = 1;
	var id = ""
	var initId = "sidebar-box-"+init+"-container";
	var initIdTitle = "sidebar-box-"+init;

	var listElArray = document.getElementsByTagName("div");
	for (var i = 0; i < listElArray.length ; i++) {
		if (listElArray[i].className == "slidetitle-expanded") {
			id = "sidebar-box-"+pos;
			if (id != initIdTitle) {
				listElArray[i].className = "slidetitle-colapsed";
			}
		}
		if (listElArray[i].className == "sidebar-box-container") {
			id = "sidebar-box-"+pos+"-container";
			if (id != initId) {
				listElArray[i].style.display = "none";
			}
			pos++
		}
	}
	return true
}

/*----------------------------------*/
/* Scripted Questions functionality
/*----------------------------------*/
//Function that uses the DOM to find the DT parent node of a 
//clicked question link and passes it as an object to showContent() for handling
function showPanel(href) {
	var itemEl = href.parentNode;
	while (itemEl.nodeName.toLowerCase() != "dt") {
		itemEl = itemEl.parentNode;
	}
	showContent(itemEl);
}

//Function that displays or hides Scripted 
//Answer panels in Products & Services Page
function showContent(itemEl) {
	var listElArray = document.getElementsByTagName("dt");
	for (var i = 0; i < listElArray.length ; i++) {
		if (listElArray[i] == itemEl && listElArray[i].className == "qtab") {
			listElArray[i].className = "qtabActive";
		} else if (listElArray[i] != itemEl && listElArray[i].className == "qtabActive") {
			listElArray[i].className = "qtab";
			var xDiv = document.getElementById(listElArray[i].title);
				xDiv.style.display = "none";
		}
	}
	var divEl = document.getElementById(itemEl.title);
	if (divEl != null)
		divEl.style.display = "block";
}

//Function that parses the entire webpage DOM 
//to look for scripted answer panels and based on variables hides them
function initHidePanels() {
	var pos = 1;
	var id = ""
	var listElArray = document.getElementsByTagName("dl");
	for (var i = 0; i < listElArray.length ; i++) {
		if (listElArray[i].style.display) {
			id = "q"+pos;
			if (listElArray[i].id == id) {
				if (listElArray[i].className != "init") {
					listElArray[i].style.display = "none";
				}
				pos++
			}
		}
	}
	return true
}
