
// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;

window.onload = function(){
	window.defaultStatus = document.title;
	initDHTMLAPI();
}

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;
	}

}

// 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;
}

// 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 style (or NN4 layer) reference
function getObject(obj) {
	var theObj = getRawObject(obj);
	if (theObj && isCSS) {
		theObj = theObj.style;
	}
	return theObj;
}

// Set the text of an object
function setText(obj, txtMsg) {
	var theObj = getRawObject(obj);
	if (theObj) {
		if (isNN4) {
			// need to change this for nav4
			// theObj.color = color;
		} else if (isCSS) {
			theObj.innerHTML = txtMsg;
		}
	}
}


function show_description(which) {

return;
	var theObj = getObject(which);

	// set the text of the_message
	setText(theMessage, theObj.innerHTML);

	// show the message
	theMessage.display = 'block';
	
/*
	if (theObj) {
		theObj.display = 'block';
	}
*/

}


function show_message(mess) {

	var put_text = document.search_settings.messages;
	switch (mess) {

		case "title" :
			put_text.value="Check this box to see if any search terms are in the title.\n\nUn-check this box to ignore the title.";
			break;

		case "composer" :
			put_text.value="Check this box to see if any search terms are in the composer's name.\n\nUn-check this box to ignore the composer.";
			break;

		case "category" :
			put_text.value="Check this box to see if any search terms are in the category.\n\nUn-check this box to ignore the category.";
			break;

		case "publisher" :
			put_text.value="Check this box to see if any search terms are in the publisher.\n\nUn-check this box to ignore the publisher.";
			break;

		case "description" :
			put_text.value="Check this box to see if any search terms are in the description.\n\nUn-check this box to ignore the description.";
			break;

		case "show" :
			put_text.value="Check this box to display any descriptions for the title.\n\nUn-check this box to hide descriptions.";
			break;

		case 'limit' :
			put_text.value="Select how many results you would like to show on each page.";
			
			break;

		case "highlight" :
			put_text.value="Check this box to highlight where search terms matched.\n\nUn-check this box to suppress highligting.";
			break;

		case "OK" :
			put_text.value="Click OK to keep any changes.";
			break;

		case "CANCEL" :
			put_text.value="Click CANCEL to undo any changes.";
			break;

		default :
			put_text.value='Move the mouse over a field for explanations.';

	}
}

function click_choice(mess) {

	switch (mess) {

		case "title" :
			document.search_settings.ck_title.click();
			break;

		case "composer" :
			document.search_settings.ck_composer.click();
			break;

		case "category" :
			document.search_settings.ck_category.click();
			break;

		case "publisher" :
			document.search_settings.ck_publisher.click();
			break;

		case "description" :
			document.search_settings.ck_description.click();
			break;

		case "show" :
			document.search_settings.ck_show_description.click();
			break;

		case "highlight" :
			document.search_settings.highlighting.click();
			break;

		default :
			break;

	}
}

function setBGColor(obj, color) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        } else if (isCSS) {
            theObj.backgroundColor = color;
        }
    }
}


function setHintText(obj) {

	theObj = getRawObject(obj);

	setText('browse_hint_text', theObj.lastChild.innerHTML);
	setBGColor('browse_hint_text', 'whitesmoke');
	return;
}

function hideHintText() {
	setText('browse_hint_text', '&nbsp;');
	setBGColor('browse_hint_text', 'transparent');
	return;
}


/*

alert('is CSS ' + isCSS);
alert('is W3C ' + isW3C);
alert('is IE4 ' + isIE4);
alert('is NN4 ' + isNN4);
alert('is IE6CSS ' + isIE6CSS);

*/

