var DISABLED_COLOR = "#CCCCCC";
var ENABLED_COLOR = "#FFFFFF";

var ie = document.all;

function mySelect(form, id) {

  this.select = document.forms[form][id];
  this.clear = mySelect_clear;
  this.add = mySelect_add;
  this.insert = mySelect_insert;
  this.selected = mySelect_selected;
  this.selectedIndex = mySelect_selectedIndex;
  this.length = mySelect_length;
  this.enable = mySelect_enable;
  this.remove = mySelect_remove;
  this.options = mySelect_options;
  this.selectByValue = mySelect_selectByValue;
  this.setValue = mySelect_setValue;
  this.multiSelected = mySelect_multiSelected;

}

function mySelect_clear() {

  this.select.options.length = 0;

}

function mySelect_add(text, value) {

  var idx = this.select.options.length;
  this.select.options.length++;
  this.select.options[idx].value = value;
  this.select.options[idx].text = text;

  return this.select.options[idx];
}

function mySelect_insert(text, value, position)
{
        this.select.options.length++;

        for(i=position+1; i<this.select.options.length; i++)
        {
                this.select.options[i].value = this.select.options[i-1].value;
                this.select.options[i].text = this.select.options[i-1].text;
        }

        this.select.options[position].value = value;
        this.select.options[position].text = text;
}

function mySelect_selected() {
    var idx = this.select.options.selectedIndex;

        return idx>-1 ? this.select.options[idx].value : '';
}

function mySelect_selectedIndex(idx) {
    if(idx != null)
            this.select.options.selectedIndex = idx;

        return this.select.options.selectedIndex;
}

function mySelect_length() {
        return this.select.options.length;
}

function mySelect_enable(bEnable) {
    if(ie) {
                this.select.style.backgroundColor = bEnable ? ENABLED_COLOR : DISABLED_COLOR;
        }
        this.select.disabled = !bEnable;
}

function mySelect_remove(idx) {
        var selectedIndex = this.select.options.selectedIndex;

        if(selectedIndex>idx) {
                this.select.options.selectedIndex = selectedIndex-1;
        }

        var len = this.select.options.length;
        var itm = 0;
        for(var i=0;i<len;i++) {
            if(i!=idx) {
                        this.select.options[itm].value = this.select.options[i].value;
                        this.select.options[itm].text = this.select.options[i].text;
                        itm++;
                }
        }
        if(itm<len) {
                this.select.options.length = len-1;
        }
}

function mySelect_options(idx) {
        return this.select.options[idx];
}

function mySelect_selectByValue(val) {
        for(var i=0;i<this.select.options.length;i++) {
                if(this.select.options[i].value==val) {
                        this.select.selectedIndex = i;
                        return i;
                }
        }
        return -1;
}

function mySelect_setValue(Value) {
        this.select.Value = Value;
}

function mySelect_multiSelected() {
    var selection = [];
        for(var i=0;i<this.select.options.length;i++) {
            var option = this.select.options[i];
                if( option.selected )
                        push( selection, option.value );
        }
        return selection;
}

function myInput(form, id) {
        this.input = document.forms[form][id];

        this.enable = myInput_enable;
        this.setValue = myInput_setValue;
        this.getValue = myInput_getValue;
        this.getChecked = myInput_getChecked;
        this.setChecked = myInput_setChecked;
}

function myInput_enable(bEnable) {
    if(ie) {
                this.input.style.backgroundColor = bEnable ? ENABLED_COLOR : DISABLED_COLOR;
        }
        this.input.disabled = !bEnable;
}

function myInput_setValue(text) {
        this.input.value = text;
}

function myInput_getValue() {
        return this.input.value;
}

function myInput_getChecked() {
        return this.input.checked;
}

function myInput_setChecked(check) {
        this.input.checked = check;
}