// Plant-Biotech Denmark JavaScript routines

var searchInputColor = 'black', searchMsgColor = 'gray', searchMsg = 'Search for:';

var endOffset = -1, bodyElement, adjustElement, releaseScrollbar, bodyTable, bodyTableOffset;

function init() {
	window.focus();
	if (typeof(userInit)=='function') userInit();
	if (!document.getElementById) return;
	var obj = document.getElementById('hgtObj');
	bodyElement = document.getElementById('bodyElement');
	adjustElement = document.getElementById('adjustElement');
	bodyTable = document.getElementById('bodyTable');
	releaseScrollbar = !document.all;
	endOffset = 1;
	do {
		endOffset += obj.offsetTop;
		obj = obj.offsetParent;
	} while(obj);
	obj = bodyTable;
	if (!document.styleSheets) endOffset += 7; // Opera
	adjustHeight();
/*
	if (document.getElementById('hgtObj').height>0
		&& document.documentElement.scrollHeight > bodyElement.clientHeight) {
		// further adjustment for Opera 5.5, Navigator 7.1, and whichever browser needing it
		adjust += (document.documentElement.scrollHeight - bodyElement.clientHeight);
		resize(); // again
	} // if (!ie && ...
*/
} // function init()

function adjustHeight() {
	if (endOffset<0) return; // not supported
	var height = bodyElement.clientHeight;
	document.getElementById('hgtObj').height = height>endOffset ? height-endOffset : 0;
	if (releaseScrollbar) {
		// without this code, Navigator and FireFox do not release the scrollbar
		var i = document.getElementById('hgtObj').height;
		adjustElement.innerHTML = adjustElement.innerHTML;
	} // if (releaseScrollbar)
	bodyTableOffset = getOffset(bodyTable);
// alert('adjustHeight\n'+bodyTableOffset.offsetLeft+','+bodyTableOffset.offsetTop);
	if (typeof(userResize)=='function') userResize();
// alert(endOffset+'\n'+document.getElementById('hgtObj').height+'\n'+height);
} // function adjustHeight()

function RBover(element, id, color) {
	window.status = element.title;
	element.style.cursor = navigator.appVersion.indexOf('MSIE')>=0 ? 'hand' : 'pointer';
	if (typeof(id)=='string')
		document.getElementById(id).style.backgroundColor = color;
} // function RBover()

function RBout(element, id, color) {
	window.status = '';
//	element.style.cursor = 'auto';
	if (typeof(id)=='string')
		document.getElementById(id).style.backgroundColor = color;
} // function RBout()

function RBclick(element) {
	location.href = element.title;
} // function RBclick()


function submitSearchForm(method) {
// submit the search form

	var ok = true; // true if ok to call search.asp, else false

	var form=document.forms.form1, field=form.query, search=field.value;
	if (field.style.color!=searchInputColor) {
		alert('You must select the Search field and specify the word(s) to search for');
		field.focus();
		return;
	} // if (!search>' ')
	if (search=='' || /^ *$/.test(search)) {
		alert('You must specify the word(s) to search for');
		field.focus();
		return;
	} // if (!search>' ')
	form.docs.value = method;
	if (ok)
		form.submit();
	else
		alert('You have submitted the search form to searh for\n  "'
			+ search + '"\nwith multiple words/phrases combined with "' + method
			+ '".\n\nHowever, the search facility is not yet implemented.');
} // function submitSearchForm()

function onfocusSearch(field) {
	if (field.style.color!=searchInputColor) {
		field.style.color=searchInputColor;
		field.value = '';
	} // if (field.style.color!=searchInputColor)
} // function onfocusSearch()


function onblurSearch(field) {
	if (field.value=='') {
		field.style.color=searchMsgColor;
		field.value = searchMsg;
	} // if (field.style.color!=searchInputColor)
} // function onblurSearch()

function Offset(offsetLeft, offsetTop) {
// creates an Offsets object
	this.offsetLeft = offsetLeft;
	this.offsetTop = offsetTop;
} // function Offsets()

function getOffset(element) {
// element is either an HTML element object or an HTML element ID.
// The function returns an Offsets object, or Boolean false if the offsets
// could not be determined.
var e = element;
	if (typeof(element)=='string'&&document.getElementById)
		element = document.getElementById(element);
	if (typeof(element)!='object'||typeof(element.offsetParent)!='object')
		return false;
	var offsetLeft=0, offsetTop=0;
	do {
		offsetLeft += element.offsetLeft;
		offsetTop += element.offsetTop;
		element = element.offsetParent;
	} while(element);
// alert('getOffset'+'\n'+e+'\n'+offsetLeft+','+offsetTop);
	return new Offset(offsetLeft,offsetTop);
} // function getOffset()
