/**
 * @author Cocowool,shiqiang@staff.sina.com.cn
 * 2008/12/22,添加对比类
 */

var baseUrl,cityUrl,siteType;
var url=location.href.toLowerCase();	
var arr=url.split("/");
baseUrl= "http://"+arr[2];
cityUrl= baseUrl+'/'+arr[3];

domain=document.domain.split(".");
siteCity = domain[0];
 
siteType=GetQueryString('type');
siteType= siteType==1 ? 'zu' : 'mai';


 function tip(tip){
	 $('nowTip').innerHTML+='<br/>'+tip;
 }

function GetQueryString( sProp ) {
	var re = new RegExp( sProp + "=([^\\&]*)", "i" );
	var a = re.exec( document.location.search );
	if ( a == null )
		return "";
	return a[1];          
};  


function regpub(isagent){//siteCity
	if(isagent){
		window.open('http://agent.fangyou.com/register','_blank');	
	}else{
		window.open('../register.php','_blank');			
	}
}



//获取大小，用于页面自适应
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 sina_obj_show(obj){
	if(!obj)return ;
	var elems = document.getElementsByTagName("div");   
	for( var cls, i = 0; ( elem = elems[i] ); i++ ){   
		if( elem.className == 'sider_nav_sub' ){
			if (elem.parentNode.id==obj.id){
				elem.style.display="block";
			}else {
				elem.style.display="none";
			}
		}   
	}
}

//下级隐藏所有,显示当前
function sina_sub_show(obj){
	var elems = document.getElementsByTagName("div");   
	for( var i = 0; ( elem = elems[i] ); i++ ){   
		if(elem.className == 'select_list_1' && elem !== obj.parentNode )elem.className = 'select_list_0';
	}
	
	if(obj.parentNode.className == 'select_list_1'){
		obj.parentNode.className = 'select_list_0';
	} else{
		obj.parentNode.className = 'select_list_1';
	}
}	

//显示隐藏层
function showhidendiv(id)
{
	var divobj = $(id);
	if (divobj.style.display == "none")
	{
		$(id).show();
		return true;
	}
	else
	{
		$(id).hide();;
		return false;
	}
}

//控制头部舌签的变化
function changeTabPanel(id,obj)
{
	$("topSearchHouse").style.display = "none";
	$("topSearchAround").style.display = "none";
	$("topSearchBus").style.display = "none";
	$("topSearchBusStation").style.display = "none";
	$("topSearchBusline").style.display = "none";
	$("topSearchDrive").style.display = "none";

	$(id).style.display = "";
	if(id.indexOf('topSearchBus') != -1){
		$('busswitchradio').show();
	}else{
		$('busswitchradio').hide();
	}

	$("searchTabHouse").className = "tt5_normal";
	$("searchTabAround").className = "tt5_normal";
	$("searchTabBus").className = "tt5_normal";
	$("searchTabDrive").className = "tt5_normal";

	obj.className = "tt5_active";
	
//	sinamap.changeView(id);
}

//判断字符串是否为null或者为undefined
function isNull(str){
	if(str == null || str == "null" || str == "undefined" || str == ""){
		return true;
	}else{
		return false;
	}
}

//切换效果(分块1，分块2，是否高亮)
function cg_dc(dn1, dn2, light)
{
	try{
		var dv1 = document.getElementById(dn1);
		var dv2 = document.getElementById(dn2);
		if (light)
		{
			dv1.className = "light";
			dv2.className = "number";
		}
		else
		{
			dv1.className = "";
			dv2.className = "number2";
		}
	}catch(e){
	}
}

function HideAllSelect(){
	$('map_order_selector').hide();
}

function ShowAllSelect(){
	$('map_order_selector').show();
}


//程序代理	
function functionProxy(str){
	eval(str);
}

