function navmenuHighlight() {
	if (document.getElementById("websiteLocation")) {
		var locationToHighlight = document.getElementById("websiteLocation").name;
		document.getElementById(locationToHighlight).style.color = "#ffffff";
	}
}

function stopBannerOverlap() {
	if (document.getElementById("interimnav")) {
//if IE
		if (document.all) {
			if (document.body.clientWidth < 923) {
				document.getElementById("header").style.backgroundPosition = "491px 0px";
				if (document.getElementById("dzSearch")) {
					document.getElementById("dzSearch").style.backgroundPosition = (938 - document.body.clientWidth) + "px 0px";
				}
			}
			else {
				document.getElementById("header").style.backgroundPosition = "right top";
				if (document.getElementById("dzSearch")) {
					document.getElementById("dzSearch").style.backgroundPosition = "-4px 0px";
				}
			}
		}
//if not IE
		else {
			document.body.style.overflow = "hidden";
			withoutScrollbar = document.body.clientWidth;
			document.body.style.overflow = "auto";
			scrollbarWidth = withoutScrollbar - document.body.clientWidth;
			if (window.innerWidth < 923) {
				document.getElementById("header").style.backgroundPosition = "491px 0px";
				if (scrollbarWidth == 0) {
					if (document.getElementById("dzSearch")) {
						document.getElementById("dzSearch").style.backgroundPosition = (938 - window.innerWidth) + "px 0px";		
					}
				}
				else {
					document.getElementById("dzSearch").style.backgroundPosition = (938 + scrollbarWidth - window.innerWidth) + "px 0px";			
				}
			}
			else {
				document.getElementById("header").style.backgroundPosition = "right top";
				if (document.getElementById("dzSearch")) {
					document.getElementById("dzSearch").style.backgroundPosition = "-4px 0px";
				}
			}		
		}
	}
}

function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
	return false;
}

/*
*
*	Checkbox tools
*
*/
function checkAllCheckboxesInFieldSet(name) {
	var name, o, i, inputs;
	o = document.getElementById(name);
	inputs = o.getElementsByTagName("input");
	for (i = 0; i < inputs.length; i++) {
		if (inputs[i].type = "checkbox") {
			inputs[i].checked = true;
		}
	}
}
function unCheckAllCheckboxesInFieldSet(name) {
	var name, o, i, inputs;
	o = document.getElementById(name);
	inputs = o.getElementsByTagName("input");
	for (i = 0; i < inputs.length; i++) {
		if (inputs[i].type = "checkbox") {
			inputs[i].checked = false;
		}
	}
}
function invertAllCheckboxesInFieldSet(name) {
	var name, o, i, inputs;
	o = document.getElementById(name);
	inputs = o.getElementsByTagName("input");
	for (i = 0; i < inputs.length; i++) {
		if (inputs[i].type = "checkbox") {
			inputs[i].checked = !inputs[i].checked;
		}
	}
}
/*
*
*	Image rollovers
*
*/
function findimg() {
	var imgs,i,preload,src,ftype,newsrc;
	// Loop through all images, check if they contain the class roll
	preload = new Array;
	imgs=document.getElementsByTagName('img');
	for(i=0;i<imgs.length;i++) {
		if(/roll/.test(imgs[i].className)) {
			// check src and preload the rollover
			src = imgs[i].src;
			ftype = src.substring(src.lastIndexOf('.'), src.length);
			if(/_on/.test(src)) {
				newsrc = src.replace('_on','');
			} else {
				newsrc = src.replace(ftype, '_on'+ftype);
			}
			preload[i] = new Image;
			preload[i].src = newsrc;
			// add the function roll to the parent Element of the image
			imgs[i].parentNode.onmouseover=function(){roll(this);};
			imgs[i].parentNode.onmouseout=function(){roll(this);};
			//imgs[i].parentNode.onfocus=function(){roll(this);};
			//imgs[i].parentNode.onblur=function(){roll(this);};
		}
	}
}

function roll(o) {
	var i,isnode,src,ftype,newsrc,nownode;
	// loop through all childNodes
	for (i=0;i<o.childNodes.length;i++) {
		nownode=o.childNodes[i];
		// if the node is an element and an IMG set the variable and exit the loop
		if(nownode.nodeType==1 && /img/i.test(nownode.nodeName)) {
			isnode=i;
			break;
		}
	}
	// check src and do the rollover
	src = o.childNodes[isnode].src;
	ftype = src.substring(src.lastIndexOf('.'), src.length);
	if(/_on/.test(src)) {
		newsrc = src.replace('_on','');
	} else {
		newsrc = src.replace(ftype, '_on'+ftype);
	}
	o.childNodes[isnode].src=newsrc;
}

addEvent(window, 'load', findimg);

