/**
 * Programmer
 * Zhi Liu (B. Eng. Msc)
 * Systems Analyst, GIS/RS Specialist
 * Consultant to the Bureau of Transportation Statistics, RITA-USDOT
 * 1200 New Jersey Avenue SE, Washington, DC 20003
 * Tel: 202-366-0262
 * Email: zhi.liu@dot.gov
 * MacroSys Research and Technology
 * 888 17th Street NW, Suite 312, Washington DC 20006
 **/
function CTPPDataAnalysisItemSelection(form) {
	var DCode = "";
	var OCode = "";
	var MeasureCode = "";
	var SummaryLevel = "";
	var FlowDirectionCode = "";
 
	// Determine O-D level for view file construction
	for (var i = 0; i < form.odLevelList.length; i++){
	if (form.odLevelList.options[i].selected) {
	SummaryLevel = form.odLevelList.options[i].value;
	}
	}
	SummaryLevel = SummaryLevel;
 
    // Measure selection
	if (form.measureList.options[0].selected) {
	MeasureCode = "ALL";
	}
	else {
	for (var n = 1; n < form.measureList.length; n++) {
	if (form.measureList.options[n].selected) {
	MeasureCode += form.measureList.options[n].value + ", ";
	}
	}
	MeasureCode = MeasureCode.substr(0,(MeasureCode.length-2));
	}
	
    //Determine O Code
	if (form.oList.options[1].selected) {
	OCode = "ALL";
	}
	else {
	for (var i = 2; i < form.oList.length; i++) {
	if (form.oList.options[i].selected) {
	OCode += form.oList.options[i].value + ", ";
	}
	}
	OCode = OCode.substr(0, (OCode.length-2));
	}
	
	
	//Determine D Code
	if (form.dList.options[1].selected) {
	DCode = "ALL";
	}
	else {
	for (var j = 2; j < form.dList.length; j++) {
	if (form.dList.options[j].selected) {
	DCode += form.dList.options[j].value + ", ";
	}
	}
	DCode = DCode.substr(0, (DCode.length-2));
	}
	
	// Determine Flow Direction
 	if (DCode.length == 0) {
 	FlowDirectionCode = "O";
 	}
 	else if (OCode.length == 0) {
 	FlowDirectionCode = "D";
 	}
 	else {
	FlowDirectionCode = "OD";
 	}
 	
	
	if (DCode.length == 0 && OCode.length == 0 || MeasureCode.length == 0 || SummaryLevel.length == 0){
	alert("Missing enough selection items for query, please try again.");
	return false;			
	}
 
	//alert("Selected parameters: " + OCode + "----" + DCode + "----" + FlowDirectionCode);
	
	//frames['IFrameResult'].location.href="ctpp2000p3chartVarSel.jsp?OC=" + OCode + "&DC=" + DCode + "&MC=" + MeasureCode + "&SL=" + SummaryLevel + "&FDC=" + FlowDirectionCode;
    var postForm = document.postForm;
	postForm.SL.value = SummaryLevel;
	postForm.FDC.value = FlowDirectionCode;
	postForm.MC.value = MeasureCode;
	postForm.OC.value = OCode;
	postForm.DC.value = DCode;
	
	postForm.submit();		
}
	var comboSearchChars;
	var KEY_BACKSPACE = 8;

	function initComboSearch() {
	comboSearchChars = "";
	}

	function searchComboBox(theComboBox) {
	//undo the keypress to avoid the default browser behaviour
	window.event.returnValue = false;

	var keyCode = window.event.keyCode;
	if (keyCode == KEY_BACKSPACE) {
	comboSearchChars = comboSearchChars.substring(0, comboSearchChars.length-1);
	} else {
	var keyChar = String.fromCharCode(keyCode);
	comboSearchChars += keyChar.toLowerCase();
	}

	for (var i = 0; i < theComboBox.length; i++) {
	var comboValue = theComboBox.options[i].text.substring(0, comboSearchChars.length);
	comboValue = comboValue.toLowerCase();
	if (comboValue == comboSearchChars) {
	theComboBox.options[i].selected = true;
	return;
	}
	}
	}
