function _dataAccess()
{
  /**
   *  Propriedades da Classe
   *  ======================================================================= //
   */
  this.buffer = '';
  this.dbGrid = '';
  this.loginUSER = '';
  this.root = _getPathUnit("rpcStudio.js");
  this.path = this.root.substr(0, this.root.indexOf('lib_JS') ) + 'core/';

  this.setDBgrid = function( txt )
  {
    this.dbGrid = txt;
  }
  this.addBuffer = function( txt )
  {
    this.buffer += txt;
  }
  this.echo = function( nObj )
  {
    var objDOM = findDOM( nObj, 0 );

    objDOM.innerHTML = this.buffer;
    this.buffer = '';
    
    if( this.dbGrid != '' )
    {
      dbGrid_refresh( this.dbGrid );
    }//
  }

/**
 *  send()
 */
  this.send = function( txt )
  {
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._send",
                           "dataAccess.set_path",
                           txt,
                           false );
    //alert('send[ ' + this.path + ' ]');
  }
  this._send = function( text, callId  )
  {
    alert( text + " return");
  }// End this._send = function( text, callId  )
  
/**
 *  teste()
 */
  this.teste = function( txt )
  {
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._teste",
                           "dataAccess.teste",
                           txt,
                           false );
    //alert('teste ['+this.path+'] 1: ' + txt);
  }
  this._teste = function( text, callId )
  {
    arr = text.split( '#' );
    if( arr[0] == '1')
    {
      alert( 'back: ' + text );
    }else
    {
      alert( 'back:[Error] ' + arr[2] );
    }// End if( arr[0] == '1')
  }

/**
 *  Atualiza o Registro Corrente
 */
  this.upDate = function( txt )
  {
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._upDate",
                           "dataAccess.up_date",
                           txt,
                           false);
//    alert('tst 2: ' + this.path );
//    alert('send cmd[ ' + txt + ' ]');
  }
  
  this._upDate = function( text, callId )
  {
    //alert( 'ret2: ' + text );
  }

  this.getResult = function( txt )
  {
    //alert('getFields' + this.path );
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._getResult",
                           "dataAccess.get_result",
                           txt,
                           false);
