// Support construction of dynamic PayPal args.
var blk1  = "https://www.paypal.com/cgi-bin/webscr" +
            "?cmd=_cart";
var blk1a = "&add=1";
var blk1d = "&display=1";
var blk2  = "&business=sales%40magicofyes.com";
var blk3  = "&item_name=";
var blk3n = "Test";
var blk4  = "&amount=";
var blk4a = "6.66";
var blk5  = "&image_url=";
var winpar = "width=600,height=400,scrollbars," +
             "location," +  // some users delete this
             "resizable,status";

function AddBoth (strn1, strn2, arg) {  // add to both fields
  AddStyle (strn1, "0");  // add to description
  AddPrice (strn2, arg);  // add to price
}

function AddPrice (strn, arg) {  // add to current price
var r1,r2,pos;
  r1 = blk4a * 1.0 + 0.005; // float 'em
  r2 = strn * 1.0;
  strn = escape (r1 + r2);  // add and put back to string
  pos = strn.indexOf ("."); // find decimal point
  blk4a = strn.substring (0, pos + 3);  // lop off extra
  if (arg != "0") CallPay ();
}

function AddStyle (strn, arg) {  // add to current description
  blk3n = blk3n + "%2C%20" + escape (strn);
  if (arg != "0") CallPay ();
}

function CallPay () { // call the PayPal shopping cart
  window.open (blk1 + blk1a +  // open the PayPal cart window
               blk2 + blk3 + blk3n + blk4 + blk4a + blk5,
               "paypal",
               winpar);
}

function CallView () { // call the PayPal shopping cart view
  window.open (blk1 + blk1d +  // open the PayPal cart window
               blk2,
               "paypal",
               winpar);
}

function ChkQty (obj1) { // input qty and check for discounts
var r1, r2, val;
  r1 = obj1.value;  // the qty entered by the user
  r2 = blk4a * 1.0; // float item price for math
  val = r1 * r2;    // the base price before discount 

  // the discount ladder... (start from highest)
  if (r1 > 999) {
    val = val * 0.7;  // 30 percent discount
  }
  else if (r1 > 99) {
    val = val * 0.8;  // 20 percent discount
  }
  else if (r1 > 49) {
    val = val * 0.85;  // 15 percent discount
  }
  else if (r1 > 9) {
    val = val * 0.9;  // 10 percent discount
  }
  AddStyle ("QTY=" + r1, "0");  // add to desc field
  SetPrice (val);               // set the new price
}

function SetBoth (strn1, strn2, arg) {  // set desc and value
  SetDesc  (strn1);
  SetPrice (strn2);
  if (arg != "0") CallPay ();
}

function SetDesc (strn) {  // set the desc field
  blk3n = escape (strn);
}

function SetPrice (strn) {  // set the current price
  blk4a = '0.0';
  AddPrice (strn, '0');
}