/*
 * 创建用户浏览历史对象
 * 用来存储用户浏览历史数据
 * 
 */

 var History = {
 	list:[],
 	points:[],
	innerHTML:[],
	addHistoryItem:function(hid,obj){
		this.innerHTML.reverse();
		if(this.points) this.points.reverse();
		this.list.reverse();
		
		for(var i=0,len=sinamap.points.length;i<len;i++){
			if(hid == sinamap.points[i].id && this.list.indexOf(hid) == '-1'){
				this.list.push(hid);
				var temppoint = sinamap.points[i];
				temppoint.imgURL = 'http://map.house.sina.com.cn/images/' + this.list.size() + '.gif';
				temppoint.style.imgURL = 'http://map.house.sina.com.cn/images/' + this.list.size() + '.gif';
				if(!this.points) this.points=[];
				this.points.push(temppoint);
				
				var hid = temppoint.id;
				this.innerHTML.push("<li id='rst_r"+hid+"' class='number' onclick=\"MapAbc.showPoint("+hid+");\" onmouseover=\"cg_dc('rst_r"+hid+"','tip_pic"+hid+"','1');MapAbc.changeIconColor('"+hid+"','ON');\" onmouseout=\"cg_dc('rst_r"+hid+"','tip_pic"+hid+"');MapAbc.changeIconColor('"+hid+"','OFF');\" >"+obj.innerHTML.sub('number','number2').gsub(/\>[0-9]{1,2}</,'>'+this.list.size()+'<')+'</li>');
			}
		}
		
		if(this.points && this.points.length >= 11){
			this.points.shift();
			this.innerHTML.shift();
			this.list.shift();
			
			for(var j=0,len=this.list.length;j<len;j++){
				this.points[j].imgURL = 'http://map.house.sina.com.cn/images/' + (j+1) + '.gif';
				this.points[j].style.imgURL = 'http://map.house.sina.com.cn/images/' + (j+1) + '.gif';
				this.innerHTML[j] = this.innerHTML[j].gsub(/\>[0-9]{1,2}</,'>'+(j+1)+'<');
			}
		}


		this.innerHTML.reverse();
		if(this.points)this.points.reverse();
		this.list.reverse();
	}
 }

/* get, set, and delete cookies */
function getCookie( 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 setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.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";
}

/*
 * 在input上绑定事件
 * 
 */
function bindEvent(id,obj){
	Event.observe(id,'focus',function(){
		if(obj.value == sinamap.conf.defaultValue[id].text){
			obj.value = '';
		}
	});
			
	Event.observe(id,'blur',function(){
		if(obj.value == ''){
			obj.value = sinamap.conf.defaultValue[id].text;
		}
	});
}

function changePageSize(type){
	
	switch(type){
		case "d":
			$('map_resultnum_select').innerHTML = "<a href=\"javascript:MapFilter.setPageSize(20,'d');\" title='每页显示20条结果'>20条记录</a>&nbsp;&nbsp;<a href=\"javascript:MapFilter.setPageSize(35,'d');\" title='每页显示35条结果'>35条记录</a>&nbsp;&nbsp;<a href=\"javascript:MapFilter.setPageSize(50,'d');\" title='每页显示50条结果'>50条记录</a>";
			break;
		case "c":
			$('map_resultnum_select').innerHTML = "<a href=\"javascript:MapFilter.setPageSize(20,'c');\" title='每页显示20条结果'>20条记录</a>&nbsp;&nbsp;<a href=\"javascript:MapFilter.setPageSize(35,'c');\" title='每页显示35条结果'>35条记录</a>&nbsp;&nbsp;<a href=\"javascript:MapFilter.setPageSize(50,'c');\" title='每页显示50条结果'>50条记录</a>";
			break;
		case "e":
		default:
			$('map_resultnum_select').innerHTML = "每页记录：<a href=\"javascript:MapFilter.setPageSize(20);\" title='每页显示20条结果'>20条</a>&nbsp;&nbsp;<a href=\"javascript:MapFilter.setPageSize(35);\" title='每页显示35条结果'>35条</a>&nbsp;&nbsp;<a href=\"javascript:MapFilter.setPageSize(50);\" title='每页显示50条结果'>50条</a>";
			break;
	}
}

/*
 * 得到格式化后的行驶里程
 */
function getdistance(le){
	if(le<=1000){
		var s = le;
		return s+"米";
	}else{
		var s = Math.round(le/1000);
		return ""+s+"公里";
	}
}

//切换效果2(分块1，分块2，是否高亮)
function cg_show(ds1,bgcolor)
{
	var dv = document.getElementById(ds1);
	if(dv.className != "search_traffic3"){
		if (bgcolor)
		{
			dv.className = "search_traffic";

		}
		else
		{
			dv.className = "search_traffic2";
		}
	}
}

