$(document).ready(function(){					
	$('#slideshow').cycle({
		delay: 2000,
		speed: 1000
	});
	
	$('table tr:even').addClass('alt');
	
	$('#row4').css('background-color', '#EDF0D1');
	$('#text4').css('color', '#000');
	$('#memorialName, #luncheonName, #showRecurring').hide();
	$('#recipient').hide();
	
	
	$('.option_button').click(function() {
		
		$('.tableRowA > div').css("color", "#666");
		$('.tableRowB > div').css("color", "#666");
		$('.tableRowA').css("background-color", "#fff");
		$('.tableRowB').css("background-color", "#fff");
		
		$(this).parent("div").parent("div").css("background-color", "#EDF0D1");
		$(this).parent("div").siblings().css("color", "#000");
		
		var currentId = $(this).attr('id').replace(/[^0-9]/g, '');
		var amount = $(this).val();
		
		if (currentId == "11")
		{
			$("#otherAmount").attr("disabled", "");
		}
		else
		{
			$("#otherAmount").attr("disabled", "disabled");
			$("#otherAmount").val("0.00");
		}
		
/*		if ($("#council").attr("checked") == true)
		{
			if (amount < 1000)
			{
				$("#council").attr("checked", "");
				$("#noMembership").attr("checked", "checked");
			}
		}
		
		if ($("#president").attr("checked") == true)
		{
			if (amount < 5000)
			{
				$('#president').attr("checked", "");
				$("#noMembership").attr("checked", "checked");
			}
		}*/
	});
	
	
/*	$('.set_membership').click(function() {
		
		if ($(this).attr('id') == "council" && $("#otherAmount").val() < 1000 && $("#button8").attr("checked") == false && $("#button9").attr("checked") == false && $("#button10").attr("checked") == false)
		{
			alert('To join the Council of 100, you must select a donation level of $1000 or higher, or select "Other" in the form above and enter a donation of at least $1000.\n\nClick OK to change your donation.');
			$(this).attr("checked", "");
			$('#noMembership').attr("checked", "checked");
			return false;
		}
		
		if ($(this).attr('id') == "president" && $("#otherAmount").val() < 5000)
		{
			alert('To join the President\'s Council, you must select "Other" in the form above and enter a donation of at least $5000.\n\nClick OK to change your donation.');
			$(this).attr("checked", "");
			$('#noMembership').attr("checked", "checked");
			return false;
		}
		
	});*/
	
	
/*	$('#otherAmount').blur(function() {
		
		if ($(this).val() < 5000 && $("#president").attr("checked") == true)
		{
			alert('To join the President\'s Council, you must select "Other" in the form above and enter a donation of at least $5000.\n\nClick OK to change your donation.');
			$(this).attr("checked", "");
			$('#noMembership').attr("checked", "checked");
			return false;
		}
		
	});*/
	
	$("input[name='recurring']").click(function(){
		if ($(this).attr('id') == "recurring_yes") {
			$('#showRecurring').show();
		}else{
			$('#showRecurring').hide();
		}
	});
	$('.set_memorial').click(function() {
		if ($(this).attr('id') == "aLuncheon")
		{
			$('#memorialName').hide();
			$('#name').val("");
			$('#luncheonName').show();
			$('#luncheon_name').focus();
		}	
		else if ($(this).attr('id') == "noMemorial")
		{
			$('#memorialName,#luncheonName').hide();
			$('#name').val("");
			$('#luncheon_name').val("");
		}
		else
		{
			$('#luncheonName').hide();
			$('#luncheon_name').val("");
			$('#memorialName').show();
			$('#name').focus();
		}
		
	});
	
	
	$('#shippingChoice').click(function() {
		
		if ($(this).attr("checked"))
		{
			$('#recipient').show();
			$("#shipTo_firstName").focus();
		}
		else
		{
			$('#recipient').hide();
			$('#shipTo_firstName').val("");
			$('#shipTo_lastName').val("");
			$('#shipTo_street1').val("");
			$('#shipTo_street2').val("");
			$('#shipTo_city').val("");
			$('#shipTo_state').val("");
			$('#shipTo_postalCode').val("");
		}
		
	});
	
	
	$('#orderForm').submit(function() {
		
		var otherAmount = $("#otherAmount").val();
		
		if ($('#button11').attr("checked") == true)
		{
			if ((otherAmount == "0.00") || (otherAmount <= 0))
			{
				alert('You must enter a donation amount.\n\nClick OK to try again.');
				$('#otherAmount').focus();
				return false;
			}
		}
		if ($('#recurring').val() == "Yes" ){
			if ( $('#recurring_period').val() == "" ) {
				alert('Please select the period of your recurring donation');
				$('#recurring_period').focus();
				return false;
			}
			if ( $('#recurring_duration').val() == "" ) {
				alert('Please select the duration of your recurring donation');
				$('#recurring_duration').focus();
				return false;
			}
		}
		if ($('#aLuncheon').attr("checked") == true)
		{
			if ( $('#luncheon_name').val() == "" ) {
				alert('Please enter the name of the luncheon host');
				$('#luncheon_name').focus();
				return false;
			}
		}
		if (($('#aMemorial').attr("checked") == true) || ($('#anHonor').attr("checked") == true))
		{
			if ($('#name').val() == "")
			{
				alert('If you are donating in memory or honor of another person, you must enter their name.\n\nClick OK to try again.');
				$('#name').focus();
				return false;
			}
		}
		
		if ($('#shippingChoice').attr("checked") == true)
		{
			if ($('#shipTo_firstName').val() == "")
			{
				alert('You must enter the first name of the recipient.\n\nClick OK to try again.');
				$('#shipTo_firstName').focus;
				return false;
			}
			
			if ($('#shipTo_lastName').val() == "") {
				alert('You must enter the last name of the recipient.\n\nClick OK to try again.');
				('#shipTo_lastName').focus();
				return false;
			}
			
			if ($('#shipTo_street1').val() == "") {
				alert('You must enter the recipient\'s street address.\n\nClick OK to try again.');
				('#shipTo_street1').focus();
				return false;
			}

			if ($('#shipTo_city').val() == "") {
				alert('You must enter the recipient\'s city.\n\nClick OK to try again.');
				('#shipTo_city').focus();
				return false;
			}

			if ($('#shipTo_state').val() == "") {
				alert('You must enter the recipient\'s state.\n\nClick OK to try again.');
				('#shipTo_state').focus();
				return false;
			}

			if ($('#shipTo_postalCode').val() == "") {
				alert('You must enter the recipient\'s zip code.\n\nClick OK to try again.');
				('#shipTo_postalCode').focus();
				return false;
			}
		}

	});
	
	
	$('#billingForm').submit(function() {
		
		if ($('#firstName').val() == "") {
			alert('You must enter your first name.\n\nClick OK to try again.');
			$('#firstName').focus();
			return false;
		}

		if ($('#lastName').val() == "") {
			alert('You must enter your last name.\n\nClick OK to try again.');
			$('#lastName').focus();
			return false;
		}

		if ($('#street1').val() == "") {
			alert('You must enter your street address.\n\nClick OK to try again.');
			$('#street1').focus();
			return false;
		}

		if ($('#city').val() == "") {
			alert('You must enter the name of your city.\n\nClick OK to try again.');
			$('#city').focus();
			return false;
		}

		if ($('#state').val() == "") {
			alert('You must enter the abbreviation of your state.\n\nClick OK to try again.');
			$('#state').focus();
			return false;
		}

		if ($('#zip').val() == "") {
			alert('You must enter your zip code.\n\nClick OK to try again.');
			$('#zip').focus();
			return false;
		}

		if ($('#phone').val() == "") {
			alert('You must enter your phone number.\n\nClick OK to try again.');
			$('#phone').focus();
			return false;
		} else {
			// Validate the phone number format
			regex = /\s+/;
			var phoneNumber = $('#phone').val();
			if (phoneNumber.match(regex)) {
				alert('The phone number cannot contain any spaces.\n\nClick OK to try again.');
				$('#phone').focus();
				return false;
			}

			regex = /\(?\d{3}\)?[-\s.]?\d{3}[-\s.]\d{4}/;
			if (!phoneNumber.match(regex)) {
				alert('The phone number you entered was invalid.\n\nClick OK to try again.');
				$('#phone').focus();
				return false;
			}
		}

		if ($('#emailAddress').val() == "") {
			alert('You must enter your email address.\n\nClick OK to try again.');
			$('#emailAddress').focus();
			return false;
		} else {
			// Validate the email address
			var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var emailAddress = $('#emailAddress').val();
			if (!emailAddress.match(regex)) {
				alert('The email address you entered was invalid.\n\nClick OK to try again.');
				$('#emailAddress').focus();
				return false;
			}
		}
		
	});
	
});