﻿// ----------------------------------------------------------------------
//    Handle the various names for each volume
// ----------------------------------------------------------------------

function VolInf(volume, code, name, id)
{
  this.m_volume = volume;
  this.m_code   = code;
  this.m_name   = name;
  this.m_id     = id;
} // end VolInf()



function gtVolumeNameMapping()
{
  this.m_array = [];

  var reProductCode = /..-..[0-9]+|..[0-9]+/;
  for (var volId in Extents)
  {
    var match = reProductCode.exec(volId);
    if (match)
    {
      var productCode = match[0];
      var productName = volId.substr(productCode.length + 1);
    }
    else
    {
      var productCode = volId;
      var productName = volId;
    }
    this.m_array.push(new VolInf(volId, productCode, productName, Volumes[volId]));
  }

  // Create "indexes"
  this.m_vol  = {};
  this.m_code = {};
  this.m_ids  = {};
  for (var i = 0; i < this.m_array.length; i++)
  {
    var v = this.m_array[i];
    this.m_vol [v.m_volume] = v;
    this.m_code[v.m_code]   = v;
    this.m_ids [v.m_id]     = v;
  }
} // end constructor



gtVolumeNameMapping.prototype.getVolumeFromCode = function getVolumeFromCode(code)
{
  var v = this.m_code[code];
  if (v)
    return v.m_volume;
  else
    return "";
} // end getVolumeFromCode()



gtVolumeNameMapping.prototype.getCodeFromVolume = function getCodeFromVolume(volume)
{
  var v = this.m_vol[volume];
  if (v)
    return v.m_code;
  else
    return "";
} // end getCodeFromVolume()



gtVolumeNameMapping.prototype.getVolInfFromId = function getVolInfFromId(id)
{
  return this.m_ids[id];
} // end getVolInfFromVolume()



/*
gtVolumeNameMapping.prototype. = function()
{
} // end
*/
