// ici valeurs en dur mais pour vérifier on peut voir
// engine::constant
var ADDRESS_PAYER = 5;
var DATE_BEFORE_PAYMENTDUE = 10;
var DATE_AFTER_PAYMENTDUE = 11;

function updateConventionType(formName)
{
  if( getForm( formName ) == null )
  {
    return;
  }
  // Conv spécific
  if( getInputValue('convention_convention_type',formName) == 0 )
  {
    showLayer('info_for_specific_only1');
    showLayer('info_for_specific_only2');
    showLayer('info_for_specific_only3');
    showLayer('info_for_specific_only4');
    showLayer('info_for_specific_only5');

    if( pConfig.getVarValue('use_selling_mod_cat') > 0 )
      hideLayer('selling_mod_cat_layer');
    if( getInputValue( 'convention_id', formName ) )
      showLayer('address_settings_layer');
    else
      hideLayer('address_settings_layer');

    enableInputChecker( 'convention_customer' );
    enableInputChecker( 'convention_service' );
    enableInputChecker( 'commercial_user_id' );
    enableInputChecker( 'admin_user_id' );
    enableInputChecker( 'signee_user_id' );
    
    //type de client : on l'affiche pas pour les conv specific
    hideLayer( 'info_customer_type_basic_only' );
    disableInputChecker( 'convention_customer_type' );
  }
  else
  {
    //Conv de base
    hideLayer('info_for_specific_only1');
    hideLayer('info_for_specific_only2');
    hideLayer('info_for_specific_only3');
    hideLayer('info_for_specific_only4');
    hideLayer('info_for_specific_only5');
    hideLayer('address_settings_layer');
    if( pConfig.getVarValue('use_selling_mod_cat') > 0 )
      showLayer('selling_mod_cat_layer');
    disableInputChecker( 'convention_customer' );
    disableInputChecker( 'convention_service' );
    disableInputChecker( 'commercial_user_id' );
    disableInputChecker( 'admin_user_id' );
    disableInputChecker( 'signee_user_id' );

    //la par contre on affiche 
    showLayer('info_customer_type_basic_only');
    enableInputChecker( 'convention_customer_type' );
  }
}

function changeMailFlow(flow)
{
  if (flow.value == 1)
    {
      showLayer('address_row');
      showLayer('immediate_email_row');
      enableInputChecker( 'cond_traitment_ma' );
    }
  else
    {
      hideLayer('address_row');
      hideLayer('immediate_email_row');
      disableInputChecker( 'cond_traitment_ma' );
    }
}


// recherche value dans tab
// retourne le premier index qui contient value, sinon -1
// delta = pas de la recherche
function searchInTab( tab, value, delta )
{
  var i = 0;  
  while (i < tab.length)
  {
    if (tab[i] == value)
    {
      return i;
    }
    else i = i + delta;
  }
  return -1;
}

function updateFromTreatmentID( sName, sFormName ) 
{
  // on récupère le traitement (ou modèle de document) sélecté dans le SELECT :
  // on MAJ la liste "envoyé"
  // on MAJ la liste "ou nombre de jours"
  // on montre/cache le champ "Montant minimum restant à payer sur l'échéance"

  // on récupère le traitement (ou modèle de document) sélecté dans le SELECT :
  var pTreatment = getFormObject( sName + '_doc', sFormName );
  var sTreatmentID = pTreatment.value;
  
  // recherche de l'index du traitement sélecté dans le tableau aTreatments
  var nIndex = searchInTab( aTreatments, sTreatmentID, 4 )
  
  if ( nIndex != -1 )
  {
    var addressesTab = aTreatments[nIndex+1];
    var datesTab = aTreatments[nIndex+2];
    var bPaymentDueDoc = aTreatments[nIndex+3];
    
    // on MAJ la liste "envoyé"
    var nMailAddress = getInputValue( sName + '_ma', sFormName );
    var pMailAddress = getFormObject( sName + '_ma', sFormName );
    
    pMailAddress.options.length = 0;
    for (i = 0; i < addressesTab.length; i++)
    {
      addressID = addressesTab[i];
      addressLabel = addressesLabels[addressID];
      pMailAddress.options[i] = new Option( addressLabel, addressID );
    }
    setSelectInputValue( sName + '_ma', nMailAddress, sFormName );
    
    // on MAJ la liste "ou nombre de jours"
    var nDate = getInputValue( sName + '_dr', sFormName );
    var pDateRef = getFormObject( sName + "_dr", sFormName);
    
    pDateRef.options.length = 0;
    for (i = 0; i < datesTab.length; i++)
    {
      dateID = datesTab[i];
      dateLabel = datesLabels[dateID];
      pDateRef.options[i] = new Option( dateLabel, dateID );
    }
    setSelectInputValue( sName + '_dr', nDate, sFormName );
    
    // on montre/cache le champ "Montant minimum restant à payer sur l'échéance"
    if ( bPaymentDueDoc )
      showLayer('paymentdue_balance_min_row');
    else // on ne fait que cacher le champ, on ne vide pas le montant (c'est pour éviter de perdre la valeur s'il y en avait une)
      hideLayer('paymentdue_balance_min_row');
  }
}

function updateViewsFromListParam( sListParamSelectName, sViewSelectName, sOpenButtonName, sFormName ) 
{
  // on récupère le listParam sélectionné dans le SELECT :
  // on MAJ le SELECT des vues dispos pour ce listParam avec un remote
  // on MAJ le lien vers le listParam
  
  // on récupère le listParam sélectionné dans le SELECT
  var pListParam = getFormObject( sListParamSelectName, sFormName );
  if ( pListParam )
  {
    var sListParamID = pListParam.value;
    
    if ( sListParamID != '' )
    {
      var viewsTab = getSharedViews( sListParamID );
      
      // on MAJ le SELECT des vues dispos pour ce listParam
      var pSelectedView = getInputValue( sViewSelectName, sFormName );
      var pViewList = getFormObject( sViewSelectName, sFormName );
      
      // vide le SELECT des vues
      pViewList.options.length = 0;
      
      if ( viewsTab.length == 0 )
      {
        pViewList.options[0] = new Option( LANG_no_view_available_for_this_listparam, '' );
      }
      else
      {
        var nbViews = viewsTab.length / 2;
        for (i = 0; i < nbViews; i++)
        {
          viewCode = viewsTab[2*i];
          viewLabel = viewsTab[2*i + 1];
          pViewList.options[i] = new Option( viewLabel, viewCode );
        }
      }
      setSelectInputValue( sViewSelectName, pSelectedView, sFormName );
      
      // on MAJ le lien vers le listParam
      var aLinksToUpdate = getObjectsByName( sOpenButtonName );
      var sShortListParamName = sListParamID.replace( /customoutputhtmlprinterinputlistparam/, '');
      var sReplaceString = new String ( 'list_name=' + sShortListParamName + '&' );
      var regExp = /list_name=[^&]*&/;
      setLinks( aLinksToUpdate, regExp, sReplaceString ) ;
    
      // affiche les lignes pour les controls "Vue" et "Ouvrir le listparam"
      showRow( sViewSelectName + '_row_layer', null, true );
      //showRow( sOpenButtonName + '_row_layer', null, true );
      showRow( sListParamSelectName + '_row_layer', null, true );
    }
    else
    {
      var pViewList = getFormObject( sViewSelectName, sFormName );
      
      // cache les lignes pour les controls "Vue" et "Ouvrir le listparam"
      hideRow( sViewSelectName + '_row_layer', null, true );
      hideRow( sOpenButtonName + '_row_layer', null, true );
    }
  }
}

