$(document).ready(function(){
    $("#dosearch").bind("click",search);
    search();
});

function search(){
    var tradeType = $("#tradeType").val();//数据库中0代表出售
    var cityZone = $("#cityZone").val();//城区
    var module = $("#module").val();//户型室
    var moduleB = $("#moduleB").val();//户型厅
    var moduleC = $("#moduleC").val();//户型卫
    var houseType = $("#houseType").val();//房屋类型
    var priceType = $("#priceType").val();//价格类型:单价/总价
    var Price = $("#Price").val();//价格低区间
    if(Price=="") Price="0";
    var floor = $("#floor").val();
    var Acreage = $("#Acreage").val();//面积高区间
    var infoType = 0;
    var sendID = $("#sendID").val();//发布人信息
    var dates = getRadioBoxValue("dates");  //时效信息
    var decoration = $("#decoration").val();
    var district = $('#district').val();
    //window.alert("tradeType: 0  cityZone: "+cityZone+"   moduleA: "+moduleA+"  houseType: "+houseType+"   priceType: "+priceType+"   minPrice:"+minPrice+"  maxAcreage: "+maxAcreage+"  infoType: "+infoType+"  sendID: "+sendID+"  dates: "+dates);
    if(cityZone=="" && module=="0" && moduleB=="0" && floor=="0" && moduleC=="0" && houseType=="" && Price=="0" && Acreage=="0" && sendID=="" && dates=="0" && infoType=="9999"){
        window.alert("请先选择查询条件！");
        $("#cityZone")[0].focus();
        return false;
    }
    if(tradeType=="0"){
        $.get("/second_hand/saleSearchResult.jsp?tradeType="+tradeType+"&cityZone="+cityZone+"&module="+module+"&moduleB="+moduleB+"&moduleC="+moduleC+"&houseType="+houseType+"&priceType="+priceType+"&Price="+Price+"&Acreage="+Acreage+"&infoType="+infoType+"&sendID="+sendID+"&dates="+dates+"&district="+district+"&floor="+floor+"&decoration="+decoration,null,showinfo);
        $("#showresult").html("<div style=\" text-align:center; height:200px;\"><image src='/images/second_loading.gif'/><br/>数据加载中，请稍候......</div>");
    }else if(tradeType=="1"){
        $.get("/second_hand/rentSearchResult.jsp?tradeType="+tradeType+"&cityZone="+cityZone+"&module="+module+"&moduleB="+moduleB+"&moduleC="+moduleC+"&houseType="+houseType+"&priceType="+priceType+"&Price="+Price+"&Acreage="+Acreage+"&infoType="+infoType+"&sendID="+sendID+"&dates="+dates+"&district="+district+"&floor="+floor+"&decoration="+decoration,null,showinfo);
        $("#showresult").html("<div style=\" text-align:center; height:200px;\"><image src='/images/second_loading.gif'/><br/>数据加载中，请稍候......</div>");
    }else{
        alert("非法数据提交");
        return false;
    }


}

function showinfo(data){
    var tradeType = $("#tradeType").val();//数据库中0代表出售
    var replay = $.trim(data);
    var temp;
    if(tradeType=="0"){
        temp = replay.split("<form method=\"get\" action=\"/second_hand/saleSearchResult.jsp\" name=\"formSpage\">"); 
    }else if(tradeType=="1"){
        temp = replay.split("<form method=\"get\" action=\"/second_hand/rentSearchResult.jsp\" name=\"formSpage\">");
    }else{
        alert("非法数据提交");
        return false;
    }
    var context = temp[1].split("</form>");
    $("#showresult").html(context[0]);
}

