/** 搜索处理 */
function searchTextBlur(obj) {
  if(obj.value=="") {
    obj.value="输入关键词";
  }
}
function searchTextFocus(obj) {
  if(obj.value=="输入关键词") {
    obj.value="";
  }
}

/** 查询处理 */
function houseTypeSubmit() {
  if($("#searchText").val()=="输入关键词"){
    $("#searchText").val("");
  }
  return true;
}

/** 按价格查询 */
function priceSearch(price) {
  $("#totalPrice").val(price);
  $("#searchType").val('3');
  $("#houseSearchSubmit").click();
}

/** 按房数查询 */
function roomSearch(num) {
  $("#typeRoom").val(num);
  $("#searchType").val('3');
  $("#houseSearchSubmit").click();
}

/** 地区查询 */
function areaSearch(area) {
  $("#sDistrict").val(area);
  $("#houseSearchSubmit").click();
}

/** 排序查询 */
function orderbySearch(obj) {
  id = obj.attr("id");
  value = obj.val();
  if(id=="orderbyHousePrice"){
    orderby = $("#orderbyField").val();
    if(orderby=="totalPrice") {
      orderby="totalPrice desc"
      $("#housePriceValue").val("价格 ↓");
    } else {
      orderby="totalPrice";
      $("#housePriceValue").val("价格 ↑");
    }
    // 清空查询
    $("#useAreaValue").val("");
    $("#roomHallValue").val("");
    $("#orderbyField").val(orderby);
    document.getElementById("houseSubmit").click();
    
  } else if(id=="orderbyUseArea") {
    orderby = $("#orderbyField").val();
    if(orderby=="useArea") {
      orderby="useArea desc"
      $("#useAreaValue").val("面积 ↓");
    } else {
      orderby="useArea";
      $("#useAreaValue").val("面积 ↑");
    }
    // 清空查询
    $("#housePriceValue").val("");
    $("#roomHallValue").val("");
    $("#orderbyField").val(orderby);
    document.getElementById("houseSubmit").click();
  } else if (id=="orderbyRoomHall") {
    orderby = $("#orderbyField").val();
    if(orderby=="typeRoom,typeHall") {
      orderby="typeRoom desc,typeHall"
      $("#roomHallValue").val("户型 ↓");
    } else {
      orderby="typeRoom,typeHall";
      $("#roomHallValue").val("户型 ↑");
    }
    // 清空查询
    $("#housePriceValue").val("");
    $("#useAreaValue").val("");
    $("#orderbyField").val(orderby);
    document.getElementById("houseSubmit").click();
  }
  
  
  
}

$(document).ready(function(){
  $("#orderbyRoomHall").bind("click", function(){ orderbySearch($(this)); });
  $("#orderbyHousePrice").bind("click", function(){ orderbySearch($(this)); });
  $("#orderbyUseArea").bind("click", function(){ orderbySearch($(this)); });
}); 

// 设备全选
function selectAllEqp(obj) {
 $(".eqp").each(function(i){this.checked = obj.checked;});
}

// 设置验证码
function getVerify(obj) {
  if(obj.tagName=="IMG") {
    var src = obj.src;
    var baseSrc = src.substr(0,src.lastIndexOf("/"));
    obj.src=baseSrc+"/"+Math.random();
  }
}
/** 新增上传图片行数 */
var rowsnum=1;
function addRow(max){   
  if(rowsnum >= max) {
    alert("最多只能上传"+max+"张图片");
    return false;
  }
  rowsnum++;
  var tbl = document.getElementById("uploadTable");
  var row=tbl.insertRow(-1);
  //var td = arow.insertCell();
  var cell = document.createElement("td");
  cell.innerHTML='<INPUT TYPE="file" id="file[]" name="file[]" class="file  huge">';
  cell.align="center"
  row.appendChild(cell); 
  //addFileForm.num.value=rowsnum;
}

/** 年份日历 */
function td_calendar(){
  
}

/** 检查经纪公司 */
function displayCompany(obj) {
  if(obj.value=="2") {
    $("#sourceCompany").show();
  } else {
    $("#sourceCompany").hide();
  }
}

/** 选择其它小区 */
function selectComm(obj) {
  if(obj.value=="-1"){
    $("#othCommunity").show();
  } else {
    $("#othCommunity").hide();
    $("#othCommunity").val("");
  }
}

/** 选择其它室内设备 */
function selectOthIndoor(obj) {
  if(obj.checked==true) {
    $("#indoorOther").show();
  } else {
    $("#indoorOther").hide();
    $("#indoorOther").val("");
  }
}

/** 选择合租信息 */
function selectCoact(obj) {
  if(obj.checked==true) {
    $("#coactDiv").show();
  } else {
    $("#coactDiv").hide();
  }
}

/** 设置区域名称 */
function formSubmit() {
  // 读取省份名称
  provinceObj = document.getElementById("province");
  document.getElementById("provinceName").value=provinceObj.options[provinceObj.selectedIndex].text;
  // 读取城市名称
  cityObj = document.getElementById("city");
  document.getElementById("cityName").value=cityObj.options[cityObj.selectedIndex].text;
  // 读取地区名称
  districtObj = document.getElementById("district");
  document.getElementById("districtName").value=districtObj.options[districtObj.selectedIndex].text;
  // 读取小区名称
  //communityObj = document.getElementById("community");
  //document.getElementById("communityName").value=communityObj.options[communityObj.selectedIndex].text;
  return true;
}