//
// Tester le changement de date sur la fiche d'une condition de traitement
//
function changeDateMod( sName, formName, pChangeOriginObj, bDoNotTestImmediatEmail )
{

  // on recherche les champs en question
  var pImmediatEmail = getFormObject( sName + "_immediate_email", formName);
  var pDateRef       = getFormObject( sName + "_dr", formName);
  var pDate          = getFormObject( sName + "_da", formName);
  var pAbsDate       = getFormObject( sName + "_ad", formName);
  
  if( !bDoNotTestImmediatEmail && (!pImmediatEmail || !pDate) )
    return;

  // en fonction de l'objet a l'origine du changement et de sa valeur, on remet
  //  a 0 les autres champs
  if( pChangeOriginObj == pImmediatEmail && pImmediatEmail && pImmediatEmail.checked)
  {
    setInputValue( sName + '_ad', '', formName );
    setInputValue( sName + '_da', '', formName );
    setInputValue( sName + '_dr', '', formName );
  }
  else if(pChangeOriginObj == pDate && pDate.value != '' || pChangeOriginObj == pDateRef && pDateRef.value != '')
  {
    if( !bDoNotTestImmediatEmail )
      pImmediatEmail.checked = false;

    setInputValue( sName + '_ad', '', formName );
  }
  else if( pChangeOriginObj == pAbsDate && pChangeOriginObj.value != '')
  {
    setInputValue( sName + '_da', '', formName );
    setInputValue( sName + '_dr', '', formName );
    
    if( !bDoNotTestImmediatEmail )
      pImmediatEmail.checked = false;
  }

  // ensuite, en fonction de l'état des champs, on détermine dans quel
  //  mode on est et donc quels champs doivent être vérifiés lors de
  //  l'envoi du formulaire
  if( pImmediatEmail && pImmediatEmail.checked )
  {
    disableInputChecker( sName + '_da' );
    disableInputChecker( sName + '_ad' );
    disableInputChecker( sName + '_dr' );
  }
  // si une date relative est saisie
  else if( pDate.value != '' || pDateRef.value != '')
  {
    enableInputChecker( sName + '_da' );
    enableInputChecker( sName + '_dr' );
    disableInputChecker( sName + '_ad' );
  }
  // c'est une date absolue
  else
  {
    disableInputChecker( sName + '_da' );
    enableInputChecker( sName + '_ad' );
    disableInputChecker( sName + '_dr' );
  }
  
}

function changeEcheanceSelect( inputName, formName )
{
  if( getForm( formName ) == null )
  {
      return;
  }
  var val = getInputValue( inputName, formName );
  hideLayer('echeance_code_type00');
  hideLayer('echeance_code_type01');
  hideLayer('echeance_code_type10');
  hideLayer('echeance_code_type11');
  disableInputChecker( 'cond_payment_due_00' );
  disableInputChecker( 'cond_payment_due_01' );
  disableInputChecker( 'cond_payment_due_10' );
  disableInputChecker( 'cond_payment_due_11' );
  if (val=='00' || val=='01'||val=='10' || val=='11')
    {
      enableInputChecker( 'cond_payment_due_'+val );
      showLayer('echeance_code_type'+val);
    }
  if (val=='01' || val=='11')
    {
      hideLayer('div_invoice_amount');
      disableInputChecker('cond_payment_ip');
    }
  else
    {
      showLayer('div_invoice_amount');
      enableInputChecker('cond_payment_ip');
    }
  handleDateTypes( inputName, formName );
}

var soldOptions = new Array();
var echeOptions = new Array();

function handleDateTypes( inputName, formName )
{
  if( getForm( formName ) == null )
  {
      return;
  }
  var pCondPaymentDateType = getFormObject( 'cond_payment_bi', formName );
  var initialValue = getInputValue( 'cond_payment_bi', formName );
  if( soldOptions.length == 0 )
  {
    for( var i = (pCondPaymentDateType.options.length - 1) ; i >= 0 ; i-- )
    {
      if( pCondPaymentDateType.options[ i ].value == 5 ||
          pCondPaymentDateType.options[ i ].value == 6 )
      {
        soldOptions[ soldOptions.length ] = pCondPaymentDateType.options[ i ];
        pCondPaymentDateType.options[ i ] = null;
        continue;
      }
      if( pCondPaymentDateType.options[ i ].value == 7 )
      {
        echeOptions[ echeOptions.length ] = pCondPaymentDateType.options[ i ];
        soldOptions[ soldOptions.length ] = pCondPaymentDateType.options[ i ];
        pCondPaymentDateType.options[ i ] = null;
      }
    }
  }
  for( var i = (pCondPaymentDateType.options.length - 1) ; i >= 0 ; i-- )
  {
    if( pCondPaymentDateType.options[ i ].value == 5 ||
        pCondPaymentDateType.options[ i ].value == 6 ||
        pCondPaymentDateType.options[ i ].value == 7 )
    {
      pCondPaymentDateType.options[ i ] = null;
    }
  }
  var val = getInputValue( inputName, formName );
  if( val != '' )
  {
    if( val == '01' || val == '11' )
    {
      for( var i = 0 ; i < soldOptions.length ; i++ )
      {
        pCondPaymentDateType.options[ pCondPaymentDateType.options.length ] = soldOptions[ i ];
      }
    }
    else
    {
      for( var i = 0 ; i < echeOptions.length ; i++ )
      {
        pCondPaymentDateType.options[ pCondPaymentDateType.options.length ] = echeOptions[ i ];
      }
    }
  }
  setInputValue( 'cond_payment_bi', initialValue, formName );

  handleDateTypeChange( 'cond_payment_bi', formName );
}

