<?php
function create_fieldSet( $fieldSet,
                          $fieldSet_Conf,
                          $fieldSet_field )
{
  $tmp = $fieldSet . "_field_lang";
  global $componentes_no_Prj, $$tmp;
  $lang = $$tmp;
  
  foreach( $fieldSet_field as $field_ => $enable_ )
  {
    writeTO( '<label id="' . $fieldSet . $field_ . '_Label" class="fieldSet_Label">' );
    writeTO( '  ' . $lang[ $field_ ] );
    writeTO( '</label end="' . $fieldSet . $field_ . '_Label">' );
    writeTO( '<input id="' . $fieldSet . $field_ . '_Input" class="fieldSet_Input" />' );
  }// End foreach()
}// End create_fieldSet()
  
function create_fieldSet_css( $fieldSet,
                              $fieldSet_Global,
                              $fieldSet_Style,
                              $fieldSet_Conf,
                              $fieldSet_field,
                              $flagFieldSet )
{
  global $projeto,
         $esquema;

  $visible = ($fieldSet_Global['visibility'] == 'visible' ) ? 'inherit':'hidden';
  $paddingTop = 3;
  $paddingBottom = 0;
  $paddingLeft = 5;
  $lenLabel    = round( ($fieldSet_Global['width'] /2) - ($paddingTop + $paddingLeft) );
  $lenInput    = round( ($fieldSet_Global['width'] - $lenLabel)-10 );
  $initInput   = round( ($lenLabel + $paddingTop + $paddingLeft) -1 );
  $colorBorder = '#808080';

  $cor_borderLeft  = $esquema[$projeto['esquema']]['ButtonHighlight'];
  $cor_borderRight = $esquema[$projeto['esquema']]['ButtonShadow'];
  writeTO( '<!--'                                                   );
  writeTO( '  #' . $fieldSet . '{ '                                     );
  writeTO( '    position:absolute;'                                 );
  writeTO( '    top:' . $fieldSet_Global['top']                 . 'px;' );
  writeTO( '    left:' . $fieldSet_Global['left']               . 'px;' );
  writeTO( '    '                                                   );
  writeTO( '    z-index:10;'                                        );
  writeTO( ''                                                       );
  writeTO( '    width:' . $fieldSet_Global['width']               . 'px;' );
  writeTO( '    height:' . $fieldSet_Global['height']             . 'px;' );
  writeTO( '    '                                                   );
  writeTO( '    padding-top:' . $paddingTop . 'px;'                 );
  writeTO( '    padding-bottom:' . $paddingBottom . 'px;'           );
  writeTO( '    '                                                   );
  writeTO( '    color:' . $fieldSet_Global['color']               . ';' );
  writeTO( '    background-color:' . $fieldSet_Global['bgcolor']  . ';' );
  writeTO( '    '                                                   );
  writeTO( '    visibility:'.$visible.';'                                );
  writeTO( '  }'                                                    );
  writeTO( '  '                                                     );

  $topField = 0;
  foreach( $fieldSet_field as $field_ => $enable_ )
  {
    writeTO( '  #' . $fieldSet . $field_ . '_Label{ '                 );
    writeTO( '    position:absolute'                            . ';' );
    writeTO( '    top:'.$topField.'px'                          . ';' );
    writeTO( '    left:0px'                                     . ';' );
    writeTO( '    '                                                   );
    writeTO( '    width:'.$lenLabel . 'px'                      . ';' );
    writeTO( '    height:15px'                                  . ';' );
    writeTO( '  }'                                                    );
    writeTO( '  '                                                     );
    writeTO( '  #' . $fieldSet . $field_ . '_Input{ '                 );
    writeTO( '    position:absolute'                            . ';' );
    writeTO( '    top:'.$topField.'px'                          . ';' );
    writeTO( '    left:'.$initInput.'px'                        . ';' );
    writeTO( '    '                                                   );
    writeTO( '    width:'.$lenInput . 'px'                      . ';' );
    writeTO( '    height:16px'                                  . ';' );
    writeTO( '  }'                                                    );
    
    $topField += 19;
  }// End foreach()

  if( $flagFieldSet )
  {
    writeTO( '  .fieldSet_Label{ '                                       );
    writeTO( '    font-family:' . $fieldSet_Global['fontFamily']   . ';' );
    writeTO( '    font-size:' . $fieldSet_Global['fontSize']. 'px' . ';' );
    writeTO( '    padding-top:' . $paddingTop . 'px'               . ';' );
    writeTO( '    padding-left:' . $paddingLeft . 'px'             . ';' );
    writeTO( '    '                                                      );
    writeTO( '    overflow:hidden'                                 . ';' );
    writeTO( '    '                                                      );
    writeTO( '    visibility:inherit'                              . ';' );
    writeTO( '    '                                                      );
    writeTO( '    border-top:1px solid ' . $colorBorder            . ';' );
    writeTO( '    border-bottom:1px solid ' . $colorBorder         . ';' );
    writeTO( '    border-left:1px solid ' . $colorBorder           . ';' );
    writeTO( '    border-right:1px outset ' . $cor_borderRight     . ';' );
    writeTO( '  }'                                                       );
    writeTO( '  '                                                        );
    writeTO( '  .fieldSet_Input{ '                                       );
    writeTO( '    font-family:' . $fieldSet_Global['fontFamily']   . ';' );
    writeTO( '    font-size:' . $fieldSet_Global['fontSize']. 'px' . ';' );
    writeTO( '    '                                                      );
    writeTO( '    background-color:' . $fieldSet_Global['bgcolor'] . ';' );
    writeTO( '    visibility:inherit'                              . ';' );
    writeTO( '    '                                                      );
    writeTO( '    border-top:1px solid ' . $colorBorder            . ';' );
    writeTO( '    border-bottom:1px solid ' . $colorBorder         . ';' );
    writeTO( '    border-left:1px solid ' . $cor_borderLeft        . ';' );
    writeTO( '    border-right:1px solid ' . $colorBorder          . ';' );
    writeTO( '  }'                                                       );
  }// End if()
  writeTO( '-->'                                                    );
}// End create_fieldSet_css()


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

  $comp_no_Prj = $componentes_no_Prj;
  $path  = ( $modo_RAD )? _CFG_ : CFG;
  $nDest = $path . "fieldSet.control.js.php";

  $fp = @fopen( $nDest, 'wb' );
  foreach( $comp_no_Prj as $comp_ => $obj_ )
  {
    if( $comp_ == 'fieldSet' )
    {
      $nrObj  = 0;
      $arrObj = array();
      $arrSub = array();

      foreach( $obj_ as $i_ => $v_ )
      {
        $arrObj[ $nrObj ] = $i_;
        $nrObj ++;
      }// End foreach()

      writeTO( "fieldSet_obj      = " . $nrObj . ";", $fp );
      writeTO( "fieldSet_selected = new Array();"   , $fp );
      writeTO( "fieldSet_nrFields = new Array();"   , $fp );
      writeTO( "fieldSet_enable   = new Array();"   , $fp );
      writeTO( "fieldSet_bgcolor  = new Array();"   , $fp );
      writeTO( "  "                                 , $fp );

      for( $ix = 0; $ix < $nrObj; $ix ++)
      {
        $tmp = $arrObj[$ix];
        include( CFG . $tmp . ".config.field.php" );
        include( CFG . $tmp . ".config.def.php" );
        include( CFG . $tmp . ".config.php" );
        //echo $tmp . ".config.field.php";
        $glo_ = $tmp . '_Global';
        $arrGlo = $$glo_;
        $tmp .= "_field";
        $arr = $$tmp;
        writeTO( "fieldSet_nrFields[" . $ix . "] = ".count($arr) . ";", $fp );
        writeTO( "fieldSet_selected[" . $ix . "] = 0;"         , $fp );
        writeTO( "fieldSet_enable["   . $ix . "] = new Array();"         , $fp );
        writeTO( "fieldSet_bgcolor["  . $ix . "] = '".$arrGlo['bgcolor']."';", $fp );
        writeTO( "  "                                                 , $fp );

        $ind = 0;
        foreach( $arr as $ix_ => $enable_ )
        {
          writeTO( "fieldSet_enable["   . $ix . "][" . $ind . "] = ".$enable_ . ";", $fp );
          $ind ++;
        }// End foreach()
        writeTO( "  ", $fp );
      }// End for()
      writeTO( "  ", $fp );

    }// End if()
  }// End foreach()
  fclose( $fp );

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


?> 
