<?php
function create_checkBox( $checkBox,
                          $checkBox_Conf)
{
  if( $checkBox_Conf['enabled'] == 'true' )
  {
      $enabled = "";
  }else
  {
      $enabled = "disabled";
  }// End if( $checkBox_Conf['enabled'] == 'true' )
  
  if( $checkBox_Conf['checked'] != 'true' )
  {
      $checked = "true";
  }else
  {
      $checked = "false";
  }// End if( $checkBox_Conf['checked'] == 'true' )
  
  if( $checkBox_Conf['caption'] == 'auto' )
  {
    $label = $checkBox;
  }else
  {
    $label = $checkBox_Conf['caption'];
  }// End if( $checkBox_Conf['caption'] == 'auto' )
  
  if ( $checkBox_Conf[ 'alt_key' ] == 'null' || $checkBox_Conf[ 'caption' ] == '' || $checkBox_Conf['alt_key'] == '' )
  {
    $alt_key = '';
  }else
  {
    $alt_key = $checkBox_Conf[ 'alt_key' ];
    $ix = strpos( $label, $alt_key );
    if( $ix === false )
    {
      $alt_key = '';
    }else
    {
      $label = substr( $label, 0, $ix ) . '<span id="'.$checkBox.'_key">'.$alt_key.'</span>'. substr( $label, $ix + 1 );
    }// End if( $ix === false )
  }//End if ( $checkBox_Conf[ 'alt_key' ] == 'null' )

  if( $checkBox_Conf['tab_index'] == 'auto' )
  {
    $tab_index = '';
  }else
  {
    $tab_index = $checkBox_Conf['tab_index'];
  }//End if( $edit_Conf['tab_index'] == 'auto' )

  global $_desenv_;
  $path_img = "http://";

  writeTO( '<label id="'.$checkBox.'_Caption"  for="'.$checkBox.'_Check"    ' );
  writeTO( '       accesskey="' . $alt_key . '" ' .$enabled. '>             ' );
  writeTO( '  ' . $label . '</label>                                        ' );
  writeTO( '<input id="' . $checkBox . '_Check"                             ' );
  writeTO( '    type="checkbox"            checked="' .$checked.  '"        ' );
  writeTO( '    tab_index="'.$tab_index.'" '      .$enabled. '/>            ' );
  
  
}// End create_checkBox()


/**
 *
 */
function create_checkBox_css( $checkBox,
                              $checkBox_Global,
                              $checkBox_Style,
                              $checkBox_Conf  )
{
  global $projeto,
         $esquema,
         $modo_RAD;

  if( $modo_RAD )
  {
    $visible = 'inherit';
  }else
  {
    $visible = ( $checkBox_Conf['visibility'] == 'true' ) ? 'inherit':'hidden';
  }// End if( $modo_RAD )
  
  $paddingTop = 0;
  $paddingBottom = 10;
  $paddingLeft = 5;
  
  //$lenLabel    = ($edit_Global['width'] /2) - ($paddingTop + $paddingLeft);
  //$lenInput    = ($edit_Global['width'] - $lenLabel)-10;
  //$initInput   = ($lenLabel + $paddingTop + $paddingLeft) -2;

  $lenLabel    = $checkBox_Conf['label_len'];
  $lenCheck    = $checkBox_Conf['check_len'];
  $initCheck   = ( $lenLabel + 10 );
  $colorBorder = '#808080';
//  $paddingBottom
  if ( $checkBox_Conf['font_size'] == 'auto' )
  {
    $fontSize = $checkBox_Global['fontSize'];
  }else
  {
    $fontSize = $checkBox_Conf['font_size'];
  }

  writeTO( '  #' . $checkBox . '{ '                                          );
  writeTO( '    position:absolute;'                                      );
  writeTO( '    top:' . $checkBox_Global['top'] . 'px'                 . ';' );
  writeTO( '    left:' . $checkBox_Global['left'] . 'px'               . ';' );
  writeTO( '    '                                                        );
  writeTO( '    z-index:10;'                                             );
  writeTO( ''                                                            );
  writeTO( '    width:' . ( $initCheck + $lenCheck + 5 ). 'px'  . ';' );
  writeTO( '    height:' . $checkBox_Global['height'] .            'px;'   );
  writeTO( '    '                                                        );
  writeTO( '    padding-top:'       . $paddingTop .              'px;'    );
  writeTO( '    padding-bottom:'  . $paddingBottom .             'px;'    );
  writeTO( '    '                                                        );
  writeTO( '    color:' . $checkBox_Conf['font_color']                 . ';' );
  writeTO( '    background-color:' . $checkBox_Conf['back_ground']     . ';' );
  writeTO( '    '                                                        );
  writeTO( '    visibility:'.$visible.';'                                );
  writeTO( '    '                                                        );
  writeTO( '    border-top:'    . $checkBox_Style['borderTop']         . ';' );
  writeTO( '    border-bottom:' . $checkBox_Style['borderBottom']      . ';' );
  writeTO( '    border-left:'   . $checkBox_Style['borderLeft']        . ';' );
  writeTO( '    border-right:'  . $checkBox_Style['borderRight']       . ';' );
  writeTO( '  }'                                                         );
  writeTO( '  '                                                          );
	writeTO( '  #' . $checkBox . '_Caption{ '                                  );
  writeTO( '    position:absolute;'                                      );
  writeTO( '    top:5px'                                           . ';' );
  writeTO( '    left:0px'                                         . ';' );
  writeTO( '    '                                                        );
  writeTO( '    font-size:' . $fontSize . 'px'   . ';'                   );
  writeTO( '    width:'.$lenLabel . 'px'                           . ';' );
  writeTO( '    height:' . $checkBox_Global['height'] . 'px'           . ';' );
  writeTO( '  }'                                                         );
  writeTO( '  '                                                          );
  writeTO( '  #' . $checkBox . '_Check{ '                                  );
  writeTO( '    position:absolute;'                                      );
  writeTO( '    top:0px'                                           . ';' );
  writeTO( '    left:' . ( $lenLabel + $lenCheck - 10 )   .   'px;'       );
  writeTO( '    '                                                        );
  writeTO( '    font-size:' . $fontSize . 'px'   . ';'                   );
  writeTO( '    width:'.$lenCheck . 'px'                           . ';' );
  writeTO( '    height:' . $lenCheck .     'px'                    . ';' );
  writeTO( '  }'                                                         );
  writeTO( '  #' . $checkBox . '_key{ '                                  );
  writeTO( '    text-decoration:underline;'                              );
  writeTO( '  }'                                                         );
  writeTO( '  '                                                          );

}// End function create_checkBox_css( $checkBox,


  function create_checkBox_control( $modo_RAD )
  {
    global $componentes_no_Prj,
           $projeto,
           $esquema;

    //$path  = ( $modo_RAD )? CFG : _CFG_;
    $path  = ( defined('STUDIO') )? _CFG_ : _CFG_;

    $nDest = $path . "checkBox.control.js.php";
    $comp  = $componentes_no_Prj;

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

        /**
         *  Lista das Propriedades
         */
        $checkBox_enabled = array();

        /**
         *  conta o numero de objetos checkBox 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( "checkBox_obj = ". $nrObj .";", $fp );
        writeTO( "checkBox_enabled = new Array();", $fp );
        writeTO( " ", $fp );

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


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

    return( $nDest );
  }// End function create_checkBox_control( $modo_RAD )

?>
