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

/**  
 *  comboBox_mouseClick() --------------------------------------------------  //
 */  
function comboBox_mouseClick( objID )
{
  if( objID.indexOf('comboBox') != -1 )
  {
    nrCombo = get_comboBox( objID );
    comboBox_selected = nrCombo;

/**
 *  clicou no Icone (seta) Abrir o Combo e
 *  mostrar a lista de valores (values)
 */
    if( objID.indexOf('Icone') != -1 )
    {

      ind = comboBox_itens[ nrCombo -1 ];
      arr_option = comboBox_option[ nrCombo -1 ];
//alert('icone: '+ind);
/**
 *  Monta a lista de Valores  ----------------------------------------------  //
 */
      texto  = '<table border="0" width="100%">';
      nCombo = "comboBox" + nrCombo;
      for( iix=0; iix < ind; iix++ )
      {
        if( arr_option[iix] == ''
          )
        {
          _option_ = '&nbsp;';
        }else
        {
          _option_ = arr_option[iix];
        }// End if( arr_option[nrCombo -1][iix] == '' )
        
        texto += '<tr>';
        texto += '<td id="' + nCombo + '_label_' + (iix +1) +
                 '" class="' + nCombo + '_Label">' + _option_  + '</td>';
        texto += '</tr>';
      }// End for( iix=0; iix < ind; iix++ )
      texto += "</table>";

//alert(texto);
/**
 *  mostrar a lista valores (value)
 */
      nObj = "comboBox" + nrCombo + "_Box";
//nObj.innerHTML = texto;
      
      comboDOM = findDOM( nObj, 0 );
      comboDOM.innerHTML = texto;

      comboDOM = findDOM( nObj, 1 );

      if ( comboBox_aberto[ nrCombo -1 ] )
      {
        comboDOM.visibility = "hidden";
        comboBox_aberto[ nrCombo -1 ] = false;

        nObj = "comboBox" + nrCombo;
        objDOM = findDOM( nObj, 1 );
        objDOM.zIndex = '150';
      }else
      {
        comboDOM.visibility = 'inherit';
        comboBox_aberto[ nrCombo -1 ] = true;

        nObj = "comboBox" + nrCombo;
        objDOM = findDOM( nObj, 1 );
        objDOM.zIndex = '250';
      }// End if ( comboBox_aberto[ nrCombo -1 ] )
//alert('combo');
    }// End if( objID.indexOf('Icone') != -1 )

/**
 *  clicou em uma option do Combo
 *  atualiza o value
 */
    if ( objID.indexOf('label') != -1 )
    {
      idx_label = getComboBox_index_label( objID );

      value_  = comboBox_value[ nrCombo -1 ][ idx_label -1 ];
      option_ = comboBox_option[ nrCombo -1 ][ idx_label -1 ];
      setComboBox_value( nObj, value_, option_ );
//alert(nObj+' : '+option_);

      nObj = "comboBox" + nrCombo + "_Box";
      objID_Box = findDOM( nObj, 1);
      objID_Box.visibility = "hidden";
      comboBox_aberto[ nrCombo -1 ] = false;
    }// End if ( objID.indexOf('label') != -1 )
  }// End if( objID.indexOf('comboBox') != -1 )
}// End function comboBox_mouseClick( objID )
  
/**
 *  comboBox_mouseDown()  --------------------------------------------------  //
 */
  function comboBox_mouseDown( objID )
  {
    if( objID.indexOf('comboBox') != -1 )
    {

    }
  }// End

/**
 *  comboBox_mouseUp()  ----------------------------------------------------  //
 */
  function comboBox_mouseUp( objID )
  {
    if( objID.indexOf('comboBox') != -1 )
    {

    }
  }// End

/**
 *  comboBox_mouseOver()  --------------------------------------------------  //
 */
  function comboBox_mouseOver( objID )
  {
    if( objID.indexOf('comboBox') != -1 )
    {
      if( objID.indexOf('label') != -1 )
      {
        labelDOM = findDOM(objID,1);
        labelDOM.backgroundColor="#E1E1E1";
        labelDOM.cursor="default";
      }
    }
  }// End

/**
 *  comboBox_mouseOut()  ---------------------------------------------------  //
 */
  function comboBox_mouseOut( objID )
  {
    if( objID.indexOf('comboBox') != -1 )
    {
      if( objID.indexOf('label') != -1 )
      {
        labelDOM = findDOM(objID,1);
        labelDOM.backgroundColor="#FAFAFF";
        //alert(objID);
      }
    }
  }// End

