function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}


function hideItems(id, tag, className) {
	var els = getElementsByClassName(document, tag, className);
	for(var i = 0; i<els.length; i++) {
		els[i].style.display = els[i].id == id ? "block" : "none";
	}
	return(els);
}

function tableHighlight () {

	// check page has a table before looking for table rows	
	if (document.getElementsByTagName('tbody').length > 0) {
	
	// Grab all elements with <tr> tag and puts them in a list minus the thead row)	
	var rows = document.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
 ;
	
 //	Loop through all elements of that list
		for(var i = 0; i < rows.length; i++) {
	
		 // In the onmouseover event apply the highlighting class (defined in stylesheet)  
			rows[i].onmouseover = function() {
				this.className += ' tr-highlight';
				}
			
		 // In the onmouseout event 'remove' the highlighting class
			rows[i].onmouseout = function() {
				this.className = this.className.replace('tr-highlight', '');
				}
		}
	}
}

function trainingHighlight () {
	
	// search all divs
	var trows = document.getElementsByTagName('div');
		// loop thru all divs and set a variable to check classname
		for(var i = 0; i < trows.length; i++) {
			
			var trowclass = trows[i].className;
		
		//check classname for... if found change style on mouseover and mouseout
		if (trowclass == 'training-one') {
			trows[i].onmouseover = function() {
			this.className += ' training-highlight ';
			}
			trows[i].onmouseout = function() {
				this.className = this.className.replace('training-highlight', '');
			}
		}
		
		//as above for other class
		if (trowclass == 'training-two') {
			trows[i].onmouseover = function() {
			this.className += ' training-highlight ';
			}
			trows[i].onmouseout = function() {
				this.className = this.className.replace('training-highlight', '');
			}
		}
	}
}

function linksDisplay () {
	// search all divs
	var links = document.getElementsByTagName('div');
		// loop thru all divs and set a variable to check classname
		for(var i = 0; i < links.length; i++) {
			
			var linksclass = links[i].className;
			
			if (linksclass == 'useful-links') {
				links[i].onmouseover = function() {
				this.className += ' useful-link-details ';
				}
				links[i].onmouseout = function() {
					this.className = this.className.replace('useful-link-details', 'useful-links');
				}
			}
			
			if (linksclass == 'useful-links-stripe') {
				links[i].onmouseover = function() {
				this.className += ' useful-link-details ';
				}
				links[i].onmouseout = function() {
					this.className = this.className.replace('useful-link-details', 'useful-links');
				}
			}
		}
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(tableHighlight);
addLoadEvent(trainingHighlight);
addLoadEvent(linksDisplay);
