var config = new Object();
config.domain_img = 'http://img.88880808.com/house/';
config.domain_uf = 'http://uf.88880808.com/';
config.domain_www = 'http://www.88880808.com/';

var Fangfa=new Object();

Fangfa.EventMonitor = function(){
	this.listeners = new Object();
}
Fangfa.EventMonitor.prototype.broadcast=function(widgetObj, msg, data){
	var lst = this.listeners[msg];

	if(lst != null){
		for(var o in lst){
			lst[o](widgetObj, data);
		}
	}
}
Fangfa.EventMonitor.prototype.subscribe=function(msg, callback){
	var lst = this.listeners[msg];
	if (lst) {
		lst.push(callback);
	} else {
		this.listeners[msg] = [callback];
	}
}
Fangfa.EventMonitor.prototype.unsubscribe=function(msg, callback){
	var lst = this.listener[msg];
	if (lst != null){
		lst = lst.filter(function(ele, index, arr){return ele!=callback;});
	}
}

// Page scope event-monitor obj.
var event_monitor = new Fangfa.EventMonitor();

function load_event_monitor(root) {
	var re = /a_(\w+)/;
	var fns = {};
	$(".j", root).each(function(i) {
		var m = re.exec(this.className);
		if (m) {
			var f = fns[m[1]];
			if (!f) {
				f = eval("Fangfa.init_"+m[1]);
				fns[m[1]] = f;
			}
			f && f(this);
		}
	});
}

$(function() {
	load_event_monitor(document);
});

$.viewport_size = function () {
	var b = [0, 0];
	if (typeof window.innerWidth != "undefined") {
		b = [window.innerWidth, window.innerHeight]
	} else {
		if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
			b = [document.documentElement.clientWidth, document.documentElement.clientHeight]
		} else {
			b = [document.body.clientWidth, document.body.clientHeight]
		}
	}
	return b
};
$.ajax_withck = function (b) {
	if (b.type == "POST") {
		b.data = $.extend(b.data || {},
		{
			ck: get_cookie("ck")
		})
	}
	return $.ajax(b)
};
$.postJSON_withck = function (b, c, d) {
	$.post_withck(b, c, d, "json")
};
$.post_withck = function (b, d, e, c) {
	if ($.isFunction(d)) {
		e = d;
		d = {}
	}
	return $.ajax({
		type: "POST",
		url: b,
		data: $.extend(d, {
			ck: get_cookie("ck")
		}),
		success: e,
		dataType: c
	})
};
jQuery.fn.extend({
	pos: function () {
		var c = this[0];
		if (c.offsetParent) {
			for (var d = 0, b = 0; c.offsetParent; c = c.offsetParent) {
				d += c.offsetLeft;
				b += c.offsetTop
			}
			return {
				x: d,
				y: b
			}
		} else {
			return {
				x: c.x,
				y: c.y
			}
		}
	},
	chop: function (g, b) {
		var d = [],
		c = [];
		for (var e = 0, f = this.length; e < f; e++) {
			if (!b != !g(this[e], e)) {
				d.push(this[e])
			} else {
				c.push(this[e])
			}
		}
		return [d, c]
	},
	sum: function (c, e) {
		var b = this.length,
		d = zero = e ? "" : 0;
		while (b) {
			d += this[--b][c] + (b && e || zero)
		}
		return d
	},
	set_len_limit: function (c) {
		var d = this.find(":submit:first");
		var e = d.attr("value");
		var b = function () {
			if (this.value && this.value.length > c) {
				d.attr("disabled", 1).attr("value", "字数不能超过" + c + "字")
			} else {
				d.attr("disabled", 0).attr("value", e)
			}
		};
		$("textarea", this).focus(b).blur(b).keydown(b).keyup(b)
	},
	display_limit: function (b, g) {
		var c = this,
		e, d = function (h) {
			var f = c.val();
			if (f == e) {
				return
			}
			if (f.length >= b) {
				c.val(f.substring(0, b))
			}
			g.text(b - c.val().length);
			e = c.val()
		};
		this.keyup(d);
		d()
	},
	set_caret: function () {
		if (!$.browser.msie) {
			return
		}
		var b = function () {
			this.p = document.selection.createRange().duplicate()
		};
		this.click(b).select(b).keyup(b)
	},
	insert_caret: function (c) {
		var j = this[0];
		if (document.all && j.createTextRange && j.p) {
			var i = j.p;
			i.text = i.text.charAt(i.text.length - 1) == "" ? c + "" : c
		} else {
			if (j.setSelectionRange) {
				var f = j.selectionStart;
				var h = j.selectionEnd;
				var g = j.value.substring(0, f);
				var d = j.value.substring(h);
				j.value = g + c + d;
				j.focus();
				var b = c.length;
				j.setSelectionRange(f + b, f + b);
				j.blur()
			} else {
				j.value += c
			}
		}
	},
	get_sel: function () {
		var b = this[0];
		return document.all && b.createTextRange && b.p ? b.p.text : b.setSelectionRange ? b.value.substring(b.selectionStart, b.selectionEnd) : ""
	},
	blur_hide: function () {
		var c = this,
		b = function () {
			return false
		};
		c.mousedown(b);
		$().mousedown(function () {
			c.hide().unbind("mousedown", b);
			$().unbind("mousedown", arguments.callee)
		});
		return this
	},
	yellow_fade: function () {
		var b = 0,
		d = 1,
		c = this;

		function e() {
			c.css({
				backgroundColor: "rgb(100%,100%," + b + "%)"
			});
			b += d;
			d += 0.5;
			if (b <= 100) {
				setTimeout(e, 35)
			} else {
				c.css({
					backgroundColor: ""
				})
			}
		}
		e();
		return this
	},
	hover_fold: function (d) {
		var b = {
			folder: [1, 3],
			unfolder: [0, 2]
		},
		c = function (e, f) {
			return function () {
				$("img", e).attr("src", "/pics/arrow" + f + ".gif")
			}
		};
		return this.hover(c(this, b[d][0]), c(this, b[d][1]))
	},
	multiselect: function (d) {
		var g = function () {
			return true
		},
		f = d.onselect || g,
		e = d.onremove || g,
		c = d.onchange || g,
		h = d.selclass || "sel",
		b = d.values || [];
		return this.click(function () {
			var k = /id(\d*)/.exec(this.className)[1],
			j = $.inArray(k, b);
			if (j != -1) {
				if (!e(this)) {
					return
				}
				b.splice(j, 1);
				$(this).removeClass(h)
			} else {
				if (!f(this)) {
					return
				}
				b.push(k);
				$(this).addClass(h)
			}
			c(b);
			return false
		})
	}
});

