  Browser      = new DetectBrowser();
  DisabledList = new Array(0);
  ValuesList   = new Array(0);
  FocusList   = new Array(0);
  DisBut = new Array();
  EnableBkgrColor="#7599CC";

  if (Browser.nav4) {
    window.captureEvents(Event.MOUSEOUT);
    window.onmouseout = mouseoutHandler;
    window.captureEvents(Event.KEYUP);
    window.onkeyup    = clearDisabled;
  }

  function mouseoutHandler(e) {
    var control = e.target;
    var index   = findDisabled(control);
    if(index >= 0) {
      control.value = ValuesList[index];
    }
  }


  function DetectBrowser()
  {
    var agt=navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav5up = (this.nav && (this.major >= 5));
    this.ie   = (agt.indexOf("msie") != -1);
    this.ie4  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")==-1) );
    this.ie4up  = (this.ie  && (this.major >= 4));
    this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);
  }


  function setState(button, lEnable) {
    if (!Browser.nav4) {
      if (!button.disabled && button.currentStyle && button.currentStyle.backgroundColor){
              EnableBkgrColor= button.currentStyle.backgroundColor;
      }
      button.disabled  = !lEnable;
      if( button.type!="checkbox" ) {
        if (lEnable) {
          button.style.backgroundColor   = EnableBkgrColor;
          button.style.color             = "#ffffff";
        } else {
          button.style.backgroundColor   = "#CCCCCC";
          button.style.color             = "#999999";
        }
      }
    } else {
      if (lEnable) {
        delBut(button);
        button.onfocus     = null;
        button.onmousedown = function() { return true; };
        if(DisBut.length<1) window.releaseEvents( Event.CLICK );
      } else {
        if(findBut(button) < 0) {
          DisBut.push(button);
        }
        button.onfocus     = button.blur;
        button.onmousedown = function() { return false; };
        window.captureEvents( Event.CLICK );
        window.onclick = setState.onDown;
      }
    }
  }

      setState.onDown = function(e)
    {
        var ibut=findBut(e.target);
        if (ibut>-1)  return false;
        else routeEvent(e);
    }

    function findBut(control){
      var ind=-1;
    for(var j=0; j<DisBut.length; j++) {
      if(DisBut[j] == control) {
        ind = j;
        break;
      }
    }
    return ind;
    }

    function delBut(ctrl){
    for(var k=0; k<DisBut.length; k++) {
      if(DisBut[k] == ctrl) {
        DisBut.splice(k,1);
        break;
      }
    }
    }


  function setControlState(control, lEnable) {
    if (!control) return;
    if (!Browser.nav4) {
      control.disabled  = !lEnable;
    } else {
      var index = findDisabled(control);
      if(lEnable) {
        if(index >= 0) {
          if(control.type.indexOf("select") >= 0) {
            control.onchange = ValuesList[index];
          }
          control.onfocus = FocusList[index];
          deleteFromList(index,1);
        }
      } else {
        if(index < 0) {
          insertInList(control);
          control.onfocus =  function() { control.blur(); };
          if(control.type.indexOf("select") >= 0) {
            control.onchange = function() { control.options[0].selected = true; };
          }
        }
      }
    }
  }

  function findDisabled(control) {
    var index = -1;
    for(var i=0; i<DisabledList.length; i++) {
      if(DisabledList[i] == control) {
        index = i;
        break;
      }
    }
    return index;
  }

  function clearDisabled() {
    var index;
    var control;
    for(var i=0; i<DisabledList.length; i++) {
      control       = DisabledList[i];
      control.value = ValuesList[i];
    }
  }

  function insertInList(control) {
    DisabledList.push(control);
    var value = (control.type.indexOf("select") < 0 ? control.value : control.onchange);
    var fvalue = control.onfocus;
    ValuesList.push(value);
    FocusList.push(fvalue);
  }

  function deleteFromList(index) {
    DisabledList.splice(index,1);
    ValuesList.splice(index,1);
    FocusList.splice(index,1);
  }