function handleDateTypeChange( inputName, formName )
{
  if( getForm( formName ) == null )
  {
      return;
  }

  if( getInputValue( inputName, formName ) == 7 ||
      getInputValue( inputName, formName ) == 9 )
  {
    if( !getInputValue( 'cond_payment_invd', formName ) )
    {
      enableInputChecker( 'cond_payment_start_date' );
      enableInputChecker( 'cond_payment_end_date' );
    }
    showLayer( 'cond_payment_stay_dates_layer' );
  }
  else
  {
    disableInputChecker( 'cond_payment_start_date' );
    disableInputChecker( 'cond_payment_end_date' );
    hideLayer( 'cond_payment_stay_dates_layer' );
  }
}

function selectRoomOrderAllOptions( inputName, formName )
{
  var obj = getFormObject( inputName, formName );

  obj.multiple = true;

  selectAllOptions( inputName, formName );

  return true;
}

function checkMaxRoomBeds( inputName, formName )
{
  var maxRoomBeds = getInputValue( inputName, formName );
  var roomBeds = getInputValue( 'room_beds', formName );
  if( maxRoomBeds < roomBeds )
  {
    alert( LANG_more_room_beds_than_max_beds );
    focusObject( getFormObject( inputName, formName ) );
    return false;
  }
  return true;
}

function checkMaxRoomTypeBeds( inputName, formName )
{
  var maxRoomTypeBeds = getInputValue( inputName, formName );
  var roomTypeBeds = getInputValue( 'room_type_beds', formName );
  if( maxRoomTypeBeds < roomTypeBeds )
  {
    alert( LANG_more_room_type_beds_than_max_beds );
    focusObject( getFormObject( inputName, formName ) );
    return false;
  }
  return true;
}

function checkPaxMinDefaultSup1 ( inputName, formName )
{
  var nPaxMinDefault = getInputValue( inputName, formName );
  if(nPaxMinDefault < 1)
  {
    alert( LANG_default_min_pax_format );
    focusObject( getFormObject( inputName, formName ) );
    return false;
  }
  return true;

}


function checkComfortCodes( inputName, formName )
{
  for( var sCode in aComfortCodes )
  {
    if( getInputValue( sCode, formName ) != '' )
    {
      aComfortCodes[ sCode ] = getInputValue( sCode, formName );
    }
  }

  var aCodes = new Array();

  for( var sCode in aComfortCodes )
  {
    aCodes[ aComfortCodes[ sCode ] ] = 0;
  }

  for( var sCode in aComfortCodes )
  {
    if( getInputValue( sCode, formName ) != '' )
    {
      aCodes[ aComfortCodes[ sCode ] ] += 1;
    }
  }

  for( var sCode in aComfortCodes )
  {
    if( aCodes[ aComfortCodes[ sCode ] ] > 1 )
    {
      alert( LANG_identical_comfort_code_error );
      focusObject( getFormObject( sCode, formName ) );
      return false;
    }
  }

  return true;
}

function handleTaxTypeChange( inputName, formName )
{
  if( getFormObject( inputName, formName ) == null )
  {
    return;
  }

  var tax_type = getInputValue( inputName, formName );

  formatAmount( 'tax_tax_pct', formName );
  formatAmount( 'tax_tax_part1', formName );
  formatAmount( 'tax_tax_part2', formName );

  if( tax_type == 1 )
  {
    showLayer( 'compound_tax_layer' );
    hideLayer( 'simple_tax_layer' );
    disableInputChecker( 'tax_tax_pct' );
    enableInputChecker( 'tax_tax_code1' );
    enableInputChecker( 'tax_tax_part1' );
    enableInputChecker( 'tax_tax_code2' );
    enableInputChecker( 'tax_tax_part2' );
  }
  else
  {
    hideLayer( 'compound_tax_layer' );
    showLayer( 'simple_tax_layer' );
    enableInputChecker( 'tax_tax_pct' );
    disableInputChecker( 'tax_tax_code1' );
    disableInputChecker( 'tax_tax_part1' );
    disableInputChecker( 'tax_tax_code2' );
    disableInputChecker( 'tax_tax_part2' );
  }
}

function handleCriteriaTypeChange( inputName, formName )
{
  var criteriaType = getInputValue( inputName, formName );
  if( criteriaType == '1' )
  {
    hideLayer( 'criteria_type_enum_row_layer' );
    showLayer( 'criteria_type_free_text_default_value_row_layer' );
  }
  else if( criteriaType == '2' )
  {
    hideLayer( 'criteria_type_free_text_default_value_row_layer' );
    showLayer( 'criteria_type_enum_row_layer' );
  }
  else
  {
    hideLayer( 'criteria_type_enum_row_layer' );
    hideLayer( 'criteria_type_free_text_default_value_row_layer' );
  }
}

function copyRoomTypeSettings( roomType, periodCode, parameterName, formName )
{
  var val = getInputValue( parameterName + '_' + periodCode + '_' + roomType, formName );

  var aRoomTypes = getFormObject( 'room_type', formName );
  if( aRoomTypes.length == null )
  {
    aRoomTypes = new Array( aRoomTypes );
  }

  var aPeriodCodes = getFormObject( 'period_code', formName );
  if( aPeriodCodes.length == null )
  {
    aPeriodCodes = new Array( aPeriodCodes );
  }

  for( var i = 0 ; i < aRoomTypes.length ; i++ )
  {
    var rVal = aRoomTypes[i].value;

    for( var j = 0 ; j < aPeriodCodes.length ; j++ )
    {
      var pVal = aPeriodCodes[j].value;

      if( rVal == roomType && pVal != periodCode )
      {
        var inputName = parameterName + '_' + pVal + '_' + rVal;

        if( getFormObject( inputName, formName ) != null )
        {
          setInputValue( inputName, val, formName );
        }
      }
    }
  }
}