var show_dialog = function (b) {
	if ($("#dialog").length) {
		return
	}
	$("body").prepend('<div id="overlay"></div><div id="dialog"></div>');
	if (b != null) {
		$("#dialog").html(b)
	} else {
		$("#dialog").html("<div class='loadpop'>正在载入，请稍候...</div>")
	}
	set_overlay()
};
var set_overlay = function () {
	var d = ($.browser.msie ? 11 : 26),
	c = $("#dialog")[0],
	b = c.offsetWidth,
	e = (document.body.offsetWidth - b) / 2 + "px";
	$("#overlay").css({
		height: c.offsetHeight + d,
		width: b + 26,
		left: e
	});
	c.style.left = e
};
var close_dialog = function () {
	$("#overlay").unbind("click");
	$("#dialog,#overlay,.bgi").remove();
	if (typeof document.body.style.maxHeight == "undefined") {
		$("body", "html").css({
			height: "auto",
			width: "auto"
		});
		$("html").css("overflow", "")
	}
	document.onkeydown = "";
	return false
};
var refine_dialog = function () {
	if (!$("#dialog").length) {
		return
	}
	var b = navigator.userAgent.toLowerCase();
	var c = 0.5 * ($.viewport_size()[1] - $("#dialog")[0].offsetHeight) + 140;
	$("#dialog,#overlay").css("top", c);
	set_overlay()
};

function js_parser(htm) {
	var tag = "script>",
	begin = "<" + tag,
	end = "</" + tag,
	pos = pos_pre = 0,
	result = script = "";
	while ((pos = htm.indexOf(begin, pos)) + 1) {
		result += htm.substring(pos_pre, pos);
		pos += 8;
		pos_pre = htm.indexOf(end, pos);
		if (pos_pre < 0) {
			break
		}
		script += htm.substring(pos, pos_pre) + ";";
		pos_pre += 9
	}
	result += htm.substring(pos_pre, htm.length);
	return {
		htm: result,
		js: function () {
			eval(script)
		}
	}
}
function center(b) {
	return {
		left: (document.documentElement.offsetWidth - b.offsetWidth) / 2 + "px",
		top: (document.documentElement.clientHeight - b.offsetHeight) * 0.45 + "px"
	}
}
function pop_win(f, e) {
	if (!window.__pop_win) {
		var h = document.createElement("div");
		h.className = "pop_win_bg";
		document.body.appendChild(h);
		var j = document.createElement("div");
		j.className = "pop_win";
		document.body.appendChild(j);
		__pop_win = {
			bg: h,
			body: j,
			body_j: $(j),
			bg_j: $(h)
		}
	}
	var c = __pop_win.body,
	d = __pop_win.body_j,
	i = js_parser(f);
	if (e !== true) {
		i.htm = '<a onclick="pop_win.close()" href="javascript:;" class="pop_win_close">X</a>' + i.htm
	}
	c.innerHTML = i.htm;
	var g = center(c);
	if (document.documentElement.clientHeight < c.offsetHeight) {
		g.top = "0";
		g.height = document.documentElement.clientHeight - 40 + "px";
		g.overflow = "auto"
	}
	d.css({
		display: "block"
	}).css(g).css({
		visibility: "visible",
		zIndex: 101
	});
	i.js();
	pop_win.fit();
	if (!window.XMLHttpRequest) {
		__pop_win.bg.style.top = ""
	}
}
pop_win.fit = function () {
	if (window.__pop_win) {
		var c = __pop_win.body;
		__pop_win.bg_j.css({
			height: c.offsetHeight + 20 + "px",
			width: c.offsetWidth + 20 + "px",
			left: c.offsetLeft - 10 + "px",
			top: c.offsetTop - 10 + "px",
			zIndex: 100
		}).show()
	}
};
pop_win.close = function () {
	$(__pop_win.bg).remove();
	$(__pop_win.body).remove();
	window.__pop_win = null
};
pop_win.load = function (c, b) {
	pop_win("加载中,请稍等...");
	$.ajax({
		url: c,
		success: pop_win,
		cache: b || false
	});
	return false
};

