function SC_TopMessageShow()
{
  var LMessage = ElementGet('spMessage');
  if ((LMessage) && (LMessage.style.display == 'none'))
    LMessage.style.display = 'inline';
}

function ProductInventorySet_ShoppingCart(AElement, AInventoryMappingKeys, AInventoryMappingValues, AInventoryMappingImages, AKeySchema, AItemID, AImageMaxHeight)
{
  SC_TopMessageShow();

  if (!(AInventoryMappingKeys))
    return;

  var LPrice = document.getElementById('inpPrice_' + AItemID);
  var LQuantity = document.getElementById('Quantity_' + AItemID);
  var LspanPrice = document.getElementById('Price_' + AItemID);
  var LAttributeOptionIDs = AKeySchema.match(/Attr_(\d+)_(\d+)/g);

  var LKey = '';
  var LAttributeOptions = new Array();

  document.getElementsByName('IsDirty')[0].value = 'true';

  for (var i = 0; i < LAttributeOptionIDs.length; i++)
  {
    LAttributeOptions[i] = document.getElementById(LAttributeOptionIDs[i]);
    if (LAttributeOptions[i].value == '')
    {
      LspanPrice.innerHTML = 'n/a';
      LPrice.value = '';
      return;
    }
    else
      LKey = LKey + (LKey == '' ? '' : '|') + LAttributeOptions[i].value;
  }

  var LKeyIndex = InventoryMappingValueProcess(LKey, AInventoryMappingKeys, AInventoryMappingValues, LAttributeOptions, false, LPrice, LQuantity);
  if (LKeyIndex >= 0)
  {
    LspanPrice.innerHTML = LPrice.value;
    ProductInventoryPictureSet_ShoppingCart(LKeyIndex, AItemID, AInventoryMappingImages, AImageMaxHeight);
    return;
  }

  alert("This product doesn't have an inventory with current set of attributes");
  AElement.value = '';
  LPrice.value = 'n/a';
  LspanPrice.innerHTML = 'n/a';
}

function SC_SkipAttributesValidation()
{
  var LInputs = document.getElementsByTagName('input');
  for (var i = 0; i < LInputs.length; i++)
    if ((LInputs[i].name.indexOf('FInvQty') != -1) && (LInputs[i].value == 0))
      return true;

  return false;
}

function ShoppingCart_SelectsAdjust()
{
  ElementsWidthAdjust('Attribute', false, ['select']);
}

function SC_Validate()
{
  var LSelects = document.getElementsByTagName('select');

  for (var i = 0; i < LSelects.length; i++)
  {
    var LSelect = LSelects[i];
    if (LSelect.parentNode.id == 'Attribute')
    {
      if (LSelect.disabled)
      {
        alert('Please, remove not available products from your shopping cart');
        return false;
      }
      else
      if (LSelect.value == '')
      {
        alert('Please, select the ' + LSelect.parentNode.parentNode.parentNode.parentNode.id + ' for each product where it is available and then click on the "Update Cart" button');
        return false;
      }
    }
  }

  return true;
}


function SC_QuantityValidate(AForm)
{
  for (var i = 0; i < AForm.elements.length; i++)
  {
    var LElement = AForm.elements[i];
    if ((LElement.id.substr(0, 8) == 'Quantity') && !FieldValidate(LElement, fvtInt, 'Quantity', '', true))
      return false;
  }
  return true;
}