/** 普通信息提示框 */
function dialogWindowShow(title, msg) {
  msg="<div style='font-size:12px;font-weight:bold;color:#6f6f6f;'>"+
    "<table border=0 width='100%' height='145'><tr height='70'><td align='left' valign='top' style='padding-top:20px;padding-left:10px;' >"+msg+"</td></tr>"+
    "<tr height='40' ><td align='center' style='background-color:#f3f3f3;' ><input type='button' value='确 定' onclick='tb_remove()' ></td></tr>"+
    "</table></div>";
  $('#china186msgwindow').attr('innerHTML', msg);
  var width = 300;
  var height = 150;
  if(title=="") { title="温馨提示"; }
  title="<span style='color:#a2cf06;font-weight:bold;'>"+title+"</span>";
  tb_show(title,'#TB_inline?height='+height+'&width='+width+'&inlineId=china186msgwindow');
}

/** 新增提示 */
function returnTrade(id, msg, view) {
  if(view!="") {
    viewUrl="/"+commDomain+"/house/"+view+"/id/"+id;
  } else {
    viewUrl="/"+commDomain+"/house/listHouse";
  }
  closeTitle = "<div style=\"width:100%;height:20px;border-bottom:solid 1px #afafaf; \" >"+
    "<span style=\"float:left;color:#A1C134;\"><b>操作成功</b></span><span style=\"float:right;\">"+
    "<a href=\"#\" onclick=\"closeOpenWindow()\" style=\"float:right;\"><img src=\"/js/thickbox/close.gif\" ></a></span></div>";
  info = closeTitle+"<br><br>&nbsp;&nbsp;&nbsp;<a href=\""+viewUrl+"\">查看请点击 这里</a><br><br><br><span id=\"modalWindowCount\" style=\"color:red;\" >5</span><span>&nbsp;秒后窗口将关闭</span>";
  showMsg3("<center>"+info+"</center>");
  intervalId=window.setInterval("intervalTimeCall('"+viewUrl+"')", 1000);
}
var intervalId='';
/** 显示时间 */
function intervalTimeCall(url) {
  var s=parseInt(document.getElementById("modalWindowCount").innerHTML)-1;
  document.getElementById("modalWindowCount").innerHTML=s; 
  if(s==0){ 
    document.location.href=url;
  }
  if(s<0) {
    closeOpenWindow();
  }
}

function closeOpenWindow() {
  window.close();
}

/** 标注地图位置 */
function setMap(obj) {
  var titletext = "<font color='#0066ff'><b>地图定位(单击鼠标左键定位)</b></font>";
  if (document.all){ // IE 使用DVI模式
    var url="#TB_inline?height=405&width=605&inlineId=setMapDiv";
	}else{ // FIREFOX 使用IFRAME模式
    var url="/map/commuReg.php?keepThis=true&TB_iframe=true&height=400&width=600";
	}
  tb_show(titletext, url);
}

function hide_map(){
  tb_remove();
}

function clickValueBack(x,y) {
  x=""+x;
  y=""+y;
  document.getElementById("houseX").value=x;
  document.getElementById("houseY").value=y;
  pStr = x.substr(0, 6);
  pStr += " , "+y.substr(0, 6);
  document.getElementById("mapPointValue").innerHTML="<b>[标注成功("+pStr+")]</b>";
  displayMessage(x, y);
}

// 地图操作同域处理
function house_map_init(obj) {
   try {
    map=window.frames.mapObject;
    map.enablePanZoomBar();
    map.enableAddPOI();
   } catch(e) {
   }
}
/** 地图回调函数 */
function GetLatLonByMap(x, y) {
  clickValueBack(x, y);
}

/** 显示提示信息 */
var intTimeObj = null;
var outTimeObj = null;
var mapObjDivHeight = 0;
function displayMessage(x, y) {
  document.getElementById("mapObject").style.height="400px";
  // 先清楚存在的定时
  window.clearTimeout(outTimeObj);
  window.clearInterval(intTimeObj);
  msgDiv = document.getElementById("map_point_msg_div");
  msgDiv.style.height="18px";
  msgDiv.style.display="block";
  msgDiv.style.textAlign="center";
  msgDiv.innerHTML= "<font color=red><b>成功标注了点 [ "+x + " , " +y+" ]</b></font>";
  // 
  mapObjDivHeight = document.getElementById("mapObject").style.height;
  document.getElementById("mapObject").style.height=(document.getElementById("mapObject").clientHeight-18)+"px";
  outTimeObj = window.setTimeout(setStartHideMessge, 1500);
}

function setStartHideMessge() {
  window.clearTimeout(outTimeObj);
  intTimeObj = window.setInterval(hiddenMessage, 100);
}
function hiddenMessage() {
  msgDiv = document.getElementById("map_point_msg_div");
  if(msgDiv.clientHeight<5) {
    msgDiv.style.display="none";
    window.clearInterval(intTimeObj);
    document.getElementById("mapObject").style.height="398px";
  }
  msgDiv .style.height = (msgDiv.clientHeight-2)+"px";
  document.getElementById("mapObject").style.height=(document.getElementById("mapObject").clientHeight+2)+"px";
}



