// Support construction of dynamic PayPal args.

var blk1="https://www.paypal.com/cart/";
var blk1a = "add=1";
var blk1d = "display=1";
var blk2  = "&business=neworder%40ds3switch.com";
var blk3  = "&item_name=";
var blk3n = "Test";
var blk4  = "&amount=";
var blk4a = "2275.00";
var blk5  = "&return=http%3A//www.ds3switch.com/ppthanks.html&cancel_return=http%3A//www.ds3switch.com/ppcancel.html" +
     "&image_url=http%3a//" + 
     "www.ds3switch.com/images/cfb4pp.gif"
var winpar = "width=600, height=400, scrollbars," +
             "location," +  // some users delete this
             "resizable, status";


function chkint (qty) {
var re = /\d+/;
var newq;

   newq = qty.value.match (/\d+/); // remove whitespace from ends
   NOTOK = !re.test(newq);

   if (NOTOK){
      window.alert ("Please enter a quantity");
	return ("");
	}
   else {
	qty.value = newq;
	return ("1");
	}
}

function OrderSw (qty,chans,type,voltage) {
   if (chkint(qty)) {
	if (type[type.selectedIndex].value == "NONE")
	  window.alert ("Please select a transmission medium")
	else {
		if (voltage[voltage.selectedIndex].value == "NONE")
		  window.alert ("Please select a voltage")
		else {
		 if (chans[chans.selectedIndex].value == "NONE")
		  window.alert ("Please select single or dual telco channels")
		 else {
		  SetDesc ("100BaseTX to ");
		  AddStyle (chans[chans.selectedIndex].value,'0');
		  AddStyle (" ", '0');
		  AddStyle (type[type.selectedIndex].value,'0');
		  AddStyle (" ", '0');
		  AddStyle (voltage[voltage.selectedIndex].value,'0');
		  AddStyle (" Converter Ver5.1 @ ", '0');
		  SetPrice ("2275.00");
		  ChkQty(qty);
		  blk1d = "display=1";
		  CallPay();
		  }
		 }
		}
	}
}

function OrderLP () { //qty
//  if (chkint (qty)) {
        window.alert ("Please adjust upcoming PayPal qty.");
	  SetDesc ("Lightning Warranty");
	  SetPrice ("100.00");
	  blk1d = "display=1&unspecified_quantity=1";// + qty.value;
	  CallPay();
//	}
}

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 + escape (strn);
  if (arg != "0") CallPay ();
}

function CallPay () { // call the PayPal shopping cart
/*
document.order.testout.value = //blk1 + blk1a +  // open the PayPal cart window
//               blk2 + 
blk3 + blk3n + blk4 + blk4a 
//+ blk5
*/
  window.open (blk1 + blk1a +  // open the PayPal cart window
               blk2 + blk3 + blk3n + blk4 + blk4a + blk5,
               "cartwin",
               winpar);

}

function CallView () { // call the PayPal shopping cart view
  window.open (blk1 + blk1d +  // open the PayPal cart window
               blk2,
               "cartwin",
               winpar);
}

function ChkQty (obj1) { // input quantity 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 > 5) {
    r2 = r2 - 400.00;  // 
  }
  else if (r1 > 3) {
    r2 = r2 - 200.00;  // 
  }
  val = r1 * r2;
  AddStyle ("$" + r2, "0");
  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');
}
