// ***
// *** This function locates an html object by it's id
// ***

function find_element_by_id(anId) {

	var element;

	if (document.getElementById) {
	// *** W3C Standard
	element = eval('document.getElementById(\'' + anId + '\')');
	} else if (document.all) {
	// *** old ie versions
	element = eval('document.all[\'' + anId + '\']');
	} else if (document.layers) {
	// *** nn4
	element = eval('document.layers[\'' + anId + '\']');
	}

	return element;
}

function findLivePageHeight() {
	if (window.innerHeight != null) {
		return window.innerHeight;
	}
	if (document.body.clientHeight != null) {
			return document.body.clientHeight;
		}
	return (0);
}

function findLivePageWidth() {
	if (window.innerWidth != null) {
		return window.innerWidth;
	}
	if (document.body.clientWidth != null) {
			return document.body.clientWidth;
		}
	return (0);
}

function getTop(aHeight) {
	var spacingTop;
	windowHeight = findLivePageHeight();
	diff = windowHeight - aHeight;
	if (diff > 0) {
		spacingTop = parseInt(diff / 2 + 10);
		spacingTop = spacingTop + 'px';
	} else {
		spacingTop = '200px';
	}
	return spacingTop;
}

function getLeft(aWidth) {
	var spacingLeft;
	windowWidth = findLivePageWidth();
	diff = windowWidth - aWidth;
	if (diff > 0) {
		spacingLeft = parseInt(diff / 2 + 10);
		spacingLeft = spacingLeft + 'px';
	} else {
		spacingLeft = '100px';
	}
	return spacingLeft;
}

function toggleImageDisplay(anImagePath, anImageId, aWidth, aHeight) {
	imageDiv = find_element_by_id('oh_' + anImageId);
	if (imageDiv.style.display == 'none') {
		cssLeft = getLeft(aWidth);
		cssTop = getTop(aHeight);
		imageDiv.style.left = cssLeft;
		imageDiv.style.top = cssTop;
		imageDiv.style.display = 'block';
		setStateFieldDisplay('none');
	} else {
		imageDiv.style.display = 'none';
		setStateFieldDisplay('block');
	}
}

function setStateFieldDisplay(aDisplayAttribute) {
	stateField = find_element_by_id('oh_state');
	if (stateField != null) {
		stateField.style.display = aDisplayAttribute;
	}
}
