// JavaScript Document
<!-- Begin
/* This code is in the page that checks the coupon. */
function MakeBuy () {  // test the coupon
var coup,cp,l,ship,bamt;
var d1,mm,yy,pp,d2;    // the coupon format

  coup = document.buy.coupon.value;  // get coupon number
  ship = document.buy.shipping.value;  // get shipping
  handling = document.buy.handling.checked;  // get handling
  bamt = document.buy.baseamt.value*1.0;  // get amount

  if (ship == 0.00) { // reset shipping2 if necessary
	// alert (ship);
	// alert (document.buy.shipping2.value);
	document.buy.shipping2.value = (0.00);
	// alert (document.buy.shipping2.value);
  }

  if (handling) { // allow gift message if necessary
	// alert (document.buy.no_note.value);
	// alert (document.buy.cn.value);
	document.buy.no_note.value = (0);
	document.buy.cn.value = ('Gift Message');
	// alert (document.buy.no_note.value);
	// alert (document.buy.cn.value);
  }

  if (coup == "") {
    document.buy.amount.value = Dollar (bamt);
    return true;
  }
  coup = coup / 13.0;             // divide
  coup = coup - 1234567890;       // subtract
  
  // now decode and check with todays date...
  cp = escape (coup);  // make a string
  l  = cp.length;      // how long is it
  d2 = cp.substring (l-2, l);
  pp = cp.substring (l-4, l-2);
  yy = cp.substring (l-6, l-4);
  mm = cp.substring (l-8, l-6);
  d1 = cp.substring (0, l-8);

  // and verify the coupon...
  if (d1 != d2*1.0 || yy > 10 || yy < 3 || mm > 11 || pp > 30) {
    alert ("\n\n Invalid coupon! \n\n");
    return false;
  }

 // set coupon date for comparison...
 // cd.setDate (d1);  // create coupon date
 // cd.setMonth (mm);
 // cd.setFullYear (yy + 2000.0, mm, d1);

  var td = new Date ();  // todays date.
  var cd = new Date (yy*1.0 + 2000, mm, d1);  // coupon date.

  if (td > cd) { // test dates
    alert ("\n\n Coupon has expired! \n\n");
    return false;
  }

//alert ("\n\n Coupon looks good, and is still valid! \n\n");
bamt = bamt * (1.0 - pp/100.0);
document.buy.amount.value = Dollar (bamt);

return true;
/* at this point the pp value is valid as a percent discount
  and may be applied.  */
}

function setField(what) {
    if (what.coupon.checked)
        what.myText.value = 'checked';
    else
        what.myText.value = '';
}

function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < 1) rnd = 1;
  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;
}

<!-- Begin
function popup(page) {
    popupWin = window.open(page, 'remote', "resizable=no,location=no,scrollbars=yes,toolbar=no,menubar=no,directories=no,height=600,width=400"); popupWin.opener.name = "popup";
}

//  End -->

