
/* These are the Tunes Download page Array Functions, which use the data from tunes-array-data.js */


var arrayLength = (tunesArray.length/numberOfItems); //for loop only loops once for every numberOfItems, more efficient.

function changeMake(){
	//This code builds the model select menu
	var selectIndex = 1;
	document.bikeform.bikemodel.options.length = 0;
	document.bikeform.bikemodel.options[0] = new Option("Select Model...", " ", true, false); //new Option(text, value, defaultSelected, selected)
	for(i=0; i<arrayLength; i++){
		//if bike make == make selected && bike model != last select option model (to prevent model showing up multiple times in select)
		if(tunesArray[i*numberOfItems]==document.bikeform.bikemake.value && document.bikeform.bikemodel.options[selectIndex-1].value!=tunesArray[i*numberOfItems+1]){
			document.bikeform.bikemodel.options[selectIndex] = new Option(tunesArray[i*numberOfItems+1], tunesArray[i*numberOfItems+1], false, false);
			selectIndex++;
		}
	}
}

function changeYear(){
	//This code builds the year select menu
	var selectIndex = 1;
	document.bikeform.bikeyear.options.length = 0;		
	document.bikeform.bikeyear.options[0] = new Option("Select Year...", " ", true, false); //new Option(text, value, defaultSelected, selected)
	for(i=0; i<arrayLength; i++){
		//if bike model == model selected && bike year != last select option year (to prevent year showing up multiple times in select)
		if(tunesArray[i*numberOfItems+1]==document.bikeform.bikemodel.value && document.bikeform.bikeyear.options[selectIndex-1].value!=tunesArray[i*numberOfItems+2]){
			document.bikeform.bikeyear.options[selectIndex] = new Option(tunesArray[i*numberOfItems+2], tunesArray[i*numberOfItems+2], false, false);
			selectIndex++;
		}
	}
	//160310 - if document.bikeform.bikeyear.options.length == 2, then only one item displayed, so default to that item "All Years" for example...
	if(document.bikeform.bikeyear.options.length == 2){
		document.bikeform.bikeyear.options.length = 0;		
		document.bikeform.bikeyear.options[0] = new Option(tunesArray[2], tunesArray[2], true, false);
		showSpecified();
	}
}
		
function showSpecified(){
	//This code builds tune table data, depending on make and model of bike
	var tuneDivContent = "<DIV class=table1 id=table2col>";
			tuneDivContent += "<P class=pdownloads><b>Displaying tunes for: </b>&nbsp;&nbsp;&nbsp;" + document.bikeform.bikemake.value + "&nbsp;&nbsp;" + document.bikeform.bikemodel.value + "&nbsp;&nbsp;" + document.bikeform.bikeyear.value + "</P>";
			tuneDivContent += "<DIV class=table1_row>";
			tuneDivContent += "<DIV class=table1_col1><H5>DESCRIPTION</H5></DIV>";
			tuneDivContent += "<DIV class=table1_col3><H5>TUNE NUMBER</H5></DIV>";
			tuneDivContent += "</DIV><!-- table1_row end -->";
			tuneDivContent += "<DIV class=table1_row1_divider_orange></DIV>";

	for(i=0; i<arrayLength; i++){
		//if bikemake == selected make && bikemodel == selected model && bikeyear == selected year 
		if(tunesArray[i*numberOfItems]==document.bikeform.bikemake.value && tunesArray[i*numberOfItems+1]==document.bikeform.bikemodel.value && tunesArray[i*numberOfItems+2]==document.bikeform.bikeyear.value){
			//alert(tunesArray[i*numberOfItems] + ", " + tunesArray[i*numberOfItems+1] + ", " + tunesArray[i*numberOfItems+2] + ", " + tunesArray[i*numberOfItems+3] + ", " + tunesArray[i*numberOfItems+4] + ", " + tunesArray[i*numberOfItems+5]);
			tuneDivContent += "<DIV class=table1_row>";
			tuneDivContent += "<DIV class=table1_col1><p>" + tunesArray[i*numberOfItems+3] + "</p></DIV>";
			tuneDivContent += "<DIV class=table1_col3><p><a href=\"http:/\/www.tuneboy.com.au/TuneDownloads/PHPFiles/" + tunesArray[i*numberOfItems+4] + "Tune.php\">" + tunesArray[i*numberOfItems+4] + "</a></p></DIV>";
			tuneDivContent += "</DIV><!-- table1_row end -->";
			tuneDivContent += "<DIV class=table1_row1_divider></DIV>";
		}
	}
			tuneDivContent += "</DIV><!-- table1 end -->";
			document.getElementById('tuneDisplayContainer').innerHTML = tuneDivContent;
}
