﻿var xmlHttp=null;
    var xmlDoc = null;
    var infoList = null;
    //var beforeAllList = null;
    var nodeHTML = "";
    var count = 10;
    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 changeByTime(){
          if(infoList!=null && infoList.length>0){
                var selectValue = document.getElementById("select1").value;
                var selectList = new Array();
                for(var n=0;n<infoList.length;n++){//alert("ddddd");
                    if(selectValue===infoList[n].yearValue){
                        selectList.push({desc:infoList[n].desc,dateValue:infoList[n].dateValue,linkValue:infoList[n].linkValue});
                    }
                }
                createSelectDiv("productsContent",selectList);
          } 
    }
    function initShow(divName)
    {
        nodeHTML = "";
        var listValue ="";
        currentCount=1;
        xmlDoc = null;
         for(var i =0;i<document.getElementsByName("productClass").length;i++)
             {
              if (document.getElementsByName("productClass")[i].checked== true )
              {
               selectType = document.getElementsByName("productClass")[i].value;
              }
             }
        var thisUrl = document.location.href;
        var beforeListShowdoNode = document.getElementById("beforeListShow");
        if (thisUrl.indexOf("?") != -1 && initFalg) 
        {
              var strUrl = thisUrl.substr(thisUrl.indexOf("?")+1);
              listValue = strUrl.split("=")[1];
              initFalg = false;
        }else{
              if(selectType==2){
                listValue = "products_press";//document.getElementById("car").value;
                 beforeListShowdoNode.style.display = "";
              }else if(selectType==3){
                listValue = "corparate_press";//document.getElementById("car1").value;
                 beforeListShowdoNode.style.display = "";
              }else if(selectType==4){
                listValue = "product_promotion_press";//document.getElementById("car2").value;
                 beforeListShowdoNode.style.display = "";
              }else if(selectType==5){
                listValue = "map_updates_press";
                beforeListShowdoNode.style.display = "";
              }else{
                listValue = "all_press";
                beforeListShowdoNode.style.display = "";
             }
        }
        //alert(listValue);
        ajaxRequest(listValue);
        createInfoList();
        /*if(beforeAllList!=null && beforeAllList.length>0){
            createBeforeContentDiv("productsContent1",beforeAllList);
        }*/
        if(infoList !=null && infoList.length >0){
             createContentDiv(currentCount);
        }
        show = document.getElementById(divName);
        show.innerHTML = "";//alert(nodeHTML);
        show.innerHTML = nodeHTML;
        
        
    }
    function readyStateChangeHandle()
    {
        if(xmlHttp.readyState==4)
        {
            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){
                xmlDoc = document.implementation.createDocument("","",null);
                xmlDoc.async=false;
                xmlDoc.load(xmlName);
        }
    }
        function createInfoList()
        {
            infoList = new Array(); 
            //beforeAllList = new Array(); 
            pidIndex = 0;
            infoIndex = 0;
            var listNodes = xmlDoc.getElementsByTagName("product");
            var listNumber = listNodes.length;
            for(var i=0;i<listNumber;i++)
            {
                if(listNodes[i].nodeType == 3)
                {
                          continue;
                    }
                var pNode = listNodes[i].getElementsByTagName("desc");
                var pid = pNode[0].childNodes[0].nodeValue;
                var date1 = listNodes[i].getElementsByTagName("date");
                var dateValue = date1[0].childNodes[0].nodeValue;
                var yearNode = listNodes[i].getElementsByTagName("year");
                var linkNode = listNodes[i].getElementsByTagName("link");
                var linkValue = linkNode[0].childNodes[0].nodeValue;
                <!--if(i>=3){-->
                     infoList.push({desc:pid,dateValue:dateValue,yearValue:yearNode[0].childNodes[0].nodeValue,linkValue:linkValue});//alert("2");            
                          /*}else{
                      beforeAllList.push({desc:pid,dateValue:dateValue});
                }*/
                
            }
        }
        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=\"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>";
            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=\"h3top fltl\"><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>";
            return pageStr;
        }
    function createSelectDiv(divName,selectList){
           var divcontentStr = "<div class=\"h3\"></div><div class=\"press_list_block\"><ul class=\"\">"; 
           for(var m=0;m<selectList.length;m++){
                   divcontentStr +="<li class=\"btm_dash\"><div class=\"press_list_txt\"><a href='"+infoList[m].linkValue+"'>"+selectList[m].desc+"</a></div><div class=\"press_date\">"+selectList[m].dateValue+"</div></li>"
           }
            divcontentStr += "</div><div class=\"h3\"></div>";
            var beforeCont = document.getElementById(divName);
        beforeCont.innerHTML = "";//alert(nodeHTML);
        beforeCont.innerHTML = divcontentStr;
            
    }
    function createContentDiv(curPage)
    {
        nodeHTML = nodeHTML += "<div class=\"h3\"><div class=\"fltr mb5\">";
        if(count<infoList.length){
            nodeHTML = nodeHTML + createheaderDiv();
        }
        nodeHTML += "</div><div><div class=\"press_list_block\"><ul>";
        var iCount = (curPage - 1) * count;
        var cCount = curPage * count;
        if(cCount > infoList.length)
        {
            cCount = infoList.length;
        }
        for(var m=iCount;m<cCount;m++){
            nodeHTML +="<li class=\"btm_dash\"><div class=\"press_list_txt\"><a href='"+infoList[m].linkValue+"'>"+infoList[m].desc+"</a></div>"
            nodeHTML += "<div class=\"press_date\">"+infoList[m].dateValue+"</div></li>";
        }
        nodeHTML = nodeHTML += "</ul></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);
    }