<script language="javascript">
<?php
  include( create_dbNavigator_control( $modo_RAD ) );
?>

/**
 *  dbNavigator_mouseClick()
 */
  function dbNavigator_mouseClick( objID )
  {
//alert('dbn: '+getDbNavigator_enable( objID ));
    if( objID.indexOf('dbnavigator') != -1 )
    {
      if( getDbNavigator_enable( objID ) )
      {
        var btn      = getDbNavigator_button( objID );
        var idx_nav  = getDbNavigator_index( objID );
        var dataSet  = dbnavigator_dataset[ idx_nav ];
        var idx_grid = false;
        // get ID do DbGrid
        for( nrG=0; nrG < dbgrid_obj; nrG++ )
        {
          if( dataSet == dbgrid_dataset[nrG] )
          {
            idx_grid = nrG;
            dbGrid = dbgrid_ID[ nrG ];
            atual = dbgrid_linha_corrente[ nrG ];
          }// End if( dataSet == dbgrid_dataset[nrG] )
        }// End for( nrG=0; nrG < dbgrid_obj; nrG++ )
//alert('atual: '+atual);
//alert('dbGrid: '+dbGrid);
        switch( btn )
        {
          case 'insert':
            setDBgrid_nova_linha( dbGrid );
            setDbNavigator_post( idx_nav, true );
            break;
          case 'prior':
            if( atual > 1 )
            {
              setDBgrid_linha_off( idx_grid );
              setDBgrid_linha_on( idx_grid, --atual );
                
              setDbNavigator_next( idx_nav, true );
              setDbNavigator_last( idx_nav, true );
              if( atual == 1 )
              {
                setDbNavigator_first( idx_nav, false );
                setDbNavigator_prior( idx_nav, false );
              }// End if( atual == 1 )
            }// End if( atual > 1 )
            break;
          case 'next':
            if( atual < getDBgrid_nr_linhas(dbGrid) )
            {
              setDBgrid_linha_off( idx_grid );
              setDBgrid_linha_on( idx_grid, ++atual );
              setDbNavigator_first( idx_nav, true );
              setDbNavigator_prior( idx_nav, true );
              if( atual == getDBgrid_nr_linhas(dbGrid) )
              {
                setDbNavigator_next( idx_nav, false );
                setDbNavigator_last( idx_nav, false );
              }// End if( atual == getDBgrid_nr_linhas(dbGrid) )
            }// End if( atual < getDBgrid_nr_linhas(dbGrid) )
            break;
          case 'first':
            setDBgrid_linha_off( idx_grid );
            setDBgrid_linha_on( idx_grid, 1 );
            
            setDbNavigator_first( idx_nav, false );
            setDbNavigator_prior( idx_nav, false );
            setDbNavigator_next( idx_nav, true );
            setDbNavigator_last( idx_nav, true );
            break;
          case 'last':
            if( atual < getDBgrid_nr_linhas(dbGrid) )
            {
              setDBgrid_linha_off( idx_grid );
              atual = getDBgrid_nr_linhas(dbGrid);
              setDBgrid_linha_on( idx_grid, atual );
              setDbNavigator_first( idx_nav, true );
              setDbNavigator_prior( idx_nav, true );
              setDbNavigator_next( idx_nav, false );
              setDbNavigator_last( idx_nav, false );
            }// end if( atual < getDBgrid_nr_linhas(dbGrid) )
            break;
          case 'delete':
            setDBgrid_delete_linha( dbGrid );
            resetDBgrid( dbGrid );
            break;
          case 'edit':
            setDBGrid_edit_line( dbGrid, true );
            setDbNavigator_post( idx_nav, true );
            break;
          case 'post':
            setDBgrid_post( dbGrid );
            setDbNavigator_post( idx_nav, false );
            break;
          case 'refresh':
            resetDBgrid( dbGrid );
            break;
          case 'cancel':
            setDBGrid_edit_line( dbGrid, false );
            delDBgrid_nova_linha( dbGrid );
            setDbNavigator_post( idx_nav, false );
            break;
        }// End switch( btn )
      }// End if( getDbNavigator_enable( objID ) )
    }// End if( objID.indexOf('dbnavigator') != -1 )

  }// End function dbNavigator_mouseClick( objID )

/**
 *  dbNavigator_mouseDown()
 */
  function dbNavigator_mouseDown( objID )
  {
    if( objID.indexOf('dbnavigator') != -1 )
    {
//alert(objID);
    }
  }// End function()

/**
 *  dbNavigator_mouseUp()
 */
  function dbNavigator_mouseUp( objID )
  {
    if( objID.indexOf('dbnavigator') != -1 )
    {

    }
  }// End function()

/**
 *  dbNavigator_mouseOver()
 */
  function dbNavigator_mouseOver( objID )
  {
    if( objID.indexOf('dbnavigator') != -1 )
    {

    }
  }// End function()

