// BCA Membership Form.
// copyright (c) 2008, David Gibson, LEEDS, UK

// ======================================================
// Specify next publication
// ======================================================

// eventually, grab this from database. for now, its hard-coded

// eventually, grab this from database. for now, its hard-coded

    $cksVolume 		= 36;   // <============ altered 19/01/10, 27/3/09
    $cksIssue 		= 1;	// <============ altered 9/01/10, 25/6/09 ( 27/3/09 6/10/08 )
    $speleoIssue 	= 15;	// <============ altered 26/8/09 (25/6/09 ( 6/10/08 )
    $bcaNews 		= 13;	// <============ altered 17/12/09, 25/6/09 ( 19/12/08
    
    $cksList		= '';   // <============ altered 27/3/09 16/2/09 @)
    $SpeleoList		= '';
    $bcaList		= '';
    
    // for Associates, Clubs $cksList and $speleoList are always '@'
    // for subscribers, $cksList is '@' after issue 1 of a vol has been published
    
    $cksNumber 		= "" + $cksVolume + $cksIssue;
    // $cksVolume*3 - 3 + $cksIssue;


// ======================================================
// Define Fees
// ======================================================


fees = new Array(1);  // make array intentionally too small
j=0;

fees[j++] = 15; 	// 	DIM_basic		fee_
fees[j++] = 16;		// 	DIM_caver		fee_
fees[j++] =  5;		// 	DIM_noncaver		fee
fees[j++] =  0;		// 	DIM_prepaid_ins		fee_

fees[j++] = 20;		// 	bcra_fee(std)		fee_BCRA_std
fees[j++] = 12;		// 	bcra_fee(reduced)	fee_BCRA_reduced

fees[j++] =  3;		// 	post_sp_WE		fee_
fees[j++] =  6;		// 	post_sp_ROW		fee_
fees[j++] =  3;		// 	post_cks_WE		fee_
fees[j++] =  6;		// 	post_cks_ROW		fee_

fees[j++] = -75;	// 	join_december		fee_  (join for last month of present year only)
fees[j++] = '+25';	// 	join_nextyear		fee_  (as above but also for all of next year)
fees[j++] = '  0'; 	// 	join_january		fee_
fees[j++] = -25;	// 	join_april		fee_
fees[j++] = -50;	// 	join_july		fee_
fees[j++] = -75;	// 	join_october		fee_
fees[j++] = -100;	// 	join_free		fee_
jmax = j-1;


// ======================================================
// Define some variables
// ======================================================

var footlegFlag = false;  
// set this to true whilst processing a window.confirm to avoid Firefox bug.
// if flag is true we dont allow form to be submitted

// var $hy = '&nbsp;-&nbsp;';


// ======================================================
// Initialise Form (called from BODY ONLOAD)
// ======================================================

function initialise()
{
  df = document.form;
  // we could use CHECKED in html, but this is clearer
  df.DIM_basic.checked = true;
  df.isCaver1.checked = true;
  
  /*
  estimatedCavers = (df.surname.value != '') + (df.surname2.value != '');
  if (estimatedCavers == 0) estimatedCavers = 1;
  df.DIM_caver.selectedIndex = estimatedCavers;
  df.DIM_noncaver.selectedIndex = 0;
  df.DIM_prepaid_ins.selectedIndex = 0;
  */
  
  if ((!df.country[0].checked) & (!df.country[1].checked) & (!df.country[2].checked) & (!df.country[3].checked))
  { df.country[0].checked = true; }
  
  clearDiscountBoxes();
  setDiscountBoxDefault();
  
  tidyImportedData();
  
  recalculate('');

}
  

// ======================================================
// Helper Functions
// ======================================================

function writeFee(s1,s2)
  // Fees must be integer pounds for this function.
  // This function writes the fee with optional string arguments either side.
  // (Needed because my HTML editor inserts unwanted spaces around SCRIPT tags)

  {
  var undefined;  // undefined is a variable wihch is undefined because it has not been given a value
  if (s1 === undefined) { s1 = ''}  // cant use (s1 == null) as firefox wont accept this
  if (s2 === undefined) { s2 = ''}  // in JS v1.2 [special exception]
  document.write(s1, fees[j++], s2);
  if (j > jmax) { j = 0; }
  document.close();
  }

function money_blankzero(m)
{
  if (m == 0) return ''; 
  return money(m)
}
  
function money(m)
  // Make a money string, right-aligned, 4 pounds digits and two decimal places
  // This is used to set the VALUE attribute in the sub-total boxes
{
   
  var m0 = m; m = ' ' + Math.abs(m); // forces m to be a string
  var dp = m.indexOf('.');
  if (dp == -1) 		{ m += '.00' ; }
  else if (dp == m.length -1) 	{ m += '00'; }
  else if (dp == m.length -2) 	{ m += '0'; }
  if (dp == 0)			{ m = '0' + m; }
  m = '  ' + m;
  m = m.substr(m.length -7);  // Use 7 for 4 pounds digits; 6 for 3
  m = '£' + m;
  if (m0 < 0) { m += '-'; } else { m += ' '; }
  return m;
}

function readMoney(m)
  // Read a string and extract the amount of money
  // Reads the VALUE attribute of subtotals
  {
  if (m=='') { return 0; }
  var sign = 2 * (m.indexOf('-') == -1) - 1;
  var amt = parseFloat(m.substr(2));
  return (sign * amt);
  }

/* --------------------------------------------------------------------------------

function punctuate(s)
  {
  if (s != '') { return ', ' + s; }
  else         { return '' }
  }

*/
/* --------------------------------------------------------------------------------

function reportError(s1,e)
  {
  if (s1 != '') { return s1; }
  else          { return 'ERROR: ' + e; }
  }

*/
// --------------------------------------------------------------------------------

function pluralise(number, singular, plural)
  {
  if (number==1) { return number + ' ' + singular; }
  else           { return number + ' ' + plural;   }
  }

// --------------------------------------------------------------------------------

function warnNoUserAlteration()
    { window.alert('You cannot change this box yourself.\nThe value is calculated for you.'); }

/* --------------------------------------------------------------------------------

function parseInteger(qtyraw)
{
  if (qtyraw === '') return '' ;
  var qty = parseInt(qtyraw);
  if ((qty != qtyraw) | (qty > 500) | (qty < 0)) 
  {
    window.alert('You have not entered a valid number');
    return '';
  }
  return qty;
}

*/

function countryAlert()
{
  window.alert('Please select a country from the\n' +
  	       'drop-down list to the right');
}

