var ERR_MISSING_CREDITCARD                = 1001;
var ERR_FAILED_PAYMENT                    = 1002;
var ERR_MISSING_SEND_CHANNEL              = 1003;
var ERR_INCOMPLETE_ADDRESS                = 1004;
var WARNING_BAD_PAYMENTDUES               = 1005;
var WARNING_ARCHIVED_CAMPAIGN             = 1006;
var WARNING_READ_ONLY                     = 1007;
var ERR_TOO_MANY_CC_PAYMENTS              = 1008;
var WARNING_PLEASE_SAVE_BEFORE_QUITTING   = 1009;
var ERR_PRICING_POLARITY_CHANGE           = 1015;
var WARNING_CLOSED_CAMPAIGN               = 1016;
  
var ERR_CANNOT_MIX_WL_STAYS_WITH_NORMAL_STAYS = 4101;

var textFormats = new Array();
textFormats[ 'text' ] = /^\w*$/;
textFormats[ 'int' ] = /^\d*$/;
textFormats[ 'uint' ] = /^\-?\d*$/;
textFormats[ 'positiv_int' ] = /^[1-9]\d*$/;
textFormats[ 'positiv_int_include_zero' ] = /^[0-9]\d*$/;
textFormats[ 'float' ] = /^\d*\.?\d*$/;
textFormats[ 'ufloat' ] = /^\-?\d*\.?\d*$/;
textFormats[ 'money' ] = /^\d+\.\d{2,2}$/;
textFormats[ 'smoney' ] = /^\-?\d+\.\d{2,2}$/;
textFormats[ 'money_special' ] = /^\d+\.\d{2,2}|\-$/;
textFormats[ 'step' ] = /^[1-9]\d?$/;
textFormats[ 'step0' ] = /^\d{1,2}$/;
textFormats[ 'stay' ] = /^[1-9]\d{0,2}$/;
textFormats[ 'product_code' ] = /^[0-9A-Z_]{1,9}$/;
textFormats[ 'char2' ] = /^[0-9A-Z_]{1,2}$/;
textFormats[ 'char4' ] = /^[0-9A-Z_]{1,4}$/;
textFormats[ 'char10' ] = /^[0-9A-Z_]{1,10}$/;
textFormats[ 'char30' ] = /^.{0,30}$/;
textFormats[ 'alpha10' ] = /^[0-9A-Za-z\/_]{1,10}$/;
textFormats[ 'num4' ] = /^[0-9]{1,4}$/;
textFormats[ 'num3' ] = /^[0-9]{1,3}$/;
textFormats[ 'num2' ] = /^[0-9]{1,2}$/;
textFormats[ 'color_code' ] = /^[0-9A-F]{6,6}$/;
textFormats[ 'quantity' ] = /^\d{1,3}\.\d{2,2}$/;
textFormats[ 'squantity' ] = /^\-?\d{1,3}\.\d{2,2}$/;
textFormats[ 'squantitydif0' ] = /^\-?[1-9][0-9]{0,2}\.\d{2,2}$/;
textFormats[ 'customer_code' ] = /^[0-9A-Z_\/]{1,9}$/;
textFormats[ 'amount_pct' ] = /^%\d{1,2}\.\d{2,2}|\d{1,2}\.\d{2,2}%|%100\.00|100\.00%|\d+\.\d{2,2}$/;
textFormats[ 'amount_pct_hyphen' ] = /^%\d{1,2}\.\d{2,2}|\d{1,2}\.\d{2,2}%|%100\.00|100\.00%|\d+\.\d{2,2}|-$/;
textFormats[ 'pct' ] = /^%\d{1,2}\.\d{2,2}|\d{1,2}\.\d{2,2}%|%100\.00|100\.00%$/;
textFormats[ 'pctb' ] = /^\d{1,2}\.\d{2,2}|\d{1,2}\.\d{2,2}|100\.00|100\.00$/;
textFormats[ 'avaibility_pct' ] = /^%\d{1,2}\.\d{2,2}|\d{1,2}\.\d{2,2}%|%100\.00|100\.00%|\d+$/;
textFormats[ 'age' ] = /^\d{1,2}\.?\d?$/;
textFormats[ 'hour' ] = /^[0-2]?[0-9]\:[0-5]?[0-9]$/;
textFormats[ 'visa' ] = /^4(\d){15}$/;
textFormats[ 'cb' ] = /^4(\d){15}$/;
textFormats[ 'mastercard' ] = /^5(\d){15}$/;
textFormats[ 'amex' ] = /^3(\d){14}$/;
textFormats[ 'aurore' ] = /^(\d){19}$/;
textFormats[ 'email' ] = /^[a-zA-Z0-9\-_\.]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,5}$/;