/**
 *  dbNavigator_mouseOut()
 */
  function dbNavigator_mouseOut( objID )
  {
    if( objID.indexOf('dbnavigator') != -1 )
    {

    }
  }// End function()


//  ------------------------------------------------------------  //
//  Lista de Métodos do Componente                                //
//  Conjunto de funções para manipular as propriedades do Objeto  //
//  ------------------------------------------------------------  //

/**
 *  seta o Buttom post (Post) para o status desejado
 */
  function setDbNavigator_post( idx_nav, status )
  {
    iix = parseInt(idx_nav)+1;
    if( iix > 0 )
    {
      nObj_nav = 'dbnavigator'+iix+'_post';
      dbnDOM = findDOM( nObj_nav,0 );
//alert('dbn: '+nObj_nav+' :: '+dbnDOM+' = '+status);
      set_Status( dbnDOM, status );
    }// End if( iix > 0 )
  }// End function setDbNavigator_post( idx_nav, status )
/**
 *  seta o Buttom first (primeiro) para o status desejado
 */
  function setDbNavigator_first( idx_nav, status )
  {
    iix = parseInt(idx_nav)+1;
    if( iix > 0 )
    {
      nObj_nav = 'dbnavigator'+iix+'_first';
      dbnDOM = findDOM( nObj_nav,0 );
      set_Status( dbnDOM, status );
    }// End if( iix > 0 )
  }// End function setDbNavigator_first( idx_nav, status )
/**
 *  seta o Buttom prior (anterior) para o status desejado
 */
  function setDbNavigator_prior( idx_nav, status )
  {
    iix = parseInt(idx_nav)+1;
    if( iix > 0)
    {
      nObj_nav = 'dbnavigator'+iix+'_prior';
      dbnDOM = findDOM( nObj_nav,0 );
      set_Status( dbnDOM, status );
    }//
  }//
/**
 *  seta o Buttom next (proximo) para o status desejado
 */
  function setDbNavigator_next( idx_nav, status )
  {
    iix = parseInt(idx_nav)+1;
    if( iix > 0 )
    {
      nObj_nav = 'dbnavigator'+iix+'_next';
      dbnDOM = findDOM( nObj_nav,0 );
      set_Status( dbnDOM, status );
    }// End if( iix > 0 )
  }// End function setDbNavigator_next( idx_nav, status )
/**
 *  seta o Buttom last (último) para o status desejado
 */
  function setDbNavigator_last( idx_nav, status )
  {
    iix = parseInt(idx_nav)+1;
    if( iix > 0 )
    {
      nObj_nav = 'dbnavigator'+iix+'_last';
      dbnDOM = findDOM( nObj_nav,0 );
      set_Status( dbnDOM, status );
    }// End if( iix > 0 )
  }// End function setDbNavigator_last( idx_nav, status )

  
  function setDbNavigator_enable( objID, status )
  {
    dbnDOM = findDOM( objID,0 );
//    dbnStyle = findDOM( objID,1 );
    set_Status( dbnDOM, status );
  }// End function setDbNavigator_enable( objID )

function set_Status( dbnDOM, status )
{
//alert(typeof(dbnDOM));
//alert( dbnDOM.id );
  if( typeof(dbnDOM) == 'object' )
  {
    if( status || status == 'true' )
    {
      dbnDOM.disabled = false;
      dbnDOM.style.borderTop    = '2px outset ButtonHighlight';
      dbnDOM.style.borderLeft   = '2px outset ButtonHighlight';
      dbnDOM.style.borderBottom = '2px inset ButtonShadow';
      dbnDOM.style.borderRight  = '2px inset ButtonShadow';
    }else
    {
      dbnDOM.disabled = true;
      dbnDOM.style.border = '2px solid #B0B0B0';
    }// End if( status || status == 'true' )
  }// End if( typeof(dbnDOM) == 'object' )
  
}// End function set_Status( dbnDOM, status )



  function getDbNavigator_enable( objID )
  {
    dbnDOM = findDOM( objID,0 );
    if( dbnDOM.disabled )
    {
      ret = false;
    }else
    {
      ret = true;
    }
    return ret;
  }//


/**
 *  retorna o indice do dbNavigator
 */
  function getDbNavigator_index( objID )
  {
    ret = null;
    ix  = 0;
    if( objID.indexOf('dbnavigator') != -1 )
    {
      ix = objID.indexOf('_');
      if( ix != -1 )
      {
        idx = objID.slice( 11, ix );
      }else
      {
        idx = objID.slice( 11 );
      }// End
      ret = parseInt( idx ) -1;
    }// End
    return ret;
  }// End function getDbNavigator_index( objID )
  