function payCode(s1,s2,s3)
{
  suffix = '?';
  if (s3 == 'UK')  suffix = '';
  if (s3 == 'WE')  suffix = 'E';
  if (s3 == 'EE')  suffix = 'W';
  if (s3 == 'RW')  suffix = 'W';
  
  
  if ((s1 == 'DIM') 		& (s2 == ''))	 	return 'A' + suffix;
  if ((s1 == 'DIM-T') 		& (s2 == ''))	 	return 'B' + suffix; // T => non-caver
  if ((s1 == 'DIMJ') 		& (s2 == 'DIM2')) 	return 'C' + suffix;
  if ((s1 == 'DIMJ') 		& (s2 == 'DIM2-T'))  	return 'D' + suffix;
  if ((s1 == 'DIMJ-T') 		& (s2 == 'DIM2'))  	return 'D' + suffix;
  if ((s1 == 'DIMJ-T') 		& (s2 == 'DIM2-T'))  	return 'E' + suffix;
  
  if ((s1 == 'DIM-BK') 		& (s2 == ''))	 	return 'F' + suffix; // B => BCRA, K => C&KS
  if ((s1 == 'DIM-BK-T') 	& (s2 == ''))	 	return 'G' + suffix;
  if ((s1 == 'DIMJ-BK') 	& (s2 == 'DIM2-BK'))  	return 'H' + suffix;
  if ((s1 == 'DIMJ-BK') 	& (s2 == 'DIM2-BK-T'))	return 'I' + suffix;
  if ((s1 == 'DIMJ-BK-T') 	& (s2 == 'DIM2-BK'))	return 'I' + suffix;
  if ((s1 == 'DIMJ-BK-T') 	& (s2 == 'DIM2-BK-T'))	return 'J' + suffix;
  
  if (s1  == 'CIM')					return 'K' + suffix;
  if (s1  == 'CIM-T')					return 'L' + suffix;
  if (s1  == 'CIMS')					return 'M' + suffix;
  
  if ((s1 == 'DIM-B') 		& (s2 == ''))	 	return 'N' + suffix; // B => BCRA
  if ((s1 == 'DIM-B-T') 	& (s2 == ''))	 	return 'O' + suffix;
  if ((s1 == 'DIMJ-B') 		& (s2 == 'DIM2-B'))  	return 'P' + suffix;
  if ((s1 == 'DIMJ-B') 		& (s2 == 'DIM2-B-T')) 	return 'Q' + suffix;
  if ((s1 == 'DIMJ-B-T') 	& (s2 == 'DIM2-B')) 	return 'Q' + suffix;
  if ((s1 == 'DIMJ-B-T') 	& (s2 == 'DIM2-B-T')) 	return 'R' + suffix;
  
  return '?' + suffix;
}  

// ======================================================
// String Functions
// ======================================================

function stripComma(s)
{
  // WAS: while ((s.slice(-1) == ' ') | (s.slice(-1) == ',') | (s.slice(-1) == '.'))
  // THEN WAS: while (s.match(/\W$/)) 
  // WITH: { s = s.slice(0,-1);   }
  // return s;
  return s.replace(/[^a-zA-Z0-9)]+$/, '')
}

String.prototype.toTitleCase = function()
{
  // If string contains only upper case then convert it all to lower case first
  // This means that Caps Lock/Unlock is corrected but that "Big Road NW" stays as is.
  
  sUpper = this.toUpperCase();
  s = this;
  if (s == sUpper) s = s.toLowerCase();
  s = s.split(' ');
  s1 = '';
  for (i=0; i<s.length; i++)
  {
    s1 += s[i].charAt(0).toUpperCase() + s[i].substring(1) + ' ';
  }
  s1 = s1.slice(0,-1);
  
  // WAS:   s = this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
  // TRIED: s = s.replace(/ (.)/g, '_$1');  // & variants thereof, but cant convert $1 to upper
  
  return s1;
}

String.prototype.toCityCase = function()
{
  // convert to upper case, except words in brackets go to title case  
  s = this.toUpperCase();
  s = s.split(' ');
  s1 = ''; cityflag = false;
  for (i=0; i<s.length; i++)
  {
    if (s[i].charAt(0) == '(' )  { s1 += '(';  s[i] = s[i].substring(1); cityflag = true; }
    if (cityflag)
    {
      s1 += s[i].charAt(0) + s[i].substring(1).toLowerCase() + ' ';
    }
    else
    {
      s1 += s[i] + ' ';
    }
    if (s[i].slice(-1) == ')' )  { cityflag = false; }
  }
  s1 = s1.slice(0,-1);
  return s1;
}



function checkPostcode(pc, s1)
{
  // ----- check syntax of postcode -----
    // This is a basic check, based on BS 7666, as quoted at http://en.wikipedia.org/wiki/UK_postcodes#Format
    // [A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][A-Z-[CIKMOV]]{2}
    //               ^?                   ^?
    // There is a more complicated syntax check that could be done (see URL above) but is it worth it?
    
  $regexp = '^[A-Z]{1,2}[0-9][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$';

  if ((pc.match($regexp) == null) & (pc.indexOf('BFPO') == -1) & (pc != '')) 
  {
    window.alert('The postcode in section ' + s1 + ' does not appear to have \n' +
      		 'the correct format. If you do not know your postcode \n' +
      		 'please leave this box blank or, for overseas \n' + 
      		 'addresses, please see the note in Section B.');
    return false;
  }
  return true;
}

// ======================================================
// helpers for setting discount boxes
// ======================================================

function clearDiscountBoxes()
{
    df.join_january.checked  = false;
    df.join_april.checked    = false;
    df.join_july.checked     = false;
    df.join_october.checked  = false;
    df.join_december.checked = false;
    df.join_nextyear.checked = false;
    df.join_free.checked     = false;
}

function setDiscountBoxDefault()
{
    timenow = new Date();
    month = timenow.getMonth();
    year = timenow.getFullYear();
    
    if (month > 10)     { df.join_january.checked = true; }
    else if (month > 8) { df.join_october.checked = true; }
    else if (month > 5) { df.join_july.checked = true; }
    else if (month > 2) { df.join_april.checked = true; }
    else 		{ df.join_january.checked = true; }
}

function warnNoPostdating()
{ 
  clearDiscountBoxes();
  setDiscountBoxDefault();
  window.alert('You cannot post-date your membership application'); 
}

function warnNoBackdating()
{ 
  clearDiscountBoxes();
  setDiscountBoxDefault();
  window.alert('You cannot back-date this far'); 
  // note: this function should never be called, because the checkboxes should be HIDDEN if month!=11
}

// ======================================================
// Count characters in a textarea
// ======================================================

