﻿// JScript File
var xmlhttp;
var fname="";
function getHttpRequest(){

  try{
       xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
  }catch(e){
       xmlhttp = new XMLHttpRequest();
  }  
}

function callXmlHttp(url){
    xmlhttp.open("GET", url, true);
    xmlhttp.setRequestHeader("Content-Type","text/xml; charset=utf-8"); 
    xmlhttp.onreadystatechange=callback;
    xmlhttp.send(null);    
}

function bindLifeCirclef(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {         
      var str=xmlhttp.responseText;   
      var arr=new Array();
      arr=str.split(',');
      var ddl=document.getElementById("ddlSearchLifeCircle")  ; 
      ddl.length=1;
    
      for(var i=0;i<arr.length-1;i++)     {
        var b=arr[i].split('&');
        ddl.options[i+1]=new Option(b[0],b[1]);
      }    
    }      
}

function bindShoppingf(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {         
      var str=xmlhttp.responseText;   
      var arr=new Array();
      arr=str.split(',');
      var ddl=document.getElementById("ddlShopping11")  ; 
      ddl.length=1;
    
      for(var i=0;i<arr.length-1;i++)     {
        var b=arr[i].split('&');
        ddl.options[i+1]=new Option(b[0],b[1]);
      }    
    }
    if(Shopping !=null)
        UndoDll("ddlShopping11",Shopping);    
}

function bindShoppingf1(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {         
      var str=xmlhttp.responseText;   
      var arr=new Array();
      arr=str.split(',');
      var ddl=document.getElementById("ddlShopping1")  ; 
      ddl.length=1;
    
      for(var i=0;i<arr.length-1;i++)     {
        var b=arr[i].split('&');
        ddl.options[i+1]=new Option(b[0],b[1]);
      }    
    }      
}

function bindShoppingf2(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {         
      var str=xmlhttp.responseText;   
      var arr=new Array();
      arr=str.split(',');
      var ddl=document.getElementById("ddlShopping2")  ; 
      ddl.length=1;
    
      for(var i=0;i<arr.length-1;i++)     {
        var b=arr[i].split('&');
        ddl.options[i+1]=new Option(b[0],b[1]);
      }    
    }      
}

function bindXmlHttpRequest(url,Fun)
{ 
   xmlhttp.open("GET", url, true);
   xmlhttp.onreadystatechange = Fun; 
   xmlhttp.send(null);  
}
   
function ddlPriceChange()
{    
    var ddl=document.getElementById("SearchPrice");
    if(ddl!= null)
    {    
        if(document.getElementById("txtSearchPrice1"))document.getElementById("txtSearchPrice1").value="";
        if(document.getElementById("txtSearchPrice2"))document.getElementById("txtSearchPrice2").value=""; 
        if(ddl.selectedIndex==ddl.options.length-1) {    
            document.getElementById("divSearchPrice").style.display="";            
        }
        else
            document.getElementById("divSearchPrice").style.display="none";
    }
}
function ddlSelectAreaChange()
{
    var ddl=document.getElementById("SelectArea");
    if(ddl!= null)
    {
        if(document.getElementById("txtSearchArea1"))document.getElementById("txtSearchArea1").value="";
        if(document.getElementById("txtSearchArea2"))document.getElementById("txtSearchArea2").value="";        
        if(ddl.selectedIndex==ddl.options.length-1) {          
            document.getElementById("divSearchArea1").style.display="";
        }
        else
            document.getElementById("divSearchArea1").style.display="none";
    }
    
}

function BindShopping()
{
    ddlSearchCity = document.getElementById("ddlSearchCity");
    var ddl=document.getElementById("ddlSearchArea");
    var val=ddl.options[ddl.selectedIndex].value;   
    
    if(ddlSearchCity != null){
        bindXmlHttpRequest("IndexSearchTable/BindShopping.ashx?ws3803="+val+ "&ddlDefaultProvince=" + ddlSearchCity.value,bindShoppingf);
    }else{
        bindXmlHttpRequest("IndexSearchTable/BindShopping.ashx?ws3803="+val,bindShoppingf);
    }
} 

function BindShopping1()
{
    var ddl=document.getElementById("ddlSearchArea1");
    var val=ddl.options[ddl.selectedIndex].value;   

    bindXmlHttpRequest("IndexSearchTable/BindShopping.ashx?ws3803="+val,bindShoppingf1);
} 

function BindShopping2()
{
    var ddl=document.getElementById("ddlSearchArea2");
    var val=ddl.options[ddl.selectedIndex].value;   

    bindXmlHttpRequest("IndexSearchTable/BindShopping.ashx?ws3803="+val,bindShoppingf2);
}

function BindLifeCircle()
{
    var ddl=document.getElementById("ddlSearchArea");
    var val=ddl.options[ddl.selectedIndex].value;   
    
    if(ddl != null)
    {
        bindXmlHttpRequest("IndexSearchTable/BindLifeCircle.ashx?pu0106="+val,bindLifeCirclef);
    }
}

function BindLifeCircle2()
{
    var ddl=document.getElementById("ddlSearchArea");
    var val=ddl.options[ddl.selectedIndex].value;   
    
    if(ddl != null)
    {
        bindXmlHttpRequest("../../IndexSearchTable/BindLifeCircle.ashx?pu0106="+val,bindLifeCirclef);
    }
}        

function BindCommunitySearch(keywords, city)
{
    keywords = encodeURI(keywords);
    //alert(keywords);
    bindXmlHttpRequest("../../IndexSearchTable/CommunitySearch.ashx?keywords="+keywords+"&city="+city,bindCommunitySearch);
}
function BindCommunitySearch2(keywords, city)
{
    keywords = encodeURI(keywords);
    //alert(keywords);
    bindXmlHttpRequest("../../IndexSearchTable/CommunitySearch2.ashx?keywords="+keywords+"&city="+city,bindCommunitySearch);
}
function bindCommunitySearch(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {         
      var str=xmlhttp.responseText;
      var div=document.getElementById("searchResult");
      var list=document.getElementById("searchList");
      list.innerHTML = str;
      div.style.display = "";
    }      
}  
 

function SubmitSearchForm(){
     ddlSearchCity = document.getElementById("ddlSearchCity");
     if(ddlSearchCity != null){
        ResetProvince(ddlSearchCity.value);
     }
     return true;
}
