$(function() {
	
	
	$('#quoteme').click(function(e) {
		
		$('#priceSection').addClass('d-none');
		$('#altSection').addClass('d-none');
		$('#feedback').empty();
		
		e.preventDefault();
		var params = $.param({ product: $('#product').val(), 
	                           edition: $('#edition').val(), 
	                           term: $('#term').val(), 
	           				   quantity: $('#users').val(),
	           				   currency:  $('#currency').val(),
	           				   customer: $('#customer').val(),
	           				   reseller: $('#reseller').val()
	           				});
	           				   
		$.post('/app/api/quote', params, function(data) {
       	   if(data.success) {
				$('.currencyDisplay').text(data.price.currencyCode);
				if(data.price.price > $('#discount').val()) {		
					$('#displayPrice').val(data.price.price);
	       	   		$('#priceSection').removeClass('d-none');
				} else {
					JadaptiveUtils.error($('#feedback'), "An upgrade is not available.");
				}
				
				if(data.alt) {	
					if(data.alt.price > $('#discount').val()) { 	   		
						$('#displayAlt').val(data.alt.price);
						$('#altSection').removeClass('d-none');
					}
				}
       	   }
    	});
	});
	
	
	$('#price').click(function(e) {
		e.preventDefault();
		$('input[name="price"]').val($('#displayPrice').val());
		$('form').submit();	
	});
	
	$('#renewal').click(function(e) {
		e.preventDefault();
		
		$('input[name="price"]').val($('#displayAlt').val());
       	$('input[name="renewal"]').val('true');
       	
		$('form').submit();	
	});
	
});