function countTextArea(textarea, max, $id) 
{
  textarea.value = textarea.value.substring(0, max);
  $remaining = max - textarea.value.length;   
  e = document.getElementById($id);	// use W3C DOM, global e
  if (!e) e = document.all[$id];	// Use IE4 DOM
  if (e)
  {
    e.innerHTML = $remaining + ' characters remaining'; // IE DOM but also implemented by NN and Moz
  }
}

// --------------------------------------------------------------------------------

function populate()
{
    df.city.value = 'LEEDS';
    df.postcode.value = 'LS8 4BX';
    df.street_line1.value = '12 Well House Drive';
    df.street_line2.value = 'Debug\'s \"quote\"';
    df.surname.value = 'GIBSON';
    df.fname.value = 'David';
    df.gift1_yes.checked = true;    df.gift1_no.checked = false;
    df.confirm1.checked = true;
    df.isCaver1.checked = true;
    df.bcra_fee[1].checked = true;
 }


// --------------------------------------------------------------------------------


// ---- botched addition F.T.B. for imported data....

function tidyImportedData()  // this will run in initialise();
{
  df.city.value 	= stripComma(df.city.value.toCityCase()		);
  df.postcode.value 	= stripComma(df.postcode.value.toUpperCase()	);
  df.surname.value 	= stripComma(df.surname.value.toUpperCase()	);
  df.fname.value 	= stripComma(df.fname.value.toTitleCase()	);
  df.surname2.value 	= stripComma(df.surname2.value.toUpperCase()	);
  df.fname2.value 	= stripComma(df.fname2.value.toTitleCase()	);
  df.building.value	= stripComma(df.building.value.toTitleCase()	);
  df.street_line1.value	= stripComma(df.street_line1.value.toTitleCase());
  df.street_line2.value	= stripComma(df.street_line2.value.toTitleCase());
  checkPostcode(df.postcode.value, 'B');
}

function eraseImportedData()  // this will run in the form RESET or these dont seem to get cleared
{
  df.city.value 	= '';
  df.postcode.value 	= '';
  df.surname.value 	= '';
  df.fname.value 	= '';
  df.surname2.value 	= '';
  df.fname2.value 	= '';
  df.building.value	= '';
  df.street_line1.value	= '';
  df.street_line2.value	= '';
  df.postcode.value	= '';
  df.number.value	= '';
  df.number2.value	= '';
  df.addr_status.value	= '';
}


// ======================================================
// Process User Clicks
// ======================================================

