//函數：在 IE 中建立 XMLHttpRequest 物件，避免不同瀏覽器的差異性
if (typeof XMLHttpRequest == "undefined" && window.ActiveXObject) {
	function XMLHttpRequest() {
		var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for (var i=0; i < arrSignatures.length; i++) {
			try {
				var oRequest = new ActiveXObject(arrSignatures[i]);
				return oRequest;
			} catch (oError) {
				//ignore
			}
		}
		throw new Error("MSXML is not installed on your system.");
	}
}

//函數：將參數加入到 URL 尾端，以便讓 GET 使用
function addURLParam(sURL, sParamName, sParamValue, sParamName1, sParamValue1, sParamName2, sParamValue2) {
	sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
	sURL += encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
	sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
	sURL += encodeURIComponent(sParamName1) + "=" + encodeURIComponent(sParamValue1);
	sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
	sURL += encodeURIComponent(sParamName2) + "=" + encodeURIComponent(sParamValue2);
	return sURL;
}
//-----------------------------------------------------------------------
//
//分別取得兩個選單 的reference

//後端傳回 JSON 資料的路徑
var cusURL = "product_show.php";

//用來儲存 JSON 的全域變數
var jsonProd;

//一開始時先將第二個選單停用

//地區別
function prodCheck(prodId, level1Id, level2Id) {
	//如果選擇的是第一個選項，第二個選單只顯示"請選擇"，並且無法使用。
	sURLProd = addURLParam(cusURL,"p_id",prodId,"level1_id",level1Id,"level2_id",level2Id);
	var oRequestProd = new XMLHttpRequest();
	oRequestProd.open("post", sURLProd, true);
	
	oRequestProd.onreadystatechange = function() {
		if(oRequestProd.readyState == 4) {
			if(oRequestProd.status == 200 ){
				jsonProd = oRequestProd.responseText;
				document.getElementById('prodshow').innerHTML = jsonProd;
			}else{
				//document.getElementById('prodshow').style.display = "block";
			}
		}
	}
	//送出 Ajax 要求
	oRequestProd.send(null);
}