SearchSelect = Class.create({
  initialize: function(){
    this.locID      = null;
    this.tableDB    = null;
    this.prefixDB   = null;
    this.tableName  = null;  
    this.prefixName = null;
    this.parentNane = null; 
    this.tables     = new Array();

    this.tables['country'] = 'region';
    this.tables['region']  = 'city';
    
  }, //initialize
  
  getLocation: function( id, table, prefix, parent, size, selected ){
    var self = this;

    var requestParams = {
      method: 'GET',
      onComplete: function() {
        if ( this.transport.status == 200 ) {
          var resXML = this.transport.responseXML;
          root = resXML.getElementsByTagName( 'root' )[0];
          self.tableName  = table;
          self.prefixName = prefix;
          self.parentName = parent; 

          self.showLocation( root.getElementsByTagName( 'element' ), id, table, prefix, size, selected );
        } // if
      } // onComplete
    } // var requestParams
    
    var url = '/inc/list_location.xml?location=' + id + '&table=' + table + '&prefix=' + prefix + '&parent=' + parent;
    new Ajax.Request( url, requestParams );
    
  }, //getLocation
  
  showLocation: function( locationList, id, table, prefix, size, selectValue ){
    var self = this;   
    
    if ( locationList.length != 0 ) {
      
      objTable = _obj_( 'tabid' );
        tr = addRow( objTable );
        tr.id = table;
          tdText = addCell( tr );
          
          if ( table == 'region' )
            tdText.innerHTML = 'òÅÇ¦ÏÎ';
          else tdText.innerHTML = 'í¦ÓÔÏ / ëÕÒÏÒÔ';  
         
          tdText.width = 80; 
          tdText.style.color = '#797979'
          td = addCell( tr );
            select = document.createElement( 'SELECT' );
        
            select.id = 'select' + id;
            select.name = 'select' + id ;
            select.style.width = '160px';
            select.onchange = function() {
              self.locID    = this.value;
              self.tableDB  = table;
              self.prefixDB = prefix;
              
              _obj_( table + 'ID' ).value = this.value;
              
              if ( self.table != 'city' ) {
            
                if ( _obj_( self.tables[table] ) != undefined ) {
                  removeObjById( self.tables[table] );
                  self.region = this.value;
                } else {  
                  self.getLocation( this.value, 'city', 'ci', 'r', 0 );
                } // if ( _obj_( self.tables[table] ) != undefined ) 
                
              } // if ( self.table != 'city' ) 
              
            } // if ( this.value !+ 0 )
            
            
          td.appendChild( select );
            options = _obj_( 'select' + id );
            if ( size== 0 )
              options.options[0] = new Option( "- ×Ói -", 0 );
            if ( locationList.length != 0 ) {
              for ( i = 0; i < locationList.length; i++ ) {
                if ( size != 0 ) ind = i; else  ind = i + 1;
                options.options[ind] = new Option( locationList[i].firstChild.nodeValue, locationList[i].attributes[0].nodeValue );
                if ( options.options[ind].value == selectValue ) options.options[ind].selected = true;
              }
            }
    }
  }, //showLocation 
  
  
  clear: function(){
    if ( _obj_( 'region' ) != undefined ) removeObj( _obj_( 'region' ) )
    if ( _obj_( 'city' )   != undefined ) removeObj( _obj_( 'city' ) ) 
  } //clear  
  
});