function recalculate(s)
{
  df = document.form;
  
  //  ----- boxes that user cannot alter -----
    
  if (s.substr(0,3)=='fee')	{ warnNoUserAlteration(); }
  if (s == 'DIM_basic')		{ df.DIM_basic.checked = true; warnNoUserAlteration(); }
  if (s.substr(0,5)=='post_')	{ warnNoUserAlteration(); }

//  if (s.substr(0,4)=='join')	{ warnNoUserAlteration(); }

  //  ----- preset for debugging ------------------

  if ((s == 'surname') & (df.surname.value == '%%'))
  {
    populate();    
    window.alert('form populated for debugging');
  } 

  //  ----- lookup data ------------------

  if (s == 'lookup')
  {
    // window.alert('This facility is not yet available'); return false; 
    if ((df.surname.value == '') | (df.number.value == ''))
    {  window.alert('You must specify a surname and membership number'); return false; }
    // submit form to this page
    df.action = '';
    df.submit();
  }
  
  // ------ M1office version ------------------

  if (s == 'countyNotUsed')
  {
    countymessage = 'do not use';
    if ((df.countyNotUsed.value != '') & (df.countyNotUsed.value != countymessage) )
    {
      window.alert('You cannot use this field. It will be deleted \n' +
      		   'when this form is submitted');
      df.countyNotUsed.value = '';
      return false;
    }
  }

  if (s == 'speedyBCRA')
  {
    if (df.speedyBCRA.checked)		// as a result of the click
    {
      df.speedyCKS.checked  = true;	// added to force paperCKS whenever BCRA box is checked
      df.bcra_fee[1].checked = (df.speedyCKS.checked  == true);
      df.bcra_fee[2].checked = (df.speedyCKS.checked  == false);
    }
    else
    {
      df.speedyCKS.checked  = false;
      df.bcra_fee[0].checked = true;
    }
  }
  
  if (s == 'speedyCKS')
  {
    if (df.speedyCKS.checked)		// as a result of the click
    {
      df.speedyBCRA.checked = true;
      df.bcra_fee[1].checked = true;
    }
    else
    {
      df.bcra_fee[2].checked = true;
    }
  }
  
  //  ----- address actions ------------------
  
  // if membership number given, but address is altered by user then assume he is 
  // correcting the pre-populated address data
  
  if (df.number.value != '')
  {
    if ((s == 'building') | (s == 'street_line1') | (s == 'street_line2') | (s == 'city') | (s == 'postcode'))
    { df.addr_status.value = 'user altered'; }
  }
  
  if (s == 'city')   		df.city.value 		= stripComma(df.city.value.toCityCase()	);
  if (s == 'postcode')  	df.postcode.value 	= stripComma(df.postcode.value.toUpperCase()	);
  if (s == 'surname')   	df.surname.value 	= stripComma(df.surname.value.toUpperCase()	);
  if (s == 'surname2')  	df.surname2.value 	= stripComma(df.surname2.value.toUpperCase()	);
  if (s == 'fname')  		df.fname.value 		= stripComma(df.fname.value.toTitleCase()	);
  if (s == 'fname2')    	df.fname2.value 	= stripComma(df.fname2.value.toTitleCase()	);
  if (s == 'postcode')  	checkPostcode(df.postcode.value, 'B');

  // added on 29-jun-08
  if (s == 'building')		df.building.value	= stripComma(df.building.value.toTitleCase()	);
  if (s == 'street_line1') 	df.street_line1.value	= stripComma(df.street_line1.value.toTitleCase());
  if (s == 'street_line2') 	df.street_line2.value	= stripComma(df.street_line2.value.toTitleCase());

  // added on 30-jun-08

  if ((s == 'street_line1') | (s == 'street_line2'))
  { if (df.street_line1.value == df.street_line2.value)  	{ df.street_line2.value = ''; } }

  if ((s == 'city') | (s == 'street_line2'))
  { if (df.street_line2.value.toUpperCase() == df.city.value)	{ df.street_line2.value = ''; } }

  if (s == 'building')
  {  if (df.building.value == parseInt(df.building.value))	
     { df.street_line1.value = df.building.value + ' ' + df.street_line1.value;
       df.building.value = '';
  }  }

  
  //  ----- country radio-button actions -------------------
  
  function clearAllButUK()  { df.WE_list.selectedIndex =0; df.EE_list.selectedIndex =0; df.ROW_list.selectedIndex =0; df.otherCountries.value = ''}
  function clearAllButWE()  {                              df.EE_list.selectedIndex =0; df.ROW_list.selectedIndex =0; df.otherCountries.value = ''}
  function clearAllButEE()  { df.WE_list.selectedIndex =0;                              df.ROW_list.selectedIndex =0; df.otherCountries.value = ''}
  function clearAllButROW() { df.WE_list.selectedIndex =0; df.EE_list.selectedIndex =0;                              }
  
  if ( s == 'UK')   { clearAllButUK(); }
  if ( s == 'WE')   { clearAllButWE(); }
  if ( s == 'EE')   { clearAllButEE(); }
  if ( s == 'ROW')  { clearAllButROW(); }
 
  if ((s == 'WE')  & (df.WE_list.selectedIndex == 0))  countryAlert();  
  if ((s == 'EE')  & (df.EE_list.selectedIndex == 0))  countryAlert();  
  if ((s == 'ROW') & (df.ROW_list.selectedIndex == 0)) countryAlert();  
    
  //  ----- country drop-down list actions ------------------
  
  $maxCountryList = 13;
  
  if ((s == 'WE_list')  & (df.WE_list.selectedIndex !=0))  { df.country[1].checked = true; clearAllButWE(); }
  if ((s == 'EE_list')  & (df.EE_list.selectedIndex !=0))  { df.country[2].checked = true; clearAllButEE(); }
  if ((s == 'ROW_list') & (df.ROW_list.selectedIndex !=0)) { df.country[3].checked = true; clearAllButROW(); }
  
  if ((s == 'ROW_list') & (df.ROW_list.selectedIndex == $maxCountryList)) 
  { window.alert('If your country is not in this list, \nplease type it in the box below'); }
  
  if ((s == 'ROW_list') & (df.ROW_list.selectedIndex != $maxCountryList)) 
  { df.otherCountries.value = ''; }
  
  
 if (s == 'otherCountries')
 {
   if ((df.otherCountries.value != '') & (df.otherCountries.value != df.ROW_list[df.ROW_list.selectedIndex].text))
   {
     df.ROW_list.selectedIndex = $maxCountryList;
     df.country[3].checked = true; 
     clearAllButROW();
     df.otherCountries.value = df.otherCountries.value.toTitleCase();
   }
 } 

  //  ----- from country settings, select postage type

  if (df.country[0].checked)  // UK
  {
    df.post_sp_WE.checked = false;
    df.post_sp_ROW.checked = false;
    df.post_cks_WE.checked = false;
    df.post_cks_ROW.checked = false;
  }
    
  if (df.country[1].checked)  // WE
  {
    df.post_sp_WE.checked = true;
    df.post_sp_ROW.checked = false;
    df.post_cks_WE.checked = df.bcra_fee[1].checked;  // BCRA standard fee
    df.post_cks_ROW.checked = false;
  }
   
  if ((df.country[2].checked) | (df.country[3].checked))  // EE and ROW
  {
    df.post_sp_WE.checked = false;
    df.post_sp_ROW.checked = true;
    df.post_cks_WE.checked = false;
    df.post_cks_ROW.checked = df.bcra_fee[1].checked;  // BCRA standard fee
  }
  
  /* What a fucking pain. Although Firefox likes {select.value} MSIE seems not
     to consider {value} to be a property of {select}, and therefore requires
     {select[select.selectedIndex].text}
  */
  
  if (df.country[0].checked) country1 = '';
  if (df.country[1].checked) country1 = df.WE_list[df.WE_list.selectedIndex].text;
  if (df.country[2].checked) country1 = df.EE_list[df.EE_list.selectedIndex].text;
  if (df.country[3].checked) 
  {
    if (df.ROW_list.selectedIndex == $maxCountryList)
          { country1 = df.otherCountries.value; }
    else  { country1 = df.ROW_list[df.ROW_list.selectedIndex].text;       }
  }
  countryWithEU = country1;
  $regexp = '\(EU\)';
  country1 = country1.replace($regexp,'');

  //  ----- check signature and caver boxes -----
  
  /* do we really need to check any of these?
  It causes difficulty when tryingt to initialise MC string in M1office
  
  if ((s == 'confirm1') & (df.surname.value == '')) df.confirm1.checked = false; 
  if ((s == 'isCaver1') & (df.surname.value == '')) df.isCaver1.checked = false; 
  if ((s == 'isCaver2') & (df.surname2.value == '')) df.isCaver2.checked = false; 
  if ((s == 'isChild1') & (df.surname.value == '')) df.isChild1.checked = false; 
  if ((s == 'isChild2') & (df.surname2.value == '')) df.isChild2.checked = false; 
  */  

  // ----- check Section C box values ------------
  // we no longer need the tests in this section except to say...

  if (s == 'DIM_prepaid_ins')
  {
    window.alert('To alter the figure in this box, either a) check/uncheck the\n' +
    		 '\'Insurance cover for a caver\' boxes in section B, or \n' +
    		 'b) check/uncheck the \'Insurance fee pre-paid\' boxes below.')
  }
  
  if ((s == 'DIM_caver') | (s == 'DIM_noncaver'))
  {
    window.alert('To alter the figure in this box, check/uncheck the\n' +
    		 '\'Insurance cover for a caver\' boxes in section B. \n');
  }

 // ----- make gift aid checkboxes work like radio buttons
  
  if (s == 'gift1_yes') { df.gift1_yes.checked = true;    df.gift1_no.checked = false; }
  if (s == 'gift1_no')  { df.gift1_yes.checked = false;   df.gift1_no.checked = true; }
  if (s == 'gift2_yes') { df.gift2_yes.checked = true;    df.gift2_no.checked = false; }
  if (s == 'gift2_no')  { df.gift2_yes.checked = false;   df.gift2_no.checked = true; }
  
  // ----- test and set discount check boxes
  // ----- first, make them work like radio buttons
  
  if (s == 'join_december') { clearDiscountBoxes(); df.join_december.checked  = true; }
  if (s == 'join_nextyear') { clearDiscountBoxes(); df.join_nextyear.checked  = true; }
  if (s == 'join_january')  { clearDiscountBoxes(); df.join_january.checked   = true; }
  if (s == 'join_april')    { clearDiscountBoxes(); df.join_april.checked     = true; }
  if (s == 'join_july')     { clearDiscountBoxes(); df.join_july.checked      = true; }
  if (s == 'join_october')  { clearDiscountBoxes(); df.join_october.checked   = true; }
  if (s == 'join_free')     { clearDiscountBoxes(); df.join_free.checked      = true; }
  
  // ----- now check for invalid options
  
  // these two options are only allowed in December. 
  if ((s == 'join_december') & (month != 11) ) { warnNoBackdating(); }
  if ((s == 'join_nextyear') & (month != 11) ) { warnNoBackdating(); }
  
  month_1 = (month + 1) % 12;
  // month_1 is now ZERO for December, 1 for January etc, so the following options
  // are not allowed TOO EARLY in the year (i.e. user is trying to post-date) or 
  // in DECEMBER. In December the options are as above, or join_january
  
  if ((s == 'join_april')    & (month_1 < 4) ) { warnNoPostdating(); }
  if ((s == 'join_july')     & (month_1 < 7) ) { warnNoPostdating(); }
  if ((s == 'join_october')  & (month_1 < 10)) { warnNoPostdating(); }
  
  
  // ----- check number of cavers -----
  // ----- set Section C boxes based on speedy data in M1office ------------
    
  joint = ((df.surname.value != '') & (df.surname2.value != ''));
    
  // do this as a recalculation, i.e. every time
  // if ((s == 'isCaver1') | (s == 'isCaver2') | (s == 'speedyPPI1') | (s == 'speedyPPI2') )
  {
    df.DIM_caver.selectedIndex		= (df.isCaver1.checked  & !df.speedyPPI1.checked)
    					+ (df.isCaver2.checked  & !df.speedyPPI2.checked & joint);
    df.DIM_noncaver.selectedIndex	= (!df.isCaver1.checked & !df.speedyPPI1.checked)
    					+ (!df.isCaver2.checked & !df.speedyPPI2.checked & joint);
    df.DIM_prepaid_ins.selectedIndex	= df.speedyPPI1.checked
    					+ (df.speedyPPI2.checked & joint);
    num_caver 		= df.DIM_caver.selectedIndex;
    num_noncaver	= df.DIM_noncaver.selectedIndex;
    num_prepaid_ins 	= df.DIM_prepaid_ins.selectedIndex;
  }

  // ----- calculate the fees
  
  j=0;
  
  df.fee_DIM_basic.value    	= money_blankzero(df.DIM_basic.checked 			* fees[j++]);
  df.fee_DIM_caver.value    	= money_blankzero(df.DIM_caver.selectedIndex 		* fees[j++]);
  df.fee_DIM_noncaver.value 	= money_blankzero(df.DIM_noncaver.selectedIndex 	* fees[j++]);
  
  if (df.DIM_prepaid_ins.selectedIndex == 0)
  {
    df.fee_DIM_prepaid_ins.value  = money_blankzero(df.DIM_prepaid_ins.selectedIndex	* fees[j++]);
  }
  else
  {
    df.fee_DIM_prepaid_ins.value  = money(df.DIM_prepaid_ins.selectedIndex		* fees[j++]);
  }
  
  df.fee_BCRA_std.value 	= money_blankzero(df.bcra_fee[1].checked		* fees[j++]);
  df.fee_BCRA_reduced.value 	= money_blankzero(df.bcra_fee[2].checked 		* fees[j++]);
    
  df.fee_post_sp_WE.value 	= money_blankzero(df.post_sp_WE.checked 		* fees[j++]);
  df.fee_post_sp_ROW.value 	= money_blankzero(df.post_sp_ROW.checked 		* fees[j++]);
  df.fee_post_cks_WE.value 	= money_blankzero(df.post_cks_WE.checked 		* fees[j++]);
  df.fee_post_cks_ROW.value 	= money_blankzero(df.post_cks_ROW.checked 		* fees[j++]);
  
  $subtotal_BCA =	readMoney(df.fee_DIM_basic.value) +
			readMoney(df.fee_DIM_caver.value) +
  			readMoney(df.fee_DIM_noncaver.value) +
			readMoney(df.fee_DIM_prepaid_ins.value) +
			readMoney(df.fee_post_sp_WE.value) +
			readMoney(df.fee_post_sp_ROW.value);

  $subtotal_BCRA = 	readMoney(df.fee_BCRA_std.value) +
			readMoney(df.fee_BCRA_reduced.value) +
			readMoney(df.fee_post_cks_WE.value) +
			readMoney(df.fee_post_cks_ROW.value) ;
			
  $subtotal = $subtotal_BCA + $subtotal_BCRA;

  df.fee_subtotal.value =  money_blankzero($subtotal);
			
  
  df.fee_join_december.value	= money_blankzero(df.join_december.checked * $subtotal	* fees[j++]/100);
  df.fee_join_nextyear.value	= money_blankzero(df.join_nextyear.checked * $subtotal	* fees[j++]/100);
  df.fee_join_january.value	= money_blankzero(df.join_january.checked * $subtotal	* fees[j++]/100);
  df.fee_join_april.value	= money_blankzero(df.join_april.checked   * $subtotal	* fees[j++]/100);
  df.fee_join_july.value	= money_blankzero(df.join_july.checked    * $subtotal	* fees[j++]/100);
  df.fee_join_october.value	= money_blankzero(df.join_october.checked * $subtotal	* fees[j++]/100);
  df.fee_join_free.value	= money_blankzero(df.join_free.checked    * $subtotal	* fees[j++]/100);
  
  $total = 	readMoney(df.fee_subtotal.value) +
  		readMoney(df.fee_join_december.value) +
  		readMoney(df.fee_join_nextyear.value) +
  		readMoney(df.fee_join_january.value) +
		readMoney(df.fee_join_april.value) +
		readMoney(df.fee_join_july.value) +
		readMoney(df.fee_join_october.value) +
		readMoney(df.fee_join_free.value);
		
  // increase the sub-totals figures
  fraction = $total/$subtotal;
  $subtotal_BCRA = $subtotal_BCRA * fraction;
  $subtotal_BCA  = $total - $subtotal_BCRA;
  		
  df.fee_total.value =  money($total);
  
  
  
  // calculate the membership class. This is done here so it can be displayed to the user
  
  memClass = 'DIM'; memClass2 = '';
  if (df.join_free.checked)		memClass += 'H';
  if (df.surname2.value != '')		memClass += 'J';
  if (!df.bcra_fee[0].checked)		memClass += '-B';
  if (df.bcra_fee[1].checked)		memClass += 'K';
  if (!df.isCaver1.checked)		memClass += '-T';

  if (df.surname2.value != '')		
  { 
    memClass2 = 'DIM2';
    if (!df.bcra_fee[0].checked)	memClass2 += '-B';
    if (df.bcra_fee[1].checked)		memClass2 += 'K';
    if (!df.isCaver2.checked)		memClass2 += '-T';
  }
  
  writeMemClass(memClass,  'showMC1');
  writeMemClass(memClass2, 'showMC2');
  
}

