	var TAF = TAF || {};
	
	TAF.init = function () {
		// set up the variables we are going to be using
		var $bid_form = $('#contact_form'),
			$bid = $bid_form.find('input[name="cf_bid"]'),
			$seats = $bid_form.find('select[name="cf_seats"]'),
			$bid_total = $bid_form.find('input[name="cf_total"]').attr('readOnly','readOnly'),
			$button = $bid_form.find('button[name="submit"]'),
			total,
			num_seats,
			bid_val;
		
		// only allow numbers to be put in the bid amount
		$bid.keypress(function(event){
			if (event.charCode && (event.charCode < 48 || event.charCode > 57)) 
			{
				event.preventDefault();
			}
		})
		
		// make a calculation when the dollar amount changes
		$bid.keyup( function() {
			grand_total();
		})
		
		// or when the select amount is changed
		$seats.change( function() {
			grand_total();
		})
		
		function grand_total() {
			total = 0;
			bid_val = parseInt($bid.val()) ? parseInt($bid.val()) : 0;
			num_seats = parseInt($seats.val()) ? parseInt($seats.val()) : 0;
			
			total = bid_val * num_seats;
			
			// if total is a number insert it into the cf_total field
			if (! isNaN(total)) {
				$bid_total.val(total);
			}
			
			// see if there is a total or not, enable and disable to reflect that
			if ( parseInt($bid_total.val()) )
			{
				$button.removeAttr('disabled').removeClass('disabled');
			}
			else
			{
				$button.attr("disabled", "disabled").addClass('disabled');
			}
		}
		
		// stop the form submitting if total is empty
		$bid_form.submit(function(event) {
			if (! parseInt($bid_total.val()) )
			{
				event.preventDefault();
			}
		});
		
	} // ends TAF.init

$(document).ready(function() {
		if ('#contact_form') {
			TAF.init()
		}
	});

