var CoupledCombos = {

  createOption: function( text, page, list )
  {
    var option = new Option( text );
    option.page = page;
    option.list = list;
    return option;
  },


  fillComboWithOptions: function( id, list ) 
  {
    this.changeComboOptions( document.getElementById( id ), list );
  },


  changeComboOptions: function( combo, list ) 
  {
    while( combo.options.length > 0 )
    {
      combo.options[ 0 ] = null;
    }

    combo.disabled = list == null || list.length == 0;
    if( !combo.disabled )
    {
      for( var i = 0; i < list.length; i++ ) 
      {
        combo.options[ i ] = list[ i ];
      }
      combo.options[ 0 ].selected = true;
    }

    this.comboSelectionChanged( combo );
  },


  comboSelectionChanged: function( src )
  {
    var bind = src.getAttribute( 'bind' );
    if( bind != null )
    {
      var option = ( src.selectedIndex >= 0 ) ? src.options[ src.selectedIndex ] : null;
      this.fillComboWithOptions( bind, ( option != null ) ? option.list : null ); 
    }
  }

}