// David Gibson 6-1-06
// temporary stuff, till I sort these pages out properly

// more temporary mods on 17-12-08


// -----------------------------------------------------------------------

function updateform()
{
  if (document.form.paytype[0].checked) 
  {
    document.form.reference.value = 'new subscription';
  }
  else
  {
    if (document.form.reference.value == 'new subscription')
    {
      document.form.reference.value = '';
    }
  }
}

// -----------------------------------------------------------------------

function go(moneycode, facility)
{

  var ref = '';

  if (facility == 'PP')  
  { 
    actionName = 'PayPal';
    actionAddress = 'https://www.paypal.com/cgi-bin/webscr' ;
    // account = 'creg-payments@' ;  // ******* no longer use this, 6/1/09
    account = 'paypal@' ;
  }
  else
  { 
    actionName = 'NoChex';
    actionAddress = 'https://secure.nochex.com/' ;
    account = 'nochex@' ;
  }

  if ((document.form.reference.value == ''))
  {
    window.alert('You must enter a payment reference in the box');
    return false;
  }

  if (document.form.discount.checked) ref += '-d';

  document.form.action            = actionAddress;
  document.form.merchant_id.value       = account + 'caves.org.uk';
  
  // ******* no longer use this, 6/1/09
  //document.form.business.value  = account + 'bcra.org.uk';
  
  document.form.business.value    = account + 'caves.org.uk';

  if (moneycode == 'UK') cost = '8.50';
  else if (moneycode == 'EU') cost = '10.00';
  else if (moneycode == 'SU') cost = '10.00';
  else if (moneycode == 'WA') cost = '12.50';
  else 
  {
    cost = document.form.amount.value;		// for all non subs payment pages, read AMOUNT box
// ******* no longer use this, 6/1/09
//    if (moneycode != 'creg-misc')		// and if not the CREG-MISC page, assume its DG payments
//    {
//      document.form.business.value = account + 'caves.org.uk';
//      if (facility == 'PP') account = 'paypal@'; 
//    }
  }
  
  ref = document.form.reference.value + ', ' + moneycode;

  document.form.item_name.value   = ref;
  document.form.description.value = ref;
  document.form.amount.value      = cost;

  q = window.confirm('You are about to be directed to ' + actionName + '\n' +
                     'with a request to pay £' + cost + ' to the account of' + '\n' + 
                      account + 'caves.org.uk, with reference...\n\n' + ref + '\n')

  return q;
}


function readMoney(m)
{
  m = parseFloat(m);          // this adds 0 before dp, if needed.
  if (isNaN(m)) m=0;
  m = ' ' + m; // forces m to be a string
  var dp = m.indexOf('.');
  if (dp == -1) { m += '.'; dp = m.length-1; }  // if no dp, add this
  m += '00' ;
  m = m.substr(0,dp+3);       // truncate to 2 dec places
  m = m.substr(1);            // strip leading space added above
  return m;
}