/*
  The array of fields to be checked:
  0 - Is empty allowed
  1 - If empty message
  2 - Text format name
  3 - If bad format message
  4 - Function name to be called (paramï¿½tres: inputName, formName)
  5 - Is check active
  6 - Array of valid actions (if null then any action is valid)
*/
var fields = new Array();
var multipleFields = new Array();

function setInputChecker( inputName, isEmptyAllowed, emptyMessage, textFormat, formatMessage, functionName, actionName )
{ 
  fields[ inputName ] = new Array( isEmptyAllowed, emptyMessage, textFormat, formatMessage, functionName );
  if( actionName != null )
  {
    fields[ inputName ][ 6 ] = new Array( );

    for( var i = 6 ; i < setInputChecker.arguments.length ; i++ )
    {
      fields[ inputName ][ 6 ][ fields[ inputName ][ 6 ].length ] = setInputChecker.arguments[ i ];
    }
  }
}

function setCheckSubstitute(inputNameSub, inputNameDiscount, inputNameSup, MsgErreur)
{
  var SubPrice = fields[ inputNameSub ];
  if(SubPrice != 0 && SubPrice)
  {
    var Discount = fields[ inputNameDiscount];
    var Sup = fields[ inputNameSup ];
    if((Discount != 0 && Discount) || (Sup != 0 && Sup))
    {
      alert(MsgErreur);
      return false;
    }
  }
  return true;
}

function isInputChecker( inputName )
{
  return fields[ inputName ] ? true : false;
}

function copyInputChecker( inputNameSrc, inputNameDest )
{
  fields[ inputNameDest ] = fields[ inputNameSrc ];
}

function disableInputChecker( inputName )
{
  //alert( 'disableInputChecker=' + inputName  );
  if( fields[ inputName ] != null )
  {
    fields[ inputName ][ 5 ] = false;
  }
}

function enableInputChecker( inputName )
{
  if( fields[ inputName ] != null )
  {
    //alert( 'enableInputChecker=' + inputName  );
    fields[ inputName ][ 5 ] = true;
  }
}

function removeInputChecker( inputName )
{
  if( fields[ inputName ] != null )
  {
    delete fields[ inputName ];
  }
}

function validateForm( formName, actionName )
{
  if( !formName || !getForm( formName ))
  {
    return true;
  }

  var bHasChecks = false;
  for(var sKey in fields)
  {
    bHasChecks = true;
    break;
  }
  
  if( bHasChecks )
  {
    var elements = getForm( formName ).elements;
  
    //alert( elements + ' length=' + elements.length );
  
    for( var i = 0 ; i < elements.length ; i++ )
    {
      var element = elements[ i ];
  
      //alert( element.name );
  
      if( actionName != null )
      {
        if( !isValidAction( element.name, actionName ) )
        {
          continue;
        }
      }
  
      if( !checkInput( element.name, formName ) )
      {
        return false;
      }
    }
  }

  if( !validateMultipleInputs( formName ) )
  {
    return false;
  }

  return true;
}

function validateAction( formName, actionName )
{
  if( formName == null )
  {
    return;
  }

  var elements = getForm( formName ).elements;

  for( var i = 0 ; i < elements.length ; i++ )
  {
    var element = elements[ i ];

    if( isValidAction( element.name, actionName ) )
    {
      if( !checkInput( element.name, formName ) )
      {
        return false;
      }
    }
  }

  return true;
}

