<?php 
function create_comboBox( $comboBox,
                          $comboBox_Conf)
{
  global $modo_RAD, $_desenv_;

/**
 *  verifica o .config.data.ini existe, caso
 *  não exista, cria o arquivo
 */
  $path  = ( $modo_RAD )? _CFG_ : CFG;
  $nFile = $path . $comboBox . ".config.data.ini";
  if( !file_exists( $nFile ) )
  {
    $arrINI = reset_arrINI_comboBox( $comboBox );
    writeINIfile( $nFile, $arrINI, ";", "");
  }// End if( !file_exists( $nFile ) )
  
  if( $comboBox_Conf['enabled'] == 'true' )
  {
    $enabled = "";
  }else
  {
    $enabled = "disabled";
  }// End if( $comboBox_Conf['enabled'] == 'true' )

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

  if( defined( 'STUDIO' ) )
  {
    $path  = ( STUDIO == 'core' )? CFG : _CFG_;
  }else
  {
    $path  = _CFG_;
  }// End if( defined( 'STUDIO' ) )
  $nFile = $path . $comboBox . ".config.data.ini";
  if( file_exists( $nFile ) )
  {
    $arr = readINIfile( $nFile );
//echo"<pre>";print_r($arr);exit;
    $ite1 = $arr[ strtolower($comboBox) . '_option' ];
    $opt  = each( $ite1 );
    $ite2 = $arr[ strtolower($comboBox) . '_value' ];
    $val  = each( $ite2 );
  }else
  {
    $opt['value'] = "&nbsp;";
    $val['value'] = "";
  }// End if( file_exists( $nFile ) )
  
  writeTO( '  <label id="' . $comboBox . '_Caption"'                        );
  writeTO( '         class="' . $comboBox . '"'                             );
  writeTO( '         for="' . $comboBox . '_Option"></label>'                );
  writeTO( '  <input id="' . $comboBox . '_Value" '                         );
  writeTO( '         type="hidden" '                                        );
  writeTO( '         value="'.$val['value'].'" />'                          );
  writeTO( '  <input id="' . $comboBox . '_Option"  '                       );
  writeTO( '         type="text" '                                          );
  writeTO( '         value="'.$opt['value'].'" '                            );
  writeTO( '         readOnly="true" '                                      );
  writeTO( '         tabindex="'.$tab_index.'"'                             );
  writeTO( '         '.$enabled. ' />'                                      );
  writeTO( '  <img id="' . $comboBox . '_Icone" src="imagens/seta3.gif" />' );
  writeTO( '  '                                                             );
  writeTO( '  <div id="' . $comboBox . '_Box">'                             );
  writeTO( '  </div end="' . $comboBox . '_Box">'                           );

  create_file_of_evento( "comboBox", "onClick" );
  create_file_of_evento( "comboBox", "onOver" );
  create_file_of_evento( "comboBox", "onOut" );
  
  create_afterLoad_comboBox( $comboBox );
  create_method_comboBox(    $comboBox );
}// End create_comboBox()
   

/**
 *
 */
