
	$(document).ready( function() {

		$("#myhost").change(function () {
			callAHAH('xmpx/golfcontact','rm=g&id='+$("#myhost option:selected").val(),'myname','retrieving','select');
		});
				
		$('#addl_dinner').blur(function () {
			addtotals();
			$("#payment").show();
		});	
		$('#gift').blur(function () {
			addtotals();
			$("#payment").show();
		});	
		$(window).load(function () {
		 	if ($('#amount').val() >= 179) {
		 		$("#payment").show();
		 	}
		});

		function addtotals() {
			dinner = parseInt($("#addl_dinner").val() * 20);
			gift = parseInt($('#gift').val());
			golf = parseInt($("#amount").val());
			if (!isNaN(dinner)) { var total = dinner }
			if (!isNaN(gift)) { total += gift }
			if (!isNaN(golf)) { total += golf }	
			$("#total").val(total);
		}
		
		//after an error show previously opened divs
		if ($('#host_click:checked').val() == "host") {
			$("#guest_entry").show();
		} else if ($('#guest_click:checked').val() == "guest") {
			$("#host_select").show();
		} else if ($('#single_click:checked').val() == "single") {
			$("#handicap_entry").show();	
		}
		
		//open divs per click
		$("#host_click").click(function () { 
   		$("#guest_entry").show(); 
   		$("#host_select").hide();
   		$("#handicap_entry").hide();
   	});
		$("#guest_click").click(function () { 
   		$("#guest_entry").hide(); 
   		$("#host_select").show();
   		$("#handicap_entry").hide();
   	});
		$("#single_click").click(function () { 
   		$("#guest_entry").hide(); 
   		$("#host_select").hide();
   		$("#handicap_entry").show();
   	});
   	
   	//adjust amount per click
   	amount = parseInt($("#amount").val());
   	
		$("#guest1pay").click(function () { 
			addamounts(1);
   	});
		$("#guest2pay").click(function () { 
			addamounts(2);
   	});
		$("#guest3pay").click(function () { 
			addamounts(3);
   	});
   	
   	function addamounts(num) {
   		if ($('#guest'+num+'pay:checked').val() > 0 ) {
				amount = parseInt(amount + 179 );
			} else {
				amount = amount - 179;
			}
			$("#amount").val(amount);
			addtotals();
		}
   	
  	});
  	
	function counter(num,size,id) {
		var text = document.getElementById(id).value;
		var len = text.length;
		if (len > size) {
			text = text.substring(1, len-2);
			document.getElementById(id).value = text;
			return false;
		} else {
			document.getElementById("counter"+num).value = size - len;
		return;
		}
		//<textarea name="messge" id="message" style="width: 200px; float: left;" onkeyup="counter(3,999,'message');"></textarea>
		//<input type="text" id="counter1" size="3" readonly="readonly" value="999" />
	}