// TableV and TableT information
var TableV = new Array();
var TableT = new Array();
TableV[0] = new Array('T301C1');
TableV[1] = new Array('T308C1_1', 'T308C1_2', 'T308C1_3', 'T308C1_4', 'T308C2_1', 'T308C2_2', 'T308C2_3', 'T308C2_4', 'T308C3_1', 'T308C3_2', 'T308C3_3', 'T308C3_4', 'T308C4_1', 'T308C4_2', 'T308C4_3', 'T308C4_4', 'T308C5_1', 'T308C5_2', 'T308C5_3', 'T308C5_4', 'T308C6_1', 'T308C6_2', 'T308C6_3', 'T308C6_4', 'T308C7_1', 'T308C7_2', 'T308C7_3', 'T308C7_4', 'T308C8_1', 'T308C8_2', 'T308C8_3', 'T308C8_4');
TableV[2] = new Array('T309C1_1', 'T309C1_2',  'T309C1_3',  'T309C1_4',  'T309C2_1',  'T309C2_2',  'T309C2_3', 'T309C2_4',  'T309C3_1',  'T309C3_2',  'T309C3_3',  'T309C3_4',  'T309C4_1',  'T309C4_2',  'T309C4_3',  'T309C4_4',  'T309C5_1',  'T309C5_2', 'T309C5_3',  'T309C5_4',  'T309C6_1',  'T309C6_2',  'T309C6_3',  'T309C6_4',  'T309C7_1',  'T309C7_2',  'T309C7_3',  'T309C7_4',  'T309C8_1', 'T309C8_2',  'T309C8_3',  'T309C8_4');
TableV[3] = new Array('T314C1_1', 'T314C1_2',  'T314C1_3',  'T314C1_4',  'T314C2_1',  'T314C2_2',  'T314C2_3', 'T314C2_4',  'T314C3_1',  'T314C3_2',  'T314C3_3',  'T314C3_4',  'T314C4_1',  'T314C4_2',  'T314C4_3',  'T314C4_4',  'T314C5_1',  'T314C5_2', 'T314C5_3',  'T314C5_4',  'T314C6_1',  'T314C6_2',  'T314C6_3',  'T314C6_4',  'T314C7_1',  'T314C7_2',  'T314C7_3',  'T314C7_4',  'T314C8_1', 'T314C8_2',  'T314C8_3',  'T314C8_4');
TableV[99] = new Array('~Make Selection Below~');