function writeMemClass(mcdata, mcid)
{
  e = document.getElementById(mcid);	// use W3C DOM, global e
  if (!e) e = document.all[mcid];	// Use IE4 DOM
  if (e) {e.innerHTML = mcdata;} 	// IE DOM but also implemented by NN and Moz
}

// ======================================================
// Check and submit form
// ======================================================

function checkAndSubmit(button)
{
  if (button != '_submit')
  {
    populate();  // populate for debugging
    recalculate('');
    window.alert('Populating debug info');
    return false;
  }
  
  if (!checkUserInput()) return false;
  
  if (jsversion != 'JS1v2')
  {
    window.alert('Your browser is reporting that JavaScript 1.2 \n' +
    		 'is not available, and so you cannot submit  \n' +
    		 'this form.');
    return false;
  }
  
  buildPurchaseOrder();
  addSubsInfo();
  addValuesToForm();
  // df.submit(); 
  df.action = "../../shr2/confirm.html";
  return true; // instead of df.submit(), now PAY button is type=SUBMIT
}
  




  //  -----  Check user input ---------------------------
  
function checkUserInput()
{  
  //  ----- check integrity of name and address -----
   
   if (df.surname.value == '')
     { window.alert('You have not entered a surname in  \nsection B.'); return false; }
     		    
   if ((df.surname2.value == '') & (df.fname2.value != ''))
     { window.alert('You have not entered a surname in section B,\nfor the second-listed applicant.'); return false; }
     
   if ((df.building.value != '') & (df.street_line1.value == ''))
   {
     df.street_line1.value = df.building.value;
     df.building.value = '';
   }
     		    
   if ( ((df.street_line1.value == '') | (df.city.value == '')) & (df.postcode.value.indexOf('BFPO') < 0) )
     { window.alert('Your postal address appears to be  \nincomplete in section B.'); return false; }

   if ((df.country[0].checked) & (df.postcode.value == ''))
     { window.alert('Your postcode is missing in section B.'); return false; }
     
     
/*   if ((df.countyNotUsed.value != '') & (df.countyNotUsed.value != 'do not use') )
   { 
     window.alert('The county field is not used as counties are no longer \n' +
         	  'part of UK postal addresses. Please ensure that the data\n' +
     		  'in this field is placed elsewhere, if that is necessary');
     return false;
   }
   else  
   {
     df.countyNotUsed.value = '';
   }
*/     
  //  ----- check 'signature' boxes -------------------
  
  if (!df.confirm1.checked)
    { window.alert('You have not checked the \'signature box\'  \n' +
     		   'in section B.'); return false; }
  
//  if ((!(df.confirm2.checked) & df.surname2.value != ''))
//    { window.alert('You have not checked the \'signature box\'  \n' +
//     		   'in section B, for the second-listed applicant.'); return false; }

  //  ----- check country data has been given ---------
  
  if ((df.country[1].checked) & (df.WE_list.selectedIndex == 0))
    { window.alert('You have indicated an overseas address [WE], but \n' +
    		   'you have not selected a country in section B.');   return false; }

  if ((df.country[2].checked) & (df.EE_list.selectedIndex == 0))
    { window.alert('You have indicated an overseas address [EE], but \n' +
    		   'you have not selected a country in section B.');   return false; }

  if ((df.country[3].checked) & (df.ROW_list.selectedIndex == 0))
    { window.alert('You have indicated an overseas address [RW], but \n' +
    		   'you have not selected a country in section B.');   return false; }

  if ((df.country[3].checked) & (df.ROW_list.selectedIndex == $maxCountryList) & (df.otherCountries.value = ""))
    { window.alert('You have indicated an overseas address [RW], but \n' +
    		   'you have not selected a country from the list or \n' +
    		   'typed one in the box in section B.');   return false; }
    		   
    // ----- use of postcode box ------------------------------

  if ((!df.country[0].checked) & (df.postcode.value != ''))
    { window.alert('You have indicated an overseas address but you\n' +
    		   'have typed a postcode in the \'UK postcode\' box\n' +
    		   'in section B. Please delete this and read the \n' +
    		   'note on overseas addresses in section B.');   return false; }
    		   
    		   
  if (!checkPostcode(df.postcode.value, 'B')) return false;

  //  ----- check insurance numbers match applicants -----    
  // simpler than it used to be

  if ((df.isCaver2.checked) & (!joint))
  { window.alert('You have indicated more cavers in section B  \n' +
    		 'than you have applicants');
    return false;
  }

  $insuranceDetails = 'section C';
  if (df.formsubtype.value == 'office') $insuranceDetails = 'section B';
  
  if ((df.speedyPPI2.checked) & (!joint))
  { window.alert('You have indicated more insurance exemptions in  \n' + $insuranceDetails +
  		 ' than you have applicants in section B');
    return false;
  }

  //  ----- check insurance exemption reason has been completed    

  if ((df.insurance_exemption.value != '') & (df.DIM_prepaid_ins.selectedIndex == 0))
    { window.alert('You have entered some text in the Insurance Exemption box\n' +
		   'in section C but you have not said in ' + $insuranceDetails + '\n' +
		   'how many applicants have pre-paid their insurance.');   return false; }

  if ((df.insurance_exemption.value == '') & (df.DIM_prepaid_ins.selectedIndex != 0))
    { window.alert('You have indicated in ' + $insuranceDetails + ' that applicant(s) have \n' +
		   'pre-paid the insurance contribution, but you have not  \n' +
		   'given a reason in the Insurance Exemption box in section C.');   return false; }
		   
  //  ----- check whether Gift Aid boxes are checked -----
  
  // If only one applicant then clear the gift aid check boxes for 2nd applicant
  if ( (df.surname2.value == '') & ((df.gift2_yes.checked) | (df.gift2_no.checked))) 
  { df.gift2_yes.checked = false; df.gift2_no.checked = false; }

  // If gift aid 1 boxes not checked but BCRA membership required then advise...
  if ( (!df.gift1_yes.checked) & (!df.gift1_no.checked) & (!df.bcra_fee[0].checked) & (!df.join_free.checked) ) 
  {  window.alert('You have not completed a BCRA gift-aid declaration\n' +
		  'in section D. Please check the YES or NO box.'); return false; }

  // If gift aid 2 boxes not checked but BCRA joint membership required then advise...
  if ( (df.surname2.value != '') & (!df.gift2_yes.checked) & (!df.gift2_no.checked) & (!df.bcra_fee[0].checked)) 
  {  window.alert('You have not completed a BCRA gift-aid declaration.\n' +
		  'for the second-listed applicant.\n' +
		  'Please check the YES or NO box.'); return false; }
  
  // If either gift aid = yes box checked but BCRA membership NOT required then advise...
  if ( ((df.gift1_yes.checked) | (df.gift2_yes.checked)) & (df.bcra_fee[0].checked)) 
  { window.alert('You have completed a BCRA gift-aid declaration, but \n' +
		 'you have not opted for BCRA membership. You need \n' +
		 'to opt for BCRA membership or say NO to the gift-aid\n' +
		 'declaration in section D. '); return false; }

  // If either gift aid = no box checked but BCRA membership NOT required then clear the gift aid boxes
  if ( ((df.gift1_no.checked) | (df.gift2_no.checked)) & ((df.bcra_fee[0].checked) | (df.join_free.checked)) ) 
  { df.gift1_no.checked = false; df.gift2_no.checked = false; }

  gift1 = 'n/a';
  gift2 = 'n/a';
  if (df.gift1_yes.checked) gift1 = 'yes';
  if (df.gift1_no.checked)  gift1 = 'no';
  if (df.gift2_yes.checked) gift2 = 'yes';
  if (df.gift2_no.checked)  gift2 = 'no';

// -- check for discount options in December
// 30-nov-09 changed 2009 to 'next year' in strings below

  if (df.join_december.checked)
  { return window.confirm('You have requested membership for the remainder \n' +
  		 'of the current year only. Your insurance cover  \n' +
  		 'will cease on 31 December. \n\n' +
  		 'Because of the timing of your application, you  \n' +
  		 'may not receive a renewal notice for next year. If   \n' +
  		 'you require membership for next year, please consider\n' +
  		 'purchasing it now. \n\n' +
  		 'Do you want to submit this application as it is?');
  }
  
  if ((month == 11) & (df.join_january.checked))
  { return window.confirm('You have requested membership for ' +
  (year + 1) + '. \n\n' +
  		 'If this application is for a NEW membership (as \n' +
  		 'opposed to a RENEWAL) then your insurance cover \n' +
  		 'will not begin until 1 January. If you require  \n' +
  		 'your insurance cover to begin before then, you  \n' +
  		 'must purchase membership for the remainder of   \n' +
  		 'the current year. \n\n' +
  		 'Do you want to submit this application as it is? \n' +
  		 '(If this is a RENEWAL, click OK). ');
  // nead year+1 in above as $insuranceYear is not yet set
  }
  
// -- check for insurance options

  if ((df.isCaver1.checked) & (!df.country[0].checked))
  { return window.confirm('You have requested insurance for a caver who lives\n' +
  		  'outside the UK. If you already have a similar\n' +
  		  'insurance from another national caving organisation\n' +
  		  'then you can save money by requesting the non-\n' +
  		  'caver rate. To proceed with this application, \n' +
  		  'click OK, or else click cancel and modify your\n' +
  		  'application to show yourself as a non-caver.');
  }

  // ----- everything is in order ------
  
  return true;
}


