﻿var xmlHttp=null;
    var xmlDoc = null;
    var infoList = null;
    var picList = null;
    var descList = null;
    var nodeHTML = "";
    var count = 12;
    var currentCount = 1;
    var show;
    var initFalg = true;
    var nameList;
    var pidIndex;
    var infoIndex;
    var filePath;
    var totlePage;
    var selectType = 1;
    function changeSelectedType(type){
        selectType = type;
    }
    function initShow(divName)
    {
        nodeHTML = "";
        var listValue ="";
        currentCount=1;
         for(var i =0;i<document.getElementsByName("R1").length;i++)
     {
      if (document.getElementsByName("R1")[i].checked== true )
      {
       selectType = document.getElementsByName("R1")[i].value;
      }
     }
        var thisUrl = document.location.href;
        if (thisUrl.indexOf("?") != -1 && initFalg) 
        {
              var strUrl = thisUrl.substr(thisUrl.indexOf("?")+1);
              listValue = strUrl.split("=")[1];
              initFalg = false;
        }else{
              if(selectType==2){
                listValue = document.getElementById("car").value;
              }else if(selectType==3){
                listValue = document.getElementById("car1").value;
              }else if(selectType==4){
                listValue = document.getElementById("car2").value;
              }else{
                listValue = "accxml1";
             }
        }xmlDoc = null;
          ajaxRequest(listValue);
            createInfoList();//alert(infoList.length);
            if(infoList !=null && infoList.length >0)
            {
                //createheaderDiv();
                createContentDiv(currentCount);
                //createheaderDiv();
            }
        show = document.getElementById(divName);
        show.innerHTML = "";//alert(nodeHTML);
        show.innerHTML = nodeHTML;
        
        
    }
    function readyStateChangeHandle()
    {//alert("------");
        if(xmlHttp.readyState==4)
        {//alert("------"+xmlHttp.status);
            if(xmlHttp.status==200)
            {
                xmlDoc=xmlHttp.responseXML;//alert(xmlDoc.xml);
            }
        }    
    }
    function ajaxRequest(xmlName)
    {
        xmlName = xmlName+".xml";//alert(xmlName);
        if(window.XMLHttpRequest)
        {
            xmlHttp=new XMLHttpRequest();
        }
        else if(window.ActiveXObject)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        if(xmlHttp != null){
            xmlHttp.onreadystatechange=readyStateChangeHandle;
            xmlHttp.open("GET",xmlName,false);
            xmlHttp.send(null);
        }//alert("oooooo");
        if(xmlDoc==null && window.XMLHttpRequest){//alert("oooooo");
                xmlDoc = document.implementation.createDocument("","",null);
                xmlDoc.async=false;
                xmlDoc.load(xmlName);
        }
    }
        function createInfoList()
        {
            nameList = new Array();
            infoList = new Array(); 
            picList = new Array();
            descList = new Array();
            pidIndex = 0;
            infoIndex = 0;
            //var list = xmlDoc.getElementsByTagName("list");
            //var listNodes = list[0].childNodes;
            //alert("dddddddd");
            var listNumber = 0;
            var listNodes = xmlDoc.getElementsByTagName("acc");
            listNumber = listNodes.length;
            for(var i=0;i<listNumber;i++)
            {
                if(listNodes[i].nodeType == 3)//无效的TEXT_NODE 
                {
                      continue;
                    }
                var pNode = listNodes[i].getElementsByTagName("name");
                var pid = pNode[0].childNodes[0].nodeValue;
                if(checkPid(pid))
                {
                    nameList[pidIndex] = pid;//alert(pid);
                    //alert(pidIndex+"  etrt  "+pidList[pidIndex]);
                    pidIndex++;
                    var nNode = listNodes[i].getElementsByTagName("name");
                    var pName = nNode[0].childNodes[0].nodeValue;
                    infoList[infoIndex] = pName;
                    var picNode = listNodes[i].getElementsByTagName("img");
                    var picSrc = picNode[0].childNodes[0].nodeValue;
                    picList[infoIndex] = picSrc;
                    var descNode = listNodes[i].getElementsByTagName("text");
                    var desc = descNode[0].childNodes[0].nodeValue;
                    descList[infoIndex] = desc;
                    infoIndex++;
                }
            }
        }
        function createheaderDiv()
        {
            var str = "";
            var pageStr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";        
            for(var i=1;i<=getTotalPage();i++)//totlePage
            {
                str += "<li><a href=\"#\" onclick=\"changePage("+i+")\" cursor=\"pointer\">"+i+"</a></li>";
            }//alert(str);
            pageStr += "<div class=\"h3\"  style=\"margin-bottom:10px;\"><div class=\"fltr\"><div class=\"pgno\"><span class=\"previous\"><a href=\"#\"onclick=\"previousPage()\" cursor=\"pointer\"></a></span>"+"<ul><li class=\"txt\">页面:"+str+"</li></ul>"+" <a href=\"#\"onclick=\"nextPage()\" cursor=\"pointer\"></a></div></div></div><div class=\"clearb\" /></div>";
            return pageStr;
        }
        function createheaderDiv2()
        {
            var str = "";
            var pageStr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";        
            for(var i=1;i<=getTotalPage();i++)//totlePage
            {
                str += "<li><a href=\"#\" onclick=\"changePage("+i+")\" cursor=\"pointer\">"+i+"</a></li>";
            }//alert(str);
            pageStr += "<div class=\"\"><div class=\"word_btn fltl\">"+"<span class=\"next\"></span>"+"<a class=\"aline\" href=\"where-to-buy.htm\">哪里买</a></div><div class=\"fltr\"><div class=\"pgno\"><span class=\"previous\"><a href=\"#\"onclick=\"previousPage()\" cursor=\"pointer\"></a></span>"+"<ul><li class=\"txt\">页面:"+str+"</li></ul>"+" <a href=\"#\"onclick=\"nextPage()\" cursor=\"pointer\"></a></div></div><div class=\"top\"><a href=\"#\">回到顶部</a></div></div><div class=\"clearb\"></div>";
            return pageStr;
        }
    
    function createContentDiv(curPage)
    {
        nodeHTML = nodeHTML += "<div class=\"product_content\"><div class=\"\"><div class=\"word_btn fltl\" ><span class=\"next\"></span><a href=\"where-to-buy.htm\" class=\"aline\">哪里买</a></div>";
        if(count<infoList.length){
            nodeHTML = nodeHTML + createheaderDiv();
        }
        nodeHTML += "<div class=\"h3_acc\"><div class=\"access_home\">";
        var iCount = (curPage - 1) * count;
        var cCount = curPage * count;
        if(cCount > infoList.length)
        {
            cCount = infoList.length;
        }
        for(var i=iCount;i<cCount;i=i+2)
        {
            if(infoList[i+1] == undefined)
            {
                nodeHTML = nodeHTML += "<div class='acc_list'><div class='box bottomdot'><div class='leftimg'><img src='"+picList[i]+"'/></div><div class=\"righttop\">"+infoList[i]+"</div><div class=\"rightbottom\">"+descList[i]+"<br/><a href='http://eshop.mio.com.cn/eshop/shop_index.jsp' class='button'>立即购买</a><a href='#' class='button_right'></a></div></div></div>";
            }
            else
            {
                nodeHTML = nodeHTML += "<div class='acc_list bottomdot'><div class='box'><div class='leftimg'><img src='"+picList[i]+"'/></div><div class=\"righttop\">"+infoList[i]+"</div><div class=\"rightbottom\">"+descList[i]+"<br/><a href='http://eshop.mio.com.cn/eshop/shop_index.jsp' class='button'>立即购买</a><a href='#' class='button_right'></a></div><div class=\"clearb\"></div></div><div class=\"box\"><div class=\"leftimg\"><img src='"+picList[i+1]+"'/></div><div class='righttop'>"+infoList[i+1]+"</strong></div><div class=\"rightbottom\">"+descList[i+1]+"<br/><a href='http://eshop.mio.com.cn/eshop/shop_index.jsp' class='button'>立即购买</a><a href='#' class='button_right'></a></div><div class=\"clearb\"></div></div></div>";
            }
        }
        nodeHTML = nodeHTML += "</div></div>";
        if(count<infoList.length){
            nodeHTML = nodeHTML + createheaderDiv2();
        }
    }
    function checkPid(pidValue)
    {
        for(var i=0;i<pidIndex;i++)
        {
            if(nameList[i] == pidValue)
            {
                return false;
            }
        }
        return true;
    } 
    function changePage(pageCount)
    {
        currentCount = pageCount;
        nodeHTML = "";
        //createheaderDiv();
        createContentDiv(currentCount);
        //createheaderDiv();
        show.innerHTML = nodeHTML;
    }
    
    function nextPage()
    {
        if(currentCount<totlePage)
        {
            currentCount = currentCount + 1;
        }
        nodeHTML = "";
        //createheaderDiv();
        createContentDiv(currentCount);
        //createheaderDiv();
        show.innerHTML = nodeHTML;
    }
    
    function previousPage()
    {
        if(currentCount>1)
        {
            currentCount = currentCount - 1;
        }
        nodeHTML = "";
        //createheaderDiv();
        createContentDiv(currentCount);
        //createheaderDiv();
        show.innerHTML = nodeHTML;
    }
    function getTotalPage(){
        return (infoList.length)%count>0?(((infoList.length)/count)+1):((infoList.length)/count);
    }
