﻿//初始化城市区县
//$("box1List").style.height =  "85px";
function initialDistricts()
{
	//初始化District数据
	var obj = $('districts');
	
	for (var i=0; i<Districts.length; i++)
	{
		if(Districts[i].name.indexOf("周边") > -1 || Districts[i].name.indexOf("其他") > -1)
		{
			
		}
		else
		{
			if(Districts[i].name==districtname)
			{
				districtname += ','+Districts[i].index;
			}
			obj.options.add(new Option(Districts[i].name,Districts[i].name+','+Districts[i].index)); 
		}
	}
	
}

//控制分类搜索项前的图标
function showdiv(index)
{
	if($(index).style.display == "none")
	{
		var elems = document.getElementsByTagName("div");   
		for( var i = 0; ( elem = elems[i] ); i++ ){   
		if(elem.className == 'box1List2' )
		{
			elem.style.display = "none";
			var temp = elem.id;
			if(temp != "")
			{
				$(temp+"img").src = "http://guilinhouse.cn/template/images/maps/dot3.gif";
			}
		}
		}
		//$("paramsimg").src = "http://guilinhouse.cn/template/images/maps/dot3.gif";
		$(index).style.display = "block";
		
		$(index+"img").src = "http://guilinhouse.cn/template/images/maps/dot2.gif";
		/*if(checkFirefoxOrIE() == 0)
		{
			var menutop = $(index).offsetTop ;
		}
		else
		{
			var menutop = $(index).offsetTop - $("map_menu_container").offsetTop;
		}
		$("map_menu_container").scrollTop = menutop - 50;
		//$("map_menu_container").scrollTop = $(index).offsetTop-50;
		//alert(menutop);
		//alert($(index).offsetHeight);
		*/
	}
	else
	{
		$(index).style.display = "none";
		$(index+"img").src = "http://guilinhouse.cn/template/images/maps/dot3.gif";
	}
}
//初始化商圈
function initalparams(disdata)
{
	var obj = $('params');
	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>';
			//}
		}
	}
}
//初始化物业类型
function initialPurposes()
{
	//初始化物业类型
	var obj = $('purposes');
	for (var i=0; i<Purposes.length; i++)
	{
		obj.options.add(new Option(Purposes[i].name,Purposes[i].name+','+Purposes[i].index)); 
		if(Purposes[i].name==purposename)
		{
			purposename += ','+Purposes[i].index;
		}
		//if(Purposes[i].name == purposename)
		//{
		//	showdiv('purposes');
		//	initialPrice(Purposes[i].index);
		//	inttialover = 1;
		//	$("purposestitle").innerHTML = purposename;
		//	searchcondition['purposes'] = purposename;
		//	v_html += '<div id="purposestitlename'+i+'" class="name_on">'+Purposes[i].name+'</div><div class="clear"></div></li>';
		//}
		
		
	}
	//if(inttialover == 0)
	//{
		initialPrice(-1);
	//}
}
//物业类型变化
function changepurp(purp)
{
	if(purp == "")
	{
		initialPrice(-1);
	}
	else
	{
		var datas = purp.split(',');
		initialPrice(datas[1]);
	}
}
function checkbox(boxname)
{
var str=document.getElementsByName(boxname);
var objarray=str.length;
var chestr="";
for (var i=0;i<objarray;i++)
{
  if(str[i].checked == true)
  {
   chestr+=str[i].id;
  }
}
return chestr;
}
//初始化价格
function initialPrice(index)
{
	
	//初始化价格
	var obj = $('price');
	
	obj.innerHTML = "";
	//obj.options.length=0; 
	obj.options.add(new Option("楼盘均价","")); 
	/*
	var checkstr = checkbox("purposes");
	if(checkstr != "")
	{
		var index1 = checkstr.substring(8,checkstr.length);
		if(index1.length == 1)
		{
			index = parseInt(index1);
		}
		else
		{
			index = -1;
		}
	}
	else
	{
		index = -1;
	}
	*/
	
	var pricecondition = "";
	var price = Price[index];
	var priceSuffix;
	if(price.unit.indexOf('天')>-1)
	{
		priceSuffix='天';
	}
	else if(price.unit.indexOf('月')>-1)
	{
		priceSuffix='月';
	}
	else if(price.unit.indexOf('万')>-1)
	{
		priceSuffix='套价';
	}
	else
	{
		priceSuffix='';
	}
	if(price.text.length > 0)
	{
		var group = document.createElement('OPTGROUP');  
    	group.label = price.unit;  
    	group.id = price.unit;
    	obj.appendChild(group); 
	}        
	for (var i=0; i<price.text.length; i++)
	{
		if(price.value[i].indexOf('以下')>-1)
		{
			pricecondition = "[,"+price.value[i].substr(0,price.value[i].indexOf('以下'))+"]";
		}
		else if(price.value[i].indexOf('以上')>-1)
		{
			pricecondition = "["+price.value[i].substr(0,price.value[i].indexOf('以上'))+",]";
		}
		else
		{
			var tempprice = price.value[i].split("-");
			pricecondition = "["+tempprice[0]+","+tempprice[1]+"]";
		}
		obj.options.add(new Option(price.value[i],pricecondition+priceSuffix)); 
		if(price.value[i]==pricevalue)
		{
			pricevalue = pricecondition+priceSuffix;
		}
		//if(price.value[i]+priceSuffix == pricevalue)
		//{
		//	showdiv('price');
		//	$("pricetitle").innerHTML = price.value[i];
		//	searchcondition['price'] = pricecondition+priceSuffix;
		//	v_html += '<div id="pricetitlename'+i+'" class="name_on">'+price.value[i]+'</div><div class="clear"></div></li>';
		//}
		//else
		//{
		//	v_html += '<div id="pricetitlename'+i+'" class="name">'+price.value[i]+'</div><div class="clear"></div></li>';
		//}
		
	}
	price = Price[parseInt(index)+10];
	if(price)
	{
		if(price.unit.indexOf('天')>-1)
		{
			priceSuffix='天';
		}
		else if(price.unit.indexOf('月')>-1)
		{
			priceSuffix='月';
		}
		else if(price.unit.indexOf('万')>-1)
		{
			priceSuffix='套价';
		}
		else
		{
			priceSuffix='';
		}
		if(price.text.length > 0)
		{
			var   group   =   document.createElement('OPTGROUP');  
    		group.label   =   price.unit;  
    		obj.appendChild(group); 
		}        
		for (var j=0; j<0+price.text.length; j++)
		{
			if(price.value[j].indexOf('以下')>-1)
			{
				pricecondition = "[,"+price.value[j].substr(0,price.value[j].indexOf('以下'))+"]";
			}
			else if(price.value[j].indexOf('以上')>-1)
			{
				pricecondition = "["+price.value[j].substr(0,price.value[j].indexOf('以上'))+",]";
			}
			else
			{
				var tempprice = price.value[j].split("-");
				pricecondition = "["+tempprice[0]+","+tempprice[1]+"]";
			}
			obj.options.add(new Option(price.value[j],pricecondition+priceSuffix)); 
			if(price.value[j]==pricevalue)
			{
				pricevalue = pricecondition+priceSuffix;
			}
			//if(price.value[j]+priceSuffix == pricevalue)
			//{
			//	showdiv('price');
			//	$("pricetitle").innerHTML = price.value[j];
			//	searchcondition['price'] = pricecondition+priceSuffix;
			//	v_html += '<div id="pricetitlename'+parseInt(j+i+1)+'" class="name_on">'+price.value[j]+'</div><div class="clear"></div></li>';
			//}
			
		}
		
	}
}

