//validates the description boxes to make sure there is something in each box
function validateRegistration() {
	//Ensure the fields are populated
	if (document.description.name.value == "")
	{
		alert("Please fill out the registration name");
	}
	else if (document.description.address.value == "")
	{
		alert("Please fill out the registration address");
	}
	else if (document.description.city.value == "")
	{
		alert("Please fill out the registration city");
	}
	else if (document.description.state.value == "")
	{
		alert("Please fill out the registration state");
	}
	else if (document.description.zip.value == "")
	{
		alert("Please fill out the registration zip");
	}
	else if (document.description.phone.value == "")
	{
		alert("Please fill out the registration phone");
	}
	else if (document.description.email.value == "")
	{
		alert("Please fill out the registration email");
	}
	else if (!(document.description.individual.checked || document.description.family.checked ||
		document.description.mothers_work_club.checked || document.description.mothers_club.checked ||
		document.description.international.checked || document.description.friendship.checked ||
		document.description.memorial.checked))
	{
		alert("Please check a donation amount");
	}
	else if (!(document.description.none.checked || document.description.fifty.checked ||
		document.description.one_hundred.checked || document.description.two_hundred_fifty.checked ||
		document.description.five_hundred.checked || document.description.one_thousand.checked))
	{
		alert("Please check an additional donation amount");
	}
	else if (document.description.mothers_work_club_amount.disabled == false && 
		(26 > parseFloat(document.description.mothers_work_club_amount.value) ||
		100 < parseFloat(document.description.mothers_work_club_amount.value)))
	{
		alert("Please enter a valid donation amount between $26.00 - $100.00");
		
	}
	else if (document.description.mothers_club_amount.disabled == false && 
		(101 > parseFloat(document.description.mothers_club_amount.value) ||
		500 < parseFloat(document.description.mothers_club_amount.value)))
	{
		alert("Please enter a valid donation amount between $101.00 - $500.00");
	}
	else if (document.description.international_amount.disabled == false &&
		(501 > parseFloat(document.description.international_amount.value) ||
		1000 < parseFloat(document.description.international_amount.value)))
	{
		alert("Please enter a valid donation amount between $501.00 - $1000.00");
	}
	else if (document.description.friendship_amount.disabled == false &&
		(1001 > parseFloat(document.description.friendship_amount.value) || 
		5000 < parseFloat(document.description.friendship_amount.value)))
	{
		alert("Please enter a valid donation amount between $1001.00 - $5000.00");
	}
	else
	{
		//Submit the form
		document.description.amount.value = calculateDonation();
		document.description.item_name.value = getItemName();
		document.description.formsubmit.value = "1";
		document.description.submit();
	}
}

function checkDonation(checkedRadio) {
	//Uncheck all buttons first
	document.description.individual.checked = false;
	document.description.family.checked = false;
	document.description.mothers_work_club.checked = false;
	document.description.mothers_club.checked = false;
	document.description.international.checked = false;
	document.description.friendship.checked = false;
	document.description.memorial.checked = false;
	
	//Disable and clear all textboxes
	document.description.mothers_work_club_amount.disabled = true;
	document.description.mothers_work_club_amount.value = "";
	document.description.mothers_club_amount.disabled = true;
	document.description.mothers_club_amount.value = "";
	document.description.international_amount.disabled = true;
	document.description.international_amount.value = "";
	document.description.friendship_amount.disabled = true;
	document.description.friendship_amount.value = "";
	
	//Check the radio button they selected
	switch (checkedRadio.name) {
		case "individual": document.description.individual.checked = true; break;
		case "family": document.description.family.checked = true; break;
		case "mothers_work_club":
			document.description.mothers_work_club.checked = true;
			document.description.mothers_work_club_amount.disabled = false;
			break;
		case "mothers_club":
			document.description.mothers_club.checked = true;
			document.description.mothers_club_amount.disabled = false;
			break;
		case "international":
			document.description.international.checked = true;
			document.description.international_amount.disabled = false;
			break;
		case "friendship":
			document.description.friendship.checked = true;
			document.description.friendship_amount.disabled = false;
			break;
		case "memorial": document.description.memorial.checked = true; break;
	}
}

function checkAddDonation(checkedRadio) {
	//Uncheck all buttons first
	document.description.none.checked = false;
	document.description.fifty.checked = false;
	document.description.one_hundred.checked = false;
	document.description.two_hundred_fifty.checked = false;
	document.description.five_hundred.checked = false;
	document.description.one_thousand.checked = false;
	
	//Check the radio button they selected
	switch (checkedRadio.name) {
		case "none": document.description.none.checked = true; break;
		case "fifty": document.description.fifty.checked = true; break;
		case "one_hundred": document.description.one_hundred.checked = true; break;
		case "two_hundred_fifty": document.description.two_hundred_fifty.checked = true; break;
		case "five_hundred": document.description.five_hundred.checked = true; break;
		case "one_thousand": document.description.one_thousand.checked = true; break;
	}
}

function calculateDonation() {
	//Calculate the donation amount
	var amount;
	amount = 0;
	
	//First donation amount
	if (document.description.individual.checked)
	{
		amount = amount + 10.00;
	}
	else if (document.description.family.checked)
	{
		amount = amount + 25.00;
	}
	else if (document.description.mothers_work_club.checked)
	{
		amount = amount + parseFloat(document.description.mothers_work_club_amount.value);
	}
	else if (document.description.mothers_club.checked)
	{
		amount = amount + parseFloat(document.description.mothers_club_amount.value);
	}
	else if (document.description.international.checked)
	{
		amount = amount + parseFloat(document.description.international_amount.value);
	}
	else if (document.description.friendship.checked)
	{
		amount = amount + parseFloat(document.description.friendship_amount.value);
	}
	else if (document.description.memorial.checked)
	{
		amount = amount + 10000.00;
	}
	
	//Second donation amount
	if (document.description.none.checked == false)
	{
		if (document.description.fifty.checked)
		{
			amount = amount + 50.00;
			document.description.amount_deductable.value = "$50.00";
		}
		else if (document.description.one_hundred.checked)
		{
			amount = amount + 100.00;
			document.description.amount_deductable.value = "$100.00";
		}
		else if (document.description.two_hundred_fifty.checked)
		{
			amount = amount + 250.00;
			document.description.amount_deductable.value = "$250.00";
		}
		else if (document.description.five_hundred.checked)
		{
			amount = amount + 500.00;
			document.description.amount_deductable.value = "$500.00";
		}
		else if (document.description.one_thousand.checked)
		{
			amount = amount + 1000.00;
			document.description.amount_deductable.value = "$1000.00";
		}
	}
	
	return "$" + amount;
}

function getItemName()
{
	var name
	
	name=""
		//First donation amount
	if (document.description.individual.checked)
	{
		name = "Individual Donation";
	}
	else if (document.description.family.checked)
	{
		name = "Family Donation";
	}
	else if (document.description.mothers_work_club.checked)
	{
		name = "Mothers Work Club Donation";
	}
	else if (document.description.mothers_club.checked)
	{
		name = "Mothers Club Donation";
	}
	else if (document.description.international.checked)
	{
		name = "International Club Donation";
	}
	else if (document.description.friendship.checked)
	{
		name = "Friendship Sponsors Donation";
	}
	else if (document.description.memorial.checked)
	{
		name = "Memorial Endowment Donation";
	}
	
	name = name + " by " + document.description.name.value;
	return name;
}