// Generic start-up handler. // This function can be used to add events to the // Window on-load event. // Usage: addLoadEvent(nameOfSomeFunctionToRunOnPageLoad); // addLoadEvent(function() { // more code to run on page load // }); function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } /* Function: XBrowserAddHandler * @author: Jim Donnell * @date: March 2006 * @comments: XBrowserAddHandler provides a browser agnostic way to add event handlers using the DOM 2 * The code below was originally taken from this page: http://weblogs.asp.net/asmith/archive/2003/10/06/30744.aspx * I modified it significantly because it didn't work for me using the code and example. * I also removed the originalHandler part because I didn't think it was important */ function XBrowserAddHandler(obj,eventName,handlerName) { if ( obj.addEventListener ) { // Check if Mozilla / W3C Compatible Browser obj.addEventListener(eventName, handlerName, false); // Add the event listener } else if ( obj.attachEvent ) { // Check if IE obj.attachEvent("on" + eventName, handlerName); // Add the event listener } else { alert("Sorry, your browser is not supported and may not function correctly."); } } /* Function: getCommonObj * @author: Jim Donnell * @date: March 2006 * @returns: The object on which the event occurred. * @comments: This function coverts the event object into a common object whose attributes can be * accessed in a browser agnostic "standard" way. * * This function should be called from the event handler to convert the event object into a common * object. * * Ex: * function someEventHandler(evt) { * var commonObj = getCommonObj(evt); * alert("commonObj.value=" + commonObj.value); * } */ function getCommonObj(evt){ var ieEventName = "srcElement"; // IE event object extension "evt.srcElement" var mozEventName = "target"; // Moz event object extension "evt.target" if(evt[mozEventName]){ // Assign the correct extension and return. return evt[mozEventName]; }else{ return evt[ieEventName]; } } // Found this function at http://www.degraeve.com/reference/simple-ajax-example.php // I'm not sure how the "this" part works but it seems too and be pretty clean. // This is the basic AJAX call functionality. // @param strURL - The URL of the servlet that will handle the request and return the // results. // @param queryStr - The query string attributes to pass to the servlet. // @param handler - The name of the function that will handle the return // from the servlet. function xmlhttpPost(strURL, queryStr, handler) { // alert("In xmlhttpPost"); var xmlHttpReq = false; var self = this; // Mozilla/Safari if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } // IE else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } self.xmlHttpReq.open('POST', strURL, true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { // call the callBack handler handler(self.xmlHttpReq.responseText); } } self.xmlHttpReq.send(queryStr); } /** // Get a browser neutral XMLHttpRequest object. // This commented out because I'm not using it right now // but it is good example code. function getXmlHttpObj() { var xmlHttpReq; // Mozilla/Safari if (window.XMLHttpRequest) { xmlHttpReqObj = new XMLHttpRequest(); } // IE else if (window.ActiveXObject) { xmlHttpReqObj = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlHttpReqObj; } */ // *************************************************************************************** // Search Table Functions // *************************************************************************************** /** * This array is used to remember mark status of rows in browse mode */ var marked_row = new Array; /** * enables highlight and marking of rows in data tables * */ function markRowsInit() { // alert("In markRowsInit!"); // for every table row ... var rows = document.getElementsByTagName('tr'); for ( var i = 0; i < rows.length; i++ ) { // ... with the class 'odd' or 'even' ... if ( 'odd' != rows[i].className && 'even' != rows[i].className ) { continue; } // ... add event listeners ... // ... to highlight the row on mouseover ... if ( navigator.appName == 'Microsoft Internet Explorer' ) { // but only for IE, other browsers are handled by :hover in css rows[i].onmouseover = function() { this.className += ' hover'; } rows[i].onmouseout = function() { this.className = this.className.replace( ' hover', '' ); } } // ... and to mark the row on click ... rows[i].onmousedown = function() { // alert("Mouse down on row " + i); var unique_id; var checkbox; checkbox = this.getElementsByTagName( 'input' )[0]; if ( checkbox && checkbox.type == 'checkbox' ) { unique_id = checkbox.name + checkbox.value; } else if ( this.id.length > 0 ) { unique_id = this.id; } else { return; } if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) { marked_row[unique_id] = true; } else { marked_row[unique_id] = false; } if ( marked_row[unique_id] ) { this.className += ' marked'; } else { this.className = this.className.replace(' marked', ''); } if ( checkbox && checkbox.disabled == false ) { checkbox.checked = marked_row[unique_id]; } } // ... and disable label ... var labeltag = rows[i].getElementsByTagName('label')[0]; if ( labeltag ) { labeltag.onclick = function() { return false; } } // .. and checkbox clicks var checkbox = rows[i].getElementsByTagName('input')[0]; if ( checkbox ) { checkbox.onclick = function() { // opera does not recognize return false; this.checked = ! this.checked; } } } } /** * marks all rows and selects its first checkbox inside the given element * the given element is usaly a table or a div containing the table or tables * * @param container DOM element */ function markAllRows( container_id ) { var rows = document.getElementById(container_id).getElementsByTagName('tr'); var unique_id; var checkbox; for ( var i = 0; i < rows.length; i++ ) { checkbox = rows[i].getElementsByTagName( 'input' )[0]; if ( checkbox && checkbox.type == 'checkbox' ) { unique_id = checkbox.name + checkbox.value; if ( checkbox.disabled == false ) { checkbox.checked = true; if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) { rows[i].className += ' marked'; marked_row[unique_id] = true; } } } } return true; } /** * marks all rows and selects its first checkbox inside the given element * the given element is usaly a table or a div containing the table or tables * * @param container DOM element */ function unMarkAllRows( container_id ) { var rows = document.getElementById(container_id).getElementsByTagName('tr'); var unique_id; var checkbox; for ( var i = 0; i < rows.length; i++ ) { checkbox = rows[i].getElementsByTagName( 'input' )[0]; if ( checkbox && checkbox.type == 'checkbox' ) { unique_id = checkbox.name + checkbox.value; checkbox.checked = false; rows[i].className = rows[i].className.replace(' marked', ''); marked_row[unique_id] = false; } } return true; }