function callbackFailure(o)
{
	alert('Error ' + o.status + ': ' + o.statusText);
}

function callbackSuccess(o)
{
	if (200 == o.status)
	{
		try {
		    var response = YAHOO.lang.JSON.parse(o.responseText);
		}
		catch (e) {
		    alert("Invalid data");
		    return;
		}
		var select = document.getElementById(response.qt);
		var options = select.options;
		options.length = 1;
		for (var o in response.data)
		{
			var opt = new Option(o, response.data[o]);
			//select.add(opt, null);	// doesn't work in IE
			var i = select.options.length;
			select.options[i] = opt;
		}
	}
}

var callback =
{
	success: callbackSuccess,
	failure: callbackFailure
}

function chooseMake()
{
	var makeSelect = document.getElementById('cmake');
	var make_id = makeSelect.options[makeSelect.selectedIndex].value;
	var url = urlBase + 'qt=cmodel&cmake=' + escape(make_id);
	var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
	var yearSelect = document.getElementById('cyear');
	yearSelect.options.length = 1;
}

function chooseModel()
{
	var makeSelect = document.getElementById('cmake');
	var make_id = makeSelect.options[makeSelect.selectedIndex].value;
	var modelSelect = document.getElementById('cmodel');
	var model = modelSelect.options[modelSelect.selectedIndex].value;
	var url = urlBase + 'qt=cyear&cmake=' + escape(make_id) + '&cmodel=' + escape(model);
	var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
}

function chooseDevice()
{
	var brandSelect = document.getElementById('dbrand');
	var brand_id = brandSelect.options[brandSelect.selectedIndex].value;
	var url = urlBase + 'qt=dmodel&dbrand=' + escape(brand_id);
	var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
}

function disableVehicleMounts()
{
	var checked = document.getElementById('chkVehicleMount').checked;
	document.getElementById('cmake').disabled = checked;
	document.getElementById('cmodel').disabled = checked;
	document.getElementById('cyear').disabled = checked;
}

function disableDeviceHolders()
{
	var checked = document.getElementById('chkDeviceHolder').checked;
	document.getElementById('dbrand').disabled = checked;
	document.getElementById('dmodel').disabled = checked;
}