/*
*
* Suckerfish Dropdowns
*
*/

function suckerfish(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
	}
}

sfHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

sfFocus = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}

sfActive = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmousedown=function() {
			this.className+=" sfactive";
		}
		sfEls[i].onmouseup=function() {
			this.className=this.className.replace(new RegExp(" sfactive\\b"), "");
		}
	}
}

sfTarget = function(sfEls) {
	var aEls = document.getElementsByTagName("A");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i];
				aEls[j].onclick = function() {
					if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
					if (this.targetEl) this.targetEl.className+=" sftarget";
					document.lastTarget=this.targetEl;
					return true;
				}
			}
		}
	}
}

suckerfish(sfHover, "LI", "nav");

/*
*
* Search Box stuff
*
*/

function addField (form, fieldType, fieldName, fieldValue) {
	if (document.getElementById) {
		var input = document.createElement('INPUT');
			if (document.all) { // what follows should work with NN6 but doesn't in M14
				input.type = fieldType;
				input.name = fieldName;
				input.value = fieldValue;
			}
			else if (document.getElementById) { // so here is the NN6 workaround
				input.setAttribute('type', fieldType);
				input.setAttribute('name', fieldName);
				input.setAttribute('value', fieldValue);
			}
		form.appendChild(input);
	}
}

function do_search(o) {
	params = new Array;

	// Weblinks
	params['KC'] = new Array
	params['KC']['action'] = "/infoservices/cgi-bin/knowledge/search.cgi";
	params['KC']['method'] = "post";
	params['KC']['name'] = "query";

	// Library Catalogue
	params['LIB'] = new Array
	params['LIB']['action'] = "/infoservices/catalogue/search.php?ccsForm=Search";
	params['LIB']['method'] = "post";
	params['LIB']['name'] = "s_Keywords";

	// PIRNC
	params['PIRNC'] = new Array
	params['PIRNC']['action'] = "/infoservices/pirnc/project_list.php";
	params['PIRNC']['method'] = "get";
	params['PIRNC']['name'] = "s_keyword";

	// Jobs
	params['JOBS'] = new Array
	params['JOBS']['action'] = "/infoservices/cgi-bin/jobs/search.cgi";
	params['JOBS']['method'] = "post";
	params['JOBS']['name'] = "query";

	// Glossary
	params['GLOS'] = new Array
	params['GLOS']['action'] = "/infoservices/glossary/index.php?ccsForm=acrSrch";
	params['GLOS']['method'] = "post";
	params['GLOS']['name'] = "sAcr";

	selected = o.to.options[document.dzSearch.to.selectedIndex].value;
	o.action = params[selected]['action'];
	o.method = params[selected]['method'];

	// This adds an input field with the right name for the target form.
	if(params[selected]['name'] != "query") {
		addField (o, 'hidden', params[selected]['name'], o.query.value);
	}

	// ## This alternate code changes the name of the main input
	//  Will interfere with back button operation.  i.e. won't remember non-links query terms.
	/*
	if (document.all) {
		document.dzSearch.query.name = params[selected]['name'];
	} else if (document.getElementById) { // so here is the NN6 workaround
		document.dzSearch.query.setAttribute('name', params[selected]['name']);
	}
	//  ##
	*/

	// Add any optional fields.
	if (params[selected]['options']) {
		for (var word in params[selected]['options']) {
			addField (document.dzSearch, 'hidden', word, params[selected]['options'][word]);
		}
	}
	//  These don't work. Where are x and y coming from?
	// removeField(document.dzSearch, 'x');
	// removeField(document.dzSearch, 'y');
	// removeField(document.dzSearch, 'to');

	return;
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
  }
  else if (document.all)
  {
	this.obj = document.all[name];
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
  } 
  else 
  {
    return false;
  }

   return this.obj;
}


function utf(letter) {
	return letter.toString(16);
}


function macrons(obj) {
//  convert iso encoded macron strings to utf characters

if(obj.length == 0) { return; }

if (/\&\#[2|3]\d\d\;/g, obj.value) {
text = obj.value;
text = text.replace(/\&\#256\;/g, utf('\u0100'));
text = text.replace(/\&\#257\;/g, utf('\u0101'));
text = text.replace(/\&\#274\;/g, utf('\u0112'));
text = text.replace(/\&\#275\;/g, utf('\u0113'));
text = text.replace(/\&\#298\;/g, utf('\u012A'));
text = text.replace(/\&\#299\;/g, utf('\u012B'));
text = text.replace(/\&\#332\;/g, utf('\u014C'));
text = text.replace(/\&\#333\;/g, utf('\u014D'));
text = text.replace(/\&\#362\;/g, utf('\u016A'));
text = text.replace(/\&\#363\;/g, utf('\u016B'));
obj.value = text;
return obj;

} 
return;

}