//加入收藏夹
Fangfa.init_add_favorite = function(o){
	$(o).click(function(){
		var surl = window.location;
		var stitle = document.title;
		try{
			window.external.addFavorite(surl, stitle);
		}catch (e){
			try{
				window.sidebar.addPanel(stitle, surl, "");
			}catch (e){
				alert("加入收藏失败，请使用Ctrl+D进行添加");
			}
		}
	});
}
//设置为首页
Fangfa.init_sethome = function(o){
	$(o).click(function(){
		try{
			this.style.behavior='url(#default#homepage)';this.setHomePage(window.location);
		}
		catch(e){
			if(window.netscape) {
				try {
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				}catch (e) {
					alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
				}
				var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
				prefs.setCharPref('browser.startup.homepage',window.location);
			}
		}

	});
}

Fangfa.init_copy_house_url = function(o){
	$(o).click(function(){
		var clipBoardContent=$('#house-info h2').text()+"\n" +window.location;
		window.clipboardData.setData("Text",clipBoardContent);
		alert('复制到剪切板了。');
	});
}


Fangfa.init_house_list_form = function(o){
	$('.a_order').click(function(){

		$('#select_order').val($(this).attr('id').split('-')[1]);
		$('#house_list_form').submit();
		return false;
	});

	$('#select_order').change(function(){
		$('#house_list_form').submit();
		return false;
	});

	if($('#kw').val() == ''){
		$('#kw').val('在结果中筛选');
	}
	$('#kw').click(function(){
		if($('#kw').val() == '在结果中筛选'){
			$('#kw').val('');
		}
	});

	$('#house_list_form').submit(function(){
		if($('#kw').val() == '在结果中筛选'){
			$('#kw').val('');
		}
	});
}

//房源列表
Fangfa.init_house_1_detail_ul = function(o){
	$('li.house_detail').hover(function(){
		$(this).addClass('house_detail_hover');
	},function(){
		$(this).removeClass('house_detail_hover');
	});


	//compare

	$('#compare-wapper').css({"position":"fixed","z-index":"9999","right":"0px","bottom":"0px","width":"160px"});

	if($.browser.msie && $.browser.version == 6) {
		$('#compare-wapper').css('position','absolute');
		$(window).scroll(function(){
			var f_top = $(window).scrollTop() + $(window).height() - $("#compare-wapper").height() - parseFloat($("#compare-wapper").css("borderTopWidth")) - parseFloat($("#compare-wapper").css("borderBottomWidth")) - 20;
			$('#compare-wapper').css( 'top' , f_top );
		});
	}


	$('.compare_house_checkbox').each(function(){
		$(this).click(function(){
			var ck_compare = $.cookie(COOKIE_COMPARE_SALE_NAME)||'';

			var arr_compare = new Array();
			if(ck_compare != ''){
				arr_compare = ck_compare.split(';;n;;');
			}

			//
			if($(this).attr("checked") == true){
				//选中状态
				if(arr_compare.length >=4){
					alert('最多保存4个条件.');
					return false;
				}
				$.cookie(COOKIE_COMPARE_SALE_SHOW_NAME,'1',options_sale);
				arr_compare.push($(this).attr('id').split('-')[1]+';;h;;'+$(this).attr('title'));

			}else{
				//未选中状态
				for(var i = 0;i<arr_compare.length;i++){
					if(arr_compare[i].split(';;h;;')[0] == $(this).attr('id').split('-')[1]){
						arr_compare.splice(i,1);
					}
				}
			}


			$.cookie(COOKIE_COMPARE_SALE_NAME, arr_compare.join(';;n;;'), options_sale);

			write_compare_back_1();
			
		});
	});

	write_compare_back_1();
}

Fangfa.init_house_2_detail_ul = function(o){
	$('li.house_detail').mouseover(function(){
		$(this).addClass('house_detail_hover');
	}).mouseout(function(){
		$(this).removeClass('house_detail_hover');
	}).click(function(){
		//window.location.href=$(this).find('a').attr('href');
	});


	//compare

	$('#compare-wapper').css({"position":"fixed","z-index":"9999","right":"0px","bottom":"0px"});

	if($.browser.msie && $.browser.version == 6) {
		$('#compare-wapper').css('position','absolute');
		$(window).scroll(function(){
			var f_top = $(window).scrollTop() + $(window).height() - $("#compare-wapper").height() - parseFloat($("#compare-wapper").css("borderTopWidth")) - parseFloat($("#compare-wapper").css("borderBottomWidth")) - 20;
			$('#compare-wapper').css( 'top' , f_top );
		});
	}


	$('.compare_house_checkbox').each(function(){
		$(this).click(function(){
			var ck_compare = $.cookie(COOKIE_COMPARE_RENT_NAME)||'';

			var arr_compare = new Array();
			if(ck_compare != ''){
				arr_compare = ck_compare.split(';;n;;');
			}

			//
			if($(this).attr("checked") == true){
				//选中状态
				if(arr_compare.length >=4){
					alert('最多保存4个条件.');
					return false;
				}
				$.cookie(COOKIE_COMPARE_RENT_SHOW_NAME,'1',options_rent);
				arr_compare.push($(this).attr('id').split('-')[1]+';;h;;'+$(this).attr('title'));

			}else{
				//未选中状态
				for(var i = 0;i<arr_compare.length;i++){
					if(arr_compare[i].split(';;h;;')[0] == $(this).attr('id').split('-')[1]){
						arr_compare.splice(i,1);
					}
				}
			}


			$.cookie(COOKIE_COMPARE_RENT_NAME, arr_compare.join(';;n;;'), options_rent);

			write_compare_back_2();
			
		});
	});

	write_compare_back_2();
}