//设定单击后列表的样式
function set_bsl_style(listid,listlength)
{
	for(var i = 1;i <= listlength; i++)
	{
		$("busline_"+i).className = "search_traffic2";
	}
	$("busline_"+listid).className = "search_traffic3";
}

//下级隐藏所有,显示当前(公交查询)
function sina_traffic_show(obj){
	var elems = document.getElementsByTagName("div");   
	for( var i = 0; ( elem = elems[i] ); i++ ){   
		if(elem == obj.parentNode ){
			if(elem.className == 'search_traffic_end'){
				elem.className = 'search_traffic_end_on';
			}else{
				elem.className = 'search_traffic_end';
			}
		}else{
			if(elem.className == 'search_traffic_end_on' )elem.className = 'search_traffic_end';
		}
	} 
}	


/*
 * 切换公交换乘的起始点
 */
function switchbusstartend(d)
{
	var temp;
	var tempName,tempX,tempY,tempAddress,tempTel,tempPID;

	switch(d){
		case "start":
			$("bus_start_on").style.display = "";
			$("bus_end_on").style.display = "none";	
			direction = "start";
			statusBusStartEnd = "start";
			break;
		case "end":
			$("bus_start_on").style.display = "none";
			$("bus_end_on").style.display = "";
			direction = "end";
			statusBusStartEnd = "end";
			break;
	}

	temp = $("_rightbusstart").disabled;
	$("_rightbusstart").disabled = $("_rightbusend").disabled;
	$("_rightbusend").disabled = temp;

	temp = $("_rightbusstart").value;
	$("_rightbusstart").value = $("_rightbusend").value;
	$("_rightbusend").value = temp;

	temp = $("bus_startpoint").value;
	$("bus_startpoint").value = $("bus_endpoint").value;
	$("bus_endpoint").value = temp;

	tempName = MapAbc.bus.start; MapAbc.bus.start = MapAbc.bus.end;	MapAbc.bus.end = tempName;
	tempName = MapAbc.bus.startpointname; MapAbc.bus.startpointname = MapAbc.bus.endpointname;	MapAbc.bus.endpointname = tempName;
	tempX = MapAbc.bus.startx; MapAbc.bus.startx = MapAbc.bus.endx; MapAbc.bus.endx = MapAbc.bus.tempX;
	tempY = MapAbc.bus.starty; MapAbc.bus.starty = MapAbc.bus.endy; MapAbc.bus.endy = MapAbc.bus.tempY;
	tempAddress = MapAbc.bus.startaddress; MapAbc.bus.startaddress = MapAbc.bus.endaddress; MapAbc.bus.endaddress = tempAddress;
	tempTel = MapAbc.bus.starttel; MapAbc.bus.starttel = MapAbc.bus.endtel; MapAbc.bus.endtel = tempTel;
	tempPID = MapAbc.bus.startpid; MapAbc.bus.startpid = MapAbc.bus.endpid; MapAbc.bus.endpid = tempPID;
	temp = MapAbc.bus.startstatus; MapAbc.bus.startstatus = MapAbc.bus.endstatus; MapAbc.bus.endstatus = temp;
}

/*
 * 切换公交换乘的起始点
 */
