function cq() {
// Change quantity
  var quantity= document.getElementById("selectBox").selectedIndex + 1;
  
  if( quantity > 9) {
    quantity += ((quantity-10)*3)+6;
  }
  else {
    if( quantity > 6) {
      quantity= ((quantity-7)*2)+8;
    }
  }
  
  var link= document.getElementById("buyLink").href;
  // Find first "=" in "/cgi-bin/review_order.cgi?quantity_5=2"
  var pos= link.indexOf( "=");
  // Change the "quantity_5=2" to "quantity_5=10" or whatever
  document.getElementById("buyLink").href= link.substr( 0, pos+1) + quantity;
}

cq(); // Netscape refresh fix

document.getElementById("selectBox").onchange= function () { cq() }

// Turn text link into image
document.getElementById("buyLink").innerHTML= '<img id="buy" src="img/buy_poppers_online.gif" alt="Buy now">';

// ========= DISCONTINUED ========= //

// Alert the user if this brand has been discontinued
var pTag= document.getElementById( "discontinued");
if( pTag) {
  var pTagHTML= pTag.innerHTML;
  var pos= pTagHTML.indexOf( 'Buy:'); // Find "Buy:" (before <select>2, 3, 4...</select> ...)
  if( pos > -1) {                     // Hopefully that's the only/first "Buy:" in the paragraph. 
    pTag.innerHTML= pTagHTML.substring( 0, pos)
      + '<span style="color: #FFF; padding: 3px; background-color: #C00; border: 1px solid #C00">Sorry, this brand has been discontinued</span>'
      + '<br><br>But you can choose from our <a href="buy_poppers_online.shtml">many other poppers brands &gt;&gt;</a>';
  }
}

// ========= OUT OF STOCK ========= //

function oos() {

  alert(
    "We expect to have this brand available\n"
  + "in the next 2-3 weeks.\n\n"
  + "If you drop us a line through our\n"
  + "Contact page, we will email you once\n"
  + "we are ready to ship this product\n"
  + "again."
  );
}

pTag= document.getElementById( "oos");
if( pTag) {
  var pTagHTML= pTag.innerHTML;
  var pos= pTagHTML.indexOf( 'Buy:'); // Find "Buy:" (before <select>2, 3, 4...</select> ...)
  if( pos > -1) {                     // Hopefully that's the only/first "Buy:" in the paragraph. 
    pTag.innerHTML= pTagHTML.substring( 0, pos)
      + '<span style="color: #C00; padding: 3px; border: 1px solid #C00; background-color: #FF3; font-weight: bold">Temporarily out of stock</span>'
      + '&nbsp; <a style="color: #00F; font-size: 11px" href="javascript:oos()">When can I buy?</a>'
      + '<br><br>But you can choose from our <a href="buy_poppers_online.shtml">many other poppers brands &gt;&gt;</a>';
  }
}

// ========= COMING SOON ========= //

function cs() {

  alert(
    "We expect to have this brand available\n"
  + "in the next 4-6 weeks.\n\n"
  + "If you drop us a line through our\n"
  + "Contact page, we will email you once\n"
  + "we are ready to ship this product."
  );
}

pTag= document.getElementById( "cs");
if( pTag) {
  var pTagHTML= pTag.innerHTML;
  var pos= pTagHTML.indexOf( 'Buy:'); // Find "Buy:" (before <select>2, 3, 4...</select> ...)
  if( pos > -1) {                     // Hopefully that's the only/first "Buy:" in the paragraph. 
    pTag.innerHTML= pTagHTML.substring( 0, pos)
      + '<span style="color: #C00; padding: 3px; border: 1px solid #C00; background-color: #FF3; font-weight: bold">Coming soon !</span>'
      + '&nbsp; <a style="color: #00F; font-size: 11px" href="javascript:cs()">When can I buy?</a>'
      + '<br><br>But you can choose from our <a href="buy_poppers_online.shtml">many other poppers brands &gt;&gt;</a>';
  }
}


