/*
  Donation form processing for NCCF.
  Allow either a radio button select of a fixed amount, or
  checkbox the "other" checkbox and enter a custom amount.

    Hook using jquery:

    <script type="text/javascript" src="/static/js/donation.js"></script>
    <script type="text/javascript">

    $(document).ready(function(){
        donation();
     });
    </script>

*/
function donation() {
    $("#other_check").click(function(){
        if ($(this).is(":checked"))
        {
            $("#other_amt").attr("disabled", false);
            $(":radio").attr("checked", false);
        }
        else {
            $("#other_amt").attr("disabled", true);
        };
    }); // click function

    $(":radio").click(function(){

        // clear out the "other amount" inputs
        $("#other_check").attr("checked", false);
        $("#other_amt").val('');
        $("#other_amt").attr("disabled", true);

        // save value for authorize
        $("#id_x_amount").val( $(this).val() );
    }); // click function

    $("form").submit(function(){

	if ($('#other_check').is(":checked"))
        {
            v = this.other_amt.value;
	    if ( (v == null) || (v == ''))
	      {
		alert("Please enter an amount");
		return false;
	      }
	    else {
	      $("#id_x_amount").val(v);
	    }
        }
	else {
	  v = $("#id_x_amount").val();
	     if ( (v == null) || (v == ''))
	       {
		 alert("Please enter an amount");
		 return false;
	       };
	};

      }); // submit function

    // initial display
    $("#other_amt").attr("disabled", true);


}
