$(function()
{
	$('#ContributeForm')
		.find('#ContributeSubmit').click(validateContributeForm)
		.end()
		.find('input[name="amount_option"]').click(amountRadioClick)
		.end()
		.find('#OtherAmount').blur(otherAmount_blur);
});

function amountRadioClick()
{
	var amountRadio = $(this);

	amountRadio.closest('#ContributeForm').find('#Amount').attr('value', amountRadio.val());
}

function otherAmount_blur()
{
	var amountTextBox = $(this);
	var dollarAmount = amountTextBox.val();
	
	if(dollarAmount != '')
		amountTextBox.closest('#ContributeForm').find('#Amount').attr('value', dollarAmount);	
}

function validateContributeForm()
{
	var amount = $(this).parent().siblings('#Amount').val();
	
	if(isFinite(amount))
	{
		amount = parseInt(amount);
		
		if(amount <= 0 || amount > 6100)
		{
			alert('Please choose a dollar amount between $1 and $6100 for your contribution.');
			return(false);
		}
	}
	else
	{
		alert('Please enter a valid dollar amount.');	
		return(false);
	}
}