﻿//清空所有条件
function clearallsearch()
{
	//搜索条件设为空
	$('sort').value = "";
	$('purposes').value = "";
	$('price').value = "";
	$('sale').value = "";
	var obj = document.getElementsByName('mapsale');
	for(var i=0;i<obj.length;i++) //循环
   	{
  		obj[i].checked=false; //修改选中状态
     }
     mapsalevalue = "";
	$('fitment').value = "";
	searchcondition['opentime'] = "";
	searchcondition['intime'] = "";
	$('opentimetitle').innerHTML = "开盘时间不限";
	$('intimetitle').innerHTML = "入住时间不限";
	searchresult();
	//setbox1height();
	//$("districtsfont").innerHTML = "";
	//$("paramsfont").innerHTML = "";
	//$("purposesfont").innerHTML = "";
	//$("pricefont").innerHTML = "";
	//$("salefont").innerHTML = "";
	//$("roundfont").innerHTML = "";
	//$("subwayfont").innerHTML = "";
	//$("fitmentfont").innerHTML = "";
	//$("opentimefont").innerHTML = "";
	//$("intimefont").innerHTML = "";
	//各个分类搜索项还原
	
	
}
/*
 * 创建用户浏览历史对象
 * 用来存储用户浏览历史数据
 * 
 */
var history_list = new Array();
function addHistoryItem(hid,title)
{
	for(var i=0; i < history_list.length ; ++i )
	{
      	if( history_list[i].indexOf(hid) > -1 )
      	{
          	return;
       	}
  	}
	var len = history_list.length;
	history_list[len] = hid+';'+title;
	//var v_html = "";
	//v_html += '<li id="history_list_'+ hid +'"><div class="s1"><input name="" onclick="addToCompareList(\''+ hid +'\',this);" type="checkbox" value="' + hid + '" /></div>';
	//v_html += '<div class="s2">' + title + '</div>';
	//v_html += '<div class="s3"><a href="javascript:void(0);" onclick="clearHistory('+ hid +')"><img src="http://guilinhouse.cn/template/images/maps/dot9.gif" alt="" /></a></div>';
	//v_html += '<div class="clear"></div></li>';
	//$("historymenu").innerHTML = $("historymenu").innerHTML + v_html;
	listhistory();
}

function listhistory()
{
	var len = history_list.length;
	history_list.reverse();
	if(len > 10)
	{
		len = 10;
	}
	var v_html = "";
	for(var i=0;i<len;i++)
	{
		var temparr = history_list[i].split(";");
		v_html += '<li id="history_list_'+ temparr[0] +'"><div class="s1"><input name="" onclick="addToCompareList(\''+ temparr[0] +'\',this);" type="checkbox" value="' + temparr[0] + '" /></div>';
		v_html += '<div class="s2">' + temparr[1] + '</div>';
		v_html += '<div class="s3"><a href="javascript:void(0);" onclick="clearHistory('+ temparr[0] +')"><img src="http://guilinhouse.cn/template/images/maps/dot9.gif" alt="" /></a></div>';
		v_html += '<div class="clear"></div></li>';
	}
	history_list.reverse();
	$("historymenu").innerHTML = v_html;
}
//浏览器打开时加载浏览记录
function loadBrowseHistory(){
		try{
			var history = Get_Cookie('newhouseDetail_map');
			history_list = history.split("|");
			listhistory();
			
		}catch(e){
//			alert('No Cookie Stored');
		}
	}
loadBrowseHistory();	
//浏览器关闭时，写入用户历史记录
function writeCookie(){
		try {
			var strCookie = "";
			for(var i=0; i < history_list.length ; ++i )
			{
      			if(i>0)
      			{
      				strCookie +="|";
      			}
				strCookie += history_list[i];
	  		}
			var tdate = new Date();
			tdate.setHours(tdate.getHours() + 1);
			Set_Cookie('newhouseDetail_map', strCookie, tdate, "/", "guilinhouse.cn", "");//map.soufun.com
		}catch(e){
			//没有Cookie
		}
	}
var check_newcode = new Array();
function addToCompareList(hid,obj)
{
	try{
		if(obj.checked)
		{
			if(check_newcode.length >= 4){
				alert("抱歉，您最多选择四个楼盘进行比较");
				obj.checked = false;
			}else{
				check_newcode.push(hid);			
			}
		}else if(!obj.checked){
			checkarrremove(hid);
		}
	}catch(e){
	
	}
}
	