function copyRoomTypeProdQuotaSettings( timePeriod, periodCode, parameterName, formName )
{
  var val = getInputValue( parameterName + '_' + periodCode + '_' + timePeriod, formName );

  var aTimePeriods = getFormObject( 'time_period', formName );
  if( aTimePeriods.length == null )
  {
    aTimePeriods = new Array( aTimePeriods );
  }

  var aPeriodCodes = getFormObject( 'period_code', formName );
  if( aPeriodCodes.length == null )
  {
    aPeriodCodes = new Array( aPeriodCodes );
  }

  for( var i = 0 ; i < aTimePeriods.length ; i++ )
  {
    var rVal = aTimePeriods[i].value;

    for( var j = 0 ; j < aPeriodCodes.length ; j++ )
    {
      var pVal = aPeriodCodes[j].value;

      if( rVal == timePeriod && pVal != periodCode )
      {
        var inputName = parameterName + '_' + pVal + '_' + rVal;

        if( getFormObject( inputName, formName ) != null )
        {
          setInputValue( inputName, val, formName );
        }
      }
    }
  }
}

function copyRoomTypeMinSettings( roomType, periodCode, nJ, parameterName, formName )
{
  var val = getInputValue( parameterName + '_' + periodCode + '_' + roomType + '_' + nJ, formName );
  var sDiscountCode = getInputValue( 'discount_code_' + periodCode + '_' + roomType + '_' + nJ, formName );
  var prod = getInputValue( 'product_' + periodCode + '_' + roomType + '_' + nJ, formName );
  var prodSelect = getFormObject( 'product_' + periodCode + '_' + roomType + '_' + nJ + '_select', formName );

  var aRoomTypes = getFormObject( 'room_type', formName );
  if( aRoomTypes.length == null )
  {
    aRoomTypes = new Array( aRoomTypes );
  }

  var aPeriodCodes = getFormObject( 'period_code', formName );
  if( aPeriodCodes.length == null )
  {
    aPeriodCodes = new Array( aPeriodCodes );
  }

  //alert( aRoomTypes.length + ' ' + aPeriodCodes.length );

  //return ;

  for( var i = 0 ; i < aRoomTypes.length ; i++ )
  {
    var rVal = aRoomTypes[i].value;

    for( var j = 0 ; j < aPeriodCodes.length ; j++ )
    {
      var pVal = aPeriodCodes[j].value;

      if( rVal == roomType && pVal != periodCode )
      {
        var inputName = parameterName + '_' + pVal + '_' + rVal + '_' + nJ;

        // si la ligne n'existe pas, on la créé
        var nMaxRowCreation = 10;
        while(getFormObject( inputName, formName ) == null && nMaxRowCreation > 0)
        {
          addMinEmptyRow(pVal, rVal, formName);
          nMaxRowCreation--;
        }
          
        if( getFormObject( inputName, formName ) != null )
        {
          setInputValue( inputName, val, formName );
          setInputValue( 'product_' + pVal + '_' + rVal + '_' + nJ, prod, formName );

          if( prodSelect.options.length != null )
          {
            var pProd = getFormObject( 'product_' + pVal + '_' + rVal + '_' + nJ + '_select', formName );
            if( pProd.options.length != null )
            {
              for( var k = pProd.options.length ; k > 0 ; k-- )
              {
                pProd.options[k] = null;
                //alert( periodCode + ' ' + pVal + ' ' + k );
              }
            }

            for( var l=0 ; l<prodSelect.options.length ; l++ )
            {
              //alert( periodCode + ' ' + pVal + ' ' + l );
              pProd.options[l] = new Option( prodSelect.options[l].text, prodSelect.options[l].value );
            }

            pProd.selectedIndex = prodSelect.selectedIndex;
          }
        }
        if( getFormObject( 'discount_code_' + pVal + '_' + rVal + '_' + nJ, formName ) != null )
        {
          setInputValue( 'discount_code_' + pVal + '_' + rVal + '_' + nJ, sDiscountCode, formName )
        }
      }
    }
  }
}

function addMinEmptyRow(sPeriodCode, sRoomType, sFormName)
{
  // recherche du prochain index
  var iIndex = 0;
  while(getFormObject('quantity_'+sPeriodCode+'_'+sRoomType+'_'+iIndex, sFormName))
    iIndex++;
  // creation de la ligne vide
  var sEmptyRow = new String(sPeriodCode == g_sFirstPeriod ? g_sEmptyRowModelWithCopy : g_sEmptyRowModelWithoutCopy);
  sEmptyRow = sEmptyRow.replace(/\[period_code\]/g,sPeriodCode);
  sEmptyRow = sEmptyRow.replace(/\[room_type\]/g,sRoomType);
  sEmptyRow = sEmptyRow.replace(/\[index\]/g,iIndex);
  // on ajoute la nouvelle ligne
  var pContainer = getDOMObject('container_'+sPeriodCode+'_'+sRoomType);
  if( pContainer )
  {
    var sHTML = new String(pContainer.innerHTML);
    sHTML = sHTML.replace(/\<MARKER\>/, sEmptyRow+'<MARKER>');
    pContainer.innerHTML = sHTML;
  }
  setInputValue('nb_'+sPeriodCode+'_'+sRoomType, iIndex+1, sFormName);
}

function setObsValue( inputName, formName )
{
    setInputValue( inputName, eval( 'document.all.'+inputName+'_div.innerHTML' ), formName );
    return true;
}

function handleGatewayEtabGroupementsuserChange( nEtabID , sGroupementsuser)
{
  try
  {
    var sRet = remoteCall( 'custom::remote::gateway', null, nEtabID , sGroupementsuser);
    if( sRet )
    {
      var nDelim = sRet.indexOf('|');
      var sGatewayName = sRet.substring( 0, nDelim );
      var sHTML = sRet.substring( nDelim + 1 );

      setSelectInputValue( 'gateway_id', sGatewayName, 'gateway_form' );
      
      hideLayer( 'no_gateway_layer' );
      showLayer( 'gateway_layer' );
      getLayer( 'gateway_params_layer' ).innerHTML = sHTML;
    }
    else
    {
      setSelectInputValue( 'gateway_id', '', 'gateway_form' );
      hideLayer( 'gateway_layer' );
      showLayer( 'no_gateway_layer' );
    }
  }
  catch(ex)
  {
    if(ex.showUser)
      ex.showUser();
    else
      throw ex;
  }
}

function handleGatewayChange( gatewayName, nEtabID, sGroupementsuser )
{
  if( gatewayName != "" )
  {
    hideLayer( 'no_gateway_layer' );
    showLayer( 'gateway_layer' );
    try
    {
      var sRet = remoteCall( 'custom::remote::gateway', gatewayName, nEtabID, sGroupementsuser );
      if( sRet )
      {
        var nDelim = sRet.indexOf('|');
        var sHTML = sRet.substring( nDelim + 1 );
        getLayer( 'gateway_params_layer' ).innerHTML = sHTML;
      }
    }
    catch(ex)
    {
      if(ex.showUser)
        ex.showUser();
      else
        throw ex;
    }
  }
  else
  {
    hideLayer( 'gateway_layer' );
    showLayer( 'no_gateway_layer' );
  }
}

