var discnt = 0;   // no default percent discount

var coupons = new Array (  // place to put coupon codes
  "xoxo",                 // 1st coupon value - comma seperated
  "sweet",                 // 2nd coupon value - add all you want
  " ",
  ""
);
var coupdc  = new Array (  // place to put discounts for coupon vals
  10,
  20,
   0,
   0
);

var coupval = "(blanket)"; // what user entered as coupon code
var color,bd;


function ChkCoup () {      // check user coupon entry
if ((color.length==0) || (color==null))
	{
	alert('Please enter your color') 
      return false; 
	}

var i;
discnt = 0;              // assume the worst

  for (i=0; i < coupons.length; i++) {
    if (coupval == coupons[i]) {
      discnt = coupdc[i];  // remember the discount amt

	  if (coupval == "LOULOU" && bd != "12 x 16 C.C.F.C. Bolsters"){discnt = -1;}
 
	  if (discnt >= 0){
	  //alert ("Valid coupon number! \n\n" + discnt + 
      //       "% discount now in effect for this item.");
	      return true;
	  }
    }
  }
alert ("'" + coupval + "'  is not a valid code!");  
return false;
}

function Dollar (val) {      // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}


function ReadForm (obj1) {  // apply the discount
var amt,des;
  amt = obj1.baseamt.value*1.0;       // base amount
  des = obj1.basedes.value;           // base description

  if (discnt > 0) {                   // only if discount is active
    amt = Dollar (amt - (amt * discnt/100.0));
    des = des + ", " + discnt + "% dis, COUP = " + coupval;
  }

  obj1.amount.value = Dollar (amt);
  obj1.item_name.value = des;
}


function ReadRetailForm (obj1) {  // apply the discount
var amt,des,gift;
  amt = obj1.baseamt.value*1.0;       // base amount
  des = obj1.basedes.value;           // base description
  gift = obj1.giftwrap.checked;
  inventory = obj1.inventory.value;
  qty = obj1.quantity.value;

  if (inventory > 0 && qty > inventory) {
	alert("There are only " + inventory + " left! Sorry, that's the max you can order of this item.") 
  	obj1.quantity.value = inventory;
      return false; 
  }
  if (discnt > 0) {                   // only if discount is active
    amt = amt - (amt * discnt/100.0);
    des = des + ", " + discnt + "% dis, COUP = " + coupval;
  }
  if (gift == true){
    amt = (amt + 7.0);
    des = des + ", gift wrapped";
  }

  obj1.amount.value = Dollar (amt);
  obj1.item_name.value = des;
}

function ReadWholesaleForm (obj1) {  // apply the discount
var amt,des,qty,color,minqty;
  amt = obj1.baseamt.value*1.0;       // base amount
  des = obj1.basedes.value;           // base description
  qty = obj1.quantity.value;
  color = obj1.os0.value;
// feather = obj1.feather.value;
  minqty = obj1.minquantity.value;

  if (discnt > 0) {                   // only if discount is active
    amt = Dollar (amt - (amt * discnt/100.0));
    des = des + ", " + discnt + "% dis, COUP = " + coupval;
  }

if ((color.length==0) || (color==null))
	{
	alert('Please select a color') 
      return false; 
	}
if (isNaN(qty)){
	alert ("Please enter a quantity" );
	return false;
  }

if (isNaN(minqty) || qty < minqty) {
    alert ("You must order at least " + minqty + " items!");
    return false;
  }

//  if (obj1.feather.checked == false){ feather = 0; }
//  if (feather == "" || feather == "no"){ feather = 0; }
//  else { des = des + " | Feather"; }
//  feather = feather*1.0;

  obj1.amount.value = Dollar (amt);//  obj1.amount.value = Dollar (amt+feather);
  obj1.item_name.value = des;
}