function checkarrremove(obj)
{
	for(var i=0; i < check_newcode.length ; ++i )
	{
        if ( check_newcode[i] == obj ){
            check_newcode.splice(i, 1); 
            break;
        }
    }
}
function openCompare()
{
	if(check_newcode.length > 1)
	{
		var str = '';
		
			str += "http://guilinhouse.cn/newhouse/newhouse_compare_house.aspx?str_id=";
		
		for(var i=0,len=check_newcode.length;i<len;i++){
			str += check_newcode[i] + "|";
		}
		window.open(str);
	}else{
		alert("请选中两个或者两个以上楼盘进行比较");
	}
}
//清除浏览历史记录
function clearHistory(hid)
{
	if(hid > 0)
	{
		//var divobj = $("history_list_"+hid);
		//divobj.parentNode.removeChild(divobj);
		//checkarrremove(hid);
		//$("history_list_"+hid).innerHTML = "";
		for(var i=0; i < history_list.length ; ++i )
		{
      		if ( history_list[i].indexOf(hid) > -1 )
      	 	 {
        		 history_list.splice(i, 1);
        		 listhistory(); 
          		 break;
       		}
  		}
	}
	else
	{
		$("historymenu").innerHTML = "";
		for(var i=0; i < history_list.length ; ++i )
		{
      		var tempid = history_list[i].substring(0,history_list[i].indexOf(';'));
			checkarrremove(tempid);
  		}
		history_list = new Array();
	}
}
window.onunload = function(){
	writeCookie();
	GUnload();
}
//页面高度自适应
function autoResize()
{
	var MINHEIGHT = 630;	//浏览器允许的最小高度
	var MINWIDTH = 900;	//浏览器允许的最小宽度
	var TOPHEIGHT = 5;		//顶部通栏的高度
	var BOTTOMHEIGHT = 10;		//底部信息栏的高度
	var RESULTHEIGHT = 90;	//结果栏顶部和底部的和
	var screenSize = getScreenSize();
	if(screenSize[1] < MINHEIGHT){
		screenSize[1] = MINHEIGHT;			
	}
	var contentHeight = screenSize[1] - TOPHEIGHT - BOTTOMHEIGHT - 2;
	var zs_height = 172;
	if(window.innerWidth)
	{
		zs_height += 6;
	}
	if($("jc_menu"))
	{
		zs_height += 27;
	}
	if($("zs_menu"))
	{
		zs_height += 27;
	}
	if($("esf_menu"))
	{
		zs_height += 27;
	}
	if($("rent_menu"))
	{
		zs_height += 27;
	}
	$("map_menu_container").style.height =  (contentHeight - zs_height) + "px";
	$("tab_div0").style.height =  (contentHeight - 50) + "px";
	$("tab_div1").style.height =  (contentHeight - 50) + "px";
	//$("zhuangshi_tab_div0").style.height =  (contentHeight - 30) + "px";
	//$("zhuangshi_tab_div1").style.height =  (contentHeight - 30) + "px";
	for(var i = 2 ; i < 5 ; i++)
	{
		for(var j = 0 ; j < 4 ; j++)
		{
			
			if($("rightmenu"+i+"list"+j))
			{
				$("rightmenu"+i+"list"+j).style.height =  (contentHeight - 50) + "px";
			}
		}
	}
	
	$("box2ListSearch").style.height =  (contentHeight - 135) + "px";
	$("historymenu").style.height =  (contentHeight - 200) + "px";
	//$("zs_historymenu").style.height =  (contentHeight - 120) + "px";
	//$("zs_box2ListSearch").style.height =  (contentHeight - 120) + "px";
	$("searchNearResult").style.height =  (contentHeight - 185) + "px";
	$("bussteplistmenu").style.height =  (contentHeight - 115) + "px";
	$("buslinelistmenu").style.height =  (contentHeight - 110) + "px";
	$("carsteplistmenu").style.height =  (contentHeight - 145) + "px";
	$("map_result_bar").style.height =   (contentHeight - 215) + "px";
	$("map_result_bar2").style.height =   (contentHeight - 215) + "px";
	$("mapObj").style.height = (contentHeight - 22) + "px";
}
//window.onload = function(){
	//autoResize();
//}
window.onresize = function(){
	autoResize();
}
var mapsalevalue = "";
function mapselectsale(mapsale)
{
	mapsalevalue = mapsale;
	$('sale').value = mapsale;
	searchresult();
}
function changemapsale(sale)
{
	var obj = document.getElementsByName('mapsale');
	mapsalevalue = "";
	for(var i=0;i<obj.length;i++) //循环
   	{
   		if(obj[i].value==sale) //比较值
   		{	
			mapsalevalue = sale;
   			obj[i].checked=true; //修改选中状态
   			
   		}
   		else
   		{
   			obj[i].checked=false;
   		}
   }
}

//区县变化
function changedis(disdata)
{
	isdragend = 0;
	var obj = $('params');
	//清空所有option
	obj.options.length=0; 
	obj.options.add(new Option("选择商圈","")); 
	if(disdata == "")
	{
		map.setCenter(new GLatLng(cityy,cityx), mapsize);
		return;
	}
	
	var datas = disdata.split(',');
	
	if(Area[parseInt(datas[1])])
	{
		var area = Area[parseInt(datas[1])];
		var params;
		for (var i=0; i<area.length; i++)
		{
			params = area[i].split(',');
			obj.options.add(new Option(params[1],params[1])); 
			//if(params[1] == paramsname)
			//{
			//	showdiv('params');
			//	$("paramstitle").innerHTML = paramsname;
			//	searchcondition['params'] = paramsname;
			//	v_html += '<div id="paramstitlename'+i+'" class="name_on">'+params[1]+'</div><div class="clear"></div></li>';
			//}
		}
	}
	//中心点变化
	getcenter(datas[0],"");
}
function changeparams(params)
{
	isdragend = 0;
	var disdata = $('districts').value;
	var datas = disdata.split(',');
	//中心点变化
	getcenter(datas[0],params);
	
}