function setValidAction( inputName, actionName )
{
  if( fields[ inputName ][ 6 ] == null )
  {
    fields[ inputName ][ 6 ] = new Array();
  }
  if( !isValidAction( inputName, actionName ) )
  {
    fields[ inputName ][ 6 ][ fields[ inputName ][ 6 ].length ] = actionName;
  }
}

function isValidAction( inputName, actionName )
{
  if( fields[ inputName ] == null )
  {
    return false;
  }

  if( fields[ inputName ][ 6 ] == null )
  {
    return false;
  }

  for( var i=0 ; i < fields[ inputName ][ 6 ].length ; i++ )
  {
    if( fields[ inputName ][ 6 ][ i ] == actionName )
    {
      return true;
    }
  }

  return false;
}

function checkInput( inputName, formName )
{
  var element = getFormObject( inputName, formName );
  //alert( element + ' ' + inputName + ' ' + fields[ element.name ] );

  if( fields[ element.name ] == null ||
      element.disabled == true )
  {
    //alert( 'TRUE: fields[ element.name ] == null || element.disabled == true ---> ' + fields[ element.name ] + ' ' + element.disabled );
    return true;
  }

  var isCheckActive = fields[ element.name ][ 5 ];
  if( isCheckActive == false )
  {
    //alert( 'TRUE: isCheckActive == false ---> ' + element.name + ' ' + isCheckActive );
    return true;
  }

  var isEmptyAllowed = fields[ element.name ][ 0 ];
  //alert( ( getInputValue( element.name, formName ) == '' ) + ' ' + (isEmptyAllowed != null) + ' ' + (isEmptyAllowed != '') + ' isEmptyAllowed=' + isEmptyAllowed );
  if( getInputValue( element.name, formName ) == '' && isEmptyAllowed != null )
  {
    //alert( 'isEmptyAllowed ---> ' + isEmptyAllowed );
    if( !isEmptyAllowed )
    {
      //alert( 'Empty not allowed for: ' + fields[ element.name ]);
      alert( fields[ element.name ][ 1 ] );
      focusObject( element );
      return false;
    }
    else
    {
      var functionName = fields[ element.name ][ 4 ];
      //alert( element.name + ' ' + functionName );
      if( functionName != null && functionName != '' )
      {
        var ret = evalFunc( functionName, inputName, formName );
        return ret;
      }
      return true;
    }
  }

  if ( element.type == 'text' ||
       element.type == 'password' ||
       element.type == 'textarea' )
  {
    var textFormat = textFormats[ fields[ element.name ][ 2 ] ];
    if( textFormat != '' && textFormat != null )
    {
      //alert( 'Format checked for: ' + textFormats[ fields[ element.name ][ 2 ] ] );
      if( element.value.match( textFormat ) != element.value )
      {
        alert( fields[ element.name ][ 3 ] );
        focusObject( element );
        return false;
      }
    }
  }

  var functionName = fields[ element.name ][ 4 ];
  //alert( element.name + ' ' + functionName );
  if( functionName != null && functionName != '' )
  {
    var ret = evalFunc( functionName, inputName, formName );
    return ret;
  }

  return true;
}

function focusObject( obj, bDoNotShowLayer)
{
  // if the form object is disabled, it cannot get focus.
  if(!obj || obj.disabled)
    return;
  if(!bDoNotShowLayer)
  {
    var parentNode = obj.parentNode;
    while(parentNode)
    {
      if( parentNode.style != null )
      {
        if( parentNode.style.display == 'none' )
        {
          parentNode.style.display = '';
        }
      }
    
      parentNode = parentNode.parentNode;
    }
  }
  if(obj.type != 'hidden')
	  obj.focus();
  if( obj.select )
  {
    obj.select();
  }
}