//房源搜索条件
var COOKIE_CONDITION_SALE_NAME = 'search_condition_save_sale'
var COOKIE_CONDITION_RENT_NAME = 'search_condition_save_rent'

var options_sale = { path: '/sale/', expires: 10 };
var options_rent = { path: '/rent/', expires: 10 };

function search_condition_write_back_1(){
	var ck = $.cookie(COOKIE_CONDITION_SALE_NAME)||'';
	var arr = ck.split(';;n;;');
	var htmlarr = new Array();
	for(var k in arr){
		var v = arr[k].split(';;h;;');
		if(v[0] && v[1] && v[1]){
			htmlarr.push('<li><a href="'+v[1]+'">'+v[2]+'</a><span class="j a_delete_one_search_result_1" id="'+v[0]+'">X</span></li>')
		}
	}
	$('#search_save_results').html(htmlarr.join(''));
	load_event_monitor($('#search_save_box'));

}

function search_condition_write_back_2(){
	var ck = $.cookie(COOKIE_CONDITION_RENT_NAME)||'';
	var arr = ck.split(';;n;;');
	var htmlarr = new Array();
	for(var k in arr){
		var v = arr[k].split(';;h;;');
		if(v[0] && v[1] && v[1]){
			htmlarr.push('<li><a href="'+v[1]+'">'+v[2]+'</a><span class="j a_delete_one_search_result_2" id="'+v[0]+'">X</span></li>')
		}

	}
	$('#search_save_results').html(htmlarr.join(''));
	load_event_monitor($('#search_save_box'));

}

Fangfa.init_search_save_box_1 = function(){

	$('#search_save_submit').click(function(){


		if($.trim($('#search_save_title').html()) == ''){
			$('#search_save_result').html('缩小搜索范围再来保存吧.');
			return ;
		}

		var ck = $.cookie(COOKIE_CONDITION_SALE_NAME);
		var v = Math.random( )+';;h;;'+window.location + ';;h;;' + $('#search_save_title').html();

		var arr = new Array();
		if(ck != null){
			arr = ck.split(';;n;;');
		}
		if(arr.length >3){
			$('#search_save_result').html('最多保存3个条件.');
			return ;
		}
		arr.push(v);

		$.cookie(COOKIE_CONDITION_SALE_NAME, arr.join(';;n;;'), options_sale);

		search_condition_write_back_1();
		//$('#search_save_submit').hide();
		$('#search_save_result').html('搜索条件保存成功.');
		//setTimeout(function () { $('#search_save_result').hide(); }, 2000);
	});

	search_condition_write_back_1();
}

Fangfa.init_search_save_box_2 = function(){

	$('#search_save_submit').click(function(){


		if($.trim($('#search_save_title').html()) == ''){
			$('#search_save_result').html('缩小搜索范围再来保存吧.');
			return ;
		}

		var ck = $.cookie(COOKIE_CONDITION_RENT_NAME);
		var v = Math.random( )+';;h;;'+window.location + ';;h;;' + $('#search_save_title').html();

		var arr = new Array();
		if(ck != null){
			arr = ck.split(';;n;;');
		}
		if(arr.length >=3){
			$('#search_save_result').html('最多保存3个条件.');
			return ;
		}
		arr.push(v);

		$.cookie(COOKIE_CONDITION_RENT_NAME, arr.join(';;n;;'), options_rent);

		search_condition_write_back_2();
		//$('#search_save_submit').hide();
		$('#search_save_result').html('搜索条件保存成功.');
		setTimeout(function () { $('#search_save_result').hide(); }, 2000);
	});

	search_condition_write_back_2();
}

Fangfa.init_delete_one_search_result_1 = function(o){

	$(o).click(function(){
		var ck = $.cookie(COOKIE_CONDITION_SALE_NAME);
		var arr = ck.split(';;n;;');
		for(var i = 0;i<arr.length;i++){
			if(arr[i].split(';;h;;')[0] == $(this).attr('id')){
				arr.splice(i,1);
			}
		}
		$.cookie(COOKIE_CONDITION_SALE_NAME, arr.join(';;n;;'), options_sale);
		search_condition_write_back_1();
	});
}

Fangfa.init_delete_one_search_result_2 = function(o){

	$(o).click(function(){
		var ck = $.cookie(COOKIE_CONDITION_RENT_NAME);
		var arr = ck.split(';;n;;');
		for(var i = 0;i<arr.length;i++){
			if(arr[i].split(';;h;;')[0] == $(this).attr('id')){
				arr.splice(i,1);
			}
		}
		$.cookie(COOKIE_CONDITION_RENT_NAME, arr.join(';;n;;'), options_rent);
		search_condition_write_back_2();
	});
}

var COOKIE_COMPARE_SALE_NAME = 'sale_compare'
var COOKIE_COMPARE_SALE_SHOW_NAME = 'sale_compare_show'
var COOKIE_COMPARE_RENT_NAME = 'rent_compare'
var COOKIE_COMPARE_RENT_SHOW_NAME = 'rent_compare_show'

