// Awsome non-obtrusive script that highlights all text input fields in a page based on a CSS class.
// Script found at http://kalsey.com/2006/07/highlighting_form_fields_with_unobtrusive_javascript/

/******
  REQUIRES: class_manipulation.js (can be found at http://snippets.dzone.com/posts/show/2630)
  This was added to work with jQuery validation scripts.
  This change by Keith Wolf - keith@wolfster.net
******/

function initHighlightInput() {
    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 () {AddClassName(this, 'highlightActiveField');}
            field.onblur = function () {RemoveClassName(this, 'highlightActiveField');}
        }
    }
    var allfields = document.getElementsByTagName("textarea");
    // loop through all textarea tags and add events (should be identical instructions to the above loop for text fields)
    for (var i=0; i<allfields.length; i++){
			var field = allfields[i];
					field.onfocus = function () {AddClassName(this, 'highlightActiveField');}
					field.onblur = function () {RemoveClassName(this, 'highlightActiveField');}
    }
}



// Nifty function to add onload events without overwriting
// ones already there courtesy of the lovely and talented
// Simon Willison http://simon.incutio.com/
function addLoadEvent(func) {   
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }
}

addLoadEvent(initHighlightInput);

