var qty = new Array(10,50,100,500,1000);
var price = new Array(15,12,7,4,2,1);

function calprice(total){
  //sanity checks
  if (total < 1) return 0;

  var i = 0;
  var cost = 0;
  for (i=0;i<qty.length;i++) {
//    alert('total is '+total+', i is '+i+', qty is '+qty[i]);
    if (total > qty[i]) {
      if (i>0)
        cost += (qty[i]-qty[i-1])*price[i];
      else
        cost += qty[i]*price[i];
    }else{
      if (i>0) {
        total = total - qty[i-1];
      }
      cost += total*price[i];
      break;
    }
  }
  return cost;
}

function setPrice(qtyCtrl, costCtrl){
  var fm = document.qcc;
  if (qtyCtrl.value > qty[qty.length-1]){
    alert("You have entered a quantity that exceeded our fixed pricing schedule.\nContact us directly for our best offer instead.");
	qtyCtrl.value = '';
  }
  costCtrl.value = calprice(qtyCtrl.value);
}