function switchdrivestartend(d)
{
	var temp;
	var tempName,tempX,tempY,tempAddress,tempTel,tempPID;

	switch(d){
		case "start":
			$("bus_start_on").style.display = "";
			$("bus_end_on").style.display = "none";	
			direction = "start";
			statusBusStartEnd = "start";
			break;
		case "end":
			$("bus_start_on").style.display = "none";
			$("bus_end_on").style.display = "";
			direction = "end";
			statusBusStartEnd = "end";
			break;
	}

	temp = $("_rightbusstart").disabled;
	$("_rightbusstart").disabled = $("_rightbusend").disabled;
	$("_rightbusend").disabled = temp;

	temp = $("_rightbusstart").value;
	$("_rightbusstart").value = $("_rightbusend").value;
	$("_rightbusend").value = temp;

	temp = $("drive_startpoint").value;
	$("drive_startpoint").value = $("drive_endpoint").value;
	$("drive_endpoint").value = temp;

	tempName = MapAbc.drive.start; MapAbc.drive.start = MapAbc.drive.end;	MapAbc.drive.end = tempName;
	tempName = MapAbc.drive.startpointname; MapAbc.drive.startpointname = MapAbc.drive.endpointname;	MapAbc.drive.endpointname = tempName;
	tempX = MapAbc.drive.startx; MapAbc.drive.startx = MapAbc.drive.endx; MapAbc.drive.endx = MapAbc.drive.tempX;
	tempY = MapAbc.drive.starty; MapAbc.drive.starty = MapAbc.drive.endy; MapAbc.drive.endy = MapAbc.drive.tempY;
	tempAddress = MapAbc.drive.startaddress; MapAbc.drive.startaddress = MapAbc.drive.endaddress; MapAbc.drive.endaddress = tempAddress;
	tempTel = MapAbc.drive.starttel; MapAbc.drive.starttel = MapAbc.drive.endtel; MapAbc.drive.endtel = tempTel;
	tempPID = MapAbc.drive.startpid; MapAbc.drive.startpid = MapAbc.drive.endpid; MapAbc.drive.endpid = tempPID;
	temp = MapAbc.drive.startstatus; MapAbc.drive.startstatus = MapAbc.drive.endstatus; MapAbc.drive.endstatus = temp;
}
/*
 * 处理对比页面的导向
 *
 */
var HouseCompare = {
	hid:[],
	addToCompareList:function(hid,obj){
		try{
			if(obj.checked){
				if(this.hid.length >= 4){
					alert("抱歉，您最多选择四个楼盘进行比较");
					obj.checked = false;
				}else{
					this.hid.push(hid);			
				}
			}else if(!obj.checked){
				this.hid.remove(hid);
			}
		}catch(e){
		
		}
	},
	openCompare:function(){
		if(this.hid.length > 1){
			var str = '';

			str += sinamap.conf.linkstr + "/compare.php?act=cmp&seq=";
			for(var i=0,len=this.hid.length;i<len;i++){
				str += this.hid[i] + ",";
			}
			window.open(str);
		}else{
			alert("请选中两个或者两个以上楼盘进行比较");
		}
	}
}

Array.prototype.remove = function(obj){
    for(var i=0; i < this.length ; ++i ){
        if ( this[i] == obj ){
            this.splice(i, 1); 
            break;
        }
    }
};

/**
 * 实现纠错功能，点击后建立纠错界面，使用singlton模式
 * 
 */

 var SendMessage = (function(){
 	var uniqueInstance;
	
	function CreateInterface(){
		var obj;
		
		function getObj(){
			var obj = document.createElement('div');
			obj.id = "sendmessage";
			obj.className = "sendmessage";
			
			var div = document.createElement('div');
			obj.appendChild(div);
			
			var html = "";
			html += "<form id='messageform' name='messageform' onsubmit='return SendMessage.getInstance().checkForm();' target='_blank' action='../api/sendmessage.php' method='post'>";
			html += "<p class='messagetitle'><a href='javascript:SendMessage.getInstance().hide();'>关闭</a></p>";
			html += "<div class='messagecontent'>";
			html += "<p>如果您想向我们提出意见或建议，请填写具体内容</p>";
			html += "<p><textarea id='messagecontent' name='messagecontent' style='width:450px;height:200px;'></textarea></p>";
			html += "<p><span>姓名：</span><input id='username' name='username' type='text' /></p>";
			html += "<p><span>电话：</span><input id='usertel' name='usertel' type='text' /></p>";
			html += "<p><span>邮箱：</span><input id='email' name='email' type='text' /><span style='color:red;'>*</span></p>";
			html += "<p><input type='submit' id='submit' name='submit' value='发送' />&nbsp;&nbsp;<input type='reset' id='reset' value='重置' name='reset' /></p>";
			html += "</div></form>";
			
			div.innerHTML = html;
			
			var hackdiv = document.createElement('div');
			hackdiv.className = "hackbox";
			obj.appendChild(hackdiv);
			
			document.body.appendChild(obj);

			return obj;								
		};
		
		return {
			hide:function(){
				if(!obj){
					obj = getObj();
				}
				
				obj.style.display = 'none';	
			},
			show:function(){
				if(!obj){
					obj = getObj();
				}
				
				obj.style.display = 'block';					
			},
			checkForm:function(){
				if(!obj){
					return false;
				}
				
				try{
					if($("email").value != ""){
						if($("email").value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)){
							this.hide();
							return true;
						}else{
							alert("请填写合法的邮箱地址!");
							return false
						}
					}else{
						alert("请填写邮箱地址!");
						return false;
					}
				}catch(e){
					alert(e);
				}				
			}
		};
	};
	
	return {
		getInstance:function(){
			if(!uniqueInstance){
				uniqueInstance = CreateInterface();		
			}
			return uniqueInstance;
		}
	}
 })();
 
 //改变选择条目的样式
 function set_s_style(listid,listlength,search_type){
	try{
		for (var i = 0; i < listlength; i++) {
			$(""+search_type+"_"+i).className="";
		}
		$(listid).className="subSelect";
	}catch(e){
		return true;
	}
}

