
// globals to identify the current browser.
var BrowserIsIE = (navigator.appName.indexOf("Microsoft") != -1);
var BrowserIsNN4x = (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==4);
var BrowserIsNN6x = (navigator.appName == "Netscape" && parseInt(navigator.appVersion)>=5);	// also describes Mozilla.
// global to identify Mac OS.
var ComputerIsAMac = navigator.platform.indexOf("Mac") != -1;

// this gives access to page elements appropriate to each browser environment.
// these references are used to change content & appearance dynamically w/o reloading the page.
function getObjectRef(aDocumentObject){
	var objRef;
	
	if (BrowserIsIE && ComputerIsAMac){
		objRef = document[aDocumentObject];
	} else if (BrowserIsNN4x) {	// note: in NN4x we can only change layers dynamically.
		objRef = eval("document." + aDocumentObject);
		//objRef = document.layers[aDocumentObject+ "-layer"];
	} else {
		objRef = document.getElementById(aDocumentObject);
	}
	return objRef;
}

// returns contents of a link.
function getLinkText(linkObj){
	if (BrowserIsNN4x){
		return linkObj.text;
	} else {
		return linkObj.innerHTML;
	}
}
//
function setLinkText(linkObj, newText){
	if (BrowserIsNN4x){
		linkObj.text = newText;
	} else {
		linkObj.innerHTML = newText;
	}
}

/* String utilities */
// returns the characters in str leading up to the delimiter.
function getLeft(str, delim){
	var delimPos = str.indexOf(delim);
	if (delimPos == -1) return str;
	var leftStr = str.substring(0, delimPos);
	return leftStr;
}
// returns the characters in str following the delimiter.
function getRight(str, delim){
	var delimPos = str.indexOf(delim);
	if (delimPos == -1) return str;
	var rightStr = str.substring(delimPos+1);
	return rightStr;
}

/* Document Element utilities */
// returns the current screen location of any page element.
function getScreenLoc(element, offset){
	if (offset == undefined){
		offset = new Array(2);
		offset[0] = 0;
		offset[1] = 0;
	}
	offset[0] += element.offsetLeft;
	offset[1] += element.offsetTop;
	if (element == document.body){
		return offset;
	}
	return getScreenLoc(element.offsetParent, offset);
}

// returns the closest container whose id starts with <prefix>, before the specified <delim> character 
// (eg; returns "book_1" if the <startElement> is contained in the document element "book_1", the prefix is "book", and the delim is "_").
function getContainerByPrefix(startElement, prefix, delim){
	if (getLeft(startElement.id, delim) == prefix) return startElement;
	return getContainerByPrefix(startElement.parentElement, prefix, delim);
}