// Expand/collapse sections
function initExpandCollapse() {
	if (document.getElementById && document.createTextNode) {
		var content = document.getElementById('toggleSections');
		if ( content == null ) return;
		var as = content.getElementsByTagName('a');
		for (var i = 0; i < as.length; i++) {
			if (as[i].className != "normalLink") {
				as[i].onclick = function() {
				
					// -- Start WebTrends stuff				
					var tabs = null;
					try {
						tabs = document.getElementById('tabs').getElementsByTagName('a');
					} // try
					catch (e) {
						tabs = null;
					} // catch						
					var arrHref = this.href.split('/');
					var sectionTitle = this.innerHTML;
					
					var drilldownMeta = null;
					try {
						drilldownMeta = document.getElementById('DCSext.lwdrill').content;
					} // try
					catch (e) {
						drilldownMeta = null;
					} // catch
						
					if (drilldownMeta != null) {					
						if (tabs != null) {
							var regEx = new RegExp ('&amp;', 'gi');
							drilldownMeta += ';' + tabs[1].innerHTML.replace(regEx, 'and') + ';' + sectionTitle.replace(regEx, 'and');				
						} // if
						else {
							drilldownMeta += ';' + sectionTitle.replace(regEx, 'and');				
						} // else					
						
						dcsMultiTrack('DCSext.lwdrill', drilldownMeta);
					} // if
					// -- End WebTrends stuff				
					
					expandCollapseSection(this);
					return false;
				}
				as[i].onkeypress = function() {
					if (window.event.keyCode && window.event.keyCode == 13) {
						expandCollapseSection(this);
						return false;
					}
				}
			}
		}
		collapseAllSections();
	}
}

function expandCollapseSection(l) {
	var id = l.href.match(/#(\w.+)/)[1];
	var ref = document.getElementById(id);
	if (ref.style.display == 'none') {
		collapseAllSections();
		ref.style.display = 'block';
		l.style.backgroundImage = 'url(/img/campaigns/labelwriter/images/collapse.gif)';
	}
	else {
		ref.style.display = 'none';
		l.style.backgroundImage = 'url(/img/campaigns/labelwriter/images/expand.gif)';
	}
	// Rewrite footer to solve CSS / JS positioning conflicts 
//	var footerRef= document.getElementById('container-footer');
//	footerRef.style.display = 'none';
//	footerRef.style.display = 'block';
}

function collapseAllSections() {
	var content = document.getElementById('toggleSections');
	var as = content.getElementsByTagName('a');
	var sections = content.getElementsByTagName('div');
	for (var h = 0; h < as.length; h++) {
		as[h].style.backgroundImage = 'url(/img/campaigns/labelwriter/images/expand.gif)';
	}
	for (var i = 0; i < sections.length; i++) {
		if (sections[i].className == 'toggleSection') {
			sections[i].style.display = 'none';
		}
	}
}