function updateCampaignConventionList(sConventionFieldName, sCampaignFieldName, sFormName)
{
  if(!g_sSelectedCampaignCode ||
     !getInputValue(sConventionFieldName,sFormName) ||
     confirmUserMessage('LANG_confirm_change_campaign_will_reset_conventions'))
  {
    g_sSelectedCampaignCode = getInputValue(sCampaignFieldName, sFormName);
    var aOptions = new Array();
    if(g_aConventions[g_sSelectedCampaignCode])
    {
      for(var i = 0;i<g_aConventions[g_sSelectedCampaignCode].length;i++)
        aOptions.push(new Option(g_aConventions[g_sSelectedCampaignCode][i][1],g_aConventions[g_sSelectedCampaignCode][i][0]));
    }
    if(isMultipleSelect(sConventionFieldName,sFormName))
      setMultipleSelectOptions(sConventionFieldName,sFormName,aOptions);
    else
      setSelectOptions(sConventionFieldName,sFormName,aOptions);
  }
  else
  {
    setInputValue(sCampaignFieldName, g_sSelectedCampaignCode, sFormName);
  }
}

function updateClientConventionList(sConventionFieldName, sClientFieldName, sFormName)
{
  var sClientTypeCode = getInputValue(sClientFieldName, sFormName);
  if(sClientTypeCode && sClientTypeCode != '')
  {
    if(confirmUserMessage('LANG_confirm_change_client_will_change_conventions'))
      setMultipleSelectInputValue(sConventionFieldName, g_aClientConventions[sClientTypeCode], sFormName);
    else
      setCodeSelectInputValue(sClientFieldName, '', sFormName);
  }
}

function updateAvailableConventionListForClientType( sConventionFieldName, sClientFieldName, sFormName, pDocument, bNoCheck, bNoKeepSelection )
{
  var sSelectedClientTypes = getInputValue( sClientFieldName, sFormName, pDocument );

  var aClientTypeCodes = sSelectedClientTypes ? sSelectedClientTypes.split("|") : new Array();
//  var aOldClientTypeCodes = g_sPreviousCustomerTypeCodes ? g_sPreviousCustomerTypeCodes.split("|") : new Array();

  var sSelectedConventions = getInputValue( sConventionFieldName, sFormName, pDocument );
  var aOldConventionIDs = sSelectedConventions ? sSelectedConventions.split("|") : new Array();

  // J'enleve le message de confirmation, ça ne sert à rien ici

  // si on ne fait qu'ajouter un type on ne demande pas de confirmation
//  var bNewTypes = aClientTypeCodes.length > aOldClientTypeCodes.length && aOldClientTypeCodes.length != 0;

  // alert si des conventions sont déjà saisies
//  if( bNewTypes || bNoCheck ||
//      !getInputValue( sConventionFieldName, sFormName, pDocument ) ||
//      confirmUserMessage('LANG_confirm_change_customer_type_will_reset_conventions') )
//  {
    g_sPreviousCustomerTypeCodes = sSelectedClientTypes;

    var aOptions   = new Array();
    var aSelection = new Array();
    for( var nI = 0; nI < g_aConventions[g_sSelectedCampaignCode].length; nI++ )
    {
      // prend les conventions qui ont le bon code client, ou toutes si aucun sélectionné
      var aConv = g_aConventions[g_sSelectedCampaignCode][nI];
      if( aClientTypeCodes.length == 0 || arrayContains(aClientTypeCodes, aConv[2]) )
      {
        aOptions.push( new Option( aConv[1], aConv[0] ) );
        if( !bNoKeepSelection && arrayContains( aOldConventionIDs, aConv[0] ) )
          aSelection.push( aConv[0] );
      }
    }
    setMultipleSelectOptions( sConventionFieldName, sFormName, aOptions, false );
    // on garde l'ancienne selection si possible
    if( !bNoKeepSelection )
      setMultipleSelectInputValue( sConventionFieldName, aSelection, sFormName, pDocument );
//  }
//  else
//  {
//    setMultipleSelectInputValue( sClientFieldName, aOldClientTypeCodes, sFormName, pDocument );
//    return false;
//  }

  return true;
}

function updateOwnerPricingType( formName )
{
  var nOwnerPricingType = getInputValue( 'owner_pricing_type', formName );
  if( nOwnerPricingType == 1 )
  {
    // pourcentage / prix public
    hideLayer( 'amount_layer' );
    disableInputChecker( 'owner_amount' );

    showLayer( 'pct_layer' );
    showLayer( 'product_layer' );
    enableInputChecker( 'owner_pct1' );
    enableInputChecker( 'owner_pct2' );
    enableInputChecker( 'owner_product' );
  }
  else if( nOwnerPricingType == 2 || nOwnerPricingType == 3 )
  {
    // montant fixe si sejours
    hideLayer( 'pct_layer' );
    hideLayer( 'product_layer' );
    disableInputChecker( 'owner_pct1' );
    disableInputChecker( 'owner_pct2' );
    disableInputChecker( 'owner_product' );

    showLayer( 'amount_layer' );
    enableInputChecker( 'owner_amount' );
  }
  else if( nOwnerPricingType == 4 )
  {
    // pourcentage C.A. hebergement
    hideLayer( 'amount_layer' );
    hideLayer( 'product_layer' );
    disableInputChecker( 'owner_amount' );
    disableInputChecker( 'owner_product' );

    showLayer( 'pct_layer' );
    enableInputChecker( 'owner_pct1' );
    enableInputChecker( 'owner_pct2' );
  }
  else if( nOwnerPricingType == 5 )
  {
    // pourcentage / prix public + montant garanti
    showLayer( 'amount_layer' );
    enableInputChecker( 'owner_amount' );

    showLayer( 'pct_layer' );
    showLayer( 'product_layer' );
    enableInputChecker( 'owner_pct1' );
    enableInputChecker( 'owner_pct2' );
    enableInputChecker( 'owner_product' );
  }
}

