<?php 
  function create_button( $button,
                          $button_Conf )
  {
    $tab_index = $button_Conf['tab_index'];
    $caption   = $button_Conf['caption'];
    if( $button_Conf['enabled'] == 'true' )
    {
      $enabled = "";
    }else
    {
      $enabled = "disabled";
    }// End if( $button_Conf['enabled'] == 'true' )

    
    $caption = $button_Conf[ 'caption' ];
    if ( $button_Conf[ 'alt_key' ] !== 'null' ||
         $button_Conf[ 'alt_key' ] !== ''     ||
         !empty( $button_Conf[ 'alt_key' ])
        )
    {
      $str = strtolower($caption);
      $ix = strpos( $str, $button_Conf[ 'alt_key' ] );
      if( $ix !== false )
      {
        //$ix = strpos( $str, $button_Conf[ 'alt_key' ] );
        // echo($ix);
        if( $ix == 0 )
        {
          $caption = '<span class="'.$button.'_key">' .
                     substr( $caption, 0, 1)
                     . '</span>' . substr( $caption, $ix +1 );
        }else
        {
          $caption = substr( $caption, 0, $ix )
                     . '<span class="'.$button.'_key">' .
                     substr( $caption, $ix, 1 )
                     . '</span>' . substr( $caption, $ix+1 );
        }// End
      }// End if( $ix = strpos( $str, $button_Conf[ 'alt_key' ] ) !== false )
    }// End if ( $button_Conf[ 'alt_key' ] == 'null' )


    //$caption = $button_Conf[ 'caption' ];
    //$caption = '<span class="'.$button.'_em">T</span>estando';
    
    writeTO( '<button id="' . $button . '_Caption" tabindex="'.$tab_index.'"' );
    writeTO( '        accesskey="' . $button_Conf[ 'alt_key' ] . '" '        );
    writeTO( '        class="button_Caption" '. $enabled. '>' );

    writeTO( '  ' . $caption . ' ' );
    writeTO( '</button end="' . $button . '_Caption">' );
  }// End create_button()
  