function setMultipleChecker( fieldName, errorMessage )
{
  multipleFields[ fieldName ] = new Array( errorMessage, true );
  multipleFields[ fieldName ][ 2 ] = new Array();
  var bMax = null;
  for( var i = 2 ; i < setMultipleChecker.arguments.length ; i++ )
  {
    if( i == ( setMultipleChecker.arguments.length - 1 ) )
    {
      //alert( setMultipleChecker.arguments[ i ] + ' ' + ( new String( setMultipleChecker.arguments[ i ] ) ).match( /^\d+$/ ) );
      if( ( new String( setMultipleChecker.arguments[ i ] ) ).match( /^\d+$/ ) )
      {
	bMax = setMultipleChecker.arguments[ i ];
      }
      else
      {
	multipleFields[ fieldName ][ 2 ][ multipleFields[ fieldName ][ 2 ].length ] = setMultipleChecker.arguments[ i ];
      }
    }
    else
    {
      multipleFields[ fieldName ][ 2 ][ multipleFields[ fieldName ][ 2 ].length ] = setMultipleChecker.arguments[ i ];
    }
  }

  multipleFields[ fieldName ][ 3 ] = bMax;
}

function enableMultipleChecker( fieldName )
{
  if( multipleFields[ fieldName ] != null )
  {
    multipleFields[ fieldName ][ 1 ] = true;
  }
}

function disableMultipleChecker( fieldName )
{
  if( multipleFields[ fieldName ] != null )
  {
    multipleFields[ fieldName ][ 1 ] = false;
  }
}

function checkMultipleInput( fieldName, formName )
{
  var fields = multipleFields[ fieldName ][ 2 ];
  var cnt = 0;
  for( var i = 0 ; i < fields.length ; i++ )
  {
    if( getInputValue( fields[ i ], formName ) != '' )
    {
      cnt++;
    }
  }

  //alert( 'cnt=' + cnt );

  if( cnt == 0 )
  {
    alert( multipleFields[ fieldName ][ 0 ] );
    focusObject( getFormObject( multipleFields[ fieldName ][ 2 ][ 0 ], formName ) );
    return false;
  }

  if( multipleFields[ fieldName ][ 3 ] != null )
  {
    if( cnt > multipleFields[ fieldName ][ 3 ] )
    {
      alert( multipleFields[ fieldName ][ 0 ] );
      focusObject( getFormObject( multipleFields[ fieldName ][ 2 ][ 0 ], formName ) );
      return false;
    }
  }

  return true;
}

function validateMultipleInputs( formName )
{
  for( var fieldName in multipleFields )
  {
    if( multipleFields[ fieldName ][ 1 ] == true )
    {
      if( !checkMultipleInput( fieldName, formName ) )
      {
        return false;
      }
    }
  }

  return true;
}

function checkFormDateFormat(inputName, formName)
{
  var bOK = checkAndUpdateDateField( getFormObject(inputName, formName), null, true );
  return bOK;
}

function checkFormHourFormat(inputName, formName)
{
  var bOK = checkAndUpdateHourField( getFormObject(inputName, formName), null, true );
  return bOK;
}

function getUserMessage(sMessageID, hParameters)
{
  var args = getUserMessage.arguments;
  var sMessage = "_"+sMessageID+"_";
  if(window[sMessageID])
    sMessage = window[sMessageID];
  for(var sKey in hParameters)
  {
    //var re = getRegExp("\\\\\\["+sKey+"\\\\\\]");
    var re = getRegExp("\\["+sKey+"\\]");
    sMessage = sMessage.replace(re, hParameters[sKey])
  }
  return sMessage;
}

function showUserMessage(sMessageID, pWindow, hParameters)
{
  showMessage(getUserMessage(sMessageID, hParameters), pWindow);
}

function showMessage(sMessage, pWindow)
{
  if(!pWindow)
    pWindow = window;
  pWindow.alert(sMessage);
}

function confirmUserMessage(sMessageID, paParams)
{
  return confirm(getUserMessage(sMessageID, paParams));
}

