/* 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=ecirone@gmail.com";
var blkcc = "&currency_code=USD&lc=US";
var blk3  = "&item_name=";
var blk3n = "Test";
var blk4  = "&amount=";
var blk4a = "6.66";
var winpar = "width=700,height=400,scrollbars," +
             "location,resizable,status";
var referer = "";
var file = "";
var count = -1;

function AddDesc (strn) {  // add to current description
var c;
  if (blk3n.length > 0) c = ",+"; else c = "";
  blk3n = blk3n + escape (c + strn);
}

function AddPrice (strn) {  // add to current price
var pos;
  strn = escape (blk4a*1.0 + strn*1.0 + 0.005);  // add
  pos = strn.indexOf ("."); // find decimal point
  if (pos > 0) strn = strn.substring (0, pos + 3);  // lop off extra
  blk4a = strn;
}

function CallPay () { // call the PayPal shopping cart
var strn;
  strn = blk1 + blk1a + // open the PayPal cart window
         blk2 + blkcc + blk3 + blk3n + blk4 + blk4a;
  blk3n = "";  // zap data for next call
  blk4a = "";
  count--;
  window.open (strn, "paypal", winpar);
}

function CallView () { // call the PayPal shopping cart view
  window.open (blk1 + blk1d + blk2, "paypal", winpar);
}

function SetDesc (strn) {  // set the desc field
  blk3n = strn;
}

function SetReturn (strn) {
  referer = escape (strn);
}

function SetFile (strn) {
  file = escape (strn);
}

function SetPrice (strn) {  // set the current price
  blk4a = 0;
  AddPrice (strn*1.0);
}

function returnRefer () {
  history.go(count);
}
	

// site specific code...
function GetArgs () { // get the calling query string data
/* This function parses comma-separated name=value argument pairs
from the query string of the URL. It stores the pairs in properties
of an object which is returned to the caller. From David Flanagan's
"JavaScript" book (O'Reilly), example 13-5.
*/
var args = new Object (); // where to put the data
var i,pos,argname,value;
var query = location.search.substring(1); // get query string
var pairs = query.split (",");     // break at comma
  for (i=0; i<pairs.length; i++) {
    pos = pairs[i].indexOf ("=");  // look for name=value
    if (pos == -1) continue;       // skip if not found
    argname = pairs[i].substring (0, pos); // get name
    value = pairs[i].substring (pos + 1);  // get value
    args[argname] = value;         // store as property
  }
return args; // return object
}

// executed immediately after script loads
var args = GetArgs (); // see what user passed
SetDesc ("");
SetPrice (0);
if (args.iname)  {SetDesc (args.iname);} // load 'em up
if (args.irefer) {SetReturn (args.irefer);
if (args.ifile) {SetFile (args.ifile);}