$(function () {
	$(".search_list li").hover(
		function(){
			$(this).addClass("bb");
		},
		function(){
			$(this).removeClass("bb");
		}
	);
	$(".top_search_div").hover(
		function(){
			$(this).addClass("aa");
		},
		function(){
			$(this).removeClass("aa");
		}
	);
	search_type();
	search_tab_new();
	//changewords();
	
});
function search_tab_new(){
	var uri = location.href;
	var search_type = 0;
	if(uri.indexOf("so.jsp?stype=1") != -1){
		search_type = 0;	
	}else if(uri.indexOf("so.jsp?stype=3") != -1){
		search_type = 3;
	}else if(uri.indexOf("so.jsp?stype=4") != -1){
		search_type = 4;
	}
	search_tab(search_type);	
}
function search_list(id){
	var offset = $("#"+id+"_div").offset();		
	var top = offset.top+24;
	var left=offset.left;//-65;
	if(id == "price" && ($("#search_type").val()==2 || $("#search_type").val()==4))
		id = "price_rent";
	$("#search_"+id).css("top",top);
	$("#search_"+id).css("left",left);
	if($("#search_"+id).css("display") == "none"){
		search_list_none();
		$("#search_"+id).css("display","block");
//		$("#"+id+"_div").addClass("aa");
	}
	
	else if($("#search_"+id).css("display") == "block"){
		$("#search_"+id).css("display","none");
//		$("#"+id+"_div").removeClass("aa");
	}
		
}
function search_list_none(){
	$("#search_search_type").css("display","none");
	$("#search_house_type").css("display","none");
	$("#search_room_type").css("display","none");
	$("#search_area_size").css("display","none");
	$("#search_price").css("display","none");
	$("#search_price_rent").css("display","none");
	$("#search_floor_area_code").css("display","none");
	$("#search_floor_search_type").css("display","none");
	$("#search_esf_area_code").css("display","none");
}
function search_select(id,k,v){
	var old_search_type = $("#search_type").val();
	$("#top_"+id).html(v);
	$("#"+id).val(k);
	if(id == "price" && ($("#search_type").val()==2 || $("#search_type").val()==4))
		id = "price_rent";
	$("#search_"+id).css("display","none");
	if(id == "search_type"){
		if((k == 1 || k == 3) && (old_search_type == 2 || old_search_type == 4 )){cleanPrice();}
		else if((k == 2 || k == 4) && (old_search_type == 1 || old_search_type == 3 )){cleanPrice();}
	}

//	$("#"+id+"_"+k).html("<font color='red'>"+v+"</font>");
}
function search_area_size_deal(){
	var s = $("input[name=search_area_size_begin]").val();
	var e = $("input[name=search_area_size_end]").val();
	if(isNaN(s) || isNaN(e))return;
	if(s == "" && e == "")return;
	var k = "";
	if(s == "")
		k = e+"以下";
	else if(e == "")
		k = s+"以上";
	else
		k = s+"-"+e;
	if(k != "-")
		search_select("area_size",k,k+"m<sup>2</sup>");	
}
function search_price_deal(){
	var s = $("input[name=search_price_begin]").val();
	var e = $("input[name=search_price_end]").val();
	var dan = "万";
	if($("#search_type").val()==2 || $("#search_type").val()==4){
		s = $("input[name=search_rent_price_begin]").val();
		e = $("input[name=search_rent_price_end]").val();	
		dan = "元";
	}
	if(isNaN(s) || isNaN(e))return;
	if(s == "" && e == "")return;
	var k = "";
	var v = "";
	if(s == ""){
		k = e+"以下";
		v = e+dan+"以下";
	}else if(e == ""){
		k = s+"以上";
		v = s+dan+"以上";
	}else{
		k = s+"-"+e;
		v = s+"-"+e+dan;
	}
	if(k != "-")
		search_select("price",k,v);	
}
/*根据不同的地市改变关键字*/
function changewords(){
	var area_code = $("#esf_area_code").val();
	var search_type = $("#search_type").val();
	var act = getHttp(area_code);
	var str = "<span style='padding-left:20px; font-size:12px; color:#c00;line-height:180%; padding:5px 0; font-weight:normal;'>热搜：</span>";
	var k_addr = "?title=";
	if(search_type == 1 || search_type == 3)k_addr = "?addr=";
	if(act != "http://esf.sdfdc.com/"){
//		$("#words11").load(act+"hot_sdfdc.php",{"search_type":search_type});
		$.getJSON(act + "hot_sdfdc.php?callback=?",{"search_type":search_type},function(json){
			$.each(json,function(i,item){
				str += "<a style='padding-right:8px; color:#006699; font-size:12px;' href="+act+"list_"+search_type+".php"+k_addr+item.encode+" target=_blank>"+item.words+"</a>";				
			});
		$("#words").html(str);
		});
	}else{
		$.getJSON(act + "hot_sdfdc.php?callback=?",{"search_type":search_type},function(json){
			$.each(json,function(i,item){
				str += "<a style='padding-right:8px; color:#006699; font-size:12px;' href="+act+"house/houseSale.do?d=listSearchHouseSale&area_code=016&wd=sf&addr="+item.encode+" target=_blank>"+item.words+"</a>";				
			});
		$("#words").html(str);
		});
	}
}
function getHttp(area_code){
	if(area_code == '')area_code = "016001";
	var act = "http://esf.sdfdc.com/";
	if (area_code.indexOf("016001") != -1) act = "http://esf.jn.sdfdc.com/";
	else if (area_code.indexOf("016002") != -1) act = "http://esf.lc.sdfdc.com/";
	else if (area_code.indexOf("016004") != -1) act = "http://esf.dy.sdfdc.com/";
	else if (area_code.indexOf("016005") != -1) act = "http://esf.zbfdc.com/";
	else if (area_code.indexOf("016008") != -1) act = "http://esf.wh.sdfdc.com/";
	else if (area_code.indexOf("016009") != -1) act = "http://www.qdfdc.com/2sf/";
	else if (area_code.indexOf("016010") != -1) act = "http://esf.rz.sdfdc.com/";	
	return act;
}
function submitForm(){
	var area_code = $("#esf_area_code").val();
	var addr = $("input[name=addr]").val();
	if(addr == "请输入位置关键字")addr = "";
//	alert(area_code);
/*
	var act = "http://esf.sdfdc.com/";
	if (area_code.indexOf("016001") != -1) act = "http://esf.jn.sdfdc.com/";
	else if (area_code.indexOf("016002") != -1) act = "http://esf.lc.sdfdc.com/";
	else if (area_code.indexOf("016004") != -1) act = "http://esf.dy.sdfdc.com/";
	else if (area_code.indexOf("016005") != -1) act = "http://esf.zbfdc.com/";
	else if (area_code.indexOf("016008") != -1) act = "http://esf.wh.sdfdc.com/";
	else if (area_code.indexOf("016009") != -1) act = "http://esf.qdfdc.com/";
	else if (area_code.indexOf("016010") != -1) act = "http://esf.rz.sdfdc.com/";		
*/
	var act = getHttp(area_code);
	if(act != "http://esf.sdfdc.com/"){
		var search_type = $("#search_type").val();
		var addr = $("input[name=addr]").val();
		switch(search_type){
			case "1": act = act + "?q=sale";break;
			case "2": act = act + "?q=sale&act=hire";break;
			case "3": act = act + "?q=sale&act=buy";break;
			case "4": act = act + "?q=sale&act=beg";break;
		}
     $("#searchFormkey").attr('value',addr);
	}else {
		document.charset='utf-8';
		var search_type = $("#search_type").val();
		var addr = $("input[name=addr]").val();
		if(addr == "请输入位置关键字")addr = "";
		switch(search_type){
			case "1": act = act + "house/houseSale.do?d=listHouseSale";break;
			case "2": act = act + "house/houseRent.do?d=listHouseRent";break;
			case "3": act = act + "house/houseBuy.do?d=listHouseBuy";$("#title").val(addr);break;
			case "4": act = act + "house/houseBeg.do?d=listHouseBeg";$("#title").val(addr);break;
		}	
	}
	$("input[name=addr]").val(addr);
	
	$("#top_searchForm").attr("action",act);
	$("#top_searchForm").submit();
}
function search_tab(id){
	search_tab_none();
	$("#tab_"+id).addClass("TabsLiHover");
	$("#search_tab_"+id).addClass("dis");
	$("#search_tab_"+id).css("display","block");
}
function search_tab_none(){
	search_list_none();
	for(i=0;i<5;i++){
		$("#tab_"+i).removeClass("TabsLiHover");
		$("#search_tab_"+i).removeClass("dis");
		$("#search_tab_"+i).addClass("undis");
		$("#search_tab_"+i).css("display","none");
	}
}
function cleanPrice(){
	$("#top_price").html("价格范围");
	$("#price").val("");	
}
function search_type(){
	var uri = location.href;
	var search_type = 1;
	var top_search_type = "出售";
	if(uri.indexOf("list_2.php") != -1){
		search_type = 2;
		top_search_type = "出租";
	}else if(uri.indexOf("list_3.php") != -1){
		search_type = 3;
		top_search_type = "求购";
	}else if(uri.indexOf("list_4.php") != -1){
		search_type = 4;
		top_search_type = "求租";
	}
	$("#search_type").val(search_type);
	$("#top_search_type").html(top_search_type);
}
