// Function for dynamic pull down lists
deviceList = new Array(6);
deviceListVal = new Array(7);
deviceList[0] = "選択...";
deviceList[1] = "キャプチャカード";
deviceList[2] = "ビデオカメラ＆VTR";
deviceList[3] = "DVDライター";
deviceList[4] = "グラフィックカード";
deviceList[5] = "サウンドカード";
deviceList[6] = "Blu-rayプレーヤー";
deviceListVal[0] = "";
deviceListVal[1] = "capture";
deviceListVal[2] = "cameras";
deviceListVal[3] = "dvd";
deviceListVal[4] = "graphic";
deviceListVal[5] = "sound";
deviceListVal[6] = "bluray";


function setDevice() {
	var listObj = document.forms['versionForm'].version;
	var listObj2 = document.forms['versionForm'].device;

	listObj2.length = 0;

	var	listLength = 0;
	cat_display('show');
	var which = listObj.options[listObj.selectedIndex].value

	if (which == "1.0") {
		listLength = 3;
	} else {
		if (which =="1.5") {
			listLength = 4;
		} else {
			if (which =="2.0") {
				listLength = 6;
			} else {
				if (which =="CS3") {
					listLength = 6;
				} else {
					if (which =="CS4") {
					listLength = 7;
						} else {
					listLength = 1;
				   }
				}
			}
		}
	}
	for (var i = 0; i < listLength; i++) {
		listObj2.options[i] = new Option(deviceList[i]);
		listObj2.options[i].value = deviceListVal[i];
	}	
}

function setFormat() {
	var listObj = document.forms['versionForm'].device;
	var listObj2 = document.forms['versionForm'].format;

	listObj2.options[0].selected = true;
	which = listObj.options[listObj.selectedIndex].value

	if (which == "cameras") {
		cat_display('hide');
	} else {
		cat_display('show');
	}
}

// Function to hide pull down list for format
function cat_display(state) {
   var id = 'cat_' + state;
   var id2 = 'cat2_' + state;

   document.getElementById('cat_hide').style.display="none";
   document.getElementById('cat_show').style.display="none";
   document.getElementById('cat2_hide').style.display="none";
   document.getElementById('cat2_show').style.display="none";
   document.getElementById(id).style.display="inline";
   document.getElementById(id2).style.display="inline";

   return false;
}

// Function to set pulldowns to whatever user selected
function reset_pulldown2(w,x,y,z) {
	var listObj = document.forms['versionForm'];
	var listObj2 = document.forms['versionForm2'];
	
	for (var i=0; i<listObj.version.length; i++) {
		if (listObj.version.options[i].value == x) {
			listObj.version.options[i].selected = "true";
			setDevice();
		}
	}
	for (var i=0; i<listObj.device.length; i++) {
		if (listObj.device.options[i].value == y) {
			listObj.device.options[i].selected = "true";
		}
	}
	if (z != "") {
		for (var i=0; i<listObj.format.length; i++) {
			if (listObj.format.options[i].value == z) {
				cat_display('hide');
				listObj.format.options[i].selected = "true";
			}
		}
	}
	for (var i=0; i<listObj2.allmanufacturers.length; i++) {
		if (listObj2.allmanufacturers.options[i].value == w) {
			listObj2.allmanufacturers.options[i].selected = "true";
		}
	}
}

// Function to pass values for which column will table will be sorted by
function column_sort(x) {
	if (x == "manu") {
		document.forms['versionForm'].manuSearchVar.value="1";
		document.forms['versionForm'].modelSearchVar.value="0";
		document.forms['versionForm'].supportSearchVar.value="0";
		document.forms['versionForm'].dataFormat.value="";
	} else {
		if (x == "model") {
			document.forms['versionForm'].manuSearchVar.value="0";
			document.forms['versionForm'].modelSearchVar.value="1";
			document.forms['versionForm'].supportSearchVar.value="0";
			document.forms['versionForm'].dataFormat.value="";
		} else {
			if (x == "support") {
				document.forms['versionForm'].manuSearchVar.value="0";
				document.forms['versionForm'].modelSearchVar.value="0";
				document.forms['versionForm'].supportSearchVar.value="1";
				document.forms['versionForm'].dataFormat.value="";
			} else {
				if (x == "SD") {
					document.forms['versionForm'].manuSearchVar.value="1";
					document.forms['versionForm'].modelSearchVar.value="0";
					document.forms['versionForm'].supportSearchVar.value="0";
					document.forms['versionForm'].dataFormat.value="SD";
				}
			}
		}
	}

	document.forms['versionForm'].submit();
}

// function to move user to a printer friendly page
function print_page() {
	document.forms['versionForm'].action = "print_friendly.html";
	document.forms['versionForm'].method="GET";
	document.forms['versionForm'].submit();
}

// function to validate user selection
function submit_results() {
	var listObj = document.forms['versionForm'];
	var version_var = listObj.version.options[listObj.version.selectedIndex].value;
	var device_var = listObj.device.options[listObj.device.selectedIndex].value;
	var format_var = listObj.format.options[listObj.format.selectedIndex].value;

	if (version_var == "") {
		alert("バージョンを選択してください");
		return false;
	} else {
		if (device_var == "") {
			alert("ハードウェアの種類を選択してください");
			return false;
		} else {
			if ((device_var =="cameras") && (format_var == "")) {
				alert("ビデオフォーマットを選択してください");
				return false;
			} else {
				if ((version_var == "2.0") && (device_var =="capture")) {
					document.forms['versionForm'].action = "search_result_2_0_capture.html";
				} else {
					if ((version_var == "CS3") && (device_var =="capture")) {
						document.forms['versionForm'].action = "search_result_2_0_capture.html";
					} else {
						if ((version_var == "CS4") && (device_var =="capture")) {
						document.forms['versionForm'].action = "search_result_2_0_capture.html";
					} else 
						document.forms['versionForm'].submit();
					}
				}
			}
		}
	}
}

// Function to dynamically generate list of manufacturers in pull down menu
narrow_array = new Array(200);
final_array = new Array(200);
var nar_length = 0;

function narrow_func(x) {
	narrow_array[nar_length] = x;
	nar_length++;
}

function narrow_manufacturer() {
	var listObj = document.forms['versionForm2'].allmanufacturers;
	listObj.length = 0;
	var listLength = nar_length;
	var j = 2;
	var temp = narrow_array[0];
	final_array[0] = "すべてのメーカー";
	final_array[1] = narrow_array[0];
	
	for (var i = 1; i < listLength; i++) {
		if (temp != narrow_array[i]) {
			final_array[j] = narrow_array[i];
			temp = narrow_array[i];
			j++;
		}
	}
	
	for (var i = 0; i < j; i++) {
		listObj.options[i] = new Option(final_array[i]);
		listObj.options[i].value = final_array[i];
	}	
		listObj.options[0].value = "";
}

//Function to set Brand variable in Narrow Search Results
function filter() {
	var listObj = document.forms['versionForm'];
	var listObj2 = document.forms['versionForm2'];
	
	var which = listObj2.allmanufacturers.options[listObj2.allmanufacturers.selectedIndex].value;

	listObj.brand.value = which;
	document.forms['versionForm'].submit();
}

//Function to pass details to new page
function go_detail(w,x,y,z) {
	
	var detaillink = "detail.html?manuf_detail=" + w + "&model_detail=" + x + "&support_detail=" + y + "&note_detail=" + z;
	alert(detaillink);
	document.location.href = detaillink;
}
