  product_stock = [ ];  
  function update_stock_info(PrID,SuID,PrLink)
  {
    var stockUnits = product_stock[PrID];
    var SU = null;
    for(var x = 0; x < stockUnits.length; x++)
    {
      if(SuID == stockUnits[x].SuID)
      {
        // Found 
        var price = document.getElementById('suprice' + PrID);
        var avail = document.getElementById('suavailability' + PrID);
        var link  = document.getElementById('sulink' + PrID);
        var qty   = document.getElementById('suqty' + PrID);
        var sunotify   = document.getElementById('sunotify' + PrID);
        
        if(price) price.innerHTML = '$' + stockUnits[x].SuCurrentPrice.toFixed(2);
        if(avail) avail.innerHTML = (stockUnits[x].SuQuantityInStock == null || stockUnits[x].SuQuantityInStock > 0) ? 'IN STOCK' : 'SOLD OUT';
        
        if(stockUnits[x].SuQuantityInStock == null || stockUnits[x].SuQuantityInStock > 0)
        {
          if(link)     link.innerHTML = '<a href="' + PrLink + '?SelectSuID=' + SuID + '">Order Now</a>';
          if(qty)      qty.style.display = '';
          if(sunotify) sunotify.style.display = 'none';
        }
        else
        {
          if(link)     link.innerHTML = '<a href="' + PrLink + '?SelectSuID=' + SuID + '">Notify when available</a>';
          if(qty)      qty.style.display = 'none';
          if(sunotify) sunotify.style.display = '';
        }                
        return;
      }
    }
  }
  
  product_options = [ ];
  function update_choices(option_pos,field_pfx,under_form,options,sales_units,on_change_callback)
  {
    var Chosen = [ ];
    var selects = under_form.getElementsByTagName('select');
              
    selects.getByOptionPos = 
      function(pos) 
      { 
        for(var i = 0; i < this.length; i++) 
        { 
          if(this[i].name == field_pfx + '[SuName][' + pos + ']') return this[i]; 
        }
        
        return false;
      }
    
    // Grab the choices for those up to this point
    for(var i = 0; i <= option_pos; i++)
    {             
      var choice = selects.getByOptionPos(i);
      
      if(!choice)
      {
        choice = '';
      }
      else
      {
        choice = choice.options[choice.selectedIndex].value;
      }
      Chosen[i] = choice;
    }
    
    // reconstruct the choices from here on
    for(var i = option_pos+1; i < options.length; i++)
    {
      var optField = selects.getByOptionPos(i);
      var choices  = options[i].choices;
      
      if(!optField)
      {
        // Hmm, what now?
      }
      else if(optField.tagName.toLowerCase() == 'select')
      {
        var currentChoice = optField.selectedIndex == -1 ? null : optField.options[optField.selectedIndex].value;
        
        // Nuke currents
        for(var j = optField.options.length-1;j >= 0; j--)
        {
          optField.options[j] = null;
        }
        
        for(var j = 0; j < choices.length; j++)
        {
          // ennsure there is a SU with this option
          var has_one    = false;
          var nameStarts = Chosen.concat([ choices[j] ]).join(':'); 
          for(var x = 0; x < sales_units.length; x++)
          {
            if(sales_units[x].SuName.substr(0,nameStarts.length) == nameStarts) 
            {
              has_one = true;
              break;
            }
          }
          
          if(has_one)
          {
            optField.options[optField.options.length] = new Option(choices[j], choices[j]);
            if(choices[j] == currentChoice) optField.selectedIndex = optField.options.length-1;
          }
        }
      
        if(optField.selectedIndex >= 0)
        {
          Chosen[Chosen.length] = optField.options[optField.selectedIndex].value;
        }
        else
        {
          Chosen[Chosen.length] = '';
        }
      }
    }
  
    // Update the selected sales unit
    var SelectedName = Chosen.join(':');
    for(var i = 0; i < sales_units.length; i++)
    {
      if(sales_units[i].SuName == SelectedName)
      {
        var inputs = under_form.getElementsByTagName('input');
        for(var j = 0; j < inputs.length; j++)
        {
          if(inputs[j].name == field_pfx + '[SuID]')
          {
            inputs[j].value = sales_units[i].SuID;     
                        
            if(on_change_callback) on_change_callback(sales_units[i]);
                      
            return;
          }
        }
      }
    }
    
  }