function updateOwnerEtab( formName )
{
  var nEtabID = getInputValue( 'owner_etab_num', formName );

  var nOwnerPricingType = getInputValue( 'owner_pricing_type', formName );
  var sProductCode = getInputValue( 'owner_product', formName );
  if( ( nOwnerPricingType == 1 || nOwnerPricingType == 5 ) && sProductCode )
  {
    if( confirm( LANG_owner_etab_change ) )
    {
      setProductCodeSelectInputValues( 'owner_product', '', formName );
    }
  }
}

function updateResID( sResFieldName, sFieldName, sFormName )
{
  var nResID = getInputValue( sResFieldName, sFormName );

  var pOccupant = getFormObject( sFieldName, sFormName );
  for( var i = (pOccupant.options.length - 1) ; i >= 0 ; i-- )
  {
    pOccupant.options[ i ] = null;
  }

  var aOccupants = remoteCall( 'custom::remote::occupant', nResID );
  if( !aOccupants )
  {
    alert( LANG_reservation_does_not_exist );
    setInputValue( sResFieldName, '', sFormName );
    return;
  }
  for( var i = 0 ; i < aOccupants.length ; i++ )
  {
    pOccupant.options[ i ] = new Option( aOccupants[ i ][ 1 ], aOccupants[ i ][ 0 ] );
  }
}

function updateYieldRuleConventionBlock( sInputName, sFormName, pDocument )
{
  // met à jour les lignes affichées et vide/rétablit les champs appropriés
  
  var nConventionMode = getInputValue( sInputName+'_convention_list_type', sFormName, pDocument );
  
  // demande une confirmation si on des conventions sélectionnées
  if( !getInputValue( sInputName+'_convention_ids', sFormName, pDocument ) ||
      confirmUserMessage('LANG_confirm_change_application_mode_will_reset_conventions') )
  {
    g_nPreviousConventionMode = nConventionMode;

    if( nConventionMode == 1 )
    {
      hideLayer( 'convention_label_include', pDocument, true );
      showLayer( 'convention_label_exclude', pDocument, true );
      showRow( 'customer_type_row', pDocument, true )
  
      enableInputChecker( sInputName+'_customer_types' );
      disableInputChecker( sInputName+'_convention_ids' );

      // vide la selection des convention  
      if( getInputValue( sInputName+'_convention_ids', sFormName, pDocument ) != '' )
        setMultipleSelectInputValue( sInputName+'_convention_ids', new Array(), sFormName, pDocument );
    }
    else
    {
      var sPreviousTypeCode = getInputValue( sInputName+'_customer_types', sFormName, pDocument );
  
      hideLayer( 'convention_label_exclude', pDocument, true );
      showLayer( 'convention_label_include', pDocument, true );
      hideRow( 'customer_type_row', pDocument, true )

      // supprime la selection des codes client
      setMultipleSelectInputValue( sInputName+'_customer_types', '', sFormName, pDocument );
  
      disableInputChecker( sInputName+'_customer_types' );
      enableInputChecker( sInputName+'_convention_ids' );
  
      // retablit la liste des conventions dispo
      if( g_sPreviousCustomerTypeCodes || getInputValue( sInputName+'_convention_ids', sFormName, pDocument ) )
        updateAvailableConventionListForClientType( sInputName+'_convention_ids', sInputName+'_customer_types', sFormName, pDocument, true, true );
    }
    return true;
  }
  else
  {
    // on recoche le bon bouton
    if( g_nPreviousConventionMode == 0 )
    {
      getDOMObject( sInputName+'_convention_list_type_include', pDocument ).checked = true;
      getDOMObject( sInputName+'_convention_list_type_exclude', pDocument ).checked = false;
    }
    else
    {
      getDOMObject( sInputName+'_convention_list_type_include', pDocument ).checked = false;
      getDOMObject( sInputName+'_convention_list_type_exclude', pDocument ).checked = true;
    }
    return false;
  }
}

function updateAvailablePeriodForPriorityRule( sEtabFieldName, sPeriodListFieldName, sFormName, pDocument )
{
  var nEtabID = getInputValue( sEtabFieldName, sFormName, pDocument );

  var sPeriodCodes    = getInputValue( sPeriodListFieldName, sFormName, pDocument );
  var aOldPeriodCodes = sPeriodCodes ? sPeriodCodes.split("|") : new Array();

  var aOptions   = new Array();
  var aSelection = new Array();
  
  var aPeriods = g_aEtabPeriods[sPeriodListFieldName][nEtabID] ? g_aEtabPeriods[sPeriodListFieldName][nEtabID] : new Array();

  for( var nI = 0; nI < aPeriods.length; nI++ )
  {
    var sValue = aPeriods[ nI ][ 0 ];
    var sLabel = aPeriods[ nI ][ 1 ];
    aOptions.push( new Option( sLabel, sValue ) );
    if( arrayContains( aOldPeriodCodes, sValue ) )
      aSelection.push( sValue );
  }

  setMultipleSelectOptions( sPeriodListFieldName, sFormName, aOptions, false );
  // on garde l'ancienne selection
  setMultipleSelectInputValue( sPeriodListFieldName, aSelection, sFormName, pDocument );
}

function findConvention( sCampaignCode, sCustomerTypeCode )
{
  var pConvention = null;
  try
  {
    var sXMLConvention = remoteCall( "custom::remote::reservation::convention",
                                     'getConventionFromCustomerType',
                                     sCampaignCode,
                                     sCustomerTypeCode,
                                     true );
    if(sXMLConvention)
    {
      var xmldDoc = XmlUtils_getXMLDOM(sXMLConvention);
      pConvention = new Convention().fromXMLElement(xmldDoc.documentElement);
    }
  }
  catch(ex)
  {
    if(ex instanceof CheckerException)
    {
      ex.showUser();
    }
  }
  return pConvention;
}


function updateFactTO( sFormName, pDocument )
{
  var pObject = getFormObject( 'convention_facto', sFormName, pDocument );
  if( pObject == null )
    return;
  
  if( pObject.checked )
  {
    showRow( 'convention_not_invoice_null_row', pDocument, true );
  }
  else
  {
    hideRow( 'convention_not_invoice_null_row', pDocument, true );
    getFormObject( 'convention_not_invoice_null', sFormName, pDocument ).checked = false;
  }
}

