// Working area for unobtrusive stuff

window.onload=doDOMstuff;	
// When we only use one function, we don't use the parenthesis at the end of the
// function name, as that would send back the result of the function rather than
// trigger the function.

function doDOMstuff()
{
	if(document.getElementById && document.createTextNode)
	{
		// add popup controls to all "ifspop" anchors
		var contentHole = document.getElementById('contentHole');
		if (contentHole) {
			var aTags = contentHole.getElementsByTagName('a');
			for (var i=0; i<aTags.length; i++) {
				if (aTags[i].target=="ifspop") {
					aTags[i].onclick=function(){openEventDetail(this);return false;};
				}
			}
		}
		
		// add calendar highlighting to calendar anchors
		var calendarView = document.getElementById('calendarView');
		if (calendarView) {
			var param = "";
			aTags = calendarView.getElementsByTagName('a');
			for (var i=0; i<aTags.length; i++) {
				aTags[i].onclick=function(){highlight(this)};
			}
		}
	}


/*	if(o)
	{
		o.style.background=col;
	}	*/
}



function highlight(eDateHref) {
	param = eDateHref.href;
	eDate = param.replace(/[^#]*#(\w+)/, "$1");

	// reset all selected DIVs to regular event DIVs
	// get obj whose id is eDate (e.g., "Sep21")
	// get next sibling until tag = div and class = event
	// if we have a valid div, set class to eventSelected
	// do it again to each div/class until we have another <a name> tag
	
	var objHole = document.getElementById("contentHole");
	if (! objHole) { return false; }
	var possibleEvents = objHole.getElementsByTagName("div");
	for (i=0; i<possibleEvents.length; i++) {
		if (possibleEvents[i].className=="event selected") {
			possibleEvents[i].className="event";
		}
		if (possibleEvents[i].className=="event selected belowmonth") {
			possibleEvents[i].className="event belowmonth";
		}
	}
	
	if (! eDate || eDate=="") { return false; }
	var objDate = document.getElementById(eDate);
	if (! objDate) { return false; }
	
	var isDiv = objDate;
	do {
		// document.write(isDiv.tagName + "/" + isDiv.className + "<br>\n");
		isDiv = isDiv.nextSibling;
		strDivTagName = "" + isDiv.tagName;
	} while (strDivTagName.toUpperCase()!="DIV" || (isDiv.className!="event" && isDiv.className!="event belowmonth"));
	
	strDivTagName = "" + isDiv.tagName;
	while (strDivTagName.toUpperCase()!="A" || isDiv.id==eDate) {
		if (isDiv.className=="event") {
			isDiv.className="event selected";
		}
		if (isDiv.className=="event belowmonth") {
			isDiv.className="event selected belowmonth";
		}

		isDiv = isDiv.nextSibling;
		if (! isDiv) { break; }
		strDivTagName = "" + isDiv.tagName;
	} 
}