function create_comboBox_css( $comboBox,
                              $comboBox_Global,
                              $comboBox_Style)
{
  global $modo_RAD;
  
  if( $modo_RAD )
  {
    $visible = 'inherit';
  }else
  {
    $visible = ( $comboBox_Global['visibility'] == 'true' ) ? 'inherit':'hidden';
  }// End if( $modo_RAD )
  $topTexto = 0;
  $widthTexto = $comboBox_Global['width']-5; 
  $heightTexto = $comboBox_Global['height'] -1;
  
  $topIcone  = 1;
//  $leftIcone = ($comboBox_Global['left'] + $comboBox_Global['width'])-20;
  $leftIcone = $comboBox_Global['width']-17;

  $topBox  = ($topTexto + $heightTexto ) + 4;
//  $leftBox = $comboBox_Global['left'];
  $leftBox = '1';
  $widthBox = $comboBox_Global['width'] -5;

  writeTO('  #' . $comboBox . '{'                                       );
  writeTO('    position:absolute;'                                      );
  writeTO('    top:' . $comboBox_Global['top'] . 'px;'                  );
  writeTO('    left:' . $comboBox_Global['left'] .'px;'                 );
  writeTO('    '                                                        );    
  writeTO('    z-index:10;'                                             );
  writeTO('    '                                                        );    
  writeTO('    width:' . $comboBox_Global['width']              . 'px;' );
  writeTO('    height:' . $comboBox_Global['height']            . 'px;' );
  writeTO('    '                                                        );    
  writeTO('    color:' . $comboBox_Global['color']              . ';'   );
  writeTO('    background-color:' . $comboBox_Global['bgcolor'] . ';'   );
  writeTO('    '                                                        );    
  writeTO('    visibility: ' .$visible. ';'                             );
  writeTO('    '                                                        );    
  writeTO('    border-top:'    . $comboBox_Style['borderTop']    . ';'  );
  writeTO('    border-bottom:' . $comboBox_Style['borderBottom'] . ';'  );
  writeTO('    border-left:'   . $comboBox_Style['borderLeft']   . ';'  );
  writeTO('    border-right:'  . $comboBox_Style['borderRight']  . ';'  );
  writeTO('  }'                                                         );
  writeTO('  '                                                          );

  writeTO('  #' . $comboBox . '_Option{'                                 );
  writeTO('    position:absolute;'                                      );
  writeTO('    top:' . $topTexto . 'px;'                                );
  writeTO('    left:0px;'                                               );
  writeTO('  '                                                          );    
  writeTO('    z-index:10;'                                             );
  writeTO('  '                                                          );
  writeTO('    font-family:verdana;'                                    );
  writeTO('    font-size:11px;'                                         );
  writeTO('    padding-top:1px;'                                        );
  writeTO('    padding-left:3px;'                                       );
  writeTO('  '                                                          );
  writeTO('    color:' . $comboBox_Global['color']              . ';'   );
  writeTO('    background-color:#FFFFFF'  . ';'                         );
  writeTO('    visibility: inherit ;'                                   );
  writeTO('  '                                                          );
  writeTO('    width:' . $widthTexto              . 'px;'               );
  writeTO('    height:' . $heightTexto            . 'px;'               );
  writeTO('  '                                                          );
  writeTO('    border-top: 0px; '  );
  writeTO('    border-bottom:0px;'  );
  writeTO('    border-left:0px;'  );
  writeTO('    border-right:0px;'  );
  writeTO('  }'                                                         );
  writeTO('  '                                                          );

  writeTO('  #' . $comboBox . '_Icone{'                                 );
  writeTO('    position:absolute;'                                      );
  writeTO('    top:' .  $topIcone . 'px;'                               );
  writeTO('    left:' . $leftIcone .'px;'                               );
  writeTO('    '                                                          );    
  writeTO('    z-index:10;'                                             );
  writeTO('    width:16px'              . ';'                           );
  writeTO('    height:17px'            . ';'                            );
  writeTO('    visibility: inherit ;'                                   );
  writeTO('  }'                                                         );
  writeTO('  '                                                          );

  writeTO('  #' . $comboBox . '_Box{'                                   );
  writeTO('    position:absolute;'                                      );
  writeTO('    top:' .  $topBox . 'px;'                                 );
  writeTO('    left:' . $leftBox .'px;'                                 );
  writeTO('    '                                                        );    
  writeTO('    color:' . $comboBox_Global['color']              . ';'   );
  writeTO('    background-color:#FFFFFF'  . ';'                         );
  writeTO('    '                                                        );    
  writeTO('    font-family:verdana;'                                    );
  writeTO('    font-size:16px;'                                         );
  writeTO('    padding-top:2px;'                                        );
  writeTO('    padding-left:1px;'                                       );
  writeTO('    '                                                        );    
  writeTO('    visibility: hidden;'                                     );
  writeTO('    overflow: auto;'                                     );
  writeTO('    '                                                        );
  writeTO('    width:'.$widthBox.'px;'                  );
  writeTO('  '                                                          );    
  writeTO('    border-top:1px solid #000000'     . ';'  );
  writeTO('    border-bottom:1px solid #000000' . ';'  );
  writeTO('    border-left:1px solid #000000'     . ';'  );
  writeTO('    border-right:1px solid #000000'   . ';'  );
  writeTO('  }'                                                         );

  writeTO('  .' . $comboBox . '_Label{'                                 );
  writeTO('    '                                                        );    
  writeTO('    font-family:verdana;'                                    );
  writeTO('    font-size:11px;'                                         );
  writeTO('    background-color:#FAFAFF;'                               );
  writeTO('    color:#000080;'                                          );
  writeTO('  }'                                                         );
  writeTO('  '                                                          );

}// End create_comboBox() 


