
function checkRoomQuantity( inputName, formName )
{
  if( !checkInput( inputName, formName ) )
  {
    focusObject( getFormObject( inputName, formName ) );
    return false;
  }

  //alert( 'input format is fine' );

  var fieldName = getInputValue( inputName + '_field_name', formName );

  ( new String( inputName ) ).match( /(.*[^\d])(\d+)_(\d+)$/ );

  var cellname = RegExp.$1;
  var i = RegExp.$2;
  var j = RegExp.$3;

  // now verify that we do not go over the set quota

  return true;
}

function copyRoomQuantities( inputName, formName )
{
  //alert( 'copyAmounts' + getFormObject( inputName, formName).onblur );
  if( !checkRoomQuantity( inputName, formName ) )
  {
    return false;
  }

  if( !confirm( LANG_copy_room_quantities ) )
  {
    return;
  }

  var fieldName = getInputValue( inputName + '_field_name', formName );
  var value = getInputValue( inputName, formName );

  ( new String( inputName ) ).match( /(.*[^\d])(\d+)_(\d+)$/ );

  var cellName = RegExp.$1;
  var i = RegExp.$2;
  var j = RegExp.$3;

  var height = getInputValue( 'period_table_height', formName );
  var width = getInputValue( 'period_table_width', formName );

  var fieldName = new String( fieldName );
  var field_type = fieldName.substring( 0, fieldName.indexOf( '_' ) );
  var focusObj = null;
  for( var j=0 ; j<width ; j++ )
  {
    for( var i=0 ; i<height ; i++ )
    {
      if( getFormObject( cellName + i + '_' + j + '_field_name', formName ) != null )
      {
        var tmpFieldName = getInputValue( cellName + i + '_' + j + '_field_name', formName );
        //alert( tmpFieldName + ' ' + field_type );
        if( (new String( tmpFieldName )).indexOf( field_type ) != -1 )
        {
          if( j > 2 )
          {
            if( focusObj == null )
            {
              focusObj = getFormObject( cellName + i + '_' + j, formName );
            }
          }
          setInputValue( cellName + i + '_' + j, value, formName );
          if( !checkRoomQuantity( cellName + i + '_' + j, formName ) )
          {
            return;
          }
        }
      }
    }
  }
  //alert( focusObj + ' ' + focusObj.name );
  if( focusObj != null )
  {
    focusObject( focusObj );
  }
}

function checkPaxMini( inputName, formName )
{
  if( !checkInput( inputName, formName ) )
  {
    focusObject( getFormObject( inputName, formName ) );
    return false;
  }

  //alert( 'input format is fine' );

  var fieldName = getInputValue( inputName + '_field_name', formName );

  ( new String( inputName ) ).match( /(.*[^\d])(\d+)_(\d+)$/ );

  var cellname = RegExp.$1;
  var i = RegExp.$2;
  var j = RegExp.$3;

  // now verify that we do not go over the set quota

  return true;
}

function copyPaxMini( inputName, formName )
{
  //alert( 'copyAmounts' + getFormObject( inputName, formName).onblur );
  if( !checkPaxMini( inputName, formName ) )
  {
    return false;
  }

  if( !confirm( LANG_copy_pax_mini ) )
  {
    return;
  }

  var fieldName = getInputValue( inputName + '_field_name', formName );
  var value = getInputValue( inputName, formName );

  ( new String( inputName ) ).match( /(.*[^\d])(\d+)_(\d+)$/ );

  var cellName = RegExp.$1;
  var i = RegExp.$2;
  var j = RegExp.$3;

  var height = getInputValue( 'period_table_height', formName );
  var width = getInputValue( 'period_table_width', formName );

  var fieldName = new String( fieldName );
  var field_type = fieldName.substring( 0, fieldName.indexOf( '_' ) );
  var focusObj = null;
  for( var j=0 ; j<width ; j++ )
  {
    for( var i=0 ; i<height ; i++ )
    {
      if( getFormObject( cellName + i + '_' + j + '_field_name', formName ) != null )
      {
        var tmpFieldName = getInputValue( cellName + i + '_' + j + '_field_name', formName );
        //alert( tmpFieldName + ' ' + field_type );
        if( (new String( tmpFieldName )).indexOf( field_type ) != -1 )
        {
          if( j > 2 )
          {
            if( focusObj == null )
            {
              focusObj = getFormObject( cellName + i + '_' + j, formName );
            }
          }
          setInputValue( cellName + i + '_' + j, value, formName );
          if( !checkPaxMini( cellName + i + '_' + j, formName ) )
          {
            return;
          }
        }
      }
    }
  }
  //alert( focusObj + ' ' + focusObj.name );
  if( focusObj != null )
  {
    focusObject( focusObj );
  }
}