//初始化环线
function initialRound()
{
	var obj = $('round');
	//清空所有option
	//obj.options.length=0; 
	//obj.options.add(new Option("选择环线","")); 
	if(mapcityround == "")
	{
		return;
	}
	else
	{
		var roundarr = mapcityround.split(",");
		
		for(var i = 0 ; i < roundarr.length ; i++)
		{
			obj.options.add(new Option(roundarr[i],roundarr[i])); 
			
		}
	}
}
//搜索条件字符
function settitle(index,titlestr,num)
{
	return;
	$(index+"title").innerHTML = titlestr;
	/*
	if(titlestr == "全部" || titlestr == "")
	{
		$(index+"font").innerHTML = "";
	}
	else
	{
		$(index+"font").innerHTML = " - "+titlestr;	
	}
	
	//如果没有选项就显示北京全部楼盘
	if($('districtsfont').innerHTML == "" && $('paramsfont').innerHTML == "" && $('purposesfont').innerHTML == ""
		&& $('pricefont').innerHTML == "" && $('salefont').innerHTML == "" && $('roundfont').innerHTML == ""
		&& $('subwayfont').innerHTML == "" && $('fitmentfont').innerHTML == "" && $('opentimefont').innerHTML == ""
		&& $('intimefont').innerHTML == "")
	{
		$('cityname').innerHTML = searchcondition['cityname']+"全部楼盘";	
	}
	else
	{
		$('cityname').innerHTML = searchcondition['cityname'];	
	}
	*/
	if($(index+"titlename"))
	{
		$(index+"titlename").className = "name";
	}
	for(var i=0;i<100;i++)
	{
		if($(index+"titlename"+i))
		{
			$(index+"titlename"+i).className = "name";
		}
	}
	if($(index+"titlename"+num))
	{
		$(index+"titlename"+num).className = "name_on";
	}
	if(index=="districts")
	{
		getcenter(titlestr,"");
	}
	if(index=="params")
	{
		getcenter(searchcondition['districts'],titlestr);
	}
	//setbox1height();
	
}
//设置开始时间面板
function openmenu(index)
{
	if($(index+"menu").style.display == "none")
	{
		$(index+"menu").style.display = "block";
	}
	else
	{
		$(index+"menu").style.display = "none";
	}
	
}
//搜索条件字符 时间样式
function settimetitle(index)
{
	closetip();
	var titlestr = "";
	var syear = $(index+"syear").value;
	var smonth = $(index+"smonth").value;
	var eyear = $(index+"eyear").value;
	var emonth = $(index+"emonth").value;
	var searchdate = "[";
	if(smonth == "" && syear == "" && emonth == "" && eyear == "")
	{
		$(index+"menu").style.display = "none";
		if(index == "intime")
		{
			$(index+"title").innerHTML = "入住时间";
		}
		else
		{
			$(index+"title").innerHTML = "开盘时间";
		}
		searchcondition[index] = "";
		searchresult();
		return;
	}
	if(smonth != "" && syear == "")
	{
		alert("输入开始年份");
		return false;
	}
	if(emonth != "" && eyear== "")
	{
		alert("输入结束年份");
		return false;
	}
	if(syear >= eyear)
	{
		if(((parseInt(syear+smonth) > parseInt(eyear+emonth)) && (parseInt(eyear+emonth) != 0)))
		{
			alert("结束时间必须大于开始时间");
			return false;
		}
	}
	
	
	if(smonth != "")
	{
		
		titlestr += syear+"."+smonth.substring(0,2);
		searchdate += syear+smonth;
	}
	else
	{
		if(syear != "")
		{
			titlestr += syear;
			searchdate += syear+"0101";
		}
		else
		{
			searchdate += "";
		}
	}
	searchdate += ",";
	if(emonth != "" && !(eyear == syear && emonth == smonth))
	{
		titlestr += "-"+eyear+"."+emonth.substring(0,2);
		searchdate += eyear+emonth;
	}
	else
	{
		if(eyear != "" && eyear!=syear)
		{
			titlestr += "-"+eyear;
			searchdate += eyear+"1231";
		}
		else if(eyear != "")
		{
			searchdate += eyear+"1231";
		}
	}
	searchdate += "]";
	$(index+"title").innerHTML = titlestr;
	$(index+"menu").style.display = "none";
	searchcondition[index] = searchdate;
	searchresult();
}
//设置搜索条件并搜索
function setsearch(index,searchvalue)
{
	if(searchurl == "")
	{
		return;
	}
	$("resultList").innerHTML = "";
	$("newmapObj").style.display = "block";
	var url = searchurl;
	var pars = searchurlpars;
	if(index == "page")
	{
		pars +=  '&page='+searchvalue;
		pars +=  '&sort='+$('sort').value;
	}
	else if(index == "sort")
	{
		pars +=  '&page=0';
		pars +=  '&sort='+searchvalue;
	}
	
	var myAjax = new Ajax.Request
	(
         url,
         {method: 'post', postBody: pars,onFailure:showFailure, onComplete: showSearchResult}
    );
	//searchresult();
}
//点击菜单上面的搜索条件字符串搜索
function allsearch()
{
	searchcondition["newcode"] = "";
	searchcondition["page"] = "";
	searchcondition["key"] = "";
	searchresult();
}
//提示字符
function lostfocus(index)
{
	var str = defaultValue[index]["text"];
	if($(index).value == "")
	{
		
		$(index).value = str;
	}
}
//提示字符
function getinput(index)
{
	var str = defaultValue[index]["text"];
	if($(index).value == str)
	{
		$(index).value = "";
	}
}
//控制右侧菜单的显示
function showmenu(index,list)
{
	for(var j =0;j < 10;j++)
	{
		if($("rightmenu"+j))
		{
			$("rightmenu"+j).style.display = "none";
		}
	}
	if($("rightmenu"+index))
	{
		$("rightmenu"+index).style.display = "block";
	}
	if(index == 0)
	{
		tabit('tab',list-1,2,'a_');
	}
	else
	{
		for(var j =0;j < 4;j++)
		{
			if($("rightmenu"+index+"list"+j))
			{
				$("rightmenu"+index+"list"+j).style.display = "none";
			}
		}
		if($("rightmenu"+index+"list"+list))
		{
			$("rightmenu"+index+"list"+list).style.display = "block";
		}
	}
}
var searchbustype = "1";
function setsearchbustype(type)
{
	searchbustype = type;
	for(var j =0;j < 10;j++)
	{
		if($("bustype"+j))
		{
			$("bustype"+j).style.display = "none";
		}
	}
	$("bustype"+type).style.display = "block";
}
function getdistance(le){//得到里程
	if(le<=1000){
		var s = le;
		return s+"米";
	}else{
		var s = Math.round(le/1000);
		return "约"+s+"公里";
	}
}
//显示周边搜索右边栏
function filltempsearch(cname,num)
{
	house_near_num = num;
	showmenu(2,1);
	$("tempnearname").value = cname;
}
//地图比例放大
function zoomIn()
{
	//var zoomnum = map.getZoom();
	//mapObj.setZoomLevel(parseInt(zoomnum)+1);
	map.zoomIn();
}
//地图比例缩小
function zoomOut()
{
	//var zoomnum = mapObj.getZoomLevel();
	//mapObj.setZoomLevel(parseInt(zoomnum)-1);
	map.zoomOut();
}
//设置为驾车的终点
function gotodriveend()
{
	temp_driveend_x = temp_drivestart_x;
	temp_driveend_y = temp_drivestart_y;
	temp_drivestart_y = "";
	temp_drivestart_x = "";
	var tempstr = $("tempdriverend").value;
	$("tempdriverend").value = $("tempdriverstart").value;
	$("tempdriverstart").value = tempstr;
	temp = $("tempdriverend").disabled;
	$("tempdriverend").disabled = $("tempdriverstart").disabled;
	$("tempdriverstart").disabled = temp;
	$("setdriverend").style.display = "block";
	$("setdriverstart").style.display = "none";
}
//设置为驾车的起点
function gotodrivestart()
{
	temp_drivestart_x = temp_driveend_x;
	temp_drivestart_y = temp_driveend_y;
	temp_driveend_x = "";
	temp_driveend_y = "";
	var tempstr = $("tempdriverend").value;
	$("tempdriverend").value = $("tempdriverstart").value;
	$("tempdriverstart").value = tempstr;
	temp = $("tempdriverend").disabled;
	$("tempdriverend").disabled = $("tempdriverstart").disabled;
	$("tempdriverstart").disabled = temp;
	$("setdriverend").style.display ="none";
	$("setdriverstart").style.display = "block";
}
//右侧菜单的驾车搜索
function gotosearchdrive(btype)
{
	//$("startarea").value = $("tempdriverstart").value;
	//$("endarea").value = $("tempdriverend").value;
	if(document.popup != null)
    {
        document.popup.hide(true);
    }
	isdragend = 1;
	listname(btype);
}
//链接到驾车搜索的右侧菜单
var temp_drivestart_x = "";
var temp_drivestart_y = "";
var temp_driveend_x = "";
var temp_driveend_y = "";
function filltempdrive(cname,hitx,hity)
{
	showmenu(4,0);
	temp_driveend_x = hitx;
	temp_driveend_y = hity;
	$("tempdriverstart").value = "";
	$("tempdriverend").value = cname;
	$("setdriverend").style.display ="block";
	$("setdriverstart").style.display = "none";
}
function filltempstartdrive(cname,hitx,hity)
{
	showmenu(4,0);
	temp_drivestart_x = hitx;
	temp_drivestart_y = hity;
	$("tempdriverend").value = "";
	$("tempdriverstart").value = cname;
	$("setdriverstart").style.display ="block";
	$("setdriverend").style.display = "none";
}
//设置为驾车的终点
function gotobusend()
{
	temp_driveend_x = temp_drivestart_x;
	temp_driveend_y = temp_drivestart_y;
	temp_drivestart_y = "";
	temp_drivestart_x = "";
	var tempstr = $("tempbusend").value;
	$("tempbusend").value = $("tempbusstart").value;
	$("tempbusstart").value = tempstr;
	temp = $("tempbusend").disabled;
	$("tempbusend").disabled = $("tempbusstart").disabled;
	$("tempbusstart").disabled = temp;
	$("setbusend").style.display = "block";
	$("setbusstart").style.display = "none";
}
//设置为驾车的起点
function gotobusstart()
{
	temp_drivestart_x = temp_driveend_x;
	temp_drivestart_y = temp_driveend_y;
	temp_driveend_x = "";
	temp_driveend_y = "";
	var tempstr = $("tempbusend").value;
	$("tempbusend").value = $("tempbusstart").value;
	$("tempbusstart").value = tempstr;
	temp = $("tempbusend").disabled;
	$("tempbusend").disabled = $("tempbusstart").disabled;
	$("tempbusstart").disabled = temp;
	$("setbusend").style.display ="none";
	$("setbusstart").style.display = "block";
	
}
//链接到公交搜索的右侧菜单
function filltempbus(cname,hitx,hity)
{
	temp_driveend_x = hitx;
	temp_driveend_y = hity;
	showmenu(3,0);
	$("tempbusstart").value = "";
	$("tempbusend").value = cname;
	$("setbusend").style.display ="block";
	$("setbusstart").style.display = "none";
}
//右侧菜单的公交搜索
function gotosearchbus()
{
	searchbustype = "1";
	$("busstartname").value = $("tempbusstart").value;
	$("busendname").value = $("tempbusend").value;
	searchbuslist();
}


