if (window.attachEvent) {
  window.attachEvent("onload", setListeners);
} else if (window.addEventListener) {
  window.addEventListener("load", setListeners, false);
}

function setListeners(){
  var inputList = document.getElementsByTagName("INPUT");
  var selectList = document.getElementsByTagName("SELECT");
  if (window.attachEvent) {
    attachEventToElements(inputList);
    attachEventToElements(selectList);
  } else if (window.addEventListener) {
    addEventListenerToElements(inputList);
    addEventListenerToElements(selectList);
  }
}

function attachEventToElements(list){
  for (var i=0; i<list.length; i++) {
    if (list[i].style.backgroundColor) {
       list[i].style.backgroundColor = "";
    }
    list[i]["backgroundColorOnLoad"] = list[i].style.backgroundColor;
    list[i].attachEvent("onpropertychange", restoreStyles);
  }
}

function addEventListenerToElements(list){
  for (var i=0; i<list.length; i++) {
    if (list[i].style.backgroundColor) {
       list[i].style.backgroundColor = "";
    }
    list[i]["backgroundColorOnLoad"] = list[i].style.backgroundColor;
    list[i].addEventListener("DOMAttrModified", restoreStyles, false);
  }
}

function restoreStyles(evt){
  var input;
  if (evt.currentTarget && evt.attrName == "style") {
    input = evt.currentTarget;
  } else if (evt.srcElement && evt.propertyName == "style.backgroundColor") {
    input = evt.srcElement;
  }
  if (input) {
    if (input.style.backgroundColor != input["backgroundColorOnLoad"]) {
      input.style.backgroundColor = input["backgroundColorOnLoad"];
    }
  }
}
