// JavaScript Document
<!--
var discnt = 0;   // no default percent discount

var coupons = new Array (  // place to put coupon codes
          // 1st coupon value - comma seperated
	"cp10",
	"cp15",
	"save10",
	"save15",
	"best10",
	"best15",
	"healthy10",
	"healthy15",
	"fab10",
	"fab15",
	"a362210",
	"a362215",
  "FAV10",               
  "fav10",                 
  "HAPPY10",          
  "happy10",                 
  "FIT10",                 
  "fit10",
  "FB10",                  
  "fb10",                  
  "GB10",                  
  "gb10",                                  
  "SAVE10",                  
  "save10",                               
  "dc10",                  
  "DC10",                                                     
  "hg10",                       
  "HG10",                                    
  "jm10",                  
  "JM10",                                   
  "mb10",                       
  "MB10",                                    
  "km10",                  
  "KM10",                                    
  "rr10",                       
  "RR10",                  
  "FC10",
  "fc10",
  "ww10",
  "WW10",
  "FLAX10",
  "flax10", 
  "synapse10",
  "SYNAPSE10",
  "jb10",
  "jb10"
);
var coupdc  = new Array (  // place to put discounts for coupon vals
  10,
  15,
  10,
  15,
  10,
  15,
  10,
  15,
  10,
  15,
  10,
  15,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10,
  10
);
var coupval = "(blanket)"; // what user entered as coupon code

function ChkCoup () {      // check user coupon entry
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
      alert ("Valid coupon number! \n\n" + discnt + 
             "% discount now in effect.");
      return;
    }
  }
  alert ("'" + coupval + "'  is not a valid code!");
}

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;
}
//-->