function write_compare_back_1(){

	var ck_compare = $.cookie(COOKIE_COMPARE_SALE_NAME)||'';
	var ck_compare_show = $.cookie(COOKIE_COMPARE_SALE_SHOW_NAME)||'0';

	if(ck_compare == ''){
		$('#compare-wapper').hide();
	}else{
		$('#compare-wapper').show();
	}

	if(ck_compare_show == '0'){
		$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_big.gif');
		$('#compare-content').hide();
	}else{
		$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_close.gif');
		$('#compare-content').show();
	}


	var arr = ck_compare.split(';;n;;');
	var htmlarr = new Array();
	for(var k in arr){
		var v = arr[k].split(';;h;;');
		if(v[0] && v[1]){
			htmlarr.push('<li>'+v[1]+'<span class="j a_delete_one_compare_result_1" id="'+v[0]+'">X</span></li>');
			$('#house_checkbox-'+v[0]).attr('checked',true);
		}
	}
	$('#compare-box-li-count').html(arr.length);
	$('#compare-box-list').html(htmlarr.join(''));
	load_event_monitor($('#compare-box-list'));



}



Fangfa.init_delete_one_compare_result_1 = function(o){

	$(o).click(function(){

		var ck_compare = $.cookie(COOKIE_COMPARE_SALE_NAME);
		var arr_compare = new Array();
		if(ck_compare != null){
			arr_compare = ck_compare.split(';;n;;');
		}
		$('#house_checkbox-'+$(this).attr('id')).attr('checked',false);

		//未选中状态
		for(var i = 0;i<arr_compare.length;i++){
			if(arr_compare[i].split(';;h;;')[0] == $(this).attr('id')){
				arr_compare.splice(i,1);
			}
		}

		$.cookie(COOKIE_COMPARE_SALE_NAME, arr_compare.join(';;n;;'), options_sale);

		write_compare_back_1();

	});

}

Fangfa.init_compare_clear_sale_button = function(o){
	$(o).click(function(){
		
		$('.compare_house_checkbox').attr('checked',false);
		$.cookie(COOKIE_COMPARE_SALE_NAME, '', options_sale);

		write_compare_back_1();
	});
}
Fangfa.init_compare_clear_rent_button = function(o){
	$(o).click(function(){
		$('.compare_house_checkbox').attr('checked',false);
		$.cookie(COOKIE_COMPARE_RENT_NAME, '', options_sale);

		write_compare_back_2();
	});
}

Fangfa.init_compare_box_img_1 = function(o){
	$(o).click(function(){

		//
		var ck_compare_show = $.cookie(COOKIE_COMPARE_SALE_SHOW_NAME)||'0';

		if(ck_compare_show == '0'){
			$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_close.gif');
			$.cookie(COOKIE_COMPARE_SALE_SHOW_NAME,'1',options_sale);
		}else{
			$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_big.gif');
			$.cookie(COOKIE_COMPARE_SALE_SHOW_NAME,'0',options_sale);
		}

		$('#compare-content').slideToggle('slow');
	});
}

function write_compare_back_2(){

	var ck_compare = $.cookie(COOKIE_COMPARE_RENT_NAME)||'';
	var ck_compare_show = $.cookie(COOKIE_COMPARE_RENT_SHOW_NAME)||'0';

	if(ck_compare == ''){
		$('#compare-wapper').hide();
	}else{
		$('#compare-wapper').show();
	}

	if(ck_compare_show == '0'){
		$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_big.gif');
		$('#compare-content').hide();
	}else{
		$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_close.gif');
		$('#compare-content').show();
	}


	var arr = ck_compare.split(';;n;;');
	var htmlarr = new Array();
	for(var k in arr){
		var v = arr[k].split(';;h;;');
		if(v[0] && v[1]){
			htmlarr.push('<li>'+v[1]+'<span class="j a_delete_one_compare_result_2" id="'+v[0]+'">X</span></li>');
			$('#house_checkbox-'+v[0]).attr('checked',true);
		}
	}
	$('#compare-box-li-count').html(arr.length);
	$('#compare-box-list').html(htmlarr.join(''));
	load_event_monitor($('#compare-box-list'));



}



Fangfa.init_delete_one_compare_result_2 = function(o){

	$(o).click(function(){

		var ck_compare = $.cookie(COOKIE_COMPARE_RENT_NAME);
		var arr_compare = new Array();
		if(ck_compare != null){
			arr_compare = ck_compare.split(';;n;;');
		}
		$('#house_checkbox-'+$(this).attr('id')).attr('checked',false);

		//未选中状态
		for(var i = 0;i<arr_compare.length;i++){
			if(arr_compare[i].split(';;h;;')[0] == $(this).attr('id')){
				arr_compare.splice(i,1);
			}
		}

		$.cookie(COOKIE_COMPARE_RENT_NAME, arr_compare.join(';;n;;'), options_rent);

		write_compare_back_2();

	});

}

Fangfa.init_compare_box_img_2 = function(o){
	$(o).click(function(){

		//
		var ck_compare_show = $.cookie(COOKIE_COMPARE_RENT_SHOW_NAME)||'0';

		if(ck_compare_show == '0'){
			$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_close.gif');
			$.cookie(COOKIE_COMPARE_RENT_SHOW_NAME,'1',options_rent);
		}else{
			$('#compare_box_img').attr('src',config.domain_uf+'pics/icon_big.gif');
			$.cookie(COOKIE_COMPARE_RENT_SHOW_NAME,'0',options_rent);
		}

		$('#compare-content').slideToggle('slow');
	});
}

