/*---------------
SelectBox
----------------*/
function SelectOption(parentValue, text, value, style) {

  this.parentValue = parentValue;

  this.setOption = function() {
    this.text = text;
    this.value = value;
    if(style) {
      this.style.cssText = style;
    }
  };

  return this;
}

function SelectBox(id) {
  
  function getObject() {
    var obj = document.getElementById(id);
    if(!obj.options && ( (typeof obj.length) == "number") ) {
      if(obj.length > 0) {
        obj = obj[0];
      } else {
        obj = null;
      }
    }
    return obj;
  }
  

  var options = [];

  this.registOption = function(option) {
    options[options.length] = option;
  };

  var child = null;

  this.setChild = function(childObj) {
    child = childObj;
  };

  this.make = function(parentValue) {
    var obj = getObject();
    if(obj) {

      obj.options.length = 0;

      var opt = (parentValue != null) ? [] : options;
      if(parentValue != null) {
        for(var i = 0; i < options.length; i++) {
          if( (options[i].parentValue == null) || (options[i].parentValue == parentValue) ) {
            opt[opt.length] = options[i];
          }
        }
      }

      obj.options.length = opt.length;
      for(var i = 0; i < opt.length; i++) {
        opt[i].setOption.call(obj.options[i]);
      }

      if(child) {
        child.make(obj.value);
      }
    }
  };
  
  return this;
}
