﻿// JScript 文件
function SelectProduct(stype)
{
    
    var d = document.getElementById(dotnetIdPrefix + "cmbProductName");
    if(d==null )
        d = document.getElementById("cmbProductName");
    d.options.length = 0;
    
    var opt = new Option("loading...","-1",true,true)
    d.options[d.options.length] = opt;
     
    RequestProduct(stype);
    
}

function RequestProduct(stype)
{    
    var c = document.getElementById(dotnetIdPrefix + "cmbCategory")
    if (c==null )
        c=document.getElementById("cmbCategory")        
    var CategoryId = c.value;            
    if(CategoryId == -1 ) 
    {
        var d = document.getElementById(dotnetIdPrefix + "cmbProductName");
        if(d==null )
           d = document.getElementById("cmbProductName");
        d.options.length = 0;
        return;
    }
    
    createXMLHttpRequest(); 
    
    var url = webheader + 'xml/ProductXml.aspx?CategoryId=' + CategoryId+"&stype=" + stype;
    XMLHttpReq.open("GET", url, true); 
    
    XMLHttpReq.onreadystatechange = doSelectProduct;//指定响应函数 
    XMLHttpReq.send(null); // 发送请求 
    //return false;
}

function doSelectProduct()
{
    if (XMLHttpReq.readyState == 4) 
    { // 判断对象状态 
        if (XMLHttpReq.status == 200) 
        { // 信息已经成功返回
           
           var d = document.getElementById(dotnetIdPrefix + "cmbProductName");
           if(d==null )
              d = document.getElementById("cmbProductName");
           d.options.length = 0;
                    
           var item = XMLHttpReq.responseXML.getElementsByTagName("product"); 
           for(var i=0;i<item.length;i++)
           {
                 var pValue = item[i].childNodes[0].firstChild.nodeValue;
                 var pText = item[i].childNodes[1].firstChild.nodeValue;
                 
                 var d = document.getElementById(dotnetIdPrefix + "cmbProductName");   
                 if(d==null )
                    d = document.getElementById("cmbProductName");
                 var opt = new Option(pText,pValue,true,true)   
                 d.options[d.options.length]  =  opt;
           }
           
        } 
        else 
        { //页面不正常 
	        alert("读取品名数据错误，请稍候再试，或联系网站管理员。");
        } 
    } 
}