Fangfa.init_compare_sumbit_button = function(o){
	$(o).click(function(){



		if($('input[name=house_type]').val() == '1'){

			var ck_compare = $.cookie(COOKIE_COMPARE_SALE_NAME)||'';
			var arr = ck_compare.split(';;n;;');
			var htmlarr = new Array();
			for(var k in arr){
				var v = arr[k].split(';;h;;');
				if(v[0] && v[1]){
					htmlarr.push(v[0]);
				}
			}

			if(htmlarr.length < 2){
				alert('您至少选择2条房源进行比较!');
				return false;
			}

			window.open('/sale/house-compare/?house_ids='+htmlarr.join(','));
		}else{

			var ck_compare = $.cookie(COOKIE_COMPARE_RENT_NAME)||'';
			var arr = ck_compare.split(';;n;;');
			var htmlarr = new Array();
			for(var k in arr){
				var v = arr[k].split(';;h;;');
				if(v[0] && v[1]){
					htmlarr.push(v[0]);
				}
			}
			if(htmlarr.length < 2){
				alert('您至少选择2条房源进行比较!');
				return false;
			}
			window.open('/rent/house-compare/?house_ids='+htmlarr.join(','));
		}


	});
}

Fangfa.init_building_map = function(){
	var map = null;
	var marker = null;

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("building_map"));

		map.addControl(new GSmallMapControl());

		var lng = $('#building_longitude').val();
		var lat = $('#building_latitude').val();

		map.setCenter( new GLatLng(lat,lng), 14);

		//var letteredIcon = new GIcon(G_DEFAULT_ICON);
		//  letteredIcon.image = "http://maps.google.com/mapfiles/kml/pushpin/red-pushpin.png";

		marker = new GMarker( new GLatLng(lat,lng));
		map.addOverlay(marker);

	}

}

Fangfa.init_nobody_house_bbs_add = function(o){

	$(o).validate({
		rules:{
			hb_u_name:{
				required:true,
				rangelength:[2,4]
			},
			hb_content:"required",
			hb_u_email:{
				email:true
			}
		},
		messages:{
			hb_u_name:{
				required:'请输入您的姓名',
				rangelength:'姓名长度不正确。'
			},
			hb_content:{
				required:'请输入您要咨询的内容。'
			},
			hb_u_email:{
				email:'邮件格式不正确。'
			}
		},
		errorLabelContainer: $("#err-nobody_house_bbs_add")
	});



	//	$(o).submit(function(){
	//		$.post($(this).attr('action')+'&ajax=1',$(this).serialize(),function(data){
	//			if(data == '1'){
	//				$('#house_bbs_result').html('你提交的咨询已经记录，谢谢。');
	//			}else{
	//				$('#house_bbs_result').html('err');
	//			}
	//		});
	//		return false;
	//	});
}





Fangfa.init_top_filter = function(o){
	$("body").click(function(e){
		$(".dropbox-list").hide();
		var target = $(e.target);
		if (target.is("#filter_name-area")){
			$(".filter_name-area").slideDown(100)
		}else
		if (target.is("#filter_name-carea")){
			$(".filter_name-carea").slideDown(100)
		}else
		if (target.is("#filter_name-price")){
			$(".filter_name-price").slideDown(100)
		}else
		if (target.is("#filter_name-croom")){
			$(".filter_name-croom").slideDown(100)
		}
	});
	$('.top_filter').each(function(){
		$(this).click(function(){
			var kv = $(this).attr('id').split('-');
			var k = kv[0]; var v = kv[1];
			$('input[name='+k+']').val(v);
			$('#filter_name-'+k).html($(this).html());
		});
	});
	$(o).submit(function(){
		$('#text-a').focus();
	});
}

Fangfa.init_hover_nh_pic = function(){
	$(".nh-list li").hover(
	function(){$(this).find("img.broker_avatar").css({"visibility":"visible","z-index":"100"})},
	function(){$(this).find("img.broker_avatar").css("visibility","hidden")}
	);
}

Fangfa.init_report = function(o){
	$(o).click(function(){
		show_dialog($('#report').html());
		load_event_monitor("#dialog");
	});
}

Fangfa.init_show_subscription_box = function(o){
	$(o).click(function(){
		show_dialog($('#subscription_box').html());
		load_event_monitor("#subscription_box");
		return false;
	});
}

Fangfa.init_nobody_subscription_from = function(o){
	$(o).validate({
		rules:{
			subscription_name:{
				required:true,
				rangelength:[2,4]
			},
			randcode:{
				required:true,
				rangelength:[4,4]
			},
			subscription_mobile:{
				number:true,
				rangelength:[11,11]
			},
			subscription_email:{
				email:true
			}
		},
		messages:{
			subscription_name:{
				required:'订阅人姓名必填。',
				rangelength:'订阅人姓名不合法。'
			},
			randcode:{
				required:'验证码必填。',
				rangelength:'验证码格式不正确。'
			},
			subscription_mobile:{
				number:'订阅移动电话格式不正确。',
				rangelength:'订阅移动电话格式不正确'
			},
			subscription_email:{
				email:'邮件格式不正确。'
			}
		}
		,
		errorLabelContainer: $("#err-nobody_subscription")
	});
}

Fangfa.init_house_booking = function(o){
	$(o).click(function(){
		show_dialog($('#booking').html());
		load_event_monitor("#dialog");
		//
		$('#check_code_img').click();
		$('#booking_user').focus();
	});
}
Fangfa.init_newhome_planintro = function(){
	$("#newhouse-subnav a").click(function(){
		$("#newhouse-subnav a").removeClass("active");
		$(this).addClass("active");
		$(".model-type").hide();
		$("."+$(this).attr("id")).show();
		return false;
	});
	$("#newhouse-subnav a#showall").click(function(){$(".model-type").show()})
}

