//


function openwindows(url, name, width, height)
{
	window.open(url, name, "width=" + width + ",height=" + height + ",menubar=no, scrollbars=no, status=no, resizable=no");
}

function zoomIn(url)
{
	if (url.length > 0) {
		openwindows(url, "PrductDetail", 680, 580);
	}
}

function doPrint(url)
{
	if (url.length > 0) {
		openwindows(url, "PrductPrint", 740, 728);
	}
}

function doZine(url) 
{
	if (url.length > 0) {
		location.href=url;
	}
}

var ajaxObj;

function doExport(url)
{
	if (!ajaxObj) {
		ajaxObj = new jsAjax();
	}
	ajaxObj.send(loadExport, url, null, "GET");

}

function doShopping(url)
{
	if (url.length > 0) {
		window.open(url, "pdt_shopping");
	}
}


function doGoodsChange()
{
	var s = document.getElementById("cat_select_list");
	var s1 = document.getElementById("pro_select_list");
	
	if (s && s1) {
		if (s1.selectedIndex > -1) {
			if (s1.options[s1.selectedIndex].value != "") {
//				location.href = "Pdt" + s.options[s.selectedIndex].value + s1.options[s1.selectedIndex].value + "_v.asp";
				location.href = "PdtInfo.asp?code=" + s1.options[s1.selectedIndex].value;
			}
		}
		
	}

}

function loadExport(httpObj)
{

	if (httpObj.status == 200)	{
		var str = httpObj.responseText;
		if (str.length > 100) {
			if (window.clipboardData.setData("Text", str)) {
				alert(pdtName + "source is copied. paste it using ctrl+V");
			}
		}
		else {
			alert(str);
		}

	}
}

var pdtCodeArray
var pdtNameArray
var ajaxObj

function doCatsChange()
{
    
    var s = document.getElementById("cat_select_list");
	var s1 = document.getElementById("pro_select_list");
    if (s && s1) {
        var idx = s.selectedIndex;

        // 

        if (idx < ptdCodeList.length) {
            if (ptdCodeList[idx] && ptdNameList[idx]) {
                fillGoods(ptdCodeList[idx], ptdNameList[idx]); 
                return ;
            }
        }

		if (idx > -1) {
			s1.selectedIndex = 0;
			
			var catCode = s.options[idx].value;
			if (!ajaxObj) 
				ajaxObj = new jsAjax();

			ajaxObj.send(parseGoods, "../PdtProductsInCat.asp?cat=" + catCode, null, "GET");
		}
        //
    }
}


function getBorwserType()
{
	var browser = '';
	if (browser == '') {
	     if (navigator.appName.indexOf('Microsoft') != -1)
		      browser = 'IE'
	     else if (navigator.appName.indexOf('Netscape') != -1)
		      browser = 'Netscape'
	     else browser = 'IE';
	}
	return browser;
}
// -->

function parseGoods(xmlHttp)
{
	if (xmlHttp.status == 200) {
		var pdtCodes = "";
		var pdtNames = "";

		var xmlDoc = xmlHttp.responseXML;
		var pdtObjs = xmlDoc.getElementsByTagName("product");

		if (pdtObjs) {

			for (var i=0; i < pdtObjs.length; i++) {
				
				var childObjs = pdtObjs[i].childNodes;
				for (var j=0; j < childObjs.length; j++) {
					if (childObjs[j].nodeName == "product-code")
						pdtCodes += (childObjs[j].childNodes[0].nodeValue + "|");
					else if (childObjs[j].nodeName == "product-name")
						pdtNames += (childObjs[j].childNodes[0].nodeValue + "|");
				}
			}

			var catObjs = xmlDoc.getElementsByTagName("category");
			if (!catObjs) {
				return ;
			}
			var catCode = catObjs[0].childNodes[0].nodeValue;

			if (pdtCodes == "" || pdtNames == "" || catCode == undefined || catCode == null) 
	            return;

			// 
			var arrPdtCode = pdtCodes.substr(0, pdtCodes.length-1).split("|");
			var arrPdtName = pdtNames.substr(0, pdtNames.length-1).split("|");
        
			var s = document.getElementById("cat_select_list");
			if (s) {

				// 
				var arrId = -1;
				for (var i=0; i < s.options.length; i++) {
					if (catCode == s.options[i].value) {
						arrId = i;
						break;
					}
				}
				
				if (arrId > -1) {
					ptdCodeList[arrId] = arrPdtCode;
					ptdNameList[arrId] = arrPdtName;
				}
			}

			fillGoods(arrPdtCode, arrPdtName);
		}
	}
}

function fillGoods(arrPdtCode, arrPdtName)
{
        
	var s1 = document.getElementById("pro_select_list");
	if (s1) {

		var bwType= getBorwserType();

		if (bwType == "IE") {

			for (var i=s1.options.length-1; i > 0; i--) {
			
				s1.options.remove(i);
			}  
			
			for (var i=0; i < arrPdtCode.length; i++) {
				var o = document.createElement("option");
				s1.options.add(o);
				o.value = arrPdtCode[i];
				// if css is appled,
				//o.innerText = "&nbsp;&nbsp;" + arrPdtName[i];
				// else
				o.innerText = arrPdtName[i];

			}
			// if css is appled,
			//s1.reInitializeSelectBox();
		}
		else {
			var in_str = "";
			 for (var i=0; i < arrPdtCode.length; i++) {
				in_str += "<option value='" + arrPdtCode[i] + "'>&nbsp;&nbsp;" + arrPdtName[i] + "</option>"
			}
			s1.innerHTML = in_str;
		}

	}
}

