﻿
$(document).ready(function() {

	//Can't type letters into the credit card number box or the security code box or the postcode box
	$("#ctl00_maincontent_donateform_tc_txtCCNumber, #ctl00_maincontent_donateform_tc_txtCCSecurityCode, #ctl00_maincontent_donateform_tc_txtPostcode").keypress(function(event) {
  		// Backspace, tab, enter, end, home, left, right
  		// We don't support the del key in Opera because del == . == 46.
  		var controlKeys = [8, 9, 13, 35, 36, 37, 39];
  		// IE doesn't support indexOf
  		var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
  		// Some browsers just don't raise events for control keys. Easy.
  		// e.g. Safari backspace.
  		if (!event.which || // Control keys in most browsers. e.g. Firefox tab is 0
    	    (48 <= event.which && event.which <= 57) || // Always 1 through 9
    	    isControlKey) { // Opera assigns values for control keys.
    	return;
  		}   else {
   	      event.preventDefault();
  	    }
	});

	if ($.cookie("myemergencyresponse-donate-default") != 'visited') {

		// Adds the yellow colour
		$(".one-off").parent().eq(1).addClass("donation-option-selected");
		// Makes the radio button selected
		$("#option-2").attr('checked', 'checked');
		// Default value for the amount when once only is selected
		$(".one-off").parent().parent().parent().find('.form-row input#ctl00_maincontent_donateform_txtAmount').val("125");
			
		
    	$.cookie("myemergencyresponse-donate-default", 'visited');
    } else {
    	// Resets the amount when one off is selected to nil
		$(".one-off").parent().parent().parent().find('.form-row input#ctl00_maincontent_donateform_txtAmount').val("");
    };
		
		// Resets the amount when monthly is selected to nil
	$(".monthly").parent().parent().parent().find('.form-row input#ctl00_maincontent_donateform_txtAmount').val("");
		
	$(".monthly").parent().click(
		function(event) {
		    $(".donation-option").removeClass("donation-option-selected");
		    $(this).addClass("donation-option-selected").find("input:radio").attr("checked", "checked");
		
		    if ($('#option-1').is(':checked')) {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("20");
		    }
		    if ($('#option-2').is(':checked')) {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("30");
		    }
		    if ($('#option-3').is(':checked')) {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("50");
		    }
		    if ($('#option-4').is(':checked')) {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("80");
		    }
		
		}
	);
    	
    $(".one-off").parent().click(
		function(event) {
		    $(".donation-option").removeClass("donation-option-selected");
		    $(this).addClass("donation-option-selected").find("input:radio").attr("checked", "checked");
	
		    if ($('#option-1').is(':checked'))  {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("75");
		    }
		    if ($('#option-2').is(':checked')) {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("125");
		    }
		    if ($('#option-3').is(':checked')) {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("240");
		    }
		    if ($('#option-4').is(':checked')) {
		        $("input#ctl00_maincontent_donateform_txtAmount").val("720");
		    }
	
		}
	);

});