var c = 0; // is this used anymore?

// Round the Conveyor Capacity field to two decimal places
function roundResult() {
	var n = document.getElementById("XLEW_2_22_8");
	var v = n.value;
	v = Math.round(v*100)/100;
	n.value = v;
}

// The value on the left appears in the combo box,
// and the value on the right is placed on the text field
// below it.
var flightParams = [
	// flightOD, flightID
	[4, 1.25],
	[6, 1.25],
	[9, 2.5],
	[10, 2.5],
	[12, 3.5],
	[14, 3.5],
	[16, 4],
	[18, 4],
	[20, 4],
	[24, 4]
];

// Updates the flight ID and pitch based on the selected flight OD
function updateFlightParameters() {
	var flightOD = document.getElementById("flightOD").value;
	var flightID = 0;
	for (var i = 0; i < flightParams.length; i++)
		if (flightParams[i][0] == flightOD) {
			flightID = flightParams[i][1];
			break;
		}
	if (flightID == 0)
		flightID = "N/A";
	var pitch = flightOD; // form is restricted to full pitch values
	
	document.getElementById("XLEW_1_14_7").value = flightOD;
	document.getElementById("XLEW_1_15_7").value = flightID;
	document.getElementById("XLEW_1_16_7").value = pitch;
	recalc_onclick("XLEW_1_14_7");
	recalc_onclick("XLEW_1_15_7");
	recalc_onclick("XLEW_1_16_7");
}

// Set the FlightOD and FlightID to default values
function resetFlightParams(){
	for (var i = 0; i < flightParams.length; i++)
		if (flightParams[i][0] == 12)
			document.getElementById("flightOD").selectedIndex = i;
	updateFlightParameters();
}

// must listen for any change to update properly
var f = document.forms[0];
for (var i = 0; i < f.length; i++)
	addListener('onblur', f.elements[i], roundResult);
addListener('onblur', document.getElementById("XLEW_1_14_7"), updateFlightParameters);
resetFlightParams();

// cross browser function to attach a listener to an event
function addListener(eType,el,func) {
	if (window.addEventListener) { // W3C/Mozilla
		el.addEventListener(eType,func,false)
	} else if (window.attachEvent) { // IE
		el.attachEvent(eType,func)
	}
}

