

function SkudProduct(productId, productNumber, attributeCount, storeId, catalogId, langId, lockedOut)
{
  this.productId      = productId;
  this.productNumber  = productNumber;
  this.attributeCount = attributeCount;
  this.storeId        = storeId;
  this.catalogId      = catalogId;
  this.langId         = langId;
  this.lockedOut      = lockedOut;
}

SkudProduct.prototype.selectBoxFor = function(attributeNumber)
{
  if (attributeNumber < this.attributeCount) {
    return $("attributeValue_" + this.productNumber + "_" + attributeNumber);
  }
  return $("catEntryId_" + this.productNumber);
}

SkudProduct.prototype.attributeNameFor = function(attributeNumber)
{
  var hiddenInput = $("attributeName_" + this.productNumber + "_" + attributeNumber);
  return hiddenInput ? hiddenInput.getValue().strip() : "";
}

SkudProduct.prototype.attributeDivFor = function(attributeNumber)
{
  return "attribute_" + this.productNumber + "_" + attributeNumber;
}

SkudProduct.prototype.disableChildrenOf = function(attributeNumber)
{
  for (var i = attributeNumber + 1; i <= this.attributeCount; i++) {
    var selectBox = this.selectBoxFor(i);
    if (selectBox) {
      selectBox.value = "";
      selectBox.disabled = true;
    }
  }
}

SkudProduct.prototype.updateValues = function(attributeNumber)
{
  var attributeName = this.attributeNameFor(attributeNumber);
  var priceLocked   = this.lockedOut || attributeNumber < this.attributeCount;
  
  if (attributeName) {
  
    var params = {
      storeId         : this.storeId,
      catalogId       : this.catalogId,
      langId          : this.langId,
      productNumber   : this.productNumber,
      attributeNumber : attributeNumber,
      attributeName   : attributeName,
      attributeCount  : this.attributeCount,
      productId       : this.productId,
      lockedOut       : priceLocked ? "true" : "false"    
    } 
  
    for (var i = 1; i < attributeNumber; i++) {
      params[this.attributeNameFor(i).toLowerCase()] = this.selectBoxFor(i).getValue().strip();
    }
    
    new Ajax.Updater(this.attributeDivFor(attributeNumber), "/webapp/wcs/stores/servlet/AttributeSelectBoxView", { parameters : params });
  }
}