var colorful = new ColorfulInput;
window.onload = function() {
    colorful.set();
}
function ColorfulInput() {
  // 処理をスキップしたい属性
  this.skip = ['button','checkbox','radio','search','submit','select-one'];
  // 処理をスキップしたいid
  this.skip_id = ['#'];
  this.color = { 'blur': '', 'focus': '#f5f5f5' };
  this.set = function() {
    var i;
    for (i = 0; i < document.forms.length; i++) {
      for (var f = 0; f < document.forms[i].length; f++) {
        var elm = document.forms[i][f];
        if(!this._checkSkip(elm)) continue;
        this._setColor(elm, 'focus');
        this._setColor(elm, 'blur');
      }
    }
  };
  this._checkSkip = function(elm) {
    var i;
    for(i in this.skip) {
      if(elm.type == this.skip[i]) return false;
    }
    for(i in this.skip_id) {
      if(elm.id == this.skip_id[i]) return false;
    }
    return true;
  };
  this._setColor = function(elm, type) {
    var i;
    var color = this.color[type];
    var event = function() {
      elm.style.backgroundColor = color;
    };
    if(elm.addEventListener) {
      elm.addEventListener(type, event, false);
    } else if(elm.attachEvent) {
      elm.attachEvent('on'+type, event);
    } else {
      elm['on'+type] = event;
    }   
  };   
}
