/**
 * @author Cocowool
 */

window.onload = function(){
	sinamap.autoResize();
}
	
window.onresize = function(){
	sinamap.autoResize();
}

window.onunload = function(){
	sinamap.writeCookie();
}

var SinaMap = function(url,mapabc,xhr,conf){
	this.url = url || "";
	this.mapabc = mapabc || MapAbc;
	this.xhr = xhr || "";
	this.conf = conf || '';
	
	this.points = [];		//记录楼盘搜索结果标点
	this.centerpoint = [];	//记录中心楼盘点
	this.result = '';		//记录楼盘搜索文字结果,对象格式
	this.resultHtml = '';
	this.tabstatus = 'result';
	
	this.pageinit();
	
	if(this.url.getParam() != false){
		//处理URL请求		
		MapFilter.changeMenu($(this.conf.initMenu),false);
	}else{
		//加载菜单显示
		if(!isNull(this.conf.initMenu)){
			MapFilter.changeMenu($(this.conf.initMenu));
		}else{
			MapFilter.changeMenu($(this.conf.initMenu),false);
			Element.hide('nowLoading');
		}
	}
};

SinaMap.prototype = {
	MINHEIGHT:600,	//浏览器允许的最小高度
	MINWIDTH:900,	//浏览器允许的最小宽度
	TOPHEIGHT:106,		//顶部通栏的高度
	BOTTOMHEIGHT:2,		//底部信息栏的高度
	RESULTHEIGHT:90,	//结果栏顶部和底部的和
	pageinit:function(){
		this.autoResize();
		this.initEvent();
		this.mapabc.init(this.conf);
		
		this.loadAdInfo();
		this.loadBrowseHistory();
		//显示加载进度提示
		var ajaxGlobalHandlers = {
			onCreate:function(){
				Element.show('nowLoading');
			},
			onComplete:function(){
				if(Ajax.activeRequestCount == 0){
					Element.hide('nowLoading');
				}
			}
		};
		Ajax.Responders.register(ajaxGlobalHandlers);
		
		window.scroll(0,650000);	//纠正Firefox下地图无法正常点击
		
		//初始化自动提示
		var options = {
			//发送的请求
			script:function(str){
				var url = "query.php?";
				var q = "q=keyword:" + str + " OR houseaddress:" + str;
				return url + q ; 
				},
			varname:"q",
			json:true,
			shownoresults:true,
			maxentries:15
		};
		var sina_suggest = new bsn.AutoSuggest('housekeyword', options);
	},
	//初始化页面中的事件
	initEvent:function(){
		var that = this;
		
		//右侧蓝隐藏
		Event.observe('map_result_bar','click',function(){
			that.hideSidebar();
		});
		
		//打印地图功能
		Event.observe('sinamapPrint','click',function(){
			that.printMap();
		});
		
		Event.observe('sh_nav_10','mouseover',function(){
			that.switchResultAndHistory('result');
		});

		Event.observe('sh_nav_11','mouseover',function(){
			that.switchResultAndHistory('history');
		});
		
		for(var i in this.conf.defaultValue){
			$(i).value = this.conf.defaultValue[i].text;
			bindEvent(i,$(i));
		};
	},
	hideSidebar:function(flag){
		if($('map_result_main').style.display == ''){
			$('map_result_main').hide();
			$('map_main_container').style.paddingRight = '8px';
			$('map_result_barimg').src = 'http://map.house.sina.com.cn/images/btn_sider_left.gif';
		}else{
			$('map_result_main').show();
			$('map_main_container').style.paddingRight = '255px';
			$('map_result_barimg').src = 'http://map.house.sina.com.cn/images/btn_sider.gif';
		}
		
		if(flag != undefined && flag == false){
			$('map_result_main').show();
			$('map_main_container').style.paddingRight = '255px';
			$('map_result_barimg').src = 'http://map.house.sina.com.cn/images/btn_sider.gif';
		}
	},
	autoResize:function(){
		var screenSize = getScreenSize();
		if(screenSize[1] < this.MINHEIGHT){
			screenSize[1] = this.MINHEIGHT;			
		}
		var contentHeight = screenSize[1] - this.TOPHEIGHT - this.BOTTOMHEIGHT - 2;
		$("map_main_container").style.height =  contentHeight + "px";
		$("map_menu_container").style.height =  contentHeight + "px";
		
		$("map_result_main").style.height =   contentHeight + "px";
		$("map_result_bar").style.height =   contentHeight + "px";
		$("map_result_content").style.height =   (contentHeight - this.RESULTHEIGHT) + "px";
		
		$("map_flashmap").style.height = (contentHeight - 30) + "px";

		var elems = document.getElementsByTagName("div");   
		for( var cls, i = 0; ( elem = elems[i] ); i++ ){   
			if( elem.className == 'sider_nav_sub' ){
				elem.style.height = (contentHeight - 126) + "px";
			}   
		} 
	},
	/*
	 * 改变页面的视图
	 */
	changeView:function(flag){
	 	var items = $('map_result_top').getElementsByTagName('div');
		for (var i = 0 in items) {
			if (typeof items[i] != 'object') {
				continue;
			}
			items[i].style.display = 'none';
		}

	 	var items = $('map_result_bottom').getElementsByTagName('div');
		for (var i = 0 in items) {
			if (typeof items[i] != 'object') {
				continue;
			}
			items[i].style.display = 'none';
		}
		
		switch(flag){
			case "topSearchAround":
				this.hideSidebar(false);
				Element.show('map_result_top_around');
				Element.show('map_result_bottom_around');
				
				$('map_result_top').style.height = '45px';
				$('map_result_bottom').style.height = '45px';
				this.RESULTHEIGHT = '90';
				this.autoResize();
				
				$('sinamapPrint').style.display = 'none';
				$('windowPrint').style.display = '';
				
				break;
			case "topSearchBus":
			case "topSearchBusStation":
			case "topSearchBusline":
				this.hideSidebar(false);
				Element.show('map_result_top_bus');
				Element.show('map_result_bottom_bus');
				Element.hide('map_routetype_select');

				$('map_result_bottom').style.height = '27px';
				$('map_result_top').style.height = '27px';
				this.RESULTHEIGHT = '54';
				this.autoResize();

				$('sinamapPrint').style.display = 'none';
				$('windowPrint').style.display = '';

				break;
			case "topSearchDrive":
				this.hideSidebar(false);
				Element.hide('map_result_top_house');

				Element.show('map_result_top_drive');
				Element.show('map_result_bottom_drive');

//				$('map_result_bottom').style.height = '27px';
//				this.RESULTHEIGHT = '72';
//				this.autoResize();

				Element.hide('map_driveroutetype_select');
				$('map_result_bottom').style.height = '27px';
				$('map_result_top').style.height = '27px';
				this.RESULTHEIGHT = '54';
				this.autoResize();

				$('sinamapPrint').style.display = 'none';
				$('windowPrint').style.display = '';
				break;
			case "topSearchHouse":
			default:
				Element.show('map_result_top_house');
				Element.show('map_result_bottom_house');
				sinamap.hideSidebar(false);		//显示结果栏
				sinamap.switchResultAndHistory('result');

				$('map_result_top').style.height = '45px';
				$('map_result_bottom').style.height = '45px';
				this.RESULTHEIGHT = '90';
				this.autoResize();
				$('sinamapPrint').style.display = '';
				$('windowPrint').style.display = 'none';
				break;
		}
	},
	
	fireRequest:function(pars,callback){
		var url = 'query.php';
//		alert(url + "?" +pars);

//		回调函数，利用js填充数据；
		var myAjax = new Ajax.Request(
			url,{
				method:'post',
				parameters:pars,
				onComplete:callback
				}
		);
	},
	fillData:function(data){
		try{
			var data = data.responseText;
			//tip( data);
			data = eval('('+data+')');
			
			data = sinamap.checkData(data);
			sinamap.result = data;
			sinamap.setPageInfo(data.total);
			
			$("map_result_content").innerHTML = "<ul class='search_list'>" + ADDATA.innerHTML.collect(function(s){
					return s;
				}).join('') + sinamap.renderText(data) + "</ul>";		//填充文字内容
			
			//$("map_result_content").innerHTML = "<ul class='search_list'>" + sinamap.renderText(data) + "</ul>";		//填充文字内容
			
			sinamap.resultHtml = $("map_result_content").innerHTML;
			sinamap.mapabc.removeAllPoints();
			sinamap.mapabc.removeAllOverlays();
			sinamap.points = [];
			sinamap.points = sinamap.drawPoints(data);
//			sinamap.points.push(ADDATA.points);
			if(ADDATA.points && ADDATA.points.length > 0){
				sinamap.mapabc.drawCustomPoints(ADDATA.points);		
			}
			
			if(sinamap.points.length > 0){
				sinamap.mapabc.drawCustomPoints(sinamap.points);		//在地图上画点
			}

			sinamap.changeView();			
		}catch(e){
			//Do Nothing
//			alert(e);
		}
	},
	fillRectSearchData:function(data){
		try{
			var data = data.responseText;
			data = eval('('+data+')');
	
			data = sinamap.checkData(data);
			sinamap.result = data;
			
			sinamap.setPageInfo(data.total,",'d'");
			$("map_result_content").innerHTML = "<ul class='search_list'>" + sinamap.renderText(data) + "</ul>";		//填充文字内容
			sinamap.resultHtml = $("map_result_content").innerHTML;
			sinamap.mapabc.removeAllPoints();
			sinamap.points = [];
			sinamap.points = sinamap.drawPoints(data);
			sinamap.mapabc.drawCustomPoints(sinamap.points);		//在地图上画点

			sinamap.changeView();			
		}catch(e){
			//Do Nothing
		}
	},
	fillCenterSearchData:function(data){
		try{
			var data = data.responseText;
			
			data = eval('('+data+')');
	
			data = sinamap.checkData(data);
			sinamap.result = data;
			
			sinamap.setPageInfo(data.total,",'c'");
			$("map_result_content").innerHTML = "<ul class='search_list'>" + sinamap.renderText(data) + "</ul>";		//填充文字内容
			sinamap.resultHtml = $("map_result_content").innerHTML;
			sinamap.mapabc.removeAllPoints();
			sinamap.points = [];
			sinamap.points = sinamap.drawPoints(data);
			sinamap.mapabc.drawCustomPoints(sinamap.points);		//在地图上画点

			sinamap.changeView();			
		}catch(e){
			//Do Nothing
		}
	},
	fillAdData:function(data){
		try{
			var data = data.responseText;
			data = eval('(' + data + ')');
			
			data = sinamap.checkData(data);
			var html = sinamap.renderText(data,'AD');
			var div = document.createElement('div');
			div.id = 'ad_tempcontainer';
			div.innerHTML = html;
			var lis = div.getElementsByTagName('li');
			var _i = 0;
						
			for (var i = 0 in lis) {
				if (typeof lis[i] != 'object') {
					_i--;
					continue;
				}
				_i++;
				if(Prototype.Browser.IE){
					var id = data.result[_i].fields.id;
					ADDATA.innerHTML.push("<li id='rst_r" + id + "' class='number' onclick=\"MapAbc.showPoint('" + id + "');\" onmouseover=\"cg_dc('rst_r" + id + "','tip_pic" + id + "','1');MapAbc.changeIconColor('" + id + "','ON');\" onmouseout=\"cg_dc('rst_r" + id + "','tip_pic" + id + "');MapAbc.changeIconColor('" + id + "','OFF');\">" + lis[i].innerHTML + '</li>');					
				}else{
					var id = data.result[i].fields.id;
					ADDATA.innerHTML.push("<li id='rst_r" + id + "' class='number' onclick=\"MapAbc.showPoint('" + id + "');\" onmouseover=\"cg_dc('rst_r" + id + "','tip_pic" + id + "','1');MapAbc.changeIconColor('" + id + "','ON');\" onmouseout=\"cg_dc('rst_r" + id + "','tip_pic" + id + "');MapAbc.changeIconColor('" + id + "','OFF');\">" + lis[i].innerHTML + '</li>');										
				}
			};
			ADDATA.points = [];
			ADDATA.points = sinamap.drawPoints(data,"AD");
			ADDATA.points.reverse();

			ADDATA.innerHTML.reverse();
		}catch(e){
//			alert(e);
		}
	},
	fillHistoryData:function(data){
		try {
			var data = data.responseText;
			data = eval('(' + data + ')');
			
			data = sinamap.checkData(data);
			var html = sinamap.renderText(data);
			var div = document.createElement('div');
			div.id = 'tempcontainer';
			div.innerHTML = html;
			var lis = div.getElementsByTagName('li');
			var _i = 0;
						
			for (var i = 0 in lis) {
				if (typeof lis[i] != 'object') {
					_i--;
					continue;
				}
				_i++;
				if(Prototype.Browser.IE){
					var id = data.result[_i].fields.id;
					History.innerHTML.push("<li id='rst_r" + id + "' class='number' onclick=\"MapAbc.showPoint('" + id + "');\" onmouseover=\"cg_dc('rst_r" + id + "','tip_pic" + id + "','1');MapAbc.changeIconColor('" + id + "','ON');\" onmouseout=\"cg_dc('rst_r" + id + "','tip_pic" + id + "');MapAbc.changeIconColor('" + id + "','OFF');\">" + lis[i].innerHTML + '</li>');					
				}else{
					var id = data.result[i].fields.id;
					History.innerHTML.push("<li id='rst_r" + id + "' class='number' onclick=\"MapAbc.showPoint('" + id + "');\" onmouseover=\"cg_dc('rst_r" + id + "','tip_pic" + id + "','1');MapAbc.changeIconColor('" + id + "','ON');\" onmouseout=\"cg_dc('rst_r" + id + "','tip_pic" + id + "');MapAbc.changeIconColor('" + id + "','OFF');\">" + lis[i].innerHTML + '</li>');										
				}
			};
			History.points = new Array();
			History.points = sinamap.drawPoints(data);
			
			History.points.reverse();
			History.innerHTML.reverse();
		}catch(e){
			//alert(e);
		}	
	},
	setPageInfo:function(total,type){		//设置分页信息
		total!=''?MapFilter.totalpage = Math.ceil(total/MapFilter.pagesize):'';
		if(isNull(type)){
			type = '';
		}
		
		if(!this.pagelink){
			this.pagelink = {};
			this.pagelink = document.createElement('p');
			this.pagelink.prevpage = document.createElement('a');
			this.pagelink.prevpage.innerHTML = '上一页';
			this.pagelink.prevpage.style.display = 'none';
			
			this.pagelink.nextpage = document.createElement('a');
			this.pagelink.nextpage.innerHTML = '下一页';
			this.pagelink.nextpage.href = "javascript:MapFilter.setPage(" + (MapFilter.currentpage + 1) + type + ");";
			this.pagelink.appendChild(this.pagelink.prevpage);
			this.pagelink.appendChild(this.pagelink.nextpage);
			
			this.pagelink.numlink = []
			for(var i=0;i<MapFilter.linknum;i++){
				var obj = document.createElement('a');
				obj.innerHTML = '[' + (i+1) + ']';
				obj.href = "javascript:MapFilter.setPage(" + (i+1) + type + ");";
				this.pagelink.numlink.push(obj);
				this.pagelink.appendChild(obj);
			}
			this.pagelink.numlink[0].className = 'on';

			this.pagelink.resultinfo = document.createElement('p');
			this.pagelink.resultinfo.innerHTML = '找到' + total + '条结果,共 ' + MapFilter.totalpage + ' 页';
			this.pagelink.appendChild(this.pagelink.resultinfo);
			
			$('map_result_bottom_house').appendChild(this.pagelink);
		}else{
			this.pagelink.removeChild(this.pagelink.resultinfo);
			this.pagelink.resultinfo = document.createElement('p');
			this.pagelink.resultinfo.innerHTML = '找到' + total + '条结果,共 ' + MapFilter.totalpage + ' 页';
			this.pagelink.appendChild(this.pagelink.resultinfo);

			if(MapFilter.currentpage > 1){
				this.pagelink.prevpage.style.display = '';
				this.pagelink.prevpage.href = "javascript:MapFilter.setPage(" + (MapFilter.currentpage - 1) + type + ");";
			}else{
				this.pagelink.prevpage.style.display = 'none';
			}
			if(MapFilter.currentpage == MapFilter.totalpage){
				this.pagelink.nextpage.style.display = 'none';
			}else{
				this.pagelink.nextpage.href = "javascript:MapFilter.setPage(" + (parseInt(MapFilter.currentpage) + parseInt(1)) + type + ");";
			}
			
			for(var i=0;i<this.pagelink.numlink.length;i++){
				this.pagelink.numlink[i].innerHTML = '[' + (MapFilter.currentpage+i-(MapFilter.linknum-1)/2) + ']';
				this.pagelink.numlink[i].href = "javascript:MapFilter.setPage(" + (MapFilter.currentpage+i-(MapFilter.linknum-1)/2) + type + ");";
				this.pagelink.numlink[i].className = '';
				this.pagelink.numlink[i].style.display = '';
				
				if((MapFilter.currentpage+i-(MapFilter.linknum-1)/2) > MapFilter.totalpage){
					this.pagelink.numlink[i].style.display = 'none';
				}else if((MapFilter.currentpage+i-(MapFilter.linknum-1)/2) <= 0){
					this.pagelink.numlink[i].style.display = 'none';
				}
				
				if((MapFilter.currentpage+i-(MapFilter.linknum-1)/2) == MapFilter.currentpage){
					this.pagelink.numlink[i].className = 'on';
				}
			}
		}	
	},
	checkData:function(data){
		if(data.total != '0'){
			for (var i = 0, len = data.result.length; i < len; i++) {
				var fields = data.result[i].fields;
				

				isNull(fields.communityname)?fields.communityname = "暂无":fields.communityname;
				fields.price =  (siteType=='zu' ?  fields.rentprice+' 元/月' : (fields.saleprice/10000)+' 万' );
				isNull(fields.buildingarea)?fields.buildingarea = "暂无":fields.buildingarea;
			
				isNull(fields.houseaddress)?fields.houseaddress = "暂无":fields.houseaddress;
			
				isNull(fields.updatetime)?fields.updatetime = "待定":fields.updatetime;
				//isNull(fields.type)?fields.type = "home":fields.type;
				
			}
		}
		
		return data;
	},
	drawPoints:function(data){
		var temppoints = []
		if(data.total != '0'){
			for(var i = 0,len = data.result.length;i<len;i++){
				var fields = data.result[i].fields;
				var label = i + 1;
				var houseurl = "index.php?type=h&id=" + fields.id + "&keyword=" + fields.communityname;
				var busurl = "index.php?type=hb&name=" + fields.communityname + "&x=" +fields.coordx + "&y=" + fields.coordy;
				var driveurl = "index.php?type=hd&name=" + fields.communityname + "&x=" +fields.coordx + "&y=" + fields.coordy;
				var content = '';
				content += "<font size='14'><b>" + fields.communityname + "</b></font><br/><br/>";
				
				if(getDetailLink(fields.id,this.conf.citycode) != false){
					content += "<a href=\"" + getDetailLink(fields.id,this.conf.citycode) + "\"  target='_blank'>详情页</a>&nbsp;&nbsp;";	
				}else{
					content += "<a href='" + this.conf.linkstr + "/house-" + fields.id + ".html' target='_blank'>详情页</a>&nbsp;&nbsp;"
				}
				//TODO 考虑隐藏某些对开发商不利的实景
				if(this.conf.shijing){
					content += "&nbsp;<a href=\"javascript:sinamap.shijingShow('"+fields.coordx+"','"+fields.coordy+"','"+fields.communityname.substr(0,12)+"');\">实景地图</a>&nbsp;&nbsp;";
				}
				content += "<br/>";
				if(siteType=='zu'){					
					content += "<b>租金</b>："+fields.price + "";
				}else{
					content += "<b>价格</b>："+fields.price + "";
				}
				content += "&nbsp;&nbsp;<b>户型</b>："+fields.model_room+'/'+fields.model_hall+'/'+fields.model_toilet + "<br/>";
				
				content += "<b>发布时间</b>："+fields.updatetime + "<br/>";
				//content += "<b>电话</b>："+fields.saleplace_phone.replace(/(.{14})/g,"$1\n") + "<br/>";
				content += "<b>地址</b>："+fields.houseaddress.replace(/(.{14})/g,"$1\n") + "<br/>";
//				content += "<a href=\"javascript:MapAbc.centerkeywordSearchDecorator('" + fields.id + "','"+ fields.communityname + "');\">周边查询</a>&nbsp;&nbsp;"
				content += "<a href=\"javascript:MapAbc.centerkeywordSearchDecorator('" + fields.id + "','" + fields.communityname + "');\">周边查询</a>&nbsp;&nbsp;"

				if(this.conf.bussearch && this.conf.bussearch == 'false'){
				}else{
					content += "<a href=\"javascript:MapAbc.busSearchProxy('"+fields.communityname+"','"+fields.coordx+"','"+fields.coordy+"','"+fields.id+"','end')\" >公交查询</a>&nbsp;&nbsp;"
				}

//				content += "<a href='" + encodeURI(driveurl) + "' >驾车查询</a>&nbsp;&nbsp;"
				content += "<a href=\"javascript:MapAbc.driveSearchProxy('"+fields.communityname+"','"+fields.coordx+"','"+fields.coordy+"','"+fields.id+"','end')\" >驾车查询</a>&nbsp;&nbsp;"
				content += "<br />[快速定位]&nbsp;&nbsp;<a href=\"javascript:MapAbc.zoom('"+fields.coordy+"','"+fields.coordx+"',7)\">省</a>&nbsp;&nbsp;<a href=\"javascript:MapAbc.zoom('"+fields.coordy+"','"+fields.coordx+"',10)\">城市</a>&nbsp;&nbsp;<a href=\"javascript:MapAbc.zoom('"+fields.coordy+"','"+fields.coordx+"',14)\">县区</a>&nbsp;&nbsp;<a href=\"javascript:MapAbc.zoom('"+fields.coordy+"','"+fields.coordx+"',16)\">街道</a>";
				
				//图片地址
				if(!isNull(fields.picurl)){
					//广州站数据中存在链接形式的图片地址，做判断
					if((fields.picurl).indexOf("<img") != -1){
						var _src = fields.picurl;
						_src = _src.split("src=")[1];
						_src = _src.split("style")[0];
						content += "<img src='" + _src + "' width='120' height='100' />";	
					}else{
						content += "<img src='http://buyhome.house.sina.com.cn/ndata/" + fields.picurl + "' width='120' height='100' />";							
					}
				}
				content += "<br/>";
				
				var imgurl = '';
				if (!isNull(fields.price_tehui)) {
					imgurl = "http://map.house.sina.com.cn/images/promote.png";
				}
				else 
				{
					if (!isNull(fields.price_zhekou) || fields.zhekou_flag == "1") 
					{
						imgurl = "http://map.house.sina.com.cn/images/discount.png";
					}
					else {
						if(getAdLogo(fields.id,this.conf.citycode) != false){
							imgurl = getAdLogo(fields.id,this.conf.citycode);
						}else{
							if(!isNull(arguments[1])){
								imgurl = "http://map.house.sina.com.cn/images/promote.png";
							}else{
								imgurl = 'http://map.house.sina.com.cn/images/' + (i+1) + '.gif';
							}
						}
					}
				}
				
				if(getAdLogo(fields.id,this.conf.citycode) != false){
							imgurl = getAdLogo(fields.id,this.conf.citycode);
				}else{
					if(!isNull(arguments[1])){
						imgurl = "http://map.house.sina.com.cn/images/promote.png";
					}else{
						imgurl = 'http://map.house.sina.com.cn/images/' + (i+1) + '.gif';
					}
				}
				
				if(!isNull(fields.coordx) && !isNull(fields.coordy)){
					temppoints.push(this.mapabc.createCustomPoint(fields.coordx+','+fields.coordy,imgurl,content,fields.id));
				}
			}
			return temppoints;
		}
	},
	
	renderText:function(data){
		var result = '';
		
		if(data.total == "0"){
			return result = "<br /><p style='text-align:left;padding:0px 10px;'>对不起，暂未发现该区域内存在选定类别的房源，请切换至其他位置重新尝试，谢谢。</p>";
		}else{
			var html = '';
			for(var i = 0,len = data.result.length;i<len;i++){
				var fields = data.result[i].fields;
				var strLi = "";	
				
				strLi += "<li  id=\"rst_r"+(i+1)+"\"";		
				
				
				if(isNull(fields.coordy) || isNull(fields.coordx)) {
					strLi += "onclick=\"showNoPointTip()\"";
				}else{
					strLi += "onclick=\"MapAbc.showPoint('"+fields.id+"');History.addHistoryItem('" + fields.id + "',this);\" onmouseover=\"cg_dc('rst_r"+(i+1)+"','tip_pic"+(i+1)+"','1');MapAbc.changeIconColor('"+fields.id+"','ON');\" onmouseout=\"cg_dc('rst_r"+(i+1)+"','tip_pic"+(i+1)+"');MapAbc.changeIconColor('"+fields.id+"','OFF');\"";
				}
				strLi += "\"><div class=\"s_left\">";
				strLi += "<h3 id=\"tip_pic"+(i+1)+"\" ";
				
				if(!isNull(fields.coordy) && !isNull(fields.coordx)){
					strLi += "class=\"number2\"";
				}
				
				if(!isNull(arguments[1])){
					strLi += ">荐</h3>";
				}else{
					strLi += ">"+(i+1)+"</h3>";
				}
				
				strLi += "<input type=\"checkbox\" name=\"result_"+i+"\" value=\""+fields.id+"\" onclick=\"HouseCompare.addToCompareList('"+fields.id+"',this);\" /><label>对比</label></div>";
				strLi += "<div class=\"s_right\"><h4><a name='searchResult' href=\"javascript:void(0);\">"+fields.communityname.substr(0,12)+"</a></h4><p>";
				strLi += "面积：<span title='" + fields.buildingarea + "'>"+fields.buildingarea + " m<sup>2</sup></span>";	
				strLi += "&nbsp;&nbsp;户型："+fields.model_room+'/'+fields.model_hall+'/'+fields.model_toilet + "<br/>";
				if(siteType=='zu'){
					strLi += "租金：<span title='" + fields.price + "'>"+fields.price + "</span><br />";
				}else{
					strLi += "价格：<span title='" + fields.price + "'>"+fields.price + "</span><br/>";
				}
				//alert(strLi);
				if(this.conf.shijing && this.shijingcheck(fields.id) && !isNull(fields.coordx) && !isNull(fields.coordy)){
					var shijinglink = "&nbsp;<a href=\"javascript:sinamap.shijingShow('"+fields.coordx+"','"+fields.coordy+"','"+fields.communityname.substr(0,12)+"');\">实景地图</a>&nbsp;&nbsp;";
				}else{
					var shijinglink = "";
				}
				
				//详情页链接
				var detailLink = "";
				if(getDetailLink(fields.id,this.conf.citycode) != false){
					detailLink = "<a href=\"" + getDetailLink(fields.id,this.conf.citycode) + "\"  target='_blank'>详情页</a>";	
				}else{
					if(fields.tehui_url != null && fields.tehui_url != ""){
						detailLink = "<a href=\"" + fields.tehui_url + "\"  target='_blank'>详情页</a>";						
					}else{
						detailLink = "<a href=\"" + this.conf.linkstr + "/house-" + fields.id + ".html\"  target='_blank'>详情页</a>";						
					}
				}

				strLi += "<span class=\"linkRed3\">" + detailLink + "&nbsp;" + shijinglink + "<a href='javascript:void(0);'>定位</a></span>";
				strLi += "<br />地址：<span title="+fields.houseaddress+">"+fields.houseaddress.substr(0,10)+"</span>";
				strLi += "</div><div class=\"clear\"></div></li>";
				html += strLi;				
			}
			return result = html;
		}
	},
	shijingcheck:function(id){
		try{
			for(var i=0,len=this.conf.hidehouse.length;i<len;i++){
				if(this.conf.hidehouse[i] == id){
					return false;
				}				
			}
			
			return true;
		}catch(e){
			return true;
		}
	},
	shijingShow:function(x,y,name){
		HideAllSelect();
		
		if (!this.shijing) {
			this.shijingInit();
			this.shijing.player.addEventListener("onFlashInited",this.shijingShow(x,y,name));//注册播放器初始化完成的事件
		}else{
			try{
				$('shijingcontainer').show();
				$('shijingname').innerHTML = name;
				
				this.shijing.player.setDomainValue(this.conf.domain,this.conf.ajaxDomain,this.conf.panoLibDomain);
				this.shijing.player.flashProxy.callFlashAPI("showPanobyTheodolite",  x, y, "MapABC",this.conf.citycode);			
			}catch(e){
				setTimeout("sinamap.shijingShow('" + x + "','" + y + "','" + name + "')",1000)
			}
		}
	},
	shijingInit:function(){
		this.shijing = {};
		
		this.shijing.container = document.createElement('div');
		this.shijing.container.className = 'TopLayer';
		this.shijing.container.id = 'shijingcontainer';
		this.shijing.container.style.height = getScreenSize()[1];
		
		this.shijing.shijingplayer = document.createElement('div');
		this.shijing.shijingplayer.className = 'shijingplayer';
		this.shijing.shijingplayer.id = 'shijingPlayer';
		this.shijing.container.appendChild(this.shijing.shijingplayer);
		
		this.shijing.shijinginfo = document.createElement('div');
		this.shijing.shijinginfo.className = 'shijinginfo';
		this.shijing.shijinginfo.innerHTML = "<div class='closewrapper'><span class='close' onclick='Element.up(this).up(0).up(0).hide();ShowAllSelect();'><b style='color:red;'>X</b>&nbsp;关闭</span></div>";
		this.shijing.shijinginfo.innerHTML += "<p class='shijinginfo_title'>实景位置：<span id='shijingname'></span></p>";
		this.shijing.shijinginfo.innerHTML += "<p class='shijinginfo_tip'><span>实景数据较大，请耐心等待或</span>&nbsp;&nbsp;<a href=''>返回楼盘地图</a></p>";
		
		this.shijing.container.appendChild(this.shijing.shijinginfo);
		document.body.appendChild(this.shijing.container);

		var opt = new Object();
		opt.showPano = true;
		opt.showMap = false;
		var playerOptions = new PanoOption();
		playerOptions.domain = this.conf.domain;
		playerOptions.ajaxDomain = this.conf.ajaxDomain;
		playerOptions.panoLibDomain = this.conf.panoLibDomain;
		playerOptions.cityCode = this.conf.citycode;
		playerOptions.panoID = this.conf.panoID;
		opt.playerOption = playerOptions;
		opt.mapCxx = this.conf.x;
		opt.mapCyy = this.conf.y;
		this.shijing = new C8PlayerMap("shijingPlayer", "map_flashmap", opt);
	},
	printMap:function(){
		if(!this.staticmap){
			this.staticmap = {};
			
			this.staticmap.container = document.createElement('div');
			this.staticmap.container.className = 'staticmapTopLayer';
			this.staticmap.container.id = 'staticmapcontainer';
			this.staticmap.container.style.height = getScreenSize()[1];
			this.staticmap.container.style.width = getScreenSize()[0];
			
			this.staticmap.ifr = document.createElement('iframe');
			this.staticmap.ifr.className = 'staticmap';
			this.staticmap.ifr.scrolling = 'no';
			this.staticmap.ifr.style.backgroundColor = '#666';
			this.staticmap.ifr.id = 'staticmapiframe';
			this.staticmap.ifr.src = 'printmap.php';
			
			this.staticmap.container.appendChild(this.staticmap.ifr);
			document.body.appendChild(this.staticmap.container);
		}
		this.staticmap.ifr.src = 'printmap.php';
		this.staticmap.container.style.display = '';

		this.staticmap.cord = this.mapabc.getCenterCord();
		this.staticmap.zoomlevel = this.mapabc.getZoomLevel();

		HideAllSelect();
	},
	closePrintMap:function(){
		this.staticmap.container.style.display = 'none';
		ShowAllSelect();
	},
	
	switchResultAndHistory:function(type){
		if(type == this.tabstatus){
			return;
		}
		
		switch(type){
			case "history":
				//切换页面元素
				$("sh_nav_11").className = 'tt3_active';
				$("sh_nav_10").className = 'tt3_normal';
				$('map_result_content').innerHTML = "<ul class='search_list'>" + History.innerHTML.collect(function(s){
					return s;
				}).join('') + "</ul>";
				if(this.pagelink){
					Element.hide(this.pagelink);
				}
				Element.hide('map_order_selector');
				Element.hide('map_resultnum_select');
				Element.hide('map_resultnum_select');
				$('map_result_top').style.height = '27px';
				this.RESULTHEIGHT = '72';
				this.autoResize();
				
				//标注历史记录点
				this.mapabc.removeAllPoints();
				if(History.points && History.points.length > 0){
					this.mapabc.drawCustomPoints(History.points);
				}
				
				this.tabstatus = "history";
				break;
			case "result":
				//切换页面元素
				$("sh_nav_10").className = 'tt3_active';
				$("sh_nav_11").className = 'tt3_normal';
				$('map_result_content').innerHTML = this.resultHtml;
				if(this.pagelink){
					this.pagelink.show();
				}
				$('map_order_selector').show();
				$('map_resultnum_select').show();
				$('map_result_top').style.height = '45px';
				this.RESULTHEIGHT = '90';
				this.autoResize();
				
				//标注结果点
				this.mapabc.removeAllPoints();
				if(ADDATA.points && ADDATA.points.length){
					this.mapabc.drawCustomPoints(ADDATA.points);		
				}
				
				if(this.points && this.points.length > 0){
					this.mapabc.drawCustomPoints(this.points);
				}

				this.tabstatus = "result";
				break;
		};
	},
	//浏览器关闭时，写入用户历史记录
	writeCookie:function(){
		try {
			setCookie('BrowseHistory_'+this.conf.citycode, History.list, 30);
		}catch(e){
			//没有Cookie
		}
	},
	//加载该站的广告信息
	loadAdInfo:function(){
		try{
			var q = "";
			for(var i=0,len = ad_customers.length; i<len; i++){
				if(ad_customers[i].citycode == this.conf.citycode && ad_customers[i].top == 'true'){
					q += 'id:' + ad_customers[i].id + ' OR ';
				}
				
				if( this.conf.citycode == ad_customers[i].citycode && (ad_customers[i].type == "hotlink" || ad_customers[i].type == "vip")){
				//加载热门链接
//					var l = new Element('li',{"style":"padding-right:5px"}).update(
//						new Element('a',{'href':"javascript:MapFilter.setOutCondition('communityname','" + ad_customers[i].name + "');"}).update(ad_customers[i].name)
//					);
//					$('hothouse').appendChild(l);
				}
			}
			q += " id:000";
			q = "q=" + q;				
			
			setTimeout("sinamap.fireRequest('"+q+"',sinamap.fillAdData);",1000);
		}catch(e){
			alert(e);
		}
	},
	//浏览器打开时加载浏览记录
	loadBrowseHistory:function(){
		try{
			var history = getCookie('BrowseHistory_'+this.conf.citycode);
			var history = history.split(",");
			var q = '';
			
			History.list = history;
			
			if(history.length > 1){
				for(var i=0,len=history.length;i<len;i++){
					q += 'id:' + history[i] + ' OR ';
				}
				q += " id:000";
				q = "q=" + q;
				
				
	//			alert(q);
				setTimeout("sinamap.fireRequest('"+q+"',sinamap.fillHistoryData);",2000);
			}
		}catch(e){
//			alert('No Cookie Stored');
		}
	},
	defaultValueCheck:function(obj){
		if(this.conf.defaultValue[obj.id].text != obj.value){
			return obj.value;
		}else{
			return this.conf.defaultValue[obj.id].value;
		}
	},
	createBusPlaceList:function(){
		var obj = null;
		
		function getObj(){
			var obj = document.createElement('div');
			obj.id = 'bus_place_list';
			obj.className = 'search_list_drive';
			
			var html = '';
			html += "<div id=\"bus_place_list\" class=\"search_list_drive\" style=\"display:;\">";
			html += 	"<h3>选择起点：用鼠标设置起点</h3>";
			html +=		"<div id=\"bs_content\" class=\"drive_list\">";
			html +=		"</div>";
			html +=		"<h3 class=\"ico_red\">选择终点：用鼠标设置终点</h3>";
			html +=		"<div id=\"be_content\" class=\"drive_list\">";
			html +=		"</div><br />";
			html +=		"<input id=\"busquery\" type=\"button\" onclick=\"MapAbc.triggerBusSearch();\" class=\"btn_balance\" value=\"查询\" />&nbsp;&nbsp;";
//			html +=		"<input id=\"busback\" type=\"button\" onclick=\"javascript:void(0);\" class=\"btn_balance\" value=\"返回\" />";
			
			obj.innerHTML = html;
			
			return obj;
		};
		
		return {
			getInstance:function(){
				if(obj == null){
					return obj = getObj();
				}else{
					return obj;
				}
			}
		}
	},
	createDrivePlaceList:function(){
		var obj = null;
		
		function getObj(){
			var obj = document.createElement('div');
			obj.id = 'drive_place_list';
			obj.className = 'search_list_drive';
			
			var html = '';
			html += "<div id=\"drive_place_list\" class=\"search_list_drive\" style=\"display:;\">";
			html += 	"<h3>选择起点：用鼠标设置起点</h3>";
			html +=		"<div id=\"bs_content\" class=\"drive_list\">";
			html +=		"</div>";
			html +=		"<h3 class=\"ico_red\">选择终点：用鼠标设置终点</h3>";
			html +=		"<div id=\"be_content\" class=\"drive_list\">";
			html +=		"</div><br />";
			html +=		"<input id=\"busquery\" type=\"button\" onclick=\"MapAbc.triggerDriveSearch();\" class=\"btn_balance\" value=\"查询\" />&nbsp;&nbsp;";
//			html +=		"<input id=\"busback\" type=\"button\" onclick=\"javascript:void(0);\" class=\"btn_balance\" value=\"返回\" />";
			
			obj.innerHTML = html;
			
			return obj;
		};
		
		return {
			getInstance:function(){
				if(obj == null){
					return obj = getObj();
				}else{
					return obj;
				}
			}
		}
	}
}


