var id = 0;
var brandID = 0;

function delObject( id ) {
  removeObjById( id );
  obj( 'button' ).style.display = 'none';
  return false;
}

function selectValue( id ) {
  brandID = id;
}

function goSubCategory() {
  if ( id != 0 ) {
    location.replace( "/production/subcategory" + id + "/goods/" );          
  }
}

function goBrand( ) {
  if ( brandID != '0' ) {
    location.replace( "/production/goods" + brandID + "/" );          
    return false;
  }
} 

function createSelect( list, defaultOption ) {
  if ( list.length !=0 ) {
    td = obj( 'iddiv' );
    select = document.createElement( 'SELECT' );
    select.id = 'select';
    select.name = 'select';
    select.style.width = '155px';
    td.appendChild( select );
                     
    select.onchange = function() {
      id = this.value;  
    }
    optionList = obj( 'select' );
    optionList.options[0] = new Option( defaultOption, 0 ); 
    for ( i = 0; i < list.length; i++ ) {
      optionList.options[i+1] = new Option( list[i].firstChild.nodeValue, list[i].attributes[0].nodeValue );
    }
    obj( 'button' ).style.display = 'inline';
  }
  return false;
}

function load( id, defaultOption ) {
  if ( obj( 'select') != null ) {
    delObject( 'select' )
  }
  req = new BGRequest();
  req.open( "GET", "/production/subcategory_list.xml?id=" + id );
    req.onComplete = function() {
      xmlText = req.responseText;
      xmlDoc = XMLDocument( xmlText );
      root = xmlDoc.getElementsByTagName( 'root' )[0];
      list = root.getElementsByTagName( 'option' );
      createSelect( list, defaultOption );
    }
  req.send();
}