
function doSiteSearch() {
  // Called when site users clic the "GO" button/lin next to the search field above-right each page
  var frm = document.forms['frmTopSearch'];
  var s = frm.elements['query'];
  if (s.value=='') return false; 
  else frm.submit()
}

function hasValue(value) {
	if ((value != null) && (value != "") && !isblank(value))  return true;
	else return false;
}

function isblank(s){
	for (var i=0; i<s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}
  
function setColor(e, bg) {
  if (e.style) e.style.backgroundColor = bg;
}

function doBorder(img, bdrColor) {
 if (img.style) eval("img.style.borderColor = '" + bdrColor + "';")
} 

function loseBorder(img) {
 if (img.style) img.style.borderColor = 'white';
}

function doMsg() {
 alert("\nThis page will be available soon\n");
}
  
function openPlainWindow(url,width,height,winName) {
  var top = (screen.height - height)/2;
  var left = (screen.width - width)/2;
  var winProps = 'height='+height+',width='+width+',scrollbars=no,top='+top+',left='+left;
  window.open(url,winName,winProps);
}

function parseQueryString (str) {
/*  Puts querystring arguments into a hash
	Usage:  
	var args = parseQueryString (); alert(qsArgs[varName]);   	// display single variable
	for (var arg in qsArgs) alert(arg + ' = ' + qsArgs[arg]);		// display all variables 	*/
  str = str ? str : location.search;
  var query = str.charAt(0) == '?' ? str.substring(1) : str;
  var args = new Object();
  if (query) {
    var fields = query.split('&');
    for (var f = 0; f < fields.length; f++) {
      var field = fields[f].split('=');
	  if (field[0] && field[1]) {
	      args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
	  }
    }
  }
  return args;
}

function highlightPageInLeftMenu(menuID) {
  /* Highlights the current page in the left hand-side menu. It first looks for the menu specified by the 'menuID' parameter. Then
	   it gets all links contained within the menu and cycles through them, looking for a link that matches the current page URL.
	   If it finds a match, it adds a class name of "selected-menu-item" to the matching link (which effectively highlights the
	   current page within the left menu). */
  var thisPage = location.href.toLowerCase()
  if (document.getElementById) {
  // Is there a left menu?
    var leftMenu;
	eval('leftMenu = document.getElementById("'+menuID+'")')
	if ((typeof leftMenu != "undefined") && leftMenu) {
  	// Get all links in the left hand-side menu
	  var menuLinks = leftMenu.getElementsByTagName("A");
	  if (typeof menuLinks != "undefined") {
	    // cycle through the array of links
		for (var i=0; i<menuLinks.length; i++) {
			// highlight the link with the same HREF attribute as the current page
			var thisLink = menuLinks[i].href.toLowerCase();
			if (thisPage.indexOf(thisLink)>-1) 
			    menuLinks[i].className += " selected-menu-item";
			
			if (thisLink.indexOf("/pages/our-people/our-researchers.asp")>-1 && thisPage.indexOf("/pages/our-people/researcher-news/")>-1) 
	            menuLinks[i].className += " selected-menu-item";		
		}
	  }
	}
  }
}

function addEvent(o,e,f){
  if (o.addEventListener) {
    o.addEventListener(e,f,true);
	return true;
  }
  else if (o.attachEvent) {
    return o.attachEvent("on"+e,f);
  }
  else {
    return false;
  }
}

/* Use the 2 functions below to generate random hex colours */
function convertToHex(num) {
	strHexNum = num.toString(16).toUpperCase();
	if (strHexNum.length == 1) strHexNum += "0";
	return (strHexNum);
}

function getRandomColor() {
	return ("#" + convertToHex(Math.floor((255*Math.random()))) + convertToHex(Math.floor((255*Math.random()))) + convertToHex(Math.floor((255*Math.random()))) );
}