function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function initHighlight() {
    if (!document.getElementsByTagName){ return; }
    var allfields = document.getElementsByTagName("input");
    // loop through all input tags and add events
    for (var i=0; i<allfields.length; i++){
        var field = allfields[i];
        if ((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password") ) {
            field.onfocus = function () {
            	this.style.backgroundColor = "#ffffff";
            }
            field.onblur = function () {
            	this.style.backgroundColor = "#f3f3f3";
            }
        }
    }
    var allselects = document.getElementsByTagName("select");
    for (var k=0; k<allselects.length; k++){
		allselects[k].onfocus = function () {
			this.style.backgroundColor = "#ffffff";
		}
		// IE7 doesn't like onfocus for selects - requires double click
		// instead must use onfocusin 
		allselects[k].onfocusin = function () {
			this.style.backgroundColor = "#ffffff";
		}
		allselects[k].onblur = function () {
			this.style.backgroundColor = "#f3f3f3";
		}
    }
    var alltextareas = document.getElementsByTagName("textarea");
    // loop through all input tags and add events
    for (var m=0; m<alltextareas.length; m++){
        alltextareas[m].onfocus = function () {
			this.style.backgroundColor = "#ffffff";
		}
		alltextareas[m].onblur = function () {
			this.style.backgroundColor = "#f3f3f3";
		}
    }
}
addLoadEvent(initHighlight);