// Requires jQuery

var inputs = [];

$(function() {
	inputs.push(["autodealer","which auto"]);
	inputs.push(["coupon","which coupon"]);
	inputs.push(["cust referral","whoreferral"]);
	inputs.push(["ins agent","which agent"]);
	inputs.push(["ins company","which co"]);
	inputs.push(["search engine","which search"]);
	inputs.push(["radio","which radio"]);
	inputs.push(["towing co","which towing"]);
	inputs.push(["yellow pages","which yellowpg"]);
	inputs.push(["other","other info"]);

	$.each(inputs, function(i,o) {
		var check = $("input[name='"+ o[0] +"']");
		var input = $("input[name='"+ o[1] +"'],textarea[name='"+ o[1] +"']");
		
		check.click(function() {
			if (!$(this).is(":checked"))
				input.val("");
		});
		
		input.keypress(function() {
			if ($.trim($(this).val()) != "")
				check.attr("checked", "checked");
			return true;
		}).change(function() {
			if ($.trim($(this).val()) != "")
				check.attr("checked", "checked");
			return true;
		});
	});

});

function disableEnterKey(args) { return true; }

function checkAllInputs() {
	$.each(inputs, function(i,o) { 
		$("input[name='"+ o[1] +"'],textarea[name='"+ o[1] +"']").trigger("change"); 
	});
};;