
function validateSubscriptionPromoCode()
{	
	if ( $F('PromoCode') ) {
		// Post the form, creating the association in the database.
		var Req = new Ajax.Request('/subscriptions/validate_discount.json.php',
			{
				method: 'post',
				parameters: { 	PromoCode: $F('PromoCode'),
								SubscriptionTypeID: $F('SubscriptionTypeID')
							},
				evalScripts: true,
				onSuccess: displayDiscount,
				onFailure: function(){ alert('Something went wrong... could not validate discount.') }
			});
	}
	
	function displayDiscount(transport, json)
	{
		var isValid = json ? json.IsValid : false;
		
		if ( isValid ) {
			var percentageDiscount = json ? json.PercentageDiscount : 0;
			var basePrice = json ? json.BasePrice : 0;
		
			if ( percentageDiscount ) {
				var discountedPrice = basePrice*(percentageDiscount/100);
				var result=Math.round(discountedPrice*100)/100;
				
				$('discount_message_value').innerHTML = "$" + Math.round(discountedPrice*100)/100;
				$('discount_message').show();
				
				$('PercentDiscount').value = percentageDiscount;
				
				if ( percentageDiscount == 100 ) {
					$('credit_card_not_required_message').show();
				}
				else {
					$('credit_card_not_required_message').hide();
				}
			}
		}
		else {
			alert('The promo code you supplied is invalid');
		}
	}
	
	
}

