// 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=dave%40designitgear.com";
var blk2a = "&quantity=";
var blk2q = "";
var blk3  = "&item_name=";
var blk3n = "Test";
var blk4  = "&amount=";
var blk4a = "6.66";
var blk5  = "&image_url=https%3a//" + 
     "oursecurewebsite.com/designit/img/digpaypal.gif"
var blk6 = "&item_number=";
var blk7 = "unknown";  // default item number
var blk8 = "&on0=";  // option name column
var blk9 = "Options";  // default option name
var blk10 = "&os0=";  // option value column
var blk11 = "None";  // default option value
var useoptions = 0; // only use options if addstyle is called

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
  useoptions = 1;
  blk11 = escape (strn);
  // blk3n = blk3n + "%2C%20" + escape (strn);
  if (arg != "0") CallPay ();
}

function fullUrl () {
  var urlBase = blk1 + blk1a + blk2 + blk2a + blk2q + blk3 + blk3n + 
    blk4 + blk4a + blk5 + blk6 + blk7;
  var optionsPart = '';
  if (useoptions == 1) {
    optionsPart = blk8 + blk9 + blk10 + blk11;
  }
  var result = urlBase + optionsPart;
  return result;    
}

function CallPay () { // call the PayPal shopping cart
  url = fullUrl();
  window.open (url, "paypal", winpar);
  // window.open (blk1 + blk1a + // open the cart window
  // 		  blk2 + blk2a + blk2q + 
  // 		  blk3 + blk3n + blk4 + blk4a + blk5 +
  // 		  blk6 + blk7 + blk8 + blk9 + blk10 + blk11,
  // 		  "paypal",
  // 		  winpar);
}

function CallView () { // call the PayPal shopping cart view
  window.open (blk1 + blk1d +  // open the PayPal cart window
               blk2,
               "paypal",
               winpar);
}

function MakeBuy (obj1) {  //get form data for PayPal
var i,obj,temp,pick,pos;
var aray = new Array ();
useoptions = 0;
var errorcount = 0;
  for (i=0; i<1; i++) {  // get the dropdown stuff...
    obj = obj1.elements[i];     // The form element object
    blk9 = obj.name;
    pick = obj.selectedIndex;   // which option selected

    if (pick == 0) {
      alert('Please choose a ' + blk9 + '.');
      return;
    }

    if (pick) {
      aray[i] = obj.options[pick].text;  // isolate it

      temp = aray[i];  // get any price values from data
      pos  = temp.indexOf ("@$"); // is there a initial value?  
      if (pos > 0) {SetPrice (temp.substring (pos + 2));}

      pos  = temp.indexOf ("+$"); // is there an adjustment?  
      if (pos > 0) {AddPrice (temp.substring (pos + 2), "0");}
    }
  }

  // And the quantity...
  if (pick) {
    blk2q = obj1.elements[1].value;
  }
  else {
    blk2q = obj1.elements[0].value;    
  }


  if (pick) {
    AddStyle (aray.join (", "), "1");  // build desc and call cart
  }
  else {
    CallPay();
  }
    
}

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.00";
  AddPrice (strn, "0");
}

function SetItemNumber (strn) {  // set the item number field
  blk7 = escape (strn);
}

function SetDescPriceNum(desc, price, itemnum) {
  SetBoth(desc, price, 0);
  SetItemNumber(itemnum);
}  
