function setCourses(which) {
	if(which == '') { which = 'nl'; }


	//(1) remove the classnames of all elements that aren't the one passed to the function
	//(2) add toggling event listeners to all elements
	if(xGetElementById('courses')) {
		var courses = xGetElementById('courses').getElementsByTagName('ul')[0];

		for(i=0;i<courses.childNodes.length;i++) {
				if(courses.childNodes[i].nodeName == "LI" && courses.childNodes[i].className != "course") {
					//apply an event listener
					var theElement = xGetElementById(courses.childNodes[i]);
				
					xAddEventListener(theElement,'click',toggle,false);
		
					if(courses.childNodes[i].className == 'expanded' && courses.childNodes[i].id != which) {
						courses.childNodes[i].className = '';
					}
				}
		}
	}
	
}

function toggle(e) {	
	var ev=(!e)?window.event:e;//IE:Moz
	targ = getClickedElement(e);
	
	if(targ.parentNode.className != "course") {
		ev.preventDefault?ev.preventDefault():ev.returnValue = false; //syntax = testcond?true:false;
		//get the element that was clicked on
		if(xGetElementById(targ.parentNode).className == '') {
			xGetElementById(targ.parentNode).className = 'expanded';
		} else {
			xGetElementById(targ.parentNode).className = '';
		}
	}
}

function xAddEventListener(e,eT,eL,cap)
{
  if(!(e=xGetElementById(e)))return;
  eT=eT.toLowerCase();
	if(e.addEventListener) {
		e.addEventListener(eT,eL,cap||false);
	} else {
		if(e.attachEvent) {
			e.attachEvent('on'+eT,eL);
		} else {
		var o=e['on'+eT];
		e['on'+eT]=typeof o=='function' ? function(v){o(v);eL(v);} : eL;
	}
  }
}

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

function GetXmlHttpObject() {
 var xmlHttp=null;
 try {
   // Firefox, Opera 8.0+, Safari
   xmlHttp=new XMLHttpRequest();
 } catch (e) {
   // Internet Explorer
   try {
     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
 }
 return xmlHttp;
}


function getClickedElement(e) {
	var targ;
	var ev=(!e)?window.event:e;//IE:Moz
	
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;

	if (targ.nodeType == 3) // defeat Safari bug
	targ = targ.parentNode;
	return targ;
}

