function setupAjaxForm(id)
{
	$("#" + id).submit(function()
	{
		$(this).find(".button").attr("disabled", true);

		var textboxes = $(this).find(".text");
		var checkboxes = $(this).find("input[type=checkbox]");
		var selectboxes = $(this).find("select");
		var options = { submit: 1 };

		for(var i = 0; i < textboxes.size(); i++)
		{
			var element = textboxes.get(i);
			options[$(element).attr("name")] = $(element).val();
		}

		for(var i = 0; i < selectboxes.size(); i++)
		{
			var element = selectboxes.get(i);
			options[$(element).attr("name")] = $(element).val();
		}

		for(var i = 0; i < checkboxes.size(); i++)
		{
			var element = checkboxes.get(i);

			if(!$(element).attr("checked"))
			{
				continue;
			}

			var name = $(element).attr("name");
			var pos = name.indexOf("[");

			if(pos != -1)
			{
				name = name.substr(0, pos);

				if(options[name] == undefined)
				{
					options[name] = [ ];
				}

				options[name].push($(element).val());
			}
			else
			{
				options[name] = $(element).val();
			}
		}

		$.post($(this).attr("action"), options, function(data)
		{
			$("#" + id).fadeOut(300, function()
			{
				$("#" + id + "-success").fadeIn(300);
				$("#" + id).find(".button").attr("disabled", false);
			});
		});

		return false;
	});
}

$(document).ready(function()
{
	$(".question").click(function()
	{
		var answer = $(this).parent().find(".answer");
		if($(answer).hasClass("visible"))
		{
			$(answer).removeClass("visible").hide();
			$(this).find("span").text("open");
		}
		else
		{
			$(answer).addClass("visible").show();
			$(this).find("span").text("close");
		}

		return false;
	});

	$("#top .menu a.last").click(function(event)
	{
		event.preventDefault();
		var box = $("#top .menu .login");

		if(box.hasClass("visible"))
		{
			box.removeClass("visible").fadeOut();
		}
		else
		{
			box.addClass("visible").fadeIn();
		}
	});

	$("#content .comparison td a").click(function(event)
	{
		event.preventDefault();
		$(this).parent().find("div").toggle();
	});
	
	$(".item.i1").click(function()
	{
		location.href = "adresponse.php";
	});
	$(".item.i2").click(function()
	{
		location.href = "adresponse-plus.php";
	});
	$(".item.i3").click(function()
	{
		location.href = "advanced.php";
	});
	$(".item.i4").click(function()
	{
		location.href = "jobs.php";
	});
});
