function loadProduct(oID, arrName) {
	var subPD = eval('sub' + arrName);
	var objPd = document.getElementById(oID);
	//Load sub product
	for (i=0; i<subPD.length;i+=3) {
		var oOption = document.createElement("OPTION");
		objPd.options.add(oOption);
		oOption.innerText = subPD[i+1];
		oOption.value = subPD[i];
	}
}

function loadSubCatProduct(sMainCat) {
	if (sMainCat == 'H') {
		loadProduct('cbPd_ehm', 'EHM');
		loadProduct('cbPd_ehp', 'EHP');
		loadProduct('cbPd_ehb', 'EHB');
		loadProduct('cbPd_etc', 'ETC');
	}
	if (sMainCat == 'E') {
		loadProduct('cbPd_ecc', 'ECC');
		loadProduct('cbPd_ect', 'ECT');
		loadProduct('cbPd_ecr', 'ECR');
		loadProduct('cbPd_ecv', 'ECV');
		loadProduct('cbPd_ecs','ECS');
	}
	if (sMainCat == 'G') {
		loadProduct('cbPd_ecl', 'ECL');
		loadProduct('cbPd_eki', 'EKI');
		loadProduct('cbPd_ecp', 'ECP');
		loadProduct('cbPd_etp', 'ETP');
		loadProduct('cbPd_eif', 'EIF');
	}
	if (sMainCat == 'UV') {
		loadProduct('cbPd_euv', 'EUV');
	}
}

// ------------------------ THIS FUNCTION ONLY in Product Detail Page ------------------------------------
function chgProduct() {
	var i = 0;
	var objSub = document.getElementById('cbProduct');
	var sValue = cbSubCat.options[cbSubCat.selectedIndex].value;
	
	if (objSub.length > 0 ) {
		var objCount = objSub.length;
		for (i=objCount-1; i>=0; i--) {
			objSub.remove(i);
		}
	}
	loadProduct('cbProduct', sValue);
}

// ------------------------ THIS FUNCTION ONLY in Product Detail Page ------------------------------------
function setPdDisplay(arrCat, sModel) {
	var c = 0;
	loadProduct('cbProduct', arrCat);
	var objSub = document.getElementById('cbProduct');
	objSub.remove(0);
	
	// -- Set product model no.
	while (c < cbProduct.length) {
		if (sModel == cbProduct.options[c].value) {
			cbProduct.selectedIndex = c;
			break;
		}
		c++;
	}
	// -- Set product cat.	
	c = 0;
	while (c < cbSubCat.length) {
		if (arrCat == cbSubCat.options[c].value) {
			cbSubCat.selectedIndex = c;
			break;
		}
		c++;
	}
}

// ------------------------ THIS FUNCTION ONLY in Product Detail Page ------------------------------------
function goPD2PD() {
	var c = 0;
	var arrCat = eval('sub' + cbSubCat.options[cbSubCat.selectedIndex].value);
	var sValue = cbProduct.options[cbProduct.selectedIndex].value;
	while (c < arrCat.length) {
		if (arrCat[c] == sValue) {
			var sURL = arrCat[c+2];
			if (sURL != '#') {
				if (sURL.substring(0,4) == "http")
					window.open(sURL);
				else
					window.location = sURL;
			}
			break;
		}
		c+= 3;
	}
}

// ----------------------------- Sub Cat select to Product Details ----------------------------------------
function goSubCat(sSCat) {
	var c = 0;
	var objCB;
	var arrCat = eval('sub'+ sSCat);
	
	if (sSCat == 'EHM')	objCB = eval('cbPd_ehm');
	if (sSCat == 'EHP')	objCB = eval('cbPd_ehp');
	if (sSCat == 'EHB')	objCB = eval('cbPd_ehb');
	if (sSCat == 'ETC')	objCB = eval('cbPd_etc');
	if (sSCat == 'ECC')	objCB = eval('cbPd_ecc');
	if (sSCat == 'ECT')	objCB = eval('cbPd_ect');
	if (sSCat == 'ECR')	objCB = eval('cbPd_ecr');
	if (sSCat == 'ECL')	objCB = eval('cbPd_ecl');
	if (sSCat == 'ECS')	objCB = eval('cbPd_ecs');
	if (sSCat == 'EKI')	objCB = eval('cbPd_eki');
	if (sSCat == 'ECP')	objCB = eval('cbPd_ecp');
	if (sSCat == 'ECM')	objCB = eval('cbPd_ecm');
	if (sSCat == 'ECV')	objCB = eval('cbPd_ecv');
	if (sSCat == 'EUV')	objCB = eval('cbPd_euv');
	if (sSCat == 'ETP')	objCB = eval('cbPd_etp');
	if (sSCat == 'EIF')	objCB = eval('cbPd_eif');
	
	var sModel = objCB.options[objCB.selectedIndex].value;
	
	while (c< arrCat.length) {
		if (sModel == arrCat[c]) {
			if (arrCat[c+2] != '#') {
				if (arrCat[c+2].substring(0,4) == "http")
					window.open(arrCat[c+2]);
				else
					window.location = arrCat[c+2];
			}
		}
		c+= 3;
	}
}