// ======================================================
// Write Purchase Order
// ======================================================

function buildPurchaseOrder()
{
  log = 'Form M1: Application for DIM Membership \n' +
        '--------------------------------------- \n\n';

// ----- add money --------------------------------------        

  log +=                               'DIM caver basic fee                        ' + df.fee_DIM_basic.value + '\n';
    
  if (num_caver		!= 0) { log += 'Insurance contribution for ' + pluralise(num_caver,  	  'caver     ', 'cavers    ') + '    ' + df.fee_DIM_caver.value + '\n'; }
  if (num_noncaver	!= 0) { log += 'Insurance contribution for ' + pluralise(num_noncaver,    'non-caver ', 'non-cavers') + '    ' + df.fee_DIM_noncaver.value + '\n'; }
  if (num_prepaid_ins	!= 0) { log += 'Insurance contribution for ' + pluralise(num_prepaid_ins, 'pre-paid  ', 'pre-paid  ') + '    ' + df.fee_DIM_prepaid_ins.value + '\n'; }
  if (df.bcra_fee[0].checked) { log += 'BCRA membership: not requested             ' + money(0) + '\n'; }
  if (df.bcra_fee[1].checked) { log += 'BCRA membership: standard rate             ' + df.fee_BCRA_std.value + '\n';  }
  if (df.bcra_fee[2].checked) { log += 'BCRA membership: reduced rate              ' + df.fee_BCRA_reduced.value + '\n' +
  				       '  (Print version of C&KS will be not be supplied)' + '\n'; }

  if (df.country[0].checked)  { log += 'Postage of publications to a UK address    ' + money(0) + '\n'; $countryCode = 'UK'}
                                       
  if (df.country[1].checked)  { log += 'Postage of publications to Western Europe\n'; $countryCode = 'WE'}
  if (df.country[2].checked)  { log += 'Postage of publications to Eastern Europe\n'; $countryCode = 'EE'}
  if (df.country[3].checked)  { log += 'Postage of publications to outside Europe\n'; $countryCode = 'RW'}
  
  if (!df.country[0].checked) { log += '  Country: ' + countryWithEU + '\n';}
  
  if (df.post_sp_WE.checked)  { log +=  '  Speleology                               ' + df.fee_post_sp_WE.value + '\n' };
  if (df.post_sp_ROW.checked) { log +=  '  Speleology                               ' + df.fee_post_sp_ROW.value + '\n' };
  if (df.post_cks_WE.checked) { log +=  '  Cave & Karst Science (print version)     ' + df.fee_post_cks_WE.value + '\n' };
  if (df.post_cks_ROW.checked){ log +=  '  Cave & Karst Science (print version)     ' + df.fee_post_cks_ROW.value + '\n' };
  
  log +=                                '                                              -----\n' + 
                                        'Sub-total                                  ' + df.fee_subtotal.value + '\n';
    
  if (df.join_december.checked){ log +=  fees[10] + '% discount for joining from October     ' + df.fee_join_december.value + '\n' };
  if (df.join_nextyear.checked){ log +=  fees[11] + '% membership fee for rest of this year  ' + df.fee_join_nextyear.value + '\n' };
  if (df.join_january.checked) { log +=  fees[12] + '% part-year discount                    ' + df.fee_join_january.value + '\n' };
  if (df.join_april.checked)   { log +=  fees[13] + '% discount for joining from April       ' + df.fee_join_april.value + '\n' };
  if (df.join_july.checked)    { log +=  fees[14] + '% discount for joining from July        ' + df.fee_join_july.value + '\n' };
  if (df.join_october.checked) { log +=  fees[15] + '% discount for joining from October     ' + df.fee_join_october.value + '\n' };
  if (df.join_free.checked)    { log +=          '-100% discount for free-issue membership   ' + df.fee_join_free.value + '\n' };

  
  log +=                                '                                              -----\n' + 
                                        'Total                                      ' + df.fee_total.value + '\n\n';

// ----- add name and address ---------------------------        

  $fname = df.fname.value;   if ($fname  != '') $fname += ' ';
  $fname2 = df.fname2.value; if ($fname2 != '') $fname2 += ' ';

  log += $fname + df.surname.value + '\n';
  if (df.surname2.value != '')		
    { log += 'Joint application with: ' +  $fname2 + df.surname2.value + '\n'; }
    
  // log += '\n' ;
  
  // HE08 uses form of...     addr += punctuate(df.locality.value);

  if (df.building.value !='') 		log += df.building.value + '\n';
  if (df.street_line1.value !='') 	log += df.street_line1.value + '\n';
  if (df.street_line2.value !='') 	log += df.street_line2.value + '\n';
  if (df.city.value !='') 		log += df.city.value + '\n';
  if (df.postcode.value !='') 		log += df.postcode.value + '\n';
  if (country1 !='') 			log += country1 + '\n';
  
// ----- add membership class etc -----------------------        
  
  log += '\n';
  log += 'Previous membership number                 ' ;
  if (df.number.value == '') {log += '(none)'; } else {log += df.number.value; }
  log += '\n';

  if (df.surname2.value != '')
  {
  log += '2nd applicant                              ' ;
  if (df.number2.value == '') {log += '(none)'; } else {log += df.number2.value; }
  log += '\n';
  }
  
  log +=     'Membership Class                           ' + memClass + '\n';
  
  if (df.isChild1.checked) {  log += 'This person\'s age is recorded as:          under-18\n'; }
  
  if (df.surname2.value != '')		
  { 
    log +=   'Membership Class for 2nd applicant         ' + memClass2 + '\n';

  if (df.isChild2.checked) {  log += 'This person\'s age is recorded as:          under-18\n'; }
    
  }  
  
// for 2010 dont use Payment code
//log += 'Payment code                               ' + payCode(memClass,memClass2, $countryCode) + '\n';
  log += 'Country code                               ' + $countryCode  + '\n';

  if (!df.bcra_fee[0].checked)
  {
    if (df.surname2.value == '')
    {
      log +=   'BCRA Gift-Aid Declaration                  ' + gift1 + '\n';
    }
    else
    {
      log += 'BCRA Gift-Aid Declaration (1st applicant)  ' + gift1 + '\n';;
      log += 'BCRA Gift-Aid Declaration (2nd applicant)  ' + gift2 + '\n';;
    }
  }
  
  
/*  December Error: error here - needs fixing 
    30-nov-09  fix below applied. notes ...

    join_december: -75%, join for last month of present year only
    join_nextyear: +25%  as above but also for all of next year
    join_january:    0%  join from start of year (could be next year or this year)
 
    ALSO: check that free-issue sub placed in december is for whole of next year
*/

  if (month == 11) 
  {
    if ((df.join_nextyear.checked) | (df.join_january.checked))
    { $insuranceYear = year + 1; }
    else
    { $insuranceYear = year; }
  }
  else
  { $insuranceYear = year; }

  $memberexpiry  = "31/12/" + $insuranceYear;
  
  
  // ======================= add periodicals info =============================
  
  periodicals = 'n' + $bcaList + $bcaNews + 's' + $SpeleoList + $speleoIssue;
  if (df.bcra_fee[1].checked) // i.e. cks paper option
  { periodicals += 'k' + $cksList + $cksNumber; }
  
  log += 'Periodicals code (for office use)          ' + periodicals  + '\n';
  
  
  
  if (num_prepaid_ins	!= 0) 
  { log += '\n* Insurance exemption reason given as...\n' + df.insurance_exemption.value + '\n'; }
 
   
}