function create_comboBox_control( $modo_RAD )
{
  global $componentes_no_Prj;

  if( defined( 'STUDIO' ) )
  {
    $path  = ( STUDIO == 'core' )? CFG : _CFG_;
  }else
  {
    $path  = _CFG_;
  }// End if( defined( 'STUDIO' ) )

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

  $fp = @fopen( $nDest, 'wb' );
  foreach( $comp as $comp_ => $obj_ )
  {
    if( $comp_ == 'comboBox' )
    {
      $nrObj  = 0;
      $arrObj = array();
      foreach( $obj_ as $i_ => $v_ )
      {
        $arrObj[ $nrObj ] = $i_;
        $nrObj ++;
      }// end foreach()
      writeTO( "comboBox_obj      = ". $nrObj .";", $fp );
      writeTO( "comboBox_selected = 0;"           , $fp );
      writeTO( "comboBox_aberto   = new Array();" , $fp );
      writeTO( "comboBox_itens    = new Array();" , $fp );
      writeTO( "  "       , $fp );
      writeTO( "comboBox_value    = new Array();" , $fp );
      writeTO( "comboBox_option   = new Array();" , $fp );
      writeTO( "  "       , $fp );
      writeTO( "comboBox_onChange = new Array();" , $fp );
      writeTO( "  "       , $fp );

      for( $ix = 0; $ix < $nrObj; $ix++ )
      {
        //$tmp = strtolower($arrObj[$ix]);
        $tmp = $arrObj[$ix];
        $nFile = $path . $tmp . ".config.data.ini";
//echo"$nFile\n";exit;
        if( file_exists( $nFile ) )
        {
          //$arrLista = $tmp . "_Lista";
          //$$arrLista = readINIfile( $nFile );
          $arrLista = readINIfile( $nFile );
          if( isset( $arrLista[ $tmp . '_option' ] ) )
          {
            $arr_option = $arrLista[ $tmp . '_option' ];
            $arr_value  = $arrLista[ $tmp . '_value' ];
          }else
          {
            $arr_option = $arrLista[ strtolower($tmp) . '_option' ];
            $arr_value  = $arrLista[ strtolower($tmp) . '_value' ];
          }
//echo("\n<pre>");print_r($arrLista);exit;
        }else
        {
//echo"not Exist: $nFile\n";exit;
          $arr_option = array();
          $arr_value  = array();
          // em desuso, apenas para manter compatibilidade com versões antigas
          //include( $path . $tmp . ".config.data.php" );
          // echo $tmp . ".config.data.php";
          //$tmp .= "_Lista";
          //$arr = $$tmp;
        }// End if( file_exists( $path . $tmp . ".config.data.ini" ) )
        
        writeTO( "comboBox_aberto[" . $ix . "] = false;" , $fp );
        writeTO( "comboBox_onChange[" . $ix . "] = false;", $fp );
        writeTO( "  ", $fp );

        $max   = count( $arr_option );
        $lista = 'new Array(' . $max . ');';
        writeTO( "comboBox_itens[" . $ix . "] = " . $max . ";" , $fp );
        writeTO( "comboBox_value[" . $ix . "] = " . $lista , $fp );
        writeTO( "comboBox_option[" . $ix . "] = " . $lista , $fp );
        writeTO( "  ", $fp );

        $ind_ = 0;
        foreach( $arr_option as $ii_ => $val )
        {
          writeTO( 'comboBox_option[' . $ix . '][' . $ind_ . '] = "' . $val . '"', $fp );
          if( isset( $arr_value[ $ii_ ] ) )
          {
            $value_ = $arr_value[ $ii_ ];
          }else
          {
            $value_ = '';
          }// End
          writeTO( 'comboBox_value[' . $ix . '][' . $ind_ . '] = "' . $value_ . '"', $fp );
          $ind_ ++;
        }
        //echo("\n<pre>");print_r($arr);exit;

      }// End for()
    }// End if()
  }// End foreach()
  fclose( $fp );
  
  return( $nDest );    
}// End function()

   
function create_method_comboBox( $nObj )
{
  $nFile = _INC_  . $nObj . "_eventos.js.php";

  if( !file_exists( $nFile ) )
  {
    $_fp_ = @fopen( $nFile, 'wb');
    @fwrite($_fp_, '<script language="javascript">'                   . NEWLINE );
    @fwrite($_fp_, '  '.$nObj.'_ID = findDOM( "'.$nObj.'_Option", 0 );' . NEWLINE );
    @fwrite($_fp_, '  '.$nObj.'_ID.attachEvent( "onchange" , ' . $nObj . '_onChange );'. NEWLINE );
    @fwrite($_fp_, '  '.$nObj.'_ID.attachEvent( "onfocus"  , ' . $nObj . '_onFocus );' . NEWLINE );
    @fwrite($_fp_, '  '.$nObj.'_ID.attachEvent( "onblur"   , ' . $nObj . '_onBlur );'  . NEWLINE );
    @fwrite($_fp_, '  '. NEWLINE );
    @fwrite($_fp_, '  function '.$nObj.'_onChange( evt )'. NEWLINE );
    @fwrite($_fp_, '  {'. NEWLINE );
    @fwrite($_fp_, '    '. NEWLINE );
    @fwrite($_fp_, '  }'. NEWLINE );
    @fwrite($_fp_, '  '. NEWLINE );
    @fwrite($_fp_, '  function '.$nObj.'_onFocus( evt )'. NEWLINE );
    @fwrite($_fp_, '  {'. NEWLINE );
    @fwrite($_fp_, '    '. NEWLINE );
    @fwrite($_fp_, '  }'. NEWLINE );
    @fwrite($_fp_, '  '. NEWLINE );
    @fwrite($_fp_, '  function '.$nObj.'_onBlur( evt )'. NEWLINE );
    @fwrite($_fp_, '  {'. NEWLINE );
    @fwrite($_fp_, '    idx = getComboBox_index( getObjEvento(evt) )-1;'. NEWLINE );
    @fwrite($_fp_, '    if( comboBox_onChange[ idx ] )'. NEWLINE );
    @fwrite($_fp_, '    {'. NEWLINE );
    @fwrite($_fp_, '      comboBox_onChange[ idx ] = false;'. NEWLINE );
    @fwrite($_fp_, '      '.$nObj.'_onChange( evt );'. NEWLINE );
    @fwrite($_fp_, '    }'. NEWLINE );
    @fwrite($_fp_, '  }'. NEWLINE );
    @fwrite($_fp_, '  '. NEWLINE );

    @fwrite($_fp_, '</script>'                                  . NEWLINE );
    @fclose( $_fp_ );
  }// End
}// end

function create_afterLoad_comboBox( $nObj )
{
  $nFile = _INC_  . $nObj . "_afterLoad.js.php";

  if( !file_exists( $nFile ) )
  {
    $_fp_ = @fopen( $nFile, 'wb');
    @fwrite($_fp_, '<script language="javascript">' . NEWLINE );
    @fwrite($_fp_, '  '                             . NEWLINE );
    @fwrite($_fp_, '</script>'                      . NEWLINE );
    @fclose( $_fp_ );
  }// End if( !file_exists( $nFile ) )
}// End function create_afterLoad_comboBox( $nObj )


function reset_arrINI_comboBox( $comboBox )
{
  $arr_INI = array();
  $ix_ = $comboBox . '_Option';
  $arr_INI[ $ix_ ][ 'opt1' ] = '';
  $ix_ = $comboBox . '_Value';
  $arr_INI[ $ix_ ][ 'opt1' ] = '';

  return( $arr_INI );
}// End

?> 
