﻿function addFields(f)
{ 
	total = 0.00;

	if (f.item_name.value == "Regular Membership $15.00")
		total += 15.00;

	if (f.item_name.value == "Associate Membership (Students under 21) - $10.00")
		total += 10.00;

	if (f.item_name.value == "Family Membership - $22.50")
		total += 22.50;

	if (f.item_name.value == "Institutional Membership (Non-Profit) - $50.00")
		total += 50.00;

	if (f.item_name.value == "Corporate Membership - $100.00")
		total += 100.00;

	f.amount.value=total;
}

function valid_page(theForm)
{

  if (theForm.item_name.value == "Select")
  {
    alert("Please select your membership level.");
    theForm.item_name.focus();
    return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Please enter your email address.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.last_name.value == "")
  {
    alert("Please enter your last name.");
    theForm.last_name.focus();
    return (false);
  }

  if (theForm.first_name.value == "")
  {
    alert("Please enter your first name.");
    theForm.first_name.focus();
    return (false);
  }

  if (theForm.address1.value == "")
  {
    alert("Please enter your address.");
    theForm.address1.focus();
    return (false);
  }

  if (theForm.city.value == "")
  {
    alert("Please enter your city.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.state.value == "")
  {
    alert("Please enter your state.");
    theForm.state.focus();
    return (false);
  }

  if (theForm.zip.value == "")
  {
    alert("Please enter your zip code.");
    theForm.zip.focus();
    return (false);
  }

  if (theForm.zip.value.length < 5)
  {
    alert("Please enter at least 5 numeric characters zip code field.");
    theForm.zip.focus();
    return (false);
  }

  if (theForm.zip.value.length > 10)
  {
    alert("Please enter at most 10 characters in the zip code field.");
    theForm.zip.focus();
    return (false);
  }
//*******
//  if (theForm.x_email.value == "")
//  {
//    alert("Please enter a value for the \"x_email\" field.");
//    theForm.x_email.focus();
//    return (false);
//  }

//  if (theForm.x_email.value.length < 10)
//  {
//    alert("Please enter at least 10 characters in the \"x_email\" field.");
//    theForm.x_email.focus();
//    return (false);
//  }

//  if (theForm.x_email.value.length > 60)
//  {
//    alert("Please enter at most 60 characters in the \"x_email\" field.");
//    theForm.x_email.focus();
//    return (false);
//  }
//

  if (theForm.amount.value.length > 12)
  {
    alert("Please enter at most 12 characters in the Donation Amount Field.");
    theForm.amount.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.amount.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the amount field.");
    theForm.amount.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the amount  field.");
    theForm.amount.focus();
    return (false);
  }
  
	document.Form.action = "https://www.paypal.com/cgi-bin/webscr"
	document.Form.submit();
	return true;

}

