


    function onTableClick(mEvent) {
        if (!document.forms[0]) return;
        var ele = mEvent.srcElement;
        if (!ele) ele = mEvent.target;
        var tab = getTable(ele);
        if (!tab) return;

        var id = tab.id;
        if (!id) {
         	alert("oa.js Error: table does not have the ID attribute set - needs to match name of OADataTable when added to OAForm.");
         	return;
        }

        if (!id) return;
        while (ele && ele.tagName!="TABLE" && ele.tagName!="INPUT") {
           var value = ele.getAttribute("oaValue");
           if (ele.className == "oaColumnCommand") break;
           if (value) {
	          if (!document.forms[0].oaTableName || !document.forms[0].oaTableCommand) {
	          	alert("oa.js Error: this page does not have hidden form controls oaTableName, oaTableCommand");
	          	break;
	          }
              document.forms[0].oaTableName.value = id;
              document.forms[0].oaTableCommand.value = value;
			  //alert("onTableClick " + document.forms[0].elements["oaTableName"].value + ", " + document.forms[0].elements["oaTableCommand"].value);
              document.forms[0].submit();
              break;
          }
          ele = ele.parentNode;
        }
    }

    function onTableMouseOut(ele) {
		if (lastRow) {
	        lastRow.className = lastRowClassName;
		}
		if (true) return;
		
        var tab = getTable(ele);
        if (tab) {
            if (tab.getAttribute("holdRow")) {
                var row = tab.getAttribute("holdRow");
                row.className = tab.getAttribute("holdClassName");
                tab.removeAttribute("holdRow");
            }
        }
    }

	var lastRow;
	var lastRowClassName;
	
    function onTableMouseOver(mEvent) {
        document.forms[0].oaTableName.value = "";
        document.forms[0].oaTableCommand.value = "";
        var ele = mEvent.srcElement;
        if (!ele) ele = mEvent.target;
       
        onTableMouseOut(ele);
        // first find the TR that has "oaValue" attribute set.
        while (ele && (!ele.tagName ||  ele.tagName.toUpperCase()!="TR"))
        {
            ele = ele.parentNode;
        }
    
        if (ele && ele.getAttribute("oaValue")) {
             var tab = getTable(ele);
             // tab.setAttribute("holdRow", ele);
             // tab.setAttribute("holdClassName", ele.className);

			 lastRow = ele;
			 lastRowClassName = ele.className;

             ele.className = 'oaTableOver';
        }
    }

    function getTable(ele) {
        while (ele && (!ele.className || ele.className.toUpperCase()!="OATABLE" || !ele.tagName || ele.tagName.toUpperCase()!="TABLE"))
        {
            ele = ele.parentNode;
        }
        return ele;
    }


	function onDataTableCheckBoxEvent(mEvent) {
        var ele = mEvent.srcElement;
        if (!ele) ele = mEvent.target;
		var chked = ele.checked;
		var table = getTable(ele);
		
       	var theForm = ele.form, z = 0;
	 	for(z=0; z<theForm.length;z++){
	      	if (theForm[z] != ele && theForm[z].type == 'checkbox'){
	      		if (getTable(theForm[z]) == table) {
		  			theForm[z].checked = chked;
		  		}
	  		}
		}	  	
	}



	/////////////////////////////////////////////////////
	// This function is used to find the first descendant with the specified tag name.
	/////////////////////////////////////////////////////
	function findNode(startingNode, tagName)
	{
		  // on Firefox, the <td> node might not be the firstChild node of the <tr> node
		  myElement=startingNode;
		  var i=0;
		  while (myElement && (!myElement.tagName || (myElement.tagName && myElement.tagName!=tagName)))
		  {
		    myElement=startingNode.childNodes[i++];
		  } 
		  if (myElement && myElement.tagName && myElement.tagName==tagName)
		  {
		    return myElement;
		  }
		  // On Internet Explorer, the <tr> node might be the firstChild node of the <tr> node 
		  else if (startingNode.firstChild)
		    return findNode(startingNode.firstChild, tagName);
		  return 0;
	}



	/*** Code for popup ============================== **/

	var lastPopup;
	function showPopup(myEvent, divElementId) {
		var popup = getElement(divElementId);
		if (!popup) return;
	
		popup.style.visibility='hidden';	
		var x = myEvent.clientX;

		// more browser fun, see: www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
		var x = myEvent.clientX;
		var x2 = 0; 
		if (window.pageXOffset)  x2 = window.pageXOffset;
		else if (document.documentElement) x2 = document.documentElement.scrollLeft;
		else if (document.body) x2 = document.body.scrollLeft;
		x += x2;

		var y = myEvent.clientY;
		var y2 = 0; 
		if (window.pageYOffset)  y2 = window.pageYOffset;
		else if (document.documentElement) y2 = document.documentElement.scrollTop;
		else if (document.body) y2 = document.body.scrollTop;
		y += y2;

		// make adjustment so that the element will be on top of the window, so that mouseout event wont be called.
		x -= 7;
		y -= 7;

		popup.style.left = x;
		popup.style.top = y;
	
		popup.style.visibility='visible';
		lastPopup = popup;
	}
	function hidePopup() {
		if (lastPopup) lastPopup.style.visibility='hidden';
	}	

	function showIt(elementId) {
		var ele = getElement(elementId);
		if (!ele) return;
		ele.style.visibility = 'visible';
	}
	function hideIt(ele) {
		if (ele) ele.style.visibility = 'hidden';
	}


	function getElement(myId) {
	   if (document.getElementById(myId)) {
	     return document.getElementById(myId);
	   }
	   else {
	     return window.document[myId]; 
	   }     
	}