function checkEmailAddress( pEmailAddressField, bNoAlert )
{
  var emailAddress = pEmailAddressField.value;
  if(emailAddress == "")
    return true;
  
  var bEmailAddressOK = true;
  sEmailAddress = new String( emailAddress );

  var aEmailAddress = sEmailAddress.split(';');
  // Expression reguliere inspiree de http://www.regular-expressions.info/email.html afin de respecter au plus pres la RFC 2822.
  var filter = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,6}$/gi;
  for ( var i = 0; i < aEmailAddress.length; i++ )
  {
    var sEmailAddress = aEmailAddress[ i ];
    if(!filter.test(sEmailAddress))
    {
      bEmailAddressOK = false; 
      break;
    }
    filter.compile(filter);
  }

  if(bEmailAddressOK)
    return true;

  if ( !bNoAlert )
    alert( LANG_incorrect_email_address_format );

  focusObject( pEmailAddressField ); 
  pEmailAddressField.select();

 return false;
}

function checkName( pNameField, bNoAlert )
{
  var name = pNameField.value;
  if(name == "")
    return true;
  
  sName = new String( name );
  if( trim(sName) != "" )
    return true;

  focusObject( pNameField );  
  pNameField.select();
  
  return false;
}

function checkLogin( pLoginField, bNoAlert )
{
  var login = pLoginField.value;
  if(login == "")
    return true;
  
  slogin = new String( login );
  if( trim(slogin) != "" )
    return true;

  focusObject( pLoginField );  
  pLoginField.select();
  
  return false;
}

function checkCreditCardNumber( sFormName, sTypeCreditCardField, sNumCCField, bNoAlert )
{
  var sCreditCardType = getInputValue( sTypeCreditCardField, sFormName );
  var sNumCC          = new String( getInputValue( sNumCCField, sFormName ));

  if ( (sCreditCardType == 1 && sNumCC.match(textFormats[ 'visa' ] )) || 
       (sCreditCardType == 2 && sNumCC.match(textFormats[ 'mastercard' ]))  || 
       (sCreditCardType == 3 && sNumCC.match(textFormats[ 'amex' ]))  || 
       (sCreditCardType == 4 && sNumCC.match(textFormats[ 'aurore' ]))   || 
       (sCreditCardType == 5 && sNumCC.match(textFormats[ 'cb' ]) ))    
      return true;
  
  
  if ( !bNoAlert )
    alert( "Le numero de carte bleu est invalide" );


  return false;
}

function Configuration()
{
  this.addVar = Configuration_addVar;
  this.getVarValue = Configuration_getVarValue;
  this.getChildAgeMax = Configuration_getChildAgeMax;
  //
  this.aVars = new Array();
}

function Configuration_addVar(sVarID, sVarValue)
{
  this.aVars[sVarID] = sVarValue;
}

function Configuration_getVarValue(sVarID)
{
  return this.aVars[sVarID];
}

function Configuration_getChildAgeMax(sCampaignCode, sVarID)
{
  var nChildCampaign = this.aVars[sCampaignCode];
  if(nChildCampaign == null)
  {
    nChildCampaign = this.aVars[sVarID];
  }
  return nChildCampaign;
}