function updateBaseConventionFlags( sFormName, pDocument )
{
  if( getForm(sFormName) == null )
    return;
  
  var sCampaignCode     = getInputValue( 'convention_campagne_code', sFormName, pDocument );
  var sCustomerTypeCode = getInputValue( 'convention_customer_type', sFormName, pDocument );
  
  // pas de message d'erreur puisque c'est un action automatique
  if( !sCampaignCode )
    return;

  if( !sCustomerTypeCode )
    return;
  
  // chercher la convention de base qui s'applique
  var pConvention = findConvention( sCampaignCode, sCustomerTypeCode, pDocument );
  
  // on ne met pas à jour si on trouve la convention en cours d'édition!
  var nCurrentConventionID = getInputValue( 'convention_id', sFormName, pDocument );
  if( pConvention && pConvention.getID() != nCurrentConventionID )
  {
    var pFactTOCheckbox = getFormObject( 'convention_facto', sFormName, pDocument );
    pFactTOCheckbox.checked = pConvention.isFactTO();

    updateFactTO( sFormName, pDocument );
  }
}


function updateLaunchPreinvoicingPeriods(sCampaignCode, nAloID, sFormName)
{
  var aPeriodOptions = new Array();
  try
  {
    g_MultipleSelectExtSort['period_codes'] = new Array();
    var sEtabIDs = getInputValue('etab_ids', sFormName);
    if( sEtabIDs )
    {
      var aRet = remoteCall( 'custom::remote::periods', 'getInputAloPeriods', sCampaignCode, null, null, sEtabIDs, nAloID );
      if( aRet )
      {
        for(var j=0;j<aRet.length;j++)
        {
          aPeriodOptions.push(new Option( aRet[j][1], aRet[j][0]));
          g_MultipleSelectExtSort['period_codes'][aRet[j][0]] = aRet[j][2];
        }
      }
    }
  }
  catch(ex)
  {
    if(ex.showUser)
      ex.showUser();
    else
      throw ex;
  }
  setMultipleSelectOptions('period_codes', sFormName, aPeriodOptions, false, false, true, true);
}

function updatePartnerAloPeriods(sFormName)
{
  var aPeriodOptions = new Array();
  try
  {
    var sEtabID = getInputValue('etab_id', sFormName);
    var sCampCode = getInputValue('cd_camp', sFormName);
    var sCustomerCode = getInputValue('cd_client_num_cli_code', sFormName);
    var nServiceID = getInputValue('cd_client_num_cli_service', sFormName);
    if( sEtabID != '' && sCustomerCode && nServiceID != '' )
    {
      var aRet = remoteCall( 'custom::remote::periods', 'getInputPartnerAloPeriods', sCampCode, null, null, sEtabID, null, sCustomerCode, nServiceID );
      if( aRet )
      {
        for(var j=0;j<aRet.length;j++)
          aPeriodOptions.push(new Option( aRet[j][1], aRet[j][0]));
      }
    }
  }
  catch(ex)
  {
    if(ex.showUser)
      ex.showUser();
    else
      throw ex;
  }
  setCodeSelectOptions('period_code', sFormName, aPeriodOptions, false, false, true);
  setFormObjectProperty('period_code_select', sFormName, 'disabled', false);
}

function updateTeenagerPeriods(sFormName)
{
  var aPeriodOptions = new Array();
  try
  {
    var sEtabID = getInputValue('etab_id', sFormName);
    var sCampCode = getInputValue('cd_camp', sFormName);
    //var sCustomerCode = getInputValue('cd_client_num_cli_code', sFormName);
    //var nServiceID = getInputValue('cd_client_num_cli_service', sFormName);
    //if( sEtabID != '' && sCustomerCode && nServiceID != '' )
    if( sEtabID != '' && sCampCode != '' )
    {
      var aRet = remoteCall( 'custom::remote::periods', 'getInputTeenagerPeriods', sCampCode, sEtabID );
      if( aRet )
      {
        for(var j=0;j<aRet.length;j++)
          aPeriodOptions.push(new Option( aRet[j][1], aRet[j][0]));
      }
    }
  }
  catch(ex)
  {
    if(ex.showUser)
      ex.showUser();
    else
      throw ex;
  }
  setCodeSelectOptions('period_code', sFormName, aPeriodOptions, false, false, true);
  setFormObjectProperty('period_code_select', sFormName, 'disabled', false);
}

//==================================
// Pour le planning des séjours
//==================================
function onClickCellStay( pCell )
{
  if ( !bBlockDiv )
  {
    var sRegCellID1 = getInputValue( 'reg_cell_id1', 'planning_form' );
  
    // il y a déjà eu 1 click sur un séjour, donc ce click a permis de choisir le 2e séjour pour l'échange de surbook
    if ( sRegCellID1 != '' && sRegCellID1 != null )
    {
      // on vérifie que ce n'est pas le même séjour 
      var nIndexOf1 = sRegCellID1.lastIndexOf( '_' );
      var sStayCell1 = sRegCellID1.substring(0, nIndexOf1);
  
      var sRegCellID2 = pCell.id;
      var nIndexOf2 = sRegCellID2.lastIndexOf( '_' );
      var sStayCell2 = sRegCellID2.substring(0, nIndexOf2);
      if( sStayCell1 != sStayCell2 )
      {
        switchLineColor( pCell, true );
        setNamedObjectProperty( 'reg_cell_id2', 'value', pCell.id );
        
        var sStayTitle = getDOMObject( sRegCellID1 ).parentNode.cells[0].innerHTML;
        var pStayInfo = getDOMObject( 'click2_stay1_info' );
        pStayInfo.innerHTML = LANG_reservation + ' n° ' + sStayTitle;
        
        var sStayTitle = pCell.parentNode.cells[0].innerHTML;
        var pStayInfo = getDOMObject( 'click2_stay2_info' );
        pStayInfo.innerHTML = LANG_reservation + ' n° ' + sStayTitle;
        
        bBlockDiv = true;
        showLayer('click2_div');
      }
    }
    else
    {
      // est-ce que la case clickée est un jour surbooké
      var sClassName = pCell.className;
      var nIndexOf = sClassName.lastIndexOf( 'surbook' );
      if( nIndexOf != -1 )
      {
        switchLineColor( pCell, true );
        setNamedObjectProperty( 'reg_cell_id1', 'value', pCell.id );
        
        var sStayTitle = pCell.parentNode.cells[0].innerHTML;
        var pStayInfo = getDOMObject( 'click1_stay_info' );
        pStayInfo.innerHTML = LANG_reservation + ' n° ' + sStayTitle;
        g_sSelectedStayTitle = sStayTitle;
        
        bBlockDiv = true;
        showLayer('click1_div');
      }
    }
  }
}

