/*
 * General utils for dom malipulation.
 * This is intented to be replaced by prototype.js once this it is 
 * able to be used throughout the application.
 * The current barrier to this is incompatiablity between the commons validation
 * JS and prototype.js.
 */
 
 /*
  * getElementById for all modern browsers an IE 4.
  * prototype method: $()
  */
 function elementById(id){
 	if( typeof id == 'string' ){
	 	if( document.getElementById ){
	 		return document.getElementById(id);
	 	}else if( document.all ){
	 		return document.all[id];
	 	} //else the result is null
 	} else {
 		// if not a string return the element
	 	return id ;
 	}
 }
 
 /*
  * Shows a previously hidden element.
  * prototype method: Element.show()
  */
 function showElement(id){
 	return elementById(id).style.display = '';
 }

 /*
  * Hides a given element.
  * prototype method: Element.hide()
  */
 function hideElement(id){
 	return elementById(id).style.display = 'none';
 }
 
 /*
  * highlights table rows , and makes them clickable
  */
   function highlightTableRows(tableId) {
    var previousClass = null;
    var table = document.getElementById(tableId); 
	if(table!=null){
    var tbody = table.getElementsByTagName("tbody")[0];
    if (tbody == null) {
        var rows = table.getElementsByTagName("tr");
    } else {
        var rows = tbody.getElementsByTagName("tr");
    }
    // add event handlers so rows light up and are clickable
    for (i=0; i < rows.length; i++) {
        rows[i].onmouseover = function() { 
			previousClass=this.className;
			this.className='over' ;
		};
        rows[i].onmouseout = function() { 
			this.className=previousClass;
		};

        rows[i].onclick = function() {
            var cell = this.getElementsByTagName("td")[0];
            var link = cell.getElementsByTagName("a")[0];
            location.href = link.getAttribute("href");
            this.style.cursor="wait";
        }
    }
  }
}