function CheckerException( sMessageID, sGUIID, sFormFieldName, sFormName, pDocument, nErrorNumber, pWindow, hMessageParameters )
{
  this.sMessageID = sMessageID;
  this.hMessageParameters = hMessageParameters;
  this.sMessage = null;
  this.sGUIID = sGUIID;
  this.sFormFieldName = sFormFieldName;
  this.sFormName = sFormName;
  this.pDocument = pDocument;
  this.nErrorNumber = nErrorNumber;
  this.pWindow = pWindow;
  //
  this.showUser = CheckerException_showUser;
  this.showUserMessage = CheckerException_showUserMessage;
  this.getMessageID = CheckerException_getMessageID;
  this.getMessageParameters = CheckerException_getMessageParameters;
  this.getMessage = CheckerException_getMessage;
  this.getGUIID = CheckerException_getGUIID;
  this.setGUIID = CheckerException_setGUIID;
  this.getFormFieldName = CheckerException_getFormFieldName;
  this.setFormFieldName = CheckerException_setFormFieldName;
  this.getFormName = CheckerException_getFormName;
  this.getLayer = CheckerException_getLayer;
  this.setLayer = CheckerException_setLayer;
  this.setTab = CheckerException_setTab;
  this.getDocument = CheckerException_getDocument;
  this.setFormField = CheckerException_setFormField;
  this.setFormName = CheckerException_setFormName;
  this.setDocument = CheckerException_setDocument;
  this.setErrorNumber = CheckerException_setErrorNumber;
  this.getErrorNumber = CheckerException_getErrorNumber;
  this.getWindow = CheckerException_getWindow;
  this.setWindow = CheckerException_setWindow;
}

function CheckerException_showUser(pWindow)
{
  if(pWindow == null)
  {
    if(this.pWindow)
    {
      pWindow = this.pWindow;
    }
    else if(this.pDocument && this.pDocument.parentWindow)
    {
      pWindow = this.pDocument.parentWindow;
    }
  }
  if(this.getLayer())
    showLayer(this.getLayer());
  var bTabActivated = false;
  if(this.sTabsID && this.sTabID)
  {
    activateTab(this.sTabsID, this.sTabID, true);
    bTabActivated = true;
  }

  if(this.getFormFieldName() && this.getFormName())
    focusObject(getFormObject( this.getFormFieldName(), this.getFormName(), pWindow ? pWindow.document : (this.pDocument ? this.pDocument : null)), bTabActivated);
  this.showUserMessage(pWindow);
}

function CheckerException_showUserMessage(pWindow)
{
  showMessage(this.getMessage(), pWindow);
}

function CheckerException_getMessageID()
{
  return this.sMessageID;
}

function CheckerException_getMessageParameters()
{
  return this.hMessageParameters;
}

function CheckerException_getMessage()
{
  if(this.sMessage)
    return this.sMessage;
  return getUserMessage(this.getMessageID(), this.getMessageParameters());
}

function CheckerException_getErrorNumber()
{
  return this.nErrorNumber;
}

function CheckerException_setErrorNumber( nErrorNumber )
{
  this.nErrorNumber = nErrorNumber;
}

function CheckerException_getGUIID()
{
  return this.sGUIID;
}

function CheckerException_setGUIID(sGUIID)
{
  this.sGUIID = sGUIID;
}

function CheckerException_getFormFieldName()
{
  return this.sFormFieldName;
}

function CheckerException_setFormFieldName(sFormFieldName)
{
  this.sFormFieldName = sFormFieldName;
}

function CheckerException_setFormName(sFormName)
{
  this.sFormName = sFormName;
}

function CheckerException_getFormName()
{
  return this.sFormName;
}

function CheckerException_setTab(sTabsID, sTabID)
{
  this.sTabsID = sTabsID;
  this.sTabID = sTabID;
}

function CheckerException_setFormField(sFormFieldName, sFormName)
{
  this.sFormFieldName = sFormFieldName;
  this.sFormName = sFormName;
}

function CheckerException_getLayer()
{
  return this.sLayer;
}

function CheckerException_setLayer(sLayer)
{
  this.sLayer = sLayer;
}

function CheckerException_setDocument(pDocument)
{
  this.pDocument = pDocument;
}

function CheckerException_getDocument()
{
  return this.pDocument;
}

function CheckerException_getWindow()
{
  return this.pWindow;
}

function CheckerException_setWindow(pWindow)
{
  this.pWindow = pWindow;
}

function checkForbiddenValues(inputName, sFormName )
{
  var value = getInputValue(inputName, sFormName);
  
  if ( value )
  {
    for (var i=0; i < aForbiddenValue.length; ++i )
    {
      if( aForbiddenValue[i] == value )
      {
        alert(sErrorMsg);      
        return false;
      }
    }  
  }
  return true;
}

