jQuery(document).ready(function() {
	if(jQuery("form#cforms2form") != undefined){
		jQuery("input#sendbutton2").click(function() {
			return cforms_validate('2', true);			
		});		
		
		// On first load we want to hide both payment option fieldsets
		formElement = jQuery("form#cforms2form");		
		formInputs = jQuery('form#cforms2form :input');

		// Hide the second fieldset for donation type (recurring)
		jQuery('fieldset.cf-fs4').hide();
		jQuery('hr.#hr-5').hide();
		jQuery('li#li-2-10').hide();
		jQuery('li#li-2-11').hide();
		jQuery('li#li-2-12').hide();
				
		// If there is no CAPTCHA, remove the fieldset
		if(jQuery("input#cforms_captcha2").attr('id') === undefined){
			jQuery("fieldset.cf-fs8").hide();
		}		
		
		jQuery('input#donation-type-1').click(function() {
			jQuery('fieldset.cf-fs3').show();
			jQuery('fieldset.cf-fs4').hide();
			jQuery('hr.#hr-5').hide();
			jQuery('hr.#hr-4').show();
		});
		
		jQuery('input#is-memoriam-gift-1').click(function() {			
			
				jQuery('li#li-2-10').show();
				jQuery('li#li-2-11').show();
				jQuery('li#li-2-12').show();
				
				jQuery('ol.cf-ol li#li-2-11 label span').html('In Memory Of:');
		
		});
		
				
		jQuery('input#is-memoriam-gift-2').click(function() {			
			
				jQuery('li#li-2-10').show();
				jQuery('li#li-2-11').show();
				jQuery('li#li-2-12').show();
				
				jQuery('ol.cf-ol li#li-2-11 label span').html('Gift in Honour of:');
		});
		
		jQuery('input#donation-type-2').click(function() {
			jQuery('fieldset.cf-fs3').hide();
			jQuery('fieldset.cf-fs4').show();
			jQuery('hr.#hr-5').show();
			jQuery('hr.#hr-4').hide();
		});

		jQuery('input#billing-same-address').click(function() {

			if(jQuery('input#billing-same-address:checked').val() !== undefined){

				jQuery('input#billing-address-line1').attr('value',jQuery('input#address-line1').attr('value'));
				jQuery('input#billing-address-line2').attr('value',jQuery('input#address-line2').attr('value'));
				jQuery('input#billing-city').attr('value',jQuery('input#city').attr('value'));
				jQuery('select#billing-prov-state').attr('selectedIndex',jQuery('select#prov-state').attr("selectedIndex"));
				jQuery('input#billing-postal-zip-code').attr('value',jQuery('input#postal-zip-code').attr('value'));
				jQuery('select#billing-country').attr('selectedIndex',jQuery('select#country').attr("selectedIndex"));
			
				jQuery('input#billing-address-line1').attr('disabled','disabled');
				jQuery('input#billing-address-line2').attr('disabled','disabled');
				jQuery('input#billing-city').attr('disabled','disabled');

				jQuery('select#billing-prov-state').attr('disabled','disabled');
				jQuery('input#billing-postal-zip-code').attr('disabled','disabled');
				jQuery('select#billing-country').attr('disabled','disabled');
			}else{
				jQuery('input#billing-address-line1').removeAttr('disabled');
				jQuery('input#billing-address-line2').removeAttr('disabled');
				jQuery('input#billing-city').removeAttr('disabled');
				jQuery('select#billing-prov-state').removeAttr('disabled');
				jQuery('input#billing-postal-zip-code').removeAttr('disabled');
				jQuery('select#billing-country').removeAttr('disabled');
			}			
		});
		
		jQuery('input#specified-amount-onetime').click(function() {
			jQuery('input#gift-amount-onetime-6').attr('checked',true);
		});
		
		jQuery('input#specified-amount-monthly').click(function() {
			jQuery('input#gift-amount-monthly-5').attr('checked',true);
		});
		
		jQuery('ol.cf-ol li#li-2-33 label span').html('<b>CVV Number</b> <a target=\'_blank\' href=\'https://missionservices.ca/moneris-integration/cvv-desc.html\'>[need help?]</a>');
	}
});


