 /*
    名称：产品查询
    编写：GeSen
    时间：06-06-07
    功能：利用Ajax进行产品查询，请在调用的页面家在Ajax.js
*/
 
        ///////////////////////////////////////////////////////////// 设置视图 /////////////////////////////////////////////////////////////
        function sendAjaxAllBigSort()
        {
            var select1 = document.getElementById("select1");
            if(select1.options[0].value == "" && select1.options.length == 1)
            {
                sendAjaxWithXml("?type=allBigSort", setSelectBigSort);
            }
        }
        // 初始化大类
        function setSelectBigSort()
        {
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
                var xmlDom = xmlHttp.responseXml;
                var rows = xmlDom.getElementsByTagName("row");
                var select1 = document.getElementById("select1");
                for(var i = select1.options.length; i > -1 ; i--)
                {
                    select1.options.remove(i);
                }
                var op = document.createElement("option");
                op.value = "";
                op.text = "--全部大类--";
                select1.add(op);
                for(var i = 0; i < rows.length; i++)
                {
                    var id = rows.item(i).getElementsByTagName('id').item(0).text
                    var name = rows.item(i).getElementsByTagName('name').item(0).text
                    var op = document.createElement("option");
                    op.value = id;
                    op.text = name;
                    select1.add(op);
                }
            }
        }
        // 根据大类查小类
        function sendAjaxByBigSort()
        {
            var select1 = document.getElementById("select1");
            var bigSortId = select1.options[select1.selectedIndex].value;
            sendAjaxWithXml("?type=smallSortByBigSort&bigSortId=" + bigSortId, setSelectSmallSort);
        }
        function setSelectSmallSort()
        {
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
                var xmlDom = xmlHttp.responseXml;
                var rows = xmlDom.getElementsByTagName("row");
                var select2 = document.getElementById("select2");
                var select3 = document.getElementById("select3");
                for(var i = select2.options.length; i > -1 ; i--)
                {
                    select2.options.remove(i);
                }
                for(var i = select3.options.length; i > -1 ; i--)
                {
                    select3.options.remove(i);
                }
                var op = document.createElement("option");
                op.value = "";
                op.text = "--全部小类--";
                select2.add(op);
                for(var i = 0; i < rows.length; i++)
                {
                    var id = rows.item(i).getElementsByTagName('id').item(0).text
                    var name = rows.item(i).getElementsByTagName('name').item(0).text
                    var op = document.createElement("option");
                    op.value = id;
                    op.text = name;
                    select2.add(op);
                }
            }
        }
        // 根据小类查品牌
        function sendAjaxBySmallSort()
        {
            var select2 = document.getElementById("select2");
            var smallSortId = select2.options[select2.selectedIndex].value;
            sendAjaxWithXml("?type=brandBySmallSort&smallSortId=" + smallSortId, setSelectBrandSort);
        }
        function setSelectBrandSort()
        {
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
                var xmlDom = xmlHttp.responseXml;
                var rows = xmlDom.getElementsByTagName("row");
                var select3 = document.getElementById("select3");
                for(var i = select3.options.length; i > -1 ; i--)
                {
                    select3.options.remove(i);
                }
                var op = document.createElement("option");
                op.value = "";
                op.text = "--全部品牌--";
                select3.add(op);
                for(var i = 0; i < rows.length; i++)
                {
                    var id = rows.item(i).getElementsByTagName('id').item(0).text
                    var name = rows.item(i).getElementsByTagName('name').item(0).text
                    var op = document.createElement("option");
                    op.value = id;
                    op.text = name;
                    select3.add(op);
                }
            }
        }
        // 查询
        function btnSearch()
        {
            var select1 = document.getElementById("select1");
            var select2 = document.getElementById("select2");
            var select3 = document.getElementById("select3");
            var txtPrice1 = document.getElementById("txtPrice1");
            var txtPrice2 = document.getElementById("txtPrice2");
            var txtKeyword = document.getElementById("txtKeyword"); 
	        
	        var bigSortId = select1.options[select1.selectedIndex].value;
	        var smallSortId = "";
	        var brandId = "";
	        var price1 = txtPrice1.value;
	        var price2 = txtPrice2.value;
	        var keyword = encodeURIComponent(txtKeyword.value);
	        var bigSortName = encodeURIComponent(select1.options[select1.selectedIndex].text);
	        var smallSortName = "";
	        var brandName = "";
            
	        if(select2.options.length != 0)
	        {
		        smallSortId = select2.options[select2.selectedIndex].value;
		        smallSortName = encodeURIComponent(select2.options[select2.selectedIndex].text);
	        }
	        if(select3.options.length != 0)
	        {
		        brandId = select3.options[select3.selectedIndex].value;
		        brandName = encodeURIComponent(select3.options[select3.selectedIndex].text);
	        }
	        window.open("http://szh.525j.com.cn/NewStore/ProductList_search2_" + bigSortId + "_" + bigSortName + "_" + smallSortId + "_" + smallSortName + "_" + brandId + "_" + brandName + "_" + price1 + "_" + price2 + "_" + keyword + ".html");
        }