//alert('tst 1: ' + this.path );
//alert('send cmd[ ' + txt + ' ]');
  }
  
  this._getResult = function( list, callId )
  {
//alert( 'ret: '+ list );
    nrLine = list.length;
    nObj   = list[0];
//    arrLinha = new Array(1);
//alert( nObj+' '+arrLinha);
    if( nObj.substr( 0, 4 ) == 'erro' )
    {
      //alert( 'ret2: ' + nObj );
    }else
    {
//alert('ok : '+list);
      var objDOM = findDOM( nObj, 0 );
      var tmp = '  <tbody>';

      for( nlin_ = 1; nlin_ < nrLine; nlin_ ++ )
      {
        linha = list[ nlin_ ];
        arrLinha = linha.split( '#' );
        nrField = arrLinha.length;
//alert(arrLinha[1]);
        tmp += '  <tr id="' + nObj + '_tit">';

        tmp += '    <th id="' + nObj + '_th_' + nlin_ + '" class="' + nObj + '_tit">';
        tmp += '      <span id="' + nObj + '_num_' + nlin_ + '"';
        tmp += '            class="' + nObj + '_col">&nbsp;' + nlin_ + '&nbsp;</span>';
        tmp += '    </th>';
        
        ixx = 0;
        ix_obj = getDBgrid_index( nObj );
        for( ix = 0; ix < dbgrid_nr_coluna[ ix_obj ]; ix++ )
        {
          temp_ = arrLinha[ix];
          arrField = temp_.split( ':' );
          tpoField = arrField[0];
          namField = arrField[1];
          valField = arrField[2];
          tipoField = 'field';

          switch( tpoField )
          {
            case 'C':
              formula = valField;
              //valField = 'teste';
              tipoField = 'calculado';
              break;
            case 'L':
              valField = 'teste';
              valField  = arrField[2];
              tipoField = 'lookup';
              break;
            default:
              valField  = arrField[2];
              tipoField = 'field';
              break;
          }
          ixx ++;
          tmp += '    <td id="' + nObj + '_td_' + nlin_ + '_' + ixx + '">';
          tmp += '      <input id="' + nObj + '_col_' + nlin_ + '_' + ixx + '"';
          tmp += '             type="text" readOnly="true"';
          tmp += '             class="' + nObj + '_col_' + ixx + '"';
          tmp += '             colName="' + namField + '"  ';
          tmp += '             colTipo="' + tipoField + '"  ';
          tmp += '             tipoDado=""  ';
          tmp += '             value="' + valField + '" />';

          if( tpoField == 'C' )
          {
            tmp += '    <span id="' + nObj + '_formula_' + nlin_ + '_' + ixx + '"';
            tmp += '        class="' + nObj + '_formula">';
            tmp += formula;
            tmp += '    </span>';
          }// End

          tmp += '    </td>';
        }// End for( ix = 0; ix < nrField; ix++ )
        tmp += '  </tr>';
      }// End
      
//alert(arrLinha);
      tmp += '  </tbody>';
      tmp += '</table>';
      tmp += '<input id="'+nObj+'_nrLinhas" type="hidden" value="'+(nlin_-1)+'" />';

// inclui a alinha de inclusão
      tmp += '';
      tmp += '<table id="' + nObj + '_insert" cellpadding="2" cellspacing="1">';
      tmp += '  <tr>';
      tmp += '    <th id="' + nObj + '_th_0" class="' + nObj + '_tit">';
      tmp += '      <span id="' + nObj + '_num_0" class="' + nObj + '_col">';
      tmp += '        &nbsp;&nbsp;&nbsp; ';
      tmp += '      </span>';
      tmp += '    </th>';
      tmp += ' ';

      ixx = 0;
      ix_obj = getDBgrid_index( nObj );
      for( ix = 0; ix < dbgrid_nr_coluna[ ix_obj ]; ix++ )
      {
        temp_ = arrLinha[ix];
        value_ = '';
        arrField = temp_.split( ':' );
        tpoField = arrField[0];
        namField = arrField[1];
        valField = arrField[2];
        tipoField = 'field';

        ixx ++;
        tmp += '    <td id="' + nObj + '_td_0_' + ixx + '">';
        tmp += '      <input id="' + nObj + '_col_0_' + ixx + '"';

        switch( tpoField )
        {
          case 'C':
            formula = valField;
            value_ = ' ';
            tipoField = 'calculado';
            tmp += '        type="text" readOnly="true"';
            tmp += '        disabled';
            break;
          case 'L':
            formula = '';
            value_ = ' ';
            tipoField = '';
            tmp += '        type="text" readOnly="true"';
            tmp += '        disabled';
            break;
          default:
            value_  = ' ';
            tipoField = 'field';
            tmp += '        type="text"';
            break;
        }// End switch( tpoField )

        tmp += '             class="' + nObj + '_col_' + ixx + '"';
        tmp += '             colName="' + namField + '"  ';
        tmp += '             colTipo="' + tipoField + '"  ';
        tmp += '             tipoDado=""  ';
        tmp += '             value="'+value_+'" />';
        tmp += '    </td>';
      }// End for( ix = 0; ix < nrField; ix++ )

      tmp += '';
      tmp += '  </tr>';
      tmp += '</table>';

      this.addBuffer( tmp );
      this.echo( nObj );
      dbGrid_refresh( nObj );
//alert('ok:'+nObj);

    }// End if( nObj.substr( 0, 4 ) == 'erro' )
  }// End this._getResult = function( list, callId )