/**
 * @abstract 存储广告数据
 */
 var ADDATA = {
 	list: [],
 	points: [],
 	innerHTML: []
 }
 
var ad_customers = [
//	Sample 
//	{
//		"type":"",			//广告类型,search:默认搜索,hotlink:热门链接,top:竞价排名前三,vip:vip客户图标
//		"hid":"2627",
//		"name":"公园1872",		//3.13 10:00下线
//		"citycode":"010",
//		"link":"http://sina.allyes.com/main/adfclick?db=sina&bid=150638,189595,194583&cid=0,0,0&sid=182316&advid=1832&camid=26112&show=ignore&url=http://ad.foloda.com/08dy/gy1872/",
//		"img":"http://map.house.sina.com.cn/images/adimages/huarun.png",	//是否使用自定义图标
//		"top":'false'	//是否显示在结果前三名
//	},

	{
		"type":"top",
		"hid":"3697",			//3.27下线
		"name":"新时代富嘉花园",
		"citycode":"021",
		"link":"",
		"img":"",
		"top":'true'
	}
//	{
//		"type":"search",
//		"hid":"3130",			//4.1-4.3 4.20-4.24 4.27-4.30下线
//		"name":"亦庄北岸",
//		"citycode":"010",
//		"link":"http://sina.allyes.com/main/adfclick?db=sina&bid=152570,192077,197068&cid=0,0,0&sid=184844&advid=5635&camid=26203&show=ignore&url=http://www.cityhouse365.com/kehu/yizhuangbeian.htm",
//		"img":"",
//		"top":'false'
//	}
//	{
//		"type":"hotlink",
//		"hid":"3486",			//4.1下线
//		"name":"融科·香雪兰溪",
//		"citycode":"010",
//		"link":"",
//		"img":"",
//		"top":'false'\ti
//	},
//	{
//		"type":"top",
//		"hid":"3272",			//4.1 下线
//		"name":"保利·西山林语",
//		"citycode":"010",
//		"link":"http://sina.allyes.com/main/adfclick?db=sina&bid=152170,191641,196631&cid=0,0,0&sid=184404&advid=1832&camid=26413&show=ignore&url=http://www.bjhouseonline.com/kehu/blxsly/index.html",
//		"img":"",
//		"top":'true'
//	},
//	{
//		"type":"hotlink",
//		"hid":"2834",			//4.1下线
//		"name":"纳帕尔湾",
//		"citycode":"010",
//		"link":"",
//		"img":"",
//		"top":'false'
//	}
];

//得到广告客户的详情页链接
function getDetailLink(hid,citycode){
	try{
		for(var i=0,len=ad_customers.length;i<len;i++){
			if(hid == ad_customers[i].hid && citycode == ad_customers[i].citycode && ad_customers[i].link !=''){
				return ad_customers[i].link;
			}
		}

		return false;
	}catch(e){
		return false;
	}
}

function getAdLogo(hid,citycode){
	try{
		for(var i=0,len=ad_customers.length;i<len;i++){
			if(hid == ad_customers[i].hid && citycode == ad_customers[i].citycode && ad_customers[i].img != ''){
				return ad_customers[i].img;
			}
		}

		return false;
	}catch(e){
		return false;
	}
}


function showNoPointTip(){
	return;
}