Fangfa.init_newhome_photos = function(){
	$("#newhouse-subnav a").click(function(){
		$("#newhouse-subnav a").removeClass("active");
		$(this).addClass("active");
		$(".pic-list").hide();
		$("div."+$(this).attr("id")).show()
	});
	$("#newhouse-subnav a#showall").click(function(){$(".pic-list").show()});
}



Fangfa.init_nobody_report_house = function(o){
	$.metadata.setType("attr", "validate");

	$(o).validate({
		rules:{



			report_mobile:{
				required:true,
				number:true,
				rangelength:[11,11]
			}

		},
		messages:{
			report_mobile:{
				required:'手机号码必填',
				number:'手机号码输入有误',
				rangelength:'手机号码输入有误'
			}
		},
		errorLabelContainer: $("#err-nobody_report"),
		submitHandler: function(form) {
			$.post($(form).attr('action')+'&ajax=1',$(form).serialize(),function(data){
				alert(data == '1'?'提交成功！':'提交失败！');
				close_dialog();
			});
			return false;
		}
	});

}

Fangfa.init_nobody_booking_form = function(o){


	$(o).validate({
		rules:{

			booking_user:{
				required:true,
				rangelength:[2,4]
			},

			booking_link:{
				required:true,
				number:true,
				rangelength:[11,11]
			},
			booking_content:{
				required:true,
				maxlength:20
			},
			check_code:{
				required:true,
				rangelength:[4,4],
				remote:"/a.php?action=check_code"
			}

		},
		messages:{
			booking_user:{
				required:'请填入您的姓名。',
				rangelength:'请检查您填入姓名的格式。'
			},
			booking_link:{
				required:'手机号码必填',
				number:'手机号码输入有误',
				rangelength:'手机号码输入有误'
			},
			booking_content:{
				required:'请填入内容。',
				maxlength:'请控制在20个字符'
			},
			check_code:{
				required:'请输入验证码',
				rangelength:'验证码格式不正确。',
				remote:'验证码输入不正确'
			}
		},
		errorPlacement: function(error, element) {
			error.appendTo ( '#err-'+element.attr("id") );
		},
		submitHandler: function(form) {
			$.getJSON($(form).attr('action')+'&ajax=1',$(form).serialize(),function(j){

				alert(j.msg);

				if(j.err == '0'){
					close_dialog();
				}
				$('#check_code_img').click();
				$('#check_code').val('');

			});
			return false;
		}
	});

}



Fangfa.init_main_search = function(o){
	$(".selling").mouseover(function(){
		$(this).removeClass("sover");
		$(".renting").removeClass("rnow");
		//
		$('.main_search_form').hide();
		$('#main_search_sale_form').show();
	});
	$(".renting").mouseover(function(){
		$(this).addClass("rnow");
		$(".selling").addClass("sover");
		$('.main_search_form').hide();
		$('#main_search_rent_form').show();
	});

	$("body").click(function(e){
		$(".dropbox-list").hide();
		var target = $(e.target);
		if (target.is(".dropbox")){
			$("#"+target.attr('id')+'s').slideDown(100)
		}
	});
	$(".selling").mouseover();



	//推荐翻页
	//@sale
	$('#tj_sale_multi a').click(function(){
		$('#tj_sale_multi a').removeClass('current');
		$(this).addClass('current');
		$('#tj_sale_list li').hide();
		$('#tj_sale_list li.house_li_'+$(this).attr('href').split('-')[1]).show();
		return false;
	});
	$('#tj_sale_list li').hide();
	$('#tj_sale_multi a:first').click();
	//
	setInterval("autoPlay_tj_sale()",6*1000);
	//@rent
	$('#tj_rent_multi a').click(function(){
		$('#tj_rent_multi a').removeClass('current');
		$(this).addClass('current');
		$('#tj_rent_list li').hide();
		$('#tj_rent_list li.house_li_'+$(this).attr('href').split('-')[1]).show();
		return false;
	});
	$('#tj_rent_list li').hide();
	$('#tj_rent_multi a:first').click();
	//
	setInterval("autoPlay_tj_rent()",6*1000);


	//submit
	$('.main_search_form').submit(function(){
		if($('.main-text').val() == "请输入房源特征,地点或小区名..." || $('.main-text').val() == "请输入房源特征,地点或楼盘名..." || $('.main-text').val() == "请输入楼盘地点或名称..."){
			$('.main-text').val('');
		}
	});
}

//search keyword
Fangfa.init_main_text = function(o){
	$(o).focus(function(){
		if($(o).val() == "请输入房源特征,地点或小区名..." || $(o).val() == "请输入房源特征,地点或楼盘名..." || $(o).val() == "请输入楼盘地点或名称..."){
			$(o).val('');
		}
	}).blur(function(){
		if($(o).val() == ""){
			$(o).val('请输入房源特征,地点或小区名...');
		}
	}).autocomplete("/a.php?action=buildinglist", {
		width: 218,
		selectFirst: false
	});
	//
	$(o).blur();
}