/**
 *  Solicita o valor de um campo da Tabela
 */
  this.getField_value = function( txt )
  {
    //alert('getFields' + this.path );
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._getField_value",
                           "dataAccess.get_field_value",
                           txt,
                           false);
    //alert('tst 1: ' + this.path );
    //alert('send cmd[ ' + txt + ' ]');
  }
  this._getField_value = function( value, callId )
  {
    //alert( value );
    arr = value.split( '#' );
    //alert( arr );
    if( arr[0] == '1' )
    {
      obj = arr[1];
      //alert( arr[1] );
      //alert( arr[2] );
      if( obj.indexOf('dbedit') != -1 )
      {
        setDBedit_value( arr[1], arr[2] );
      }
      if( obj.indexOf('dbtext') != -1 )
      {
        setDBtext_value( arr[1], arr[2] );
      }
    }else
    {
      alert( 'Erro[getField] ' + arr[2] );
      
    }// End

  }// End function




/**
 *  Solicita a lista de Campos
 */
  this.getFields = function( txt )
  {
    //alert('getFields' + this.path );
    var cmd = loginUSER + ':' + txt;
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._getFields",
                           "dataAccess.get_fields",
                           cmd,
                           false);
//alert('tst 1: ' + this.path );
//    alert('send cmd[ ' + cmd + ' ]');
  }
  this._getFields = function( field, callId )
  {
    var tmp = '';
    nrField = field.length;
    nObj  = field[0];
//alert('fields: '+field);
    if( nObj.substr( 0, 4 ) == 'erro' )
    {
      alert( 'ret2:: ' + nObj );
    }else
    {
      var objDOM = findDOM( nObj, 0 );
      var tmp = '';
//alert(nObj);
      tmp += '<table id="' + nObj + '_table" cellpadding="2" cellspacing="1">';
      tmp += '  <thead>';
      tmp += '  <tr id="' + nObj + '_tit">';
      tmp += '    <th id="' + nObj + '_th" class="' + nObj + '_tit">';
      tmp += '      <span id="' + nObj + '_num" class="' + nObj + '_col">';
      tmp += '        &nbsp; &nbsp; ';
      tmp += '      </span>';
      tmp += '    </th>';

      for( ix = 1; ix < nrField; ix++ )
      {
        tmp += '    <th id="' + nObj + '_th_' + ix + '" class="' + nObj + '_tit">';
        tmp += '      <input id="' + nObj + '_tit_' + ix+'" type="text" readOnly="true"';
        tmp += '             value="'+field[ix] + '" class="' + nObj + '_col_' + ix+'">';
        tmp += '    </th>';
      }
      tmp += '  </tr>';
      tmp += '</thead>';
//      tmp += '';
//      tmp += '';
//      tmp += '';
//      tmp += '</table>';
//alert(tmp);
      this.addBuffer( tmp );
    }// End if( nObj.substr( 0, 4 ) == 'erro' )
  }// End function

/**
 *  Atualizar/Incluir registro
 */
  this.setRecord = function( txt )
  {
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._setRecord",
                           "dataAccess.set_record",
                           txt,
                           false);
    //alert('send cmd[ ' + txt + ' ]');
  }
  this._setRecord = function( result, callId )
  {
//alert( 'result: '+result );
    if( result.indexOf( 'erro' ) != -1 )
    {
      //alert( result );
    }else
    {
      resetDBgrid( result );
    }
  }// End

/**
 *  Executa uma query
 */
  this.execSql = function( txt )
  {
    var callId = jsrsCall( this.path + "rpcServer.dataAccess.php",
                           "dataAccess._execSql",
                           "dataAccess.exec_sql",
                           txt,
                           false);
//alert('send cmd[ ' + txt + ' ]');
  }
  this._execSql = function( result, callId )
  {
    setLabel_texto( "label1", result );
//alert( 'ret: '+result );
  }


}// End function _dataAccess()


var dataAccess = new _dataAccess(); // Pseudo static