function switchCellColor( pObject, bSelect )
{
  if ( pObject )
  {
    setNamedObjectProperty( pObject.id, 'bgColor', '' );
    
    var sClassName = pObject.className;
    var nIndexOf = sClassName.lastIndexOf( 'Selected' );
    if( nIndexOf == -1 )
    {
      if ( bSelect )
        pObject.className = sClassName + 'Selected';
    }
    else
    {
      if ( !bSelect )
        pObject.className = sClassName.substring(0, nIndexOf);
    }
  }
}

function switchLineColor( pObject, bSelect )
{
  if ( pObject )
  {
    var aStayCells = pObject.parentNode.cells;

    // on ne doit pas switcher la couleur du 1er séjour sélectionné pour l'échange
    var sStayTitle = aStayCells[0].innerHTML;
    if ( sStayTitle == g_sSelectedStayTitle )
      return;
    
    // on change le style de toute la ligne du séjour
    for( var i = 0; i < aStayCells.length; i++ )
    {
      var pCell = aStayCells[i];
      if ( pCell && pCell.id != '' && pCell.id != null )
        switchCellColor( pCell, bSelect );
    }
  }
}

function cancelClick1()
{
  g_sSelectedStayTitle = '';

  switchLineColor( getDOMObject( getDOMObject( 'reg_cell_id1').value ), false );
  setNamedObjectProperty( 'reg_cell_id1', 'value', '' );

  bBlockDiv = false; 
  hideLayer('click1_div');
}

function cancelClick2()
{
  g_sSelectedStayTitle = '';

  switchLineColor( getDOMObject( getDOMObject( 'reg_cell_id1').value ), false );
  setNamedObjectProperty( 'reg_cell_id1', 'value', '' );

  switchLineColor( getDOMObject( getDOMObject( 'reg_cell_id2').value ), false );
  setNamedObjectProperty( 'reg_cell_id2', 'value', '' );

  bBlockDiv = false;
  hideLayer('click2_div');
}

function onClickRegInQuota()
{
  var sQuotaCode = getDOMObject( 'reg_quota_code').value;
  if ( sQuotaCode == null || sQuotaCode == '' )
  {
    showUserMessage('LANG_quota_code_is_missing');
  }
  else
  {
    bBlockDiv = false;
    submitActionForm('REG_SURBOOK_IN_QUOTA', 'planning_form');
  }
}

function onClickChooseSecondStay()
{
  bBlockDiv = false;
  hideLayer('click1_div');
}

function onClickRegWithStay()
{
  bBlockDiv = false;
  submitActionForm('REG_SURBOOK_WITH_STAY', 'planning_form');
}

// utilitaire pour extraire le numRes, le stayID et la date de l'id d'une cellule du plaaning séjour
function _extractStayInfo ( sStayResID )
{
  var aRet = new Array();
  var aValues = sStayResID ? sStayResID.split("_") : new Array();
  aRet.push(aValues[1]);
  aRet.push(aValues[3]);
  aRet.push(aValues[5]);
  return aRet;
}

//==================================
// FIN : Pour le planning des séjours
//==================================


//====================================
// Pour la liste "traduction en masse"
//====================================
var g_sCurrentLangVarCode = '';
function showHTMLEditor( sLangVarCode )
{
  g_sCurrentLangVarCode = sLangVarCode;
  
  var sHTML = getDOMInputValue( 'to_trad_' + g_sCurrentLangVarCode );
  html_editor.setHTML( sHTML );
  
  showLayer('html_editor_div', null, null, null, true);
}

function setLanguageVarHTMLValue()
{
  var sHTML = html_editor.getHTML();
  setDOMInputValue( 'to_trad_' + g_sCurrentLangVarCode, sHTML );
  
  hideLayer('html_editor_div', null, null, null, true);
  g_sCurrentLangVarCode = '';
  return true;
}

function emptyMemCache()
{
  try
  {
    remoteCall( 'engine::remote::cache', 'empty_memcache', null );
  }
  catch(ex)
  {
    if( ex.showUser )
      ex.showUser();
    else
      throw ex;
  }
}

function toggleFullSize( sImageID )
{
  var pImage = getDOMObject( sImageID );
  
  if( pImage )
  {
    if( pImage.className == "thumbFull" )
    {
      pImage.className = "thumb";
    }
    else
    {
      pImage.className = "thumbFull";
    }
  }
}

function handleCMSCriteriaTypeChange( inputName, formName )
{
  var criteriaType = getInputValue( inputName, formName );
  if( criteriaType == '2' )
    showLayer( 'cms_criteria_type_enum_row_layer' );
  else
    hideLayer( 'cms_criteria_type_enum_row_layer' );
}

function resetStockToSales( sCampaignCode, nEtabNum, sRoomType, sPeriodCode, nNumAlo, formName )
{
  try
  {
    sNbReserved = remoteCall( "custom::remote::alo",
                              "getNbReserved",
                              sCampaignCode, nEtabNum, sRoomType, sPeriodCode, nNumAlo );
    if( sNbReserved && sNbReserved != '' )
    {
      var aNbReserved = sNbReserved ? sNbReserved.split("|") : new Array();
      setInputValue( 'blocking_' + sPeriodCode + '_' + sRoomType, aNbReserved[0], formName );
      setInputValue( 'non_blocking_' + sPeriodCode + '_' + sRoomType, aNbReserved[1], formName );
    }
  }
  catch(ex)
  {
    if( ex.showUser )
      ex.showUser();
    else
      throw ex;
  }
}

function leaseInputUpdateBankAccountsList( formName )
{
  var sCustomerCode = getDOMObject( 'cd_client_num_cli_code' ).value;
  
  try
  {
    var aBankAccountsOptions = new Array();
    var aBankAccounts = remoteCall( "custom::remote::customer",
                                    "getBankAccounts",
                                    sCustomerCode );
    if( aBankAccounts.length > 0 )
      aBankAccountsOptions.push( new Option(LANG_please_select, '') );
    else
      aBankAccountsOptions.push( new Option(LANG_no_bank_account_available, '') );
    
    for(var i=0;i<aBankAccounts.length;i=i+2)
    {
      nBankAccountID = aBankAccounts[i];
      nBankAccountLabel = aBankAccounts[i+1];
      aBankAccountsOptions.push( new Option(nBankAccountLabel, nBankAccountID) );
    }
    setSelectOptions('object_num_bank_account', formName, aBankAccountsOptions);
  }
  catch(ex)
  {
    if(ex.showUser)
      ex.showUser();
    else
      throw ex;
  }
}
