function toggleLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	
	if (elem) {
		vis = elem.style;
		// if the style.display value is blank we try to figure it out here
		if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
		
		// change the + to a -, or vice versa
		var toggleSignId = "toggle-sign_" + whichLayer;
		toggleSign = document.getElementById(toggleSignId);
	
		if (toggleSign.innerHTML == "+") {
			toggleSign.innerHTML = "&ndash;";
		} else {
			toggleSign.innerHTML = "+";
		}
	}
}

function displayIncomingLink() {
	
	// if the incoming link specifies a course to display, display it
	
	var locate = location.href;

	if (locate.indexOf('#') > -1) {
		begin = locate.indexOf('#') + 3;
		course = locate.substring(begin, (begin + 5));
		toggleLayer(course);
	}
}

function evaluateCourse(descriptionLength,courseId) {
	if (descriptionLength < 20) { // if the course doesn't have a description, don't display it
		document.getElementById('c_' + courseId).style.display='none';
		document.getElementsByName('a_' + courseId)[0].style.display='none';
		document.getElementById('section_' + courseId).id='';
		document.getElementById('offered_' + courseId).id='';
		document.getElementById(courseId).id='';
		
	} else if (document.getElementById('schedule_' + courseId) == null) { // if the class isn't scheduled this semester then delete the section header and "offered" copy; if IE, reformat section div
		document.getElementById('section_' + courseId).style.display='none';
		document.getElementById('offered_' + courseId).style.display='none';
		
		/*if (navigator.appName == "Microsoft Internet Explorer") {
			document.getElementById('notes_' + courseId).style.marginBottom="-5px";
		}*/
	}
}

function changeARR(courseDays) {
	// replace "A, R, R" with "Arranged" and "R" with "Th" in the days field; getElementsByName method doesn't work in IE, so this is a work-around

	var days = document.getElementById(courseDays);
	if (days.innerHTML == "A, R, R") {
		days.innerHTML = "Arranged";
	} else if (days.innerHTML.indexOf("R") > -1) {
		days.innerHTML = days.innerHTML.slice(0,days.innerHTML.indexOf("R")) + "Th";
	}
	
	// if there are two instances of AM or PM, remove the first

	try {
		var times = document.getElementById("times_" + courseDays.slice(5));
		var pm = times.innerHTML.match(/PM/g);
		var am = times.innerHTML.match(/AM/g);
		if (am != null && am.length > 1) {
			times.innerHTML = times.innerHTML.replace(/AM/, "");
		} else if (pm != null && pm.length > 1) {
			times.innerHTML = times.innerHTML.replace(/PM/, "");
		}
	} catch(err) {
		return;
	}
}