/**
 *  retorna o Button do dbNavigator
 */
  function getDbNavigator_button( objID )
  {
    ret = null;
    ix  = 0;
    if( objID.indexOf('dbnavigator') != -1 )
    {
      ix  = objID.indexOf('_');
      ret = objID.slice( ix +1 );
    }// End
    return ret;
  }// End function getDbNavigator_buttom( objID )




  function dbNavigator_mouseClick_old( objID )
  {
    if( objID.indexOf('dbnavigator') != -1 )
    {
      if( getDbNavigator_enable( objID ) )
      {
        //alert('dbNavigator: '+objID);
        idx_nav = getDbNavigator_index( objID );
        dataSet = dbnavigator_dataset[ idx_nav ];

        // get ID do DbGrid
        nrGrid = dbgrid_obj;
        for( nrG=0; nrG< nrGrid; nrG++ )
        {
          if( dataSet == dbgrid_dataset[nrG] )
          {
            idx_grid = nrG;
          }
        }
//alert(idx_grid);
        //
        for( nr = 0; nr < dbgrid_obj; nr++ )
        {
          if( dataSet == dbgrid_dataset[ nr ] )
          {
            //alert( getDbNavigator_buttom( objID ) );
            //buttom = getDbNavigator_buttom( objID );
            dbGrid = dbgrid_ID[ nr ];
            atual = dbgrid_linha_corrente[ nr ];
//alert(getDbNavigator_buttom( objID ));
            switch( getDbNavigator_buttom( objID ) )
            {
              case 'first':
                setDBgrid_linha_off( idx_grid );
                setDBgrid_linha_on( idx_grid, 1 );

                setDbNavigator_first( idx_nav, false );
                setDbNavigator_prior( idx_nav, false );
                setDbNavigator_next( idx_nav, true );
                setDbNavigator_last( idx_nav, true );
                break;
              case 'prior':
                if( atual > 1 )
                {
                  setDBgrid_linha_off( idx_grid );
                  setDBgrid_linha_on( idx_grid, --atual );

                  setDbNavigator_next( idx_nav, true );
                  setDbNavigator_last( idx_nav, true );
                  if( atual == 1 )
                  {
                    setDbNavigator_first( idx_nav, false );
                    setDbNavigator_prior( idx_nav, false );
                  }// End
                }// End
                break;
              case 'next':
                if( atual < getDBgrid_nr_linhas(dbGrid) )
                {
alert('next: ' + atual);
//                  setDBgrid_linha_off( idx_grid );
//                  setDBgrid_linha_on( idx_grid, ++atual );

//                  setDbNavigator_first( idx_nav, true );
//                  setDbNavigator_prior( idx_nav, true );
//                  if( atual == getDBgrid_nr_linhas(dbGrid) )
//                  {
//                    //setDbNavigator_enable( objID, false );
//                    setDbNavigator_next( idx_nav, false );
//                    setDbNavigator_last( idx_nav, false );
//                  }
                }// End if( next < getDBgrid_nr_linhas(dbGrid) )
                break;
              case 'last':
                if( atual < getDBgrid_nr_linhas(dbGrid) )
                {
                  setDBgrid_linha_off( idx_grid );
                  atual = getDBgrid_nr_linhas(dbGrid);
                  setDBgrid_linha_on( idx_grid, atual );

                  setDbNavigator_first( idx_nav, true );
                  setDbNavigator_prior( idx_nav, true );
                  setDbNavigator_next( idx_nav, false );
                  setDbNavigator_last( idx_nav, false );

                }// end if( atual < getDBgrid_nr_linhas(dbGrid) )
                break;
              case 'insert':
                setDBgrid_nova_linha( dbGrid );
                setDbNavigator_post( idx_nav, true );
                break;
              case 'delete':
                setDBgrid_delete_linha( dbGrid );
//alert('delete');
                resetDBgrid( dbGrid );
                break;
              case 'edit':
                setDBGrid_edit_line( dbGrid, true );
                setDbNavigator_post( idx_nav, true );
                break;
              case 'post':
                setDBgrid_post( dbGrid );
                setDbNavigator_post( idx_nav, false );
//alert('post');
//                resetDBgrid( dbGrid );
                break;
              case 'refresh':
                resetDBgrid( dbGrid );
                //setDBgrid_linha_on( idx_grid, atual )
//alert('refresh');
                //dbGrid_refresh( dbGrid );
                break;
              case 'cancel':
                setDBGrid_edit_line( dbGrid, false );
                delDBgrid_nova_linha( dbGrid );
                setDbNavigator_post( idx_nav, false );
                //alert('refresh');
                //dbGrid_refresh( dbGrid );
                break;
            }// End switch( getDbNavigator_buttom( objID ) )
          }// End if( dataSet == dbgrid_dataset[ nr ] )
        }// end for( nr = 0; nr < dbgrid_obj; nr++ )
      }// End if( getDbNavigator_enable( objID ) )
    }// End if( objID.indexOf('dbnavigator') != -1 )
//alert('postEnd');
  }// End function()

</script>