/* get, set, and delete cookies */
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires.toGMTString() : "" ) + //expires.toGMTString()
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


//获取大小，用于页面自适应
function getScreenSize()
{
	var theWidth,theHeight;
	if (window.innerWidth) 
	{ 
		theWidth = window.innerWidth ;
		theHeight = window.innerHeight;
	} 
	else if (document.compatMode=='CSS1Compat') 
	{ 
		theWidth = document.documentElement.clientWidth ;
		theHeight = document.documentElement.clientHeight ;
	
	} 
	else if (document.body) 
	{ 
		theWidth = document.body.clientWidth ;
		theHeight = document.body.clientHeight ;

	} 
	var result = [theWidth,theHeight];
	return result;
}
function hideRightMenu()
{
	if($('map_result_main').style.display == 'none')
	{
		$('map_result_main').style.display='block';
		$('map_body_box').style.paddingRight = '214px';
		$('map_result_barimg_open').style.display = "none";
		$('map_result_barimg_hide').style.display = "block";
	}
	else
	{
		$('map_result_main').style.display='none';
		$('map_body_box').style.paddingRight = '4px';
		$('map_result_barimg_hide').style.display = "none";
		$('map_result_barimg_open').style.display = "block";
	}
	map.checkResize();
}
function hideLeftMenu()
{
	if($('map_left_container').style.display == 'none')
	{
		$('map_left_container').style.display='block';
		$('pagebodyRight1').style.marginLeft = '180px';
		$('map_result_barimg_open2').style.display = "none";
		$('map_result_barimg_hide2').style.display = "block";
	}
	else
	{
		$('map_left_container').style.display='none';
		$('pagebodyRight1').style.marginLeft = '6px';
		$('map_result_barimg_hide2').style.display = "none";
		$('map_result_barimg_open2').style.display = "block";
	}
	map.checkResize();
}
//清空检索项
function clearitem(index)
{
	if($(index+"title"))
	{
		$(index+"title").innerHTML = "";
	}
	//$(index+"font").innerHTML = "";
	//$('cityname').innerHTML = searchcondition['cityname']+"全部楼盘";	
	if($(index+"titlename"))
	{
		$(index+"titlename").className = "name";
	}
	for(var i=0;i<100;i++)
	{
		if($(index+"titlename"+i))
		{
			$(index+"titlename"+i).className = "name";
		}
	}
}
function cleartimeitem(index)
{
	$(index+"title").innerHTML = "";
	//$(index+"font").innerHTML = "";
	//$('cityname').innerHTML = searchcondition['cityname']+"全部楼盘";	
	$(index+"syear").value = "";
	$(index+"smonth").value = "";
	$(index+"eyear").value = "";
	$(index+"emonth").value = "";
}
function setbox1height()
{
	var str = $('box1Listsearch').innerHTML;
	var exp = /\"/g;
	str = str.replace(exp,"");
	var len = str.length;
	if(len > 338 && len <= 354)
	{
		$("box1List").style.height =  (85 + 15) + "px";
	}
	else if(len > 354 && len <= 370)
	{
		$("box1List").style.height =  (85 + 30) + "px";
	}
	else if(len > 370 && len <= 386)
	{
		$("box1List").style.height =  (85 + 50) + "px";
	}
	else if(len > 386)
	{
		$("box1List").style.height =  (85 + 65) + "px";
	}
	else
	{
		$("box1List").style.height =  "85px";
	}
	$("map_menu_container").style.height =  ($("map_left_container").offsetHeight - $("box1Listup").offsetHeight - 30) + "px";
}
function checkFirefoxOrIE(){
userAgent=window.navigator.userAgent.toLowerCase();
if(userAgent.indexOf("firefox")>=1){
return 1;
}
else {
	return 0;
}
}

function changeround(round)
{
	isdragend = 0;
	searchtype = 1;
	searchrsstatrt = 1;
	searchresult();
}
function changesubway(subway)
{
	isdragend = 0;
	searchtype = 1;
	searchrsstatrt = 1;
	searchresult();
}

function gotoorder(index,city)
{
	if(city=="bj")
	{
		window.location='http://'+index+'.soufun.com/map/';
	}
	else
	{
		window.location='http://'+index+'.'+city+'.soufun.com/map/';
	}
}