
// switch paypal donation name based on checkbox value
$(document).ready(function(){
					$("#donationtype").click(function(){
						var checked = $(this).is(':checked');
						if(checked){
payPalRecurringDonationForm.item_name.value="Japanase Relief Effort";
payPalOneTimeDonationForm.item_name.value="Japanase Relief Effort";
						} else {
payPalRecurringDonationForm.item_name.value="Catapult Design Donation";
payPalOneTimeDonationForm.item_name.value="Catapult Design Donation";
						}
					});
				});


function setupDonations() {
// for safety's sake, make sure we're set up in the 'once' state (for reloads)
    $('#recurrenceOnce').attr('checked','checked');
//  make sure donation type is not checked on reloads  
    $('#donationtype').attr('unchecked','checked');

    $('#payPalDonationForm input[name=src]').val(0); // set recurring payments off
    
    // again, make sure we're set up at $25.00 to start
    $('#donate25').attr('checked','checked');
    $('#payPalDonationForm input[name=a3]').val('25.00');
    
    $('#paypalSubmitButton').click(function(){
        // dev note: yes this can all be done in php dynamically, but for speed we're just manipulating a form and submitting
        //  todo: make better later
    
        var recur = $('input[name=recurrence]:checked').val();
        
         // set up amount
        if ( $('#donateOther').is(':checked') ) {
            checkOtherAmount();
            if ( $('#otherAmount').val() == '' || $('#otherAmount').val() == '0.00'  ) {
                otherAmountNotValid();
                return false;
            } else {
                var amount = $('#otherAmount').val();
            }            
        } else {
            var amount = $('input[name=donateAmount]:checked').val();            
        }
        if ( recur == 'once' ) {
             $('#payPalOneTimeDonationForm input[name=amount]').val(amount);
        } else {
            $('#payPalRecurringDonationForm input[name=a3]').val(amount);
        }
       
        // set up recurrence in the form
        if ( recur == 'once' ) {
            $('#payPalOneTimeDonationForm').submit()
        } else {
            switch (recur) {
                case 'W':
                    $('#payPalRecurringDonationForm input[name=src]').val(1); // set recurring payments on
                    $('#payPalRecurringDonationForm input[name=t3]').val('W'); // set the recurrence interval to be weekly
                    break;
                case 'M':
                    $('#payPalRecurringDonationForm input[name=src]').val(1); // set recurring payments on
                    $('#payPalRecurringDonationForm input[name=t3]').val('M'); // set the recurrence interval to be monthly
                    break;
                default:
                    $('#payPalRecurringDonationForm input[name=src]').val(0); // set recurring payments off, to be safe
            } 
            // submit form
            $('#payPalRecurringDonationForm').submit();
        }
        
        
    });

    $("#otherAmount").numeric(null).focus(function(){
        $('#donateOther').attr('checked','checked');
    });
    
    function checkOtherAmount() {
        var otherVal = $('#otherAmount').val().toString();
        userVal=(otherVal.replace(/[^\d\.]/g, "")*1).toFixed(2);
        $('#otherAmount').val(userVal)
    }
    
    $('#otherAmount').blur(checkOtherAmount);
    
    function otherAmountNotValid() {
        checkOtherAmount();
        $("#otherAmount").focus().css('backgroundColor','#FDCC48');
        $('.inputError').show();
    }
}








