var dimNumbers = -1; // numarul de modele de la toate produsele de pe pagina

var products   = []; // tabloul de id-uri ale produselor ce sunt caracteristice modelelor
var dimensions = []; // tabloul de productQuantityID
var references = []; // tabloul de referinte
var loPrices   = []; // preturile de oferta
var hiPrices   = []; // preturile standard
var pictures   = []; // pozele modelelor

function addDim(productID, productQuantityID, reference, loPrice, hiPrice, picture){
  dimNumbers++;
  products[dimNumbers]   = productID;
  dimensions[dimNumbers] = productQuantityID;
  references[dimNumbers] = reference;
  loPrices[dimNumbers]   = loPrice;
  hiPrices[dimNumbers]   = hiPrice;
  pictures[dimNumbers]   = picture;
}

function searchDimnesion(productQuantityID){
  for (var kk=0; kk <= dimNumbers; kk++)
    if (dimensions[kk] == productQuantityID)
      return kk;
  return false;
}

function doChange(productID){
  var ref = document.getElementById("ref_" + productID);
  var productQuantityID = document.getElementById("quantities_"+productID).value;
  var dimPosVector = searchDimnesion(productQuantityID);
  
  var picture = document.getElementById('picture_' + productID);
  
  var toOffer = document.getElementById("toOffer").value;
  var loPrice = document.getElementById("loPrice_" + productID);
  var hiPrice = document.getElementById("hiPrice_" + productID);
  
  picture.src = pictures[dimPosVector];
  ref.innerHTML = references[dimPosVector];
  
  hiPrice.innerHTML = hiPrices[dimPosVector] + " RON";
  if (toOffer == 1){
    loPrice.innerHTML = loPrices[dimPosVector] + " RON";
  }
}

function toOrder(productID, productQuantityID, qty){
  if (productQuantityID != -1){ // cazul cu mai multe cantitati
    return 'add-to-cart.php?id=' + productID + '&did=' + productQuantityID + '&qty='+qty;
  }
  else{
    var dim = document.getElementById("quantities_" + productID).value;
    return 'add-to-cart.php?id=' + productID + '&did=' + dim + '&qty='+qty;
  }
}

