/*
	楼盘大卖场导航菜单
	初始化
*/
try {  
	document.execCommand("BackgroundImageCache", false, true); 
} catch(err) {}

var def="3";
function mover(object){
  //主菜单
  var mm=document.getElementById("m_"+object);
  mm.className="now";
  //初始主菜单先隐藏效果
  if(def!=0){
    var mdef=document.getElementById("m_"+def);
    mdef.className="m_li";
  }
  //子菜单
  var ss=document.getElementById("s_"+object);
  ss.style.display="block";
  //初始子菜单先隐藏效果
  if(def!=0){
    var sdef=document.getElementById("s_"+def);
    sdef.style.display="none";
  }
}

function mout(object){
  //主菜单
  var mm=document.getElementById("m_"+object);
  mm.className="m_li";
  //初始主菜单还原效果
  if(def!=0){
    var mdef=document.getElementById("m_"+def);
    mdef.className="now";
  }
  //子菜单
  var ss=document.getElementById("s_"+object);
  ss.style.display="none";
  //初始子菜单还原效果
  if(def!=0){
    var sdef=document.getElementById("s_"+def);
    sdef.style.display="block";
  }
}

/**
	* dom加裁完成开始执行
*/
var XMLHttp = null;
$(function(){
	//根据关键字获取相关楼盘
	function getlikekeword(k){
		if(XMLHttp){
			XMLHttp.abort();
		}
		XMLHttp = $.ajax({
				type:'POST',
				url:'../searchpost.php',
				data:'act=searchkey&keyword='+encodeURIComponent(k),
				success:function(result){
					$('#likehandhousekeyword').empty();
					if(result){
						$('#likehandhousekeyword').append(result);
					}else{
						$(".association").hide();
					}
				}
		});
	}
	
	//设置搜索框的值
	function setkword(kw){
		$("input[name=keyword]").val(kw).focus();
		$(".association").hide();
	}
	//点击列表设置搜索框的值
	$('.lx').live('click',function(e){
		 setkword($(this).text());
		 e.preventDefault();
	});
	//点击隐藏联想列表
	$(".close").live('click', function(e){
		$(".association").hide();
		e.preventDefault();
	})
	//点击搜索框联想功能
	$('input[name=keyword]').bind('click',function(){
		if($.trim(this.value) == '请输入关键字...'){
			this.value='';
		}
	}).bind('blur',function(){
		if($.trim(this.value) == ''){
			this.value='请输入关键字...';
		}
	}).bind('input',function(){
		if($.trim(this.value)=='' || $.trim(this.value)=='请输入关键字...'){
			$(".association").hide();
			return;
		}else{
			getlikekeword($.trim(this.value));
			$(".association").show();
		}
	}).bind('propertychange',function(){
		if($.trim(this.value)=='' || $.trim(this.value)=='请输入关键字...'){
			$(".association").hide();
			return;
		}else{
			getlikekeword($.trim(this.value));
			$(".association").show();
		}
	});
	
	//选择城区/地铁线
	$('#areametroinput').bind('click',function(event){
		$('#areametrolist').toggle();
		event.stopPropagation();
		$(document).one('click',function(){
			$('#areametrolist').hide();
		});
	});
	
	//class为areametro的a标签点击执行事件
	$('.areametro').bind('click',function(){
		$('#areametroinput').val($(this).text());
		var id = $(this).attr('id');
		//截掉a元素id的areametro_部分，得到选择区域的id
		var paramArr = id.split('_');
		var type = paramArr[0];
		var val = paramArr[1];
		$('#areametroid').attr('name',type+'_id').val(val);
	});
	$('#cancelareametro').bind('click',function(){
		$('#areametroinput').val('区县/地铁线');
		$('#areametroid').val('');
	});
	
	//点击登录提交表单
	
	$('#loginbutton').bind('click',function(){
		tologin($('#txtUsername'),$('#txtPassword'),$('#loginform'));
	});
	
	//Ctrl+Enter登录
	$('#loginform').bind('keydown',function(event){
		if(event.keyCode==13){
			this.submit();
		}
	});
	
	//列表页选择楼盘进行对比
	$('.checkhousing').bind('click',function(event){
		checknum($('.checkhousing'), 3);
		if($(this).attr('checked')){
			var hosuing_id = $(this).val();
			$('.search_pklist > ul').append("<li id='pkhousing_" + hosuing_id + "'><span class='fl fea5504 fb f14'>" + $('#housingname_' + hosuing_id).html() + "</span><input type='hidden' name='abouthousing_id[]' value='" + hosuing_id + "' /><span class='fr'><a href='javascript:;' class='removehousing' id='" + hosuing_id + "'>[删除]</a></span></li>");
		}else{
			$('#pkhousing_' + $(this).val()).remove();
		}
		$('#pkbox').css('top',event.clientY+$(document).scrollTop()-500).show();
	});
	//关闭隐藏
	$('#closepkbox').bind('click',function(){
		$('#pkbox').hide();
	});
	//删除选中的对比楼盘
	$('.removehousing').live('click',function(){
		//$(this).parents('li').remove();
		$('#pkhousing_' + $(this).attr('id')).remove();
		$('#checkhousing_' + $(this).attr('id')).attr('checked',false);
		checknum($('.checkhousing'), 3);
	});
	
	/*--------------------------------以下是楼盘介绍页面的js--------------------------------*/
	
	//点击团购按钮执行事件
	$('#groupbuy').bind('click',function(){
		addactivity();
	});
	
	
	//幸福指数
	$('#happnissbutton').bind('click',function(){
		var useranswer_community = $('#housingname').val();
		window.location.href='happinessindex.php?useranswer_community='+encodeURIComponent(useranswer_community);
	});
	
	//登录按钮点击
	$('#loginbut').bind('click',function(){
		var txtUsername = $('#txtUsername').val();
		var txtPassword = $('#txtPassword').val();
		if(txtUsername==''){
			$('#errormsg').html('用户名不能不空');
			return false;
		}
		if(txtPassword==''){
			$('#errormsg').html('密码不能为空');
			return false;
		}
		$('#loginform').submit();
	});
	
	
	//楼盘比较
	checkboxtodisalled('samehousing_id[]');

	checkboxtodisalled('abouthousing_id[]');
	//周边楼盘比较
	tocompare('aboutcomparebutton','abouthousing_id[]','aboutcompare_form');
	//同价位楼盘
	tocompare('comparebutton','samehousing_id[]','samecompare_form');
	
});

/**
	* 打开计算器
*/
function openCount(){
	window.open('count.html','_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=530,height=840,top=50,left=50');
}





