﻿    // JScript 文件
    var request;
    var nextname;
    var hotname;
    var fan;
    var fantype;
    function createRequest() {
      try {
        request = new XMLHttpRequest();
      } catch (trymicrosoft) {
        try {
          request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (othermicrosoft) {
          try {
            request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (failed) {
            request = false;
          }
        }
      }
      if (!request)
        alert("Error initializing XMLHttpRequest!");
    }
    //*******
    //第一个请求
    //*******
    function showarea(idname,hotarea,classid) {
      nextname=idname;
      hotname=hotarea;
     document.getElementById("areavalue").value="-1";
     document.getElementById("hotvalue").value="-1";

      RemoveAll(document.getElementById(nextname));
      RemoveAll(document.getElementById(hotname));
      createRequest();
      var url='area.html?classid='+classid;
      request.open("GET",url,true);
      request.onreadystatechange=updateeara;
      request.send(null);
    }
    function updateeara(){
        if(request.readyState==4){
            if(request.status==200){
      showlist();//处理服务器端返回的信息.
               
            }
        }
        else{
      document.getElementById("nextdrp").style.display="none";
      document.getElementById("listdiv").style.display="block";
      document.getElementById("Div1").style.display="none";
      document.getElementById("Div2").style.display="none";
      }
    }

    function showlist(){
        var arealist=request.responseXML;   
        var date=new Date();                             //获得数据
    if(arealist==null)return;

    var rootarea=arealist.documentElement;
    if(rootarea)                                                //如果存在

    {
        document.getElementById("listdiv").style.display="none";
        document.getElementById("nextdrp").style.display="block";
        document.getElementById("Div1").style.display="none";
        document.getElementById("Div2").style.display="none";
        var xingzhengarea=document.getElementById(nextname);
        xingzhengarea.options.add(new Option("Any","-1",true,true)); 
        var hotarea=document.getElementById(hotname);
        hotarea.options.add(new Option("Any","-1",true,true));   
        for(var i=0;i<rootarea.childNodes.length;i++)//遍历行
         {
            var seclist=rootarea.childNodes[i];
            for(j=0;j<seclist.childNodes.length;j++)
            {
             var rootlistarea=seclist.childNodes[j];
             if(i==0)
             {
                xingzhengarea.options.add(new Option(rootlistarea.childNodes[0].firstChild.nodeValue,rootlistarea.childNodes[1].firstChild.nodeValue));
                 
              }
              else
               {
                  hotarea.options.add(new Option(rootlistarea.childNodes[0].firstChild.nodeValue,rootlistarea.childNodes[1].firstChild.nodeValue));
               } 
              }
        }    
    }
    }
    function   RemoveAll(oElem)   
    {  
            
    var i=0;     
    for (i= oElem.length;i>=0;   i--)
    {     
    oElem.remove(i);     
    }     
    }
    function setvalue(name,zz)
    {
    document.getElementById(name).value=zz;
    }
    //显示价格范围
    function showprice(idname,fanname,classid) {
      fantype=idname;
      fan=fanname;
      document.getElementById("fanvalue").value="-1";
      //document.getElementById("fantype").value="mfan";
      if(classid==17)
      {   
       document.getElementById("fantype").value="dfan";
       }
       else
       {
       if(classid==18)
       {     
       document.getElementById("fantype").value="wfan";
       }
       else
       {     
      document.getElementById("fantype").value="mfan";
      }
      }
      RemoveAll(document.getElementById(fan));
     // RemoveAll(document.getElementById(hotname));
      createRequest();
      var url='area.html?classid='+classid;
      request.open("GET",url,true);
      request.onreadystatechange=pricepage;
      request.send(null);
    }
    function pricepage(){
        if(request.readyState==4){
            if(request.status==200){
      getprice();//处理服务器端返回的信息.
               
            }
        }
        else{
      document.getElementById("Div4").style.display="none";
      document.getElementById("Div3").style.display="block";
      }
    }

    function getprice(){
        var xml=request.responseXML;   
        var date=new Date();                             //获得数据
    if(xml==null)return;

    var root=xml.documentElement;
    if(root)                                                //如果存在

    {
        document.getElementById("Div3").style.display="none";
        document.getElementById("Div4").style.display="block";
        var pricefan=document.getElementById(fan);
        pricefan.options.add(new Option("Any","-1",true,true)); 
        for(var i=0;i<root.childNodes.length;i++)//遍历行
         {
            var seclist=root.childNodes[i];
            for(j=0;j<seclist.childNodes.length;j++)
            {
                var rootlist=seclist.childNodes[j];
                pricefan.options.add(new Option(rootlist.childNodes[0].firstChild.nodeValue,rootlist.childNodes[1].firstChild.nodeValue));
                 
              }
        }    
    }
    }
function findvalue(classid) {
  createRequest();
  var url='/range.html?classid='+classid;
  request.open("GET",url,true);
  request.onreadystatechange=findfanclassid;
  request.send(null);
}
function findfanclassid(){
    if(request.readyState==4){
        if(request.status==200){
        var classtxt=request.responseText;
        if(classtxt=="0")
        {
        document.getElementById("btnsearch").disabled=true;
        document.getElementById("pfan").value="";
        alert("please select children item");
        }
        else
        {
        if(classtxt=="1")
        {
           document.getElementById("btnsearch").disabled=true;
           document.getElementById("pfan").value="";
           alert("no find the item!");
        }
        else
        {
        document.getElementById("pfan").value=classtxt;
        document.getElementById("btnsearch").disabled=false;
       }
        }
     
           
        }
    }
    else{
        document.getElementById("btnsearch").disabled=true;
    }
}