function _doQuery(pageNo){
   var curPage=1;
   if(pageNo!=null && pageNo!=""){
       curPage = pageNo;
   }
	var tradeType = $("#tradeType").val();//数据库中0代表出售
    var cityZone = $("#hcityZone").val();//城区
    var module = $("#hmodule").val();//户型室
    var moduleB = $("#hmoduleB").val();//户型厅
    var moduleC = $("#hmoduleC").val();//户型卫
    var houseType = $("#hhouseType").val();//房屋类型
    var priceType = $("#hpriceType").val();//价格类型:单价/总价
    var Price = $("#hPrice").val();//价格低区间
    if(Price=="") Price="0";
    var floor = $("#hfloor").val();
    var Acreage = $("#hAcreage").val();//面积高区间
    var infoType = 0;
    var sendID = $("#hsendID").val();//发布人信息
    var dates = $("#hdates").val();  //时效信息
    var district = $('#hdistrict').val();
    var decoration=$("#hdecoration").val();
    if(tradeType=="0"){
        $.get("/second_hand/saleSearchResult.jsp?tradeType="+tradeType+"&cityZone="+cityZone+"&module="+module+"&moduleB="+moduleB+"&moduleC="+moduleC+"&houseType="+houseType+"&priceType="+priceType+"&Price="+Price+"&Acreage="+Acreage+"&infoType="+infoType+"&sendID="+sendID+"&dates="+dates+"&district="+district+"&floor="+floor+"&decoration="+decoration+"&pageno="+curPage,null,showinfo);
        $("#showresult").html("<div style=\" text-align:center; height:200px;\"><image src='/images/second_loading.gif'/><br/>数据加载中，请稍候......</div>");
    }else if(tradeType=="1"){
        $.get("/second_hand/rentSearchResult.jsp?tradeType="+tradeType+"&cityZone="+cityZone+"&module="+module+"&moduleB="+moduleB+"&moduleC="+moduleC+"&houseType="+houseType+"&priceType="+priceType+"&Price="+Price+"&Acreage="+Acreage+"&infoType="+infoType+"&sendID="+sendID+"&dates="+dates+"&district="+district+"&floor="+floor+"&decoration="+decoration+"&pageno="+curPage,null,showinfo);
        $("#showresult").html("<div style=\" text-align:center; height:200px;\"><image src='/images/second_loading.gif'/><br/>数据加载中，请稍候......</div>");
    }else{
        alert("非法数据提交");
        return false;
    }
}

function getRadioBoxValue(radioName)
{
    var obj = document.getElementsByName(radioName);             //这个是以标签的name来取控件
    for(i=0;i<obj.length;i++){
		if(obj[i].checked){
            return obj[i].value;
        }
    }
    return "1";
  } 

function submitRentSearch(){
    var tradeType = 0;//数据库中0代表出售
    var cityZone = document.searchRentInfo.cityZone[document.searchRentInfo.cityZone.selectedIndex].value;//城区
    var module = document.searchRentInfo.module.value;//户型室
    var moduleB = document.searchRentInfo.moduleB.value;//户型厅
    var moduleC = document.searchRentInfo.moduleC.value;//户型卫
    var houseType = document.searchRentInfo.houseType[document.searchRentInfo.houseType.selectedIndex].value;//房屋类型
    var priceType = document.searchRentInfo.priceType.value;//价格类型:单价/总价
    var Price = document.searchRentInfo.Price.value;//价格低区间
    var floor = document.searchSaleInfo.floor.value;
    alert(floor);
    if(Price=="") Price="0";
    var Acreage = document.searchRentInfo.Acreage[document.searchRentInfo.Acreage.selectedIndex].value;//面积高区间
//    var minPrice = document.searchRentInfo.minPrice.value;//价格低区间
//    if(minPrice=="") minPrice="0";
//    var maxPrice = document.searchRentInfo.maxPrice.value;//价格高区间
//    if(maxPrice=="") maxPrice="0";
//    var minAcreage = document.searchRentInfo.minAcreage[document.searchRentInfo.minAcreage.selectedIndex].value;//面积低区间
//    var maxAcreage = document.searchRentInfo.maxAcreage[document.searchRentInfo.maxAcreage.selectedIndex].value;//面积高区间
    //var infoType = document.searchRentInfo.infoType[document.searchRentInfo.infoType.selectedIndex].value;//信息类型:挂牌/成交
    var infoType = 0;
    var sendID = document.searchRentInfo.sendID[document.searchRentInfo.sendID.selectedIndex].value;//发布人信息
    var dates = getRadioBoxValue("dates");//时效信息
    //window.alert("tradeType: 0  cityZone: "+cityZone+"   moduleA: "+moduleA+"  houseType: "+houseType+"   priceType: "+priceType+"   minPrice:"+minPrice+"  maxAcreage: "+maxAcreage+"  infoType: "+infoType+"  sendID: "+sendID+"  dates: "+dates);
    if(cityZone=="" && module=="0" && moduleB=="0" && floor=="0" && moduleC=="0" && houseType=="" && Price=="0" && Acreage=="0" && sendID=="" && dates=="0" && infoType=="9999"){
      window.alert("请先选择查询条件！");
      document.searchRentInfo.cityZone.focus();
      return ;
    }
    document.searchRentInfo.target="rentSearchResult";
    document.searchRentInfo.submit();
    //document.frames.rentSearchResult.window.location.reload();
    //document.frames.rentSearchResult.window.location.href="";
  }

  function getRadioBoxValue(radioName)
{
    var obj = document.getElementsByName(radioName);             //这个是以标签的name来取控件
    for(i=0;i<obj.length;i++){
		if(obj[i].checked){
            return obj[i].value;
        }
    }
    return "1";
  }   