Fangfa.init_filter_value = function(o){
	$(o).click(function(){
		//alert($(this).attr('id'));
		var kv = $(this).attr('id').split('_');
		var t = kv[0]; var k = kv[1]; var v = kv[2];
		var n = $(this).attr('name');
		//alert("t:"+t+"\nn:"+n+"\nv:"+v);
		$('input[class='+t+'][name='+n+']').val(v);
		$('#filter_'+t+'_'+k).html($(this).text());
		//
		if($(this).hasClass('hassubarea')){

			var htmlarr = new Array();
			$.getJSON("/a.php?action=get_area_chilren",{area_code:v,output:'json'}, function(data){
				$.each(data, function(i,item){
					htmlarr.push('<li id="'+t+'_subarea_'+item.TypeId+'" name="area" class="top_filter j a_filter_value"><span >'+item.TypeName+'</span></li>');
				});

				if(t == 'sale'){
					$('#filter_sale_subareas').html( htmlarr.join(''));
					load_event_monitor('#filter_sale_subareas');
				}else{
					$('#filter_rent_subareas').html( htmlarr.join(''));
					load_event_monitor('#filter_rent_subareas');
				}

			});
		}
	});
}



var last_tj_sale = 1;
var this_tj_sale = 1;
function autoPlay_tj_sale(){
	for(i=1;i<=3;i++){
		this_tj_sale = last_tj_sale%i;
		$("#tj_sale_multi a:eq("+this_tj_sale+")").click();
	}
	last_tj_sale++;
}
var last_tj_rent = 1;
var this_tj_rent = 1;
function autoPlay_tj_rent(){
	for(i=1;i<=3;i++){
		this_tj_rent = last_tj_rent%i;
		$("#tj_rent_multi a:eq("+this_tj_rent+")").click();
	}
	last_tj_rent++;
}

Fangfa.init_form_nobody_newhome_order = function(o){
	$(o).validate({
		rules:{
			u_name:{
				required:true,
				rangelength:[2,4]
			},
			u_mobile:{
				required:true,
				number:true,
				rangelength:[11,11]
			},
			u_age:{
				number:true
			},
			u_phone_family:{
				number:true
			},
			u_phone_office:{
				number:true
			},
			u_email:{
				required:true,
				email:true
			},
			u_postcode:{
				required:true,
				number:true,
				rangelength:[6,6]
			},
			u_address:{
				required:true
			}
		},
		messages:{
			u_name:{
				required:'姓名必填。',
				rangelength:'姓名长度不正确。'
			},
			u_mobile:{
				required:'手机必填。',
				number:'手机格式不正确。',
				rangelength:'手机格式不正确。'
			},
			u_age:{
				number:'年龄格式不正确。'
			},
			u_phone_family:{
				number:'家庭电话格式不正确。'
			},
			u_phone_office:{
				number:'办公电话格式不正确。'
			},
			u_email:{
				required:'邮件地址必填。',
				email:'邮件格式不正确。'
			},
			u_postcode:{
				required:'邮编必填。',
				number:'邮编格式不正确。',
				rangelength:'邮编格式不正确。'
			},
			u_address:{
				required:'邮寄地址必填。'
			}
		}
		,
		errorLabelContainer: $("#err-nobody_newhome_order")
		//		errorPlacement: function(error, element) {
		//			error.appendTo ( '#err-nobody_newhome_order' );
		//		}
	});
}

Fangfa.init_etown_stores_map = function(o){
	var map = null;

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));

		map.addControl(new GSmallMapControl());

		var lng = $('#building_longitude').val();
		var lat = $('#building_latitude').val();

		map.setCenter( new GLatLng(30.65725857159338,104.06593322753906), 12);

		$.getJSON("/a.php?action=get_stores",{output:'json'}, function(data){
			$.each(data, function(i,item){
				var icon = new GIcon(G_DEFAULT_ICON);
				icon.image = config.domain_www+'assets/logo_j.gif';
				icon.shadow = config.domain_www+"assets/shad.gif";
				icon.iconSize = new GSize(30, 20);
				icon.shadowSize = new GSize(1, 1);
				markerOptions = { icon:icon };
				var marker = new GMarker( new GLatLng(item.buildup_latitude,item.buildup_longitude),markerOptions);
				map.addOverlay(marker);

				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml("<img src=\""+config.domain_uf + item.buildup_pic.replace(/.jpg/g,"_100x100.jpg")+"\" style=\"float:right;\"/><b>" + item.buildup_name + "店</b><br /><br />地址:" + item.buildup_address + "<br />联系人:" + item.buildup_linkman + "<br />联系电话:" + item.buildup_phone + "");
				});

			});
		});


	}
}

Fangfa.init_broker_ulshow = function(){
	
	$('ul#brokers li.broker').mouseover(function(){
		$(this).addClass('house_detail_hover');
	}).mouseout(function(){
		$(this).removeClass('house_detail_hover');
	}).click(function(){
		window.location.href=$(this).find('a').attr('href');
	});
}

Fangfa.init_broker_link = function(){
	
	$('ul.profile').mouseover(function(){
		$(this).addClass('house_detail_hover');
	}).mouseout(function(){
		$(this).removeClass('house_detail_hover');
	}).click(function(){
		window.location.href=$(this).find('a').attr('href');
	});
	
	
}



function exp_dialog(b) {
    var c = document.documentElement;
    return 0 - parseInt(b.offsetHeight / 2) + (TBWindowMargin = c && c.scrollTop || document.body.scrollTop) + "px"
}
function exp_overlay(b) {
    return 0 - parseInt(b.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + "px"
}
