/* APT Distribution
 *
 * Douglas Thrift
 *
 * $Id: aptdist.js 1202 2010-04-22 07:21:07Z douglas $
 */

function p2p()
{
	if ($('#p2p').is(':checked'))
	{
		$('.p2p').text('/' + $('#host').val() + ':' + $('#port').val());

		return true;
	}

	return false;
}

$(function()
{
	$('#dist').change(function()
	{
		$('.dist').text($(this).val());
	});
	$('#p2p').change(function()
	{
		if (p2p())
			$('.secure').empty();
		else
		{
			if (window.location.protocol == 'https:')
				$('.secure').text('s');

			$('.p2p').empty();
		}
	});
	$('#host').change(p2p); // TODO
	$('#port').change(p2p); // TODO
	$('#vendor').change(function()
	{
		$.getJSON('/aptdist/' + $(this).val(), function(json)
		{
			var select = $('#dist');

			select.empty();
			$.each(json.dists, function(index, dist)
			{
				var option = $('<option/>');

				option.text(dist);
				select.append(option);
			});
			select.val(json.dist).change();
			$('.component').text(json.component);
		});
	});
});

