var PP_Percent = .022; //PayPal Percentage Fee
var PP_TransFee = .30;      //PayPal Transaction Fee

//***************************************************************************
function CalcFee(Frm,x) {
 var SpanFee = document.getElementById('Fee'+x);   //point to "+ Fee1" text
 var SpanFeeA = document.getElementById('Fee'+x+'a');   //point to "+ Fee1a" text
 var SpanDues = document.getElementById('Dues'+x).firstChild.nodeValue; //Get Dues Amount
 var Qty = document.getElementById('Quan').value;
 var Fee = (PP_Percent*(SpanDues*Qty)) /(1-PP_Percent) + PP_TransFee;//=%*Amt/1-% + Transaction Fee
 var PayFee = document.getElementById('PayFee'+x).checked;
 var Total = (SpanDues * Qty).toFixed(2);
 var Amount
 Fee = Fee.toFixed(2);
 SpanFeeA.firstChild.nodeValue = Fee;
 document.getElementById('Total').firstChild.nodeValue = Total;
 Amount=(Qty*SpanDues+Fee*1).toFixed(2)
 if (PayFee) {
  if (x<=4) {
   Frm.amount.value = Amount;
   SpanFee.firstChild.nodeValue = " + $"+Fee+" Processing Fee ";
  }
  else { //x>2
   Frm.a3.value = (SpanDues*1+Fee*1).toFixed(2);
   SpanFee.firstChild.nodeValue = " + $"+Fee+" Processing Fee";
  }
 }
 else { //no PayFee
  if (x<=4) {
   Frm.amount.value = Qty*SpanDues;
   SpanFee.firstChild.nodeValue = " ";
  }
  else {x>4
   Frm.a3.value = SpanDues;
   SpanFee.firstChild.nodeValue = ' ';
  }
 }
}

//***************************************************************************
//addLoadEvent code obtained from http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 }
 else {
  window.onload = function() {
   if (oldonload) {
    oldonload();
   }
   func();
  }
 }
}
//addLoadEvent(CalcFee);
addLoadEvent(function() {  //run this code after page is loaded
 var x
 for (x=1; x<2; x++) {
  document.getElementById('PayFee'+x).checked = false;
  CalcFee(document.getElementById('PP_Form'+x),x);
 } //for x
});

