window.onload=collapse;

//	------------------------------------------------------
//	Toggle visibility of the next sibling of h4 elements in the FAQ on/off
//	slightly adapted from script by Christian Heilmann (http://icant.co.uk)
//	http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
function collapse() {
	if (!document.createTextNode) { return; }
	var heads=document.getElementsByTagName('h4');
	for(var i=0;i<heads.length;i++) {
		var tohide=heads[i].nextSibling;
		while(tohide.nodeType!=1) {
			tohide=tohide.nextSibling;
		}
		cssjs('add',tohide,'hidden')
		cssjs('add',heads[i],'trigger')
		heads[i].tohide=tohide;
		heads[i].onmouseover=function() { cssjs('add',this,'hover'); }
		heads[i].onmouseout=function() { cssjs('remove',this,'hover'); }
		heads[i].onclick=function() {
			if(cssjs('check',this.tohide,'hidden')) {
				cssjs('swap',this,'trigger','open');			
				cssjs('swap',this.tohide,'hidden','shown');			
			} else {
				cssjs('swap',this,'open','trigger');			
				cssjs('swap',this.tohide,'shown','hidden');			
			}
		}
	}
	function cssjs(a,o,c1,c2) {
		switch (a){
			case 'swap':
				o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
		}
	}
}

//	------------------------------------------------------
//	Loops through all the options of the form's select element 
//	then assigns different class name to selected/no selected options
function show_topic_description(zis) {
	for (var i=0; i<zis.length; i++) {
		var opt = zis.options[i].value;
		if (opt == zis.value && zis.value != 'none') {
			document.getElementById(opt).className = 'show_description';
		//	conditional necessary for options in <select> that don't have a corresponding <li>
		//	because trying to assign a className to a 'null' element id will throw an error and stop the loop
		} else if (document.getElementById(opt)) { 
			document.getElementById(opt).className = '';
		}	
	}
}