// Some simple code to loop through all forms on the page and set any
// text entry inputs to highlight when they are active.

function initHighlights() {
	for(var i=0; i < document.forms.length; i++) {
		for(var j=0; j < document.forms[i].elements.length; j++) {
			if(document.forms[i].elements[j].type == "text" || document.forms[i].elements[j].type == "textarea" || document.forms[i].elements[j].type == "password") {
				document.forms[i].elements[j].oldfocus = document.forms[i].elements[j].onfocus;
				document.forms[i].elements[j].oldblur = document.forms[i].elements[j].onblur;
				document.forms[i].elements[j].onfocus = function () {this.className = this.className + ' highlight'; if(typeof this.oldfocus == 'function') return this.oldfocus();};
				document.forms[i].elements[j].onblur = function () {this.className = this.className.replace(/highlight/gi, ''); if(typeof this.oldblur == 'function') return this.oldblur();};
			}
		}
	}
}

// Adds a function to the onload event of the page

function addLoadEvent(func) {   
  var oldonload = window.onload;
  if (typeof window.onload != 'function'){
    window.onload = func;
  } else {
    window.onload = function(){
      oldonload();
      func();
    }
  }
}

addLoadEvent(initHighlights);
