function UpdateTotals() {

var SuccessMemb = false;
var SuccessContrib = false;
var Success = false;

var TotalDues = 0;
var Years = 0;
var TotalContribs = 0;

if (document.RenewForm.NumYears[0].checked == true) {
   Years = 1;
   }

if (document.RenewForm.NumYears[1].checked == true) {
   Years = 2;
   }

if (document.RenewForm.NumYears[2].checked == true) {
   Years = 3;
   }


if (document.RenewForm.MembType[3].checked == true) {
   TotalDues = 500;
   SuccessMemb = true;
   }

if (document.RenewForm.MembType[2].checked == true) {
   TotalDues = 10*Years;
   SuccessMemb = true;
   }

if (document.RenewForm.MembType[1].checked == true) {
   TotalDues = 25*Years;
   SuccessMemb = true;
   }

if (document.RenewForm.MembType[0].checked == true) {
   TotalDues = 15*Years;
   SuccessMemb = true;
   }

if (SuccessMemb == true) {
   document.RenewForm.MembDuesTotal.value = TotalDues;
   }


// In the following statements, the "*1" is used to ensure that the quantity is treated as a number,
// instead of a text string.  (There's probably a cleaner way to do this typecasting in JavaScript,
// but I'm a beginner and am doing it this way...)

if (isNaN(document.RenewForm.ContribBG.value) == false) {
  if (isNaN(document.RenewForm.ContribGF.value) == false) {
    if (isNaN(document.RenewForm.ContribLMF.value) == false) {
      TotalContribs = TotalContribs*1 + document.RenewForm.ContribBG.value*1 + document.RenewForm.ContribGF.value*1 + document.RenewForm.ContribLMF.value*1;
      document.RenewForm.ContribTotal.value = TotalContribs;
      SuccessContrib = true;
      }
    }
  }

if (SuccessMemb == true) {
  if (SuccessContrib == true) {
    document.RenewForm.TotalToPay.value = TotalDues*1 + TotalContribs*1;
    Success = true;
   }
  }

return Success;
}



function CreatePayPalFields() {

var Success = false;
var BlankFields = false;
var OptionText1 = "";
var OptionText2 = "";
var BlankFieldList ="";
var Years = 0;
var MembText = "";
var ContribText ="";
var NegativeFields = false;
var NegativeFieldList = "";

if (document.RenewForm.MemberName.value == "") {
   BlankFieldList = BlankFieldList + "Member name\n";
   BlankFields = true;
   }

if (document.RenewForm.MemberEmail.value == "") {
   BlankFieldList = BlankFieldList + "Member e-mail\n";
   BlankFields = true;
   }

if (document.RenewForm.HomePhone.value == "") {
   BlankFieldList = BlankFieldList + "Home phone\n";
   BlankFields = true;
   }

if (document.RenewForm.MembDuesTotal.value == "") {
   BlankFieldList = BlankFieldList + "Membership desired\n";
   BlankFields = true;
   }

if (BlankFields == true) {
   alert("Please fill in the following before checking out:\n\n" + BlankFieldList);
   }

if (Number(document.RenewForm.ContribBG.value) < 0) {
   NegativeFieldList = NegativeFieldList + "Bobbi Gillotti contribution\n";
   NegativeFields = true;
   }

if (Number(document.RenewForm.ContribGF.value) < 0) {
   NegativeFieldList = NegativeFieldList + "General fund contribution\n";
   NegativeFields = true;
   }

if (Number(document.RenewForm.ContribLMF.value) < 0) {
   NegativeFieldList = NegativeFieldList + "Live music fund contribution\n";
   NegativeFields = true;
   }

if (NegativeFields == true) {
   alert("The following fields must be blank or non-negative:\n\n" + NegativeFieldList);
   }


if (BlankFields == true || NegativeFields == true) {
   Success = false;
   }
else {
   Success = true;
   }

if (Success == true) {

   // If we've reached this point, then all form fields are valid, and we may proceed to checkout.

   document.RenewForm.item_name.value = "TIFD membership renewal/donation: " + document.RenewForm.MemberName.value + " (" + document.RenewForm.MemberEmail.value + "; " + document.RenewForm.HomePhone.value + ")";
   document.RenewForm.amount.value = document.RenewForm.TotalToPay.value;

   if (document.RenewForm.FamMember1Name.value == "") {
     // Do nothing!
   }
   else
     {
     OptionText1 = OptionText1 + "+ " + document.RenewForm.FamMember1Name.value + " (" + document.RenewForm.FamMember1Email.value + "); ";
     }

   if (document.RenewForm.FamMember2Name.value == "") {
     // Do nothing!
   }
   else
     {
     OptionText1 = OptionText1 + "+ " + document.RenewForm.FamMember2Name.value + " (" + document.RenewForm.FamMember2Email.value + "); ";
     }

   document.RenewForm.os0.value = OptionText1;


   if (document.RenewForm.NumYears[0].checked == true) {
      Years = 1;
      }

   if (document.RenewForm.NumYears[1].checked == true) {
      Years = 2;
      }

   if (document.RenewForm.NumYears[2].checked == true) {
      Years = 3;
      }

  if (document.RenewForm.MembType[3].checked == true) {
     MembText = "Life membership";
     }

  if (document.RenewForm.MembType[2].checked == true) {
     MembText = "Student membership, " + String(Years) + " yrs.";
     }

  if (document.RenewForm.MembType[1].checked == true) {
     MembText = "Family membership, " + String(Years) + " yrs.";
     }

  if (document.RenewForm.MembType[0].checked == true) {
     MembText = "Individual membership, " + String(Years) + " yrs.";
     }

  if (Number(document.RenewForm.ContribBG.value) > 0) {
     ContribText = ContribText + "BG contrib: $" + document.RenewForm.ContribBG.value + "; ";
     }

  if (Number(document.RenewForm.ContribGF.value) > 0) {
     ContribText = ContribText + "GF contrib: $" + document.RenewForm.ContribGF.value + "; ";
     }

  if (Number(document.RenewForm.ContribLMF.value) > 0) {
     ContribText = ContribText + "LMF contrib: $" + document.RenewForm.ContribLMF.value;
     }

  OptionText2 = MembText + "; " + ContribText;
  document.RenewForm.os1.value = OptionText2;


   } // end of if (Success...


// alert("About to exit CreatePayPalFields!");

return Success;
}



