// Global variables
var isCSS, isW3C, isIE4, isNN4, isSafari, isMac, isIEMac;
// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	}
	if (navigator.platform.indexOf("Mac") > -1)	isMac = true;
	if (isMac && (navigator.appName.indexOf("Microsoft") > -1)) isIEMac = true;
	// assume this is true for safari
	if (navigator.vendor == "Apple Computer, Inc.") {
		isSafari = true;
	}
	if (isIEMac || isIE4) {
		mudBlur();
	}
}

// Seek nested NN4 layer from string name
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;
        }
        // dive 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 object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// blur out those annoying blue boxes around links
function mudBlur() {
	var selections = getTagObject('select');
	for( i = 0; i < selections.length; i++ ) {
		selections[i].onfocus = function() { this.blur() };
	}
	var anchors = getTagObject('a');
	for( i = 0; i < anchors.length; i++ ) {
		anchors[i].onfocus = function() { this.blur() };
	}
	var cbox = getTagObject('input');
	for( i = 0; i < cbox.length; i++ ) {
		if ((cbox[i].type == 'checkbox') || (cbox[i].type == 'radio') || (cbox[i].type == 'submit') || (cbox[i].type == 'reset')) {
			cbox[i].onfocus = function() { this.blur() };
		}
	}
}


// grab objects by html tag name
function getTagObject(obj) {
	var mudObj;
	if (isW3C) {
		mudObj = document.getElementsByTagName(obj);
	}
	else if (isIE4) {
		mudObj = document.all(obj);
	}
	else if (isNN4) {
		mudObj = obj;
	}
	return mudObj;
}



function setDisplay(id) {
	var obj = getObject(id);
	obj.display = "block";
}

function unsetDisplay(id) {
	var obj = getObject(id);
	obj.display = "none";
}

function hideLayer(id) {
	var obj = getObject(id);
	if (isNN4) {
		obj.visibility = "hide";
	}
	if (isIE4 || isW3C) {
		obj.visibility = "hidden";
	}
}

function showLayer(id) {
	var obj = getObject(id);
	if (isNN4) {
		obj.visibility = "show";
	}
	if (isIE4 || isW3C) {
		obj.visibility = "visible";
	}
}

function changeClass(id, newClass) {
	var obj = getRawObject(id);
	obj.className=newClass;
}
