function toggleDisplay(divId)
{
        var div = document.getElementById(divId);
        div.style.display = ( div.style.display == "block" ? "none" : "block" );
}

function getDropDown( name, limit, default_value )
{
	var toReturn = "";
	toReturn = "<select id=\"" + name + "\" name=\"data[" + name + "]\" onChange=\"paymentType( 'commitment', this.value )\">";
	for( var i = limit; i > 0; i-- )
	{
		if ( i == default_value )
			toReturn += "<option value=\"" + i + "\" SELECTED>" + i + "</option>";
		else
			toReturn += "<option value=\"" + i + "\">" + i + "</option>";
	}
	
	toReturn += "</select>";
	
	return toReturn;
}

function paymentType( change_type, new_length )
{
	//
	// Gathering the needed information
	//
	var div1 = document.getElementById('UserGradyear');
	var div2 = document.getElementById('UserDonationTotal');
	var div6 = document.getElementById('UserDonationType');
	var div3 = document.getElementById('donationDesc');
	var div4 = document.getElementById('donationAmount');
	var div5 = document.getElementById('commit_length');
	
	//
	// Setting the Payment Type
	//
	var d = new Date();
	var paymentType = div6.value;
	var paymentAmt = div2.value;

	//
	// One Time Donation
	//
	if ( paymentType == 'onetime')
	{
		div3.innerHTML = "<font color=\"red\"><b><u>One-Time Amount<br>To Friends of Georgtown Sailing</u></b></font>";
		
		if ( change_type == 'plan' )
		{
			div2.value = "";
			div4.innerHTML = "<font color=\"white\"><b>$ 0.00</b></font>";
		}
		else 
		{
			div2.value = (paymentAmt * 1).toFixed(2);
			
			if ( paymentAmt >= 1000 )
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .95).toFixed(2) + "</b></font>";
			else
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .9).toFixed(2) + "</b></font>";
		}
	}
	//
	// Recurring Annual Donation
	//
	else if ( paymentType == 'recurring-annual')
	{
		if ( change_type == 'commitment' )
			div3.innerHTML = "<font color=\"red\"><b><u>Recurring Annual Amount for " + getDropDown( 'commit_length', 10, new_length ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";
		else
			div3.innerHTML = "<font color=\"red\"><b><u>Recurring Annual Amount for " + getDropDown( 'commit_length', 10, 10 ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";

		if ( change_type == 'plan' )
		{
			div2.value = "";
			div4.innerHTML = "<font color=\"white\"><b>$ 0.00</b> (per year)</font>";
		}
		else 
		{
			div2.value = (paymentAmt * 1).toFixed(2);
			
			if ( paymentAmt >= 1000 )
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .95).toFixed(2) + "</b> (per year)</font>";
			else
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .9).toFixed(2) + "</b> (per year)</font>";
		}
	}
	//
	// Recurring Monthly Donation
	//
	else if ( paymentType == 'recurring-monthly')
	{
		if ( change_type == 'commitment' )
			div3.innerHTML = "<font color=\"red\"><b><u>Recurring Monthly Amount for " + getDropDown( 'commit_length', 10, new_length ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";
		else
			div3.innerHTML = "<font color=\"red\"><b><u>Recurring Monthly Amount for " + getDropDown( 'commit_length', 10, 10 ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";

		if ( change_type == 'plan' )
		{
			div2.value = "";
			div4.innerHTML = "<font color=\"white\"><b>$ 0.00</b> (per month)</font>";
		}
		else
		{
			div2.value = (paymentAmt * 1).toFixed(2);
			
			if ( paymentAmt >= 1000 )
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .95).toFixed(2) + "</b> (per month)</font>";
			else
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .9).toFixed(2) + "</b> (per month)</font>";
		}
	}
	//
	// Recurring Quigley One Time Donation
	//
	else if ( paymentType == 'quigley-onetime')
	{	
		if (( d.getFullYear() - 10 ) <= div1.value )
			div3.innerHTML = "<font color=\"red\"><b><u>Young Alumni Quigley Society One-Time Commitment<br>to Friends of Georgtown Sailing</u></b></font>";
		else
			div3.innerHTML = "<font color=\"red\"><b><u>Quigley Society One-Time Commitment<br>to Friends of Georgtown Sailing</u></b></font>";
					

		if ( change_type == 'plan' )
		{
			div2.value = (1000 / .95).toFixed(2);
			div4.innerHTML = "<font color=\"white\"><b>$ 1000.00</b></font>";
		}
		else if ( paymentAmt < 1052.63 )
		{
			alert( 'In Order to Qualify for Quigley, Young Alumni One-Time Donations Must Be More Than $1,000.00' );
			div2.value = (1000 / .95).toFixed(2);
			div4.innerHTML = "<font color=\"white\"><b>$ 1000.00</b></font>";
		}
		else 
		{
			div2.value = (paymentAmt * 1).toFixed(2);
			
			if ( paymentAmt >= 1000 )
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .95).toFixed(2) + "</b></font>";
			else
				div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .9).toFixed(2) + "</b></font>";
		}
	}
	//
	// Recurring Quigley Annual Donation
	//
	else if ( paymentType == 'quigley-annual')
	{
		if (( d.getFullYear() - 10 ) <= div1.value )
		{
			// Calculating the Remaining Years As Young Alumni
			var remainder = div1.value - (d.getFullYear() - 10);

			// Calculating the New Length Requested for Quigley Society
			if ( new_length )
				div3.innerHTML = "<font color=\"red\"><b><u>Young Alumni " + getDropDown( 'commit_length', remainder, new_length ) + " Year Annual Commitment<br>to Friends of Georgtown Sailing</u></b></font>";
			else
				div3.innerHTML = "<font color=\"red\"><b><u>Young Alumni " + getDropDown( 'commit_length', remainder, remainder ) + " Year Annual Commitment<br>to Friends of Georgtown Sailing</u></b></font>";

			// Calculating the New Commitment Length
			var commitment = document.getElementById('commit_length').value;
			
			if ( change_type == 'plan' )
			{
				var annual = (1000 / parseInt(commitment));
	
				var fee = 0;
				if ( annual > 1000 )
				{			
					fee = ( annual / .95 ) - annual;
				}
				else
				{
					fee = ( annual / .9 ) - annual;
				}
	
				div2.value = ((annual + fee) * commitment).toFixed(2);
				div4.innerHTML = "<font color=\"white\"><b>$ " + (annual).toFixed(2) + "</b> (per year)</font>";
			}
			else if ( change_type == 'commitment' )
			{
				var annual = (paymentAmt / parseInt(commitment));
	
				if ( annual >= 1000 )
					div4.innerHTML = "<font color=\"white\"><b>$ " + (annual * .95).toFixed(2) + "</b> (per year)</font>";
				else
					div4.innerHTML = "<font color=\"white\"><b>$ " + (annual * .9).toFixed(2) + "</b> (per year)</font>";
			}
			else 
			{
				var annual = (paymentAmt / parseInt(commitment));

				if ( annual >= 1000 )
					div4.innerHTML = "<font color=\"white\"><b>$ " + (annual * .95).toFixed(2) + "</b> (per year)</font>";
				else
					div4.innerHTML = "<font color=\"white\"><b>$ " + (annual * .9).toFixed(2) + "</b> (per year)</font>";
			}
		}
		else
		{
			if ( change_type == 'commitment' )
				div3.innerHTML = "<font color=\"red\"><b><u>Recurring Annual Amount for " + getDropDown( 'commit_length', 10, new_length ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";
			else
				div3.innerHTML = "<font color=\"red\"><b><u>Recurring Annual Amount for " + getDropDown( 'commit_length', 10, 10 ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";
	
			if ( change_type == 'plan' )
			{
				div2.value = "";
				div4.innerHTML = "<font color=\"white\"><b>$ 0.00</b> (per year)</font>";
			}
			else 
			{
				div2.value = (paymentAmt * 1).toFixed(2);
				
				if ( paymentAmt >= 1000 )
					div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .95).toFixed(2) + "</b> (per year)</font>";
				else
					div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .9).toFixed(2) + "</b> (per year)</font>";
			}
		}
	}
	//
	// Recurring Quigley Monthly Donation
	//
	else if ( paymentType == 'quigley-monthly')
	{
		if (( d.getFullYear() - 10 ) <= div1.value )
		{
			// Calculating the Remaining Years As Young Alumni
			var remainder = div1.value - (d.getFullYear() - 10);

			// Calculating the New Length Requested for Quigley Society
			if ( new_length )
				div3.innerHTML = "<font color=\"red\"><b><u>Young Alumni " + getDropDown( 'commit_length', remainder, new_length ) + " Year Monthly Commitment<br>to Friends of Georgtown Sailing</u></b></font>";
			else
				div3.innerHTML = "<font color=\"red\"><b><u>Young Alumni " + getDropDown( 'commit_length', remainder, remainder ) + " Year Monthly Commitment<br>to Friends of Georgtown Sailing</u></b></font>";

			// Calculating the New Commitment Length
			var commitment = document.getElementById('commit_length').value;
			
			if ( change_type == 'plan' )
			{
				var monthly = (1000 / parseInt(commitment * 12));
	
				var fee = 0;
				if ( monthly > 1000 )
				{			
					fee = ( monthly / .95 ) - monthly;
				}
				else
				{
					fee = ( monthly / .9 ) - monthly;
				}
	
				div2.value = ((monthly + fee) * commitment * 12).toFixed(2);
				div4.innerHTML = "<font color=\"white\"><b>$ " + (monthly).toFixed(2) + "</b> (per month)</font>";
			}
			else if ( change_type == 'commitment' )
			{
				var monthly = (paymentAmt / parseInt(commitment * 12));
	
				if ( monthly >= 1000 )
					div4.innerHTML = "<font color=\"white\"><b>$ " + (monthly * .95).toFixed(2) + "</b> (per month)</font>";
				else
					div4.innerHTML = "<font color=\"white\"><b>$ " + (monthly * .9).toFixed(2) + "</b> (per month)</font>";
			}
			else 
			{
				var monthly = (paymentAmt / parseInt(commitment * 12));

				if ( monthly >= 1000 )
					div4.innerHTML = "<font color=\"white\"><b>$ " + (monthly * .95).toFixed(2) + "</b> (per month)</font>";
				else
					div4.innerHTML = "<font color=\"white\"><b>$ " + (monthly * .9).toFixed(2) + "</b> (per month)</font>";
			}
		}
		else
		{
			if ( change_type == 'commitment' )
				div3.innerHTML = "<font color=\"red\"><b><u>Recurring Monthly Amount for " + getDropDown( 'commit_length', 10, new_length ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";
			else
				div3.innerHTML = "<font color=\"red\"><b><u>Recurring Monthly Amount for " + getDropDown( 'commit_length', 10, 10 ) + " Year(s)<br>to Friends of Georgtown Sailing</u></b></font>";
	
			if ( change_type == 'plan' )
			{
				div2.value = "";
				div4.innerHTML = "<font color=\"white\"><b>$ 0.00</b> (per month)</font>";
			}
			else
			{
				div2.value = (paymentAmt * 1).toFixed(2);
				
				if ( paymentAmt >= 1000 )
					div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .95).toFixed(2) + "</b> (per month)</font>";
				else
					div4.innerHTML = "<font color=\"white\"><b>$ " + (paymentAmt * .9).toFixed(2) + "</b> (per month)</font>";
			}
		}
	}
	//
	// Some Other Donation
	//
	else
	{
		div3.innerHTML = "<font color=\"red\"><b><u>Total Amount<br>To Friends of Georgtown Sailing</u></b></font>";
		div2.value = "";
		div4.innerHTML = "<font color=\"white\"><b>$ 0.00</b></font>";
	}
}