/**
 *  function create_button_css()
 */
  function create_button_css( $button,
                              $button_Global,
                              $button_Style,
                              $button_Conf,
                              $flag_button )
  {
    global $projeto,
           $esquema,
           $modo_RAD;

    if( $modo_RAD )
    {
      $visible = 'inherit';
    }else
    {
      $visible = ( $button_Global['visibility'] == 'true' ) ? 'inherit':'hidden';
    }// End
    $bold = ( $button_Conf['bold'] == 'true' ) ? 'bold':'normal';
    $tipo = $button_Conf['tipo_button'];
//    $bgColor = $esquema[$projeto['esquema']]['ButtonFace'];
    
    if( $button_Conf['font_family'] == 'auto' )
    {
      $font_family = $esquema[$projeto['esquema']]['FontFamily'];
    }else
    {
      $font_family = $button_Conf['font_family'];
    }// End if( $button_Conf['font_family'] == 'auto' )
    
    if( $button_Conf['font_size'] == 'auto' )
    {
      $font_size = $esquema[$projeto['esquema']]['FontSize'];
    }else
    {
      $font_size = $button_Conf['font_size'];
    }// End
    
    if( $button_Conf['font_color'] == 'auto' )
    {
      $font_color = $esquema[$projeto['esquema']]['ButtonText'];
    }else
    {
      $font_color = '#' . $button_Conf['font_color'];
    }// End if( $button_Conf['font_color'] == 'auto' )
    
    if( $button_Conf['back_ground'] == 'auto' )
    {
      $back_ground = $esquema[$projeto['esquema']]['ButtonFace'];
    }else
    {
      $back_ground = '#' . $button_Conf['back_ground'];
    }// End


    writeTO( '  #' . $button . '{ '                           );
    writeTO( '    position:absolute; '                        );
    writeTO( '    top:' . $button_Global['top'] . 'px;'       );
    writeTO( '    left:' . $button_Global['left'] . 'px;'     );
    writeTO( '    '                                           );
    writeTO( '    z-index:10;'                                );
    writeTO( '    '                                           );
    writeTO( '    width:' . $button_Global['width'] . 'px;'   );
    writeTO( '    height:' . $button_Global['height'] . 'px;' );
    writeTO( '    '                                           );
    writeTO( '    visibility:' . $visible .  ';'              );
    writeTO( '    }'                                          );
    writeTO( '    '                                           );
    writeTO( '    span.' . $button . '_key{ '                 );
    writeTO( '    text-decoration:underline;'                 );
    writeTO( '    }'                                          );
    writeTO( '    '                                           );
    writeTO( '    #' . $button . '_Caption{ '                 );
    writeTO( '    position:absolute;'                         );
    writeTO( '    top:0px'                              . ';' );
    writeTO( '    left:0px'                             . ';' );
    writeTO( '    '                                           );
    writeTO( '    width:' . $button_Global['width'] . 'px;'   );
    writeTO( '    height:' . $button_Global['height'] . 'px;' );
    writeTO( '    '                                           );
    writeTO( '    background-color:' . $back_ground . ';'     );
    writeTO( '    font-family:' . $font_family .           ';');
    writeTO( '    font-size:' . $font_size .           'px;'  );
    writeTO( '    color:'    . $font_color .               ';');
    writeTO( '    font-weight:' . $bold .           ';'       );
    writeTO( '    '                                           );
    writeTO( '    border-top: ' . $button_Style['borderTop']    .   ';' );
    writeTO( '    border-bottom:' . $button_Style['borderBottom'] . ';' );
    writeTO( '    border-left:' . $button_Style['borderLeft']   .   ';' );
    writeTO( '    border-right:' . $button_Style['borderRight']  .  ';' );
    writeTO( '    }'                                                );
  }// End create_button_css()
  
  /**
   *  create_button_control()
   *  ======================================================================= //
   */
  function create_button_control( $modo_RAD )
  {
    global $componentes_no_Prj,
           $projeto,
           $esquema;

    //$path  = ( $modo_RAD )? CFG : _CFG_;
    $path  = ( defined('STUDIO') )? _CFG_ : _CFG_;
    
    $nDest = $path . "button.control.js.php";
    $comp  = $componentes_no_Prj;

    $fp = @fopen( $nDest, 'wb' );
    foreach( $comp as $comp_ => $obj_ )
    {
      if( $comp_ == 'button' )
      {
        $nrObj  = 0;
        $arrObj = array();
        $arrConf = array();

        /**
         *  Lista das Propriedades
        $button_enabled = array();
        $button_color   = array();
        $button_over    = array();
        $button_bold    = array();
        $button_tipo    = array();
         */

        /**
         *  conta o numero de objetos Button no projeto
         *  e armazena os nomes de cada Objetos no
         *  array $arrObj
         */
        foreach( $obj_ as $i_ => $v_ )
        {
          $arrObj[ $nrObj ] = $i_;

          /**
           *  inclui o arquivo .config.def.php de cada Objeto
           */
          include( $path . $i_ . ".config.def.php" );
          $nConf_ = $i_ . "_Conf";
          $arrConf[$i_] = $$nConf_;

          $nrObj ++;
        }// end foreach( $obj_ as $i_ => $v_ )
        writeTO( "button_obj = ". $nrObj .";", $fp );
        writeTO( "button_color_new = '". $esquema[$projeto['esquema']]['Highlight'] ."';", $fp);
        writeTO( "button_color = new Array(); ", $fp );
        writeTO( "button_enabled = new Array();", $fp );
        writeTO( "button_over = new Array();", $fp );
        writeTO( "button_bold = new Array();", $fp );
        writeTO( "button_tipo = new Array();", $fp );
        writeTO( " ", $fp );

        $idx = 0;
        foreach( $arrConf as $ind => $val)
        {
          writeTO( 'button_enabled['.$idx . '] = '  . $val['enabled'] .';', $fp );
          $idx ++;
        }// End foreach($arrConf as $ind => $val)
        writeTO( " ", $fp );
        $idx = 0;
        foreach( $arrConf as $ind => $val)
        {
          if( $val['font_color'] == 'auto' )
          {
            writeTO( 'button_color[' . $idx . '] = "' . $esquema[$projeto['esquema']]['ButtonText'] .'";', $fp );
          }else
          {
            writeTO( 'button_color[' . $idx . '] = "' . $val['font_color'] .'";', $fp );
          }// End
          $idx ++;
        }// End foreach($arrConf as $ind => $val)
        writeTO( " ", $fp );

        $idx = 0;
        foreach( $arrConf as $ind => $val)
        {
          writeTO( 'button_over['.$idx . '] = "'  . $val['efeito_over'] .'";', $fp );
          $idx ++;
        }// End foreach($arrConf as $ind => $val)
        writeTO( " ", $fp );

        $idx = 0;
        foreach( $arrConf as $ind => $val)
        {
          writeTO( 'button_bold['.$idx . '] = '  . $val['bold'] .';', $fp );
          $idx ++;
        }// End foreach($arrConf as $ind => $val)
        writeTO( " ", $fp );

        $idx = 0;
        foreach( $arrConf as $ind => $val)
        {
          writeTO( 'button_tipo['.$idx . '] = "'  . $val['tipo_button'] .'";', $fp );
          $idx ++;
        }// End foreach($arrConf as $ind => $val)

      }// End if( $comp_ == 'button' )
    }// End foreach( $comp as $comp_ => $obj_ )
    fclose( $fp );

    return( $nDest );
  }// End function create_button_control( $modo_RAD )
?> 