TableT[0] = new Array('Table 1 Col 1 Var 1---Total workers');
TableT[1] = new Array('Table 8 Col 1 Var 1---Total; Means of transportation (Total; Time leaving home )(Minutes) ', 'Table 8 Col 1 Var 2---Total; Means of transportation (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 1 Var 3---Total; Means of transportation (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 1 Var 4---Total; Means of transportation (Worked at home )(Minutes) ', 'Table 8 Col 2 Var 1---Drove alone (Total; Time leaving home) (Minutes) ', 'Table 8 Col 2 Var 2---Drove alone (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 2 Var 3---Drove alone (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 2 Var 4---Drove alone (Worked at home )(Minutes) ', 'Table 8 Col 3 Var 1---2-person carpool (Total; Time leaving home) (Minutes) ', 'Table 8 Col 3 Var 2---2-person carpool (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 3 Var 3---2-person carpool (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 3 Var 4---2-person carpool (Worked at home )(Minutes) ', 'Table 8 Col 4 Var 1---3-or-more-person carpool (Total; Time leaving home) (Minutes) ', 'Table 8 Col 4 Var 2---3-or-more-person carpool (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 4 Var 3---3-or-more-person carpool (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 4 Var 4---3-or-more-person carpool (Worked at home )(Minutes) ', 'Table 8 Col 5 Var 1---Bus or trolley bus (Total; Time leaving home) (Minutes) ', 'Table 8 Col 5 Var 2---Bus or trolley bus (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 5 Var 3---Bus or trolley bus (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 5 Var 4---Bus or trolley bus (Worked at home )(Minutes) ', 'Table 8 Col 6 Var 1---Streetcar; subway; railroad or ferryboat(Total; Time leaving home) (Minutes) ', 'Table 8 Col 6 Var 2---Streetcar; subway; railroad or ferryboat(5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 6 Var 3---Streetcar; subway; railroad or ferryboat(9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 6 Var 4---Streetcar; subway; railroad or ferryboat(Worked at home )(Minutes) ', 'Table 8 Col 7 Var 1---Bicycle; walked; taxicab; motorcycle .. (Total; Time leaving home) (Minutes) ', 'Table 8 Col 7 Var 2---Bicycle; walked; taxicab; motorcycle .. (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 7 Var 3---Bicycle; walked; taxicab; motorcycle .. (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 7 Var 4---Bicycle; walked; taxicab; motorcycle .. (Worked at home )(Minutes) ', 'Table 8 Col 8 Var 1---Worked at home (Total; Time leaving home) (Minutes) ', 'Table 8 Col 8 Var 2---Worked at home (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 8 Col 8 Var 3---Worked at home (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 8 Col 8 Var 4---Worked at home (Worked at home )(Minutes) ');
TableT[2] = new Array('Table 9 Col 1 Var 1---Total; Means of transportation (Total; Time leaving home )(Minutes) ', 'Table 9 Col 1 Var 2---Total; Means of transportation (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 1 Var 3---Total; Means of transportation (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 1 Var 4---Total; Means of transportation (Worked at home )(Minutes) ', 'Table 9 Col 2 Var 1---Drove alone (Total; Time leaving home) (Minutes) ', 'Table 9 Col 2 Var 2---Drove alone (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 2 Var 3---Drove alone (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 2 Var 4---Drove alone (Worked at home )(Minutes) ', 'Table 9 Col 3 Var 1---2-person carpool (Total; Time leaving home) (Minutes) ', 'Table 9 Col 3 Var 2---2-person carpool (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 3 Var 3---2-person carpool (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 3 Var 4---2-person carpool (Worked at home )(Minutes) ', 'Table 9 Col 4 Var 1---3-or-more-person carpool (Total; Time leaving home) (Minutes) ', 'Table 9 Col 4 Var 2---3-or-more-person carpool (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 4 Var 3---3-or-more-person carpool (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 4 Var 4---3-or-more-person carpool (Worked at home )(Minutes) ', 'Table 9 Col 5 Var 1---Bus or trolley bus (Total; Time leaving home) (Minutes) ', 'Table 9 Col 5 Var 2---Bus or trolley bus (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 5 Var 3---Bus or trolley bus (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 5 Var 4---Bus or trolley bus (Worked at home )(Minutes) ', 'Table 9 Col 6 Var 1---Streetcar; subway; railroad or ferryboat(Total; Time leaving home) (Minutes) ', 'Table 9 Col 6 Var 2---Streetcar; subway; railroad or ferryboat(5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 6 Var 3---Streetcar; subway; railroad or ferryboat(9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 6 Var 4---Streetcar; subway; railroad or ferryboat(Worked at home )(Minutes) ', 'Table 9 Col 7 Var 1---Bicycle; walked; taxicab; motorcycle .. (Total; Time leaving home) (Minutes) ', 'Table 9 Col 7 Var 2---Bicycle; walked; taxicab; motorcycle .. (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 7 Var 3---Bicycle; walked; taxicab; motorcycle .. (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 7 Var 4---Bicycle; walked; taxicab; motorcycle .. (Worked at home )(Minutes) ', 'Table 9 Col 8 Var 1---Worked at home (Total; Time leaving home) (Minutes) ', 'Table 9 Col 8 Var 2---Worked at home (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 9 Col 8 Var 3---Worked at home (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 9 Col 8 Var 4---Worked at home (Worked at home )(Minutes) ');
TableT[3] = new Array('Table 14 Col 1 Var 1---Total; Means of transportation (Total; Time leaving home )(Minutes) ', 'Table 14 Col 1 Var 2---Total; Means of transportation (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 1 Var 3---Total; Means of transportation (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 1 Var 4---Total; Means of transportation (Worked at home )(Minutes) ', 'Table 14 Col 2 Var 1---Drove alone (Total; Time leaving home) (Minutes) ', 'Table 14 Col 2 Var 2---Drove alone (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 2 Var 3---Drove alone (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 2 Var 4---Drove alone (Worked at home )(Minutes) ', 'Table 14 Col 3 Var 1---2-person carpool (Total; Time leaving home) (Minutes) ', 'Table 14 Col 3 Var 2---2-person carpool (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 3 Var 3---2-person carpool (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 3 Var 4---2-person carpool (Worked at home )(Minutes) ', 'Table 14 Col 4 Var 1---3-or-more-person carpool (Total; Time leaving home) (Minutes) ', 'Table 14 Col 4 Var 2---3-or-more-person carpool (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 4 Var 3---3-or-more-person carpool (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 4 Var 4---3-or-more-person carpool (Worked at home )(Minutes) ', 'Table 14 Col 5 Var 1---Bus or trolley bus (Total; Time leaving home) (Minutes) ', 'Table 14 Col 5 Var 2---Bus or trolley bus (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 5 Var 3---Bus or trolley bus (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 5 Var 4---Bus or trolley bus (Worked at home )(Minutes) ', 'Table 14 Col 6 Var 1---Streetcar; subway; railroad or ferryboat(Total; Time leaving home) (Minutes) ', 'Table 14 Col 6 Var 2---Streetcar; subway; railroad or ferryboat(5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 6 Var 3---Streetcar; subway; railroad or ferryboat(9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 6 Var 4---Streetcar; subway; railroad or ferryboat(Worked at home )(Minutes) ', 'Table 14 Col 7 Var 1---Bicycle; walked; taxicab; motorcycle .. (Total; Time leaving home) (Minutes) ', 'Table 14 Col 7 Var 2---Bicycle; walked; taxicab; motorcycle .. (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 7 Var 3---Bicycle; walked; taxicab; motorcycle .. (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 7 Var 4---Bicycle; walked; taxicab; motorcycle .. (Worked at home )(Minutes) ', 'Table 14 Col 8 Var 1---Worked at home (Total; Time leaving home) (Minutes) ', 'Table 14 Col 8 Var 2---Worked at home (5:00 a.m. to 8:59 a.m. )(Minutes) ', 'Table 14 Col 8 Var 3---Worked at home (9:00 a.m. to 4:59 a.m. )(Minutes) ', 'Table 14 Col 8 Var 4---Worked at home (Worked at home )(Minutes) ');
TableT[99] = new Array('~Make Selection Below~');

function getTableValue(){
	TableV[99].length = 1;
	TableT[99].length = 1;
	for (var t = 0; t <= 3; t++) {
		if (document.CTPPDataAnalysisItem.elements['tableGroupList'].options[t].selected) {
			TableV[99] = TableV[99].concat(TableV[t]);
			TableT[99] = TableT[99].concat(TableT[t]);
		}
	}
			
    //a little better performance
	var optionList = document.CTPPDataAnalysisItem.elements['measureList'].options
	var tableLen = TableV[99].length;
	optionList.length = tableLen;
	for(var eye = 0; eye < tableLen; eye += 1){
		//fix bug in firefox;
		optionList[eye] = new Option(TableT[99][eye], TableV[99][eye]);
	}	
}  // End of getTableValue