// ======================================================
// Write subscription info
// ======================================================

function addSubsInfo()
{
  if (df.message.value != '') 
  { log += '\n* Message to BCA: ' + df.message.value + '\n'; }

  log += '\n* Your membership and insurance cover will expire at the end of ' + $insuranceYear + '.\n';
  
  if ((month == 11) & (df.join_january.checked))
  { log += '\n* If this is a new membership application (i.e. not a renewal) please note ' +
             'that your insurance cover will not start until 1 January ' + $insuranceYear + '.\n'; }
  
  { log += '\n* The next BCA newsletter to be issued will be #' +
           $bcaNews + '. Please check our web-site for back-issues.\n'; 
  }
  
  if (true)
  { log += '\n* The next issue of Speleology to be published will be #' +
           $speleoIssue + '. Please order separately any back-issues that you require.\n'; 
  }

  if (!df.bcra_fee[0].checked)
  { log += '\n* The next issue of Cave and Karst Science to be published will be volume ' +
           $cksVolume + '(' + $cksIssue + '). ' + 
           'Please order separately any back-issues that you require.\n'; 

//    if ($cksIssue > 1)
//    { log += 'If this is a membership renewal we can send you any missing back-issues of CKS free of ' +
//    	     'charge (apart from postage) but you must contact us to request this.' ;
//    }
  }
  log += '\n';
} 

// ======================================================
// Add useful parameters to Form
// ======================================================

// to make the PHP simpler, we record a few additional variables
// order, memberexpiry, periodicals, countryname, memClass, memClass2, breakdown
// When the order form is assembled in PHP, these might not be needed here.

function addValuesToForm()
{
  df.formtype.value = 'BCA9-M1-0v1';

  df.order_js.value 	= log;
  df.memberexpiry.value	= $memberexpiry;
  df.periodicals.value	= periodicals;
  df.countryname.value	= country1;
  df.memClass.value	= memClass;
  df.memClass2.value	= memClass2;
  
  if (df.join_december.checked){ fraction =  fees[10] + '%'; }
  if (df.join_nextyear.checked){ fraction =  fees[11] + '%'; }
  if (df.join_january.checked) { fraction =  fees[12] + '%'; }
  if (df.join_april.checked)   { fraction =  fees[13] + '%'; }
  if (df.join_july.checked)    { fraction =  fees[14] + '%'; }
  if (df.join_october.checked) { fraction =  fees[15] + '%'; }

  df.breakdown.value = $subtotal_BCA + ',' + 
  	$subtotal_BCRA + ',' + 
  	0 + ',' + 
  	0 + ',' + 
	fraction;
}      