function checkAndUpdatePhoneField( pPhoneField, sDelimiter, bNoAlert )
{
  if(pPhoneField.value == "")
    return true;
  
  // check si c'est le bon format
  var sPhone = new String( pPhoneField.value );
  if( sPhone.match("^([0-9][0-9][. ]){4}[0-9][0-9]$") )
  {
    return true;
  }
  
  // garde seulement les chiffres
  var sOnlyDigits = sPhone.replace( /[^\d]/g, '');
  var nNbDigits = sOnlyDigits.length;

  // s'il n'y a que des chiffres, on reformate le numï¿½ro de tï¿½lï¿½phone
  if ( nNbDigits > 0 && nNbDigits == sPhone.length)
  {
    var sFormatedPhone = '';
    // on regroupe les chiffres par paire, et on sï¿½pare par sDelimiter
    for ( var i = nNbDigits; i >= 1; i = i-2 )
    {
      var s2digits = sOnlyDigits.substring( i-2, i );
      sFormatedPhone = sDelimiter + s2digits + sFormatedPhone;
    }
    
    pPhoneField.value = sFormatedPhone.substring(1, sFormatedPhone.length);
  }
  
  return true;
}

//pour utiliser ce checker, il faut que les champs aient des noms bien spÃ©cifiques (liste dans aCheckFields)
function checkAddBankAccountForm( sFormName, sPrefix )
{
  if( sPrefix == null || sPrefix == '' )
  {
    sPrefix = 'add_bank_account_';
  }
  
  var aRIBCheckFields = new Array( 'Label', 'BankCode', 'AgencyCode', 'AccountNumber', 'RIBKey' );
  var aRIBNbCharMax = new Array( -1, 5, 5, 64, 2 );
  var aIBANCheckFields = new Array( 'Label', 'AccountNumber', 'BICCode', 'IBAN' );
  var aIBANNbCharMax = new Array( -1, 64, 20, 36 );
  var aCheckFields;
  var aNbCharMax;

  // RIB (1) ou IBAN (2)
  var nType = getInputValue( sPrefix+'Type', sFormName );
  if( nType == 1 )
  {
    aCheckFields = aRIBCheckFields;
    aNbCharMax = aRIBNbCharMax;
  }
  else
  {
    aCheckFields = aIBANCheckFields;
    aNbCharMax = aIBANNbCharMax;
  }
  
  for( var nI = 0; nI < aCheckFields.length; nI++ )
  {
    var sValue = getInputValue( sPrefix+aCheckFields[ nI ], sFormName );
    //la valeur est-elle vide ?
    if( !sValue )
    {
      alert( LANG_webres_please_fill );
      getFormObject( sPrefix+aCheckFields[ nI ], sFormName ).focus();
      return false;
    }
    //la valeur dÃ©passe-t-elle la limite de nb de caractÃ¨res ?
    else if( aNbCharMax[ nI ] != -1 && sValue.length > aNbCharMax[ nI ] )
    {
      alert( LANG_webres_error_entry );
      getFormObject( sPrefix+aCheckFields[ nI ], sFormName ).focus();
      return false;
    }
  }
  return true;
}

var LANG_vat_invalidvat = 'Numéro TVA invalide. Veuillez vérifier le numéro.';

function checkVatCode(inputobj) {
	//see "Validation du numéro de TVA par VIES", 
	//http://ec.europa.eu/taxation_customs/vies/lang.do?fromWhichPage=vieshome&selectedLanguage=FR
	//http://ec.europa.eu/taxation_customs/vies/faqvies.do#item11
	//From http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl :
	if (!/[A-Z]{2}[0-9A-Za-z\+\*\.]{2,12}/.test(inputobj.value.toUpperCase()))
	{
		alert(LANG_vat_invalidvat);
		return false;
	}
	inputobj.value = inputobj.value.toUpperCase();
	return true; 
}