/**
 *  comboBox_mouseMove()  --------------------------------------------------  //
 */
  function comboBox_mouseMove( objID )
  {
    if( objID.indexOf('comboBox') != -1 )
    {

    }
  }// End


/*
 * retorna o numero do ComboBox  -------------------------------------------  //
 */
function get_comboBox( objID )
{
  ix = objID.indexOf('_');
  if ( ix == -1 )
  {
    ix = objID.length;
  }//End if()

  if ( objID.substr( ix -2, 1 ) == 'x' )
  {
    nx = 1;
  }else
  {
    nx = 2;
  }// Endif
  //alert( 'comboBox: '+ ret );
  
  return objID.substr( ix -nx, nx );
}// End function()


/**
 *  setTexto_comboBox()  ---------------------------------------------------  //
 */
function setTexto_comboBox( obj, txt )
{
  if( obj.indexOf( 'comboBox' ) != -1 )
  {
    nrCombo = get_comboBox( obj );

    cmd = obj + '_Option.innerHTML = "' + txt +'"';
    eval( cmd );

//    comboBox_selected = nrCombo;
  }// end if()
}// End function

function getTexto_comboBox( obj )
{
  ret = "";
  if( obj.indexOf( 'comboBox' ) != -1 )
  {
    cmd = "ret = " + obj + "_Option.innerHTML";
  }// End if()

  return ret;
}// End function()



//  Conjunto de funções para manipular as propriedades do Objeto  //
//  ------------------------------------------------------------  //

function setComboBox_reset( objID )
{
  if( objID.indexOf( 'comboBox' ) != -1 )
  {
//alert(objID);
    var nrCombo = get_comboBox( objID );
//alert( comboBox_itens[ nrCombo -1 ] );
    for( ix_combo=0; ix_combo < comboBox_itens[ nrCombo -1 ]; ix_combo++ )
    {
      comboBox_option[ nrCombo -1 ][ ix_combo ] = '';
    }// End for()

    comboBox_itens[ nrCombo -1 ] = 1;
    setComboBox_value( objID, ' ' );
  }// End if()
}// End function()


/**
 *  setar o value do ComboBox
 */
function setComboBox_value( objID, val, opt )
{
  //alert('setCombo: '+val+' = '+opt);
  if( objID.indexOf( 'comboBox' ) != -1 )
  {
    var nObj_value  = objID + '_Value';
    var nObj_option = objID + '_Option';

    objDOM_val = findDOM( nObj_value, 0 );
    old_val = objDOM_val.value;
    objDOM_opt = findDOM( nObj_option, 0 );
    old_opt = objDOM_opt.value;

    if( old_val != val || old_opt != opt )
    {
      if( val == '' )
      {
        val = ' ';
      }// End if( val == '' )
      nrCombo = get_comboBox( objID );
      comboBox_onChange[nrCombo -1] = true;

      objDOM_val.value = val;

      objDOM_opt.focus();
      //alert(objDOM_opt.value);
      objDOM_opt.value = opt;
      //alert(objDOM_opt.value);
      //objDOM_opt.change();
      objDOM_opt.blur();
    }// End if()
  }// End if()
}// End function()

/**
 *  retorna o value do ComboBox
 */
function getComboBox_value( objID )
{
  if( objID.indexOf( 'comboBox' ) != -1 )
  {
    nObj = objID + '_Value';

    comboDOM = findDOM( nObj, 0 );
    return comboDOM.value;
  }// End if()

}// End function()

/**
 *  retorna o Option do ComboBox
 */
function getComboBox_option( objID )
{
  if( objID.indexOf( 'comboBox' ) != -1 )
  {
    nObj = objID + '_Option';

    comboDOM = findDOM( nObj, 0 );
    return comboDOM.value;
  }// End if()

}// End function()



/**
 *  retorna o index do Label
 */
function getComboBox_index_label( objID )
{
  var ixx = objID.indexOf('label') + 6;
  return( objID.slice( ixx ) );
}// End

/**
 *  retorna o index do ComboBox
 */
function getComboBox_index( objID )
{
  var ixx = objID.indexOf('_');
  return( objID.slice( 8, ixx ) );
}// End

</script>
