// ******  DHTML API  ****** //

// global variables
var isCSS = isNS4 = isNS6 = isIE4 = isIE6 = false;

// call init function
initDHTMLAPI();

// initialise API - browser detection
function initDHTMLAPI() {
	if (document.body && document.body.style) isCSS = true;
	if (document.layers) isNS4 = true;
	if (document.getElementById) isNS6 = true;
	if (document.all) isIE4 = true;
	if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) isIE6 = true;
}

// get NS4 layer name from string
function seekLayer(doc, name) {
	var theObj;
	
	for (var i=0; i<doc.layers.length; i++) {
		if (doc.layers[i].name == name) {
			theObj = doc.layers[i];
			break;
		}
		
		// go into nested layers if necessary
		if (doc.layers[i].document.layers.length > 0) {
			theObj = seekLayer(document.layers[i].document, name);
		}
	}
	return theObj;
}

// convert object name string or reference into valid object reference
function getRawObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isNS6) {
			theObj = document.getElementById(obj);
		} else if (isIE4) {
			theObj = document.all(obj);
		} else if (isNS4) {
			theObj = seekLayer(document, obj);
		}
	} else {
		theObj = obj;
	}
	return theObj;
}

// convert object reference into valid style reference
function getObject(obj) {
	var theObj = getRawObject(obj);
	//if (theObj && (isCSS || isIE6)) theObj = theObj.style
	if (theObj) theObj = theObj.style;
	return theObj;
}

// set visibility of object to visible
function show(obj) {
	var theObj = getObject(obj);
	if (theObj) theObj.visibility = "visible"
}

// set visibility of object to hidden
function hide(obj) {
	var theObj = getObject(obj);
	if (theObj) theObj.visibility = "hidden"
}
